diff --git a/lib/cancan/ability.rb b/lib/cancan/ability.rb index ba308dc..53cb409 100644 --- a/lib/cancan/ability.rb +++ b/lib/cancan/ability.rb @@ -302,7 +302,8 @@ module CanCan can_definitions.each do |can_definition| merge_association_joins(joins, can_definition.association_joins || []) end - clear_association_joins(joins) + joins = clear_association_joins(joins) + joins unless joins.empty? end def merge_association_joins(what, with) diff --git a/spec/cancan/ability_spec.rb b/spec/cancan/ability_spec.rb index d76afd5..d8dd689 100644 --- a/spec/cancan/ability_spec.rb +++ b/spec/cancan/ability_spec.rb @@ -270,6 +270,21 @@ describe CanCan::Ability do @ability.sql_conditions(:read, SqlSanitizer).should == 'true=true' end + it "should accept array condition for use in sql" do + @ability.can :read, SqlSanitizer, ["user_id = ?", 1] + + @ability.sql_conditions(:read, SqlSanitizer).should == ['user_id = ?', 1] + @ability.association_joins(:read, SqlSanitizer).should be_nil + end + + it "should accept array condition for use in sql and do sanitizing in complex conditions" do + @ability.cannot :read, SqlSanitizer + @ability.can :read, SqlSanitizer, ["user_id = ?", 1] + + @ability.sql_conditions(:read, SqlSanitizer).should == 'user_id = 1' + @ability.association_joins(:read, SqlSanitizer).should be_nil + end + it "should has eated cheezburger" do lambda { @ability.can? :has, :cheezburger