Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
O
OHR Support
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
97
Issues
97
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Projects
OHR Support
Commits
c04ff93f
Commit
c04ff93f
authored
May 20, 2011
by
Holger Just
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[
#112
] Properly stub SQLite3 for version tests
parent
6e105a76
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
6 deletions
+30
-6
database_test.rb
test/unit/lib/chili_project/database_test.rb
+30
-6
No files found.
test/unit/lib/chili_project/database_test.rb
View file @
c04ff93f
...
...
@@ -16,12 +16,10 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
require
File
.
expand_path
(
'../../../../test_helper'
,
__FILE__
)
require
'sqlite3_api'
class
ChiliProject
::
DatabaseTest
<
ActiveSupport
::
TestCase
setup
do
ChiliProject
::
Database
.
stubs
(
:adapter_name
).
returns
"SQLite"
SQLite3
::
Driver
::
Native
::
API
.
stubs
(
:sqlite3_libversion
).
returns
"3.6.12"
end
should
"return the correct identifier"
do
...
...
@@ -34,13 +32,31 @@ class ChiliProject::DatabaseTest < ActiveSupport::TestCase
assert_equal
true
,
ChiliProject
::
Database
.
sqlite?
end
should
"return a version string"
do
assert_equal
"3.6.12"
,
ChiliProject
::
Database
.
version
should
"return a version string for SQLite3"
do
begin
ChiliProject
::
Database
.
stubs
(
:adapter_name
).
returns
"SQLite"
# if we run the tests on sqlite, just stub the version method
if
Object
.
const_defined?
'SQLite3'
SQLite3
::
Driver
::
Native
::
API
.
stubs
(
:sqlite3_libversion
).
returns
"1.2.3"
else
# if we don't have any sqlite3 module, stub the whole module
module
::
SQLite3
;
module
Driver
;
module
Native
;
module
API
def
self
.
sqlite3_libversion
;
"1.2.3"
;
end
end
;
end
;
end
;
end
created_stub
=
true
end
assert_equal
"1.2.3"
,
ChiliProject
::
Database
.
version
assert_equal
"1.2.3"
,
ChiliProject
::
Database
.
version
(
true
)
ensure
# Clean up after us
Object
.
instance_eval
{
remove_const
:SQLite3
}
if
created_stub
end
end
should
"return
long version string for raw==true
"
do
should
"return
a version string for PostgreSQL
"
do
ChiliProject
::
Database
.
stubs
(
:adapter_name
).
returns
"PostgreSQL"
raw_version
=
"PostgreSQL 8.3.11 on x86_64-pc-linux-gnu, compiled by GCC gcc-4.3.real (Debian 4.3.2-1.1) 4.3.2"
ActiveRecord
::
Base
.
connection
.
stubs
(
:select_value
).
returns
raw_version
...
...
@@ -48,4 +64,12 @@ class ChiliProject::DatabaseTest < ActiveSupport::TestCase
assert_equal
raw_version
,
ChiliProject
::
Database
.
version
(
true
)
end
should
"return a version string for MySQL"
do
ChiliProject
::
Database
.
stubs
(
:adapter_name
).
returns
"MySQL"
ActiveRecord
::
Base
.
connection
.
stubs
(
:select_value
).
returns
"5.1.2"
assert_equal
"5.1.2"
,
ChiliProject
::
Database
.
version
assert_equal
"5.1.2"
,
ChiliProject
::
Database
.
version
(
true
)
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment