carlosbrando-remarkable 2.2.6 → 2.2.7
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/lib/remarkable/active_record/helpers.rb +30 -23
- data/lib/remarkable/active_record/macros/database/have_db_column_matcher.rb +1 -1
- data/lib/remarkable/active_record/macros/validations/validate_exclusion_of_matcher.rb +19 -3
- data/lib/remarkable/active_record/macros/validations/validate_inclusion_of_matcher.rb +19 -3
- data/lib/remarkable/active_record/macros/validations/validate_length_of_matcher.rb +6 -6
- data/lib/remarkable/active_record/macros/validations/validate_numericality_of_matcher.rb +3 -3
- data/lib/remarkable/active_record/macros/validations/validate_uniqueness_of_matcher.rb +1 -1
- data/lib/remarkable/controller/macros/assign_matcher.rb +1 -1
- data/lib/remarkable/controller/macros/set_session_matcher.rb +2 -2
- data/lib/remarkable/controller/macros.rb +2 -2
- data/lib/remarkable.rb +1 -1
- data/remarkable.gemspec +1 -1
- metadata +1 -1
@@ -52,7 +52,7 @@ module Remarkable # :nodoc:
|
|
52
52
|
# It checks for the key, if it exists and it's true, tests that the value
|
53
53
|
# given is bad, otherwise tests that the value is good.
|
54
54
|
#
|
55
|
-
def assert_bad_or_good_if_key(key, value, missing, message_key = :message
|
55
|
+
def assert_bad_or_good_if_key(key, value, missing, message_key = :message)
|
56
56
|
return true unless @options.key? key
|
57
57
|
|
58
58
|
if @options[key]
|
@@ -70,14 +70,14 @@ module Remarkable # :nodoc:
|
|
70
70
|
# It checks for the key, if it exists and it's true, tests that the value
|
71
71
|
# given is good, otherwise tests that the value is bad.
|
72
72
|
#
|
73
|
-
def assert_good_or_bad_if_key(key, value, missing, message_key = :message
|
73
|
+
def assert_good_or_bad_if_key(key, value, missing, message_key = :message)
|
74
74
|
return true unless @options.key? key
|
75
75
|
|
76
76
|
if @options[key]
|
77
|
-
return true if good?(value, message_key
|
77
|
+
return true if good?(value, message_key)
|
78
78
|
missing = 'not ' + missing
|
79
79
|
else
|
80
|
-
return true if bad?(value, message_key
|
80
|
+
return true if bad?(value, message_key)
|
81
81
|
end
|
82
82
|
|
83
83
|
@missing = missing
|
@@ -89,9 +89,9 @@ module Remarkable # :nodoc:
|
|
89
89
|
# Notice that it checks for @options[:message], so be sure that this option
|
90
90
|
# is properly set.
|
91
91
|
#
|
92
|
-
def allow_nil?(message_key = :message
|
92
|
+
def allow_nil?(message_key = :message)
|
93
93
|
message = "allow #{@attribute} be set to nil"
|
94
|
-
assert_good_or_bad_if_key(:allow_nil, nil, message, message_key
|
94
|
+
assert_good_or_bad_if_key(:allow_nil, nil, message, message_key)
|
95
95
|
end
|
96
96
|
|
97
97
|
# Default allow_blank? validation.
|
@@ -99,25 +99,25 @@ module Remarkable # :nodoc:
|
|
99
99
|
# Notice that it checks for @options[:message], so be sure that this option
|
100
100
|
# is properly set.
|
101
101
|
#
|
102
|
-
def allow_blank?(message_key = :message
|
102
|
+
def allow_blank?(message_key = :message)
|
103
103
|
message = "allow #{@attribute} be set to blank"
|
104
|
-
assert_good_or_bad_if_key(:allow_blank, '', message, message_key
|
104
|
+
assert_good_or_bad_if_key(:allow_blank, '', message, message_key)
|
105
105
|
end
|
106
106
|
|
107
107
|
# Shortcut for assert_good_value.
|
108
108
|
# Please notice that it has instance variables hard coded. So do not use
|
109
109
|
# it if you are trying to assert another instance besides @subject.
|
110
110
|
#
|
111
|
-
def good?(value, message_sym = :message
|
112
|
-
assert_good_value(@subject, @attribute, value, @options[message_sym]
|
111
|
+
def good?(value, message_sym = :message)
|
112
|
+
assert_good_value(@subject, @attribute, value, @options[message_sym])
|
113
113
|
end
|
114
114
|
|
115
115
|
# Shortcut for assert_bad_value.
|
116
116
|
# Please notice that it has instance variables hard coded. So do not use
|
117
117
|
# it if you are trying to assert another instance besides @subject.
|
118
118
|
#
|
119
|
-
def bad?(value, message_sym = :message
|
120
|
-
assert_bad_value(@subject, @attribute, value, @options[message_sym]
|
119
|
+
def bad?(value, message_sym = :message)
|
120
|
+
assert_bad_value(@subject, @attribute, value, @options[message_sym])
|
121
121
|
end
|
122
122
|
|
123
123
|
# Asserts that an Active Record model validates with the passed
|
@@ -137,13 +137,13 @@ module Remarkable # :nodoc:
|
|
137
137
|
# @product = Product.new(:tangible => false)
|
138
138
|
# assert_good_value(Product, :price, "0")
|
139
139
|
#
|
140
|
-
def assert_good_value(object_or_klass, attribute, value, error_message_to_avoid =
|
140
|
+
def assert_good_value(object_or_klass, attribute, value, error_message_to_avoid = //) # :nodoc:
|
141
141
|
object = get_instance_of(object_or_klass)
|
142
142
|
object.send("#{attribute}=", value)
|
143
143
|
|
144
144
|
return true if object.valid?
|
145
145
|
|
146
|
-
error_message_to_avoid = error_message_from_model(object, attribute, error_message_to_avoid
|
146
|
+
error_message_to_avoid = error_message_from_model(object, attribute, error_message_to_avoid)
|
147
147
|
|
148
148
|
assert_does_not_contain(object.errors.on(attribute), error_message_to_avoid)
|
149
149
|
end
|
@@ -165,14 +165,14 @@ module Remarkable # :nodoc:
|
|
165
165
|
# @product = Product.new(:tangible => true)
|
166
166
|
# assert_bad_value(Product, :price, "0")
|
167
167
|
#
|
168
|
-
def assert_bad_value(object_or_klass, attribute, value, error_message_to_expect = :invalid
|
168
|
+
def assert_bad_value(object_or_klass, attribute, value, error_message_to_expect = :invalid) # :nodoc:
|
169
169
|
object = get_instance_of(object_or_klass)
|
170
170
|
object.send("#{attribute}=", value)
|
171
171
|
|
172
172
|
return false if object.valid?
|
173
173
|
return false unless object.errors.on(attribute)
|
174
174
|
|
175
|
-
error_message_to_expect = error_message_from_model(object, attribute, error_message_to_expect
|
175
|
+
error_message_to_expect = error_message_from_model(object, attribute, error_message_to_expect)
|
176
176
|
|
177
177
|
assert_contains(object.errors.on(attribute), error_message_to_expect)
|
178
178
|
end
|
@@ -207,18 +207,25 @@ module Remarkable # :nodoc:
|
|
207
207
|
# Using the underlying mechanism inside ActiveRecord makes us free from
|
208
208
|
# all thos errors.
|
209
209
|
#
|
210
|
-
#
|
210
|
+
# We replace {{count}} interpolation for __count__ which later is
|
211
|
+
# replaced by a regexp which contains \d+.
|
211
212
|
#
|
212
|
-
def error_message_from_model(model, attribute, message
|
213
|
+
def error_message_from_model(model, attribute, message) #:nodoc:
|
213
214
|
if message.is_a? Symbol
|
214
|
-
if Object.const_defined?(:I18n) # Rails >= 2.2
|
215
|
-
model.errors.generate_message(attribute, message, :count =>
|
215
|
+
message = if Object.const_defined?(:I18n) # Rails >= 2.2
|
216
|
+
model.errors.generate_message(attribute, message, :count => '__count__')
|
216
217
|
else # Rails <= 2.1
|
217
|
-
::ActiveRecord::Errors.default_error_messages[message] %
|
218
|
+
::ActiveRecord::Errors.default_error_messages[message] % '__count__'
|
219
|
+
end
|
220
|
+
|
221
|
+
if message =~ /__count__/
|
222
|
+
message = Regexp.escape(message)
|
223
|
+
message.gsub!('__count__', '\d+')
|
224
|
+
message = /#{message}/
|
218
225
|
end
|
219
|
-
else
|
220
|
-
message
|
221
226
|
end
|
227
|
+
|
228
|
+
message
|
222
229
|
end
|
223
230
|
|
224
231
|
end
|
@@ -10,7 +10,7 @@ module Remarkable # :nodoc:
|
|
10
10
|
|
11
11
|
# TODO: remove it
|
12
12
|
def of_type(type)
|
13
|
-
warn "[DEPRECATION] option of_type is deprecated. Use type instead."
|
13
|
+
warn "[DEPRECATION] option of_type is deprecated in have_db_column. Use type instead."
|
14
14
|
@options[:type] = type
|
15
15
|
self
|
16
16
|
end
|
@@ -13,6 +13,7 @@ module Remarkable # :nodoc:
|
|
13
13
|
#
|
14
14
|
# Options:
|
15
15
|
#
|
16
|
+
# * <tt>:in</tt> - values to test exclusion.
|
16
17
|
# * <tt>:allow_nil</tt> - when supplied, validates if it allows nil or not.
|
17
18
|
# * <tt>:allow_blank</tt> - when supplied, validates if it allows blank or not.
|
18
19
|
# * <tt>:message</tt> - value the test expects to find in <tt>errors.on(:attribute)</tt>.
|
@@ -20,12 +21,27 @@ module Remarkable # :nodoc:
|
|
20
21
|
#
|
21
22
|
# Example:
|
22
23
|
#
|
23
|
-
# it { should validate_exclusion_of(:username, "admin", "user") }
|
24
|
-
# it {
|
24
|
+
# it { should validate_exclusion_of(:username, :in => ["admin", "user"]) }
|
25
|
+
# it { should validate_exclusion_of(:age, :in => 30..60) }
|
25
26
|
#
|
26
|
-
#
|
27
|
+
# should_validate_exclusion_of :username, :in => ["admin", "user"]
|
28
|
+
# should_validate_exclusion_of :age, :in => 30..60
|
27
29
|
#
|
28
30
|
def validate_exclusion_of(attribute, *good_values)
|
31
|
+
# TODO Remove this until the next comment
|
32
|
+
options = good_values.extract_options!
|
33
|
+
|
34
|
+
unless options.key?(:in) || good_values.empty?
|
35
|
+
warn "[DEPRECATION] Please use validate_exclusion_of #{attribute.inspect}, :in => #{good_values[0..-2].inspect} " <<
|
36
|
+
"instead of validate_exclusion_of #{attribute.inspect}, #{good_values[0..-2].inspect[1..-2]}."
|
37
|
+
end
|
38
|
+
|
39
|
+
options[:in] ||= good_values
|
40
|
+
|
41
|
+
# From now on is what should be the actual method.
|
42
|
+
good_values = [options.delete(:in)].flatten.compact
|
43
|
+
good_values << options
|
44
|
+
|
29
45
|
if good_values.first.is_a? Range
|
30
46
|
EnsureValueInRangeMatcher.new(attribute, :exclusion, *good_values)
|
31
47
|
else
|
@@ -13,6 +13,7 @@ module Remarkable # :nodoc:
|
|
13
13
|
#
|
14
14
|
# Options:
|
15
15
|
#
|
16
|
+
# * <tt>:in</tt> - values to test inclusion.
|
16
17
|
# * <tt>:allow_nil</tt> - when supplied, validates if it allows nil or not.
|
17
18
|
# * <tt>:allow_blank</tt> - when supplied, validates if it allows blank or not.
|
18
19
|
# * <tt>:message</tt> - value the test expects to find in <tt>errors.on(:attribute)</tt>.
|
@@ -20,12 +21,27 @@ module Remarkable # :nodoc:
|
|
20
21
|
#
|
21
22
|
# Example:
|
22
23
|
#
|
23
|
-
# it { should validate_inclusion_of(:
|
24
|
-
# it { should_not validate_inclusion_of(:isbn, "bad 1", "bad 2") }
|
25
|
-
#
|
24
|
+
# it { should validate_inclusion_of(:size, :in => ["S", "M", "L", "XL"]) }
|
26
25
|
# it { should validate_inclusion_of(:age, 18..100) }
|
27
26
|
#
|
27
|
+
# should_validate_inclusion_of :size, :in => ["S", "M", "L", "XL"]
|
28
|
+
# should_validate_inclusion_of :age, :in => 18..100
|
29
|
+
#
|
28
30
|
def validate_inclusion_of(attribute, *good_values)
|
31
|
+
# TODO Remove this until the next comment
|
32
|
+
options = good_values.extract_options!
|
33
|
+
|
34
|
+
unless options.key?(:in) || good_values.empty?
|
35
|
+
warn "[DEPRECATION] Please use validate_inclusion_of #{attribute.inspect}, :in => #{good_values[0..-2].inspect} " <<
|
36
|
+
"instead of validate_inclusion_of #{attribute.inspect}, #{good_values[0..-2].inspect[1..-2]}."
|
37
|
+
end
|
38
|
+
|
39
|
+
options[:in] ||= good_values
|
40
|
+
|
41
|
+
# From now on is what should be the actual method.
|
42
|
+
good_values = [options.delete(:in)].flatten.compact
|
43
|
+
good_values << options
|
44
|
+
|
29
45
|
if good_values.first.is_a? Range
|
30
46
|
EnsureValueInRangeMatcher.new(attribute, :inclusion, *good_values)
|
31
47
|
else
|
@@ -70,16 +70,16 @@ module Remarkable # :nodoc:
|
|
70
70
|
end
|
71
71
|
|
72
72
|
def allow_nil?
|
73
|
-
super(:short_message
|
73
|
+
super(:short_message)
|
74
74
|
end
|
75
75
|
|
76
76
|
def allow_blank?
|
77
|
-
super(:short_message
|
77
|
+
super(:short_message)
|
78
78
|
end
|
79
79
|
|
80
80
|
def less_than_min_length?
|
81
81
|
return true if @behavior == :maximum || @options[:minimum] <= 0
|
82
|
-
return true if bad?(value_for_length(@options[:minimum] - 1), :short_message
|
82
|
+
return true if bad?(value_for_length(@options[:minimum] - 1), :short_message)
|
83
83
|
|
84
84
|
@missing = "allow #{@attribute} to be less than #{@options[:minimum]} chars long"
|
85
85
|
return false
|
@@ -87,7 +87,7 @@ module Remarkable # :nodoc:
|
|
87
87
|
|
88
88
|
def exactly_min_length?
|
89
89
|
return true if @behavior == :maximum || @options[:minimum] <= 0
|
90
|
-
return true if good?(value_for_length(@options[:minimum]), :short_message
|
90
|
+
return true if good?(value_for_length(@options[:minimum]), :short_message)
|
91
91
|
|
92
92
|
@missing = "not allow #{@attribute} to be exactly #{@options[:minimum]} chars long"
|
93
93
|
return false
|
@@ -95,7 +95,7 @@ module Remarkable # :nodoc:
|
|
95
95
|
|
96
96
|
def more_than_max_length?
|
97
97
|
return true if @behavior == :minimum
|
98
|
-
return true if bad?(value_for_length(@options[:maximum] + 1), :long_message
|
98
|
+
return true if bad?(value_for_length(@options[:maximum] + 1), :long_message)
|
99
99
|
|
100
100
|
@missing = "allow #{@attribute} to be more than #{@options[:maximum]} chars long"
|
101
101
|
return false
|
@@ -103,7 +103,7 @@ module Remarkable # :nodoc:
|
|
103
103
|
|
104
104
|
def exactly_max_length?
|
105
105
|
return true if @behavior == :minimum || @options[:minimum] == @options[:maximum]
|
106
|
-
return true if good?(value_for_length(@options[:maximum]), :long_message
|
106
|
+
return true if good?(value_for_length(@options[:maximum]), :long_message)
|
107
107
|
|
108
108
|
@missing = "not allow #{@attribute} to be exactly #{@options[:maximum]} chars long"
|
109
109
|
return false
|
@@ -66,7 +66,7 @@ module Remarkable # :nodoc:
|
|
66
66
|
|
67
67
|
def equal_to?(key, add = 0)
|
68
68
|
return true unless @options.key?(key)
|
69
|
-
return true if good?(@options[key] + add, default_message_for(key)
|
69
|
+
return true if good?(@options[key] + add, default_message_for(key))
|
70
70
|
|
71
71
|
@missing = "did not allow value equals to #{@options[key]} for #{@attribute}"
|
72
72
|
false
|
@@ -74,7 +74,7 @@ module Remarkable # :nodoc:
|
|
74
74
|
|
75
75
|
def more_than_maximum?(key, add = 0)
|
76
76
|
return true unless @options.key?(key)
|
77
|
-
return true if bad?(@options[key] + add, default_message_for(key)
|
77
|
+
return true if bad?(@options[key] + add, default_message_for(key))
|
78
78
|
|
79
79
|
# We should do @options[key] + add - 1 to adjust messages in less_than cases.
|
80
80
|
@missing = "allowed value #{@options[key] + add} which is more than #{@options[key] + add - 1} for #{@attribute}"
|
@@ -83,7 +83,7 @@ module Remarkable # :nodoc:
|
|
83
83
|
|
84
84
|
def less_than_minimum?(key, add = 0)
|
85
85
|
return true unless @options.key?(key)
|
86
|
-
return true if bad?(@options[key] + add, default_message_for(key)
|
86
|
+
return true if bad?(@options[key] + add, default_message_for(key))
|
87
87
|
|
88
88
|
# We should do @options[key] + add + 1 to adjust messages in greater_than cases.
|
89
89
|
@missing = "allowed value #{@options[key] + add} which is less than #{@options[key] + add + 1} for #{@attribute}"
|
@@ -50,7 +50,7 @@ module Remarkable # :nodoc:
|
|
50
50
|
|
51
51
|
def after_initialize
|
52
52
|
if @options[:scoped_to] # TODO Deprecate scoped_to
|
53
|
-
warn "[DEPRECATION] :scoped_to is deprecated. Use :scope instead."
|
53
|
+
warn "[DEPRECATION] :scoped_to is deprecated in should_validate_uniqueness_of. Use :scope instead."
|
54
54
|
@options[:scope] = [*@options.delete(:scoped_to)].compact
|
55
55
|
else
|
56
56
|
@options[:scope] = [*@options[:scope]].compact
|
@@ -9,7 +9,7 @@ module Remarkable # :nodoc:
|
|
9
9
|
@names = names
|
10
10
|
@options[:equals] = block if block_given?
|
11
11
|
|
12
|
-
warn "[DEPRECATION] Strings given in :equals to
|
12
|
+
warn "[DEPRECATION] Strings given in :equals to should_assign_to won't be evaluated anymore. You can give procs or use blocks instead." if @options[:equals].is_a?(String)
|
13
13
|
end
|
14
14
|
|
15
15
|
def matches?(subject)
|
@@ -34,7 +34,7 @@ module Remarkable # :nodoc:
|
|
34
34
|
expected_value = if @expected.is_a?(Proc)
|
35
35
|
@spec.instance_eval &@expected
|
36
36
|
else
|
37
|
-
warn "[DEPRECATION] Strings given to
|
37
|
+
warn "[DEPRECATION] Strings given to should_set_session won't be evaluated anymore. Give a block or a proc instead."
|
38
38
|
@spec.instance_eval(@expected) rescue @expected
|
39
39
|
end
|
40
40
|
return true if @session[@key] == expected_value
|
@@ -61,7 +61,7 @@ module Remarkable # :nodoc:
|
|
61
61
|
end
|
62
62
|
|
63
63
|
def return_from_session(*args, &block)
|
64
|
-
warn "[DEPRECATION]
|
64
|
+
warn "[DEPRECATION] should_return_from_session is deprecated. Use should_set_session instead."
|
65
65
|
set_session(*args, &block)
|
66
66
|
end
|
67
67
|
end
|
@@ -22,7 +22,7 @@ module Remarkable # :nodoc:
|
|
22
22
|
elsif url.is_a?(Proc)
|
23
23
|
self.instance_eval &url
|
24
24
|
else
|
25
|
-
warn "[DEPRECATION] Strings given to
|
25
|
+
warn "[DEPRECATION] Strings given to should_redirect_to won't be evaluated anymore. Give a proc or a block instead." if url.is_a?(String)
|
26
26
|
self.instance_eval(url) rescue url
|
27
27
|
end
|
28
28
|
|
@@ -37,7 +37,7 @@ module Remarkable # :nodoc:
|
|
37
37
|
elsif url.is_a?(Proc)
|
38
38
|
self.instance_eval &url
|
39
39
|
else
|
40
|
-
warn "[DEPRECATION] Strings given to
|
40
|
+
warn "[DEPRECATION] Strings given to should_not_redirect_to won't be evaluated anymore. Give a proc or a block instead." if url.is_a?(String)
|
41
41
|
self.instance_eval(url) rescue url
|
42
42
|
end
|
43
43
|
|
data/lib/remarkable.rb
CHANGED
data/remarkable.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{remarkable}
|
5
|
-
s.version = "2.2.
|
5
|
+
s.version = "2.2.7"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Carlos Brando", "Jos\303\251 Valim", "Diego Carrion"]
|