From ff14edd58d4d3adf6eea96de47baf8b73b9328ba Mon Sep 17 00:00:00 2001 From: Adam Mueller Date: Mon, 9 Jan 2017 13:22:26 -0800 Subject: [PATCH 1/3] Stubbed models not allowed to acces the database Newer versions of RSpec cause this to error hard instead of letting it slide. --- .../solidus_paypal_braintree/source_spec.rb | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/spec/models/solidus_paypal_braintree/source_spec.rb b/spec/models/solidus_paypal_braintree/source_spec.rb index c5647080..ffdcdfda 100644 --- a/spec/models/solidus_paypal_braintree/source_spec.rb +++ b/spec/models/solidus_paypal_braintree/source_spec.rb @@ -23,19 +23,19 @@ subject { described_class.new.can_capture?(payment) } context "when the payment state is pending" do - let(:payment) { build_stubbed(:payment, state: "pending") } + let(:payment) { build(:payment, state: "pending") } it { is_expected.to be } end context "when the payment state is checkout" do - let(:payment) { build_stubbed(:payment, state: "checkout") } + let(:payment) { build(:payment, state: "checkout") } it { is_expected.to be } end context "when the payment is completed" do - let(:payment) { build_stubbed(:payment, state: "completed") } + let(:payment) { build(:payment, state: "completed") } it { is_expected.to_not be } end @@ -45,19 +45,19 @@ subject { described_class.new.can_void?(payment) } context "when the payment failed" do - let(:payment) { build_stubbed(:payment, state: "failed") } + let(:payment) { build(:payment, state: "failed") } it { is_expected.not_to be } end context "when the payment is already voided" do - let(:payment) { build_stubbed(:payment, state: "void") } + let(:payment) { build(:payment, state: "void") } it { is_expected.not_to be } end context "when the payment is completed" do - let(:payment) { build_stubbed(:payment, state: "completed") } + let(:payment) { build(:payment, state: "completed") } it { is_expected.to be } end @@ -68,20 +68,20 @@ context "when the payment is completed" do context "and the credit allowed is 100" do - let(:payment) { build_stubbed(:payment, state: "completed", amount: 100) } + let(:payment) { build(:payment, state: "completed", amount: 100) } it { is_expected.to be } end context "and the credit allowed is 0" do - let(:payment) { build_stubbed(:payment, state: "completed", amount: 0) } + let(:payment) { build(:payment, state: "completed", amount: 0) } it { is_expected.not_to be } end end context "when the payment has not been completed" do - let(:payment) { build_stubbed(:payment, state: "checkout") } + let(:payment) { build(:payment, state: "checkout") } it { is_expected.not_to be } end From 015936b0e13a3e0af41c52d87955dd0049b70101 Mon Sep 17 00:00:00 2001 From: Adam Mueller Date: Mon, 9 Jan 2017 15:09:18 -0800 Subject: [PATCH 2/3] Log capybara output to test.log instead of STDOUT This avoids having PayPal logging show up in the middle of the test run, while still keeping it available should you need to debug it. --- spec/spec_helper.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 8a6cad2d..00fb8155 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -39,7 +39,10 @@ require 'capybara/poltergeist' Capybara.register_driver :poltergeist do |app| # Paypal requires TLS v1.2 for ssl connections - Capybara::Poltergeist::Driver.new(app, { phantomjs_options: ['--ssl-protocol=tlsv1.2'] }) + Capybara::Poltergeist::Driver.new(app, { + phantomjs_logger: Rails.logger, + phantomjs_options: ['--ssl-protocol=tlsv1.2'] + }) end Capybara.register_driver :chrome do |app| Capybara::Selenium::Driver.new(app, browser: :chrome) From 8799c8438594138dd232d8653f9abfc93778c46a Mon Sep 17 00:00:00 2001 From: Adam Mueller Date: Mon, 9 Jan 2017 16:37:24 -0800 Subject: [PATCH 3/3] Reset payments to ensure changes are noticed Newer versions of Solidus no longer internally reload the association, which we were incorrectly counting on before. Let's make our requirement explicit so that this test will work with all versions of Solidus. --- spec/models/solidus_paypal_braintree/gateway_spec.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spec/models/solidus_paypal_braintree/gateway_spec.rb b/spec/models/solidus_paypal_braintree/gateway_spec.rb index c3784ede..25c57b99 100644 --- a/spec/models/solidus_paypal_braintree/gateway_spec.rb +++ b/spec/models/solidus_paypal_braintree/gateway_spec.rb @@ -37,6 +37,8 @@ end it 'can complete an order' do + order.payments.reset + expect(order.total).to eq 55 expect(payment.capture_events.count).to eq 0