diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2010-07-07 14:23:16 -0700 |
---|---|---|
committer | wycats <wycats@gmail.com> | 2010-07-07 14:25:22 -0700 |
commit | c58e7a71b52a38885352768c74b7563395566bb6 (patch) | |
tree | 6c29247c6226904a57e7e9af60313d006acf33ae /activerecord/test/cases | |
parent | 81f398b804a68c8090c0fbea20f50c0ae253b708 (diff) | |
download | rails-c58e7a71b52a38885352768c74b7563395566bb6.tar.gz rails-c58e7a71b52a38885352768c74b7563395566bb6.tar.bz2 rails-c58e7a71b52a38885352768c74b7563395566bb6.zip |
adding some behavioral tests for the sqlite adapter. [#5065 state:resolved]
Signed-off-by: wycats <wycats@gmail.com>
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/adapters/sqlite/sqlite_adapter_test.rb | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/activerecord/test/cases/adapters/sqlite/sqlite_adapter_test.rb b/activerecord/test/cases/adapters/sqlite/sqlite_adapter_test.rb new file mode 100644 index 0000000000..69cfb00faf --- /dev/null +++ b/activerecord/test/cases/adapters/sqlite/sqlite_adapter_test.rb @@ -0,0 +1,100 @@ +require "cases/helper" + +module ActiveRecord + module ConnectionAdapters + class SQLiteAdapterTest < ActiveRecord::TestCase + def setup + @ctx = Base.sqlite3_connection :database => ':memory:', + :adapter => 'sqlite3', + :timeout => nil + @ctx.execute <<-eosql + CREATE TABLE items ( + id integer PRIMARY KEY AUTOINCREMENT, + number integer + ) + eosql + end + + def test_execute + @ctx.execute "INSERT INTO items (number) VALUES (10)" + records = @ctx.execute "SELECT * FROM items" + assert_equal 1, records.length + + record = records.first + assert_equal 10, record['number'] + assert_equal 1, record['id'] + end + + def test_quote_string + assert_equal "''", @ctx.quote_string("'") + end + + def test_insert_sql + 2.times do |i| + rv = @ctx.insert_sql "INSERT INTO items (number) VALUES (#{i})" + assert_equal(i + 1, rv) + end + + records = @ctx.execute "SELECT * FROM items" + assert_equal 2, records.length + end + + def test_insert_sql_logged + sql = "INSERT INTO items (number) VALUES (10)" + name = "foo" + + assert_logged([[sql, name]]) do + @ctx.insert_sql sql, name + end + end + + def test_insert_id_value_returned + sql = "INSERT INTO items (number) VALUES (10)" + idval = 'vuvuzela' + id = @ctx.insert_sql sql, nil, nil, idval + assert_equal idval, id + end + + def test_select_rows + 2.times do |i| + @ctx.create "INSERT INTO items (number) VALUES (#{i})" + end + rows = @ctx.select_rows 'select number, id from items' + assert_equal [[0, 1], [1, 2]], rows + end + + def test_select_rows_logged + sql = "select * from items" + name = "foo" + + assert_logged([[sql, name]]) do + @ctx.select_rows sql, name + end + end + + def test_transaction + count_sql = 'select count(*) from items' + + @ctx.begin_db_transaction + @ctx.create "INSERT INTO items (number) VALUES (10)" + + assert_equal 1, @ctx.select_rows(count_sql).first.first + @ctx.rollback_db_transaction + assert_equal 0, @ctx.select_rows(count_sql).first.first + end + + def assert_logged logs + @ctx.extend(Module.new { + attr_reader :logged + def log sql, name + @logged ||= [] + @logged << [sql, name] + yield + end + }) + yield + assert_equal logs, @ctx.logged + end + end + end +end |