Navigation Menu

Skip to content

Commit

Permalink
Use string eval instead of define_method for integration session me…
Browse files Browse the repository at this point in the history
…thod delegation

This is an alternative of b7e591a and a43de73.

Handling `if options.any?` is not preferable solution for kwargs.
  • Loading branch information
kamipo committed Feb 5, 2020
1 parent 9b797b9 commit 1dac170
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions actionpack/lib/action_dispatch/testing/integration.rb
Expand Up @@ -354,20 +354,22 @@ def remove! # :nodoc:
end

%w(get post patch put head delete cookies assigns follow_redirect!).each do |method|
define_method(method) do |*args, **options|
# reset the html_document variable, except for cookies/assigns calls
unless method == "cookies" || method == "assigns"
@html_document = nil
end
# reset the html_document variable, except for cookies/assigns calls
unless method == "cookies" || method == "assigns"
reset_html_document = "@html_document = nil"
end

result = if options.any?
integration_session.__send__(method, *args, **options)
else
integration_session.__send__(method, *args)
definition = RUBY_VERSION >= "2.7" ? "..." : "*args"

module_eval <<~RUBY, __FILE__, __LINE__ + 1
def #{method}(#{definition})
#{reset_html_document}
result = integration_session.#{method}(#{definition})
copy_session_variables!
result
end
copy_session_variables!
result
end
RUBY
end

# Open a new session instance. If a block is given, the new session is
Expand Down

0 comments on commit 1dac170

Please sign in to comment.