Compare commits
2 Commits
445cdfa024
...
51489a83ab
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
51489a83ab
|
||
|
|
05426e4ced
|
@@ -2,54 +2,57 @@ 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!
|
||||
feature "Update email address" do
|
||||
let(:geraint) { create :user, id: 2, cn: 'geraint', email: "lamagliarosa@example.com" }
|
||||
|
||||
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
|
||||
before do
|
||||
login_as user, :scope => :user
|
||||
geraint.save!
|
||||
|
||||
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")
|
||||
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
|
||||
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"
|
||||
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(:update_email))
|
||||
expect(user.reload.unconfirmed_email).to be_nil
|
||||
within ".error-msg" do
|
||||
expect(page).to have_content("has already been taken")
|
||||
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 works' do
|
||||
visit setting_path(:account)
|
||||
fill_in 'Address', with: "lamagliabianca@example.com"
|
||||
fill_in 'Current password', with: "valid password"
|
||||
click_button "Update"
|
||||
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(: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")
|
||||
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
|
||||
|
||||
45
spec/features/settings/profile_spec.rb
Normal file
45
spec/features/settings/profile_spec.rb
Normal file
@@ -0,0 +1,45 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'Profile settings', type: :feature do
|
||||
let(:user) { create :user, cn: "mwahlberg" }
|
||||
|
||||
before do
|
||||
login_as user, :scope => :user
|
||||
end
|
||||
|
||||
feature "Update display name" do
|
||||
before do
|
||||
allow(user).to receive(:display_name).and_return("Mark")
|
||||
allow_any_instance_of(User).to receive(:dn).and_return("cn=mwahlberg,ou=kosmos.org,cn=users,dc=kosmos,dc=org")
|
||||
allow_any_instance_of(User).to receive(:ldap_entry).and_return({
|
||||
uid: user.cn, ou: user.ou, display_name: "Mark"
|
||||
})
|
||||
end
|
||||
|
||||
scenario 'fails with validation error' do
|
||||
visit setting_path(:profile)
|
||||
fill_in 'Display name', with: "M"
|
||||
click_button "Save"
|
||||
|
||||
expect(current_url).to eq(setting_url(:profile))
|
||||
expect(page).to have_field('Display name', with: 'M')
|
||||
within ".error-msg" do
|
||||
expect(page).to have_content("is too short")
|
||||
end
|
||||
end
|
||||
|
||||
scenario 'works with valid input' do
|
||||
expect(LdapManager::UpdateDisplayName).to receive(:call)
|
||||
.with(user.dn, "Marky Mark").and_return(true)
|
||||
|
||||
visit setting_path(:profile)
|
||||
fill_in 'Display name', with: "Marky Mark"
|
||||
click_button "Save"
|
||||
|
||||
expect(current_url).to eq(setting_url(:profile))
|
||||
within ".flash-msg" do
|
||||
expect(page).to have_content("Settings saved")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user