Skip to content

Commit

Permalink
Merge 51ab104 into b7a8403
Browse files Browse the repository at this point in the history
  • Loading branch information
jmortlock committed Jun 1, 2020
2 parents b7a8403 + 51ab104 commit c29f3cd
Show file tree
Hide file tree
Showing 12 changed files with 57 additions and 43 deletions.
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.5.0
2.7.1
7 changes: 3 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
language: ruby
rvm:
- 2.2
- 2.3
- 2.4
- 2.5
- 2.6
- 2.7
before_install:
- gem install bundler --version "1.17.3"
script: bundle && bundle exec rake spec
gemfile:
- gemfiles/rails4.gemfile
- gemfiles/rails5.gemfile
- gemfiles/rails6.gemfile
notifications:
email:
- support@travellink.com.au
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).
This changelog adheres to [Keep a CHANGELOG](http://keepachangelog.com/).

## [Unreleased]
- [TT-7385] Update Money dependency, test against Ruby 2.7 / Rails 6

## [3.9.0]
### Added
- [DC-3115] Add customer comments method in booking
Expand Down
9 changes: 0 additions & 9 deletions gemfiles/rails4.gemfile

This file was deleted.

8 changes: 8 additions & 0 deletions gemfiles/rails6.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
source 'https://rubygems.org'
gemspec :path => '../'

group :development, :test do
gem 'activesupport', '~> 6.0'
gem 'activerecord', '~> 6.0'
gem 'actionpack', '~> 6.0'
end
1 change: 1 addition & 0 deletions lib/quick_travel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#
module QuickTravel
require 'active_support' # for .try, etc.
require 'money_extensions'

require 'quick_travel/cache'
require 'quick_travel/config'
Expand Down
2 changes: 1 addition & 1 deletion lib/quick_travel/booking.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def self.api_base
end

def self.find_by_reference(reference)
find_all!("#{api_base}/reference/#{URI.escape(reference)}.json").first
find_all!("#{api_base}/reference/#{URI.encode_www_form_component(reference)}.json").first
end

def documents(regenerate = false)
Expand Down
9 changes: 8 additions & 1 deletion lib/quick_travel/cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,20 @@ def self.cache(key, cache_options = nil)
cache_options ||= {}
key = "#{@@namespace}_#{key}" unless cache_options[:disable_namespacing]
cached_value = cache_store.read(key)
return cached_value unless cached_value.nil?
return cached_value unless cache_empty?(cached_value)
return nil unless block_given?
cache_options ||= {}
cache_options[:expires_in] = 1.day unless cache_options.key?(:expires_in)
yield.tap { |value| cache_store.write(key, value, cache_options) }
end

def self.cache_empty?(cached_value)
if cached_value.respond_to?(:body)
return cached_value.body.nil? || cached_value.body.empty?
end
cached_value.nil?
end

def self.delete(key, namespace = true)
key = "#{@@namespace}_#{key}" if namespace
cache_store.delete(key)
Expand Down
2 changes: 1 addition & 1 deletion lib/quick_travel/passenger_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def self.passenger_counts(count_hash)
end

def self.pluralize(count, singular, plural = nil)
"#{count || 0} " + ((count == 1 || count =~ /^1(\.0+)?$/) ? singular : (plural || singular.pluralize))
"#{count || 0} " + ((count == 1) ? singular : (plural || singular.pluralize))
end
end
end
10 changes: 5 additions & 5 deletions quicktravel_client.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ Gem::Specification.new do |spec|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ['lib']

spec.add_dependency 'httparty', '~> 0.17'
spec.add_dependency 'json'
spec.add_dependency 'activesupport', '>= 2.0.0'
spec.add_dependency 'httparty'
spec.add_dependency 'activesupport', '>= 5.0.0'
spec.add_dependency 'facets'
spec.add_dependency 'money', '>= 3.0', '< 6.0' # 6.0 starts to deprecate/split
spec.add_dependency 'money', '>= 6.0'
spec.add_dependency 'money_extensions', '>= 1.0'
spec.add_dependency 'will_paginate'

spec.add_development_dependency 'bundler', '~> 1.7'
spec.add_development_dependency 'bundler', '~> 2'
spec.add_development_dependency 'rake'
spec.add_development_dependency 'rspec'
spec.add_development_dependency 'rspec-its'
Expand Down
42 changes: 21 additions & 21 deletions spec/discounts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@

specify { expect(price_change.target.type).to eq 'Booking' }
specify { expect(price_change.target.id).to eq booking.id }
specify { expect(price_change.original_price).to eq 640.00 }
specify { expect(price_change.changed_price).to eq 380.00 }
specify { expect(price_change.price_change).to eq(-260.00) }
specify { expect(price_change.original_price).to eq 640.00.to_money }
specify { expect(price_change.changed_price).to eq 380.00.to_money }
specify { expect(price_change.price_change).to eq(-260.00.to_money) }
specify do
expect(price_change.reservation_price_changes.count).to(
eq booking.reservations.count)
Expand All @@ -43,9 +43,9 @@

specify { expect(price_change.target.type).to eq 'Reservation' }
specify { expect(price_change.target.id).to eq reservation.id }
specify { expect(price_change.original_price).to eq 400.00 }
specify { expect(price_change.changed_price).to eq 200.00 }
specify { expect(price_change.price_change).to eq(-200) }
specify { expect(price_change.original_price).to eq 400.00.to_money }
specify { expect(price_change.changed_price).to eq 200.00.to_money }
specify { expect(price_change.price_change).to eq(-200.to_money) }
end

context 'the total price_change applied on the top level reservation' do
Expand All @@ -57,9 +57,9 @@

specify { expect(price_change.target.type).to eq 'Reservation' }
specify { expect(price_change.target.id).to eq reservation.id }
specify { expect(price_change.original_price).to eq 640.00 }
specify { expect(price_change.changed_price).to eq 380.00 }
specify { expect(price_change.price_change).to eq(-260.00) }
specify { expect(price_change.original_price).to eq 640.00.to_money }
specify { expect(price_change.changed_price).to eq 380.00.to_money }
specify { expect(price_change.price_change).to eq(-260.00.to_money) }
end

context 'the price_change applied on the first extra pick' do
Expand All @@ -71,9 +71,9 @@

specify { expect(price_change.target.type).to eq 'Reservation' }
specify { expect(price_change.target.id).to eq extra_pick_without_price_change.id }
specify { expect(price_change.original_price).to eq 120 }
specify { expect(price_change.changed_price).to eq 120 }
specify { expect(price_change.price_change).to eq 0 }
specify { expect(price_change.original_price).to eq 120.to_money }
specify { expect(price_change.changed_price).to eq 120.to_money }
specify { expect(price_change.price_change).to eq 0.to_money }
end

context 'the total price_change applied on the first extra pick' do
Expand All @@ -85,9 +85,9 @@

specify { expect(price_change.target.type).to eq 'Reservation' }
specify { expect(price_change.target.id).to eq extra_pick_without_price_change.id }
specify { expect(price_change.original_price).to eq 120 }
specify { expect(price_change.changed_price).to eq 120 }
specify { expect(price_change.price_change).to eq 0 }
specify { expect(price_change.original_price).to eq 120.to_money }
specify { expect(price_change.changed_price).to eq 120.to_money }
specify { expect(price_change.price_change).to eq 0.to_money }
end

context 'the price_change applied on second extra pick' do
Expand All @@ -99,9 +99,9 @@

specify { expect(price_change.target.type).to eq 'Reservation' }
specify { expect(price_change.target.id).to eq extra_pick_with_price_change.id }
specify { expect(price_change.original_price).to eq 120.00 }
specify { expect(price_change.changed_price).to eq 60.00 }
specify { expect(price_change.price_change).to eq(-60.00) }
specify { expect(price_change.original_price).to eq 120.00.to_money }
specify { expect(price_change.changed_price).to eq 60.00.to_money }
specify { expect(price_change.price_change).to eq(-60.00.to_money) }
end

context 'the total price_change applied on second extra pick' do
Expand All @@ -113,9 +113,9 @@

specify { expect(price_change.target.type).to eq 'Reservation' }
specify { expect(price_change.target.id).to eq extra_pick_with_price_change.id }
specify { expect(price_change.original_price).to eq 120.00 }
specify { expect(price_change.changed_price).to eq 60.00 }
specify { expect(price_change.price_change).to eq(-60.00) }
specify { expect(price_change.original_price).to eq 120.00.to_money }
specify { expect(price_change.changed_price).to eq 60.00.to_money }
specify { expect(price_change.price_change).to eq(-60.00.to_money) }
end
end
end
5 changes: 5 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
require 'quick_travel/connection_error'
require 'quick_travel/cache'

Money.default_currency = Money::Currency.new("AUD")
Money.locale_backend = nil
Money.default_formatting_rules = { thousands_separator: "," }
Money.rounding_mode = BigDecimal::ROUND_HALF_UP

class HashCache
def initialize
@cache = {}
Expand Down

0 comments on commit c29f3cd

Please sign in to comment.