From a8d321a21ec5bfd85472bfb6e205e63b05526172 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Wed, 14 Dec 2016 01:08:29 +0100 Subject: [PATCH] Fixed issue #433 - Object manager allows method names as attributes. --- app/models/object_manager/attribute.rb | 8 ++++++++ test/unit/object_manager_test.rb | 20 ++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/app/models/object_manager/attribute.rb b/app/models/object_manager/attribute.rb index a003a41b3..0928b2ed5 100644 --- a/app/models/object_manager/attribute.rb +++ b/app/models/object_manager/attribute.rb @@ -663,6 +663,14 @@ to send no browser reload event, pass false raise 'At least one letters is needed' elsif name =~ /^(destroy|true|false|integer|select|drop|create|alter|index|table|varchar|blob|date|datetime|timestamp)$/ raise "#{name} is a reserved word, please choose a different one" + + # do not allow model method names as attributes + else + model = Kernel.const_get(object_lookup.name) + record = model.new + if record.respond_to?(name.to_sym) && !record.attributes.key?(name) + raise "#{name} is a reserved word, please choose a different one" + end end true end diff --git a/test/unit/object_manager_test.rb b/test/unit/object_manager_test.rb index 68bb42634..a7b218419 100644 --- a/test/unit/object_manager_test.rb +++ b/test/unit/object_manager_test.rb @@ -407,6 +407,26 @@ class ObjectManagerTest < ActiveSupport::TestCase } assert_equal(false, ObjectManager::Attribute.pending_migration?) + assert_raises(RuntimeError) { + attribute18 = ObjectManager::Attribute.add( + object: 'Ticket', + name: 'delete', + display: 'Test 18', + data_type: 'input', + data_option: { + maxlength: 200, + type: 'text', + null: false, + }, + active: true, + screens: {}, + position: 20, + created_by_id: 1, + updated_by_id: 1, + ) + } + assert_equal(false, ObjectManager::Attribute.pending_migration?) + end test 'b object manager attribute' do