Skip to content

Commit 92853a9

Browse files
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
1 parent 8014369 commit 92853a9

File tree

4 files changed

+1
-26
lines changed

4 files changed

+1
-26
lines changed

app/services/forest_liana/schema_adapter.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,6 @@ def add_associations
242242
SchemaUtils.associations(@model).each do |association|
243243
begin
244244
if SchemaUtils.polymorphic?(association) &&
245-
(ENV['ENABLE_SUPPORT_POLYMORPHISM'].present? && ENV['ENABLE_SUPPORT_POLYMORPHISM'].downcase == 'true')
246-
247245
collection.fields << {
248246
field: association.name.to_s,
249247
type: get_type_for_association(association),

app/services/forest_liana/schema_utils.rb

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,7 @@ class SchemaUtils
44
def self.associations(active_record_class)
55
active_record_class.reflect_on_all_associations.select do |association|
66
begin
7-
if (ENV['ENABLE_SUPPORT_POLYMORPHISM'].present? && ENV['ENABLE_SUPPORT_POLYMORPHISM'].downcase == 'true')
8-
polymorphic?(association) ? true : !is_active_type?(association.klass)
9-
else
10-
!polymorphic?(association) && !is_active_type?(association.klass)
11-
end
12-
7+
polymorphic?(association) ? true : !is_active_type?(association.klass)
138
rescue
149
FOREST_LOGGER.warn "Unknown association #{association.name} on class #{active_record_class.name}"
1510
false

spec/services/forest_liana/schema_adapter_spec.rb

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -40,23 +40,6 @@ module ForestLiana
4040

4141
expect(removed_fields).to be_empty
4242
end
43-
44-
context 'when the polymorphic support was disabled' do
45-
it 'should not define the association' do
46-
ENV['ENABLE_SUPPORT_POLYMORPHISM'] = 'false'
47-
Bootstrapper.new(true)
48-
collection = ForestLiana.apimap.find do |object|
49-
object.name.to_s == ForestLiana.name_for(Address)
50-
end
51-
association = collection.fields.find { |field| field[:field] == 'addressable' }
52-
fields = collection.fields.select do |field|
53-
field[:field] == 'addressable_id' || field[:field] == 'addressable_type'
54-
end
55-
56-
expect(association).to be_nil
57-
expect(fields.size).to eq(2)
58-
end
59-
end
6043
end
6144

6245
context 'with an "unhandled" column types (binary, postgis geography, ...)' do

spec/spec_helper.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
2020
RSpec.configure do |config|
2121
ENV['RAILS_ENV'] = 'test'
22-
ENV['ENABLE_SUPPORT_POLYMORPHISM'] = 'true'
2322

2423
require File.expand_path('../dummy/config/environment', __FILE__)
2524

0 commit comments

Comments
 (0)