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
2
votes
3 answers

How to disable database_cleaner for cucumber/rails?

I set up cucumber/rails for my rails project and populated the test database with data, to run tests against it. When I run "rake cucumber" the database gets truncated. I tried to set DatabaseCleaner.strategy to :transaction and nil, but it still…
2
votes
0 answers

Rspec Feature Spec using Factory Girl Associations

I am trying to test a feature spec for a user who needs to edit their account model settings. I am new to testing so not sure if my issue is due to how I am setting up my Factory girl associations or if a problem with my database cleaner…
Steve
  • 2,596
  • 26
  • 33
2
votes
1 answer

How should I handle a Rails model record that my controller and views rely on?

I have a Rails application that deals with sports teams. There's a model, Club, that contains all the teams and they relate to Matches, etc. The application is centered around one of these clubs, and relies on the existence of that record. I've got…
Ben Saufley
  • 3,259
  • 5
  • 27
  • 42
2
votes
1 answer

RSpec & Database Cleaner - Keep certain objects permanently in the test database

I have (belatedly) started testing my Rails app (a shopping website) with RSpec/capybara, using database cleaner to clear the database and Factory Girl to generate new objects for every test (like most people do). This works fine, and I do think it…
Marco Prins
  • 7,189
  • 11
  • 41
  • 76
2
votes
2 answers

database cleaning for postgres schemas

I have gem devise and gem apartment which I'm using to create separate schemas for each devise's user account. Apartment's doc and advice in that issue suggest to use Rack middleware to switch between tenants. In that case it's not possible (as far…
pawel7318
  • 3,383
  • 2
  • 28
  • 44
2
votes
1 answer

What is the default value of use_transactional_fixtures in rspec?

I am asking this because in the articles I have read so far, concerning rspec and the database_cleaner gem I see the line config.use_transactional_fixtures = false. If I use the database_cleaner gem couldn't I just delete this line?
Alexander Popov
  • 23,073
  • 19
  • 91
  • 130
2
votes
1 answer

typeahead.js test failing on Rails 4 with Cucumber and Capybara-Webkit

I have the following Cucumber feature testing an input form using typeahead.js: @javascript Scenario: Creating a battery using typeahead When I create a new battery using typeahead Then I should be on the show battery page And I should see the…
2
votes
1 answer

Rails minitest, database cleaner how to turn use_transactional_fixtures = false

i would like to disable use_transactional_fixtures = false in ministest to catch after_commit callback. What and where should i set-up?
Jakub Kuchar
  • 1,665
  • 2
  • 23
  • 39
2
votes
2 answers

DB Cleaner not cleaning database after each test after switching from sqlite to PostgreSQL

This config worked fine when I was using sqlite: config.before(:suite) do DatabaseCleaner.strategy = :truncation end config.before(:each) do controller.stub(:should_navigate_user?).and_return(false) rescue "" DatabaseCleaner.start …
Ecnalyr
  • 5,792
  • 5
  • 43
  • 89
2
votes
0 answers

DatabaseCleaner strategy transaction is not working

In My env.rb Before do DatabaseCleaner.strategy = :transaction end Also created a hook in my shared_steps.rb Before('@database_cleaner_before') do DatabaseCleaner.start end After('@database_cleaner_after') do …
RKP
  • 174
  • 2
  • 9
2
votes
1 answer

When using cucumber and databasecleaner can I keep a single entry in a table?

I am currently using cucumber and databasecleaner to test my application. And currently in my env.rb i have the setup of the cleaner as: DatabaseCleaner.strategy = :truncation, {:except => %w[TABLE]} After do DatabaseCleaner.clean end This way I…
Martin Larsson
  • 1,008
  • 1
  • 8
  • 25
1
vote
1 answer

rspec failing - Bundle.require(*Rails.groups)

I have been running Rspec recently but realised it was completely deleting my development database. I believe the cause of this is the failure of setting 'RAILS_ENV' at the beginning of 'rails_helper.rb' and therefore database cleaner is clearing…
1
vote
1 answer

Rspec Capybara Failure/Error: DatabaseCleaner.clean

I am using rails 6.1.4 (Ubuntu 20.04) and am running tests with rspec, factorybot, and capybara. I also got database_cleaner where I'm using :truncation to start each test block with a clean slate (yes, not the fastest way but the most rigorous…
1
vote
0 answers

ActionView::Template::Error: while running rspec in groups or file

I am working on view specs using RSpec. When I use render in it block. Then my first test case is passed but 2nd one is saying the error. Failure/Error: render ActionView::Template::Error: undefined method…
1
vote
1 answer

How to clean test database, but not entirely, only the data generated by the tests with RSPEC and Capybara

I have an application in rails 5.2.6 to which I am doing the test with RSPEC and Capybara and for it I have a test database with data that I use to perform the tests and I am running some tests that generate data that are stored in this database.…