holidays 2.2.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (212) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +11 -0
  3. data/README.md +22 -8
  4. data/Rakefile +26 -8
  5. data/bin/console +7 -0
  6. data/bin/setup +5 -0
  7. data/{data → definitions}/SYNTAX.rdoc +0 -0
  8. data/{data → definitions}/ar.yaml +0 -0
  9. data/{data → definitions}/at.yaml +1 -1
  10. data/{data → definitions}/au.yaml +80 -51
  11. data/{data → definitions}/be.yaml +0 -0
  12. data/{data → definitions}/br.yaml +0 -0
  13. data/{data → definitions}/ca.yaml +0 -0
  14. data/{data → definitions}/ch.yaml +0 -0
  15. data/{data → definitions}/cl.yaml +0 -0
  16. data/{data → definitions}/cr.yaml +0 -0
  17. data/{data → definitions}/cz.yaml +0 -0
  18. data/{data → definitions}/de.yaml +25 -34
  19. data/{data → definitions}/dk.yaml +0 -0
  20. data/{data → definitions}/ecb_target.yaml +2 -2
  21. data/{data → definitions}/el.yaml +0 -0
  22. data/{data → definitions}/es.yaml +37 -26
  23. data/{data → definitions}/federal_reserve.yaml +0 -0
  24. data/{data → definitions}/fedex.yaml +9 -3
  25. data/{data → definitions}/fi.yaml +0 -0
  26. data/{data → definitions}/fr.yaml +0 -0
  27. data/{data → definitions}/gb.yaml +19 -19
  28. data/{data → definitions}/hr.yaml +0 -0
  29. data/{data → definitions}/hu.yaml +1 -1
  30. data/{data → definitions}/ie.yaml +0 -0
  31. data/{data → definitions}/index.yaml +0 -0
  32. data/{data → definitions}/is.yaml +0 -0
  33. data/{data → definitions}/it.yaml +0 -0
  34. data/{data → definitions}/jp.yaml +3 -3
  35. data/{data → definitions}/li.yaml +3 -3
  36. data/{data → definitions}/lt.yaml +0 -0
  37. data/{data → definitions}/ma.yaml +0 -0
  38. data/{data → definitions}/mx.yaml +0 -0
  39. data/{data → definitions}/nerc.yaml +0 -0
  40. data/{data → definitions}/nl.yaml +0 -0
  41. data/{data → definitions}/no.yaml +0 -0
  42. data/{data → definitions}/north_america_informal.yaml +0 -0
  43. data/{data → definitions}/nyse.yaml +0 -0
  44. data/{data → definitions}/nz.yaml +21 -10
  45. data/{data → definitions}/ph.yaml +0 -0
  46. data/{data → definitions}/pl.yaml +0 -0
  47. data/{data → definitions}/pt.yaml +0 -0
  48. data/{data → definitions}/ro.yaml +1 -2
  49. data/{data → definitions}/se.yaml +0 -0
  50. data/{data → definitions}/sg.yaml +0 -0
  51. data/{data → definitions}/si.yaml +6 -6
  52. data/{data → definitions}/sk.yaml +0 -0
  53. data/{data → definitions}/united_nations.yaml +0 -0
  54. data/{data → definitions}/ups.yaml +17 -11
  55. data/{data → definitions}/us.yaml +20 -15
  56. data/{data → definitions}/ve.yaml +0 -0
  57. data/{data → definitions}/vi.yaml +0 -0
  58. data/{data → definitions}/za.yaml +0 -0
  59. data/holidays.gemspec +2 -1
  60. data/lib/generated_definitions/MANIFEST +56 -0
  61. data/lib/generated_definitions/REGIONS.rb +4 -0
  62. data/lib/{holidays → generated_definitions}/ar.rb +2 -2
  63. data/lib/{holidays → generated_definitions}/at.rb +2 -2
  64. data/lib/{holidays → generated_definitions}/au.rb +19 -10
  65. data/lib/{holidays → generated_definitions}/be.rb +2 -2
  66. data/lib/{holidays → generated_definitions}/br.rb +2 -2
  67. data/lib/{holidays → generated_definitions}/ca.rb +2 -2
  68. data/lib/{holidays → generated_definitions}/ch.rb +2 -2
  69. data/lib/{holidays → generated_definitions}/cl.rb +2 -2
  70. data/lib/{holidays → generated_definitions}/cr.rb +2 -2
  71. data/lib/{holidays → generated_definitions}/cz.rb +2 -2
  72. data/lib/{holidays → generated_definitions}/de.rb +5 -4
  73. data/lib/{holidays → generated_definitions}/dk.rb +2 -2
  74. data/lib/{holidays → generated_definitions}/ecb_target.rb +2 -2
  75. data/lib/{holidays → generated_definitions}/el.rb +2 -2
  76. data/lib/{holidays → generated_definitions}/es.rb +6 -6
  77. data/lib/{holidays → generated_definitions}/europe.rb +7 -6
  78. data/lib/{holidays → generated_definitions}/fed_ex.rb +8 -3
  79. data/lib/{holidays → generated_definitions}/federal_reserve.rb +2 -2
  80. data/lib/{holidays → generated_definitions}/fi.rb +2 -2
  81. data/lib/{holidays → generated_definitions}/fr.rb +2 -2
  82. data/lib/{holidays → generated_definitions}/gb.rb +2 -2
  83. data/lib/{holidays → generated_definitions}/hr.rb +2 -2
  84. data/lib/{holidays → generated_definitions}/hu.rb +2 -2
  85. data/lib/{holidays → generated_definitions}/ie.rb +2 -2
  86. data/lib/{holidays → generated_definitions}/is.rb +2 -2
  87. data/lib/{holidays → generated_definitions}/it.rb +2 -2
  88. data/lib/{holidays → generated_definitions}/jp.rb +5 -5
  89. data/lib/{holidays → generated_definitions}/li.rb +2 -2
  90. data/lib/{holidays → generated_definitions}/lt.rb +2 -2
  91. data/lib/{holidays → generated_definitions}/ma.rb +2 -2
  92. data/lib/{holidays → generated_definitions}/mx.rb +2 -2
  93. data/lib/{holidays → generated_definitions}/nerc.rb +2 -2
  94. data/lib/{holidays → generated_definitions}/nl.rb +2 -2
  95. data/lib/{holidays → generated_definitions}/no.rb +2 -2
  96. data/lib/{holidays → generated_definitions}/north_america.rb +8 -3
  97. data/lib/{holidays → generated_definitions}/nyse.rb +2 -2
  98. data/lib/{holidays → generated_definitions}/nz.rb +5 -5
  99. data/lib/{holidays → generated_definitions}/ph.rb +2 -2
  100. data/lib/{holidays → generated_definitions}/pl.rb +2 -2
  101. data/lib/{holidays → generated_definitions}/pt.rb +2 -2
  102. data/lib/{holidays → generated_definitions}/ro.rb +2 -2
  103. data/lib/{holidays → generated_definitions}/scandinavia.rb +2 -2
  104. data/lib/{holidays → generated_definitions}/se.rb +2 -2
  105. data/lib/{holidays → generated_definitions}/sg.rb +2 -2
  106. data/lib/{holidays → generated_definitions}/si.rb +2 -2
  107. data/lib/{holidays → generated_definitions}/sk.rb +2 -2
  108. data/lib/{holidays → generated_definitions}/united_nations.rb +2 -2
  109. data/lib/{holidays → generated_definitions}/ups.rb +8 -3
  110. data/lib/{holidays → generated_definitions}/us.rb +8 -3
  111. data/lib/{holidays → generated_definitions}/ve.rb +2 -2
  112. data/lib/{holidays → generated_definitions}/vi.rb +2 -2
  113. data/lib/{holidays → generated_definitions}/za.rb +2 -2
  114. data/lib/holidays.rb +120 -665
  115. data/lib/holidays/core_extensions/date.rb +39 -0
  116. data/lib/holidays/date_calculator/day_of_month.rb +68 -0
  117. data/lib/holidays/date_calculator/easter.rb +58 -0
  118. data/lib/holidays/date_calculator/weekend_modifier.rb +49 -0
  119. data/lib/holidays/date_calculator_factory.rb +21 -0
  120. data/lib/holidays/definition/context/generator.rb +216 -0
  121. data/lib/holidays/definition/context/merger.rb +26 -0
  122. data/lib/holidays/definition/repository/cache.rb +33 -0
  123. data/lib/holidays/definition/repository/holidays_by_month.rb +49 -0
  124. data/lib/holidays/definition/repository/proc_cache.rb +36 -0
  125. data/lib/holidays/definition/repository/regions.rb +36 -0
  126. data/lib/holidays/definition/validator/region.rb +45 -0
  127. data/lib/holidays/definition_factory.rb +50 -0
  128. data/lib/holidays/option/context/parse_options.rb +96 -0
  129. data/lib/holidays/option_factory.rb +14 -0
  130. data/lib/holidays/use_case/context/between.rb +105 -0
  131. data/lib/holidays/use_case/context/dates_driver_builder.rb +64 -0
  132. data/lib/holidays/use_case_factory.rb +20 -0
  133. data/lib/holidays/version.rb +1 -1
  134. data/test/defs/test_defs_ar.rb +1 -1
  135. data/test/defs/test_defs_at.rb +2 -2
  136. data/test/defs/test_defs_au.rb +61 -43
  137. data/test/defs/test_defs_be.rb +1 -1
  138. data/test/defs/test_defs_br.rb +1 -1
  139. data/test/defs/test_defs_ca.rb +1 -1
  140. data/test/defs/test_defs_ch.rb +1 -1
  141. data/test/defs/test_defs_cl.rb +1 -1
  142. data/test/defs/test_defs_cr.rb +1 -1
  143. data/test/defs/test_defs_cz.rb +1 -1
  144. data/test/defs/test_defs_de.rb +18 -30
  145. data/test/defs/test_defs_dk.rb +1 -1
  146. data/test/defs/test_defs_ecb_target.rb +3 -3
  147. data/test/defs/test_defs_el.rb +1 -1
  148. data/test/defs/test_defs_es.rb +36 -25
  149. data/test/defs/test_defs_europe.rb +82 -84
  150. data/test/defs/test_defs_fed_ex.rb +4 -1
  151. data/test/defs/test_defs_federal_reserve.rb +1 -1
  152. data/test/defs/test_defs_fi.rb +1 -1
  153. data/test/defs/test_defs_fr.rb +1 -1
  154. data/test/defs/test_defs_gb.rb +20 -20
  155. data/test/defs/test_defs_hr.rb +1 -1
  156. data/test/defs/test_defs_hu.rb +2 -2
  157. data/test/defs/test_defs_ie.rb +1 -1
  158. data/test/defs/test_defs_is.rb +1 -1
  159. data/test/defs/test_defs_it.rb +1 -1
  160. data/test/defs/test_defs_jp.rb +1 -1
  161. data/test/defs/test_defs_li.rb +4 -4
  162. data/test/defs/test_defs_lt.rb +1 -1
  163. data/test/defs/test_defs_ma.rb +1 -1
  164. data/test/defs/test_defs_mx.rb +1 -1
  165. data/test/defs/test_defs_nerc.rb +1 -1
  166. data/test/defs/test_defs_nl.rb +1 -1
  167. data/test/defs/test_defs_no.rb +1 -1
  168. data/test/defs/test_defs_north_america.rb +5 -3
  169. data/test/defs/test_defs_nyse.rb +1 -1
  170. data/test/defs/test_defs_nz.rb +19 -9
  171. data/test/defs/test_defs_ph.rb +1 -1
  172. data/test/defs/test_defs_pl.rb +1 -1
  173. data/test/defs/test_defs_pt.rb +1 -1
  174. data/test/defs/test_defs_ro.rb +2 -3
  175. data/test/defs/test_defs_scandinavia.rb +1 -1
  176. data/test/defs/test_defs_se.rb +1 -1
  177. data/test/defs/test_defs_sg.rb +1 -1
  178. data/test/defs/test_defs_si.rb +7 -7
  179. data/test/defs/test_defs_sk.rb +1 -1
  180. data/test/defs/test_defs_united_nations.rb +1 -1
  181. data/test/defs/test_defs_ups.rb +5 -2
  182. data/test/defs/test_defs_us.rb +5 -3
  183. data/test/defs/test_defs_ve.rb +1 -1
  184. data/test/defs/test_defs_vi.rb +1 -1
  185. data/test/defs/test_defs_za.rb +1 -1
  186. data/test/{test_date.rb → holidays/core_extensions/test_date.rb} +8 -2
  187. data/test/holidays/date_calculator/test_day_of_month.rb +27 -0
  188. data/test/holidays/date_calculator/test_easter.rb +29 -0
  189. data/test/holidays/date_calculator/test_weekend_modifier.rb +33 -0
  190. data/test/holidays/definition/context/test_generator.rb +84 -0
  191. data/test/holidays/definition/context/test_merger.rb +22 -0
  192. data/test/holidays/definition/repository/test_cache.rb +82 -0
  193. data/test/holidays/definition/repository/test_holidays_by_month.rb +187 -0
  194. data/test/holidays/definition/repository/test_proc_cache.rb +29 -0
  195. data/test/holidays/definition/repository/test_regions.rb +86 -0
  196. data/test/holidays/definition/validator/test_region.rb +50 -0
  197. data/test/holidays/option/context/test_parse_options.rb +69 -0
  198. data/test/holidays/test_date_calculator_factory.rb +21 -0
  199. data/test/holidays/test_definition_factory.rb +34 -0
  200. data/test/holidays/test_option_factory.rb +9 -0
  201. data/test/holidays/test_use_case_factory.rb +13 -0
  202. data/test/holidays/use_case/context/test_between.rb +75 -0
  203. data/test/holidays/use_case/context/test_dates_driver_builder.rb +91 -0
  204. data/test/test_all_regions.rb +14 -3
  205. data/test/test_helper.rb +2 -1
  206. data/test/test_holidays.rb +19 -24
  207. data/test/test_holidays_between.rb +85 -0
  208. data/test/test_multiple_regions.rb +2 -2
  209. data/test/test_parse_definitions.rb +10 -4
  210. metadata +181 -111
  211. data/.coveralls.yml +0 -1
  212. data/lib/holidays/MANIFEST +0 -55
@@ -0,0 +1,29 @@
1
+ require File.expand_path(File.dirname(__FILE__)) + '/../../../test_helper'
2
+
3
+ require 'holidays/definition/repository/proc_cache'
4
+
5
+ class ProcCacheRepoTests < Test::Unit::TestCase
6
+ def setup
7
+ @subject = Holidays::Definition::Repository::ProcCache.new
8
+ end
9
+
10
+ def test_lookup_stores_and_returns_result_of_function_if_it_is_not_present
11
+ function = lambda { |year| Date.civil(year, 2, 1) - 1 }
12
+ year = 2015
13
+
14
+ assert_equal(Date.civil(year, 1, 31), @subject.lookup(function, year))
15
+ end
16
+
17
+ #FIXME This test stinks. I don't know how to show that the second invocation
18
+ # doesn't call the function. In rspec I could just do an expect().not_to
19
+ # but it doesn't seem like Mocha can do that? I'm punting.
20
+ def test_lookup_simply_returns_result_of_cache_if_present_after_first_call
21
+ function = lambda { |year| Date.civil(year, 2, 1) - 1 }
22
+ year = 2015
23
+
24
+ @subject.lookup(function, year)
25
+
26
+ assert_equal(Date.civil(year, 1, 31), @subject.lookup(function, year))
27
+ end
28
+ end
29
+
@@ -0,0 +1,86 @@
1
+ require File.expand_path(File.dirname(__FILE__)) + '/../../../test_helper'
2
+
3
+ require 'holidays/definition/repository/regions'
4
+
5
+ class RegionsRepoTests < Test::Unit::TestCase
6
+ def setup
7
+ @subject = Holidays::Definition::Repository::Regions.new
8
+ end
9
+
10
+ def test_all_returns_an_empty_array_if_just_initialize
11
+ assert_equal([], @subject.all)
12
+ end
13
+
14
+ def test_add_successfully_adds_a_region
15
+ @subject.add(:test)
16
+ assert_equal([:test], @subject.all)
17
+ end
18
+
19
+ def test_add_raises_error_if_symbol_not_provided
20
+ assert_raises ArgumentError do
21
+ @subject.add('not-a-symbol')
22
+ end
23
+ end
24
+
25
+ def test_add_raises_error_if_argument_is_nil
26
+ assert_raises ArgumentError do
27
+ @subject.add(nil)
28
+ end
29
+ end
30
+
31
+ def test_add_raises_error_if_any_region_is_not_a_symbol
32
+ assert_raises ArgumentError do
33
+ @subject.add([:test, 'not-a-symbol'])
34
+ end
35
+ end
36
+
37
+ def test_add_does_not_add_if_the_region_already_exists
38
+ @subject.add(:test)
39
+ @subject.add(:test)
40
+ assert_equal([:test], @subject.all)
41
+ end
42
+
43
+ def test_add_accepts_array_of_regions
44
+ @subject.add([:test, :test2])
45
+ assert_equal([:test, :test2], @subject.all)
46
+ end
47
+
48
+ def test_exists_returns_true_if_region_is_present
49
+ @subject.add(:test)
50
+ assert @subject.exists?(:test)
51
+ end
52
+
53
+ def tests_exists_returns_false_if_region_is_not_present
54
+ assert_equal(false, @subject.exists?(:something))
55
+ end
56
+
57
+ def test_exists_raises_error_if_invalid_argument
58
+ assert_raises ArgumentError do
59
+ @subject.exists?(nil)
60
+ end
61
+ end
62
+
63
+ def test_search_returns_empty_array_if_no_matches_found
64
+ assert_equal([], @subject.search("something"))
65
+ end
66
+
67
+ def test_search_returns_matches_on_prefix
68
+ @subject.add([:another_region, :test_region])
69
+ assert_equal([:test_region], @subject.search("test_"))
70
+ end
71
+
72
+ def test_search_returns_multiple_matches_on_prefix
73
+ @subject.add([:another_region, :test_region, :test_region2])
74
+ assert_equal([:test_region, :test_region2], @subject.search("test_"))
75
+ end
76
+
77
+ def test_search_raises_error_if_prefix_is_not_a_string
78
+ assert_raises ArgumentError do
79
+ @subject.search(:sym)
80
+ end
81
+
82
+ assert_raises ArgumentError do
83
+ @subject.search(nil)
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,50 @@
1
+ require File.expand_path(File.dirname(__FILE__)) + '/../../../test_helper'
2
+
3
+ require 'holidays/definition/validator/region'
4
+
5
+ class RegionValidatorTests < Test::Unit::TestCase
6
+ def setup
7
+ @regions_repo = mock()
8
+ @regions_repo.stubs(:exists?).returns(false)
9
+
10
+ @subject = Holidays::Definition::Validator::Region.new(@regions_repo)
11
+ end
12
+
13
+ def test_returns_true_if_region_exists_in_generated_files
14
+ assert(@subject.valid?(:us))
15
+ assert(@subject.valid?(:federal_reserve))
16
+ assert(@subject.valid?(:ecb_target))
17
+ assert(@subject.valid?(:gb))
18
+ assert(@subject.valid?(:jp))
19
+ end
20
+
21
+ def test_returns_true_if_region_is_in_regions_repository
22
+ @regions_repo.expects(:exists?).with(:custom).returns(true)
23
+ assert(@subject.valid?(:custom))
24
+ end
25
+
26
+ def test_returns_false_if_region_does_not_exist_in_generated_files_or_regions_repo
27
+ @regions_repo.expects(:exists?).with(:unknown_region).returns(false)
28
+ assert_equal(false, @subject.valid?(:unknown_region))
29
+ end
30
+
31
+ def test_returns_false_if_region_is_not_a_symbol
32
+ assert_equal(false, @subject.valid?('not-a-symbol'))
33
+ end
34
+
35
+ def test_returns_true_if_subregion
36
+ assert(@subject.valid?(:ca_qc))
37
+ end
38
+
39
+ def test_returns_true_if_region_is_any
40
+ assert(@subject.valid?(:any))
41
+ end
42
+
43
+ def test_returns_true_if_wildcard_region_is_valid
44
+ assert(@subject.valid?(:gb_))
45
+ end
46
+
47
+ def test_returns_false_if_wildcard_region_is_invalid
48
+ assert_equal(false, @subject.valid?(:somethingweird_))
49
+ end
50
+ end
@@ -0,0 +1,69 @@
1
+ require File.expand_path(File.dirname(__FILE__)) + '/../../../test_helper'
2
+
3
+ require 'holidays/option/context/parse_options'
4
+
5
+ #TODO This set of tests need love. Since the class itself requires actual
6
+ # definition files we have real defs in here, meaning that these tests
7
+ # could break if a definition is removed/changed.
8
+ # Also, there are no actual tests that the files are actually required.
9
+ # We need a mechanism to load things from the defs and then BOOM. We can test
10
+ # that this mechanism is called.
11
+ class ParseOptionsTests < Test::Unit::TestCase
12
+ def setup
13
+ @regions_repo = mock()
14
+
15
+ @region_validator = mock()
16
+ @region_validator.stubs(:valid?).returns(true)
17
+
18
+ @subject = Holidays::Option::Context::ParseOptions.new(
19
+ @regions_repo,
20
+ @region_validator,
21
+ )
22
+ end
23
+
24
+ def test_returns_observed_true_if_options_contains_observed_flag
25
+ @regions_repo.expects(:exists?).returns(false)
26
+ regions, observed, informal = @subject.call([:ca, :observed])
27
+ assert_equal(true, observed)
28
+ end
29
+
30
+ def test_returns_observed_false_if_options_contains_observed_flag
31
+ @regions_repo.expects(:exists?).returns(false)
32
+ regions, observed, informal = @subject.call([:ca])
33
+ assert_equal(false, observed)
34
+ end
35
+
36
+ def test_returns_informal_true_if_options_contains_informal_flag
37
+ @regions_repo.expects(:exists?).returns(false)
38
+ regions, observed, informal = @subject.call([:ca, :informal])
39
+ assert_equal(true, informal)
40
+ end
41
+
42
+ def test_returns_informal_false_if_options_contains_informal_flag
43
+ @regions_repo.expects(:exists?).returns(false)
44
+ regions, observed, informal = @subject.call([:ca])
45
+ assert_equal(false, informal)
46
+ end
47
+
48
+ def test_returns_any_if_no_regions_are_provided
49
+ regions, observed, informal = @subject.call(:informal)
50
+ assert_equal([:any], regions)
51
+ end
52
+
53
+ def test_wildcard_regions_are_removed_if_found
54
+ @regions_repo.expects(:exists?).with(:ch).returns(true)
55
+ @regions_repo.expects(:exists?).with(:ch_zh).returns(true)
56
+ @regions_repo.expects(:search).with('ch_').returns([:ch_zh])
57
+
58
+ regions, observed, informal = @subject.call([:ch_])
59
+ assert_equal(false, regions.include?(:ch_))
60
+ end
61
+
62
+ def test_raises_error_if_regions_are_invalid
63
+ @region_validator.stubs(:valid?).returns(false)
64
+
65
+ assert_raise Holidays::UnknownRegionError do
66
+ @subject.call([:unknown_region])
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,21 @@
1
+ require File.expand_path(File.dirname(__FILE__)) + '/../test_helper'
2
+
3
+ require 'holidays/date_calculator_factory'
4
+
5
+ class DateCalculatorFactoryTests < Test::Unit::TestCase
6
+ def setup
7
+ @subject = Holidays::DateCalculatorFactory
8
+ end
9
+
10
+ def test_day_of_month_calculator
11
+ assert @subject.day_of_month_calculator.is_a?(Holidays::DateCalculator::DayOfMonth)
12
+ end
13
+
14
+ def test_weekend_modifier
15
+ assert @subject.weekend_modifier.is_a?(Holidays::DateCalculator::WeekendModifier)
16
+ end
17
+
18
+ def test_easter_calculator
19
+ assert @subject.easter_calculator.is_a?(Holidays::DateCalculator::Easter)
20
+ end
21
+ end
@@ -0,0 +1,34 @@
1
+ require File.expand_path(File.dirname(__FILE__)) + '/../test_helper'
2
+
3
+ require 'holidays/definition_factory'
4
+
5
+ class DefinitionFactoryTests < Test::Unit::TestCase
6
+ def test_definition_file_parser
7
+ assert Holidays::DefinitionFactory.file_parser.is_a?(Holidays::Definition::Context::Generator)
8
+ end
9
+
10
+ def test_definition_source_generator
11
+ assert Holidays::DefinitionFactory.source_generator.is_a?(Holidays::Definition::Context::Generator)
12
+ end
13
+
14
+ def test_definition_merger
15
+ assert Holidays::DefinitionFactory.merger.is_a?(Holidays::Definition::Context::Merger)
16
+ end
17
+
18
+ def test_holidays_by_month_repository
19
+ assert Holidays::DefinitionFactory.holidays_by_month_repository.is_a?(Holidays::Definition::Repository::HolidaysByMonth)
20
+ end
21
+
22
+ def test_regions_repository
23
+ assert Holidays::DefinitionFactory.regions_repository.is_a?(Holidays::Definition::Repository::Regions)
24
+ end
25
+
26
+ def test_cache_repository
27
+ assert Holidays::DefinitionFactory.cache_repository.is_a?(Holidays::Definition::Repository::Cache)
28
+ end
29
+
30
+ def test_proc_cache_repository
31
+ assert Holidays::DefinitionFactory.proc_cache_repository.is_a?(Holidays::Definition::Repository::ProcCache)
32
+ end
33
+
34
+ end
@@ -0,0 +1,9 @@
1
+ require File.expand_path(File.dirname(__FILE__)) + '/../test_helper'
2
+
3
+ require 'holidays/option_factory'
4
+
5
+ class OptionFactoryTests < Test::Unit::TestCase
6
+ def test_parse_options_factory
7
+ assert Holidays::OptionFactory.parse_options.is_a?(Holidays::Option::Context::ParseOptions)
8
+ end
9
+ end
@@ -0,0 +1,13 @@
1
+ require File.expand_path(File.dirname(__FILE__)) + '/../test_helper'
2
+
3
+ require 'holidays/use_case_factory'
4
+
5
+ class UseCaseFactoryTests < Test::Unit::TestCase
6
+ def test_between_factory
7
+ assert Holidays::UseCaseFactory.between.is_a?(Holidays::UseCase::Context::Between)
8
+ end
9
+
10
+ def test_dates_driver_builder_factory
11
+ assert Holidays::UseCaseFactory.dates_driver_builder.is_a?(Holidays::UseCase::Context::DatesDriverBuilder)
12
+ end
13
+ end
@@ -0,0 +1,75 @@
1
+ require File.expand_path(File.dirname(__FILE__)) + '/../../../test_helper'
2
+
3
+ require 'holidays/use_case/context/between'
4
+
5
+ #TODO These tests need love. This is the heart of the holiday logic and I'm only
6
+ # now starting to tear bits and pieces of it apart to untangle it. This is a start
7
+ # but definitely needs more coverage.
8
+ class BetweenTests < Test::Unit::TestCase
9
+ def setup
10
+ @holidays_by_month_repo = mock()
11
+ @day_of_month_calculator = mock()
12
+ @proc_cache_repo = mock()
13
+
14
+ @subject = Holidays::UseCase::Context::Between.new(
15
+ @holidays_by_month_repo,
16
+ @day_of_month_calculator,
17
+ @proc_cache_repo,
18
+ )
19
+
20
+ @start_date = Date.civil(2015, 1, 1)
21
+ @end_date = Date.civil(2015, 1, 1)
22
+ @dates_driver = {2015 => [0, 1, 2], 2014 => [0, 12]}
23
+ @regions = [:us]
24
+ @observed = false
25
+ @informal = false
26
+ end
27
+
28
+ def test_returns_error_if_start_date_is_missing
29
+ assert_raise ArgumentError do
30
+ @subject.call(nil, @end_date, @dates_driver, @regions, @observed, @informal)
31
+ end
32
+ end
33
+
34
+ def test_returns_error_if_end_date_is_missing
35
+ assert_raise ArgumentError do
36
+ @subject.call(@start_date, nil, @dates_driver, @regions, @observed, @informal)
37
+ end
38
+ end
39
+
40
+ def test_returns_error_if_driver_hash_is_nil
41
+ assert_raise ArgumentError do
42
+ @subject.call(@start_date, @end_date, nil, @regions, @observed, @informal)
43
+ end
44
+ end
45
+
46
+ def test_returns_error_if_driver_hash_is_empty
47
+ assert_raise ArgumentError do
48
+ @subject.call(@start_date, @end_date, {}, @regions, @observed, @informal)
49
+ end
50
+ end
51
+
52
+ def test_returns_error_if_driver_hash_has_empty_months_array
53
+ assert_raise ArgumentError do
54
+ @subject.call(@start_date, @end_date, {2015 => nil}, @regions, @observed, @informal)
55
+ end
56
+
57
+ assert_raise ArgumentError do
58
+ @subject.call(@start_date, @end_date, {2015 => []}, @regions, @observed, @informal)
59
+ end
60
+
61
+ assert_raise ArgumentError do
62
+ @subject.call(@start_date, @end_Date, {2015 => [1], 2016 => [1], 2017 => []}, @regions, @observed, @informal)
63
+ end
64
+ end
65
+
66
+ def test_returns_error_if_regions_are_missing_or_empty
67
+ assert_raise ArgumentError do
68
+ @subject.call(@start_date, @end_date, @dates_driver, nil, @observed, @informal)
69
+ end
70
+
71
+ assert_raise ArgumentError do
72
+ @subject.call(@start_date, @end_date, @dates_driver, [], @observed, @informal)
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,91 @@
1
+ require File.expand_path(File.dirname(__FILE__)) + '/../../../test_helper'
2
+
3
+ require 'holidays/use_case/context/dates_driver_builder'
4
+
5
+ class DatesDriverBuilderTests < Test::Unit::TestCase
6
+ def setup
7
+ @subject = Holidays::UseCase::Context::DatesDriverBuilder.new
8
+ end
9
+
10
+ def test_returns_appropriately_formatted_hash
11
+ start_date = Date.civil(2015, 1, 1)
12
+ end_date = Date.civil(2015, 1, 31)
13
+
14
+ dates_driver = @subject.call(start_date, end_date)
15
+
16
+ assert(dates_driver.is_a?(Hash))
17
+
18
+ dates_driver.each do |year, months|
19
+ assert(year.is_a?(Integer))
20
+ assert(months.is_a?(Array))
21
+ end
22
+ end
23
+
24
+ def test_all_years_always_contains_variable_month
25
+ start_date = Date.civil(2010, 1, 1)
26
+ end_date = Date.civil(2020, 1, 1)
27
+
28
+ dates_driver = @subject.call(start_date, end_date)
29
+
30
+ assert(dates_driver[2010].include?(0))
31
+ assert(dates_driver[2011].include?(0))
32
+ assert(dates_driver[2012].include?(0))
33
+ assert(dates_driver[2013].include?(0))
34
+ assert(dates_driver[2014].include?(0))
35
+ assert(dates_driver[2015].include?(0))
36
+ assert(dates_driver[2016].include?(0))
37
+ assert(dates_driver[2017].include?(0))
38
+ assert(dates_driver[2018].include?(0))
39
+ assert(dates_driver[2019].include?(0))
40
+ assert(dates_driver[2020].include?(0))
41
+ end
42
+
43
+ def test_january_includes_february
44
+ dates_driver = @subject.call(Date.civil(2015, 1, 1), Date.civil(2015, 1, 1))
45
+
46
+ assert(dates_driver[2015].include?(1))
47
+ assert(dates_driver[2015].include?(2))
48
+ end
49
+
50
+ def test_january_includes_previous_year_december
51
+ dates_driver = @subject.call(Date.civil(2015, 1, 1), Date.civil(2015, 1, 1))
52
+
53
+ assert(dates_driver[2015].include?(1))
54
+ assert(dates_driver[2014].include?(12))
55
+ end
56
+
57
+ def test_december_includes_november
58
+ dates_driver = @subject.call(Date.civil(2015, 12, 1), Date.civil(2015, 12, 1))
59
+
60
+ assert(dates_driver[2015].include?(12))
61
+ assert(dates_driver[2015].include?(11))
62
+ end
63
+
64
+ def test_december_includes_next_year_january
65
+ dates_driver = @subject.call(Date.civil(2015, 12, 1), Date.civil(2015, 12, 1))
66
+
67
+ assert(dates_driver[2015].include?(12))
68
+ assert(dates_driver[2016].include?(1))
69
+ end
70
+
71
+ def test_middle_months_include_border_months
72
+ dates_driver = @subject.call(Date.civil(2015, 5, 1), Date.civil(2015, 5, 1))
73
+ assert(dates_driver[2015].include?(4))
74
+ assert(dates_driver[2015].include?(5))
75
+ assert(dates_driver[2015].include?(6))
76
+
77
+ dates_driver = @subject.call(Date.civil(2015, 10, 1), Date.civil(2015, 10, 1))
78
+ assert(dates_driver[2015].include?(9))
79
+ assert(dates_driver[2015].include?(10))
80
+ assert(dates_driver[2015].include?(11))
81
+
82
+ dates_driver = @subject.call(Date.civil(2015, 3, 1), Date.civil(2015, 7, 1))
83
+ assert(dates_driver[2015].include?(2))
84
+ assert(dates_driver[2015].include?(3))
85
+ assert(dates_driver[2015].include?(4))
86
+ assert(dates_driver[2015].include?(5))
87
+ assert(dates_driver[2015].include?(6))
88
+ assert(dates_driver[2015].include?(7))
89
+ assert(dates_driver[2015].include?(8))
90
+ end
91
+ end