shoulda-matchers 2.4.0 → 2.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +7 -4
- data/Appraisals +19 -7
- data/Gemfile.lock +1 -1
- data/NEWS.md +35 -0
- data/README.md +1204 -46
- data/features/step_definitions/rails_steps.rb +1 -1
- data/gemfiles/3.0.gemfile.lock +1 -1
- data/gemfiles/3.1.gemfile.lock +1 -1
- data/gemfiles/3.2.gemfile.lock +1 -1
- data/gemfiles/{4.0.gemfile → 4.0.0.gemfile} +4 -4
- data/gemfiles/{4.0.gemfile.lock → 4.0.0.gemfile.lock} +24 -24
- data/gemfiles/4.0.1.gemfile +19 -0
- data/gemfiles/4.0.1.gemfile.lock +161 -0
- data/lib/shoulda/matchers/action_controller.rb +1 -0
- data/lib/shoulda/matchers/action_controller/filter_param_matcher.rb +4 -2
- data/lib/shoulda/matchers/action_controller/redirect_to_matcher.rb +6 -3
- data/lib/shoulda/matchers/action_controller/render_template_matcher.rb +6 -3
- data/lib/shoulda/matchers/action_controller/render_with_layout_matcher.rb +4 -2
- data/lib/shoulda/matchers/action_controller/rescue_from_matcher.rb +4 -2
- data/lib/shoulda/matchers/action_controller/respond_with_matcher.rb +4 -2
- data/lib/shoulda/matchers/action_controller/route_matcher.rb +13 -19
- data/lib/shoulda/matchers/action_controller/route_params.rb +47 -0
- data/lib/shoulda/matchers/action_controller/set_session_matcher.rb +4 -2
- data/lib/shoulda/matchers/action_controller/set_the_flash_matcher.rb +4 -2
- data/lib/shoulda/matchers/active_model.rb +4 -3
- data/lib/shoulda/matchers/active_model/allow_mass_assignment_of_matcher.rb +9 -6
- data/lib/shoulda/matchers/active_model/allow_value_matcher.rb +4 -2
- data/lib/shoulda/matchers/active_model/disallow_value_matcher.rb +6 -4
- data/lib/shoulda/matchers/active_model/ensure_inclusion_of_matcher.rb +4 -1
- data/lib/shoulda/matchers/active_model/ensure_length_of_matcher.rb +8 -1
- data/lib/shoulda/matchers/active_model/have_secure_password_matcher.rb +4 -2
- data/lib/shoulda/matchers/active_model/numericality_matchers/comparison_matcher.rb +59 -0
- data/lib/shoulda/matchers/active_model/numericality_matchers/odd_even_number_matcher.rb +51 -0
- data/lib/shoulda/matchers/active_model/numericality_matchers/only_integer_matcher.rb +41 -0
- data/lib/shoulda/matchers/active_model/validate_absence_of_matcher.rb +77 -0
- data/lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb +14 -12
- data/lib/shoulda/matchers/active_model/validate_uniqueness_of_matcher.rb +6 -6
- data/lib/shoulda/matchers/active_model/validation_matcher.rb +10 -7
- data/lib/shoulda/matchers/active_record.rb +2 -0
- data/lib/shoulda/matchers/active_record/accept_nested_attributes_for_matcher.rb +4 -2
- data/lib/shoulda/matchers/active_record/association_matcher.rb +11 -3
- data/lib/shoulda/matchers/active_record/association_matchers/model_reflection.rb +80 -0
- data/lib/shoulda/matchers/active_record/association_matchers/model_reflector.rb +20 -55
- data/lib/shoulda/matchers/active_record/association_matchers/source_matcher.rb +40 -0
- data/lib/shoulda/matchers/active_record/have_db_column_matcher.rb +4 -2
- data/lib/shoulda/matchers/active_record/have_db_index_matcher.rb +4 -2
- data/lib/shoulda/matchers/active_record/have_readonly_attribute_matcher.rb +7 -4
- data/lib/shoulda/matchers/active_record/serialize_matcher.rb +4 -2
- data/lib/shoulda/matchers/integrations/test_unit.rb +3 -3
- data/lib/shoulda/matchers/rails_shim.rb +14 -6
- data/lib/shoulda/matchers/version.rb +1 -1
- data/spec/shoulda/matchers/action_controller/filter_param_matcher_spec.rb +1 -1
- data/spec/shoulda/matchers/action_controller/rescue_from_matcher_spec.rb +2 -2
- data/spec/shoulda/matchers/action_controller/route_matcher_spec.rb +5 -0
- data/spec/shoulda/matchers/action_controller/route_params_spec.rb +30 -0
- data/spec/shoulda/matchers/active_model/allow_mass_assignment_of_matcher_spec.rb +1 -1
- data/spec/shoulda/matchers/active_model/allow_value_matcher_spec.rb +1 -1
- data/spec/shoulda/matchers/active_model/disallow_value_matcher_spec.rb +2 -2
- data/spec/shoulda/matchers/active_model/ensure_inclusion_of_matcher_spec.rb +10 -0
- data/spec/shoulda/matchers/active_model/ensure_length_of_matcher_spec.rb +7 -0
- data/spec/shoulda/matchers/active_model/{comparison_matcher_spec.rb → numericality_matchers/comparison_matcher_spec.rb} +2 -2
- data/spec/shoulda/matchers/active_model/{odd_even_number_matcher_spec.rb → numericality_matchers/odd_even_number_matcher_spec.rb} +4 -4
- data/spec/shoulda/matchers/active_model/{only_integer_matcher_spec.rb → numericality_matchers/only_integer_matcher_spec.rb} +3 -3
- data/spec/shoulda/matchers/active_model/validate_absence_of_matcher_spec.rb +139 -0
- data/spec/shoulda/matchers/active_model/validate_numericality_of_matcher_spec.rb +7 -7
- data/spec/shoulda/matchers/active_model/validate_uniqueness_of_matcher_spec.rb +48 -38
- data/spec/shoulda/matchers/active_record/accept_nested_attributes_for_matcher_spec.rb +6 -6
- data/spec/shoulda/matchers/active_record/association_matcher_spec.rb +21 -8
- data/spec/shoulda/matchers/active_record/association_matchers/model_reflection_spec.rb +247 -0
- data/spec/shoulda/matchers/active_record/have_readonly_attributes_matcher_spec.rb +1 -1
- data/spec/shoulda/matchers/active_record/serialize_matcher_spec.rb +3 -3
- data/spec/spec_helper.rb +9 -15
- data/spec/support/active_resource_builder.rb +2 -0
- data/spec/support/controller_builder.rb +4 -10
- data/spec/support/model_builder.rb +6 -2
- data/spec/support/rails_versions.rb +18 -0
- data/spec/support/shared_examples/numerical_submatcher_spec.rb +4 -4
- data/spec/support/test_application.rb +97 -0
- metadata +30 -14
- data/lib/shoulda/matchers/active_model/comparison_matcher.rb +0 -57
- data/lib/shoulda/matchers/active_model/odd_even_number_matcher.rb +0 -47
- data/lib/shoulda/matchers/active_model/only_integer_matcher.rb +0 -37
@@ -10,7 +10,7 @@ describe Shoulda::Matchers::ActiveRecord::AcceptNestedAttributesForMatcher do
|
|
10
10
|
|
11
11
|
matcher.matches?(rejecting_children).should be_false
|
12
12
|
|
13
|
-
matcher.
|
13
|
+
matcher.failure_message.
|
14
14
|
should eq 'Expected Parent to accept nested attributes for children (is not declared)'
|
15
15
|
end
|
16
16
|
|
@@ -32,7 +32,7 @@ describe Shoulda::Matchers::ActiveRecord::AcceptNestedAttributesForMatcher do
|
|
32
32
|
matching = accepting_children(:allow_destroy => true)
|
33
33
|
|
34
34
|
matcher.allow_destroy(false).matches?(matching).should be_false
|
35
|
-
matcher.
|
35
|
+
matcher.failure_message.should =~ /should not allow destroy/
|
36
36
|
end
|
37
37
|
|
38
38
|
it 'rejects an invalid falsey value' do
|
@@ -40,7 +40,7 @@ describe Shoulda::Matchers::ActiveRecord::AcceptNestedAttributesForMatcher do
|
|
40
40
|
matching = accepting_children(:allow_destroy => false)
|
41
41
|
|
42
42
|
matcher.allow_destroy(true).matches?(matching).should be_false
|
43
|
-
matcher.
|
43
|
+
matcher.failure_message.should =~ /should allow destroy/
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
@@ -54,7 +54,7 @@ describe Shoulda::Matchers::ActiveRecord::AcceptNestedAttributesForMatcher do
|
|
54
54
|
rejecting = accepting_children(:limit => 3)
|
55
55
|
|
56
56
|
matcher.limit(2).matches?(rejecting).should be_false
|
57
|
-
matcher.
|
57
|
+
matcher.failure_message.should =~ /limit should be 2, got 3/
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
@@ -74,7 +74,7 @@ describe Shoulda::Matchers::ActiveRecord::AcceptNestedAttributesForMatcher do
|
|
74
74
|
rejecting = accepting_children(:update_only => true)
|
75
75
|
|
76
76
|
matcher.matches?(rejecting).should be_false
|
77
|
-
matcher.
|
77
|
+
matcher.failure_message.should =~ /should not be update only/
|
78
78
|
end
|
79
79
|
|
80
80
|
it 'rejects an invalid falsey value' do
|
@@ -82,7 +82,7 @@ describe Shoulda::Matchers::ActiveRecord::AcceptNestedAttributesForMatcher do
|
|
82
82
|
rejecting = accepting_children(:update_only => false)
|
83
83
|
|
84
84
|
matcher.matches?(rejecting).should be_false
|
85
|
-
matcher.
|
85
|
+
matcher.failure_message.should =~ /should be update only/
|
86
86
|
end
|
87
87
|
end
|
88
88
|
|
@@ -247,7 +247,7 @@ describe Shoulda::Matchers::ActiveRecord::AssociationMatcher do
|
|
247
247
|
|
248
248
|
matcher.matches?(having_many_children).should be_false
|
249
249
|
|
250
|
-
matcher.
|
250
|
+
matcher.failure_message.should =~ /does not have any relationship to conceptions/
|
251
251
|
end
|
252
252
|
|
253
253
|
it 'rejects an association that has the wrong :through option' do
|
@@ -266,7 +266,7 @@ describe Shoulda::Matchers::ActiveRecord::AssociationMatcher do
|
|
266
266
|
|
267
267
|
matcher = have_many(:children).through(:relationships)
|
268
268
|
matcher.matches?(Parent.new).should be_false
|
269
|
-
matcher.
|
269
|
+
matcher.failure_message.should =~ /through relationships, but got it through conceptions/
|
270
270
|
end
|
271
271
|
|
272
272
|
it 'accepts an association with a valid :dependent option' do
|
@@ -279,7 +279,20 @@ describe Shoulda::Matchers::ActiveRecord::AssociationMatcher do
|
|
279
279
|
|
280
280
|
having_many_children.should_not matcher
|
281
281
|
|
282
|
-
matcher.
|
282
|
+
matcher.failure_message.should =~ /children should have destroy dependency/
|
283
|
+
end
|
284
|
+
|
285
|
+
it 'accepts an association with a valid :source option' do
|
286
|
+
having_many_children(:source => :user).
|
287
|
+
should have_many(:children).source(:user)
|
288
|
+
end
|
289
|
+
|
290
|
+
it 'rejects an association with a bad :source option' do
|
291
|
+
matcher = have_many(:children).source(:user)
|
292
|
+
|
293
|
+
having_many_children.should_not matcher
|
294
|
+
|
295
|
+
matcher.failure_message.should =~ /children should have user as source option/
|
283
296
|
end
|
284
297
|
|
285
298
|
it 'accepts an association with a valid :order option' do
|
@@ -292,7 +305,7 @@ describe Shoulda::Matchers::ActiveRecord::AssociationMatcher do
|
|
292
305
|
|
293
306
|
having_many_children.should_not matcher
|
294
307
|
|
295
|
-
matcher.
|
308
|
+
matcher.failure_message.should =~ /children should be ordered by id/
|
296
309
|
end
|
297
310
|
|
298
311
|
it 'accepts an association with a valid :conditions option' do
|
@@ -437,7 +450,7 @@ describe Shoulda::Matchers::ActiveRecord::AssociationMatcher do
|
|
437
450
|
|
438
451
|
having_one_detail.should_not matcher
|
439
452
|
|
440
|
-
matcher.
|
453
|
+
matcher.failure_message.should =~ /detail should have destroy dependency/
|
441
454
|
end
|
442
455
|
|
443
456
|
it 'accepts an association with a valid :order option' do
|
@@ -449,7 +462,7 @@ describe Shoulda::Matchers::ActiveRecord::AssociationMatcher do
|
|
449
462
|
|
450
463
|
having_one_detail.should_not matcher
|
451
464
|
|
452
|
-
matcher.
|
465
|
+
matcher.failure_message.should =~ /detail should be ordered by id/
|
453
466
|
end
|
454
467
|
|
455
468
|
it 'accepts an association with a valid :conditions option' do
|
@@ -652,7 +665,7 @@ describe Shoulda::Matchers::ActiveRecord::AssociationMatcher do
|
|
652
665
|
def define_association_with_conditions(model, macro, name, conditions, other_options={})
|
653
666
|
args = []
|
654
667
|
options = {}
|
655
|
-
if Shoulda::Matchers::RailsShim.
|
668
|
+
if Shoulda::Matchers::RailsShim.active_record_major_version == 4
|
656
669
|
args << lambda { where(conditions) }
|
657
670
|
else
|
658
671
|
options[:conditions] = conditions
|
@@ -664,7 +677,7 @@ describe Shoulda::Matchers::ActiveRecord::AssociationMatcher do
|
|
664
677
|
def define_association_with_order(model, macro, name, order, other_options={})
|
665
678
|
args = []
|
666
679
|
options = {}
|
667
|
-
if Shoulda::Matchers::RailsShim.
|
680
|
+
if Shoulda::Matchers::RailsShim.active_record_major_version == 4
|
668
681
|
args << lambda { order(order) }
|
669
682
|
else
|
670
683
|
options[:order] = order
|
@@ -0,0 +1,247 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Shoulda::Matchers::ActiveRecord::AssociationMatchers::ModelReflection do
|
4
|
+
it 'delegates other methods to the given Reflection object' do
|
5
|
+
define_model(:country)
|
6
|
+
person_model = define_model(:person, country_id: :integer) do
|
7
|
+
belongs_to :country
|
8
|
+
end
|
9
|
+
delegate_reflection = person_model.reflect_on_association(:country)
|
10
|
+
delegate_reflection.stubs(foo: 'bar')
|
11
|
+
reflection = described_class.new(delegate_reflection)
|
12
|
+
|
13
|
+
expect(reflection.foo).to eq 'bar'
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '#associated_class' do
|
17
|
+
it 'returns the model that the association refers to' do
|
18
|
+
define_model(:country)
|
19
|
+
person_model = define_model(:person, country_id: :integer) do
|
20
|
+
belongs_to :country
|
21
|
+
end
|
22
|
+
delegate_reflection = person_model.reflect_on_association(:country)
|
23
|
+
reflection = described_class.new(delegate_reflection)
|
24
|
+
|
25
|
+
expect(reflection.associated_class).to be Country
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe '#through?' do
|
30
|
+
it 'returns true if the reflection is for a has_many :through association' do
|
31
|
+
define_model(:city, person_id: :integer)
|
32
|
+
define_model(:person, country_id: :integer) do
|
33
|
+
has_many :cities
|
34
|
+
end
|
35
|
+
country_model = define_model(:country) do
|
36
|
+
has_many :people
|
37
|
+
has_many :cities, through: :people
|
38
|
+
end
|
39
|
+
delegate_reflection = country_model.reflect_on_association(:cities)
|
40
|
+
reflection = described_class.new(delegate_reflection)
|
41
|
+
|
42
|
+
expect(reflection).to be_through
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'returns false if not' do
|
46
|
+
define_model(:person, country_id: :integer)
|
47
|
+
country_model = define_model(:country) do
|
48
|
+
has_many :people
|
49
|
+
end
|
50
|
+
delegate_reflection = country_model.reflect_on_association(:people)
|
51
|
+
reflection = described_class.new(delegate_reflection)
|
52
|
+
|
53
|
+
expect(reflection).not_to be_through
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe '#join_table' do
|
58
|
+
context 'when the association was defined with a :join_table option' do
|
59
|
+
it 'returns the value of the option' do
|
60
|
+
define_model(:person, country_id: :integer)
|
61
|
+
country_model = define_model(:country) do
|
62
|
+
has_and_belongs_to_many :people, join_table: 'foos'
|
63
|
+
end
|
64
|
+
delegate_reflection = country_model.reflect_on_association(:people)
|
65
|
+
reflection = described_class.new(delegate_reflection)
|
66
|
+
|
67
|
+
expect(reflection.join_table).to eq 'foos'
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context 'when the association was not defined with :join_table' do
|
72
|
+
it 'returns the default join_table that ActiveRecord generates' do
|
73
|
+
define_model(:person, country_id: :integer)
|
74
|
+
country_model = define_model(:country) do
|
75
|
+
has_and_belongs_to_many :people
|
76
|
+
end
|
77
|
+
delegate_reflection = country_model.reflect_on_association(:people)
|
78
|
+
reflection = described_class.new(delegate_reflection)
|
79
|
+
|
80
|
+
expect(reflection.join_table).to eq 'countries_people'
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe '#association_relation' do
|
86
|
+
if rails_4_x?
|
87
|
+
context 'when the reflection object has a #scope method' do
|
88
|
+
context 'when the scope is a block' do
|
89
|
+
it 'executes the block in the context of an empty scope' do
|
90
|
+
define_model(:country, mood: :string)
|
91
|
+
person_model = define_model(:person, country_id: :integer) do
|
92
|
+
belongs_to :country, -> { where(mood: 'nice') }
|
93
|
+
end
|
94
|
+
delegate_reflection = person_model.reflect_on_association(:country)
|
95
|
+
reflection = described_class.new(delegate_reflection)
|
96
|
+
|
97
|
+
actual_sql = reflection.association_relation.to_sql
|
98
|
+
expected_sql = Country.where(mood: 'nice').to_sql
|
99
|
+
expect(actual_sql).to eq expected_sql
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
context 'when the scope is nil' do
|
104
|
+
it 'returns an empty scope' do
|
105
|
+
define_model(:country)
|
106
|
+
person_model = define_model(:person, country_id: :integer) do
|
107
|
+
belongs_to :country
|
108
|
+
end
|
109
|
+
delegate_reflection = person_model.reflect_on_association(:country)
|
110
|
+
reflection = described_class.new(delegate_reflection)
|
111
|
+
|
112
|
+
actual_sql = reflection.association_relation.to_sql
|
113
|
+
expected_sql = Country.all.to_sql
|
114
|
+
expect(actual_sql).to eq expected_sql
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
if rails_3_x?
|
121
|
+
context 'when the reflection object does not have a #scope method' do
|
122
|
+
context 'when the reflection options contain :conditions' do
|
123
|
+
it 'creates an ActiveRecord::Relation from the conditions' do
|
124
|
+
define_model(:country, mood: :string)
|
125
|
+
person_model = define_model(:person, country_id: :integer) do
|
126
|
+
belongs_to :country, conditions: { mood: 'nice' }
|
127
|
+
end
|
128
|
+
delegate_reflection = person_model.reflect_on_association(:country)
|
129
|
+
reflection = described_class.new(delegate_reflection)
|
130
|
+
|
131
|
+
actual_sql = reflection.association_relation.to_sql
|
132
|
+
expected_sql = Country.where(mood: 'nice').to_sql
|
133
|
+
expect(actual_sql).to eq expected_sql
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
context 'when the reflection options contain :order' do
|
138
|
+
it 'creates an ActiveRecord::Relation from the order' do
|
139
|
+
define_model(:person, country_id: :integer, age: :integer)
|
140
|
+
country_model = define_model(:country) do
|
141
|
+
has_many :people, order: 'age'
|
142
|
+
end
|
143
|
+
delegate_reflection = country_model.reflect_on_association(:people)
|
144
|
+
reflection = described_class.new(delegate_reflection)
|
145
|
+
|
146
|
+
actual_sql = reflection.association_relation.to_sql
|
147
|
+
expected_sql = Person.order('age').to_sql
|
148
|
+
expect(actual_sql).to eq expected_sql
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
context 'when the reflection options contain :include' do
|
153
|
+
it 'creates an ActiveRecord::Relation from the include' do
|
154
|
+
define_model(:city, country_id: :integer)
|
155
|
+
define_model(:country) do
|
156
|
+
has_many :cities
|
157
|
+
end
|
158
|
+
person_model = define_model(:person, country_id: :integer) do
|
159
|
+
belongs_to :country, include: :cities
|
160
|
+
end
|
161
|
+
delegate_reflection = person_model.reflect_on_association(:country)
|
162
|
+
reflection = described_class.new(delegate_reflection)
|
163
|
+
|
164
|
+
actual_includes = reflection.association_relation.includes_values
|
165
|
+
expected_includes = Country.includes(:cities).includes_values
|
166
|
+
expect(actual_includes).to eq expected_includes
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
context 'when the reflection options contain :group' do
|
171
|
+
it 'creates an ActiveRecord::Relation from the group' do
|
172
|
+
country_model = define_model(:country, mood: :string) do
|
173
|
+
has_many :people, group: 'age'
|
174
|
+
end
|
175
|
+
define_model(:person, country_id: :integer, age: :integer)
|
176
|
+
delegate_reflection = country_model.reflect_on_association(:people)
|
177
|
+
reflection = described_class.new(delegate_reflection)
|
178
|
+
|
179
|
+
actual_sql = reflection.association_relation.to_sql
|
180
|
+
expected_sql = Person.group('age').to_sql
|
181
|
+
expect(actual_sql).to eq expected_sql
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
context 'when the reflection options contain :having' do
|
186
|
+
it 'creates an ActiveRecord::Relation from the having' do
|
187
|
+
country_model = define_model(:country) do
|
188
|
+
has_many :people, having: 'country_id > 1'
|
189
|
+
end
|
190
|
+
define_model(:person, country_id: :integer)
|
191
|
+
delegate_reflection = country_model.reflect_on_association(:people)
|
192
|
+
reflection = described_class.new(delegate_reflection)
|
193
|
+
|
194
|
+
actual_sql = reflection.association_relation.to_sql
|
195
|
+
expected_sql = Person.having('country_id > 1').to_sql
|
196
|
+
expect(actual_sql).to eq expected_sql
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
context 'when the reflection options contain :limit' do
|
201
|
+
it 'creates an ActiveRecord::Relation from the limit' do
|
202
|
+
country_model = define_model(:country) do
|
203
|
+
has_many :people, limit: 10
|
204
|
+
end
|
205
|
+
define_model(:person, country_id: :integer)
|
206
|
+
delegate_reflection = country_model.reflect_on_association(:people)
|
207
|
+
reflection = described_class.new(delegate_reflection)
|
208
|
+
|
209
|
+
actual_sql = reflection.association_relation.to_sql
|
210
|
+
expected_sql = Person.limit(10).to_sql
|
211
|
+
expect(actual_sql).to eq expected_sql
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
context 'when the reflection options contain :offset' do
|
216
|
+
it 'creates an ActiveRecord::Relation from the offset' do
|
217
|
+
country_model = define_model(:country) do
|
218
|
+
has_many :people, offset: 5
|
219
|
+
end
|
220
|
+
define_model(:person, country_id: :integer)
|
221
|
+
delegate_reflection = country_model.reflect_on_association(:people)
|
222
|
+
reflection = described_class.new(delegate_reflection)
|
223
|
+
|
224
|
+
actual_sql = reflection.association_relation.to_sql
|
225
|
+
expected_sql = Person.offset(5).to_sql
|
226
|
+
expect(actual_sql).to eq expected_sql
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
context 'when the reflection options contain :select' do
|
231
|
+
it 'creates an ActiveRecord::Relation from the select' do
|
232
|
+
country_model = define_model(:country) do
|
233
|
+
has_many :people, select: 'age'
|
234
|
+
end
|
235
|
+
define_model(:person, country_id: :integer, age: :integer)
|
236
|
+
delegate_reflection = country_model.reflect_on_association(:people)
|
237
|
+
reflection = described_class.new(delegate_reflection)
|
238
|
+
|
239
|
+
actual_sql = reflection.association_relation.to_sql
|
240
|
+
expected_sql = Person.select('age').to_sql
|
241
|
+
expect(actual_sql).to eq expected_sql
|
242
|
+
end
|
243
|
+
end
|
244
|
+
end
|
245
|
+
end
|
246
|
+
end
|
247
|
+
end
|
@@ -15,7 +15,7 @@ describe Shoulda::Matchers::ActiveRecord::SerializeMatcher do
|
|
15
15
|
|
16
16
|
matcher.matches?(unserialized_model)
|
17
17
|
|
18
|
-
matcher.
|
18
|
+
matcher.failure_message.should =~ /to serialize the attribute called :attr/
|
19
19
|
end
|
20
20
|
|
21
21
|
it 'assigns a helpful failure message when using #as' do
|
@@ -23,7 +23,7 @@ describe Shoulda::Matchers::ActiveRecord::SerializeMatcher do
|
|
23
23
|
|
24
24
|
matcher.matches?(unserialized_model)
|
25
25
|
|
26
|
-
matcher.
|
26
|
+
matcher.failure_message.should =~ /with a type of Hash/
|
27
27
|
end
|
28
28
|
|
29
29
|
it 'assigns a helpful failure message when using #as_instance_of' do
|
@@ -31,7 +31,7 @@ describe Shoulda::Matchers::ActiveRecord::SerializeMatcher do
|
|
31
31
|
|
32
32
|
matcher.matches?(unserialized_model)
|
33
33
|
|
34
|
-
matcher.
|
34
|
+
matcher.failure_message.should =~ /with an instance of Hash/
|
35
35
|
end
|
36
36
|
|
37
37
|
def unserialized_model
|
data/spec/spec_helper.rb
CHANGED
@@ -1,28 +1,22 @@
|
|
1
|
-
|
2
|
-
TESTAPP_ROOT = File.join(File.dirname(__FILE__), '..', 'tmp', 'aruba', 'testapp')
|
3
|
-
FileUtils.rm_rf(TESTAPP_ROOT) if File.exists?(TESTAPP_ROOT)
|
4
|
-
`rails new #{TESTAPP_ROOT}`
|
1
|
+
require File.expand_path('../support/test_application', __FILE__)
|
5
2
|
|
3
|
+
$test_app = TestApplication.new
|
4
|
+
$test_app.create
|
5
|
+
$test_app.load
|
6
|
+
|
7
|
+
ENV['BUNDLE_GEMFILE'] ||= app.gemfile_path
|
6
8
|
ENV['RAILS_ENV'] = 'test'
|
7
|
-
ENV['BUNDLE_GEMFILE'] ||= TESTAPP_ROOT + '/Gemfile'
|
8
9
|
|
9
|
-
require "#{TESTAPP_ROOT}/config/environment"
|
10
10
|
require 'bourne'
|
11
11
|
require 'shoulda-matchers'
|
12
12
|
require 'rspec/rails'
|
13
13
|
|
14
|
-
PROJECT_ROOT = File.expand_path(
|
15
|
-
|
14
|
+
PROJECT_ROOT = File.expand_path('../..', __FILE__)
|
16
15
|
$LOAD_PATH << File.join(PROJECT_ROOT, 'lib')
|
17
|
-
|
18
|
-
Dir[File.join(PROJECT_ROOT, 'spec', 'support', '**', '*.rb')].each { |file| require(file) }
|
19
|
-
|
20
|
-
# Run the migrations
|
21
|
-
ActiveRecord::Migration.verbose = false
|
22
|
-
ActiveRecord::Migrator.migrate(Rails.root.join('db/migrate'))
|
16
|
+
Dir[ File.join(PROJECT_ROOT, 'spec/support/**/*.rb') ].each { |file| require file }
|
23
17
|
|
24
18
|
RSpec.configure do |config|
|
25
19
|
config.mock_with :mocha
|
26
20
|
config.include Shoulda::Matchers::ActionController,
|
27
|
-
:
|
21
|
+
example_group: { file_path: /action_controller/ }
|
28
22
|
end
|