diff --git a/app/controllers/list_controller.rb b/app/controllers/list_controller.rb index ec901ddb638..8fea454ebf0 100644 --- a/app/controllers/list_controller.rb +++ b/app/controllers/list_controller.rb @@ -110,10 +110,13 @@ class ListController < ApplicationController end def category_default - if @category.default_view == 'top' + view_method = @category.default_view + view_method = 'latest' unless %w(latest top).include?(view_method) + + if view_method == 'top' top(category: @category.id) else - self.send(@category.default_view || 'latest') + self.send(view_method) end end diff --git a/spec/controllers/list_controller_spec.rb b/spec/controllers/list_controller_spec.rb index 9673858aaa3..0c5b41596bc 100644 --- a/spec/controllers/list_controller_spec.rb +++ b/spec/controllers/list_controller_spec.rb @@ -192,26 +192,34 @@ describe ListController do end describe "category default views" do - it "top default view" do + it "has a top default view" do category.update_attributes!(default_view: 'top', default_top_period: 'monthly') described_class.expects(:best_period_with_topics_for).with(anything, category.id, :monthly).returns(:monthly) xhr :get, :category_default, category: category.slug expect(response).to be_success end - it "default view is nil" do + it "has a default view of nil" do category.update_attributes!(default_view: nil) described_class.expects(:best_period_for).never xhr :get, :category_default, category: category.slug expect(response).to be_success end - it "default view is latest" do + it "has a default view of ''" do + category.update_attributes!(default_view: '') + described_class.expects(:best_period_for).never + xhr :get, :category_default, category: category.slug + expect(response).to be_success + end + + it "has a default view of latest" do category.update_attributes!(default_view: 'latest') described_class.expects(:best_period_for).never xhr :get, :category_default, category: category.slug expect(response).to be_success end + end end end