Class: TC_Database

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
test/tc_database.rb

Instance Method Summary collapse

Instance Method Details

#setupObject



52
53
54
55
# File 'test/tc_database.rb', line 52

def setup
  @db = SQLite3::Database.open( "foo.db",
    :driver => Driver, :statement_factory => Statement )
end

#test_authorizerObject



96
97
98
99
100
# File 'test/tc_database.rb', line 96

def test_authorizer
  Driver.any_instance.expects(:set_authorizer).with('cookie', 15).returns(0)
  @db.authorizer( 15 ) { "foo" }
  # assert_equal 1, driver.mock_blocks[:set_authorizer].length
end

#test_changesObject



184
185
186
187
# File 'test/tc_database.rb', line 184

def test_changes
  Driver.any_instance.expects(:changes).returns(14)
  assert_equal 14, @db.changes
end

#test_closeObject



82
83
84
85
86
87
88
# File 'test/tc_database.rb', line 82

def test_close
  Driver.any_instance.expects(:close).returns(0)
  @db.close
  assert @db.closed?
  Driver.any_instance.expects(:close).never
  @db.close
end

#test_completeObject



62
63
64
65
# File 'test/tc_database.rb', line 62

def test_complete
  Driver.any_instance.expects(:complete?)
  @db.complete? "foo"
end

#test_errcodeObject



72
73
74
75
# File 'test/tc_database.rb', line 72

def test_errcode
  Driver.any_instance.expects(:errcode)
  @db.errcode
end

#test_errmsgObject



67
68
69
70
# File 'test/tc_database.rb', line 67

def test_errmsg
  Driver.any_instance.expects(:errmsg)
  @db.errmsg
end

#test_execute2_no_blockObject



141
142
143
144
145
146
147
148
149
# File 'test/tc_database.rb', line 141

def test_execute2_no_block
  # any_instance fails here...
  statement = Statement.new('cookie', 'foo')
  statement.expects(:execute).with('bar', 'baz').returns(MockResultSet.new)
  Statement.stubs(:new).returns(statement)
  MockResultSet.any_instance.stubs(:inject).returns([['name'], ['foo']])
  result = @db.execute2( "foo", "bar", "baz" )
  assert_equal [["name"],["foo"]], result
end

#test_execute2_with_blockObject



151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'test/tc_database.rb', line 151

def test_execute2_with_block
  called = false
  parts = [ ["name"],["foo"] ]
  # any_instance fails here...
  statement = Statement.new('cookie', 'foo')
  statement.expects(:execute).with('bar', 'baz').returns(MockResultSet.new)
  Statement.stubs(:new).returns(statement)
  @db.execute2( "foo", "bar", "baz" ) do |row|
    called = true
    assert_equal parts.shift, row
  end

  assert called
end

#test_execute_batchObject



166
167
168
169
170
171
172
# File 'test/tc_database.rb', line 166

def test_execute_batch
  # any_instance fails here...
  statement = Statement.new('cookie', 'foo')
  statement.expects(:execute).with('bar', 'baz').returns(MockResultSet.new)
  Statement.stubs(:new).returns(statement)
  @db.execute_batch( "foo", "bar", "baz" )
end

#test_execute_no_blockObject



117
118
119
120
121
122
123
124
125
# File 'test/tc_database.rb', line 117

def test_execute_no_block
  # any_instance fails here...
  statement = Statement.new('cookie', 'foo')
  statement.expects(:execute).with('bar', 'baz').returns(MockResultSet.new)
  Statement.stubs(:new).returns(statement)
  MockResultSet.any_instance.stubs(:inject).returns([['foo']])
  result = @db.execute( "foo", "bar", "baz" )
  assert_equal [["foo"]], result
end

#test_execute_with_blockObject



127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'test/tc_database.rb', line 127

def test_execute_with_block
  called = false
  # any_instance fails here...
  statement = Statement.new('cookie', 'foo')
  statement.expects(:execute).with('bar', 'baz').returns(MockResultSet.new)
  Statement.stubs(:new).returns(statement)
  @db.execute( "foo", "bar", "baz" ) do |row|
    called = true
    assert_equal ["foo"], row
  end

  assert called
end

#test_get_first_rowObject



174
175
176
177
# File 'test/tc_database.rb', line 174

def test_get_first_row
  result = @db.get_first_row( "foo", "bar", "baz" )
  assert_equal ["foo"], result
end

#test_get_first_valueObject



179
180
181
182
# File 'test/tc_database.rb', line 179

def test_get_first_value
  result = @db.get_first_value( "foo", "bar", "baz" )
  assert_equal "foo", result
end

#test_interruptObject



194
195
196
197
# File 'test/tc_database.rb', line 194

def test_interrupt
  Driver.any_instance.expects(:interrupt)
  @db.interrupt
end

#test_prepare_no_blockObject



102
103
104
105
# File 'test/tc_database.rb', line 102

def test_prepare_no_block
  Statement.any_instance.expects(:close).never
  assert_nothing_raised { @db.prepare( "foo" ) }
end

#test_prepare_with_blockObject



107
108
109
110
111
112
113
114
115
# File 'test/tc_database.rb', line 107

def test_prepare_with_block
  called = false
  # any_instance fails here...
  statement = Statement.new('cookie', 'foo')
  statement.expects(:close).once
  Statement.stubs(:new).returns(statement)
  @db.prepare( "foo" ) { |stmt| called = true }
  assert called
end

#test_quoteObject



57
58
59
60
# File 'test/tc_database.rb', line 57

def test_quote
  assert_equal "''one''two''three''", SQLite3::Database.quote(
    "'one'two'three'" )
end

#test_total_changesObject



189
190
191
192
# File 'test/tc_database.rb', line 189

def test_total_changes
  Driver.any_instance.expects(:total_changes).returns(28)
  assert_equal 28, @db.total_changes
end

#test_traceObject



90
91
92
93
94
# File 'test/tc_database.rb', line 90

def test_trace
  Driver.any_instance.expects(:trace).with('cookie', 15)
  @db.trace( 15 ) { "foo" }
  # assert_equal 1, driver.mock_blocks[:trace].length
end

#test_translatorObject



77
78
79
80
# File 'test/tc_database.rb', line 77

def test_translator
  translator = @db.translator
  assert_instance_of SQLite3::Translator, translator
end