Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix single table inheritance deprecation warning bug #84

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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