Permalink
Browse files

Parse datetime into the correct class. Fixes #1125

  • Loading branch information...
1 parent b9f365b commit 3ce8e1e63d1cb96f014c810465839ae0fa487624 @henare henare committed Feb 9, 2017
@@ -203,7 +203,12 @@ def add_database_type_translations(db)
%w(date datetime).each do |type|
db.translator.add_translator(type) do |t, v|
begin
- Date.parse(v.to_s)
+ case t.downcase
+ when "date"
+ Date.parse(v.to_s)
+ when "datetime"
+ DateTime.parse(v.to_s)
+ end
rescue ArgumentError
v
end
@@ -56,6 +56,11 @@
database = Morph::Database.new(RSpec.configuration.fixture_path + "/files/sqlite_databases/unparseable_date_stored_as_fixnum/")
expect(database.sql_query("SELECT * FROM data")).to eql [{"some_column" => 148392075227}]
end
+
+ it "converts datetime field into DateTime object" do
+ database = Morph::Database.new(RSpec.configuration.fixture_path + "/files/sqlite_databases/datetime_field/")
+ expect(database.sql_query("SELECT * FROM data")).to eql [{"some_column" => DateTime.new(2017, 1, 2, 3, 4, 56.789012)}]
+ end
end
end
end

0 comments on commit 3ce8e1e

Please sign in to comment.