Skip to content

Commit

Permalink
Refactor activestorage/test/models/attached_test.rb
Browse files Browse the repository at this point in the history
Don't include `ActiveJob::TestHelper` since there is no test that uses it.

Ensure removing of overridden User's methods.

Related to #33085 (comment)
Module#remove_method is private in Ruby 2.4.

Related to fd0bd1b
  • Loading branch information
bogdanvlviv committed Jun 7, 2018
1 parent 3573005 commit 8bc9062
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions activestorage/test/models/attached_test.rb
Expand Up @@ -4,8 +4,6 @@
require "database/setup"

class ActiveStorage::AttachmentsTest < ActiveSupport::TestCase
include ActiveJob::TestHelper

setup do
@user = User.create!(name: "Josh")
end
Expand All @@ -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
Expand All @@ -39,16 +39,18 @@ def avatar
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

0 comments on commit 8bc9062

Please sign in to comment.