Merge pull request #1783 from opf/hotfix/13789_apiv2_ids_parameter_ignored_for_planning_elements

[Hotfix] 13789 apiv2 ids parameter ignored for planning elements
pull/1796/head
ulferts 10 years ago
commit ff2e5d6584
  1. 7
      app/controllers/api/v2/planning_elements_controller.rb
  2. 48
      spec/controllers/api/v2/planning_elements_controller_spec.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

@ -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

Loading…
Cancel
Save