Permalink
Browse files

Added to Userstamps plugin a way to use a unconventionally named User…

… class (e.g., SpecialUser).
  • Loading branch information...
Mark Coates (oddlyzen) authored and bkeepers committed Jun 17, 2011
1 parent 58c8735 commit 4f68bcf64b580d0f5c0dfea42cbab854081f07ea
Showing with 16 additions and 7 deletions.
  1. +6 −3 lib/mongo_mapper/plugins/userstamps.rb
  2. +10 −4 test/functional/test_userstamps.rb
@@ -5,11 +5,14 @@ module Userstamps
extend ActiveSupport::Concern
module ClassMethods
- def userstamps!
+ def userstamps!(class_name = 'User')
key :creator_id, ObjectId
key :updater_id, ObjectId
- belongs_to :creator, :class_name => 'User'
- belongs_to :updater, :class_name => 'User'
+ belongs_to :creator, :class_name => class_name
+ belongs_to :updater, :class_name => class_name
+ end
+ def userstamps_for!(class_name = 'User')
+ userstamps!(class_name)
end
end
end
@@ -6,22 +6,28 @@ class UserstampsTest < Test::Unit::TestCase
@document = Doc do
userstamps!
end
+ @document_alt_user = Doc do
+ userstamps! 'AltUser'
+ end
+ @document_for_alt_user = Doc do
+ userstamps_for! 'AltUser'
+ end
end
should "add creator_id key" do
- @document.keys.keys.should include('creator_id')
+ [@document, @document_alt_user, @document_for_alt_user].each{ |d| d.keys.keys.should include('creator_id') }
end
should "add updater_id key" do
- @document.keys.keys.should include('updater_id')
+ [@document, @document_alt_user, @document_for_alt_user].each{ |d| d.keys.keys.should include('updater_id') }
end
should "add belongs_to creator" do
- @document.associations.keys.should include(:creator)
+ [@document, @document_alt_user, @document_for_alt_user].each{ |d| d.associations.keys.should include(:creator) }
end
should "add belongs_to updater" do
- @document.associations.keys.should include(:updater)
+ [@document, @document_alt_user, @document_for_alt_user].each{ |d| d.associations.keys.should include(:updater) }
end
end
end

0 comments on commit 4f68bcf

Please sign in to comment.