Permalink
Browse files

Adding ability to set collection name on documents

  • Loading branch information...
1 parent 045ebab commit 34a5098d741e41694d4b332011ca51382cee4fee @durran durran committed Dec 27, 2009
Showing with 22 additions and 0 deletions.
  1. +5 −0 lib/mongoid/document.rb
  2. +4 −0 spec/spec_helper.rb
  3. +13 −0 spec/unit/mongoid/document_spec.rb
@@ -26,6 +26,11 @@ def collection
@collection ||= Mongoid.database.collection(@collection_name)
end
+ # Set the collection name for the +Document+.
+ def collection_name(name)
+ @collection_name = name
+ end
+
# Returns a hash of all the default values
def defaults
@defaults
View
@@ -153,6 +153,10 @@ class Game < Mongoid::Document
belongs_to_related :person
end
+class Patient < Mongoid::Document
+ collection_name "population"
+end
+
if RUBY_VERSION == '1.8.6'
class Array
alias :count :size
@@ -109,6 +109,19 @@
end
+ describe ".collection_name" do
+
+ before do
+ @coll = stub(:name => "population")
+ end
+
+ it "sets the collection name on the document class" do
+ Mongoid.database.expects(:collection).with("population").returns(@coll)
+ Patient.collection.should == @coll
+ end
+
+ end
+
describe ".defaults" do
it "returns a hash of all the default values" do

0 comments on commit 34a5098

Please sign in to comment.