valid_email2 5.0.5 → 5.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 521793d68b526dfac3faf2966f62eefe5b78ccb021c004f7b2157448a1f7b81d
4
- data.tar.gz: 761ca49f96808213830e62c2bf7d61db39edb5457498c6e9192abd20063e6dfe
3
+ metadata.gz: ca51b0f797d9251b8a850e2d55640ea0c278128f29ebed57b8d1e0d426393b0f
4
+ data.tar.gz: e3d180928ccea8db43191a40df53c0b2f8a226452b30fa55e8ed3d4a32c39186
5
5
  SHA512:
6
- metadata.gz: e8fa138e0cf2474732b12b8dde26d8d1e7d1ebf24dd3984acbf94e163ad131b4a09dfa06e316e9d93e6e2758badc63d05bb792ca255f23b6b880239dd7cde2ca
7
- data.tar.gz: 53fc5f63e4832f6b025c7fd74c9bd14be9ab0a5eadac087d1cc020e5d7c5807e9f336d91f86dc5b7fe435520e70fdc77d2b477c60d51e25287ce7925b7b4aff0
6
+ metadata.gz: b0cdb4311843b16ee38ab13c774c8f9f4e75c6e208f2feca5e143d8abf465bfb29d0e6bf314e0789d18178620bac7c96c17c06fb61c5d4a32b5157ac8a584cf4
7
+ data.tar.gz: 3c8fc7f7ae71dcb32f290254678d98f1d15151c60ee15602d82765947faae76466609ac483c910f8ce0a3f403eaaab8126abf001b00311c2556ae58d40bbcb66
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## Version 5.1.0
2
+ * Allow dynamic validaton error messages [#221](https://github.com/micke/valid_email2/pull/221)
3
+
1
4
  ## Version 5.0.5
2
5
  * Remove false positive duck.com
3
6
 
@@ -66,7 +66,9 @@ module ValidEmail2
66
66
  end
67
67
 
68
68
  def error(record, attribute)
69
- record.errors.add(attribute, options[:message] || :invalid)
69
+ message = options[:message].respond_to?(:call) ? options[:message].call : options[:message]
70
+
71
+ record.errors.add(attribute, message || :invalid)
70
72
  end
71
73
  end
72
74
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal:true
2
2
 
3
3
  module ValidEmail2
4
- VERSION = "5.0.5"
4
+ VERSION = "5.1.0"
5
5
  end
@@ -47,6 +47,14 @@ class TestUserMessage < TestModel
47
47
  validates :email, 'valid_email_2/email': { message: "custom message" }
48
48
  end
49
49
 
50
+ class TestUserMessageWithLambda < TestModel
51
+ validates :email, 'valid_email_2/email': { message: -> { "custom message lambda" } }
52
+ end
53
+
54
+ class TestUserMessageWithProc < TestModel
55
+ validates :email, 'valid_email_2/email': { message: Proc.new { "custom message proc" } }
56
+ end
57
+
50
58
  class TestUserMultiple < TestModel
51
59
  validates :email, 'valid_email_2/email': { multiple: true }
52
60
  end
@@ -188,11 +196,11 @@ describe ValidEmail2 do
188
196
  let(:whitelist_domain) { disposable_domain }
189
197
  let(:whitelist_file_path) { "config/whitelisted_email_domains.yml" }
190
198
 
191
- # Some of the specs below need to explictly set the whitelist var or it
199
+ # Some of the specs below need to explictly set the whitelist var or it
192
200
  # may be cached to an empty set
193
201
  def set_whitelist
194
202
  ValidEmail2.instance_variable_set(
195
- :@whitelist,
203
+ :@whitelist,
196
204
  ValidEmail2.send(:load_if_exists, ValidEmail2::WHITELIST_FILE)
197
205
  )
198
206
  end
@@ -308,11 +316,29 @@ describe ValidEmail2 do
308
316
  end
309
317
  end
310
318
 
311
- describe "with custom error message" do
312
- it "supports settings a custom error message" do
313
- user = TestUserMessage.new(email: "fakeemail")
314
- user.valid?
315
- expect(user.errors.full_messages).to include("Email custom message")
319
+ context "when message is present" do
320
+ describe "with custom error message" do
321
+ it "supports settings a custom error message" do
322
+ user = TestUserMessage.new(email: "fakeemail")
323
+ user.valid?
324
+ expect(user.errors.full_messages).to include("Email custom message")
325
+ end
326
+ end
327
+
328
+ describe "with custom error message lambda" do
329
+ it "supports settings a custom error message lambda" do
330
+ user = TestUserMessageWithLambda.new(email: "fakeemail")
331
+ user.valid?
332
+ expect(user.errors.full_messages).to include("Email custom message lambda")
333
+ end
334
+ end
335
+
336
+ describe "with custom error message proc" do
337
+ it "supports settings a custom error message proc" do
338
+ user = TestUserMessageWithProc.new(email: "fakeemail")
339
+ user.valid?
340
+ expect(user.errors.full_messages).to include("Email custom message proc")
341
+ end
316
342
  end
317
343
  end
318
344
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: valid_email2
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.5
4
+ version: 5.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Micke Lisinge
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-09-30 00:00:00.000000000 Z
11
+ date: 2023-10-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler