Sha256: d3f2ec360d0e8ba212490500bb1c1b28066d620c718cbd54edf09a0e6f2cb94b

Contents?: true

Size: 1.19 KB

Versions: 11

Compression:

Stored size: 1.19 KB

Contents

require 'rails_helper'

module Spree
  RSpec.describe ShippingCalculator, type: :model do
    let(:variant1) { build(:variant, price: 10) }
    let(:variant2) { build(:variant, price: 20) }

    let(:package) do
      build(:stock_package, variants_contents: { variant1 => 2, variant2 => 1 })
    end

    subject { ShippingCalculator.new }

    it 'computes with a shipment' do
      shipment = mock_model(Spree::Shipment)
      expect(subject).to receive(:compute_shipment).with(shipment)
      subject.compute(shipment)
    end

    it 'computes with a package' do
      expect(subject).to receive(:compute_package).with(package)
      subject.compute(package)
    end

    it 'compute_shipment must be overridden' do
      expect {
        subject.compute_shipment(shipment)
      }.to raise_error NameError
    end

    it 'compute_package must be overridden' do
      expect {
        subject.compute_package(package)
      }.to raise_error NotImplementedError
    end

    it 'checks availability for a package' do
      expect(subject.available?(package)).to be true
    end

    it 'calculates totals for content_items' do
      expect(subject.send(:total, package.contents)).to eq 40.00
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

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