mirror of
https://github.com/internetee/registry.git
synced 2025-08-03 08:22:05 +02:00
parent
c1875ec88e
commit
787cca8e4c
9 changed files with 134 additions and 46 deletions
53
spec/requests/registrar/current_user_spec.rb
Normal file
53
spec/requests/registrar/current_user_spec.rb
Normal file
|
@ -0,0 +1,53 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'Registrar current user', db: false do
|
||||
describe 'GET /registrar/current_user/switch/2' do
|
||||
context 'when user is authenticated', db: true do
|
||||
let!(:current_user) { create(:api_user, id: 1, identity_code: 'test') }
|
||||
let!(:new_user) { create(:api_user, id: 2, identity_code: 'test') }
|
||||
|
||||
before do
|
||||
sign_in_to_registrar_area(user: current_user)
|
||||
end
|
||||
|
||||
context 'when ip is allowed' do
|
||||
let(:restricted_ip) { instance_double(Authorization::RestrictedIP,
|
||||
can_access_registrar_area?: true) }
|
||||
|
||||
before do
|
||||
allow(Authorization::RestrictedIP).to receive(:new).and_return(restricted_ip)
|
||||
end
|
||||
|
||||
specify do
|
||||
make_request
|
||||
expect(response).to redirect_to('http://previous.url')
|
||||
end
|
||||
end
|
||||
|
||||
context 'when ip is not allowed' do
|
||||
let(:restricted_ip) { instance_double(Authorization::RestrictedIP,
|
||||
can_access_registrar_area?: false) }
|
||||
|
||||
before do
|
||||
allow(Authorization::RestrictedIP).to receive(:new).and_return(restricted_ip)
|
||||
end
|
||||
|
||||
specify do
|
||||
make_request
|
||||
expect(response).to redirect_to(registrar_login_url)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when user is not authenticated' do
|
||||
specify do
|
||||
make_request
|
||||
expect(response).to redirect_to(registrar_login_url)
|
||||
end
|
||||
end
|
||||
|
||||
def make_request
|
||||
get '/registrar/current_user/switch/2', nil, { 'HTTP_REFERER' => 'http://previous.url' }
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue