Skip to content

Commit

Permalink
Merge pull request #1790 from jhawthorn/avoid_stubbing_in_payment_spec
Browse files Browse the repository at this point in the history
Avoid some stubbing in payment spec
  • Loading branch information
jhawthorn authored Mar 30, 2017
2 parents 24c6554 + bb561a2 commit e0ac650
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions core/spec/models/spree/payment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
let(:card) { create :credit_card }

let(:payment) do
payment = Spree::Payment.new
payment.source = card
payment.order = order
payment.payment_method = gateway
payment.amount = 5
payment
Spree::Payment.create! do |payment|
payment.source = card
payment.order = order
payment.payment_method = gateway
payment.amount = 5
end
end

let(:amount_in_cents) { (payment.amount * 100).round }
Expand All @@ -39,11 +39,6 @@
ActiveMerchant::Billing::Response.new(false, '', {}, {})
end

before(:each) do
# So it doesn't create log entries every time a processing method is called
allow(payment.log_entries).to receive(:create!)
end

context '.risky' do
let!(:payment_1) { create(:payment, avs_response: 'Y', cvv_response_code: 'M', cvv_response_message: 'Match') }
let!(:payment_2) { create(:payment, avs_response: 'Y', cvv_response_code: 'M', cvv_response_message: '') }
Expand Down Expand Up @@ -246,8 +241,9 @@

it "should log the response" do
payment.save!
expect(payment.log_entries).to receive(:create!).with(details: anything)
payment.authorize!
expect {
payment.authorize!
}.to change { payment.log_entries.count }.by(1)
end

describe 'billing_address option' do
Expand Down Expand Up @@ -355,8 +351,9 @@

it "should log the response" do
payment.save!
expect(payment.log_entries).to receive(:create!).with(details: anything)
payment.purchase!
expect {
payment.purchase!
}.to change { payment.log_entries.count }.by(1)
end

context "if successful" do
Expand Down Expand Up @@ -532,8 +529,9 @@
end

it "should log the response" do
expect(payment.log_entries).to receive(:create!).with(details: anything)
payment.void_transaction!
expect {
payment.void_transaction!
}.to change { payment.log_entries.count }.by(1)
end

context "if successful" do
Expand Down Expand Up @@ -688,6 +686,8 @@
let(:attributes) { attributes_for(:credit_card) }

it "should not try to create profiles on old failed payment attempts" do
order.payments.destroy_all

allow_any_instance_of(Spree::Payment).to receive(:payment_method) { gateway }

Spree::PaymentCreate.new(order, {
Expand Down

0 comments on commit e0ac650

Please sign in to comment.