aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeorge Claghorn <george.claghorn@gmail.com>2018-06-07 19:49:29 -0400
committerGitHub <noreply@github.com>2018-06-07 19:49:29 -0400
commit6cd5cc375a5c78d08463254460b324a17d078586 (patch)
treee75b85d5d20974be5ac1f97ae80e7d79e8afd81e
parent93ef783e3ff4af1dbcd55003de11625da87ad53a (diff)
parent8bc9062aee34ef590b21cab57b9b0a9da8872d24 (diff)
downloadrails-6cd5cc375a5c78d08463254460b324a17d078586.tar.gz
rails-6cd5cc375a5c78d08463254460b324a17d078586.tar.bz2
rails-6cd5cc375a5c78d08463254460b324a17d078586.zip
Merge pull request #33089 from bogdanvlviv/refactor-attached_test.rb
Refactor 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