Skip to content

Commit

Permalink
Test for JSONP support
Browse files Browse the repository at this point in the history
  • Loading branch information
Gareth Edwards committed Feb 22, 2013
1 parent 7cd224c commit ee1ac78
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions spec/grape/entity_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit ee1ac78

Please sign in to comment.