Sha256: 94b3d3cfc0c4990b8ffcd5cc758e8f1cf0118480c70585046a6c6787222a9b12

Contents?: true

Size: 1.97 KB

Versions: 9

Compression:

Stored size: 1.97 KB

Contents

require 'spec_helper'

describe CatarsePagarme::SlipController do
  before do
    controller.stub(:current_user).and_return(user)
    Bank.create(name: 'foo', code: '123')
  end

  let(:project) { create(:project, goal: 10_000, state: 'online') }
  let(:contribution) { create(:contribution, value: 10, project: project) }
  let(:payment) { contribution.payments.first }
  let(:credit_card) { create(:credit_card, subscription_id: '1542')}

  describe 'GET update' do
    context  'without an user' do
      let(:user) { nil }

      it 'should raise a error' do
        expect {
          get :update, locale: :pt, id: contribution.id, use_route: 'catarse_pagarme'
        }.to raise_error('invalid user')
      end
    end

    context 'with an user' do
      let(:user) { payment.user }

      before do
        get :update, locale: :pt, id: contribution.id, use_route: 'catarse_pagarme'
      end

      it 'boleto_url should be filled' do
        expect(response.body).to be_present
      end
    end
  end

  describe 'POST create' do
    context  'without an user' do
      let(:user) { nil }

      it 'should raise a error' do
        expect {
          post :create, { locale: :pt, id: contribution.id, use_route: 'catarse_pagarme' }
        }.to raise_error('invalid user')
      end
    end

    context 'with an user' do
      let(:user) { payment.user }

      before do
        post :create, {
          locale: :pt, id: contribution.id, use_route: 'catarse_pagarme',
          user: { bank_account_attributes: {
            bank_id: Bank.first.id, agency: '1', agency_digit: '1', account: '1', account_digit: '1', owner_name: 'foo', owner_document: '1'
          } } }
      end

      it 'boleto_url should be filled' do
        expect(ActiveSupport::JSON.decode(response.body)['boleto_url']).not_to be_nil
      end

      it 'payment_status should be waiting_payment' do
        expect(ActiveSupport::JSON.decode(response.body)['payment_status']).to eq 'waiting_payment'
      end
    end
  end
end


Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
catarse_pagarme-2.7.11 spec/controllers/catarse_pagarme/slip_controller_spec.rb
catarse_pagarme-2.7.10 spec/controllers/catarse_pagarme/slip_controller_spec.rb
catarse_pagarme-2.7.9 spec/controllers/catarse_pagarme/slip_controller_spec.rb
catarse_pagarme-2.7.8 spec/controllers/catarse_pagarme/slip_controller_spec.rb
catarse_pagarme-2.7.7 spec/controllers/catarse_pagarme/slip_controller_spec.rb
catarse_pagarme-2.7.6 spec/controllers/catarse_pagarme/slip_controller_spec.rb
catarse_pagarme-2.7.5 spec/controllers/catarse_pagarme/slip_controller_spec.rb
catarse_pagarme-2.7.4 spec/controllers/catarse_pagarme/slip_controller_spec.rb
catarse_pagarme-2.7.3 spec/controllers/catarse_pagarme/slip_controller_spec.rb