Fix #tables deprecation in Rails 5.0 and keep compatibility with Rails 4.x

This commit is contained in:
Gui Albuk 2016-06-28 12:43:41 -03:00 committed by Elliot Winkler
parent 90c0728cf7
commit a6d09aa5de
2 changed files with 9 additions and 1 deletions

View File

@ -38,7 +38,7 @@ module Shoulda
end
def join_table_exists?
if connection.tables.include?(join_table_name)
if RailsShim.tables_and_views(connection).include?(join_table_name)
true
else
@failure_message = missing_table_message

View File

@ -55,6 +55,14 @@ module Shoulda
I18n.translate(primary_translation_key, translate_options)
end
def self.tables_and_views(connection)
if active_record_major_version >= 5
connection.data_sources
else
connection.tables
end
end
def self.active_record_major_version
::ActiveRecord::VERSION::MAJOR
end