Database cleanup clears all tables even when used: except option

I have a problem with a database cleaner in a rails project. I use the sqlite3 database in my test environment, and it has several tables containing reference data filled in by the db: test: prepare task, which do not need to be wiped between tests.

I have a number of cucumber scripts with @javascript tags using the webdriver driver, and some without this tag.

In my env.rb file, I configured the database cleaner to use the truncation strategy with the except option:

DatabaseCleaner.strategy = :truncation, {:except => %w[ignore me]} 

DatabaseCleaner.clean is called after each script and works as expected in scripts with a javascript tag.

However, for scripts other than javascript, it truncates the entire database, including the tables listed in the: except array. I also tried calling DatabaseCleaner.clean_with , which didn't work either.

+6
source share
2 answers

I encountered a similar error, except that I saw a problem when running @javascript scripts.

After long searches, reading and pulling hair, I came across this post

I looked in the hook_cleaner hook file mentioned there ( cucumber-rails-0.4.0 / lib / cucumber / rails / hooks / database_cleaner.rb ), and lo-and-behold sets the cleaner database strategy for: truncate without exception before each script with the following tags: @ no-txn, @selenium, @culerity, @celerity, @javascript.

 Before('@no-txn,@selenium,@culerity,@celerity,@javascript') do DatabaseCleaner.strategy = :truncation end 

I copied and pasted the previous statement into my env.rb cucumber file and added my: except statement to it. This seems to fix the problem.

Are you sure these are not your @javascript scripts that are causing the problem?

+7
source

I had a similar problem with PostgreSQL and database_cleaner (1.4.0). This code did not work and truncated everything, despite the option: except:

 DatabaseCleaner.clean_with(:truncation, :except => %w[countries] ) 

I found out that you need to provide the full name of the table in order for it to work with PostgreSQL. The following code worked as expected:

 DatabaseCleaner.clean_with(:truncation, :except => %w[public.countries] ) 

UPDATE: this seems to be fixed in database version 1.4.1 and it works there as expected

+8
source

Source: https://habr.com/ru/post/890036/


All Articles