Skip to content

Commit

Permalink
Merge pull request #84 from vassyz/fix-single-table-inheritance-bug
Browse files Browse the repository at this point in the history
Fix single table inheritance deprecation warning bug
  • Loading branch information
duncanjbrown authored Aug 29, 2023
2 parents e35de06 + 31f06af commit 6d42dc0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/dfe/analytics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,11 @@ def self.initialize!

entities_for_analytics.each do |entity|
models_for_entity(entity).each do |m|
if m.include?(DfE::Analytics::Entities) && !@shown_deprecation_warning
if m.include?(DfE::Analytics::Entities)
Rails.logger.info("DEPRECATION WARNING: DfE::Analytics::Entities was manually included in a model (#{m.name}), but it's included automatically since v1.4. You're running v#{DfE::Analytics::VERSION}. To silence this warning, remove the include from model definitions in app/models.")
else
m.include(DfE::Analytics::Entities)
break
end
end
end
Expand Down
7 changes: 6 additions & 1 deletion spec/dfe/analytics/single_table_inheritance_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,17 @@

# autogenerate a compliant blocklist
allow(DfE::Analytics).to receive(:blocklist).and_return(DfE::Analytics::Fields.generate_blocklist)
DfE::Analytics.initialize!
end

it 'correctly includes callbacks for each member of the STI party' do
DfE::Analytics.initialize!
expect(Parent).to include(DfE::Analytics::Entities)
expect(Child).to include(DfE::Analytics::Entities)
expect(Sibling).to include(DfE::Analytics::Entities)
end

it 'does not log a deprecation warning' do
expect(Rails.logger).not_to receive(:info).with(/DEPRECATION WARNING/)
DfE::Analytics.initialize!
end
end

0 comments on commit 6d42dc0

Please sign in to comment.