| 1 |
require 'rubygems' |
|---|
| 2 |
require 'active_record' |
|---|
| 3 |
require 'test/unit' |
|---|
| 4 |
|
|---|
| 5 |
class RecordsAffectedTest < Test::Unit::TestCase |
|---|
| 6 |
def setup |
|---|
| 7 |
ActiveRecord::Base.establish_connection( |
|---|
| 8 |
:adapter => 'sqlserver', |
|---|
| 9 |
:host => 'HOST', |
|---|
| 10 |
:database => 'DATABASE', |
|---|
| 11 |
:username => 'USERNAME', |
|---|
| 12 |
:password => 'PASSWORD') if RUBY_PLATFORM =~ /mswin32/i |
|---|
| 13 |
|
|---|
| 14 |
ActiveRecord::Base.establish_connection( |
|---|
| 15 |
:adapter => 'sqlserver', |
|---|
| 16 |
:mode => 'odbc', |
|---|
| 17 |
:dsn => 'DSN', |
|---|
| 18 |
:username => 'USERNAME', |
|---|
| 19 |
:password => 'PASSWORD') if RUBY_PLATFORM =~ /linux/i |
|---|
| 20 |
@conn = ActiveRecord::Base.connection |
|---|
| 21 |
|
|---|
| 22 |
@conn.execute "CREATE TABLE #RecordsAffectedTest(foo int)" |
|---|
| 23 |
end |
|---|
| 24 |
|
|---|
| 25 |
def teardown |
|---|
| 26 |
@conn.execute "DROP TABLE #RecordsAffectedTest" |
|---|
| 27 |
end |
|---|
| 28 |
|
|---|
| 29 |
def test_update |
|---|
| 30 |
assert ActiveRecord::Base.connection.instance_variable_get("@connection")["AutoCommit"], "This only seems to happen when auto-commit is on" |
|---|
| 31 |
|
|---|
| 32 |
(1..10).each do |i| |
|---|
| 33 |
@conn.execute "INSERT INTO #RecordsAffectedTest(foo) VALUES (#{i})" |
|---|
| 34 |
end |
|---|
| 35 |
assert_equal 10, @conn.update("UPDATE #RecordsAffectedTest SET foo = -1"), "@@ROWCOUNT should be 10" |
|---|
| 36 |
end |
|---|
| 37 |
end |
|---|