Any sample controller test code for create, destroy?

37 views
Skip to first unread message

asfan

unread,
May 23, 2007, 9:05:31 PM5/23/07
to 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

unread,
May 24, 2007, 5:03:54 AM5/24/07
to 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

unread,
May 24, 2007, 1:26:57 PM5/24/07
to 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!

Reply all
Reply to author
Forward
0 new messages