C0 code coverage information
Generated on Wed Jul 30 00:45:19 -0400 2008 with
rcov 0.8.1.2
Code reported as executed by Ruby looks like
this... and this: this line is also marked as
covered. Lines considered as run by rcov, but
not reported by Ruby, look like this, and
this: these lines were inferred by rcov (using simple heuristics).
Finally, here's a line marked as not
executed.
| Name | Total lines | Lines of code |
Total coverage | Code coverage
|
| spec/dbi.rb |
128 | 89 | | |
1
require 'spec/helper' 2
3 $dbh = DBI.connect(
"DBI:Pg:m4dbi", "m4dbi", "m4dbi" )
4 # See test-schema.sql
and test-data.sql 5
6 describe
'DBI::DatabaseHandle#select_column' do 7 8 it
'selects one column' do 9
name = $dbh.select_column( 10 "SELECT name FROM authors LIMIT 1"
11 ) 12 name.class.should.not.equal Array
13 name.should.equal
'author1' 14 end
15 16 it 'selects one column of first
row' do 17 name =
$dbh.select_column( 18
"SELECT name FROM authors ORDER BY name DESC" 19 ) 20 name.should.equal 'author3' 21 end 22 23 it 'selects first column of first row' do 24 name = $dbh.select_column(
25 "SELECT name,
id FROM authors ORDER BY name DESC" 26 )
27 name.should.equal 'author3' 28 end 29
30 end 31 32 describe
'DBI::DatabaseHandle#one_transaction' do 33 34
it 'turns off autocommit for the duration of a single transaction' do
35 $dbh.d( "DELETE
FROM many_col_table;" ) 36 $dbh.i( "INSERT INTO many_col_table ( id, c1 )
VALUES ( 1, 10 );" ) 37
38 # Here we will attempt to increment a value two times in parallel.
39 # If each
multi-operation transaction is truly atomic, we expect that 40 # the final value will reflect
two increments. 41 # If
atomicity is not respected, the value should only reflect one 42 # increment. 43 44 # First, we test the non-transactional case, to show
failure. 45
46 thread1 = Thread.new
do 47 value = $dbh.sc
"SELECT c1 FROM many_col_table WHERE id = 1;" 48 value.should.equal 10 49 sleep 2 # seconds 50 $dbh.u "UPDATE many_col_table
SET c1 = ?", ( value + 1 ) 51 end 52 53
thread2 = Thread.new do
54 value = $dbh.sc "SELECT c1 FROM many_col_table WHERE id = 1;"
55 value.should.equal 10
56 # Update right away
57 $dbh.u "UPDATE
many_col_table SET c1 = ?", ( value + 1 ) 58 end 59 60 thread2.join 61 thread1.join 62 63
value = $dbh.sc "SELECT c1 FROM many_col_table WHERE id = 1;"
64 # Failure; two
increments should give a final value of 12. 65 value.should.equal( 10 + 1 ) 66 67 # Now, we show that transactions keep things sane.
68 69 thread1 = Thread.new do
70 $dbh.one_transaction
do |dbh| 71 value =
dbh.sc "SELECT c1 FROM many_col_table WHERE id = 1;" 72 sleep 2 # seconds 73 dbh.u "UPDATE many_col_table
SET c1 = ?", ( value + 1 ) 74 end 75 end 76 77
thread2 = Thread.new do
78 $dbh.one_transaction do |dbh| 79 value = dbh.sc "SELECT c1 FROM many_col_table
WHERE id = 1;" 80
# Update right away 81
dbh.u "UPDATE many_col_table SET c1 = ?", ( value + 1 )
82 end 83 end 84 85 thread2.join 86 thread1.join 87 88
value = $dbh.sc "SELECT c1 FROM many_col_table WHERE id = 1;"
89 value.should.equal( 11
+ 1 + 1 ) 90 end
91 92 end 93 94 describe 'DBI::Row accessors' do 95 96 it 'provide read access via #fieldname' do
97 row = $dbh.select_one(
98 "SELECT * FROM
posts ORDER BY author_id DESC LIMIT 1" 99 ) 100 row.should.not.equal nil 101 102 row._id.should.be.same_as row[ 'id' ] 103 row.id_.should.be.same_as row[
'id' ] 104
row.author_id.should.be.same_as row[ 'author_id' ] 105 row.text.should.be.same_as row[
'text' ] 106
107 row.text.should.equal
'Second post.' 108 end
109 110 it 'provide in-memory
(non-syncing) write access via #fieldname=' do 111 row = $dbh.select_one(
112 "SELECT * FROM
posts ORDER BY author_id DESC LIMIT 1" 113 ) 114 row.should.not.equal nil
115 116 old_id = row._id 117 row.id = old_id + 1 118 row._id.should.not.equal old_id
119 row._id.should.equal(
old_id + 1 ) 120
121 old_text = row.text
122 new_text = 'This is
the new post text.' 123
row.text = new_text 124
row.text.should.not.equal old_text 125 row.text.should.equal new_text 126 end 127 128 end
Generated using the rcov
code coverage analysis tool for Ruby version 0.8.1.2.