Skip to content

Commit

Permalink
Add spec for Spree::Core::Environment::Calculators
Browse files Browse the repository at this point in the history
  • Loading branch information
mamhoff committed Feb 14, 2024
1 parent f106451 commit 0b70bfc
Showing 1 changed file with 75 additions and 0 deletions.
75 changes: 75 additions & 0 deletions core/spec/lib/spree/core/environment/calculators_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# frozen_string_literal: true

require "rails_helper"

RSpec.describe Spree::Core::Environment::Calculators do
subject { described_class.new }

describe "#shipping_methods" do
it "is empty by default" do
expect(subject.shipping_methods).to be_empty
end

it "can be set to a new value" do
subject.shipping_methods = ["Spree::Calculator::Shipping::FlatRate"]
expect(subject.shipping_methods).to include(Spree::Calculator::Shipping::FlatRate)
end
end

describe "#tax_rates" do
it "is empty by default" do
expect(subject.tax_rates).to be_empty
end

it "can be set to a new value" do
subject.tax_rates = ["Spree::Calculator::Shipping::FlatRate"]
expect(subject.tax_rates).to include(Spree::Calculator::Shipping::FlatRate)
end
end

describe "deprecated methods" do
around do |example|
Spree.deprecator.silence do
example.run
end
end

describe "#promotion_actions_create_adjustments" do
it "contains the default calculators" do
expect(subject.promotion_actions_create_adjustments).to eq(Spree::Config.promotions.calculators["Spree::Promotion::Actions::CreateAdjustment"])
end

it "can be set to a new value" do
previous_value = subject.promotion_actions_create_adjustments
subject.promotion_actions_create_adjustments = ["Spree::Calculator::FlatRate"]
expect(subject.promotion_actions_create_adjustments).to include(Spree::Calculator::FlatRate)
subject.promotion_actions_create_adjustments = previous_value
end
end

describe "#promotion_actions_create_item_adjustments" do
it "contains the default calculators" do
expect(subject.promotion_actions_create_item_adjustments).to eq(Spree::Config.promotions.calculators["Spree::Promotion::Actions::CreateItemAdjustments"])
end

it "can be set to a new value" do
previous_value = subject.promotion_actions_create_item_adjustments
subject.promotion_actions_create_item_adjustments = ["Spree::Calculator::FlatRate"]
expect(subject.promotion_actions_create_item_adjustments).to include(Spree::Calculator::FlatRate)
subject.promotion_actions_create_item_adjustments = previous_value
end
end
describe "#promotion_actions_create_quantity_adjustments" do
it "contains the default calculators" do
expect(subject.promotion_actions_create_quantity_adjustments).to eq(Spree::Config.promotions.calculators["Spree::Promotion::Actions::CreateQuantityAdjustments"])
end

it "can be set to a new value" do
previous_value = subject.promotion_actions_create_quantity_adjustments
subject.promotion_actions_create_quantity_adjustments = ["Spree::Calculator::FlatRate"]
expect(subject.promotion_actions_create_quantity_adjustments).to include(Spree::Calculator::FlatRate)
subject.promotion_actions_create_quantity_adjustments = previous_value
end
end
end
end

0 comments on commit 0b70bfc

Please sign in to comment.