Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSONP content-type does not serialize entities properly... #346

Merged
merged 1 commit into from
Feb 22, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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