From f6353003d90518850b6a10ad940bfb632dcface5 Mon Sep 17 00:00:00 2001 From: Hagen Schink Date: Wed, 9 Jul 2014 13:34:09 +0200 Subject: [PATCH 1/2] Add specs --- .../v2/planning_elements_controller_spec.rb | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/spec/controllers/api/v2/planning_elements_controller_spec.rb b/spec/controllers/api/v2/planning_elements_controller_spec.rb index 7689a767d3..ccb14b54aa 100644 --- a/spec/controllers/api/v2/planning_elements_controller_spec.rb +++ b/spec/controllers/api/v2/planning_elements_controller_spec.rb @@ -315,6 +315,54 @@ describe Api::V2::PlanningElementsController do end end + describe 'ids' do + let(:project_a) { FactoryGirl.create(:project) } + let(:project_b) { FactoryGirl.create(:project) } + let(:project_c) { FactoryGirl.create(:project) } + let!(:work_package_a) { FactoryGirl.create(:work_package, + project: project_a) } + let!(:work_package_b) { FactoryGirl.create(:work_package, + project: project_b) } + let!(:work_package_c) { FactoryGirl.create(:work_package, + project: project_c) } + let(:project_ids) { [project_a, project_b, project_c].collect(&:id).join(',') } + let(:wp_ids) { [work_package_a, work_package_b].collect(&:id) } + + become_admin { [project_a, project_b, work_package_c.project] } + + describe 'empty ids' do + before { get 'index', project_id: project_ids, ids: '', format: 'xml' } + + it { expect(assigns(:planning_elements)).to be_empty } + end + + shared_examples_for "valid ids request" do + before { get 'index', project_id: project_ids, ids: wp_ids.join(','), format: 'xml' } + + subject { assigns(:planning_elements).collect(&:id) } + + it { expect(subject).to include(*wp_ids) } + + it { expect(subject).not_to include(*invalid_wp_ids) } + end + + describe 'known ids' do + context 'single id' do + it_behaves_like "valid ids request" do + let(:wp_ids) { [work_package_a.id] } + let(:invalid_wp_ids) { [work_package_b.id, work_package_c.id] } + end + end + + context 'multiple ids' do + it_behaves_like "valid ids request" do + let(:wp_ids) { [work_package_a.id, work_package_b.id] } + let(:invalid_wp_ids) { [work_package_c.id] } + end + end + end + end + describe 'w/ list of projects' do describe 'w/ an unknown project' do it 'renders a 404 Not Found page' do From 08c55efd49cb09d7469ad2b719ea7d3eecb57b8d Mon Sep 17 00:00:00 2001 From: Hagen Schink Date: Wed, 9 Jul 2014 13:34:29 +0200 Subject: [PATCH 2/2] Consider ids parameter --- app/controllers/api/v2/planning_elements_controller.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/controllers/api/v2/planning_elements_controller.rb b/app/controllers/api/v2/planning_elements_controller.rb index b7b9985624..0efaf9043c 100644 --- a/app/controllers/api/v2/planning_elements_controller.rb +++ b/app/controllers/api/v2/planning_elements_controller.rb @@ -259,6 +259,9 @@ module Api .changed_since(@since) .includes(:status, :project, :type, :custom_values) + wp_ids = parse_work_package_ids + work_packages = work_packages.where(id: wp_ids) if wp_ids + if params[:f] #we need a project to make project-specific custom fields work project = timeline_to_project(params[:timeline]) @@ -341,6 +344,10 @@ module Api def parse_changed_since @since = Time.at(Float(params[:changed_since] || 0).to_i) rescue render_400 end + + def parse_work_package_ids + params[:ids] ? params[:ids].split(',') : nil + end end end end