SCENARIO
I have extracted a concern called Taggable
. It\'s a module that allows any model to support tagging. I have included
I would suggest having DummyClass
be a generic ActiveRecord::Base
child with very little custom code besides just include Taggable
, so that you would be isolating your concern module as much as possible but still being an AR class. Avoiding the use of one of your "real" classes like User
still isolates you from any other code in those classes, which seems valuable.
So something like this:
class DummyClass < ActiveRecord::Base; end
describe Taggable do
before do
@dummy_class = DummyClass.new
end
...
end
Since your DummyClass
may need to actually interact with the DB to test things like associations, you may need to create temporary tables in the DB during testing. The temping Ruby gem may be able to help with that, since its designed to create temporary ActiveRecord models and their underlying database tables.
Temping allows you to create arbitrary ActiveRecord models backed by a temporary SQL table for use in tests. You may need to do something like this if you're testing a module that is meant to be mixed into ActiveReord models without relaying on a concrete class.