akkounts/spec/features/settings/account_spec.rb
Râu Cao 51489a83ab
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
Use feature block for email update specs
2023-05-28 15:25:53 +02:00

59 lines
1.9 KiB
Ruby

require 'rails_helper'
RSpec.describe 'Account settings', type: :feature do
let(:user) { create :user }
feature "Update email address" do
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 '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 '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 'works with valid password and address' 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
end