Skip to content

Commit 7986f0a

Browse files
committed
Make updating public projects specs more realistic
The immediate use case for `Api::PublicProjectsController#update` is for experience-cs admin users to change the name of a public project. Since experience-cs only deals with Scratch projects, it makes sense to use projects of this type in the specs. However, since we're using `ProjectLoader` to find the project and the default scope is still in place to hide Scratch projects, we need to make use of the `ProjectScoping` concern to use the `project_type` param to set `Current.project_scope` to include Scratch projects.
1 parent ce20014 commit 7986f0a

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

spec/features/public_project/updating_a_public_project_spec.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
RSpec.describe 'Updating a public project', type: :request do
66
let(:creator) { build(:user) }
7-
let(:project) { create(:project, locale: 'en') }
7+
let(:project) { create(:project, locale: 'en', project_type: Project::Types::SCRATCH) }
88
let(:headers) { { Authorization: UserProfileMock::TOKEN } }
99
let(:params) { { project: { name: 'New name' } } }
1010

@@ -13,29 +13,29 @@
1313
end
1414

1515
it 'responds 200 OK' do
16-
put("/api/public_projects/#{project.identifier}", headers:, params:)
16+
put("/api/public_projects/#{project.identifier}?project_type=scratch", headers:, params:)
1717
expect(response).to have_http_status(:success)
1818
end
1919

2020
it 'responds with the project JSON' do
21-
put("/api/public_projects/#{project.identifier}", headers:, params:)
21+
put("/api/public_projects/#{project.identifier}?project_type=scratch", headers:, params:)
2222
data = JSON.parse(response.body, symbolize_names: true)
2323

2424
expect(data).to include(name: 'New name')
2525
end
2626

2727
it 'responds 400 Bad Request when params are malformed' do
28-
put("/api/public_projects/#{project.identifier}", headers:, params: {})
28+
put("/api/public_projects/#{project.identifier}?project_type=scratch", headers:, params: {})
2929
expect(response).to have_http_status(:bad_request)
3030
end
3131

3232
it 'responds 401 Unauthorized when no token is given' do
33-
put("/api/public_projects/#{project.identifier}", params:)
33+
put("/api/public_projects/#{project.identifier}?project_type=scratch", params:)
3434
expect(response).to have_http_status(:unauthorized)
3535
end
3636

3737
it 'responds 404 Not Found when project is not found' do
38-
put('/api/public_projects/another-identifier', headers:, params:)
38+
put('/api/public_projects/another-identifier?project_type=scratch', headers:, params:)
3939
expect(response).to have_http_status(:not_found)
4040
end
4141
end

spec/requests/public_projects/update_spec.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
RSpec.describe 'Update public project requests' do
66
let(:locale) { 'fr' }
77
let(:project_loader) { instance_double(ProjectLoader) }
8-
let(:project) { create(:project, locale: 'en') }
8+
let(:project) { create(:project, locale: 'en', project_type: Project::Types::SCRATCH) }
99
let(:creator) { build(:user) }
1010
let(:params) { { project: { name: 'New name' } } }
1111

@@ -25,19 +25,19 @@
2525
end
2626

2727
it 'builds ProjectLoader with identifier & locale' do
28-
put("/api/public_projects/#{project.identifier}?locale=#{locale}", headers:, params:)
28+
put("/api/public_projects/#{project.identifier}?project_type=scratch&locale=#{locale}", headers:, params:)
2929

3030
expect(ProjectLoader).to have_received(:new).with(project.identifier, [locale])
3131
end
3232

3333
it 'uses ProjectLoader#load to find the project based on identifier & locale' do
34-
put("/api/public_projects/#{project.identifier}?locale=#{locale}", headers:, params:)
34+
put("/api/public_projects/#{project.identifier}?project_type=scratch&locale=#{locale}", headers:, params:)
3535

3636
expect(project_loader).to have_received(:load)
3737
end
3838

3939
it 'returns success' do
40-
put("/api/public_projects/#{project.identifier}", headers:, params:)
40+
put("/api/public_projects/#{project.identifier}?project_type=scratch", headers:, params:)
4141

4242
expect(response).to have_http_status(:success)
4343
end
@@ -53,7 +53,7 @@
5353
end
5454

5555
it 'returns error' do
56-
put("/api/public_projects/#{project.identifier}", headers:, params:)
56+
put("/api/public_projects/#{project.identifier}?project_type=scratch", headers:, params:)
5757

5858
expect(response).to have_http_status(:unprocessable_entity)
5959
end
@@ -62,7 +62,7 @@
6262

6363
context 'when no token is given' do
6464
it 'returns unauthorized' do
65-
put("/api/public_projects/#{project.identifier}", headers:, params:)
65+
put("/api/public_projects/#{project.identifier}?project_type=scratch", headers:, params:)
6666

6767
expect(response).to have_http_status(:unauthorized)
6868
end

0 commit comments

Comments
 (0)