diff --git a/app/models/concerns/has_object_manager_attributes_validation.rb b/app/models/concerns/has_object_manager_attributes_validation.rb index 75e678ad3..b42875c5b 100644 --- a/app/models/concerns/has_object_manager_attributes_validation.rb +++ b/app/models/concerns/has_object_manager_attributes_validation.rb @@ -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 diff --git a/app/models/ticket.rb b/app/models/ticket.rb index 8c5904653..79b27c889 100644 --- a/app/models/ticket.rb +++ b/app/models/ticket.rb @@ -89,8 +89,6 @@ class Ticket < ApplicationModel association_attributes_ignored :flags, :mentions - self.inheritance_column = nil - attr_accessor :callback_loop =begin diff --git a/spec/models/concerns/has_object_manager_attributes_validation_examples.rb b/spec/models/concerns/has_object_manager_attributes_validation_examples.rb index 42e34c2c4..acdacfc06 100644 --- a/spec/models/concerns/has_object_manager_attributes_validation_examples.rb +++ b/spec/models/concerns/has_object_manager_attributes_validation_examples.rb @@ -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 diff --git a/spec/models/group_spec.rb b/spec/models/group_spec.rb index 96d4d355c..0b8f5cb7a 100644 --- a/spec/models/group_spec.rb +++ b/spec/models/group_spec.rb @@ -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'