database-cleaner

Is DatabaseCleaner still necessary with Rails system specs?

一个人想着一个人 提交于 2019-12-02 19:05:31
From all that I've read about Rails 5.1 new system specs my understanding was that Rails now handles database transactions internally. From Rspec's blog : "[previously] your tests and your code under test cannot share a database transaction, and so you cannot use RSpec's built in mechanism to roll back database changes, instead requiring a gem like database cleaner. With system tests, the Rails team has done the hard work to ensure that this is not the case, and so you can safely use RSpec's mechanism, without needing an extra gem." My experience is different: My Rspec feature tests were all

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

亡梦爱人 提交于 2019-12-02 05:30:07
问题 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 is a good idea to clear the data between tests. However, it can get slow and (as far as I can figure out) a bit tedious to generate multiple instances of the same object. There are some objects that are always the same in my database, or that I

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

梦想与她 提交于 2019-12-02 01:18:29
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 is a good idea to clear the data between tests. However, it can get slow and (as far as I can figure out) a bit tedious to generate multiple instances of the same object. There are some objects that are always the same in my database, or that I will always generate an identical copy of for testing. For example, my Package model, which defines the

Rails minitest, database cleaner how to turn use_transactional_fixtures = false

℡╲_俬逩灬. 提交于 2019-12-02 01:09:05
i would like to disable use_transactional_fixtures = false in ministest to catch after_commit callback. What and where should i set-up? You have a few options. One is to create a test without transactional fixtures and hope that the changes you make to the test database isn't going to break any other tests. class SomethingTest < ActiveSupport::TestCase self.use_transactional_fixtures = false def test_something_with_after_commit # do work here, which will change your test database end end Another option you have is to keep the transactional fixtures, but invoke the after_commit callback

How can I clean my database between erroneous rspec specs?

房东的猫 提交于 2019-12-01 02:18:05
问题 I have added the database_cleaner gem to my rails application in order to clean my database between specs. Here's my current configuration for database_cleaner, located in spec/spec_helper.rb : config.before(:suite) do DatabaseCleaner.strategy = :transaction DatabaseCleaner.clean_with(:truncation) DatabaseCleaner.start DatabaseCleaner.clean end config.before(:each) do DatabaseCleaner.clean end config.after(:each) do DatabaseCleaner.clean end config.after(:suite) do DatabaseCleaner.clean end

PG::ConnectionBad: connection is closed after upgrading rails from 4.2 to 5.2

不问归期 提交于 2019-11-30 20:25:14
I have upgraded my rails version of a project from 4.2 to 5.2.1 some of my tests are failed because of pg connection closed error on the full trace is is as following. Failure/Error: DatabaseCleaner[:active_record].clean_with(:truncation) ActiveRecord::StatementInvalid: PG::ConnectionBad: connection is closed: TRUNCATE TABLE "public"."alerts", "public"."article_attachments", "public"."article_check_specification_tolerances", "public"."article_machine_part_settings", "public"."articles", "public"."attachments", "public"."check_batches", "public"."check_groups", "public"."check_specification

Database Cleaner not working in minitest rails

怎甘沉沦 提交于 2019-11-30 20:12:54
My Minitest controller tests are working fine if I run them alone using rake minitest:controllers but when I run rake minitest:all then I get validation failed error. It is because email is already used in model tests. I used DatabaseCleaner to clean the database but unable to clean database. My code for database cleaner: require "database_cleaner" DatabaseCleaner.strategy = :transaction class MiniTest::Rails::ActionController::TestCase include Devise::TestHelpers def setup DatabaseCleaner.start end def teardown DatabaseCleaner.clean end Short answer: gem install "minitest-around" Long answer:

PG::ConnectionBad: connection is closed after upgrading rails from 4.2 to 5.2

Deadly 提交于 2019-11-30 04:52:47
问题 I have upgraded my rails version of a project from 4.2 to 5.2.1 some of my tests are failed because of pg connection closed error on the full trace is is as following. Failure/Error: DatabaseCleaner[:active_record].clean_with(:truncation) ActiveRecord::StatementInvalid: PG::ConnectionBad: connection is closed: TRUNCATE TABLE "public"."alerts", "public"."article_attachments", "public"."article_check_specification_tolerances", "public"."article_machine_part_settings", "public"."articles",

Database Cleaner not working in minitest rails

风格不统一 提交于 2019-11-30 04:50:58
问题 My Minitest controller tests are working fine if I run them alone using rake minitest:controllers but when I run rake minitest:all then I get validation failed error. It is because email is already used in model tests. I used DatabaseCleaner to clean the database but unable to clean database. My code for database cleaner: require "database_cleaner" DatabaseCleaner.strategy = :transaction class MiniTest::Rails::ActionController::TestCase include Devise::TestHelpers def setup DatabaseCleaner