Any sample controller test code for create, destroy?

37 vues
Accéder directement au premier message non lu

asfan

non lue,
23 mai 2007, 21:05:3123/05/2007
à 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

non lue,
24 mai 2007, 05:03:5424/05/2007
à 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

non lue,
24 mai 2007, 13:26:5724/05/2007
à 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!

Répondre à tous
Répondre à l'auteur
Transférer
0 nouveau message