spec/support/mongo_mapper/models.rb in audited-3.0.0.rc1 vs spec/support/mongo_mapper/models.rb in audited-3.0.0.rc2
- old
+ new
@@ -13,11 +13,11 @@
key :activated, Boolean
key :suspended_at, Time
key :logins, Integer, :default => 0
timestamps!
- audited :except => :password
+ audited :allow_mass_assignment => true, :except => :password
attr_protected :logins
def name=(val)
write_attribute(:name, CGI.escapeHTML(val))
@@ -36,26 +36,26 @@
timestamps!
audited :comment_required => true
end
- class UnprotectedUser
+ class AccessibleAfterDeclarationUser
include ::MongoMapper::Document
key :name, String
key :username, String
key :password, String
key :activated, Boolean
key :suspended_at, Time
key :logins, Integer, :default => 0
timestamps!
- audited :protect => false
+ audited
attr_accessible :name, :username, :password
end
- class AccessibleUser
+ class AccessibleBeforeDeclarationUser
include ::MongoMapper::Document
key :name, String
key :username, String
key :password, String
@@ -77,11 +77,11 @@
key :activated, Boolean
key :suspended_at, Time
key :logins, Integer, :default => 0
timestamps!
- audited
+ audited :allow_mass_assignment => true
end
class UserWithAfterAudit
include ::MongoMapper::Document
@@ -167,8 +167,44 @@
key :name, String
key :owner_id, ObjectId
audited :on => [:create, :update]
+ end
+
+ class RichObjectUser
+ include ::MongoMapper::Document
+
+ class Name
+ attr_accessor :first_name, :last_name
+
+ def self.from_mongo(value)
+ case value
+ when String then new(*value.split)
+ when self then value
+ end
+ end
+
+ def self.to_mongo(value)
+ case value
+ when String then value
+ when self then value.to_s
+ end
+ end
+
+ def initialize(first_name, last_name)
+ self.first_name, self.last_name = first_name, last_name
+ end
+
+ def to_s
+ [first_name, last_name].compact.join(' ')
+ end
+ end
+
+ key :name, Name
+
+ attr_accessible :name
+
+ audited
end
end
end