Skip to content

Commit

Permalink
An email address added by an admin should be confirmed (#427)
Browse files Browse the repository at this point in the history
* Add test verifying that edited email should be confirmed
* Confirm primary emails edited by the admin
* Add unit test to ensure all admin created emails are confirmed

Closes #424
  • Loading branch information
ChrisMacNaughton committed Oct 30, 2022
1 parent f5281fc commit b1c9cd0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/controllers/admin/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def update # rubocop:disable Metrics/MethodLength, Metrics/AbcSize, Metrics/Cycl

email = @model.emails.find_by(address: address)
email.primary = true
email.confirm
email.save
email = @model.emails.find_by(address: old_email)
return if email.nil?
Expand Down
27 changes: 27 additions & 0 deletions spec/controllers/admin/users_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,33 @@
'type="hidden" name="custom_data[Has pets]" id="custom_data_Has_pets" value="false"'
)
end

it "can edit a user's primary email and it gets confirmed" do
expect(user.emails.first.address).to eq('user@localhost')
expect(user.emails.first.confirmed?).to be_truthy
post(:update, params: { id: user.id, user: { email: 'user2@localhost' } })
user.reload
expect(user.emails.first.address).to eq('user2@localhost')
expect(user.emails.first.confirmed?).to be_truthy
end

it "can edit a user's additional emails and it gets confirmed" do
first = user.emails.order(created_at: :asc).first

expect(first.address).to eq('user@localhost')
expect(first.confirmed?).to be_truthy
post(:update, params: { id: user.id, user: {
email: user.emails.first.address, email_addresses: ['user2@localhost']
} })
user.reload

first = user.emails.order(created_at: :asc).first
last = user.emails.order(created_at: :asc).last
expect(first.address).to eq('user@localhost')
expect(first.confirmed?).to be_truthy
expect(last.address).to eq('user2@localhost')
expect(last.confirmed?).to be_truthy
end
end
it 'can expire a user' do
expect(user.expired?).to be false
Expand Down

0 comments on commit b1c9cd0

Please sign in to comment.