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
6
votes
6 answers

database_cleaner is wiping my development database

I have database-cleaner configured for my rails 4 application, Each time I run the test, I discovered that my database gets wiped out in both the test and development environment. My configurations are in rails_helper as follow: ENV["RAILS_ENV"] ||=…
x6iae
  • 4,074
  • 3
  • 29
  • 50
6
votes
2 answers

Rspec extremely slow

My rspec tests seem to run extremely slow even with guard & spork. Finished in 5.36 seconds 13 examples, 2 failures I understand that there are several things I can do to optimize my tests & reduce interaction with the database, but I strongly…
6
votes
1 answer

Rails Rspec Capybara and DatabaseCleaner - using truncation only on feature tests

I saw this cool method for only using Database cleaners :truncation for capybara test using :js => true In spec_helper.rb: config.before(:each) do DatabaseCleaner.strategy = if example.metadata[:js] :truncation else :transaction end …
Squadrons
  • 2,467
  • 5
  • 25
  • 36
5
votes
0 answers

Database_Cleaner with AR-Octopus not cleaning records

We have a project that is using the AR-Octopus gem using sharded databases. The problem we are running into is that the gem 'database_cleaner' is not cleaning records when using this setup, as we are consistently having leftover records in our test…
William Holt
  • 549
  • 4
  • 14
5
votes
1 answer

Database Cleaner: Clean vs truncation

What is the difference between the following? DatabaseCleaner.clean_with(:truncation) DatabaseCleaner.clean What i'm trying to figure out is what is the best way to clean up a before(:all) hook in my tests (performance wise) using database…
Jshoe523
  • 3,851
  • 2
  • 18
  • 21
4
votes
2 answers

Rails clean database between tests not work

I'm new in rails. In my project i use rspec + capybara + poltergeist + selenium + database_cleaner. Source code github link I have postgresql 9.5.5, ubuntu 16.04 LTS. When run test rspec spec/controllers # everything work fine When run rspec…
4
votes
1 answer

rspec with mongoid, devise, database_cleaner : ActiveRecord::ConnectionNotEstablished error

i'm trying to use rspec with mongoid, devise, database_cleaner and i have this error Failure/Error: Unable to find matching line from backtrace ActiveRecord::ConnectionNotEstablished: ActiveRecord::ConnectionNotEstablished #…
Adham El-Deeb
  • 335
  • 3
  • 16
4
votes
1 answer

Sudden inexplicable active record connection timeouts while testing with RSPEC

This is an area I know almost nothing about, so apologies in advance. I have a suite of over 800 rspec tests. Suddenly and inexplicably when running the whole set or just particular test files, after just a few of these, (say 20 or so, although it's…
4
votes
0 answers

How do you ensure data created by ActiveRecord Fixtures is rolled back when database_cleaner controls the transaction?

I use ActiveRecord Fixtures to define preset data for tests. I use the database_cleaner gem to reset the database between tests. I follow the approach described by Avdi Grimm to use truncation for javascript tests, but transactions for…
Joshua Flanagan
  • 8,527
  • 2
  • 31
  • 40
4
votes
2 answers

rspec DatabaseCleaner skip clean for example group metadata tag

How can I tag an example group so that the database isn't cleaned between each example, but is cleaned before and after the whole group? And untagged specs should clean the database between each example. I would like to write: describe…
rigyt
  • 2,219
  • 3
  • 28
  • 40
4
votes
1 answer

Configure Turnip and Database_cleaner

I'm using Turnip and Ruby on Rails. I have scenarios with and without using javascript. I want to use the transaction DatabaseCleaner strategy for the non-javascript scenarios and the truncation strategy for scenarios marked by @javascript,…
petRUShka
  • 9,812
  • 12
  • 61
  • 95
3
votes
2 answers

While running specs entries are getting delete from schema migrations table

When upgraded to rails 6.1 my specs are failing due to entries are getting delete from schema_migrations table ActiveRecord::SchemaMigration.count (2.1ms) SELECT COUNT(*) FROM "SCHEMA_MIGRATIONS" =>…
Aniket Tiwari
  • 3,561
  • 4
  • 21
  • 61
3
votes
2 answers

DatabaseCleaner don't reset autoincrement index in rails test unit

test/test_helper.rb : ENV["RAILS_ENV"] ||= "test" require File.expand_path('../../config/environment', __FILE__) require 'rails/test_help' require 'database_cleaner' DatabaseCleaner.strategy = :transaction DatabaseCleaner.clean_with(:truncation,…
Matrix
  • 3,458
  • 6
  • 40
  • 76
3
votes
1 answer

Can't clear Mongo DB while running test

I am using rails, mongoid, spork, rspec. While running tests via rspec I see increasing number of records in my database. Neither purge! nor database_cleaner didn't help. My test is: describe MyConvertor do context 'working with my model' …
Nick Roz
  • 3,918
  • 2
  • 36
  • 57
3
votes
0 answers

Parallel test execution with rspec and database cleaning

I have upgraded rspec to version 3.2 and now I get a lot of database errors (Mysql2::Error: Duplicate entry) when I run the specs. The specs seems to be running in parallel. I am using the database cleaner gem (1.4.1), and it was working before the…
Daniel Cukier
  • 11,502
  • 15
  • 68
  • 123
1
2
3
9 10