Browse Source

Fixed issue #2172 - Do not allow to create pre existing attributes like updated_at via object manager.

Martin Edenhofer 6 years ago
parent
commit
1755163c00
2 changed files with 47 additions and 0 deletions
  1. 1 0
      app/models/object_manager/attribute.rb
  2. 46 0
      test/integration/object_manager_test.rb

+ 1 - 0
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

+ 46 - 0
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