From c23e80b56d4feaa6ff4bdd6bde831ea3a025d58b Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Mon, 19 Dec 2016 16:26:17 +0000 Subject: [PATCH] Test Post.recently_active --- spec/models/post_spec.rb | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rb index bcb144a42..18822016f 100644 --- a/spec/models/post_spec.rb +++ b/spec/models/post_spec.rb @@ -76,7 +76,7 @@ describe Post do Time.stub(now: Time.now) end - let(:post) { FactoryGirl.create(:post, created_at: 1.day.ago) } + let!(:post) { FactoryGirl.create(:post, created_at: 1.day.ago) } it "sets recent activity to post time" do post.recent_activity.to_i.should eq post.created_at.to_i @@ -90,14 +90,17 @@ describe Post do it "shiny new post is recently active" do # create a shiny new post - @post2 = FactoryGirl.create(:post, created_at: 1.minute.ago) - Post.recently_active.first.should eq @post2 + post2 = FactoryGirl.create(:post, created_at: 1.minute.ago) + Post.recently_active.first.should eq post2 + Post.recently_active.second.should eq post end it "new comment on old post is recently active" do # now comment on an older post - @comment2 = FactoryGirl.create(:comment, post: post, created_at: 1.second.ago) + post2 = FactoryGirl.create(:post, created_at: 1.minute.ago) + FactoryGirl.create(:comment, post: post, created_at: 1.second.ago) Post.recently_active.first.should eq post + Post.recently_active.second.should eq post2 end end