Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Ruby 3.1 and Rails 7.0 #521

Merged
merged 7 commits into from
Mar 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,17 @@ jobs:
- lint
strategy:
matrix:
rails: ['5.2', '6.0.4', '6.1']
ruby: ['2.6', '2.7', '3.0']
rails: ['5.2', '6.0.4', '6.1', '7.0']
ruby: ['2.6', '2.7', '3.0', '3.1']
exclude:
- rails: '5.2'
ruby: '3.0'
- rails: '5.2'
ruby: '3.1'
- rails: '7.0'
ruby: '2.6'
- rails: '7.0'
ruby: '2.7'
runs-on: ubuntu-latest
env:
RAILS_VERSION: ${{ matrix.rails }}
Expand Down
2 changes: 1 addition & 1 deletion lib/ice_cube/parsers/yaml_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class YamlParser < HashParser
attr_reader :hash

def initialize(yaml)
@hash = YAML.load(yaml)
@hash = YAML.safe_load(yaml, permitted_classes: [Date, Symbol, Time], aliases: true)
yaml.match SERIALIZED_START do |match|
start_time = hash[:start_time] || hash[:start_date]
TimeUtil.restore_deserialized_offset start_time, match[:tz]
Expand Down
2 changes: 1 addition & 1 deletion lib/ice_cube/rule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def to_yaml(*args)

# From yaml
def self.from_yaml(yaml)
from_hash YAML.load(yaml)
from_hash YAML.safe_load(yaml, permitted_classes: [Date, Symbol, Time])
end

def to_hash
Expand Down
9 changes: 5 additions & 4 deletions spec/examples/active_support_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require File.dirname(__FILE__) + "/../spec_helper"
require "active_support"
require "active_support/time"
require "active_support/version"
require "tzinfo" if ActiveSupport::VERSION::MAJOR == 3
Expand Down Expand Up @@ -45,10 +46,10 @@ module IceCube
end

it "can round trip TimeWithZone to YAML" do
schedule = Schedule.new(t0 = Time.zone.parse("2010-02-05 05:00:00"))
schedule.add_recurrence_time t0
schedule2 = Schedule.from_yaml(schedule.to_yaml)
expect(schedule.all_occurrences).to eq(schedule2.all_occurrences)
schedule1 = Schedule.new(t0 = Time.zone.parse("2010-02-05 05:00:00"))
schedule1.add_recurrence_time t0
schedule2 = Schedule.from_yaml(schedule1.to_yaml)
expect(schedule2.all_occurrences).to eq(schedule1.all_occurrences)
end

it "uses local zone from start time to determine occurs_on? from the beginning of day" do
Expand Down
2 changes: 1 addition & 1 deletion spec/examples/serialization_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
let(:start_time) { Time.now.in_time_zone("America/Vancouver") }

it "serializes time as a Hash" do
hash = YAML.load(yaml)
hash = YAML.safe_load(yaml, permitted_classes: [Symbol, Time])
expect(hash[:start_time][:time]).to eq start_time.utc
expect(hash[:start_time][:zone]).to eq "America/Vancouver"
end
Expand Down
1 change: 1 addition & 0 deletions spec/examples/to_ical_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require File.dirname(__FILE__) + "/../spec_helper"
require "active_support"
require "active_support/time"

describe IceCube, "to_ical" do
Expand Down
14 changes: 8 additions & 6 deletions spec/examples/to_yaml_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,15 @@ module IceCube
end

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

yaml_string = schedule.to_yaml
yaml_string = schedule1.to_yaml
schedule2 = Schedule.from_yaml(yaml_string)

# compare without usecs
expect(schedule.first(10).map { |r| r.to_s }).to eq(schedule2.first(10).map { |r| r.to_s })
expect(schedule2.first(10).map { |r| r.to_s })
.to eq(schedule1.first(10).map { |r| r.to_s })
end

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

end_time = Time.now + ONE_DAY
expect(schedule1.occurrences(end_time)).to eq(schedule2.occurrences(end_time))
expect(schedule2.occurrences(end_time)).to eq(schedule1.occurrences(end_time))
end

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

symbol_yaml = Schedule.from_hash(symbol_data).to_yaml
string_yaml = Schedule.from_hash(string_data).to_yaml
expect(YAML.load(symbol_yaml)).to eq(YAML.load(string_yaml))
expect(YAML.safe_load(symbol_yaml, permitted_classes: [Symbol, Time]))
.to eq(YAML.safe_load(string_yaml, permitted_classes: [Symbol, Time]))
end

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