From 9318cd2fbe90ccc10cfc47acf3e6c94ae6c6cd4c Mon Sep 17 00:00:00 2001 From: Toshi MARUYAMA Date: Sat, 4 Feb 2012 08:26:28 +0000 Subject: [PATCH] Merged r8761 from trunk attachment: fix that diff type is not saved in user preference. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/branches/1.3-stable@8763 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/controllers/attachments_controller.rb | 5 +++++ test/functional/attachments_controller_test.rb | 15 +++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 55cef02a8..53ff69ba8 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -29,6 +29,11 @@ class AttachmentsController < ApplicationController @diff = File.new(@attachment.diskfile, "rb").read @diff_type = params[:type] || User.current.pref[:diff_type] || 'inline' @diff_type = 'inline' unless %w(inline sbs).include?(@diff_type) + # Save diff type as user preference + if User.current.logged? && @diff_type != User.current.pref[:diff_type] + User.current.pref[:diff_type] = @diff_type + User.current.preference.save + end render :action => 'diff' elsif @attachment.is_text? && @attachment.filesize <= Setting.file_max_size_displayed.to_i.kilobyte @content = File.new(@attachment.diskfile, "rb").read diff --git a/test/functional/attachments_controller_test.rb b/test/functional/attachments_controller_test.rb index 625a21eb5..837f6398f 100644 --- a/test/functional/attachments_controller_test.rb +++ b/test/functional/attachments_controller_test.rb @@ -91,6 +91,21 @@ class AttachmentsControllerTest < ActionController::TestCase set_tmp_attachments_directory end + def test_save_diff_type + @request.session[:user_id] = 1 # admin + user = User.find(1) + get :show, :id => 5 + assert_response :success + assert_template 'diff' + user.reload + assert_equal "inline", user.pref[:diff_type] + get :show, :id => 5, :type => 'sbs' + assert_response :success + assert_template 'diff' + user.reload + assert_equal "sbs", user.pref[:diff_type] + end + def test_show_text_file get :show, :id => 4 assert_response :success