holidays 2.2.0 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -0
- data/README.md +22 -8
- data/Rakefile +26 -8
- data/bin/console +7 -0
- data/bin/setup +5 -0
- data/{data → definitions}/SYNTAX.rdoc +0 -0
- data/{data → definitions}/ar.yaml +0 -0
- data/{data → definitions}/at.yaml +1 -1
- data/{data → definitions}/au.yaml +80 -51
- data/{data → definitions}/be.yaml +0 -0
- data/{data → definitions}/br.yaml +0 -0
- data/{data → definitions}/ca.yaml +0 -0
- data/{data → definitions}/ch.yaml +0 -0
- data/{data → definitions}/cl.yaml +0 -0
- data/{data → definitions}/cr.yaml +0 -0
- data/{data → definitions}/cz.yaml +0 -0
- data/{data → definitions}/de.yaml +25 -34
- data/{data → definitions}/dk.yaml +0 -0
- data/{data → definitions}/ecb_target.yaml +2 -2
- data/{data → definitions}/el.yaml +0 -0
- data/{data → definitions}/es.yaml +37 -26
- data/{data → definitions}/federal_reserve.yaml +0 -0
- data/{data → definitions}/fedex.yaml +9 -3
- data/{data → definitions}/fi.yaml +0 -0
- data/{data → definitions}/fr.yaml +0 -0
- data/{data → definitions}/gb.yaml +19 -19
- data/{data → definitions}/hr.yaml +0 -0
- data/{data → definitions}/hu.yaml +1 -1
- data/{data → definitions}/ie.yaml +0 -0
- data/{data → definitions}/index.yaml +0 -0
- data/{data → definitions}/is.yaml +0 -0
- data/{data → definitions}/it.yaml +0 -0
- data/{data → definitions}/jp.yaml +3 -3
- data/{data → definitions}/li.yaml +3 -3
- data/{data → definitions}/lt.yaml +0 -0
- data/{data → definitions}/ma.yaml +0 -0
- data/{data → definitions}/mx.yaml +0 -0
- data/{data → definitions}/nerc.yaml +0 -0
- data/{data → definitions}/nl.yaml +0 -0
- data/{data → definitions}/no.yaml +0 -0
- data/{data → definitions}/north_america_informal.yaml +0 -0
- data/{data → definitions}/nyse.yaml +0 -0
- data/{data → definitions}/nz.yaml +21 -10
- data/{data → definitions}/ph.yaml +0 -0
- data/{data → definitions}/pl.yaml +0 -0
- data/{data → definitions}/pt.yaml +0 -0
- data/{data → definitions}/ro.yaml +1 -2
- data/{data → definitions}/se.yaml +0 -0
- data/{data → definitions}/sg.yaml +0 -0
- data/{data → definitions}/si.yaml +6 -6
- data/{data → definitions}/sk.yaml +0 -0
- data/{data → definitions}/united_nations.yaml +0 -0
- data/{data → definitions}/ups.yaml +17 -11
- data/{data → definitions}/us.yaml +20 -15
- data/{data → definitions}/ve.yaml +0 -0
- data/{data → definitions}/vi.yaml +0 -0
- data/{data → definitions}/za.yaml +0 -0
- data/holidays.gemspec +2 -1
- data/lib/generated_definitions/MANIFEST +56 -0
- data/lib/generated_definitions/REGIONS.rb +4 -0
- data/lib/{holidays → generated_definitions}/ar.rb +2 -2
- data/lib/{holidays → generated_definitions}/at.rb +2 -2
- data/lib/{holidays → generated_definitions}/au.rb +19 -10
- data/lib/{holidays → generated_definitions}/be.rb +2 -2
- data/lib/{holidays → generated_definitions}/br.rb +2 -2
- data/lib/{holidays → generated_definitions}/ca.rb +2 -2
- data/lib/{holidays → generated_definitions}/ch.rb +2 -2
- data/lib/{holidays → generated_definitions}/cl.rb +2 -2
- data/lib/{holidays → generated_definitions}/cr.rb +2 -2
- data/lib/{holidays → generated_definitions}/cz.rb +2 -2
- data/lib/{holidays → generated_definitions}/de.rb +5 -4
- data/lib/{holidays → generated_definitions}/dk.rb +2 -2
- data/lib/{holidays → generated_definitions}/ecb_target.rb +2 -2
- data/lib/{holidays → generated_definitions}/el.rb +2 -2
- data/lib/{holidays → generated_definitions}/es.rb +6 -6
- data/lib/{holidays → generated_definitions}/europe.rb +7 -6
- data/lib/{holidays → generated_definitions}/fed_ex.rb +8 -3
- data/lib/{holidays → generated_definitions}/federal_reserve.rb +2 -2
- data/lib/{holidays → generated_definitions}/fi.rb +2 -2
- data/lib/{holidays → generated_definitions}/fr.rb +2 -2
- data/lib/{holidays → generated_definitions}/gb.rb +2 -2
- data/lib/{holidays → generated_definitions}/hr.rb +2 -2
- data/lib/{holidays → generated_definitions}/hu.rb +2 -2
- data/lib/{holidays → generated_definitions}/ie.rb +2 -2
- data/lib/{holidays → generated_definitions}/is.rb +2 -2
- data/lib/{holidays → generated_definitions}/it.rb +2 -2
- data/lib/{holidays → generated_definitions}/jp.rb +5 -5
- data/lib/{holidays → generated_definitions}/li.rb +2 -2
- data/lib/{holidays → generated_definitions}/lt.rb +2 -2
- data/lib/{holidays → generated_definitions}/ma.rb +2 -2
- data/lib/{holidays → generated_definitions}/mx.rb +2 -2
- data/lib/{holidays → generated_definitions}/nerc.rb +2 -2
- data/lib/{holidays → generated_definitions}/nl.rb +2 -2
- data/lib/{holidays → generated_definitions}/no.rb +2 -2
- data/lib/{holidays → generated_definitions}/north_america.rb +8 -3
- data/lib/{holidays → generated_definitions}/nyse.rb +2 -2
- data/lib/{holidays → generated_definitions}/nz.rb +5 -5
- data/lib/{holidays → generated_definitions}/ph.rb +2 -2
- data/lib/{holidays → generated_definitions}/pl.rb +2 -2
- data/lib/{holidays → generated_definitions}/pt.rb +2 -2
- data/lib/{holidays → generated_definitions}/ro.rb +2 -2
- data/lib/{holidays → generated_definitions}/scandinavia.rb +2 -2
- data/lib/{holidays → generated_definitions}/se.rb +2 -2
- data/lib/{holidays → generated_definitions}/sg.rb +2 -2
- data/lib/{holidays → generated_definitions}/si.rb +2 -2
- data/lib/{holidays → generated_definitions}/sk.rb +2 -2
- data/lib/{holidays → generated_definitions}/united_nations.rb +2 -2
- data/lib/{holidays → generated_definitions}/ups.rb +8 -3
- data/lib/{holidays → generated_definitions}/us.rb +8 -3
- data/lib/{holidays → generated_definitions}/ve.rb +2 -2
- data/lib/{holidays → generated_definitions}/vi.rb +2 -2
- data/lib/{holidays → generated_definitions}/za.rb +2 -2
- data/lib/holidays.rb +120 -665
- data/lib/holidays/core_extensions/date.rb +39 -0
- data/lib/holidays/date_calculator/day_of_month.rb +68 -0
- data/lib/holidays/date_calculator/easter.rb +58 -0
- data/lib/holidays/date_calculator/weekend_modifier.rb +49 -0
- data/lib/holidays/date_calculator_factory.rb +21 -0
- data/lib/holidays/definition/context/generator.rb +216 -0
- data/lib/holidays/definition/context/merger.rb +26 -0
- data/lib/holidays/definition/repository/cache.rb +33 -0
- data/lib/holidays/definition/repository/holidays_by_month.rb +49 -0
- data/lib/holidays/definition/repository/proc_cache.rb +36 -0
- data/lib/holidays/definition/repository/regions.rb +36 -0
- data/lib/holidays/definition/validator/region.rb +45 -0
- data/lib/holidays/definition_factory.rb +50 -0
- data/lib/holidays/option/context/parse_options.rb +96 -0
- data/lib/holidays/option_factory.rb +14 -0
- data/lib/holidays/use_case/context/between.rb +105 -0
- data/lib/holidays/use_case/context/dates_driver_builder.rb +64 -0
- data/lib/holidays/use_case_factory.rb +20 -0
- data/lib/holidays/version.rb +1 -1
- data/test/defs/test_defs_ar.rb +1 -1
- data/test/defs/test_defs_at.rb +2 -2
- data/test/defs/test_defs_au.rb +61 -43
- data/test/defs/test_defs_be.rb +1 -1
- data/test/defs/test_defs_br.rb +1 -1
- data/test/defs/test_defs_ca.rb +1 -1
- data/test/defs/test_defs_ch.rb +1 -1
- data/test/defs/test_defs_cl.rb +1 -1
- data/test/defs/test_defs_cr.rb +1 -1
- data/test/defs/test_defs_cz.rb +1 -1
- data/test/defs/test_defs_de.rb +18 -30
- data/test/defs/test_defs_dk.rb +1 -1
- data/test/defs/test_defs_ecb_target.rb +3 -3
- data/test/defs/test_defs_el.rb +1 -1
- data/test/defs/test_defs_es.rb +36 -25
- data/test/defs/test_defs_europe.rb +82 -84
- data/test/defs/test_defs_fed_ex.rb +4 -1
- data/test/defs/test_defs_federal_reserve.rb +1 -1
- data/test/defs/test_defs_fi.rb +1 -1
- data/test/defs/test_defs_fr.rb +1 -1
- data/test/defs/test_defs_gb.rb +20 -20
- data/test/defs/test_defs_hr.rb +1 -1
- data/test/defs/test_defs_hu.rb +2 -2
- data/test/defs/test_defs_ie.rb +1 -1
- data/test/defs/test_defs_is.rb +1 -1
- data/test/defs/test_defs_it.rb +1 -1
- data/test/defs/test_defs_jp.rb +1 -1
- data/test/defs/test_defs_li.rb +4 -4
- data/test/defs/test_defs_lt.rb +1 -1
- data/test/defs/test_defs_ma.rb +1 -1
- data/test/defs/test_defs_mx.rb +1 -1
- data/test/defs/test_defs_nerc.rb +1 -1
- data/test/defs/test_defs_nl.rb +1 -1
- data/test/defs/test_defs_no.rb +1 -1
- data/test/defs/test_defs_north_america.rb +5 -3
- data/test/defs/test_defs_nyse.rb +1 -1
- data/test/defs/test_defs_nz.rb +19 -9
- data/test/defs/test_defs_ph.rb +1 -1
- data/test/defs/test_defs_pl.rb +1 -1
- data/test/defs/test_defs_pt.rb +1 -1
- data/test/defs/test_defs_ro.rb +2 -3
- data/test/defs/test_defs_scandinavia.rb +1 -1
- data/test/defs/test_defs_se.rb +1 -1
- data/test/defs/test_defs_sg.rb +1 -1
- data/test/defs/test_defs_si.rb +7 -7
- data/test/defs/test_defs_sk.rb +1 -1
- data/test/defs/test_defs_united_nations.rb +1 -1
- data/test/defs/test_defs_ups.rb +5 -2
- data/test/defs/test_defs_us.rb +5 -3
- data/test/defs/test_defs_ve.rb +1 -1
- data/test/defs/test_defs_vi.rb +1 -1
- data/test/defs/test_defs_za.rb +1 -1
- data/test/{test_date.rb → holidays/core_extensions/test_date.rb} +8 -2
- data/test/holidays/date_calculator/test_day_of_month.rb +27 -0
- data/test/holidays/date_calculator/test_easter.rb +29 -0
- data/test/holidays/date_calculator/test_weekend_modifier.rb +33 -0
- data/test/holidays/definition/context/test_generator.rb +84 -0
- data/test/holidays/definition/context/test_merger.rb +22 -0
- data/test/holidays/definition/repository/test_cache.rb +82 -0
- data/test/holidays/definition/repository/test_holidays_by_month.rb +187 -0
- data/test/holidays/definition/repository/test_proc_cache.rb +29 -0
- data/test/holidays/definition/repository/test_regions.rb +86 -0
- data/test/holidays/definition/validator/test_region.rb +50 -0
- data/test/holidays/option/context/test_parse_options.rb +69 -0
- data/test/holidays/test_date_calculator_factory.rb +21 -0
- data/test/holidays/test_definition_factory.rb +34 -0
- data/test/holidays/test_option_factory.rb +9 -0
- data/test/holidays/test_use_case_factory.rb +13 -0
- data/test/holidays/use_case/context/test_between.rb +75 -0
- data/test/holidays/use_case/context/test_dates_driver_builder.rb +91 -0
- data/test/test_all_regions.rb +14 -3
- data/test/test_helper.rb +2 -1
- data/test/test_holidays.rb +19 -24
- data/test/test_holidays_between.rb +85 -0
- data/test/test_multiple_regions.rb +2 -2
- data/test/test_parse_definitions.rb +10 -4
- metadata +181 -111
- data/.coveralls.yml +0 -1
- data/lib/holidays/MANIFEST +0 -55
data/test/test_all_regions.rb
CHANGED
@@ -3,7 +3,7 @@ require File.expand_path(File.dirname(__FILE__)) + '/test_helper'
|
|
3
3
|
class MultipleRegionsTests < Test::Unit::TestCase
|
4
4
|
|
5
5
|
def test_definition_dir
|
6
|
-
assert File.directory?(Holidays::
|
6
|
+
assert File.directory?(Holidays::FULL_DEFINITIONS_PATH)
|
7
7
|
end
|
8
8
|
|
9
9
|
def test_getting_available_paths
|
@@ -27,7 +27,6 @@ class MultipleRegionsTests < Test::Unit::TestCase
|
|
27
27
|
assert defs.include?(:united_nations)
|
28
28
|
end
|
29
29
|
|
30
|
-
|
31
30
|
def test_loading_all
|
32
31
|
Holidays.load_all
|
33
32
|
holidays = Holidays.on(Date.civil(2011, 5, 1), :any)
|
@@ -59,8 +58,20 @@ class MultipleRegionsTests < Test::Unit::TestCase
|
|
59
58
|
assert holidays.any? { |h| h[:name] == 'Neujahrstag' }
|
60
59
|
end
|
61
60
|
|
61
|
+
def test_unknown_region_raises_exception
|
62
|
+
assert_raise Holidays::UnknownRegionError do
|
63
|
+
Holidays.on(Date.civil(2014, 1, 1), :something_we_do_not_recognize)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_malicious_load_attempt_raises_exception
|
68
|
+
assert_raise Holidays::UnknownRegionError do
|
69
|
+
Holidays.between(Date.civil(2014, 1, 1), Date.civil(2016, 1, 1), '../../../../../../../../../../../../tmp/profile_pic.jpg')
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
62
73
|
private
|
63
74
|
def def_count
|
64
|
-
Dir.glob(Holidays::
|
75
|
+
Dir.glob(Holidays::FULL_DEFINITIONS_PATH + '/*.rb').size
|
65
76
|
end
|
66
77
|
end
|
data/test/test_helper.rb
CHANGED
@@ -7,9 +7,10 @@ $KCODE = 'u' if RUBY_VERSION =~ /^1\.8/
|
|
7
7
|
|
8
8
|
require 'rubygems'
|
9
9
|
require 'test/unit'
|
10
|
+
require 'mocha/test_unit'
|
10
11
|
require 'date'
|
11
12
|
require 'holidays'
|
12
|
-
require
|
13
|
+
require "#{Holidays::DEFINITIONS_PATH}/ca"
|
13
14
|
|
14
15
|
module Holidays
|
15
16
|
# Test region used for generating a holiday on Date.today
|
data/test/test_holidays.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__)) + '/test_helper'
|
2
2
|
|
3
|
-
require
|
3
|
+
require "#{Holidays::DEFINITIONS_PATH}/ca"
|
4
4
|
|
5
5
|
# Re-include CA defs via holidays/north_america to ensure that individual
|
6
6
|
# defs aren't duplicated.
|
7
|
-
require
|
7
|
+
require "#{Holidays::DEFINITIONS_PATH}/north_america"
|
8
8
|
|
9
9
|
class HolidaysTests < Test::Unit::TestCase
|
10
10
|
def setup
|
@@ -19,17 +19,6 @@ class HolidaysTests < Test::Unit::TestCase
|
|
19
19
|
assert_equal 0, holidays.length
|
20
20
|
end
|
21
21
|
|
22
|
-
def test_between
|
23
|
-
holidays = Holidays.between(Date.civil(2008,7,1), Date.civil(2008,7,1), :ca)
|
24
|
-
assert_equal 1, holidays.length
|
25
|
-
|
26
|
-
holidays = Holidays.between(Date.civil(2008,7,1), Date.civil(2008,7,31), :ca)
|
27
|
-
assert_equal 1, holidays.length
|
28
|
-
|
29
|
-
holidays = Holidays.between(Date.civil(2008,7,2), Date.civil(2008,7,31), :ca)
|
30
|
-
assert_equal 0, holidays.length
|
31
|
-
end
|
32
|
-
|
33
22
|
def test_full_week
|
34
23
|
## Full weeks:
|
35
24
|
# Try with a Monday
|
@@ -40,7 +29,7 @@ class HolidaysTests < Test::Unit::TestCase
|
|
40
29
|
assert Holidays.full_week?(Date.civil(2012,1,29), :us)
|
41
30
|
# Try Wednesday on a week going into a new month
|
42
31
|
assert Holidays.full_week?(Date.civil(2012,2,1), :us)
|
43
|
-
|
32
|
+
|
44
33
|
## Weeks with holidays:
|
45
34
|
# New Year's 2012 (on Sunday, observed Monday). Test from a Wednesday.
|
46
35
|
assert_equal(false, Holidays.full_week?(Date.civil(2012,1,4), :us))
|
@@ -53,7 +42,7 @@ class HolidaysTests < Test::Unit::TestCase
|
|
53
42
|
holidays_in_2012 = weeks_in_2012.times.count { |week| Holidays.full_week?(Date.commercial(2012,week+1), :us) == false }
|
54
43
|
assert_equal 10, holidays_in_2012
|
55
44
|
end
|
56
|
-
|
45
|
+
|
57
46
|
def test_requires_valid_regions
|
58
47
|
assert_raises Holidays::UnknownRegionError do
|
59
48
|
Holidays.on(Date.civil(2008,1,1), :xx)
|
@@ -75,7 +64,7 @@ class HolidaysTests < Test::Unit::TestCase
|
|
75
64
|
holidays = Holidays.on(@date, [:ca_bc,:ca])
|
76
65
|
assert_equal 1, holidays.length
|
77
66
|
end
|
78
|
-
|
67
|
+
|
79
68
|
def test_observed_dates
|
80
69
|
# Should fall on Tuesday the 1st
|
81
70
|
assert_equal 1, Holidays.on(Date.civil(2008,7,1), :ca, :observed).length
|
@@ -100,7 +89,7 @@ class HolidaysTests < Test::Unit::TestCase
|
|
100
89
|
holidays = Holidays.between(Date.civil(2008,5,1), Date.civil(2008,5,31))
|
101
90
|
assert holidays.length >= 3
|
102
91
|
end
|
103
|
-
|
92
|
+
|
104
93
|
def test_sub_regions
|
105
94
|
# Should return Victoria Day.
|
106
95
|
holidays = Holidays.between(Date.civil(2008,5,1), Date.civil(2008,5,31), :ca)
|
@@ -126,7 +115,7 @@ class HolidaysTests < Test::Unit::TestCase
|
|
126
115
|
assert_equal '2067-04-03', Holidays.easter(2067).to_s
|
127
116
|
assert_equal '2099-04-12', Holidays.easter(2099).to_s
|
128
117
|
end
|
129
|
-
|
118
|
+
|
130
119
|
def test_orthodox_easter
|
131
120
|
assert_equal '2000-04-30', Holidays.orthodox_easter(2000).to_s
|
132
121
|
assert_equal '2008-04-27', Holidays.orthodox_easter(2008).to_s
|
@@ -158,15 +147,21 @@ class HolidaysTests < Test::Unit::TestCase
|
|
158
147
|
}
|
159
148
|
end
|
160
149
|
|
150
|
+
#FIXME - I am not a huge fan of this test as it is written. It depends on the definitions not changing.
|
151
|
+
# I think that this is fine for an integration test but I think it should be labeled as such.
|
161
152
|
def test_caching
|
153
|
+
start_date = Date.civil(2008, 3, 21)
|
154
|
+
end_date = Date.civil(2008, 3, 25)
|
155
|
+
cache_data = Holidays.between(start_date, end_date, :ca, :informal)
|
156
|
+
options = [:ca, :informal]
|
157
|
+
|
158
|
+
Holidays::DefinitionFactory.cache_repository.expects(:cache_between).with(start_date, end_date, cache_data, options)
|
159
|
+
|
162
160
|
Holidays.cache_between(Date.civil(2008,3,21), Date.civil(2008,3,25), :ca, :informal)
|
163
161
|
|
164
|
-
# Test that cache has been set
|
165
|
-
|
166
|
-
assert_equal Date.civil(2008,3,
|
167
|
-
assert_equal Date.civil(2008,3,25), Holidays.cache_range[cache_key].end
|
168
|
-
assert_equal Date.civil(2008,3,21), Holidays.cache[cache_key].first[:date]
|
169
|
-
assert_equal Date.civil(2008,3,24), Holidays.cache[cache_key].last[:date]
|
162
|
+
# Test that cache has been set and it returns the same as before
|
163
|
+
assert_equal 1, Holidays.on(Date.civil(2008, 3, 21), :ca, :informal).length
|
164
|
+
assert_equal 1, Holidays.on(Date.civil(2008, 3, 24), :ca, :informal).length
|
170
165
|
|
171
166
|
# Test that correct results are returned outside the cache range, and with no caching
|
172
167
|
assert_equal 1, Holidays.on(Date.civil(2035,1,1), :ca, :informal).length
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__)) + '/test_helper'
|
2
|
+
|
3
|
+
require "#{Holidays::DEFINITIONS_PATH}/ca"
|
4
|
+
|
5
|
+
# Re-include CA defs via holidays/north_america to ensure that individual
|
6
|
+
# defs aren't duplicated.
|
7
|
+
#
|
8
|
+
# NOTE: this test is a mixture of integration and unit tests. It's messy and bad.
|
9
|
+
# I am not fixing it here because I am trying to clean up the 'between' use case
|
10
|
+
# and don't want to bite off more than I can chew.
|
11
|
+
require "#{Holidays::DEFINITIONS_PATH}/north_america"
|
12
|
+
|
13
|
+
class HolidaysTests < Test::Unit::TestCase
|
14
|
+
def setup
|
15
|
+
@date = Date.civil(2008,1,1)
|
16
|
+
@subject = Holidays.method(:between)
|
17
|
+
end
|
18
|
+
|
19
|
+
def teardown
|
20
|
+
Holidays::DefinitionFactory.cache_repository.reset!
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_between
|
24
|
+
holidays = @subject.call(Date.civil(2008,7,1), Date.civil(2008,7,1), :ca)
|
25
|
+
assert_equal 1, holidays.length
|
26
|
+
|
27
|
+
holidays = @subject.call(Date.civil(2008,7,1), Date.civil(2008,7,31), :ca)
|
28
|
+
assert_equal 1, holidays.length
|
29
|
+
|
30
|
+
holidays = @subject.call(Date.civil(2008,7,2), Date.civil(2008,7,31), :ca)
|
31
|
+
assert_equal 0, holidays.length
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_between_raises_error_if_missing_start_or_end_date
|
35
|
+
assert_raise ArgumentError do
|
36
|
+
@subject.call(nil, Date.civil(2015, 1, 1), :us)
|
37
|
+
end
|
38
|
+
|
39
|
+
assert_raise ArgumentError do
|
40
|
+
@subject.call(Date.civil(2015, 1, 1), nil, :us)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_cached_holidays_are_returned_if_present
|
45
|
+
start_date = Date.civil(2015, 1, 1)
|
46
|
+
end_date = Date.civil(2015, 1, 31)
|
47
|
+
options = [:us, :informal]
|
48
|
+
|
49
|
+
Holidays::DefinitionFactory.cache_repository.expects(:find).with(start_date, end_date, options).returns({cached: 'data'})
|
50
|
+
|
51
|
+
assert_equal({cached: 'data'}, @subject.call(start_date, end_date, *options))
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_options_are_parsed
|
55
|
+
start_date = Date.civil(2015, 1, 1)
|
56
|
+
end_date = Date.civil(2015, 1, 31)
|
57
|
+
options = [:us]
|
58
|
+
|
59
|
+
options_parser_mock = mock()
|
60
|
+
Holidays::OptionFactory.stubs(:parse_options).returns(options_parser_mock)
|
61
|
+
options_parser_mock.expects(:call).with(options).returns([[:us], false, false])
|
62
|
+
|
63
|
+
between_mock = mock()
|
64
|
+
Holidays::UseCaseFactory.stubs(:between).returns(between_mock)
|
65
|
+
between_mock.expects(:call).with(start_date, end_date, {2015 => [0, 1, 2], 2014 => [0, 12]}, [:us], false, false)
|
66
|
+
|
67
|
+
@subject.call(start_date, end_date, *options)
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_dates_driver_builder_is_called
|
71
|
+
start_date = Date.civil(2015, 1, 1)
|
72
|
+
end_date = Date.civil(2015, 1, 31)
|
73
|
+
options = [:us]
|
74
|
+
|
75
|
+
dates_driver_builder_mock = mock()
|
76
|
+
Holidays::UseCaseFactory.stubs(:dates_driver_builder).returns(dates_driver_builder_mock)
|
77
|
+
dates_driver_builder_mock.expects(:call).with(start_date, end_date).returns({2015 => [0, 1, 2]})
|
78
|
+
|
79
|
+
between_mock = mock()
|
80
|
+
Holidays::UseCaseFactory.stubs(:between).returns(between_mock)
|
81
|
+
between_mock.expects(:call).with(start_date, end_date, {2015 => [0, 1, 2]}, [:us], false, false)
|
82
|
+
|
83
|
+
@subject.call(start_date, end_date, *options)
|
84
|
+
end
|
85
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__)) + '/test_helper'
|
2
|
-
require
|
3
|
-
require
|
2
|
+
require "#{Holidays::DEFINITIONS_PATH}/gb"
|
3
|
+
require "#{Holidays::DEFINITIONS_PATH}/ie"
|
4
4
|
|
5
5
|
class MultipleRegionsTests < Test::Unit::TestCase
|
6
6
|
def setup
|
@@ -1,12 +1,15 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__)) + '/test_helper'
|
2
2
|
|
3
|
-
class
|
3
|
+
class ParseDefinitionsIntegrationTests < Test::Unit::TestCase
|
4
4
|
|
5
5
|
def test_single_parse_definition_file
|
6
|
-
module_src, test_src = Holidays.parse_definition_files_and_return_source(:test_region, 'test/data/test_single_custom_holiday_defs.yaml')
|
6
|
+
module_src, test_src, regions = Holidays.parse_definition_files_and_return_source(:test_region, 'test/data/test_single_custom_holiday_defs.yaml')
|
7
7
|
|
8
8
|
assert_equal false, module_src.empty?
|
9
9
|
assert_equal false, test_src.empty?
|
10
|
+
|
11
|
+
assert regions.is_a?(Array)
|
12
|
+
assert_equal false, regions.empty?
|
10
13
|
end
|
11
14
|
|
12
15
|
def test_parsing_without_def_file_results_in_error
|
@@ -16,9 +19,12 @@ class ParseDefinitionsTests < Test::Unit::TestCase
|
|
16
19
|
end
|
17
20
|
|
18
21
|
def test_parsing_of_multiple_definition_files
|
19
|
-
module_src, test_src = Holidays.parse_definition_files_and_return_source(:test_region_multiple, 'test/data/test_single_custom_holiday_defs.yaml', 'test/data/test_custom_govt_holiday_defs.yaml')
|
22
|
+
module_src, test_src, regions = Holidays.parse_definition_files_and_return_source(:test_region_multiple, 'test/data/test_single_custom_holiday_defs.yaml', 'test/data/test_custom_govt_holiday_defs.yaml')
|
20
23
|
|
21
24
|
assert_equal false, module_src.empty?
|
22
25
|
assert_equal false, test_src.empty?
|
26
|
+
|
27
|
+
assert regions.is_a?(Array)
|
28
|
+
assert_equal false, regions.empty?
|
23
29
|
end
|
24
|
-
end
|
30
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: holidays
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Dunae
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-12-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: mocha
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.0'
|
69
83
|
description: A collection of Ruby methods to deal with statutory and other holidays.
|
70
84
|
You deserve a holiday!
|
71
85
|
email:
|
@@ -74,121 +88,141 @@ executables: []
|
|
74
88
|
extensions: []
|
75
89
|
extra_rdoc_files: []
|
76
90
|
files:
|
77
|
-
- ".coveralls.yml"
|
78
91
|
- CHANGELOG.md
|
79
92
|
- Gemfile
|
80
93
|
- LICENSE
|
81
94
|
- README.md
|
82
95
|
- REFERENCES
|
83
96
|
- Rakefile
|
84
|
-
-
|
85
|
-
-
|
86
|
-
-
|
87
|
-
-
|
88
|
-
-
|
89
|
-
-
|
90
|
-
-
|
91
|
-
-
|
92
|
-
-
|
93
|
-
-
|
94
|
-
-
|
95
|
-
-
|
96
|
-
-
|
97
|
-
-
|
98
|
-
-
|
99
|
-
-
|
100
|
-
-
|
101
|
-
-
|
102
|
-
-
|
103
|
-
-
|
104
|
-
-
|
105
|
-
-
|
106
|
-
-
|
107
|
-
-
|
108
|
-
-
|
109
|
-
-
|
110
|
-
-
|
111
|
-
-
|
112
|
-
-
|
113
|
-
-
|
114
|
-
-
|
115
|
-
-
|
116
|
-
-
|
117
|
-
-
|
118
|
-
-
|
119
|
-
-
|
120
|
-
-
|
121
|
-
-
|
122
|
-
-
|
123
|
-
-
|
124
|
-
-
|
125
|
-
-
|
126
|
-
-
|
127
|
-
-
|
128
|
-
-
|
129
|
-
-
|
130
|
-
-
|
131
|
-
-
|
132
|
-
-
|
133
|
-
-
|
134
|
-
-
|
135
|
-
-
|
97
|
+
- bin/console
|
98
|
+
- bin/setup
|
99
|
+
- definitions/SYNTAX.rdoc
|
100
|
+
- definitions/ar.yaml
|
101
|
+
- definitions/at.yaml
|
102
|
+
- definitions/au.yaml
|
103
|
+
- definitions/be.yaml
|
104
|
+
- definitions/br.yaml
|
105
|
+
- definitions/ca.yaml
|
106
|
+
- definitions/ch.yaml
|
107
|
+
- definitions/cl.yaml
|
108
|
+
- definitions/cr.yaml
|
109
|
+
- definitions/cz.yaml
|
110
|
+
- definitions/de.yaml
|
111
|
+
- definitions/dk.yaml
|
112
|
+
- definitions/ecb_target.yaml
|
113
|
+
- definitions/el.yaml
|
114
|
+
- definitions/es.yaml
|
115
|
+
- definitions/federal_reserve.yaml
|
116
|
+
- definitions/fedex.yaml
|
117
|
+
- definitions/fi.yaml
|
118
|
+
- definitions/fr.yaml
|
119
|
+
- definitions/gb.yaml
|
120
|
+
- definitions/hr.yaml
|
121
|
+
- definitions/hu.yaml
|
122
|
+
- definitions/ie.yaml
|
123
|
+
- definitions/index.yaml
|
124
|
+
- definitions/is.yaml
|
125
|
+
- definitions/it.yaml
|
126
|
+
- definitions/jp.yaml
|
127
|
+
- definitions/li.yaml
|
128
|
+
- definitions/lt.yaml
|
129
|
+
- definitions/ma.yaml
|
130
|
+
- definitions/mx.yaml
|
131
|
+
- definitions/nerc.yaml
|
132
|
+
- definitions/nl.yaml
|
133
|
+
- definitions/no.yaml
|
134
|
+
- definitions/north_america_informal.yaml
|
135
|
+
- definitions/nyse.yaml
|
136
|
+
- definitions/nz.yaml
|
137
|
+
- definitions/ph.yaml
|
138
|
+
- definitions/pl.yaml
|
139
|
+
- definitions/pt.yaml
|
140
|
+
- definitions/ro.yaml
|
141
|
+
- definitions/se.yaml
|
142
|
+
- definitions/sg.yaml
|
143
|
+
- definitions/si.yaml
|
144
|
+
- definitions/sk.yaml
|
145
|
+
- definitions/united_nations.yaml
|
146
|
+
- definitions/ups.yaml
|
147
|
+
- definitions/us.yaml
|
148
|
+
- definitions/ve.yaml
|
149
|
+
- definitions/vi.yaml
|
150
|
+
- definitions/za.yaml
|
136
151
|
- holidays.gemspec
|
152
|
+
- lib/generated_definitions/MANIFEST
|
153
|
+
- lib/generated_definitions/REGIONS.rb
|
154
|
+
- lib/generated_definitions/ar.rb
|
155
|
+
- lib/generated_definitions/at.rb
|
156
|
+
- lib/generated_definitions/au.rb
|
157
|
+
- lib/generated_definitions/be.rb
|
158
|
+
- lib/generated_definitions/br.rb
|
159
|
+
- lib/generated_definitions/ca.rb
|
160
|
+
- lib/generated_definitions/ch.rb
|
161
|
+
- lib/generated_definitions/cl.rb
|
162
|
+
- lib/generated_definitions/cr.rb
|
163
|
+
- lib/generated_definitions/cz.rb
|
164
|
+
- lib/generated_definitions/de.rb
|
165
|
+
- lib/generated_definitions/dk.rb
|
166
|
+
- lib/generated_definitions/ecb_target.rb
|
167
|
+
- lib/generated_definitions/el.rb
|
168
|
+
- lib/generated_definitions/es.rb
|
169
|
+
- lib/generated_definitions/europe.rb
|
170
|
+
- lib/generated_definitions/fed_ex.rb
|
171
|
+
- lib/generated_definitions/federal_reserve.rb
|
172
|
+
- lib/generated_definitions/fi.rb
|
173
|
+
- lib/generated_definitions/fr.rb
|
174
|
+
- lib/generated_definitions/gb.rb
|
175
|
+
- lib/generated_definitions/hr.rb
|
176
|
+
- lib/generated_definitions/hu.rb
|
177
|
+
- lib/generated_definitions/ie.rb
|
178
|
+
- lib/generated_definitions/is.rb
|
179
|
+
- lib/generated_definitions/it.rb
|
180
|
+
- lib/generated_definitions/jp.rb
|
181
|
+
- lib/generated_definitions/li.rb
|
182
|
+
- lib/generated_definitions/lt.rb
|
183
|
+
- lib/generated_definitions/ma.rb
|
184
|
+
- lib/generated_definitions/mx.rb
|
185
|
+
- lib/generated_definitions/nerc.rb
|
186
|
+
- lib/generated_definitions/nl.rb
|
187
|
+
- lib/generated_definitions/no.rb
|
188
|
+
- lib/generated_definitions/north_america.rb
|
189
|
+
- lib/generated_definitions/nyse.rb
|
190
|
+
- lib/generated_definitions/nz.rb
|
191
|
+
- lib/generated_definitions/ph.rb
|
192
|
+
- lib/generated_definitions/pl.rb
|
193
|
+
- lib/generated_definitions/pt.rb
|
194
|
+
- lib/generated_definitions/ro.rb
|
195
|
+
- lib/generated_definitions/scandinavia.rb
|
196
|
+
- lib/generated_definitions/se.rb
|
197
|
+
- lib/generated_definitions/sg.rb
|
198
|
+
- lib/generated_definitions/si.rb
|
199
|
+
- lib/generated_definitions/sk.rb
|
200
|
+
- lib/generated_definitions/united_nations.rb
|
201
|
+
- lib/generated_definitions/ups.rb
|
202
|
+
- lib/generated_definitions/us.rb
|
203
|
+
- lib/generated_definitions/ve.rb
|
204
|
+
- lib/generated_definitions/vi.rb
|
205
|
+
- lib/generated_definitions/za.rb
|
137
206
|
- lib/holidays.rb
|
138
|
-
- lib/holidays/
|
139
|
-
- lib/holidays/
|
140
|
-
- lib/holidays/
|
141
|
-
- lib/holidays/
|
142
|
-
- lib/holidays/
|
143
|
-
- lib/holidays/
|
144
|
-
- lib/holidays/
|
145
|
-
- lib/holidays/
|
146
|
-
- lib/holidays/
|
147
|
-
- lib/holidays/
|
148
|
-
- lib/holidays/
|
149
|
-
- lib/holidays/
|
150
|
-
- lib/holidays/
|
151
|
-
- lib/holidays/
|
152
|
-
- lib/holidays/
|
153
|
-
- lib/holidays/
|
154
|
-
- lib/holidays/
|
155
|
-
- lib/holidays/
|
156
|
-
- lib/holidays/federal_reserve.rb
|
157
|
-
- lib/holidays/fi.rb
|
158
|
-
- lib/holidays/fr.rb
|
159
|
-
- lib/holidays/gb.rb
|
160
|
-
- lib/holidays/hr.rb
|
161
|
-
- lib/holidays/hu.rb
|
162
|
-
- lib/holidays/ie.rb
|
163
|
-
- lib/holidays/is.rb
|
164
|
-
- lib/holidays/it.rb
|
165
|
-
- lib/holidays/jp.rb
|
166
|
-
- lib/holidays/li.rb
|
167
|
-
- lib/holidays/lt.rb
|
168
|
-
- lib/holidays/ma.rb
|
169
|
-
- lib/holidays/mx.rb
|
170
|
-
- lib/holidays/nerc.rb
|
171
|
-
- lib/holidays/nl.rb
|
172
|
-
- lib/holidays/no.rb
|
173
|
-
- lib/holidays/north_america.rb
|
174
|
-
- lib/holidays/nyse.rb
|
175
|
-
- lib/holidays/nz.rb
|
176
|
-
- lib/holidays/ph.rb
|
177
|
-
- lib/holidays/pl.rb
|
178
|
-
- lib/holidays/pt.rb
|
179
|
-
- lib/holidays/ro.rb
|
180
|
-
- lib/holidays/scandinavia.rb
|
181
|
-
- lib/holidays/se.rb
|
182
|
-
- lib/holidays/sg.rb
|
183
|
-
- lib/holidays/si.rb
|
184
|
-
- lib/holidays/sk.rb
|
185
|
-
- lib/holidays/united_nations.rb
|
186
|
-
- lib/holidays/ups.rb
|
187
|
-
- lib/holidays/us.rb
|
188
|
-
- lib/holidays/ve.rb
|
207
|
+
- lib/holidays/core_extensions/date.rb
|
208
|
+
- lib/holidays/date_calculator/day_of_month.rb
|
209
|
+
- lib/holidays/date_calculator/easter.rb
|
210
|
+
- lib/holidays/date_calculator/weekend_modifier.rb
|
211
|
+
- lib/holidays/date_calculator_factory.rb
|
212
|
+
- lib/holidays/definition/context/generator.rb
|
213
|
+
- lib/holidays/definition/context/merger.rb
|
214
|
+
- lib/holidays/definition/repository/cache.rb
|
215
|
+
- lib/holidays/definition/repository/holidays_by_month.rb
|
216
|
+
- lib/holidays/definition/repository/proc_cache.rb
|
217
|
+
- lib/holidays/definition/repository/regions.rb
|
218
|
+
- lib/holidays/definition/validator/region.rb
|
219
|
+
- lib/holidays/definition_factory.rb
|
220
|
+
- lib/holidays/option/context/parse_options.rb
|
221
|
+
- lib/holidays/option_factory.rb
|
222
|
+
- lib/holidays/use_case/context/between.rb
|
223
|
+
- lib/holidays/use_case/context/dates_driver_builder.rb
|
224
|
+
- lib/holidays/use_case_factory.rb
|
189
225
|
- lib/holidays/version.rb
|
190
|
-
- lib/holidays/vi.rb
|
191
|
-
- lib/holidays/za.rb
|
192
226
|
- test/data/test_custom_govt_holiday_defs.yaml
|
193
227
|
- test/data/test_multiple_custom_holiday_defs.yaml
|
194
228
|
- test/data/test_single_custom_holiday_defs.yaml
|
@@ -244,11 +278,29 @@ files:
|
|
244
278
|
- test/defs/test_defs_ve.rb
|
245
279
|
- test/defs/test_defs_vi.rb
|
246
280
|
- test/defs/test_defs_za.rb
|
281
|
+
- test/holidays/core_extensions/test_date.rb
|
282
|
+
- test/holidays/date_calculator/test_day_of_month.rb
|
283
|
+
- test/holidays/date_calculator/test_easter.rb
|
284
|
+
- test/holidays/date_calculator/test_weekend_modifier.rb
|
285
|
+
- test/holidays/definition/context/test_generator.rb
|
286
|
+
- test/holidays/definition/context/test_merger.rb
|
287
|
+
- test/holidays/definition/repository/test_cache.rb
|
288
|
+
- test/holidays/definition/repository/test_holidays_by_month.rb
|
289
|
+
- test/holidays/definition/repository/test_proc_cache.rb
|
290
|
+
- test/holidays/definition/repository/test_regions.rb
|
291
|
+
- test/holidays/definition/validator/test_region.rb
|
292
|
+
- test/holidays/option/context/test_parse_options.rb
|
293
|
+
- test/holidays/test_date_calculator_factory.rb
|
294
|
+
- test/holidays/test_definition_factory.rb
|
295
|
+
- test/holidays/test_option_factory.rb
|
296
|
+
- test/holidays/test_use_case_factory.rb
|
297
|
+
- test/holidays/use_case/context/test_between.rb
|
298
|
+
- test/holidays/use_case/context/test_dates_driver_builder.rb
|
247
299
|
- test/test_all_regions.rb
|
248
300
|
- test/test_custom_holidays.rb
|
249
|
-
- test/test_date.rb
|
250
301
|
- test/test_helper.rb
|
251
302
|
- test/test_holidays.rb
|
303
|
+
- test/test_holidays_between.rb
|
252
304
|
- test/test_multiple_regions.rb
|
253
305
|
- test/test_parse_definitions.rb
|
254
306
|
homepage: https://github.com/alexdunae/holidays
|
@@ -271,7 +323,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
271
323
|
version: '0'
|
272
324
|
requirements: []
|
273
325
|
rubyforge_project:
|
274
|
-
rubygems_version: 2.
|
326
|
+
rubygems_version: 2.4.5
|
275
327
|
signing_key:
|
276
328
|
specification_version: 4
|
277
329
|
summary: A collection of Ruby methods to deal with statutory and other holidays.
|
@@ -331,10 +383,28 @@ test_files:
|
|
331
383
|
- test/defs/test_defs_ve.rb
|
332
384
|
- test/defs/test_defs_vi.rb
|
333
385
|
- test/defs/test_defs_za.rb
|
386
|
+
- test/holidays/core_extensions/test_date.rb
|
387
|
+
- test/holidays/date_calculator/test_day_of_month.rb
|
388
|
+
- test/holidays/date_calculator/test_easter.rb
|
389
|
+
- test/holidays/date_calculator/test_weekend_modifier.rb
|
390
|
+
- test/holidays/definition/context/test_generator.rb
|
391
|
+
- test/holidays/definition/context/test_merger.rb
|
392
|
+
- test/holidays/definition/repository/test_cache.rb
|
393
|
+
- test/holidays/definition/repository/test_holidays_by_month.rb
|
394
|
+
- test/holidays/definition/repository/test_proc_cache.rb
|
395
|
+
- test/holidays/definition/repository/test_regions.rb
|
396
|
+
- test/holidays/definition/validator/test_region.rb
|
397
|
+
- test/holidays/option/context/test_parse_options.rb
|
398
|
+
- test/holidays/test_date_calculator_factory.rb
|
399
|
+
- test/holidays/test_definition_factory.rb
|
400
|
+
- test/holidays/test_option_factory.rb
|
401
|
+
- test/holidays/test_use_case_factory.rb
|
402
|
+
- test/holidays/use_case/context/test_between.rb
|
403
|
+
- test/holidays/use_case/context/test_dates_driver_builder.rb
|
334
404
|
- test/test_all_regions.rb
|
335
405
|
- test/test_custom_holidays.rb
|
336
|
-
- test/test_date.rb
|
337
406
|
- test/test_helper.rb
|
338
407
|
- test/test_holidays.rb
|
408
|
+
- test/test_holidays_between.rb
|
339
409
|
- test/test_multiple_regions.rb
|
340
410
|
- test/test_parse_definitions.rb
|