From a9c364b4656312ef75b2d178476fa93d4c45323a Mon Sep 17 00:00:00 2001 From: Gui Albuk Date: Tue, 28 Jun 2016 12:43:41 -0300 Subject: [PATCH] Fix #tables deprecation in Rails 5.0 and keep compatibility with Rails 4.x --- .../association_matchers/join_table_matcher.rb | 2 +- lib/shoulda/matchers/rails_shim.rb | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/shoulda/matchers/active_record/association_matchers/join_table_matcher.rb b/lib/shoulda/matchers/active_record/association_matchers/join_table_matcher.rb index c46f2d4bf..b214445f7 100644 --- a/lib/shoulda/matchers/active_record/association_matchers/join_table_matcher.rb +++ b/lib/shoulda/matchers/active_record/association_matchers/join_table_matcher.rb @@ -38,7 +38,7 @@ def join_table_option_correct? 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 diff --git a/lib/shoulda/matchers/rails_shim.rb b/lib/shoulda/matchers/rails_shim.rb index 7eb10b688..5159468ce 100644 --- a/lib/shoulda/matchers/rails_shim.rb +++ b/lib/shoulda/matchers/rails_shim.rb @@ -55,6 +55,14 @@ def self.simply_generate_validation_message(attribute, type, model_name, options 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