Sha256: 2693faae38416569d3f6189201cbac145fc6812e66e3d492adfd275942f4e647

Contents?: true

Size: 1.85 KB

Versions: 23

Compression:

Stored size: 1.85 KB

Contents

require 'rails_helper'

module MnoEnterprise
  describe Auth::ConfirmationsController, type: :controller do
    routes { MnoEnterprise::Engine.routes }

    before { @request.env['devise.mapping'] = Devise.mappings[:user] }

    let(:unconfirmed_user) { build(:user, :unconfirmed, organizations: [])}
    let(:confirmed_user) { build(:user, organizations: [])}


    describe 'GET #show' do
      subject { get :show, confirmation_token: user.confirmation_token }

      before do
        allow(MnoEnterprise::User).to receive(:find_for_confirmation) { user }
        allow(user).to receive(:save)
      end

      context 'unconfirmed user' do
        let(:user) { unconfirmed_user }

        it 'does not sign in the user' do
          subject
          expect(controller.current_user).to be_nil
        end

        it 'render the template' do
          expect(subject).to render_template('show')
        end
      end

      context 'confirmed user' do
        let(:user) { confirmed_user }

        context 'with a new email' do
          let(:email) { 'unconfirmed@example.com' }

          before do
            user.unconfirmed_email = email

            api_stub_for(get: "/users?filter[email]=#{email}&limit=1", response: from_api(nil))
            api_stub_for(get: "/org_invites?filter[user_email]=#{email}", response: from_api(nil))
          end

          it 'sign in the user' do
            subject
            expect(controller.current_user).to eq(user)
          end

          it 'redirects to the dashboard' do
            expect(subject).to redirect_to(controller.signed_in_root_path(user))
          end
        end

        it 'does not sign in the user' do
          subject
          expect(controller.current_user).to be_nil
        end

        it 'returns an error' do
          expect(subject).to render_template("new")
        end
      end
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
mno-enterprise-api-3.1.4 spec/controllers/mno_enterprise/auth/confirmation_controller_spec.rb
mno-enterprise-api-3.0.7 spec/controllers/mno_enterprise/auth/confirmation_controller_spec.rb
mno-enterprise-api-2.0.9 spec/controllers/mno_enterprise/auth/confirmation_controller_spec.rb
mno-enterprise-api-3.1.3 spec/controllers/mno_enterprise/auth/confirmation_controller_spec.rb
mno-enterprise-api-3.0.6 spec/controllers/mno_enterprise/auth/confirmation_controller_spec.rb
mno-enterprise-api-2.0.8 spec/controllers/mno_enterprise/auth/confirmation_controller_spec.rb
mno-enterprise-api-3.1.2 spec/controllers/mno_enterprise/auth/confirmation_controller_spec.rb
mno-enterprise-api-3.0.5 spec/controllers/mno_enterprise/auth/confirmation_controller_spec.rb
mno-enterprise-api-2.0.7 spec/controllers/mno_enterprise/auth/confirmation_controller_spec.rb
mno-enterprise-api-2.0.6 spec/controllers/mno_enterprise/auth/confirmation_controller_spec.rb
mno-enterprise-api-2.0.5 spec/controllers/mno_enterprise/auth/confirmation_controller_spec.rb
mno-enterprise-api-3.1.1 spec/controllers/mno_enterprise/auth/confirmation_controller_spec.rb
mno-enterprise-api-3.0.4 spec/controllers/mno_enterprise/auth/confirmation_controller_spec.rb
mno-enterprise-api-2.0.4 spec/controllers/mno_enterprise/auth/confirmation_controller_spec.rb
mno-enterprise-api-3.1.0 spec/controllers/mno_enterprise/auth/confirmation_controller_spec.rb
mno-enterprise-api-3.0.3 spec/controllers/mno_enterprise/auth/confirmation_controller_spec.rb
mno-enterprise-api-2.0.3 spec/controllers/mno_enterprise/auth/confirmation_controller_spec.rb
mno-enterprise-api-3.0.2 spec/controllers/mno_enterprise/auth/confirmation_controller_spec.rb
mno-enterprise-api-2.0.2 spec/controllers/mno_enterprise/auth/confirmation_controller_spec.rb
mno-enterprise-api-3.0.1 spec/controllers/mno_enterprise/auth/confirmation_controller_spec.rb