Skip to content

Commit

Permalink
Add message
Browse files Browse the repository at this point in the history
  • Loading branch information
hunchr committed Aug 14, 2024
1 parent 237b8d3 commit 46541f1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
7 changes: 6 additions & 1 deletion app/models/person/data_quality_issue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,17 @@ class Person::DataQualityIssue < ApplicationRecord

validate :person_attribute_exists
validates :attr, :severity, presence: true
validates :key, uniqueness: { scope: %i[person_id attr] }, presence: true
validates :key, uniqueness: {scope: %i[person_id attr]}, presence: true

def severity=(value)
super(self.class.severities.keys.index(value.to_s)&.next)
end

def message
I18n.t("activemodel.errors.models.person.data_quality_issue.message",
attr: Person.human_attribute_name(attr), key: key)
end

private

def person_attribute_exists
Expand Down
3 changes: 3 additions & 0 deletions config/locales/wagon.de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ de:
ist bereits Mitglied der Sektion oder
hat ein offenes Beitrittsgesuch
must_be_family_main_person: muss Hauptperson der Familie sein
person:
data_quality_issue:
message: '%{attr} %{key}'

wizards/steps/choose_sektion:
requires_admin: Wir bitten dich den gewünschten Sektionswechsel
Expand Down
8 changes: 8 additions & 0 deletions spec/models/person/data_quality_issue_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,13 @@
expect(data_quality.errors[:severity]).to eq ["muss ausgefüllt werden"]
end
end

context "#message" do
it "shows an error message" do
data_quality = person.data_quality_issues
.new(attr: "zip_code", key: "ist leer", severity: "error")
expect(data_quality.message).to eq("PLZ ist leer")
end
end
end
end

0 comments on commit 46541f1

Please sign in to comment.