adding :singular option to support has_one associations in load/authorize resource - closes #93

This commit is contained in:
Ryan Bates
2010-08-06 11:03:10 -07:00
parent 6998e8bdd1
commit 84f4c904b7
3 changed files with 41 additions and 4 deletions

View File

@@ -166,6 +166,26 @@ describe CanCan::ControllerResource do
@controller.instance_variable_get(:@ability).should == :some_ability
end
it "should find record through has_one association with :singular option" do
@params.merge!(:action => "show")
person = Object.new
@controller.instance_variable_set(:@person, person)
stub(person).ability { :some_ability }
resource = CanCan::ControllerResource.new(@controller, :through => :person, :singular => true)
resource.load_resource
@controller.instance_variable_get(:@ability).should == :some_ability
end
it "should build record through has_one association with :singular option" do
@params.merge!(:action => "create", :ability => :ability_attributes)
person = Object.new
@controller.instance_variable_set(:@person, person)
stub(person).build_ability(:ability_attributes) { :new_ability }
resource = CanCan::ControllerResource.new(@controller, :through => :person, :singular => true)
resource.load_resource
@controller.instance_variable_get(:@ability).should == :new_ability
end
it "should only authorize :read action on parent resource" do
@params.merge!(:action => "new", :person_id => 123)
stub(Person).find(123) { :some_person }