-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #463 from roomorama/bugfix/kigo_quote_price
Bugfix for kigo quote price
- Loading branch information
Showing
7 changed files
with
207 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
module Kigo::Mappers | ||
# It's possible that min_stay value for property and min_stay value for | ||
# calendar entry can be different. | ||
# | ||
# This class solves the problem of determining which min_stay value | ||
# we should use. | ||
# | ||
# This class should be used everywhere where we need to set min_stay values. | ||
class MinStay | ||
attr_reader :prop_min_stay, :cal_min_stay | ||
|
||
def initialize(prop_min_stay, cal_min_stay) | ||
@prop_min_stay = prop_min_stay | ||
@cal_min_stay = cal_min_stay | ||
end | ||
|
||
# Compare and return the most strict min_stay value. | ||
# Return nil if both prop_min_stay and cal_min_stay are zero | ||
def value | ||
min_stay = [prop_min_stay.to_i, cal_min_stay.to_i].max | ||
|
||
min_stay.zero? ? nil : min_stay | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
spec/lib/concierge/suppliers/kigo/mappers/min_stay_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
require 'spec_helper' | ||
|
||
RSpec.describe Kigo::Mappers::MinStay do | ||
describe "#value" do | ||
it "selects property's minimum_stay if it's bigger than calendar's minimum_stay" do | ||
prop_min_stay = 20 | ||
cal_min_stay = 19 | ||
|
||
min_stay = described_class.new(prop_min_stay, cal_min_stay) | ||
expect(min_stay.value).to eq(20) | ||
end | ||
|
||
it "selects calendars's minimum_stay if it's bigger than property's minimum_stay" do | ||
prop_min_stay = 16 | ||
cal_min_stay = 17 | ||
|
||
min_stay = described_class.new(prop_min_stay, cal_min_stay) | ||
expect(min_stay.value).to eq(17) | ||
end | ||
|
||
it "selects any of minimum_stay values if they equal to each other" do | ||
prop_min_stay = 15 | ||
cal_min_stay = 15 | ||
|
||
min_stay = described_class.new(prop_min_stay, cal_min_stay) | ||
expect(min_stay.value).to eq(15) | ||
end | ||
|
||
it "selects property's minimum_stay when calendar's one is nil" do | ||
prop_min_stay = 13 | ||
cal_min_stay = nil | ||
|
||
min_stay = described_class.new(prop_min_stay, cal_min_stay) | ||
expect(min_stay.value).to eq(13) | ||
end | ||
|
||
it "selects property's minimum_stay when calendar's one is nil" do | ||
prop_min_stay = nil | ||
cal_min_stay = 11 | ||
|
||
min_stay = described_class.new(prop_min_stay, cal_min_stay) | ||
expect(min_stay.value).to eq(11) | ||
end | ||
|
||
it "applies .to_i to property's minimum_stay values" do | ||
prop_min_stay = "20" | ||
cal_min_stay = 19 | ||
|
||
min_stay = described_class.new(prop_min_stay, cal_min_stay) | ||
expect(min_stay.value).to eq(20) | ||
end | ||
|
||
it "applies .to_i to calendars's minimum_stay values" do | ||
prop_min_stay = 10 | ||
cal_min_stay = "19" | ||
|
||
min_stay = described_class.new(prop_min_stay, cal_min_stay) | ||
expect(min_stay.value).to eq(19) | ||
end | ||
|
||
it "returns error when both minimum_stay values are nil or 0" do | ||
null_values = [nil, 0] | ||
|
||
null_values.each do |prop_min_stay| | ||
null_values.each do |cal_min_stay| | ||
min_stay = described_class.new(prop_min_stay, cal_min_stay) | ||
expect(min_stay.value).to be_nil | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters