@@ -22,7 +22,7 class CustomValue < ActiveRecord::Base | |||
|
22 | 22 | |
|
23 | 23 | def initialize(attributes=nil, *args) |
|
24 | 24 | super |
|
25 | if new_record? && custom_field && (customized_type.blank? || (customized && customized.new_record?)) | |
|
25 | if new_record? && custom_field && !attributes.key?(:value) | |
|
26 | 26 | self.value ||= custom_field.default_value |
|
27 | 27 | end |
|
28 | 28 | end |
@@ -92,12 +92,12 module Redmine | |||
|
92 | 92 | if field.multiple? |
|
93 | 93 | values = custom_values.select { |v| v.custom_field == field } |
|
94 | 94 | if values.empty? |
|
95 |
values << custom_values.build(:customized => self, :custom_field => field |
|
|
95 | values << custom_values.build(:customized => self, :custom_field => field) | |
|
96 | 96 | end |
|
97 | 97 | x.value = values.map(&:value) |
|
98 | 98 | else |
|
99 | 99 | cv = custom_values.detect { |v| v.custom_field == field } |
|
100 |
cv ||= custom_values.build(:customized => self, :custom_field => field |
|
|
100 | cv ||= custom_values.build(:customized => self, :custom_field => field) | |
|
101 | 101 | x.value = cv.value |
|
102 | 102 | end |
|
103 | 103 | x.value_was = x.value.dup if x.value |
@@ -562,7 +562,7 JSON | |||
|
562 | 562 | assert_equal "", issue.reload.custom_field_value(field) |
|
563 | 563 | end |
|
564 | 564 | |
|
565 |
test "PUT /issues/:id.json with tracker change and omitted custom field specific to that tracker |
|
|
565 | test "PUT /issues/:id.json with tracker change and omitted custom field specific to that tracker should set default value" do | |
|
566 | 566 | field = IssueCustomField.generate!(:default_value => "Default", :tracker_ids => [2]) |
|
567 | 567 | issue = Issue.generate!(:project_id => 1, :tracker_id => 1) |
|
568 | 568 | |
@@ -573,7 +573,7 JSON | |||
|
573 | 573 | end |
|
574 | 574 | |
|
575 | 575 | assert_equal 2, issue.reload.tracker_id |
|
576 |
assert_ |
|
|
576 | assert_equal "Default", issue.reload.custom_field_value(field) | |
|
577 | 577 | end |
|
578 | 578 | |
|
579 | 579 | test "PUT /issues/:id.json with tracker change and custom field specific to that tracker set to blank should not set default value" do |
@@ -20,15 +20,25 require File.expand_path('../../test_helper', __FILE__) | |||
|
20 | 20 | class CustomValueTest < ActiveSupport::TestCase |
|
21 | 21 | fixtures :custom_fields, :custom_values, :users |
|
22 | 22 | |
|
23 | def test_default_value | |
|
24 |
field = CustomField. |
|
|
25 | assert_not_nil field | |
|
23 | def test_new_without_value_should_set_default_value | |
|
24 | field = CustomField.generate!(:default_value => 'Default string') | |
|
26 | 25 | |
|
27 | 26 | v = CustomValue.new(:custom_field => field) |
|
28 | 27 | assert_equal 'Default string', v.value |
|
28 | end | |
|
29 | ||
|
30 | def test_new_with_value_should_not_set_default_value | |
|
31 | field = CustomField.generate!(:default_value => 'Default string') | |
|
32 | ||
|
33 | v = CustomValue.new(:custom_field => field, :value => 'String') | |
|
34 | assert_equal 'String', v.value | |
|
35 | end | |
|
36 | ||
|
37 | def test_new_with_nil_value_should_not_set_default_value | |
|
38 | field = CustomField.generate!(:default_value => 'Default string') | |
|
29 | 39 | |
|
30 |
v = CustomValue.new(:custom_field => field, :value => |
|
|
31 |
assert_ |
|
|
40 | v = CustomValue.new(:custom_field => field, :value => nil) | |
|
41 | assert_nil v.value | |
|
32 | 42 | end |
|
33 | 43 | |
|
34 | 44 | def test_sti_polymorphic_association |
General Comments 0
You need to be logged in to leave comments.
Login now