Sha256: 60dd7d70fcbdfaae4d35a15339222125113754d44b6ff909b078281bcb562a9e

Contents?: true

Size: 1.19 KB

Versions: 10

Compression:

Stored size: 1.19 KB

Contents

require 'spec_helper'

describe MasqueradesController, 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(MasqueradesController).to receive(:masquerade_authorized?) { false }
    end

    before { logged_in }

    let(:mask) { create(:user) }

    before { get :show, :id => mask.to_param }

    it { expect(response.status).to eq(403) }
    it { expect(session.keys).not_to include('devise_masquerade_user') }
    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(MasqueradesController).to receive(:masquerade_authorized?) { true }
    end

    before { logged_in }

    let(:mask) { create(:user) }

    before do
      expect(SecureRandom).to receive(:urlsafe_base64) { "secure_key" }
      get :show, :id => mask.to_param
    end

    it { expect(response.status).to eq(302) }
    it { expect(session.keys).to include('devise_masquerade_user') }
    it { expect(session["warden.user.user.key"].first.first).to eq(mask.id) }
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
devise_masquerade-0.6.5 spec/controllers/masquerades_controller_spec.rb
devise_masquerade-0.6.4 spec/controllers/masquerades_controller_spec.rb
devise_masquerade-0.6.3 spec/controllers/masquerades_controller_spec.rb
devise_masquerade-0.6.2 spec/controllers/masquerades_controller_spec.rb
devise_masquerade-0.6.1 spec/controllers/masquerades_controller_spec.rb
devise_masquerade-0.6.0 spec/controllers/masquerades_controller_spec.rb
devise_masquerade-0.5.3 spec/controllers/masquerades_controller_spec.rb
devise_masquerade-0.5.2 spec/controllers/masquerades_controller_spec.rb
devise_masquerade-0.5.1 spec/controllers/masquerades_controller_spec.rb
devise_masquerade-0.5.0 spec/controllers/masquerades_controller_spec.rb