Skip to content

Commit 0e6db54

Browse files
authored
Remove code for unsupported versions (#1270)
1 parent d97bdd6 commit 0e6db54

File tree

9 files changed

+48
-259
lines changed

9 files changed

+48
-259
lines changed

lib/shoulda/matchers/active_record/have_db_column_matcher.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ def initialize(model, column)
269269
end
270270

271271
def type_cast_default
272-
Shoulda::Matchers::RailsShim.type_cast_default_for(model, self)
272+
model.column_defaults[name]
273273
end
274274

275275
def primary?

lib/shoulda/matchers/rails_shim.rb

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@ module Matchers
33
# @private
44
module RailsShim
55
class << self
6-
def action_pack_gte_4_1?
7-
Gem::Requirement.new('>= 4.1').satisfied_by?(action_pack_version)
8-
end
9-
106
def action_pack_gte_5?
117
Gem::Requirement.new('>= 5').satisfied_by?(action_pack_version)
128
end
@@ -85,15 +81,6 @@ def attribute_serialization_coder_for(model, attribute_name)
8581
serialized_attributes_for(model)[attribute_name.to_s]
8682
end
8783

88-
def type_cast_default_for(model, column)
89-
if model.respond_to?(:column_defaults)
90-
# Rails 4.2
91-
model.column_defaults[column.name]
92-
else
93-
column.default
94-
end
95-
end
96-
9784
def tables_and_views(connection)
9885
if active_record_gte_5?
9986
connection.data_sources
@@ -103,11 +90,7 @@ def tables_and_views(connection)
10390
end
10491

10592
def verb_for_update
106-
if action_pack_gte_4_1?
107-
:patch
108-
else
109-
:put
110-
end
93+
:patch
11194
end
11295

11396
def validation_message_key_for_association_required_option

spec/support/acceptance/helpers/n_unit_helpers.rb

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,7 @@ def n_unit_test_case_superclass
1313
end
1414

1515
def default_test_framework
16-
if rails_version =~ '< 4'
17-
:test_unit
18-
elsif rails_version =~ '~> 4.0.0'
19-
:minitest_4
20-
else
21-
:minitest
22-
end
16+
:minitest
2317
end
2418
end
2519
end

spec/support/acceptance/helpers/step_helpers.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,6 @@ def run_rspec_suite
112112
end
113113

114114
def add_spring_to_project
115-
if rails_version < 4
116-
add_gem 'spring'
117-
end
118-
119115
add_gem 'spring-commands-rspec'
120116
end
121117
end

spec/support/unit/helpers/rails_versions.rb

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,6 @@ def rails_version
1111
Tests::Version.new(Rails::VERSION::STRING)
1212
end
1313

14-
def rails_3_x?
15-
rails_version =~ '~> 3.0'
16-
end
17-
18-
def rails_4_x?
19-
rails_version =~ '~> 4.0'
20-
end
21-
22-
def rails_lte_4?
23-
rails_version <= 4
24-
end
25-
26-
def rails_gte_4_1?
27-
rails_version >= 4.1
28-
end
29-
30-
def rails_gte_4_2?
31-
rails_version >= 4.2
32-
end
33-
3414
def rails_lt_5?
3515
rails_version < 5
3616
end

spec/unit/shoulda/matchers/action_controller/permit_matcher_spec.rb

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -508,36 +508,19 @@ def params_with_conditional_require(params, *filters)
508508
end
509509

510510
context 'when given :update' do
511-
if rails_gte_4_1?
512-
it 'PATCHes to the controller' do
513-
controller = ActionController::Base.new
514-
context = build_context
515-
matcher = permit(:name).for(:update).in_context(context)
516-
517-
matcher.matches?(controller)
518-
519-
expect_to_have_made_controller_request(
520-
verb: :patch,
521-
action: :update,
522-
params: {},
523-
context: context,
524-
)
525-
end
526-
else
527-
it 'PUTs to the controller' do
528-
controller = ActionController::Base.new
529-
context = build_context
530-
matcher = permit(:name).for(:update).in_context(context)
511+
it 'PATCHes to the controller' do
512+
controller = ActionController::Base.new
513+
context = build_context
514+
matcher = permit(:name).for(:update).in_context(context)
531515

532-
matcher.matches?(controller)
516+
matcher.matches?(controller)
533517

534-
expect_to_have_made_controller_request(
535-
verb: :put,
536-
action: :update,
537-
params: {},
538-
context: context,
539-
)
540-
end
518+
expect_to_have_made_controller_request(
519+
verb: :patch,
520+
action: :update,
521+
params: {},
522+
context: context,
523+
)
541524
end
542525
end
543526

spec/unit/shoulda/matchers/active_model/validate_presence_of_matcher_spec.rb

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -946,37 +946,23 @@ def record_belonging_to(
946946
end
947947
end
948948

949-
if rails_lte_4?
950-
context 'an active_resource model' do
951-
context 'with the validation context' do
952-
it 'does not raise an exception' do
953-
expect do
954-
expect(active_resource_model).to validate_presence_of(:attr)
955-
end.to_not raise_exception
956-
end
949+
context 'against a pre-set password in a model that has_secure_password' do
950+
it 'raises a CouldNotSetPasswordError' do
951+
user_class = define_model :user, password_digest: :string do
952+
has_secure_password validations: false
953+
validates_presence_of :password
957954
end
958-
end
959-
end
960955

961-
if rails_4_x?
962-
context 'against a pre-set password in a model that has_secure_password' do
963-
it 'raises a CouldNotSetPasswordError' do
964-
user_class = define_model :user, password_digest: :string do
965-
has_secure_password validations: false
966-
validates_presence_of :password
967-
end
968-
969-
user = user_class.new
970-
user.password = 'something'
956+
user = user_class.new
957+
user.password = 'something'
971958

972-
assertion = lambda do
973-
expect(user).to validate_presence_of(:password)
974-
end
975-
976-
expect(&assertion).to raise_error(
977-
Shoulda::Matchers::ActiveModel::CouldNotSetPasswordError
978-
)
959+
assertion = lambda do
960+
expect(user).to validate_presence_of(:password)
979961
end
962+
963+
expect(&assertion).to raise_error(
964+
Shoulda::Matchers::ActiveModel::CouldNotSetPasswordError
965+
)
980966
end
981967
end
982968

spec/unit/shoulda/matchers/active_record/association_matchers/model_reflection_spec.rb

Lines changed: 21 additions & 150 deletions
Original file line numberDiff line numberDiff line change
@@ -87,163 +87,34 @@
8787
end
8888

8989
describe '#association_relation' do
90-
if rails_4_x?
91-
context 'when the reflection object has a #scope method' do
92-
context 'when the scope is a block' do
93-
it 'executes the block in the context of an empty scope' do
94-
define_model(:country, mood: :string)
95-
person_model = define_model(:person, country_id: :integer) do
96-
belongs_to :country, -> { where(mood: 'nice') }
97-
end
98-
delegate_reflection = person_model.reflect_on_association(:country)
99-
reflection = described_class.new(delegate_reflection)
100-
101-
actual_sql = reflection.association_relation.to_sql
102-
expected_sql = Country.where(mood: 'nice').to_sql
103-
expect(actual_sql).to eq expected_sql
90+
context 'when the reflection object has a #scope method' do
91+
context 'when the scope is a block' do
92+
it 'executes the block in the context of an empty scope' do
93+
define_model(:country, mood: :string)
94+
person_model = define_model(:person, country_id: :integer) do
95+
belongs_to :country, -> { where(mood: 'nice') }
10496
end
105-
end
97+
delegate_reflection = person_model.reflect_on_association(:country)
98+
reflection = described_class.new(delegate_reflection)
10699

107-
context 'when the scope is nil' do
108-
it 'returns an empty scope' do
109-
define_model(:country)
110-
person_model = define_model(:person, country_id: :integer) do
111-
belongs_to :country
112-
end
113-
delegate_reflection = person_model.reflect_on_association(:country)
114-
reflection = described_class.new(delegate_reflection)
115-
116-
actual_sql = reflection.association_relation.to_sql
117-
expected_sql = Country.all.to_sql
118-
expect(actual_sql).to eq expected_sql
119-
end
100+
actual_sql = reflection.association_relation.to_sql
101+
expected_sql = Country.where(mood: 'nice').to_sql
102+
expect(actual_sql).to eq expected_sql
120103
end
121104
end
122-
end
123-
124-
if rails_3_x?
125-
context 'when the reflection object does not have a #scope method' do
126-
context 'when the reflection options contain :conditions' do
127-
it 'creates an ActiveRecord::Relation from the conditions' do
128-
define_model(:country, mood: :string)
129-
person_model = define_model(:person, country_id: :integer) do
130-
belongs_to :country, conditions: { mood: 'nice' }
131-
end
132-
delegate_reflection = person_model.reflect_on_association(:country)
133-
reflection = described_class.new(delegate_reflection)
134-
135-
actual_sql = reflection.association_relation.to_sql
136-
expected_sql = Country.where(mood: 'nice').to_sql
137-
expect(actual_sql).to eq expected_sql
138-
end
139-
end
140105

141-
context 'when the reflection options contain :order' do
142-
it 'creates an ActiveRecord::Relation from the order' do
143-
define_model(:person, country_id: :integer, age: :integer)
144-
country_model = define_model(:country) do
145-
has_many :people, order: 'age'
146-
end
147-
delegate_reflection = country_model.reflect_on_association(:people)
148-
reflection = described_class.new(delegate_reflection)
149-
150-
actual_sql = reflection.association_relation.to_sql
151-
expected_sql = Person.order('age').to_sql
152-
expect(actual_sql).to eq expected_sql
106+
context 'when the scope is nil' do
107+
it 'returns an empty scope' do
108+
define_model(:country)
109+
person_model = define_model(:person, country_id: :integer) do
110+
belongs_to :country
153111
end
154-
end
155-
156-
context 'when the reflection options contain :include' do
157-
it 'creates an ActiveRecord::Relation from the include' do
158-
define_model(:city, country_id: :integer)
159-
define_model(:country) do
160-
has_many :cities
161-
end
162-
person_model = define_model(:person, country_id: :integer) do
163-
belongs_to :country, include: :cities
164-
end
165-
delegate_reflection = person_model.reflect_on_association(:country)
166-
reflection = described_class.new(delegate_reflection)
167-
168-
actual_includes = reflection.association_relation.includes_values
169-
expected_includes = Country.includes(:cities).includes_values
170-
expect(actual_includes).to eq expected_includes
171-
end
172-
end
112+
delegate_reflection = person_model.reflect_on_association(:country)
113+
reflection = described_class.new(delegate_reflection)
173114

174-
context 'when the reflection options contain :group' do
175-
it 'creates an ActiveRecord::Relation from the group' do
176-
country_model = define_model(:country, mood: :string) do
177-
has_many :people, group: 'age'
178-
end
179-
define_model(:person, country_id: :integer, age: :integer)
180-
delegate_reflection = country_model.reflect_on_association(:people)
181-
reflection = described_class.new(delegate_reflection)
182-
183-
actual_sql = reflection.association_relation.to_sql
184-
expected_sql = Person.group('age').to_sql
185-
expect(actual_sql).to eq expected_sql
186-
end
187-
end
188-
189-
context 'when the reflection options contain :having' do
190-
it 'creates an ActiveRecord::Relation from the having' do
191-
country_model = define_model(:country) do
192-
has_many :people, having: 'country_id > 1'
193-
end
194-
define_model(:person, country_id: :integer)
195-
delegate_reflection = country_model.reflect_on_association(:people)
196-
reflection = described_class.new(delegate_reflection)
197-
198-
actual_sql = reflection.association_relation.to_sql
199-
expected_sql = Person.having('country_id > 1').to_sql
200-
expect(actual_sql).to eq expected_sql
201-
end
202-
end
203-
204-
context 'when the reflection options contain :limit' do
205-
it 'creates an ActiveRecord::Relation from the limit' do
206-
country_model = define_model(:country) do
207-
has_many :people, limit: 10
208-
end
209-
define_model(:person, country_id: :integer)
210-
delegate_reflection = country_model.reflect_on_association(:people)
211-
reflection = described_class.new(delegate_reflection)
212-
213-
actual_sql = reflection.association_relation.to_sql
214-
expected_sql = Person.limit(10).to_sql
215-
expect(actual_sql).to eq expected_sql
216-
end
217-
end
218-
219-
context 'when the reflection options contain :offset' do
220-
it 'creates an ActiveRecord::Relation from the offset' do
221-
country_model = define_model(:country) do
222-
has_many :people, offset: 5
223-
end
224-
define_model(:person, country_id: :integer)
225-
delegate_reflection = country_model.reflect_on_association(:people)
226-
reflection = described_class.new(delegate_reflection)
227-
228-
actual_sql = reflection.association_relation.to_sql
229-
expected_sql = Person.offset(5).to_sql
230-
expect(actual_sql).to eq expected_sql
231-
end
232-
end
233-
234-
context 'when the reflection options contain :select' do
235-
it 'creates an ActiveRecord::Relation from the select' do
236-
country_model = define_model(:country) do
237-
has_many :people, select: 'age'
238-
end
239-
define_model(:person, country_id: :integer, age: :integer)
240-
delegate_reflection = country_model.reflect_on_association(:people)
241-
reflection = described_class.new(delegate_reflection)
242-
243-
actual_sql = reflection.association_relation.to_sql
244-
expected_sql = Person.select('age').to_sql
245-
expect(actual_sql).to eq expected_sql
246-
end
115+
actual_sql = reflection.association_relation.to_sql
116+
expected_sql = Country.all.to_sql
117+
expect(actual_sql).to eq expected_sql
247118
end
248119
end
249120
end

spec/unit_spec_helper.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@
3131
UnitTests::ValidationMatcherScenarioHelpers.configure_example_group(config)
3232
UnitTests::MessageHelpers.configure_example_group(config)
3333

34-
if UnitTests::RailsVersions.rails_lte_4?
35-
UnitTests::ActiveResourceBuilder.configure_example_group(config)
36-
end
37-
3834
config.include UnitTests::Matchers
3935

4036
config.infer_spec_type_from_file_location!

0 commit comments

Comments
 (0)