Skip to content
This repository has been archived by the owner on Dec 12, 2021. It is now read-only.

Commit

Permalink
quick fix to get nested resources working again - closes #482
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanb committed Oct 4, 2011
1 parent 26b40f2 commit 67a3038
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion cancan.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Gem::Specification.new do |s|
s.files = Dir["{lib,spec}/**/*", "[A-Z]*", "init.rb"] - ["Gemfile.lock"]
s.require_path = "lib"

s.add_development_dependency 'rspec', '~> 2.1.0'
s.add_development_dependency 'rspec', '~> 2.6.0'
s.add_development_dependency 'rails', '~> 3.0.9'
s.add_development_dependency 'rr', '~> 0.10.11' # 1.0.0 has respond_to? issues: http://github.com/btakita/rr/issues/issue/43
s.add_development_dependency 'supermodel', '~> 0.1.4'
Expand Down
2 changes: 1 addition & 1 deletion lib/cancan/controller_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def name
end

def namespaced_name
@params[:controller].sub("Controller", "").singularize.camelize.constantize
@name || @params[:controller].sub("Controller", "").singularize.camelize.constantize
rescue NameError
name
end
Expand Down
4 changes: 2 additions & 2 deletions spec/cancan/controller_resource_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,8 @@ class Project < ::Project; end

it "should load parent resource through proper id parameter" do
project = Project.create!
@params.merge!(:action => "index", :project_id => project.id)
resource = CanCan::ControllerResource.new(@controller, :project, :parent => true)
@params.merge!(:controller => "categories", :action => "index", :project_id => project.id)
resource = CanCan::ControllerResource.new(@controller, :project)
resource.load_resource
@controller.instance_variable_get(:@project).should == project
end
Expand Down
4 changes: 0 additions & 4 deletions spec/cancan/model_adapters/active_record_adapter_spec.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
if ENV["MODEL_ADAPTER"].nil? || ENV["MODEL_ADAPTER"] == "active_record"
require "spec_helper"

RSpec.configure do |config|
config.extend WithModel
end

ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")

describe CanCan::ModelAdapters::ActiveRecordAdapter do
Expand Down
4 changes: 4 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@
require 'cancan/matchers'

RSpec.configure do |config|
config.treat_symbols_as_metadata_keys_with_true_values = true
config.filter_run :focus => true
config.run_all_when_everything_filtered = true
config.mock_with :rr
config.before(:each) do
Project.delete_all
Category.delete_all
end
config.extend WithModel

This comment has been minimized.

Copy link
@andhapp

andhapp May 10, 2012

Collaborator

This causes failures for data_mapper and mongoid since with_model is only part of active_record specs.

end

class Ability
Expand Down

2 comments on commit 67a3038

@jibiel
Copy link

@jibiel jibiel commented on 67a3038 Feb 23, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please merge this fix to the 2.0 branch?

@harmdewit
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes please merge this fix, it solves a nested resource problem on 2.0.

Without this fix nested resources don't work correctly. My controller code:

  load_and_authorize_resource :user
  load_and_authorize_resource :strategy, through: :user

Gave me the error undefined method "strategies" for #<Strategy:0x007fcddef74528>. It is because of the namespaced_name method in controller_resource.rb on line 211

Please sign in to comment.