From ee1ac78d88411281a6ff57c52982585dcccbce99 Mon Sep 17 00:00:00 2001 From: Gareth Edwards Date: Fri, 22 Feb 2013 18:26:00 +0000 Subject: [PATCH] Test for JSONP support --- spec/grape/entity_spec.rb | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/spec/grape/entity_spec.rb b/spec/grape/entity_spec.rb index ff6a6c0669..4618574f0a 100644 --- a/spec/grape/entity_spec.rb +++ b/spec/grape/entity_spec.rb @@ -196,6 +196,34 @@ def initialize(args) last_response.headers['Content-type'].should == "application/json" last_response.body.should == '{"example":{"name":"johnnyiller"}}' end + + # We ignore the JSONP callback and rack-jsonp dependency for this test + # the main focus is the serialization of the Entity with the + # application/javascript content-type + it 'presents with jsonp' do + entity = Class.new(Grape::Entity) + entity.root "examples", "example" + entity.expose :name + + subject.content_type :jsonp, 'application/javascript' + subject.format :jsonp + + subject.get '/example' do + c = Class.new do + attr_reader :name + def initialize(args) + @name = args[:name] || "no name set" + end + end + + present c.new({:name => "johnnyiller"}), :with => entity + end + get '/example' + last_response.status.should == 200 + last_response.headers['Content-type'].should == "application/javascript" + last_response.body.should == '{"example":{"name":"johnnyiller"}}' + end + end end \ No newline at end of file