From d9ce0daade097abf28796d54c5a5b48cb18bc16c Mon Sep 17 00:00:00 2001 From: James Harrison Date: Tue, 28 Dec 2010 22:11:33 +0000 Subject: [PATCH 1/3] Removes SystemTimer for Ruby 1.9.2 compat --- redistat.gemspec | 1 - 1 file changed, 1 deletion(-) diff --git a/redistat.gemspec b/redistat.gemspec index 3fef21e..83968ca 100644 --- a/redistat.gemspec +++ b/redistat.gemspec @@ -22,7 +22,6 @@ Gem::Specification.new do |s| s.add_runtime_dependency 'activesupport', '>= 2.3.0' s.add_runtime_dependency 'json', '>= 1.4.0' s.add_runtime_dependency 'redis', '>= 2.1.0' - s.add_runtime_dependency 'system_timer', '>= 1.0.0' s.add_runtime_dependency 'time_ext', '>= 0.2.8' s.add_development_dependency 'rspec', '>= 2.1.0' From 6a66605e0b89019cc047ab957c1ce9eef51b8991 Mon Sep 17 00:00:00 2001 From: James Harrison Date: Tue, 28 Dec 2010 23:46:25 +0000 Subject: [PATCH 2/3] Adds Ruby 1.9.2 compat (references to TimeExt#round collide with the new real Time#now, changed to TimeExt#beginning_of_closest), 3 specs failing relating to time equality testing --- Gemfile.lock | 3 --- lib/redistat.rb | 1 + lib/redistat/core_ext/bignum.rb | 8 ++++++++ lib/redistat/date.rb | 2 ++ lib/redistat/finder/date_set.rb | 4 ++-- 5 files changed, 13 insertions(+), 5 deletions(-) create mode 100755 lib/redistat/core_ext/bignum.rb diff --git a/Gemfile.lock b/Gemfile.lock index 3e263ca..8e905de 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -5,7 +5,6 @@ PATH activesupport (>= 2.3.0) json (>= 1.4.0) redis (>= 2.1.0) - system_timer (>= 1.0.0) time_ext (>= 0.2.8) GEM @@ -24,7 +23,6 @@ GEM rspec-expectations (2.1.0) diff-lcs (~> 1.1.2) rspec-mocks (2.1.0) - system_timer (1.0) time_ext (0.2.8) activesupport (>= 2.3.0) i18n (>= 0.4.2) @@ -39,6 +37,5 @@ DEPENDENCIES redis (>= 2.1.0) redistat! rspec (>= 2.1.0) - system_timer (>= 1.0.0) time_ext (>= 0.2.8) yard (>= 0.6.3) diff --git a/lib/redistat.rb b/lib/redistat.rb index e18c076..3d26d18 100644 --- a/lib/redistat.rb +++ b/lib/redistat.rb @@ -26,6 +26,7 @@ require 'redistat/summary' require 'redistat/core_ext/date' require 'redistat/core_ext/time' require 'redistat/core_ext/fixnum' +require 'redistat/core_ext/bignum' module Redistat diff --git a/lib/redistat/core_ext/bignum.rb b/lib/redistat/core_ext/bignum.rb new file mode 100755 index 0000000..20e08e2 --- /dev/null +++ b/lib/redistat/core_ext/bignum.rb @@ -0,0 +1,8 @@ +class Bignum + include Redistat::DateHelper + + def to_time + Time.at(self) + end + +end diff --git a/lib/redistat/date.rb b/lib/redistat/date.rb index 48fb65e..218a914 100644 --- a/lib/redistat/date.rb +++ b/lib/redistat/date.rb @@ -22,6 +22,8 @@ module Redistat from_string(input) elsif input.is_a?(::Fixnum) from_integer(input) + elsif input.is_a?(::Bignum) + from_integer(input) end end diff --git a/lib/redistat/finder/date_set.rb b/lib/redistat/finder/date_set.rb index 32c5a60..0bb805b 100644 --- a/lib/redistat/finder/date_set.rb +++ b/lib/redistat/finder/date_set.rb @@ -42,7 +42,7 @@ module Redistat return find_start_year_for(start_date, end_date, lowest_depth) if unit == :year index = Date::DEPTHS.index(unit) nunit = Date::DEPTHS[(index > 0) ? index-1 : index] - if start_date < start_date.round(nunit) || start_date.next(nunit).beginning_of(nunit) > end_date.beginning_of(nunit) + if start_date < start_date.beginning_of_closest(nunit) || start_date.next(nunit).beginning_of(nunit) > end_date.beginning_of(nunit) add = [] start_date.beginning_of_each(unit, :include_start => lowest_depth).until(start_date.end_of(nunit)) do |t| add << t.to_rs.to_s(unit) if t < end_date.beginning_of(unit) @@ -59,7 +59,7 @@ module Redistat index = Date::DEPTHS.index(unit) nunit = Date::DEPTHS[(index > 0) ? index-1 : index] has_nunit = end_date.prev(nunit).beginning_of(nunit) >= start_date.beginning_of(nunit) - nearest_nunit = end_date.round(nunit) + nearest_nunit = end_date.beginning_of_closest(nunit) if end_date >= nearest_nunit && has_nunit add = [] end_date.beginning_of(nunit).beginning_of_each(unit, :include_start => true, :include_end => lowest_depth).until(end_date) do |t| From 93360dbeb980448d5e671ad4d74e24c747671c80 Mon Sep 17 00:00:00 2001 From: James Harrison Date: Tue, 28 Dec 2010 23:55:39 +0000 Subject: [PATCH 3/3] Specs pass again - problem with Time.now resolution surpassing that provided by values stored in a Redistat::Date, truncated to seconds by using to_s, which is accurate enough for testing purposes --- spec/event_spec.rb | 6 +++--- spec/key_spec.rb | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/spec/event_spec.rb b/spec/event_spec.rb index 14fd9e5..3550c59 100644 --- a/spec/event_spec.rb +++ b/spec/event_spec.rb @@ -20,7 +20,7 @@ describe Redistat::Event do @event.scope.should == @scope @event.label.should == @label @event.label_hash.should == @label_hash - @event.date.to_time.should == @date + @event.date.to_time.to_s.should == @date.to_s @event.stats.should == @stats @event.meta.should == @meta @event.options.should == @event.default_options.merge(@options) @@ -28,10 +28,10 @@ describe Redistat::Event do it "should allow changing attributes" do # date - @event.date.to_time.should == @date + @event.date.to_time.to_s.should == @date.to_s @date = Time.now @event.date = @date - @event.date.to_time.should == @date + @event.date.to_time.to_s.should == @date.to_s # label @event.label.should == @label @event.label_hash.should == @label_hash diff --git a/spec/key_spec.rb b/spec/key_spec.rb index bb2cd20..9d8bec4 100644 --- a/spec/key_spec.rb +++ b/spec/key_spec.rb @@ -46,10 +46,10 @@ describe Redistat::Key do @key.scope = @scope @key.scope.should == @scope # date - @key.date.to_time.should == @date + @key.date.to_time.to_s.should == @date.to_s @date = Time.now @key.date = @date - @key.date.to_time.should == @date + @key.date.to_time.to_s.should == @date.to_s # label @key.label.should == @label @key.label_hash == @label_hash