From 7ed7b1ef6454339bee88bd2ab01b180225624f8d Mon Sep 17 00:00:00 2001 From: Dan Ungureanu Date: Wed, 17 Jun 2020 21:41:16 +0300 Subject: [PATCH] DEV: Add test (#10064) Follow-up-to 84dfaad137a215bf722388cccbe22f593279f5a2 --- spec/components/email_updater_spec.rb | 2 ++ spec/requests/users_controller_spec.rb | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/spec/components/email_updater_spec.rb b/spec/components/email_updater_spec.rb index 3476f485279..43709612044 100644 --- a/spec/components/email_updater_spec.rb +++ b/spec/components/email_updater_spec.rb @@ -159,6 +159,8 @@ describe EmailUpdater do context 'confirming a valid token' do it "adds a user email" do + expect(UserHistory.where(action: UserHistory.actions[:add_email], acting_user_id: user.id).last).to be_present + Jobs.expects(:enqueue).once.with(:critical_user_email, has_entries(type: :notify_old_email_add, to_address: old_email)) updater.confirm(@change_req.new_email_token.token) expect(updater.errors).to be_blank diff --git a/spec/requests/users_controller_spec.rb b/spec/requests/users_controller_spec.rb index 4e91e14a629..ec5adf4018a 100644 --- a/spec/requests/users_controller_spec.rb +++ b/spec/requests/users_controller_spec.rb @@ -2581,7 +2581,8 @@ describe UsersController do expect(user_email.reload.primary).to eq(true) expect(other_email.reload.primary).to eq(false) - put "/u/#{user.username}/preferences/primary-email.json", params: { email: other_email.email } + expect { put "/u/#{user.username}/preferences/primary-email.json", params: { email: other_email.email } } + .to change { UserHistory.where(action: UserHistory.actions[:update_email], acting_user_id: user.id).count }.by(1) expect(response.status).to eq(200) expect(user_email.reload.primary).to eq(false) expect(other_email.reload.primary).to eq(true) @@ -2604,7 +2605,8 @@ describe UsersController do expect(response.status).to eq(428) expect(user.reload.user_emails.pluck(:email)).to contain_exactly(user_email.email, other_email.email) - delete "/u/#{user.username}/preferences/email.json", params: { email: other_email.email } + expect { delete "/u/#{user.username}/preferences/email.json", params: { email: other_email.email } } + .to change { UserHistory.where(action: UserHistory.actions[:destroy_email], acting_user_id: user.id).count }.by(1) expect(response.status).to eq(200) expect(user.reload.user_emails.pluck(:email)).to contain_exactly(user_email.email) end