Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
FORMAT_RULES = [
[:too_long, ->(id, max) { id.length > max }],
[:numerical, ->(id, _) { id.match?(/\A\d+\z/) }],
[:starts_with_number, ->(id, _) { id.match?(/\A\d/) }],
[:does_not_start_with_letter, ->(id, _) { !id.match?(/\A[A-Za-z]/) }],
[:special_characters, ->(id, _) { id.match?(/[^a-zA-Z0-9_]/) }],
[:not_fully_uppercased, ->(id, _) { id != id.upcase }]
].freeze
Expand All @@ -83,7 +83,7 @@
def scope
@scope ||= exceeds_max_length
.or(contains_non_alphanumeric)
.or(starts_with_digit)
.or(does_not_start_with_letter)
.or(not_fully_uppercased)
end

Expand Down Expand Up @@ -114,7 +114,7 @@

def exceeds_max_length = Project.where("length(identifier) > ?", self.class.max_identifier_length)
def contains_non_alphanumeric = Project.where("identifier ~ ?", "[^a-zA-Z0-9_]")
def starts_with_digit = Project.where("identifier ~ ?", "^[0-9]")
def does_not_start_with_letter = Project.where("identifier ~ ?", "^[^A-Za-z]")

Check notice on line 117 in app/services/project_identifiers/identifier_autofix/problematic_identifiers.rb

View workflow job for this annotation

GitHub Actions / rubocop

[rubocop] app/services/project_identifiers/identifier_autofix/problematic_identifiers.rb#L117 <Naming/PredicatePrefix>

Rename `does_not_start_with_letter` to `does_not_start_with_letter?`.
Raw output
app/services/project_identifiers/identifier_autofix/problematic_identifiers.rb:117:11: C: Naming/PredicatePrefix: Rename `does_not_start_with_letter` to `does_not_start_with_letter?`.
def not_fully_uppercased = Project.where("identifier != UPPER(identifier)")

def collision_error_reason(identifier)
Expand Down
2 changes: 1 addition & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ en:
autofix_preview:
error_too_long: Has to be 10 characters or fewer
error_numerical: Cannot be purely numerical
error_starts_with_number: Cannot start with a number
error_does_not_start_with_letter: Must start with an uppercase letter
error_special_characters: Special characters not allowed
error_not_fully_uppercased: Must be uppercase
error_in_use: Already in use as another project's active handle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ def create_project_with_raw_identifier(name:, identifier:)
expect(result.projects_data.first[:error_reason]).to eq(:numerical)
end

it "assigns :starts_with_number when identifier begins with a digit" do
it "assigns :does_not_start_with_letter when identifier begins with a digit" do
create_project_with_raw_identifier(name: "Test", identifier: "1abc")
expect(result.projects_data.first[:error_reason]).to eq(:starts_with_number)
expect(result.projects_data.first[:error_reason]).to eq(:does_not_start_with_letter)
end

it "assigns :not_fully_uppercased when identifier is lowercase but otherwise valid" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,16 @@ def create_project_with_raw_identifier(name:, identifier:)
expect(analysis.scope).to include(Project.find(project.id))
end

it "includes projects with identifiers starting with a digit" do
it "includes projects with identifiers not starting with a letter" do
project = create_project_with_raw_identifier(name: "Test", identifier: "1abc")
expect(analysis.scope).to include(Project.find(project.id))
end

it "includes projects with identifiers starting with an underscore" do
project = create_project_with_raw_identifier(name: "Test", identifier: "_FOO")
expect(analysis.scope).to include(Project.find(project.id))
end

it "includes projects with non-uppercased identifiers" do
project = create_project_with_raw_identifier(name: "Test", identifier: "proj")
expect(analysis.scope).to include(Project.find(project.id))
Expand Down Expand Up @@ -90,12 +95,16 @@ def create_project_with_raw_identifier(name:, identifier:)
expect(described_class.format_error_reason("12345")).to eq(:numerical)
end

it "returns :starts_with_number when identifier begins with a digit" do
expect(described_class.format_error_reason("1abc")).to eq(:starts_with_number)
it "returns :does_not_start_with_letter when identifier begins with a digit" do
expect(described_class.format_error_reason("1abc")).to eq(:does_not_start_with_letter)
end

it "returns :does_not_start_with_letter when identifier begins with an underscore" do
expect(described_class.format_error_reason("_FOO")).to eq(:does_not_start_with_letter)
end

it "returns :special_characters when identifier has non-alphanumeric chars" do
expect(described_class.format_error_reason("ab-c")).to eq(:special_characters)
expect(described_class.format_error_reason("AB-C")).to eq(:special_characters)
end

it "returns :not_fully_uppercased when identifier is lowercase but otherwise valid" do
Expand Down Expand Up @@ -139,7 +148,7 @@ def create_project_with_raw_identifier(name:, identifier:)
end

it "delegates format checks to .format_error_reason" do
expect(analysis.error_reason("ab-c")).to eq(:special_characters)
expect(analysis.error_reason("_FOO")).to eq(:does_not_start_with_letter)
end
end

Expand Down
Loading