【发布时间】:2011-02-10 01:38:36
【问题描述】:
我刚刚开始为我的 Rails 应用程序编写测试套件。我在 Rails 3 应用程序上使用 Factory Girl 和 Shoulda。在我的控制器中,我有:
def create
@topic = @forum.topics.build(params[:topic])
@topic.user = current_user
#So the topic gets pushed to the top without any replies
@topic.last_poster = current_user
@topic.last_post_at = Time.now
respond_to do |format|
if @topic.save
format.html { redirect_to(forum_topic_path(@topic.forum, @topic), :notice => 'Topic was successfully created.') }
format.xml { render :xml => @topic, :status => :created, :location => @topic }
else
format.html { render :action => "new" }
format.xml { render :xml => @topic.errors, :status => :unprocessable_entity }
end
end
end
我的问题是我将如何编写测试来验证 @topic.last_post_at 是否得到时间戳并正确保存,我会将这个测试编写为功能测试还是单元测试?
【问题讨论】:
标签: ruby-on-rails unit-testing ruby-on-rails-3 testing functional-testing