Permalink
Browse files

Remove ActionController::Base.resources_path_names

  • Loading branch information...
1 parent ba57575 commit 6a061187e26f0942c458a859c8e941ed092a48c1 Carl Lerche committed Feb 24, 2010
@@ -20,8 +20,6 @@ class ::ActionController::ActionControllerError < StandardError #:nodoc:
class << self
delegate :default_charset=, :to => "ActionDispatch::Response"
- delegate :resources_path_names, :to => "ActionDispatch::Routing::Routes"
- delegate :resources_path_names=, :to => "ActionDispatch::Routing::Routes"
end
# cattr_reader :protected_instance_variables
@@ -244,14 +244,15 @@ class Resource #:nodoc:
attr_reader :collection_methods, :member_methods, :new_methods
attr_reader :path_prefix, :name_prefix, :path_segment
attr_reader :plural, :singular
- attr_reader :options
+ attr_reader :options, :defaults
- def initialize(entities, options)
+ def initialize(entities, options, defaults)
@plural ||= entities
@singular ||= options[:singular] || plural.to_s.singularize
@path_segment = options.delete(:as) || @plural
@options = options
+ @defaults = defaults
arrange_actions
add_default_actions
@@ -280,7 +281,7 @@ def path
def new_path
new_action = self.options[:path_names][:new] if self.options[:path_names]
- new_action ||= ActionController::Base.resources_path_names[:new]
+ new_action ||= self.defaults[:path_names][:new]
@new_path ||= "#{path}/#{new_action}"
end
@@ -370,7 +371,7 @@ def add_default_action(collection, method, action)
end
class SingletonResource < Resource #:nodoc:
- def initialize(entity, options)
+ def initialize(entity, options, defaults)
@singular = @plural = entity
options[:controller] ||= @singular.to_s.pluralize
super
@@ -717,7 +718,7 @@ def resource(*entities, &block)
private
def map_resource(entities, options = {}, &block)
- resource = Resource.new(entities, options)
+ resource = Resource.new(entities, options, :path_names => @set.resources_path_names)
with_options :controller => resource.controller do |map|
map_associations(resource, options)
@@ -734,7 +735,7 @@ def map_resource(entities, options = {}, &block)
end
def map_singleton_resource(entities, options = {}, &block)
- resource = SingletonResource.new(entities, options)
+ resource = SingletonResource.new(entities, options, :path_names => @set.resources_path_names)
with_options :controller => resource.controller do |map|
map_associations(resource, options)
@@ -826,7 +827,7 @@ def map_member_actions(map, resource)
actions.each do |action|
[method].flatten.each do |m|
action_path = resource.options[:path_names][action] if resource.options[:path_names].is_a?(Hash)
- action_path ||= ActionController::Base.resources_path_names[action] || action
+ action_path ||= @set.resources_path_names[action] || action
map_resource_routes(map, resource, action, "#{resource.member_path}#{resource.action_separator}#{action_path}", "#{action}_#{resource.shallow_name_prefix}#{resource.singular}", m, { :force_id => true })
end
@@ -31,10 +31,10 @@ class ImagesController < ResourcesController; end
class ResourcesTest < ActionController::TestCase
def test_should_arrange_actions
- resource = ActionDispatch::Routing::DeprecatedMapper::Resource.new(:messages,
+ resource = ActionDispatch::Routing::DeprecatedMapper::Resource.new(:messages, {
:collection => { :rss => :get, :reorder => :post, :csv => :post },
:member => { :rss => :get, :atom => :get, :upload => :post, :fix => :post },
- :new => { :preview => :get, :draft => :get })
+ :new => { :preview => :get, :draft => :get }}, {})
assert_resource_methods [:rss], resource, :collection, :get
assert_resource_methods [:csv, :reorder], resource, :collection, :post
@@ -44,18 +44,18 @@ def test_should_arrange_actions
end
def test_should_resource_controller_name_equal_resource_name_by_default
- resource = ActionDispatch::Routing::DeprecatedMapper::Resource.new(:messages, {})
+ resource = ActionDispatch::Routing::DeprecatedMapper::Resource.new(:messages, {}, {})
assert_equal 'messages', resource.controller
end
def test_should_resource_controller_name_equal_controller_option
- resource = ActionDispatch::Routing::DeprecatedMapper::Resource.new(:messages, :controller => 'posts')
+ resource = ActionDispatch::Routing::DeprecatedMapper::Resource.new(:messages, {:controller => 'posts'}, {})
assert_equal 'posts', resource.controller
end
def test_should_all_singleton_paths_be_the_same
[ :path, :nesting_path_prefix, :member_path ].each do |method|
- resource = ActionDispatch::Routing::DeprecatedMapper::SingletonResource.new(:messages, :path_prefix => 'admin')
+ resource = ActionDispatch::Routing::DeprecatedMapper::SingletonResource.new(:messages, {:path_prefix => 'admin'}, {})
assert_equal 'admin/messages', resource.send(method)
end
end
@@ -111,8 +111,8 @@ def test_override_paths_for_member_and_collection_methods
end
def test_override_paths_for_default_restful_actions
- resource = ActionDispatch::Routing::DeprecatedMapper::Resource.new(:messages,
- :path_names => {:new => 'nuevo', :edit => 'editar'})
+ resource = ActionDispatch::Routing::DeprecatedMapper::Resource.new(:messages, {
+ :path_names => {:new => 'nuevo', :edit => 'editar'}}, {})
assert_equal resource.new_path, "#{resource.path}/nuevo"
end
@@ -1162,8 +1162,9 @@ def assert_restful_routes_for(controller_name, options = {})
options[:shallow_options] = options[:options]
end
- new_action = ActionController::Base.resources_path_names[:new] || "new"
- edit_action = ActionController::Base.resources_path_names[:edit] || "edit"
+ new_action = ActionDispatch::Routing::Routes.resources_path_names[:new] || "new"
+ edit_action = ActionDispatch::Routing::Routes.resources_path_names[:edit] || "edit"
+
if options[:path_names]
new_action = options[:path_names][:new] if options[:path_names][:new]
edit_action = options[:path_names][:edit] if options[:path_names][:edit]

0 comments on commit 6a06118

Please sign in to comment.