From f774c46db3ea0d320f7022d08251be92fba72967 Mon Sep 17 00:00:00 2001 From: cmrd Senya Date: Fri, 26 Apr 2019 19:45:55 +0300 Subject: [PATCH] AccountMigration specs: move one-time shared contexts in place --- spec/integration/account_migration_spec.rb | 164 +++++++++++++++++++- spec/shared_behaviors/account_migration.rb | 169 --------------------- 2 files changed, 162 insertions(+), 171 deletions(-) delete mode 100644 spec/shared_behaviors/account_migration.rb diff --git a/spec/integration/account_migration_spec.rb b/spec/integration/account_migration_spec.rb index 8064a0a26..361741b22 100644 --- a/spec/integration/account_migration_spec.rb +++ b/spec/integration/account_migration_spec.rb @@ -43,7 +43,103 @@ shared_examples_for "old person doesn't have any reference left" do end shared_examples_for "every migration scenario" do - it_behaves_like "it updates person references" + it "updates contact reference" do + contact = FactoryGirl.create(:contact, person: old_person) + run_migration + expect(contact.reload.person).to eq(new_person) + end + + it "updates status message reference" do + post = FactoryGirl.create(:status_message, author: old_person) + run_migration + expect(post.reload.author).to eq(new_person) + end + + it "updates reshare reference" do + reshare = FactoryGirl.create(:reshare, author: old_person) + run_migration + expect(reshare.reload.author).to eq(new_person) + end + + it "updates photo reference" do + photo = FactoryGirl.create(:photo, author: old_person) + run_migration + expect(photo.reload.author).to eq(new_person) + end + + it "updates comment reference" do + comment = FactoryGirl.create(:comment, author: old_person) + run_migration + expect(comment.reload.author).to eq(new_person) + end + + it "updates like reference" do + like = FactoryGirl.create(:like, author: old_person) + run_migration + expect(like.reload.author).to eq(new_person) + end + + it "updates participations reference" do + participation = FactoryGirl.create(:participation, author: old_person) + run_migration + expect(participation.reload.author).to eq(new_person) + end + + it "updates poll participations reference" do + poll_participation = FactoryGirl.create(:poll_participation, author: old_person) + run_migration + expect(poll_participation.reload.author).to eq(new_person) + end + + it "updates conversation visibilities reference" do + conversation = FactoryGirl.build(:conversation) + FactoryGirl.create(:contact, user: old_user, person: conversation.author) if old_person.local? + conversation.participants << old_person + conversation.save! + visibility = ConversationVisibility.find_by(person_id: old_person.id) + run_migration + expect(visibility.reload.person).to eq(new_person) + end + + it "updates message reference" do + message = FactoryGirl.create(:message, author: old_person) + run_migration + expect(message.reload.author).to eq(new_person) + end + + it "updates conversation reference" do + conversation = FactoryGirl.create(:conversation, author: old_person) + run_migration + expect(conversation.reload.author).to eq(new_person) + end + + it "updates block references" do + user = FactoryGirl.create(:user) + block = user.blocks.create(person: old_person) + run_migration + expect(block.reload.person).to eq(new_person) + end + + it "updates role reference" do + role = FactoryGirl.create(:role, person: old_person) + run_migration + expect(role.reload.person).to eq(new_person) + end + + it "updates notification actors" do + notification = FactoryGirl.build(:notification) + notification.actors << old_person + notification.save! + actor = notification.notification_actors.find_by(person_id: old_person.id) + run_migration + expect(actor.reload.person).to eq(new_person) + end + + it "updates mention reference" do + mention = FactoryGirl.create(:mention, person: old_person) + run_migration + expect(mention.reload.person).to eq(new_person) + end it_behaves_like "old person account is closed and profile is cleared" @@ -208,7 +304,71 @@ describe "account migration" do expect(old_user.reload).to be_a_clear_account end - it_behaves_like "it updates user references" + it "updates invited users reference" do + invited_user = FactoryGirl.create(:user, invited_by: old_user) + run_migration + expect(invited_user.reload.invited_by).to eq(new_user) + end + + it "updates aspect reference" do + aspect = FactoryGirl.create(:aspect, user: old_user, name: r_str) + run_migration + expect(aspect.reload.user).to eq(new_user) + end + + it "updates contact reference" do + contact = FactoryGirl.create(:contact, user: old_user) + run_migration + expect(contact.reload.user).to eq(new_user) + end + + it "updates services reference" do + service = FactoryGirl.create(:service, user: old_user) + run_migration + expect(service.reload.user).to eq(new_user) + end + + it "updates user preference references" do + pref = UserPreference.create!(user: old_user, email_type: "also_commented") + run_migration + expect(pref.reload.user).to eq(new_user) + end + + it "updates tag following references" do + tag_following = FactoryGirl.create(:tag_following, user: old_user) + run_migration + expect(tag_following.reload.user).to eq(new_user) + end + + it "updates blocks refrences" do + block = FactoryGirl.create(:block, user: old_user) + run_migration + expect(block.reload.user).to eq(new_user) + end + + it "updates notification refrences" do + notification = FactoryGirl.create(:notification, recipient: old_user) + run_migration + expect(notification.reload.recipient).to eq(new_user) + end + + it "updates report refrences" do + report = FactoryGirl.create(:report, user: old_user) + run_migration + expect(report.reload.user).to eq(new_user) + end + + it "updates authorization refrences" do + authorization = FactoryGirl.create(:auth_with_read, user: old_user) + run_migration + expect(authorization.reload.user).to eq(new_user) + end + + it "updates share visibility refrences" do + share_visibility = FactoryGirl.create(:share_visibility, user: old_user) + run_migration + expect(share_visibility.reload.user).to eq(new_user) + end end end end diff --git a/spec/shared_behaviors/account_migration.rb b/spec/shared_behaviors/account_migration.rb deleted file mode 100644 index bcfa964ef..000000000 --- a/spec/shared_behaviors/account_migration.rb +++ /dev/null @@ -1,169 +0,0 @@ -# frozen_string_literal: true - -shared_examples_for "it updates person references" do - it "updates contact reference" do - contact = FactoryGirl.create(:contact, person: old_person) - run_migration - expect(contact.reload.person).to eq(new_person) - end - - it "updates status message reference" do - post = FactoryGirl.create(:status_message, author: old_person) - run_migration - expect(post.reload.author).to eq(new_person) - end - - it "updates reshare reference" do - reshare = FactoryGirl.create(:reshare, author: old_person) - run_migration - expect(reshare.reload.author).to eq(new_person) - end - - it "updates photo reference" do - photo = FactoryGirl.create(:photo, author: old_person) - run_migration - expect(photo.reload.author).to eq(new_person) - end - - it "updates comment reference" do - comment = FactoryGirl.create(:comment, author: old_person) - run_migration - expect(comment.reload.author).to eq(new_person) - end - - it "updates like reference" do - like = FactoryGirl.create(:like, author: old_person) - run_migration - expect(like.reload.author).to eq(new_person) - end - - it "updates participations reference" do - participation = FactoryGirl.create(:participation, author: old_person) - run_migration - expect(participation.reload.author).to eq(new_person) - end - - it "updates poll participations reference" do - poll_participation = FactoryGirl.create(:poll_participation, author: old_person) - run_migration - expect(poll_participation.reload.author).to eq(new_person) - end - - it "updates conversation visibilities reference" do - conversation = FactoryGirl.build(:conversation) - FactoryGirl.create(:contact, user: old_user, person: conversation.author) if old_person.local? - conversation.participants << old_person - conversation.save! - visibility = ConversationVisibility.find_by(person_id: old_person.id) - run_migration - expect(visibility.reload.person).to eq(new_person) - end - - it "updates message reference" do - message = FactoryGirl.create(:message, author: old_person) - run_migration - expect(message.reload.author).to eq(new_person) - end - - it "updates conversation reference" do - conversation = FactoryGirl.create(:conversation, author: old_person) - run_migration - expect(conversation.reload.author).to eq(new_person) - end - - it "updates block references" do - user = FactoryGirl.create(:user) - block = user.blocks.create(person: old_person) - run_migration - expect(block.reload.person).to eq(new_person) - end - - it "updates role reference" do - role = FactoryGirl.create(:role, person: old_person) - run_migration - expect(role.reload.person).to eq(new_person) - end - - it "updates notification actors" do - notification = FactoryGirl.build(:notification) - notification.actors << old_person - notification.save! - actor = notification.notification_actors.find_by(person_id: old_person.id) - run_migration - expect(actor.reload.person).to eq(new_person) - end - - it "updates mention reference" do - mention = FactoryGirl.create(:mention, person: old_person) - run_migration - expect(mention.reload.person).to eq(new_person) - end -end - -shared_examples_for "it updates user references" do - it "updates invited users reference" do - invited_user = FactoryGirl.create(:user, invited_by: old_user) - run_migration - expect(invited_user.reload.invited_by).to eq(new_user) - end - - it "updates aspect reference" do - aspect = FactoryGirl.create(:aspect, user: old_user, name: r_str) - run_migration - expect(aspect.reload.user).to eq(new_user) - end - - it "updates contact reference" do - contact = FactoryGirl.create(:contact, user: old_user) - run_migration - expect(contact.reload.user).to eq(new_user) - end - - it "updates services reference" do - service = FactoryGirl.create(:service, user: old_user) - run_migration - expect(service.reload.user).to eq(new_user) - end - - it "updates user preference references" do - pref = UserPreference.create!(user: old_user, email_type: "also_commented") - run_migration - expect(pref.reload.user).to eq(new_user) - end - - it "updates tag following references" do - tag_following = FactoryGirl.create(:tag_following, user: old_user) - run_migration - expect(tag_following.reload.user).to eq(new_user) - end - - it "updates blocks refrences" do - block = FactoryGirl.create(:block, user: old_user) - run_migration - expect(block.reload.user).to eq(new_user) - end - - it "updates notification refrences" do - notification = FactoryGirl.create(:notification, recipient: old_user) - run_migration - expect(notification.reload.recipient).to eq(new_user) - end - - it "updates report refrences" do - report = FactoryGirl.create(:report, user: old_user) - run_migration - expect(report.reload.user).to eq(new_user) - end - - it "updates authorization refrences" do - authorization = FactoryGirl.create(:auth_with_read, user: old_user) - run_migration - expect(authorization.reload.user).to eq(new_user) - end - - it "updates share visibility refrences" do - share_visibility = FactoryGirl.create(:share_visibility, user: old_user) - run_migration - expect(share_visibility.reload.user).to eq(new_user) - end -end