You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

user_preference_test.rb 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2017 Jean-Philippe Lang
  3. #
  4. # This program is free software; you can redistribute it and/or
  5. # modify it under the terms of the GNU General Public License
  6. # as published by the Free Software Foundation; either version 2
  7. # of the License, or (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program; if not, write to the Free Software
  16. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17. require File.expand_path('../../test_helper', __FILE__)
  18. class UserPreferenceTest < ActiveSupport::TestCase
  19. fixtures :users, :user_preferences
  20. def setup
  21. User.current = nil
  22. end
  23. def test_hide_mail_should_default_to_true
  24. preference = UserPreference.new
  25. assert_equal true, preference.hide_mail
  26. end
  27. def test_hide_mail_should_default_to_false_with_setting
  28. with_settings :default_users_hide_mail => '0' do
  29. preference = UserPreference.new
  30. assert_equal false, preference.hide_mail
  31. end
  32. end
  33. def test_time_zone_should_default_to_setting
  34. with_settings :default_users_time_zone => 'Paris' do
  35. preference = UserPreference.new
  36. assert_equal 'Paris', preference.time_zone
  37. end
  38. end
  39. def test_no_self_notified_should_default_to_true
  40. preference = UserPreference.new
  41. assert_equal true, preference.no_self_notified
  42. end
  43. def test_create
  44. user = User.new(:firstname => "new", :lastname => "user", :mail => "newuser@somenet.foo")
  45. user.login = "newuser"
  46. user.password, user.password_confirmation = "password", "password"
  47. assert user.save
  48. assert_kind_of UserPreference, user.pref
  49. assert_kind_of Hash, user.pref.others
  50. assert user.pref.save
  51. end
  52. def test_update
  53. user = User.find(1)
  54. assert_equal true, user.pref.hide_mail
  55. user.pref['preftest'] = 'value'
  56. assert user.pref.save
  57. user.reload
  58. assert_equal 'value', user.pref['preftest']
  59. end
  60. def test_others_hash
  61. user = User.new(:firstname => "new", :lastname => "user", :mail => "newuser@somenet.foo")
  62. user.login = "newuser"
  63. user.password, user.password_confirmation = "password", "password"
  64. assert user.save
  65. assert_nil user.preference
  66. up = UserPreference.new(:user => user)
  67. assert_kind_of Hash, up.others
  68. up.others = nil
  69. assert_nil up.others
  70. assert up.save
  71. assert_kind_of Hash, up.others
  72. end
  73. def test_reading_value_from_nil_others_hash
  74. up = UserPreference.new(:user => User.new)
  75. up.others = nil
  76. assert_nil up.others
  77. assert_nil up[:foo]
  78. end
  79. def test_writing_value_to_nil_others_hash
  80. up = UserPreference.new(:user => User.new)
  81. up.others = nil
  82. assert_nil up.others
  83. up[:foo] = 'bar'
  84. assert_equal 'bar', up[:foo]
  85. end
  86. def test_removing_a_block_should_clear_its_settings
  87. up = User.find(2).pref
  88. up.my_page_layout = {'top' => ['news', 'documents']}
  89. up.my_page_settings = {'news' => {:foo => 'bar'}, 'documents' => {:baz => 'quz'}}
  90. up.save!
  91. up.remove_block 'news'
  92. up.save!
  93. assert_equal ['documents'], up.my_page_settings.keys
  94. end
  95. end