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 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2015 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 test_hide_mail_should_default_to_true
  21. preference = UserPreference.new
  22. assert_equal true, preference.hide_mail
  23. end
  24. def test_create
  25. user = User.new(:firstname => "new", :lastname => "user", :mail => "newuser@somenet.foo")
  26. user.login = "newuser"
  27. user.password, user.password_confirmation = "password", "password"
  28. assert user.save
  29. assert_kind_of UserPreference, user.pref
  30. assert_kind_of Hash, user.pref.others
  31. assert user.pref.save
  32. end
  33. def test_update
  34. user = User.find(1)
  35. assert_equal true, user.pref.hide_mail
  36. user.pref['preftest'] = 'value'
  37. assert user.pref.save
  38. user.reload
  39. assert_equal 'value', user.pref['preftest']
  40. end
  41. def test_others_hash
  42. user = User.new(:firstname => "new", :lastname => "user", :mail => "newuser@somenet.foo")
  43. user.login = "newuser"
  44. user.password, user.password_confirmation = "password", "password"
  45. assert user.save
  46. assert_nil user.preference
  47. up = UserPreference.new(:user => user)
  48. assert_kind_of Hash, up.others
  49. up.others = nil
  50. assert_nil up.others
  51. assert up.save
  52. assert_kind_of Hash, up.others
  53. end
  54. def test_others_should_be_blank_after_initialization
  55. pref = User.new.pref
  56. assert_equal({}, pref.others)
  57. end
  58. def test_reading_value_from_nil_others_hash
  59. up = UserPreference.new(:user => User.new)
  60. up.others = nil
  61. assert_nil up.others
  62. assert_nil up[:foo]
  63. end
  64. def test_writing_value_to_nil_others_hash
  65. up = UserPreference.new(:user => User.new)
  66. up.others = nil
  67. assert_nil up.others
  68. up[:foo] = 'bar'
  69. assert_equal 'bar', up[:foo]
  70. end
  71. end