Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Remove references to unsupported Rails versions #1584

Merged
merged 1 commit into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Shoulda
module Matchers
module ActiveRecord
# The `have_implicit_order_column` matcher tests that the model has `implicit_order_column`
# assigned to one of the table columns. (Rails 6+ only)
# assigned to one of the table columns.
#
# class Product < ApplicationRecord
# self.implicit_order_column = :created_at
Expand All @@ -20,10 +20,8 @@ module ActiveRecord
#
# @return [HaveImplicitOrderColumnMatcher]
#
if RailsShim.active_record_gte_6?
def have_implicit_order_column(column_name)
HaveImplicitOrderColumnMatcher.new(column_name)
end
def have_implicit_order_column(column_name)
HaveImplicitOrderColumnMatcher.new(column_name)
end

# @private
Expand Down
4 changes: 0 additions & 4 deletions lib/shoulda/matchers/rails_shim.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ def action_pack_version
Gem::Version.new('0')
end

def active_record_gte_6?
Gem::Requirement.new('>= 6').satisfied_by?(active_record_version)
end

def active_record_version
Gem::Version.new(::ActiveRecord::VERSION::STRING)
rescue NameError
Expand Down
4 changes: 0 additions & 4 deletions spec/support/acceptance/helpers/rails_version_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ def rails_version
bundle_version_of('rails')
end

def rails_gt_6_0?
rails_version > 6.0
end

def rails_6_x?
rails_version =~ '~> 6.0'
end
Expand Down
8 changes: 2 additions & 6 deletions spec/support/acceptance/helpers/step_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,7 @@ def create_rails_application
end

def rails_new_command
if rails_version >= 6.0
"bundle exec rails new #{fs.project_directory} --database=#{database.adapter_name} --skip-bundle --skip-javascript --no-rc --skip-bootsnap"
else
"bundle exec rails new #{fs.project_directory} --database=#{database.adapter_name} --skip-bundle --no-rc --skip-bootsnap"
end
"bundle exec rails new #{fs.project_directory} --database=#{database.adapter_name} --skip-bundle --skip-javascript --no-rc --skip-bootsnap"
end

def configure_routes
Expand All @@ -116,7 +112,7 @@ def add_rspec_to_project

def add_rspec_rails_to_project!
add_gem 'rspec-rails', rspec_rails_version
run_command_within_bundle!('bundle install --local --binstubs') if rails_gt_6_0?
run_command_within_bundle!('bundle install --local --binstubs')
run_command_within_bundle!('rails g rspec:install')
remove_from_file '.rspec', '--warnings'
end
Expand Down
18 changes: 0 additions & 18 deletions spec/support/unit/helpers/action_pack_versions.rb

This file was deleted.

28 changes: 0 additions & 28 deletions spec/support/unit/helpers/active_model_versions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,5 @@ def self.configure_example_group(example_group)
def active_model_version
Tests::Version.new(::ActiveModel::VERSION::STRING)
end

def active_model_3_1?
(::ActiveModel::VERSION::MAJOR == 3 && ::ActiveModel::VERSION::MINOR >= 1) || active_model_4_0?
end

def active_model_3_2?
(::ActiveModel::VERSION::MAJOR == 3 && ::ActiveModel::VERSION::MINOR >= 2) || active_model_4_0?
end

def active_model_4_0?
::ActiveModel::VERSION::MAJOR == 4
end

def active_model_supports_absence_validation?
active_model_version >= 4
end

def active_model_supports_strict?
active_model_version >= 3.2
end

def active_model_supports_full_attributes_api?
active_model_version >= '5.2'
end

def active_model_supports_custom_has_secure_password_attribute?
active_model_version >= '6.0'
end
end
end
8 changes: 0 additions & 8 deletions spec/support/unit/helpers/active_record_versions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,5 @@ def self.configure_example_group(example_group)
def active_record_version
Tests::Version.new(::ActiveRecord::VERSION::STRING)
end

def active_record_supports_validate_presence_on_active_storage?
active_record_version >= '6.0.0.beta1'
end

def active_record_supports_implicit_order_column?
active_record_version >= '6.0.0.beta1'
end
end
end
11 changes: 2 additions & 9 deletions spec/support/unit/helpers/model_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,8 @@ def define_model(name, columns = {}, options = {}, &block)
private

def clear_column_caches
# Rails 4.x
if ::ActiveRecord::Base.connection.respond_to?(:schema_cache)
DevelopmentRecord.connection.schema_cache.clear!
ProductionRecord.connection.schema_cache.clear!
# Rails 3.1 - 4.0
elsif ::ActiveRecord::Base.connection_pool.respond_to?(:clear_cache!)
DevelopmentRecord.connection_pool.clear_cache!
ProductionRecord.connection_pool.clear_cache!
end
DevelopmentRecord.connection.schema_cache.clear!
ProductionRecord.connection.schema_cache.clear!
end

def drop_created_tables
Expand Down
2 changes: 1 addition & 1 deletion spec/support/unit/helpers/rails_versions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def rails_version
end

def rails_oldest_version_supported
5.2
6.1
end
end
end
8 changes: 2 additions & 6 deletions spec/support/unit/rails_application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def load
load_environment

add_active_storage_migration
add_action_text_migration if rails_version >= 6.0
add_action_text_migration

run_migrations
end
Expand Down Expand Up @@ -90,11 +90,7 @@ def rails_new
end

def rails_new_command
if rails_version >= 6.0
"bundle exec rails new #{fs.project_directory} --database=#{database.adapter_name} --skip-bundle --skip-javascript --no-rc --skip-bootsnap"
else
"bundle exec rails new #{fs.project_directory} --database=#{database.adapter_name} --skip-bundle --no-rc --skip-bootsnap"
end
"bundle exec rails new #{fs.project_directory} --database=#{database.adapter_name} --skip-bundle --skip-javascript --no-rc --skip-bootsnap"
end

def fix_available_locales_warning
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -603,10 +603,6 @@ def build_context
end

def expect_to_have_made_controller_request(context:, verb:, action:, params:)
if action_pack_gte_5?
expect(context).to have_received(verb).with(action, params: params)
else
expect(context).to have_received(verb).with(action, params)
end
expect(context).to have_received(verb).with(action, params: params)
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,6 @@
expect(matcher.description).to eq 'allow :baz to be ‹"foo"›'
end

if active_model_3_2?
it 'describes itself with a strict validation' do
strict_matcher = allow_value('xyz').for(:attr).strict

expect(strict_matcher.description).to eq(
'allow :attr to be ‹"xyz"›, raising a validation exception on failure',
)
end
end

it 'truncates the description when long' do
matcher = allow_value('A' * 10000).for(:baz)

Expand Down Expand Up @@ -559,45 +549,6 @@
end
end

if active_model_3_2?
context 'an attribute with a strict format validation' do
context 'when qualified with strict' do
it 'rejects a bad value, providing the correct failure message' do
message = <<-MESSAGE.strip_heredoc
After setting :attr to ‹"xyz"›, the matcher expected the Example to be
valid, but it was invalid instead, raising a validation exception with
the message "Attr is invalid".
MESSAGE

assertion = lambda do
expect(validating_format(with: /abc/, strict: true)).
to allow_value('xyz').for(:attr).strict
end

expect(&assertion).to fail_with_message(message)
end

context 'qualified with a custom message' do
it 'rejects a bad value when the failure messages do not match' do
message = <<-MESSAGE.strip_heredoc
After setting :attr to ‹"xyz"›, the matcher expected the Example to be
invalid and to raise a validation exception with message matching
‹/abc/›. The record was indeed invalid, but the exception message was
"Attr is invalid" instead.
MESSAGE

assertion = lambda do
expect(validating_format(with: /abc/, strict: true)).
not_to allow_value('xyz').for(:attr).with_message(/abc/).strict
end

expect(&assertion).to fail_with_message(message)
end
end
end
end
end

context 'when the attribute interferes with attempts to be set' do
context 'when the attribute cannot be changed from nil to non-nil' do
context 'and the record remains valid' do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,20 @@
end
end

if active_model_supports_custom_has_secure_password_attribute?
context 'when custom attribute is given to has_secure_password' do
it 'matches when the subject configures has_secure_password with correct options' do
working_model = define_model(:example, reset_password_digest: :string) { has_secure_password :reset_password }
expect(working_model.new).to have_secure_password :reset_password
end
context 'when custom attribute is given to has_secure_password' do
it 'matches when the subject configures has_secure_password with correct options' do
working_model = define_model(:example, reset_password_digest: :string) { has_secure_password :reset_password }
expect(working_model.new).to have_secure_password :reset_password
end

it 'does not match when the subject does not authenticate a password' do
no_secure_password = define_model(:example)
expect(no_secure_password.new).not_to have_secure_password :reset_password
end
it 'does not match when the subject does not authenticate a password' do
no_secure_password = define_model(:example)
expect(no_secure_password.new).not_to have_secure_password :reset_password
end

it 'does not match when the subject is missing the custom digest attribute' do
no_digest_column = define_model(:example) { has_secure_password :reset_password }
expect(no_digest_column.new).not_to have_secure_password :reset_password
end
it 'does not match when the subject is missing the custom digest attribute' do
no_digest_column = define_model(:example) { has_secure_password :reset_password }
expect(no_digest_column.new).not_to have_secure_password :reset_password
end
end
end
Loading