spec/adapters/sqlite_spec.rb in sequel-4.41.0 vs spec/adapters/sqlite_spec.rb in sequel-4.42.0

- old
+ new

@@ -295,11 +295,11 @@ end end if DB.adapter_scheme == :sqlite describe "An SQLite dataset" do before do - @d = DB[:items] + @d = DB.dataset end it "should raise errors if given a regexp pattern match" do proc{@d.literal(Sequel.expr(:x).like(/a/))}.must_raise(Sequel::InvalidOperation) proc{@d.literal(~Sequel.expr(:x).like(/a/))}.must_raise(Sequel::InvalidOperation) @@ -345,10 +345,13 @@ @d.delete # remove all records @d << {:name => 'abc', :value => 1.23} @d << {:name => 'def', :value => 4.56} @d << {:name => 'ghi', :value => 7.89} end + after do + DB.drop_table?(:items) + end it "should return the number of records affected when filtered" do @d.count.must_equal 3 @d.filter{value < 3}.delete.must_equal 1 @d.count.must_equal 2 @@ -456,11 +459,11 @@ DB[:test].explain.must_be_kind_of(String) end it "should have #explain work when identifier_output_method is modified" do DB[:test].with_identifier_output_method(:upcase).explain.must_be_kind_of(String) - end + end if IDENTIFIER_MANGLING end describe "A SQLite database" do before do @db = DB @@ -468,11 +471,11 @@ text :name integer :value end end after do - @db.drop_table?(:test2) + @db.drop_table?(:test, :test2, :test3, :test3_backup0, :test3_backup1, :test3_backup2) end it "should support add_column operations" do @db.add_column :test2, :xyz, :text @@ -541,16 +544,14 @@ @db[:test3].insert(:name => "def", :test_id => @db[:test].insert(:name => "bar", :value => 4)) @db.drop_column :test3, :value @db[:test].filter(:name => 'bar').delete - @db[:test3][:name => 'def'][:test_id].must_equal nil + @db[:test3][:name => 'def'][:test_id].must_be_nil @db[:test].filter(:name => 'foo').update(:id=>100) @db[:test3][:name => 'abc'][:test_id].must_equal 100 - - @db.drop_table? :test, :test3 end end it "should support rename_column operations" do @db[:test2].delete @@ -580,13 +581,27 @@ @db.rename_column :test3, :s, :t @db[:test3].insert @db[:test3].first[:t].must_equal 'a' @db[:test3].delete end + + + it "should preserve autoincrement after table modification" do + @db.create_table!(:test2) do + primary_key :id + Integer :val, :null => false + end + @db.rename_column(:test2, :val, :value) + + t = @db[:test2] + id1 = t.insert(:value=>1) + t.delete + id2 = t.insert(:value=>1) + id2.must_be :>, id1 + end it "should handle quoted tables when dropping or renaming columns" do - @db.quote_identifiers = true table_name = "T T" @db.drop_table?(table_name) @db.create_table! table_name do Integer :"s s" Integer :"i i" @@ -638,11 +653,10 @@ @db[:test3].columns.must_equal [:i] @db[:test3_backup0].columns.must_equal [:j] @db[:test3_backup1].columns.must_equal [:k] @db[:test3_backup2].columns.must_equal [:l] @db.loggers.delete(l) - @db.drop_table?(:test3, :test3_backup0, :test3_backup1, :test3_backup2) end it "should support add_index" do @db.add_index :test2, :value, :unique => true @db.add_index :test2, [:name, :value] @@ -652,16 +666,16 @@ @db.add_index :test2, :value, :unique => true @db.drop_index :test2, :value end it "should keep applicable indexes when emulating schema methods" do - @db.create_table!(:a){Integer :a; Integer :b} - @db.add_index :a, :a - @db.add_index :a, :b - @db.add_index :a, [:b, :a] - @db.drop_column :a, :b - @db.indexes(:a).must_equal(:a_a_index=>{:unique=>false, :columns=>[:a]}) + @db.create_table!(:test3){Integer :a; Integer :b} + @db.add_index :test3, :a + @db.add_index :test3, :b + @db.add_index :test3, [:b, :a] + @db.drop_column :test3, :b + @db.indexes(:test3).must_equal(:test3_a_index=>{:unique=>false, :columns=>[:a]}) end it "should have support for various #transaction modes" do sqls = [] @db.loggers << Class.new{%w'info error'.each{|m| define_method(m){|sql| sqls << sql}}}.new @@ -677,10 +691,10 @@ end @db.transaction do sqls.last.must_equal Sequel::Database::SQL_BEGIN end - @db.transaction_mode.must_equal nil + @db.transaction_mode.must_be_nil @db.transaction_mode = :immediate @db.transaction_mode.must_equal :immediate @db.transaction do sqls.last.must_equal "BEGIN IMMEDIATE TRANSACTION" end