revised_holidays 9.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.
- checksums.yaml +7 -0
- data/.github/workflows/ruby.yml +25 -0
- data/CHANGELOG.md +446 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +3 -0
- data/LICENSE +21 -0
- data/Makefile +45 -0
- data/README.md +337 -0
- data/Rakefile +109 -0
- data/bin/console +7 -0
- data/bin/setup +6 -0
- data/definitions/.github/workflows/ruby.yml +25 -0
- data/definitions/.gitignore +5 -0
- data/definitions/CHANGELOG.md +352 -0
- data/definitions/Gemfile +6 -0
- data/definitions/LICENSE +21 -0
- data/definitions/METHODS.yml +26 -0
- data/definitions/Makefile +9 -0
- data/definitions/README.md +22 -0
- data/definitions/ar.yaml +268 -0
- data/definitions/at.yaml +116 -0
- data/definitions/au.yaml +907 -0
- data/definitions/be_fr.yaml +153 -0
- data/definitions/be_nl.yaml +153 -0
- data/definitions/bg.yaml +186 -0
- data/definitions/br.yaml +178 -0
- data/definitions/ca.yaml +969 -0
- data/definitions/ch.yaml +277 -0
- data/definitions/cl.yaml +294 -0
- data/definitions/co.yaml +437 -0
- data/definitions/cr.yaml +100 -0
- data/definitions/cz.yaml +137 -0
- data/definitions/de.yaml +401 -0
- data/definitions/dk.yaml +220 -0
- data/definitions/doc/CONTRIBUTING.md +44 -0
- data/definitions/doc/MAINTAINERS.md +39 -0
- data/definitions/doc/SYNTAX.md +435 -0
- data/definitions/doc/architecture/README.md +15 -0
- data/definitions/doc/architecture/adr-001.md +86 -0
- data/definitions/doc/architecture/adr-002.md +64 -0
- data/definitions/ecbtarget.yaml +74 -0
- data/definitions/ee.yaml +123 -0
- data/definitions/es.yaml +495 -0
- data/definitions/federalreserve.yaml +389 -0
- data/definitions/federalreservebanks.yaml +821 -0
- data/definitions/fedex.yaml +102 -0
- data/definitions/fi.yaml +234 -0
- data/definitions/fr.yaml +157 -0
- data/definitions/gb.yaml +565 -0
- data/definitions/ge.yaml +158 -0
- data/definitions/gr.yaml +158 -0
- data/definitions/hk.yaml +287 -0
- data/definitions/hr.yaml +171 -0
- data/definitions/hu.yaml +156 -0
- data/definitions/ie.yaml +172 -0
- data/definitions/index.yaml +80 -0
- data/definitions/is.yaml +247 -0
- data/definitions/it.yaml +246 -0
- data/definitions/jp.yaml +761 -0
- data/definitions/ke.yaml +107 -0
- data/definitions/kr.yaml +166 -0
- data/definitions/kz.yaml +128 -0
- data/definitions/li.yaml +154 -0
- data/definitions/lib/validation/custom_method_validator.rb +38 -0
- data/definitions/lib/validation/definition_validator.rb +35 -0
- data/definitions/lib/validation/error.rb +11 -0
- data/definitions/lib/validation/month_validator.rb +58 -0
- data/definitions/lib/validation/run.rb +66 -0
- data/definitions/lib/validation/test_validator.rb +83 -0
- data/definitions/lt.yaml +198 -0
- data/definitions/lu.yaml +123 -0
- data/definitions/lv.yaml +229 -0
- data/definitions/ma.yaml +96 -0
- data/definitions/mt_en.yaml +131 -0
- data/definitions/mt_mt.yaml +131 -0
- data/definitions/mx.yaml +160 -0
- data/definitions/my.yaml +79 -0
- data/definitions/nerc.yaml +94 -0
- data/definitions/ng.yaml +97 -0
- data/definitions/nl.yaml +127 -0
- data/definitions/no.yaml +169 -0
- data/definitions/northamericainformal.yaml +105 -0
- data/definitions/nyse.yaml +137 -0
- data/definitions/nz.yaml +346 -0
- data/definitions/pe.yaml +208 -0
- data/definitions/ph.yaml +130 -0
- data/definitions/pl.yaml +796 -0
- data/definitions/pt.yaml +187 -0
- data/definitions/ro.yaml +240 -0
- data/definitions/rs_cyrl.yaml +129 -0
- data/definitions/rs_la.yaml +129 -0
- data/definitions/ru.yaml +108 -0
- data/definitions/se.yaml +238 -0
- data/definitions/sg.yaml +89 -0
- data/definitions/si.yaml +162 -0
- data/definitions/sk.yaml +154 -0
- data/definitions/spec/coverage_report.rb +7 -0
- data/definitions/spec/data/invalid/months/malformed/bad.yaml +15 -0
- data/definitions/spec/data/invalid/months/missing/no_months.yaml +9 -0
- data/definitions/spec/data/valid/simple.yaml +15 -0
- data/definitions/spec/spec_helper.rb +7 -0
- data/definitions/spec/validation/custom_method_validator_spec.rb +60 -0
- data/definitions/spec/validation/definition_validator_spec.rb +43 -0
- data/definitions/spec/validation/month_validator_spec.rb +175 -0
- data/definitions/spec/validation/test_validator_spec.rb +169 -0
- data/definitions/th.yaml +111 -0
- data/definitions/tn.yaml +83 -0
- data/definitions/tr.yaml +174 -0
- data/definitions/ua.yaml +161 -0
- data/definitions/unitednations.yaml +189 -0
- data/definitions/ups.yaml +102 -0
- data/definitions/us.yaml +965 -0
- data/definitions/ve.yaml +118 -0
- data/definitions/vi.yaml +54 -0
- data/definitions/za.yaml +139 -0
- data/doc/CONTRIBUTING.md +72 -0
- data/doc/MAINTAINERS.md +81 -0
- data/doc/REFERENCES +19 -0
- data/lib/generated_definitions/MANIFEST +83 -0
- data/lib/generated_definitions/REGIONS.rb +6 -0
- data/lib/generated_definitions/ar.rb +60 -0
- data/lib/generated_definitions/at.rb +37 -0
- data/lib/generated_definitions/au.rb +177 -0
- data/lib/generated_definitions/be.rb +42 -0
- data/lib/generated_definitions/be_fr.rb +36 -0
- data/lib/generated_definitions/be_nl.rb +36 -0
- data/lib/generated_definitions/bg.rb +53 -0
- data/lib/generated_definitions/br.rb +37 -0
- data/lib/generated_definitions/ca.rb +88 -0
- data/lib/generated_definitions/ch.rb +95 -0
- data/lib/generated_definitions/cl.rb +71 -0
- data/lib/generated_definitions/co.rb +121 -0
- data/lib/generated_definitions/cr.rb +35 -0
- data/lib/generated_definitions/cz.rb +37 -0
- data/lib/generated_definitions/de.rb +65 -0
- data/lib/generated_definitions/dk.rb +48 -0
- data/lib/generated_definitions/ecbtarget.rb +30 -0
- data/lib/generated_definitions/ee.rb +36 -0
- data/lib/generated_definitions/el.rb +38 -0
- data/lib/generated_definitions/es.rb +56 -0
- data/lib/generated_definitions/europe.rb +638 -0
- data/lib/generated_definitions/federalreserve.rb +35 -0
- data/lib/generated_definitions/federalreservebanks.rb +35 -0
- data/lib/generated_definitions/fedex.rb +36 -0
- data/lib/generated_definitions/fi.rb +61 -0
- data/lib/generated_definitions/fr.rb +39 -0
- data/lib/generated_definitions/gb.rb +51 -0
- data/lib/generated_definitions/ge.rb +41 -0
- data/lib/generated_definitions/gr.rb +38 -0
- data/lib/generated_definitions/hk.rb +106 -0
- data/lib/generated_definitions/hr.rb +40 -0
- data/lib/generated_definitions/hu.rb +35 -0
- data/lib/generated_definitions/ie.rb +33 -0
- data/lib/generated_definitions/is.rb +60 -0
- data/lib/generated_definitions/it.rb +45 -0
- data/lib/generated_definitions/jp.rb +166 -0
- data/lib/generated_definitions/ke.rb +34 -0
- data/lib/generated_definitions/kr.rb +40 -0
- data/lib/generated_definitions/kz.rb +38 -0
- data/lib/generated_definitions/li.rb +44 -0
- data/lib/generated_definitions/lt.rb +38 -0
- data/lib/generated_definitions/lu.rb +35 -0
- data/lib/generated_definitions/lv.rb +56 -0
- data/lib/generated_definitions/ma.rb +33 -0
- data/lib/generated_definitions/mt_en.rb +38 -0
- data/lib/generated_definitions/mt_mt.rb +38 -0
- data/lib/generated_definitions/mx.rb +54 -0
- data/lib/generated_definitions/my.rb +30 -0
- data/lib/generated_definitions/nerc.rb +30 -0
- data/lib/generated_definitions/ng.rb +33 -0
- data/lib/generated_definitions/nl.rb +37 -0
- data/lib/generated_definitions/no.rb +40 -0
- data/lib/generated_definitions/northamerica.rb +229 -0
- data/lib/generated_definitions/nyse.rb +34 -0
- data/lib/generated_definitions/nz.rb +105 -0
- data/lib/generated_definitions/pe.rb +43 -0
- data/lib/generated_definitions/ph.rb +50 -0
- data/lib/generated_definitions/pl.rb +73 -0
- data/lib/generated_definitions/pt.rb +40 -0
- data/lib/generated_definitions/ro.rb +39 -0
- data/lib/generated_definitions/rs_cyrl.rb +39 -0
- data/lib/generated_definitions/rs_la.rb +39 -0
- data/lib/generated_definitions/ru.rb +37 -0
- data/lib/generated_definitions/scandinavia.rb +166 -0
- data/lib/generated_definitions/se.rb +53 -0
- data/lib/generated_definitions/sg.rb +31 -0
- data/lib/generated_definitions/si.rb +39 -0
- data/lib/generated_definitions/sk.rb +39 -0
- data/lib/generated_definitions/southamerica.rb +248 -0
- data/lib/generated_definitions/th.rb +36 -0
- data/lib/generated_definitions/tn.rb +32 -0
- data/lib/generated_definitions/tr.rb +64 -0
- data/lib/generated_definitions/ua.rb +37 -0
- data/lib/generated_definitions/unitednations.rb +81 -0
- data/lib/generated_definitions/ups.rb +36 -0
- data/lib/generated_definitions/us.rb +153 -0
- data/lib/generated_definitions/ve.rb +36 -0
- data/lib/generated_definitions/vi.rb +29 -0
- data/lib/generated_definitions/za.rb +36 -0
- data/lib/holidays/core_extensions/date.rb +57 -0
- data/lib/holidays/core_extensions/time.rb +23 -0
- data/lib/holidays/date_calculator/day_of_month.rb +68 -0
- data/lib/holidays/date_calculator/easter.rb +91 -0
- data/lib/holidays/date_calculator/lunar_date.rb +371 -0
- data/lib/holidays/date_calculator/weekend_modifier.rb +80 -0
- data/lib/holidays/definition/context/function_processor.rb +91 -0
- data/lib/holidays/definition/context/generator.rb +209 -0
- data/lib/holidays/definition/context/load.rb +29 -0
- data/lib/holidays/definition/context/merger.rb +22 -0
- data/lib/holidays/definition/decorator/custom_method_proc.rb +28 -0
- data/lib/holidays/definition/decorator/custom_method_source.rb +30 -0
- data/lib/holidays/definition/decorator/test.rb +37 -0
- data/lib/holidays/definition/entity/custom_method.rb +11 -0
- data/lib/holidays/definition/entity/test.rb +11 -0
- data/lib/holidays/definition/generator/module.rb +54 -0
- data/lib/holidays/definition/generator/regions.rb +55 -0
- data/lib/holidays/definition/generator/test.rb +51 -0
- data/lib/holidays/definition/parser/custom_method.rb +67 -0
- data/lib/holidays/definition/parser/test.rb +86 -0
- data/lib/holidays/definition/repository/cache.rb +47 -0
- data/lib/holidays/definition/repository/custom_methods.rb +27 -0
- data/lib/holidays/definition/repository/holidays_by_month.rb +57 -0
- data/lib/holidays/definition/repository/proc_result_cache.rb +51 -0
- data/lib/holidays/definition/repository/regions.rb +46 -0
- data/lib/holidays/definition/validator/custom_method.rb +31 -0
- data/lib/holidays/definition/validator/region.rb +36 -0
- data/lib/holidays/definition/validator/test.rb +71 -0
- data/lib/holidays/errors.rb +11 -0
- data/lib/holidays/factory/date_calculator.rb +42 -0
- data/lib/holidays/factory/definition.rb +143 -0
- data/lib/holidays/factory/finder.rb +70 -0
- data/lib/holidays/finder/context/between.rb +45 -0
- data/lib/holidays/finder/context/dates_driver_builder.rb +64 -0
- data/lib/holidays/finder/context/next_holiday.rb +57 -0
- data/lib/holidays/finder/context/parse_options.rb +104 -0
- data/lib/holidays/finder/context/search.rb +111 -0
- data/lib/holidays/finder/context/year_holiday.rb +57 -0
- data/lib/holidays/finder/rules/in_region.rb +31 -0
- data/lib/holidays/finder/rules/year_range.rb +58 -0
- data/lib/holidays/load_all_definitions.rb +56 -0
- data/lib/holidays/version.rb +3 -0
- data/lib/holidays.rb +130 -0
- data/lib/revised_holidays.rb +1 -0
- data/revised_holidays.gemspec +31 -0
- data/test/coverage_report.rb +26 -0
- data/test/data/test_custom_govt_holiday_defs.yaml +5 -0
- data/test/data/test_custom_informal_holidays_defs.yaml +11 -0
- data/test/data/test_custom_year_range_holiday_defs.yaml +31 -0
- data/test/data/test_invalid_region.rb +15 -0
- data/test/data/test_multiple_custom_holiday_defs.yaml +12 -0
- data/test/data/test_multiple_regions_with_conflicts_region_1.yaml +38 -0
- data/test/data/test_multiple_regions_with_conflicts_region_2.yaml +38 -0
- data/test/data/test_region.rb +15 -0
- data/test/data/test_single_custom_holiday_defs.yaml +12 -0
- data/test/data/test_single_custom_holiday_with_custom_procs.yaml +28 -0
- data/test/defs/test_defs_ar.rb +69 -0
- data/test/defs/test_defs_at.rb +31 -0
- data/test/defs/test_defs_au.rb +233 -0
- data/test/defs/test_defs_be_fr.rb +45 -0
- data/test/defs/test_defs_be_nl.rb +45 -0
- data/test/defs/test_defs_bg.rb +41 -0
- data/test/defs/test_defs_br.rb +49 -0
- data/test/defs/test_defs_ca.rb +289 -0
- data/test/defs/test_defs_ch.rb +51 -0
- data/test/defs/test_defs_cl.rb +69 -0
- data/test/defs/test_defs_co.rb +113 -0
- data/test/defs/test_defs_cr.rb +29 -0
- data/test/defs/test_defs_cz.rb +37 -0
- data/test/defs/test_defs_de.rb +89 -0
- data/test/defs/test_defs_dk.rb +47 -0
- data/test/defs/test_defs_ecbtarget.rb +27 -0
- data/test/defs/test_defs_ee.rb +41 -0
- data/test/defs/test_defs_es.rb +137 -0
- data/test/defs/test_defs_europe.rb +1522 -0
- data/test/defs/test_defs_fed_ex.rb +24 -0
- data/test/defs/test_defs_federalreserve.rb +119 -0
- data/test/defs/test_defs_federalreservebanks.rb +251 -0
- data/test/defs/test_defs_fedex.rb +31 -0
- data/test/defs/test_defs_fi.rb +59 -0
- data/test/defs/test_defs_fr.rb +43 -0
- data/test/defs/test_defs_gb.rb +159 -0
- data/test/defs/test_defs_ge.rb +53 -0
- data/test/defs/test_defs_gr.rb +41 -0
- data/test/defs/test_defs_hk.rb +59 -0
- data/test/defs/test_defs_hr.rb +45 -0
- data/test/defs/test_defs_hu.rb +47 -0
- data/test/defs/test_defs_ie.rb +53 -0
- data/test/defs/test_defs_is.rb +51 -0
- data/test/defs/test_defs_it.rb +55 -0
- data/test/defs/test_defs_jp.rb +159 -0
- data/test/defs/test_defs_ke.rb +31 -0
- data/test/defs/test_defs_kr.rb +37 -0
- data/test/defs/test_defs_kz.rb +39 -0
- data/test/defs/test_defs_li.rb +35 -0
- data/test/defs/test_defs_lt.rb +65 -0
- data/test/defs/test_defs_lu.rb +35 -0
- data/test/defs/test_defs_lv.rb +98 -0
- data/test/defs/test_defs_ma.rb +29 -0
- data/test/defs/test_defs_mt_en.rb +41 -0
- data/test/defs/test_defs_mt_mt.rb +41 -0
- data/test/defs/test_defs_mx.rb +49 -0
- data/test/defs/test_defs_my.rb +23 -0
- data/test/defs/test_defs_nerc.rb +29 -0
- data/test/defs/test_defs_ng.rb +29 -0
- data/test/defs/test_defs_nl.rb +33 -0
- data/test/defs/test_defs_no.rb +43 -0
- data/test/defs/test_defs_northamerica.rb +667 -0
- data/test/defs/test_defs_nyse.rb +46 -0
- data/test/defs/test_defs_nz.rb +67 -0
- data/test/defs/test_defs_pe.rb +47 -0
- data/test/defs/test_defs_ph.rb +29 -0
- data/test/defs/test_defs_pl.rb +229 -0
- data/test/defs/test_defs_pt.rb +47 -0
- data/test/defs/test_defs_ro.rb +65 -0
- data/test/defs/test_defs_rs_cyrl.rb +46 -0
- data/test/defs/test_defs_rs_la.rb +46 -0
- data/test/defs/test_defs_ru.rb +34 -0
- data/test/defs/test_defs_scandinavia.rb +215 -0
- data/test/defs/test_defs_se.rb +59 -0
- data/test/defs/test_defs_sg.rb +25 -0
- data/test/defs/test_defs_si.rb +105 -0
- data/test/defs/test_defs_sk.rb +41 -0
- data/test/defs/test_defs_southamerica.rb +327 -0
- data/test/defs/test_defs_th.rb +33 -0
- data/test/defs/test_defs_tn.rb +27 -0
- data/test/defs/test_defs_tr.rb +60 -0
- data/test/defs/test_defs_ua.rb +41 -0
- data/test/defs/test_defs_unitednations.rb +11 -0
- data/test/defs/test_defs_ups.rb +31 -0
- data/test/defs/test_defs_us.rb +387 -0
- data/test/defs/test_defs_ve.rb +35 -0
- data/test/defs/test_defs_vi.rb +22 -0
- data/test/defs/test_defs_za.rb +35 -0
- data/test/holidays/core_extensions/test_date.rb +122 -0
- data/test/holidays/core_extensions/test_date_time.rb +60 -0
- data/test/holidays/date_calculator/test_day_of_month.rb +27 -0
- data/test/holidays/date_calculator/test_easter_gregorian.rb +30 -0
- data/test/holidays/date_calculator/test_easter_julian.rb +36 -0
- data/test/holidays/date_calculator/test_lunar_date.rb +89 -0
- data/test/holidays/date_calculator/test_weekend_modifier.rb +54 -0
- data/test/holidays/definition/context/test_function_processor.rb +199 -0
- data/test/holidays/definition/context/test_generator.rb +226 -0
- data/test/holidays/definition/context/test_load.rb +37 -0
- data/test/holidays/definition/context/test_merger.rb +25 -0
- data/test/holidays/definition/decorator/test_custom_method_proc.rb +113 -0
- data/test/holidays/definition/decorator/test_custom_method_source.rb +96 -0
- data/test/holidays/definition/decorator/test_test.rb +123 -0
- data/test/holidays/definition/generator/test_module.rb +268 -0
- data/test/holidays/definition/generator/test_regions.rb +97 -0
- data/test/holidays/definition/generator/test_test.rb +113 -0
- data/test/holidays/definition/parser/test_custom_method.rb +79 -0
- data/test/holidays/definition/parser/test_test.rb +142 -0
- data/test/holidays/definition/repository/test_cache.rb +123 -0
- data/test/holidays/definition/repository/test_custom_methods.rb +43 -0
- data/test/holidays/definition/repository/test_holidays_by_month.rb +275 -0
- data/test/holidays/definition/repository/test_proc_result_cache.rb +91 -0
- data/test/holidays/definition/repository/test_regions.rb +104 -0
- data/test/holidays/definition/validator/test_custom_method.rb +94 -0
- data/test/holidays/definition/validator/test_region.rb +54 -0
- data/test/holidays/definition/validator/test_test.rb +60 -0
- data/test/holidays/finder/context/test_between.rb +172 -0
- data/test/holidays/finder/context/test_dates_driver_builder.rb +91 -0
- data/test/holidays/finder/context/test_next_holiday.rb +156 -0
- data/test/holidays/finder/context/test_parse_options.rb +141 -0
- data/test/holidays/finder/context/test_search.rb +232 -0
- data/test/holidays/finder/context/test_year_holiday.rb +202 -0
- data/test/holidays/finder/rules/test_in_region.rb +42 -0
- data/test/holidays/finder/rules/test_year_range.rb +166 -0
- data/test/integration/README.md +9 -0
- data/test/integration/test_all_regions.rb +49 -0
- data/test/integration/test_any_holidays_during_work_week.rb +90 -0
- data/test/integration/test_available_regions.rb +23 -0
- data/test/integration/test_custom_holidays.rb +41 -0
- data/test/integration/test_custom_informal_holidays.rb +15 -0
- data/test/integration/test_custom_year_range_holidays.rb +35 -0
- data/test/integration/test_holidays.rb +243 -0
- data/test/integration/test_holidays_between.rb +87 -0
- data/test/integration/test_multiple_regions.rb +71 -0
- data/test/integration/test_multiple_regions_with_conflict.rb +29 -0
- data/test/integration/test_nonstandard_regions.rb +25 -0
- data/test/test_helper.rb +37 -0
- metadata +649 -0
|
@@ -0,0 +1,141 @@
|
|
|
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
|
|
@@ -0,0 +1,232 @@
|
|
|
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
|
+
end
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__)) + '/../../../test_helper'
|
|
2
|
+
|
|
3
|
+
require 'holidays/finder/context/year_holiday'
|
|
4
|
+
|
|
5
|
+
class YearHolidayTests < 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::YearHoliday.new(
|
|
16
|
+
@definition_search,
|
|
17
|
+
@dates_driver_builder,
|
|
18
|
+
@options_parser,
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
@from_date= Date.civil(2015, 1, 1)
|
|
22
|
+
@dates_driver = {2015 => [0, 1, 2], 2014 => [0, 12]}
|
|
23
|
+
@options = [@regions, @observed, @informal]
|
|
24
|
+
|
|
25
|
+
@definition_search.expects(:call).at_most_once.with(
|
|
26
|
+
@dates_driver,
|
|
27
|
+
@regions,
|
|
28
|
+
[],
|
|
29
|
+
).returns([{
|
|
30
|
+
:date => Date.civil(2015, 1, 1),
|
|
31
|
+
:name => "Test",
|
|
32
|
+
:regions => [:us],
|
|
33
|
+
}])
|
|
34
|
+
|
|
35
|
+
@dates_driver_builder.expects(:call).at_most_once.with(
|
|
36
|
+
@from_date, @from_date >> 12,
|
|
37
|
+
).returns(
|
|
38
|
+
@dates_driver,
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
@options_parser.expects(:call).at_most_once.with(@options).returns(@options)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def test_returns_error_if_from_date_is_missing
|
|
45
|
+
assert_raise ArgumentError do
|
|
46
|
+
@subject.call(nil, @options)
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def test_returns_error_if_from_date_is_not_a_date
|
|
51
|
+
assert_raise ArgumentError do
|
|
52
|
+
@subject.call("2015-1-1", @options)
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def test_returns_single_holiday
|
|
57
|
+
assert_equal(
|
|
58
|
+
[
|
|
59
|
+
{
|
|
60
|
+
:date => Date.civil(2015, 1, 1),
|
|
61
|
+
:name => "Test",
|
|
62
|
+
:regions => [:us],
|
|
63
|
+
}
|
|
64
|
+
],
|
|
65
|
+
@subject.call(@from_date, @options)
|
|
66
|
+
)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def test_returns_multiple_holidays_in_a_year
|
|
70
|
+
@definition_search.expects(:call).at_most_once.with(
|
|
71
|
+
@dates_driver,
|
|
72
|
+
@regions,
|
|
73
|
+
[],
|
|
74
|
+
).returns([
|
|
75
|
+
{
|
|
76
|
+
:date => Date.civil(2015, 1, 1),
|
|
77
|
+
:name => "Test",
|
|
78
|
+
:regions => [:us],
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
:date => Date.civil(2015, 2, 1),
|
|
82
|
+
:name => "Test",
|
|
83
|
+
:regions => [:us],
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
:date => Date.civil(2015, 12, 1),
|
|
87
|
+
:name => "Test",
|
|
88
|
+
:regions => [:us],
|
|
89
|
+
},
|
|
90
|
+
]
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
assert_equal(
|
|
94
|
+
[
|
|
95
|
+
{
|
|
96
|
+
:date => Date.civil(2015, 1, 1),
|
|
97
|
+
:name => "Test",
|
|
98
|
+
:regions => [:us],
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
:date => Date.civil(2015, 2, 1),
|
|
102
|
+
:name => "Test",
|
|
103
|
+
:regions => [:us],
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
:date => Date.civil(2015, 12, 1),
|
|
107
|
+
:name => "Test",
|
|
108
|
+
:regions => [:us],
|
|
109
|
+
}
|
|
110
|
+
],
|
|
111
|
+
@subject.call(@from_date, @options)
|
|
112
|
+
)
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def test_returns_multiple_holidays_filters_dates_outside_of_year
|
|
116
|
+
@definition_search.expects(:call).at_most_once.with(
|
|
117
|
+
@dates_driver,
|
|
118
|
+
@regions,
|
|
119
|
+
[],
|
|
120
|
+
).returns([
|
|
121
|
+
{
|
|
122
|
+
:date => Date.civil(2015, 1, 1),
|
|
123
|
+
:name => "Test",
|
|
124
|
+
:regions => [:us],
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
:date => Date.civil(2015, 2, 1),
|
|
128
|
+
:name => "Test",
|
|
129
|
+
:regions => [:us],
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
:date => Date.civil(2016, 12, 1),
|
|
133
|
+
:name => "Test",
|
|
134
|
+
:regions => [:us],
|
|
135
|
+
},
|
|
136
|
+
]
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
assert_equal(
|
|
140
|
+
[
|
|
141
|
+
{
|
|
142
|
+
:date => Date.civil(2015, 1, 1),
|
|
143
|
+
:name => "Test",
|
|
144
|
+
:regions => [:us],
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
:date => Date.civil(2015, 2, 1),
|
|
148
|
+
:name => "Test",
|
|
149
|
+
:regions => [:us],
|
|
150
|
+
},
|
|
151
|
+
],
|
|
152
|
+
@subject.call(@from_date, @options)
|
|
153
|
+
)
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
def test_returns_sorted_multiple_holidays
|
|
157
|
+
@definition_search.expects(:call).at_most_once.with(
|
|
158
|
+
@dates_driver,
|
|
159
|
+
@regions,
|
|
160
|
+
[],
|
|
161
|
+
).returns(
|
|
162
|
+
[
|
|
163
|
+
{
|
|
164
|
+
:date => Date.civil(2015, 1, 1),
|
|
165
|
+
:name => "Test",
|
|
166
|
+
:regions => [:us],
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
:date => Date.civil(2015, 12, 1),
|
|
170
|
+
:name => "Test",
|
|
171
|
+
:regions => [:us],
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
:date => Date.civil(2015, 2, 1),
|
|
175
|
+
:name => "Test",
|
|
176
|
+
:regions => [:us],
|
|
177
|
+
},
|
|
178
|
+
]
|
|
179
|
+
)
|
|
180
|
+
|
|
181
|
+
assert_equal(
|
|
182
|
+
[
|
|
183
|
+
{
|
|
184
|
+
:date => Date.civil(2015, 1, 1),
|
|
185
|
+
:name => "Test",
|
|
186
|
+
:regions => [:us],
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
:date => Date.civil(2015, 2, 1),
|
|
190
|
+
:name => "Test",
|
|
191
|
+
:regions => [:us],
|
|
192
|
+
},
|
|
193
|
+
{
|
|
194
|
+
:date => Date.civil(2015, 12, 1),
|
|
195
|
+
:name => "Test",
|
|
196
|
+
:regions => [:us],
|
|
197
|
+
}
|
|
198
|
+
],
|
|
199
|
+
@subject.call(@from_date, @options)
|
|
200
|
+
)
|
|
201
|
+
end
|
|
202
|
+
end
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__)) + '/../../../test_helper'
|
|
2
|
+
|
|
3
|
+
require 'holidays/finder/rules/in_region'
|
|
4
|
+
|
|
5
|
+
class FinderRulesInRegionTests < Test::Unit::TestCase
|
|
6
|
+
def setup
|
|
7
|
+
@available = [:test]
|
|
8
|
+
@subject = Holidays::Finder::Rules::InRegion
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def test_returns_true_if_any_specified
|
|
12
|
+
assert_equal(true, @subject.call([:any], @available))
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def test_returns_true_if_exact_match_found
|
|
16
|
+
assert_equal(true, @subject.call([:test], @available))
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def test_returns_true_if_subregion_matches_parent
|
|
20
|
+
assert_equal(true, @subject.call([:test_sub], @available))
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def test_returns_true_if_subregion_matches_grandparent
|
|
24
|
+
assert_equal(true, @subject.call([:test_sub_sub], @available))
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def test_returns_true_if_subregion_is_in_available
|
|
28
|
+
assert_equal(true, @subject.call([:test_sub], [:test, :test_sub]))
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def test_returns_false_if_match_not_found
|
|
32
|
+
assert_equal(false, @subject.call([:other], @available))
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def test_returns_false_if_match_not_found_for_subregion
|
|
36
|
+
assert_equal(false, @subject.call([:other_sub], @available))
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def test_returns_true_if_request_includes_nonmatching_but_also_any
|
|
40
|
+
assert_equal(true, @subject.call([:other_sub, :other, :any], @available))
|
|
41
|
+
end
|
|
42
|
+
end
|