shoulda-matchers 2.6.1 → 2.6.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (146) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +9 -0
  4. data/.yardopts +8 -0
  5. data/Appraisals +82 -33
  6. data/Gemfile +18 -2
  7. data/Gemfile.lock +13 -1
  8. data/NEWS.md +27 -2
  9. data/README.md +83 -1329
  10. data/Rakefile +118 -1
  11. data/cucumber.yml +1 -0
  12. data/doc_config/gh-pages/index.html.erb +9 -0
  13. data/doc_config/yard/setup.rb +22 -0
  14. data/doc_config/yard/templates/default/fulldoc/html/css/bootstrap.css +5967 -0
  15. data/doc_config/yard/templates/default/fulldoc/html/css/full_list.css +12 -0
  16. data/doc_config/yard/templates/default/fulldoc/html/css/global.css +45 -0
  17. data/doc_config/yard/templates/default/fulldoc/html/css/solarized.css +69 -0
  18. data/doc_config/yard/templates/default/fulldoc/html/css/style.css +283 -0
  19. data/doc_config/yard/templates/default/fulldoc/html/full_list.erb +32 -0
  20. data/doc_config/yard/templates/default/fulldoc/html/full_list_class.erb +1 -0
  21. data/doc_config/yard/templates/default/fulldoc/html/full_list_method.erb +8 -0
  22. data/doc_config/yard/templates/default/fulldoc/html/js/app.js +298 -0
  23. data/doc_config/yard/templates/default/fulldoc/html/js/full_list.js +1 -0
  24. data/doc_config/yard/templates/default/fulldoc/html/js/jquery.stickyheaders.js +289 -0
  25. data/doc_config/yard/templates/default/fulldoc/html/js/underscore.min.js +6 -0
  26. data/doc_config/yard/templates/default/fulldoc/html/setup.rb +8 -0
  27. data/doc_config/yard/templates/default/layout/html/breadcrumb.erb +14 -0
  28. data/doc_config/yard/templates/default/layout/html/fonts.erb +1 -0
  29. data/doc_config/yard/templates/default/layout/html/layout.erb +23 -0
  30. data/doc_config/yard/templates/default/layout/html/search.erb +13 -0
  31. data/doc_config/yard/templates/default/layout/html/setup.rb +40 -0
  32. data/doc_config/yard/templates/default/method_details/html/source.erb +10 -0
  33. data/doc_config/yard/templates/default/module/html/box_info.erb +31 -0
  34. data/docs.watchr +5 -0
  35. data/features/rails_integration.feature +32 -0
  36. data/features/step_definitions/rails_steps.rb +55 -9
  37. data/features/support/env.rb +1 -0
  38. data/gemfiles/3.0.gemfile +13 -1
  39. data/gemfiles/3.0.gemfile.lock +13 -1
  40. data/gemfiles/3.1.gemfile +17 -2
  41. data/gemfiles/3.1.gemfile.lock +31 -2
  42. data/gemfiles/3.1_1.9.2.gemfile +33 -0
  43. data/gemfiles/3.1_1.9.2.gemfile.lock +203 -0
  44. data/gemfiles/3.2.gemfile +18 -2
  45. data/gemfiles/3.2.gemfile.lock +32 -2
  46. data/gemfiles/3.2_1.9.2.gemfile +32 -0
  47. data/gemfiles/3.2_1.9.2.gemfile.lock +200 -0
  48. data/gemfiles/4.0.0.gemfile +20 -1
  49. data/gemfiles/4.0.0.gemfile.lock +46 -2
  50. data/gemfiles/4.0.1.gemfile +20 -1
  51. data/gemfiles/4.0.1.gemfile.lock +46 -2
  52. data/gemfiles/4.1.gemfile +21 -2
  53. data/gemfiles/4.1.gemfile.lock +47 -4
  54. data/lib/shoulda/matchers/action_controller.rb +0 -20
  55. data/lib/shoulda/matchers/action_controller/callback_matcher.rb +119 -28
  56. data/lib/shoulda/matchers/action_controller/filter_param_matcher.rb +22 -6
  57. data/lib/shoulda/matchers/action_controller/redirect_to_matcher.rb +43 -10
  58. data/lib/shoulda/matchers/action_controller/render_template_matcher.rb +40 -13
  59. data/lib/shoulda/matchers/action_controller/render_with_layout_matcher.rb +63 -11
  60. data/lib/shoulda/matchers/action_controller/rescue_from_matcher.rb +34 -1
  61. data/lib/shoulda/matchers/action_controller/respond_with_matcher.rb +84 -15
  62. data/lib/shoulda/matchers/action_controller/route_matcher.rb +84 -28
  63. data/lib/shoulda/matchers/action_controller/route_params.rb +4 -3
  64. data/lib/shoulda/matchers/action_controller/set_session_matcher.rb +76 -13
  65. data/lib/shoulda/matchers/action_controller/set_the_flash_matcher.rb +147 -13
  66. data/lib/shoulda/matchers/action_controller/strong_parameters_matcher.rb +148 -2
  67. data/lib/shoulda/matchers/active_model.rb +0 -25
  68. data/lib/shoulda/matchers/active_model/allow_mass_assignment_of_matcher.rb +66 -9
  69. data/lib/shoulda/matchers/active_model/allow_value_matcher.rb +161 -19
  70. data/lib/shoulda/matchers/active_model/disallow_value_matcher.rb +5 -5
  71. data/lib/shoulda/matchers/active_model/ensure_exclusion_of_matcher.rb +92 -13
  72. data/lib/shoulda/matchers/active_model/ensure_inclusion_of_matcher.rb +218 -16
  73. data/lib/shoulda/matchers/active_model/ensure_length_of_matcher.rb +198 -32
  74. data/lib/shoulda/matchers/active_model/errors.rb +5 -2
  75. data/lib/shoulda/matchers/active_model/exception_message_finder.rb +1 -1
  76. data/lib/shoulda/matchers/active_model/have_secure_password_matcher.rb +29 -8
  77. data/lib/shoulda/matchers/active_model/helpers.rb +20 -8
  78. data/lib/shoulda/matchers/active_model/numericality_matchers.rb +9 -0
  79. data/lib/shoulda/matchers/active_model/numericality_matchers/comparison_matcher.rb +4 -6
  80. data/lib/shoulda/matchers/active_model/numericality_matchers/even_number_matcher.rb +4 -3
  81. data/lib/shoulda/matchers/active_model/numericality_matchers/numeric_type_matcher.rb +3 -2
  82. data/lib/shoulda/matchers/active_model/numericality_matchers/odd_number_matcher.rb +4 -3
  83. data/lib/shoulda/matchers/active_model/numericality_matchers/only_integer_matcher.rb +4 -3
  84. data/lib/shoulda/matchers/active_model/validate_absence_of_matcher.rb +52 -14
  85. data/lib/shoulda/matchers/active_model/validate_acceptance_of_matcher.rb +51 -13
  86. data/lib/shoulda/matchers/active_model/validate_confirmation_of_matcher.rb +53 -7
  87. data/lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb +275 -19
  88. data/lib/shoulda/matchers/active_model/validate_presence_of_matcher.rb +84 -14
  89. data/lib/shoulda/matchers/active_model/validate_uniqueness_of_matcher.rb +170 -41
  90. data/lib/shoulda/matchers/active_model/validation_matcher.rb +20 -15
  91. data/lib/shoulda/matchers/active_model/validation_message_finder.rb +1 -2
  92. data/lib/shoulda/matchers/active_record.rb +1 -12
  93. data/lib/shoulda/matchers/active_record/accept_nested_attributes_for_matcher.rb +89 -15
  94. data/lib/shoulda/matchers/active_record/association_matcher.rb +726 -70
  95. data/lib/shoulda/matchers/active_record/association_matchers.rb +9 -0
  96. data/lib/shoulda/matchers/active_record/association_matchers/counter_cache_matcher.rb +4 -3
  97. data/lib/shoulda/matchers/active_record/association_matchers/dependent_matcher.rb +4 -3
  98. data/lib/shoulda/matchers/active_record/association_matchers/inverse_of_matcher.rb +4 -3
  99. data/lib/shoulda/matchers/active_record/association_matchers/model_reflection.rb +2 -1
  100. data/lib/shoulda/matchers/active_record/association_matchers/model_reflector.rb +4 -3
  101. data/lib/shoulda/matchers/active_record/association_matchers/option_verifier.rb +4 -5
  102. data/lib/shoulda/matchers/active_record/association_matchers/order_matcher.rb +4 -3
  103. data/lib/shoulda/matchers/active_record/association_matchers/source_matcher.rb +4 -3
  104. data/lib/shoulda/matchers/active_record/association_matchers/through_matcher.rb +4 -3
  105. data/lib/shoulda/matchers/active_record/have_db_column_matcher.rb +79 -15
  106. data/lib/shoulda/matchers/active_record/have_db_index_matcher.rb +64 -15
  107. data/lib/shoulda/matchers/active_record/have_readonly_attribute_matcher.rb +21 -7
  108. data/lib/shoulda/matchers/active_record/serialize_matcher.rb +85 -10
  109. data/lib/shoulda/matchers/assertion_error.rb +7 -1
  110. data/lib/shoulda/matchers/doublespeak.rb +2 -1
  111. data/lib/shoulda/matchers/doublespeak/double.rb +3 -1
  112. data/lib/shoulda/matchers/doublespeak/double_collection.rb +2 -1
  113. data/lib/shoulda/matchers/doublespeak/double_implementation_registry.rb +1 -0
  114. data/lib/shoulda/matchers/doublespeak/object_double.rb +2 -1
  115. data/lib/shoulda/matchers/doublespeak/proxy_implementation.rb +2 -1
  116. data/lib/shoulda/matchers/doublespeak/structs.rb +2 -0
  117. data/lib/shoulda/matchers/doublespeak/stub_implementation.rb +2 -1
  118. data/lib/shoulda/matchers/doublespeak/world.rb +3 -4
  119. data/lib/shoulda/matchers/error.rb +1 -0
  120. data/lib/shoulda/matchers/independent/delegate_matcher.rb +108 -20
  121. data/lib/shoulda/matchers/independent/delegate_matcher/stubbed_target.rb +4 -3
  122. data/lib/shoulda/matchers/integrations/nunit_test_case_detection.rb +3 -0
  123. data/lib/shoulda/matchers/rails_shim.rb +3 -2
  124. data/lib/shoulda/matchers/version.rb +2 -1
  125. data/lib/shoulda/matchers/warn.rb +1 -0
  126. data/script/SUPPORTED_VERSIONS +1 -0
  127. data/script/install_gems_in_all_appraisals +14 -0
  128. data/script/run_all_tests +14 -0
  129. data/shoulda-matchers.gemspec +0 -10
  130. data/spec/report_warnings.rb +7 -0
  131. data/spec/shoulda/matchers/action_controller/route_matcher_spec.rb +1 -1
  132. data/spec/shoulda/matchers/action_controller/strong_parameters_matcher_spec.rb +9 -0
  133. data/spec/shoulda/matchers/active_model/validate_uniqueness_of_matcher_spec.rb +0 -36
  134. data/spec/shoulda/matchers/active_model/validation_message_finder_spec.rb +2 -2
  135. data/spec/shoulda/matchers/doublespeak/double_spec.rb +1 -1
  136. data/spec/shoulda/matchers/doublespeak/world_spec.rb +11 -29
  137. data/spec/shoulda/matchers/doublespeak_spec.rb +3 -3
  138. data/spec/spec_helper.rb +17 -0
  139. data/spec/support/class_builder.rb +4 -0
  140. data/spec/support/test_application.rb +1 -1
  141. data/spec/warnings_spy.rb +64 -0
  142. data/spec/warnings_spy/filesystem.rb +45 -0
  143. data/spec/warnings_spy/partitioner.rb +29 -0
  144. data/spec/warnings_spy/reader.rb +64 -0
  145. data/spec/warnings_spy/reporter.rb +87 -0
  146. metadata +49 -134
@@ -1,25 +1,95 @@
1
- module Shoulda # :nodoc:
1
+ module Shoulda
2
2
  module Matchers
3
- module ActiveModel # :nodoc:
4
-
5
- # Ensures that the model is not valid if the given attribute is not
6
- # present.
3
+ module ActiveModel
4
+ # The `validate_presence_of` matcher tests usage of the
5
+ # `validates_presence_of` validation.
6
+ #
7
+ # class Robot
8
+ # include ActiveModel::Model
9
+ # attr_accessor :arms
10
+ #
11
+ # validates_presence_of :arms
12
+ # end
13
+ #
14
+ # # RSpec
15
+ # describe Robot do
16
+ # it { should validate_presence_of(:arms) }
17
+ # end
18
+ #
19
+ # # Test::Unit
20
+ # class RobotTest < ActiveSupport::TestCase
21
+ # should validate_presence_of(:arms)
22
+ # end
23
+ #
24
+ # #### Caveats
25
+ #
26
+ # Under Rails 4 and greater, if your model `has_secure_password` and you
27
+ # are validating presence of the password using a record whose password
28
+ # has already been set prior to calling the matcher, you will be
29
+ # instructed to use a record whose password is empty instead.
30
+ #
31
+ # For example, given this scenario:
32
+ #
33
+ # class User < ActiveRecord::Base
34
+ # has_secure_password validations: false
35
+ #
36
+ # validates_presence_of :password
37
+ # end
38
+ #
39
+ # describe User do
40
+ # subject { User.new(password: '123456') }
41
+ #
42
+ # it { should validate_presence_of(:password) }
43
+ # end
44
+ #
45
+ # the above test will raise an error like this:
46
+ #
47
+ # The validation failed because your User model declares
48
+ # `has_secure_password`, and `validate_presence_of` was called on a
49
+ # user which has `password` already set to a value. Please use a user
50
+ # with an empty `password` instead.
51
+ #
52
+ # This happens because `has_secure_password` itself overrides your model
53
+ # so that it is impossible to set `password` to nil. This means that it is
54
+ # impossible to test that setting `password` to nil places your model in
55
+ # an invalid state (which in turn means that the validation itself is
56
+ # unnecessary).
57
+ #
58
+ # #### Qualifiers
59
+ #
60
+ # ##### with_message
61
+ #
62
+ # Use `with_message` if you are using a custom validation message.
63
+ #
64
+ # class Robot
65
+ # include ActiveModel::Model
66
+ # attr_accessor :legs
67
+ #
68
+ # validates_presence_of :legs, message: 'Robot has no legs'
69
+ # end
70
+ #
71
+ # # RSpec
72
+ # describe Robot do
73
+ # it do
74
+ # should validate_presence_of(:legs).
75
+ # with_message('Robot has no legs')
76
+ # end
77
+ # end
7
78
  #
8
- # Options:
9
- # * <tt>with_message</tt> - value the test expects to find in
10
- # <tt>errors.on(:attribute)</tt>. <tt>Regexp</tt> or <tt>String</tt>.
11
- # Defaults to the translation for <tt>:blank</tt>.
79
+ # # Test::Unit
80
+ # class RobotTest < ActiveSupport::TestCase
81
+ # should validate_presence_of(:legs).
82
+ # with_message('Robot has no legs')
83
+ # end
12
84
  #
13
- # Examples:
14
- # it { should validate_presence_of(:name) }
15
- # it { should validate_presence_of(:name).
16
- # with_message(/is not optional/) }
85
+ # @return [ValidatePresenceOfMatcher]
17
86
  #
18
87
  def validate_presence_of(attr)
19
88
  ValidatePresenceOfMatcher.new(attr)
20
89
  end
21
90
 
22
- class ValidatePresenceOfMatcher < ValidationMatcher # :nodoc:
91
+ # @private
92
+ class ValidatePresenceOfMatcher < ValidationMatcher
23
93
  def with_message(message)
24
94
  @expected_message = message if message
25
95
  self
@@ -1,38 +1,178 @@
1
- module Shoulda # :nodoc:
1
+ module Shoulda
2
2
  module Matchers
3
- module ActiveModel # :nodoc:
4
- # Ensures that the model is invalid if the given attribute is not unique.
5
- # It uses the first existing record or creates a new one if no record
6
- # exists in the database. It simply uses `validate: false` to get
7
- # around validations, so it will probably fail if there are `NOT NULL`
8
- # constraints. In that case, you must create a record before calling
9
- # `validate_uniqueness_of`.
10
- #
11
- # Example:
12
- # it { should validate_uniqueness_of(:email) }
13
- #
14
- # Options:
15
- #
16
- # * <tt>with_message</tt> - value the test expects to find in
17
- # <tt>errors.on(:attribute)</tt>. <tt>Regexp</tt> or <tt>String</tt>.
18
- # Defaults to the translation for <tt>:taken</tt>.
19
- # * <tt>scoped_to</tt> - field(s) to scope the uniqueness to.
20
- # * <tt>case_insensitive</tt> - ensures that the validation does not
21
- # check case. Off by default. Ignored by non-text attributes.
22
- #
23
- # Examples:
24
- # it { should validate_uniqueness_of(:keyword) }
25
- # it { should validate_uniqueness_of(:keyword).with_message(/dup/) }
26
- # it { should validate_uniqueness_of(:email).scoped_to(:name) }
27
- # it { should validate_uniqueness_of(:email).
28
- # scoped_to(:first_name, :last_name) }
29
- # it { should validate_uniqueness_of(:keyword).case_insensitive }
3
+ module ActiveModel
4
+ # The `validate_uniqueness_of` matcher tests usage of the
5
+ # `validates_uniqueness_of` validation. It first checks for an existing
6
+ # instance of your model in the database, creating one if necessary. It
7
+ # then takes a new record and asserts that it fails validation if the
8
+ # attribute or attributes you've specified in the validation are set to
9
+ # values which are the same as those of the pre-existing record (thereby
10
+ # failing the uniqueness check).
11
+ #
12
+ # class Post < ActiveRecord::Base
13
+ # validates_uniqueness_of :permalink
14
+ # end
15
+ #
16
+ # # RSpec
17
+ # describe Post do
18
+ # it { should validate_uniqueness_of(:permalink) }
19
+ # end
20
+ #
21
+ # # Test::Unit
22
+ # class PostTest < ActiveSupport::TestCase
23
+ # should validate_uniqueness_of(:permalink)
24
+ # end
25
+ #
26
+ # #### Caveat
27
+ #
28
+ # This matcher works a bit differently than other matchers. As noted
29
+ # before, it will create an instance of your model if one doesn't already
30
+ # exist. Sometimes this step fails, especially if you have database-level
31
+ # restrictions on any attributes other than the one which is unique. In
32
+ # this case, the solution is to **create a record manually** before you
33
+ # call `validate_uniqueness_of`.
34
+ #
35
+ # For example, say you have the following migration and model:
36
+ #
37
+ # class CreatePosts < ActiveRecord::Migration
38
+ # def change
39
+ # create_table :posts do |t|
40
+ # t.string :title
41
+ # t.text :content, null: false
42
+ # end
43
+ # end
44
+ # end
45
+ #
46
+ # class Post < ActiveRecord::Base
47
+ # validates :title, uniqueness: true
48
+ # end
49
+ #
50
+ # You may be tempted to test the model like this:
51
+ #
52
+ # describe Post do
53
+ # it { should validate_uniqueness_of(:title) }
54
+ # end
55
+ #
56
+ # However, running this test will fail with something like:
57
+ #
58
+ # Failures:
59
+ #
60
+ # 1) Post should require case sensitive unique value for title
61
+ # Failure/Error: it { should validate_uniqueness_of(:title) }
62
+ # ActiveRecord::StatementInvalid:
63
+ # SQLite3::ConstraintException: posts.content may not be NULL: INSERT INTO "posts" ("title") VALUES (?)
64
+ #
65
+ # To fix this, you'll need to write this instead:
66
+ #
67
+ # describe Post do
68
+ # it do
69
+ # Post.create!(content: 'Here is the content')
70
+ # should validate_uniqueness_of(:title)
71
+ # end
72
+ # end
73
+ #
74
+ # Or, if you're using
75
+ # [FactoryGirl](http://github.com/thoughtbot/factory_girl) and you have a
76
+ # `post` factory defined which automatically sets `content`, you can say:
77
+ #
78
+ # describe Post do
79
+ # it do
80
+ # FactoryGirl.create(:post)
81
+ # should validate_uniqueness_of(:title)
82
+ # end
83
+ # end
84
+ #
85
+ # #### Qualifiers
86
+ #
87
+ # ##### with_message
88
+ #
89
+ # Use `with_message` if you are using a custom validation message.
90
+ #
91
+ # class Post < ActiveRecord::Base
92
+ # validates_uniqueness_of :title, message: 'Please choose another title'
93
+ # end
94
+ #
95
+ # # RSpec
96
+ # describe Post do
97
+ # it do
98
+ # should validate_uniqueness_of(:title).
99
+ # with_message('Please choose another title')
100
+ # end
101
+ # end
102
+ #
103
+ # # Test::Unit
104
+ # class PostTest < ActiveSupport::TestCase
105
+ # should validate_uniqueness_of(:title).
106
+ # with_message('Please choose another title')
107
+ # end
108
+ #
109
+ # ##### scoped_to
110
+ #
111
+ # Use `scoped_to` to test usage of the `:scope` option. This asserts that
112
+ # a new record fails validation if not only the primary attribute is not
113
+ # unique, but the scoped attributes are not unique either.
114
+ #
115
+ # class Post < ActiveRecord::Base
116
+ # validates_uniqueness_of :slug, scope: :user_id
117
+ # end
118
+ #
119
+ # # RSpec
120
+ # describe Post do
121
+ # it { should validate_uniqueness_of(:slug).scoped_to(:journal_id) }
122
+ # end
123
+ #
124
+ # # Test::Unit
125
+ # class PostTest < ActiveSupport::TestCase
126
+ # should validate_uniqueness_of(:slug).scoped_to(:journal_id)
127
+ # end
128
+ #
129
+ # ##### case_insensitive
130
+ #
131
+ # Use `case_insensitive` to test usage of the `:case_sensitive` option
132
+ # with a false value. This asserts that the uniquable attributes fail
133
+ # validation even if their values are a different case than corresponding
134
+ # attributes in the pre-existing record.
135
+ #
136
+ # class Post < ActiveRecord::Base
137
+ # validates_uniqueness_of :key, case_sensitive: false
138
+ # end
139
+ #
140
+ # # RSpec
141
+ # describe Post do
142
+ # it { should validate_uniqueness_of(:key).case_insensitive }
143
+ # end
144
+ #
145
+ # # Test::Unit
146
+ # class PostTest < ActiveSupport::TestCase
147
+ # should validate_uniqueness_of(:key).case_insensitive
148
+ # end
149
+ #
150
+ # ##### allow_nil
151
+ #
152
+ # Use `allow_nil` to assert that the attribute allows nil.
153
+ #
154
+ # class Post < ActiveRecord::Base
155
+ # validates_uniqueness_of :author_id, allow_nil: true
156
+ # end
157
+ #
158
+ # # RSpec
159
+ # describe Post do
160
+ # it { should validate_uniqueness_of(:author_id).allow_nil }
161
+ # end
162
+ #
163
+ # # Test::Unit
164
+ # class PostTest < ActiveSupport::TestCase
165
+ # should validate_uniqueness_of(:author_id).allow_nil
166
+ # end
167
+ #
168
+ # @return [ValidateUniquenessOfMatcher]
30
169
  #
31
170
  def validate_uniqueness_of(attr)
32
171
  ValidateUniquenessOfMatcher.new(attr)
33
172
  end
34
173
 
35
- class ValidateUniquenessOfMatcher < ValidationMatcher # :nodoc:
174
+ # @private
175
+ class ValidateUniquenessOfMatcher < ValidationMatcher
36
176
  include Helpers
37
177
 
38
178
  def initialize(attribute)
@@ -115,11 +255,6 @@ module Shoulda # :nodoc:
115
255
 
116
256
  @subject.class.new.tap do |instance|
117
257
  instance.__send__("#{@attribute}=", value)
118
-
119
- other_non_nullable_columns.each do |non_nullable_column|
120
- instance.__send__("#{non_nullable_column.name}=", correct_type_for_column(non_nullable_column))
121
- end
122
-
123
258
  if has_secure_password?
124
259
  instance.password = 'password'
125
260
  instance.password_confirmation = 'password'
@@ -203,7 +338,7 @@ module Shoulda # :nodoc:
203
338
  end
204
339
 
205
340
  def correct_type_for_column(column)
206
- if column.type == :string || column.type == :binary
341
+ if column.type == :string
207
342
  '0'
208
343
  elsif column.type == :datetime
209
344
  DateTime.now
@@ -225,12 +360,6 @@ module Shoulda # :nodoc:
225
360
  end
226
361
  value
227
362
  end
228
-
229
- def other_non_nullable_columns
230
- @subject.class.columns.select do |column|
231
- column.name != @attribute && !column.null && !column.primary
232
- end
233
- end
234
363
  end
235
364
  end
236
365
  end
@@ -1,7 +1,8 @@
1
- module Shoulda # :nodoc:
1
+ module Shoulda
2
2
  module Matchers
3
- module ActiveModel # :nodoc:
4
- class ValidationMatcher # :nodoc:
3
+ module ActiveModel
4
+ # @private
5
+ class ValidationMatcher
5
6
  attr_reader :failure_message
6
7
 
7
8
  alias failure_message_for_should failure_message
@@ -9,6 +10,8 @@ module Shoulda # :nodoc:
9
10
  def initialize(attribute)
10
11
  @attribute = attribute
11
12
  @strict = false
13
+ @failure_message = nil
14
+ @failure_message_when_negated = nil
12
15
  end
13
16
 
14
17
  def on(context)
@@ -60,31 +63,33 @@ module Shoulda # :nodoc:
60
63
  end
61
64
 
62
65
  def allow_value_matcher(value, message)
63
- matcher = AllowValueMatcher.
64
- new(value).
65
- for(@attribute).
66
- on(@context).
66
+ matcher = AllowValueMatcher.new(value).for(@attribute).
67
67
  with_message(message)
68
68
 
69
+ if defined?(@context)
70
+ matcher.on(@context)
71
+ end
72
+
69
73
  if strict?
70
74
  matcher.strict
71
- else
72
- matcher
73
75
  end
76
+
77
+ matcher
74
78
  end
75
79
 
76
80
  def disallow_value_matcher(value, message)
77
- matcher = DisallowValueMatcher.
78
- new(value).
79
- for(@attribute).
80
- on(@context).
81
+ matcher = DisallowValueMatcher.new(value).for(@attribute).
81
82
  with_message(message)
82
83
 
84
+ if defined?(@context)
85
+ matcher.on(@context)
86
+ end
87
+
83
88
  if strict?
84
89
  matcher.strict
85
- else
86
- matcher
87
90
  end
91
+
92
+ matcher
88
93
  end
89
94
 
90
95
  def strict?
@@ -1,8 +1,7 @@
1
1
  module Shoulda
2
2
  module Matchers
3
3
  module ActiveModel
4
-
5
- # Finds message information from a model's #errors method.
4
+ # @private
6
5
  class ValidationMessageFinder
7
6
  include Helpers
8
7
 
@@ -1,4 +1,5 @@
1
1
  require 'shoulda/matchers/active_record/association_matcher'
2
+ require 'shoulda/matchers/active_record/association_matchers'
2
3
  require 'shoulda/matchers/active_record/association_matchers/counter_cache_matcher'
3
4
  require 'shoulda/matchers/active_record/association_matchers/inverse_of_matcher'
4
5
  require 'shoulda/matchers/active_record/association_matchers/order_matcher'
@@ -16,18 +17,6 @@ require 'shoulda/matchers/active_record/accept_nested_attributes_for_matcher'
16
17
 
17
18
  module Shoulda
18
19
  module Matchers
19
- # = Matchers for your active record models
20
- #
21
- # These matchers will test the associations for your
22
- # ActiveRecord models.
23
- #
24
- # describe User do
25
- # it { should have_one(:profile) }
26
- # it { should have_many(:dogs) }
27
- # it { should have_many(:messes).through(:dogs) }
28
- # it { should belong_to(:lover) }
29
- # end
30
- #
31
20
  module ActiveRecord
32
21
  end
33
22
  end