Allow email address updates on account settings page
This commit is contained in:
55
spec/features/settings/account_spec.rb
Normal file
55
spec/features/settings/account_spec.rb
Normal file
@@ -0,0 +1,55 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'Account settings', type: :feature do
|
||||
let(:user) { create :user }
|
||||
let(:geraint) { create :user, id: 2, cn: 'geraint', email: "lamagliarosa@example.com" }
|
||||
|
||||
before do
|
||||
login_as user, :scope => :user
|
||||
geraint.save!
|
||||
|
||||
allow_any_instance_of(User).to receive(:valid_ldap_authentication?)
|
||||
.with("invalid password").and_return(false)
|
||||
allow_any_instance_of(User).to receive(:valid_ldap_authentication?)
|
||||
.with("valid password").and_return(true)
|
||||
end
|
||||
|
||||
scenario 'Update email address fails with invalid password' do
|
||||
visit setting_path(:account)
|
||||
fill_in 'Address', with: "lamagliarosa@example.com"
|
||||
fill_in 'Current password', with: "invalid password"
|
||||
click_button "Update"
|
||||
|
||||
expect(current_url).to eq(setting_url(:account))
|
||||
expect(user.reload.unconfirmed_email).to be_nil
|
||||
within ".flash-msg" do
|
||||
expect(page).to have_content("did not match your current password")
|
||||
end
|
||||
end
|
||||
|
||||
scenario 'Update email address fails when new address already taken' do
|
||||
visit setting_path(:account)
|
||||
fill_in 'Address', with: "lamagliarosa@example.com"
|
||||
fill_in 'Current password', with: "valid password"
|
||||
click_button "Update"
|
||||
|
||||
expect(current_url).to eq(setting_url(:update_email))
|
||||
expect(user.reload.unconfirmed_email).to be_nil
|
||||
within ".error-msg" do
|
||||
expect(page).to have_content("has already been taken")
|
||||
end
|
||||
end
|
||||
|
||||
scenario 'Update email address works' do
|
||||
visit setting_path(:account)
|
||||
fill_in 'Address', with: "lamagliabianca@example.com"
|
||||
fill_in 'Current password', with: "valid password"
|
||||
click_button "Update"
|
||||
|
||||
expect(current_url).to eq(setting_url(:account))
|
||||
expect(user.reload.unconfirmed_email).to eq("lamagliabianca@example.com")
|
||||
within ".flash-msg" do
|
||||
expect(page).to have_content("Please confirm your new address")
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -103,9 +103,16 @@ RSpec.describe User, type: :model do
|
||||
|
||||
describe "#devise_after_confirmation" do
|
||||
include ActiveJob::TestHelper
|
||||
after { clear_enqueued_jobs }
|
||||
|
||||
let(:user) { create :user, cn: "willherschel", ou: "kosmos.org" }
|
||||
let(:user) { create :user, cn: "willherschel", ou: "kosmos.org", email: "will@hrsch.el" }
|
||||
|
||||
before do
|
||||
allow(user).to receive(:ldap_entry).and_return({
|
||||
uid: "willherschel", ou: "kosmos.org", mail: "will@hrsch.el"
|
||||
})
|
||||
end
|
||||
|
||||
after { clear_enqueued_jobs }
|
||||
|
||||
it "enables default services" do
|
||||
expect(user).to receive(:enable_service).with(%w[ discourse gitea mediawiki xmpp ])
|
||||
@@ -124,10 +131,11 @@ RSpec.describe User, type: :model do
|
||||
let(:guest) { create :user, id: 2, cn: "isaacnewton", ou: "kosmos.org", email: "newt@example.com" }
|
||||
|
||||
before do
|
||||
# TODO remove when defaults are implemented
|
||||
user.update! preferences: { xmpp_exchange_contacts_with_invitees: true }
|
||||
Invitation.create! user: user, invited_user_id: guest.id, used_at: DateTime.now
|
||||
allow_any_instance_of(User).to receive(:enable_service)
|
||||
allow(guest).to receive(:ldap_entry).and_return({
|
||||
uid: "isaacnewton", ou: "kosmos.org", mail: "newt@example.com"
|
||||
})
|
||||
end
|
||||
|
||||
it "enqueues jobs to exchange XMPP contacts between inviter and invitee" do
|
||||
@@ -138,5 +146,31 @@ RSpec.describe User, type: :model do
|
||||
expect(job["arguments"][1]['_aj_globalid']).to eq('gid://akkounts/User/2')
|
||||
end
|
||||
end
|
||||
|
||||
context "for email address update of existing account" do
|
||||
before do
|
||||
allow(user).to receive(:ldap_entry)
|
||||
.and_return({ uid: "willherschel", ou: "kosmos.org", mail: "willyboy@aol.com" })
|
||||
allow(user).to receive(:dn)
|
||||
.and_return("cn=willherschel,ou=kosmos.org,cn=users,dc=kosmos,dc=org")
|
||||
allow(LdapManager::UpdateEmail).to receive(:call)
|
||||
end
|
||||
|
||||
it "updates the LDAP 'mail' attribute" do
|
||||
expect(LdapManager::UpdateEmail).to receive(:call)
|
||||
.with("cn=willherschel,ou=kosmos.org,cn=users,dc=kosmos,dc=org", "will@hrsch.el")
|
||||
user.send :devise_after_confirmation
|
||||
end
|
||||
|
||||
it "does not re-enable default services" do
|
||||
expect(user).not_to receive(:enable_service)
|
||||
user.send :devise_after_confirmation
|
||||
end
|
||||
|
||||
it "does not enqueue any delayed jobs" do
|
||||
user.send :devise_after_confirmation
|
||||
expect(enqueued_jobs).to be_empty
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user