Fixed issue #2172 - Do not allow to create pre existing attributes like updated_at via object manager.
This commit is contained in:
parent
0c7c33b64c
commit
1755163c00
2 changed files with 47 additions and 0 deletions
|
@ -870,6 +870,7 @@ is certain attribute used by triggers, overviews or schedulers
|
||||||
|
|
||||||
record = object_lookup.name.constantize.new
|
record = object_lookup.name.constantize.new
|
||||||
return true if !record.respond_to?(name.to_sym)
|
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)
|
return true if record.attributes.key?(name)
|
||||||
raise "#{name} is a reserved word, please choose a different one"
|
raise "#{name} is a reserved word, please choose a different one"
|
||||||
end
|
end
|
||||||
|
|
|
@ -427,6 +427,52 @@ class ObjectManagerTest < ActiveSupport::TestCase
|
||||||
end
|
end
|
||||||
assert_equal(false, ObjectManager::Attribute.pending_migration?)
|
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
|
end
|
||||||
|
|
||||||
test 'b object manager attribute' do
|
test 'b object manager attribute' do
|
||||||
|
|
Loading…
Reference in a new issue