Skip to content

Commit 6b97e77

Browse files
authored
Add Ruby 3.1 and Rails 7.0 (#521)
* Add Ruby 3.1 and Rails 7.0 * Exclude older versions of ruby from rails 7 * Exclude individually * Switch to YAML.safe_load * Add time helpers * require active_support * require active_support
1 parent 2cdfdba commit 6b97e77

File tree

7 files changed

+25
-15
lines changed

7 files changed

+25
-15
lines changed

.github/workflows/tests.yaml

+8-2
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,17 @@ jobs:
4242
- lint
4343
strategy:
4444
matrix:
45-
rails: ['5.2', '6.0.4', '6.1']
46-
ruby: ['2.6', '2.7', '3.0']
45+
rails: ['5.2', '6.0.4', '6.1', '7.0']
46+
ruby: ['2.6', '2.7', '3.0', '3.1']
4747
exclude:
4848
- rails: '5.2'
4949
ruby: '3.0'
50+
- rails: '5.2'
51+
ruby: '3.1'
52+
- rails: '7.0'
53+
ruby: '2.6'
54+
- rails: '7.0'
55+
ruby: '2.7'
5056
runs-on: ubuntu-latest
5157
env:
5258
RAILS_VERSION: ${{ matrix.rails }}

lib/ice_cube/parsers/yaml_parser.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class YamlParser < HashParser
77
attr_reader :hash
88

99
def initialize(yaml)
10-
@hash = YAML.load(yaml)
10+
@hash = YAML.safe_load(yaml, permitted_classes: [Date, Symbol, Time], aliases: true)
1111
yaml.match SERIALIZED_START do |match|
1212
start_time = hash[:start_time] || hash[:start_date]
1313
TimeUtil.restore_deserialized_offset start_time, match[:tz]

lib/ice_cube/rule.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def to_yaml(*args)
4242

4343
# From yaml
4444
def self.from_yaml(yaml)
45-
from_hash YAML.load(yaml)
45+
from_hash YAML.safe_load(yaml, permitted_classes: [Date, Symbol, Time])
4646
end
4747

4848
def to_hash

spec/examples/active_support_spec.rb

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require File.dirname(__FILE__) + "/../spec_helper"
2+
require "active_support"
23
require "active_support/time"
34
require "active_support/version"
45
require "tzinfo" if ActiveSupport::VERSION::MAJOR == 3
@@ -45,10 +46,10 @@ module IceCube
4546
end
4647

4748
it "can round trip TimeWithZone to YAML" do
48-
schedule = Schedule.new(t0 = Time.zone.parse("2010-02-05 05:00:00"))
49-
schedule.add_recurrence_time t0
50-
schedule2 = Schedule.from_yaml(schedule.to_yaml)
51-
expect(schedule.all_occurrences).to eq(schedule2.all_occurrences)
49+
schedule1 = Schedule.new(t0 = Time.zone.parse("2010-02-05 05:00:00"))
50+
schedule1.add_recurrence_time t0
51+
schedule2 = Schedule.from_yaml(schedule1.to_yaml)
52+
expect(schedule2.all_occurrences).to eq(schedule1.all_occurrences)
5253
end
5354

5455
it "uses local zone from start time to determine occurs_on? from the beginning of day" do

spec/examples/serialization_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
let(:start_time) { Time.now.in_time_zone("America/Vancouver") }
1616

1717
it "serializes time as a Hash" do
18-
hash = YAML.load(yaml)
18+
hash = YAML.safe_load(yaml, permitted_classes: [Symbol, Time])
1919
expect(hash[:start_time][:time]).to eq start_time.utc
2020
expect(hash[:start_time][:zone]).to eq "America/Vancouver"
2121
end

spec/examples/to_ical_spec.rb

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require File.dirname(__FILE__) + "/../spec_helper"
2+
require "active_support"
23
require "active_support/time"
34

45
describe IceCube, "to_ical" do

spec/examples/to_yaml_spec.rb

+8-6
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,15 @@ module IceCube
7878
end
7979

8080
it "should be able to make a round-trip to YAML with .day_of_year" do
81-
schedule = Schedule.new(Time.now)
82-
schedule.add_recurrence_rule Rule.yearly.day_of_year(100, 200)
81+
schedule1 = Schedule.new(Time.now)
82+
schedule1.add_recurrence_rule Rule.yearly.day_of_year(100, 200)
8383

84-
yaml_string = schedule.to_yaml
84+
yaml_string = schedule1.to_yaml
8585
schedule2 = Schedule.from_yaml(yaml_string)
8686

8787
# compare without usecs
88-
expect(schedule.first(10).map { |r| r.to_s }).to eq(schedule2.first(10).map { |r| r.to_s })
88+
expect(schedule2.first(10).map { |r| r.to_s })
89+
.to eq(schedule1.first(10).map { |r| r.to_s })
8990
end
9091

9192
it "should be able to make a round-trip to YAML with .hour_of_day" do
@@ -184,7 +185,7 @@ module IceCube
184185
schedule2 = Schedule.from_yaml(schedule1.to_yaml) # round trip
185186

186187
end_time = Time.now + ONE_DAY
187-
expect(schedule1.occurrences(end_time)).to eq(schedule2.occurrences(end_time))
188+
expect(schedule2.occurrences(end_time)).to eq(schedule1.occurrences(end_time))
188189
end
189190

190191
it "should be able to make a round trip with an exception time" do
@@ -323,7 +324,8 @@ module IceCube
323324

324325
symbol_yaml = Schedule.from_hash(symbol_data).to_yaml
325326
string_yaml = Schedule.from_hash(string_data).to_yaml
326-
expect(YAML.load(symbol_yaml)).to eq(YAML.load(string_yaml))
327+
expect(YAML.safe_load(symbol_yaml, permitted_classes: [Symbol, Time]))
328+
.to eq(YAML.safe_load(string_yaml, permitted_classes: [Symbol, Time]))
327329
end
328330

329331
it "should raise an ArgumentError when trying to deserialize an invalid rule type" do

0 commit comments

Comments
 (0)