holidays 4.6.0 → 4.7.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/CONTRIBUTING.md +5 -5
- data/Makefile +29 -0
- data/README.md +13 -1
- data/Rakefile +2 -2
- data/definitions/au.yaml +12 -9
- data/definitions/ca.yaml +17 -2
- data/definitions/ch.yaml +1 -1
- data/definitions/index.yaml +3 -0
- data/definitions/is.yaml +1 -1
- data/definitions/jp.yaml +19 -14
- data/definitions/kr.yaml +282 -0
- data/definitions/lu.yaml +56 -0
- data/definitions/my.yaml +51 -0
- data/definitions/ups.yaml +1 -1
- data/definitions/us.yaml +1 -1
- data/lib/generated_definitions/MANIFEST +3 -0
- data/lib/generated_definitions/REGIONS.rb +1 -1
- data/lib/generated_definitions/au.rb +11 -8
- data/lib/generated_definitions/ca.rb +1 -1
- data/lib/generated_definitions/ch.rb +1 -1
- data/lib/generated_definitions/europe.rb +2 -2
- data/lib/generated_definitions/is.rb +1 -1
- data/lib/generated_definitions/jp.rb +13 -15
- data/lib/generated_definitions/kr.rb +248 -0
- data/lib/generated_definitions/lu.rb +39 -0
- data/lib/generated_definitions/my.rb +36 -0
- data/lib/generated_definitions/north_america.rb +2 -2
- data/lib/generated_definitions/scandinavia.rb +1 -1
- data/lib/generated_definitions/ups.rb +1 -1
- data/lib/generated_definitions/us.rb +1 -1
- data/lib/holidays.rb +29 -51
- data/lib/holidays/core_extensions/date.rb +1 -1
- data/lib/holidays/definition/context/function_processor.rb +86 -0
- data/lib/holidays/definition/context/generator.rb +31 -6
- data/lib/holidays/definition/parser/custom_method.rb +1 -3
- data/lib/holidays/definition/repository/holidays_by_month.rb +1 -1
- data/lib/holidays/definition/validator/region.rb +1 -3
- data/lib/holidays/errors.rb +1 -0
- data/lib/holidays/factory/date_calculator.rb +37 -0
- data/lib/holidays/factory/definition.rb +96 -0
- data/lib/holidays/factory/finder.rb +70 -0
- data/lib/holidays/finder/context/between.rb +43 -0
- data/lib/holidays/{use_case → finder}/context/dates_driver_builder.rb +6 -4
- data/lib/holidays/finder/context/next_holiday.rb +57 -0
- data/lib/holidays/{option → finder}/context/parse_options.rb +6 -8
- data/lib/holidays/finder/context/search.rb +86 -0
- data/lib/holidays/finder/context/year_holiday.rb +57 -0
- data/lib/holidays/finder/rules/in_region.rb +23 -0
- data/lib/holidays/finder/rules/year_range.rb +82 -0
- data/lib/holidays/load_all_definitions.rb +7 -5
- data/lib/holidays/version.rb +1 -1
- data/test/coverage_report.rb +7 -0
- data/test/defs/test_defs_au.rb +1 -1
- data/test/defs/test_defs_ca.rb +16 -1
- data/test/defs/test_defs_jp.rb +4 -0
- data/test/defs/test_defs_kr.rb +26 -0
- data/test/defs/test_defs_lu.rb +24 -0
- data/test/defs/test_defs_my.rb +20 -0
- data/test/defs/test_defs_north_america.rb +16 -1
- data/test/holidays/core_extensions/test_date_time.rb +7 -7
- data/test/holidays/definition/context/test_function_processor.rb +175 -0
- data/test/holidays/definition/context/test_generator.rb +18 -11
- data/test/holidays/definition/parser/test_custom_method.rb +2 -2
- data/test/holidays/definition/repository/test_proc_result_cache.rb +1 -1
- data/test/holidays/{test_date_calculator_factory.rb → factory/test_date_calculator.rb} +3 -3
- data/test/holidays/factory/test_definition.rb +53 -0
- data/test/holidays/factory/test_finder.rb +25 -0
- data/test/holidays/finder/context/test_between.rb +172 -0
- data/test/holidays/{use_case → finder}/context/test_dates_driver_builder.rb +2 -2
- data/test/holidays/finder/context/test_next_holiday.rb +156 -0
- data/test/holidays/{option → finder}/context/test_parse_options.rb +9 -9
- data/test/holidays/finder/context/test_search.rb +203 -0
- data/test/holidays/finder/context/test_year_holiday.rb +202 -0
- data/test/holidays/finder/rules/test_in_region.rb +38 -0
- data/test/holidays/finder/rules/test_year_range.rb +170 -0
- data/test/integration/README.md +9 -0
- data/test/{test_all_regions.rb → integration/test_all_regions.rb} +16 -2
- data/test/{test_custom_holidays.rb → integration/test_custom_holidays.rb} +2 -2
- data/test/{test_custom_year_range_holidays.rb → integration/test_custom_year_range_holidays.rb} +1 -1
- data/test/{test_holidays.rb → integration/test_holidays.rb} +43 -32
- data/test/{test_holidays_between.rb → integration/test_holidays_between.rb} +8 -16
- data/test/{test_multiple_regions.rb → integration/test_multiple_regions.rb} +1 -1
- data/test/test_helper.rb +3 -4
- metadata +67 -39
- data/benchmark.rb +0 -8
- data/lib/holidays/date_calculator_factory.rb +0 -35
- data/lib/holidays/definition_factory.rb +0 -86
- data/lib/holidays/option_factory.rb +0 -15
- data/lib/holidays/use_case/context/between.rb +0 -45
- data/lib/holidays/use_case/context/context_common.rb +0 -123
- data/lib/holidays/use_case/context/next_holiday.rb +0 -54
- data/lib/holidays/use_case/context/year_holiday.rb +0 -51
- data/lib/holidays/use_case_factory.rb +0 -41
- data/test/holidays/test_definition_factory.rb +0 -49
- data/test/holidays/test_option_factory.rb +0 -9
- data/test/holidays/test_use_case_factory.rb +0 -13
- data/test/holidays/use_case/context/test_between.rb +0 -77
@@ -37,7 +37,7 @@ class GeneratorTests < Test::Unit::TestCase
|
|
37
37
|
files = ['test/data/test_single_custom_holiday_defs.yaml']
|
38
38
|
@custom_method_parser.expects(:call).with(nil).returns({})
|
39
39
|
|
40
|
-
regions
|
40
|
+
regions = @generator.parse_definition_files(files)[0]
|
41
41
|
|
42
42
|
assert_equal [:custom_single_file], regions
|
43
43
|
end
|
@@ -46,7 +46,7 @@ class GeneratorTests < Test::Unit::TestCase
|
|
46
46
|
files = ['test/data/test_single_custom_holiday_defs.yaml']
|
47
47
|
@custom_method_parser.expects(:call).with(nil).returns({})
|
48
48
|
|
49
|
-
|
49
|
+
rules_by_month = @generator.parse_definition_files(files)[1]
|
50
50
|
|
51
51
|
expected_rules_by_month = {
|
52
52
|
6 => [
|
@@ -65,7 +65,7 @@ class GeneratorTests < Test::Unit::TestCase
|
|
65
65
|
files = ['test/data/test_single_custom_holiday_defs.yaml']
|
66
66
|
@custom_method_parser.expects(:call).with(nil).returns({})
|
67
67
|
|
68
|
-
|
68
|
+
custom_methods = @generator.parse_definition_files(files)[2]
|
69
69
|
|
70
70
|
expected_custom_methods = {}
|
71
71
|
assert_equal expected_custom_methods, custom_methods
|
@@ -75,7 +75,7 @@ class GeneratorTests < Test::Unit::TestCase
|
|
75
75
|
files = ['test/data/test_single_custom_holiday_defs.yaml']
|
76
76
|
@custom_method_parser.expects(:call).with(nil).returns({})
|
77
77
|
|
78
|
-
|
78
|
+
tests = @generator.parse_definition_files(files)[3]
|
79
79
|
|
80
80
|
expected_tests = [[
|
81
81
|
"{Date.civil(2013,6,20) => 'Company Founding'}.each do |date, name|\n assert_equal name, (Holidays.on(date, :custom_single_file)[0] || {})[:name]\nend"
|
@@ -89,7 +89,7 @@ class GeneratorTests < Test::Unit::TestCase
|
|
89
89
|
@custom_method_parser.expects(:call).with(nil).returns({})
|
90
90
|
|
91
91
|
regions, rules_by_month, custom_methods, tests = @generator.parse_definition_files(files)
|
92
|
-
module_src
|
92
|
+
module_src = @generator.generate_definition_source("test", files, regions, rules_by_month, custom_methods, tests)[0]
|
93
93
|
|
94
94
|
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/holidays/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\n def self.custom_methods\n {\n \n }\n end\n end\nend\n"
|
95
95
|
|
@@ -101,7 +101,7 @@ class GeneratorTests < Test::Unit::TestCase
|
|
101
101
|
@custom_method_parser.expects(:call).with(nil).returns({})
|
102
102
|
|
103
103
|
regions, rules_by_month, custom_methods, tests = @generator.parse_definition_files(files)
|
104
|
-
|
104
|
+
test_src = @generator.generate_definition_source("test", files, regions, rules_by_month, custom_methods, tests)[1]
|
105
105
|
|
106
106
|
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"
|
107
107
|
|
@@ -112,7 +112,7 @@ class GeneratorTests < Test::Unit::TestCase
|
|
112
112
|
files = ['test/data/test_custom_year_range_holiday_defs.yaml']
|
113
113
|
@custom_method_parser.expects(:call).with(nil).returns({})
|
114
114
|
|
115
|
-
|
115
|
+
rules_by_month = @generator.parse_definition_files(files)[1]
|
116
116
|
|
117
117
|
expected_rules_by_month = {
|
118
118
|
6 => [
|
@@ -132,7 +132,7 @@ class GeneratorTests < Test::Unit::TestCase
|
|
132
132
|
:name => "between_year",
|
133
133
|
:regions => [:custom_year_range_file],
|
134
134
|
:mday => 3,
|
135
|
-
:year_ranges => [{"between" =>
|
135
|
+
:year_ranges => [{"between" => 2016..2018}]
|
136
136
|
},
|
137
137
|
{
|
138
138
|
:name => "limited_year",
|
@@ -157,7 +157,7 @@ class GeneratorTests < Test::Unit::TestCase
|
|
157
157
|
@custom_method_parser.expects(:call).with(nil).returns({})
|
158
158
|
|
159
159
|
regions, rules_by_month, custom_methods, tests = @generator.parse_definition_files(files)
|
160
|
-
module_src
|
160
|
+
module_src = @generator.generate_definition_source("test", files, regions, rules_by_month, custom_methods, tests)[0]
|
161
161
|
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_custom_year_range_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/holidays/holidays\n module TEST # :nodoc:\n def self.defined_regions\n [:custom_year_range_file]\n end\n\n def self.holidays_by_month\n {\n 6 => [{:mday => 1, :year_ranges => [{:after => 2016}],:name => \"after_year\", :regions => [:custom_year_range_file]},\n {:mday => 2, :year_ranges => [{:before => 2017}],:name => \"before_year\", :regions => [:custom_year_range_file]},\n {:mday => 3, :year_ranges => [{:between => 2016..2018}],:name => \"between_year\", :regions => [:custom_year_range_file]},\n {:mday => 4, :year_ranges => [{:limited => [2016, 2018, 2019]}],:name => \"limited_year\", :regions => [:custom_year_range_file]},\n {:mday => 5, :year_ranges => [{:before => 2015},{:after => 2017}],:name => \"multiple_conditions\", :regions => [:custom_year_range_file]}]\n }\n end\n\n def self.custom_methods\n {\n \n }\n end\n end\nend\n"
|
162
162
|
|
163
163
|
assert_equal expected_module_src, module_src
|
@@ -171,7 +171,7 @@ class GeneratorTests < Test::Unit::TestCase
|
|
171
171
|
@custom_method_source_decorator.expects(:call).once.with(@parsed_custom_method).returns("\"custom_method(year, month)\" => Proc.new { |year, month|\nsource_stuff\n}")
|
172
172
|
|
173
173
|
regions, rules_by_month, custom_methods, tests = @generator.parse_definition_files(files)
|
174
|
-
module_src
|
174
|
+
module_src = @generator.generate_definition_source("test", files, regions, rules_by_month, custom_methods, tests)[0]
|
175
175
|
|
176
176
|
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_with_custom_procs.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/holidays/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 0 => [{:function => \"custom_method(year, month)\", :function_arguments => [:year, :month], :function_modifier => 5, :name => \"Custom Holiday\", :regions => [:custom_single_file]}],\n 6 => [{:mday => 20, :name => \"Company Founding\", :regions => [:custom_single_file]}]\n }\n end\n\n def self.custom_methods\n {\n \"custom_method(year, month)\" => Proc.new { |year, month|\nsource_stuff\n},\n\n\n }\n end\n end\nend\n"
|
177
177
|
|
@@ -186,10 +186,17 @@ class GeneratorTests < Test::Unit::TestCase
|
|
186
186
|
@custom_method_source_decorator.expects(:call).once.with("method").returns("\"custom_method(year, month)\" => Proc.new { |year, month|\nsource_stuff\n}")
|
187
187
|
|
188
188
|
regions, rules_by_month, custom_methods, tests = @generator.parse_definition_files(files)
|
189
|
-
|
189
|
+
test_src = @generator.generate_definition_source("test", files, regions, rules_by_month, custom_methods, tests)[1]
|
190
190
|
|
191
191
|
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_with_custom_procs.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\n{Date.civil(2015, 1, 1) => 'Custom Holiday'}.each do |date, name|\n assert_equal name, (Holidays.on(date, :custom_single_file)[0] || {}[:name]\nend\n\n end\nend\n"
|
192
192
|
|
193
193
|
assert_equal expected_test_src, test_src
|
194
194
|
end
|
195
|
+
|
196
|
+
#TODO Missing test scenarios. Adding here so I don't forget when I split this
|
197
|
+
# apart into smaller components.
|
198
|
+
#
|
199
|
+
# 1) If a year_range contains empty entries then we should blow up.
|
200
|
+
# 2) If year_range contains invalid (i.e. too many types per entry) then
|
201
|
+
# we should blow up
|
195
202
|
end
|
@@ -63,7 +63,7 @@ class ParserCustomMethodTests < Test::Unit::TestCase
|
|
63
63
|
@validator.expects(:valid?).with({:name => "custom_method", :arguments => "year", :source => "d = Date.civil(year, 1, 1)\nd + 2\n"}).returns(false)
|
64
64
|
|
65
65
|
assert_raises ArgumentError do
|
66
|
-
|
66
|
+
@parser.call(input)
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
@@ -73,7 +73,7 @@ class ParserCustomMethodTests < Test::Unit::TestCase
|
|
73
73
|
@validator.expects(:valid?).with({:name => "second_method", :arguments => "month", :source => "source"}).returns(false)
|
74
74
|
|
75
75
|
assert_raises ArgumentError do
|
76
|
-
|
76
|
+
@parser.call(input)
|
77
77
|
end
|
78
78
|
end
|
79
79
|
end
|
@@ -76,7 +76,7 @@ class ProcResultCacheRepoTests < Test::Unit::TestCase
|
|
76
76
|
@subject.lookup(function, function_argument)
|
77
77
|
end
|
78
78
|
|
79
|
-
|
79
|
+
function_argument = Proc.new { |arg1| "arg1" + "something"}
|
80
80
|
assert_raise ArgumentError do
|
81
81
|
@subject.lookup(function, function_argument)
|
82
82
|
end
|
@@ -1,10 +1,10 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__)) + '
|
1
|
+
require File.expand_path(File.dirname(__FILE__)) + '/../../test_helper'
|
2
2
|
|
3
|
-
require 'holidays/
|
3
|
+
require 'holidays/factory/date_calculator'
|
4
4
|
|
5
5
|
class DateCalculatorFactoryTests < Test::Unit::TestCase
|
6
6
|
def setup
|
7
|
-
@subject = Holidays::
|
7
|
+
@subject = Holidays::Factory::DateCalculator
|
8
8
|
end
|
9
9
|
|
10
10
|
def test_day_of_month_calculator
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__)) + '/../../test_helper'
|
2
|
+
|
3
|
+
require 'holidays/factory/definition'
|
4
|
+
|
5
|
+
class DefinitionFactoryTests < Test::Unit::TestCase
|
6
|
+
def test_definition_file_parser
|
7
|
+
assert Holidays::Factory::Definition.file_parser.is_a?(Holidays::Definition::Context::Generator)
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_definition_source_generator
|
11
|
+
assert Holidays::Factory::Definition.source_generator.is_a?(Holidays::Definition::Context::Generator)
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_definition_merger
|
15
|
+
assert Holidays::Factory::Definition.merger.is_a?(Holidays::Definition::Context::Merger)
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_holidays_by_month_repository
|
19
|
+
assert Holidays::Factory::Definition.holidays_by_month_repository.is_a?(Holidays::Definition::Repository::HolidaysByMonth)
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_regions_repository
|
23
|
+
assert Holidays::Factory::Definition.regions_repository.is_a?(Holidays::Definition::Repository::Regions)
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_cache_repository
|
27
|
+
assert Holidays::Factory::Definition.cache_repository.is_a?(Holidays::Definition::Repository::Cache)
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_proc_result_cache_repository
|
31
|
+
assert Holidays::Factory::Definition.proc_result_cache_repository.is_a?(Holidays::Definition::Repository::ProcResultCache)
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_custom_method_parser
|
35
|
+
assert Holidays::Factory::Definition.custom_method_parser.is_a?(Holidays::Definition::Parser::CustomMethod)
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_custom_method_source_decorator
|
39
|
+
assert Holidays::Factory::Definition.custom_method_source_decorator.is_a?(Holidays::Definition::Decorator::CustomMethodSource)
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_custom_method_validator
|
43
|
+
assert Holidays::Factory::Definition.custom_method_validator.is_a?(Holidays::Definition::Validator::CustomMethod)
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_region_validator
|
47
|
+
assert Holidays::Factory::Definition.region_validator.is_a?(Holidays::Definition::Validator::Region)
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_function_processor
|
51
|
+
assert Holidays::Factory::Definition.function_processor.is_a?(Holidays::Definition::Context::FunctionProcessor)
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__)) + '/../../test_helper'
|
2
|
+
|
3
|
+
require 'holidays/factory/finder'
|
4
|
+
|
5
|
+
class FinderFactoryTests < Test::Unit::TestCase
|
6
|
+
def test_search
|
7
|
+
assert Holidays::Factory::Finder.search.is_a?(Holidays::Finder::Context::Search)
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_between
|
11
|
+
assert Holidays::Factory::Finder.between.is_a?(Holidays::Finder::Context::Between)
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_next_holiday
|
15
|
+
assert Holidays::Factory::Finder.next_holiday.is_a?(Holidays::Finder::Context::NextHoliday)
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_year_holiday
|
19
|
+
assert Holidays::Factory::Finder.year_holiday.is_a?(Holidays::Finder::Context::YearHoliday)
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_parse_options_factory
|
23
|
+
assert Holidays::Factory::Finder.parse_options.is_a?(Holidays::Finder::Context::ParseOptions)
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,172 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__)) + '/../../../test_helper'
|
2
|
+
|
3
|
+
require 'holidays/finder/context/between'
|
4
|
+
|
5
|
+
class BetweenTests < 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::Between.new(
|
16
|
+
@definition_search,
|
17
|
+
@dates_driver_builder,
|
18
|
+
@options_parser,
|
19
|
+
)
|
20
|
+
|
21
|
+
@start_date = Date.civil(2015, 1, 1)
|
22
|
+
@end_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
|
+
@start_date, @end_date,
|
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_start_date_is_missing
|
46
|
+
assert_raise ArgumentError do
|
47
|
+
@subject.call(nil, @end_date, @options)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_returns_error_if_end_date_is_missing
|
52
|
+
assert_raise ArgumentError do
|
53
|
+
@subject.call(@start_date, nil, @options)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_returns_single_holiday
|
58
|
+
assert_equal(
|
59
|
+
[
|
60
|
+
{
|
61
|
+
:date => Date.civil(2015, 1, 1),
|
62
|
+
:name => "Test",
|
63
|
+
:regions => [:us],
|
64
|
+
}
|
65
|
+
],
|
66
|
+
@subject.call(@start_date, @end_date, @options)
|
67
|
+
)
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_returns_sorted_multiple_holidays
|
71
|
+
@start_date = Date.civil(2015, 1, 1)
|
72
|
+
@end_date = Date.civil(2016, 12, 31)
|
73
|
+
|
74
|
+
@definition_search.expects(:call).at_most_once.with(
|
75
|
+
@dates_driver,
|
76
|
+
@regions,
|
77
|
+
[],
|
78
|
+
).returns([
|
79
|
+
{
|
80
|
+
:date => Date.civil(2015, 6, 1),
|
81
|
+
:name => "2015-June",
|
82
|
+
:regions => [:us],
|
83
|
+
},
|
84
|
+
{
|
85
|
+
:date => Date.civil(2015, 1, 1),
|
86
|
+
:name => "2015-Jan",
|
87
|
+
:regions => [:us],
|
88
|
+
},
|
89
|
+
{
|
90
|
+
:date => Date.civil(2016, 6, 1),
|
91
|
+
:name => "2016-June",
|
92
|
+
:regions => [:us],
|
93
|
+
},
|
94
|
+
])
|
95
|
+
|
96
|
+
@dates_driver_builder.expects(:call).at_most_once.with(
|
97
|
+
@start_date, @end_date,
|
98
|
+
).returns(
|
99
|
+
@dates_driver,
|
100
|
+
)
|
101
|
+
|
102
|
+
assert_equal(
|
103
|
+
[
|
104
|
+
{
|
105
|
+
:date => Date.civil(2015, 1, 1),
|
106
|
+
:name => "2015-Jan",
|
107
|
+
:regions => [:us],
|
108
|
+
},
|
109
|
+
{
|
110
|
+
:date => Date.civil(2015, 6, 1),
|
111
|
+
:name => "2015-June",
|
112
|
+
:regions => [:us],
|
113
|
+
},
|
114
|
+
{
|
115
|
+
:date => Date.civil(2016, 6, 1),
|
116
|
+
:name => "2016-June",
|
117
|
+
:regions => [:us],
|
118
|
+
},
|
119
|
+
],
|
120
|
+
@subject.call(@start_date, @end_date, @options)
|
121
|
+
)
|
122
|
+
end
|
123
|
+
|
124
|
+
def test_filters_holidays_returned_by_search_if_not_in_date_range
|
125
|
+
@start_date = Date.civil(2015, 1, 1)
|
126
|
+
@end_date = Date.civil(2015, 12, 31)
|
127
|
+
|
128
|
+
@definition_search.expects(:call).at_most_once.with(
|
129
|
+
@dates_driver,
|
130
|
+
@regions,
|
131
|
+
[],
|
132
|
+
).returns([
|
133
|
+
{
|
134
|
+
:date => Date.civil(2015, 6, 1),
|
135
|
+
:name => "2015-June",
|
136
|
+
:regions => [:us],
|
137
|
+
},
|
138
|
+
{
|
139
|
+
:date => Date.civil(2015, 1, 1),
|
140
|
+
:name => "2015-Jan",
|
141
|
+
:regions => [:us],
|
142
|
+
},
|
143
|
+
{
|
144
|
+
:date => Date.civil(2016, 6, 1),
|
145
|
+
:name => "2016-June",
|
146
|
+
:regions => [:us],
|
147
|
+
},
|
148
|
+
])
|
149
|
+
|
150
|
+
@dates_driver_builder.expects(:call).at_most_once.with(
|
151
|
+
@start_date, @end_date,
|
152
|
+
).returns(
|
153
|
+
@dates_driver,
|
154
|
+
)
|
155
|
+
|
156
|
+
assert_equal(
|
157
|
+
[
|
158
|
+
{
|
159
|
+
:date => Date.civil(2015, 1, 1),
|
160
|
+
:name => "2015-Jan",
|
161
|
+
:regions => [:us],
|
162
|
+
},
|
163
|
+
{
|
164
|
+
:date => Date.civil(2015, 6, 1),
|
165
|
+
:name => "2015-June",
|
166
|
+
:regions => [:us],
|
167
|
+
},
|
168
|
+
],
|
169
|
+
@subject.call(@start_date, @end_date, @options)
|
170
|
+
)
|
171
|
+
end
|
172
|
+
end
|
@@ -1,10 +1,10 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__)) + '/../../../test_helper'
|
2
2
|
|
3
|
-
require 'holidays/
|
3
|
+
require 'holidays/finder/context/dates_driver_builder'
|
4
4
|
|
5
5
|
class DatesDriverBuilderTests < Test::Unit::TestCase
|
6
6
|
def setup
|
7
|
-
@subject = Holidays::
|
7
|
+
@subject = Holidays::Finder::Context::DatesDriverBuilder.new
|
8
8
|
end
|
9
9
|
|
10
10
|
def test_returns_appropriately_formatted_hash
|
@@ -0,0 +1,156 @@
|
|
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
|