Use feature block for email update specs
This commit is contained in:
parent
05426e4ced
commit
51489a83ab
@ -2,54 +2,57 @@ require 'rails_helper'
|
|||||||
|
|
||||||
RSpec.describe 'Account settings', type: :feature do
|
RSpec.describe 'Account settings', type: :feature do
|
||||||
let(:user) { create :user }
|
let(:user) { create :user }
|
||||||
let(:geraint) { create :user, id: 2, cn: 'geraint', email: "lamagliarosa@example.com" }
|
|
||||||
|
|
||||||
before do
|
feature "Update email address" do
|
||||||
login_as user, :scope => :user
|
let(:geraint) { create :user, id: 2, cn: 'geraint', email: "lamagliarosa@example.com" }
|
||||||
geraint.save!
|
|
||||||
|
|
||||||
allow_any_instance_of(User).to receive(:valid_ldap_authentication?)
|
before do
|
||||||
.with("invalid password").and_return(false)
|
login_as user, :scope => :user
|
||||||
allow_any_instance_of(User).to receive(:valid_ldap_authentication?)
|
geraint.save!
|
||||||
.with("valid password").and_return(true)
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario 'Update email address fails with invalid password' do
|
allow_any_instance_of(User).to receive(:valid_ldap_authentication?)
|
||||||
visit setting_path(:account)
|
.with("invalid password").and_return(false)
|
||||||
fill_in 'Address', with: "lamagliarosa@example.com"
|
allow_any_instance_of(User).to receive(:valid_ldap_authentication?)
|
||||||
fill_in 'Current password', with: "invalid password"
|
.with("valid password").and_return(true)
|
||||||
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
|
||||||
end
|
|
||||||
|
|
||||||
scenario 'Update email address fails when new address already taken' do
|
scenario 'fails with invalid password' do
|
||||||
visit setting_path(:account)
|
visit setting_path(:account)
|
||||||
fill_in 'Address', with: "lamagliarosa@example.com"
|
fill_in 'Address', with: "lamagliarosa@example.com"
|
||||||
fill_in 'Current password', with: "valid password"
|
fill_in 'Current password', with: "invalid password"
|
||||||
click_button "Update"
|
click_button "Update"
|
||||||
|
|
||||||
expect(current_url).to eq(setting_url(:update_email))
|
expect(current_url).to eq(setting_url(:account))
|
||||||
expect(user.reload.unconfirmed_email).to be_nil
|
expect(user.reload.unconfirmed_email).to be_nil
|
||||||
within ".error-msg" do
|
within ".flash-msg" do
|
||||||
expect(page).to have_content("has already been taken")
|
expect(page).to have_content("did not match your current password")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
scenario 'Update email address works' do
|
scenario 'fails when new address already taken' do
|
||||||
visit setting_path(:account)
|
visit setting_path(:account)
|
||||||
fill_in 'Address', with: "lamagliabianca@example.com"
|
fill_in 'Address', with: "lamagliarosa@example.com"
|
||||||
fill_in 'Current password', with: "valid password"
|
fill_in 'Current password', with: "valid password"
|
||||||
click_button "Update"
|
click_button "Update"
|
||||||
|
|
||||||
expect(current_url).to eq(setting_url(:account))
|
expect(current_url).to eq(setting_url(:update_email))
|
||||||
expect(user.reload.unconfirmed_email).to eq("lamagliabianca@example.com")
|
expect(user.reload.unconfirmed_email).to be_nil
|
||||||
within ".flash-msg" do
|
within ".error-msg" do
|
||||||
expect(page).to have_content("Please confirm your new address")
|
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
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user