Sha256: 4bb8146134a509e0265a17baeb1048b6c4372fbe2f8e6b2987b04afe817df2cf

Contents?: true

Size: 1.72 KB

Versions: 15

Compression:

Stored size: 1.72 KB

Contents

require 'spec_helper'
require 'shared_examples/calculator_shared_examples'

describe Spree::Calculator::FlatRate, type: :model do
  let(:calculator) { Spree::Calculator::FlatRate.new }

  it_behaves_like 'a calculator with a description'

  let(:order) do
    mock_model(
      Spree::Order, quantity: 10, currency: "USD"
    )
  end

  context "compute" do
    it "should compute the amount as the rate when currency matches the order's currency" do
      calculator.preferred_amount = 25.0
      calculator.preferred_currency = "GBP"
      allow(order).to receive_messages currency: "GBP"
      expect(calculator.compute(order).round(2)).to eq(25.0)
    end

    it "should compute the amount as 0 when currency does not match the order's currency" do
      calculator.preferred_amount = 100.0
      calculator.preferred_currency = "GBP"
      allow(order).to receive_messages currency: "USD"
      expect(calculator.compute(order).round(2)).to eq(0.0)
    end

    it "should compute the amount as 0 when currency is blank" do
      calculator.preferred_amount = 100.0
      calculator.preferred_currency = ""
      allow(order).to receive_messages currency: "GBP"
      expect(calculator.compute(order).round(2)).to eq(0.0)
    end

    it "should compute the amount as the rate when the currencies use different casing" do
      calculator.preferred_amount = 100.0
      calculator.preferred_currency = "gBp"
      allow(order).to receive_messages currency: "GBP"
      expect(calculator.compute(order).round(2)).to eq(100.0)
    end

    it "should compute the amount as 0 when there is no object" do
      calculator.preferred_amount = 100.0
      calculator.preferred_currency = "GBP"
      expect(calculator.compute.round(2)).to eq(0.0)
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
solidus_core-2.3.1 spec/models/spree/calculator/flat_rate_spec.rb
solidus_core-2.2.2 spec/models/spree/calculator/flat_rate_spec.rb
solidus_core-2.1.1 spec/models/spree/calculator/flat_rate_spec.rb
solidus_core-2.3.0 spec/models/spree/calculator/flat_rate_spec.rb
solidus_core-2.3.0.rc3 spec/models/spree/calculator/flat_rate_spec.rb
solidus_core-2.3.0.rc2 spec/models/spree/calculator/flat_rate_spec.rb
solidus_core-2.3.0.rc1 spec/models/spree/calculator/flat_rate_spec.rb
solidus_core-2.3.0.beta1 spec/models/spree/calculator/flat_rate_spec.rb
solidus_core-2.2.1 spec/models/spree/calculator/flat_rate_spec.rb
solidus_core-2.2.0 spec/models/spree/calculator/flat_rate_spec.rb
solidus_core-2.2.0.rc1 spec/models/spree/calculator/flat_rate_spec.rb
solidus_core-2.2.0.beta1 spec/models/spree/calculator/flat_rate_spec.rb
solidus_core-2.1.0 spec/models/spree/calculator/flat_rate_spec.rb
solidus_core-2.1.0.rc1 spec/models/spree/calculator/flat_rate_spec.rb
solidus_core-2.1.0.beta1 spec/models/spree/calculator/flat_rate_spec.rb