reps_client 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. data/.gitignore +8 -0
  2. data/.rspec +1 -0
  3. data/.rvmrc +2 -0
  4. data/Gemfile +4 -0
  5. data/README.md +62 -0
  6. data/Rakefile +14 -0
  7. data/lib/reps_client.rb +12 -0
  8. data/lib/reps_client/client.rb +95 -0
  9. data/lib/reps_client/community.rb +23 -0
  10. data/lib/reps_client/configuration.rb +83 -0
  11. data/lib/reps_client/errors.rb +36 -0
  12. data/lib/reps_client/lead.rb +291 -0
  13. data/lib/reps_client/pick_list.rb +62 -0
  14. data/lib/reps_client/version.rb +3 -0
  15. data/reps_client.gemspec +36 -0
  16. data/spec/fixtures/faults/client_fault.xml +28 -0
  17. data/spec/fixtures/faults/invalid_enterprise_key_fault.xml +25 -0
  18. data/spec/fixtures/faults/server_fault.xml +25 -0
  19. data/spec/fixtures/get_communities/multiple_communities.xml +59 -0
  20. data/spec/fixtures/get_communities/single_community.xml +54 -0
  21. data/spec/fixtures/get_pick_lists/full_pick_lists.xml +100 -0
  22. data/spec/fixtures/get_pick_lists/single_prefix.xml +70 -0
  23. data/spec/fixtures/get_pick_lists/single_relationship_type.xml +70 -0
  24. data/spec/fixtures/get_pick_lists/single_source.xml +71 -0
  25. data/spec/fixtures/get_pick_lists/single_suffix.xml +70 -0
  26. data/spec/reps_client/client_spec.rb +217 -0
  27. data/spec/reps_client/community_spec.rb +139 -0
  28. data/spec/reps_client/configuration_spec.rb +132 -0
  29. data/spec/reps_client/errors_spec.rb +56 -0
  30. data/spec/reps_client/lead_spec.rb +906 -0
  31. data/spec/reps_client/pick_list_spec.rb +320 -0
  32. data/spec/reps_client_spec.rb +11 -0
  33. data/spec/spec_helper.rb +21 -0
  34. data/spec/support/fault_handler_shared_examples.rb +51 -0
  35. data/spec/support/lead_shared_examples.rb +33 -0
  36. data/spec/support/pick_list_shared_examples.rb +16 -0
  37. metadata +259 -0
@@ -0,0 +1,70 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
3
+ <soap:Header>
4
+ <wsa:Action>http://www.mdiachieve.com/GetPickListsResponse</wsa:Action>
5
+ <wsa:MessageID>urn:uuid:cb9bfa9e-1ccf-4cbd-bcee-d6ede6c33356</wsa:MessageID>
6
+ <wsa:RelatesTo>urn:uuid:30678ac1-b23c-4088-9688-4491f438f51a</wsa:RelatesTo>
7
+ <wsa:To>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:To>
8
+ <wsse:Security>
9
+ <wsu:Timestamp wsu:Id="Timestamp-c78ed006-c873-4052-8a40-672f10840366">
10
+ <wsu:Created>2011-10-10T05:06:08Z</wsu:Created>
11
+ <wsu:Expires>2011-10-10T05:11:08Z</wsu:Expires>
12
+ </wsu:Timestamp>
13
+ </wsse:Security>
14
+ </soap:Header>
15
+ <soap:Body>
16
+ <GetPickListsResponse xmlns="http://www.mdiachieve.com/">
17
+ <GetPickListsResult>
18
+ <xs:schema xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="PickLists">
19
+ <xs:element name="PickLists" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
20
+ <xs:complexType>
21
+ <xs:choice minOccurs="0" maxOccurs="unbounded">
22
+ <xs:element name="Prefix" msdata:CaseSensitive="False" msdata:Locale="en-US">
23
+ <xs:complexType>
24
+ <xs:sequence>
25
+ <xs:element name="UserListIDY" type="xs:int" minOccurs="0"/>
26
+ <xs:element name="ListValue" type="xs:string" minOccurs="0"/>
27
+ </xs:sequence>
28
+ </xs:complexType>
29
+ </xs:element>
30
+ <xs:element name="Suffix" msdata:CaseSensitive="False" msdata:Locale="en-US">
31
+ <xs:complexType>
32
+ <xs:sequence>
33
+ <xs:element name="UserListIDY" type="xs:int" minOccurs="0"/>
34
+ <xs:element name="ListValue" type="xs:string" minOccurs="0"/>
35
+ </xs:sequence>
36
+ </xs:complexType>
37
+ </xs:element>
38
+ <xs:element name="RelationshipType" msdata:CaseSensitive="False" msdata:Locale="en-US">
39
+ <xs:complexType>
40
+ <xs:sequence>
41
+ <xs:element name="RelationshipTypeIDY" type="xs:int" minOccurs="0"/>
42
+ <xs:element name="RelationshipName" type="xs:string" minOccurs="0"/>
43
+ </xs:sequence>
44
+ </xs:complexType>
45
+ </xs:element>
46
+ <xs:element name="Source" msdata:CaseSensitive="False" msdata:Locale="en-US">
47
+ <xs:complexType>
48
+ <xs:sequence>
49
+ <xs:element name="SourceIDY" type="xs:int" minOccurs="0"/>
50
+ <xs:element name="Code" type="xs:string" minOccurs="0"/>
51
+ <xs:element name="Description" type="xs:string" minOccurs="0"/>
52
+ </xs:sequence>
53
+ </xs:complexType>
54
+ </xs:element>
55
+ </xs:choice>
56
+ </xs:complexType>
57
+ </xs:element>
58
+ </xs:schema>
59
+ <diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
60
+ <PickLists xmlns="">
61
+ <RelationshipType diffgr:id="RelationshipType1" msdata:rowOrder="0" diffgr:hasChanges="inserted">
62
+ <RelationshipTypeIDY>84</RelationshipTypeIDY>
63
+ <RelationshipName>Brother-in-law </RelationshipName>
64
+ </RelationshipType>
65
+ </PickLists>
66
+ </diffgr:diffgram>
67
+ </GetPickListsResult>
68
+ </GetPickListsResponse>
69
+ </soap:Body>
70
+ </soap:Envelope>
@@ -0,0 +1,71 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
3
+ <soap:Header>
4
+ <wsa:Action>http://www.mdiachieve.com/GetPickListsResponse</wsa:Action>
5
+ <wsa:MessageID>urn:uuid:cb9bfa9e-1ccf-4cbd-bcee-d6ede6c33356</wsa:MessageID>
6
+ <wsa:RelatesTo>urn:uuid:30678ac1-b23c-4088-9688-4491f438f51a</wsa:RelatesTo>
7
+ <wsa:To>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:To>
8
+ <wsse:Security>
9
+ <wsu:Timestamp wsu:Id="Timestamp-c78ed006-c873-4052-8a40-672f10840366">
10
+ <wsu:Created>2011-10-10T05:06:08Z</wsu:Created>
11
+ <wsu:Expires>2011-10-10T05:11:08Z</wsu:Expires>
12
+ </wsu:Timestamp>
13
+ </wsse:Security>
14
+ </soap:Header>
15
+ <soap:Body>
16
+ <GetPickListsResponse xmlns="http://www.mdiachieve.com/">
17
+ <GetPickListsResult>
18
+ <xs:schema xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="PickLists">
19
+ <xs:element name="PickLists" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
20
+ <xs:complexType>
21
+ <xs:choice minOccurs="0" maxOccurs="unbounded">
22
+ <xs:element name="Prefix" msdata:CaseSensitive="False" msdata:Locale="en-US">
23
+ <xs:complexType>
24
+ <xs:sequence>
25
+ <xs:element name="UserListIDY" type="xs:int" minOccurs="0"/>
26
+ <xs:element name="ListValue" type="xs:string" minOccurs="0"/>
27
+ </xs:sequence>
28
+ </xs:complexType>
29
+ </xs:element>
30
+ <xs:element name="Suffix" msdata:CaseSensitive="False" msdata:Locale="en-US">
31
+ <xs:complexType>
32
+ <xs:sequence>
33
+ <xs:element name="UserListIDY" type="xs:int" minOccurs="0"/>
34
+ <xs:element name="ListValue" type="xs:string" minOccurs="0"/>
35
+ </xs:sequence>
36
+ </xs:complexType>
37
+ </xs:element>
38
+ <xs:element name="RelationshipType" msdata:CaseSensitive="False" msdata:Locale="en-US">
39
+ <xs:complexType>
40
+ <xs:sequence>
41
+ <xs:element name="RelationshipTypeIDY" type="xs:int" minOccurs="0"/>
42
+ <xs:element name="RelationshipName" type="xs:string" minOccurs="0"/>
43
+ </xs:sequence>
44
+ </xs:complexType>
45
+ </xs:element>
46
+ <xs:element name="Source" msdata:CaseSensitive="False" msdata:Locale="en-US">
47
+ <xs:complexType>
48
+ <xs:sequence>
49
+ <xs:element name="SourceIDY" type="xs:int" minOccurs="0"/>
50
+ <xs:element name="Code" type="xs:string" minOccurs="0"/>
51
+ <xs:element name="Description" type="xs:string" minOccurs="0"/>
52
+ </xs:sequence>
53
+ </xs:complexType>
54
+ </xs:element>
55
+ </xs:choice>
56
+ </xs:complexType>
57
+ </xs:element>
58
+ </xs:schema>
59
+ <diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
60
+ <PickLists xmlns="">
61
+ <Source diffgr:id="Source1" msdata:rowOrder="0" diffgr:hasChanges="inserted">
62
+ <SourceIDY>321</SourceIDY>
63
+ <Code>YP104</Code>
64
+ <Description>Yellow Pages</Description>
65
+ </Source>
66
+ </PickLists>
67
+ </diffgr:diffgram>
68
+ </GetPickListsResult>
69
+ </GetPickListsResponse>
70
+ </soap:Body>
71
+ </soap:Envelope>
@@ -0,0 +1,70 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
3
+ <soap:Header>
4
+ <wsa:Action>http://www.mdiachieve.com/GetPickListsResponse</wsa:Action>
5
+ <wsa:MessageID>urn:uuid:cb9bfa9e-1ccf-4cbd-bcee-d6ede6c33356</wsa:MessageID>
6
+ <wsa:RelatesTo>urn:uuid:30678ac1-b23c-4088-9688-4491f438f51a</wsa:RelatesTo>
7
+ <wsa:To>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:To>
8
+ <wsse:Security>
9
+ <wsu:Timestamp wsu:Id="Timestamp-c78ed006-c873-4052-8a40-672f10840366">
10
+ <wsu:Created>2011-10-10T05:06:08Z</wsu:Created>
11
+ <wsu:Expires>2011-10-10T05:11:08Z</wsu:Expires>
12
+ </wsu:Timestamp>
13
+ </wsse:Security>
14
+ </soap:Header>
15
+ <soap:Body>
16
+ <GetPickListsResponse xmlns="http://www.mdiachieve.com/">
17
+ <GetPickListsResult>
18
+ <xs:schema xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="PickLists">
19
+ <xs:element name="PickLists" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
20
+ <xs:complexType>
21
+ <xs:choice minOccurs="0" maxOccurs="unbounded">
22
+ <xs:element name="Prefix" msdata:CaseSensitive="False" msdata:Locale="en-US">
23
+ <xs:complexType>
24
+ <xs:sequence>
25
+ <xs:element name="UserListIDY" type="xs:int" minOccurs="0"/>
26
+ <xs:element name="ListValue" type="xs:string" minOccurs="0"/>
27
+ </xs:sequence>
28
+ </xs:complexType>
29
+ </xs:element>
30
+ <xs:element name="Suffix" msdata:CaseSensitive="False" msdata:Locale="en-US">
31
+ <xs:complexType>
32
+ <xs:sequence>
33
+ <xs:element name="UserListIDY" type="xs:int" minOccurs="0"/>
34
+ <xs:element name="ListValue" type="xs:string" minOccurs="0"/>
35
+ </xs:sequence>
36
+ </xs:complexType>
37
+ </xs:element>
38
+ <xs:element name="RelationshipType" msdata:CaseSensitive="False" msdata:Locale="en-US">
39
+ <xs:complexType>
40
+ <xs:sequence>
41
+ <xs:element name="RelationshipTypeIDY" type="xs:int" minOccurs="0"/>
42
+ <xs:element name="RelationshipName" type="xs:string" minOccurs="0"/>
43
+ </xs:sequence>
44
+ </xs:complexType>
45
+ </xs:element>
46
+ <xs:element name="Source" msdata:CaseSensitive="False" msdata:Locale="en-US">
47
+ <xs:complexType>
48
+ <xs:sequence>
49
+ <xs:element name="SourceIDY" type="xs:int" minOccurs="0"/>
50
+ <xs:element name="Code" type="xs:string" minOccurs="0"/>
51
+ <xs:element name="Description" type="xs:string" minOccurs="0"/>
52
+ </xs:sequence>
53
+ </xs:complexType>
54
+ </xs:element>
55
+ </xs:choice>
56
+ </xs:complexType>
57
+ </xs:element>
58
+ </xs:schema>
59
+ <diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
60
+ <PickLists xmlns="">
61
+ <Suffix diffgr:id="Suffix1" msdata:rowOrder="0" diffgr:hasChanges="inserted">
62
+ <UserListIDY>56</UserListIDY>
63
+ <ListValue>D. Pharm.</ListValue>
64
+ </Suffix>
65
+ </PickLists>
66
+ </diffgr:diffgram>
67
+ </GetPickListsResult>
68
+ </GetPickListsResponse>
69
+ </soap:Body>
70
+ </soap:Envelope>
@@ -0,0 +1,217 @@
1
+ require 'spec_helper'
2
+
3
+ describe RepsClient::Client do
4
+ subject { client }
5
+
6
+ after { RepsClient.reset }
7
+
8
+ let(:client) { RepsClient::Client.new(options) }
9
+
10
+ let(:endpoint) { 'https://foo.com?wsdl' }
11
+ let(:username) { 'test_user' }
12
+ let(:password) { 'secret' }
13
+ let(:namespace) { 'http://foo.com/namespace' }
14
+ let(:enterprise_key) { 'enterprise_key' }
15
+ let(:options) do
16
+ {:endpoint => endpoint,
17
+ :username => username,
18
+ :password => password,
19
+ :namespace => namespace,
20
+ :enterprise_key => enterprise_key}
21
+ end
22
+
23
+ context 'with default configuration' do
24
+ let(:client) { RepsClient::Client.new }
25
+
26
+ its(:endpoint) { should == RepsClient::DEFAULT_ENDPOINT }
27
+ its(:namespace) { should == RepsClient::DEFAULT_NAMESPACE }
28
+ its(:username) { should be_nil }
29
+ its(:password) { should be_nil }
30
+ its(:enterprise_key) { should be_nil }
31
+ end
32
+
33
+ context 'with non-default configuration' do
34
+ its(:endpoint) { should == endpoint }
35
+ its(:namespace) { should == namespace }
36
+ its(:username) { should == username }
37
+ its(:password) { should == password }
38
+ its(:enterprise_key) { should == enterprise_key }
39
+
40
+ describe '#endpoint=' do
41
+ subject { client.endpoint = new_endpoint }
42
+
43
+ context 'with nil endpoint' do
44
+ let(:new_endpoint) { nil }
45
+
46
+ context 'when there is an endpoint configured at the top-level module' do
47
+ let(:configured_endpoint) { 'http://endpoint.from.config.com' }
48
+ before { RepsClient.configure { |config| config.endpoint = configured_endpoint } }
49
+
50
+ it 'should change the value of the endpoint to match the configuration' do
51
+ expect { subject }.to change { client.endpoint }.from(endpoint).to(configured_endpoint)
52
+ end
53
+ end
54
+
55
+ context 'when there is no endpoint configured at the top level' do
56
+ it 'should change the value of the endpoint to match the default' do
57
+ expect { subject }.to change { client.endpoint }.from(endpoint).to(RepsClient::DEFAULT_ENDPOINT)
58
+ end
59
+ end
60
+ end
61
+
62
+ context 'with new endpoint' do
63
+ let(:new_endpoint) { 'https://totally.new.com' }
64
+
65
+ it 'should change the value of the endpoint to match the new value' do
66
+ expect { subject }.to change { client.endpoint }.from(endpoint).to(new_endpoint)
67
+ end
68
+ end
69
+ end
70
+
71
+ describe '#namespace=' do
72
+ subject { client.namespace = new_namespace }
73
+
74
+ context 'with nil namespace' do
75
+ let(:new_namespace) { nil }
76
+
77
+ context 'when there is a namespace configured at the top-level module' do
78
+ let(:configured_namespace) { 'http://namespace.from.config.com' }
79
+ before { RepsClient.configure { |config| config.namespace = configured_namespace } }
80
+
81
+ it 'should change the value of the namespace to match the configuration' do
82
+ expect { subject }.to change { client.namespace }.from(namespace).to(configured_namespace)
83
+ end
84
+ end
85
+
86
+ context 'when there is no namespace configured at the top level' do
87
+ it 'should change the value of the namespace to match the default' do
88
+ expect { subject }.to change { client.namespace }.from(namespace).to(RepsClient::DEFAULT_NAMESPACE)
89
+ end
90
+ end
91
+ end
92
+
93
+ context 'with new namespace' do
94
+ let(:new_namespace) { 'https://totally.new.com' }
95
+
96
+ it 'should change the value of the namespace to match the new value' do
97
+ expect { subject }.to change { client.namespace }.from(namespace).to(new_namespace)
98
+ end
99
+ end
100
+ end
101
+
102
+ describe '#username=' do
103
+ subject { client.username = new_username }
104
+
105
+ context 'with nil username' do
106
+ let(:new_username) { nil }
107
+
108
+ context 'when there is a username configured at the top-level module' do
109
+ let(:configured_username) { 'configured user' }
110
+ before { RepsClient.configure { |config| config.username = configured_username } }
111
+
112
+ it 'should change the value of the username to match the configuration' do
113
+ expect { subject }.to change { client.username }.from(username).to(configured_username)
114
+ end
115
+ end
116
+
117
+ context 'when there is no username configured at the top level' do
118
+ it 'should change the value of the username to match the default' do
119
+ expect { subject }.to change { client.username }.from(username).to(nil)
120
+ end
121
+ end
122
+ end
123
+
124
+ context 'with new username' do
125
+ let(:new_username) { 'new user' }
126
+
127
+ it 'should change the value of the username to match the new value' do
128
+ expect { subject }.to change { client.username }.from(username).to(new_username)
129
+ end
130
+ end
131
+ end
132
+
133
+ describe '#password=' do
134
+ subject { client.password = new_password }
135
+
136
+ context 'with nil password' do
137
+ let(:new_password) { nil }
138
+
139
+ context 'when there is a password configured at the top-level module' do
140
+ let(:configured_password) { 'configured user' }
141
+ before { RepsClient.configure { |config| config.password = configured_password } }
142
+
143
+ it 'should change the value of the password to match the configuration' do
144
+ expect { subject }.to change { client.password }.from(password).to(configured_password)
145
+ end
146
+ end
147
+
148
+ context 'when there is no password configured at the top level' do
149
+ it 'should change the value of the password to match the default' do
150
+ expect { subject }.to change { client.password }.from(password).to(nil)
151
+ end
152
+ end
153
+ end
154
+
155
+ context 'with new password' do
156
+ let(:new_password) { 'new user' }
157
+
158
+ it 'should change the value of the password to match the new value' do
159
+ expect { subject }.to change { client.password }.from(password).to(new_password)
160
+ end
161
+ end
162
+ end
163
+
164
+ describe '#enterprise_key=' do
165
+ subject { client.enterprise_key = new_enterprise_key }
166
+
167
+ context 'with nil enterprise key' do
168
+ let(:new_enterprise_key) { nil }
169
+
170
+ context 'when there is an enterprise key configured at the top level' do
171
+ let(:configured_enterprise_key) { 'configured key' }
172
+ before { RepsClient.configure { |config| config.enterprise_key = configured_enterprise_key } }
173
+
174
+ it 'should change the value of the enterprise key to match the configuration' do
175
+ expect { subject }.to change { client.enterprise_key }.from(enterprise_key).to(configured_enterprise_key)
176
+ end
177
+ end
178
+
179
+ context 'when there is no enterprise key configured at the top level' do
180
+ it 'should reset the enterprise key' do
181
+ expect { subject }.to change { client.enterprise_key }.from(enterprise_key).to(nil)
182
+ end
183
+ end
184
+ end
185
+
186
+ context 'with new enterprise key' do
187
+ let(:new_enterprise_key) { 'new key' }
188
+
189
+ it 'should set the enterprise key' do
190
+ expect { subject }.to change { client.enterprise_key }.from(enterprise_key).to(new_enterprise_key)
191
+ end
192
+ end
193
+ end
194
+
195
+ describe '#soap_client' do
196
+ subject { client.soap_client }
197
+
198
+ it { should respond_to(:wsdl) }
199
+
200
+ describe 'wsdl' do
201
+ subject { client.soap_client.wsdl }
202
+
203
+ its(:endpoint) { should == endpoint }
204
+ its(:namespace) { should == namespace }
205
+ end
206
+
207
+ it { should respond_to(:http) }
208
+
209
+ describe 'wsse' do
210
+ subject { client.soap_client.wsse }
211
+
212
+ its(:username) { should == username }
213
+ its(:password) { should == password }
214
+ end
215
+ end
216
+ end
217
+ end
@@ -0,0 +1,139 @@
1
+ require 'spec_helper'
2
+
3
+ describe RepsClient::Community do
4
+ subject { community }
5
+
6
+ let(:community_id) { 42 }
7
+ let(:name) { 'Garbage Can Towers' }
8
+ let(:address1) { '123 Sesame St.' }
9
+ let(:address2) { 'Apt 1A' }
10
+ let(:city) { 'New York' }
11
+ let(:state) { 'NY' }
12
+ let(:zip) { '12345' }
13
+
14
+ context 'with default initialization' do
15
+ let(:community) { RepsClient::Community.new }
16
+
17
+ its(:community_id) { should be_nil }
18
+ its(:name) { should be_nil }
19
+ its(:address1) { should be_nil }
20
+ its(:address2) { should be_nil }
21
+ its(:city) { should be_nil }
22
+ its(:state) { should be_nil }
23
+ its(:zip) { should be_nil }
24
+ end
25
+
26
+ context 'with full snake_case initialization' do
27
+ let(:community) { RepsClient::Community.new(attributes) }
28
+ let(:attributes) do
29
+ {:community_id => community_id.to_s,
30
+ :name => name,
31
+ :address1 => address1,
32
+ :address2 => address2,
33
+ :city => city,
34
+ :state => state,
35
+ :zip => zip}
36
+ end
37
+
38
+ its(:community_id) { should == community_id }
39
+ its(:name) { should == name }
40
+ its(:address1) { should == address1 }
41
+ its(:address2) { should == address2 }
42
+ its(:city) { should == city }
43
+ its(:state) { should == state }
44
+ its(:zip) { should == zip }
45
+ end
46
+
47
+ context 'with properties requiring translation' do
48
+ let(:community) { RepsClient::Community.new(attributes) }
49
+ let(:attributes) do
50
+ {'community_idy' => community_id,
51
+ 'name' => name,
52
+ 'community_address1' => address1,
53
+ 'community_address2' => address2,
54
+ 'community_city' => city,
55
+ 'community_state' => state,
56
+ 'community_zip' => zip}
57
+ end
58
+
59
+ its(:community_id) { should == community_id.to_i }
60
+ its(:name) { should == name }
61
+ its(:address1) { should == address1 }
62
+ its(:address2) { should == address2 }
63
+ its(:city) { should == city }
64
+ its(:state) { should == state }
65
+ its(:zip) { should == zip }
66
+ end
67
+ end
68
+
69
+ describe 'community methods mixin' do
70
+ let(:test_object) { RepsClient::Client.new(:enterprise_key => enterprise_key) }
71
+ let(:enterprise_key) { 'foo' }
72
+
73
+ describe '#get_communities' do
74
+ subject { communities }
75
+ let(:communities) { test_object.get_communities }
76
+
77
+ context 'when there is one community' do
78
+ before { savon.stubs('GetCommunities').returns(:single_community) }
79
+
80
+ it 'should call the remote service with the correct enterprise key' do
81
+ savon.expects('GetCommunities').with(:enterprise_key => enterprise_key).returns(:single_community)
82
+ subject
83
+ end
84
+
85
+ it { should be }
86
+ it { should have(1).community }
87
+
88
+ describe 'the first community' do
89
+ subject { communities.first }
90
+
91
+ its(:community_id) { should == 2 }
92
+ its(:name) { should == 'Grouch Towers' }
93
+ its(:address1) { should == '123 Sesame St' }
94
+ its(:address2) { should be_nil }
95
+ its(:city) { should == 'New York' }
96
+ its(:state) { should == 'NY' }
97
+ its(:zip) { should == '12345' }
98
+ end
99
+ end
100
+
101
+ context 'when there are multiple communities' do
102
+ before { savon.stubs('GetCommunities').returns(:multiple_communities) }
103
+
104
+ it 'should call the remote service with the correct enterprise key' do
105
+ savon.expects('GetCommunities').with(:enterprise_key => enterprise_key).returns(:multiple_communities)
106
+ subject
107
+ end
108
+
109
+ it { should be }
110
+ it { should have(2).communities }
111
+
112
+ describe 'the first community' do
113
+ subject { communities.first }
114
+
115
+ its(:community_id) { should == 7 }
116
+ its(:name) { should == 'The Homestead at Babbling Brook' }
117
+ its(:address1) { should be_nil }
118
+ its(:address2) { should be_nil }
119
+ its(:city) { should be_nil }
120
+ its(:state) { should be_nil }
121
+ its(:zip) { should be_nil }
122
+ end
123
+
124
+ describe 'the last community' do
125
+ subject { communities.last }
126
+
127
+ its(:community_id) { should == 1 }
128
+ its(:name) { should == 'The Gardens at Countryside Meadows' }
129
+ its(:address1) { should == '999 Prairie View Ln' }
130
+ its(:address2) { should == 'Suite 42' }
131
+ its(:city) { should == 'Detroit' }
132
+ its(:state) { should == 'MI' }
133
+ its(:zip) { should == '11235' }
134
+ end
135
+ end
136
+
137
+ it_should_behave_like 'a fault handler', 'GetCommunities'
138
+ end
139
+ end