Add inspection methods to shipping option
This commit is contained in:
parent
a0ab3cc6da
commit
86dffbc8fe
@ -1,5 +1,17 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module PlanetExpress
|
module PlanetExpress
|
||||||
ShippingOption = Struct.new(:provider, :package_size, :price_in_cents)
|
ShippingOption = Struct.new(:provider, :package_size, :price_in_cents) do
|
||||||
|
def s_shipment?
|
||||||
|
package_size == 'S'
|
||||||
|
end
|
||||||
|
|
||||||
|
def l_shipment?
|
||||||
|
package_size == 'L'
|
||||||
|
end
|
||||||
|
|
||||||
|
def inspect
|
||||||
|
"ShippingOption [proivder=#{provider} package_size=#{package_size} price_in_cents=#{price_in_cents}]"
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
35
spec/shipping_option_spec.rb
Normal file
35
spec/shipping_option_spec.rb
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
RSpec.describe PlanetExpress::ShippingOption do
|
||||||
|
describe '#s_shipment?' do
|
||||||
|
context 'with S package size' do
|
||||||
|
subject { build(:shipping_option, package_size: 'S') }
|
||||||
|
it 'returns true' do
|
||||||
|
expect(subject.s_shipment?).to eq(true)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with non S package size' do
|
||||||
|
subject { build(:shipping_option, package_size: 'M') }
|
||||||
|
it 'returns false' do
|
||||||
|
expect(subject.s_shipment?).to eq(false)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '#l_shipment?' do
|
||||||
|
context 'with L package size' do
|
||||||
|
subject { build(:shipping_option, package_size: 'L') }
|
||||||
|
it 'returns true' do
|
||||||
|
expect(subject.l_shipment?).to eq(true)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with non L package size' do
|
||||||
|
subject { build(:shipping_option, package_size: 'M') }
|
||||||
|
it 'returns false' do
|
||||||
|
expect(subject.l_shipment?).to eq(false)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user