diff --git a/app/models/object_manager/attribute.rb b/app/models/object_manager/attribute.rb index 0a4bcfc1c..5750f1290 100644 --- a/app/models/object_manager/attribute.rb +++ b/app/models/object_manager/attribute.rb @@ -870,6 +870,7 @@ is certain attribute used by triggers, overviews or schedulers record = object_lookup.name.constantize.new return true if !record.respond_to?(name.to_sym) + raise "#{name} already exists!" if record.attributes.key?(name) && new_record? return true if record.attributes.key?(name) raise "#{name} is a reserved word, please choose a different one" end diff --git a/test/integration/object_manager_test.rb b/test/integration/object_manager_test.rb index e28cf1394..972345819 100644 --- a/test/integration/object_manager_test.rb +++ b/test/integration/object_manager_test.rb @@ -427,6 +427,52 @@ class ObjectManagerTest < ActiveSupport::TestCase end assert_equal(false, ObjectManager::Attribute.pending_migration?) + attribute_count = ObjectManager::Attribute.count + assert_raises(RuntimeError) do + attribute19 = ObjectManager::Attribute.add( + object: 'Ticket', + name: 'updated_at', + display: 'Update Time', + data_type: 'datetime', + data_option: { + future: true, + past: true, + diff: 24, + null: true, + }, + active: true, + screens: {}, + position: 20, + created_by_id: 1, + updated_by_id: 1, + ) + assert_equal(false, ObjectManager::Attribute.pending_migration?) + end + assert_equal(attribute_count, ObjectManager::Attribute.count) + + assert_raises(RuntimeError) do + attribute20 = ObjectManager::Attribute.add( + object: 'Ticket', + name: 'updated_AT', + display: 'Update Time', + data_type: 'datetime', + data_option: { + future: true, + past: true, + diff: 24, + null: true, + }, + active: true, + screens: {}, + position: 20, + created_by_id: 1, + updated_by_id: 1, + ) + assert_equal(false, ObjectManager::Attribute.pending_migration?) + end + + assert_equal(attribute_count, ObjectManager::Attribute.count) + end test 'b object manager attribute' do