Remove rails 5.1 support (#1429)

* Remove Rails 5.1 support

* Remove active_record_supports_active_storage? method

* Remove rails_gte_5_2? method
This commit is contained in:
Pedro Paiva 2021-04-17 17:13:09 -03:00 committed by GitHub
parent 293a815fbe
commit 50085f03d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 135 additions and 202 deletions

View File

@ -33,7 +33,6 @@ jobs:
appraisal:
- rails_6_0
- rails_5_2
- rails_5_1
adapter:
- sqlite3
- postgresql

View File

@ -23,26 +23,6 @@ shared_dependencies = proc do
instance_eval(&shared_test_dependencies)
end
appraise 'rails_5_1' do
instance_eval(&shared_dependencies)
instance_eval(&controller_test_dependency)
gem 'rails', '5.1.7'
gem 'puma', '~> 3.7'
gem 'sass-rails', '~> 5.0'
gem 'turbolinks', '~> 5'
gem 'jbuilder', '~> 2.5'
gem 'bcrypt', '~> 3.1.7'
gem 'capybara', '~> 2.13'
gem 'selenium-webdriver'
gem 'listen', '~> 3.0.5'
gem 'spring-watcher-listen', '~> 2.0.0'
# Database adapters
gem 'pg', '~> 0.18'
gem 'sqlite3', '~> 1.3.6'
end
appraise 'rails_5_2' do
instance_eval(&shared_dependencies)
instance_eval(&controller_test_dependency)

View File

@ -469,7 +469,7 @@ machine, understanding the codebase, and creating a good pull request.
## Compatibility
Shoulda Matchers is tested and supported against Ruby 2.6+, Rails
5.1+, RSpec 3.x, and Minitest 5.x.
5.2+, RSpec 3.x, and Minitest 5.x.
- For Ruby < 2.4 and Rails < 4.1 compatibility, please use [v3.1.3][v3.1.3].
- For Ruby < 3.0 and Rails < 6.1 compatibility, please use [v4.5.1][v4.5.1].

View File

@ -1,36 +0,0 @@
# This file was generated by Appraisal
source "https://rubygems.org"
gem "appraisal", "2.2.0"
gem "bundler", "~> 1.1"
gem "pry"
gem "pry-byebug"
gem "rake", "13.0.1"
gem "rspec", "~> 3.9"
gem "rubocop", require: false
gem "rubocop-packaging", require: false
gem "rubocop-rails", require: false
gem "warnings_logger"
gem "zeus", require: false
gem "fssm"
gem "redcarpet"
gem "rouge"
gem "yard"
gem "spring"
gem "spring-commands-rspec"
gem "rspec-rails", "~> 4.0"
gem "shoulda-context", "~> 1.2.0"
gem "rails-controller-testing", ">= 1.0.1"
gem "rails", "5.1.7"
gem "puma", "~> 3.7"
gem "sass-rails", "~> 5.0"
gem "turbolinks", "~> 5"
gem "jbuilder", "~> 2.5"
gem "bcrypt", "~> 3.1.7"
gem "capybara", "~> 2.13"
gem "selenium-webdriver"
gem "listen", "~> 3.0.5"
gem "spring-watcher-listen", "~> 2.0.0"
gem "pg", "~> 0.18"
gem "sqlite3", "~> 1.3.6"

View File

@ -37,5 +37,5 @@ Gem::Specification.new do |s|
s.require_paths = ['lib']
s.required_ruby_version = '>= 2.6.0'
s.add_dependency('activesupport', '>= 5.1.0')
s.add_dependency('activesupport', '>= 5.2.0')
end

View File

@ -11,10 +11,6 @@ module UnitTests
Tests::Version.new(::ActiveRecord::VERSION::STRING)
end
def active_record_supports_active_storage?
active_record_version >= 5.2
end
def active_record_supports_validate_presence_on_active_storage?
active_record_version >= '6.0.0.beta1'
end

View File

@ -10,9 +10,5 @@ module UnitTests
def rails_version
Tests::Version.new(Rails::VERSION::STRING)
end
def rails_gte_5_2?
rails_version >= 5.2
end
end
end

View File

@ -1,194 +1,192 @@
require 'unit_spec_helper'
describe Shoulda::Matchers::ActiveRecord::HaveAttachedMatcher, type: :model do
if active_record_supports_active_storage?
before do
create_table :active_storage_blobs do |t|
t.string :key, null: false
t.string :filename, null: false
t.string :content_type
t.text :metadata
t.bigint :byte_size, null: false
t.string :checksum, null: false
t.datetime :created_at, null: false
before do
create_table :active_storage_blobs do |t|
t.string :key, null: false
t.string :filename, null: false
t.string :content_type
t.text :metadata
t.bigint :byte_size, null: false
t.string :checksum, null: false
t.datetime :created_at, null: false
t.index [:key], unique: true
end
t.index [:key], unique: true
end
create_table :active_storage_attachments do |t|
t.string :name, null: false
t.references :record, null: false, polymorphic: true, index: false
t.references :blob, null: false
create_table :active_storage_attachments do |t|
t.string :name, null: false
t.references :record, null: false, polymorphic: true, index: false
t.references :blob, null: false
t.datetime :created_at, null: false
t.datetime :created_at, null: false
t.index [:record_type, :record_id, :name, :blob_id],
name: 'index_active_storage_attachments_uniqueness', unique: true
t.index [:record_type, :record_id, :name, :blob_id],
name: 'index_active_storage_attachments_uniqueness', unique: true
# The original rails migration has a foreign key.
# Since this messes up the clearing of the database, it's removed here.
# t.foreign_key :active_storage_blobs, column: :blob_id
# The original rails migration has a foreign key.
# Since this messes up the clearing of the database, it's removed here.
# t.foreign_key :active_storage_blobs, column: :blob_id
end
end
describe 'have_one_attached' do
describe '#description' do
it 'returns the message with the name of the association' do
matcher = have_one_attached(:avatar)
expect(matcher.description).
to eq('have a has_one_attached called avatar')
end
end
describe 'have_one_attached' do
describe '#description' do
it 'returns the message with the name of the association' do
matcher = have_one_attached(:avatar)
expect(matcher.description).
to eq('have a has_one_attached called avatar')
end
context 'when the attached exists on the model' do
it 'matches' do
record = record_having_one_attached(:avatar)
expect { have_one_attached(:avatar) }.
to match_against(record).
or_fail_with(<<-MESSAGE)
Did not expect User to have a has_one_attached called avatar, but it does.
MESSAGE
end
context 'when the attached exists on the model' do
context 'and the reader attribute does not exist' do
it 'matches' do
record = record_having_one_attached(:avatar)
record = record_having_one_attached(:avatar, remove_reader: true)
expect { have_one_attached(:avatar) }.
to match_against(record).
or_fail_with(<<-MESSAGE)
Did not expect User to have a has_one_attached called avatar, but it does.
MESSAGE
end
context 'and the reader attribute does not exist' do
it 'matches' do
record = record_having_one_attached(:avatar, remove_reader: true)
expect { have_one_attached(:avatar) }.
not_to match_against(record).
and_fail_with(<<-MESSAGE)
not_to match_against(record).
and_fail_with(<<-MESSAGE)
Expected User to have a has_one_attached called avatar, but this could not be proved.
User does not have a :avatar method.
MESSAGE
end
MESSAGE
end
end
context 'and the writer attribute does not exist' do
it 'matches' do
record = record_having_one_attached(:avatar, remove_writer: true)
expect { have_one_attached(:avatar) }.
not_to match_against(record).
and_fail_with(<<-MESSAGE)
context 'and the writer attribute does not exist' do
it 'matches' do
record = record_having_one_attached(:avatar, remove_writer: true)
expect { have_one_attached(:avatar) }.
not_to match_against(record).
and_fail_with(<<-MESSAGE)
Expected User to have a has_one_attached called avatar, but this could not be proved.
User does not have a :avatar= method.
MESSAGE
end
MESSAGE
end
end
context 'and the attachments association does not exist' do
it 'matches' do
record = record_having_one_attached(:avatar, remove_attachments: true)
expect { have_one_attached(:avatar) }.
not_to match_against(record).
and_fail_with(<<-MESSAGE)
context 'and the attachments association does not exist' do
it 'matches' do
record = record_having_one_attached(:avatar, remove_attachments: true)
expect { have_one_attached(:avatar) }.
not_to match_against(record).
and_fail_with(<<-MESSAGE)
Expected User to have a has_one_attached called avatar, but this could not be proved.
Expected User to have a has_one association called avatar_attachment (no association called avatar_attachment)
MESSAGE
end
MESSAGE
end
end
context 'and the blobs association is invalid' do
it 'matches' do
record = record_having_one_attached(:avatar, invalidate_blobs: true)
expect { have_one_attached(:avatar) }.
not_to match_against(record).
and_fail_with(<<-MESSAGE)
context 'and the blobs association is invalid' do
it 'matches' do
record = record_having_one_attached(:avatar, invalidate_blobs: true)
expect { have_one_attached(:avatar) }.
not_to match_against(record).
and_fail_with(<<-MESSAGE)
Expected User to have a has_one_attached called avatar, but this could not be proved.
Expected User to have a has_one association called avatar_blob through avatar_attachment (avatar_blob should resolve to ActiveStorage::Blob for class_name)
MESSAGE
end
MESSAGE
end
end
context 'and the eager loading scope does not exist' do
it 'matches' do
record = record_having_one_attached(:avatar, remove_eager_loading_scope: true)
expect { have_one_attached(:avatar) }.
not_to match_against(record).
and_fail_with <<-MESSAGE
context 'and the eager loading scope does not exist' do
it 'matches' do
record = record_having_one_attached(:avatar, remove_eager_loading_scope: true)
expect { have_one_attached(:avatar) }.
not_to match_against(record).
and_fail_with <<-MESSAGE
Expected User to have a has_one_attached called avatar, but this could not be proved.
User does not have a :with_attached_avatar scope.
MESSAGE
end
MESSAGE
end
end
end
end
describe 'have_many_attached' do
describe '#description' do
it 'returns the message with the name of the association' do
matcher = have_many_attached(:avatars)
expect(matcher.description).
to eq('have a has_many_attached called avatars')
describe 'have_many_attached' do
describe '#description' do
it 'returns the message with the name of the association' do
matcher = have_many_attached(:avatars)
expect(matcher.description).
to eq('have a has_many_attached called avatars')
end
end
context 'when the attached exists on the model' do
it 'matches' do
record = record_having_many_attached(:avatars)
expect { have_many_attached(:avatars) }.
to match_against(record).
or_fail_with(<<-MESSAGE)
Did not expect User to have a has_many_attached called avatars, but it does.
MESSAGE
end
context 'and the reader attribute does not exist' do
it 'matches' do
record = record_having_many_attached(:avatars, remove_reader: true)
expect { have_many_attached(:avatars) }.
not_to match_against(record).
and_fail_with(<<-MESSAGE)
Expected User to have a has_many_attached called avatars, but this could not be proved.
User does not have a :avatars method.
MESSAGE
end
end
context 'when the attached exists on the model' do
context 'and the writer attribute does not exist' do
it 'matches' do
record = record_having_many_attached(:avatars)
record = record_having_many_attached(:avatars, remove_writer: true)
expect { have_many_attached(:avatars) }.
to match_against(record).
or_fail_with(<<-MESSAGE)
Did not expect User to have a has_many_attached called avatars, but it does.
MESSAGE
end
context 'and the reader attribute does not exist' do
it 'matches' do
record = record_having_many_attached(:avatars, remove_reader: true)
expect { have_many_attached(:avatars) }.
not_to match_against(record).
and_fail_with(<<-MESSAGE)
Expected User to have a has_many_attached called avatars, but this could not be proved.
User does not have a :avatars method.
MESSAGE
end
end
context 'and the writer attribute does not exist' do
it 'matches' do
record = record_having_many_attached(:avatars, remove_writer: true)
expect { have_many_attached(:avatars) }.
not_to match_against(record).
and_fail_with(<<-MESSAGE)
not_to match_against(record).
and_fail_with(<<-MESSAGE)
Expected User to have a has_many_attached called avatars, but this could not be proved.
User does not have a :avatars= method.
MESSAGE
end
MESSAGE
end
end
context 'and the attachments association does not exist' do
it 'matches' do
record = record_having_many_attached(:avatars, remove_attachments: true)
expect { have_many_attached(:avatars) }.
not_to match_against(record).
and_fail_with(<<-MESSAGE)
context 'and the attachments association does not exist' do
it 'matches' do
record = record_having_many_attached(:avatars, remove_attachments: true)
expect { have_many_attached(:avatars) }.
not_to match_against(record).
and_fail_with(<<-MESSAGE)
Expected User to have a has_many_attached called avatars, but this could not be proved.
Expected User to have a has_many association called avatars_attachments (no association called avatars_attachments)
MESSAGE
end
MESSAGE
end
end
context 'and the blobs association is invalid' do
it 'matches' do
record = record_having_many_attached(:avatars, invalidate_blobs: true)
expect { have_many_attached(:avatars) }.
not_to match_against(record).
and_fail_with(<<-MESSAGE)
context 'and the blobs association is invalid' do
it 'matches' do
record = record_having_many_attached(:avatars, invalidate_blobs: true)
expect { have_many_attached(:avatars) }.
not_to match_against(record).
and_fail_with(<<-MESSAGE)
Expected User to have a has_many_attached called avatars, but this could not be proved.
Expected User to have a has_many association called avatars_blobs through avatars_attachments (avatars_blobs should resolve to ActiveStorage::Blob for class_name)
MESSAGE
end
MESSAGE
end
end
context 'and the eager loading scope does not exist' do
it 'matches' do
record = record_having_many_attached(:avatars, remove_eager_loading_scope: true)
expect { have_many_attached(:avatars) }.
not_to match_against(record).
and_fail_with(<<-MESSAGE)
context 'and the eager loading scope does not exist' do
it 'matches' do
record = record_having_many_attached(:avatars, remove_eager_loading_scope: true)
expect { have_many_attached(:avatars) }.
not_to match_against(record).
and_fail_with(<<-MESSAGE)
Expected User to have a has_many_attached called avatars, but this could not be proved.
User does not have a :with_attached_avatars scope.
MESSAGE
end
MESSAGE
end
end
end