Automatically add accessible_by to Mongoid Documents to match CanCan 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.
This commit is contained in:
Mani Tadayon 2011-01-03 12:32:44 -08:00
parent 6ccb4dd684
commit f759ab7e54
2 changed files with 5 additions and 2 deletions

View File

@ -51,3 +51,8 @@ module CanCan
alias_method :matches_conditions_hash?, :matches_conditions_hash_with_mongoid_subject? alias_method :matches_conditions_hash?, :matches_conditions_hash_with_mongoid_subject?
end end
end end
# simplest way to add `accessible_by` to all Mongoid Documents
module Mongoid::Document::ClassMethods
include CanCan::ModelAdditions::ClassMethods
end

View File

@ -3,14 +3,12 @@ if ENV["MODEL_ADAPTER"] == "mongoid"
class MongoidCategory class MongoidCategory
include Mongoid::Document include Mongoid::Document
include CanCan::ModelAdditions
references_many :mongoid_projects references_many :mongoid_projects
end end
class MongoidProject class MongoidProject
include Mongoid::Document include Mongoid::Document
include CanCan::ModelAdditions
referenced_in :mongoid_category referenced_in :mongoid_category