From 3c67cf8acd0976a0287e8b768df04965b66faff2 Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 28 Jun 2013 15:14:44 +1000 Subject: [PATCH] remove timecop, specs were failing and we can avoid it here anyway --- app/models/user.rb | 4 ++-- spec/models/user_spec.rb | 29 ++++------------------------- 2 files changed, 6 insertions(+), 27 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index c911ff0fe..3bfcd6763 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -282,8 +282,8 @@ class User < ActiveRecord::Base end end - def update_last_seen! - now = Time.zone.now + def update_last_seen!(now=nil) + now ||= Time.zone.now now_date = now.to_date # Only update last seen once every minute redis_key = "user:#{self.id}:#{now_date.to_s}" diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 58806d807..545ec95c2 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -599,12 +599,7 @@ describe User do let!(:first_visit_date) { Time.zone.now } before do - Timecop.freeze(first_visit_date) - user.update_last_seen! - end - - after do - Timecop.return + user.update_last_seen!(first_visit_date) end it "should have no value" do @@ -613,13 +608,7 @@ describe User do describe "another call right after" do before do - # A different time, to make sure it doesn't change - Timecop.freeze(10.minutes.from_now) - user.update_last_seen! - end - - after do - Timecop.return + user.update_last_seen!(10.minutes.from_now) end it "still has no value" do @@ -631,12 +620,7 @@ describe User do let!(:second_visit_date) { 2.hours.from_now } before do - Timecop.freeze(second_visit_date) - user.update_last_seen! - end - - after do - Timecop.return + user.update_last_seen!(second_visit_date) end it "should have the previous visit value" do @@ -648,12 +632,7 @@ describe User do let!(:third_visit_date) { 5.hours.from_now } before do - Timecop.freeze(third_visit_date) - user.update_last_seen! - end - - after do - Timecop.return + user.update_last_seen!(third_visit_date) end it "should have the second visit value" do