Expected response to be a <:redirect>, but was <200> when using should_redirect_to

99 views
Skip to first unread message

rtacconi

unread,
Jul 26, 2010, 1:05:06 PM7/26/10
to shoulda
I have this test:

context "should destroy participation" do
setup do
@configuration = Factory.create :configuration, :status =>
'LIVE'
@p = Factory.create :participation, :configuration =>
@configuration
@admin = Factory.create :participant, :admin => true
login_as @admin
end

should "delete :destroy participations" do
assert_difference('Participation.count', -1) do
delete :destroy, :id => @p.to_param
end
end

should_redirect_to("redirect to edit configuration")
{ edit_configuration_path @configuration }
# should_set_the_flash_to "The host has been unassociated."
end

The shoulda context tests this controller action:

def destroy
@participation = Participation.find(params[:id])
@c = Configuration.find @participation.configuration_id
@participation.destroy
flash[:notice] = 'The host has been unassociated.'

respond_to do |format|
format.html { redirect_to(edit_configuration_path @c) }
end
end


I get this message as failed test:

Expected response to be a <:redirect>, but was <200>

But why? That method really return a 302 (redirrect) method. Do I miss
something?

Dan Croak

unread,
Aug 4, 2010, 12:59:11 PM8/4/10
to sho...@googlegroups.com
Looks pretty good to me. Are you sure the failure is this test? You're
not accidentally running another test? (I've done that many times!)

Stylistically, you may want to change a few things:

redirect_to(edit_configuration_path @c)

I don't think precedence will matter there but I think most Rubyists
prefer it this way.

redirect_to(edit_configuration_path(@c))

Another:

@configuration = Factory.create :configuration, :status =>
'LIVE'

You can shorten that up with:

@configuration = Factory(:configuration, :status =>
'LIVE')

> --
> Individuals over processes. Interactions over tools.
>
> Agile Rails training from thoughtbot, the makers of Clearance, Shoulda, & Factory Girl:
> http://thoughtbot.com/services/training
>
> The Shoulda group:
> http://groups.google.com/group/shoulda
>
> To post to this group, send email to
> sho...@googlegroups.com
>
> To unsubscribe from this group, send email to
> shoulda+u...@googlegroups.com
>

Riccardo Tacconi

unread,
Aug 4, 2010, 1:20:11 PM8/4/10
to sho...@googlegroups.com
I am 100% sure and it is happening in several test. I discovered that instead of a redirect I get <html><body><a href="http://.../configuration/1/edit">redirected</a>...

This is why I get a 200. Instead of 302 and redirecting I get just a silly page saying that I've been redirected. It might be Rails that behaves that way.

I am testing is a contains redirected to see if the controller redirect works ok
--
Riccardo Tacconi
Web developer at Wolseley UK

http://www.linkedin.com/in/riccardotacconi
http://riccardotacconi.blogspot.com/
http://twitter.com/rtacconi
Linux user: #400461
Reply all
Reply to author
Forward
0 new messages