Any sample controller test code for create, destroy?

瀏覽次數:37 次
跳到第一則未讀訊息

asfan

未讀,
2007年5月23日 晚上9: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日 清晨5: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日 下午1: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 則新訊息