Make sure conditions on associations are pluralized

This commit is contained in:
Logan Raarup
2010-05-11 19:30:28 +08:00
committed by Ryan Bates
parent 06296b0a40
commit 605063b974
5 changed files with 26 additions and 6 deletions

View File

@@ -16,13 +16,13 @@ describe CanCan::ActiveRecordAdditions do
it "should call where with matching ability conditions" do
@ability.can :read, @model_class, :foo => {:bar => 1}
stub(@model_class).where(:foo => { :bar => 1 }).stub!.joins([:foo]) { :found_records }
stub(@model_class).where(:foos => { :bar => 1 }).stub!.joins([:foo]) { :found_records }
@model_class.accessible_by(@ability, :read).should == :found_records
end
it "should default to :read ability and use scoped when where isn't available" do
@ability.can :read, @model_class, :foo => {:bar => 1}
stub(@model_class).scoped(:conditions => {:foo => {:bar => 1}}, :joins => [:foo]) { :found_records }
stub(@model_class).scoped(:conditions => {:foos => {:bar => 1}}, :joins => [:foo]) { :found_records }
@model_class.accessible_by(@ability).should == :found_records
end
end

View File

@@ -30,4 +30,10 @@ describe CanCan::CanDefinition do
@conditions[:foo] = {:bar => {1 => 2}}
@can.association_joins.should == [{:foo => [:bar]}]
end
it "should return table names in conditions for association joins" do
@conditions[:foo] = {:bar => 1}
@conditions[:test] = 1
@can.conditions(:tableize => true).should == { :foos => { :bar => 1}, :test => 1 }
end
end