diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb index 051ca31f..047bc5e2 100644 --- a/app/controllers/pages_controller.rb +++ b/app/controllers/pages_controller.rb @@ -19,8 +19,8 @@ def read_news_topic_config(config) limit = config['display'] || 3 @topic = Forums::Topic.find(config['id']) - @threads = @topic.threads.ordered.limit(limit) + @threads = @topic.threads.visible.ordered.limit(limit) @news_posts = @threads.map { |thread| [thread, thread.original_post] }.to_h - @more_threads = @topic.threads.limit(limit + 1).size > limit + @more_threads = @topic.threads.visible.limit(limit + 1).size > limit end end diff --git a/spec/controllers/pages_controller_spec.rb b/spec/controllers/pages_controller_spec.rb index 9ffe707a..bb09ba08 100644 --- a/spec/controllers/pages_controller_spec.rb +++ b/spec/controllers/pages_controller_spec.rb @@ -25,6 +25,20 @@ expect(response).to have_http_status(:success) end + + it 'hides hidden threads' do + topic = create(:forums_topic) + thread = create(:forums_thread, topic: topic) + hidden_thread = create(:forums_thread, topic: topic, hidden: true) + + Rails.configuration.news['type'] = 'topic' + Rails.configuration.news['id'] = topic.id + + get :home + + expect(response).to have_http_status(:success) + expect(controller.view_assigns['threads']).to eq([thread]) + end end context 'invalid news config' do