【发布时间】:2011-02-06 17:28:02
【问题描述】:
试图让这个功能测试通过:
test "should create question" do
assert_difference('Question.count') do
post :create, :question => @question.attributes
end
end
但是@question 的验证器要求特定的子节点出现在一个主题中:
class Question < ActiveRecord::Base
has_many :topic_questions
has_many :topics, :through => :topic_questions
validate :has_topic
def has_topic
(errors[:base] << "You must have one topic") if (topics.count < 1)
end
end
我将如何 1) 在测试中为 @question 构建主题,然后 2) 将其传递给 post 方法,因为 .attributes() 函数不会传递它?
【问题讨论】:
标签: ruby-on-rails testing ruby-on-rails-3 functional-testing fixtures