]> source.dussan.org Git - redmine.git/commitdiff
Clear settings for blocks that are no longer used.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Wed, 15 Mar 2017 17:52:41 +0000 (17:52 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Wed, 15 Mar 2017 17:52:41 +0000 (17:52 +0000)
git-svn-id: http://svn.redmine.org/redmine/trunk@16405 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/user_preference.rb
test/functional/my_controller_test.rb
test/unit/user_preference_test.rb

index 0ebafa839d0c344312fbef4c571b6e4357417241..e0b17631c79b8072642957603668356bbe150c59 100644 (file)
@@ -23,7 +23,7 @@ class UserPreference < ActiveRecord::Base
 
   attr_protected :others, :user_id
 
-  before_save :set_others_hash
+  before_save :set_others_hash, :clear_unused_block_settings
 
   safe_attributes 'hide_mail',
     'time_zone',
@@ -132,4 +132,10 @@ class UserPreference < ActiveRecord::Base
     block_settings = my_page_settings(block).merge(settings.symbolize_keys)
     my_page_settings[block] = block_settings
   end
+
+  def clear_unused_block_settings
+    blocks = my_page_layout.values.flatten
+    my_page_settings.keep_if {|block, settings| blocks.include?(block)}
+  end
+  private :clear_unused_block_settings
 end
index f79cca5d9b0982b58d0cd35a94132e046f8f6a5a..f6c9d5ab27a8921bc82df951625d8efa7af0a5a2 100644 (file)
@@ -266,12 +266,12 @@ class MyControllerTest < Redmine::ControllerTest
     user = User.generate!(:language => 'en')
     @request.session[:user_id] = user.id
 
-    xhr :post, :update_page, :settings => {'timelog' => {'days' => '14'}}
+    xhr :post, :update_page, :settings => {'issuesassignedtome' => {'columns' => ['subject', 'due_date']}}
     assert_response :success
-    assert_include '$("#block-timelog").replaceWith(', response.body
-    assert_include '14 days', response.body
+    assert_include '$("#block-issuesassignedtome").replaceWith(', response.body
+    assert_include 'Due date', response.body
 
-    assert_equal({:days => "14"}, user.reload.pref.my_page_settings('timelog'))
+    assert_equal({:columns => ['subject', 'due_date']}, user.reload.pref.my_page_settings('issuesassignedtome'))
   end
 
   def test_add_block
@@ -321,6 +321,7 @@ class MyControllerTest < Redmine::ControllerTest
   end
 
   def test_reset_rss_key_without_existing_key
+    Token.delete_all
     assert_nil User.find(2).rss_token
     post :reset_rss_key
 
index bbf5f70babca533b6dfbf3b04519dd055706a56a..757a795d9d1c341bccf57984219cb61351e67114 100644 (file)
@@ -93,4 +93,15 @@ class UserPreferenceTest < ActiveSupport::TestCase
     up[:foo] = 'bar'
     assert_equal 'bar', up[:foo]
   end
+
+  def test_removing_a_block_should_clear_its_settings
+    up = User.find(2).pref
+    up.my_page_layout = {'top' => ['news', 'documents']}
+    up.my_page_settings = {'news' => {:foo => 'bar'}, 'documents' => {:baz => 'quz'}}
+    up.save!
+
+    up.remove_block 'news'
+    up.save!
+    assert_equal ['documents'], up.my_page_settings.keys
+  end
 end