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)
|
|
|
|
valid = create(:online_notification, user_id: existing_user_id)
|
|
|
|
|
|
|
|
expect do
|
|
|
|
migrate
|
|
|
|
end.to change {
|
|
|
|
OnlineNotification.count
|
|
|
|
}.by(-1)
|
|
|
|
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
|
|
|
|
|
|
|
create(:recent_view, created_by_id: 1337)
|
|
|
|
valid = create(:recent_view, created_by_id: existing_user_id)
|
|
|
|
|
|
|
|
expect do
|
|
|
|
migrate
|
|
|
|
end.to change {
|
|
|
|
RecentView.count
|
|
|
|
}.by(-1)
|
|
|
|
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)
|
|
|
|
valid_ticket = create(:avatar, object_lookup_id: ObjectLookup.by_name('Ticket'), o_id: 1337)
|
|
|
|
valid_user = create(:avatar, object_lookup_id: ObjectLookup.by_name('User'), o_id: existing_user_id)
|
|
|
|
|
|
|
|
expect do
|
|
|
|
migrate
|
|
|
|
end.to change {
|
|
|
|
Avatar.count
|
|
|
|
}.by(-1)
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'adds OnlineNotification#user_id foreign key' do
|
|
|
|
adds_foreign_key(:online_notifications, column: :user_id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|