From 2c3bdf48d113c5e75acfc761b5176bdc135f42a3 Mon Sep 17 00:00:00 2001 From: Konrad Borowski Date: Tue, 12 Aug 2014 09:23:57 +0200 Subject: [PATCH 1/3] Use infinity instead of 3000-01-01 as max date. This fixes the y3k problem in Discourse that made topics with pins appear after threads updated in year 3000. --- lib/topic_query_sql.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/topic_query_sql.rb b/lib/topic_query_sql.rb index 1256971c0..465737ce1 100644 --- a/lib/topic_query_sql.rb +++ b/lib/topic_query_sql.rb @@ -12,7 +12,7 @@ module TopicQuerySQL end def highest_date - "3000-01-01" + "infinity" end def order_by_category_sql(dir) From 3e5ff66bed5dbc4f2bbffcb0b817930ec6be3112 Mon Sep 17 00:00:00 2001 From: Konrad Borowski Date: Tue, 12 Aug 2014 09:51:54 +0200 Subject: [PATCH 2/3] 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 From 3189296e5fa55650df81c0f4637abb9c7e34117f Mon Sep 17 00:00:00 2001 From: Konrad Borowski Date: Tue, 12 Aug 2014 10:31:21 +0200 Subject: [PATCH 3/3] Fix ordering of posts in posts in order unit test. --- spec/components/topic_query_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/components/topic_query_spec.rb b/spec/components/topic_query_spec.rb index 9c11f7bfc..9ff3a3b84 100644 --- a/spec/components/topic_query_spec.rb +++ b/spec/components/topic_query_spec.rb @@ -165,10 +165,10 @@ 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, future_topic, regular_topic, invisible_topic, closed_topic].map(&:id) + ids_in_order('posts').should == [future_topic, pinned_topic, archived_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, future_topic, archived_topic, pinned_topic].map(&:id) + ids_in_order('posts', false).should == [closed_topic, invisible_topic, regular_topic, archived_topic, pinned_topic, future_topic].map(&:id) # returns the topics in likes order if requested ids_in_order('likes').should == [pinned_topic, regular_topic, archived_topic, future_topic, invisible_topic, closed_topic].map(&:id)