Skip to content

Commit

Permalink
Validate email_language on registration
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchellhenke committed Feb 15, 2022
1 parent e3f1224 commit 5cc7369
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/forms/register_user_email_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class RegisterUserEmailForm
include FormEmailValidator

validate :validate_terms_accepted
validates_inclusion_of :email_language, in: I18n.available_locales.map(&:to_s).append(nil)

attr_reader :email_address, :terms_accepted
attr_accessor :email_language
Expand Down
21 changes: 21 additions & 0 deletions spec/forms/register_user_email_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -240,5 +240,26 @@
expect(submit_form.errors).to eq errors
end
end

context 'when user provides invalid email_language' do
it 'returns failure with errors' do
errors = { email_language: [t('errors.messages.inclusion')] }
extra = {
domain_name: 'gmail.com',
email_already_exists: false,
throttled: false,
user_id: 'anonymous-uuid',
}
submit_form = subject.submit(
email: '[email protected]',
terms_accepted: '1',
email_language: '01234567890'
)

expect(submit_form.success?).to eq false
expect(submit_form.extra).to eq extra
expect(submit_form.errors).to eq errors
end
end
end
end

0 comments on commit 5cc7369

Please sign in to comment.