-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test that all AR subclasses with a type column have STI disabled
- Loading branch information
Showing
1 changed file
with
28 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
describe "Disable STI when inheriting from ActiveRecord::Base" do | ||
def columns_for_table(table_name) | ||
ActiveRecord::Base.connection.columns(table_name) | ||
rescue ActiveRecord::StatementInvalid | ||
ActiveRecord::Base.connection.reconnect! | ||
[] | ||
end | ||
|
||
def table_has_type_column?(table_name) | ||
return unless table_name | ||
columns_for_table(table_name).detect { |i| i.name == "type" } | ||
end | ||
|
||
it "with self.inheritance_column = :_type_disabled" do | ||
Dir.glob(ManageIQ::Schema::Engine.root.join("db", "migrate", "*.rb")).each { |i| require i } | ||
|
||
needs_inheritance_column_type_disabled = ActiveRecord::Base.descendants.collect do |i| | ||
next unless table_has_type_column?(i.table_name) | ||
i.name unless i.inheritance_column == "_type_disabled" | ||
end.compact | ||
|
||
expect(needs_inheritance_column_type_disabled).to eq([]), <<~EOM | ||
The line `self.inheritance_column = :_type_disabled` is missing from the following class definitions: | ||
#{needs_inheritance_column_type_disabled.join("\n")} | ||
EOM | ||
end | ||
end |