mirror of
https://github.com/thoughtbot/shoulda-matchers.git
synced 2022-11-09 12:01:38 -05:00
Remove code for unsupported versions (#1270)
This commit is contained in:
parent
d97bdd6cab
commit
0e6db542be
9 changed files with 48 additions and 259 deletions
|
@ -269,7 +269,7 @@ module Shoulda
|
|||
end
|
||||
|
||||
def type_cast_default
|
||||
Shoulda::Matchers::RailsShim.type_cast_default_for(model, self)
|
||||
model.column_defaults[name]
|
||||
end
|
||||
|
||||
def primary?
|
||||
|
|
|
@ -3,10 +3,6 @@ module Shoulda
|
|||
# @private
|
||||
module RailsShim
|
||||
class << self
|
||||
def action_pack_gte_4_1?
|
||||
Gem::Requirement.new('>= 4.1').satisfied_by?(action_pack_version)
|
||||
end
|
||||
|
||||
def action_pack_gte_5?
|
||||
Gem::Requirement.new('>= 5').satisfied_by?(action_pack_version)
|
||||
end
|
||||
|
@ -85,15 +81,6 @@ module Shoulda
|
|||
serialized_attributes_for(model)[attribute_name.to_s]
|
||||
end
|
||||
|
||||
def type_cast_default_for(model, column)
|
||||
if model.respond_to?(:column_defaults)
|
||||
# Rails 4.2
|
||||
model.column_defaults[column.name]
|
||||
else
|
||||
column.default
|
||||
end
|
||||
end
|
||||
|
||||
def tables_and_views(connection)
|
||||
if active_record_gte_5?
|
||||
connection.data_sources
|
||||
|
@ -103,11 +90,7 @@ module Shoulda
|
|||
end
|
||||
|
||||
def verb_for_update
|
||||
if action_pack_gte_4_1?
|
||||
:patch
|
||||
else
|
||||
:put
|
||||
end
|
||||
end
|
||||
|
||||
def validation_message_key_for_association_required_option
|
||||
|
|
|
@ -13,13 +13,7 @@ module AcceptanceTests
|
|||
end
|
||||
|
||||
def default_test_framework
|
||||
if rails_version =~ '< 4'
|
||||
:test_unit
|
||||
elsif rails_version =~ '~> 4.0.0'
|
||||
:minitest_4
|
||||
else
|
||||
:minitest
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -112,10 +112,6 @@ module AcceptanceTests
|
|||
end
|
||||
|
||||
def add_spring_to_project
|
||||
if rails_version < 4
|
||||
add_gem 'spring'
|
||||
end
|
||||
|
||||
add_gem 'spring-commands-rspec'
|
||||
end
|
||||
end
|
||||
|
|
|
@ -11,26 +11,6 @@ module UnitTests
|
|||
Tests::Version.new(Rails::VERSION::STRING)
|
||||
end
|
||||
|
||||
def rails_3_x?
|
||||
rails_version =~ '~> 3.0'
|
||||
end
|
||||
|
||||
def rails_4_x?
|
||||
rails_version =~ '~> 4.0'
|
||||
end
|
||||
|
||||
def rails_lte_4?
|
||||
rails_version <= 4
|
||||
end
|
||||
|
||||
def rails_gte_4_1?
|
||||
rails_version >= 4.1
|
||||
end
|
||||
|
||||
def rails_gte_4_2?
|
||||
rails_version >= 4.2
|
||||
end
|
||||
|
||||
def rails_lt_5?
|
||||
rails_version < 5
|
||||
end
|
||||
|
|
|
@ -508,7 +508,6 @@ describe Shoulda::Matchers::ActionController::PermitMatcher, type: :controller d
|
|||
end
|
||||
|
||||
context 'when given :update' do
|
||||
if rails_gte_4_1?
|
||||
it 'PATCHes to the controller' do
|
||||
controller = ActionController::Base.new
|
||||
context = build_context
|
||||
|
@ -523,22 +522,6 @@ describe Shoulda::Matchers::ActionController::PermitMatcher, type: :controller d
|
|||
context: context,
|
||||
)
|
||||
end
|
||||
else
|
||||
it 'PUTs to the controller' do
|
||||
controller = ActionController::Base.new
|
||||
context = build_context
|
||||
matcher = permit(:name).for(:update).in_context(context)
|
||||
|
||||
matcher.matches?(controller)
|
||||
|
||||
expect_to_have_made_controller_request(
|
||||
verb: :put,
|
||||
action: :update,
|
||||
params: {},
|
||||
context: context,
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when given a custom action and verb' do
|
||||
|
|
|
@ -946,19 +946,6 @@ validation exception on failure, but this could not be proved.
|
|||
end
|
||||
end
|
||||
|
||||
if rails_lte_4?
|
||||
context 'an active_resource model' do
|
||||
context 'with the validation context' do
|
||||
it 'does not raise an exception' do
|
||||
expect do
|
||||
expect(active_resource_model).to validate_presence_of(:attr)
|
||||
end.to_not raise_exception
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if rails_4_x?
|
||||
context 'against a pre-set password in a model that has_secure_password' do
|
||||
it 'raises a CouldNotSetPasswordError' do
|
||||
user_class = define_model :user, password_digest: :string do
|
||||
|
@ -978,7 +965,6 @@ validation exception on failure, but this could not be proved.
|
|||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the attribute typecasts nil to another blank value, such as an empty array' do
|
||||
it 'accepts (and does not raise an AttributeChangedValueError)' do
|
||||
|
|
|
@ -87,7 +87,6 @@ describe Shoulda::Matchers::ActiveRecord::AssociationMatchers::ModelReflection d
|
|||
end
|
||||
|
||||
describe '#association_relation' do
|
||||
if rails_4_x?
|
||||
context 'when the reflection object has a #scope method' do
|
||||
context 'when the scope is a block' do
|
||||
it 'executes the block in the context of an empty scope' do
|
||||
|
@ -120,132 +119,4 @@ describe Shoulda::Matchers::ActiveRecord::AssociationMatchers::ModelReflection d
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
if rails_3_x?
|
||||
context 'when the reflection object does not have a #scope method' do
|
||||
context 'when the reflection options contain :conditions' do
|
||||
it 'creates an ActiveRecord::Relation from the conditions' do
|
||||
define_model(:country, mood: :string)
|
||||
person_model = define_model(:person, country_id: :integer) do
|
||||
belongs_to :country, conditions: { mood: 'nice' }
|
||||
end
|
||||
delegate_reflection = person_model.reflect_on_association(:country)
|
||||
reflection = described_class.new(delegate_reflection)
|
||||
|
||||
actual_sql = reflection.association_relation.to_sql
|
||||
expected_sql = Country.where(mood: 'nice').to_sql
|
||||
expect(actual_sql).to eq expected_sql
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the reflection options contain :order' do
|
||||
it 'creates an ActiveRecord::Relation from the order' do
|
||||
define_model(:person, country_id: :integer, age: :integer)
|
||||
country_model = define_model(:country) do
|
||||
has_many :people, order: 'age'
|
||||
end
|
||||
delegate_reflection = country_model.reflect_on_association(:people)
|
||||
reflection = described_class.new(delegate_reflection)
|
||||
|
||||
actual_sql = reflection.association_relation.to_sql
|
||||
expected_sql = Person.order('age').to_sql
|
||||
expect(actual_sql).to eq expected_sql
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the reflection options contain :include' do
|
||||
it 'creates an ActiveRecord::Relation from the include' do
|
||||
define_model(:city, country_id: :integer)
|
||||
define_model(:country) do
|
||||
has_many :cities
|
||||
end
|
||||
person_model = define_model(:person, country_id: :integer) do
|
||||
belongs_to :country, include: :cities
|
||||
end
|
||||
delegate_reflection = person_model.reflect_on_association(:country)
|
||||
reflection = described_class.new(delegate_reflection)
|
||||
|
||||
actual_includes = reflection.association_relation.includes_values
|
||||
expected_includes = Country.includes(:cities).includes_values
|
||||
expect(actual_includes).to eq expected_includes
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the reflection options contain :group' do
|
||||
it 'creates an ActiveRecord::Relation from the group' do
|
||||
country_model = define_model(:country, mood: :string) do
|
||||
has_many :people, group: 'age'
|
||||
end
|
||||
define_model(:person, country_id: :integer, age: :integer)
|
||||
delegate_reflection = country_model.reflect_on_association(:people)
|
||||
reflection = described_class.new(delegate_reflection)
|
||||
|
||||
actual_sql = reflection.association_relation.to_sql
|
||||
expected_sql = Person.group('age').to_sql
|
||||
expect(actual_sql).to eq expected_sql
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the reflection options contain :having' do
|
||||
it 'creates an ActiveRecord::Relation from the having' do
|
||||
country_model = define_model(:country) do
|
||||
has_many :people, having: 'country_id > 1'
|
||||
end
|
||||
define_model(:person, country_id: :integer)
|
||||
delegate_reflection = country_model.reflect_on_association(:people)
|
||||
reflection = described_class.new(delegate_reflection)
|
||||
|
||||
actual_sql = reflection.association_relation.to_sql
|
||||
expected_sql = Person.having('country_id > 1').to_sql
|
||||
expect(actual_sql).to eq expected_sql
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the reflection options contain :limit' do
|
||||
it 'creates an ActiveRecord::Relation from the limit' do
|
||||
country_model = define_model(:country) do
|
||||
has_many :people, limit: 10
|
||||
end
|
||||
define_model(:person, country_id: :integer)
|
||||
delegate_reflection = country_model.reflect_on_association(:people)
|
||||
reflection = described_class.new(delegate_reflection)
|
||||
|
||||
actual_sql = reflection.association_relation.to_sql
|
||||
expected_sql = Person.limit(10).to_sql
|
||||
expect(actual_sql).to eq expected_sql
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the reflection options contain :offset' do
|
||||
it 'creates an ActiveRecord::Relation from the offset' do
|
||||
country_model = define_model(:country) do
|
||||
has_many :people, offset: 5
|
||||
end
|
||||
define_model(:person, country_id: :integer)
|
||||
delegate_reflection = country_model.reflect_on_association(:people)
|
||||
reflection = described_class.new(delegate_reflection)
|
||||
|
||||
actual_sql = reflection.association_relation.to_sql
|
||||
expected_sql = Person.offset(5).to_sql
|
||||
expect(actual_sql).to eq expected_sql
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the reflection options contain :select' do
|
||||
it 'creates an ActiveRecord::Relation from the select' do
|
||||
country_model = define_model(:country) do
|
||||
has_many :people, select: 'age'
|
||||
end
|
||||
define_model(:person, country_id: :integer, age: :integer)
|
||||
delegate_reflection = country_model.reflect_on_association(:people)
|
||||
reflection = described_class.new(delegate_reflection)
|
||||
|
||||
actual_sql = reflection.association_relation.to_sql
|
||||
expected_sql = Person.select('age').to_sql
|
||||
expect(actual_sql).to eq expected_sql
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -31,10 +31,6 @@ RSpec.configure do |config|
|
|||
UnitTests::ValidationMatcherScenarioHelpers.configure_example_group(config)
|
||||
UnitTests::MessageHelpers.configure_example_group(config)
|
||||
|
||||
if UnitTests::RailsVersions.rails_lte_4?
|
||||
UnitTests::ActiveResourceBuilder.configure_example_group(config)
|
||||
end
|
||||
|
||||
config.include UnitTests::Matchers
|
||||
|
||||
config.infer_spec_type_from_file_location!
|
||||
|
|
Loading…
Add table
Reference in a new issue