-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathgrape_rabl_xml_spec.rb
52 lines (44 loc) · 1.12 KB
/
grape_rabl_xml_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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 do
env['api.tilt.root'] = "#{File.dirname(__FILE__)}/views"
env['api.format'] = :xml
end
end
it 'should respond with proper content-type' do
subject.get('/home', rabl: 'user') {}
get('/home')
expect(last_response.headers['Content-Type']).to eq('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'
expect(last_response.body).to eq(%(<?xml version="1.0" encoding="UTF-8"?>
<user>
<name>LTe</name>
<email>email@example.com</email>
<project>
<name>First</name>
</project>
</user>
))
end
end
end
end