mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #20444 from y-yagi/can_use_path_helper_method_in_console
modify console of app method in that can use the path helpers
This commit is contained in:
commit
847a5ea7db
2 changed files with 17 additions and 0 deletions
|
@ -18,6 +18,11 @@ module Rails
|
||||||
app = Rails.application
|
app = Rails.application
|
||||||
session = ActionDispatch::Integration::Session.new(app)
|
session = ActionDispatch::Integration::Session.new(app)
|
||||||
yield session if block_given?
|
yield session if block_given?
|
||||||
|
|
||||||
|
# This makes app.url_for and app.foo_path available in the console
|
||||||
|
session.extend(app.routes.url_helpers)
|
||||||
|
session.extend(app.routes.mounted_helpers)
|
||||||
|
|
||||||
session
|
session
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,18 @@ class ConsoleTest < ActiveSupport::TestCase
|
||||||
assert_instance_of ActionDispatch::Integration::Session, console_session
|
assert_instance_of ActionDispatch::Integration::Session, console_session
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_app_can_access_path_helper_method
|
||||||
|
app_file 'config/routes.rb', <<-RUBY
|
||||||
|
Rails.application.routes.draw do
|
||||||
|
get 'foo', to: 'foo#index'
|
||||||
|
end
|
||||||
|
RUBY
|
||||||
|
|
||||||
|
load_environment
|
||||||
|
console_session = irb_context.app
|
||||||
|
assert_equal '/foo', console_session.foo_path
|
||||||
|
end
|
||||||
|
|
||||||
def test_new_session_should_return_integration_session
|
def test_new_session_should_return_integration_session
|
||||||
load_environment
|
load_environment
|
||||||
session = irb_context.new_session
|
session = irb_context.new_session
|
||||||
|
|
Loading…
Reference in a new issue