Sha256: 41cd2b4802989b671b429395d882216faafc4fc13ec6d859abf0b516dbd78770

Contents?: true

Size: 964 Bytes

Versions: 11

Compression:

Stored size: 964 Bytes

Contents

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) { mock_model Spree::LineItem }

  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 '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

11 entries across 11 versions & 1 rubygems

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