thoughtbot/shoulda-matchers — pull request #154 by karledurante (2012-09-18 19:37:30+00:00)
Title: Ability to use 'have_and_belong_to_many' matcher when models use an alternate database

The have_and_belong_to_many matcher assumes that the join table exists in the database defined in ActiveRecord::Base.connection. However, it's possible to define models that point to alternate databases. When these models use HABTM relationships, the join table will also exist in this "other" database.

The code change I have made is simple: Instead of using ActiveRecord::Base.connection, I use model_class.connection. This ensures that we look for the join table using the parent model's connection.

In theory, there should be no test changes. All the the tests should continue to work, that's the test.

However, if you have some suggestions for how I should test this, please let me know.