can accept array for sql sanitizing in conditions

This commit is contained in:
Yura Sokolov 2010-05-25 14:01:53 +04:00
parent b473d8827f
commit 9c0346b90b
2 changed files with 17 additions and 1 deletions

View File

@ -302,7 +302,8 @@ module CanCan
can_definitions.each do |can_definition| can_definitions.each do |can_definition|
merge_association_joins(joins, can_definition.association_joins || []) merge_association_joins(joins, can_definition.association_joins || [])
end end
clear_association_joins(joins) joins = clear_association_joins(joins)
joins unless joins.empty?
end end
def merge_association_joins(what, with) def merge_association_joins(what, with)

View File

@ -270,6 +270,21 @@ describe CanCan::Ability do
@ability.sql_conditions(:read, SqlSanitizer).should == 'true=true' @ability.sql_conditions(:read, SqlSanitizer).should == 'true=true'
end 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 it "should has eated cheezburger" do
lambda { lambda {
@ability.can? :has, :cheezburger @ability.can? :has, :cheezburger