I'd love to get Active Record Fixtures working in my mailer previews. No documentation seems to exist for this, and I've gotten stuck hacking around the Rails code base. Maybe someone can take it from here, as it would be nice to have.
require "rails/test_help"
class MyMailerPreview < ActionMailer::Preview
include ActiveRecord::TestFixtures
# this is officially depreciated in favor of `ActiveSupport::TestCase.fixture_paths`,
# but I couldn't get that working
self.fixture_path = 'test/fixtures'
# this should create fixtures, but fails as `setup_fixtures` hasn't been called, and so `@fixture_cache` is not defined. See ActiveRecord lib/active_record/test_fixtures.rb
fixtures :all
# override b/c the original reference some variable `name`
# which I can't find the definition of
def run_in_transaction?
true
end
def my_preview
# setup_fixtures is accessible as an instance method, which sets up the
# @fixture_cache / etc, but at this point I haven't called the class
# method and so we still don't get fixtures
setup_fixtures
end
I got about this far a PG duplicate key error from calling setup_fixtures, and decided to abandon ship for now.