Skip to content

Commit

Permalink
Automatically add accessible_by to Mongoid Documents to match CanCa…
Browse files Browse the repository at this point in the history
…n behavior for ActiveRecord and DataMapper.

Previously, CanCan::ModelAdditions had to be included in each and every Mongoid document separately. Also removed manual include of CanCan::ModelAdditions from Mongoid documents in Mongoid adapter specs.
  • Loading branch information
bowsersenior committed Jan 3, 2011
1 parent 6ccb4dd commit f759ab7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 5 additions & 0 deletions lib/cancan/model_adapters/mongoid_adapter.rb
Expand Up @@ -51,3 +51,8 @@ def matches_conditions_hash_with_mongoid_subject?(subject, conditions = @conditi
alias_method :matches_conditions_hash?, :matches_conditions_hash_with_mongoid_subject?
end
end

# simplest way to add `accessible_by` to all Mongoid Documents
module Mongoid::Document::ClassMethods
include CanCan::ModelAdditions::ClassMethods
end
2 changes: 0 additions & 2 deletions spec/cancan/model_adapters/mongoid_adapter_spec.rb
Expand Up @@ -3,14 +3,12 @@

class MongoidCategory
include Mongoid::Document
include CanCan::ModelAdditions

references_many :mongoid_projects
end

class MongoidProject
include Mongoid::Document
include CanCan::ModelAdditions

referenced_in :mongoid_category

Expand Down

0 comments on commit f759ab7

Please sign in to comment.