FIX: Possible 500 error if category saved incorrectly

This commit is contained in:
Robin Ward 2017-05-08 15:17:58 -04:00
parent 4f6e5fed2a
commit afe04b8bbb
2 changed files with 16 additions and 5 deletions

View File

@ -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

View File

@ -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