Skip to content

Commit

Permalink
enclosing_resource_name is the name of the mapped enclosing resource …
Browse files Browse the repository at this point in the history
…(which may not be the class name underscored).

This keeps parity with resource_name, and allows sending params to the enclosing_resource_path like enclosing_resource_path(enclosing_resource_name => {:enabled => true})
  • Loading branch information
ianwhite committed Oct 10, 2008
1 parent 264608d commit 40174b5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
3 changes: 2 additions & 1 deletion lib/ardes/resources_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ def enclosing_resource

# returns the name of the immediately enclosing resource
def enclosing_resource_name
enclosing_resource.class.name.underscore
@enclosing_resource_name
end

# returns the resource service for the controller - this will be lazilly created
Expand Down Expand Up @@ -781,6 +781,7 @@ def add_enclosing_resource(resource, options = {})
update_name_prefix(options[:name_prefix] || (options[:name_prefix] == false ? '' : "#{name}_"))
enclosing_resources << resource
enclosing_collection_resources << resource unless options[:is_singleton]
instance_variable_set("@enclosing_resource_name", options[:name])
instance_variable_set("@#{name}", resource)
instance_variable_set("@#{options[:as]}", resource) if options[:as]
end
Expand Down
16 changes: 8 additions & 8 deletions spec/lib/resources_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,23 @@
it "resources_controller_for :forums, :in => [:user, '*', '*', :comment] should raise argument error (no multiple wildcards in a row)" do
lambda { @controller.resources_controller_for :forums, :in => [:user, '*', '*', :comment] }.should raise_error(ArgumentError)
end


end

describe "ResourcesController#enclosing_resource_name" do
before do
@controller = ForumsController.new
@controller = TagsController.new
info = mock_model(Info, :tags => [])
@controller.stub!(:current_user).and_return(mock_model(User, :info => info))
@controller.stub!(:recognized_route).and_return(ActionController::Routing::Routes.named_routes[:account_info_tags])
@controller.send :load_enclosing_resources
end

it "should be the class name underscored" do
@controller.instance_variable_set('@enclosing_resources', [mock_model(User)])
@controller.enclosing_resource_name.should == 'user'
it "should be the name of the mapped enclosing_resource" do
@controller.enclosing_resource_name.should == 'info'
end
end

describe "A controller's resource_service" do

before do
@controller = ForumsController.new
end
Expand All @@ -54,4 +54,4 @@
@controller.save_resource
end
end
end
end

0 comments on commit 40174b5

Please sign in to comment.