Use ActiveRecord Column#type_cast to properly parse fields represented by a string.

Fixed issued reported by Nick Burdick where imported datetime fields was not correctly working with certain string formats for MySQL which doesn't support MM/DD/YYYY format directly.
This commit is contained in:
Zach Dennis 2011-01-05 19:05:31 -05:00
parent 8e266f74f7
commit 8fbf841fde
3 changed files with 15 additions and 2 deletions

View file

@ -199,4 +199,16 @@ describe "#import" do
end
end
context "importing a datetime field" do
it "should import a date with MM/DD/YYYY format just fine" do
Topic.import [:author_name, :title, :last_read], [["Bob Jones", "Topic 1", "05/14/2010"]]
assert_equal "05/14/2010".to_date, Topic.last.last_read.to_date
end
it "should import a date with YYYY/MM/DD format just fine" do
Topic.import [:author_name, :title, :last_read], [["Bob Jones", "Topic 2", "2010/05/14"]]
assert_equal "05/14/2010".to_date, Topic.last.last_read.to_date
end
end
end