Permalink
Browse files

add human_name support for rails compatibility

  • Loading branch information...
1 parent 7f8e123 commit 105d944b108bd101db8cb4709ce11b0c180b2645 Seth Ladd committed with jnunemaker Nov 13, 2009
@@ -4,6 +4,10 @@ module Document
def self.included(model)
model.class_eval do
alias_method :new_record?, :new?
+
+ def human_name
+ self.name.demodulize.humanize
+ end
end
end
end
@@ -17,6 +17,10 @@ module ClassMethods
def column_names
keys.keys
end
+
+ def human_name
+ self.name.demodulize.humanize
+ end
end
end
end
@@ -1,6 +1,10 @@
require 'test_helper'
class TestRailsCompatibility < Test::Unit::TestCase
+ class Stuff
+ include MongoMapper::Document
+ end
+
class Item
include MongoMapper::EmbeddedDocument
key :for_all, String
@@ -31,5 +35,15 @@ class SecondItem < Item
instance = Item.new
instance.new_record?.should == instance.new?
end
+
+ should "implement human_name" do
+ Item.human_name.should == 'Item'
+ end
+ end
+
+ context "Document" do
+ should "implement human_name" do
+ Stuff.human_name.should == 'Stuff'
+ end
end
end

0 comments on commit 105d944

Please sign in to comment.