Created
January 6, 2014 06:17
-
-
Save pixeltrix/8278962 to your computer and use it in GitHub Desktop.
Where to put default_url_options
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'action_controller/railtie' | |
require 'minitest/autorun' | |
class RoutingApp < Rails::Application | |
config.eager_load = false | |
config.root = File.dirname(__FILE__) | |
config.session_store :cookie_store, key: 'session' | |
config.secret_key_base = 'secret' | |
end | |
RoutingApp.initialize! | |
RoutingApp.routes.draw do | |
default_url_options host: 'routes.rb' | |
root to: 'pages#index' | |
end | |
class Foo | |
include Rails.application.routes.url_helpers | |
end | |
class Bar | |
include Rails.application.routes.url_helpers | |
def default_url_options | |
{ host: 'job.rb' } | |
end | |
end | |
require 'rails/test_help' | |
class RoutingTest < ActiveSupport::TestCase | |
def test_default_url_options_in_routes_rb | |
assert_equal 'http://routes.rb/', Rails.application.routes.url_helpers.root_url | |
end | |
def test_default_url_options_in_class | |
assert_equal 'http://routes.rb/', Foo.new.root_url | |
end | |
def test_overriding_default_url_options_in_class | |
assert_equal 'http://job.rb/', Bar.new.root_url | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment