mirror of
https://github.com/internetee/registry.git
synced 2025-08-06 01:35:10 +02:00
Refactor Devise integration
- Use scoped users - Use the named route helpers instead of hardcoded paths
This commit is contained in:
parent
c31f507c25
commit
9684c8e59f
52 changed files with 313 additions and 280 deletions
|
@ -2,7 +2,7 @@ require 'rails_helper'
|
|||
|
||||
RSpec.feature 'Registrar area home link', db: true do
|
||||
scenario 'is visible' do
|
||||
visit registrar_login_url
|
||||
visit new_registrar_user_session_url
|
||||
expect(page).to have_link('registrar-home-btn', href: registrar_root_path)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -9,7 +9,7 @@ RSpec.feature 'Mobile ID login', db: true do
|
|||
end
|
||||
|
||||
scenario 'login with phone number' do
|
||||
visit registrar_login_path
|
||||
visit new_registrar_user_session_url
|
||||
click_on 'login-with-mobile-id-btn'
|
||||
|
||||
fill_in 'user[phone]', with: '1234'
|
||||
|
|
|
@ -1,39 +0,0 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.feature 'Registrar area password sign-in' do
|
||||
scenario 'signs in the user with valid credentials' do
|
||||
create(:api_user_with_unlimited_balance,
|
||||
active: true,
|
||||
login: 'test',
|
||||
password: 'testtest')
|
||||
|
||||
visit registrar_login_path
|
||||
sign_in_with 'test', 'testtest'
|
||||
|
||||
expect(page).to have_text(t('registrar.base.current_user.sign_out'))
|
||||
end
|
||||
|
||||
scenario 'notifies the user with invalid credentials' do
|
||||
create(:api_user, login: 'test', password: 'testtest')
|
||||
|
||||
visit registrar_login_path
|
||||
sign_in_with 'test', 'invalid'
|
||||
|
||||
expect(page).to have_text('No such user')
|
||||
end
|
||||
|
||||
scenario 'notifies the user with inactive account' do
|
||||
create(:api_user, active: false, login: 'test', password: 'testtest')
|
||||
|
||||
visit registrar_login_path
|
||||
sign_in_with 'test', 'testtest'
|
||||
|
||||
expect(page).to have_text('User is not active')
|
||||
end
|
||||
|
||||
def sign_in_with(username, password)
|
||||
fill_in 'depp_user_tag', with: username
|
||||
fill_in 'depp_user_password', with: password
|
||||
click_button 'Login'
|
||||
end
|
||||
end
|
|
@ -1,14 +0,0 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.feature 'Registrar area sign-out', settings: false do
|
||||
background do
|
||||
sign_in_to_registrar_area(user: create(:api_user_with_unlimited_balance))
|
||||
end
|
||||
|
||||
scenario 'signs the user out' do
|
||||
visit registrar_root_path
|
||||
click_on t('registrar.base.current_user.sign_out')
|
||||
|
||||
expect(page).to have_text('Signed out successfully.')
|
||||
end
|
||||
end
|
|
@ -22,7 +22,7 @@ RSpec.describe 'Registrar area IP restriction', settings: false do
|
|||
context 'when ip is allowed' do
|
||||
let!(:white_ip) { create(:white_ip,
|
||||
ipv4: '127.0.0.1',
|
||||
registrar: controller.current_user.registrar,
|
||||
registrar: controller.current_registrar_user.registrar,
|
||||
interfaces: [WhiteIp::REGISTRAR]) }
|
||||
|
||||
specify do
|
||||
|
@ -36,12 +36,12 @@ RSpec.describe 'Registrar area IP restriction', settings: false do
|
|||
it 'signs the user out' do
|
||||
get registrar_root_url
|
||||
follow_redirect!
|
||||
expect(controller.current_user).to be_nil
|
||||
expect(controller.current_registrar_user).to be_nil
|
||||
end
|
||||
|
||||
it 'redirects to login url' do
|
||||
get registrar_root_url
|
||||
expect(response).to redirect_to(registrar_login_url)
|
||||
expect(response).to redirect_to(new_registrar_user_session_url)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -67,14 +67,14 @@ RSpec.describe 'Registrar area IP restriction', settings: false do
|
|||
interfaces: [WhiteIp::REGISTRAR]) }
|
||||
|
||||
specify do
|
||||
get registrar_login_path
|
||||
get new_registrar_user_session_path
|
||||
expect(response).to be_success
|
||||
end
|
||||
end
|
||||
|
||||
context 'when ip is not allowed' do
|
||||
specify do
|
||||
get registrar_login_path
|
||||
get new_registrar_user_session_path
|
||||
expect(response.body).to match "Access denied"
|
||||
end
|
||||
end
|
||||
|
@ -82,7 +82,7 @@ RSpec.describe 'Registrar area IP restriction', settings: false do
|
|||
|
||||
context 'when IP restriction is disabled' do
|
||||
specify do
|
||||
get registrar_login_path
|
||||
get new_registrar_user_session_path
|
||||
expect(response).to be_success
|
||||
end
|
||||
end
|
||||
|
|
|
@ -6,7 +6,7 @@ RSpec.describe 'Registrar area linked users', db: false do
|
|||
let!(:current_user) { create(:api_user, id: 1, identity_code: 'code') }
|
||||
|
||||
before do
|
||||
sign_in_to_registrar_area(user: current_user)
|
||||
sign_in current_user
|
||||
end
|
||||
|
||||
context 'when ip is allowed' do
|
||||
|
@ -23,7 +23,7 @@ RSpec.describe 'Registrar area linked users', db: false do
|
|||
it 'signs in as a new user' do
|
||||
put '/registrar/current_user/switch/2', nil, { HTTP_REFERER: registrar_contacts_url }
|
||||
follow_redirect!
|
||||
expect(controller.current_user.id).to eq(2)
|
||||
expect(controller.current_registrar_user.id).to eq(2)
|
||||
end
|
||||
|
||||
it 'redirects back' do
|
||||
|
@ -46,7 +46,6 @@ RSpec.describe 'Registrar area linked users', db: false do
|
|||
put '/registrar/current_user/switch/2', nil, { HTTP_REFERER: registrar_contacts_path }
|
||||
end
|
||||
|
||||
follow_redirect!
|
||||
expect(controller.current_user.id).to eq(1)
|
||||
end
|
||||
end
|
||||
|
@ -62,7 +61,7 @@ RSpec.describe 'Registrar area linked users', db: false do
|
|||
|
||||
specify do
|
||||
put '/registrar/current_user/switch/2'
|
||||
expect(response).to redirect_to(registrar_login_url)
|
||||
expect(response).to redirect_to(new_registrar_user_session_url)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -70,7 +69,7 @@ RSpec.describe 'Registrar area linked users', db: false do
|
|||
context 'when user is not authenticated' do
|
||||
specify do
|
||||
put '/registrar/current_user/switch/2'
|
||||
expect(response).to redirect_to(registrar_login_url)
|
||||
expect(response).to redirect_to(new_registrar_user_session_url)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,16 +0,0 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'Registrar area password sign-in', settings: false do
|
||||
let!(:user) { create(:api_user, active: true, login: 'test', password: 'testtest') }
|
||||
|
||||
it 'signs the user in' do
|
||||
post registrar_sessions_path, depp_user: { tag: 'test', password: 'testtest' }
|
||||
follow_redirect!
|
||||
expect(controller.current_user).to eq(user)
|
||||
end
|
||||
|
||||
it 'redirects to root url' do
|
||||
post registrar_sessions_path, depp_user: { tag: 'test', password: 'testtest' }
|
||||
expect(response).to redirect_to(registrar_root_url)
|
||||
end
|
||||
end
|
|
@ -1,18 +0,0 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'Registrar area sign-out', settings: false do
|
||||
before do
|
||||
sign_in_to_registrar_area
|
||||
end
|
||||
|
||||
it 'signs the user out' do
|
||||
delete registrar_destroy_user_session_path
|
||||
follow_redirect!
|
||||
expect(controller.current_user).to be_nil
|
||||
end
|
||||
|
||||
it 'redirects to login url' do
|
||||
delete registrar_destroy_user_session_path
|
||||
expect(response).to redirect_to(registrar_login_url)
|
||||
end
|
||||
end
|
|
@ -1,7 +1,7 @@
|
|||
module Features
|
||||
module SessionHelpers
|
||||
def sign_in_to_admin_area(user: create(:admin_user))
|
||||
visit admin_login_url
|
||||
visit new_admin_user_session_url
|
||||
|
||||
fill_in 'admin_user[username]', with: user.username
|
||||
fill_in 'admin_user[password]', with: user.password
|
||||
|
@ -10,7 +10,7 @@ module Features
|
|||
end
|
||||
|
||||
def sign_in_to_registrar_area(user: create(:api_user))
|
||||
visit registrar_login_url
|
||||
visit new_registrar_user_session_url
|
||||
|
||||
fill_in 'depp_user_tag', with: user.username
|
||||
fill_in 'depp_user_password', with: user.password
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
module Requests
|
||||
module SessionHelpers
|
||||
def sign_in_to_admin_area(user: create(:admin_user))
|
||||
post admin_sessions_path, admin_user: { username: user.username, password: user.password }
|
||||
post admin_user_session_path, admin_user: { username: user.username, password: user.password }
|
||||
end
|
||||
|
||||
def sign_in_to_registrar_area(user: create(:api_user))
|
||||
post registrar_sessions_path, { depp_user: { tag: user.username, password: user.password } }
|
||||
post registrar_user_session_path, { depp_user: { tag: user.username, password: user.password } }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue