fixing the ancestor-chain, adding tests on removed children

pull/445/head
Stefan Frank 11 years ago
parent c261d06324
commit 5598d181b4
  1. 2
      app/controllers/api/v2/planning_elements_controller.rb
  2. 20
      features/planning_elements/filter.feature
  3. 5
      features/step_definitions/api_steps.rb

@ -261,7 +261,7 @@ module Api
# remove all children, that are not present in the filtered set
pe.children = pe.children.select {|child| filtered_ids.include? child.id} unless pe.children.empty?
# re-wire the parent of this pe to the first ancestor found in the filtered set
pe.parent = pe.ancestors.select {|ancestor| filtered_ids.include? ancestor.id}.first if pe.parent_id
pe.parent = pe.ancestors.select {|ancestor| filtered_ids.include? ancestor.id}.last if pe.parent_id
end
end
end

@ -144,6 +144,18 @@ Feature: Filtering work packages via the api
And the json-response should contain a work_package "work_package#1.1.1"
And the json-response should say that "work_package#1" is parent of "work_package#1.1.1"
Scenario: The parent should be rewired to the first ancestor present in the filtered set
Given there are the following work packages in project "sample_project":
| subject | type | parent |
| work_package#1 | Epic | |
| work_package#1.1 | Task | work_package#1 |
| work_package#1.1.1 | Bug | work_package#1.1 |
| work_package#1.1.1.1 | Task | work_package#1.1.1 |
When I call the work_package-api on project "sample_project" requesting format "json" filtering for type "Epic,Task"
Then the json-response should include 3 work packages
And the json-response should say that "work_package#1.1" is parent of "work_package#1.1.1.1"
Scenario: When all ancestors are filtered, the work_package should have no parent
Given there are the following work packages in project "sample_project":
| subject | type | parent |
@ -154,3 +166,11 @@ Feature: Filtering work packages via the api
Then the json-response should include 1 work packages
And the json-response should say that "work_package#1.1.1" has no parent
Scenario: Children are filtered out
Given there are the following work packages in project "sample_project":
| subject | type | parent |
| work_package#1 | Epic | |
| work_package#1.1 | Task | work_package#1 |
| work_package#1.2 | Story | work_package#1 |
When I call the work_package-api on project "sample_project" requesting format "json" filtering for type "Epic,Story"
And the json-response should say that "work_package#1" has 1 child

@ -62,6 +62,11 @@ And(/^the json\-response should say that "(.*?)" has no parent$/) do |child_name
expect(child["parent"]).to be_nil
end
And(/^the json\-response should say that "(.*?)" has (\d+) child(ren)?$/) do |parent_name, nr_of_children,plural|
parent = decoded_json["planning_elements"].select {|wp| wp["name"] == parent_name}.first
expect(parent["children"].size).to eql nr_of_children.to_i
end
Then(/^I call the work_package\-api on project "(.*?)" requesting format "(.*?)" filtering for type "(.*?)"$/) do |project_name, format, type_names|
types = Project.find_by_identifier(project_name).types.where(name: type_names.split(","))

Loading…
Cancel
Save