Skip to content

Commit

Permalink
Merge pull request #2501 from CandleScience/fix-calculator-bug
Browse files Browse the repository at this point in the history
Fix calculator class check bug
  • Loading branch information
jhawthorn authored Jan 15, 2018
2 parents 4745ded + 5a8c2e8 commit bd15e16
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion core/app/models/concerns/spree/calculated_adjustments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def calculator_type

def calculator_type=(calculator_type)
klass = calculator_type.constantize if calculator_type
self.calculator = klass.new if klass && !calculator.is_a?(klass)
self.calculator = klass.new if klass && !calculator.instance_of?(klass)
end
end
end
20 changes: 20 additions & 0 deletions core/spec/lib/calculated_adjustments_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,24 @@
expect(subject.calculator.preferred_first_item).to eq(123)
end
end

describe '#calculator_type=' do
subject { Calculable.new }

let(:calculator_subclass) { Spree::Calculator::Shipping::FlatRate }
let(:calculator_superclass) { Spree::ShippingCalculator }

before(:each) do
subject.calculator_type = calculator_subclass.to_s
end

it 'sets calculator type' do
expect(subject.calculator_type).to eq(calculator_subclass.to_s)
end

it 'switches from calculator subclass to calculator superclass' do
subject.calculator_type = calculator_superclass.to_s
expect(subject.calculator_type).to eq(calculator_superclass.to_s)
end
end
end

0 comments on commit bd15e16

Please sign in to comment.