spec/adapter_spec.rb in chrono_model-0.4.0 vs spec/adapter_spec.rb in chrono_model-0.5.0.beta

- old
+ new

@@ -57,11 +57,11 @@ ['baz', 'text'] ] def native.to_proc proc {|t| - t.string :test + t.string :test, :null => false t.integer :foo t.float :bar t.text :baz } end @@ -323,23 +323,23 @@ assert = proc do it { (subject & columns).should == columns } it { should include(['id', 'integer']) } end - with_temporal_table &assert - with_plain_table &assert + with_temporal_table(&assert) + with_plain_table( &assert) end describe '.primary_key' do subject { adapter.primary_key(table) } assert = proc do it { should == 'id' } end - with_temporal_table &assert - with_plain_table &assert + with_temporal_table(&assert) + with_plain_table( &assert) end describe '.indexes' do subject { adapter.indexes(table) } @@ -351,12 +351,12 @@ it { subject.map(&:name).should =~ %w( foo_index bar_index ) } it { subject.map(&:columns).should =~ [['foo'], ['bar', 'baz']] } end - with_temporal_table &assert - with_plain_table &assert + with_temporal_table(&assert) + with_plain_table( &assert) end describe '.on_schema' do before(:all) do 5.times {|i| adapter.execute "CREATE SCHEMA test_#{i}"} @@ -390,9 +390,76 @@ adapter.on_schema('test_3', false) { should be_in_schema('test_1') } } } should be_in_schema(:default) end + end + end + + + context 'INSERT multiple values' do + before :all do + adapter.create_table table, :temporal => true, &columns + end + + after :all do + adapter.drop_table table + end + + let(:current) { [ChronoModel::Adapter::TEMPORAL_SCHEMA, table].join('.') } + let(:history) { [ChronoModel::Adapter::HISTORY_SCHEMA, table].join('.') } + + def count(table) + adapter.select_value("SELECT COUNT(*) FROM ONLY #{table}").to_i + end + + def ids(table) + adapter.select_values("SELECT id FROM ONLY #{table} ORDER BY id") + end + + context 'when succeeding' do + def insert + adapter.execute <<-SQL + INSERT INTO #{table} (test, foo) VALUES + ('test1', 1), + ('test2', 2); + SQL + end + + it { expect { insert }.to_not raise_error } + it { count(current).should == 2 } + it { count(history).should == 2 } + end + + context 'when failing' do + def insert + adapter.execute <<-SQL + INSERT INTO #{table} (test, foo) VALUES + ('test3', 3), + (NULL, 0); + SQL + end + + it { expect { insert }.to raise_error } + it { count(current).should == 2 } # Because the previous + it { count(history).should == 2 } # records are preserved + end + + context 'after a failure' do + def insert + adapter.execute <<-SQL + INSERT INTO #{table} (test, foo) VALUES + ('test4', 3), + ('test5', 4); + SQL + end + + it { expect { insert }.to_not raise_error } + + it { count(current).should == 4 } + it { count(history).should == 4 } + + it { ids(current).should == ids(history) } end end end