views:

117

answers:

1

I recently started learning ruby on rails. I completed the weblog walkthru(links below) and want to make tests for it. I took this functional testing from the video version of the weblog demo. Now i want to make this testing work for the netbeans edition, which actually is structured differently in terms of how the comments relates to the post. From what I gathered, in the netbeans version, all comment views are done through the posts views. Now this test method needs to be modified to accomodate for that. How would I create the post object with a comment also? I dont know how objects work in Ruby. Like how to instantiate and such.

  test "should create comment and redirect to post without javascript" do
 p= Post.create!(:title => 'hello',:body => 'world')
 post :create, :post_id => p.id, :comment => {:body =>'nice!'}
 assert_redirected_to post_url(p)
 assert_equal 'nice!',p.comments.first.body
end
+1  A: 

From what I gather, you are trying to imitate a user submitting a comment on existing post. What you can do is run the project, open your web page, navigate to a post and create a comment. Then, check the server log file and find the part that was caused by you posting that comment. There you will see something like this:

Processing PostsController#create (for 127.0.0.1 at 2009-06-27 16:54:18) [POST]
Session ID: 17134c01441c1e26e17baeee4681dd3b
Parameters: {"action"=>"create", "controller"=>"posts", "comment"=> {"foo" => "bar"}}

Then just imitate that in your test, by writing something like:

post :create, :comment => {:foo => "bar"}

And that should create a new comment on the post.

However, you should do it this way ONLY WHILE LEARNING! Once you have got the hang of things, write tests before, outline how it all should work, and then work on the implementation until it does.

Toms Mikoss
Where would I find the server log file?
Egg
By default it is in PROJECT_DIR/log, look for development.log. Also, you should be able to see what gets written there at runtime, depending on how you start the server - the same terminal window where you wrote 'script/server', if you start it up that way. I think netbeans had some sort of in-build server console too, if you launch the server by some IDE command - haven't used NB in ages.
Toms Mikoss