support loading resource :through method along with instance variable - closes #146

This commit is contained in:
Ryan Bates
2010-09-21 11:42:47 -07:00
parent 264e2d2b68
commit c11ffb6fd1
3 changed files with 21 additions and 3 deletions

View File

@@ -164,7 +164,7 @@ describe CanCan::ControllerResource do
@controller.instance_variable_get(:@project).should == :some_project
end
it "should load resource through the association of another parent resource" do
it "should load resource through the association of another parent resource using instance variable" do
@params.merge!(:action => "show", :id => 123)
category = Object.new
@controller.instance_variable_set(:@category, category)
@@ -174,6 +174,16 @@ describe CanCan::ControllerResource do
@controller.instance_variable_get(:@project).should == :some_project
end
it "should load resource through the association of another parent resource using method" do
@params.merge!(:action => "show", :id => 123)
category = Object.new
stub(@controller).category { category }
stub(category).projects.stub!.find(123) { :some_project }
resource = CanCan::ControllerResource.new(@controller, :through => :category)
resource.load_resource
@controller.instance_variable_get(:@project).should == :some_project
end
it "should not load through parent resource if instance isn't loaded when shallow" do
@params.merge!(:action => "show", :id => 123)
stub(Project).find(123) { :some_project }