diff --git a/spec/controllers/spree/paypal_controller_spec.rb b/spec/controllers/spree/paypal_controller_spec.rb new file mode 100644 index 0000000000..90f97fcb7d --- /dev/null +++ b/spec/controllers/spree/paypal_controller_spec.rb @@ -0,0 +1,42 @@ +require 'spec_helper' + +module Spree + describe PaypalController, type: :controller do + context 'when cancelling' do + it 'redirects back to checkout' do + expect(spree_get(:cancel)).to redirect_to checkout_path + end + end + + context 'when confirming' do + let(:previous_order) { controller.current_order(true) } + let(:payment_method) { create(:payment_method) } + + before do + allow(previous_order).to receive(:complete?).and_return(true) + end + + it 'resets the order' do + spree_post :confirm, payment_method_id: payment_method.id + expect(controller.current_order).not_to eq(previous_order) + end + + it 'sets the access token of the session' do + spree_post :confirm, payment_method_id: payment_method.id + expect(session[:access_token]).to eq(controller.current_order.token) + end + end + + describe '#expire_current_order' do + it 'empties the order_id of the session' do + expect(session).to receive(:[]=).with(:order_id, nil) + controller.expire_current_order + end + + it 'resets the @current_order ivar' do + controller.expire_current_order + expect(controller.instance_variable_get(:@current_order)).to be_nil + end + end + end +end diff --git a/spec/models/spree/gateway_tagging_spec.rb b/spec/models/spree/gateway_tagging_spec.rb new file mode 100644 index 0000000000..2a5eb5c23e --- /dev/null +++ b/spec/models/spree/gateway_tagging_spec.rb @@ -0,0 +1,55 @@ +require "spec_helper" + +# We extended Spree::PaymentMethod to be taggable. Unfortunately, an inheritance +# bug prevented the taggable code to be passed on to the descendants of +# PaymentMethod. We fixed that in config/initializers/spree.rb. +# +# This spec tests several descendants for their taggability. The tests are in +# a separate file, because they cover one aspect of several classes. +shared_examples "taggable" do |expected_taggable_type| + it "provides a tag list" do + expect(subject.tag_list).to eq [] + end + + it "stores tags for the root taggable type" do + subject.tag_list.add("one") + subject.save! + + expect(subject.taggings.last.taggable_type).to eq expected_taggable_type + end +end + +module Spree + describe "PaymentMethod and descendants" do + let(:shop) { create(:enterprise) } + let(:valid_subject) do + # Supply required parameters so that it can be saved to attach taggings. + described_class.new( + name: "Some payment method", + distributor_ids: [shop.id] + ) + end + subject { valid_subject } + + describe PaymentMethod do + it_behaves_like "taggable", "Spree::PaymentMethod" + end + + describe Gateway do + it_behaves_like "taggable", "Spree::PaymentMethod" + end + + describe Gateway::PayPalExpress do + it_behaves_like "taggable", "Spree::PaymentMethod" + end + + describe Gateway::StripeConnect do + subject do + # StripeConnect needs an owner to be valid. + valid_subject.tap { |m| m.preferred_enterprise_id = shop.id } + end + + it_behaves_like "taggable", "Spree::PaymentMethod" + end + end +end