From f0bc64f7f63ebb581f94a92c3c6c08c22e579188 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Nguyen?= Date: Fri, 29 Mar 2013 15:13:32 +0100 Subject: [PATCH] fix double WEEKLY string in to_ical result --- lib/ice_cube/rule.rb | 7 +++++-- spec/examples/to_ical_spec.rb | 10 ++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/ice_cube/rule.rb b/lib/ice_cube/rule.rb index cd8cc955..d4a47c8b 100644 --- a/lib/ice_cube/rule.rb +++ b/lib/ice_cube/rule.rb @@ -47,8 +47,11 @@ def to_hash def self.from_hash(original_hash) hash = IceCube::FlexibleHash.new original_hash return nil unless match = hash[:rule_type].match(/\:\:(.+?)Rule/) - rule = IceCube::Rule.send(match[1].downcase.to_sym, hash[:interval] || 1) - rule.interval(hash[:interval] || 1, TimeUtil.wday_to_sym(hash[:week_start] || 0)) if match[1] == "Weekly" + if match[1] == "Weekly" + rule = IceCube::Rule.send(match[1].downcase.to_sym, hash[:interval] || 1, TimeUtil.wday_to_sym(hash[:week_start] || 0)) + else + rule = IceCube::Rule.send(match[1].downcase.to_sym, hash[:interval] || 1) + end rule.until(TimeUtil.deserialize_time(hash[:until])) if hash[:until] rule.count(hash[:count]) if hash[:count] hash[:validations] && hash[:validations].each do |key, value| diff --git a/spec/examples/to_ical_spec.rb b/spec/examples/to_ical_spec.rb index 5206681a..23ed5451 100644 --- a/spec/examples/to_ical_spec.rb +++ b/spec/examples/to_ical_spec.rb @@ -243,4 +243,14 @@ rule.to_ical.should == "FREQ=WEEKLY;INTERVAL=#{interval};WKST=MO" end + [:yearly, :monthly, :weekly, :daily, :hourly, :minutely, :secondly].each do |type| + it "should make a #{type} rule roundtrip with to_yaml and same to_ical results" do + rule = IceCube::Rule.send(type) + + yaml_string = rule.to_yaml + rule2 = IceCube::Rule.from_yaml(yaml_string) + rule.to_ical.should == rule2.to_ical + end + end + end