Permalink
Browse files

Fixed compatibility with edge rails (rails 3 master), with correspond…

…ing tests.
  • Loading branch information...
fredwu committed Mar 17, 2010
1 parent 34e6235 commit 6e5e531312ef98c30e33286a1f80dd000468ed07
Showing with 30 additions and 2 deletions.
  1. +10 −2 lib/mongo_mapper/plugins/rails.rb
  2. +20 −0 test/unit/test_document.rb
@@ -9,14 +9,22 @@ module InstanceMethods
def to_param
id.to_s
end
-
+
+ def to_key
+ persisted? ? [id.to_s] : nil
+ end
+
def to_model
self
end
-
+
def new_record?
new?
end
+
+ def persisted?
+ !(new_record? || destroyed?)
+ end
def read_attribute(name)
self[name]
View
@@ -111,6 +111,13 @@ class Post
doc.to_param.should be_instance_of(String)
end
+ should "have to_key that is array representation of id" do
+ doc = @document.new(:id => Mongo::ObjectID.new)
+ doc.save
+ doc.to_key.should == [doc.id.to_s]
+ doc.to_key.should be_instance_of(Array)
+ end
+
should "have access to logger" do
doc = @document.new
doc.logger.should == @document.logger
@@ -159,6 +166,19 @@ class Post
doc.id = '1234'
doc.new?.should be_true
end
+
+ should "have to_key that returns nil on non-persisted records (new records)" do
+ @document.new.to_key.should be(nil)
+ end
+ end
+
+ context "destroyed?" do
+ should "have to_key that returns nil on non-persisted records (destroyed records)" do
+ doc = @document.new
+ doc.save
+ doc.destroy
+ doc.to_key.should be(nil)
+ end
end
context "clone" do

5 comments on commit 6e5e531

@geetarista

This comment has been minimized.

Show comment Hide comment
@geetarista

geetarista Mar 17, 2010

Works perfectly!

Works perfectly!

@jnunemaker

This comment has been minimized.

Show comment Hide comment
@jnunemaker

jnunemaker Mar 17, 2010

This is only with rails edge or something? I have not ran into this.

This is only with rails edge or something? I have not ran into this.

@geetarista

This comment has been minimized.

Show comment Hide comment
@geetarista

geetarista Mar 17, 2010

@jnunemaker: This is with Rails edge.

@jnunemaker: This is with Rails edge.

@fredwu

This comment has been minimized.

Show comment Hide comment
@fredwu

fredwu Mar 17, 2010

Owner

@jnunemaker: As geetarista stated above, this is a fix for the edge rails. Since one of the libraries I use (devise) requires edge rails, I think it makes sense to patch it up now. It does not effect v3.0.0.beta1 users. :)

Owner

fredwu replied Mar 17, 2010

@jnunemaker: As geetarista stated above, this is a fix for the edge rails. Since one of the libraries I use (devise) requires edge rails, I think it makes sense to patch it up now. It does not effect v3.0.0.beta1 users. :)

@parasew

This comment has been minimized.

Show comment Hide comment
@parasew

parasew Mar 21, 2010

yes, this is an issue that only affects edge rails.
it looks like the form_for and similar refactoring is done, so i would say it is safe to patch it up.

yes, this is an issue that only affects edge rails.
it looks like the form_for and similar refactoring is done, so i would say it is safe to patch it up.

Please sign in to comment.