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

streamline project api specs

ulferts9a0fe1074f3e
diff --git a/modules/bcf/spec/requests/api/bcf/v2_1/projects/projects_api_spec.rb b/modules/bcf/spec/requests/api/bcf/v2_1/projects/projects_api_spec.rb
index 3ff63bb4cbd..b638d086c3a 100644
--- a/modules/bcf/spec/requests/api/bcf/v2_1/projects/projects_api_spec.rb
+++ b/modules/bcf/spec/requests/api/bcf/v2_1/projects/projects_api_spec.rb
@@ -43,24 +43,32 @@ describe 'BCF 2.1 projects resource', type: :request do
let(:project) { FactoryBot.create(:project, enabled_module_names: [:bcf]) }
subject(:response) { last_response }
- describe 'GET /api/bcf/2.1/projects/:project_id' do
- let(:path) { "/api/bcf/2.1/projects/#{project.id}" }
- let(:current_user) { member_user }
-
- before do
- login_as(current_user)
- get path
- end
-
+ shared_examples_for 'successful get request' do
it 'responds 200 OK' do
expect(subject.status)
.to eql 200
end
it 'returns the project' do
+ expect(subject.body)
+ .to be_json_eql(expected_body.to_json)
+ end
+
+ it 'is has a json content type header' do
+ expect(subject.headers['Content-Type'])
+ .to eql 'application/json; charset=utf-8'
+ end
+ end
+
+ shared_examples_for 'not found' do
+ it 'responds 404 NOT FOUND' do
+ expect(subject.status)
+ .to eql 404
+ end
+
+ it 'states a NOT FOUND message' do
expected = {
- project_id: project.id,
- name: project.name
+ message: 'The requested resource could not be found.'
}
expect(subject.body)
@@ -71,28 +79,30 @@ describe 'BCF 2.1 projects resource', type: :request do
expect(subject.headers['Content-Type'])
.to eql 'application/json; charset=utf-8'
end
+ end
- context 'lacking permissions' do
- let(:current_user) { non_member_user }
+ describe 'GET /api/bcf/2.1/projects/:project_id' do
+ let(:path) { "/api/bcf/2.1/projects/#{project.id}" }
+ let(:current_user) { member_user }
- it 'responds 404 NOT FOUND' do
- expect(subject.status)
- .to eql 404
- end
+ before do
+ login_as(current_user)
+ get path
+ end
- it 'states a NOT FOUND message' do
- expected = {
- message: 'The requested resource could not be found.'
+ it_behaves_like 'successful get request' do
+ let(:expected_body) do
+ {
+ project_id: project.id,
+ name: project.name
}
-
- expect(subject.body)
- .to be_json_eql(expected.to_json)
end
+ end
- it 'is has a json content type header' do
- expect(subject.headers['Content-Type'])
- .to eql 'application/json; charset=utf-8'
- end
+ context 'lacking permissions' do
+ let(:current_user) { non_member_user }
+
+ it_behaves_like 'not found'
end
end
@@ -114,24 +124,15 @@ describe 'BCF 2.1 projects resource', type: :request do
get path
end
- it 'responds 200 OK' do
- expect(subject.status)
- .to eql 200
- end
-
- it 'returns an array of visible projects having bim enabled' do
- expected = {
- project_id: project.id,
- name: project.name
- }
-
- expect(subject.body)
- .to be_json_eql([expected].to_json)
- end
-
- it 'is has a json content type header' do
- expect(subject.headers['Content-Type'])
- .to eql 'application/json; charset=utf-8'
+ it_behaves_like 'successful get request' do
+ let(:expected_body) do
+ [
+ {
+ project_id: project.id,
+ name: project.name
+ }
+ ]
+ end
end
end
end