Sha256: aa0ea1682b25093a6a786cc41dfc7f8f9d2777d18b0c975a1a723388f773ca16

Contents?: true

Size: 1.78 KB

Versions: 7

Compression:

Stored size: 1.78 KB

Contents

require 'spec_helper'

module Spree
  class GatewayWithPassword < PaymentMethod
    preference :password, :string, :default => "password"
  end

  describe Admin::PaymentMethodsController, :type => :controller do
    stub_authorization!

    let(:payment_method) { GatewayWithPassword.create!(:name => "Bogus", :preferred_password => "haxme") }

    # regression test for https://github.com/spree/spree/issues/2094
    it "does not clear password on update" do
      expect(payment_method.preferred_password).to eq("haxme")
      spree_put :update, :id => payment_method.id, :payment_method => { :type => payment_method.class.to_s, :preferred_password => "" }
      expect(response).to redirect_to(spree.edit_admin_payment_method_path(payment_method))

      payment_method.reload
      expect(payment_method.preferred_password).to eq("haxme")
    end

    context "tries to save invalid payment" do
      it "doesn't break, responds nicely" do
        spree_post :create, :payment_method => { :name => "", :type => "Spree::Gateway::Bogus" }
      end
    end

    it "can create a payment method of a valid type" do
      expect {
        spree_post :create, :payment_method => { :name => "Test Method", :type => "Spree::Gateway::Bogus" }
      }.to change(Spree::PaymentMethod, :count).by(1)

      expect(response).to be_redirect
      expect(response).to redirect_to spree.edit_admin_payment_method_path(assigns(:payment_method))
    end

    it "can not create a payment method of an invalid type" do
      expect {
        spree_post :create, :payment_method => { :name => "Invalid Payment Method", :type => "Spree::InvalidType" }
      }.to change(Spree::PaymentMethod, :count).by(0)

      expect(response).to be_redirect
      expect(response).to redirect_to spree.new_admin_payment_method_path
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
solidus_backend-1.2.3 spec/controllers/spree/admin/payment_methods_controller_spec.rb
solidus_backend-1.2.2 spec/controllers/spree/admin/payment_methods_controller_spec.rb
solidus_backend-1.2.1 spec/controllers/spree/admin/payment_methods_controller_spec.rb
solidus_backend-1.2.0 spec/controllers/spree/admin/payment_methods_controller_spec.rb
solidus_backend-1.2.0.rc2 spec/controllers/spree/admin/payment_methods_controller_spec.rb
solidus_backend-1.2.0.rc1 spec/controllers/spree/admin/payment_methods_controller_spec.rb
solidus_backend-1.2.0.beta1 spec/controllers/spree/admin/payment_methods_controller_spec.rb