30 errors with should_be_restful

0 views
Skip to first unread message

Sean Hussey

unread,
Mar 27, 2008, 2:53:09 PM3/27/08
to shoulda
Hi everyone,

I'm using resource_controller, which I hope isn't causing this issue.

A sampling of some of the test errors:

test: on PUT to :update with {} should not have errors on @news_post.
(NewsPostsontrollerTest):
RuntimeError: Called id for nil, which would mistakenly be 4 (etc...)

They're all like that.

My test (in setup @news_post = news_posts :one):

should_be_restful do |resource|
resource.klass = NewsPost # Tried without this, same result.
resource.object = :news_post # Tried without this, same result.
resource.parent = :cause
resource.formats = [:html]
end

Cause has_many :news_posts and NewsPost belongs_to :cause.

Routing:

map.resources :causes, :has_many => :news_posts # Also tried with
normal do block, same result.

I have another parent/child relationship with members and memberships
that works fine in tests. I can't see any differences in the two
approaches. Any ideas?

Thanks!

Sean

James Golick

unread,
Mar 27, 2008, 2:55:12 PM3/27/08
to sho...@googlegroups.com
Can you pastie the backtrace pls. This combination (r_c & shoulda) is my toolset for nearly every project I work on, so I'm pretty sure I can help.

Sean Hussey

unread,
Mar 27, 2008, 2:59:17 PM3/27/08
to shoulda
Here's a few:


17) Error:
test: on GET to :new should render 'new' template.
(NewsPostsControllerTest):
RuntimeError: Called id for nil, which would mistakenly be 4 -- if you
really wanted the id of nil, use object_id
/Users/sean/Projects/Rails/onecause/vendor/plugins/shoulda/lib/
shoulda/controller_tests/controller_tests.rb:458:in
`make_parent_params'
/Users/sean/Projects/Rails/onecause/vendor/plugins/shoulda/lib/
shoulda/controller_tests/formats/html.rb:83:in
`__bind_1206644279_40486'
/Users/sean/Projects/Rails/onecause/vendor/plugins/shoulda/lib/
shoulda/gem/shoulda.rb:101:in `call'
/Users/sean/Projects/Rails/onecause/vendor/plugins/shoulda/lib/
shoulda/gem/shoulda.rb:101:in `test: on GET to :new should render
'new' template. '
/Users/sean/Projects/Rails/onecause/vendor/plugins/shoulda/lib/
shoulda/gem/shoulda.rb:101:in `each'
/Users/sean/Projects/Rails/onecause/vendor/plugins/shoulda/lib/
shoulda/gem/shoulda.rb:101:in `test: on GET to :new should render
'new' template. '


25) Error:
test: on POST to :create with {} should not have errors on @news_post.
(NewsPostsControllerTest):
RuntimeError: Called id for nil, which would mistakenly be 4 -- if you
really wanted the id of nil, use object_id
/Users/sean/Projects/Rails/onecause/vendor/plugins/shoulda/lib/
shoulda/controller_tests/controller_tests.rb:458:in
`make_parent_params'
/Users/sean/Projects/Rails/onecause/vendor/plugins/shoulda/lib/
shoulda/controller_tests/formats/html.rb:137:in
`__bind_1206644279_51048'
/Users/sean/Projects/Rails/onecause/vendor/plugins/shoulda/lib/
shoulda/gem/shoulda.rb:101:in `call'
/Users/sean/Projects/Rails/onecause/vendor/plugins/shoulda/lib/
shoulda/gem/shoulda.rb:101:in `test: on POST to :create with {} should
not have errors on @news_post. '
/Users/sean/Projects/Rails/onecause/vendor/plugins/shoulda/lib/
shoulda/gem/shoulda.rb:101:in `each'
/Users/sean/Projects/Rails/onecause/vendor/plugins/shoulda/lib/
shoulda/gem/shoulda.rb:101:in `test: on POST to :create with {} should
not have errors on @news_post. '




30) Error:
test: on PUT to :update with {} should redirect to
"cause_news_post_url(@news_post.cause, @news_post)".
(NewsPostsControllerTest):
RuntimeError: Called id for nil, which would mistakenly be 4 -- if you
really wanted the id of nil, use object_id
/Users/sean/Projects/Rails/onecause/vendor/plugins/shoulda/lib/
shoulda/controller_tests/controller_tests.rb:458:in
`make_parent_params'
/Users/sean/Projects/Rails/onecause/vendor/plugins/shoulda/lib/
shoulda/controller_tests/formats/html.rb:170:in
`__bind_1206644279_57644'
/Users/sean/Projects/Rails/onecause/vendor/plugins/shoulda/lib/
shoulda/gem/shoulda.rb:101:in `call'
/Users/sean/Projects/Rails/onecause/vendor/plugins/shoulda/lib/
shoulda/gem/shoulda.rb:101:in `test: on PUT to :update with {} should
redirect to "cause_news_post_url(@news_post.cause, @news_post)". '
/Users/sean/Projects/Rails/onecause/vendor/plugins/shoulda/lib/
shoulda/gem/shoulda.rb:101:in `each'
/Users/sean/Projects/Rails/onecause/vendor/plugins/shoulda/lib/
shoulda/gem/shoulda.rb:101:in `test: on PUT to :update with {} should
redirect to "cause_news_post_url(@news_post.cause, @news_post)". '


On Mar 27, 2:55 pm, "James Golick" <jamesgol...@gmail.com> wrote:
> Can you pastie the backtrace pls. This combination (r_c & shoulda) is my
> toolset for nearly every project I work on, so I'm pretty sure I can help.
>

James Golick

unread,
Mar 27, 2008, 3:00:55 PM3/27/08
to sho...@googlegroups.com
is @news_post.cause nil? that looks like it's the problem.

Sean Hussey

unread,
Mar 27, 2008, 3:07:44 PM3/27/08
to shoulda
Ugh, sorta, kinda, not really. The fixtures were set up with cause: 1
instead of cause_id: 1.

Thanks for the help!

Sean

On Mar 27, 3:00 pm, "James Golick" <jamesgol...@gmail.com> wrote:
> is @news_post.cause nil? that looks like it's the problem.
>
Reply all
Reply to author
Forward
0 new messages