carlosbrando-remarkable 2.2.10 → 2.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest.txt +2 -3
- data/lib/remarkable.rb +1 -1
- data/lib/remarkable/active_record/helpers.rb +2 -1
- data/lib/remarkable/active_record/macros/validations/ensure_value_in_range_matcher.rb +11 -47
- data/lib/remarkable/active_record/macros/validations/validate_acceptance_of_matcher.rb +0 -7
- data/lib/remarkable/active_record/macros/validations/validate_exclusion_of_matcher.rb +3 -3
- data/lib/remarkable/active_record/macros/validations/validate_inclusion_of_matcher.rb +3 -3
- data/lib/remarkable/active_record/macros/validations/validate_length_of_matcher.rb +1 -29
- data/lib/remarkable/active_record/macros/validations/validate_numericality_of_matcher.rb +0 -14
- data/lib/remarkable/active_record/macros/validations/validate_presence_of_matcher.rb +0 -7
- data/lib/remarkable/active_record/macros/validations/validate_uniqueness_of_matcher.rb +17 -46
- data/lib/remarkable/controller/README.markdown +15 -7
- data/lib/remarkable/controller/macros.rb +2 -4
- data/lib/remarkable/controller/macros/assign_matcher.rb +1 -4
- data/lib/remarkable/controller/macros/set_session_matcher.rb +16 -7
- data/lib/remarkable/controller/macros/{set_the_flash_to_matcher.rb → set_the_flash_matcher.rb} +21 -5
- data/remarkable.gemspec +2 -2
- metadata +2 -4
- data/lib/remarkable/active_record/macros/validations/protect_attributes_matcher.rb +0 -51
data/Manifest.txt
CHANGED
@@ -20,7 +20,6 @@ lib/remarkable/active_record/macros/validations/have_class_methods_matcher.rb
|
|
20
20
|
lib/remarkable/active_record/macros/validations/have_instance_methods_matcher.rb
|
21
21
|
lib/remarkable/active_record/macros/validations/have_named_scope_matcher.rb
|
22
22
|
lib/remarkable/active_record/macros/validations/have_readonly_attributes_matcher.rb
|
23
|
-
lib/remarkable/active_record/macros/validations/protect_attributes_matcher.rb
|
24
23
|
lib/remarkable/active_record/macros/validations/validate_acceptance_of_matcher.rb
|
25
24
|
lib/remarkable/active_record/macros/validations/validate_associated_matcher.rb
|
26
25
|
lib/remarkable/active_record/macros/validations/validate_confirmation_of_matcher.rb
|
@@ -44,7 +43,7 @@ lib/remarkable/controller/macros/respond_with_content_type_matcher.rb
|
|
44
43
|
lib/remarkable/controller/macros/respond_with_matcher.rb
|
45
44
|
lib/remarkable/controller/macros/set_session_matcher.rb
|
46
45
|
lib/remarkable/controller/macros/route_matcher.rb
|
47
|
-
lib/remarkable/controller/macros/
|
46
|
+
lib/remarkable/controller/macros/set_the_flash_matcher.rb
|
48
47
|
lib/remarkable/dsl.rb
|
49
48
|
lib/remarkable/example/example_methods.rb
|
50
49
|
lib/remarkable/helpers.rb
|
@@ -58,4 +57,4 @@ remarkable.gemspec
|
|
58
57
|
script/console
|
59
58
|
script/destroy
|
60
59
|
script/generate
|
61
|
-
|
60
|
+
|
data/lib/remarkable.rb
CHANGED
@@ -38,7 +38,8 @@ module Remarkable # :nodoc:
|
|
38
38
|
object = @spec ? @spec.instance_variable_get("@#{instance_variable_name_for(klass)}") : nil
|
39
39
|
object ||= klass.new
|
40
40
|
else
|
41
|
-
object_or_klass
|
41
|
+
object = @spec ? @spec.instance_variable_get("@#{instance_variable_name_for(object_or_klass.class)}") : nil
|
42
|
+
object || object_or_klass
|
42
43
|
end
|
43
44
|
end
|
44
45
|
|
@@ -6,26 +6,8 @@ module Remarkable # :nodoc:
|
|
6
6
|
|
7
7
|
arguments :attribute, :behavior, :ranges
|
8
8
|
|
9
|
-
def low_message(message)
|
10
|
-
warn "[DEPRECATION] should_ensure_value_in_range.low_message is deprecated. " <<
|
11
|
-
"Use should_validate_inclusion_of.message instead."
|
12
|
-
@options[:low_message] = message
|
13
|
-
self
|
14
|
-
end
|
15
|
-
|
16
|
-
def high_message(message)
|
17
|
-
warn "[DEPRECATION] should_ensure_value_in_range.high_message is deprecated. " <<
|
18
|
-
"Use should_validate_inclusion_of.message instead."
|
19
|
-
@options[:high_message] = message
|
20
|
-
self
|
21
|
-
end
|
22
|
-
|
23
|
-
# TODO Low message and High message should be deprecated (not supported by
|
24
|
-
# Rails API). In this while, we have to hack message.
|
25
9
|
def message(message)
|
26
|
-
@options[:
|
27
|
-
@options[:low_message] = message
|
28
|
-
@options[:message] = message
|
10
|
+
@options[:message] = message
|
29
11
|
self
|
30
12
|
end
|
31
13
|
|
@@ -55,7 +37,7 @@ module Remarkable # :nodoc:
|
|
55
37
|
|
56
38
|
def less_than_minimum?
|
57
39
|
return true unless @behavior == :inclusion
|
58
|
-
return true if bad?(@range.first - 1
|
40
|
+
return true if bad?(@range.first - 1)
|
59
41
|
|
60
42
|
@missing = "allow #{@attribute} to be less than #{@range.first}"
|
61
43
|
return false
|
@@ -63,7 +45,7 @@ module Remarkable # :nodoc:
|
|
63
45
|
|
64
46
|
def more_than_maximum?
|
65
47
|
return true unless @behavior == :inclusion
|
66
|
-
return true if bad?(@range.last + 1
|
48
|
+
return true if bad?(@range.last + 1)
|
67
49
|
|
68
50
|
@missing = "allow #{@attribute} to be more than #{@range.last}"
|
69
51
|
return false
|
@@ -71,7 +53,7 @@ module Remarkable # :nodoc:
|
|
71
53
|
|
72
54
|
def less_than_maximum?
|
73
55
|
return true unless @behavior == :exclusion
|
74
|
-
return true if bad?(@range.last - 1
|
56
|
+
return true if bad?(@range.last - 1)
|
75
57
|
|
76
58
|
@missing = "allow #{@attribute} to be less than #{@range.last}"
|
77
59
|
return false
|
@@ -79,21 +61,21 @@ module Remarkable # :nodoc:
|
|
79
61
|
|
80
62
|
def more_than_minimum?
|
81
63
|
return true unless @behavior == :exclusion
|
82
|
-
return true if bad?(@range.first + 1
|
64
|
+
return true if bad?(@range.first + 1)
|
83
65
|
|
84
66
|
@missing = "allow #{@attribute} to be more than #{@range.first}"
|
85
67
|
return false
|
86
68
|
end
|
87
69
|
|
88
70
|
def accepts_minimum?
|
89
|
-
return true if boundary?(@range.first
|
71
|
+
return true if boundary?(@range.first)
|
90
72
|
|
91
73
|
@missing = create_boundary_message("allow #{@attribute} to be #{@range.first}")
|
92
74
|
return false
|
93
75
|
end
|
94
76
|
|
95
77
|
def accepts_maximum?
|
96
|
-
return true if boundary?(@range.last
|
78
|
+
return true if boundary?(@range.last)
|
97
79
|
|
98
80
|
@missing = create_boundary_message("allow #{@attribute} to be #{@range.last}")
|
99
81
|
return false
|
@@ -125,36 +107,18 @@ module Remarkable # :nodoc:
|
|
125
107
|
end
|
126
108
|
end
|
127
109
|
|
128
|
-
def boundary?(value
|
110
|
+
def boundary?(value)
|
129
111
|
if @behavior == :exclusion
|
130
|
-
bad?(value,
|
112
|
+
bad?(value, :message)
|
131
113
|
else
|
132
|
-
good?(value,
|
114
|
+
good?(value, :message)
|
133
115
|
end
|
134
116
|
end
|
135
117
|
|
136
118
|
def default_options
|
137
|
-
{ :
|
138
|
-
:high_message => @behavior,
|
139
|
-
:message => @behavior }
|
119
|
+
{ :message => @behavior }
|
140
120
|
end
|
141
121
|
end
|
142
|
-
|
143
|
-
# TODO Deprecate this method, but not the matcher.
|
144
|
-
def ensure_value_in_range(attribute, range, *options) #:nodoc:
|
145
|
-
hash_options = options.extract_options!
|
146
|
-
|
147
|
-
warn "[DEPRECATION] should_ensure_value_in_range with :low_message is deprecated. " <<
|
148
|
-
"Use should_validate_inclusion_of with :message instead." if hash_options[:low_message]
|
149
|
-
|
150
|
-
warn "[DEPRECATION] should_ensure_value_in_range with :high_message is deprecated. " <<
|
151
|
-
"Use should_validate_inclusion_of with :message instead." if hash_options[:high_message]
|
152
|
-
|
153
|
-
warn "[DEPRECATION] should_ensure_value_in_range is deprecated. " <<
|
154
|
-
"Use should_validate_inclusion_of instead." if hash_options[:low_message].blank? && hash_options[:high_message].blank?
|
155
|
-
|
156
|
-
EnsureValueInRangeMatcher.new(attribute, :inclusion, range, *options)
|
157
|
-
end
|
158
122
|
end
|
159
123
|
end
|
160
124
|
end
|
@@ -65,13 +65,6 @@ module Remarkable # :nodoc:
|
|
65
65
|
ValidateAcceptanceOfMatcher.new(*attributes)
|
66
66
|
end
|
67
67
|
|
68
|
-
# TODO Deprecate this method.
|
69
|
-
def require_acceptance_of(*attributes) #:nodoc:
|
70
|
-
warn "[DEPRECATION] should_require_acceptance_of is deprecated. " <<
|
71
|
-
"Use should_validate_acceptance_of instead."
|
72
|
-
ValidateAcceptanceOfMatcher.new(*attributes)
|
73
|
-
end
|
74
|
-
|
75
68
|
end
|
76
69
|
end
|
77
70
|
end
|
@@ -28,12 +28,12 @@ module Remarkable # :nodoc:
|
|
28
28
|
# should_validate_exclusion_of :age, :in => 30..60
|
29
29
|
#
|
30
30
|
def validate_exclusion_of(attribute, *good_values)
|
31
|
-
# TODO Remove this until the next comment
|
32
31
|
options = good_values.extract_options!
|
33
32
|
|
33
|
+
# TODO Remove this until the next comment
|
34
34
|
unless options.key?(:in) || good_values.empty?
|
35
|
-
warn "[DEPRECATION] Please use validate_exclusion_of
|
36
|
-
"instead of validate_exclusion_of
|
35
|
+
warn "[DEPRECATION] Please use validate_exclusion_of(#{attribute.inspect}, :in => #{good_values.inspect}) " <<
|
36
|
+
"instead of validate_exclusion_of(#{attribute.inspect}, #{good_values.inspect[1..-2]})."
|
37
37
|
end
|
38
38
|
|
39
39
|
options[:in] ||= good_values
|
@@ -28,12 +28,12 @@ module Remarkable # :nodoc:
|
|
28
28
|
# should_validate_inclusion_of :age, :in => 18..100
|
29
29
|
#
|
30
30
|
def validate_inclusion_of(attribute, *good_values)
|
31
|
-
# TODO Remove this until the next comment
|
32
31
|
options = good_values.extract_options!
|
33
32
|
|
33
|
+
# TODO Remove this until the next comment
|
34
34
|
unless options.key?(:in) || good_values.empty?
|
35
|
-
warn "[DEPRECATION] Please use validate_inclusion_of
|
36
|
-
"instead of validate_inclusion_of
|
35
|
+
warn "[DEPRECATION] Please use validate_inclusion_of(#{attribute.inspect}, :in => #{good_values.inspect}) " <<
|
36
|
+
"instead of validate_inclusion_of(#{attribute.inspect}, #{good_values.inspect[1..-2]})."
|
37
37
|
end
|
38
38
|
|
39
39
|
options[:in] ||= good_values
|
@@ -127,7 +127,7 @@ module Remarkable # :nodoc:
|
|
127
127
|
#
|
128
128
|
def default_message_for(validation_type)
|
129
129
|
return :message if @options[:message]
|
130
|
-
@
|
130
|
+
@behavior == :is ? :wrong_length : validation_type
|
131
131
|
end
|
132
132
|
end
|
133
133
|
|
@@ -184,34 +184,6 @@ module Remarkable # :nodoc:
|
|
184
184
|
matcher
|
185
185
|
end
|
186
186
|
alias :validate_size_of :validate_length_of
|
187
|
-
|
188
|
-
# TODO This one is for shoulda compatibility. Deprecate it?
|
189
|
-
def ensure_length_of(*attributes) #:nodoc:
|
190
|
-
warn "[DEPRECATION] should_ensure_length_of is deprecated. " <<
|
191
|
-
"Use should_validate_length_of instead."
|
192
|
-
validate_length_of(*attributes)
|
193
|
-
end
|
194
|
-
|
195
|
-
# TODO Deprecate me
|
196
|
-
def ensure_length_in_range(attribute, range, options = {}) #:nodoc:
|
197
|
-
warn "[DEPRECATION] should_ensure_length_in_range is deprecated. " <<
|
198
|
-
"Use should_validate_length_of(#{attribute.inspect}, :in => #{range.inspect}) instead."
|
199
|
-
ValidateLengthOfMatcher.new(:within, range, attribute, options)
|
200
|
-
end
|
201
|
-
|
202
|
-
# TODO Deprecate me
|
203
|
-
def ensure_length_at_least(attribute, range, options = {}) #:nodoc:
|
204
|
-
warn "[DEPRECATION] should_ensure_length_at_least is deprecated. " <<
|
205
|
-
"Use should_validate_length_of(#{attribute.inspect}, :minimum => #{range.inspect}) instead."
|
206
|
-
ValidateLengthOfMatcher.new(:minimum, range, attribute, options)
|
207
|
-
end
|
208
|
-
|
209
|
-
# TODO Deprecate me
|
210
|
-
def ensure_length_is(attribute, range, options = {}) #:nodoc:
|
211
|
-
warn "[DEPRECATION] should_ensure_length_is is deprecated. " <<
|
212
|
-
"Use should_validate_length_of(#{attribute.inspect}, :is => #{range.inspect}) instead."
|
213
|
-
ValidateLengthOfMatcher.new(:is, range, attribute, options)
|
214
|
-
end
|
215
187
|
end
|
216
188
|
end
|
217
189
|
end
|
@@ -215,20 +215,6 @@ module Remarkable # :nodoc:
|
|
215
215
|
def validate_numericality_of(*attributes)
|
216
216
|
ValidateNumericalityOfMatcher.new(*attributes)
|
217
217
|
end
|
218
|
-
|
219
|
-
# TODO Deprecate me
|
220
|
-
def only_allow_numeric_values_for(*attributes) #:nodoc:
|
221
|
-
warn "[DEPRECATION] should_only_allow_numeric_values_for is deprecated. " <<
|
222
|
-
"Use should_validate_numericality_of instead."
|
223
|
-
ValidateNumericalityOfMatcher.new(*attributes)
|
224
|
-
end
|
225
|
-
|
226
|
-
# TODO Deprecate me
|
227
|
-
def only_allow_numeric_or_blank_values_for(*attributes)
|
228
|
-
warn "[DEPRECATION] should_only_allow_numeric_or_blank_values_for is deprecated. " <<
|
229
|
-
"Use should_validate_numericality_of with :allow_blank => true instead."
|
230
|
-
ValidateNumericalityOfMatcher.new(*attributes).allow_blank
|
231
|
-
end
|
232
218
|
end
|
233
219
|
end
|
234
220
|
end
|
@@ -42,13 +42,6 @@ module Remarkable # :nodoc:
|
|
42
42
|
ValidatePresenceOfMatcher.new(*attributes)
|
43
43
|
end
|
44
44
|
|
45
|
-
# TODO Deprecate me
|
46
|
-
def require_attributes(*attributes) #:nodoc:
|
47
|
-
warn "[DEPRECATION] should_require_attributes is deprecated. " <<
|
48
|
-
"Use should_validate_presence_of instead."
|
49
|
-
ValidatePresenceOfMatcher.new(*attributes)
|
50
|
-
end
|
51
|
-
|
52
45
|
end
|
53
46
|
end
|
54
47
|
end
|
@@ -8,21 +8,13 @@ module Remarkable # :nodoc:
|
|
8
8
|
optional :case_sensitive, :default => true
|
9
9
|
|
10
10
|
assertions :find_first_object?, :have_attribute?, :case_sensitive?,
|
11
|
-
:valid_when_changing_scoped_attribute?, :
|
12
|
-
:allow_nil?, :find_blank_object?, :allow_blank?
|
11
|
+
:valid_when_changing_scoped_attribute?, :allow_nil?, :allow_blank?
|
13
12
|
|
14
13
|
def scope(scope)
|
15
14
|
@options[:scope] = [*scope].compact
|
16
15
|
self
|
17
16
|
end
|
18
17
|
|
19
|
-
# TODO Deprecate this
|
20
|
-
#
|
21
|
-
def scoped_to(scoped)
|
22
|
-
warn "[DEPRECATION] scoped_to is deprecated. Use only scope instead."
|
23
|
-
scope(scoped)
|
24
|
-
end
|
25
|
-
|
26
18
|
def description
|
27
19
|
message = "require unique "
|
28
20
|
|
@@ -49,12 +41,7 @@ module Remarkable # :nodoc:
|
|
49
41
|
end
|
50
42
|
|
51
43
|
def after_initialize
|
52
|
-
|
53
|
-
warn "[DEPRECATION] :scoped_to is deprecated in should_validate_uniqueness_of. Use :scope instead."
|
54
|
-
@options[:scope] = [*@options.delete(:scoped_to)].compact
|
55
|
-
else
|
56
|
-
@options[:scope] = [*@options[:scope]].compact
|
57
|
-
end
|
44
|
+
@options[:scope] = [*@options[:scope]].compact
|
58
45
|
end
|
59
46
|
|
60
47
|
# Tries to find an object in the database.
|
@@ -79,28 +66,6 @@ module Remarkable # :nodoc:
|
|
79
66
|
false
|
80
67
|
end
|
81
68
|
|
82
|
-
# Tries to find an object where the given attribute is nil.
|
83
|
-
# This is required to test if the validation allows nil.
|
84
|
-
#
|
85
|
-
def find_nil_object?
|
86
|
-
return true unless @options.key? :allow_nil
|
87
|
-
return true if subject_class.find(:first, :conditions => "#{@attribute} IS NULL")
|
88
|
-
|
89
|
-
@missing = "can't find #{subject_class} with #{@attribute} nil"
|
90
|
-
false
|
91
|
-
end
|
92
|
-
|
93
|
-
# Tries to find an object where the given attribute is blank.
|
94
|
-
# This is required to test if the validation allows blank.
|
95
|
-
#
|
96
|
-
def find_blank_object?
|
97
|
-
return true unless @options.key? :allow_blank
|
98
|
-
return true if subject_class.find(:first, :conditions => "#{@attribute} = ''")
|
99
|
-
|
100
|
-
@missing = "can't find #{subject_class} with #{@attribute} blank"
|
101
|
-
false
|
102
|
-
end
|
103
|
-
|
104
69
|
# Check if the attribute given is valid and if the validation fails
|
105
70
|
# for equal values.
|
106
71
|
#
|
@@ -162,6 +127,20 @@ module Remarkable # :nodoc:
|
|
162
127
|
(@existing.send(scope) || 999).next
|
163
128
|
end
|
164
129
|
|
130
|
+
# Change the existing object attribute to nil to run allow nil validation.
|
131
|
+
#
|
132
|
+
def allow_nil?
|
133
|
+
@existing.update_attribute(@attribute, nil)
|
134
|
+
super
|
135
|
+
end
|
136
|
+
|
137
|
+
# Change the existing object attribute to blank to run allow blank validation.
|
138
|
+
#
|
139
|
+
def allow_blank?
|
140
|
+
@existing.update_attribute(@attribute, '')
|
141
|
+
super
|
142
|
+
end
|
143
|
+
|
165
144
|
def expectation
|
166
145
|
message = "that the #{subject_name} can be saved if "
|
167
146
|
|
@@ -180,8 +159,7 @@ module Remarkable # :nodoc:
|
|
180
159
|
#
|
181
160
|
# Requires an existing record in the database. If you supply :allow_nil as
|
182
161
|
# option, you need to have in the database a record with the given attribute
|
183
|
-
#
|
184
|
-
# allow_blank option.
|
162
|
+
# not nil. The same is required for allow_blank option.
|
185
163
|
#
|
186
164
|
# If an instance variable has been created in the setup named after the
|
187
165
|
# model being tested, then this method will use that. Otherwise, it will
|
@@ -206,13 +184,6 @@ module Remarkable # :nodoc:
|
|
206
184
|
def validate_uniqueness_of(*attributes)
|
207
185
|
ValidateUniquenessOfMatcher.new(*attributes)
|
208
186
|
end
|
209
|
-
|
210
|
-
#TODO Deprecate this alias, the deprecation warning is the matcher
|
211
|
-
def require_unique_attributes(*attributes)
|
212
|
-
warn "[DEPRECATION] should_require_unique_attributes is deprecated. " <<
|
213
|
-
"Use should_validate_uniqueness_of instead."
|
214
|
-
validate_uniqueness_of(*attributes)
|
215
|
-
end
|
216
187
|
end
|
217
188
|
end
|
218
189
|
end
|
@@ -94,11 +94,15 @@ h2. set_session
|
|
94
94
|
|
95
95
|
Macro that creates a test asserting that a value returned from the session is correct. You can given a string to compare to or a proc which will be evaluated.
|
96
96
|
|
97
|
+
Options:
|
98
|
+
|
99
|
+
* :to - A string or a proc which is evaluated and compared with the retrieved session variable.
|
100
|
+
|
97
101
|
Example:
|
98
102
|
|
99
|
-
should_set_session(:user_id, proc { @user.id })
|
103
|
+
should_set_session(:user_id, :to => proc { @user.id })
|
100
104
|
should_set_session(:user_id){ @user.id }
|
101
|
-
it { should set_session(:message, 'Free stuff') }
|
105
|
+
it { should set_session(:message, :to => 'Free stuff') }
|
102
106
|
|
103
107
|
h2. route
|
104
108
|
|
@@ -119,18 +123,22 @@ Examples:
|
|
119
123
|
it { should route(:get, "/users/1/posts/1",
|
120
124
|
:controller => :posts, :action => :show, :id => 1, :user_id => 1) }</code></pre>
|
121
125
|
|
122
|
-
h2.
|
126
|
+
h2. set_the_flash
|
123
127
|
|
124
128
|
Macro that creates a test asserting that the flash contains the given value. val can be a String, a Regex, or nil (indicating that the flash should not be set).
|
125
129
|
|
130
|
+
Options:
|
131
|
+
|
132
|
+
* :to - A value to check if it exists in flash or not.
|
133
|
+
|
126
134
|
Example:
|
127
135
|
|
128
|
-
<pre><code>
|
129
|
-
|
136
|
+
<pre><code> should_set_the_flash :to => "Thank you for placing this order."
|
137
|
+
should_set_the_flash :to => /created/i
|
130
138
|
should_not set_the_flash
|
131
139
|
|
132
|
-
it { should
|
133
|
-
it { should
|
140
|
+
it { should set_the_flash.to("Thank you for placing this order.") }
|
141
|
+
it { should set_the_flash.to(/created/i) }
|
134
142
|
it { should_not set_the_flash }</code></pre>
|
135
143
|
|
136
144
|
h2. redirect_to
|
@@ -22,8 +22,7 @@ module Remarkable # :nodoc:
|
|
22
22
|
elsif url.is_a?(Proc)
|
23
23
|
self.instance_eval &url
|
24
24
|
else
|
25
|
-
|
26
|
-
self.instance_eval(url) rescue url
|
25
|
+
url
|
27
26
|
end
|
28
27
|
|
29
28
|
response.should redirect_to(redirect_url)
|
@@ -37,8 +36,7 @@ module Remarkable # :nodoc:
|
|
37
36
|
elsif url.is_a?(Proc)
|
38
37
|
self.instance_eval &url
|
39
38
|
else
|
40
|
-
|
41
|
-
self.instance_eval(url) rescue url
|
39
|
+
url
|
42
40
|
end
|
43
41
|
|
44
42
|
response.should_not redirect_to(redirect_url)
|
@@ -11,7 +11,6 @@ module Remarkable # :nodoc:
|
|
11
11
|
@names = names
|
12
12
|
@options[:equals] = block if block_given?
|
13
13
|
|
14
|
-
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)
|
15
14
|
warn "[DEPRECATION] :equals option is deprecated in should_assign_to. Please give :with instead." if @options[:equals]
|
16
15
|
warn "[DEPRECATION] :class option is deprecated in should_assign_to. Please give :with_kind_of instead." if @options[:class]
|
17
16
|
|
@@ -66,9 +65,7 @@ module Remarkable # :nodoc:
|
|
66
65
|
def is_equals_expected_value?
|
67
66
|
return true unless @options[:with]
|
68
67
|
|
69
|
-
expected_value = if @options[:with].is_a?(
|
70
|
-
@spec.instance_eval(@options[:with]) rescue @options[:with]
|
71
|
-
elsif @options[:with].is_a?(Proc)
|
68
|
+
expected_value = if @options[:with].is_a?(Proc)
|
72
69
|
@spec.instance_eval &@options[:with]
|
73
70
|
else
|
74
71
|
@options[:with]
|
@@ -10,6 +10,11 @@ module Remarkable # :nodoc:
|
|
10
10
|
@expected = block if block_given?
|
11
11
|
end
|
12
12
|
|
13
|
+
def to(value)
|
14
|
+
@expected = value
|
15
|
+
self
|
16
|
+
end
|
17
|
+
|
13
18
|
def matches?(subject)
|
14
19
|
@subject = subject
|
15
20
|
|
@@ -34,8 +39,7 @@ module Remarkable # :nodoc:
|
|
34
39
|
expected_value = if @expected.is_a?(Proc)
|
35
40
|
@spec.instance_eval &@expected
|
36
41
|
else
|
37
|
-
|
38
|
-
@spec.instance_eval(@expected) rescue @expected
|
42
|
+
@expected
|
39
43
|
end
|
40
44
|
return true if @session[@key] == expected_value
|
41
45
|
|
@@ -57,13 +61,18 @@ module Remarkable # :nodoc:
|
|
57
61
|
end
|
58
62
|
|
59
63
|
def set_session(key, expected=nil, &block)
|
64
|
+
expected = if expected.is_a?(Hash)
|
65
|
+
expected[:to]
|
66
|
+
elsif expected
|
67
|
+
warn "[DEPRECATION] set_session(#{key.inspect}, #{expected.inspect}) is deprecated. " <<
|
68
|
+
"Please use set_session(#{key.inspect}, :to => #{expected.inspect})"
|
69
|
+
expected
|
70
|
+
else
|
71
|
+
expected
|
72
|
+
end
|
73
|
+
|
60
74
|
SetSessionMatcher.new(key, expected, &block)
|
61
75
|
end
|
62
|
-
|
63
|
-
def return_from_session(*args, &block)
|
64
|
-
warn "[DEPRECATION] should_return_from_session is deprecated. Use should_set_session instead."
|
65
|
-
set_session(*args, &block)
|
66
|
-
end
|
67
76
|
end
|
68
77
|
end
|
69
78
|
end
|
data/lib/remarkable/controller/macros/{set_the_flash_to_matcher.rb → set_the_flash_matcher.rb}
RENAMED
@@ -1,11 +1,23 @@
|
|
1
1
|
module Remarkable # :nodoc:
|
2
2
|
module Controller # :nodoc:
|
3
3
|
module Matchers # :nodoc:
|
4
|
-
class
|
4
|
+
class SetTheFlash < Remarkable::Matcher::Base
|
5
5
|
include Remarkable::Controller::Helpers
|
6
6
|
|
7
7
|
def initialize(val)
|
8
|
+
@val = if val.is_a?(Hash)
|
9
|
+
val[:to]
|
10
|
+
elsif val
|
11
|
+
warn "[DEPRECATION] set_the_flash(#{val.inspect}) is deprecated, please use set_the_flash(:to => #{val.inspect}) instead"
|
12
|
+
val
|
13
|
+
else
|
14
|
+
val
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def to(val)
|
8
19
|
@val = val
|
20
|
+
self
|
9
21
|
end
|
10
22
|
|
11
23
|
def matches?(subject)
|
@@ -36,7 +48,7 @@ module Remarkable # :nodoc:
|
|
36
48
|
return true if assert_contains(@flash.values, @val)
|
37
49
|
@missing = "not have #{@val} in the flash"
|
38
50
|
else
|
39
|
-
return true if @flash
|
51
|
+
return true if @flash.blank?
|
40
52
|
@missing = "flash is not empty"
|
41
53
|
end
|
42
54
|
return false
|
@@ -51,10 +63,14 @@ module Remarkable # :nodoc:
|
|
51
63
|
end
|
52
64
|
end
|
53
65
|
|
54
|
-
def
|
55
|
-
|
66
|
+
def set_the_flash(val={:to=>''})
|
67
|
+
SetTheFlash.new(val)
|
68
|
+
end
|
69
|
+
|
70
|
+
def set_the_flash_to(val={:to=>''})
|
71
|
+
warn "[DEPRECATION] set_the_flash_to matcher is deprecated, please use set_the_flash instead"
|
72
|
+
SetTheFlash.new(val)
|
56
73
|
end
|
57
|
-
alias_method :set_the_flash, :set_the_flash_to
|
58
74
|
end
|
59
75
|
end
|
60
76
|
end
|
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.
|
5
|
+
s.version = "2.3.0"
|
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"]
|
@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
|
|
10
10
|
s.description = %q{}
|
11
11
|
s.email = ["eduardobrando@gmail.com", "jose.valim@gmail.com", "dc.rec1@gmail.com"]
|
12
12
|
s.extra_rdoc_files = ["History.txt", "Manifest.txt", "PostInstall.txt", "README.rdoc"]
|
13
|
-
s.files = ["History.txt", "Manifest.txt", "PostInstall.txt", "README.rdoc", "Rakefile", "init.rb", "lib/remarkable.rb", "lib/remarkable/active_record/README.markdown", "lib/remarkable/active_record/active_record.rb", "lib/remarkable/active_record/helpers.rb", "lib/remarkable/active_record/macros.rb", "lib/remarkable/active_record/macros/associations/association_matcher.rb", "lib/remarkable/active_record/macros/callbacks/callback_matcher.rb", "lib/remarkable/active_record/macros/database/have_db_column_matcher.rb", "lib/remarkable/active_record/macros/database/index_matcher.rb", "lib/remarkable/active_record/macros/validations/allow_mass_assignment_of_matcher.rb", "lib/remarkable/active_record/macros/validations/ensure_value_in_list_matcher.rb", "lib/remarkable/active_record/macros/validations/ensure_value_in_range_matcher.rb", "lib/remarkable/active_record/macros/validations/have_class_methods_matcher.rb", "lib/remarkable/active_record/macros/validations/have_instance_methods_matcher.rb", "lib/remarkable/active_record/macros/validations/have_named_scope_matcher.rb", "lib/remarkable/active_record/macros/validations/have_readonly_attributes_matcher.rb", "lib/remarkable/active_record/macros/validations/
|
13
|
+
s.files = ["History.txt", "Manifest.txt", "PostInstall.txt", "README.rdoc", "Rakefile", "init.rb", "lib/remarkable.rb", "lib/remarkable/active_record/README.markdown", "lib/remarkable/active_record/active_record.rb", "lib/remarkable/active_record/helpers.rb", "lib/remarkable/active_record/macros.rb", "lib/remarkable/active_record/macros/associations/association_matcher.rb", "lib/remarkable/active_record/macros/callbacks/callback_matcher.rb", "lib/remarkable/active_record/macros/database/have_db_column_matcher.rb", "lib/remarkable/active_record/macros/database/index_matcher.rb", "lib/remarkable/active_record/macros/validations/allow_mass_assignment_of_matcher.rb", "lib/remarkable/active_record/macros/validations/ensure_value_in_list_matcher.rb", "lib/remarkable/active_record/macros/validations/ensure_value_in_range_matcher.rb", "lib/remarkable/active_record/macros/validations/have_class_methods_matcher.rb", "lib/remarkable/active_record/macros/validations/have_instance_methods_matcher.rb", "lib/remarkable/active_record/macros/validations/have_named_scope_matcher.rb", "lib/remarkable/active_record/macros/validations/have_readonly_attributes_matcher.rb", "lib/remarkable/active_record/macros/validations/validate_acceptance_of_matcher.rb", "lib/remarkable/active_record/macros/validations/validate_associated_matcher.rb", "lib/remarkable/active_record/macros/validations/validate_confirmation_of_matcher.rb", "lib/remarkable/active_record/macros/validations/validate_exclusion_of_matcher.rb", "lib/remarkable/active_record/macros/validations/validate_format_of_matcher.rb", "lib/remarkable/active_record/macros/validations/validate_inclusion_of_matcher.rb", "lib/remarkable/active_record/macros/validations/validate_length_of_matcher.rb", "lib/remarkable/active_record/macros/validations/validate_numericality_of_matcher.rb", "lib/remarkable/active_record/macros/validations/validate_presence_of_matcher.rb", "lib/remarkable/active_record/macros/validations/validate_uniqueness_of_matcher.rb", "lib/remarkable/assertions.rb", "lib/remarkable/controller/README.markdown", "lib/remarkable/controller/controller.rb", "lib/remarkable/controller/helpers.rb", "lib/remarkable/controller/macros.rb", "lib/remarkable/controller/macros/assign_matcher.rb", "lib/remarkable/controller/macros/filter_params_matcher.rb", "lib/remarkable/controller/macros/metadata_matcher.rb", "lib/remarkable/controller/macros/render_with_layout_matcher.rb", "lib/remarkable/controller/macros/respond_with_content_type_matcher.rb", "lib/remarkable/controller/macros/respond_with_matcher.rb", "lib/remarkable/controller/macros/set_session_matcher.rb", "lib/remarkable/controller/macros/route_matcher.rb", "lib/remarkable/controller/macros/set_the_flash_matcher.rb", "lib/remarkable/dsl.rb", "lib/remarkable/example/example_methods.rb", "lib/remarkable/helpers.rb", "lib/remarkable/inflections.rb", "lib/remarkable/matcher_base.rb", "lib/remarkable/private_helpers.rb", "lib/remarkable/rails.rb", "lib/remarkable/rails/extract_options.rb", "rails/init.rb", "remarkable.gemspec", "script/console", "script/destroy", "script/generate"]
|
14
14
|
s.has_rdoc = true
|
15
15
|
s.homepage = %q{http://www.nomedojogo.com/2008/11/18/shoulda-for-rspec-is-remarkable/}
|
16
16
|
s.post_install_message = %q{PostInstall.txt}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: carlosbrando-remarkable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Carlos Brando
|
@@ -91,7 +91,6 @@ files:
|
|
91
91
|
- lib/remarkable/active_record/macros/validations/have_instance_methods_matcher.rb
|
92
92
|
- lib/remarkable/active_record/macros/validations/have_named_scope_matcher.rb
|
93
93
|
- lib/remarkable/active_record/macros/validations/have_readonly_attributes_matcher.rb
|
94
|
-
- lib/remarkable/active_record/macros/validations/protect_attributes_matcher.rb
|
95
94
|
- lib/remarkable/active_record/macros/validations/validate_acceptance_of_matcher.rb
|
96
95
|
- lib/remarkable/active_record/macros/validations/validate_associated_matcher.rb
|
97
96
|
- lib/remarkable/active_record/macros/validations/validate_confirmation_of_matcher.rb
|
@@ -115,7 +114,7 @@ files:
|
|
115
114
|
- lib/remarkable/controller/macros/respond_with_matcher.rb
|
116
115
|
- lib/remarkable/controller/macros/set_session_matcher.rb
|
117
116
|
- lib/remarkable/controller/macros/route_matcher.rb
|
118
|
-
- lib/remarkable/controller/macros/
|
117
|
+
- lib/remarkable/controller/macros/set_the_flash_matcher.rb
|
119
118
|
- lib/remarkable/dsl.rb
|
120
119
|
- lib/remarkable/example/example_methods.rb
|
121
120
|
- lib/remarkable/helpers.rb
|
@@ -129,7 +128,6 @@ files:
|
|
129
128
|
- script/console
|
130
129
|
- script/destroy
|
131
130
|
- script/generate
|
132
|
-
- tasks/rspec.rake
|
133
131
|
has_rdoc: true
|
134
132
|
homepage: http://www.nomedojogo.com/2008/11/18/shoulda-for-rspec-is-remarkable/
|
135
133
|
post_install_message: PostInstall.txt
|
@@ -1,51 +0,0 @@
|
|
1
|
-
module Remarkable # :nodoc:
|
2
|
-
module ActiveRecord # :nodoc:
|
3
|
-
module Matchers # :nodoc:
|
4
|
-
class ProtectAttributes < Remarkable::Matcher::Base
|
5
|
-
def initialize(*attributes)
|
6
|
-
attributes.extract_options!
|
7
|
-
@attributes = attributes
|
8
|
-
end
|
9
|
-
|
10
|
-
def matches?(subject)
|
11
|
-
@subject = subject
|
12
|
-
|
13
|
-
assert_matcher_for(@attributes) do |attribute|
|
14
|
-
@attribute = attribute
|
15
|
-
protect_from_mass_updates?
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def description
|
20
|
-
"protect #{@attributes.to_sentence} from mass updates"
|
21
|
-
end
|
22
|
-
|
23
|
-
private
|
24
|
-
|
25
|
-
def protect_from_mass_updates?
|
26
|
-
attribute = @attribute.to_sym
|
27
|
-
protected = subject_class.protected_attributes || []
|
28
|
-
accessible = subject_class.accessible_attributes || []
|
29
|
-
|
30
|
-
return true if !protected.empty? && protected.include?(attribute.to_s)
|
31
|
-
return true if !accessible.empty? && !accessible.include?(attribute.to_s)
|
32
|
-
|
33
|
-
@missing = accessible.empty? ? "#{subject_class} is protecting #{protected.to_a.to_sentence}, but not #{attribute}." :
|
34
|
-
"#{subject_class} has made #{attribute} accessible"
|
35
|
-
return false
|
36
|
-
end
|
37
|
-
|
38
|
-
def expectation
|
39
|
-
"that #{@attribute} cannot be set on mass update"
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
# TODO Deprecate this method and the matcher.
|
44
|
-
def protect_attributes(*attributes) #:nodoc:
|
45
|
-
warn "[DEPRECATION] should_protect_attributes is deprecated. " <<
|
46
|
-
"Use should_not_allow_mass_assignment_of instead."
|
47
|
-
ProtectAttributes.new(*attributes)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|