holidays 9.1.2 → 10.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (180) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +15 -0
  3. data/README.md +38 -2
  4. data/lib/generated_definitions/MANIFEST +2 -0
  5. data/lib/generated_definitions/REGIONS.rb +2 -2
  6. data/lib/generated_definitions/au.rb +16 -42
  7. data/lib/generated_definitions/europe.rb +7 -15
  8. data/lib/generated_definitions/fr.rb +2 -2
  9. data/lib/generated_definitions/gb.rb +3 -3
  10. data/lib/generated_definitions/il.rb +74 -0
  11. data/lib/generated_definitions/lu.rb +1 -1
  12. data/lib/generated_definitions/mc.rb +36 -0
  13. data/lib/generated_definitions/northamerica.rb +3 -2
  14. data/lib/generated_definitions/nz.rb +9 -1
  15. data/lib/generated_definitions/pl.rb +3 -11
  16. data/lib/generated_definitions/us.rb +3 -2
  17. data/lib/holidays/definition/context/function_processor.rb +4 -5
  18. data/lib/holidays/definition/context/generator.rb +3 -1
  19. data/lib/holidays/version.rb +1 -1
  20. metadata +5 -309
  21. data/.github/workflows/changelog-check.yml +0 -47
  22. data/.github/workflows/release.yml +0 -46
  23. data/.github/workflows/ruby.yml +0 -26
  24. data/.gitmodules +0 -3
  25. data/CODE_OF_CONDUCT.md +0 -74
  26. data/Gemfile +0 -8
  27. data/Makefile +0 -56
  28. data/Rakefile +0 -128
  29. data/bin/console +0 -7
  30. data/bin/setup +0 -6
  31. data/doc/CONTRIBUTING.md +0 -72
  32. data/doc/MAINTAINERS.md +0 -79
  33. data/doc/REFERENCES +0 -19
  34. data/holidays.gemspec +0 -31
  35. data/test/coverage_report.rb +0 -24
  36. data/test/data/test_custom_year_range_holiday_defs.yaml +0 -31
  37. data/test/data/test_date_transform_conflict_region_1.yaml +0 -14
  38. data/test/data/test_date_transform_conflict_region_2.yaml +0 -14
  39. data/test/data/test_invalid_region.rb +0 -15
  40. data/test/data/test_region.rb +0 -15
  41. data/test/data/test_single_custom_holiday_defs.yaml +0 -12
  42. data/test/data/test_single_custom_holiday_with_custom_procs.yaml +0 -28
  43. data/test/defs/test_defs_ar.rb +0 -69
  44. data/test/defs/test_defs_at.rb +0 -31
  45. data/test/defs/test_defs_au.rb +0 -233
  46. data/test/defs/test_defs_be_fr.rb +0 -45
  47. data/test/defs/test_defs_be_nl.rb +0 -45
  48. data/test/defs/test_defs_bg.rb +0 -41
  49. data/test/defs/test_defs_br.rb +0 -49
  50. data/test/defs/test_defs_ca.rb +0 -289
  51. data/test/defs/test_defs_ch.rb +0 -51
  52. data/test/defs/test_defs_cl.rb +0 -69
  53. data/test/defs/test_defs_co.rb +0 -113
  54. data/test/defs/test_defs_cr.rb +0 -29
  55. data/test/defs/test_defs_cy.rb +0 -41
  56. data/test/defs/test_defs_cz.rb +0 -37
  57. data/test/defs/test_defs_de.rb +0 -91
  58. data/test/defs/test_defs_dk.rb +0 -47
  59. data/test/defs/test_defs_ecbtarget.rb +0 -27
  60. data/test/defs/test_defs_ee.rb +0 -41
  61. data/test/defs/test_defs_es.rb +0 -137
  62. data/test/defs/test_defs_europe.rb +0 -1526
  63. data/test/defs/test_defs_fed_ex.rb +0 -24
  64. data/test/defs/test_defs_federalreserve.rb +0 -119
  65. data/test/defs/test_defs_federalreservebanks.rb +0 -251
  66. data/test/defs/test_defs_fedex.rb +0 -31
  67. data/test/defs/test_defs_fi.rb +0 -59
  68. data/test/defs/test_defs_fr.rb +0 -43
  69. data/test/defs/test_defs_gb.rb +0 -159
  70. data/test/defs/test_defs_ge.rb +0 -53
  71. data/test/defs/test_defs_gr.rb +0 -41
  72. data/test/defs/test_defs_hk.rb +0 -93
  73. data/test/defs/test_defs_hr.rb +0 -45
  74. data/test/defs/test_defs_hu.rb +0 -47
  75. data/test/defs/test_defs_ie.rb +0 -53
  76. data/test/defs/test_defs_in.rb +0 -94
  77. data/test/defs/test_defs_is.rb +0 -51
  78. data/test/defs/test_defs_it.rb +0 -57
  79. data/test/defs/test_defs_jp.rb +0 -159
  80. data/test/defs/test_defs_ke.rb +0 -31
  81. data/test/defs/test_defs_kr.rb +0 -37
  82. data/test/defs/test_defs_kz.rb +0 -39
  83. data/test/defs/test_defs_li.rb +0 -35
  84. data/test/defs/test_defs_lt.rb +0 -65
  85. data/test/defs/test_defs_lu.rb +0 -35
  86. data/test/defs/test_defs_lv.rb +0 -98
  87. data/test/defs/test_defs_ma.rb +0 -29
  88. data/test/defs/test_defs_mt_en.rb +0 -41
  89. data/test/defs/test_defs_mt_mt.rb +0 -41
  90. data/test/defs/test_defs_mx.rb +0 -49
  91. data/test/defs/test_defs_my.rb +0 -23
  92. data/test/defs/test_defs_nerc.rb +0 -29
  93. data/test/defs/test_defs_ng.rb +0 -29
  94. data/test/defs/test_defs_nl.rb +0 -33
  95. data/test/defs/test_defs_no.rb +0 -43
  96. data/test/defs/test_defs_northamerica.rb +0 -674
  97. data/test/defs/test_defs_nyse.rb +0 -46
  98. data/test/defs/test_defs_nz.rb +0 -67
  99. data/test/defs/test_defs_pe.rb +0 -47
  100. data/test/defs/test_defs_ph.rb +0 -29
  101. data/test/defs/test_defs_pl.rb +0 -229
  102. data/test/defs/test_defs_pt.rb +0 -47
  103. data/test/defs/test_defs_ro.rb +0 -69
  104. data/test/defs/test_defs_rs_cyrl.rb +0 -46
  105. data/test/defs/test_defs_rs_la.rb +0 -46
  106. data/test/defs/test_defs_ru.rb +0 -34
  107. data/test/defs/test_defs_scandinavia.rb +0 -215
  108. data/test/defs/test_defs_se.rb +0 -59
  109. data/test/defs/test_defs_sg.rb +0 -25
  110. data/test/defs/test_defs_si.rb +0 -105
  111. data/test/defs/test_defs_sk.rb +0 -37
  112. data/test/defs/test_defs_southamerica.rb +0 -327
  113. data/test/defs/test_defs_th.rb +0 -33
  114. data/test/defs/test_defs_tn.rb +0 -27
  115. data/test/defs/test_defs_tr.rb +0 -60
  116. data/test/defs/test_defs_tsx.rb +0 -70
  117. data/test/defs/test_defs_ua.rb +0 -41
  118. data/test/defs/test_defs_unitednations.rb +0 -11
  119. data/test/defs/test_defs_ups.rb +0 -31
  120. data/test/defs/test_defs_us.rb +0 -394
  121. data/test/defs/test_defs_ve.rb +0 -35
  122. data/test/defs/test_defs_vi.rb +0 -22
  123. data/test/defs/test_defs_za.rb +0 -35
  124. data/test/e2e/README.md +0 -52
  125. data/test/e2e/data/test_multiple_regions_with_conflicts_region_1.yaml +0 -38
  126. data/test/e2e/data/test_multiple_regions_with_conflicts_region_2.yaml +0 -38
  127. data/test/e2e/data/test_multiple_regions_with_conflicts_region_3.yaml +0 -38
  128. data/test/e2e/test_all_regions.rb +0 -49
  129. data/test/e2e/test_any_holidays_during_work_week.rb +0 -90
  130. data/test/e2e/test_holidays.rb +0 -244
  131. data/test/e2e/test_holidays_between.rb +0 -87
  132. data/test/e2e/test_multiple_regions.rb +0 -71
  133. data/test/e2e/test_multiple_regions_with_conflict.rb +0 -228
  134. data/test/e2e/test_nonstandard_regions.rb +0 -25
  135. data/test/holidays/core_extensions/test_date.rb +0 -122
  136. data/test/holidays/core_extensions/test_date_time.rb +0 -60
  137. data/test/holidays/date_calculator/test_day_of_month.rb +0 -27
  138. data/test/holidays/date_calculator/test_easter_gregorian.rb +0 -30
  139. data/test/holidays/date_calculator/test_easter_julian.rb +0 -36
  140. data/test/holidays/date_calculator/test_lunar_date.rb +0 -89
  141. data/test/holidays/date_calculator/test_weekend_modifier.rb +0 -54
  142. data/test/holidays/definition/context/test_function_processor.rb +0 -199
  143. data/test/holidays/definition/context/test_generator.rb +0 -226
  144. data/test/holidays/definition/context/test_load.rb +0 -37
  145. data/test/holidays/definition/context/test_merger.rb +0 -25
  146. data/test/holidays/definition/decorator/test_custom_method_proc.rb +0 -113
  147. data/test/holidays/definition/decorator/test_custom_method_source.rb +0 -96
  148. data/test/holidays/definition/decorator/test_test.rb +0 -123
  149. data/test/holidays/definition/generator/test_module.rb +0 -268
  150. data/test/holidays/definition/generator/test_regions.rb +0 -97
  151. data/test/holidays/definition/generator/test_test.rb +0 -113
  152. data/test/holidays/definition/parser/test_custom_method.rb +0 -79
  153. data/test/holidays/definition/parser/test_test.rb +0 -142
  154. data/test/holidays/definition/repository/test_cache.rb +0 -123
  155. data/test/holidays/definition/repository/test_custom_methods.rb +0 -43
  156. data/test/holidays/definition/repository/test_holidays_by_month.rb +0 -275
  157. data/test/holidays/definition/repository/test_proc_result_cache.rb +0 -91
  158. data/test/holidays/definition/repository/test_regions.rb +0 -104
  159. data/test/holidays/definition/validator/test_custom_method.rb +0 -94
  160. data/test/holidays/definition/validator/test_region.rb +0 -54
  161. data/test/holidays/definition/validator/test_test.rb +0 -60
  162. data/test/holidays/finder/context/test_between.rb +0 -172
  163. data/test/holidays/finder/context/test_dates_driver_builder.rb +0 -91
  164. data/test/holidays/finder/context/test_next_holiday.rb +0 -156
  165. data/test/holidays/finder/context/test_parse_options.rb +0 -141
  166. data/test/holidays/finder/context/test_search.rb +0 -290
  167. data/test/holidays/finder/context/test_year_holiday.rb +0 -202
  168. data/test/holidays/finder/rules/test_in_region.rb +0 -42
  169. data/test/holidays/finder/rules/test_year_range.rb +0 -166
  170. data/test/integration/README.md +0 -48
  171. data/test/integration/data/test_custom_govt_holiday_defs.yaml +0 -5
  172. data/test/integration/data/test_custom_informal_holidays_defs.yaml +0 -11
  173. data/test/integration/data/test_multiple_custom_holiday_defs.yaml +0 -12
  174. data/test/integration/test_custom_holidays.rb +0 -41
  175. data/test/integration/test_custom_informal_holidays.rb +0 -15
  176. data/test/integration/test_custom_year_range_holidays.rb +0 -35
  177. data/test/smoke/README.md +0 -31
  178. data/test/smoke/test_available_regions.rb +0 -18
  179. data/test/smoke/test_smoke.rb +0 -74
  180. data/test/test_helper.rb +0 -37
@@ -1,156 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__)) + '/../../../test_helper'
2
-
3
- require 'holidays/finder/context/next_holiday'
4
-
5
- class NextHolidayTests < Test::Unit::TestCase
6
- def setup
7
- @regions = [:us]
8
- @observed = false
9
- @informal = false
10
-
11
- @definition_search = mock()
12
- @dates_driver_builder = mock()
13
- @options_parser = mock()
14
-
15
- @subject = Holidays::Finder::Context::NextHoliday.new(
16
- @definition_search,
17
- @dates_driver_builder,
18
- @options_parser,
19
- )
20
-
21
- @holiday_count = 1
22
- @from_date= Date.civil(2015, 1, 1)
23
- @dates_driver = {2015 => [0, 1, 2], 2014 => [0, 12]}
24
- @options = [@regions, @observed, @informal]
25
-
26
- @definition_search.expects(:call).at_most_once.with(
27
- @dates_driver,
28
- @regions,
29
- [],
30
- ).returns([{
31
- :date => Date.civil(2015, 1, 1),
32
- :name => "Test",
33
- :regions => [:us],
34
- }])
35
-
36
- @dates_driver_builder.expects(:call).at_most_once.with(
37
- @from_date, @from_date >> 12,
38
- ).returns(
39
- @dates_driver,
40
- )
41
-
42
- @options_parser.expects(:call).at_most_once.with(@options).returns(@options)
43
- end
44
-
45
- def test_returns_error_if_holidays_count_is_missing
46
- assert_raise ArgumentError do
47
- @subject.call(nil, @from_date, @options)
48
- end
49
- end
50
-
51
- def test_returns_error_if_holidays_count_is_less_than_or_equal_to_zero
52
- assert_raise ArgumentError do
53
- @subject.call(0, @from_date, @options)
54
- end
55
- end
56
-
57
- def test_returns_error_if_from_date_is_missing
58
- assert_raise ArgumentError do
59
- @subject.call(@holiday_count, nil, @options)
60
- end
61
- end
62
-
63
- def test_returns_single_holiday
64
- assert_equal(
65
- [
66
- {
67
- :date => Date.civil(2015, 1, 1),
68
- :name => "Test",
69
- :regions => [:us],
70
- }
71
- ],
72
- @subject.call(@holiday_count, @from_date, @options)
73
- )
74
- end
75
-
76
- def test_returns_correct_holidays_based_on_holiday_count
77
- @definition_search.expects(:call).at_most_once.with(
78
- @dates_driver,
79
- @regions,
80
- [],
81
- ).returns([
82
- {
83
- :date => Date.civil(2015, 1, 1),
84
- :name => "Test",
85
- :regions => [:us],
86
- },
87
- {
88
- :date => Date.civil(2015, 2, 1),
89
- :name => "Test",
90
- :regions => [:us],
91
- },
92
- {
93
- :date => Date.civil(2015, 12, 1),
94
- :name => "Test",
95
- :regions => [:us],
96
- },
97
- ])
98
-
99
- assert_equal(
100
- [
101
- {
102
- :date => Date.civil(2015, 1, 1),
103
- :name => "Test",
104
- :regions => [:us],
105
- },
106
- {
107
- :date => Date.civil(2015, 2, 1),
108
- :name => "Test",
109
- :regions => [:us],
110
- }
111
- ],
112
- @subject.call(2, @from_date, @options)
113
- )
114
- end
115
-
116
- def test_returns_correctly_sorted_holidays_based_on_holiday_count_if_holidays_are_out_of_order
117
- @definition_search.expects(:call).at_most_once.with(
118
- @dates_driver,
119
- @regions,
120
- [],
121
- ).returns([
122
- {
123
- :date => Date.civil(2015, 1, 1),
124
- :name => "Test",
125
- :regions => [:us],
126
- },
127
- {
128
- :date => Date.civil(2015, 12, 1),
129
- :name => "Test",
130
- :regions => [:us],
131
- },
132
- {
133
- :date => Date.civil(2015, 2, 1),
134
- :name => "Test",
135
- :regions => [:us],
136
- },
137
- ]
138
- )
139
-
140
- assert_equal(
141
- [
142
- {
143
- :date => Date.civil(2015, 1, 1),
144
- :name => "Test",
145
- :regions => [:us],
146
- },
147
- {
148
- :date => Date.civil(2015, 2, 1),
149
- :name => "Test",
150
- :regions => [:us],
151
- }
152
- ],
153
- @subject.call(2, @from_date, @options)
154
- )
155
- end
156
- end
@@ -1,141 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__)) + '/../../../test_helper'
2
-
3
- require 'holidays/finder/context/parse_options'
4
-
5
- class ParseOptionsTests < Test::Unit::TestCase
6
- def setup
7
- @regions_repo = mock()
8
- @regions_repo.stubs(:loaded?).returns(false)
9
-
10
- @region_validator = mock()
11
- @region_validator.stubs(:valid?).returns(true)
12
-
13
- @definition_loader = mock()
14
- @definition_loader.stubs(:call)
15
-
16
- @subject = Holidays::Finder::Context::ParseOptions.new(
17
- @regions_repo,
18
- @region_validator,
19
- @definition_loader,
20
- )
21
- end
22
-
23
- def test_returns_observed_true_if_options_contains_observed_flag
24
- @regions_repo.expects(:parent_region_lookup).with(:ca).returns(:ca)
25
- observed = @subject.call([:ca, :observed])[1]
26
- assert_equal(true, observed)
27
- end
28
-
29
- def test_returns_observed_false_if_options_does_not_contain_observed_flag
30
- @regions_repo.expects(:parent_region_lookup).with(:ca).returns(:ca)
31
- observed = @subject.call([:ca])[1]
32
- assert_equal(false, observed)
33
- end
34
-
35
- def test_returns_informal_true_if_options_contains_informal_flag
36
- @regions_repo.expects(:parent_region_lookup).with(:ca).returns(:ca)
37
- informal = @subject.call([:ca, :informal])[2]
38
- assert_equal(true, informal)
39
- end
40
-
41
- def test_returns_informal_false_if_options_does_not_contain_informal_flag
42
- @regions_repo.expects(:parent_region_lookup).with(:ca).returns(:ca)
43
- informal = @subject.call([:ca])[2]
44
- assert_equal(false, informal)
45
- end
46
-
47
- def test_raises_error_if_regions_are_invalid
48
- @region_validator.stubs(:valid?).returns(false)
49
-
50
- assert_raise Holidays::InvalidRegion do
51
- @subject.call([:unknown_region])
52
- end
53
- end
54
-
55
- def test_wildcards_load_appropriate_regions
56
- @definition_loader.expects(:call).with(:ch).returns([:ch, :ch_zh])
57
-
58
- regions = @subject.call([:ch_]).first
59
-
60
- assert_equal([:ch, :ch_zh], regions)
61
- assert_equal(false, regions.include?(:ch_))
62
- end
63
-
64
- def test_does_nothing_if_region_is_already_loaded_and_is_parent
65
- @regions_repo.expects(:parent_region_lookup).with(:test).returns(nil)
66
- regions = @subject.call([:test]).first
67
- assert_equal([:test], regions)
68
- end
69
-
70
- def test_does_nothing_if_region_is_already_loaded_and_is_parent_but_is_custom
71
- @regions_repo.expects(:parent_region_lookup).with(:custom_region).returns(nil)
72
- @regions_repo.expects(:loaded?).with(:custom_region).returns(true)
73
-
74
- regions = @subject.call([:custom_region]).first
75
- assert_equal([:custom_region], regions)
76
- end
77
-
78
- def test_has_parent_loads_parent_region
79
- @regions_repo.expects(:parent_region_lookup).with(:subregion).returns(:parent)
80
- @regions_repo.expects(:loaded?).with(:parent).returns(false)
81
- @definition_loader.expects(:call).with(:parent).returns([:parent, :subregion])
82
-
83
- regions = @subject.call([:subregion]).first
84
- assert_equal([:subregion], regions)
85
- end
86
-
87
- def test_has_parent_already_loaded_does_not_load_again
88
- @regions_repo.expects(:parent_region_lookup).with(:subregion).returns(:parent)
89
- @regions_repo.expects(:loaded?).with(:parent).returns(false)
90
- @definition_loader.expects(:call).with(:parent).returns([:parent, :subregion])
91
-
92
- regions = @subject.call([:subregion]).first
93
- assert_equal([:subregion], regions)
94
- end
95
-
96
- def test_cannot_load_region_prefix_for_wildcard_raises_error
97
- @definition_loader.expects(:call).with(:ch).raises(LoadError)
98
- assert_raises Holidays::UnknownRegionError do
99
- @subject.call([:ch_])
100
- end
101
- end
102
-
103
- def test_cannot_load_region_not_wildcard_raises_error
104
- @regions_repo.expects(:parent_region_lookup).with(:ch).returns(:ch)
105
- @definition_loader.expects(:call).with(:ch).raises(LoadError)
106
- assert_raises Holidays::UnknownRegionError do
107
- @subject.call([:ch])
108
- end
109
- end
110
-
111
- def test_region_with_multiple_underscores_load_correctly
112
- @regions_repo.expects(:parent_region_lookup).with(:subregion_with_underscores).returns(:parent)
113
- @regions_repo.expects(:loaded?).with(:parent).returns(false)
114
- @definition_loader.expects(:call).with(:parent).returns([:parent, :subregion_with_underscores])
115
-
116
- regions = @subject.call([:subregion_with_underscores]).first
117
- assert_equal([:subregion_with_underscores], regions)
118
- end
119
-
120
- def test_blank_region_should_load_all_regions_available
121
- @regions_repo.expects(:all_generated).returns([:region1, :region2])
122
- @regions_repo.expects(:loaded?).with(:region1).returns(false)
123
- @regions_repo.expects(:loaded?).with(:region2).returns(true)
124
- @regions_repo.expects(:parent_region_lookup).with(:region1).returns(:region2)
125
- @definition_loader.expects(:call).with(:region2)
126
-
127
- regions = @subject.call.first
128
- assert_equal([:region1, :region2], regions)
129
- end
130
-
131
- def test_special_any_region_should_load_all_regions_available
132
- @regions_repo.expects(:all_generated).returns([:region1, :region2])
133
- @regions_repo.expects(:loaded?).with(:region1).returns(false)
134
- @regions_repo.expects(:loaded?).with(:region2).returns(true)
135
- @regions_repo.expects(:parent_region_lookup).with(:region1).returns(:region2)
136
- @definition_loader.expects(:call).with(:region2)
137
-
138
- regions = @subject.call(:any).first
139
- assert_equal([:region1, :region2], regions)
140
- end
141
- end
@@ -1,290 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__)) + '/../../../test_helper'
2
-
3
- require 'holidays/finder/context/search'
4
-
5
- class FinderSearchTests < Test::Unit::TestCase
6
- def setup
7
- @holidays_by_month_repo = mock()
8
- @custom_method_processor = mock()
9
- @day_of_month_calculator = mock()
10
-
11
- @in_region_rule = mock()
12
- @year_range_rule = mock()
13
- @rules = {:in_region => @in_region_rule, :year_range => @year_range_rule}
14
-
15
- @custom_method_repo = mock()
16
- @proc_cache_repo = mock()
17
-
18
- @start_date = Date.civil(2015, 1, 1)
19
- @end_date = Date.civil(2015, 1, 1)
20
- @dates_driver = {2015 => [1]}
21
- @regions = [:us]
22
- @options = []
23
-
24
- @holidays_by_month_repo.expects(:find_by_month).at_most_once.returns([:mday => 1, :name => "Test", :regions=>@regions])
25
- @in_region_rule.expects(:call).at_most_once.returns(true)
26
- @year_range_rule.expects(:call).at_most_once.returns(false)
27
-
28
- @subject = Holidays::Finder::Context::Search.new(
29
- @holidays_by_month_repo,
30
- @custom_method_processor,
31
- @day_of_month_calculator,
32
- @rules,
33
- )
34
- end
35
-
36
- def test_raises_error_if_dates_driver_is_empty
37
- @dates_driver = {}
38
- assert_raises ArgumentError do
39
- @subject.call(@dates_driver, @regions, @options)
40
- end
41
- end
42
-
43
- def test_raises_error_if_dates_driver_contains_bad_month
44
- @dates_driver = {2015 => [100]}
45
- assert_raises ArgumentError do
46
- @subject.call(@dates_driver, @regions, @options)
47
- end
48
- end
49
-
50
- def test_raises_error_if_dates_driver_contains_bad_month_mixed_with_valid_months
51
- @dates_driver = {2015 => [1, 12], 2020 => [1, 200]}
52
- assert_raises ArgumentError do
53
- @subject.call(@dates_driver, @regions, @options)
54
- end
55
- end
56
-
57
- def test_returns_nothing_if_holidays_repo_returns_nil
58
- @holidays_by_month_repo.expects(:find_by_month).with(1).returns(nil)
59
- assert_equal([], @subject.call(@dates_driver, @regions, @options))
60
- end
61
-
62
- def test_returns_nothing_if_holidays_repo_returns_empty_array
63
- @holidays_by_month_repo.expects(:find_by_month).with(1).returns([])
64
- assert_equal([], @subject.call(@dates_driver, @regions, @options))
65
- end
66
-
67
- def test_returns_nothing_if_holidays_not_in_region
68
- @holidays_by_month_repo.expects(:find_by_month).returns([:regions=>[:other_region]])
69
- @in_region_rule.expects(:call).with(@regions, [:other_region]).returns(false)
70
- assert_equal([], @subject.call(@dates_driver, @regions, @options))
71
- end
72
-
73
- def test_returns_nothing_if_only_informal_holidays_are_returned_and_no_informal_flag_set
74
- @holidays_by_month_repo.expects(:find_by_month).returns([:type => :informal, :regions=>@regions])
75
- assert_equal([], @subject.call(@dates_driver, @regions, @options))
76
- end
77
-
78
- def test_year_rule_set_but_not_in_required_years_returns_nothing
79
- @holidays_by_month_repo.expects(:find_by_month).at_most_once.returns([:mday => 1, :name => "Test", :regions=>@regions, :year_ranges => [:after => 2000]])
80
- assert_equal([], @subject.call(@dates_driver, @regions, @options))
81
- end
82
-
83
- def test_function_present_returns_date
84
- @holidays_by_month_repo.expects(:find_by_month).at_most_once.returns([:mday => 1, :name => "Test", :regions=> @regions, :function => "func-id", :function_arguments => [:year], :function_modifier => 1])
85
-
86
- returned_date = Date.civil(2015, 3, 10)
87
- @custom_method_processor.expects(:call).with(
88
- {:year => 2015, :month => 1, :day => 1, :region => :us},
89
- "func-id",
90
- [:year],
91
- 1,
92
- ).returns(returned_date)
93
-
94
- assert_equal(
95
- [{
96
- :date => Date.civil(2015, 3, 10),
97
- :name => "Test",
98
- :regions => [:us],
99
- }],
100
- @subject.call(@dates_driver, @regions, @options)
101
- )
102
- end
103
-
104
- #FIXME This is a test that reflects how the current system works
105
- # but this is NOT valid. See https://github.com/holidays/holidays/issues/204
106
- def test_function_returns_nil_date_should_not_be_returned
107
- @holidays_by_month_repo.expects(:find_by_month).at_most_once.returns([:mday => 1, :name => "Test", :regions=> @regions, :function => "func-id", :function_arguments => [:year], :function_modifier => 1])
108
-
109
- @custom_method_processor.expects(:call).with(
110
- {:year => 2015, :month => 1, :day => 1, :region => :us},
111
- "func-id",
112
- [:year],
113
- 1,
114
- ).returns(nil)
115
-
116
- assert_equal([], @subject.call(@dates_driver, @regions, @options))
117
- end
118
-
119
- def test_function_not_present_mday_set
120
- @holidays_by_month_repo.expects(:find_by_month).at_most_once.returns([:mday => 15, :name => "Test", :regions=> @regions])
121
-
122
- assert_equal(
123
- [{
124
- :date => Date.civil(2015, 1, 15),
125
- :name => "Test",
126
- :regions => [:us],
127
- }],
128
- @subject.call(@dates_driver, @regions, @options)
129
- )
130
- end
131
-
132
- def test_function_not_present_mday_not_set
133
- @holidays_by_month_repo.expects(:find_by_month).at_most_once.returns([:name => "Test", :week => 1, :wday => 1, :regions=> @regions])
134
-
135
- @day_of_month_calculator.expects(:call).with(2015, 1, 1, 1).returns(20)
136
-
137
- assert_equal(
138
- [{
139
- :date => Date.civil(2015, 1, 20),
140
- :name => "Test",
141
- :regions => [:us],
142
- }],
143
- @subject.call(@dates_driver, @regions, @options)
144
- )
145
- end
146
-
147
- def test_returns_holiday_if_informal_and_informal_flag_set
148
- @holidays_by_month_repo.expects(:find_by_month).at_most_once.returns([:mday => 13, :name => "Test", :type => :informal, :regions=>@regions])
149
-
150
- assert_equal(
151
- [{
152
- :date => Date.civil(2015, 1, 13),
153
- :name => "Test",
154
- :regions => [:us],
155
- }],
156
- @subject.call(@dates_driver, @regions, [:informal])
157
- )
158
- end
159
-
160
- def test_does_not_return_holiday_if_informal_and_informal_flag_not_set
161
- @holidays_by_month_repo.expects(:find_by_month).at_most_once.returns([:mday => 13, :name => "Test", :type => :informal, :regions=>@regions])
162
-
163
- assert_equal([], @subject.call(@dates_driver, @regions, @options))
164
- end
165
-
166
- def test_returns_observed_result_if_observed_set_and_observed_function_present
167
- @holidays_by_month_repo.expects(:find_by_month).at_most_once.returns([:mday => 8, :name => "Test", :type => :observed, :observed => "SOME_OBSERVED_FUNC_ID", :regions=>@regions])
168
-
169
- @custom_method_processor.expects(:call).with(
170
- {:year => 2015, :month => 1, :day => 8, :region => :us},
171
- "SOME_OBSERVED_FUNC_ID",
172
- [:date],
173
- ).returns(Date.civil(2015, 10, 1))
174
-
175
- assert_equal(
176
- [{
177
- :date => Date.civil(2015, 10, 1),
178
- :name => "Test",
179
- :regions => [:us],
180
- }],
181
- @subject.call(@dates_driver, @regions, [:observed])
182
- )
183
- end
184
-
185
- def test_returns_unobserved_date_if_observed_method_not_set_but_flag_is_present
186
- @holidays_by_month_repo.expects(:find_by_month).at_most_once.returns([:mday => 14, :name => "Test", :type => :observed, :observed => "SOME_OBSERVED_FUNC_ID", :regions=>@regions])
187
-
188
- assert_equal(
189
- [{
190
- :date => Date.civil(2015, 1, 14),
191
- :name => "Test",
192
- :regions => [:us],
193
- }],
194
- @subject.call(@dates_driver, @regions, @options)
195
- )
196
- end
197
-
198
- # This is a specific scenario but it COULD happen in our current flow. The goal: any date
199
- # manipulation that occurs for a specific holiday should have no impact on other holidays.
200
- def test_returns_expected_result_if_custom_method_modifies_month_when_multiple_holidays_found
201
- @in_region_rule.expects(:call).twice.returns(true)
202
- @holidays_by_month_repo.expects(:find_by_month).at_most_once.returns(
203
- [
204
- {:mday => 14, :name => "Test", :function => "func-id", :function_arguments => [:year], :regions => @regions},
205
- {:mday => 14, :name => "Test2", :regions => @regions},
206
- ]
207
- )
208
-
209
- @custom_method_processor.expects(:call).with(
210
- {:year => 2015, :month => 1, :day => 14, :region => :us},
211
- "func-id",
212
- [:year],
213
- nil,
214
- ).returns(Date.civil(2015, 3, 14))
215
-
216
- assert_equal(
217
- [
218
- {
219
- :date => Date.civil(2015, 3, 14),
220
- :name => "Test",
221
- :regions => [:us],
222
- },
223
- {
224
- :date => Date.civil(2015, 1, 14),
225
- :name => "Test2",
226
- :regions => [:us],
227
- }
228
- ],
229
- @subject.call(@dates_driver, @regions, @options)
230
- )
231
- end
232
-
233
- def test_nil_returned_from_one_region_function_does_not_suppress_valid_result_from_other_region
234
- two_regions = [:r1, :r2]
235
-
236
- @holidays_by_month_repo.expects(:find_by_month).at_most_once.returns(
237
- [{ mday: 1, name: "Test", regions: two_regions, function: "func-id", function_arguments: [:year], function_modifier: nil }]
238
- )
239
- @in_region_rule.expects(:call).with(two_regions, two_regions).returns(true)
240
-
241
- @custom_method_processor.expects(:call).with(
242
- { year: 2015, month: 1, day: 1, region: :r1 }, "func-id", [:year], nil,
243
- ).returns(nil)
244
-
245
- @custom_method_processor.expects(:call).with(
246
- { year: 2015, month: 1, day: 1, region: :r2 }, "func-id", [:year], nil,
247
- ).returns(Date.civil(2015, 6, 15))
248
-
249
- result = @subject.call(@dates_driver, two_regions, [])
250
- assert_equal 1, result.count
251
- assert_equal Date.civil(2015, 6, 15), result.first[:date]
252
- end
253
-
254
- def test_conflicting_function_in_two_regions_evaluates_each_independently
255
- two_regions = [:r1, :r2]
256
-
257
- @holidays_by_month_repo.expects(:find_by_month).at_most_once.returns(
258
- [{ mday: 1, name: "Test", regions: two_regions, function: "func-id", function_arguments: [:year], function_modifier: nil }]
259
- )
260
- @in_region_rule.expects(:call).with(two_regions, two_regions).returns(true)
261
-
262
- @custom_method_processor.expects(:call).with(
263
- { year: 2015, month: 1, day: 1, region: :r1 }, "func-id", [:year], nil,
264
- ).returns(Date.civil(2015, 3, 10))
265
-
266
- @custom_method_processor.expects(:call).with(
267
- { year: 2015, month: 1, day: 1, region: :r2 }, "func-id", [:year], nil,
268
- ).returns(Date.civil(2015, 6, 15))
269
-
270
- result = @subject.call(@dates_driver, two_regions, [])
271
- assert_equal 2, result.count
272
- assert result.any? { |h| h[:date] == Date.civil(2015, 3, 10) }
273
- assert result.any? { |h| h[:date] == Date.civil(2015, 6, 15) }
274
- end
275
-
276
- def test_any_region_query_with_function_evaluates_function_exactly_once
277
- @holidays_by_month_repo.expects(:find_by_month).at_most_once.returns(
278
- [{ mday: 1, name: "Test", regions: [:r1], function: "func-id", function_arguments: [:year], function_modifier: nil }]
279
- )
280
- @in_region_rule.expects(:call).with([:any], [:r1]).returns(true)
281
-
282
- @custom_method_processor.expects(:call).with(
283
- { year: 2015, month: 1, day: 1, region: :any }, "func-id", [:year], nil,
284
- ).returns(Date.civil(2015, 3, 10))
285
-
286
- result = @subject.call(@dates_driver, [:any], [])
287
- assert_equal 1, result.count
288
- assert_equal Date.civil(2015, 3, 10), result.first[:date]
289
- end
290
- end