Fixed issue #433 - Object manager allows method names as attributes.

This commit is contained in:
Martin Edenhofer 2016-12-14 01:08:29 +01:00
parent a1e19cc75d
commit a8d321a21e
2 changed files with 28 additions and 0 deletions

View file

@ -663,6 +663,14 @@ to send no browser reload event, pass false
raise 'At least one letters is needed' raise 'At least one letters is needed'
elsif name =~ /^(destroy|true|false|integer|select|drop|create|alter|index|table|varchar|blob|date|datetime|timestamp)$/ 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" 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 end
true true
end end

View file

@ -407,6 +407,26 @@ class ObjectManagerTest < ActiveSupport::TestCase
} }
assert_equal(false, ObjectManager::Attribute.pending_migration?) 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 end
test 'b object manager attribute' do test 'b object manager attribute' do