aboutsummaryrefslogtreecommitdiffstats
path: root/activestorage/test/models/attached_test.rb
diff options
context:
space:
mode:
authorbogdanvlviv <bogdanvlviv@gmail.com>2018-06-07 20:42:23 +0300
committerbogdanvlviv <bogdanvlviv@gmail.com>2018-06-07 23:29:03 +0300
commit8bc9062aee34ef590b21cab57b9b0a9da8872d24 (patch)
treede7ebac86327922e48a14e80862f43d97526eacb /activestorage/test/models/attached_test.rb
parent35730055174c3b4b4dd2b08fc743e425310d5131 (diff)
downloadrails-8bc9062aee34ef590b21cab57b9b0a9da8872d24.tar.gz
rails-8bc9062aee34ef590b21cab57b9b0a9da8872d24.tar.bz2
rails-8bc9062aee34ef590b21cab57b9b0a9da8872d24.zip
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
Diffstat (limited to 'activestorage/test/models/attached_test.rb')
-rw-r--r--activestorage/test/models/attached_test.rb40
1 files changed, 21 insertions, 19 deletions
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