shoulda-matchers 2.0.0 → 2.1.0

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.
Files changed (39) hide show
  1. checksums.yaml +8 -8
  2. data/.travis.yml +9 -15
  3. data/Appraisals +10 -8
  4. data/Gemfile.lock +1 -1
  5. data/NEWS.md +62 -32
  6. data/gemfiles/3.0.gemfile.lock +2 -2
  7. data/gemfiles/3.1.gemfile.lock +2 -2
  8. data/gemfiles/3.2.gemfile +1 -1
  9. data/gemfiles/3.2.gemfile.lock +3 -3
  10. data/lib/shoulda/matchers/active_model.rb +1 -0
  11. data/lib/shoulda/matchers/active_model/allow_value_matcher.rb +7 -2
  12. data/lib/shoulda/matchers/active_model/ensure_exclusion_of_matcher.rb +1 -1
  13. data/lib/shoulda/matchers/active_model/ensure_inclusion_of_matcher.rb +1 -1
  14. data/lib/shoulda/matchers/active_model/ensure_length_of_matcher.rb +2 -0
  15. data/lib/shoulda/matchers/active_model/exception_message_finder.rb +3 -2
  16. data/lib/shoulda/matchers/active_model/helpers.rb +5 -2
  17. data/lib/shoulda/matchers/active_model/odd_even_number_matcher.rb +47 -0
  18. data/lib/shoulda/matchers/active_model/only_integer_matcher.rb +4 -0
  19. data/lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb +26 -3
  20. data/lib/shoulda/matchers/active_model/validate_uniqueness_of_matcher.rb +68 -16
  21. data/lib/shoulda/matchers/active_model/validation_matcher.rb +5 -0
  22. data/lib/shoulda/matchers/active_model/validation_message_finder.rb +3 -2
  23. data/lib/shoulda/matchers/active_record/association_matcher.rb +29 -4
  24. data/lib/shoulda/matchers/version.rb +1 -1
  25. data/shoulda-matchers.gemspec +1 -0
  26. data/spec/shoulda/active_model/validate_uniqueness_of_matcher_spec.rb +195 -0
  27. data/spec/shoulda/matchers/active_model/allow_value_matcher_spec.rb +18 -0
  28. data/spec/shoulda/matchers/active_model/ensure_exclusion_of_matcher_spec.rb +21 -0
  29. data/spec/shoulda/matchers/active_model/ensure_inclusion_of_matcher_spec.rb +23 -0
  30. data/spec/shoulda/matchers/active_model/ensure_length_of_matcher_spec.rb +46 -0
  31. data/spec/shoulda/matchers/active_model/odd_even_number_matcher_spec.rb +93 -0
  32. data/spec/shoulda/matchers/active_model/only_integer_matcher_spec.rb +4 -4
  33. data/spec/shoulda/matchers/active_model/validate_numericality_of_matcher_spec.rb +60 -0
  34. data/spec/shoulda/matchers/active_model/validate_presence_of_matcher_spec.rb +16 -0
  35. data/spec/shoulda/matchers/active_model/validate_uniqueness_of_matcher_spec.rb +45 -8
  36. data/spec/shoulda/matchers/active_model/validation_message_finder_spec.rb +13 -0
  37. data/spec/shoulda/matchers/active_record/association_matcher_spec.rb +50 -2
  38. data/spec/support/i18n_faker.rb +10 -0
  39. metadata +10 -3
@@ -81,9 +81,9 @@ describe Shoulda::Matchers::ActiveRecord::AssociationMatcher do
81
81
  belonging_to_parent.should_not belong_to(:parent).class_name('TreeChild')
82
82
  end
83
83
 
84
- context 'validate' do
84
+ context 'an association with a :validate option' do
85
85
  [false, true].each do |validate_value|
86
- context 'when the model has :validate => #{validate_value}' do
86
+ context "when the model has :validate => #{validate_value}" do
87
87
  it 'accepts a matching validate option' do
88
88
  belonging_to_parent(:validate => validate_value).
89
89
  should belong_to(:parent).validate(validate_value)
@@ -103,6 +103,10 @@ describe Shoulda::Matchers::ActiveRecord::AssociationMatcher do
103
103
  should_not belong_to(:parent).validate
104
104
  end
105
105
  end
106
+
107
+ it 'will not break matcher when validate option is unspecified' do
108
+ belonging_to_parent(:validate => validate_value).should belong_to(:parent)
109
+ end
106
110
  end
107
111
  end
108
112
  end
@@ -121,6 +125,50 @@ describe Shoulda::Matchers::ActiveRecord::AssociationMatcher do
121
125
  end
122
126
  end
123
127
 
128
+ context 'an association with a :touch option' do
129
+ [false, true].each do |touch_value|
130
+ context "when the model has :touch => #{touch_value}" do
131
+ it 'accepts a matching touch option' do
132
+ belonging_to_parent(:touch => touch_value).
133
+ should belong_to(:parent).touch(touch_value)
134
+ end
135
+
136
+ it 'rejects a non-matching touch option' do
137
+ belonging_to_parent(:touch => touch_value).
138
+ should_not belong_to(:parent).touch(!touch_value)
139
+ end
140
+
141
+ it 'defaults to touch(true)' do
142
+ if touch_value
143
+ belonging_to_parent(:touch => touch_value).
144
+ should belong_to(:parent).touch
145
+ else
146
+ belonging_to_parent(:touch => touch_value).
147
+ should_not belong_to(:parent).touch
148
+ end
149
+ end
150
+
151
+ it 'will not break matcher when touch option is unspecified' do
152
+ belonging_to_parent(:touch => touch_value).should belong_to(:parent)
153
+ end
154
+ end
155
+ end
156
+ end
157
+
158
+ context 'an association without a :touch option' do
159
+ it 'accepts touch(false)' do
160
+ belonging_to_parent.should belong_to(:parent).touch(false)
161
+ end
162
+
163
+ it 'rejects touch(true)' do
164
+ belonging_to_parent.should_not belong_to(:parent).touch(true)
165
+ end
166
+
167
+ it 'rejects touch()' do
168
+ belonging_to_parent.should_not belong_to(:parent).touch
169
+ end
170
+ end
171
+
124
172
  def belonging_to_parent(options = {})
125
173
  define_model :parent
126
174
  define_model :child, :parent_id => :integer do
@@ -0,0 +1,10 @@
1
+ module I18nFaker
2
+ def stub_translation(key, message)
3
+ yml = key.split('.').reverse.inject(message) { |a, n| { n => a } }
4
+ I18n.backend.store_translations(:en, yml)
5
+ end
6
+ end
7
+
8
+ RSpec.configure do |config|
9
+ config.include I18nFaker
10
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shoulda-matchers
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tammer Saleh
@@ -13,7 +13,7 @@ authors:
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2013-04-05 00:00:00.000000000 Z
16
+ date: 2013-05-05 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: activesupport
@@ -201,6 +201,7 @@ files:
201
201
  - lib/shoulda/matchers/active_model/errors.rb
202
202
  - lib/shoulda/matchers/active_model/exception_message_finder.rb
203
203
  - lib/shoulda/matchers/active_model/helpers.rb
204
+ - lib/shoulda/matchers/active_model/odd_even_number_matcher.rb
204
205
  - lib/shoulda/matchers/active_model/only_integer_matcher.rb
205
206
  - lib/shoulda/matchers/active_model/validate_acceptance_of_matcher.rb
206
207
  - lib/shoulda/matchers/active_model/validate_confirmation_of_matcher.rb
@@ -221,6 +222,7 @@ files:
221
222
  - lib/shoulda/matchers/integrations/test_unit.rb
222
223
  - lib/shoulda/matchers/version.rb
223
224
  - shoulda-matchers.gemspec
225
+ - spec/shoulda/active_model/validate_uniqueness_of_matcher_spec.rb
224
226
  - spec/shoulda/matchers/action_controller/filter_param_matcher_spec.rb
225
227
  - spec/shoulda/matchers/action_controller/redirect_to_matcher_spec.rb
226
228
  - spec/shoulda/matchers/action_controller/render_template_matcher_spec.rb
@@ -237,6 +239,7 @@ files:
237
239
  - spec/shoulda/matchers/active_model/ensure_length_of_matcher_spec.rb
238
240
  - spec/shoulda/matchers/active_model/exception_message_finder_spec.rb
239
241
  - spec/shoulda/matchers/active_model/helpers_spec.rb
242
+ - spec/shoulda/matchers/active_model/odd_even_number_matcher_spec.rb
240
243
  - spec/shoulda/matchers/active_model/only_integer_matcher_spec.rb
241
244
  - spec/shoulda/matchers/active_model/validate_acceptance_of_matcher_spec.rb
242
245
  - spec/shoulda/matchers/active_model/validate_confirmation_of_matcher_spec.rb
@@ -255,6 +258,7 @@ files:
255
258
  - spec/support/activemodel_helpers.rb
256
259
  - spec/support/class_builder.rb
257
260
  - spec/support/controller_builder.rb
261
+ - spec/support/i18n_faker.rb
258
262
  - spec/support/mailer_builder.rb
259
263
  - spec/support/model_builder.rb
260
264
  homepage: http://thoughtbot.com/community/
@@ -269,7 +273,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
269
273
  requirements:
270
274
  - - ! '>='
271
275
  - !ruby/object:Gem::Version
272
- version: '0'
276
+ version: 1.9.2
273
277
  required_rubygems_version: !ruby/object:Gem::Requirement
274
278
  requirements:
275
279
  - - ! '>='
@@ -285,6 +289,7 @@ test_files:
285
289
  - features/rails_integration.feature
286
290
  - features/step_definitions/rails_steps.rb
287
291
  - features/support/env.rb
292
+ - spec/shoulda/active_model/validate_uniqueness_of_matcher_spec.rb
288
293
  - spec/shoulda/matchers/action_controller/filter_param_matcher_spec.rb
289
294
  - spec/shoulda/matchers/action_controller/redirect_to_matcher_spec.rb
290
295
  - spec/shoulda/matchers/action_controller/render_template_matcher_spec.rb
@@ -301,6 +306,7 @@ test_files:
301
306
  - spec/shoulda/matchers/active_model/ensure_length_of_matcher_spec.rb
302
307
  - spec/shoulda/matchers/active_model/exception_message_finder_spec.rb
303
308
  - spec/shoulda/matchers/active_model/helpers_spec.rb
309
+ - spec/shoulda/matchers/active_model/odd_even_number_matcher_spec.rb
304
310
  - spec/shoulda/matchers/active_model/only_integer_matcher_spec.rb
305
311
  - spec/shoulda/matchers/active_model/validate_acceptance_of_matcher_spec.rb
306
312
  - spec/shoulda/matchers/active_model/validate_confirmation_of_matcher_spec.rb
@@ -319,5 +325,6 @@ test_files:
319
325
  - spec/support/activemodel_helpers.rb
320
326
  - spec/support/class_builder.rb
321
327
  - spec/support/controller_builder.rb
328
+ - spec/support/i18n_faker.rb
322
329
  - spec/support/mailer_builder.rb
323
330
  - spec/support/model_builder.rb