sqlite3-ruby 1.2.1-mswin32 → 1.2.2-mswin32

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.

@@ -1,35 +1,3 @@
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
1
  require 'sqlite3/errors'
34
2
  require 'sqlite3/resultset'
35
3
 
@@ -122,7 +90,11 @@ module SQLite3
122
90
  when Bignum then
123
91
  @driver.bind_int64( @handle, param, value )
124
92
  when Integer then
125
- @driver.bind_int( @handle, param, value )
93
+ if value >= (2 ** 31)
94
+ @driver.bind_int64( @handle, param, value )
95
+ else
96
+ @driver.bind_int( @handle, param, value )
97
+ end
126
98
  when Numeric then
127
99
  @driver.bind_double( @handle, param, value.to_f )
128
100
  when Blob then
@@ -1,36 +1,5 @@
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
1
  require 'time'
2
+ require 'date'
34
3
 
35
4
  module SQLite3
36
5
 
@@ -48,6 +17,7 @@ module SQLite3
48
17
  # translators for most SQL data types.
49
18
  def initialize
50
19
  @translators = Hash.new( proc { |type,value| value } )
20
+ @type_name_cache = {}
51
21
  register_default_translators
52
22
  end
53
23
 
@@ -81,18 +51,22 @@ module SQLite3
81
51
  # A convenience method for working with type names. This returns the "base"
82
52
  # type name, without any parenthetical data.
83
53
  def type_name( type )
84
- return "" if type.nil?
85
- type = $1 if type =~ /^(.*?)\(/
86
- type.upcase
54
+ @type_name_cache[type] ||= begin
55
+ type = "" if type.nil?
56
+ type = $1 if type =~ /^(.*?)\(/
57
+ type.upcase
58
+ end
87
59
  end
88
60
  private :type_name
89
61
 
90
62
  # Register the default translators for the current Translator instance.
91
63
  # This includes translators for most major SQL data types.
92
64
  def register_default_translators
93
- [ "date",
94
- "datetime",
95
- "time" ].each { |type| add_translator( type ) { |t,v| Time.parse( v ) } }
65
+ [ "time",
66
+ "timestamp" ].each { |type| add_translator( type ) { |t, v| Time.parse( v ) } }
67
+
68
+ add_translator( "date" ) { |t,v| Date.parse(v) }
69
+ add_translator( "datetime" ) { |t,v| DateTime.parse(v) }
96
70
 
97
71
  [ "decimal",
98
72
  "float",
@@ -120,7 +94,6 @@ module SQLite3
120
94
  end
121
95
  end
122
96
 
123
- add_translator( "timestamp" ) { |type, value| Time.at( value.to_i ) }
124
97
  add_translator( "tinyint" ) do |type, value|
125
98
  if type =~ /\(\s*1\s*\)/
126
99
  value.to_i == 1
data/lib/sqlite3/value.rb CHANGED
@@ -1,35 +1,3 @@
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
1
  require 'sqlite3/constants'
34
2
 
35
3
  module SQLite3
@@ -1,42 +1,10 @@
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
1
  module SQLite3
34
2
 
35
3
  module Version
36
4
 
37
5
  MAJOR = 1
38
6
  MINOR = 2
39
- TINY = 1
7
+ TINY = 2
40
8
 
41
9
  STRING = [ MAJOR, MINOR, TINY ].join( "." )
42
10
  #:beta-tag:
Binary file
@@ -1,35 +1,3 @@
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
1
  if (ENV["SQLITE3_DRIVERS"] || "Native").split(/,/).include?("DL")
34
2
  $:.unshift "../../../lib"
35
3
 
data/test/mocks.rb CHANGED
@@ -1,102 +1,45 @@
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
1
  require 'rubygems'
34
- gem 'flexmock', '< 0.1.0'
35
-
36
- require 'flexmock'
2
+ gem 'mocha'
37
3
 
38
- class FlexMockWithArgs < FlexMock
39
- attr_reader :mock_args
40
- attr_reader :mock_blocks
4
+ require 'mocha'
41
5
 
6
+ class Driver < Mocha::Mock
42
7
  def initialize
43
8
  super
44
- @mock_args = Hash.new { |h,k| h[k] = [] }
45
- @mock_blocks = Hash.new { |h,k| h[k] = [] }
46
- end
47
-
48
- def method_missing( sym, *args, &block )
49
- @mock_args[sym] << args
50
- @mock_blocks[sym] << block
51
- super
9
+ stubs( :open ).returns([0, 'cookie'])
10
+ stubs( :close ).returns(0)
11
+ stubs( :complete? ).returns(0)
12
+ stubs( :errmsg ).returns('')
13
+ stubs( :errcode ).returns(0)
14
+ stubs( :trace ).returns(nil)
15
+ stubs( :set_authorizer ).returns(0)
16
+ stubs( :prepare ).returns([0, 'stmt', 'remainder'])
17
+ stubs( :finalize ).returns(0)
18
+ stubs( :changes ).returns(14)
19
+ stubs( :total_changes ).returns(28)
20
+ stubs( :interrupt ).returns(0)
52
21
  end
53
22
  end
54
23
 
55
- class Driver < FlexMockWithArgs
56
- def self.instance
57
- @@instance
58
- end
59
-
24
+ class MockResultSet < Mocha::Mock
60
25
  def initialize
61
26
  super
62
- @@instance = self
63
- mock_handle( :open ) { [0,"cookie"] }
64
- mock_handle( :close ) { 0 }
65
- mock_handle( :complete? ) { 0 }
66
- mock_handle( :errmsg ) { "" }
67
- mock_handle( :errcode ) { 0 }
68
- mock_handle( :trace ) { nil }
69
- mock_handle( :set_authorizer ) { 0 }
70
- mock_handle( :prepare ) { [0,"stmt", "remainder"] }
71
- mock_handle( :finalize ) { 0 }
72
- mock_handle( :changes ) { 14 }
73
- mock_handle( :total_changes ) { 28 }
74
- mock_handle( :interrupt ) { 0 }
27
+ stubs( :each ).yields(['foo'])
28
+ stubs( :columns ).returns(['name'])
75
29
  end
76
30
  end
77
31
 
78
- class Statement < FlexMockWithArgs
79
- def self.instance
80
- @@instance
81
- end
82
-
32
+ class Statement < Mocha::Mock
83
33
  attr_reader :handle
84
34
  attr_reader :sql
85
35
  attr_reader :last_result
86
36
 
87
37
  def initialize( handle, sql )
88
38
  super()
89
- @@instance = self
90
39
  @handle = handle
91
40
  @sql = sql
92
- mock_handle( :close ) { 0 }
93
- mock_handle( :remainder ) { "" }
94
- mock_handle( :execute ) do
95
- @last_result = FlexMockWithArgs.new
96
- @last_result.mock_handle( :each ) { @last_result.mock_blocks[:each].last.call ["foo"] }
97
- @last_result.mock_handle( :inject ) { |a,| @last_result.mock_blocks[:inject].last.call a, ["foo"] }
98
- @last_result.mock_handle( :columns ) { ["name"] }
99
- @last_result
100
- end
41
+ stubs( :close ).returns(0)
42
+ stubs( :remainder ).returns('')
43
+ stubs( :execute ).returns(MockResultSet.new)
101
44
  end
102
45
  end
data/test/tc_database.rb CHANGED
@@ -1,35 +1,3 @@
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
1
  $:.unshift "../lib"
34
2
 
35
3
  require 'sqlite3/database'
@@ -39,19 +7,22 @@ require 'mocks'
39
7
 
40
8
  class TC_Database_Init < Test::Unit::TestCase
41
9
  def test_new
42
- db = SQLite3::Database.new( "foo.db", :driver => Driver )
43
- assert_equal 1, Driver.instance.mock_count(:open)
10
+ # any_instance fails here...
11
+ driver = Driver.new
12
+ driver.expects(:open).once.with('foo.db', false).returns([0, 'cookie'])
13
+ Driver.stubs(:new).returns(driver)
14
+ db = SQLite3::Database.new( 'foo.db', :driver => Driver )
44
15
  assert !db.closed?
45
- assert_equal [["foo.db",false]], Driver.instance.mock_args[:open]
46
16
  assert !db.results_as_hash
47
17
  assert !db.type_translation
48
18
  end
49
19
 
50
20
  def test_open
21
+ driver = Driver.new
22
+ driver.expects(:open).once.with('foo.db', false).returns([0, 'cookie'])
23
+ Driver.stubs(:new).returns(driver)
51
24
  db = SQLite3::Database.open( "foo.db", :driver => Driver )
52
- assert_equal 1, Driver.instance.mock_count(:open)
53
25
  assert !db.closed?
54
- assert_equal [["foo.db",false]], Driver.instance.mock_args[:open]
55
26
  assert !db.results_as_hash
56
27
  assert !db.type_translation
57
28
  end
@@ -89,18 +60,18 @@ class TC_Database < Test::Unit::TestCase
89
60
  end
90
61
 
91
62
  def test_complete
63
+ Driver.any_instance.expects(:complete?)
92
64
  @db.complete? "foo"
93
- assert_equal 1, Driver.instance.mock_count( :complete? )
94
65
  end
95
66
 
96
67
  def test_errmsg
68
+ Driver.any_instance.expects(:errmsg)
97
69
  @db.errmsg
98
- assert_equal 1, Driver.instance.mock_count( :errmsg )
99
70
  end
100
71
 
101
72
  def test_errcode
73
+ Driver.any_instance.expects(:errcode)
102
74
  @db.errcode
103
- assert_equal 1, Driver.instance.mock_count( :errcode )
104
75
  end
105
76
 
106
77
  def test_translator
@@ -109,84 +80,95 @@ class TC_Database < Test::Unit::TestCase
109
80
  end
110
81
 
111
82
  def test_close
83
+ Driver.any_instance.expects(:close).returns(0)
112
84
  @db.close
113
- assert_equal 1, Driver.instance.mock_count( :close )
114
85
  assert @db.closed?
86
+ Driver.any_instance.expects(:close).never
115
87
  @db.close
116
- assert_equal 1, Driver.instance.mock_count( :close )
117
88
  end
118
89
 
119
90
  def test_trace
91
+ Driver.any_instance.expects(:trace).with('cookie', 15)
120
92
  @db.trace( 15 ) { "foo" }
121
- driver = Driver.instance
122
- assert_equal 1, driver.mock_count( :trace )
123
- assert_equal [[ "cookie", 15 ]], driver.mock_args[:trace]
124
- assert_equal 1, driver.mock_blocks[:trace].length
93
+ # assert_equal 1, driver.mock_blocks[:trace].length
125
94
  end
126
95
 
127
96
  def test_authorizer
97
+ Driver.any_instance.expects(:set_authorizer).with('cookie', 15).returns(0)
128
98
  @db.authorizer( 15 ) { "foo" }
129
- driver = Driver.instance
130
- assert_equal 1, driver.mock_count( :set_authorizer )
131
- assert_equal [[ "cookie", 15 ]], driver.mock_args[:set_authorizer]
132
- assert_equal 1, driver.mock_blocks[:set_authorizer].length
99
+ # assert_equal 1, driver.mock_blocks[:set_authorizer].length
133
100
  end
134
101
 
135
102
  def test_prepare_no_block
103
+ Statement.any_instance.expects(:close).never
136
104
  assert_nothing_raised { @db.prepare( "foo" ) }
137
- assert_equal 0, Statement.instance.mock_count( :close )
138
105
  end
139
106
 
140
107
  def test_prepare_with_block
141
108
  called = false
109
+ # any_instance fails here...
110
+ statement = Statement.new('cookie', 'foo')
111
+ statement.expects(:close).once
112
+ Statement.stubs(:new).returns(statement)
142
113
  @db.prepare( "foo" ) { |stmt| called = true }
143
114
  assert called
144
- assert_equal 1, Statement.instance.mock_count( :close )
145
115
  end
146
116
 
147
117
  def test_execute_no_block
118
+ # any_instance fails here...
119
+ statement = Statement.new('cookie', 'foo')
120
+ statement.expects(:execute).with('bar', 'baz').returns(MockResultSet.new)
121
+ Statement.stubs(:new).returns(statement)
122
+ MockResultSet.any_instance.stubs(:inject).returns([['foo']])
148
123
  result = @db.execute( "foo", "bar", "baz" )
149
- stmt = Statement.instance
150
124
  assert_equal [["foo"]], result
151
- assert_equal [["bar", "baz"]], stmt.mock_args[:execute]
152
125
  end
153
126
 
154
127
  def test_execute_with_block
155
128
  called = false
129
+ # any_instance fails here...
130
+ statement = Statement.new('cookie', 'foo')
131
+ statement.expects(:execute).with('bar', 'baz').returns(MockResultSet.new)
132
+ Statement.stubs(:new).returns(statement)
156
133
  @db.execute( "foo", "bar", "baz" ) do |row|
157
134
  called = true
158
135
  assert_equal ["foo"], row
159
136
  end
160
137
 
161
- stmt = Statement.instance
162
138
  assert called
163
- assert_equal [["bar", "baz"]], stmt.mock_args[:execute]
164
139
  end
165
140
 
166
141
  def test_execute2_no_block
142
+ # any_instance fails here...
143
+ statement = Statement.new('cookie', 'foo')
144
+ statement.expects(:execute).with('bar', 'baz').returns(MockResultSet.new)
145
+ Statement.stubs(:new).returns(statement)
146
+ MockResultSet.any_instance.stubs(:inject).returns([['name'], ['foo']])
167
147
  result = @db.execute2( "foo", "bar", "baz" )
168
- stmt = Statement.instance
169
148
  assert_equal [["name"],["foo"]], result
170
- assert_equal [["bar", "baz"]], stmt.mock_args[:execute]
171
149
  end
172
150
 
173
151
  def test_execute2_with_block
174
152
  called = false
175
153
  parts = [ ["name"],["foo"] ]
154
+ # any_instance fails here...
155
+ statement = Statement.new('cookie', 'foo')
156
+ statement.expects(:execute).with('bar', 'baz').returns(MockResultSet.new)
157
+ Statement.stubs(:new).returns(statement)
176
158
  @db.execute2( "foo", "bar", "baz" ) do |row|
177
159
  called = true
178
160
  assert_equal parts.shift, row
179
161
  end
180
162
 
181
- stmt = Statement.instance
182
163
  assert called
183
- assert_equal [["bar", "baz"]], stmt.mock_args[:execute]
184
164
  end
185
165
 
186
166
  def test_execute_batch
167
+ # any_instance fails here...
168
+ statement = Statement.new('cookie', 'foo')
169
+ statement.expects(:execute).with('bar', 'baz').returns(MockResultSet.new)
170
+ Statement.stubs(:new).returns(statement)
187
171
  @db.execute_batch( "foo", "bar", "baz" )
188
- stmt = Statement.instance
189
- assert_equal [["bar", "baz"]], stmt.mock_args[:execute]
190
172
  end
191
173
 
192
174
  def test_get_first_row
@@ -200,17 +182,17 @@ class TC_Database < Test::Unit::TestCase
200
182
  end
201
183
 
202
184
  def test_changes
185
+ Driver.any_instance.expects(:changes).returns(14)
203
186
  assert_equal 14, @db.changes
204
- assert_equal 1, Driver.instance.mock_count(:changes)
205
187
  end
206
188
 
207
189
  def test_total_changes
190
+ Driver.any_instance.expects(:total_changes).returns(28)
208
191
  assert_equal 28, @db.total_changes
209
- assert_equal 1, Driver.instance.mock_count(:total_changes)
210
192
  end
211
193
 
212
194
  def test_interrupt
195
+ Driver.any_instance.expects(:interrupt)
213
196
  @db.interrupt
214
- assert_equal 1, Driver.instance.mock_count(:interrupt)
215
197
  end
216
198
  end