Hi

When trying to play around with the attached integration test, I
spotted a problem,
The test does not produce any arror, but the second comment on the
post is produced without any post ID, see output below...


  def dump_comments
    Comment.find(:all).each { |comment|
      puts "- comment: <#{comment.post_id}>#{comment.comment}"
    }
  end


  def test_should_create_1_post_and_2_comments
    post '/posts/create', :post => {:title=>"Rails", :body=>"I love
Rails"}
    assert assigns(:post).valid?
    assert_redirected_to post_path(assigns(:post))

    post '/posts/post_comment', :comment => {:post_id=>
(:post).id, :comment=>"my comment"}
    assert assigns(:comment).valid?
    assert_redirected_to :action => 'show'
#  ==> remove this line to make it work...    post '/posts/show', :id
=> flash[:post_id]

    post '/posts/post_comment', :comment => {:post_id=>
(:post).id, :comment=>"my comment 2"}
    assert assigns(:comment).valid?
    assert_redirected_to :action => 'show'
    # debug method of the test
    dump_comments
  end

Output:
- comment: <11>What are you talking about?
- comment: <11>What a stupid comment
- comment: <12>This is a comment for the 2nd posting
- comment: <15>my comment
- comment: <>my comment 2
---------------------------------------------------------
See last comment has no post_id, to fix it, add the line under
comment, do trigger the display_post again

This brought me to thinking...
- Does anyone know why it doesnt work without the re-"show"?
- When the Comment has a "belongs_to :post" definition, aren't we
supposed to get protected from such problems? shouldn't the post_id
field be mandatory?

Cheers

Dov

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "ruby-on-rails-programming-with-passion" group.
To unsubscribe from this group, send email to
ruby-on-rails-programming-with-passion-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/ruby-on-rails-programming-with-passion?hl=en?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to