From ca6325a3feed554f54c90ee514ef5195a03e15d0 Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 28 Jun 2013 15:38:47 +1000 Subject: [PATCH] a pile of complicated and hard to follow specs were replaced by something that makes sense to old people like myself --- spec/models/user_spec.rb | 62 ++++++++++------------------------------ 1 file changed, 15 insertions(+), 47 deletions(-) diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 545ec95c252..723ee740c35 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -586,62 +586,30 @@ describe User do describe "previous_visit_at" do let(:user) { Fabricate(:user) } + let!(:first_visit_date) { Time.zone.now } + let!(:second_visit_date) { 2.hours.from_now } + let!(:third_visit_date) { 5.hours.from_now } before do SiteSetting.stubs(:active_user_rate_limit_secs).returns(0) end - it "should be blank on creation" do + it "should act correctly" do user.previous_visit_at.should be_nil - end - describe "first time" do - let!(:first_visit_date) { Time.zone.now } + # first visit + user.update_last_seen!(first_visit_date) + user.previous_visit_at.should be_nil - before do - user.update_last_seen!(first_visit_date) - end + # second visit + user.update_last_seen!(second_visit_date) + user.reload + user.previous_visit_at.should be_within_one_second_of(first_visit_date) - it "should have no value" do - user.previous_visit_at.should be_nil - end - - describe "another call right after" do - before do - user.update_last_seen!(10.minutes.from_now) - end - - it "still has no value" do - user.previous_visit_at.should be_nil - end - end - - describe "second visit" do - let!(:second_visit_date) { 2.hours.from_now } - - before do - user.update_last_seen!(second_visit_date) - end - - it "should have the previous visit value" do - user.reload - user.previous_visit_at.should be_within_one_second_of(first_visit_date) - end - - describe "third visit" do - let!(:third_visit_date) { 5.hours.from_now } - - before do - user.update_last_seen!(third_visit_date) - end - - it "should have the second visit value" do - user.previous_visit_at.should be_within_one_second_of(second_visit_date) - end - - end - - end + # third visit + user.update_last_seen!(third_visit_date) + user.reload + user.previous_visit_at.should be_within_one_second_of(second_visit_date) end