File tree 3 files changed +12
-6
lines changed
lib/validates_email_format_of
3 files changed +12
-6
lines changed Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ module ActiveModel
9
9
module Validations
10
10
class EmailFormatValidator < EachValidator
11
11
def validate_each ( record , attribute , value )
12
- ( ValidatesEmailFormatOf . validate_email_format ( value , options . merge ( generate_message : true ) ) || [ ] ) . each do |error |
12
+ ( ValidatesEmailFormatOf . validate_email_format ( value , options ) || [ ] ) . each do |error |
13
13
record . errors . add ( attribute , error )
14
14
end
15
15
end
Original file line number Diff line number Diff line change 4
4
require "byebug"
5
5
6
6
RSpec ::Matchers . define :have_errors_on_email do
7
- match do |actual |
7
+ match do |user |
8
+ actual = user . errors . full_messages
9
+ expect ( user . errors . added? ( :email , ValidatesEmailFormatOf ::ERROR_MESSAGE_I18N_KEY ) )
8
10
expect ( actual ) . not_to be_nil , "#{ actual } should not be nil"
9
11
expect ( actual ) . not_to be_empty , "#{ actual } should not be empty"
10
12
expect ( actual . size ) . to eq ( @reasons . size ) , "#{ actual } should have #{ @reasons . size } elements"
19
21
chain :and_because do |reason |
20
22
( @reasons ||= [ ] ) << reason
21
23
end
22
- match_when_negated do |actual |
23
- expect ( actual ) . to ( be_empty )
24
+ match_when_negated do |user |
25
+ expect ( user . errors ) . to ( be_empty )
24
26
end
25
27
end
Original file line number Diff line number Diff line change @@ -22,7 +22,7 @@ def self.model_name
22
22
ActiveModel ::Name . new ( self , nil , "User" )
23
23
end
24
24
end
25
- user . new ( example . example_group_instance . email ) . tap ( &:valid? ) . errors . full_messages
25
+ user . new ( example . example_group_instance . email ) . tap ( &:valid? )
26
26
end
27
27
let ( :options ) { { } }
28
28
let ( :email ) { |example | example . example_group . description }
@@ -248,13 +248,17 @@ def self.model_name
248
248
let ( :mx_record ) { [ ] }
249
249
describe email do
250
250
it { should have_errors_on_email . because ( "is not routable" ) }
251
+ it "adds the i18n key" do
252
+ subject . errors . added? ( :email , ValidatesEmailFormatOf ::ERROR_MX_MESSAGE_I18N_KEY )
253
+ end
251
254
end
252
255
describe "with a custom error message" do
253
256
let ( :options ) { { check_mx : true , mx_message : "There ain't no such domain!" } }
254
257
describe email do
255
258
it { should have_errors_on_email . because ( "There ain't no such domain!" ) }
256
259
end
257
260
end
261
+
258
262
describe "i18n" do
259
263
before ( :each ) do
260
264
allow ( I18n . config ) . to receive ( :locale ) . and_return ( locale )
@@ -383,7 +387,7 @@ def self.model_name
383
387
ActiveModel ::Name . new ( self , nil , "User" )
384
388
end
385
389
end
386
- user . new ( example . example_group_instance . email ) . tap ( &:valid? ) . errors . full_messages
390
+ user . new ( example . example_group_instance . email ) . tap ( &:valid? )
387
391
end
388
392
389
393
it_should_behave_like :all_specs
You can’t perform that action at this time.
0 commit comments