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
18247a6c
Commit
18247a6c
authored
May 22, 2011
by
Holger Just
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[112] Detect SQLite3 version on JRuby
parent
79ed4920
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
12 deletions
+47
-12
database.rb
lib/chili_project/database.rb
+7
-3
database_test.rb
test/unit/lib/chili_project/database_test.rb
+40
-9
No files found.
lib/chili_project/database.rb
View file @
18247a6c
...
...
@@ -66,10 +66,14 @@ module ChiliProject
version
=
ActiveRecord
::
Base
.
connection
.
select_value
(
'SELECT version()'
)
raw
?
version
:
version
.
match
(
/^PostgreSQL (\S+)/i
)[
1
]
when
:sqlite
if
SQLite3
.
const_defined?
'SQLITE_VERSION
'
SQLite3
::
SQLITE_
VERSION
if
RUBY_ENGINE
==
'jruby
'
Jdbc
::
SQLite3
::
VERSION
else
SQLite3
::
Driver
::
Native
::
API
.
sqlite3_libversion
if
SQLite3
.
const_defined?
'SQLITE_VERSION'
SQLite3
::
SQLITE_VERSION
else
SQLite3
::
Driver
::
Native
::
API
.
sqlite3_libversion
end
end
end
end
...
...
test/unit/lib/chili_project/database_test.rb
View file @
18247a6c
...
...
@@ -36,22 +36,53 @@ class ChiliProject::DatabaseTest < ActiveSupport::TestCase
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"
if
RUBY_ENGINE
==
'jruby'
# If we have the SQLite3 gem installed, save the old constant
if
Object
.
const_defined?
(
'Jdbc'
)
&&
Jdbc
::
SQLite3
.
const_defined?
(
'SQLite3'
)
sqlite3_version
=
Jdbc
::
SQLite3
::
VERSION
# else create the module for this test
else
module
::
Jdbc
;
module
SQLite3
;
end
;
end
created_module
=
true
end
silence_warnings
{
::
Jdbc
::
SQLite3
.
const_set
(
'VERSION'
,
"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
# If we run the tests on a newer SQLite3, stub the VERSION constant
if
Object
.
const_defined?
(
'SQLite3'
)
&&
SQLite3
.
const_defined?
(
'SQLITE_VERSION'
)
sqlite3_version
=
SQLite3
::
SQLITE_VERSION
silence_warnings
{
::
SQLite3
.
const_set
(
'SQLITE_VERSION'
,
"1.2.3"
)
}
# On an older SQLite3, stub the C-provided sqlite3_libversion method
elsif
%w(SQLite3 Driver Native API)
.
inject
(
Object
){
|
m
,
defined
|
m
=
(
m
&&
m
.
const_defined?
(
defined
))
?
m
.
const_get
(
defined
)
:
false
}
SQLite3
::
Driver
::
Native
::
API
.
stubs
(
'sqlite3_libversion'
).
returns
"1.2.3"
# Fallback if nothing else worked: Stub the old SQLite3 API
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_module
=
true
end
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
if
RUBY_ENGINE
==
'jruby'
if
created_module
Jdbc
.
instance_eval
{
remove_const
'SQLite3'
}
elsif
sqlite3_version
silence_warnings
{
Jdbc
::
SQLite3
.
const_set
(
'VERSION'
,
sqlite3_version
)
}
end
else
if
created_module
Object
.
instance_eval
{
remove_const
'SQLite3'
}
elsif
sqlite3_version
silence_warnings
{
SQLite3
.
const_set
(
'SQLITE_VERSION'
,
sqlite3_version
)
}
end
end
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