sqlite3-ruby 0.5.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of sqlite3-ruby might be problematic. Click here for more details.

data/test/mocks.rb ADDED
@@ -0,0 +1,99 @@
1
+ #--
2
+ # =============================================================================
3
+ # Copyright (c) 2004, Jamis Buck (jgb3@email.byu.edu)
4
+ # All rights reserved.
5
+ #
6
+ # Redistribution and use in source and binary forms, with or without
7
+ # modification, are permitted provided that the following conditions are met:
8
+ #
9
+ # * Redistributions of source code must retain the above copyright notice,
10
+ # this list of conditions and the following disclaimer.
11
+ #
12
+ # * Redistributions in binary form must reproduce the above copyright
13
+ # notice, this list of conditions and the following disclaimer in the
14
+ # documentation and/or other materials provided with the distribution.
15
+ #
16
+ # * The names of its contributors may not be used to endorse or promote
17
+ # products derived from this software without specific prior written
18
+ # permission.
19
+ #
20
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
+ # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
24
+ # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
+ # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26
+ # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27
+ # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28
+ # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
+ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
+ # =============================================================================
31
+ #++
32
+
33
+ require 'flexmock'
34
+
35
+ class FlexMockWithArgs < FlexMock
36
+ attr_reader :mock_args
37
+ attr_reader :mock_blocks
38
+
39
+ def initialize
40
+ super
41
+ @mock_args = Hash.new { |h,k| h[k] = [] }
42
+ @mock_blocks = Hash.new { |h,k| h[k] = [] }
43
+ end
44
+
45
+ def method_missing( sym, *args, &block )
46
+ @mock_args[sym] << args
47
+ @mock_blocks[sym] << block
48
+ super
49
+ end
50
+ end
51
+
52
+ class Driver < FlexMockWithArgs
53
+ def self.instance
54
+ @@instance
55
+ end
56
+
57
+ def initialize
58
+ super
59
+ @@instance = self
60
+ mock_handle( :open ) { [0,"cookie"] }
61
+ mock_handle( :close ) { 0 }
62
+ mock_handle( :complete? ) { 0 }
63
+ mock_handle( :errmsg ) { "" }
64
+ mock_handle( :errcode ) { 0 }
65
+ mock_handle( :trace ) { nil }
66
+ mock_handle( :set_authorizer ) { 0 }
67
+ mock_handle( :prepare ) { [0,"stmt", "remainder"] }
68
+ mock_handle( :finalize ) { 0 }
69
+ mock_handle( :changes ) { 14 }
70
+ mock_handle( :total_changes ) { 28 }
71
+ mock_handle( :interrupt ) { 0 }
72
+ end
73
+ end
74
+
75
+ class Statement < FlexMockWithArgs
76
+ def self.instance
77
+ @@instance
78
+ end
79
+
80
+ attr_reader :handle
81
+ attr_reader :sql
82
+ attr_reader :last_result
83
+
84
+ def initialize( handle, sql )
85
+ super()
86
+ @@instance = self
87
+ @handle = handle
88
+ @sql = sql
89
+ mock_handle( :close ) { 0 }
90
+ mock_handle( :remainder ) { "" }
91
+ mock_handle( :execute ) do
92
+ @last_result = FlexMockWithArgs.new
93
+ @last_result.mock_handle( :each ) { @last_result.mock_blocks[:each].last.call ["foo"] }
94
+ @last_result.mock_handle( :inject ) { |a,| @last_result.mock_blocks[:inject].last.call a, ["foo"] }
95
+ @last_result.mock_handle( :columns ) { ["name"] }
96
+ @last_result
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,215 @@
1
+ #--
2
+ # =============================================================================
3
+ # Copyright (c) 2004, Jamis Buck (jgb3@email.byu.edu)
4
+ # All rights reserved.
5
+ #
6
+ # Redistribution and use in source and binary forms, with or without
7
+ # modification, are permitted provided that the following conditions are met:
8
+ #
9
+ # * Redistributions of source code must retain the above copyright notice,
10
+ # this list of conditions and the following disclaimer.
11
+ #
12
+ # * Redistributions in binary form must reproduce the above copyright
13
+ # notice, this list of conditions and the following disclaimer in the
14
+ # documentation and/or other materials provided with the distribution.
15
+ #
16
+ # * The names of its contributors may not be used to endorse or promote
17
+ # products derived from this software without specific prior written
18
+ # permission.
19
+ #
20
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
+ # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
24
+ # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
+ # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26
+ # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27
+ # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28
+ # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
+ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
+ # =============================================================================
31
+ #++
32
+
33
+ $:.unshift "../lib"
34
+
35
+ require 'sqlite3/database'
36
+ require 'test/unit'
37
+
38
+ require 'mocks'
39
+
40
+ class TC_Database_Init < Test::Unit::TestCase
41
+ def test_new
42
+ db = SQLite3::Database.new( "foo.db", :driver => Driver )
43
+ assert_equal 1, Driver.instance.mock_count(:open)
44
+ assert !db.closed?
45
+ assert_equal [["foo.db",false]], Driver.instance.mock_args[:open]
46
+ assert !db.results_as_hash
47
+ assert !db.type_translation
48
+ end
49
+
50
+ def test_open
51
+ db = SQLite3::Database.open( "foo.db", :driver => Driver )
52
+ assert_equal 1, Driver.instance.mock_count(:open)
53
+ assert !db.closed?
54
+ assert_equal [["foo.db",false]], Driver.instance.mock_args[:open]
55
+ assert !db.results_as_hash
56
+ assert !db.type_translation
57
+ end
58
+
59
+ def test_with_type_translation
60
+ db = SQLite3::Database.open( "foo.db", :driver => Driver,
61
+ :type_translation => true )
62
+ assert db.type_translation
63
+ end
64
+
65
+ def test_with_results_as_hash
66
+ db = SQLite3::Database.open( "foo.db", :driver => Driver,
67
+ :results_as_hash => true )
68
+ assert db.results_as_hash
69
+ end
70
+
71
+ def test_with_type_translation_and_results_as_hash
72
+ db = SQLite3::Database.open( "foo.db", :driver => Driver,
73
+ :results_as_hash => true,
74
+ :type_translation => true )
75
+ assert db.results_as_hash
76
+ assert db.type_translation
77
+ end
78
+ end
79
+
80
+ class TC_Database < Test::Unit::TestCase
81
+ def setup
82
+ @db = SQLite3::Database.open( "foo.db",
83
+ :driver => Driver, :statement_factory => Statement )
84
+ end
85
+
86
+ def test_quote
87
+ assert_equal "''one''two''three''", @db.quote( "'one'two'three'" )
88
+ end
89
+
90
+ def test_complete
91
+ @db.complete? "foo"
92
+ assert_equal 1, Driver.instance.mock_count( :complete? )
93
+ end
94
+
95
+ def test_errmsg
96
+ @db.errmsg
97
+ assert_equal 1, Driver.instance.mock_count( :errmsg )
98
+ end
99
+
100
+ def test_errcode
101
+ @db.errcode
102
+ assert_equal 1, Driver.instance.mock_count( :errcode )
103
+ end
104
+
105
+ def test_translator
106
+ translator = @db.translator
107
+ assert_instance_of SQLite3::Translator, translator
108
+ end
109
+
110
+ def test_close
111
+ @db.close
112
+ assert_equal 1, Driver.instance.mock_count( :close )
113
+ assert @db.closed?
114
+ @db.close
115
+ assert_equal 1, Driver.instance.mock_count( :close )
116
+ end
117
+
118
+ def test_trace
119
+ @db.trace( 15 ) { "foo" }
120
+ driver = Driver.instance
121
+ assert_equal 1, driver.mock_count( :trace )
122
+ assert_equal [[ "cookie", 15 ]], driver.mock_args[:trace]
123
+ assert_equal 1, driver.mock_blocks[:trace].length
124
+ end
125
+
126
+ def test_authorizer
127
+ @db.authorizer( 15 ) { "foo" }
128
+ driver = Driver.instance
129
+ assert_equal 1, driver.mock_count( :set_authorizer )
130
+ assert_equal [[ "cookie", 15 ]], driver.mock_args[:set_authorizer]
131
+ assert_equal 1, driver.mock_blocks[:set_authorizer].length
132
+ end
133
+
134
+ def test_prepare_no_block
135
+ assert_nothing_raised { @db.prepare( "foo" ) }
136
+ assert_equal 0, Statement.instance.mock_count( :close )
137
+ end
138
+
139
+ def test_prepare_with_block
140
+ called = false
141
+ @db.prepare( "foo" ) { |stmt| called = true }
142
+ assert called
143
+ assert_equal 1, Statement.instance.mock_count( :close )
144
+ end
145
+
146
+ def test_execute_no_block
147
+ result = @db.execute( "foo", "bar", "baz" )
148
+ stmt = Statement.instance
149
+ assert_equal [["foo"]], result
150
+ assert_equal [["bar", "baz"]], stmt.mock_args[:execute]
151
+ end
152
+
153
+ def test_execute_with_block
154
+ called = false
155
+ @db.execute( "foo", "bar", "baz" ) do |row|
156
+ called = true
157
+ assert_equal ["foo"], row
158
+ end
159
+
160
+ stmt = Statement.instance
161
+ assert called
162
+ assert_equal [["bar", "baz"]], stmt.mock_args[:execute]
163
+ end
164
+
165
+ def test_execute2_no_block
166
+ result = @db.execute2( "foo", "bar", "baz" )
167
+ stmt = Statement.instance
168
+ assert_equal [["name"],["foo"]], result
169
+ assert_equal [["bar", "baz"]], stmt.mock_args[:execute]
170
+ end
171
+
172
+ def test_execute2_with_block
173
+ called = false
174
+ parts = [ ["name"],["foo"] ]
175
+ @db.execute2( "foo", "bar", "baz" ) do |row|
176
+ called = true
177
+ assert_equal parts.shift, row
178
+ end
179
+
180
+ stmt = Statement.instance
181
+ assert called
182
+ assert_equal [["bar", "baz"]], stmt.mock_args[:execute]
183
+ end
184
+
185
+ def test_execute_batch
186
+ @db.execute_batch( "foo", "bar", "baz" )
187
+ stmt = Statement.instance
188
+ assert_equal [["bar", "baz"]], stmt.mock_args[:execute]
189
+ end
190
+
191
+ def test_get_first_row
192
+ result = @db.get_first_row( "foo", "bar", "baz" )
193
+ assert_equal ["foo"], result
194
+ end
195
+
196
+ def test_get_first_value
197
+ result = @db.get_first_value( "foo", "bar", "baz" )
198
+ assert_equal "foo", result
199
+ end
200
+
201
+ def test_changes
202
+ assert_equal 14, @db.changes
203
+ assert_equal 1, Driver.instance.mock_count(:changes)
204
+ end
205
+
206
+ def test_total_changes
207
+ assert_equal 28, @db.total_changes
208
+ assert_equal 1, Driver.instance.mock_count(:total_changes)
209
+ end
210
+
211
+ def test_interrupt
212
+ @db.interrupt
213
+ assert_equal 1, Driver.instance.mock_count(:interrupt)
214
+ end
215
+ end
data/test/tests.rb ADDED
@@ -0,0 +1,35 @@
1
+ #--
2
+ # =============================================================================
3
+ # Copyright (c) 2004, Jamis Buck (jgb3@email.byu.edu)
4
+ # All rights reserved.
5
+ #
6
+ # Redistribution and use in source and binary forms, with or without
7
+ # modification, are permitted provided that the following conditions are met:
8
+ #
9
+ # * Redistributions of source code must retain the above copyright notice,
10
+ # this list of conditions and the following disclaimer.
11
+ #
12
+ # * Redistributions in binary form must reproduce the above copyright
13
+ # notice, this list of conditions and the following disclaimer in the
14
+ # documentation and/or other materials provided with the distribution.
15
+ #
16
+ # * The names of its contributors may not be used to endorse or promote
17
+ # products derived from this software without specific prior written
18
+ # permission.
19
+ #
20
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30
+ # POSSIBILITY OF SUCH DAMAGE.
31
+ # =============================================================================
32
+ #++
33
+
34
+ Dir.chdir File.dirname( __FILE__ )
35
+ Dir["**/tc_*.rb"].each { |file| load file }
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.8.3
3
+ specification_version: 1
4
+ name: sqlite3-ruby
5
+ version: !ruby/object:Gem::Version
6
+ version: 0.5.0
7
+ date: 2004-12-21
8
+ summary: SQLite3/Ruby is a module to allow Ruby scripts to interface with a SQLite3 database.
9
+ require_paths:
10
+ - lib
11
+ email: jgb3@email.byu.edu
12
+ homepage: http://sqlite-ruby.rubyforge.org/sqlite3
13
+ rubyforge_project:
14
+ description:
15
+ autorequire: sqlite3
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: true
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ -
22
+ - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: 1.8.0
25
+ version:
26
+ platform: ruby
27
+ authors:
28
+ - Jamis Buck
29
+ files:
30
+ - doc/faq
31
+ - doc/faq/faq.html
32
+ - doc/faq/faq.yml
33
+ - doc/faq/faq.rb
34
+ - lib/sqlite3.rb
35
+ - lib/sqlite3
36
+ - lib/sqlite3/statement.rb
37
+ - lib/sqlite3/database.rb
38
+ - lib/sqlite3/driver
39
+ - lib/sqlite3/constants.rb
40
+ - lib/sqlite3/translator.rb
41
+ - lib/sqlite3/resultset.rb
42
+ - lib/sqlite3/value.rb
43
+ - lib/sqlite3/version.rb
44
+ - lib/sqlite3/pragmas.rb
45
+ - lib/sqlite3/errors.rb
46
+ - lib/sqlite3/driver/dl
47
+ - lib/sqlite3/driver/dl/driver.rb
48
+ - lib/sqlite3/driver/dl/api.rb
49
+ - test/bm.rb
50
+ - test/mocks.rb
51
+ - test/tests.rb
52
+ - test/driver
53
+ - test/tc_database.rb
54
+ - test/driver/dl
55
+ - test/driver/dl/tc_driver.rb
56
+ - README
57
+ test_files:
58
+ - test/tests.rb
59
+ rdoc_options:
60
+ - "--main"
61
+ - README
62
+ extra_rdoc_files:
63
+ - README
64
+ executables: []
65
+ extensions: []
66
+ requirements: []
67
+ dependencies: []