whyvalidationssuckin96 1.6.1 → 1.6.2
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.
- data/VERSION +1 -1
- data/lib/whyvalidationssuckin96/macros/validates_date.rb +1 -0
- data/lib/whyvalidationssuckin96/validation_support.rb +1 -1
- data/lib/whyvalidationssuckin96/vendor/rfc822.rb +3 -2
- data/test/macros/validates_acceptance_test.rb +1 -1
- data/test/macros/validates_associated_test.rb +1 -1
- data/test/macros/validates_confirmation_test.rb +1 -1
- data/test/macros/validates_date_test.rb +1 -1
- data/test/macros/validates_email_test.rb +1 -1
- data/test/macros/validates_exclusion_test.rb +1 -1
- data/test/macros/validates_format_test.rb +1 -1
- data/test/macros/validates_inclusion_test.rb +1 -1
- data/test/macros/validates_length_test.rb +1 -1
- data/test/macros/validates_numericality_test.rb +29 -29
- data/test/macros/validates_presence_test.rb +1 -1
- data/test/macros/validates_url_test.rb +1 -1
- data/test/rails/association_validation_test.rb +37 -24
- data/test/rails/macros/validates_uniqueness_test.rb +33 -25
- data/test/validation_test.rb +1 -1
- data/whyvalidationssuckin96.gemspec +3 -3
- metadata +32 -17
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.6.
|
1
|
+
1.6.2
|
@@ -88,7 +88,7 @@ module WhyValidationsSuckIn96
|
|
88
88
|
if defined?(@run_with_generic_callbacks)
|
89
89
|
@run_with_generic_callbacks
|
90
90
|
else
|
91
|
-
@run_with_generic_callbacks = public_instance_methods.
|
91
|
+
@run_with_generic_callbacks = !public_instance_methods.grep(/run_callbacks/).empty?
|
92
92
|
end
|
93
93
|
end
|
94
94
|
|
@@ -1,7 +1,8 @@
|
|
1
|
+
# encoding: binary
|
1
2
|
#
|
2
3
|
# RFC822 Email Address Regex
|
3
4
|
# --------------------------
|
4
|
-
#
|
5
|
+
#
|
5
6
|
# Originally written by Cal Henderson
|
6
7
|
# c.f. http://iamcal.com/publish/articles/php/parsing_email/
|
7
8
|
#
|
@@ -9,7 +10,7 @@
|
|
9
10
|
#
|
10
11
|
# Licensed under a Creative Commons Attribution-ShareAlike 2.5 License
|
11
12
|
# http://creativecommons.org/licenses/by-sa/2.5/
|
12
|
-
#
|
13
|
+
#
|
13
14
|
module WhyValidationsSuckIn96
|
14
15
|
module RFC822
|
15
16
|
EmailAddress = begin
|
@@ -3,7 +3,7 @@ require 'teststrap'
|
|
3
3
|
context "validates acceptance" do
|
4
4
|
|
5
5
|
should "add a validation macro" do
|
6
|
-
WhyValidationsSuckIn96::ValidationBuilder.instance_methods
|
6
|
+
WhyValidationsSuckIn96::ValidationBuilder.instance_methods.map {|im| im.to_s}
|
7
7
|
end.includes('validates_acceptance_of')
|
8
8
|
|
9
9
|
context "with some default options" do
|
@@ -3,7 +3,7 @@ require 'teststrap'
|
|
3
3
|
context "validates associated" do
|
4
4
|
|
5
5
|
should "add a validation macro" do
|
6
|
-
WhyValidationsSuckIn96::ValidationBuilder.instance_methods
|
6
|
+
WhyValidationsSuckIn96::ValidationBuilder.instance_methods.map {|im| im.to_s}
|
7
7
|
end.includes('validates_associated')
|
8
8
|
|
9
9
|
context "with some default options" do
|
@@ -3,7 +3,7 @@ require 'teststrap'
|
|
3
3
|
context "validates confirmation" do
|
4
4
|
|
5
5
|
should "add a validation macro" do
|
6
|
-
WhyValidationsSuckIn96::ValidationBuilder.instance_methods
|
6
|
+
WhyValidationsSuckIn96::ValidationBuilder.instance_methods.map {|im| im.to_s}
|
7
7
|
end.includes('validates_confirmation_of')
|
8
8
|
|
9
9
|
context "with some default options" do
|
@@ -3,7 +3,7 @@ require 'teststrap'
|
|
3
3
|
context "validates date" do
|
4
4
|
|
5
5
|
should "add a validation macro" do
|
6
|
-
WhyValidationsSuckIn96::ValidationBuilder.instance_methods
|
6
|
+
WhyValidationsSuckIn96::ValidationBuilder.instance_methods.map {|im| im.to_s}
|
7
7
|
end.includes('validates_as_date')
|
8
8
|
|
9
9
|
context "with some default options" do
|
@@ -3,7 +3,7 @@ require 'teststrap'
|
|
3
3
|
context "validates email" do
|
4
4
|
|
5
5
|
should "add a validation macro" do
|
6
|
-
WhyValidationsSuckIn96::ValidationBuilder.instance_methods
|
6
|
+
WhyValidationsSuckIn96::ValidationBuilder.instance_methods.map {|im| im.to_s}
|
7
7
|
end.includes('validates_as_email')
|
8
8
|
|
9
9
|
context "with some default options" do
|
@@ -3,7 +3,7 @@ require 'teststrap'
|
|
3
3
|
context "validates exclusion" do
|
4
4
|
|
5
5
|
should "add a validation macro" do
|
6
|
-
WhyValidationsSuckIn96::ValidationBuilder.instance_methods
|
6
|
+
WhyValidationsSuckIn96::ValidationBuilder.instance_methods.map {|im| im.to_s}
|
7
7
|
end.includes('validates_exclusion_of')
|
8
8
|
|
9
9
|
should "raise if an :in option is not given" do
|
@@ -3,7 +3,7 @@ require 'teststrap'
|
|
3
3
|
context "validates format" do
|
4
4
|
|
5
5
|
should "add a validation macro" do
|
6
|
-
WhyValidationsSuckIn96::ValidationBuilder.instance_methods
|
6
|
+
WhyValidationsSuckIn96::ValidationBuilder.instance_methods.map {|im| im.to_s}
|
7
7
|
end.includes('validates_format_of')
|
8
8
|
|
9
9
|
should "raise if a :with option is not given" do
|
@@ -3,7 +3,7 @@ require 'teststrap'
|
|
3
3
|
context "validates inclusion" do
|
4
4
|
|
5
5
|
should "add a validation macro" do
|
6
|
-
WhyValidationsSuckIn96::ValidationBuilder.instance_methods
|
6
|
+
WhyValidationsSuckIn96::ValidationBuilder.instance_methods.map {|im| im.to_s}
|
7
7
|
end.includes('validates_inclusion_of')
|
8
8
|
|
9
9
|
should "raise if an :in option is not given" do
|
@@ -3,7 +3,7 @@ require 'teststrap'
|
|
3
3
|
context "validates length" do
|
4
4
|
|
5
5
|
should "add a validation macro" do
|
6
|
-
WhyValidationsSuckIn96::ValidationBuilder.instance_methods
|
6
|
+
WhyValidationsSuckIn96::ValidationBuilder.instance_methods.map {|im| im.to_s}
|
7
7
|
end.includes('validates_length_of')
|
8
8
|
|
9
9
|
should "raise if an no options are given" do
|
@@ -1,115 +1,115 @@
|
|
1
1
|
require 'teststrap'
|
2
2
|
|
3
3
|
context "validates numericality" do
|
4
|
-
|
4
|
+
|
5
5
|
should "add a validation macro" do
|
6
|
-
WhyValidationsSuckIn96::ValidationBuilder.instance_methods
|
6
|
+
WhyValidationsSuckIn96::ValidationBuilder.instance_methods.map {|im| im.to_s}
|
7
7
|
end.includes('validates_numericality_of')
|
8
|
-
|
8
|
+
|
9
9
|
context "with some default options" do
|
10
10
|
setup do
|
11
11
|
WhyValidationsSuckIn96::ValidatesNumericality.new(Object.new, :attribute => :number)
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
should "have a message accessor with a default message" do
|
15
15
|
topic.message
|
16
16
|
end.equals("is not a numerical value")
|
17
17
|
end # with some default options
|
18
|
-
|
18
|
+
|
19
19
|
context "validating an object" do
|
20
|
-
|
20
|
+
|
21
21
|
context "with the default option of :only_integer being false" do
|
22
22
|
validatable = OpenStruct.new(:number => 123)
|
23
|
-
|
23
|
+
|
24
24
|
setup do
|
25
25
|
WhyValidationsSuckIn96::ValidatesNumericality.new(validatable, :attribute => :number)
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
28
|
should "pass for an actual integer" do
|
29
29
|
validatable.number = 30000
|
30
30
|
topic.validates?
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
should "pass for a regular old integer string" do
|
34
34
|
validatable.number = "123"
|
35
35
|
topic.validates?
|
36
36
|
end
|
37
|
-
|
37
|
+
|
38
38
|
should "pass for a valid integer with spaces" do
|
39
39
|
validatable.number = "123 456"
|
40
40
|
topic.validates?
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
43
|
should "pass for a valid integer with commas" do
|
44
44
|
validatable.number = "123,456"
|
45
45
|
topic.validates?
|
46
46
|
end
|
47
|
-
|
47
|
+
|
48
48
|
should "pass for a valid integer with a positive sign" do
|
49
49
|
validatable.number = "+1234"
|
50
50
|
topic.validates?
|
51
51
|
end
|
52
|
-
|
52
|
+
|
53
53
|
should "pass for a valid integer with a negative sign" do
|
54
|
-
validatable.number "-1234"
|
54
|
+
validatable.number = "-1234"
|
55
55
|
topic.validates?
|
56
56
|
end
|
57
|
-
|
57
|
+
|
58
58
|
should "fail for an integer with letters" do
|
59
59
|
validatable.number = "a1234"
|
60
60
|
topic.validates?
|
61
61
|
end.equals(false)
|
62
|
-
|
62
|
+
|
63
63
|
should "fail for an integer with other punctuation" do
|
64
64
|
validatable.number = "!1234"
|
65
65
|
topic.validates?
|
66
66
|
end.equals(false)
|
67
|
-
|
67
|
+
|
68
68
|
should "pass for an actual float" do
|
69
69
|
validatable.number = 123.45
|
70
70
|
topic.validates?
|
71
71
|
end
|
72
|
-
|
72
|
+
|
73
73
|
should "pass for a regular old float" do
|
74
74
|
validatable.number = "123.456"
|
75
75
|
topic.validates?
|
76
76
|
end
|
77
|
-
|
77
|
+
|
78
78
|
should "pass for a valid float with spaces" do
|
79
79
|
validatable.number = "123 456.10"
|
80
80
|
topic.validates?
|
81
81
|
end
|
82
|
-
|
82
|
+
|
83
83
|
should "pass for a valid float with commas" do
|
84
84
|
validatable.number = "123,456.10"
|
85
85
|
topic.validates?
|
86
86
|
end
|
87
|
-
|
87
|
+
|
88
88
|
should "pass for a valid float with a positive sign" do
|
89
89
|
validatable.number = "+123456.10"
|
90
90
|
topic.validates?
|
91
91
|
end
|
92
|
-
|
92
|
+
|
93
93
|
should "pass for a valid float with a negative sign" do
|
94
94
|
validatable.number = "-123456.10"
|
95
95
|
topic.validates?
|
96
96
|
end
|
97
|
-
|
97
|
+
|
98
98
|
should "fail for a float with letters other than the exponent" do
|
99
99
|
validatable.number = "123z456.10"
|
100
100
|
topic.validates?
|
101
101
|
end.equals(false)
|
102
|
-
|
102
|
+
|
103
103
|
should "fail for a float with other punctuation" do
|
104
104
|
validatable.number = "$123456.10"
|
105
105
|
topic.validates?
|
106
106
|
end.equals(false)
|
107
|
-
|
107
|
+
|
108
108
|
end # with the default option of :only_integer being false
|
109
|
-
|
109
|
+
|
110
110
|
context "with the :only_integer option being true" do
|
111
111
|
validatable = OpenStruct.new(:number => 123)
|
112
|
-
|
112
|
+
|
113
113
|
setup do
|
114
114
|
WhyValidationsSuckIn96::ValidatesNumericality.new(validatable, :attribute => :number, :only_integer => true)
|
115
115
|
end
|
@@ -118,12 +118,12 @@ context "validates numericality" do
|
|
118
118
|
validatable.number = 123.456
|
119
119
|
topic.validates?
|
120
120
|
end.equals(false)
|
121
|
-
|
121
|
+
|
122
122
|
should "allow integer values" do
|
123
123
|
validatable.number = 123
|
124
124
|
topic.validates?
|
125
125
|
end
|
126
|
-
|
126
|
+
|
127
127
|
end # with the :only_integer option being true
|
128
128
|
end # validating an object
|
129
129
|
end # validates numericality
|
@@ -3,7 +3,7 @@ require 'teststrap'
|
|
3
3
|
context "validates presence" do
|
4
4
|
|
5
5
|
should "add a validation macro" do
|
6
|
-
WhyValidationsSuckIn96::ValidationBuilder.instance_methods
|
6
|
+
WhyValidationsSuckIn96::ValidationBuilder.instance_methods.map {|im| im.to_s}
|
7
7
|
end.includes('validates_presence_of')
|
8
8
|
|
9
9
|
context "validating an object" do
|
@@ -3,7 +3,7 @@ require 'teststrap'
|
|
3
3
|
context "validates url" do
|
4
4
|
|
5
5
|
should "add a validation macro" do
|
6
|
-
WhyValidationsSuckIn96::ValidationBuilder.instance_methods
|
6
|
+
WhyValidationsSuckIn96::ValidationBuilder.instance_methods.map {|im| im.to_s}
|
7
7
|
end.includes('validates_as_url')
|
8
8
|
|
9
9
|
context "with some default options" do
|
@@ -7,105 +7,118 @@ context "association validation" do
|
|
7
7
|
validation_klass == WhyValidationsSuckIn96::ValidatesAssociated && opts[:attribute] == assoc && opts[:on] == :save
|
8
8
|
end.nil?
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
|
+
teardown do
|
12
|
+
next unless topic.kind_of?(Class)
|
13
|
+
Object.send(:remove_const, topic.name)
|
14
|
+
end
|
15
|
+
|
11
16
|
context "against has_many" do
|
12
17
|
context "with :validate set to true" do
|
13
18
|
setup do
|
14
|
-
|
19
|
+
class ::TestBook < Book
|
15
20
|
has_many :chapters, :validate => true
|
21
|
+
self
|
16
22
|
end
|
17
23
|
end
|
18
|
-
|
24
|
+
|
19
25
|
should "set up an association validation" do
|
20
26
|
has_association_validation[topic, :chapters]
|
21
27
|
end
|
22
28
|
end # with :validate set to true
|
23
|
-
|
29
|
+
|
24
30
|
context "with :validate set to false" do
|
25
31
|
setup do
|
26
|
-
|
32
|
+
class ::TestBook < Book
|
27
33
|
has_many :chapters, :validate => false
|
34
|
+
self
|
28
35
|
end
|
29
36
|
end
|
30
|
-
|
37
|
+
|
31
38
|
should "not set up an association validation" do
|
32
39
|
has_association_validation[topic, :chapters]
|
33
40
|
end.equals(false)
|
34
41
|
end # with :validate set to false
|
35
42
|
end # against has_many
|
36
|
-
|
43
|
+
|
37
44
|
context "against has_and_belongs_to_many" do
|
38
45
|
context "with :validate set to true" do
|
39
46
|
setup do
|
40
|
-
|
47
|
+
class ::TestGenre < Genre
|
41
48
|
has_and_belongs_to_many :books, :validate => true
|
49
|
+
self
|
42
50
|
end
|
43
51
|
end
|
44
|
-
|
52
|
+
|
45
53
|
should "set up an association validation" do
|
46
54
|
has_association_validation[topic, :books]
|
47
55
|
end
|
48
56
|
end # with :validate set to true
|
49
|
-
|
57
|
+
|
50
58
|
context "with :validate set to false" do
|
51
59
|
setup do
|
52
|
-
|
60
|
+
class ::TestGenre < Genre
|
53
61
|
has_and_belongs_to_many :books, :validate => false
|
62
|
+
self
|
54
63
|
end
|
55
64
|
end
|
56
|
-
|
65
|
+
|
57
66
|
should "not set up an association validation" do
|
58
67
|
has_association_validation[topic, :books]
|
59
68
|
end.equals(false)
|
60
69
|
end # with :validate set to false
|
61
70
|
end # against has_and_belongs_to_many
|
62
|
-
|
71
|
+
|
63
72
|
context "against has_one" do
|
64
73
|
context "with :validate set to true" do
|
65
74
|
setup do
|
66
|
-
|
75
|
+
class ::TestBook < Book
|
67
76
|
has_one :glossary, :validate => true
|
77
|
+
self
|
68
78
|
end
|
69
79
|
end
|
70
|
-
|
80
|
+
|
71
81
|
should "set up an association validation" do
|
72
82
|
has_association_validation[topic, :glossary]
|
73
83
|
end
|
74
84
|
end # with :validate set to true
|
75
|
-
|
85
|
+
|
76
86
|
context "with :validate set to false" do
|
77
87
|
setup do
|
78
|
-
|
88
|
+
class ::TestBook < Book
|
79
89
|
has_one :glossary, :validate => false
|
90
|
+
self
|
80
91
|
end
|
81
92
|
end
|
82
|
-
|
93
|
+
|
83
94
|
should "not set up an association validation" do
|
84
95
|
has_association_validation[topic, :glossary]
|
85
96
|
end.equals(false)
|
86
97
|
end # with :validate set to false
|
87
98
|
end # against has_one
|
88
|
-
|
99
|
+
|
89
100
|
context "against belongs_to" do
|
90
101
|
context "with :validate set to true" do
|
91
102
|
setup do
|
92
|
-
|
103
|
+
class ::TestChapter < Chapter
|
93
104
|
belongs_to :book, :validate => true
|
105
|
+
self
|
94
106
|
end
|
95
107
|
end
|
96
|
-
|
108
|
+
|
97
109
|
should "set up an association validation" do
|
98
110
|
has_association_validation[topic, :book]
|
99
111
|
end
|
100
112
|
end # with :validate set to true
|
101
|
-
|
113
|
+
|
102
114
|
context "with :validate set to false" do
|
103
115
|
setup do
|
104
|
-
|
116
|
+
class ::TestChapter < Chapter
|
105
117
|
belongs_to :book, :validate => false
|
118
|
+
self
|
106
119
|
end
|
107
120
|
end
|
108
|
-
|
121
|
+
|
109
122
|
should "not set up an association validation" do
|
110
123
|
has_association_validation[topic, :book]
|
111
124
|
end.equals(false)
|
@@ -2,40 +2,46 @@ require 'teststrap'
|
|
2
2
|
require 'rails/active_record_test_helper'
|
3
3
|
|
4
4
|
context "validates uniqueness" do
|
5
|
-
|
5
|
+
|
6
6
|
should "add a validation macro" do
|
7
|
-
WhyValidationsSuckIn96::ValidationBuilder.instance_methods
|
7
|
+
WhyValidationsSuckIn96::ValidationBuilder.instance_methods.map {|im| im.to_s}
|
8
8
|
end.includes('validates_uniqueness_of')
|
9
|
-
|
9
|
+
|
10
10
|
context "with some default options" do
|
11
11
|
setup do
|
12
12
|
WhyValidationsSuckIn96::ValidatesUniqueness.new(Object.new, :attribute => :username)
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
should "have a message accessor with a default message" do
|
16
16
|
topic.message
|
17
17
|
end.equals("has already been taken")
|
18
|
-
|
18
|
+
|
19
19
|
should "default to being case insensitive" do
|
20
20
|
topic.options[:case_sensitive]
|
21
21
|
end.equals(false)
|
22
|
-
|
22
|
+
|
23
23
|
should "default :base_class_scope to true" do
|
24
24
|
topic.options[:base_class_scope]
|
25
25
|
end.equals(true)
|
26
26
|
end # with some default options
|
27
|
-
|
27
|
+
|
28
|
+
teardown do
|
29
|
+
next unless topic.kind_of?(Class)
|
30
|
+
Object.send(:remove_const, topic.name)
|
31
|
+
end
|
32
|
+
|
28
33
|
context "validating an object" do
|
29
|
-
|
34
|
+
|
30
35
|
context "with default options" do
|
31
36
|
setup do
|
32
|
-
|
37
|
+
class ::TestVisualWork < VisualWork
|
33
38
|
setup_validations do
|
34
39
|
validates_uniqueness_of :name
|
35
40
|
end
|
41
|
+
self
|
36
42
|
end # VisualWork
|
37
43
|
end # setup do
|
38
|
-
|
44
|
+
|
39
45
|
should "mark the second object with the same name as invalid" do
|
40
46
|
work = topic.new(:name => "example")
|
41
47
|
work.save!
|
@@ -51,7 +57,7 @@ context "validates uniqueness" do
|
|
51
57
|
other = topic.new(:name => "example two")
|
52
58
|
other.valid?
|
53
59
|
end
|
54
|
-
|
60
|
+
|
55
61
|
should "not care about case sensitivity by default" do
|
56
62
|
work = topic.new(:name => "cAsE SeNsItiViTy")
|
57
63
|
work.save!
|
@@ -60,7 +66,7 @@ context "validates uniqueness" do
|
|
60
66
|
fv.kind_of?(WhyValidationsSuckIn96::ValidatesUniqueness) && fv.attribute == :name
|
61
67
|
end
|
62
68
|
end
|
63
|
-
|
69
|
+
|
64
70
|
should "allow the one object to be saved twice and not violate the constraint" do
|
65
71
|
work = topic.new(:name => "screenshot")
|
66
72
|
work.save
|
@@ -71,10 +77,11 @@ context "validates uniqueness" do
|
|
71
77
|
|
72
78
|
context "uniqueness of integers" do
|
73
79
|
setup do
|
74
|
-
|
80
|
+
class ::TestChapter < Chapter
|
75
81
|
setup_validations do
|
76
82
|
validates_uniqueness_of :number, :scope_to => :book_id
|
77
83
|
end
|
84
|
+
self
|
78
85
|
end
|
79
86
|
end
|
80
87
|
|
@@ -89,22 +96,23 @@ context "validates uniqueness" do
|
|
89
96
|
end
|
90
97
|
end
|
91
98
|
end
|
92
|
-
|
99
|
+
|
93
100
|
context "specifying case sensitivity" do
|
94
101
|
setup do
|
95
|
-
|
102
|
+
class ::TestVisualWork < VisualWork
|
96
103
|
setup_validations do
|
97
104
|
validates_uniqueness_of :name, :case_sensitive => true
|
98
105
|
end
|
106
|
+
self
|
99
107
|
end # VisualWork
|
100
108
|
end # setup do
|
101
|
-
|
109
|
+
|
102
110
|
should "allow objects with the same name and different case to be valid" do
|
103
111
|
work = topic.create!(:name => "CASE SENSITIVE IS TRUE")
|
104
112
|
other_work = topic.new(:name => "case sensitive is true")
|
105
113
|
other_work.valid?
|
106
114
|
end
|
107
|
-
|
115
|
+
|
108
116
|
should "mark the second object with the name in the same case as invalid" do
|
109
117
|
work = topic.create(:name => "SO WHAT")
|
110
118
|
other_work = topic.new(:name => "SO WHAT")
|
@@ -113,14 +121,14 @@ context "validates uniqueness" do
|
|
113
121
|
end
|
114
122
|
end
|
115
123
|
end # specifying case sensitivity
|
116
|
-
|
124
|
+
|
117
125
|
context "specifying base class scope" do
|
118
126
|
context "as false" do
|
119
127
|
should "allow records to be created in different subclasses that violate the uniqueness" do
|
120
128
|
Painting.create!(:name => "painting one", :author => "humbug")
|
121
129
|
Photograph.new(:name => "photo one", :author => "humbug").valid?
|
122
|
-
end
|
123
|
-
|
130
|
+
end
|
131
|
+
|
124
132
|
should "not allow records to be created in the same class that violate the uniqueness" do
|
125
133
|
Photograph.create!(:name => "photo one", :author => "gus")
|
126
134
|
photo = Photograph.new(:name => "photo two", :author => "gus")
|
@@ -129,7 +137,7 @@ context "validates uniqueness" do
|
|
129
137
|
end
|
130
138
|
end
|
131
139
|
end # as false
|
132
|
-
|
140
|
+
|
133
141
|
context "as true" do
|
134
142
|
should "not allow records to be created that violate a uniqueness constraint based on the base class" do
|
135
143
|
VisualWork.create!(:name => "mspaint", :author => "dan")
|
@@ -138,21 +146,21 @@ context "validates uniqueness" do
|
|
138
146
|
fv.kind_of?(WhyValidationsSuckIn96::ValidatesUniqueness) && fv.attribute == :author
|
139
147
|
end
|
140
148
|
end
|
141
|
-
|
149
|
+
|
142
150
|
should "allow records to be created that don't violate the uniqueness constraint" do
|
143
151
|
VisualWork.create!(:name => "photoshop", :author => "alex")
|
144
152
|
Painting.create!(:name => "paintshop", :author => "evan")
|
145
153
|
end
|
146
154
|
end # as true
|
147
155
|
end # specifying base class scope
|
148
|
-
|
156
|
+
|
149
157
|
context "specifying scope options" do
|
150
158
|
should "pass when uniqueness is valid against the given scope column" do
|
151
159
|
Collage.create!(:name => "wired snippets", :author => "dan")
|
152
160
|
work = Collage.new(:name => "wired snippets", :author => "gabe")
|
153
161
|
work.valid?
|
154
162
|
end
|
155
|
-
|
163
|
+
|
156
164
|
should "fail when uniqueness is invalid against the given scope column" do
|
157
165
|
Collage.create!(:name => "rolling stone snippets", :author => "gabe")
|
158
166
|
work = Collage.new(:name => "rolling stone snippets", :author => "gabe")
|
@@ -161,7 +169,7 @@ context "validates uniqueness" do
|
|
161
169
|
end
|
162
170
|
end
|
163
171
|
end # specifying scope options
|
164
|
-
|
172
|
+
|
165
173
|
context "when using with_scope" do
|
166
174
|
should "basically just ignore with_scope" do
|
167
175
|
Painting.create!(:author => "fred", :name => "bbzzzt")
|
data/test/validation_test.rb
CHANGED
@@ -15,7 +15,7 @@ context "validation" do
|
|
15
15
|
end.equals(:validates_rockingness)
|
16
16
|
|
17
17
|
should "define validate as private on the new subclass" do
|
18
|
-
topic.private_instance_methods
|
18
|
+
topic.private_instance_methods.map {|im| im.to_s}
|
19
19
|
end.includes("validate")
|
20
20
|
end # creating a new subclass
|
21
21
|
|
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{whyvalidationssuckin96}
|
8
|
-
s.version = "1.6.
|
8
|
+
s.version = "1.6.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["gabrielg", "douglasmeyer"]
|
12
|
-
s.date = %q{2010-03-
|
12
|
+
s.date = %q{2010-03-17}
|
13
13
|
s.description = %q{A library for setting up model validations, such as in ActiveRecord.}
|
14
14
|
s.email = %q{gabriel.gironda@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -126,7 +126,7 @@ Gem::Specification.new do |s|
|
|
126
126
|
s.homepage = %q{http://github.com/thumblemonks/whyvalidationssuckin96}
|
127
127
|
s.rdoc_options = ["--charset=UTF-8"]
|
128
128
|
s.require_paths = ["lib"]
|
129
|
-
s.rubygems_version = %q{1.3.
|
129
|
+
s.rubygems_version = %q{1.3.6}
|
130
130
|
s.summary = %q{An alternative implementation of object validations.}
|
131
131
|
s.test_files = [
|
132
132
|
"test/attribute_based_validation_test.rb",
|
metadata
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: whyvalidationssuckin96
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 1
|
7
|
+
- 6
|
8
|
+
- 2
|
9
|
+
version: 1.6.2
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- gabrielg
|
@@ -10,39 +15,47 @@ autorequire:
|
|
10
15
|
bindir: bin
|
11
16
|
cert_chain: []
|
12
17
|
|
13
|
-
date: 2010-03-
|
18
|
+
date: 2010-03-17 00:00:00 -05:00
|
14
19
|
default_executable:
|
15
20
|
dependencies:
|
16
21
|
- !ruby/object:Gem::Dependency
|
17
22
|
name: riot
|
18
|
-
|
19
|
-
|
20
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
21
25
|
requirements:
|
22
26
|
- - ">="
|
23
27
|
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 0
|
24
30
|
version: "0"
|
25
|
-
|
31
|
+
type: :development
|
32
|
+
version_requirements: *id001
|
26
33
|
- !ruby/object:Gem::Dependency
|
27
34
|
name: yard
|
28
|
-
|
29
|
-
|
30
|
-
version_requirements: !ruby/object:Gem::Requirement
|
35
|
+
prerelease: false
|
36
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
31
37
|
requirements:
|
32
38
|
- - ">="
|
33
39
|
- !ruby/object:Gem::Version
|
40
|
+
segments:
|
41
|
+
- 0
|
34
42
|
version: "0"
|
35
|
-
|
43
|
+
type: :development
|
44
|
+
version_requirements: *id002
|
36
45
|
- !ruby/object:Gem::Dependency
|
37
46
|
name: activerecord
|
38
|
-
|
39
|
-
|
40
|
-
version_requirements: !ruby/object:Gem::Requirement
|
47
|
+
prerelease: false
|
48
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
41
49
|
requirements:
|
42
50
|
- - ">="
|
43
51
|
- !ruby/object:Gem::Version
|
52
|
+
segments:
|
53
|
+
- 2
|
54
|
+
- 3
|
55
|
+
- 0
|
44
56
|
version: 2.3.0
|
45
|
-
|
57
|
+
type: :development
|
58
|
+
version_requirements: *id003
|
46
59
|
description: A library for setting up model validations, such as in ActiveRecord.
|
47
60
|
email: gabriel.gironda@gmail.com
|
48
61
|
executables: []
|
@@ -171,18 +184,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
171
184
|
requirements:
|
172
185
|
- - ">="
|
173
186
|
- !ruby/object:Gem::Version
|
187
|
+
segments:
|
188
|
+
- 0
|
174
189
|
version: "0"
|
175
|
-
version:
|
176
190
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
177
191
|
requirements:
|
178
192
|
- - ">="
|
179
193
|
- !ruby/object:Gem::Version
|
194
|
+
segments:
|
195
|
+
- 0
|
180
196
|
version: "0"
|
181
|
-
version:
|
182
197
|
requirements: []
|
183
198
|
|
184
199
|
rubyforge_project:
|
185
|
-
rubygems_version: 1.3.
|
200
|
+
rubygems_version: 1.3.6
|
186
201
|
signing_key:
|
187
202
|
specification_version: 3
|
188
203
|
summary: An alternative implementation of object validations.
|