Sha256: f384eed374cb6f9696709e138dfadca8f08b6e87594baa50481f0c98e6bd4859

Contents?: true

Size: 1.28 KB

Versions: 21

Compression:

Stored size: 1.28 KB

Contents

# frozen_string_literal: true

require 'rails_helper'
require 'shared_examples/calculator_shared_examples'

RSpec.describe Spree::Calculator::FlatPercentItemTotal, type: :model do
  let(:calculator) { Spree::Calculator::FlatPercentItemTotal.new }
  let(:line_item) { create(:line_item) }

  it_behaves_like 'a calculator with a description'

  before { allow(calculator).to receive_messages preferred_flat_percent: 10 }

  context "compute" do
    it "should round result correctly" do
      allow(line_item).to receive_messages amount: 31.08
      expect(calculator.compute(line_item)).to eq 3.11

      allow(line_item).to receive_messages amount: 31.00
      expect(calculator.compute(line_item)).to eq 3.10
    end

    it "should round result based on order currency" do
      line_item.order.currency = 'JPY'
      allow(line_item).to receive_messages amount: 31.08
      expect(calculator.compute(line_item)).to eq 3

      allow(line_item).to receive_messages amount: 31.00
      expect(calculator.compute(line_item)).to eq 3
    end

    it 'returns object.amount if computed amount is greater' do
      allow(calculator).to receive_messages preferred_flat_percent: 110
      allow(line_item).to receive_messages amount: 30.00

      expect(calculator.compute(line_item)).to eq 30.0
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
solidus_core-2.10.5 spec/models/spree/calculator/flat_percent_item_total_spec.rb
solidus_core-2.10.3 spec/models/spree/calculator/flat_percent_item_total_spec.rb
solidus_core-2.10.2 spec/models/spree/calculator/flat_percent_item_total_spec.rb
solidus_core-2.9.6 spec/models/spree/calculator/flat_percent_item_total_spec.rb
solidus_core-2.8.6 spec/models/spree/calculator/flat_percent_item_total_spec.rb
solidus_core-2.10.1 spec/models/spree/calculator/flat_percent_item_total_spec.rb
solidus_core-2.9.5 spec/models/spree/calculator/flat_percent_item_total_spec.rb
solidus_core-2.10.0 spec/models/spree/calculator/flat_percent_item_total_spec.rb
solidus_core-2.9.4 spec/models/spree/calculator/flat_percent_item_total_spec.rb
solidus_core-2.8.5 spec/models/spree/calculator/flat_percent_item_total_spec.rb
solidus_core-2.9.3 spec/models/spree/calculator/flat_percent_item_total_spec.rb
solidus_core-2.9.2 spec/models/spree/calculator/flat_percent_item_total_spec.rb
solidus_core-2.10.0.beta1 spec/models/spree/calculator/flat_percent_item_total_spec.rb
solidus_core-2.9.1 spec/models/spree/calculator/flat_percent_item_total_spec.rb
solidus_core-2.9.0 spec/models/spree/calculator/flat_percent_item_total_spec.rb
solidus_core-2.9.0.rc.1 spec/models/spree/calculator/flat_percent_item_total_spec.rb
solidus_core-2.8.4 spec/models/spree/calculator/flat_percent_item_total_spec.rb
solidus_core-2.8.3 spec/models/spree/calculator/flat_percent_item_total_spec.rb
solidus_core-2.8.2 spec/models/spree/calculator/flat_percent_item_total_spec.rb
solidus_core-2.8.1 spec/models/spree/calculator/flat_percent_item_total_spec.rb