Improve registrar area sign-in/out specs

#599
This commit is contained in:
Artur Beljajev 2017-10-10 06:02:22 +03:00
parent 26eb47ae09
commit 6e597f39e8
9 changed files with 178 additions and 124 deletions

View file

@ -0,0 +1,12 @@
require 'rails_helper'
RSpec.feature 'Registrar area IP restriction', settings: false do
background do
Setting.registrar_ip_whitelist_enabled = true
end
scenario 'notifies the user if his IP is not allowed' do
visit registrar_root_path
expect(page).to have_text('Access denied from IP 127.0.0.1')
end
end

View file

@ -1,42 +0,0 @@
require 'rails_helper'
RSpec.feature 'Registrar area ip restriction', settings: false do
context 'when enabled' do
background do
Setting.registrar_ip_whitelist_enabled = true
end
context 'when ip is allowed' do
given!(:white_ip) { create(:white_ip,
ipv4: '127.0.0.1',
interfaces: [WhiteIp::REGISTRAR]) }
it 'does not show error message' do
visit registrar_login_path
expect(page).to_not have_text(error_message)
end
end
context 'when ip is not allowed' do
it 'shows error message' do
visit registrar_login_path
expect(page).to have_text(error_message)
end
end
end
context 'when disabled' do
background do
Setting.registrar_ip_whitelist_enabled = false
end
it 'does not show error message' do
visit registrar_login_path
expect(page).to_not have_text(error_message)
end
end
def error_message
t('registrar.authorization.ip_not_allowed', ip: '127.0.0.1')
end
end

View file

@ -0,0 +1,43 @@
require 'rails_helper'
RSpec.feature 'Registrar area password sign-in' do
background do
Setting.registrar_ip_whitelist_enabled = false
end
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