Commit c04ff93f authored by Holger Just's avatar Holger Just

[#112] Properly stub SQLite3 for version tests

parent 6e105a76
...@@ -16,12 +16,10 @@ ...@@ -16,12 +16,10 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
require File.expand_path('../../../../test_helper', __FILE__) require File.expand_path('../../../../test_helper', __FILE__)
require 'sqlite3_api'
class ChiliProject::DatabaseTest < ActiveSupport::TestCase class ChiliProject::DatabaseTest < ActiveSupport::TestCase
setup do setup do
ChiliProject::Database.stubs(:adapter_name).returns "SQLite" ChiliProject::Database.stubs(:adapter_name).returns "SQLite"
SQLite3::Driver::Native::API.stubs(:sqlite3_libversion).returns "3.6.12"
end end
should "return the correct identifier" do should "return the correct identifier" do
...@@ -34,13 +32,31 @@ class ChiliProject::DatabaseTest < ActiveSupport::TestCase ...@@ -34,13 +32,31 @@ class ChiliProject::DatabaseTest < ActiveSupport::TestCase
assert_equal true, ChiliProject::Database.sqlite? assert_equal true, ChiliProject::Database.sqlite?
end end
should "return a version string" do should "return a version string for SQLite3" do
assert_equal "3.6.12", ChiliProject::Database.version 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 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" 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" 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 ActiveRecord::Base.connection.stubs(:select_value).returns raw_version
...@@ -48,4 +64,12 @@ class ChiliProject::DatabaseTest < ActiveSupport::TestCase ...@@ -48,4 +64,12 @@ class ChiliProject::DatabaseTest < ActiveSupport::TestCase
assert_equal raw_version, ChiliProject::Database.version(true) assert_equal raw_version, ChiliProject::Database.version(true)
end 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 end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment