Permalink
Browse files

fixup the timezone issues for active and expired

  • Loading branch information...
1 parent 877f4cb commit b13b5b67167c57895f0a1f07f627e68cb96ecbee Eric Harrison committed Dec 12, 2011
Showing with 9 additions and 3 deletions.
  1. +2 −2 lib/subly/model.rb
  2. +1 −1 lib/subly/version.rb
  3. +3 −0 spec/spec_helper.rb
  4. +3 −0 spec/subly_spec.rb
View
@@ -9,12 +9,12 @@ class Model < ActiveRecord::Base
validate :ends_after_starts
def self.active
- now = Time.now
+ now = Time.zone.now
scoped(:conditions => ['starts_at <= ? AND (ends_at > ? OR ends_at IS NULL)', now, now])
end
def self.expired
- now = Time.now
+ now = Time.zone.now
scoped(:conditions => ['starts_at <= ? AND ends_at <= ?', now, now])
end
View
@@ -1,3 +1,3 @@
module Subly
- VERSION = "0.0.1"
+ VERSION = "0.1.1"
end
View
@@ -5,6 +5,9 @@
require 'subly'
require 'sqlite3'
+#Time.zone.now doesn't work in test
+
+
# Requires supporting files with custom matchers and macros, etc,
# in ./support/ and its subdirectories.
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
View
@@ -17,6 +17,7 @@ class Thing < ActiveRecord::Base
end
it "subscription should default to active" do
+ Time.stub!(:zone).and_return(Time)
thing_one = Thing.create(:name => 'Thing One', :description => 'foo')
thing_one.add_subscription('sub name').should be_true
thing_one.reload
@@ -51,10 +52,12 @@ class Thing < ActiveRecord::Base
end
it "is method should be false if it does not have an active sub" do
+ Time.stub!(:zone).and_return(Time)
Item.new.is_subby?.should be_false
end
it "is method should be true if it has an active sub" do
+ Time.stub!(:zone).and_return(Time)
item = Item.create(:name => 'foo')
item.add_subscription('subby')
item.is_subby?.should be_true

0 comments on commit b13b5b6

Please sign in to comment.