Sha256: c43ce205d84303ea4f18f9b5e3644719094da816ca36c2abd17f8988c0224caa

Contents?: true

Size: 1.29 KB

Versions: 8

Compression:

Stored size: 1.29 KB

Contents

require 'rails_helper'

module Spree
  RSpec.describe OrderUpdateAttributes do
    let(:order) { create(:order) }
    let(:payment_method) { create(:payment_method) }
    let(:request_env) { nil }
    let(:update) { described_class.new(order, attributes, request_env: request_env) }

    context 'empty attributes' do
      let(:attributes){ {} }
      it 'succeeds' do
        expect(update.apply).to be_truthy
      end
    end

    context 'with coupon code' do
      let(:attributes){ { coupon_code: 'abc123' } }
      it "sets coupon code" do
        expect(update.apply).to be_truthy
        expect(order.coupon_code).to eq('abc123')
      end
    end

    context 'with payment attributes' do
      let(:attributes) do
        {
          payments_attributes: [
            {
              payment_method_id: payment_method.id,
              source_attributes: attributes_for(:credit_card)
            }
          ]
        }
      end

      context 'with params and a request_env' do
        let(:request_env){ { 'USER_AGENT' => 'Firefox' } }
        it 'sets the request_env on the payment' do
          expect(update.apply).to be_truthy
          expect(order.payments.length).to eq 1
          expect(order.payments[0].request_env).to eq({ 'USER_AGENT' => 'Firefox' })
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
solidus_core-2.5.2 spec/models/spree/order_update_attributes_spec.rb
solidus_core-2.5.1 spec/models/spree/order_update_attributes_spec.rb
solidus_core-2.5.0 spec/models/spree/order_update_attributes_spec.rb
solidus_core-2.5.0.rc1 spec/models/spree/order_update_attributes_spec.rb
solidus_core-2.5.0.beta2 spec/models/spree/order_update_attributes_spec.rb
solidus_core-2.5.0.beta1 spec/models/spree/order_update_attributes_spec.rb
solidus_core-2.4.2 spec/models/spree/order_update_attributes_spec.rb
solidus_core-2.4.1 spec/models/spree/order_update_attributes_spec.rb