allow query.conditions to be called multiple times without losing conditions
This commit is contained in:
parent
9b8e84944c
commit
5e1e6e182b
|
@ -26,10 +26,10 @@ module CanCan
|
|||
def conditions
|
||||
if @rules.size == 1 && @rules.first.base_behavior
|
||||
# Return the conditions directly if there's just one definition
|
||||
@rules.first.tableized_conditions
|
||||
@rules.first.tableized_conditions.dup
|
||||
else
|
||||
@rules.reverse.inject(false_sql) do |sql, rule|
|
||||
merge_conditions(sql, rule.tableized_conditions, rule.base_behavior)
|
||||
merge_conditions(sql, rule.tableized_conditions.dup, rule.base_behavior)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -104,4 +104,13 @@ describe CanCan::Query do
|
|||
@ability.can :read, Project, :project => { :foo => {:bar => true}, :bar => {:zip => :zap} }
|
||||
@ability.query(:read, Project).joins.inspect.should orderlessly_match([{:project => [:bar, :foo]}, {:company => [:bar]}].inspect)
|
||||
end
|
||||
|
||||
it "should not forget conditions when calling with SQL string" do
|
||||
@ability.can :read, Project, :foo => 1
|
||||
@ability.can :read, Project, ['bar = ?', 1]
|
||||
query = @ability.query(:read, Project)
|
||||
2.times do
|
||||
query.conditions.should == "(bar = 1) OR (foo=1)"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue
Block a user