shoulda-matchers 1.3.0 → 1.4.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 (37) hide show
  1. data/.travis.yml +1 -0
  2. data/Appraisals +3 -3
  3. data/Gemfile.lock +2 -2
  4. data/NEWS.md +20 -0
  5. data/README.md +1 -1
  6. data/gemfiles/3.0.gemfile +1 -1
  7. data/gemfiles/3.0.gemfile.lock +27 -27
  8. data/gemfiles/3.1.gemfile +1 -1
  9. data/gemfiles/3.1.gemfile.lock +36 -36
  10. data/gemfiles/3.2.gemfile +1 -1
  11. data/gemfiles/3.2.gemfile.lock +35 -35
  12. data/lib/shoulda/matchers/action_controller/set_the_flash_matcher.rb +4 -1
  13. data/lib/shoulda/matchers/active_model.rb +14 -0
  14. data/lib/shoulda/matchers/active_model/allow_value_matcher.rb +45 -21
  15. data/lib/shoulda/matchers/active_model/ensure_exclusion_of_matcher.rb +28 -6
  16. data/lib/shoulda/matchers/active_model/ensure_inclusion_of_matcher.rb +22 -4
  17. data/lib/shoulda/matchers/active_model/ensure_length_of_matcher.rb +1 -0
  18. data/lib/shoulda/matchers/active_model/errors.rb +7 -0
  19. data/lib/shoulda/matchers/active_model/exception_message_finder.rb +58 -0
  20. data/lib/shoulda/matchers/active_model/validate_uniqueness_of_matcher.rb +9 -1
  21. data/lib/shoulda/matchers/active_model/validation_matcher.rb +27 -8
  22. data/lib/shoulda/matchers/active_model/validation_message_finder.rb +69 -0
  23. data/lib/shoulda/matchers/active_record/association_matcher.rb +14 -5
  24. data/lib/shoulda/matchers/active_record/have_db_index_matcher.rb +8 -5
  25. data/lib/shoulda/matchers/version.rb +1 -1
  26. data/shoulda-matchers.gemspec +1 -1
  27. data/spec/shoulda/action_controller/set_the_flash_matcher_spec.rb +6 -0
  28. data/spec/shoulda/active_model/allow_value_matcher_spec.rb +32 -0
  29. data/spec/shoulda/active_model/ensure_exclusion_of_matcher_spec.rb +23 -1
  30. data/spec/shoulda/active_model/ensure_inclusion_of_matcher_spec.rb +49 -0
  31. data/spec/shoulda/active_model/ensure_length_of_matcher_spec.rb +13 -0
  32. data/spec/shoulda/active_model/exception_message_finder_spec.rb +112 -0
  33. data/spec/shoulda/active_model/validate_presence_of_matcher_spec.rb +15 -0
  34. data/spec/shoulda/active_model/validation_message_finder_spec.rb +107 -0
  35. data/spec/shoulda/active_record/association_matcher_spec.rb +8 -0
  36. data/spec/shoulda/active_record/have_db_index_matcher_spec.rb +17 -0
  37. metadata +18 -6
@@ -0,0 +1,107 @@
1
+ require 'spec_helper'
2
+
3
+ describe Shoulda::Matchers::ActiveModel::ValidationMessageFinder do
4
+ context '#allow_description' do
5
+ it 'describes its attribute' do
6
+ finder = build_finder(:attribute => :attr)
7
+
8
+ description = finder.allow_description('allowed values')
9
+
10
+ description.should == 'allow attr to be set to allowed values'
11
+ end
12
+ end
13
+
14
+ context '#expected_message_from' do
15
+ it 'returns the message as-is' do
16
+ finder = build_finder
17
+
18
+ message = finder.expected_message_from('some message')
19
+
20
+ message.should == 'some message'
21
+ end
22
+ end
23
+
24
+ context '#has_messages?' do
25
+ it 'has messages when some validations fail' do
26
+ finder = build_finder(:format => /abc/, :value => 'xyz')
27
+
28
+ result = finder.has_messages?
29
+
30
+ result.should be_true
31
+ end
32
+
33
+ it 'has no messages when all validations pass' do
34
+ finder = build_finder(:format => /abc/, :value => 'abc')
35
+
36
+ result = finder.has_messages?
37
+
38
+ result.should be_false
39
+ end
40
+ end
41
+
42
+ context '#messages' do
43
+ it 'returns errors for the given attribute' do
44
+ finder = build_finder(:format => /abc/, :value => 'xyz')
45
+
46
+ messages = finder.messages
47
+
48
+ messages.should == ['is invalid']
49
+ end
50
+ end
51
+
52
+ context '#messages_description' do
53
+ it 'describes errors for the given attribute' do
54
+ value = 'xyz'
55
+ finder = build_finder(
56
+ :attribute => :attr,
57
+ :format => /abc/,
58
+ :value => 'xyz'
59
+ )
60
+
61
+ description = finder.messages_description
62
+
63
+ expected_messages = ['attr is invalid ("xyz")']
64
+ description.should == "errors: #{expected_messages}"
65
+ end
66
+
67
+ it 'describes errors when there are none' do
68
+ finder = build_finder(:format => /abc/, :value => 'abc')
69
+
70
+ description = finder.messages_description
71
+
72
+ description.should == 'no errors'
73
+ end
74
+ end
75
+
76
+ context '#source_description' do
77
+ it 'describes the source of its messages' do
78
+ finder = build_finder
79
+
80
+ description = finder.source_description
81
+
82
+ description.should == 'errors'
83
+ end
84
+ end
85
+
86
+ def build_finder(arguments = {})
87
+ arguments[:attribute] ||= :attr
88
+ instance = build_instance_validating(
89
+ arguments[:attribute],
90
+ arguments[:format] || /abc/,
91
+ arguments[:value] || 'abc'
92
+ )
93
+ Shoulda::Matchers::ActiveModel::ValidationMessageFinder.new(
94
+ instance,
95
+ arguments[:attribute]
96
+ )
97
+ end
98
+
99
+ def build_instance_validating(attribute, format, value)
100
+ model_class = define_model(:example, attribute => :string) do
101
+ attr_accessible attribute
102
+ validates_format_of attribute, :with => format
103
+ end
104
+
105
+ model_class.new(attribute => value)
106
+ end
107
+ end
@@ -370,6 +370,14 @@ describe Shoulda::Matchers::ActiveRecord::AssociationMatcher do
370
370
  Person.new.should_not @matcher
371
371
  end
372
372
 
373
+ it "should accept an association with an existing custom foreign key" do
374
+ define_model :detail, :detailed_person_id => :integer
375
+ define_model :person do
376
+ has_one :detail, :foreign_key => :detailed_person_id
377
+ end
378
+ Person.new.should @matcher.with_foreign_key(:detailed_person_id)
379
+ end
380
+
373
381
  it "should reject an association with a bad :as option" do
374
382
  define_model :detail, :detailable_id => :integer,
375
383
  :detailable_type => :string
@@ -85,4 +85,21 @@ describe Shoulda::Matchers::ActiveRecord::HaveDbIndexMatcher do
85
85
  it "should not context an index's uniqueness when it isn't important" do
86
86
  have_db_index(:user_id).description.should_not =~ /unique/
87
87
  end
88
+
89
+ it "allows an IndexDefinition to have a truthy value for unique" do
90
+ db_connection = create_table 'superheros' do |table|
91
+ table.integer :age
92
+ end
93
+ db_connection.add_index :superheros, :age
94
+ define_model_class 'Superhero'
95
+
96
+ @matcher = have_db_index(:age).unique(true)
97
+
98
+ index_definition = stub("ActiveRecord::ConnectionAdapters::IndexDefinition",
99
+ :unique => 7,
100
+ :name => :age)
101
+ @matcher.stubs(:matched_index => index_definition)
102
+
103
+ Superhero.new.should @matcher
104
+ end
88
105
  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: 1.3.0
4
+ version: 1.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -14,7 +14,7 @@ authors:
14
14
  autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
- date: 2012-08-30 00:00:00.000000000 Z
17
+ date: 2012-10-05 00:00:00.000000000 Z
18
18
  dependencies:
19
19
  - !ruby/object:Gem::Dependency
20
20
  name: activesupport
@@ -87,7 +87,7 @@ dependencies:
87
87
  requirements:
88
88
  - - ~>
89
89
  - !ruby/object:Gem::Version
90
- version: 1.1.0
90
+ version: '1.1'
91
91
  type: :development
92
92
  prerelease: false
93
93
  version_requirements: !ruby/object:Gem::Requirement
@@ -95,7 +95,7 @@ dependencies:
95
95
  requirements:
96
96
  - - ~>
97
97
  - !ruby/object:Gem::Version
98
- version: 1.1.0
98
+ version: '1.1'
99
99
  - !ruby/object:Gem::Dependency
100
100
  name: cucumber
101
101
  requirement: !ruby/object:Gem::Requirement
@@ -206,6 +206,8 @@ files:
206
206
  - lib/shoulda/matchers/active_model/ensure_exclusion_of_matcher.rb
207
207
  - lib/shoulda/matchers/active_model/ensure_inclusion_of_matcher.rb
208
208
  - lib/shoulda/matchers/active_model/ensure_length_of_matcher.rb
209
+ - lib/shoulda/matchers/active_model/errors.rb
210
+ - lib/shoulda/matchers/active_model/exception_message_finder.rb
209
211
  - lib/shoulda/matchers/active_model/helpers.rb
210
212
  - lib/shoulda/matchers/active_model/validate_acceptance_of_matcher.rb
211
213
  - lib/shoulda/matchers/active_model/validate_confirmation_of_matcher.rb
@@ -214,6 +216,7 @@ files:
214
216
  - lib/shoulda/matchers/active_model/validate_presence_of_matcher.rb
215
217
  - lib/shoulda/matchers/active_model/validate_uniqueness_of_matcher.rb
216
218
  - lib/shoulda/matchers/active_model/validation_matcher.rb
219
+ - lib/shoulda/matchers/active_model/validation_message_finder.rb
217
220
  - lib/shoulda/matchers/active_record.rb
218
221
  - lib/shoulda/matchers/active_record/accept_nested_attributes_for_matcher.rb
219
222
  - lib/shoulda/matchers/active_record/association_matcher.rb
@@ -250,6 +253,7 @@ files:
250
253
  - spec/shoulda/active_model/ensure_exclusion_of_matcher_spec.rb
251
254
  - spec/shoulda/active_model/ensure_inclusion_of_matcher_spec.rb
252
255
  - spec/shoulda/active_model/ensure_length_of_matcher_spec.rb
256
+ - spec/shoulda/active_model/exception_message_finder_spec.rb
253
257
  - spec/shoulda/active_model/helpers_spec.rb
254
258
  - spec/shoulda/active_model/validate_acceptance_of_matcher_spec.rb
255
259
  - spec/shoulda/active_model/validate_confirmation_of_matcher_spec.rb
@@ -257,6 +261,7 @@ files:
257
261
  - spec/shoulda/active_model/validate_numericality_of_matcher_spec.rb
258
262
  - spec/shoulda/active_model/validate_presence_of_matcher_spec.rb
259
263
  - spec/shoulda/active_model/validate_uniqueness_of_matcher_spec.rb
264
+ - spec/shoulda/active_model/validation_message_finder_spec.rb
260
265
  - spec/shoulda/active_record/accept_nested_attributes_for_matcher_spec.rb
261
266
  - spec/shoulda/active_record/association_matcher_spec.rb
262
267
  - spec/shoulda/active_record/have_db_column_matcher_spec.rb
@@ -282,15 +287,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
282
287
  - - ! '>='
283
288
  - !ruby/object:Gem::Version
284
289
  version: '0'
290
+ segments:
291
+ - 0
292
+ hash: 813377459972856034
285
293
  required_rubygems_version: !ruby/object:Gem::Requirement
286
294
  none: false
287
295
  requirements:
288
296
  - - ! '>='
289
297
  - !ruby/object:Gem::Version
290
298
  version: '0'
299
+ segments:
300
+ - 0
301
+ hash: 813377459972856034
291
302
  requirements: []
292
303
  rubyforge_project:
293
- rubygems_version: 1.8.23
304
+ rubygems_version: 1.8.24
294
305
  signing_key:
295
306
  specification_version: 3
296
307
  summary: Making tests easy on the fingers and eyes
@@ -321,6 +332,7 @@ test_files:
321
332
  - spec/shoulda/active_model/ensure_exclusion_of_matcher_spec.rb
322
333
  - spec/shoulda/active_model/ensure_inclusion_of_matcher_spec.rb
323
334
  - spec/shoulda/active_model/ensure_length_of_matcher_spec.rb
335
+ - spec/shoulda/active_model/exception_message_finder_spec.rb
324
336
  - spec/shoulda/active_model/helpers_spec.rb
325
337
  - spec/shoulda/active_model/validate_acceptance_of_matcher_spec.rb
326
338
  - spec/shoulda/active_model/validate_confirmation_of_matcher_spec.rb
@@ -328,6 +340,7 @@ test_files:
328
340
  - spec/shoulda/active_model/validate_numericality_of_matcher_spec.rb
329
341
  - spec/shoulda/active_model/validate_presence_of_matcher_spec.rb
330
342
  - spec/shoulda/active_model/validate_uniqueness_of_matcher_spec.rb
343
+ - spec/shoulda/active_model/validation_message_finder_spec.rb
331
344
  - spec/shoulda/active_record/accept_nested_attributes_for_matcher_spec.rb
332
345
  - spec/shoulda/active_record/association_matcher_spec.rb
333
346
  - spec/shoulda/active_record/have_db_column_matcher_spec.rb
@@ -341,4 +354,3 @@ test_files:
341
354
  - spec/support/controller_builder.rb
342
355
  - spec/support/mailer_builder.rb
343
356
  - spec/support/model_builder.rb
344
- has_rdoc: