From 90d555d2720f8affd1b1771d6cb3c384a10b7a02 Mon Sep 17 00:00:00 2001 From: Omar Sahyoun Date: Wed, 27 Apr 2016 19:50:30 +0100 Subject: [PATCH] Stub for error_container --- app/controllers/payment_controller.rb | 2 ++ .../api/payment/braintree_controller_spec.rb | 14 +++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/app/controllers/payment_controller.rb b/app/controllers/payment_controller.rb index e26379246..aa7161720 100644 --- a/app/controllers/payment_controller.rb +++ b/app/controllers/payment_controller.rb @@ -18,7 +18,9 @@ def transaction end else @errors = client::ErrorProcessing.new(builder.error_container).process + @page = page + respond_to do |format| format.html { render 'payment/donation_errors', layout: 'sumofus' } format.json { render json: { success: false, errors: @errors }, status: 422 } diff --git a/spec/controllers/api/payment/braintree_controller_spec.rb b/spec/controllers/api/payment/braintree_controller_spec.rb index ab714efed..03069745d 100644 --- a/spec/controllers/api/payment/braintree_controller_spec.rb +++ b/spec/controllers/api/payment/braintree_controller_spec.rb @@ -1,7 +1,11 @@ require 'rails_helper' describe Api::Payment::BraintreeController do + before do + allow(Page).to receive(:find){ page } + end + let(:page) { instance_double("Page") } let(:action) { instance_double("Action", member_id: 79) } describe "GET token" do @@ -21,8 +25,8 @@ end describe "POST transaction" do - let(:client) { PaymentProcessor::Clients::Braintree } + let(:params) do { payment_method_nonce: 'wqeuinv-50238-FIERN', @@ -32,6 +36,7 @@ page_id: '12' } end + let(:payment_options) do { nonce: params[:payment_method_nonce], @@ -41,11 +46,11 @@ page_id: params[:page_id] } end + before :each do request.accept = "application/json" # ask for json end - describe 'successfully' do describe 'with recurring: true' do @@ -104,7 +109,6 @@ end describe 'unsuccessfully' do - let(:errors) { instance_double('PaymentProcessor::Clients::Braintree::ErrorProcessing', process: {my_error: 'foo'}) } before :each do @@ -113,7 +117,7 @@ describe 'with recurring: true' do - let(:builder){ instance_double('PaymentProcessor::Clients::Braintree::Subscription', success?: false, result: {}) } + let(:builder){ instance_double('PaymentProcessor::Clients::Braintree::Subscription', success?: false, error_container: {}) } before do allow(client::Subscription).to receive(:make_subscription).and_return(builder) @@ -145,7 +149,7 @@ describe 'without recurring' do let(:transaction) { instance_double('Braintree::Transaction', id: 't1234')} - let(:builder){ instance_double('PaymentProcessor::Clients::Braintree::Transaction', success?: false, result: {}) } + let(:builder){ instance_double('PaymentProcessor::Clients::Braintree::Transaction', success?: false, error_container: {}) } before :each do allow(client::Transaction).to receive(:make_transaction).and_return(builder)