/
configuration_test.rb
55 lines (46 loc) · 1.5 KB
/
configuration_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
require File.expand_path('../teststrap', __FILE__)
context 'Rabl::Configuration' do
context 'defaults' do
# multi_json compatibility TODO
helper(:json_engine) { MultiJson.respond_to?(:adapter) ? MultiJson.adapter : MultiJson.engine }
setup { Rabl.configuration }
asserts(:include_json_root).equals true
asserts(:include_child_root).equals true
asserts(:include_xml_root).equals false
asserts(:enable_json_callbacks).equals false
asserts(:view_paths).equals []
asserts(:json_engine).equals { json_engine }
asserts(:cache_engine).is_a?(Rabl::CacheEngine)
end
context 'custom JSON engine configured as Symbol' do
setup do
Rabl.configure do |c|
c.json_engine = :oj
end
end
asserts('uses a custom JSON engine') { topic.json_engine.to_s =~ /oj/i }
end # custom json, symbol
context 'custom JSON engine configured as Class' do
setup do
Rabl.configure do |c|
c.json_engine = ActiveSupport::JSON
end
end
asserts('uses a custom JSON engine') { topic.json_engine.to_s == 'ActiveSupport::JSON' }
end # custom JSON, class
context 'invalid JSON engine configured' do
asserts {
Rabl.configure do |c|
c.json_engine = Kernel
end
}.raises(RuntimeError)
end # invalid
context 'raise on missing attributes' do
setup do
Rabl.configure do |c|
c.raise_on_missing_attribute = true
end
end
asserts(:raise_on_missing_attribute).equals true
end # raise on missing
end