Skip to content

Commit 8ef6c18

Browse files
committed
Validate format of identifier for public project
This uses the recently added `PublicProject` wrapper class to add the validation just in the context of the `Api::PublicProjectsController`. The validation is based on the regular expression in `PhaseIdentifier::PATTERN`, i.e. kebab-case.
1 parent b2ce2a0 commit 8ef6c18

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

lib/concepts/public_project/operations/create.rb

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ class << self
66
def call(project_hash:)
77
response = OperationResponse.new
88

9-
project = Project.new(project_hash).tap do |p|
10-
p.skip_identifier_generation = true
11-
end
12-
project.save!
9+
public_project = PublicProject.new(
10+
Project.new(project_hash).tap do |p|
11+
p.skip_identifier_generation = true
12+
end
13+
)
14+
public_project.save!
1315

14-
response[:project] = project
16+
response[:project] = public_project.project
1517
response
1618
rescue StandardError => e
1719
Sentry.capture_exception(e)

spec/concepts/public_project/create_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,17 @@
5555
expect(create_project[:error]).to eq("Error creating project: Validation failed: Identifier can't be blank")
5656
end
5757
end
58+
59+
context 'when identifier is in invalid format' do
60+
let(:identifier) { 'FooBarBaz' }
61+
62+
it 'returns failure' do
63+
expect(create_project.failure?).to be(true)
64+
end
65+
66+
it 'returns error message' do
67+
expect(create_project[:error]).to eq('Error creating project: Validation failed: Identifier is invalid')
68+
end
69+
end
5870
end
5971
end

0 commit comments

Comments
 (0)