Sha256: 1d8e060b5f17b2cd58de0b7993a0ef39c4302e07cdeb8c0d7b1e5fa038375a2e
Contents?: true
Size: 1.41 KB
Versions: 4
Compression:
Stored size: 1.41 KB
Contents
require 'spec_helper' describe MasqueradesTestsController, type: :controller do before { @request.env['devise.mapping'] = Devise.mappings[:user] } context 'no access for masquerade' do before do session.clear allow_any_instance_of(MasqueradesTestsController).to receive(:masquerade_authorized?) { false } end before { logged_in } let(:mask) { create(:user) } before { get :show, params: { id: mask.to_param, masquerade: mask.masquerade_key } } it { expect(response.status).to eq(403) } it { expect(cache_read(mask)).not_to be } it { expect(session['warden.user.user.key'].first.first).not_to eq(mask.id) } end context 'access for masquerade' do before do session.clear allow_any_instance_of(MasqueradesTestsController).to receive(:masquerade_authorized?) { true } end before { logged_in } let(:mask) { create(:user) } before do get :show, params: { id: mask.to_param, masquerade: mask.masquerade_key } end it { expect(response.status).to eq(302) } it { expect(cache_read(mask)).to be } it { expect(session['warden.user.user.key'].first.first).to eq(mask.id) } end def guid session[:devise_masquerade_masquerading_resource_guid] end def cache_read(user) Rails.cache.read(cache_key(user)) end def cache_key(user) "devise_masquerade_#{mask.class.name.downcase}_#{mask.to_param}_#{guid}" end end
Version data entries
4 entries across 4 versions & 1 rubygems