seb_guard wrote:> Hi everyone,
>
> I am a bit confused with xhr? and respond_to.
>
> I have the folloing code in my view to update the
''emails'' ID
> link_to_remote(image_tag("refresh"), :update =>
"emails",
> :url => { :action => "list_emails" })
>
> in the controller side i have somthing like :
> [..]
> respond_to do |type|
> type.html { render :action ''list_emails'' }
> type.js { render :partial => ''list_emails'' }
> end
> [..]
>
> The partial returns html code such as
> [..]<ul><li>email1</li></li></ul> [..]
>
> In my controller functional test
> I do
> [..]
> xhr :get,:list_emails
> assert_select "ul"
> [..]
>
> But `assert_select'' did not find anything.
> However if i changed my controller action (remove the respond_to and
> replace with xhr?)
> [..]
> if request.xhr?
> render :partial => ''list_emails''
> else
> render :action ''list_emails''
> end
> [..]
>
>
> Then the assertion works perfectly.
> Am i missing something ? Are not we supossed to migrate to the
> respond_to structure ? wht would be the recommendation for this
> situation ? stick with xhr?
>
> thanks a lot
>
> -sebastien
>
>
assert_select looks at the content-type returned and tests accordingly.
If it is js then it thinks it''s an rjs type response. I thought this
was
a bug, and filed a ticket when 1.2 was being finalised, but is
apparently expected behaviour, I think on the basis that respond_to is
asking what type of response the reqester wants.
However, it does make it tricky to test the above scenario (where you
want the Ajax response to be just a partial, which is quite a common
idiom IMHO). The best I''ve come up with is matching the @response.body
with a RegExp
Hope this helps (a bit).
Chris
--
----------------------------
http://www.autopendium.co.uk
Stuff about old cars
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---