Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fetched records should match the most liberally defined ability

  • Loading branch information...
commit e2783f5575ae9017b94f1725c26fd829cd087ba6 1 parent b4285ae
@iamvery authored
View
2  lib/cancan/model_adapters/active_record_adapter.rb
@@ -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
View
8 spec/cancan/model_adapters/active_record_adapter_spec.rb
@@ -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]
Please sign in to comment.
Something went wrong with that request. Please try again.