Skip to content
Snippets Groups Projects
Commit 9c0346b9 authored by Yura Sokolov's avatar Yura Sokolov
Browse files

can accept array for sql sanitizing in conditions

parent b473d882
No related branches found
No related tags found
No related merge requests found
......@@ -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)
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment