shoulda-matchers 2.5.0 → 2.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. data/.gitignore +8 -7
  2. data/.travis.yml +4 -0
  3. data/Appraisals +8 -0
  4. data/CONTRIBUTING.md +1 -1
  5. data/Gemfile +1 -1
  6. data/Gemfile.lock +77 -66
  7. data/MIT-LICENSE +1 -1
  8. data/NEWS.md +63 -1
  9. data/README.md +189 -33
  10. data/Rakefile +6 -5
  11. data/features/rails_integration.feature +1 -1
  12. data/features/step_definitions/rails_steps.rb +7 -6
  13. data/gemfiles/3.0.gemfile +2 -2
  14. data/gemfiles/3.0.gemfile.lock +14 -5
  15. data/gemfiles/3.1.gemfile +2 -2
  16. data/gemfiles/3.1.gemfile.lock +14 -5
  17. data/gemfiles/3.2.gemfile +2 -2
  18. data/gemfiles/3.2.gemfile.lock +16 -7
  19. data/gemfiles/4.0.0.gemfile +2 -2
  20. data/gemfiles/4.0.0.gemfile.lock +15 -6
  21. data/gemfiles/4.0.1.gemfile +2 -2
  22. data/gemfiles/4.0.1.gemfile.lock +15 -6
  23. data/gemfiles/4.1.gemfile +19 -0
  24. data/gemfiles/4.1.gemfile.lock +176 -0
  25. data/lib/shoulda/matchers.rb +17 -1
  26. data/lib/shoulda/matchers/action_controller.rb +4 -2
  27. data/lib/shoulda/matchers/action_controller/callback_matcher.rb +100 -0
  28. data/lib/shoulda/matchers/action_controller/redirect_to_matcher.rb +1 -1
  29. data/lib/shoulda/matchers/action_controller/render_template_matcher.rb +4 -4
  30. data/lib/shoulda/matchers/action_controller/rescue_from_matcher.rb +1 -1
  31. data/lib/shoulda/matchers/action_controller/route_matcher.rb +12 -12
  32. data/lib/shoulda/matchers/action_controller/route_params.rb +1 -1
  33. data/lib/shoulda/matchers/action_controller/set_the_flash_matcher.rb +2 -1
  34. data/lib/shoulda/matchers/action_controller/strong_parameters_matcher.rb +167 -0
  35. data/lib/shoulda/matchers/active_model.rb +4 -2
  36. data/lib/shoulda/matchers/active_model/allow_value_matcher.rb +23 -5
  37. data/lib/shoulda/matchers/active_model/disallow_value_matcher.rb +0 -4
  38. data/lib/shoulda/matchers/active_model/ensure_inclusion_of_matcher.rb +66 -14
  39. data/lib/shoulda/matchers/active_model/ensure_length_of_matcher.rb +8 -8
  40. data/lib/shoulda/matchers/active_model/errors.rb +40 -0
  41. data/lib/shoulda/matchers/active_model/helpers.rb +6 -6
  42. data/lib/shoulda/matchers/active_model/numericality_matchers/comparison_matcher.rb +33 -14
  43. data/lib/shoulda/matchers/active_model/numericality_matchers/even_number_matcher.rb +26 -0
  44. data/lib/shoulda/matchers/active_model/numericality_matchers/{odd_even_number_matcher.rb → numeric_type_matcher.rb} +9 -20
  45. data/lib/shoulda/matchers/active_model/numericality_matchers/odd_number_matcher.rb +26 -0
  46. data/lib/shoulda/matchers/active_model/numericality_matchers/only_integer_matcher.rb +5 -21
  47. data/lib/shoulda/matchers/active_model/validate_confirmation_of_matcher.rb +1 -1
  48. data/lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb +71 -22
  49. data/lib/shoulda/matchers/active_model/validate_presence_of_matcher.rb +6 -1
  50. data/lib/shoulda/matchers/active_model/validate_uniqueness_of_matcher.rb +25 -6
  51. data/lib/shoulda/matchers/active_record.rb +1 -0
  52. data/lib/shoulda/matchers/active_record/association_matcher.rb +67 -13
  53. data/lib/shoulda/matchers/active_record/association_matchers/inverse_of_matcher.rb +40 -0
  54. data/lib/shoulda/matchers/active_record/association_matchers/model_reflection.rb +24 -1
  55. data/lib/shoulda/matchers/active_record/association_matchers/model_reflector.rb +1 -1
  56. data/lib/shoulda/matchers/active_record/have_db_column_matcher.rb +1 -1
  57. data/lib/shoulda/matchers/active_record/have_db_index_matcher.rb +1 -1
  58. data/lib/shoulda/matchers/assertion_error.rb +7 -2
  59. data/lib/shoulda/matchers/error.rb +24 -0
  60. data/lib/shoulda/matchers/independent.rb +10 -0
  61. data/lib/shoulda/matchers/independent/delegate_matcher.rb +157 -0
  62. data/lib/shoulda/matchers/independent/delegate_matcher/stubbed_target.rb +34 -0
  63. data/lib/shoulda/matchers/integrations/nunit_test_case_detection.rb +36 -0
  64. data/lib/shoulda/matchers/integrations/rspec.rb +13 -14
  65. data/lib/shoulda/matchers/integrations/test_unit.rb +11 -9
  66. data/lib/shoulda/matchers/version.rb +1 -1
  67. data/lib/shoulda/matchers/warn.rb +7 -0
  68. data/shoulda-matchers.gemspec +2 -1
  69. data/spec/shoulda/matchers/action_controller/callback_matcher_spec.rb +79 -0
  70. data/spec/shoulda/matchers/action_controller/filter_param_matcher_spec.rb +3 -3
  71. data/spec/shoulda/matchers/action_controller/redirect_to_matcher_spec.rb +11 -11
  72. data/spec/shoulda/matchers/action_controller/render_template_matcher_spec.rb +21 -21
  73. data/spec/shoulda/matchers/action_controller/render_with_layout_matcher_spec.rb +10 -10
  74. data/spec/shoulda/matchers/action_controller/rescue_from_matcher_spec.rb +45 -18
  75. data/spec/shoulda/matchers/action_controller/respond_with_matcher_spec.rb +8 -8
  76. data/spec/shoulda/matchers/action_controller/route_matcher_spec.rb +19 -19
  77. data/spec/shoulda/matchers/action_controller/route_params_spec.rb +6 -6
  78. data/spec/shoulda/matchers/action_controller/set_session_matcher_spec.rb +11 -11
  79. data/spec/shoulda/matchers/action_controller/set_the_flash_matcher_spec.rb +44 -44
  80. data/spec/shoulda/matchers/action_controller/strong_parameters_matcher_spec.rb +205 -0
  81. data/spec/shoulda/matchers/active_model/allow_mass_assignment_of_matcher_spec.rb +24 -24
  82. data/spec/shoulda/matchers/active_model/allow_value_matcher_spec.rb +37 -37
  83. data/spec/shoulda/matchers/active_model/disallow_value_matcher_spec.rb +17 -21
  84. data/spec/shoulda/matchers/active_model/ensure_exclusion_of_matcher_spec.rb +24 -24
  85. data/spec/shoulda/matchers/active_model/ensure_inclusion_of_matcher_spec.rb +173 -67
  86. data/spec/shoulda/matchers/active_model/ensure_length_of_matcher_spec.rb +40 -40
  87. data/spec/shoulda/matchers/active_model/exception_message_finder_spec.rb +20 -20
  88. data/spec/shoulda/matchers/active_model/helpers_spec.rb +27 -25
  89. data/spec/shoulda/matchers/active_model/numericality_matchers/comparison_matcher_spec.rb +126 -13
  90. data/spec/shoulda/matchers/active_model/numericality_matchers/even_number_matcher_spec.rb +59 -0
  91. data/spec/shoulda/matchers/active_model/numericality_matchers/odd_number_matcher_spec.rb +59 -0
  92. data/spec/shoulda/matchers/active_model/numericality_matchers/only_integer_matcher_spec.rb +27 -26
  93. data/spec/shoulda/matchers/active_model/validate_absence_of_matcher_spec.rb +15 -15
  94. data/spec/shoulda/matchers/active_model/validate_acceptance_of_matcher_spec.rb +8 -8
  95. data/spec/shoulda/matchers/active_model/validate_confirmation_of_matcher_spec.rb +9 -9
  96. data/spec/shoulda/matchers/active_model/validate_numericality_of_matcher_spec.rb +229 -44
  97. data/spec/shoulda/matchers/active_model/validate_presence_of_matcher_spec.rb +44 -25
  98. data/spec/shoulda/matchers/active_model/validate_uniqueness_of_matcher_spec.rb +110 -62
  99. data/spec/shoulda/matchers/active_model/validation_message_finder_spec.rb +19 -19
  100. data/spec/shoulda/matchers/active_record/accept_nested_attributes_for_matcher_spec.rb +30 -30
  101. data/spec/shoulda/matchers/active_record/association_matcher_spec.rb +378 -192
  102. data/spec/shoulda/matchers/active_record/association_matchers/model_reflection_spec.rb +4 -0
  103. data/spec/shoulda/matchers/active_record/have_db_column_matcher_spec.rb +33 -33
  104. data/spec/shoulda/matchers/active_record/have_db_index_matcher_spec.rb +21 -17
  105. data/spec/shoulda/matchers/active_record/have_readonly_attributes_matcher_spec.rb +8 -8
  106. data/spec/shoulda/matchers/active_record/serialize_matcher_spec.rb +14 -14
  107. data/spec/shoulda/matchers/independent/delegate_matcher/stubbed_target_spec.rb +43 -0
  108. data/spec/shoulda/matchers/independent/delegate_matcher_spec.rb +184 -0
  109. data/spec/spec_helper.rb +4 -0
  110. data/spec/support/activemodel_helpers.rb +2 -2
  111. data/spec/support/capture_helpers.rb +19 -0
  112. data/spec/support/controller_builder.rb +22 -3
  113. data/spec/support/fail_with_message_including_matcher.rb +33 -0
  114. data/spec/support/model_builder.rb +1 -1
  115. data/spec/support/shared_examples/numerical_submatcher.rb +19 -0
  116. data/spec/support/shared_examples/numerical_type_submatcher.rb +17 -0
  117. data/spec/support/test_application.rb +23 -0
  118. metadata +90 -22
  119. checksums.yaml +0 -7
  120. data/spec/shoulda/matchers/active_model/numericality_matchers/odd_even_number_matcher_spec.rb +0 -97
  121. data/spec/support/shared_examples/numerical_submatcher_spec.rb +0 -23
@@ -20,7 +20,6 @@ module Shoulda # :nodoc:
20
20
  end
21
21
 
22
22
  class ValidatePresenceOfMatcher < ValidationMatcher # :nodoc:
23
-
24
23
  def with_message(message)
25
24
  @expected_message = message if message
26
25
  self
@@ -30,6 +29,12 @@ module Shoulda # :nodoc:
30
29
  super(subject)
31
30
  @expected_message ||= :blank
32
31
  disallows_value_of(blank_value, @expected_message)
32
+ rescue Shoulda::Matchers::ActiveModel::CouldNotClearAttribute => error
33
+ if @attribute == :password
34
+ raise Shoulda::Matchers::ActiveModel::CouldNotSetPasswordError.create(subject.class)
35
+ else
36
+ raise error
37
+ end
33
38
  end
34
39
 
35
40
  def description
@@ -114,17 +114,30 @@ module Shoulda # :nodoc:
114
114
  end
115
115
 
116
116
  @subject.class.new.tap do |instance|
117
- instance.send("#{@attribute}=", value)
117
+ 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
+ if has_secure_password?
124
+ instance.password = 'password'
125
+ instance.password_confirmation = 'password'
126
+ end
118
127
  instance.save(validate: false)
119
128
  end
120
129
  end
121
130
 
131
+ def has_secure_password?
132
+ @subject.class.ancestors.map(&:to_s).include?('ActiveModel::SecurePassword::InstanceMethodsOnActivation')
133
+ end
134
+
122
135
  def set_scoped_attributes
123
136
  if @options[:scopes].present?
124
137
  @options[:scopes].all? do |scope|
125
138
  setter = :"#{scope}="
126
139
  if @subject.respond_to?(setter)
127
- @subject.send(setter, existing_record.send(scope))
140
+ @subject.__send__(setter, existing_record.__send__(scope))
128
141
  true
129
142
  else
130
143
  @failure_message = "#{class_name} doesn't seem to have a #{scope} attribute."
@@ -168,10 +181,10 @@ module Shoulda # :nodoc:
168
181
  previous_value.to_s.next
169
182
  end
170
183
 
171
- @subject.send("#{scope}=", next_value)
184
+ @subject.__send__("#{scope}=", next_value)
172
185
 
173
186
  if allows_value_of(existing_value, @expected_message)
174
- @subject.send("#{scope}=", previous_value)
187
+ @subject.__send__("#{scope}=", previous_value)
175
188
 
176
189
  @failure_message_when_negated <<
177
190
  " (with different value of #{scope})"
@@ -185,7 +198,7 @@ module Shoulda # :nodoc:
185
198
  end
186
199
 
187
200
  def correct_type_for_column(column)
188
- if column.type == :string
201
+ if column.type == :string || column.type == :binary
189
202
  '0'
190
203
  elsif column.type == :datetime
191
204
  DateTime.now
@@ -201,12 +214,18 @@ module Shoulda # :nodoc:
201
214
  end
202
215
 
203
216
  def existing_value
204
- value = existing_record.send(@attribute)
217
+ value = existing_record.__send__(@attribute)
205
218
  if @options[:case_insensitive] && value.respond_to?(:swapcase!)
206
219
  value.swapcase!
207
220
  end
208
221
  value
209
222
  end
223
+
224
+ def other_non_nullable_columns
225
+ @subject.class.columns.select do |column|
226
+ column.name != @attribute && !column.null && !column.primary
227
+ end
228
+ end
210
229
  end
211
230
  end
212
231
  end
@@ -1,5 +1,6 @@
1
1
  require 'shoulda/matchers/active_record/association_matcher'
2
2
  require 'shoulda/matchers/active_record/association_matchers/counter_cache_matcher'
3
+ require 'shoulda/matchers/active_record/association_matchers/inverse_of_matcher'
3
4
  require 'shoulda/matchers/active_record/association_matchers/order_matcher'
4
5
  require 'shoulda/matchers/active_record/association_matchers/through_matcher'
5
6
  require 'shoulda/matchers/active_record/association_matchers/dependent_matcher'
@@ -6,14 +6,17 @@ module Shoulda # :nodoc:
6
6
  # Ensure that the belongs_to relationship exists.
7
7
  #
8
8
  # Options:
9
- # * <tt>:class_name</tt> - tests that the association resolves to class_name.
10
- # * <tt>:validate</tt> - tests that the association makes use of the validate
9
+ # * <tt>class_name</tt> - tests that the association resolves to class_name.
10
+ # * <tt>validate</tt> - tests that the association makes use of the validate
11
11
  # option.
12
- # * <tt>:touch</tt> - tests that the association makes use of the touch
12
+ # * <tt>touch</tt> - tests that the association makes use of the touch
13
13
  # option.
14
14
  #
15
15
  # Example:
16
16
  # it { should belong_to(:parent) }
17
+ # it { should belong_to(:parent).touch }
18
+ # it { should belong_to(:parent).validate }
19
+ # it { should belong_to(:parent).class_name("ModelClassName") }
17
20
  #
18
21
  def belong_to(name)
19
22
  AssociationMatcher.new(:belongs_to, name)
@@ -27,14 +30,19 @@ module Shoulda # :nodoc:
27
30
  # * <tt>through</tt> - association name for <tt>has_many :through</tt>
28
31
  # * <tt>dependent</tt> - tests that the association makes use of the
29
32
  # dependent option.
30
- # * <tt>:class_name</tt> - tests that the association resoves to class_name.
31
- # * <tt>:validate</tt> - tests that the association makes use of the validate
33
+ # * <tt>class_name</tt> - tests that the association resoves to class_name.
34
+ # * <tt>autosave</tt> - tests that the association makes use of the
35
+ # autosave option.
36
+ # * <tt>validate</tt> - tests that the association makes use of the validate
32
37
  # option.
33
38
  #
34
39
  # Example:
35
40
  # it { should have_many(:friends) }
36
41
  # it { should have_many(:enemies).through(:friends) }
37
42
  # it { should have_many(:enemies).dependent(:destroy) }
43
+ # it { should have_many(:friends).autosave }
44
+ # it { should have_many(:friends).validate }
45
+ # it { should have_many(:friends).class_name("Friend") }
38
46
  #
39
47
  def have_many(name)
40
48
  AssociationMatcher.new(:has_many, name)
@@ -45,14 +53,20 @@ module Shoulda # :nodoc:
45
53
  # associations.
46
54
  #
47
55
  # Options:
48
- # * <tt>:dependent</tt> - tests that the association makes use of the
56
+ # * <tt>dependent</tt> - tests that the association makes use of the
49
57
  # dependent option.
50
- # * <tt>:class_name</tt> - tests that the association resolves to class_name.
51
- # * <tt>:validate</tt> - tests that the association makes use of the validate
58
+ # * <tt>class_name</tt> - tests that the association resolves to class_name.
59
+ # * <tt>autosave</tt> - tests that the association makes use of the
60
+ # autosave option.
61
+ # * <tt>validate</tt> - tests that the association makes use of the validate
52
62
  # option.
53
63
  #
54
64
  # Example:
55
65
  # it { should have_one(:god) } # unless hindu
66
+ # it { should have_one(:god).dependent }
67
+ # it { should have_one(:god).autosave }
68
+ # it { should have_one(:god).validate }
69
+ # it { should have_one(:god).class_name("JHVH1") }
56
70
  #
57
71
  def have_one(name)
58
72
  AssociationMatcher.new(:has_one, name)
@@ -62,12 +76,14 @@ module Shoulda # :nodoc:
62
76
  # the join table is in place.
63
77
  #
64
78
  # Options:
65
- # * <tt>:class_name</tt> - tests that the association resolves to class_name.
66
- # * <tt>:validate</tt> - tests that the association makes use of the validate
79
+ # * <tt>class_name</tt> - tests that the association resolves to class_name.
80
+ # * <tt>validate</tt> - tests that the association makes use of the validate
67
81
  # option.
68
82
  #
69
83
  # Example:
70
84
  # it { should have_and_belong_to_many(:posts) }
85
+ # it { should have_and_belong_to_many(:posts).validate }
86
+ # it { should have_and_belong_to_many(:posts).class_name("Post") }
71
87
  #
72
88
  def have_and_belong_to_many(name)
73
89
  AssociationMatcher.new(:has_and_belongs_to_many, name)
@@ -75,7 +91,7 @@ module Shoulda # :nodoc:
75
91
 
76
92
  class AssociationMatcher # :nodoc:
77
93
  delegate :reflection, :model_class, :associated_class, :through?,
78
- :join_table, to: :reflector
94
+ :join_table, :polymorphic?, to: :reflector
79
95
 
80
96
  def initialize(macro, name)
81
97
  @macro = macro
@@ -109,6 +125,13 @@ module Shoulda # :nodoc:
109
125
  self
110
126
  end
111
127
 
128
+ def inverse_of(inverse_of)
129
+ inverse_of_matcher =
130
+ AssociationMatchers::InverseOfMatcher.new(inverse_of, name)
131
+ add_submatcher(inverse_of_matcher)
132
+ self
133
+ end
134
+
112
135
  def source(source)
113
136
  source_matcher = AssociationMatchers::SourceMatcher.new(source, name)
114
137
  add_submatcher(source_matcher)
@@ -120,6 +143,11 @@ module Shoulda # :nodoc:
120
143
  self
121
144
  end
122
145
 
146
+ def autosave(autosave)
147
+ @options[:autosave] = autosave
148
+ self
149
+ end
150
+
123
151
  def class_name(class_name)
124
152
  @options[:class_name] = class_name
125
153
  self
@@ -160,8 +188,10 @@ module Shoulda # :nodoc:
160
188
  @subject = subject
161
189
  association_exists? &&
162
190
  macro_correct? &&
191
+ (polymorphic? || class_exists?) &&
163
192
  foreign_key_exists? &&
164
193
  class_name_correct? &&
194
+ autosave_correct? &&
165
195
  conditions_correct? &&
166
196
  join_table_exists? &&
167
197
  validate_correct? &&
@@ -224,6 +254,9 @@ module Shoulda # :nodoc:
224
254
  def macro_correct?
225
255
  if reflection.macro == macro
226
256
  true
257
+ elsif reflection.macro == :has_many
258
+ macro == :has_and_belongs_to_many &&
259
+ reflection.name == @name
227
260
  else
228
261
  @missing = "actual association type was #{reflection.macro}"
229
262
  false
@@ -257,6 +290,27 @@ module Shoulda # :nodoc:
257
290
  end
258
291
  end
259
292
 
293
+ def class_exists?
294
+ associated_class
295
+ true
296
+ rescue NameError
297
+ @missing = "#{reflection.class_name} does not exist"
298
+ false
299
+ end
300
+
301
+ def autosave_correct?
302
+ if options.key?(:autosave)
303
+ if option_verifier.correct_for_boolean?(:autosave, options[:autosave])
304
+ true
305
+ else
306
+ @missing = "#{name} should have autosave set to #{options[:autosave]}"
307
+ false
308
+ end
309
+ else
310
+ true
311
+ end
312
+ end
313
+
260
314
  def conditions_correct?
261
315
  if options.key?(:conditions)
262
316
  if option_verifier.correct_for_relation_clause?(:conditions, options[:conditions])
@@ -284,7 +338,7 @@ module Shoulda # :nodoc:
284
338
  if option_verifier.correct_for_boolean?(:validate, options[:validate])
285
339
  true
286
340
  else
287
- @missing = "#{name} should have :validate => #{options[:validate]}"
341
+ @missing = "#{name} should have validate: #{options[:validate]}"
288
342
  false
289
343
  end
290
344
  end
@@ -293,7 +347,7 @@ module Shoulda # :nodoc:
293
347
  if option_verifier.correct_for_boolean?(:touch, options[:touch])
294
348
  true
295
349
  else
296
- @missing = "#{name} should have :touch => #{options[:touch]}"
350
+ @missing = "#{name} should have touch: #{options[:touch]}"
297
351
  false
298
352
  end
299
353
  end
@@ -0,0 +1,40 @@
1
+ module Shoulda # :nodoc:
2
+ module Matchers
3
+ module ActiveRecord # :nodoc:
4
+ module AssociationMatchers
5
+ class InverseOfMatcher
6
+ attr_accessor :missing_option
7
+
8
+ def initialize(inverse_of, name)
9
+ @inverse_of = inverse_of
10
+ @name = name
11
+ @missing_option = ''
12
+ end
13
+
14
+ def description
15
+ "inverse_of => #{inverse_of}"
16
+ end
17
+
18
+ def matches?(subject)
19
+ self.subject = ModelReflector.new(subject, name)
20
+
21
+ if option_verifier.correct_for_string?(:inverse_of, inverse_of)
22
+ true
23
+ else
24
+ self.missing_option = "#{name} should have #{description}"
25
+ false
26
+ end
27
+ end
28
+
29
+ private
30
+
31
+ attr_accessor :subject, :inverse_of, :name
32
+
33
+ def option_verifier
34
+ @option_verifier ||= OptionVerifier.new(subject)
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -15,13 +15,19 @@ module Shoulda
15
15
  reflection.klass
16
16
  end
17
17
 
18
+ def polymorphic?
19
+ reflection.options[:polymorphic]
20
+ end
21
+
18
22
  def through?
19
23
  reflection.options[:through]
20
24
  end
21
25
 
22
26
  def join_table
23
27
  join_table =
24
- if reflection.respond_to?(:join_table)
28
+ if has_and_belongs_to_many_name_table_name
29
+ has_and_belongs_to_many_name_table_name
30
+ elsif reflection.respond_to?(:join_table)
25
31
  reflection.join_table
26
32
  else
27
33
  reflection.options[:join_table]
@@ -73,6 +79,23 @@ module Shoulda
73
79
  relation
74
80
  end
75
81
  end
82
+
83
+ def has_and_belongs_to_many_name
84
+ reflection.options[:through]
85
+ end
86
+
87
+ def has_and_belongs_to_many_name_table_name
88
+ if has_and_belongs_to_many_reflection
89
+ has_and_belongs_to_many_reflection.table_name
90
+ end
91
+ end
92
+
93
+ def has_and_belongs_to_many_reflection
94
+ @_has_and_belongs_to_many_reflection ||=
95
+ if has_and_belongs_to_many_name
96
+ @subject.reflect_on_association(has_and_belongs_to_many_name)
97
+ end
98
+ end
76
99
  end
77
100
  end
78
101
  end
@@ -4,7 +4,7 @@ module Shoulda # :nodoc:
4
4
  module AssociationMatchers
5
5
  class ModelReflector
6
6
  delegate :associated_class, :through?, :join_table,
7
- :association_relation, to: :reflection
7
+ :association_relation, :polymorphic?, to: :reflection
8
8
 
9
9
  def initialize(subject, name)
10
10
  @subject = subject
@@ -13,7 +13,7 @@ module Shoulda # :nodoc:
13
13
  # it { should_not have_db_column(:admin).of_type(:boolean) }
14
14
  # it { should have_db_column(:salary).
15
15
  # of_type(:decimal).
16
- # with_options(:precision => 10, :scale => 2) }
16
+ # with_options(precision: 10, scale: 2) }
17
17
  #
18
18
  def have_db_column(column)
19
19
  HaveDbColumnMatcher.new(column)
@@ -27,7 +27,7 @@ module Shoulda # :nodoc:
27
27
  @options = {}
28
28
  end
29
29
 
30
- def unique(unique)
30
+ def unique(unique = true)
31
31
  @options[:unique] = unique
32
32
  self
33
33
  end
@@ -7,8 +7,13 @@ module Shoulda
7
7
  # Test::Unit has been loaded already, so we use it
8
8
  AssertionError = Test::Unit::AssertionFailedError
9
9
  elsif Gem.ruby_version >= Gem::Version.new("1.9")
10
- require 'minitest/unit'
11
- AssertionError = MiniTest::Assertion
10
+ begin
11
+ require 'minitest'
12
+ rescue LoadError
13
+ require 'minitest/unit'
14
+ ensure
15
+ AssertionError = MiniTest::Assertion
16
+ end
12
17
  else
13
18
  raise 'No unit test library available'
14
19
  end
@@ -0,0 +1,24 @@
1
+ module Shoulda
2
+ module Matchers
3
+ class Error < StandardError
4
+ def self.create(attributes)
5
+ allocate.tap do |error|
6
+ attributes.each do |name, value|
7
+ error.__send__("#{name}=", value)
8
+ end
9
+
10
+ error.__send__(:initialize)
11
+ end
12
+ end
13
+
14
+ def initialize(*args)
15
+ super
16
+ @message = message
17
+ end
18
+
19
+ def message
20
+ ""
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,10 @@
1
+ require 'shoulda/matchers/independent/delegate_matcher'
2
+ require 'shoulda/matchers/independent/delegate_matcher/stubbed_target'
3
+
4
+ module Shoulda
5
+ module Matchers
6
+ # Matchers for non-Rails-dependent code.
7
+ module Independent
8
+ end
9
+ end
10
+ end