Skip to content

Commit

Permalink
[RUBY-3212] Add uniqueness validation for project name
Browse files Browse the repository at this point in the history
- Updated `PafsCore::ProjectNameStep` to validate uniqueness of the project name with a custom error message.
- Added corresponding tests in `project_name_step_spec.rb` to ensure validation fails for non-unique project names.
  • Loading branch information
jjromeo committed Sep 2, 2024
1 parent ab50ae3 commit a7b6748
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/steps/pafs_core/project_name_step.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ class ProjectNameStep < BasicStep
message: "The project name must only contain letters, underscores, hyphens and numbers"
}

validates :name, uniqueness: { message: "The project name already exists. Your project must have a unique name." }

private

def step_params(params)
Expand Down
12 changes: 12 additions & 0 deletions spec/steps/pafs_core/project_name_step_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@
end
end
end

context "when name is not unique" do
before do
create(:project_name_step, name: "Existing Project")
end

it "returns false when validation fails due to non-unique name" do
duplicate_params = ActionController::Parameters.new({ project_name_step: { name: "Existing Project" } })
expect(subject.update(duplicate_params)).to be false
expect(subject.errors[:name].join).to eq("The project name already exists. Your project must have a unique name.")
end
end
end

describe "#update" do
Expand Down

0 comments on commit a7b6748

Please sign in to comment.