diff --git a/app/models/object_manager/attribute.rb b/app/models/object_manager/attribute.rb index 806b77055..2b21267df 100644 --- a/app/models/object_manager/attribute.rb +++ b/app/models/object_manager/attribute.rb @@ -834,7 +834,7 @@ is certain attribute used by triggers, overviews or schedulers end record = object_lookup.name.constantize.new - if record.respond_to?(name.to_sym) && record.attributes.key?(name) && new_record? + if new_record? && (record.respond_to?(name.to_sym) || record.attributes.key?(name)) errors.add(:name, "#{name} already exists!") end diff --git a/spec/models/object_manager/attribute_spec.rb b/spec/models/object_manager/attribute_spec.rb index 03d040947..c98d7dcde 100644 --- a/spec/models/object_manager/attribute_spec.rb +++ b/spec/models/object_manager/attribute_spec.rb @@ -76,6 +76,22 @@ RSpec.describe ObjectManager::Attribute, type: :model do end end + %w[title tags].each do |not_editable_attribute| + it "rejects '#{not_editable_attribute}' which is used" do + expect do + described_class.add attributes_for :object_manager_attribute_text, name: not_editable_attribute + end.to raise_error(ActiveRecord::RecordInvalid, 'Validation failed: Name Attribute not editable!') + end + end + + %w[priority state note number].each do |existing_attribute| + it "rejects '#{existing_attribute}' which is used" do + expect do + described_class.add attributes_for :object_manager_attribute_text, name: existing_attribute + end.to raise_error(ActiveRecord::RecordInvalid, "Validation failed: Name #{existing_attribute} already exists!") + end + end + it 'rejects duplicate attribute name of conflicting types' do attribute = attributes_for :object_manager_attribute_text described_class.add attribute