Skip to content

Instantly share code, notes, and snippets.

@voxik
Created November 6, 2010 16:11
Show Gist options
  • Save voxik/665512 to your computer and use it in GitHub Desktop.
Save voxik/665512 to your computer and use it in GitHub Desktop.
From 209aa3bcc57cf5ead57a179a8045d50e41a8d63d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?V=C3=ADt=20Ondruch?= <[email protected]>
Date: Sat, 6 Nov 2010 17:09:47 +0100
Subject: [PATCH] Make accessible_by play better with default scaffolded RSpec.
---
lib/cancan/active_record_additions.rb | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/cancan/active_record_additions.rb b/lib/cancan/active_record_additions.rb
index 24f03ae..5c31a58 100644
--- a/lib/cancan/active_record_additions.rb
+++ b/lib/cancan/active_record_additions.rb
@@ -21,8 +21,8 @@ module CanCan
# internally uses Ability#conditions method, see that for more information.
def accessible_by(ability, action = :read)
query = ability.query(action, self)
- if respond_to? :where
- where(query.conditions).joins(query.joins)
+ if respond_to? :all and query.conditions.empty? and query.joins.nil?
+ all
else
scoped(:conditions => query.conditions, :joins => query.joins)
end
--
1.7.2.3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment