diff --git a/lib/shoulda/matchers/action_controller/permit_matcher.rb b/lib/shoulda/matchers/action_controller/permit_matcher.rb index d2a4f656c..049da14fc 100644 --- a/lib/shoulda/matchers/action_controller/permit_matcher.rb +++ b/lib/shoulda/matchers/action_controller/permit_matcher.rb @@ -251,12 +251,9 @@ def matches?(controller) parameters_double_registry.register Doublespeak.with_doubles_activated do - Shoulda::Matchers::RailsShim.make_controller_request( - context, - verb, - action, - request_params, - ) + params = { params: request_params } + + context.__send__(verb, action, **params) end unpermitted_parameter_names.empty? diff --git a/lib/shoulda/matchers/active_record/association_matcher.rb b/lib/shoulda/matchers/active_record/association_matcher.rb index 48371cdb5..210b7f832 100644 --- a/lib/shoulda/matchers/active_record/association_matcher.rb +++ b/lib/shoulda/matchers/active_record/association_matcher.rb @@ -1004,7 +1004,7 @@ def initialize(macro, name) @submatchers = [] @missing = '' - if macro == :belongs_to && RailsShim.active_record_gte_5? + if macro == :belongs_to required(belongs_to_required_by_default?) end end diff --git a/lib/shoulda/matchers/active_record/association_matchers/join_table_matcher.rb b/lib/shoulda/matchers/active_record/association_matchers/join_table_matcher.rb index a6a1c4031..6faf27bf0 100644 --- a/lib/shoulda/matchers/active_record/association_matchers/join_table_matcher.rb +++ b/lib/shoulda/matchers/active_record/association_matchers/join_table_matcher.rb @@ -42,7 +42,7 @@ def join_table_option_correct? end def join_table_exists? - if RailsShim.tables_and_views(connection). + if connection.data_sources. include?(join_table_name.to_s) true else diff --git a/lib/shoulda/matchers/active_record/association_matchers/required_matcher.rb b/lib/shoulda/matchers/active_record/association_matchers/required_matcher.rb index 576c5af5c..ae0536e85 100644 --- a/lib/shoulda/matchers/active_record/association_matchers/required_matcher.rb +++ b/lib/shoulda/matchers/active_record/association_matchers/required_matcher.rb @@ -65,7 +65,7 @@ def submatcher_passes?(subject) end def validation_message_key - RailsShim.validation_message_key_for_association_required_option + :required end end end diff --git a/lib/shoulda/matchers/rails_shim.rb b/lib/shoulda/matchers/rails_shim.rb index 6cecb4b0a..2474d7363 100644 --- a/lib/shoulda/matchers/rails_shim.rb +++ b/lib/shoulda/matchers/rails_shim.rb @@ -3,24 +3,12 @@ module Matchers # @private module RailsShim # rubocop:disable Metrics/ModuleLength class << self - def action_pack_gte_5? - Gem::Requirement.new('>= 5').satisfied_by?(action_pack_version) - end - - def action_pack_lt_5? - Gem::Requirement.new('< 5').satisfied_by?(action_pack_version) - end - def action_pack_version Gem::Version.new(::ActionPack::VERSION::STRING) rescue NameError Gem::Version.new('0') end - def active_record_gte_5? - Gem::Requirement.new('>= 5').satisfied_by?(active_record_version) - end - def active_record_gte_6? Gem::Requirement.new('>= 6').satisfied_by?(active_record_version) end @@ -57,17 +45,6 @@ def generate_validation_message( ) end - def make_controller_request(context, verb, action, request_params) - params = - if action_pack_gte_5? - { params: request_params } - else - request_params - end - - context.__send__(verb, action, **params) - end - def serialized_attributes_for(model) attribute_types_for(model). inject({}) do |hash, (attribute_name, attribute_type)| @@ -85,26 +62,10 @@ def attribute_serialization_coder_for(model, attribute_name) serialized_attributes_for(model)[attribute_name.to_s] end - def tables_and_views(connection) - if active_record_gte_5? - connection.data_sources - else - connection.tables - end - end - def verb_for_update :patch end - def validation_message_key_for_association_required_option - if active_record_gte_5? - :required - else - :blank - end - end - def parent_of(mod) if mod.respond_to?(:module_parent) mod.module_parent diff --git a/spec/support/acceptance/helpers/rails_migration_helpers.rb b/spec/support/acceptance/helpers/rails_migration_helpers.rb index 211bc01b7..9c35c009b 100644 --- a/spec/support/acceptance/helpers/rails_migration_helpers.rb +++ b/spec/support/acceptance/helpers/rails_migration_helpers.rb @@ -5,11 +5,7 @@ module RailsMigrationHelpers include RailsVersionHelpers def migration_class_name - if rails_version >= 5 - "ActiveRecord::Migration[#{rails_version_for_migration}]" - else - 'ActiveRecord::Migration' - end + "ActiveRecord::Migration[#{rails_version_for_migration}]" end private diff --git a/spec/support/unit/helpers/action_pack_versions.rb b/spec/support/unit/helpers/action_pack_versions.rb index 5e6b77fa8..ef7d1dd25 100644 --- a/spec/support/unit/helpers/action_pack_versions.rb +++ b/spec/support/unit/helpers/action_pack_versions.rb @@ -11,10 +11,6 @@ def action_pack_gte_5? action_pack_version >= 5 end - def action_pack_lt_5? - action_pack_version < 5 - end - def action_pack_version Tests::Version.new(ActionPack::VERSION::STRING) end diff --git a/spec/support/unit/helpers/rails_versions.rb b/spec/support/unit/helpers/rails_versions.rb index 4e5c492d5..9728416da 100644 --- a/spec/support/unit/helpers/rails_versions.rb +++ b/spec/support/unit/helpers/rails_versions.rb @@ -11,14 +11,6 @@ def rails_version Tests::Version.new(Rails::VERSION::STRING) end - def rails_lt_5? - rails_version < 5 - end - - def rails_5_x? - rails_version =~ '~> 5.0' - end - def rails_gte_5_2? rails_version >= 5.2 end diff --git a/spec/support/unit/rails_application.rb b/spec/support/unit/rails_application.rb index 314309180..b55b12cee 100644 --- a/spec/support/unit/rails_application.rb +++ b/spec/support/unit/rails_application.rb @@ -82,9 +82,7 @@ def generate write_activerecord_model_with_default_connection write_activerecord_model_with_different_connection - if rails_version >= 5 - add_initializer_for_time_zone_aware_types - end + add_initializer_for_time_zone_aware_types end def rails_new diff --git a/spec/unit/shoulda/matchers/active_record/association_matcher_spec.rb b/spec/unit/shoulda/matchers/active_record/association_matcher_spec.rb index dbb7fdfb4..df694f707 100644 --- a/spec/unit/shoulda/matchers/active_record/association_matcher_spec.rb +++ b/spec/unit/shoulda/matchers/active_record/association_matcher_spec.rb @@ -1051,30 +1051,28 @@ def belonging_to_non_existent_class(model_name, assoc_name, options = {}) }.to fail_with_message(message) end - if rails_5_x? - context 'index_errors' do - it 'accepts an association with a matching :index_errors option' do - define_model :child, parent_id: :integer - define_model :parent do - has_many :children, index_errors: true - end - expect(Parent.new).to have_many(:children).index_errors(true) + context 'index_errors' do + it 'accepts an association with a matching :index_errors option' do + define_model :child, parent_id: :integer + define_model :parent do + has_many :children, index_errors: true end + expect(Parent.new).to have_many(:children).index_errors(true) + end - it 'rejects an association with a non-matching :index_errors option and returns the correct message' do - define_model :child, parent_id: :integer - define_model :parent do - has_many :children, autosave: false - end + it 'rejects an association with a non-matching :index_errors option and returns the correct message' do + define_model :child, parent_id: :integer + define_model :parent do + has_many :children, autosave: false + end - message = - 'Expected Parent to have a has_many association called children '\ - '(children should have index_errors set to true)' + message = + 'Expected Parent to have a has_many association called children '\ + '(children should have index_errors set to true)' - expect { - expect(Parent.new).to have_many(:children).index_errors(true) - }.to fail_with_message(message) - end + expect { + expect(Parent.new).to have_many(:children).index_errors(true) + }.to fail_with_message(message) end end