activevalidators 3.0.0 → 3.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 50acb6e676e5e32669572b48f94484fedef7fb82
4
- data.tar.gz: ebef42c4c60c751e58305630094717d65e249930
3
+ metadata.gz: adf039c3ae7e345db0269ff8495f4125dabb9816
4
+ data.tar.gz: 9fd34dd568a845762a29134badb745a48bc6e0b3
5
5
  SHA512:
6
- metadata.gz: 2e1223d430d4cde1ef2918f77d22373e45f6652e8a12262e88678357faf6a90a1afe19958603fa18a597e8a2fc08e53f8615cdc3a1462324496fbed6a796e7a4
7
- data.tar.gz: 4564020ef5cf74254bed1a98b25028c1cd8001b3d7432a15787402cab83e57886dc42c69b9367c14873a5b8146c7454eb986b4ef325b006777741e305d07fc58
6
+ metadata.gz: bcc06c8016bd48391ca41556b371a88630694d0f7372455cfa9d25871aa4b64e3723c2a3658a4db4cdbe2ea0f07f2ac4adb84a4b196be45a4f465b94eb6805f0
7
+ data.tar.gz: 0c232fbf6d0dbb28e93663266ba400753397a86be0fa350df708fa4280763185a7fe1e52d225c89d0fa202e69adb398745feb0a65303c728ccb3718b8fe2f63b
data/ChangeLog.md CHANGED
@@ -1,8 +1,15 @@
1
- # UNRELEASED (3.0.1)
1
+ # UNRELEASED
2
+
3
+ * Nothing yet.
4
+
5
+ # 3.1.0
2
6
 
3
7
  ## FEATURES
4
8
 
5
9
  * Remove default requiring
10
+ * Remove deprecation messages about `ActiveValidators.activate`
11
+
12
+ # 3.0.1 (yanked, it's now 3.1.0)
6
13
 
7
14
  # 3.0.0
8
15
 
data/README.md CHANGED
@@ -10,6 +10,10 @@ ActiveValidators is a collection of off-the-shelf and tested ActiveModel/ActiveR
10
10
 
11
11
  This projects follows [Semantic Versioning a.k.a SemVer](http://semver.org). If you use Bundler, you can use the stabby specifier `~>` safely.
12
12
 
13
+ What it means is that you should specify an ActiveValidators version like this :
14
+
15
+ gem 'activevalidators', '~> 3.0.0' # <-- mind the patch version
16
+
13
17
  Once you have `require`'d the gem, you will have to activate the validators you
14
18
  want to use as ActiveValidators doesn't force you to use them all :
15
19
 
@@ -95,7 +99,7 @@ Exhaustive list of supported validators and their implementation:
95
99
  * `tracking_number`: based on a set of predefined masks
96
100
  * `twitter` : based on a regular expression
97
101
  * `url` : based on a regular expression
98
- * `barcode` : based on known formats (default: EAN 13)
102
+ * `barcode` : based on known formats (:ean13 only for now)
99
103
 
100
104
  ## Todo
101
105
 
@@ -1,7 +1,7 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  Gem::Specification.new do |s|
3
3
  s.name = 'activevalidators'
4
- s.version = '3.0.0'
4
+ s.version = '3.1.1'
5
5
  s.platform = Gem::Platform::RUBY
6
6
  s.authors = ['Franck Verrot', 'Paco Guzmán', 'Oriol Gual', 'Garrett Bjerkhoel', 'Renato Riccieri Santos Zannon', 'Brian Moseley', 'Serj L aka Loremaster']
7
7
  s.email = ['franck@verrot.fr']
@@ -21,19 +21,4 @@ Gem::Specification.new do |s|
21
21
 
22
22
  s.files = `git ls-files`.split("\n")
23
23
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
24
-
25
- s.post_install_message = """
26
- ######################################################################
27
- # ActiveValidators v3.0.0 #
28
- ######################################################################
29
- # #
30
- # Version 3 of ActiveValidators stopped requiring all the validators #
31
- # for you. So you will have to use `ActiveValidators.activate`. #
32
- # #
33
- # By default, v3.0.0 does `ActiveValidators.activate(:all)` to help #
34
- # transitioning to v3, but 3.0.1 won't do that anymore. #
35
- # #
36
- # Thanks for using ActiveValidators ! #
37
- # #
38
- ######################################################################"""
39
24
  end
@@ -1,11 +1,17 @@
1
1
  module ActiveModel
2
2
  module Validations
3
3
  class BarcodeValidator < EachValidator
4
- def validate_each(record, attribute, value)
5
- # EAN13 by default
6
- format = options.fetch(:format, :ean13)
4
+ # We check the validity of :format option
5
+ # More at https://github.com/rails/rails/blob/aa7fdfb859d8a73f58460a7aba7174a47b5101d5/activemodel/lib/active_model/validator.rb#L180
6
+ def check_validity!
7
+ format = options.fetch(:format)
8
+ raise ArgumentError, ":format cannot be blank!" if format.blank?
7
9
  method = "valid_#{format.to_s}?"
8
- raise "Barcode format not supported (#{format})" unless self.respond_to?(method)
10
+ raise ArgumentError, "Barcode format (#{format}) not supported" unless self.respond_to?(method)
11
+ end
12
+
13
+ def validate_each(record, attribute, value)
14
+ method = "valid_#{options[:format].to_s}?"
9
15
  record.errors.add(attribute) if value.blank? || !self.send(method, value)
10
16
  end
11
17
 
@@ -30,6 +30,3 @@ module ActiveValidators
30
30
  end
31
31
  end
32
32
  end
33
-
34
- # Deprecated
35
- warn "[deprecated] ActiveValidators.activate is the recommended solution to require your validators. Please check instructions in the README. Thanks a lot !"
@@ -22,7 +22,7 @@ describe "Barcode Validation" do
22
22
  subject.errors.size.must_equal 1
23
23
  end
24
24
 
25
- it "rejects EAN13S with invalid format" do
25
+ it "rejects EAN13s with invalid value (not only integers)" do
26
26
  subject = build_barcode_record :ean13, :barcode => "502392de872e4"
27
27
  subject.valid?.must_equal false
28
28
  subject.errors.size.must_equal 1
@@ -30,6 +30,22 @@ describe "Barcode Validation" do
30
30
  end
31
31
  end
32
32
 
33
+ describe "Invalid options given to the validator" do
34
+ it "raises an error when format is not supported" do
35
+ error = assert_raises ArgumentError do
36
+ build_barcode_record :format_not_supported, :barcode => "9782940199617"
37
+ end
38
+ error.message.must_equal "Barcode format (format_not_supported) not supported"
39
+ end
40
+
41
+ it "raises an error when you omit format option" do
42
+ error = assert_raises ArgumentError do
43
+ build_barcode_record nil, :barcode => "9782940199617"
44
+ end
45
+ error.message.must_equal ":format cannot be blank!"
46
+ end
47
+ end
48
+
33
49
  def build_barcode_record(type, attrs = {})
34
50
  TestRecord.reset_callbacks(:validate)
35
51
  TestRecord.validates :barcode, :barcode => { :format => type }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activevalidators
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 3.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Franck Verrot
@@ -185,21 +185,7 @@ homepage: http://github.com/franckverrot/activevalidators
185
185
  licenses:
186
186
  - MIT
187
187
  metadata: {}
188
- post_install_message: |2-
189
-
190
- ######################################################################
191
- # ActiveValidators v3.0.0 #
192
- ######################################################################
193
- # #
194
- # Version 3 of ActiveValidators stopped requiring all the validators #
195
- # for you. So you will have to use `ActiveValidators.activate`. #
196
- # #
197
- # By default, v3.0.0 does `ActiveValidators.activate(:all)` to help #
198
- # transitioning to v3, but 3.0.1 won't do that anymore. #
199
- # #
200
- # Thanks for using ActiveValidators ! #
201
- # #
202
- ######################################################################
188
+ post_install_message:
203
189
  rdoc_options: []
204
190
  require_paths:
205
191
  - lib