]> source.dussan.org Git - redmine.git/commitdiff
Fixes User/CustomValue association broken by r2869 (#3978).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 10 Oct 2009 10:16:00 +0000 (10:16 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 10 Oct 2009 10:16:00 +0000 (10:16 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2905 e93f8b46-1217-0410-a6f0-8f06a7374b81

db/migrate/20091010093521_fix_users_custom_values.rb [new file with mode: 0644]
test/fixtures/custom_values.yml
test/unit/custom_value_test.rb

diff --git a/db/migrate/20091010093521_fix_users_custom_values.rb b/db/migrate/20091010093521_fix_users_custom_values.rb
new file mode 100644 (file)
index 0000000..923c78f
--- /dev/null
@@ -0,0 +1,9 @@
+class FixUsersCustomValues < ActiveRecord::Migration
+  def self.up
+    CustomValue.update_all("customized_type = 'Principal'", "customized_type = 'User'")
+  end
+
+  def self.down
+    CustomValue.update_all("customized_type = 'User'", "customized_type = 'Principal'")
+  end
+end
index 4e3eee4f9edf0ad02955c94a76a90837e2dc6098..783aa75c9b0bab6f1ca1ce88efebd8d4782d8c6e 100644 (file)
@@ -12,19 +12,19 @@ custom_values_007:
   id: 7
   value: Stable
 custom_values_001: 
-  customized_type: User
+  customized_type: Principal
   custom_field_id: 4
   customized_id: 3
   id: 1
   value: ""
 custom_values_002: 
-  customized_type: User
+  customized_type: Principal
   custom_field_id: 4
   customized_id: 4
   id: 2
   value: 01 23 45 67 89
 custom_values_003: 
-  customized_type: User
+  customized_type: Principal
   custom_field_id: 4
   customized_id: 2
   id: 3
index 08492ef581bc4df9eca3c731eda31bbde00d66e9..332c92644fc4e8f0dfe19cdbb213a30bc9f27670 100644 (file)
@@ -18,7 +18,7 @@
 require File.dirname(__FILE__) + '/../test_helper'
 
 class CustomValueTest < ActiveSupport::TestCase
-  fixtures :custom_fields
+  fixtures :custom_fields, :custom_values, :users
 
   def test_string_field_validation_with_blank_value
     f = CustomField.new(:field_format => 'string')
@@ -114,4 +114,10 @@ class CustomValueTest < ActiveSupport::TestCase
     v = CustomValue.new(:custom_field => field, :value => 'Not empty')
     assert_equal 'Not empty', v.value
   end
+  
+  def test_sti_polymorphic_association
+    # Rails uses top level sti class for polymorphic association. See #3978.
+    assert !User.find(4).custom_values.empty?
+    assert !CustomValue.find(2).customized.nil?
+  end
 end