Hi,
On Mon, Jan 24, 2011 at 19:33, Cezar Halmagean 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 i
On Wednesday, January 26, 2011 10:34:14 AM UTC-5, Cezar Halmagean wrote:
>
> That worked great, thank you.
You're welcome, mate!
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users
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 ?
Thanks
How about:
it 'builds a comment in the post' do
post = Post.new
comments_assoc = mock
comment = mock_model Comment
post.stub(:comments).and_return comments_assoc
comments_assoc.should_receive(:build).with(no_args).and_return comment
# invoke something to trigger the action
end
_
That worked great, thank you.___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users