From 489e1bf6434abb42cb829400adb4a090aa7bc154 Mon Sep 17 00:00:00 2001 From: cpradio Date: Wed, 12 Oct 2016 19:28:54 -0400 Subject: [PATCH] Stub the TopTopic.topics_per_period so the logic is fully tested --- spec/models/site_setting_spec.rb | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/spec/models/site_setting_spec.rb b/spec/models/site_setting_spec.rb index bf4c1c4161f..78589dc4ade 100644 --- a/spec/models/site_setting_spec.rb +++ b/spec/models/site_setting_spec.rb @@ -73,29 +73,29 @@ describe SiteSetting do context "has_enough_top_topics" do - SiteSetting.topics_per_period_in_top_page = 2 - SiteSetting.top_page_default_timeframe = 'daily' - before do - SiteSetting.expects(:min_redirected_to_top_period).returns(:daily) + SiteSetting.topics_per_period_in_top_page = 2 + SiteSetting.top_page_default_timeframe = 'daily' + TopTopic.stubs(:topics_per_period).with(:daily).returns(3) + TopTopic.refresh! end it "should_return_a_time_period" do - expect(SiteSetting.min_redirected_to_top_period(1.days.ago)).not_to eq(nil) + expect(SiteSetting.min_redirected_to_top_period(1.days.ago)).to eq(:daily) end end context "does_not_have_enough_top_topics" do - SiteSetting.topics_per_period_in_top_page = 20 - SiteSetting.top_page_default_timeframe = 'daily' - before do - SiteSetting.expects(:min_redirected_to_top_period).returns(nil) + SiteSetting.topics_per_period_in_top_page = 20 + SiteSetting.top_page_default_timeframe = 'daily' + TopTopic.stubs(:topics_per_period).with(:daily).returns(1) + TopTopic.refresh! end - it "should_return_nil" do + it "should_return_a_time_period" do expect(SiteSetting.min_redirected_to_top_period(1.days.ago)).to eq(nil) end