From e006684c83fabf904a4b4e3d8ce10d257aaa5671 Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Fri, 28 Sep 2018 17:05:39 +0200 Subject: [PATCH] Added RSpec support file to initialize database into clean state before running suite. --- Gemfile | 4 ++++ Gemfile.lock | 2 ++ db/seeds/settings.rb | 2 +- spec/support/reset_system_before_suite.rb | 8 ++++++++ 4 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 spec/support/reset_system_before_suite.rb diff --git a/Gemfile b/Gemfile index ac050f735..630b9f01f 100644 --- a/Gemfile +++ b/Gemfile @@ -173,6 +173,10 @@ group :development, :test do # record and replay TCP/HTTP transactions gem 'tcr' gem 'vcr' + + # database cleanup when transactions are not possible + # and DB initialization before running RSpec suite + gem 'database_cleaner' end # Want to extend Zammad with additional gems? diff --git a/Gemfile.lock b/Gemfile.lock index 1132a65f3..ae7e92cf7 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -113,6 +113,7 @@ GEM crass (1.0.4) daemons (1.2.5) dalli (2.7.6) + database_cleaner (1.7.0) debug_inspector (0.0.3) delayed_job (4.1.3) activesupport (>= 3.0, < 5.2) @@ -511,6 +512,7 @@ DEPENDENCIES coveralls daemons dalli + database_cleaner delayed_job_active_record diffy doorkeeper diff --git a/db/seeds/settings.rb b/db/seeds/settings.rb index 19f3d97ac..094967f5f 100644 --- a/db/seeds/settings.rb +++ b/db/seeds/settings.rb @@ -2694,7 +2694,7 @@ Setting.create_if_not_exists( area: 'Models::Base', description: 'Defines the searchable models.', options: {}, - state: [], + state: Models.searchable.map(&:to_s), preferences: { authentication: true, }, diff --git a/spec/support/reset_system_before_suite.rb b/spec/support/reset_system_before_suite.rb new file mode 100644 index 000000000..ea15a8664 --- /dev/null +++ b/spec/support/reset_system_before_suite.rb @@ -0,0 +1,8 @@ +RSpec.configure do |config| + config.before(:suite) do + DatabaseCleaner.clean_with(:truncation) + Rails.application.load_seed + Cache.clear + Setting.reload + end +end