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

This commit is contained in:
Martin Edenhofer 2018-08-06 20:44:37 +02:00
parent 0c7c33b64c
commit 1755163c00
2 changed files with 47 additions and 0 deletions

View file

@ -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

View file

@ -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