Permalink
Browse files

renaming ActiveRecordAdditions#can method to accessible_by since it f…

…lows better and makes more sense
  • Loading branch information...
1 parent ef5900c commit 240c281061baad9b470dfc930c54144db95fd371 @ryanb committed Apr 16, 2010
Showing with 11 additions and 11 deletions.
  1. +1 −1 CHANGELOG.rdoc
  2. +3 −3 README.rdoc
  3. +1 −1 lib/cancan/ability.rb
  4. +3 −3 lib/cancan/active_record_additions.rb
  5. +3 −3 spec/cancan/active_record_additions_spec.rb
View
@@ -2,7 +2,7 @@
* Adding caching to current_ability controller method, if you're overriding this be sure to add caching too.
-* Adding "can" method to Active Record for fetching records matching a specific ability
+* Adding "accessible_by" method to Active Record for fetching records matching a specific ability
* Adding conditions behavior to Ability#can and fetch with Ability#conditions - see issue #53
View
@@ -180,13 +180,13 @@ Here the @book instance variable is already set so it will not be loaded again f
== Fetching Records
-Sometimes you need to restrict which records are returned from the database based on what the user is able to access. This can be done with the +can+ method on any Active Record model. Simply pass it the current ability and an action.
+Sometimes you need to restrict which records are returned from the database based on what the user is able to access. This can be done with the +accessible_by+ method on any Active Record model. Simply pass it the current ability and an action.
- @articles = Article.can(current_ability, :read)
+ @articles = Article.accessible_by(current_ability, :read)
The action defaults to :read so that can optionally be left out.
- @articles = Article.can(current_ability)
+ @articles = Article.accessible_by(current_ability)
Here only the records which the user can read will be returned. This is an Active Record scope so other scopes and pagination can be chained onto it.
@@ -191,7 +191,7 @@ def clear_aliased_actions
# can :read, Article, :visible => true
# conditions :read, Article # returns { :visible => true }
#
- # Normally you will not call this method directly, but instead go through ActiveRecordAdditions#can method.
+ # Normally you will not call this method directly, but instead go through ActiveRecordAdditions#accessible_by method.
#
# If the ability is not defined then false is returned so be sure to take that into consideration.
# If the ability is defined using a block then this will raise an exception since a hash of conditions cannot be
@@ -6,7 +6,7 @@ module ClassMethods
# can perform a given action on. The action defaults to :read. This
# is usually called from a controller and passed the +current_ability+.
#
- # @articles = Article.can(current_ability)
+ # @articles = Article.accessible_by(current_ability)
#
# Here only the articles which the user is able to read will be returned.
# If the user does not have permission to read any articles then an empty
@@ -15,11 +15,11 @@ module ClassMethods
#
# An alternative action can optionally be passed as a second argument.
#
- # @articles = Article.can(current_ability, :update)
+ # @articles = Article.accessible_by(current_ability, :update)
#
# Here only the articles which the user can update are returned. This
# internally uses Ability#conditions method, see that for more information.
- def can(ability, action = :read)
+ def accessible_by(ability, action = :read)
conditions = ability.conditions(action, self) || {:id => nil}
if respond_to? :where
where(conditions)
@@ -11,18 +11,18 @@
it "should call where(:id => nil) when no ability is defined so no records are found" do
stub(@model_class).where(:id => nil) { :no_where }
- @model_class.can(@ability, :read).should == :no_where
+ @model_class.accessible_by(@ability, :read).should == :no_where
end
it "should call where with matching ability conditions" do
@ability.can :read, @model_class, :foo => 1
stub(@model_class).where(:foo => 1) { :found_records }
- @model_class.can(@ability, :read).should == :found_records
+ @model_class.accessible_by(@ability, :read).should == :found_records
end
it "should default to :read ability and use scoped when where isn't available" do
@ability.can :read, @model_class, :foo => 1
stub(@model_class).scoped(:conditions => {:foo => 1}) { :found_records }
- @model_class.can(@ability).should == :found_records
+ @model_class.accessible_by(@ability).should == :found_records
end
end

0 comments on commit 240c281

Please sign in to comment.