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.4KB

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