Sha256: 7b6322930da637b8981bbb013efae317a31bdf9fff89c6e9b25349657b16ed3f

Contents?: true

Size: 1.2 KB

Versions: 4

Compression:

Stored size: 1.2 KB

Contents

require 'spec_helper'

describe Devise::MasqueradesController, type: :controller do
  context 'with configured devise app' do
    before { @request.env['devise.mapping'] = Devise.mappings[:user] }

    context 'when logged in' do
      before { logged_in }

      describe '#masquerade user' do
        let(:mask) { create(:user) }

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

        it { expect(session.keys).to include('devise_masquerade_user') }
        it { expect(session["warden.user.user.key"].first.first).to eq(mask.id) }
        it { should redirect_to("/?masquerade=secure_key") }

        context 'and back' do
          before { get :back }

          it { should redirect_to(masquerade_page) }
          it { expect(current_user.reload).to eq(@user) }
          it { expect(session.keys).not_to include('devise_masquerade_user') }
        end
      end
    end

    context 'when not logged in' do
      before { get :show, :id => 'any_id' }

      it { should redirect_to(new_user_session_path) }
    end
  end

  # it's a page with masquerade button ("Login As")
  def masquerade_page
    "/"
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
devise_masquerade-0.3.1 spec/controllers/devise/masquerades_controller_spec.rb
devise_masquerade-0.3.0 spec/controllers/devise/masquerades_controller_spec.rb
devise_masquerade-0.2.0 spec/controllers/devise/masquerades_controller_spec.rb
devise_masquerade-0.1.8 spec/controllers/devise/masquerades_controller_spec.rb