Skip to content

Commit

Permalink
Merge pull request #253 from alexgerstein/master
Browse files Browse the repository at this point in the history
Fix holidays caching when using Date extensions
  • Loading branch information
ttwo32 committed Dec 25, 2016
2 parents 358b9d5 + abe8767 commit 3d11f1b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
4 changes: 2 additions & 2 deletions lib/holidays/core_extensions/date.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def self.included(base)
#
# Also available via Holidays#on.
def holidays(*options)
Holidays.on(self, options)
Holidays.on(self, *options)
end

# Check if the current date is a holiday.
Expand All @@ -25,7 +25,7 @@ def holidays(*options)
# Date.civil('2008-01-01').holiday?(:ca)
# => true
def holiday?(*options)
holidays = self.holidays(options)
holidays = self.holidays(*options)
holidays && !holidays.empty?
end

Expand Down
25 changes: 14 additions & 11 deletions test/integration/test_holidays.rb
Original file line number Diff line number Diff line change
Expand Up @@ -264,22 +264,25 @@ def test_sorting
end

def test_caching
start_date = Date.civil(2008, 3, 21)
end_date = Date.civil(2008, 3, 25)
cache_data = Holidays.between(start_date, end_date, :ca, :informal)
options = [:ca, :informal]
good_friday = Date.civil(2008, 3, 21)
easter_monday = Date.civil(2008, 3, 24)
cache_end_date = Date.civil(2008, 3, 25)

Holidays.cache_between(Date.civil(2008,3,21), Date.civil(2008,3,25), :ca, :informal)
Holidays.cache_between(good_friday, cache_end_date, :ca, :informal)

# Test that correct results are returned outside the cache range, and with no caching
assert_equal 1, Holidays.on(Date.civil(2035,1,1), :ca, :informal).length
assert_equal 1, Holidays.on(Date.civil(2035,1,1), :us).length
# Test that correct results are returned outside the
# cache range, and with no caching
assert_equal 1, Holidays.on(Date.civil(2035, 1, 1), :ca, :informal).length
assert_equal 1, Holidays.on(Date.civil(2035, 1, 1), :us).length

Holidays::Factory::Finder.expects(:between).never # Make sure cache is hit for two next call
# Make sure cache is hit for all successive calls
Holidays::Factory::Finder.expects(:between).never

# Test that cache has been set and it returns the same as before
assert_equal 1, Holidays.on(Date.civil(2008, 3, 21), :ca, :informal).length
assert_equal 1, Holidays.on(Date.civil(2008, 3, 24), :ca, :informal).length
assert_equal 1, Holidays.on(good_friday, :ca, :informal).length
assert_equal 1, Holidays.on(easter_monday, :ca, :informal).length
assert_equal 1, easter_monday.holidays(:ca, :informal).length
assert_equal true, easter_monday.holiday?(:ca, :informal)
end

def test_load_all
Expand Down

0 comments on commit 3d11f1b

Please sign in to comment.