Skip to content

Commit

Permalink
Float.to_mongo(nil) should yield nil unless there's a good reason not…
Browse files Browse the repository at this point in the history
… to. (e.g. latitude and longitude values of 0,0 actually means something.)
  • Loading branch information
conceptsahead authored and jnunemaker committed May 7, 2010
1 parent a721b66 commit 2be3cda
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/mongo_mapper/support.rb
Expand Up @@ -61,7 +61,7 @@ def self.from_mongo(value)

class Float
def self.to_mongo(value)
value.to_f
value.nil? ? nil : value.to_f
end
end

Expand Down
4 changes: 4 additions & 0 deletions test/unit/test_support.rb
Expand Up @@ -133,6 +133,10 @@ class SupportTest < Test::Unit::TestCase
Float.to_mongo(value).should == 21.0
end
end

should "leave nil values nil" do
Float.to_mongo(nil).should == nil
end
end

context "Hash#from_mongo" do
Expand Down

0 comments on commit 2be3cda

Please sign in to comment.