Skip to content

Commit

Permalink
set valid_email to true on user email change (#4292)
Browse files Browse the repository at this point in the history
* set valid_email to true on user email change

* set valid_email to false before update_request in test
  • Loading branch information
Tooyosi authored Mar 6, 2024
1 parent d8277ff commit b91a4c2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/controllers/api/v1/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def update
super do |user|
if user.email_changed?
update_email_user_ids << user.id
user.update_attribute(:valid_email, true)
end
end

Expand Down
7 changes: 7 additions & 0 deletions spec/controllers/api/v1/users_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,13 @@ def update_request
expect(UserInfoChangedMailerWorker).to receive(:perform_async).with(user.id, "email")
end

it "sets valid_email parameter to true" do
# updating the valid email to false before the request as it is set at true by default
user.update(valid_email: false)
update_request
expect(user.reload.valid_email).to be_truthy
end

describe "with an email that already exists" do
let(:put_operations) { {users: {email: User.where.not(id: user.id).first.email}} }
it "doesn't send an email to the new address if user is not valid" do
Expand Down

0 comments on commit b91a4c2

Please sign in to comment.