Skip to content

Commit

Permalink
Remove deprecated only_path option on *_path helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelfranca committed Jan 4, 2015
1 parent d282125 commit e4e1fd7
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 72 deletions.
4 changes: 4 additions & 0 deletions actionpack/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
* Remove deprecated `only_path` option on `*_path` helpers.

*Rafael Mendonça França*

* Remove deprecated `NamedRouteCollection#helpers`.

*Rafael Mendonça França*
Expand Down
29 changes: 1 addition & 28 deletions actionpack/lib/action_dispatch/routing/route_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def add(name, route)
@url_helpers_module.send :undef_method, url_name
end
routes[key] = route
define_url_helper @path_helpers_module, route, path_name, route.defaults, name, LEGACY
define_url_helper @path_helpers_module, route, path_name, route.defaults, name, PATH
define_url_helper @url_helpers_module, route, url_name, route.defaults, name, UNKNOWN

@path_helpers << path_name
Expand Down Expand Up @@ -319,34 +319,7 @@ def define_url_helper(mod, route, name, opts, route_key, url_strategy)
# :stopdoc:
# strategy for building urls to send to the client
PATH = ->(options) { ActionDispatch::Http::URL.path_for(options) }
FULL = ->(options) { ActionDispatch::Http::URL.full_url_for(options) }
UNKNOWN = ->(options) { ActionDispatch::Http::URL.url_for(options) }
LEGACY = ->(options) {
if options.key?(:only_path)
if options[:only_path]
ActiveSupport::Deprecation.warn(<<-MSG.squish)
You are calling a `*_path` helper with the `only_path` option
explicitly set to `true`. This option will stop working on
path helpers in Rails 5. Simply remove the `only_path: true`
argument from your call as it is redundant when applied to a
path helper.
MSG

PATH.call(options)
else
ActiveSupport::Deprecation.warn(<<-MSG.squish)
You are calling a `*_path` helper with the `only_path` option
explicitly set to `false`. This option will stop working on
path helpers in Rails 5. Use the corresponding `*_url` helper
instead.
MSG

FULL.call(options)
end
else
PATH.call(options)
end
}
# :startdoc:

attr_accessor :formatter, :set, :named_routes, :default_scope, :router
Expand Down
44 changes: 0 additions & 44 deletions actionpack/test/dispatch/routing/route_set_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,50 +105,6 @@ def call(env)
assert_equal 'http://example.com/foo', url_helpers.foo_url(only_path: false)
end

test "only_path: true with *_path" do
draw do
get 'foo', to: SimpleApp.new('foo#index')
end

assert_deprecated do
assert_equal '/foo', url_helpers.foo_path(only_path: true)
end
end

test "only_path: false with *_path with global :host option" do
@set.default_url_options = { host: 'example.com' }

draw do
get 'foo', to: SimpleApp.new('foo#index')
end

assert_deprecated do
assert_equal 'http://example.com/foo', url_helpers.foo_path(only_path: false)
end
end

test "only_path: false with *_path with local :host option" do
draw do
get 'foo', to: SimpleApp.new('foo#index')
end

assert_deprecated do
assert_equal 'http://example.com/foo', url_helpers.foo_path(only_path: false, host: 'example.com')
end
end

test "only_path: false with *_path with no :host option" do
draw do
get 'foo', to: SimpleApp.new('foo#index')
end

assert_deprecated do
assert_raises ArgumentError do
assert_equal 'http://example.com/foo', url_helpers.foo_path(only_path: false)
end
end
end

test "explicit keys win over implicit keys" do
draw do
resources :foo do
Expand Down

0 comments on commit e4e1fd7

Please sign in to comment.