1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
|
shared_examples_for 'a Result' do
before :all do
setup_test_environment
end
before do
@connection = DataObjects::Connection.new(CONFIG.uri)
@result = @connection.create_command("INSERT INTO users (name) VALUES (?)").execute_non_query("monkey")
end
after do
@connection.close
end
it { @result.should respond_to(:affected_rows) }
describe 'affected_rows' do
it 'should return the number of affected rows' do
@result.affected_rows.should == 1
end
end
end
shared_examples_for 'a Result which returns inserted key with sequences' do
describe 'insert_id' do
before do
setup_test_environment
@connection = DataObjects::Connection.new(CONFIG.uri)
command = @connection.create_command("INSERT INTO users (name) VALUES (?)")
# execute the command twice and expose the second result
command.execute_non_query("monkey")
@result = command.execute_non_query("monkey")
end
after do
@connection.close
end
it { @result.should respond_to(:affected_rows) }
it 'should return the insert_id' do
# This is actually the 2nd record inserted
@result.insert_id.should == 2
end
end
end
shared_examples_for 'a Result which returns nil without sequences' do
describe 'insert_id' do
before do
setup_test_environment
@connection = DataObjects::Connection.new(CONFIG.uri)
command = @connection.create_command("INSERT INTO invoices (invoice_number) VALUES (?)")
# execute the command twice and expose the second result
@result = command.execute_non_query("monkey")
end
after do
@connection.close
end
it 'should return the insert_id' do
# This is actually the 2nd record inserted
@result.insert_id.should be_nil
end
end
end
|