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
1
vote
1 answer

Testing Rails on Ruby with rspec -- it takes too long because of TRUNCATE tables on loading rspec

I'm newbie in Ruby and Rails. I just started to work with both. The application I'm working on uses rspec to run the tests in Ruby on Rails and at each round all the database tables are truncated. Tailing log/test.log displays many lines with…
Caco
  • 1,601
  • 1
  • 26
  • 53
1
vote
1 answer

Rspec variable created in before block is deleted by the time feature spec reaches POSTed controller action

I have a truncation database cleaning strategy, so not sure why else this is happening. Basically just doing a single feature spec to test that an order gets created appropriately. require 'rails_helper' describe "create successfully", type:…
james
  • 3,989
  • 8
  • 47
  • 102
1
vote
1 answer

Loading a Database of Fixtures in Rails

I am building a Rails App (I am new to this, so forgive me if some of the wording is clumsy). I am trying to write tests (with RSpec) which draw and use data from the database, and I am having trouble writing the tests in a concise way. Some of the…
1
vote
1 answer

Lock wait timeout when running spec of a multithread code

I have the following class which changes all user names to John in many threads class Users::UpdateName def call User .unscoped .find_in_batches do |batch| update_batch(batch) end end def…
1
vote
5 answers

How to clean database between different features in cucumber rails?

I am having trouble in cleaning database between features. I tried using Before hooks but it runs for each scenario but I only need to clean database at the start of each feature and not between scenarios. Any suggestions would be helpful.
Srani
  • 11
  • 1
  • 3
1
vote
1 answer

Cannot create FactoryGirl's factory for model

I have this situation with legacy project. Suppose I have rails model: rails g model entity name:string In that model there is MAIN_ENTITY constant: class Entity < ActiveRecord::Base MAIN_ENTITY_ID = 1 MAIN_ENTITY =…
1
vote
1 answer

Rsepc - Database cleaner with Neo4j.rb 8.0.13

With Old version of neo4j & eno4j.rb everything was working good RSpec.configure do |config| config.before(:suite) do DatabaseCleaner.clean_with(:truncation) DatabaseCleaner[:neo4j, connection: { type: :server_db, path:…
Vishal G
  • 1,521
  • 11
  • 30
1
vote
1 answer

rails - Objects persisted by FactoryGirl are not available in Controller

I am writing tests for my controllers in admin namespace. Using RSpec (3.5.0), FactoryGirl (4.8.0), DatabaseCleaner (1.5.3) and Mongoid (6.0.3). The problem is that these test act strangely. When testing GET index request, objects produced by…
mityakoval
  • 888
  • 3
  • 12
  • 26
1
vote
1 answer

Not working database_cleaner with Rspec test

Hello guys I'm trying to set up database_cleaner, but I can't do that and i don't know what I'm missing. What i have up to now: users_controller_spec require 'rails_helper' describe UsersController, :type => :controller do #user =…
Kristis
  • 347
  • 5
  • 20
1
vote
1 answer

Rspec with database_cleaner on Sequel causes foreign key truncation error

I'm running RSpec tests with DatabaseCleaner on the following Sequel models class User < Sequel::Model one_to_many :memberships many_through_many :accounts, [[:memberships, :user_id, :account_id]] end class Account < Sequel::Model …
RedFred
  • 999
  • 9
  • 20
1
vote
1 answer

DatabaseCleaner doesn't seem to clean between suits

saviors. I'm having a trouble with cleaning database after each RSpec example. The thing is, that when I run rspec command, users_controller_spec.rb complains that there are more records than the example expects. Indeed the records are being…
Hiro
  • 199
  • 1
  • 10
1
vote
2 answers

FactoryGirl and DatabaseCleaner best practices for entire test suite using integration and unit tests

I have a Rails test suite that uses DatabaseCleaner, FactoryGirl, and Capybara-Webkit. All my tests pass on my machine when running the suite, including when running them all in parallel (parallel_rspec). When I push to CI (circleci) I always get a…
1
vote
1 answer

Ruby on rails integration test database cleaner prevent clean?

I want to load portion of the database. When I run integration tests. But with controller and model tests I want to skip it and clean between every test. So the problem is that it currently cleans the database in the integration tests but I want to…
user3384741
  • 1,261
  • 3
  • 16
  • 21
1
vote
1 answer

Flaky tests with DatabaseCleaner and transactions. How to debug?

I have a feature/integration spec that runs through an entire user flow. By the end of that user flow, a page in the app will display a few records from my Postgres database. When I run the test by itself, it passes. I can see it saving correctly…
1
vote
1 answer

How to populate and clean a database in ruby on rails with a rake task and database cleaner gem?

I have two rake tasks in one file. seed and populate. seed is creating a necessary data, and populate is populating sample data for my tests. In my tests I am manipulating a database(adding the new entry, removing it and etc.). I am using Database…
click
  • 447
  • 1
  • 7
  • 25