Skip to content

Commit

Permalink
Fix habtm matcher to support symbols for join_table
Browse files Browse the repository at this point in the history
The fix is simple but required slightly rewriting the tests, as it turns
out the existing tests weren't exercising all of the possible checks
that join_table makes.
  • Loading branch information
mcmire committed Jul 25, 2020
1 parent 97810e6 commit f16532b
Show file tree
Hide file tree
Showing 3 changed files with 331 additions and 68 deletions.
6 changes: 3 additions & 3 deletions lib/shoulda/matchers/active_record/association_matcher.rb
Expand Up @@ -920,21 +920,21 @@ def have_one(name)
# asserts that the table you're referring to actually exists.
#
# class Person < ActiveRecord::Base
# has_and_belongs_to_many :issues, join_table: 'people_tickets'
# has_and_belongs_to_many :issues, join_table: :people_tickets
# end
#
# # RSpec
# RSpec.describe Person, type: :model do
# it do
# should have_and_belong_to_many(:issues).
# join_table('people_tickets')
# join_table(:people_tickets)
# end
# end
#
# # Minitest (Shoulda)
# class PersonTest < ActiveSupport::TestCase
# should have_and_belong_to_many(:issues).
# join_table('people_tickets')
# join_table(:people_tickets)
# end
#
# ##### validate
Expand Down
Expand Up @@ -29,7 +29,7 @@ def join_table_option_correct?
if option_verifier.correct_for_string?(:join_table, options[:join_table_name])
true
else
@failure_message = "#{name} should use '#{options[:join_table_name]}' for :join_table option"
@failure_message = "#{name} should use #{options[:join_table_name].inspect} for :join_table option"
false
end
else
Expand All @@ -38,7 +38,7 @@ def join_table_option_correct?
end

def join_table_exists?
if RailsShim.tables_and_views(connection).include?(join_table_name)
if RailsShim.tables_and_views(connection).include?(join_table_name.to_s)
true
else
@failure_message = missing_table_message
Expand Down

0 comments on commit f16532b

Please sign in to comment.