Fix ActiveSupport::TestCase tests for MySQL
This commit is contained in:
parent
0b05a58763
commit
4dba95a082
|
@ -13,6 +13,7 @@
|
|||
become the live instance.
|
||||
- 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`).
|
||||
- Gem is now tested against `MySQL` and `PostgreSQL` in addition to `SQLite`.
|
||||
|
||||
## 3.0.1
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@ Gem::Specification.new do |s|
|
|||
s.add_development_dependency 'rack-test', '>= 0.6'
|
||||
s.add_development_dependency 'rspec-rails', '~> 2.14'
|
||||
s.add_development_dependency 'generator_spec'
|
||||
s.add_development_dependency 'database_cleaner', '~> 1.2'
|
||||
|
||||
# JRuby support for the test ENV
|
||||
unless defined?(JRUBY_VERSION)
|
||||
|
|
|
@ -5,7 +5,7 @@ class SetUpTestTables < ActiveRecord::Migration
|
|||
t.text :a_text
|
||||
t.integer :an_integer
|
||||
t.float :a_float
|
||||
t.decimal :a_decimal
|
||||
t.decimal :a_decimal, :precision => 6, :scale => 4
|
||||
t.datetime :a_datetime
|
||||
t.time :a_time
|
||||
t.date :a_date
|
||||
|
|
|
@ -71,6 +71,7 @@ ActiveRecord::Schema.define(:version => 20110208155312) do
|
|||
t.integer "article_id"
|
||||
t.string "ip"
|
||||
t.string "user_agent"
|
||||
t.text :object_changes
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
test 'baseline' do
|
||||
assert_nil Widget.first
|
||||
assert_nil Widget.create.versions.first.whodunnit
|
||||
end
|
||||
|
||||
|
@ -38,7 +37,7 @@ class ModularSinatraTest < ActionDispatch::IntegrationTest
|
|||
should "sets the `user_for_paper_trail` from the `current_user` method" do
|
||||
get '/test'
|
||||
assert_equal 'Hello', last_response.body
|
||||
widget = Widget.first
|
||||
widget = Widget.last
|
||||
assert_not_nil widget
|
||||
assert_equal 'foo', widget.name
|
||||
assert_equal 1, widget.versions.size
|
||||
|
|
|
@ -30,7 +30,6 @@ class SinatraTest < ActionDispatch::IntegrationTest
|
|||
end
|
||||
|
||||
test 'baseline' do
|
||||
assert_nil Widget.first
|
||||
assert_nil Widget.create.versions.first.whodunnit
|
||||
end
|
||||
|
||||
|
@ -39,7 +38,7 @@ class SinatraTest < ActionDispatch::IntegrationTest
|
|||
should "sets the `user_for_paper_trail` from the `current_user` method" do
|
||||
get '/test'
|
||||
assert_equal 'Hai', last_response.body
|
||||
widget = Widget.first
|
||||
widget = Widget.last
|
||||
assert_not_nil widget
|
||||
assert_equal 'bar', widget.name
|
||||
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"
|
||||
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 "rails/test_help"
|
||||
require 'shoulda'
|
||||
require 'ffaker'
|
||||
require 'database_cleaner' if using_mysql?
|
||||
|
||||
Rails.backtrace_cleaner.remove_silencers!
|
||||
|
||||
|
@ -18,9 +23,18 @@ ActiveRecord::Migrator.migrate File.expand_path("../dummy/db/migrate/", __FILE__
|
|||
# Load support files
|
||||
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
|
||||
class ActiveSupport::TestCase
|
||||
if using_mysql?
|
||||
self.use_transactional_fixtures = false
|
||||
setup { DatabaseCleaner.start }
|
||||
end
|
||||
|
||||
teardown do
|
||||
DatabaseCleaner.clean if using_mysql?
|
||||
Thread.current[:paper_trail] = nil
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue