Fix ActiveSupport::TestCase tests for MySQL
This commit is contained in:
parent
0b05a58763
commit
4dba95a082
|
@ -13,6 +13,7 @@
|
||||||
become the live instance.
|
become the live instance.
|
||||||
- If `destroy` actions are tracked for a versioned model, invoking `destroy` on the model will cause the corresponding version that
|
- If `destroy` actions are tracked for a versioned model, invoking `destroy` on the model will cause the corresponding version that
|
||||||
gets generated to be assigned as the source version (`model_instance#version_association_name`, usually `model_instance#version`).
|
gets generated to be assigned as the source version (`model_instance#version_association_name`, usually `model_instance#version`).
|
||||||
|
- Gem is now tested against `MySQL` and `PostgreSQL` in addition to `SQLite`.
|
||||||
|
|
||||||
## 3.0.1
|
## 3.0.1
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,7 @@ Gem::Specification.new do |s|
|
||||||
s.add_development_dependency 'rack-test', '>= 0.6'
|
s.add_development_dependency 'rack-test', '>= 0.6'
|
||||||
s.add_development_dependency 'rspec-rails', '~> 2.14'
|
s.add_development_dependency 'rspec-rails', '~> 2.14'
|
||||||
s.add_development_dependency 'generator_spec'
|
s.add_development_dependency 'generator_spec'
|
||||||
|
s.add_development_dependency 'database_cleaner', '~> 1.2'
|
||||||
|
|
||||||
# JRuby support for the test ENV
|
# JRuby support for the test ENV
|
||||||
unless defined?(JRUBY_VERSION)
|
unless defined?(JRUBY_VERSION)
|
||||||
|
|
|
@ -5,7 +5,7 @@ class SetUpTestTables < ActiveRecord::Migration
|
||||||
t.text :a_text
|
t.text :a_text
|
||||||
t.integer :an_integer
|
t.integer :an_integer
|
||||||
t.float :a_float
|
t.float :a_float
|
||||||
t.decimal :a_decimal
|
t.decimal :a_decimal, :precision => 6, :scale => 4
|
||||||
t.datetime :a_datetime
|
t.datetime :a_datetime
|
||||||
t.time :a_time
|
t.time :a_time
|
||||||
t.date :a_date
|
t.date :a_date
|
||||||
|
|
|
@ -71,6 +71,7 @@ ActiveRecord::Schema.define(:version => 20110208155312) do
|
||||||
t.integer "article_id"
|
t.integer "article_id"
|
||||||
t.string "ip"
|
t.string "ip"
|
||||||
t.string "user_agent"
|
t.string "user_agent"
|
||||||
|
t.text :object_changes
|
||||||
end
|
end
|
||||||
|
|
||||||
add_index "versions", ["item_type", "item_id"], :name => "index_versions_on_item_type_and_item_id"
|
add_index "versions", ["item_type", "item_id"], :name => "index_versions_on_item_type_and_item_id"
|
||||||
|
|
|
@ -29,7 +29,6 @@ class ModularSinatraTest < ActionDispatch::IntegrationTest
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'baseline' do
|
test 'baseline' do
|
||||||
assert_nil Widget.first
|
|
||||||
assert_nil Widget.create.versions.first.whodunnit
|
assert_nil Widget.create.versions.first.whodunnit
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -38,7 +37,7 @@ class ModularSinatraTest < ActionDispatch::IntegrationTest
|
||||||
should "sets the `user_for_paper_trail` from the `current_user` method" do
|
should "sets the `user_for_paper_trail` from the `current_user` method" do
|
||||||
get '/test'
|
get '/test'
|
||||||
assert_equal 'Hello', last_response.body
|
assert_equal 'Hello', last_response.body
|
||||||
widget = Widget.first
|
widget = Widget.last
|
||||||
assert_not_nil widget
|
assert_not_nil widget
|
||||||
assert_equal 'foo', widget.name
|
assert_equal 'foo', widget.name
|
||||||
assert_equal 1, widget.versions.size
|
assert_equal 1, widget.versions.size
|
||||||
|
|
|
@ -30,7 +30,6 @@ class SinatraTest < ActionDispatch::IntegrationTest
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'baseline' do
|
test 'baseline' do
|
||||||
assert_nil Widget.first
|
|
||||||
assert_nil Widget.create.versions.first.whodunnit
|
assert_nil Widget.create.versions.first.whodunnit
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -39,7 +38,7 @@ class SinatraTest < ActionDispatch::IntegrationTest
|
||||||
should "sets the `user_for_paper_trail` from the `current_user` method" do
|
should "sets the `user_for_paper_trail` from the `current_user` method" do
|
||||||
get '/test'
|
get '/test'
|
||||||
assert_equal 'Hai', last_response.body
|
assert_equal 'Hai', last_response.body
|
||||||
widget = Widget.first
|
widget = Widget.last
|
||||||
assert_not_nil widget
|
assert_not_nil widget
|
||||||
assert_equal 'bar', widget.name
|
assert_equal 'bar', widget.name
|
||||||
assert_equal 1, widget.versions.size
|
assert_equal 1, widget.versions.size
|
||||||
|
|
|
@ -5,10 +5,15 @@ unless File.exists?(File.expand_path('../../test/dummy/config/database.yml', __F
|
||||||
warn "WARNING: No database.yml detected for the dummy app, please run `rake prepare` first"
|
warn "WARNING: No database.yml detected for the dummy app, please run `rake prepare` first"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def using_mysql?
|
||||||
|
@using_mysql ||= ActiveRecord::Base.connection_config[:adapter].to_sym == :mysql2
|
||||||
|
end
|
||||||
|
|
||||||
require File.expand_path("../dummy/config/environment.rb", __FILE__)
|
require File.expand_path("../dummy/config/environment.rb", __FILE__)
|
||||||
require "rails/test_help"
|
require "rails/test_help"
|
||||||
require 'shoulda'
|
require 'shoulda'
|
||||||
require 'ffaker'
|
require 'ffaker'
|
||||||
|
require 'database_cleaner' if using_mysql?
|
||||||
|
|
||||||
Rails.backtrace_cleaner.remove_silencers!
|
Rails.backtrace_cleaner.remove_silencers!
|
||||||
|
|
||||||
|
@ -18,9 +23,18 @@ ActiveRecord::Migrator.migrate File.expand_path("../dummy/db/migrate/", __FILE__
|
||||||
# Load support files
|
# Load support files
|
||||||
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
||||||
|
|
||||||
|
# DatabaseCleaner is apparently necessary for doing proper transactions within MySQL (ugh)
|
||||||
|
DatabaseCleaner.strategy = :truncation if using_mysql?
|
||||||
|
|
||||||
# global setup block resetting Thread.current
|
# global setup block resetting Thread.current
|
||||||
class ActiveSupport::TestCase
|
class ActiveSupport::TestCase
|
||||||
|
if using_mysql?
|
||||||
|
self.use_transactional_fixtures = false
|
||||||
|
setup { DatabaseCleaner.start }
|
||||||
|
end
|
||||||
|
|
||||||
teardown do
|
teardown do
|
||||||
|
DatabaseCleaner.clean if using_mysql?
|
||||||
Thread.current[:paper_trail] = nil
|
Thread.current[:paper_trail] = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue