Any sample controller test code for create, destroy?

已查看 37 次
跳至第一个未读帖子

asfan

未读,
2007年5月23日 21:05:312007/5/23
收件人 ActiveScaffold : Ruby on Rails plugin
Hi

I was wondering if any one can share some samples of test code that
tests ActiveScaffold?

Thanks

Ed W

未读,
2007年5月24日 05:03:542007/5/24
收件人 actives...@googlegroups.com

You beat me to it, but I would also like to see some example of
functional testing please (just to get a leg up to understand how to get
started)

Cheers

Ed W

asfan

未读,
2007年5月24日 13:26:572007/5/24
收件人 ActiveScaffold : Ruby on Rails plugin
Got a basic controller test working...

{{{
def test_create
group_role_count = GroupRole.find(:all).length
post :create, {"commit" => "Create", :record =>
{"role"=>{"id"=>"3"}, "group"=>{ "id"=>"3"}} }
assert_not_nil assigns("record")
assert_response :redirect
assert_equal group_role_count + 1, GroupRole.find(:all).length,
"Expected an additional GroupRole"
end
}}}

Key was the "commit" setting (at least for me) , if not it returns the
form for creating a new record.
Easy way that I used to identify how to set the parameters is to do it
manually and look at the development.log

Not exactly related but this rake task greatly improved the debugging.
It allows running of a particular test in the specified controller
test suite

http://nubyonrails.com/articles/2006/07/28/foscon-and-living-dangerously-with-rake

ActiveScaffold / Rails / Ruby rocks!

回复全部
回复作者
转发
0 个新帖子