【发布时间】:2012-03-13 01:26:28
【问题描述】:
我认为这是一个 Rails 约定,邮件程序固定装置驻留在以该邮件程序类名称命名的文件夹中,并且在该文件夹内是以邮件程序类中的每个操作命名的固定装置。
但是当我运行我的单元测试时,我注意到 rails raises 和 error 因为它试图在 mailer 类和 mailer action 类放在一起之后删除测试表名称......这很奇怪,我会假设 rails 会知道更好地忽略这些仅用于邮件内容格式比较的固定装置。
关于邮件装置的 Rails 3 文档:
10.2.1 夹具的复仇
为了对邮件程序进行单元测试,固定装置用于 提供输出应如何显示的示例。因为这些是 示例电子邮件,而不是像其他固定装置那样的 Active Record 数据, 它们与其他灯具分开保存在自己的子目录中。 test/fixtures 中的目录名直接对应 邮寄者的姓名。因此,对于名为 UserMailer 的邮件程序, 固定装置应位于 test/fixtures/user_mailer 目录中。
我正在使用 rails 3.0.12
测试助手内容:
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
我的灯具目录布局:
test/fixtures/card_sender_mailer/card_update_notificaiton.yml
这是错误:
ActiveRecord::StatementInvalid: Mysql2::Error: Table 'monkey_test.card_sender_mailer_card_update_notification' doesn't exist: DELETE FROM `card_sender_mailer_card_update_notification`
我假设因为我正在加载所有固定装置,所以它也在尝试加载它,那么我如何加载除邮件固定装置之外的所有固定装置?
更新 1
当我尝试在终端中使用 rake 加载固定装置时,我收到了类似的错误:
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
【问题讨论】:
标签: ruby-on-rails-3 testing fixtures mailer