Skip to content

Commit

Permalink
Merge pull request #45951 from vojtad/fix-active-support-current-attr…
Browse files Browse the repository at this point in the history
…ibutes-for-ruby-3

Fix ActiveSupport::CurrentAttributes for Ruby 3
  • Loading branch information
byroot authored Sep 6, 2022
2 parents e74d6ee + ad24aa5 commit c1e6127
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions activesupport/lib/active_support/current_attributes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ def method_missing(name, *args, &block)

send(name, *args, &block)
end
ruby2_keywords(:method_missing) if respond_to?(:ruby2_keywords, true)
end

attr_accessor :attributes
Expand Down
23 changes: 23 additions & 0 deletions activesupport/test/current_attributes_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@ def person=(person)
Session.current = person&.id
end

def set_world_and_account(world:, account:)
self.world = world
self.account = account
end

def get_world_and_account(hash)
hash[:world] = world
hash[:account] = account
hash
end

def request
"#{super} something"
end
Expand Down Expand Up @@ -126,6 +137,18 @@ def after_teardown
assert_equal "account/1", Current.account
end

test "using keyword arguments" do
Current.set_world_and_account(world: "world/1", account: "account/1")

assert_equal "world/1", Current.world
assert_equal "account/1", Current.account

hash = {}
assert_same hash, Current.get_world_and_account(hash)
assert_equal "world/1", hash[:world]
assert_equal "account/1", hash[:account]
end

setup { @testing_teardown = false }
teardown { assert_equal 42, Session.current if @testing_teardown }

Expand Down

0 comments on commit c1e6127

Please sign in to comment.