spec/multisert_spec.rb in multisert-0.0.1 vs spec/multisert_spec.rb in multisert-0.0.2

- old
+ new

@@ -7,19 +7,20 @@ TEST_TABLE = 'test_data' # TODO: make into yaml config $connection = Mysql2::Client.new(host: 'localhost', username: 'root') -$cleaner = MrClean.new(database: TEST_DATABASE, connection: $connection) do |mgr| +$cleaner = MultisertSpec::MrClean.new(database: TEST_DATABASE, connection: $connection) do |mgr| mgr.create_table_schemas << %[ CREATE TABLE IF NOT EXISTS #{mgr.database}.#{TEST_TABLE} ( test_field_int_1 int default null, test_field_int_2 int default null, test_field_int_3 int default null, test_field_int_4 int default null, test_field_varchar varchar(10) default null, - test_field_date DATE default null + test_field_date DATE default null, + test_field_datetime DATETIME default null )] end describe Multisert do describe "<<" do @@ -142,9 +143,36 @@ post_flush_records.to_a.should == [ {'test_field_date' => Date.parse('2013-01-15')}, {'test_field_date' => Date.parse('2013-01-16')}, {'test_field_date' => Date.parse('2013-01-17')}, {'test_field_date' => Date.parse('2013-01-18')}] + + buffer.entries.should == [] + end + + it "works with times" do + pre_flush_records = connection.query "SELECT * FROM #{TEST_DATABASE}.#{TEST_TABLE}" + pre_flush_records.to_a.should == [] + + buffer.connection = connection + buffer.database = TEST_DATABASE + buffer.table = TEST_TABLE + buffer.fields = ['test_field_datetime'] + + buffer << [Time.new(2013, 1, 15, 1, 5, 11)] + buffer << [Time.new(2013, 1, 16, 2, 6, 22)] + buffer << [Time.new(2013, 1, 17, 3, 7, 33)] + buffer << [Time.new(2013, 1, 18, 4, 8, 44)] + + buffer.flush! + + post_flush_records = connection.query %[SELECT test_field_datetime FROM #{TEST_DATABASE}.#{TEST_TABLE}] + + post_flush_records.to_a.should == [ + {'test_field_datetime' => Time.new(2013, 1, 15, 1, 5, 11)}, + {'test_field_datetime' => Time.new(2013, 1, 16, 2, 6, 22)}, + {'test_field_datetime' => Time.new(2013, 1, 17, 3, 7, 33)}, + {'test_field_datetime' => Time.new(2013, 1, 18, 4, 8, 44)}] buffer.entries.should == [] end end end