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.

custom_value_test.rb 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006- Jean-Philippe Lang
  4. #
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU General Public License
  7. # as published by the Free Software Foundation; either version 2
  8. # of the License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. require_relative '../test_helper'
  19. class CustomValueTest < ActiveSupport::TestCase
  20. fixtures :custom_fields, :custom_values, :users
  21. def setup
  22. User.current = nil
  23. end
  24. def test_new_without_value_should_set_default_value
  25. field = CustomField.generate!(:default_value => 'Default string')
  26. v = CustomValue.new(:custom_field => field)
  27. assert_equal 'Default string', v.value
  28. end
  29. def test_new_with_value_should_not_set_default_value
  30. field = CustomField.generate!(:default_value => 'Default string')
  31. v = CustomValue.new(:custom_field => field, :value => 'String')
  32. assert_equal 'String', v.value
  33. end
  34. def test_new_with_nil_value_should_not_set_default_value
  35. field = CustomField.generate!(:default_value => 'Default string')
  36. v = CustomValue.new(:custom_field => field, :value => nil)
  37. assert_nil v.value
  38. end
  39. def test_sti_polymorphic_association
  40. # Rails uses top level sti class for polymorphic association. See #3978.
  41. assert !User.find(4).custom_values.empty?
  42. assert !CustomValue.find(2).customized.nil?
  43. end
  44. end