Questions tagged [database-cleaner]

Database Cleaner is a set of strategies for cleaning your database in Ruby, primarily for testing purposes.

Database Cleaner is a set of strategies for cleaning your database in Ruby.

The original use case was to ensure a clean state during tests. Each strategy is a small amount of code but is code that is usually needed in any ruby app that is testing with a database.

ActiveRecord, DataMapper, Sequel, MongoMapper, Mongoid, CouchPotato, Ohm and Redis are supported.

https://github.com/DatabaseCleaner/database_cleaner

145 questions
3
votes
0 answers

Database_cleaner issue. Not working

My test_helper: require "simplecov" SimpleCov.start do add_filter "/factories/" end ENV['RAILS_ENV'] ||= 'test' require File.expand_path('../../config/environment', __FILE__) require 'rails/test_help' require 'capybara/rails' require…
Jwan622
  • 11,015
  • 21
  • 88
  • 181
3
votes
0 answers

How to keep test data for certain tables using rspec and database_cleaner in a rails app

I have a few features that require large amounts of data to be loaded into the test db before they're run. I have tagged these specs as "slow". What I'm trying to accomplish is that any feature spec tagged as "slow" will populate the db just once,…
croceldon
  • 4,511
  • 11
  • 57
  • 92
3
votes
2 answers

Any reason a TX in Rails should not have requires_new: true

Related to this question: custom transaction doesn't work with database_cleaner in rspec Is there any place one would not want to start a TX with requires_new? (which does nested TX) ModelObject.transaction(requires_new: true) If that's the case,…
justingordon
  • 12,553
  • 12
  • 72
  • 116
3
votes
1 answer

Using rspec, zeus and database_cleaner with two different active_record databases ends in undefined method `query_options' for nil:NilClass error

I'd like to use zeus (0.13.3) to preload my rails environment for an rails (3.2.11) app on ruby 2.0.0 and use database_cleaner (0.9.1) to clean the databases. This is working fine if as long as I use only one mysql database. In the app we have to…
Lars Schirrmeister
  • 2,215
  • 1
  • 22
  • 23
3
votes
1 answer

Rails 4 Database cleaner

I'm trying to complete some tests for a rails 4 app and I keep encountering an issue with database_cleaner. The issue is the database is not being cleaned and warnings keep raising: DEPRECATION WARNING: #increment_open_transactions is deprecated and…
David Hahn
  • 740
  • 9
  • 26
3
votes
0 answers

inserting binding.pry changes which rspec tests pass

tl;dr: I was trying to test that the correct items were added to an array. When I ran the test, it said that things were being added to the array indiscriminately. However, when I put a binding.pry in the first line of LessonPackage.available,…
Jeffrey Biles
  • 988
  • 7
  • 24
2
votes
1 answer

"Environment data not found in the schema." with database-cleaner when calling cucumber repeatedly on Rails 6

Note: This is NOT a dupe of Rails 5, Rspec: Environment data not found in the schema, though it is similar. The affected versions are different, and the solve doesn't work for me. My Rails setup is as follows: Rails 6.0.1 cucumber-rails…
Grant Birchmeier
  • 17,809
  • 11
  • 63
  • 98
2
votes
1 answer

Rails test fails requests did not finish in 60 seconds

After upgrading rails from 4.2 to 5.2 my test gets stuck on a request while it is working in development server I'm getting following failure on running test suit. Failures: 1) cold end overview shows cold end stats Failure/Error:…
2
votes
2 answers

How to run a Cucumber Background step once for all Scenarios under the same feature?

In Cucumber, is it possible to run a Background step for the whole feature? So it doesn't get repeated every scenario? I am running some tests on a search engine, and I need to pre-seed the search engine with test data. Since this data can be quite…
2
votes
1 answer

Request spec order dependent failure (wrong SQL created for devise user update on login)

We currently face a problem when a request spec fails (typo or other exception) it affects other request specs which actually should be unaffected. The problem is we use many gems so I tried to create a minimal reproduction app (without success,…
2
votes
1 answer

RSpec/Capybara/JS tests pass in isolation, but fail when run together

My issue seems to be very similar to: rspec test passes in isolation, but fails when run with other tests - but the accepted answer is something I'm already doing: I'm using avdi's database cleaner setup (and I've tried deletion instead of…
Greg Blass
  • 3,523
  • 29
  • 42
2
votes
1 answer

Database Cleaner unable to detect ORM in Rails application

The error below is displayed when $ rspec is executed: No known ORM was detected! Is ActiveRecord, DataMapper, Sequel, MongoMapper, Mongoid, Moped, or CouchPotato, Redis or Ohm loaded? (DatabaseCleaner::NoORMDetected) This is a snippet from the…
gnerkus
  • 11,357
  • 6
  • 47
  • 71
2
votes
1 answer

How to truncation all data in a schema different from the Public (database_cleaner)

In my project I use database multi-tenancy 'apartment' gem. config/initializers/apartment.rb Apartment.configure do |config| config.excluded_models = %w{ User Company } end To clean up the database it tests I use 'database_cleaner'…
2
votes
1 answer

MiniTest, Capybara, Fixture, Database_Cleaner not passing at second time

The following test passed first time (after rake db:test:prepare) but failed gave error on subsequent run. Capybara::ElementNotFound: Unable to find css "#sale_payment_btn" require "test_helper" DatabaseCleaner.strategy = :transaction class…
Tun
  • 1,345
  • 13
  • 34
2
votes
1 answer

DatabaseCleaner cleans test and development?

Why does this configuration seem to clean both my test and my development databases? It's pretty annoying to have to reseed development every time I run rspec. config.before(:suite) do DatabaseCleaner.strategy = :transaction …
t56k
  • 6,769
  • 9
  • 52
  • 115
1 2
3
9 10