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
@@ -3,7 +3,7 @@ require File.expand_path(File.dirname(__FILE__)) + '/../test_helper'
3
3
 
4
4
  # This file is generated by the Ruby Holiday gem.
5
5
  #
6
- # Definitions loaded: data/za.yaml
6
+ # Definitions loaded: definitions/za.yaml
7
7
  class ZaDefinitionTests < Test::Unit::TestCase # :nodoc:
8
8
 
9
9
  def test_za
@@ -1,6 +1,12 @@
1
- require File.expand_path(File.dirname(__FILE__)) + '/test_helper'
1
+ require File.expand_path(File.dirname(__FILE__)) + '/../../test_helper'
2
2
 
3
- class DateTests < Test::Unit::TestCase
3
+ require 'holidays/core_extensions/date'
4
+
5
+ class Date
6
+ include Holidays::CoreExtensions::Date
7
+ end
8
+
9
+ class CoreExtensionDateTests < Test::Unit::TestCase
4
10
  def setup
5
11
  @date = Date.civil(2008,1,1)
6
12
  end
@@ -0,0 +1,27 @@
1
+ require File.expand_path(File.dirname(__FILE__)) + '/../../test_helper'
2
+
3
+ require 'holidays/date_calculator/day_of_month'
4
+
5
+ class DayOfMonthDateCalculatorTests < Test::Unit::TestCase
6
+ def setup
7
+ @subject = Holidays::DateCalculator::DayOfMonth.new
8
+ end
9
+
10
+ def test_call_returns_expected_results
11
+ assert_equal 7, @subject.call(2008, 1, :first, :monday)
12
+ assert_equal 18, @subject.call(2008, 12, :third, :thursday)
13
+ assert_equal 28, @subject.call(2008, 1, :last, 1)
14
+ end
15
+
16
+ def test_returns_argument_error_with_invalid_week_parameter
17
+ assert_raises ArgumentError do
18
+ @subject.call(2008, 1, :wrong_week_argument, :monday)
19
+ end
20
+ end
21
+
22
+ def test_returns_argument_error_with_invalid_day_parameter
23
+ assert_raises ArgumentError do
24
+ @subject.call(2008, 1, :first, :bad_wday)
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,29 @@
1
+ require File.expand_path(File.dirname(__FILE__)) + '/../../test_helper'
2
+
3
+ require 'holidays/date_calculator/easter'
4
+
5
+ class EasterDateCalculatorTests < Test::Unit::TestCase
6
+ def setup
7
+ @subject = Holidays::DateCalculator::Easter.new
8
+ end
9
+
10
+ def test_calculate_easter_for_returns_expected_results
11
+ assert_equal '1800-04-13', @subject.calculate_easter_for(1800).to_s
12
+ assert_equal '1899-04-02', @subject.calculate_easter_for(1899).to_s
13
+ assert_equal '1900-04-15', @subject.calculate_easter_for(1900).to_s
14
+ assert_equal '1999-04-04', @subject.calculate_easter_for(1999).to_s
15
+ assert_equal '2000-04-23', @subject.calculate_easter_for(2000).to_s
16
+ assert_equal '2025-04-20', @subject.calculate_easter_for(2025).to_s
17
+ assert_equal '2035-03-25', @subject.calculate_easter_for(2035).to_s
18
+ assert_equal '2067-04-03', @subject.calculate_easter_for(2067).to_s
19
+ assert_equal '2099-04-12', @subject.calculate_easter_for(2099).to_s
20
+ end
21
+
22
+ def test_calculate_orthodox_easter_for_returns_expects_results
23
+ assert_equal '2000-04-30', @subject.calculate_orthodox_easter_for(2000).to_s
24
+ assert_equal '2008-04-27', @subject.calculate_orthodox_easter_for(2008).to_s
25
+ assert_equal '2009-04-19', @subject.calculate_orthodox_easter_for(2009).to_s
26
+ assert_equal '2011-04-24', @subject.calculate_orthodox_easter_for(2011).to_s
27
+ assert_equal '2020-04-19', @subject.calculate_orthodox_easter_for(2020).to_s
28
+ end
29
+ end
@@ -0,0 +1,33 @@
1
+ require File.expand_path(File.dirname(__FILE__)) + '/../../test_helper'
2
+
3
+ require 'holidays/date_calculator/weekend_modifier'
4
+
5
+ class WeekendModifierDateCalculatorTests < Test::Unit::TestCase
6
+ def setup
7
+ @subject = Holidays::DateCalculator::WeekendModifier.new
8
+ end
9
+
10
+ def test_to_monday_if_weekend
11
+ assert_equal Date.civil(2015, 5, 4), @subject.to_monday_if_weekend(Date.civil(2015, 5, 3))
12
+ assert_equal Date.civil(2015, 5, 4), @subject.to_monday_if_weekend(Date.civil(2015, 5, 2))
13
+ end
14
+
15
+ def test_to_monday_if_sunday
16
+ assert_equal Date.civil(2015, 5, 4), @subject.to_monday_if_sunday(Date.civil(2015, 5, 3))
17
+ end
18
+
19
+ def test_to_weekday_if_boxing_weekend
20
+ assert_equal Date.civil(2015, 12, 25), @subject.to_weekday_if_boxing_weekend(Date.civil(2015, 12, 25))
21
+ assert_equal Date.civil(2015, 12, 28), @subject.to_weekday_if_boxing_weekend(Date.civil(2015, 12, 26))
22
+ assert_equal Date.civil(2015, 12, 29), @subject.to_weekday_if_boxing_weekend(Date.civil(2015, 12, 27))
23
+ end
24
+
25
+ def test_to_weekday_if_weekend
26
+ assert_equal Date.civil(2015, 5, 4), @subject.to_weekday_if_weekend(Date.civil(2015, 5, 3))
27
+ assert_equal Date.civil(2015, 5, 1), @subject.to_weekday_if_weekend(Date.civil(2015, 5, 2))
28
+ end
29
+
30
+ def test_to_weekday_if_boxing_weekend_from_year
31
+ assert_equal Date.civil(2015, 12, 28), @subject.to_weekday_if_boxing_weekend_from_year(2015)
32
+ end
33
+ end
@@ -0,0 +1,84 @@
1
+ require File.expand_path(File.dirname(__FILE__)) + '/../../../test_helper'
2
+
3
+ require 'holidays/definition/context/generator'
4
+
5
+ class GeneratorTests < Test::Unit::TestCase
6
+ def setup
7
+ @generator = Holidays::Definition::Context::Generator.new
8
+ end
9
+
10
+ def test_parse_definition_files_raises_error_if_argument_is_nil
11
+ assert_raises ArgumentError do
12
+ @generator.parse_definition_files(nil)
13
+ end
14
+ end
15
+
16
+ def test_parse_definition_files_raises_error_if_files_are_empty
17
+ assert_raises ArgumentError do
18
+ @generator.parse_definition_files([])
19
+ end
20
+ end
21
+
22
+ def test_parse_definition_files_correctly_parse_regions
23
+ files = ['test/data/test_single_custom_holiday_defs.yaml']
24
+ regions, rules_by_month, custom_methods, tests = @generator.parse_definition_files(files)
25
+
26
+ assert_equal [:custom_single_file], regions
27
+ end
28
+
29
+ def test_parse_definitions_files_correctly_parse_rules_by_month
30
+ files = ['test/data/test_single_custom_holiday_defs.yaml']
31
+ regions, rules_by_month, custom_methods, tests = @generator.parse_definition_files(files)
32
+
33
+ expected_rules_by_month = {
34
+ 6 => [
35
+ {
36
+ :mday => 20,
37
+ :name => "Company Founding",
38
+ :regions => [:custom_single_file]
39
+ }
40
+ ]
41
+ }
42
+
43
+ assert_equal expected_rules_by_month, rules_by_month
44
+ end
45
+
46
+ def test_parse_definition_files_correctly_parse_custom_methods
47
+ files = ['test/data/test_single_custom_holiday_defs.yaml']
48
+ regions, rules_by_month, custom_methods, tests = @generator.parse_definition_files(files)
49
+
50
+ expected_custom_methods = {}
51
+ assert_equal expected_custom_methods, custom_methods
52
+ end
53
+
54
+ def test_parse_definition_files_correctly_parse_tests
55
+ files = ['test/data/test_single_custom_holiday_defs.yaml']
56
+ regions, rules_by_month, custom_methods, tests = @generator.parse_definition_files(files)
57
+
58
+ expected_tests = [[
59
+ "{Date.civil(2013,6,20) => 'Company Founding'}.each do |date, name|\n assert_equal name, (Holidays.on(date, :custom_single_file)[0] || {})[:name]\nend"
60
+ ]]
61
+
62
+ assert_equal expected_tests, tests
63
+ end
64
+
65
+ def test_generate_definition_source_correctly_generate_module_src
66
+ files = ['test/data/test_single_custom_holiday_defs.yaml']
67
+ regions, rules_by_month, custom_methods, tests = @generator.parse_definition_files(files)
68
+ module_src, test_src = @generator.generate_definition_source("test", files, regions, rules_by_month, custom_methods, tests)
69
+
70
+ expected_module_src = "# encoding: utf-8\nmodule Holidays\n # This file is generated by the Ruby Holidays gem.\n #\n # Definitions loaded: test/data/test_single_custom_holiday_defs.yaml\n #\n # To use the definitions in this file, load it right after you load the\n # Holiday gem:\n #\n # require 'holidays'\n # require 'generated_definitions/test'\n #\n # All the definitions are available at https://github.com/alexdunae/holidays\n module TEST # :nodoc:\n def self.defined_regions\n [:custom_single_file]\n end\n\n def self.holidays_by_month\n {\n 6 => [{:mday => 20, :name => \"Company Founding\", :regions => [:custom_single_file]}]\n }\n end\n end\n\n\nend\n\nHolidays.merge_defs(Holidays::TEST.defined_regions, Holidays::TEST.holidays_by_month)\n"
71
+
72
+ assert_equal expected_module_src, module_src
73
+ end
74
+
75
+ def test_generate_definition_source_correctly_genrate_test_src
76
+ files = ['test/data/test_single_custom_holiday_defs.yaml']
77
+ regions, rules_by_month, custom_methods, tests = @generator.parse_definition_files(files)
78
+ module_src, test_src = @generator.generate_definition_source("test", files, regions, rules_by_month, custom_methods, tests)
79
+
80
+ expected_test_src = "# encoding: utf-8\nrequire File.expand_path(File.dirname(__FILE__)) + '/../test_helper'\n\n# This file is generated by the Ruby Holiday gem.\n#\n# Definitions loaded: test/data/test_single_custom_holiday_defs.yaml\nclass TestDefinitionTests < Test::Unit::TestCase # :nodoc:\n\n def test_test\n{Date.civil(2013,6,20) => 'Company Founding'}.each do |date, name|\n assert_equal name, (Holidays.on(date, :custom_single_file)[0] || {})[:name]\nend\n end\nend\n"
81
+
82
+ assert_equal expected_test_src, test_src
83
+ end
84
+ end
@@ -0,0 +1,22 @@
1
+ require File.expand_path(File.dirname(__FILE__)) + '/../../../test_helper'
2
+
3
+ require 'holidays/definition/context/merger'
4
+
5
+ class MergerTests < Test::Unit::TestCase
6
+ def setup
7
+ @target_regions = [:new_region]
8
+ @target_holidays = {0 => [:mday => 1, :name => "Test", :regions => [:test2, :test]]}
9
+
10
+ @holidays_repo = mock()
11
+ @regions_repo = mock()
12
+
13
+ @subject = Holidays::Definition::Context::Merger.new(@holidays_repo, @regions_repo)
14
+ end
15
+
16
+ def test_repos_are_called_to_add_regions_and_holidays
17
+ @holidays_repo.expects(:add).with(@target_holidays)
18
+ @regions_repo.expects(:add).with(@target_regions)
19
+
20
+ @subject.call(@target_regions, @target_holidays)
21
+ end
22
+ end
@@ -0,0 +1,82 @@
1
+ require File.expand_path(File.dirname(__FILE__)) + '/../../../test_helper'
2
+
3
+ require 'holidays/definition/repository/cache'
4
+
5
+ class CacheRepoTests < Test::Unit::TestCase
6
+ def setup
7
+ @subject = Holidays::Definition::Repository::Cache.new
8
+ end
9
+
10
+ def test_find_returns_correct_cache_data
11
+ start_date = Date.civil(2015, 1, 1)
12
+ end_date = Date.civil(2015, 1, 1)
13
+ cache_data = [{:date=>Date.civil(2015, 1, 1), :name=>"New Year's Day", :regions=>[:us]}]
14
+ options = :us
15
+ @subject.cache_between(start_date, end_date, cache_data, options)
16
+
17
+ assert_equal(cache_data, @subject.find(start_date, end_date, options))
18
+ end
19
+
20
+ def test_find_returns_nil_if_no_match_is_found
21
+ start_date = Date.civil(2015, 1, 1)
22
+ end_date = Date.civil(2015, 1, 1)
23
+ cache_data = [{:date=>Date.civil(2015, 1, 1), :name=>"New Year's Day", :regions=>[:us]}]
24
+ options = :us
25
+ @subject.cache_between(start_date, end_date, cache_data, options)
26
+
27
+ assert_nil(@subject.find(Date.civil(2015, 7, 1), Date.civil(2015, 12, 1), options))
28
+ end
29
+
30
+ def test_cache_between_returns_error_if_dates_are_missing
31
+ start_date = Date.civil(2015, 1, 1)
32
+ end_date = Date.civil(2015, 1, 1)
33
+ cache_data = [{:date=>Date.civil(2015, 1, 1), :name=>"New Year's Day", :regions=>[:us]}]
34
+ options = :us
35
+
36
+ assert_raise ArgumentError do
37
+ @subject.cache_between(nil, end_date, cache_data, options)
38
+ end
39
+
40
+ assert_raise ArgumentError do
41
+ @subject.cache_between(start_date, nil, cache_data, options)
42
+ end
43
+ end
44
+
45
+ def test_cache_between_returns_error_if_dates_are_invalid
46
+ start_date = Date.civil(2015, 1, 1)
47
+ end_date = Date.civil(2015, 1, 1)
48
+ cache_data = [{:date=>Date.civil(2015, 1, 1), :name=>"New Year's Day", :regions=>[:us]}]
49
+ options = :us
50
+
51
+ assert_raise ArgumentError do
52
+ @subject.cache_between("invalid-date", end_date, cache_data, options)
53
+ end
54
+
55
+ assert_raise ArgumentError do
56
+ @subject.cache_between(start_date, "invalid-date", cache_data, options)
57
+ end
58
+ end
59
+
60
+ def test_cache_between_returns_error_if_cached_data_is_not_present
61
+ start_date = Date.civil(2015, 1, 1)
62
+ end_date = Date.civil(2015, 1, 1)
63
+ options = :us
64
+
65
+ assert_raise ArgumentError do
66
+ @subject.cache_between(start_date, end_date, nil, options)
67
+ end
68
+ end
69
+
70
+ def test_reset_clears_cache
71
+ start_date = Date.civil(2015, 1, 1)
72
+ end_date = Date.civil(2015, 1, 1)
73
+ cache_data = [{:date=>Date.civil(2015, 1, 1), :name=>"New Year's Day", :regions=>[:us]}]
74
+ options = :us
75
+ @subject.cache_between(start_date, end_date, cache_data, options)
76
+
77
+ assert_equal(cache_data, @subject.find(start_date, end_date, options))
78
+
79
+ @subject.reset!
80
+ assert_nil(@subject.find(start_date, end_date, options))
81
+ end
82
+ end
@@ -0,0 +1,187 @@
1
+ require File.expand_path(File.dirname(__FILE__)) + '/../../../test_helper'
2
+
3
+ require 'holidays/definition/repository/holidays_by_month'
4
+
5
+ class HolidaysByMonthRepoTests < Test::Unit::TestCase
6
+ def setup
7
+ @existing_holidays_by_month = {0 => [:mday => 1, :name => "Test", :regions => [:test]]}
8
+
9
+ @subject = Holidays::Definition::Repository::HolidaysByMonth.new
10
+ end
11
+
12
+ def test_all_returns_empty_hash_if_no_holidays_have_been_added
13
+ assert_equal({}, @subject.all)
14
+ end
15
+
16
+ def test_all_returns_existing_holidays
17
+ @subject.add(@existing_holidays_by_month)
18
+ assert_equal(@existing_holidays_by_month, @subject.all)
19
+ end
20
+
21
+ def test_add_does_not_change_data_if_it_already_exists
22
+ target_holidays = {0 => [:mday => 1, :name => "Test", :regions => [:test]]}
23
+
24
+ @subject.add(@existing_holidays_by_month)
25
+ @subject.add(target_holidays)
26
+
27
+ expected = @existing_holidays_by_month
28
+
29
+ assert_equal(expected, @subject.all)
30
+ end
31
+
32
+ def test_add_is_successful_if_name_is_different
33
+ target_holidays = {0 => [:mday => 1, :name => "Different", :regions => [:test]]}
34
+
35
+ @subject.add(@existing_holidays_by_month)
36
+ @subject.add(target_holidays)
37
+
38
+ expected = {
39
+ 0 => [
40
+ {:mday=>1, :name=>"Test", :regions=>[:test]},
41
+ {:mday=>1, :name=>"Different", :regions=>[:test]}
42
+ ]
43
+ }
44
+
45
+ assert_equal(expected, @subject.all)
46
+ end
47
+
48
+ def test_add_is_successful_if_wday_is_different
49
+ target_holidays = {0 => [:mday => 1, :name => "Test", :wday => 1, :regions => [:test]]}
50
+
51
+ @subject.add(@existing_holidays_by_month)
52
+ @subject.add(target_holidays)
53
+
54
+ expected = {
55
+ 0 => [
56
+ {:mday=>1, :name=>"Test", :regions=>[:test]},
57
+ {:mday=>1, :name=>"Test", :wday => 1, :regions=>[:test]}
58
+ ]
59
+ }
60
+
61
+ assert_equal(expected, @subject.all)
62
+ end
63
+
64
+ def test_add_is_successful_if_mday_is_different
65
+ target_holidays = {0 => [:mday => 2, :name => "Test", :regions => [:test]]}
66
+
67
+ @subject.add(@existing_holidays_by_month)
68
+ @subject.add(target_holidays)
69
+
70
+ expected = {
71
+ 0 => [
72
+ {:mday=>1, :name=>"Test", :regions=>[:test]},
73
+ {:mday=>2, :name=>"Test", :regions=>[:test]}
74
+ ]
75
+ }
76
+
77
+ assert_equal(expected, @subject.all)
78
+ end
79
+
80
+ def test_add_is_successful_if_week_is_different
81
+ target_holidays = {0 => [:mday => 1, :name => "Test", :week => :first, :regions => [:test]]}
82
+
83
+ @subject.add(@existing_holidays_by_month)
84
+ @subject.add(target_holidays)
85
+
86
+ expected = {
87
+ 0 => [
88
+ {:mday=>1, :name=>"Test", :regions=>[:test]},
89
+ {:mday=>1, :name=>"Test", :week => :first, :regions=>[:test]}
90
+ ]
91
+ }
92
+
93
+ assert_equal(expected, @subject.all)
94
+ end
95
+
96
+ def test_add_is_successful_if_function_id_is_different
97
+ target_holidays = {0 => [:mday => 1, :name => "Test", :function_id => 'test', :regions => [:test]]}
98
+
99
+ @subject.add(@existing_holidays_by_month)
100
+ @subject.add(target_holidays)
101
+
102
+ expected = {
103
+ 0 => [
104
+ {:mday=>1, :name=>"Test", :regions=>[:test]},
105
+ {:mday=>1, :name=>"Test", :function_id => 'test', :regions=>[:test]}
106
+ ]
107
+ }
108
+
109
+ assert_equal(expected, @subject.all)
110
+ end
111
+
112
+ def test_add_is_successful_if_type_is_different
113
+ target_holidays = {0 => [:mday => 1, :name => "Test", :type => :informal, :regions => [:test]]}
114
+
115
+ @subject.add(@existing_holidays_by_month)
116
+ @subject.add(target_holidays)
117
+
118
+ expected = {
119
+ 0 => [
120
+ {:mday=>1, :name=>"Test", :regions=>[:test]},
121
+ {:mday=>1, :name=>"Test", :type => :informal, :regions=>[:test]}
122
+ ]
123
+ }
124
+
125
+ assert_equal(expected, @subject.all)
126
+ end
127
+
128
+ def test_add_is_successful_if_observed_id_is_different
129
+ target_holidays = {0 => [:mday => 1, :name => "Test", :observed_id => :informal, :regions => [:test]]}
130
+
131
+ @subject.add(@existing_holidays_by_month)
132
+ @subject.add(target_holidays)
133
+
134
+ expected = {
135
+ 0 => [
136
+ {:mday=>1, :name=>"Test", :regions=>[:test]},
137
+ {:mday=>1, :name=>"Test", :observed_id => :informal, :regions=>[:test]}
138
+ ]
139
+ }
140
+
141
+ assert_equal(expected, @subject.all)
142
+ end
143
+
144
+ def test_add_is_successful_and_updates_regions_to_existing_matching_definitions
145
+ target_holidays = {0 => [:mday => 1, :name => "Test", :regions => [:test2]]}
146
+
147
+ @subject.add(@existing_holidays_by_month)
148
+ @subject.add(target_holidays)
149
+
150
+ expected = { 0 => [ {:mday=>1, :name=>"Test", :regions=>[:test, :test2]} ] }
151
+
152
+ assert_equal(expected, @subject.all)
153
+ end
154
+
155
+ def test_add_is_successful_and_updates_regions_to_existing_matching_definitions_and_deduped_correctly
156
+ target_holidays = {0 => [:mday => 1, :name => "Test", :regions => [:test2, :test]]}
157
+
158
+ @subject.add(@existing_holidays_by_month)
159
+ @subject.add(target_holidays)
160
+
161
+ expected = { 0 => [ {:mday=>1, :name=>"Test", :regions=>[:test, :test2]} ] }
162
+
163
+ assert_equal(expected, @subject.all)
164
+ end
165
+
166
+ def test_find_by_month_returns_nil_if_none_found
167
+ @subject.add(@existing_holidays_by_month)
168
+
169
+ holidays_for_month = @subject.find_by_month(12)
170
+ assert_equal(nil, holidays_for_month)
171
+ end
172
+
173
+ def test_find_by_month_returns_array_if_found
174
+ @subject.add(@existing_holidays_by_month)
175
+
176
+ holidays_for_month = @subject.find_by_month(0)
177
+ assert_equal(@existing_holidays_by_month[0], holidays_for_month)
178
+ end
179
+
180
+ def test_find_by_month_raises_error_if_month_is_not_valid
181
+ @subject.add(@existing_holidays_by_month)
182
+
183
+ assert_raise ArgumentError do
184
+ @subject.find_by_month(-1)
185
+ end
186
+ end
187
+ end