|
3 | 3 | require 'rails_helper' |
4 | 4 |
|
5 | 5 | RSpec.describe 'Project show requests' do |
6 | | - let!(:project) { create(:project) } |
| 6 | + let!(:project) { create(:project, locale: nil) } |
7 | 7 | let(:project_json) do |
8 | 8 | { |
9 | 9 | identifier: project.identifier, |
|
43 | 43 | end |
44 | 44 |
|
45 | 45 | context 'when loading another user\'s project' do |
46 | | - let!(:another_project) { create(:project) } |
| 46 | + let!(:another_project) { create(:project, locale: nil) } |
47 | 47 | let(:another_project_json) do |
48 | 48 | { |
49 | 49 | identifier: another_project.identifier, |
50 | 50 | project_type: 'python', |
51 | 51 | name: another_project.name, |
| 52 | + locale: another_project.locale, |
52 | 53 | user_id: another_project.user_id, |
53 | 54 | components: [], |
54 | 55 | image_list: [] |
|
70 | 71 |
|
71 | 72 | context 'when user is not logged in' do |
72 | 73 | context 'when loading a starter project' do |
73 | | - let!(:starter_project) { create(:project, user_id: nil) } |
| 74 | + let!(:starter_project) { create(:project, user_id: nil, locale: 'ja-JP') } |
74 | 75 | let(:starter_project_json) do |
75 | 76 | { |
76 | 77 | identifier: starter_project.identifier, |
|
84 | 85 | end |
85 | 86 |
|
86 | 87 | it 'returns success response' do |
87 | | - get("/api/projects/#{starter_project.identifier}", headers:) |
88 | | - |
| 88 | + get("/api/projects/#{starter_project.identifier}?locale=#{starter_project.locale}", headers:) |
89 | 89 | expect(response).to have_http_status(:ok) |
90 | 90 | end |
91 | 91 |
|
92 | 92 | it 'returns json' do |
93 | | - get("/api/projects/#{starter_project.identifier}", headers:) |
| 93 | + get("/api/projects/#{starter_project.identifier}?locale=#{starter_project.locale}", headers:) |
94 | 94 | expect(response.content_type).to eq('application/json; charset=utf-8') |
95 | 95 | end |
96 | 96 |
|
97 | 97 | it 'returns the project json' do |
98 | | - get("/api/projects/#{starter_project.identifier}", headers:) |
| 98 | + get("/api/projects/#{starter_project.identifier}?locale=#{starter_project.locale}", headers:) |
99 | 99 | expect(response.body).to eq(starter_project_json) |
100 | 100 | end |
101 | 101 |
|
102 | 102 | it 'returns 404 response if invalid project' do |
103 | 103 | get('/api/projects/no-such-project', headers:) |
104 | 104 | expect(response).to have_http_status(:not_found) |
105 | 105 | end |
| 106 | + |
| 107 | + it 'creates a new ProjectLoader with the correct parameters' do |
| 108 | + allow(ProjectLoader).to receive(:new).and_call_original |
| 109 | + get("/api/projects/#{starter_project.identifier}?locale=#{starter_project.locale}", headers:) |
| 110 | + expect(ProjectLoader).to have_received(:new) |
| 111 | + .with(starter_project.identifier, [starter_project.locale]) |
| 112 | + end |
106 | 113 | end |
107 | 114 |
|
108 | 115 | context 'when loading an owned project' do |
|
0 commit comments