Skip to content

Commit

Permalink
Added to_param directly to embedded document and removed from rails c…
Browse files Browse the repository at this point in the history
…ompat modules.
  • Loading branch information
jnunemaker committed Oct 16, 2009
1 parent a678807 commit b161ec6
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 18 deletions.
4 changes: 4 additions & 0 deletions lib/mongo_mapper/embedded_document.rb
Expand Up @@ -198,6 +198,10 @@ def initialize(attrs={})
def new?
!!@new_document
end

def to_param
id
end

def attributes=(attrs)
return if attrs.blank?
Expand Down
4 changes: 0 additions & 4 deletions lib/mongo_mapper/rails_compatibility/document.rb
Expand Up @@ -6,10 +6,6 @@ def self.included(model)
alias_method :new_record?, :new?
end
end

def to_param
id
end
end
end
end
4 changes: 0 additions & 4 deletions lib/mongo_mapper/rails_compatibility/embedded_document.rb
Expand Up @@ -18,10 +18,6 @@ def column_names
keys.keys
end
end

def to_param
raise "Missing to_param method in #{self.class}. You should implement it to return the unique identifier of this embedded document within a document."
end
end
end
end
5 changes: 0 additions & 5 deletions test/functional/test_rails_compatibility.rb
Expand Up @@ -16,11 +16,6 @@ class Order
setup do
Order.collection.clear
end

should "have to_param that returns id" do
instance = Order.create('_id' => 1234)
instance.to_param.should == '1234'
end

should "alias new to new_record?" do
instance = Order.new
Expand Down
5 changes: 5 additions & 0 deletions test/unit/test_embedded_document.rb
Expand Up @@ -289,6 +289,11 @@ class EmbeddedDocumentTest < Test::Unit::TestCase
end
end

should "have to_param that is id" do
doc = @document.new
doc.to_param.should == doc.id
end

should "have access to class logger" do
doc = @document.new
doc.logger.should == @document.logger
Expand Down
6 changes: 1 addition & 5 deletions test/unit/test_rails_compatibility.rb
Expand Up @@ -15,11 +15,7 @@ class SecondItem < Item
key :second_only, String
end

context "EmbeddedDocument" do
should "raise error for to_param as embedded do not have id's" do
lambda { Item.new.to_param }.should raise_error
end

context "EmbeddedDocument" do
should "alias many to has_many" do
FirstItem.should respond_to(:has_many)
FirstItem.method(:has_many).should == FirstItem.method(:many)
Expand Down

0 comments on commit b161ec6

Please sign in to comment.