试图让这个功能测试通过:Rails的功能测试利用需要的儿童
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()函数传递?
有没有办法使用以下方法做同样的事情? `后:创建,问题:{主题:@a_topics_array}` – 2013-01-07 20:21:41