Permalink
Browse files

Fetched records should match the most liberally defined ability

  • Loading branch information...
1 parent b4285ae commit e2783f5575ae9017b94f1725c26fd829cd087ba6 @iamvery iamvery committed Aug 10, 2012
@@ -89,7 +89,7 @@ def database_records
if override_scope
@model_class.scoped.merge(override_scope)
elsif @model_class.respond_to?(:where) && @model_class.respond_to?(:joins)
- mergeable_conditions = @rules.select {|rule| rule.unmergeable? }.blank?
+ mergeable_conditions = conditions == true_sql || @rules.select {|rule| rule.unmergeable? }.blank?
if mergeable_conditions
@model_class.where(conditions).joins(joins)
else
@@ -109,6 +109,14 @@
Comment.accessible_by(@ability).should == [comment1]
end
+ it "should fetch articles matching the most liberal ability" do
+ @ability.can :read, Article
+ @ability.can :read, Article, :published => true
+ article1 = Article.create!(:published => true)
+ article2 = Article.create!(:published => false)
+ Article.accessible_by(@ability).should == [article1, article2]
+ end
+
it "should allow conditions in SQL and merge with hash conditions" do
@ability.can :read, Article, :published => true
@ability.can :read, Article, ["secret=?", true]

0 comments on commit e2783f5

Please sign in to comment.