Sha256: 9a49c40da90a28331f2fd44985e62f272dddfa17ff07093527c47fbec420001e

Contents?: true

Size: 1.66 KB

Versions: 5

Compression:

Stored size: 1.66 KB

Contents

require 'spec_helper'

describe CASino::API::LoginCredentialAcceptorProcessor do
  describe '#process' do
    let(:listener) { Object.new }
    let(:processor) { described_class.new(listener) }
    let(:user_agent) { 'ThisIsATestBrwoser 1.0' }

    context 'with invalid credentials' do
      let(:login_data) { { username: 'testuser', password: 'wrong' } }

      before(:each) do
        listener.stub(:invalid_login_credentials_via_api)
      end

      it 'calls the #invalid_login_credentials_via_api method on the listener' do
        listener.should_receive(:invalid_login_credentials_via_api)
        processor.process(login_data, user_agent).should be_falsey
      end

      it 'does not generate a ticket-granting ticket' do
        expect {
          processor.process(login_data, user_agent)
        }.to_not change(CASino::TicketGrantingTicket, :count)
      end
    end

    context 'with valid credentials' do
      let(:login_data) { { username: 'testuser', password: 'foobar123' } }

      before(:each) do
        listener.stub(:user_logged_in_via_api)
      end

      it 'calls the #user_logged_in_via_api method on the listener' do
        listener.should_receive(:user_logged_in_via_api).with(/^TGC\-/)
        processor.process(login_data, user_agent)
      end

      it 'generates a ticket-granting ticket' do
        expect {
          processor.process(login_data, user_agent)
        }.to change(CASino::TicketGrantingTicket, :count).by(1)
      end

      it 'sets the user-agent in the ticket-granting ticket' do
        processor.process(login_data, user_agent)
        CASino::TicketGrantingTicket.last.user_agent.should == user_agent
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
casino-3.0.4 spec/processor/api/login_credential_acceptor_spec.rb
casino-3.0.3 spec/processor/api/login_credential_acceptor_spec.rb
casino-3.0.2 spec/processor/api/login_credential_acceptor_spec.rb
casino-3.0.1 spec/processor/api/login_credential_acceptor_spec.rb
casino-3.0.0 spec/processor/api/login_credential_acceptor_spec.rb