Sha256: 11303f1dba2459b9b0eb31298f545be259b091cc8fa68245d3e37d47b7577ac6

Contents?: true

Size: 1.57 KB

Versions: 16

Compression:

Stored size: 1.57 KB

Contents

require 'spec_helper'

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

  describe "#valid?" do
    subject { calculator.valid? }
    context "when base percent is less than zero" do
      before { calculator.preferred_base_percent = -1 }
      it { is_expected.to be false }
    end
    context "when base percent is greater than 100" do
      before { calculator.preferred_base_percent = 110 }
      it { is_expected.to be false }
    end
    context "when tiers is not a hash" do
      before { calculator.preferred_tiers = ["nope", 0] }
      it { is_expected.to be false }
    end
    context "when tiers is a hash" do
      context "and one of the keys is not a positive number" do
        before { calculator.preferred_tiers = { "nope" => 20 } }
        it { is_expected.to be false }
      end
      context "and one of the values is not a percent" do
        before { calculator.preferred_tiers = { 10 => 110 } }
        it { is_expected.to be false }
      end
    end
  end

  describe "#compute" do
    let(:line_item) { mock_model Spree::LineItem, amount: amount }
    before do
      calculator.preferred_base_percent = 10
      calculator.preferred_tiers = {
        100 => 15,
        200 => 20
      }
    end
    subject { calculator.compute(line_item) }
    context "when amount falls within the first tier" do
      let(:amount) { 50 }
      it { is_expected.to eq 5 }
    end
    context "when amount falls within the second tier" do
      let(:amount) { 150 }
      it { is_expected.to eq 22 }
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
spree_core-3.1.5 spec/models/spree/calculator/tiered_percent_spec.rb
spree_core-3.1.4 spec/models/spree/calculator/tiered_percent_spec.rb
spree_core-3.1.3 spec/models/spree/calculator/tiered_percent_spec.rb
spree_core-3.1.2 spec/models/spree/calculator/tiered_percent_spec.rb
spree_core-3.0.10 spec/models/spree/calculator/tiered_percent_spec.rb
spree_core-3.1.1 spec/models/spree/calculator/tiered_percent_spec.rb
spree_core-3.1.0 spec/models/spree/calculator/tiered_percent_spec.rb
spree_core-3.1.0.rc4 spec/models/spree/calculator/tiered_percent_spec.rb
spree_core-3.0.9 spec/models/spree/calculator/tiered_percent_spec.rb
spree_core-3.1.0.rc3 spec/models/spree/calculator/tiered_percent_spec.rb
spree_core-3.1.0.rc2 spec/models/spree/calculator/tiered_percent_spec.rb
spree_core-3.1.0.rc1 spec/models/spree/calculator/tiered_percent_spec.rb
spree_core-3.0.8 spec/models/spree/calculator/tiered_percent_spec.rb
spree_core-3.0.7 spec/models/spree/calculator/tiered_percent_spec.rb
spree_core-3.0.6.1 spec/models/spree/calculator/tiered_percent_spec.rb
spree_core-3.0.6 spec/models/spree/calculator/tiered_percent_spec.rb