mirror of
https://github.com/discourse/discourse.git
synced 2025-04-03 05:39:41 +08:00
Return default top setting as part of best_periods_for to see if it can be used
This commit is contained in:
parent
a1add415e5
commit
c5bb1d1cfe
@ -334,16 +334,18 @@ class ListController < ApplicationController
|
|||||||
return period if top_topics.count >= SiteSetting.topics_per_period_in_top_page
|
return period if top_topics.count >= SiteSetting.topics_per_period_in_top_page
|
||||||
end
|
end
|
||||||
# default period is yearly
|
# default period is yearly
|
||||||
SiteSetting.top_page_default_timeframe
|
SiteSetting.top_page_default_timeframe.to_sym
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.best_periods_for(date)
|
def self.best_periods_for(date)
|
||||||
date ||= 1.year.ago
|
date ||= 1.year.ago
|
||||||
|
default_period = SiteSetting.top_page_default_timeframe.to_sym
|
||||||
periods = []
|
periods = []
|
||||||
periods << :daily if date > 8.days.ago
|
periods << default_period if :all != default_period
|
||||||
periods << :weekly if date > 35.days.ago
|
periods << :daily if :daily != default_period && date > 8.days.ago
|
||||||
periods << :monthly if date > 180.days.ago
|
periods << :weekly if :weekly != default_period && date > 35.days.ago
|
||||||
periods << :yearly
|
periods << :monthly if :monthly != default_period && date > 180.days.ago
|
||||||
|
periods << :yearly if :yearly != default_period
|
||||||
periods
|
periods
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -224,28 +224,62 @@ describe ListController do
|
|||||||
describe "best_periods_for" do
|
describe "best_periods_for" do
|
||||||
|
|
||||||
it "returns yearly for more than 180 days" do
|
it "returns yearly for more than 180 days" do
|
||||||
|
SiteSetting.stubs(:top_page_default_timeframe).returns("all")
|
||||||
expect(ListController.best_periods_for(nil)).to eq([:yearly])
|
expect(ListController.best_periods_for(nil)).to eq([:yearly])
|
||||||
expect(ListController.best_periods_for(180.days.ago)).to eq([:yearly])
|
expect(ListController.best_periods_for(180.days.ago)).to eq([:yearly])
|
||||||
end
|
end
|
||||||
|
|
||||||
it "includes monthly when less than 180 days and more than 35 days" do
|
it "includes monthly when less than 180 days and more than 35 days" do
|
||||||
|
SiteSetting.stubs(:top_page_default_timeframe).returns("all")
|
||||||
(35...180).each do |date|
|
(35...180).each do |date|
|
||||||
expect(ListController.best_periods_for(date.days.ago)).to eq([:monthly, :yearly])
|
expect(ListController.best_periods_for(date.days.ago)).to eq([:monthly, :yearly])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it "includes weekly when less than 35 days and more than 8 days" do
|
it "includes weekly when less than 35 days and more than 8 days" do
|
||||||
|
SiteSetting.stubs(:top_page_default_timeframe).returns("all")
|
||||||
(8...35).each do |date|
|
(8...35).each do |date|
|
||||||
expect(ListController.best_periods_for(date.days.ago)).to eq([:weekly, :monthly, :yearly])
|
expect(ListController.best_periods_for(date.days.ago)).to eq([:weekly, :monthly, :yearly])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it "includes daily when less than 8 days" do
|
it "includes daily when less than 8 days" do
|
||||||
|
SiteSetting.stubs(:top_page_default_timeframe).returns("all")
|
||||||
(0...8).each do |date|
|
(0...8).each do |date|
|
||||||
expect(ListController.best_periods_for(date.days.ago)).to eq([:daily, :weekly, :monthly, :yearly])
|
expect(ListController.best_periods_for(date.days.ago)).to eq([:daily, :weekly, :monthly, :yearly])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "returns default even for more than 180 days" do
|
||||||
|
SiteSetting.stubs(:top_page_default_timeframe).returns("monthly")
|
||||||
|
expect(ListController.best_periods_for(nil)).to eq([:monthly, :yearly])
|
||||||
|
expect(ListController.best_periods_for(180.days.ago)).to eq([:monthly, :yearly])
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns default even when less than 180 days and more than 35 days" do
|
||||||
|
SiteSetting.stubs(:top_page_default_timeframe).returns("weekly")
|
||||||
|
(35...180).each do |date|
|
||||||
|
expect(ListController.best_periods_for(date.days.ago)).to eq([:weekly, :monthly, :yearly])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns default even when less than 35 days and more than 8 days" do
|
||||||
|
SiteSetting.stubs(:top_page_default_timeframe).returns("daily")
|
||||||
|
(8...35).each do |date|
|
||||||
|
expect(ListController.best_periods_for(date.days.ago)).to eq([:daily, :weekly, :monthly, :yearly])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
it "doesn't return default when set to all" do
|
||||||
|
SiteSetting.stubs(:top_page_default_timeframe).returns("all")
|
||||||
|
expect(ListController.best_periods_for(nil)).to eq([:yearly])
|
||||||
|
end
|
||||||
|
|
||||||
|
it "doesn't return value twice when matches default" do
|
||||||
|
SiteSetting.stubs(:top_page_default_timeframe).returns("yearly")
|
||||||
|
expect(ListController.best_periods_for(nil)).to eq([:yearly])
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "categories suppression" do
|
describe "categories suppression" do
|
||||||
|
Loading…
x
Reference in New Issue
Block a user