-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresource_wrapper_test.rb
More file actions
85 lines (70 loc) · 2.46 KB
/
resource_wrapper_test.rb
File metadata and controls
85 lines (70 loc) · 2.46 KB
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
# frozen_string_literal: true
require 'test_helper'
require 'sapi_client'
class CommonResource
def initialize(_ignored); end
end
class WombleResource < CommonResource
end
module SapiClient
class ResourceWrapperTest < Minitest::Test
describe 'ResourceWrapper' do
describe '#de_uri' do
it 'should convert a URI string to a symbol' do
_(ResourceWrapper.de_uri('http://wimbledon.com/womble')).must_equal(:womble)
end
it 'should convert a non-symbol to symbol' do
_(ResourceWrapper.de_uri('womble')).must_equal(:womble)
end
it 'should not change an existing symbol' do
_(ResourceWrapper.de_uri(:womble)).must_equal(:womble)
end
end
describe('#wrapper_class_constant') do
it 'should find a class constant if it exists' do
_(ResourceWrapper.wrapper_class_constant(:WombleResource)).must_equal(WombleResource)
end
it 'should return nil if no class constant exists' do
_(ResourceWrapper.wrapper_class_constant(:Wimbledon)).must_be_nil
end
end
describe('#find_wrapper_type') do
it 'should find the first matching wrapper type' do
_(
ResourceWrapper
.find_wrapper_type(%i[Wimbledon WombleResource Array])
).must_equal(WombleResource)
end
it 'should find the most specific matching wrapper type' do
_(
ResourceWrapper
.find_wrapper_type(%i[CommonResource Wimbledon WombleResource Array])
).must_equal(WombleResource)
end
it 'should return nil if a wrapper cannot be found' do
_(
ResourceWrapper
.find_wrapper_type([:Wimbledon])
).must_equal(SapiClient::SapiResource)
end
end
end
describe('#wrap_resource') do
it 'should use the explicit wrapper if given' do
_(
ResourceWrapper
.wrap_resource(nil, wrapper: :WombleResource)
).must_be_kind_of(WombleResource)
_(
ResourceWrapper
.wrap_resource(nil, wrapper: 'http://wimbledon.com/WombleResource')
).must_be_kind_of(WombleResource)
end
it 'should use the resource types method if defined' do
resource = mock('resource')
resource.expects(:types).returns(['http://wimbledon.com/WombleResource'])
_(ResourceWrapper.wrap_resource(resource)).must_be_kind_of(WombleResource)
end
end
end
end