在postgres上测试规格时发出警告:没有正在进行的事务

时间:2012-09-18 17:00:27

标签: ruby-on-rails ruby-on-rails-3 unit-testing postgresql transactions

对于每个测试步骤发生2行:

WARNING:  there is already a transaction in progress
NOTICE:  there is no transaction in progress

三叉之后的Spork系列:

NOTICE:  there is no transaction in progress
NOTICE:  there is no transaction in progress
NOTICE:  there is no transaction in progress
WARNING:  there is already a transaction in progress
WARNING:  there is already a transaction in progress
WARNING:  there is already a transaction in progress

我不知道也许这很重要,只是警告过。的Gemfile:

group :test do
  gem 'rspec-rails'
  gem 'factory_girl_rails'
  gem 'spork-rails'
  gem 'capybara'
  gem 'database_cleaner'
end

所有定制,所以不需要开发组,无论如何它都没有帮助。 this is spec_helper。我发现,它是PostgreSQL功能,但我找不到如何修复它。 我将非常感谢你的帮助

2 个答案:

答案 0 :(得分:11)

在spec_helper.rb

config.use_transactional_examples = false #factoryGirl
config.use_transactional_fixtures = false #fixtures

config.before(:suite) do
    DatabaseCleaner.strategy = :transaction
    DatabaseCleaner.clean_with(:truncation)
  end

在database.yml

test:
  adapter: postgresql
  encoding: unicode
  host: localhost
  database: myapp_test
  username: my_username
  password:
  allow_concurrency: true
  pool: 5
  min_messages: error

即使你设置了min_messages选项,你仍然可以看到如下控制台输出:

WARNING:  there is already a transaction in progress

编辑文件

/opt/local/var/db/postgresql92/defaultdb/postgresql.conf

并设置以下内容:

client_min_messages = error

现在一切都应该顺利进行。

答案 1 :(得分:9)

spec_helper.rb中,我会尝试更改此

  config.before(:suite) do
    DatabaseCleaner.strategy = :transaction
    DatabaseCleaner.clean_with(:truncation)
  end

到这个

  config.before(:suite) do
    DatabaseCleaner.strategy = :truncation
    DatabaseCleaner.clean_with(:truncation)
  end