/
format_test.rb
109 lines (87 loc) · 2.11 KB
/
format_test.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
require 'test_helper'
describe Lotus::Action do
class FormatController
include Lotus::Controller
action 'Default' do
def call(params)
end
end
action 'Custom' do
def call(params)
self.format = params[:format]
end
end
end
before do
@mime = ::Rack::Mime::MIME_TYPES
end
describe '#format' do
before do
@action = FormatController::Default.new
end
it 'lookup to #content_type if was not explicitly set (default: application/octet-stream)' do
@action.call({})
@action.send(:format).must_equal :a
end
end
describe '#format=' do
before do
@action = FormatController::Custom.new
end
describe 'html' do
before do
@action.call({ format: :html })
end
it 'sets format' do
@action.send(:format).must_equal :html
end
it 'sets content-type' do
@action.send(:content_type).must_equal 'text/html'
end
end
describe 'json' do
before do
@action.call({ format: :json })
end
it 'sets format' do
@action.send(:format).must_equal :json
end
it 'sets content-type' do
@action.send(:content_type).must_equal 'application/json'
end
end
describe 'json' do
before do
@action.call({ format: :xml })
end
it 'sets format' do
@action.send(:format).must_equal :xml
end
it 'sets content-type' do
@action.send(:content_type).must_equal 'application/xml'
end
end
describe 'atom' do
before do
@action.call({ format: :atom })
end
it 'sets format' do
@action.send(:format).must_equal :atom
end
it 'sets content-type' do
@action.send(:content_type).must_equal 'application/atom+xml'
end
end
describe 'js' do
before do
@action.call({ format: :js })
end
it 'sets format' do
@action.send(:format).must_equal :js
end
it 'sets content-type' do
@action.send(:content_type).must_equal 'application/javascript'
end
end
end
end