From 58a0086e69e193f2208cc1ab25e31e8599d05038 Mon Sep 17 00:00:00 2001 From: r888888888 Date: Thu, 12 Jun 2014 21:41:37 -0700 Subject: [PATCH] potential fix for #2192 --- app/controllers/forum_topics_controller.rb | 1 - app/models/forum_topic.rb | 4 +++- .../forum_topics_controller_test.rb | 19 +++++++++++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/app/controllers/forum_topics_controller.rb b/app/controllers/forum_topics_controller.rb index 95b2dd770..3683b6017 100644 --- a/app/controllers/forum_topics_controller.rb +++ b/app/controllers/forum_topics_controller.rb @@ -17,7 +17,6 @@ class ForumTopicsController < ApplicationController end def index - # session[:read_forum_topics] = "" @query = ForumTopic.active.search(params[:search]) @forum_topics = @query.order("is_sticky DESC, updated_at DESC").paginate(params[:page], :limit => params[:limit], :search_count => params[:search]) @read_forum_topic_ids = read_forum_topic_ids diff --git a/app/models/forum_topic.rb b/app/models/forum_topic.rb index 7dfb7ff5c..7ab53c31f 100644 --- a/app/models/forum_topic.rb +++ b/app/models/forum_topic.rb @@ -124,9 +124,11 @@ class ForumTopic < ActiveRecord::Base end hash[id.to_s] = updated_at.to_i.to_s result = hash.to_a.flatten.join(" ") - if result.size > 3000 + while result.size > 3000 ids = result.scan(/\S+/) + print "slicing from #{result.size} to " result = ids[(ids.size / 2)..-1].join(" ") + puts result.size end update_last_forum_read_at(hash.keys) result diff --git a/test/functional/forum_topics_controller_test.rb b/test/functional/forum_topics_controller_test.rb index 3ab5c37e7..1fd201dd2 100644 --- a/test/functional/forum_topics_controller_test.rb +++ b/test/functional/forum_topics_controller_test.rb @@ -16,6 +16,25 @@ class ForumTopicsControllerTest < ActionController::TestCase CurrentUser.ip_addr = nil end + context "show action" do + should "render" do + get :show, {:id => @forum_topic.id} + assert_response :success + end + + context "when the read_forum_topics session exceeds the maximum cookie size" do + setup do + @cookie_data = 1.upto(10_000).to_a.join(" ") + end + + should "truncate" do + get :show, {:id => @forum_topic.id}, {:user_id => @user.id, :read_forum_topics => @cookie_data} + assert_response :success + assert_equal(1570, session[:read_forum_topics].size) + end + end + end + context "index action" do should "list all forum topics" do get :index