Switched over to DB reset strategy in tests and removed DatabaseCleaner because it can't guarantee a clean DB state for all test scenarios.
This commit is contained in:
parent
7d9c087a84
commit
b538b05209
5 changed files with 24 additions and 14 deletions
4
Gemfile
4
Gemfile
|
@ -176,10 +176,6 @@ group :development, :test do
|
||||||
# record and replay TCP/HTTP transactions
|
# record and replay TCP/HTTP transactions
|
||||||
gem 'tcr'
|
gem 'tcr'
|
||||||
gem 'vcr'
|
gem 'vcr'
|
||||||
|
|
||||||
# database cleanup when transactions are not possible
|
|
||||||
# and DB initialization before running RSpec suite
|
|
||||||
gem 'database_cleaner'
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Want to extend Zammad with additional gems?
|
# Want to extend Zammad with additional gems?
|
||||||
|
|
|
@ -113,7 +113,6 @@ GEM
|
||||||
crass (1.0.4)
|
crass (1.0.4)
|
||||||
daemons (1.2.5)
|
daemons (1.2.5)
|
||||||
dalli (2.7.6)
|
dalli (2.7.6)
|
||||||
database_cleaner (1.7.0)
|
|
||||||
debug_inspector (0.0.3)
|
debug_inspector (0.0.3)
|
||||||
delayed_job (4.1.3)
|
delayed_job (4.1.3)
|
||||||
activesupport (>= 3.0, < 5.2)
|
activesupport (>= 3.0, < 5.2)
|
||||||
|
@ -518,7 +517,6 @@ DEPENDENCIES
|
||||||
coveralls
|
coveralls
|
||||||
daemons
|
daemons
|
||||||
dalli
|
dalli
|
||||||
database_cleaner
|
|
||||||
delayed_job_active_record
|
delayed_job_active_record
|
||||||
diffy
|
diffy
|
||||||
doorkeeper
|
doorkeeper
|
||||||
|
|
|
@ -2,10 +2,25 @@ namespace :zammad do
|
||||||
|
|
||||||
namespace :db do
|
namespace :db do
|
||||||
|
|
||||||
desc 'Truncates and reseeds the database, clears the Cache and reloads the Settings'
|
desc 'Drops, recreates and seeds the database, clears the Cache and reloads the Settings'
|
||||||
task reset: :environment do
|
task reset: :environment do
|
||||||
DatabaseCleaner.clean_with(:truncation)
|
|
||||||
Rails.application.load_seed
|
# we loop over each dependent task to be able to
|
||||||
|
# execute them and their prerequisites multiple times (in tests)
|
||||||
|
# there is no way in rake to achive that
|
||||||
|
%w[db:drop:_unsafe db:create db:schema:load db:seed].each do |task|
|
||||||
|
|
||||||
|
begin
|
||||||
|
$stdout = StringIO.new if task == 'db:schema:load'.freeze
|
||||||
|
|
||||||
|
Rake::Task[task].reenable
|
||||||
|
Rake::Task[task].invoke
|
||||||
|
ensure
|
||||||
|
$stdout = STDOUT
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
ActiveRecord::Base.connection.reconnect!
|
||||||
Cache.clear
|
Cache.clear
|
||||||
Setting.reload
|
Setting.reload
|
||||||
end
|
end
|
||||||
|
|
|
@ -8,7 +8,7 @@ RSpec.describe Issue1977RemoveInvalidUserForeignKeys, type: :db_migration do
|
||||||
|
|
||||||
context 'invalid User foreign key columns' do
|
context 'invalid User foreign key columns' do
|
||||||
|
|
||||||
it 'cleans up OnlineNotification#user_id', db_strategy: :truncation do
|
it 'cleans up OnlineNotification#user_id', db_strategy: :reset do
|
||||||
witout_foreign_key(:online_notifications, column: :user_id)
|
witout_foreign_key(:online_notifications, column: :user_id)
|
||||||
|
|
||||||
create(:online_notification, user_id: 1337)
|
create(:online_notification, user_id: 1337)
|
||||||
|
@ -21,7 +21,7 @@ RSpec.describe Issue1977RemoveInvalidUserForeignKeys, type: :db_migration do
|
||||||
}.by(-1)
|
}.by(-1)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'cleans up RecentView#created_by_id', db_strategy: :truncation do
|
it 'cleans up RecentView#created_by_id', db_strategy: :reset do
|
||||||
witout_foreign_key(:online_notifications, column: :user_id)
|
witout_foreign_key(:online_notifications, column: :user_id)
|
||||||
witout_foreign_key(:recent_views, column: :created_by_id)
|
witout_foreign_key(:recent_views, column: :created_by_id)
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ RSpec.describe Issue1977RemoveInvalidUserForeignKeys, type: :db_migration do
|
||||||
}.by(-1)
|
}.by(-1)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'cleans up Avatar#o_id', db_strategy: :truncation do
|
it 'cleans up Avatar#o_id', db_strategy: :reset do
|
||||||
witout_foreign_key(:online_notifications, column: :user_id)
|
witout_foreign_key(:online_notifications, column: :user_id)
|
||||||
|
|
||||||
create(:avatar, object_lookup_id: ObjectLookup.by_name('User'), o_id: 1337)
|
create(:avatar, object_lookup_id: ObjectLookup.by_name('User'), o_id: 1337)
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
RSpec.configure do |config|
|
RSpec.configure do |config|
|
||||||
|
|
||||||
config.around(:each, db_strategy: :truncation) do |example|
|
config.around(:each, db_strategy: :reset) do |example|
|
||||||
self.use_transactional_tests = false
|
self.use_transactional_tests = false
|
||||||
example.run
|
example.run
|
||||||
Rake::Task['zammad:db:reset'].execute
|
Rake::Task['zammad:db:reset'].reenable
|
||||||
|
Rake::Task['zammad:db:reset'].invoke
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue