Skip to content

Commit

Permalink
[#3] Respect default_format for rabl response
Browse files Browse the repository at this point in the history
  • Loading branch information
LTe committed Jun 3, 2012
1 parent f7139f9 commit ac54ebb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/grape-rabl/formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def after
rabl(current_endpoint) do |template|
engine = ::Tilt.new(view_path(template))
rendered = engine.render(current_endpoint, {})
headers['Content-Type'] = content_types[env['api.format']]
Rack::Response.new(rendered, status, headers).to_a
end
end
Expand Down
7 changes: 7 additions & 0 deletions spec/grape_rabl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,18 @@ def app; subject end
lambda{ get "/home" }.should raise_error("Use Rack::Config to set 'api.tilt.root' in config.ru")
end


context "titl root is setup" do
before do
subject.before { env["api.tilt.root"] = "#{File.dirname(__FILE__)}/views" }
end

it "should respond with proper content-type" do
subject.get("/home", :rabl => "user"){}
get("/home")
last_response.headers["Content-Type"].should == "application/json"
end

it "should not raise error about root directory" do
subject.get("/home", :rabl => true){}
lambda{ get "/home" }.should_not raise_error("Use Rack::Config to set 'api.tilt.root' in config.ru")
Expand Down

0 comments on commit ac54ebb

Please sign in to comment.