Hi,
I can''t find any information on how to specify the format (like xml,
html, js, ...) of a request in a functional controller test.
For example:
I have a create action in my bookmarks_controller which responds to
format.xml and format.html.
If html is requested it should respond with a redirect, if xml is
requested with the http status code :created.
def test_should_create_bookmark_xml
post :create, :bookmark => { :channel_id => 3, :user_id => 1 }
assert_equal old_count+1, Bookmark.count
assert_response :created
assert assigns(:bookmark)
end
def test_should_create_bookmark_html
post :create, :bookmark => { :channel_id => 3, :user_id => 1 }
assert_equal old_count+1, Bookmark.count
assert_redirected_to bookmark_path(1, assigns(:hypermark))
end
How can I specify which format post requests?
lg philipp
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
Philipp Schmid
2007-Apr-23 20:25 UTC
Re: Specify format (xml, html, etc) in functional test
A finally found a blog regarding this problem: http://singlecell.angryamoeba.co.uk/2007/03/16/testing-respond_to-actions-in-rails-121/ lg philipp Philipp Schmid wrote:> Hi, > > I can''t find any information on how to specify the format (like xml, > html, js, ...) of a request in a functional controller test. > > For example: > > I have a create action in my bookmarks_controller which responds to > format.xml and format.html. > If html is requested it should respond with a redirect, if xml is > requested with the http status code :created. > > def test_should_create_bookmark_xml > post :create, :bookmark => { :channel_id => 3, :user_id => 1 } > assert_equal old_count+1, Bookmark.count > > assert_response :created > assert assigns(:bookmark) > end > > def test_should_create_bookmark_html > post :create, :bookmark => { :channel_id => 3, :user_id => 1 } > assert_equal old_count+1, Bookmark.count > > assert_redirected_to bookmark_path(1, assigns(:hypermark)) > end > > How can I specify which format post requests? > > lg philipp--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
François Beausoleil
2007-Apr-24 01:27 UTC
Re: Specify format (xml, html, etc) in functional test
Hello Philipp, 2007/4/23, Philipp Schmid <philipp.schmid@gmail.com>:> I can't find any information on how to specify the format (like xml, > html, js, ...) of a request in a functional controller test.get :action, :format => "xml" Hope that helps ! -- François Beausoleil http://blog.teksol.info/ http://piston.rubyforge.org/ --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---