Skip to content

Commit

Permalink
Added to Userstamps plugin a way to use a unconventionally named User…
Browse files Browse the repository at this point in the history
… class (e.g., SpecialUser).
  • Loading branch information
Mark Coates (oddlyzen) authored and bkeepers committed Sep 2, 2011
1 parent 58c8735 commit 4f68bcf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
9 changes: 6 additions & 3 deletions lib/mongo_mapper/plugins/userstamps.rb
Expand Up @@ -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
Expand Down
14 changes: 10 additions & 4 deletions test/functional/test_userstamps.rb
Expand Up @@ -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.