Hi,

On Mon, Jan 24, 2011 at 19:33, Cezar Halmagean <ce...@halmagean.ro> wrote:
> So I am trying to spec a nested model / form like say Post has_many Comments
> and in order to build a nested form I need to build a new comment in
> @posts.comments like so:
> @post = Post.new
> @post.comments.build
> Now, my question is: How do you go about correctly testing this ?

I would do something as follows:

it "creates a post with a comment" do
  expect { post :create, :args => { :some => "args" } }.to
change(Post, :count).by(1)
  post = Post.last
  post.should have(1).comments
end

HTH,
Mike
_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Reply via email to