From 8a6ce3a6463f55978bc108385fe8908d19891fcd Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sat, 13 Oct 2012 07:40:07 +0000 Subject: [PATCH] Make sure that custom field format cannot be changed. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10624 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/models/custom_field.rb | 5 +++++ test/unit/custom_field_test.rb | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/app/models/custom_field.rb b/app/models/custom_field.rb index 86227a4cf..22f29d3ac 100644 --- a/app/models/custom_field.rb +++ b/app/models/custom_field.rb @@ -53,6 +53,11 @@ class CustomField < ActiveRecord::Base CUSTOM_FIELDS_NAMES = CUSTOM_FIELDS_TABS.collect{|v| v[:name]} + def field_format=(arg) + # cannot change format of a saved custom field + super if new_record? + end + def set_searchable # make sure these fields are not searchable self.searchable = false if %w(int float date bool).include?(field_format) diff --git a/test/unit/custom_field_test.rb b/test/unit/custom_field_test.rb index 547e712db..d858045ed 100644 --- a/test/unit/custom_field_test.rb +++ b/test/unit/custom_field_test.rb @@ -57,6 +57,12 @@ class CustomFieldTest < ActiveSupport::TestCase assert field.valid? end + def test_should_not_change_field_format_of_existing_custom_field + field = CustomField.find(1) + field.field_format = 'int' + assert_equal 'list', field.field_format + end + def test_possible_values_should_accept_an_array field = CustomField.new field.possible_values = ["One value", ""]