Fixed 3578 - Can't create custom fields with name "type".

This commit is contained in:
Dominik Klein 2021-07-12 08:31:37 +00:00 committed by Thorsten Eckel
parent 382291d0ae
commit 0fe81f4e0b
4 changed files with 21 additions and 2 deletions

View file

@ -5,6 +5,9 @@ module HasObjectManagerAttributesValidation
extend ActiveSupport::Concern
included do
# Disable table inheritance to allow columns with the name 'type'.
self.inheritance_column = nil
validates_with ObjectManager::Attribute::Validation, on: %i[create update]
end
end

View file

@ -89,8 +89,6 @@ class Ticket < ApplicationModel
association_attributes_ignored :flags, :mentions
self.inheritance_column = nil
attr_accessor :callback_loop
=begin

View file

@ -4,4 +4,20 @@ RSpec.shared_examples 'HasObjectManagerAttributesValidation' do
it 'validates ObjectManager::Attributes' do
expect(described_class.validators.map(&:class)).to include(ObjectManager::Attribute::Validation)
end
context "when object attribute with name 'type' is used", db_strategy: :reset do
before do
skip('Skip context if a special type handling exists') if subject.try(:type_id)
if !ObjectManager::Attribute.exists?(object_lookup: ObjectLookup.find_by(name: described_class.name), name: 'type')
create(:object_manager_attribute_text, name: 'type', object_name: described_class.name)
ObjectManager::Attribute.migration_execute
end
end
it "check that the 'type' column can be updated" do
expect { subject.reload.update(type: 'Example') }.not_to raise_error
end
end
end

View file

@ -9,6 +9,8 @@ require 'models/concerns/has_ticket_create_screen_impact_examples'
require 'models/concerns/has_xss_sanitized_note_examples'
RSpec.describe Group, type: :model do
subject(:group) { create(:group) }
it_behaves_like 'ApplicationModel'
it_behaves_like 'CanBeImported'
it_behaves_like 'HasObjectManagerAttributesValidation'