Question

I assumed it was a Rails convention that mailer fixtures reside in a folder named after that mailers class name, and inside that folder are fixtures named after each action in the mailer class.

But when I run my unit tests, I notice rails raises and error because it tries to drop a test table names after the mailer class and mailer action class put together... this is odd, I would have assumed rails would know better and ignore these fixtures that are simply used for mailer content formatting comparison.

Rails 3 documentation on the mailer fixtures:

10.2.1 Revenge of the Fixtures

For the purposes of unit testing a mailer, fixtures are used to provide an example of how the output should look. Because these are example emails, and not Active Record data like the other fixtures, they are kept in their own subdirectory apart from the other fixtures. The name of the directory within test/fixtures directly corresponds to the name of the mailer. So, for a mailer named UserMailer, the fixtures should reside in test/fixtures/user_mailer directory.

I'm using rails 3.0.12

test helper contents:

ENV["RAILS_ENV"] = "test"
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'

class ActiveSupport::TestCase
    fixtures :all
    # Add more helper methods to be used by all tests here...
end

my fixtures directory layout:

test/fixtures/card_sender_mailer/card_update_notificaiton.yml

This is the error:

ActiveRecord::StatementInvalid: Mysql2::Error: Table 'monkey_test.card_sender_mailer_card_update_notification' doesn't exist: DELETE FROM `card_sender_mailer_card_update_notification`

I assume that because I'm loading all fixtures it's trying to load this as well, so how do I load all fixtures except the mailer fixtures?

Update 1

When I try loading the fixtures with rake in the terminal, I get a similar error:

Tasks: TOP => db:fixtures:load
(See full trace by running task with --trace)
/Users/victorstan/Sites/ContactMonkey ∴ bundle exec rake db:fixtures:load 
rake aborted!
Mysql2::Error: Table 'monkey_development.card_sender_mailer_card_update_notification' doesn't exist: DELETE FROM `card_sender_mailer_card_update_notification
Was it helpful?

Solution

I will answer my own question, despite the Rails documentation: mailer fixtures should be .txt files not .yml files, if you don't want them loaded into the DB. Maybe I'll contribute to the documentation one day.

OTHER TIPS

I moved all subfolders to test/files

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top