aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2010-10-12 16:58:18 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2010-10-26 13:44:08 -0700
commit54ff59f3ba4c299ebb0b517ae1a3efb5859ab1c7 (patch)
tree1bfa30819dba19719d08fb0551ad6c0b4e06ac14 /activerecord
parentd7207cf504b67243c0b7debaff70d948bb8be7a8 (diff)
downloadrails-54ff59f3ba4c299ebb0b517ae1a3efb5859ab1c7.tar.gz
rails-54ff59f3ba4c299ebb0b517ae1a3efb5859ab1c7.tar.bz2
rails-54ff59f3ba4c299ebb0b517ae1a3efb5859ab1c7.zip
refactoring tests
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb56
1 files changed, 20 insertions, 36 deletions
diff --git a/activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb b/activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
index 969029db51..973c51f3d7 100644
--- a/activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
+++ b/activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
@@ -3,6 +3,12 @@ require "cases/helper"
module ActiveRecord
module ConnectionAdapters
class SQLite3AdapterTest < ActiveRecord::TestCase
+ def setup
+ @conn = Base.sqlite3_connection :database => ':memory:',
+ :adapter => 'sqlite3',
+ :timeout => 100
+ end
+
def test_connection_no_db
assert_raises(ArgumentError) do
Base.sqlite3_connection {}
@@ -38,42 +44,28 @@ module ActiveRecord
end
def test_connect
- conn = Base.sqlite3_connection :database => ':memory:',
- :adapter => 'sqlite3',
- :timeout => 100
- assert conn, 'should have connection'
+ assert @conn, 'should have connection'
end
# sqlite3 defaults to UTF-8 encoding
def test_encoding
- conn = Base.sqlite3_connection :database => ':memory:',
- :adapter => 'sqlite3',
- :timeout => 100
- assert_equal 'UTF-8', conn.encoding
+ assert_equal 'UTF-8', @conn.encoding
end
def test_bind_value_substitute
- conn = Base.sqlite3_connection :database => ':memory:',
- :adapter => 'sqlite3',
- :timeout => 100
-
- bind_param = conn.substitute_for('foo', [])
+ bind_param = @conn.substitute_for('foo', [])
assert_equal Arel.sql('?'), bind_param
end
def test_exec_no_binds
- conn = Base.sqlite3_connection :database => ':memory:',
- :adapter => 'sqlite3',
- :timeout => 100
-
- conn.exec('create table ex(id int, data string)')
- result = conn.exec('SELECT id, data FROM ex')
+ @conn.exec('create table ex(id int, data string)')
+ result = @conn.exec('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('INSERT INTO ex (id, data) VALUES (1, "foo")')
- result = conn.exec('SELECT id, data FROM ex')
+ @conn.exec('INSERT INTO ex (id, data) VALUES (1, "foo")')
+ result = @conn.exec('SELECT id, data FROM ex')
assert_equal 1, result.rows.length
assert_equal 2, result.columns.length
@@ -81,13 +73,9 @@ module ActiveRecord
end
def test_exec_with_binds
- conn = Base.sqlite3_connection :database => ':memory:',
- :adapter => 'sqlite3',
- :timeout => 100
-
- conn.exec('create table ex(id int, data string)')
- conn.exec('INSERT INTO ex (id, data) VALUES (1, "foo")')
- result = conn.exec(
+ @conn.exec('create table ex(id int, data string)')
+ @conn.exec('INSERT INTO ex (id, data) VALUES (1, "foo")')
+ result = @conn.exec(
'SELECT id, data FROM ex WHERE id = ?', nil, [[nil, 1]])
assert_equal 1, result.rows.length
@@ -97,15 +85,11 @@ module ActiveRecord
end
def test_exec_typecasts_bind_vals
- conn = Base.sqlite3_connection :database => ':memory:',
- :adapter => 'sqlite3',
- :timeout => 100
-
- conn.exec('create table ex(id int, data string)')
- conn.exec('INSERT INTO ex (id, data) VALUES (1, "foo")')
- column = conn.columns('ex').find { |col| col.name == 'id' }
+ @conn.exec('create table ex(id int, data string)')
+ @conn.exec('INSERT INTO ex (id, data) VALUES (1, "foo")')
+ column = @conn.columns('ex').find { |col| col.name == 'id' }
- result = conn.exec(
+ result = @conn.exec(
'SELECT id, data FROM ex WHERE id = ?', nil, [[column, '1-fuu']])
assert_equal 1, result.rows.length