Skip to content

Commit

Permalink
Removed Date as a key type as it is not supported by the mongo ruby d…
Browse files Browse the repository at this point in the history
…river currently. Should probably just map it to time so it can still be used.
  • Loading branch information
jnunemaker committed Jun 27, 2009
1 parent bdc4426 commit d436116
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions lib/mongomapper/key.rb
Expand Up @@ -2,8 +2,8 @@ class Boolean; end

module MongoMapper
class Key
# DateTime currently is not supported by mongo's bson so just use Time
NativeTypes = [String, Float, Time, Date, Integer, Boolean, Array, Hash]
# DateTime and Date are currently not supported by mongo's bson so just use Time
NativeTypes = [String, Float, Time, Integer, Boolean, Array, Hash]

attr_accessor :name, :type, :options, :default_value

Expand Down Expand Up @@ -49,7 +49,7 @@ def typecast(value)
elsif type == Float then value.to_f
elsif type == Array then value.to_a
elsif type == Time then Time.parse(value.to_s)
elsif type == Date then Date.parse(value.to_s)
#elsif type == Date then Date.parse(value.to_s)
elsif type == Boolean then ['true', 't', '1'].include?(value.to_s.downcase)
elsif type == Integer
# ganked from datamapper
Expand Down
4 changes: 2 additions & 2 deletions test/test_key.rb
Expand Up @@ -14,7 +14,7 @@ class KeyTest < Test::Unit::TestCase

context "The Key Class" do
should "have the native types defined" do
Key::NativeTypes.should == [String, Float, Time, Date, Integer, Boolean, Array, Hash]
Key::NativeTypes.should == [String, Float, Time, Integer, Boolean, Array, Hash]
end
end

Expand Down Expand Up @@ -97,7 +97,7 @@ class KeyTest < Test::Unit::TestCase
key.set('2000-01-01 01:01:01.123456').should == Time.local(2000, 1, 1, 1, 1, 1, 123456)
end

should "correctly typecast Dates" do
should_eventually "correctly typecast Dates" do
key = Key.new(:foo, Date)
key.set('2000-01-01').should == Date.new(2000, 1, 1)
end
Expand Down

0 comments on commit d436116

Please sign in to comment.