Permalink
Browse files

Travis: Added testing with MySQL. Fixes #31

  • Loading branch information...
1 parent 891c9ff commit 8923848e3a76cf0fbe111fb9a2911535313dffb2 @ledermann committed Mar 17, 2013
Showing with 29 additions and 5 deletions.
  1. +5 −0 .travis.yml
  2. +1 −0 ci/Gemfile.rails-3.1.x
  3. +1 −0 ci/Gemfile.rails-3.2.x
  4. +1 −0 rails-settings.gemspec
  5. +8 −0 spec/database.yml
  6. +12 −4 spec/spec_helper.rb
  7. +1 −1 spec/support/query_counter.rb
View
5 .travis.yml
@@ -6,3 +6,8 @@ rvm:
gemfile:
- ci/Gemfile.rails-3.1.x
- ci/Gemfile.rails-3.2.x
+env:
+ - DB=sqlite
+ - DB=mysql
+before_script:
+ - "mysql -e 'create database rails_settings_test;' >/dev/null"
View
1 ci/Gemfile.rails-3.1.x
@@ -2,5 +2,6 @@ source :rubygems
gem 'activerecord', '~> 3.1.0'
gem 'sqlite3', '~> 1.3'
+gem 'mysql2', '>= 0.3.6'
gem 'rake', '~> 10.0'
gem 'rspec', '~> 2.13'
View
1 ci/Gemfile.rails-3.2.x
@@ -2,5 +2,6 @@ source :rubygems
gem 'activerecord', '~> 3.2.0'
gem 'sqlite3', '~> 1.3'
+gem 'mysql2', '>= 0.3.6'
gem 'rake', '~> 10.0'
gem 'rspec', '~> 2.13'
View
1 rails-settings.gemspec
@@ -21,5 +21,6 @@ Gem::Specification.new do |gem|
gem.add_development_dependency 'rake', '~> 10.0'
gem.add_development_dependency 'sqlite3', '~> 1.3'
+ gem.add_development_dependency 'mysql2', '~> 0.3.11'
gem.add_development_dependency 'rspec', '~> 2.13'
end
View
8 spec/database.yml
@@ -0,0 +1,8 @@
+sqlite:
+ adapter: sqlite3
+ database: ":memory:"
+mysql:
+ adapter: mysql2
+ database: rails_settings_test
+ username:
+ encoding: utf8
View
16 spec/spec_helper.rb
@@ -23,9 +23,6 @@
require 'active_record'
require 'rails-settings'
-ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
-ActiveRecord::Migration.verbose = false
-
class User < ActiveRecord::Base
has_settings do |s|
s.key :dashboard, :defaults => { :theme => 'blue', :view => 'monthly', :filter => false }
@@ -56,6 +53,18 @@ class ProjectSettingObject < RailsSettings::SettingObject
end
def setup_db
+ ActiveRecord::Base.configurations = YAML.load_file(File.dirname(__FILE__) + '/database.yml')
+ db_name = ENV['DB'] || 'sqlite'
+ ActiveRecord::Base.establish_connection(db_name)
+
+ ActiveRecord::Migration.verbose = false
+ ActiveRecord::Base.connection.tables.each do |table|
+ next if table == 'schema_migrations'
+ ActiveRecord::Base.connection.execute("DROP TABLE #{table}")
+ end
+
+ puts "Testing on #{db_name} with ActiveRecord #{ActiveRecord::VERSION::STRING}"
+
ActiveRecord::Schema.define(:version => 1) do
create_table :settings do |t|
t.string :var, :null => false
@@ -86,5 +95,4 @@ def clear_db
RailsSettings::SettingObject.delete_all
end
-puts "Testing with ActiveRecord #{ActiveRecord::VERSION::STRING}"
setup_db
View
2 spec/support/query_counter.rb
@@ -11,7 +11,7 @@ def to_proc
end
def callback(name, start, finish, message_id, values)
- @query_count += 1 unless %w(CACHE SCHEMA).include?(values[:name]) || values[:sql] == 'begin transaction' || values[:sql] == 'commit transaction'
+ @query_count += 1 unless %w(CACHE SCHEMA).include?(values[:name]) || values[:sql] =~ /^begin/i || values[:sql] =~ /^commit/i
end
end
end

0 comments on commit 8923848

Please sign in to comment.