From 8bc9062aee34ef590b21cab57b9b0a9da8872d24 Mon Sep 17 00:00:00 2001 From: bogdanvlviv Date: Thu, 7 Jun 2018 20:42:23 +0300 Subject: Refactor activestorage/test/models/attached_test.rb Don't include `ActiveJob::TestHelper` since there is no test that uses it. Ensure removing of overridden User's methods. Related to https://github.com/rails/rails/pull/33085#issuecomment-395548563 Module#remove_method is private in Ruby 2.4. Related to fd0bd1bf682622f064ac437ceee4e1b2a6b6d3b9 --- activestorage/test/models/attached_test.rb | 40 ++++++++++++++++-------------- 1 file changed, 21 insertions(+), 19 deletions(-) (limited to 'activestorage/test/models/attached_test.rb') diff --git a/activestorage/test/models/attached_test.rb b/activestorage/test/models/attached_test.rb index 14395e12df..b10d2bebe3 100644 --- a/activestorage/test/models/attached_test.rb +++ b/activestorage/test/models/attached_test.rb @@ -4,8 +4,6 @@ require "test_helper" require "database/setup" class ActiveStorage::AttachmentsTest < ActiveSupport::TestCase - include ActiveJob::TestHelper - setup do @user = User.create!(name: "Josh") end @@ -19,16 +17,18 @@ class ActiveStorage::AttachmentsTest < ActiveSupport::TestCase # inherited only assert_equal "funky.jpg", @user.avatar.filename.to_s - User.class_eval do - def avatar - super.filename.to_s.reverse + begin + User.class_eval do + def avatar + super.filename.to_s.reverse + end end - end - # override with super - assert_equal "funky.jpg".reverse, @user.avatar - - User.send(:remove_method, :avatar) + # override with super + assert_equal "funky.jpg".reverse, @user.avatar + ensure + User.send(:remove_method, :avatar) + end end test "overriding has_many_attached methods works" do @@ -39,16 +39,18 @@ class ActiveStorage::AttachmentsTest < ActiveSupport::TestCase assert_equal "funky.jpg", @user.highlights.first.filename.to_s assert_equal "wonky.jpg", @user.highlights.second.filename.to_s - User.class_eval do - def highlights - super.reverse + begin + User.class_eval do + def highlights + super.reverse + end end - end - - # override with super - assert_equal "wonky.jpg", @user.highlights.first.filename.to_s - assert_equal "funky.jpg", @user.highlights.second.filename.to_s - User.send(:remove_method, :highlights) + # override with super + assert_equal "wonky.jpg", @user.highlights.first.filename.to_s + assert_equal "funky.jpg", @user.highlights.second.filename.to_s + ensure + User.send(:remove_method, :highlights) + end end end -- cgit v1.2.3