Skip to content

Commit

Permalink
prevent abstract class tables to leak columns to other tables
Browse files Browse the repository at this point in the history
  • Loading branch information
blahutka committed Sep 10, 2013
1 parent b27cba3 commit 56822a7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/mini_record/auto_schema.rb
Expand Up @@ -11,7 +11,7 @@ def schema_tables
end

def table_definition
return superclass.table_definition unless superclass == ActiveRecord::Base
return superclass.table_definition unless (superclass == ActiveRecord::Base) || (superclass.respond_to?(:abstract_class?) && superclass.abstract_class?)

@_table_definition ||= begin
tb = ActiveRecord::ConnectionAdapters::TableDefinition.new(connection)
Expand All @@ -21,7 +21,7 @@ def table_definition
end

def indexes
return superclass.indexes unless superclass == ActiveRecord::Base
return superclass.indexes unless (superclass == ActiveRecord::Base) || (superclass.respond_to?(:abstract_class?) && superclass.abstract_class?)

@_indexes ||= {}
end
Expand Down
22 changes: 22 additions & 0 deletions test/test_mini_record.rb
Expand Up @@ -596,4 +596,26 @@ class Bar < Foo
refute_includes tables, ''
assert_includes tables, 'bars'
end

it 'should prevent abstract table class to leak columns to other tables' do

class Base < ActiveRecord::Base
self.abstract_class = true
end

class User < Base
col :name
end

class Book < Base
col :title
col :author
end

User.auto_upgrade!
Book.auto_upgrade!

assert_equal ['id', 'name'], User.db_columns.sort
assert_equal ['author', 'id', 'title'], Book.db_columns.sort
end
end

0 comments on commit 56822a7

Please sign in to comment.