From 3e5ff66bed5dbc4f2bbffcb0b817930ec6be3112 Mon Sep 17 00:00:00 2001 From: Konrad Borowski Date: Tue, 12 Aug 2014 09:51:54 +0200 Subject: [PATCH] Add unit tests for testing if infinity as highest_date works. --- spec/components/topic_query_spec.rb | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/spec/components/topic_query_spec.rb b/spec/components/topic_query_spec.rb index 49385f336..9c11f7bfc 100644 --- a/spec/components/topic_query_spec.rb +++ b/spec/components/topic_query_spec.rb @@ -134,12 +134,21 @@ describe TopicQuery do participant_count: 2, bumped_at: 1.minute.ago) end + let!(:future_topic) do + Fabricate(:topic, title: 'this is a topic in far future', + user: creator, + views: 30, + like_count: 11, + posts_count: 6, + participant_count: 5, + bumped_at: 1000.years.from_now) + end let(:topics) { topic_query.list_latest.topics } context 'list_latest' do it "returns the topics in the correct order" do - topics.map(&:id).should == [pinned_topic, closed_topic, archived_topic, regular_topic].map(&:id) + topics.map(&:id).should == [pinned_topic, future_topic, closed_topic, archived_topic, regular_topic].map(&:id) # includes the invisible topic if you're a moderator TopicQuery.new(moderator).list_latest.topics.include?(invisible_topic).should be_true @@ -156,28 +165,28 @@ describe TopicQuery do it "returns the topics in correct order" do # returns the topics in likes order if requested - ids_in_order('posts').should == [pinned_topic, archived_topic, regular_topic, invisible_topic, closed_topic].map(&:id) + ids_in_order('posts').should == [pinned_topic, archived_topic, future_topic, regular_topic, invisible_topic, closed_topic].map(&:id) # returns the topics in reverse likes order if requested - ids_in_order('posts', false).should == [closed_topic, invisible_topic, regular_topic, archived_topic, pinned_topic].map(&:id) + ids_in_order('posts', false).should == [closed_topic, invisible_topic, regular_topic, future_topic, archived_topic, pinned_topic].map(&:id) # returns the topics in likes order if requested - ids_in_order('likes').should == [pinned_topic, regular_topic, archived_topic, invisible_topic, closed_topic].map(&:id) + ids_in_order('likes').should == [pinned_topic, regular_topic, archived_topic, future_topic, invisible_topic, closed_topic].map(&:id) # returns the topics in reverse likes order if requested - ids_in_order('likes', false).should == [closed_topic, invisible_topic, archived_topic, regular_topic, pinned_topic].map(&:id) + ids_in_order('likes', false).should == [closed_topic, invisible_topic, future_topic, archived_topic, regular_topic, pinned_topic].map(&:id) # returns the topics in views order if requested - ids_in_order('views').should == [regular_topic, archived_topic, pinned_topic, closed_topic, invisible_topic].map(&:id) + ids_in_order('views').should == [regular_topic, archived_topic, future_topic, pinned_topic, closed_topic, invisible_topic].map(&:id) # returns the topics in reverse views order if requested" do - ids_in_order('views', false).should == [invisible_topic, closed_topic, pinned_topic, archived_topic, regular_topic].map(&:id) + ids_in_order('views', false).should == [invisible_topic, closed_topic, pinned_topic, future_topic, archived_topic, regular_topic].map(&:id) # returns the topics in posters order if requested" do - ids_in_order('posters').should == [pinned_topic, regular_topic, invisible_topic, closed_topic, archived_topic].map(&:id) + ids_in_order('posters').should == [pinned_topic, regular_topic, future_topic, invisible_topic, closed_topic, archived_topic].map(&:id) # returns the topics in reverse posters order if requested" do - ids_in_order('posters', false).should == [archived_topic, closed_topic, invisible_topic, regular_topic, pinned_topic].map(&:id) + ids_in_order('posters', false).should == [archived_topic, closed_topic, invisible_topic, future_topic, regular_topic, pinned_topic].map(&:id) end end @@ -191,7 +200,7 @@ describe TopicQuery do end it "no longer shows the pinned topic at the top" do - topics.should == [closed_topic, archived_topic, pinned_topic, regular_topic] + topics.should == [future_topic, closed_topic, archived_topic, pinned_topic, regular_topic] end end