Skip to content

Commit

Permalink
Merge pull request rails#41227 from seanpdoyle/active-record-fixture-…
Browse files Browse the repository at this point in the history
…set-hook

Move ActiveStorage fixture hooks to on_load
  • Loading branch information
rafaelfranca authored Jan 26, 2021
2 parents 9c8c8ab + 48e601c commit cf2905d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
2 changes: 2 additions & 0 deletions activerecord/lib/active_record/fixtures.rb
Original file line number Diff line number Diff line change
Expand Up @@ -782,3 +782,5 @@ def find
end
end
end

ActiveSupport.run_load_hooks :active_record_fixture_set, ActiveRecord::FixtureSet
4 changes: 0 additions & 4 deletions activerecord/lib/active_record/railties/databases.rake
Original file line number Diff line number Diff line change
Expand Up @@ -388,10 +388,6 @@ db_namespace = namespace :db do
Dir["#{fixtures_dir}/**/*.yml"].map { |f| f[(fixtures_dir.size + 1)..-5] }
end

if defined? ActiveStorage::FixtureSet
ActiveStorage::FixtureSet.file_fixture_path = File.join fixtures_dir, "files"
end

ActiveRecord::FixtureSet.create_fixtures(fixtures_dir, fixture_files)
end

Expand Down
14 changes: 14 additions & 0 deletions activestorage/lib/active_storage/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,5 +143,19 @@ class Engine < Rails::Engine # :nodoc:
ActiveRecord::Reflection.singleton_class.prepend(Reflection::ReflectionExtension)
end
end

initializer "active_storage.fixture_set" do
ActiveSupport.on_load(:active_record_fixture_set) do
ActiveStorage::FixtureSet.file_fixture_path ||= Rails.root.join(*[
ENV.fetch("FIXTURES_PATH") { File.join("test", "fixtures") },
ENV["FIXTURES_DIR"],
"files"
].compact_blank)
end

ActiveSupport.on_load(:active_support_test_case) do
ActiveStorage::FixtureSet.file_fixture_path = ActiveSupport::TestCase.file_fixture_path
end
end
end
end
4 changes: 0 additions & 4 deletions railties/lib/rails/test_help.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@
ActiveSupport.on_load(:action_dispatch_integration_test) do
self.fixture_path = ActiveSupport::TestCase.fixture_path
end

ActiveSupport.on_load(:active_storage_record) do
ActiveStorage::FixtureSet.file_fixture_path = ActiveSupport::TestCase.file_fixture_path
end
end

# :enddoc:
Expand Down

0 comments on commit cf2905d

Please sign in to comment.