adding :singular option to support has_one associations in load/authorize resource - closes #93
This commit is contained in:
@@ -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 }
|
||||
|
||||
Reference in New Issue
Block a user