From 92853a91ed23b8834f85582aef8f24c6b12f3cb0 Mon Sep 17 00:00:00 2001 From: NicolasAlexandre Date: Tue, 23 Jan 2024 14:23:43 +0100 Subject: [PATCH] feat(polymorphic): enabled polymorphic associations support by default (#644) BREAKING CHANGE: polymorphic association support enabled by default. It is no longer necessary to define the env variable ENABLE_SUPPORT_POLYMORPHISM --- app/services/forest_liana/schema_adapter.rb | 2 -- app/services/forest_liana/schema_utils.rb | 7 +------ .../forest_liana/schema_adapter_spec.rb | 17 ----------------- spec/spec_helper.rb | 1 - 4 files changed, 1 insertion(+), 26 deletions(-) diff --git a/app/services/forest_liana/schema_adapter.rb b/app/services/forest_liana/schema_adapter.rb index e7489bec..582aae2d 100644 --- a/app/services/forest_liana/schema_adapter.rb +++ b/app/services/forest_liana/schema_adapter.rb @@ -242,8 +242,6 @@ def add_associations SchemaUtils.associations(@model).each do |association| begin if SchemaUtils.polymorphic?(association) && - (ENV['ENABLE_SUPPORT_POLYMORPHISM'].present? && ENV['ENABLE_SUPPORT_POLYMORPHISM'].downcase == 'true') - collection.fields << { field: association.name.to_s, type: get_type_for_association(association), diff --git a/app/services/forest_liana/schema_utils.rb b/app/services/forest_liana/schema_utils.rb index c9766ac9..4ab41940 100644 --- a/app/services/forest_liana/schema_utils.rb +++ b/app/services/forest_liana/schema_utils.rb @@ -4,12 +4,7 @@ class SchemaUtils def self.associations(active_record_class) active_record_class.reflect_on_all_associations.select do |association| begin - if (ENV['ENABLE_SUPPORT_POLYMORPHISM'].present? && ENV['ENABLE_SUPPORT_POLYMORPHISM'].downcase == 'true') - polymorphic?(association) ? true : !is_active_type?(association.klass) - else - !polymorphic?(association) && !is_active_type?(association.klass) - end - + polymorphic?(association) ? true : !is_active_type?(association.klass) rescue FOREST_LOGGER.warn "Unknown association #{association.name} on class #{active_record_class.name}" false diff --git a/spec/services/forest_liana/schema_adapter_spec.rb b/spec/services/forest_liana/schema_adapter_spec.rb index 2263974d..7be76af2 100644 --- a/spec/services/forest_liana/schema_adapter_spec.rb +++ b/spec/services/forest_liana/schema_adapter_spec.rb @@ -40,23 +40,6 @@ module ForestLiana expect(removed_fields).to be_empty end - - context 'when the polymorphic support was disabled' do - it 'should not define the association' do - ENV['ENABLE_SUPPORT_POLYMORPHISM'] = 'false' - Bootstrapper.new(true) - collection = ForestLiana.apimap.find do |object| - object.name.to_s == ForestLiana.name_for(Address) - end - association = collection.fields.find { |field| field[:field] == 'addressable' } - fields = collection.fields.select do |field| - field[:field] == 'addressable_id' || field[:field] == 'addressable_type' - end - - expect(association).to be_nil - expect(fields.size).to eq(2) - end - end end context 'with an "unhandled" column types (binary, postgis geography, ...)' do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 65ef2563..1ff43ef5 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -19,7 +19,6 @@ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration RSpec.configure do |config| ENV['RAILS_ENV'] = 'test' - ENV['ENABLE_SUPPORT_POLYMORPHISM'] = 'true' require File.expand_path('../dummy/config/environment', __FILE__)