Sha256: 1160aace69cd0aed0f0c58d8a9aa0979868e96c1114af6024333b8590117f64f
Contents?: true
Size: 1.16 KB
Versions: 1
Compression:
Stored size: 1.16 KB
Contents
require "test_helper" require "rack/jsonp/callback" class CallbackTest < Test::Unit::TestCase def setup @status = 200 @headers = { "Content-Type" => "application/json", "Content-Length" => "2" } @body = "{}" end test "doesn't change anything when callback is missing" do env = Rack::MockRequest.env_for("/") app = Rack::JSONP::Callback.new(lambda { |env| [@status, @headers, [@body]] }) status, headers, iterable = app.call(env) body = ""; iterable.each { |l| body << l } assert_equal @status, status assert_equal @headers, headers assert_equal @body, body end test "wraps response with callback and updates headers" do env = Rack::MockRequest.env_for("/?_callback=callback") app = Rack::JSONP::Callback.new(lambda { |env| [@status, @headers, [@body]] }) status, headers, iterable = app.call(env) body = ""; iterable.each { |l| body << l } expected_body = "callback(#{@body})" assert_equal @status, status assert_equal @headers, { "Content-Type" => "application/javascript", "Content-Length" => expected_body.size.to_s } assert_equal expected_body, body end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rack-jsonp-tools-0.1.0 | test/callback_test.rb |