2010-09-09 23:28:00 +00:00
|
|
|
require "spec_helper"
|
|
|
|
|
|
|
|
describe CanCan::InheritedResource do
|
|
|
|
before(:each) do
|
|
|
|
@params = HashWithIndifferentAccess.new(:controller => "projects")
|
2011-01-08 20:04:55 +00:00
|
|
|
@controller_class = Class.new
|
|
|
|
@controller = @controller_class.new
|
2010-09-09 23:28:00 +00:00
|
|
|
@ability = Ability.new(nil)
|
|
|
|
stub(@controller).params { @params }
|
|
|
|
stub(@controller).current_ability { @ability }
|
2011-01-08 20:04:55 +00:00
|
|
|
stub(@controller_class).cancan_skipper { {:authorize => {}, :load => {}} }
|
2010-09-09 23:28:00 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "show should load resource through @controller.resource" do
|
2011-03-09 00:10:40 +00:00
|
|
|
@params.merge!(:action => "show", :id => 123)
|
2010-09-09 23:28:00 +00:00
|
|
|
stub(@controller).resource { :project_resource }
|
|
|
|
CanCan::InheritedResource.new(@controller).load_resource
|
|
|
|
@controller.instance_variable_get(:@project).should == :project_resource
|
|
|
|
end
|
|
|
|
|
|
|
|
it "new should load through @controller.build_resource" do
|
|
|
|
@params[:action] = "new"
|
|
|
|
stub(@controller).build_resource { :project_resource }
|
|
|
|
CanCan::InheritedResource.new(@controller).load_resource
|
|
|
|
@controller.instance_variable_get(:@project).should == :project_resource
|
|
|
|
end
|
|
|
|
|
2011-03-08 23:39:15 +00:00
|
|
|
it "index should load through @controller.association_chain when parent" do
|
2010-09-09 23:28:00 +00:00
|
|
|
@params[:action] = "index"
|
2011-03-08 23:39:15 +00:00
|
|
|
stub(@controller).association_chain { @controller.instance_variable_set(:@project, :project_resource) }
|
2010-09-09 23:28:00 +00:00
|
|
|
CanCan::InheritedResource.new(@controller, :parent => true).load_resource
|
|
|
|
@controller.instance_variable_get(:@project).should == :project_resource
|
|
|
|
end
|
|
|
|
|
2011-03-16 00:08:17 +00:00
|
|
|
it "index should load through @controller.end_of_association_chain" do
|
2010-09-09 23:28:00 +00:00
|
|
|
@params[:action] = "index"
|
2011-02-14 18:33:53 +00:00
|
|
|
stub(Project).accessible_by(@ability, :index) { :projects }
|
2011-03-16 00:08:17 +00:00
|
|
|
stub(@controller).end_of_association_chain { Project }
|
2010-09-09 23:28:00 +00:00
|
|
|
CanCan::InheritedResource.new(@controller).load_resource
|
|
|
|
@controller.instance_variable_get(:@projects).should == :projects
|
|
|
|
end
|
|
|
|
end
|