First of all, json is usually only sent to javascript apps on web
browsers do to lack of standard xml support. Maybe you should consider
sending xml to your rails app.
First of all, json is usually only sent to javascript apps on web
browsers do to lack of standard xml support. Maybe you should consider
sending xml to your rails app.
Hi, thanks - it's not a bad idea, but we need to handle json in our
rails app, and I want to be able to test it, of course.
Ok... I think I figured it out. The problem is that I needed an
integration test, not a functional test. The way the two work seems to
be subtly different. This works ok:
def test_create
open_session do |sess|
sess.post('/resource/create.js', '{answer: 42}', {"Content-type"
=> "application/json"})
assert_equal "{answerplusone: 43}", sess.response.body
end
end
With this:
def create
respond_to do |format|
format.html {
render :text => 'hello world'
}
format.js {
ok = { :good => 'ok' }
render :json => ok.to_json
}
end
end
Well... at least in the sense of sending the right stuff and getting
the right section of code back.