2021-06-01 12:20:20 +00:00
|
|
|
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
|
|
|
|
2018-05-08 10:10:19 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe Issue1977RemoveInvalidUserForeignKeys, type: :db_migration do
|
|
|
|
|
|
|
|
context 'no online_notifications foreign key' do
|
|
|
|
|
|
|
|
let(:existing_user_id) { User.first.id }
|
|
|
|
|
|
|
|
context 'invalid User foreign key columns' do
|
|
|
|
|
2018-10-18 12:20:51 +00:00
|
|
|
it 'cleans up OnlineNotification#user_id', db_strategy: :reset do
|
2018-12-01 12:02:06 +00:00
|
|
|
without_foreign_key(:online_notifications, column: :user_id)
|
2018-05-08 10:10:19 +00:00
|
|
|
|
|
|
|
create(:online_notification, user_id: 1337)
|
2019-06-28 11:38:49 +00:00
|
|
|
create(:online_notification, user_id: existing_user_id)
|
2018-05-08 10:10:19 +00:00
|
|
|
|
|
|
|
expect do
|
|
|
|
migrate
|
2019-04-15 01:41:17 +00:00
|
|
|
end.to change(OnlineNotification, :count).by(-1)
|
2018-05-08 10:10:19 +00:00
|
|
|
end
|
|
|
|
|
2018-10-18 12:20:51 +00:00
|
|
|
it 'cleans up RecentView#created_by_id', db_strategy: :reset do
|
2018-12-01 12:02:06 +00:00
|
|
|
without_foreign_key(:online_notifications, column: :user_id)
|
|
|
|
without_foreign_key(:recent_views, column: :created_by_id)
|
2018-05-08 10:10:19 +00:00
|
|
|
|
2020-09-08 15:06:23 +00:00
|
|
|
record = build(:recent_view, created_by_id: 1337)
|
|
|
|
record.save(validate: false)
|
2019-06-28 11:38:49 +00:00
|
|
|
create(:recent_view, created_by_id: existing_user_id)
|
2018-05-08 10:10:19 +00:00
|
|
|
|
|
|
|
expect do
|
|
|
|
migrate
|
2019-04-15 01:41:17 +00:00
|
|
|
end.to change(RecentView, :count).by(-1)
|
2018-05-08 10:10:19 +00:00
|
|
|
end
|
|
|
|
|
2018-10-18 12:20:51 +00:00
|
|
|
it 'cleans up Avatar#o_id', db_strategy: :reset do
|
2018-12-01 12:02:06 +00:00
|
|
|
without_foreign_key(:online_notifications, column: :user_id)
|
2018-05-08 10:10:19 +00:00
|
|
|
|
|
|
|
create(:avatar, object_lookup_id: ObjectLookup.by_name('User'), o_id: 1337)
|
2019-06-28 11:38:49 +00:00
|
|
|
create(:avatar, object_lookup_id: ObjectLookup.by_name('Ticket'), o_id: 1337)
|
|
|
|
create(:avatar, object_lookup_id: ObjectLookup.by_name('User'), o_id: existing_user_id)
|
2018-05-08 10:10:19 +00:00
|
|
|
|
|
|
|
expect do
|
|
|
|
migrate
|
2019-04-15 01:41:17 +00:00
|
|
|
end.to change(Avatar, :count).by(-1)
|
2018-05-08 10:10:19 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'adds OnlineNotification#user_id foreign key' do
|
|
|
|
adds_foreign_key(:online_notifications, column: :user_id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|