Skip to content

Commit c0af46a

Browse files
committed
Allow experience-cs admin to set project identifier
To achieve this, I've had to remove the explicit *overriding* of `Project#identifier` in `Project::Create.build_project`. Now it only sets the identifier if none is provided. Even this isn't strictly necessary, because of the `Project#check_unique_not_null` check which is triggered on a `before_validation` callback. However, I want to keep the changes to a minimum to reduce the risk of breaking anything and, in any case, I'm not very convinced about the existence of that `before_validation`, so I'd prefer not to increase reliance on it.
1 parent 195923c commit c0af46a

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

lib/concepts/project/operations/create.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ def call(project_hash:)
1717
private
1818

1919
def build_project(project_hash)
20-
identifier = PhraseIdentifier.generate
21-
new_project = Project.new(project_hash.except(:components).merge(identifier:))
20+
project_hash[:identifier] ||= PhraseIdentifier.generate
21+
new_project = Project.new(project_hash.except(:components))
2222
new_project.components.build(project_hash[:components])
2323
new_project
2424
end

spec/features/project/creating_a_project_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@
213213
let(:params) do
214214
{
215215
project: {
216+
identifier: 'test-project',
216217
name: 'Test Project',
217218
locale: 'fr',
218219
project_type: Project::Types::SCRATCH,
@@ -230,6 +231,13 @@
230231
expect(response).to have_http_status(:created)
231232
end
232233

234+
it 'sets the project identifier to the specified (not the generated) value' do
235+
post('/api/projects', headers:, params:)
236+
data = JSON.parse(response.body, symbolize_names: true)
237+
238+
expect(data[:identifier]).to eq('test-project')
239+
end
240+
233241
it 'sets the project name to the specified value' do
234242
post('/api/projects', headers:, params:)
235243
data = JSON.parse(response.body, symbolize_names: true)

0 commit comments

Comments
 (0)