Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Merge branch 'release/12.0' into dev

ulferts5cb07c0f0205
diff --cc spec/lib/api/v3/queries/query_representer_parsing_spec.rb
index 515359dfc2b,74437cac2ad..724c0c74cf0
--- a/spec/lib/api/v3/queries/query_representer_parsing_spec.rb
+++ b/spec/lib/api/v3/queries/query_representer_parsing_spec.rb
@@@ -28,14 -28,13 +28,14 @@@
require 'spec_helper'
- describe ::API::V3::Queries::QueryRepresenter do
+ describe ::API::V3::Queries::QueryRepresenter, 'parsing' do
include ::API::V3::Utilities::PathHelper
- let(:query) { FactoryBot.build_stubbed(:query, project: project) }
- let(:project) { FactoryBot.build_stubbed(:project) }
+ let(:query) { build_stubbed(:query, project: project) }
+ let(:project) { build_stubbed(:project) }
- let(:user) { double('current_user') }
++ let(:user) { build_stubbed(:user) }
let(:representer) do
- described_class.new(query, current_user: user, embed_links: true)
+ described_class.new(query, current_user: current_user, embed_links: true)
end
let(:permissions) { [] }
@@@ -60,6 -59,8 +60,8 @@@
end
end
- current_user { FactoryBot.build_stubbed(:user) }
++ current_user { build_stubbed(:user) }
+
before do
policy
end
@@@ -124,14 -126,72 +127,72 @@@
end
end
- context 'assuming query is not new' do
+ context 'if query is not new' do
let(:new_record) { false }
- it 'should set ordered_work_packages' do
- expect(query)
- .not_to receive(:ordered_work_packages)
+ it 'sets ordered_work_packages' do
+ allow(query)
+ .to receive(:ordered_work_packages)
subject
+
+ expect(query)
+ .not_to have_received(:ordered_work_packages)
+ end
+ end
+ end
+
+ describe 'project' do
- let(:query) { FactoryBot.build_stubbed(:query, project: nil) }
++ let(:query) { build_stubbed(:query, project: nil) }
+
+ let(:request_body) do
+ {
+ '_links' => {
+ 'project' => {
+ 'href' => "/api/v3/projects/#{project_id}"
+ }
+ }
+ }
+ end
+
+ before do
+ scope = instance_double(ActiveRecord::Relation)
+
+ allow(Project)
+ .to receive(:where)
+ .with(identifier: project_id)
+ .and_return(scope)
+ allow(scope)
+ .to receive(:pick)
+ .with(:id)
+ .and_return(project.id)
+ end
+
+ context 'for a number only id' do
+ let(:project_id) { project.id }
+
+ it 'sets the project_id accordingly' do
+ expect(subject.project_id)
+ .to eql project.id
+ end
+ end
+
+ context 'for a text only id (identifier)' do
+ let(:project_id) { project.identifier }
+
+ it 'deduces the id for the project_id accordingly' do
+ expect(subject.project_id)
+ .to eql project.id
+ end
+ end
+
+ context 'for a text starting with numbers (identifier)' do
- let(:project) { FactoryBot.build_stubbed(:project, identifier: '5555-numbered-identifier') }
++ let(:project) { build_stubbed(:project, identifier: '5555-numbered-identifier') }
+ let(:project_id) { project.identifier }
+
+ it 'deduces the id for the project_id accordingly' do
+ expect(subject.project_id)
+ .to eql project.id
end
end
end