-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: render template according to request format
- Loading branch information
Showing
3 changed files
with
46 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
require 'spec_helper' | ||
|
||
describe Grape::Rabl do | ||
subject do | ||
Class.new(Grape::API) | ||
end | ||
|
||
before do | ||
subject.format :xml | ||
subject.formatter :xml, Grape::Formatter::Rabl | ||
end | ||
|
||
def app | ||
subject | ||
end | ||
|
||
context "with xml format" do | ||
before do | ||
subject.before { | ||
env["api.tilt.root"] = "#{File.dirname(__FILE__)}/views" | ||
env["api.format"] = :xml | ||
} | ||
end | ||
|
||
it "should respond with proper content-type" do | ||
subject.get("/home", :rabl => "user"){} | ||
get("/home") | ||
last_response.headers["Content-Type"].should == "application/xml" | ||
end | ||
|
||
["user", "user.rabl"].each do |rabl_option| | ||
it "should render rabl template (#{rabl_option})" do | ||
subject.get("/home", :rabl => rabl_option) do | ||
@user = OpenStruct.new(:name => "LTe", :email => "email@example.com") | ||
@project = OpenStruct.new(:name => "First") | ||
end | ||
|
||
get "/home" | ||
|
||
last_response.body.should == %Q{<?xml version="1.0" encoding="UTF-8"?>\n<user>\n <name>LTe</name>\n <email>email@example.com</email>\n <project>\n <name>First</name>\n </project>\n</user>\n} | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters