Sha256: 2674da6879544177ea3fbbb7d00a72d89cd67b491ebd295bb9a1db9e4aa4771e

Contents?: true

Size: 1.48 KB

Versions: 10

Compression:

Stored size: 1.48 KB

Contents

require 'spec_helper'

describe CatarsePagarme::NotificationsController, type: :controller do
  let(:fake_transaction) { double("fake transaction", id: payment.gateway_id, card_brand: 'visa', acquirer_name: 'stone', tid: '404040404', installments: 2) }

  before do
    PagarMe.stub(:validate_fingerprint).and_return(true)
    PagarMe::Transaction.stub(:find_by_id).and_return(fake_transaction)
  end

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

  describe 'CREATE' do
    context "with invalid payment" do
      before do
        PaymentEngines.stub(:find_payment).and_return(nil)
        post :create, { locale: :pt, id: 'abcdfg', use_route: 'catarse_pagarme' }
      end

      it "should not found the payment" do
        expect(response.code.to_i).to eq(404)
      end
    end

    context "with valid payment" do
      before do
        PaymentEngines.stub(:find_payment).and_return(payment)
        post :create, { locale: :pt, id: 'abcd', use_route: 'catarse_pagarme' }
      end

      it "should save an extra_data into payment_notifications" do
        expect(payment.payment_notifications.size).to eq(1)
      end

      it "should return 200 status" do
        expect(response.code.to_i).to eq(200)
      end
    end
  end

end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
catarse_pagarme-2.8.5 spec/controllers/catarse_pagarme/notifications_controller_spec.rb
catarse_pagarme-2.8.4 spec/controllers/catarse_pagarme/notifications_controller_spec.rb
catarse_pagarme-2.8.3 spec/controllers/catarse_pagarme/notifications_controller_spec.rb
catarse_pagarme-2.8.2 spec/controllers/catarse_pagarme/notifications_controller_spec.rb
catarse_pagarme-2.8.1 spec/controllers/catarse_pagarme/notifications_controller_spec.rb
catarse_pagarme-2.8.0 spec/controllers/catarse_pagarme/notifications_controller_spec.rb
catarse_pagarme-2.7.15 spec/controllers/catarse_pagarme/notifications_controller_spec.rb
catarse_pagarme-2.7.14 spec/controllers/catarse_pagarme/notifications_controller_spec.rb
catarse_pagarme-2.7.13 spec/controllers/catarse_pagarme/notifications_controller_spec.rb
catarse_pagarme-2.7.12 spec/controllers/catarse_pagarme/notifications_controller_spec.rb