Skip to content

Commit

Permalink
Test that all AR subclasses with a type column have STI disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
bdunne committed Aug 8, 2018
1 parent 7dad258 commit 087e18f
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions spec/automated_review/disable_sti_spec.rb
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

0 comments on commit 087e18f

Please sign in to comment.