Namespace
Methods
- S
- T
-
- test_bad_connection,
- test_bad_timeout,
- test_bind_value_substitute,
- test_column_types,
- test_columns,
- test_columns_with_default,
- test_columns_with_not_null,
- test_composite_primary_key,
- test_compound_index,
- test_connect,
- test_connect_memory_with_url,
- test_connect_with_url,
- test_connection_no_db,
- test_encoding,
- test_exec_insert,
- test_exec_no_binds,
- test_exec_query_typecasts_bind_vals,
- test_exec_query_with_binds,
- test_execute,
- test_index,
- test_indexes_logs,
- test_indexes_logs_name,
- test_insert_id_value_returned,
- test_insert_sql,
- test_insert_sql_logged,
- test_invalid_column,
- test_nil_timeout,
- test_no_indexes,
- test_no_primary_key,
- test_non_unique_index,
- test_primary_key,
- test_primary_key_returns_nil_for_no_pk,
- test_quote_binary_column_escapes_it,
- test_quote_string,
- test_respond_to_disable_extension,
- test_respond_to_enable_extension,
- test_select_rows,
- test_select_rows_logged,
- test_statement_closed,
- test_supports_extensions,
- test_table_exists_logs_name,
- test_tables,
- test_tables_logs_name,
- test_transaction,
- test_type_cast_should_not_mutate_encoding,
- test_valid_column
Included Modules
Instance Public methods
setup()
Link
test_bad_connection()
Link
# File activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb, line 22 def test_bad_connection assert_raise ActiveRecord::NoDatabaseError do connection = ActiveRecord::Base.sqlite3_connection(adapter: "sqlite3", database: "/tmp/should/_not/_exist/-cinco-dog.db") connection.exec_query('drop table if exists ex') end end
test_bad_timeout()
Link
test_bind_value_substitute()
Link
test_column_types()
Link
# File activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb, line 68 def test_column_types owner = Owner.create!(name: "hello".encode('ascii-8bit')) owner.reload select = Owner.columns.map { |c| "typeof(#{c.name})" }.join ', ' result = Owner.connection.exec_query <<-esql SELECT #{select} FROM #{Owner.table_name} WHERE #{Owner.primary_key} = #{owner.id} esql assert(!result.rows.first.include?("blob"), "should not store blobs") ensure owner.delete end
test_columns()
Link
# File activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb, line 327 def test_columns with_example_table do columns = @conn.columns('ex').sort_by { |x| x.name } assert_equal 2, columns.length assert_equal %w{ id number }.sort, columns.map { |x| x.name } assert_equal [nil, nil], columns.map { |x| x.default } assert_equal [true, true], columns.map { |x| x.null } end end
test_columns_with_default()
Link
# File activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb, line 337 def test_columns_with_default with_example_table 'id integer PRIMARY KEY AUTOINCREMENT, number integer default 10' do column = @conn.columns('ex').find { |x| x.name == 'number' } assert_equal '10', column.default end end
test_columns_with_not_null()
Link
# File activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb, line 346 def test_columns_with_not_null with_example_table 'id integer PRIMARY KEY AUTOINCREMENT, number integer not null' do column = @conn.columns('ex').find { |x| x.name == 'number' } assert_not column.null, "column should not be null" end end
test_composite_primary_key()
Link
test_compound_index()
Link
# File activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb, line 384 def test_compound_index with_example_table do @conn.add_index 'ex', %w{ id number }, name: 'fun' index = @conn.indexes('ex').find { |idx| idx.name == 'fun' } assert_equal %w{ id number }.sort, index.columns.sort end end
test_connect()
Link
test_connect_memory_with_url()
Link
# File activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb, line 42 def test_connect_memory_with_url original_connection = ActiveRecord::Base.remove_connection url = "sqlite3::memory:" ActiveRecord::Base.establish_connection(url) assert ActiveRecord::Base.connection ensure ActiveRecord::Base.establish_connection(original_connection) end
test_connect_with_url()
Link
# File activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb, line 30 def test_connect_with_url original_connection = ActiveRecord::Base.remove_connection tf = Tempfile.open 'whatever' url = "sqlite3:#{tf.path}" ActiveRecord::Base.establish_connection(url) assert ActiveRecord::Base.connection ensure tf.close tf.unlink ActiveRecord::Base.establish_connection(original_connection) end
test_connection_no_db()
Link
test_encoding()
Link
sqlite3 defaults to UTF-8 encoding
test_exec_insert()
Link
# File activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb, line 83 def test_exec_insert with_example_table do column = @conn.columns('ex').find { |col| col.name == 'number' } vals = [[column, 10]] @conn.exec_insert('insert into ex (number) VALUES (?)', 'SQL', vals) result = @conn.exec_query( 'select number from ex where number = ?', 'SQL', vals) assert_equal 1, result.rows.length assert_equal 10, result.rows.first.first end end
test_exec_no_binds()
Link
# File activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb, line 139 def test_exec_no_binds with_example_table 'id int, data string' do result = @conn.exec_query('SELECT id, data FROM ex') assert_equal 0, result.rows.length assert_equal 2, result.columns.length assert_equal %w{ id data }, result.columns @conn.exec_query('INSERT INTO ex (id, data) VALUES (1, "foo")') result = @conn.exec_query('SELECT id, data FROM ex') assert_equal 1, result.rows.length assert_equal 2, result.columns.length assert_equal [[1, 'foo']], result.rows end end
test_exec_query_typecasts_bind_vals()
Link
# File activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb, line 168 def test_exec_query_typecasts_bind_vals with_example_table 'id int, data string' do @conn.exec_query('INSERT INTO ex (id, data) VALUES (1, "foo")') column = @conn.columns('ex').find { |col| col.name == 'id' } result = @conn.exec_query( 'SELECT id, data FROM ex WHERE id = ?', nil, [[column, '1-fuu']]) assert_equal 1, result.rows.length assert_equal 2, result.columns.length assert_equal [[1, 'foo']], result.rows end end
test_exec_query_with_binds()
Link
# File activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb, line 155 def test_exec_query_with_binds with_example_table 'id int, data string' do @conn.exec_query('INSERT INTO ex (id, data) VALUES (1, "foo")') result = @conn.exec_query( 'SELECT id, data FROM ex WHERE id = ?', nil, [[nil, 1]]) assert_equal 1, result.rows.length assert_equal 2, result.columns.length assert_equal [[1, 'foo']], result.rows end end
test_execute()
Link
# File activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb, line 207 def test_execute with_example_table do @conn.execute "INSERT INTO ex (number) VALUES (10)" records = @conn.execute "SELECT * FROM ex" assert_equal 1, records.length record = records.first assert_equal 10, record['number'] assert_equal 1, record['id'] end end
test_index()
Link
# File activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb, line 365 def test_index with_example_table do @conn.add_index 'ex', 'id', unique: true, name: 'fun' index = @conn.indexes('ex').find { |idx| idx.name == 'fun' } assert_equal 'ex', index.table assert index.unique, 'index is unique' assert_equal ['id'], index.columns end end
test_indexes_logs()
Link
test_indexes_logs_name()
Link
test_insert_id_value_returned()
Link
test_insert_sql()
Link
# File activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb, line 223 def test_insert_sql with_example_table do 2.times do |i| rv = @conn.insert_sql "INSERT INTO ex (number) VALUES (#{i})" assert_equal(i + 1, rv) end records = @conn.execute "SELECT * FROM ex" assert_equal 2, records.length end end
test_insert_sql_logged()
Link
test_invalid_column()
Link
sqlite3 databases should be able to support any type and not just the ones mentioned in the native_database_types.
Therefore test_invalid column should always return true even if the type is not valid.
test_nil_timeout()
Link
connection is OK with a nil timeout
test_no_indexes()
Link
test_no_primary_key()
Link
test_non_unique_index()
Link
# File activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb, line 376 def test_non_unique_index with_example_table do @conn.add_index 'ex', 'id', name: 'fun' index = @conn.indexes('ex').find { |idx| idx.name == 'fun' } assert_not index.unique, 'index is not unique' end end
test_primary_key()
Link
# File activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb, line 392 def test_primary_key with_example_table do assert_equal 'id', @conn.primary_key('ex') with_example_table 'internet integer PRIMARY KEY AUTOINCREMENT, number integer not null', 'foos' do assert_equal 'internet', @conn.primary_key('foos') end end end
test_primary_key_returns_nil_for_no_pk()
Link
test_quote_binary_column_escapes_it()
Link
# File activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb, line 183 def test_quote_binary_column_escapes_it DualEncoding.connection.execute(" CREATE TABLE IF NOT EXISTS dual_encodings ( id integer PRIMARY KEY AUTOINCREMENT, name varchar(255), data binary ) ") str = "\x80".force_encoding("ASCII-8BIT") binary = DualEncoding.new name: 'いただきます!', data: str binary.save! assert_equal str, binary.data ensure DualEncoding.connection.execute('DROP TABLE IF EXISTS dual_encodings') end
test_quote_string()
Link
test_respond_to_disable_extension()
Link
test_respond_to_enable_extension()
Link
test_select_rows()
Link
# File activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb, line 254 def test_select_rows with_example_table do 2.times do |i| @conn.create "INSERT INTO ex (number) VALUES (#{i})" end rows = @conn.select_rows 'select number, id from ex' assert_equal [[0, 1], [1, 2]], rows end end
test_select_rows_logged()
Link
test_statement_closed()
Link
# File activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb, line 425 def test_statement_closed db = SQLite3::Database.new(ActiveRecord::Base. configurations['arunit']['database']) statement = SQLite3::Statement.new(db, 'CREATE TABLE statement_test (number integer not null)') statement.stubs(:step).raises(SQLite3::BusyException, 'busy') statement.stubs(:columns).once.returns([]) statement.expects(:close).once SQLite3::Statement.stubs(:new).returns(statement) assert_raises ActiveRecord::StatementInvalid do @conn.exec_query 'select * from statement_test' end end
test_supports_extensions()
Link
test_table_exists_logs_name()
Link
# File activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb, line 314 def test_table_exists_logs_name with_example_table do sql = <<-SQL SELECT name FROM sqlite_master WHERE (type = 'table' OR type = 'view') AND NOT name = 'sqlite_sequence' AND name = \"ex\" SQL assert_logged [[sql.squish, 'SCHEMA', []]] do assert @conn.table_exists?('ex') end end end
test_tables()
Link
# File activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb, line 287 def test_tables with_example_table do assert_equal %w{ ex }, @conn.tables with_example_table 'id integer PRIMARY KEY AUTOINCREMENT, number integer', 'people' do assert_equal %w{ ex people }.sort, @conn.tables.sort end end end
test_tables_logs_name()
Link
# File activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb, line 296 def test_tables_logs_name sql = <<-SQL SELECT name FROM sqlite_master WHERE (type = 'table' OR type = 'view') AND NOT name = 'sqlite_sequence' SQL assert_logged [[sql.squish, 'SCHEMA', []]] do @conn.tables('hello') end end
test_transaction()
Link
# File activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb, line 274 def test_transaction with_example_table do count_sql = 'select count(*) from ex' @conn.begin_db_transaction @conn.create "INSERT INTO ex (number) VALUES (10)" assert_equal 1, @conn.select_rows(count_sql).first.first @conn.rollback_db_transaction assert_equal 0, @conn.select_rows(count_sql).first.first end end
test_type_cast_should_not_mutate_encoding()
Link
# File activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb, line 199 def test_type_cast_should_not_mutate_encoding name = 'hello'.force_encoding(Encoding::ASCII_8BIT) Owner.create(name: name) assert_equal Encoding::ASCII_8BIT, name.encoding ensure Owner.delete_all end