Sha256: e4a20f8daf801227bddd136e7e1ee508adafa173febf35f7903212c33f983c81

Contents?: true

Size: 1.13 KB

Versions: 7

Compression:

Stored size: 1.13 KB

Contents

require 'rails_helper'

module MnoEnterprise
  describe ImpersonateController, type: :controller do
    render_views
    routes { MnoEnterprise::Engine.routes }

    # Stub model calls
    let(:user) { build(:user, :admin) }
    let(:user2) { build(:user) }
    before do
      api_stub_for(get: "/users/#{user.id}", response: from_api(user))
      api_stub_for(put: "/users/#{user.id}", response: from_api(user))
      api_stub_for(get: "/users/#{user2.id}", response: from_api(user2))
      api_stub_for(put: "/users/#{user2.id}", response: from_api(user2))
    end

    context "admin user" do
      before do
        sign_in user
      end

      describe "#create" do
        it do
          expect(controller.current_user.id).to eq(user.id)
          get :create, user_id: user2.id
          expect(controller.current_user.id).to eq(user2.id)
        end
      end

      describe "#destroy" do
        subject { get :destroy }
        before { get :create, user_id: user2.id }

        it { expect(controller.current_user.id).to eq(user2.id) }

        it { subject; expect(controller.current_user.id).to eq(user.id) }
      end
    end
  end

end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
mno-enterprise-api-3.1.1 spec/controllers/mno_enterprise/impersonate_controller_spec.rb
mno-enterprise-api-3.0.4 spec/controllers/mno_enterprise/impersonate_controller_spec.rb
mno-enterprise-api-3.1.0 spec/controllers/mno_enterprise/impersonate_controller_spec.rb
mno-enterprise-api-3.0.3 spec/controllers/mno_enterprise/impersonate_controller_spec.rb
mno-enterprise-api-3.0.2 spec/controllers/mno_enterprise/impersonate_controller_spec.rb
mno-enterprise-api-3.0.1 spec/controllers/mno_enterprise/impersonate_controller_spec.rb
mno-enterprise-api-3.0.0 spec/controllers/mno_enterprise/impersonate_controller_spec.rb