bookland 3.2.0 → 3.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/bookland/validators.rb +3 -2
- data/lib/bookland/version.rb +1 -1
- data/test/validators_test.rb +21 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6fb91e00c5bb23802dd09d5e3e0b5413d3b22135
|
4
|
+
data.tar.gz: c17a294ae6804e1a7a91130753fa4e03128e3f6c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aa0aa72c2402d39ff0ff1c75f15ab3d5d955e1666f150c2f897fb933d13d3437a50dab2ac1f12f648e420135b98a58737954198fac9a373e42671ea4fa55aaef
|
7
|
+
data.tar.gz: 508d0a310a0948b54fda5025d195ca287db5661414ba7fccff29cc0fe93356258723894c151f58ccb12f2e047f392f52e02eeeba68398ff5cea59600dd07041f
|
data/lib/bookland/validators.rb
CHANGED
@@ -5,10 +5,11 @@
|
|
5
5
|
return if value.nil? && options[:allow_nil]
|
6
6
|
|
7
7
|
unless Bookland::#{klass}.valid?(value)
|
8
|
+
message = "is not an #{klass}"
|
8
9
|
if options[:strict]
|
9
|
-
raise ActiveModel::StrictValidationFailed, "\#{value} \#{
|
10
|
+
raise ActiveModel::StrictValidationFailed, "\#{value} \#{message}"
|
10
11
|
else
|
11
|
-
record.errors[attribute] <<
|
12
|
+
record.errors[attribute] << message
|
12
13
|
end
|
13
14
|
end
|
14
15
|
end
|
data/lib/bookland/version.rb
CHANGED
data/test/validators_test.rb
CHANGED
@@ -27,6 +27,13 @@ class TestValidators < MiniTest::Unit::TestCase
|
|
27
27
|
assert instance.valid?
|
28
28
|
end
|
29
29
|
|
30
|
+
def test_validates_asin_with_message
|
31
|
+
@klass.validates(:attribute, asin: true)#, { message: 'is bad' })
|
32
|
+
instance = @klass.new(attribute: '123')
|
33
|
+
instance.valid?
|
34
|
+
assert_includes instance.errors.first, 'is not an ASIN'
|
35
|
+
end
|
36
|
+
|
30
37
|
def test_validates_asin_strictly
|
31
38
|
@klass.validates!(:attribute, asin: true)
|
32
39
|
instance = @klass.new(attribute: '0262011530')
|
@@ -52,6 +59,13 @@ class TestValidators < MiniTest::Unit::TestCase
|
|
52
59
|
assert instance.valid?
|
53
60
|
end
|
54
61
|
|
62
|
+
def test_validates_ean_with_message
|
63
|
+
@klass.validates(:attribute, ean: true)#, { message: 'is bad' })
|
64
|
+
instance = @klass.new(attribute: '123')
|
65
|
+
instance.valid?
|
66
|
+
assert_includes instance.errors.first, 'is not an EAN'
|
67
|
+
end
|
68
|
+
|
55
69
|
def test_validates_ean_strictly
|
56
70
|
@klass.validates!(:attribute, ean: true)
|
57
71
|
instance = @klass.new(attribute: '0814916013890')
|
@@ -76,6 +90,13 @@ class TestValidators < MiniTest::Unit::TestCase
|
|
76
90
|
assert instance.valid?
|
77
91
|
end
|
78
92
|
|
93
|
+
def test_validates_isbn_with_message
|
94
|
+
@klass.validates(:attribute, isbn: true)#, { message: 'is bad' })
|
95
|
+
instance = @klass.new(attribute: '123')
|
96
|
+
instance.valid?
|
97
|
+
assert_includes instance.errors.first, 'is not an ISBN'
|
98
|
+
end
|
99
|
+
|
79
100
|
def test_validates_isbn_strictly
|
80
101
|
@klass.validates!(:attribute, isbn: true)
|
81
102
|
instance = @klass.new(attribute: '9780262011532')
|