Skip to content

Commit

Permalink
Add missing signup/sektion family member email validation (#856)
Browse files Browse the repository at this point in the history
  • Loading branch information
amaierhofer committed Aug 20, 2024
1 parent 6ee6bf8 commit d8396a3
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def adult?
private

def assert_email_unique
if emails.include?(email)
if emails.include?(email) || Person.exists?(email: email)
errors.add(:email, :taken)
end
emails.push(email)
Expand Down
26 changes: 26 additions & 0 deletions spec/models/wizards/signup/sektion_wizard_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,32 @@ def build(params = required_attrs)
]
end

it "is invalid when on family_fields step and resuses main person email" do
@current_step = 2
required_attrs[:family_fields] = {
members_attributes: [
[0, {first_name: "Maxine", last_name: "Muster", birthday: "1.1.2000", email: "[email protected]"}]
]
}
expect(wizard).not_to be_valid
expect(wizard.errors).to be_empty
expect(wizard.family_fields).not_to be_valid
expect(wizard.family_fields.members.first.errors.full_messages).to eq ["E-Mail (optional) ist bereits vergeben. Die E-Mail muss eindeutig sein pro Person."]
end

it "is invalid when on family_fields step and uses existing email" do
@current_step = 2
required_attrs[:family_fields] = {
members_attributes: [
[0, {first_name: "Maxine", last_name: "Muster", birthday: "1.1.2000", email: "[email protected]"}]
]
}
expect(wizard).not_to be_valid
expect(wizard.errors).to be_empty
expect(wizard.family_fields).not_to be_valid
expect(wizard.family_fields.members.first.errors.full_messages).to eq ["E-Mail (optional) ist bereits vergeben. Die E-Mail muss eindeutig sein pro Person."]
end

it "is invalid when on various_fields step and data_protection is blank" do
@current_step = 3
required_attrs[:various_fields] = {data_protection: nil}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,15 @@
expect(form.errors.full_messages).to eq ["In einer Familienmitgliedschaft sind maximal 2 Erwachsene inbegriffen."]
end

it "is invalid if second member reuses existing email" do
form.members_attributes = [
[0, required_attrs.merge(email: "[email protected]")],
[1, required_attrs.merge(email: "[email protected]", birthday: "1.10.2014")]
]
expect(form).not_to be_valid
expect(form.members.second.errors.full_messages).to eq ["E-Mail (optional) ist bereits vergeben. Die E-Mail muss eindeutig sein pro Person."]
end

it "is invalid if second member reuses main_email in members" do
form.members_attributes = [
[0, required_attrs.merge(email: "[email protected]")],
Expand Down

0 comments on commit d8396a3

Please sign in to comment.