Skip to content

Commit

Permalink
[Test] Fix Rails 6.1.4 fixture issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Mth0158 committed Feb 28, 2025
1 parent e043e06 commit 406de48
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 38 deletions.
6 changes: 3 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ gemspec
# This Rails version will be the one used when running `bundle exec rake test` locally
# Uncomment the line then run `bundle install`
# gem "rails", "7.1.2"
# gem 'sqlite3', '~> 1.7'
# gem 'nokogiri', '~> 1.16', '>= 1.16.7'
# gem "sqlite3", "~> 1.7"
# gem "nokogiri", "~> 1.16", ">= 1.16.7"

group :development, :test do
# To use a debugger:
# gem 'byebug'
# gem "byebug"

# Linters
gem "rubocop", "~> 1.71", ">= 1.71.1", require: false
Expand Down
13 changes: 5 additions & 8 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -209,14 +209,11 @@ GEM
simplecov_json_formatter (~> 0.1)
simplecov-html (0.13.1)
simplecov_json_formatter (0.1.4)
sqlite3 (2.5.0-aarch64-linux-gnu)
sqlite3 (2.5.0-aarch64-linux-musl)
sqlite3 (2.5.0-arm-linux-gnu)
sqlite3 (2.5.0-arm-linux-musl)
sqlite3 (2.5.0-arm64-darwin)
sqlite3 (2.5.0-x86_64-darwin)
sqlite3 (2.5.0-x86_64-linux-gnu)
sqlite3 (2.5.0-x86_64-linux-musl)
sqlite3 (1.7.3-aarch64-linux)
sqlite3 (1.7.3-arm-linux)
sqlite3 (1.7.3-arm64-darwin)
sqlite3 (1.7.3-x86_64-darwin)
sqlite3 (1.7.3-x86_64-linux)
stringio (3.1.2)
thor (1.3.2)
timeout (0.4.3)
Expand Down
4 changes: 2 additions & 2 deletions test/dummy/app/models/active_storage_validations/check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ class ActiveStorageValidations::Check < ApplicationRecord

# We ensure that the gem is working fine when using fixtures
has_one_attached :working_with_fixture
validates :working_with_fixture, content_type: "image/png", processable_file: true
validates :working_with_fixture, content_type: "image/png", processable_file: true, attached: true

# We ensure that the gem is working fine when using fixtures + variant
has_one_attached :working_with_fixture_and_variant do |attachable|
attachable.variant :medium, resize_to_fill: [ 800, 400 ], preprocessed: true
end
validates :working_with_fixture_and_variant, content_type: "image/png", processable_file: true
validates :working_with_fixture_and_variant, content_type: "image/png", processable_file: true, attached: true
end
4 changes: 4 additions & 0 deletions test/fixtures/active_storage/attachments.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@ first_active_storage_validations_check_working_with_fixture_attachment:
name: working_with_fixture
record: one (ActiveStorageValidations::Check)
blob: first_active_storage_validations_check_working_with_fixture_blob
second_active_storage_validations_check_working_with_fixture_attachment:
name: working_with_fixture_and_variant
record: one (ActiveStorageValidations::Check)
blob: second_active_storage_validations_check_working_with_fixture_blob
1 change: 1 addition & 0 deletions test/fixtures/active_storage/blobs.yml
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
first_active_storage_validations_check_working_with_fixture_blob: <%= ActiveStorage::FixtureSet.blob filename: "image_150x150.png", service_name: "test_fixtures" %>
second_active_storage_validations_check_working_with_fixture_blob: <%= ActiveStorage::FixtureSet.blob filename: "image_150x150.png", service_name: "test_fixtures" %>
30 changes: 10 additions & 20 deletions test/global/active_storage_validations_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,18 @@
assert_equal(Marcel::MimeType.for(declared_type: "application/asv_test"), "application/asv_test")
end
end
end

if Rails.gem_version >= Gem::Version.new("7.0.0.rc1")
describe "working with active_storage fixtures" do
subject { instance.public_send(attribute) && instance }

let(:attachable) { png_file }

describe "base case" do
let(:attribute) { :working_with_fixture }

it "works fine" do
subject && assert(subject.valid?)
end
end

describe "with variant" do
let(:attribute) { :working_with_fixture_and_variant }
if Rails.gem_version >= Gem::Version.new("7.0.0.rc1")
# This test is to ensure that the gem is properly working with ActiveStorage
# fixtures. These feature is available since Rails 7.0.
class ActiveStorageValidations::FixtureTest < ActiveSupport::TestCase
setup do
@check = active_storage_validations_checks(:one)
end

it "works fine" do
subject && assert(subject.valid?)
end
end
test "working with active_storage fixtures" do
assert(@check.valid?)
end
end
end
12 changes: 7 additions & 5 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@
Rails::TestUnitReporter.executable = "bin/test"

# Load fixtures from the engine
if ActiveSupport::TestCase.respond_to?(:fixture_path=)
ActiveSupport::TestCase.fixture_path = File.expand_path("fixtures", __dir__)
ActionDispatch::IntegrationTest.fixture_path = ActiveSupport::TestCase.fixture_path
ActiveSupport::TestCase.file_fixture_path = ActiveSupport::TestCase.fixture_path + "/files"
ActiveSupport::TestCase.fixtures :all
if ActiveSupport::TestCase.respond_to?(:fixture_paths=)
fixture_path = File.expand_path("fixtures", __dir__)
ActiveSupport::TestCase.fixture_paths = [ fixture_path ]
ActionDispatch::IntegrationTest.fixture_paths = [ fixture_path ]
ActiveSupport::TestCase.file_fixture_path = ActiveSupport::TestCase.fixture_paths.first + "/files"
# Only load fixtures globally for Rails 7+
ActiveSupport::TestCase.fixtures :all if Rails.gem_version >= Gem::Version.new("7.0.0.rc1")
end

# Load test support files
Expand Down

0 comments on commit 406de48

Please sign in to comment.