0

我知道我不应该对特定的 ID 进行编码,但有时它只会让生活变得更轻松。我正在使用带有 RSpec 和 Postgres 的 DatabaseCleaner,我想知道在使用事务策略时是否可以在规范之间重置 id?

这是我目前的spec_helper

RSpec.configure do |config|

  config.expect_with :rspec do |c|
    c.syntax = [:should, :expect]
  end

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

  config.before(:all) do
    DatabaseCleaner.start
  end

  config.after(:all) do
    DatabaseCleaner.clean
  end

  config.example_status_persistence_file_path = "./spec/failures.txt"
  config.use_transactional_fixtures = true    
  config.infer_base_class_for_anonymous_controllers = false    
  config.order = "random"

  config.include FactoryGirl::Syntax::Methods
  config.include RSpec::Rails::RequestExampleGroup
  config.include Requests::JsonHelpers
  config.include Requests::Extensions

end
4

1 回答 1

0

这是不可能的,因为自动增量是通过一种称为sequence的机制实现的,并且它们不会在事务中恢复:https ://stackoverflow.com/a/2095949/299774

于 2017-08-09T09:51:10.937 回答