From da5ed5c411305b1e89021c14793bddcd2786be3f Mon Sep 17 00:00:00 2001 From: Jon Pascoe Date: Fri, 10 May 2024 08:29:36 +0100 Subject: [PATCH 01/10] Update documentation links in gemspec --- ice_cube.gemspec | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ice_cube.gemspec b/ice_cube.gemspec index b1924c18..a2016902 100644 --- a/ice_cube.gemspec +++ b/ice_cube.gemspec @@ -8,11 +8,11 @@ Gem::Specification.new do |s| s.description = "ice_cube is a recurring date library for Ruby. It allows for quick, programatic expansion of recurring date rules." s.author = "John Crepezzi" s.email = "john@crepezzi.com" - s.homepage = "https://seejohnrun.github.io/ice_cube/" + s.homepage = "https://ice-cube-ruby.github.io/ice_cube/" s.license = "MIT" - s.metadata["changelog_uri"] = "https://github.com/seejohnrun/ice_cube/blob/master/CHANGELOG.md" - s.metadata["wiki_uri"] = "https://github.com/seejohnrun/ice_cube/wiki" + s.metadata["changelog_uri"] = "https://github.com/ice-cube-ruby/ice_cube/blob/master/CHANGELOG.md" + s.metadata["wiki_uri"] = "https://github.com/ice-cube-ruby/ice_cube/wiki" s.version = IceCube::VERSION s.platform = Gem::Platform::RUBY From 4f56d19ec532e5ca41af675b2a99de9da64de013 Mon Sep 17 00:00:00 2001 From: Jon Pascoe Date: Fri, 10 May 2024 17:34:48 +0100 Subject: [PATCH 02/10] Add rule_type validation specs --- lib/ice_cube/rule.rb | 5 +--- spec/examples/from_hash_spec.rb | 45 +++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 4 deletions(-) create mode 100644 spec/examples/from_hash_spec.rb diff --git a/lib/ice_cube/rule.rb b/lib/ice_cube/rule.rb index 6652c3db..30689267 100644 --- a/lib/ice_cube/rule.rb +++ b/lib/ice_cube/rule.rb @@ -73,10 +73,7 @@ def from_hash(original_hash) rule = IceCube::Rule.send(interval_type, hash[:interval] || 1) - if match[1] == "Weekly" - rule.interval(hash[:interval] || 1, TimeUtil.wday_to_sym(hash[:week_start] || 0)) - end - + rule.interval(hash[:interval] || 1, TimeUtil.wday_to_sym(hash[:week_start] || 0)) if rule.is_a? WeeklyRule rule.until(TimeUtil.deserialize_time(hash[:until])) if hash[:until] rule.count(hash[:count]) if hash[:count] diff --git a/spec/examples/from_hash_spec.rb b/spec/examples/from_hash_spec.rb new file mode 100644 index 00000000..70c26ba2 --- /dev/null +++ b/spec/examples/from_hash_spec.rb @@ -0,0 +1,45 @@ +require File.dirname(__FILE__) + "/../spec_helper" + +module IceCube + describe Rule, "from_hash" do + describe "rule_type validations" do + it "should raise an ArgumentError when the hash is empty" do + expect { Rule.from_hash({}) } + .to raise_error ArgumentError, "Invalid rule type" + end + + it "should raise an ArgumentError when the hash[:rule_type] is invalid" do + expect { Rule.from_hash({ rule_type: "IceCube::MadeUpIntervalRule" }) } + .to raise_error ArgumentError, "Invalid rule frequency type: MadeUpInterval" + end + + it "returns a SecondlyRule when the hash[:rule_type] is secondly" do + expect(Rule.from_hash({ rule_type: "IceCube::SecondlyRule" })).to be_a SecondlyRule + end + + it "returns a MinutelyRule when the hash[:rule_type] is minutely" do + expect(Rule.from_hash({ rule_type: "IceCube::MinutelyRule" })).to be_a MinutelyRule + end + + it "returns a HourlyRule when the hash[:rule_type] is hourly" do + expect(Rule.from_hash({ rule_type: "IceCube::HourlyRule" })).to be_a HourlyRule + end + + it "returns a DailyRule when the hash[:rule_type] is daily" do + expect(Rule.from_hash({ rule_type: "IceCube::DailyRule" })).to be_a DailyRule + end + + it "returns a WeeklyRule when the hash[:rule_type] is weekly" do + expect(Rule.from_hash({ rule_type: "IceCube::WeeklyRule" })).to be_a WeeklyRule + end + + it "returns a MonthlyRule when the hash[:rule_type] is monthly" do + expect(Rule.from_hash({ rule_type: "IceCube::MonthlyRule" })).to be_a MonthlyRule + end + + it "returns a YearlyRule when the hash[:rule_type] is yearly" do + expect(Rule.from_hash({ rule_type: "IceCube::YearlyRule" })).to be_a YearlyRule + end + end + end +end From e2084e0d8f148eb4b5be402b60847ef3bf872428 Mon Sep 17 00:00:00 2001 From: Jon Pascoe Date: Fri, 10 May 2024 21:41:25 +0100 Subject: [PATCH 03/10] Validate occurrence passed to day_of_week --- lib/ice_cube/validations/day_of_week.rb | 2 + spec/examples/from_hash_spec.rb | 84 +++++++++++++++++++++++++ spec/examples/time_util_spec.rb | 30 +++++---- spec/examples/weekly_rule_spec.rb | 2 +- 4 files changed, 105 insertions(+), 13 deletions(-) diff --git a/lib/ice_cube/validations/day_of_week.rb b/lib/ice_cube/validations/day_of_week.rb index c04695bc..12937d90 100644 --- a/lib/ice_cube/validations/day_of_week.rb +++ b/lib/ice_cube/validations/day_of_week.rb @@ -15,6 +15,8 @@ class Validation attr_reader :day, :occ def initialize(day, occ) + raise ArgumentError, "Invalid day_of_week occurrence: #{occ}" if occ == 0 || occ > 5 || occ < -5 + @day = day @occ = occ end diff --git a/spec/examples/from_hash_spec.rb b/spec/examples/from_hash_spec.rb index 70c26ba2..11d8d624 100644 --- a/spec/examples/from_hash_spec.rb +++ b/spec/examples/from_hash_spec.rb @@ -41,5 +41,89 @@ module IceCube expect(Rule.from_hash({ rule_type: "IceCube::YearlyRule" })).to be_a YearlyRule end end + + describe "creating monthly rule" do + context "with valid day_of_week validations" do + let(:input_hash) { + { + "rule_type": "IceCube::MonthlyRule", + "interval": 1, + "validations": { + "day_of_week": { + "0": [2], + "1": [2], + "2": [2], + "3": [2], + "4": [2], + "5": [2], + "6": [1,2] + }, + "hour_of_day": 7, + "minute_of_hour": 19 + } + } + } + + it "can provide the first occurrence" do + rule = Rule.from_hash(input_hash) + schedule = Schedule.new(Time.utc(2010, 1, 1, 0, 0, 0)) + schedule.add_recurrence_rule rule + expect(schedule.first(10).map(&:to_time)).to eq([ + Time.utc(2010, 1, 2, 7, 19, 0), + Time.utc(2010, 1, 8, 7, 19, 0), + Time.utc(2010, 1, 9, 7, 19, 0), + Time.utc(2010, 1, 10, 7, 19, 0), + Time.utc(2010, 1, 11, 7, 19, 0), + Time.utc(2010, 1, 12, 7, 19, 0), + Time.utc(2010, 1, 13, 7, 19, 0), + Time.utc(2010, 1, 14, 7, 19, 0), + Time.utc(2010, 2, 6, 7, 19, 0), + Time.utc(2010, 2, 8, 7, 19, 0) + ]) + end + end + + context "with invalid day_of_week validations" do + let(:input_hash_with_zeroeth_occurrence) { + { + "rule_type": "IceCube::MonthlyRule", + "interval": 1, + "validations": { + "day_of_week": { + "1": [], + "2": [0], + "3": [], + "4": [] + }, + "hour_of_day": 7, + "minute_of_hour": 19 + } + } + } + let(:input_hash_with_sixth_occurrence) { + { + "rule_type": "IceCube::MonthlyRule", + "interval": 1, + "validations": { + "day_of_week": { + "1": [], + "2": [6], + "3": [], + "4": [] + }, + "hour_of_day": 7, + "minute_of_hour": 19 + } + } + } + + it "should raise an ArgumentError" do + expect { Rule.from_hash(input_hash_with_zeroeth_occurrence) } + .to raise_error ArgumentError, "Invalid day_of_week occurrence: 0" + expect { Rule.from_hash(input_hash_with_sixth_occurrence) } + .to raise_error ArgumentError, "Invalid day_of_week occurrence: 6" + end + end + end end end diff --git a/spec/examples/time_util_spec.rb b/spec/examples/time_util_spec.rb index 43491a8b..c6a434d6 100644 --- a/spec/examples/time_util_spec.rb +++ b/spec/examples/time_util_spec.rb @@ -42,32 +42,38 @@ module IceCube end describe :wday_to_sym do - it "converts 0..6 to weekday symbols" do - expect(TimeUtil.wday_to_sym(1)).to eq(:monday) - end + [:sunday, :monday, :tuesday, :wednesday, :thursday, :friday, :saturday].each_with_index do |sym, i| + it "converts #{i} to weekday symbol :#{sym}" do + expect(TimeUtil.wday_to_sym(i)).to eq(sym) + end - it "returns weekday symbols as is" do - expect(TimeUtil.wday_to_sym(:monday)).to eq(:monday) + it "returns :#{sym} when passed :#{sym}" do + expect(TimeUtil.wday_to_sym(sym)).to eq(sym) + end end it "raises an error for bad input" do expect { TimeUtil.wday_to_sym(:anyday) }.to raise_error(ArgumentError) - expect { TimeUtil.wday_to_sym(17) }.to raise_error(ArgumentError) + expect { TimeUtil.wday_to_sym(8) }.to raise_error(ArgumentError) + expect { TimeUtil.wday_to_sym(-1) }.to raise_error(ArgumentError) end end describe :sym_to_wday do - it "converts weekday symbols to 0..6 wday numbers" do - expect(TimeUtil.sym_to_wday(:monday)).to eq(1) - end + [:sunday, :monday, :tuesday, :wednesday, :thursday, :friday, :saturday].each_with_index do |sym, i| + it "converts :#{sym} to integer #{i}" do + expect(TimeUtil.sym_to_wday(sym)).to eq(i) + end - it "returns wday numbers as is" do - expect(TimeUtil.sym_to_wday(1)).to eq(1) + it "returns #{i} when passed #{i}" do + expect(TimeUtil.sym_to_wday(i)).to eq(i) + end end it "raises an error for bad input" do expect { TimeUtil.sym_to_wday(:anyday) }.to raise_error(ArgumentError) - expect { TimeUtil.sym_to_wday(17) }.to raise_error(ArgumentError) + expect { TimeUtil.sym_to_wday(-1) }.to raise_error(ArgumentError) + expect { TimeUtil.sym_to_wday(8) }.to raise_error(ArgumentError) end end diff --git a/spec/examples/weekly_rule_spec.rb b/spec/examples/weekly_rule_spec.rb index 3e8e5719..c59de2d2 100644 --- a/spec/examples/weekly_rule_spec.rb +++ b/spec/examples/weekly_rule_spec.rb @@ -96,7 +96,7 @@ module IceCube it "should raise an error on invalid input" do schedule = Schedule.new(WEDNESDAY) - expect { schedule.add_recurrence_rule Rule.weekly.day(["1", "3"]) }.to raise_error(ArgumentError) + expect { schedule.add_recurrence_rule Rule.weekly.day(["1", "3"]) }.to raise_error(ArgumentError, "expecting Integer or Symbol value for day, got \"1\"") end it "should ignore weekday validation when no days are specified" do From cb8832c09dc26ce8bd8cdc8d6a57e69ad62abb96 Mon Sep 17 00:00:00 2001 From: Jon Pascoe Date: Fri, 10 May 2024 21:51:41 +0100 Subject: [PATCH 04/10] Update CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7710a7b0..342362aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - When using a rule with hour_of_day validations, and asking for occurrences on the day that DST skips forward, valid occurrences would be missed. ([#464](https://github.com/seejohnrun/ice_cube/pull/464)) by [@jakebrady5](https://github.com/jakebrady5) - Include `exrules` when exporting a schedule to YAML, JSON or a Hash. ([#519](https://github.com/ice-cube-ruby/ice_cube/pull/519)) by [@pacso](https://github.com/pacso) - Documentation links updated to point to the new repository location. ([#553](https://github.com/ice-cube-ruby/ice_cube/pull/553)) by [@pacso](https://github.com/pacso) +- Input validation added for day_of_week validator. Fixes infinite loops when invalid day_of_week occurrences are provided. ([#554](https://github.com/ice-cube-ruby/ice_cube/pull/554)) by [@pacso](https://github.com/pacso) ## [0.16.4] - 2021-10-21 ### Added From 80f77fe721e7e7fef6138b1c6f5761ad1b55fc75 Mon Sep 17 00:00:00 2001 From: Jon Pascoe Date: Fri, 10 May 2024 21:55:11 +0100 Subject: [PATCH 05/10] linting --- lib/ice_cube/i18n.rb | 8 ++-- lib/ice_cube/rule.rb | 4 +- spec/examples/from_hash_spec.rb | 76 ++++++++++++++++----------------- 3 files changed, 44 insertions(+), 44 deletions(-) diff --git a/lib/ice_cube/i18n.rb b/lib/ice_cube/i18n.rb index 6f135026..f8cf2f04 100644 --- a/lib/ice_cube/i18n.rb +++ b/lib/ice_cube/i18n.rb @@ -4,12 +4,12 @@ module IceCube module I18n LOCALES_PATH = File.expand_path(File.join("..", "..", "..", "config", "locales"), __FILE__) - def self.t(*args, **kwargs) - backend.t(*args, **kwargs) + def self.t(*, **) + backend.t(*, **) end - def self.l(*args, **kwargs) - backend.l(*args, **kwargs) + def self.l(*, **) + backend.l(*, **) end def self.backend diff --git a/lib/ice_cube/rule.rb b/lib/ice_cube/rule.rb index 30689267..6c4c96ef 100644 --- a/lib/ice_cube/rule.rb +++ b/lib/ice_cube/rule.rb @@ -36,8 +36,8 @@ def self.from_ical(ical) end # Yaml implementation - def to_yaml(*args) - YAML.dump(to_hash, *args) + def to_yaml(*) + YAML.dump(to_hash, *) end # From yaml diff --git a/spec/examples/from_hash_spec.rb b/spec/examples/from_hash_spec.rb index 11d8d624..7ef09632 100644 --- a/spec/examples/from_hash_spec.rb +++ b/spec/examples/from_hash_spec.rb @@ -9,36 +9,36 @@ module IceCube end it "should raise an ArgumentError when the hash[:rule_type] is invalid" do - expect { Rule.from_hash({ rule_type: "IceCube::MadeUpIntervalRule" }) } + expect { Rule.from_hash({rule_type: "IceCube::MadeUpIntervalRule"}) } .to raise_error ArgumentError, "Invalid rule frequency type: MadeUpInterval" end it "returns a SecondlyRule when the hash[:rule_type] is secondly" do - expect(Rule.from_hash({ rule_type: "IceCube::SecondlyRule" })).to be_a SecondlyRule + expect(Rule.from_hash({rule_type: "IceCube::SecondlyRule"})).to be_a SecondlyRule end it "returns a MinutelyRule when the hash[:rule_type] is minutely" do - expect(Rule.from_hash({ rule_type: "IceCube::MinutelyRule" })).to be_a MinutelyRule + expect(Rule.from_hash({rule_type: "IceCube::MinutelyRule"})).to be_a MinutelyRule end it "returns a HourlyRule when the hash[:rule_type] is hourly" do - expect(Rule.from_hash({ rule_type: "IceCube::HourlyRule" })).to be_a HourlyRule + expect(Rule.from_hash({rule_type: "IceCube::HourlyRule"})).to be_a HourlyRule end it "returns a DailyRule when the hash[:rule_type] is daily" do - expect(Rule.from_hash({ rule_type: "IceCube::DailyRule" })).to be_a DailyRule + expect(Rule.from_hash({rule_type: "IceCube::DailyRule"})).to be_a DailyRule end it "returns a WeeklyRule when the hash[:rule_type] is weekly" do - expect(Rule.from_hash({ rule_type: "IceCube::WeeklyRule" })).to be_a WeeklyRule + expect(Rule.from_hash({rule_type: "IceCube::WeeklyRule"})).to be_a WeeklyRule end it "returns a MonthlyRule when the hash[:rule_type] is monthly" do - expect(Rule.from_hash({ rule_type: "IceCube::MonthlyRule" })).to be_a MonthlyRule + expect(Rule.from_hash({rule_type: "IceCube::MonthlyRule"})).to be_a MonthlyRule end it "returns a YearlyRule when the hash[:rule_type] is yearly" do - expect(Rule.from_hash({ rule_type: "IceCube::YearlyRule" })).to be_a YearlyRule + expect(Rule.from_hash({rule_type: "IceCube::YearlyRule"})).to be_a YearlyRule end end @@ -46,20 +46,20 @@ module IceCube context "with valid day_of_week validations" do let(:input_hash) { { - "rule_type": "IceCube::MonthlyRule", - "interval": 1, - "validations": { - "day_of_week": { + rule_type: "IceCube::MonthlyRule", + interval: 1, + validations: { + day_of_week: { "0": [2], "1": [2], "2": [2], "3": [2], "4": [2], "5": [2], - "6": [1,2] + "6": [1, 2] }, - "hour_of_day": 7, - "minute_of_hour": 19 + hour_of_day: 7, + minute_of_hour: 19 } } } @@ -69,50 +69,50 @@ module IceCube schedule = Schedule.new(Time.utc(2010, 1, 1, 0, 0, 0)) schedule.add_recurrence_rule rule expect(schedule.first(10).map(&:to_time)).to eq([ - Time.utc(2010, 1, 2, 7, 19, 0), - Time.utc(2010, 1, 8, 7, 19, 0), - Time.utc(2010, 1, 9, 7, 19, 0), - Time.utc(2010, 1, 10, 7, 19, 0), - Time.utc(2010, 1, 11, 7, 19, 0), - Time.utc(2010, 1, 12, 7, 19, 0), - Time.utc(2010, 1, 13, 7, 19, 0), - Time.utc(2010, 1, 14, 7, 19, 0), - Time.utc(2010, 2, 6, 7, 19, 0), - Time.utc(2010, 2, 8, 7, 19, 0) - ]) + Time.utc(2010, 1, 2, 7, 19, 0), + Time.utc(2010, 1, 8, 7, 19, 0), + Time.utc(2010, 1, 9, 7, 19, 0), + Time.utc(2010, 1, 10, 7, 19, 0), + Time.utc(2010, 1, 11, 7, 19, 0), + Time.utc(2010, 1, 12, 7, 19, 0), + Time.utc(2010, 1, 13, 7, 19, 0), + Time.utc(2010, 1, 14, 7, 19, 0), + Time.utc(2010, 2, 6, 7, 19, 0), + Time.utc(2010, 2, 8, 7, 19, 0) + ]) end end context "with invalid day_of_week validations" do let(:input_hash_with_zeroeth_occurrence) { { - "rule_type": "IceCube::MonthlyRule", - "interval": 1, - "validations": { - "day_of_week": { + rule_type: "IceCube::MonthlyRule", + interval: 1, + validations: { + day_of_week: { "1": [], "2": [0], "3": [], "4": [] }, - "hour_of_day": 7, - "minute_of_hour": 19 + hour_of_day: 7, + minute_of_hour: 19 } } } let(:input_hash_with_sixth_occurrence) { { - "rule_type": "IceCube::MonthlyRule", - "interval": 1, - "validations": { - "day_of_week": { + rule_type: "IceCube::MonthlyRule", + interval: 1, + validations: { + day_of_week: { "1": [], "2": [6], "3": [], "4": [] }, - "hour_of_day": 7, - "minute_of_hour": 19 + hour_of_day: 7, + minute_of_hour: 19 } } } From b0693e3ec1512f3f6067e3b2dd9b1d20377124fe Mon Sep 17 00:00:00 2001 From: Jon Pascoe Date: Fri, 10 May 2024 22:29:38 +0100 Subject: [PATCH 06/10] Undo linting --- lib/ice_cube/i18n.rb | 8 ++++---- lib/ice_cube/rule.rb | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/ice_cube/i18n.rb b/lib/ice_cube/i18n.rb index f8cf2f04..6f135026 100644 --- a/lib/ice_cube/i18n.rb +++ b/lib/ice_cube/i18n.rb @@ -4,12 +4,12 @@ module IceCube module I18n LOCALES_PATH = File.expand_path(File.join("..", "..", "..", "config", "locales"), __FILE__) - def self.t(*, **) - backend.t(*, **) + def self.t(*args, **kwargs) + backend.t(*args, **kwargs) end - def self.l(*, **) - backend.l(*, **) + def self.l(*args, **kwargs) + backend.l(*args, **kwargs) end def self.backend diff --git a/lib/ice_cube/rule.rb b/lib/ice_cube/rule.rb index 6c4c96ef..30689267 100644 --- a/lib/ice_cube/rule.rb +++ b/lib/ice_cube/rule.rb @@ -36,8 +36,8 @@ def self.from_ical(ical) end # Yaml implementation - def to_yaml(*) - YAML.dump(to_hash, *) + def to_yaml(*args) + YAML.dump(to_hash, *args) end # From yaml From 06f053421791c85d20981ce5b53590d050690f35 Mon Sep 17 00:00:00 2001 From: Jon Pascoe Date: Sat, 11 May 2024 00:08:56 +0100 Subject: [PATCH 07/10] Move rule specs to new folder --- spec/{examples => rules}/daily_rule_spec.rb | 0 spec/{examples => rules}/hourly_rule_spec.rb | 0 spec/{examples => rules}/minutely_rule_spec.rb | 0 spec/{examples => rules}/monthly_rule_spec.rb | 0 spec/{examples => rules}/secondly_rule_spec.rb | 0 spec/{examples => rules}/weekly_rule_spec.rb | 0 spec/{examples => rules}/yearly_rule_spec.rb | 0 7 files changed, 0 insertions(+), 0 deletions(-) rename spec/{examples => rules}/daily_rule_spec.rb (100%) rename spec/{examples => rules}/hourly_rule_spec.rb (100%) rename spec/{examples => rules}/minutely_rule_spec.rb (100%) rename spec/{examples => rules}/monthly_rule_spec.rb (100%) rename spec/{examples => rules}/secondly_rule_spec.rb (100%) rename spec/{examples => rules}/weekly_rule_spec.rb (100%) rename spec/{examples => rules}/yearly_rule_spec.rb (100%) diff --git a/spec/examples/daily_rule_spec.rb b/spec/rules/daily_rule_spec.rb similarity index 100% rename from spec/examples/daily_rule_spec.rb rename to spec/rules/daily_rule_spec.rb diff --git a/spec/examples/hourly_rule_spec.rb b/spec/rules/hourly_rule_spec.rb similarity index 100% rename from spec/examples/hourly_rule_spec.rb rename to spec/rules/hourly_rule_spec.rb diff --git a/spec/examples/minutely_rule_spec.rb b/spec/rules/minutely_rule_spec.rb similarity index 100% rename from spec/examples/minutely_rule_spec.rb rename to spec/rules/minutely_rule_spec.rb diff --git a/spec/examples/monthly_rule_spec.rb b/spec/rules/monthly_rule_spec.rb similarity index 100% rename from spec/examples/monthly_rule_spec.rb rename to spec/rules/monthly_rule_spec.rb diff --git a/spec/examples/secondly_rule_spec.rb b/spec/rules/secondly_rule_spec.rb similarity index 100% rename from spec/examples/secondly_rule_spec.rb rename to spec/rules/secondly_rule_spec.rb diff --git a/spec/examples/weekly_rule_spec.rb b/spec/rules/weekly_rule_spec.rb similarity index 100% rename from spec/examples/weekly_rule_spec.rb rename to spec/rules/weekly_rule_spec.rb diff --git a/spec/examples/yearly_rule_spec.rb b/spec/rules/yearly_rule_spec.rb similarity index 100% rename from spec/examples/yearly_rule_spec.rb rename to spec/rules/yearly_rule_spec.rb From 111fe3b3b2ef32c47bee6a00da25bc7ba180899d Mon Sep 17 00:00:00 2001 From: Jon Pascoe Date: Sat, 11 May 2024 00:10:50 +0100 Subject: [PATCH 08/10] Move i18n specs to new folder --- spec/{examples => i18n}/to_s_de_spec.rb | 0 spec/{examples => i18n}/to_s_en_spec.rb | 0 spec/{examples => i18n}/to_s_es_spec.rb | 0 spec/{examples => i18n}/to_s_id_spec.rb | 0 spec/{examples => i18n}/to_s_ja_spec.rb | 0 5 files changed, 0 insertions(+), 0 deletions(-) rename spec/{examples => i18n}/to_s_de_spec.rb (100%) rename spec/{examples => i18n}/to_s_en_spec.rb (100%) rename spec/{examples => i18n}/to_s_es_spec.rb (100%) rename spec/{examples => i18n}/to_s_id_spec.rb (100%) rename spec/{examples => i18n}/to_s_ja_spec.rb (100%) diff --git a/spec/examples/to_s_de_spec.rb b/spec/i18n/to_s_de_spec.rb similarity index 100% rename from spec/examples/to_s_de_spec.rb rename to spec/i18n/to_s_de_spec.rb diff --git a/spec/examples/to_s_en_spec.rb b/spec/i18n/to_s_en_spec.rb similarity index 100% rename from spec/examples/to_s_en_spec.rb rename to spec/i18n/to_s_en_spec.rb diff --git a/spec/examples/to_s_es_spec.rb b/spec/i18n/to_s_es_spec.rb similarity index 100% rename from spec/examples/to_s_es_spec.rb rename to spec/i18n/to_s_es_spec.rb diff --git a/spec/examples/to_s_id_spec.rb b/spec/i18n/to_s_id_spec.rb similarity index 100% rename from spec/examples/to_s_id_spec.rb rename to spec/i18n/to_s_id_spec.rb diff --git a/spec/examples/to_s_ja_spec.rb b/spec/i18n/to_s_ja_spec.rb similarity index 100% rename from spec/examples/to_s_ja_spec.rb rename to spec/i18n/to_s_ja_spec.rb From e6257b5f1ddae71bd2e20b6056a406fca4d0ed18 Mon Sep 17 00:00:00 2001 From: Jon Pascoe Date: Sat, 11 May 2024 00:15:09 +0100 Subject: [PATCH 09/10] Check the actual values, not just the count --- spec/rules/yearly_rule_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/rules/yearly_rule_spec.rb b/spec/rules/yearly_rule_spec.rb index 1e3462ef..c7869917 100644 --- a/spec/rules/yearly_rule_spec.rb +++ b/spec/rules/yearly_rule_spec.rb @@ -38,7 +38,7 @@ schedule.add_recurrence_rule IceCube::Rule.yearly.month_of_year(:april).day_of_week(monday: [1, -1]) one_year = 365 * IceCube::ONE_DAY - expect(schedule.occurrences(start_time + one_year).size).to eq(2) + expect(schedule.occurrences(start_time + one_year)).to eq [Time.local(2011, 4, 4, 5, 0, 0), Time.local(2011, 4, 25, 5, 0, 0)] end it "should produce the correct number of days for @interval = 1" do From 94df94d9bd50685102770b818152c1cea3f70cac Mon Sep 17 00:00:00 2001 From: Jon Pascoe Date: Wed, 15 May 2024 23:32:35 +0100 Subject: [PATCH 10/10] Update argument validations --- lib/ice_cube/validations/day_of_week.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/ice_cube/validations/day_of_week.rb b/lib/ice_cube/validations/day_of_week.rb index 12937d90..9fb9f1cd 100644 --- a/lib/ice_cube/validations/day_of_week.rb +++ b/lib/ice_cube/validations/day_of_week.rb @@ -15,7 +15,8 @@ class Validation attr_reader :day, :occ def initialize(day, occ) - raise ArgumentError, "Invalid day_of_week occurrence: #{occ}" if occ == 0 || occ > 5 || occ < -5 + raise ArgumentError, "Integer occurrence value required" unless occ.is_a?(Integer) + raise ArgumentError, "Invalid day_of_week occurrence: #{occ.inspect}" if occ.zero? || occ.abs > 5 @day = day @occ = occ