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,320 @@
1
+ require 'spec_helper'
2
+
3
+ describe RepsClient::Prefix do
4
+ subject { prefix }
5
+
6
+ let(:user_list_id) { 42 }
7
+ let(:list_value) { 'Dr. and Mr.' }
8
+
9
+ context 'with default initialization' do
10
+ let(:prefix) { RepsClient::Prefix.new }
11
+
12
+ its(:prefix_id) { should be_nil }
13
+ its(:value) { should be_nil }
14
+ end
15
+
16
+ context 'with full initialization' do
17
+ let(:prefix) do
18
+ RepsClient::Prefix.new(:prefix_id => user_list_id.to_s,
19
+ :value => list_value)
20
+ end
21
+
22
+ its(:prefix_id) { should == user_list_id }
23
+ its(:value) { should == list_value }
24
+ end
25
+
26
+ context 'with translation initialization' do
27
+ let(:prefix) do
28
+ RepsClient::Prefix.new(:user_list_idy => user_list_id,
29
+ :list_value => " #{list_value} ")
30
+ end
31
+
32
+ its(:prefix_id) { should == user_list_id }
33
+ its(:value) { should == list_value }
34
+ end
35
+ end
36
+
37
+ describe RepsClient::Suffix do
38
+ subject { suffix }
39
+
40
+ let(:user_list_id) { 42 }
41
+ let(:list_value) { 'D.D.S.' }
42
+
43
+ context 'with default initialization' do
44
+ let(:suffix) { RepsClient::Suffix.new }
45
+
46
+ its(:suffix_id) { should be_nil }
47
+ its(:value) { should be_nil }
48
+ end
49
+
50
+ context 'with full initialization' do
51
+ let(:suffix) do
52
+ RepsClient::Suffix.new(:suffix_id => user_list_id.to_s,
53
+ :value => list_value)
54
+ end
55
+
56
+ its(:suffix_id) { should == user_list_id }
57
+ its(:value) { should == list_value }
58
+ end
59
+
60
+ context 'with translation initialization' do
61
+ let(:suffix) do
62
+ RepsClient::Suffix.new(:user_list_idy => user_list_id,
63
+ :list_value => " #{list_value} ")
64
+ end
65
+
66
+ its(:suffix_id) { should == user_list_id }
67
+ its(:value) { should == list_value }
68
+ end
69
+ end
70
+
71
+ describe RepsClient::RelationshipType do
72
+ subject { relationship_type }
73
+
74
+ let(:relationship_type_id) { 42 }
75
+ let(:relationship_name) { 'Dr. and Mr.' }
76
+
77
+ context 'with default initialization' do
78
+ let(:relationship_type) { RepsClient::RelationshipType.new }
79
+
80
+ its(:relationship_type_id) { should be_nil }
81
+ its(:name) { should be_nil }
82
+ end
83
+
84
+ context 'with full initialization' do
85
+ let(:relationship_type) do
86
+ RepsClient::RelationshipType.new(:relationship_type_id => relationship_type_id.to_s,
87
+ :name => relationship_name)
88
+ end
89
+
90
+ its(:relationship_type_id) { should == relationship_type_id }
91
+ its(:name) { should == relationship_name }
92
+ end
93
+
94
+ context 'with translation initialization' do
95
+ let(:relationship_type) do
96
+ RepsClient::RelationshipType.new(:relationship_type_idy => relationship_type_id,
97
+ :relationship_name => " #{relationship_name} ")
98
+ end
99
+
100
+ its(:relationship_type_id) { should == relationship_type_id }
101
+ its(:name) { should == relationship_name }
102
+ end
103
+ end
104
+
105
+ describe RepsClient::Source do
106
+ subject { source }
107
+
108
+ let(:source_id) { 42 }
109
+ let(:code) { 'CGSLST' }
110
+ let(:description) { 'Craigslist ad' }
111
+
112
+ context 'with default initialization' do
113
+ let(:source) { RepsClient::Source.new }
114
+
115
+ its(:source_id) { should be_nil }
116
+ its(:code) { should be_nil }
117
+ its(:description) { should be_nil }
118
+ end
119
+
120
+ context 'with full initialization' do
121
+ let(:source) do
122
+ RepsClient::Source.new(:source_id => source_id.to_s,
123
+ :code => code,
124
+ :description => description)
125
+ end
126
+
127
+ its(:source_id) { should == source_id }
128
+ its(:code) { should == code }
129
+ its(:description) { should == description }
130
+ end
131
+
132
+ context 'with translation initialization' do
133
+ let(:source) do
134
+ RepsClient::Source.new(:source_idy => source_id,
135
+ :code => " #{code} ",
136
+ :description => " #{description}\n")
137
+ end
138
+
139
+ its(:source_id) { should == source_id }
140
+ its(:code) { should == code }
141
+ its(:description) { should == description }
142
+ end
143
+ end
144
+
145
+ describe 'pick list methods mixin' do
146
+ let(:test_object) { RepsClient::Client.new(:enterprise_key => enterprise_key) }
147
+ let(:enterprise_key) { 'foo' }
148
+
149
+ describe "#get_pick_lists" do
150
+ subject { pick_lists }
151
+ let(:pick_lists) { test_object.get_pick_lists(community_id) }
152
+
153
+ before { savon.stubs('GetPickLists').returns(fixture_name) }
154
+ let(:fixture_name) { nil }
155
+
156
+ context 'with a community id' do
157
+ let(:community_id) { 42 }
158
+
159
+ it_should_behave_like 'a fault handler', 'GetPickLists'
160
+
161
+ context 'when there is one prefix' do
162
+ let(:fixture_name) { :single_prefix }
163
+
164
+ it_should_behave_like 'a pick list requester'
165
+
166
+ its([:suffix]) { should be_empty }
167
+ its([:relationship_type]) { should be_empty }
168
+ its([:source]) { should be_empty }
169
+ its([:prefix]) { should have(1).prefix }
170
+
171
+ describe "the first prefix entry" do
172
+ subject { pick_lists[:prefix].first }
173
+
174
+ its(:prefix_id) { should == 210 }
175
+ its(:value) { should == 'Attorney' }
176
+ end
177
+ end
178
+
179
+ context 'when there is one suffix' do
180
+ let(:fixture_name) { :single_suffix }
181
+
182
+ it_should_behave_like 'a pick list requester'
183
+
184
+ its([:prefix]) { should be_empty }
185
+ its([:relationship_type]) { should be_empty }
186
+ its([:source]) { should be_empty }
187
+ its([:suffix]) { should have(1).suffix }
188
+
189
+ describe "the first suffix entry" do
190
+ subject { pick_lists[:suffix].first }
191
+
192
+ its(:suffix_id) { should == 56 }
193
+ its(:value) { should == 'D. Pharm.' }
194
+ end
195
+ end
196
+
197
+ context 'when there is one relationship_type' do
198
+ let(:fixture_name) { :single_relationship_type }
199
+
200
+ it_should_behave_like 'a pick list requester'
201
+
202
+ its([:suffix]) { should be_empty }
203
+ its([:prefix]) { should be_empty }
204
+ its([:source]) { should be_empty }
205
+ its([:relationship_type]) { should have(1).entry }
206
+
207
+ describe "the first relationship_type entry" do
208
+ subject { pick_lists[:relationship_type].first }
209
+
210
+ its(:relationship_type_id) { should == 84 }
211
+ its(:name) { should == 'Brother-in-law' }
212
+ end
213
+ end
214
+
215
+ context 'when there is a single source' do
216
+ let(:fixture_name) { :single_source }
217
+
218
+ it_should_behave_like 'a pick list requester'
219
+
220
+ its([:suffix]) { should be_empty }
221
+ its([:relationship_type]) { should be_empty }
222
+ its([:prefix]) { should be_empty }
223
+ its([:source]) { should have(1).entry }
224
+
225
+ describe "the first source entry" do
226
+ subject { pick_lists[:source].first }
227
+
228
+ its(:source_id) { should == 321 }
229
+ its(:code) { should == 'YP104' }
230
+ its(:description) { should == 'Yellow Pages' }
231
+ end
232
+ end
233
+
234
+ context 'when there are multiple types of pick lists' do
235
+ let(:fixture_name) { :full_pick_lists }
236
+
237
+ it_should_behave_like 'a pick list requester'
238
+
239
+ its([:prefix]) { should have(2).entries }
240
+
241
+ describe 'the first prefix entry' do
242
+ subject { pick_lists[:prefix].first }
243
+
244
+ its(:prefix_id) { should == 222 }
245
+ its(:value) { should == 'Dr. And Mrs.' }
246
+ end
247
+
248
+ describe 'the last prefix entry' do
249
+ subject { pick_lists[:prefix].last }
250
+
251
+ its(:prefix_id) { should == 202 }
252
+ its(:value) { should == 'Mr. & Mrs.' }
253
+ end
254
+
255
+ its([:suffix]) { should have(2).entries }
256
+
257
+ describe 'the first suffix entry' do
258
+ subject { pick_lists[:suffix].first }
259
+
260
+ its(:suffix_id) { should == 90 }
261
+ its(:value) { should == 'III' }
262
+ end
263
+
264
+ describe 'the last suffix entry' do
265
+ subject { pick_lists[:suffix].last }
266
+
267
+ its(:suffix_id) { should == 36 }
268
+ its(:value) { should == 'Jr.' }
269
+ end
270
+
271
+ its([:relationship_type]) { should have(2).entries }
272
+
273
+ describe 'the first relationship_type entry' do
274
+ subject { pick_lists[:relationship_type].first }
275
+
276
+ its(:relationship_type_id) { should == 82 }
277
+ its(:name) { should == 'Aunt' }
278
+ end
279
+
280
+ describe 'the last relationship_type entry' do
281
+ subject { pick_lists[:relationship_type].last }
282
+
283
+ its(:relationship_type_id) { should == 91 }
284
+ its(:name) { should == 'Not specified' }
285
+ end
286
+
287
+ its([:source]) { should have(2).entries }
288
+
289
+ describe 'the first source entry' do
290
+ subject { pick_lists[:source].first }
291
+
292
+ its(:source_id) { should == 251 }
293
+ its(:code) { should == 'DM' }
294
+ its(:description) { should == 'Direct Mail' }
295
+ end
296
+
297
+ describe 'the last source entry' do
298
+ subject { pick_lists[:source].last }
299
+
300
+ its(:source_id) { should == 713 }
301
+ its(:code) { should == 'Press & Sun Bulletin' }
302
+ its(:description) { should == 'Pleasant Surprises' }
303
+ end
304
+ end
305
+ end
306
+
307
+ context 'without a community id' do
308
+ let(:community_id) { nil }
309
+
310
+ it 'should not call the remote service' do
311
+ savon.expects(:get_pick_lists).never
312
+ subject rescue nil
313
+ end
314
+
315
+ it 'should raise an ArgumentError' do
316
+ expect { subject }.to raise_error
317
+ end
318
+ end
319
+ end
320
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe RepsClient do
4
+ it "should have a version" do
5
+ subject::VERSION.should be
6
+ end
7
+
8
+ it { should respond_to(:configure) }
9
+ it { should respond_to(:reset) }
10
+ it { should respond_to(:options) }
11
+ end
@@ -0,0 +1,21 @@
1
+ require 'rspec'
2
+
3
+ require 'webmock/rspec'
4
+ require 'fakefs/spec_helpers'
5
+ require 'savon_spec'
6
+
7
+ Dir[File.join(File.dirname(__FILE__), 'support', '*.rb')].each { |f| require f }
8
+
9
+ Savon::Spec::Fixture.path = File.expand_path("../fixtures", __FILE__)
10
+ Savon.configure do |config|
11
+ config.log = false
12
+ end
13
+
14
+ RSpec.configure do |config|
15
+ config.include FakeFS::SpecHelpers
16
+
17
+ config.include Savon::Spec::Macros
18
+ config.before { FakeFS::FileSystem.clone(File.expand_path('../fixtures', __FILE__)) }
19
+ end
20
+
21
+ require 'reps_client'
@@ -0,0 +1,51 @@
1
+ shared_examples_for 'a fault handler' do |soap_action|
2
+ before { savon.stubs(soap_action).raises_soap_fault.returns(Savon::Spec::Fixture[:faults, fault_type]) }
3
+
4
+ context 'when there is an invalid enterprise key fault' do
5
+ let(:fault_type) { :invalid_enterprise_key_fault }
6
+
7
+ it 'should raise a RepsClient invalid enterprise key error' do
8
+ expect { subject }.to raise_error(RepsClient::InvalidEnterpriseKeyError)
9
+ end
10
+
11
+ it 'should include the faultstring in the error object' do
12
+ expect { subject }.to raise_error { |e| e.message.should =~ /^System\.Web\.Services\.Protocols\.SoapException: Invalid Enterprise Key/ }
13
+ end
14
+
15
+ it 'should include the faultcode in the error object' do
16
+ expect { subject }.to raise_error { |e| e.code.should == 'InvalidEnterpriseKey' }
17
+ end
18
+ end
19
+
20
+ context 'when there is a client fault' do
21
+ let(:fault_type) { :client_fault }
22
+
23
+ it 'should raise a RepsClient service error' do
24
+ expect { subject }.to raise_error(RepsClient::ServiceError)
25
+ end
26
+
27
+ it 'should include the faultstring in the error object' do
28
+ expect { subject }.to raise_error { |e| e.message.should =~ /^System\.Web\.Services\.Protocols\.SoapException: Server did not recognize the value of HTTP Header SOAPAction/ }
29
+ end
30
+
31
+ it 'should include the faultcode in the error object' do
32
+ expect { subject }.to raise_error { |e| e.code.should == 'soap:Client' }
33
+ end
34
+ end
35
+
36
+ context 'when there is a server fault' do
37
+ let(:fault_type) { :server_fault }
38
+
39
+ it 'should raise a RepsClient service error' do
40
+ expect { subject }.to raise_error(RepsClient::ServiceError)
41
+ end
42
+
43
+ it 'should include the faultstring in the error object' do
44
+ expect { subject }.to raise_error { |e| e.message.should =~ /^System\.Web\.Services\.Protocols\.SoapException: Server was unable to process request/ }
45
+ end
46
+
47
+ it 'should include the faultcode in the error object' do
48
+ expect { subject }.to raise_error { |e| e.code.should == 'soap:Server' }
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,33 @@
1
+ shared_examples_for 'a contact attribute validator' do |attr_name|
2
+ it { should_not be_valid }
3
+
4
+ describe '#validate' do
5
+ subject { contact.validate }
6
+
7
+ it { should have_key(attr_name) }
8
+
9
+ describe "the errors on #{attr_name}" do
10
+ subject { contact.validate[attr_name] }
11
+
12
+ it { should have(1).error }
13
+ its(:first) { should be_an ArgumentError }
14
+ end
15
+ end
16
+ end
17
+
18
+ shared_examples_for 'a prospect attribute validator' do |attr_name|
19
+ it { should_not be_valid }
20
+
21
+ describe '#validate' do
22
+ subject { prospect.validate }
23
+
24
+ it { should have_key(attr_name) }
25
+
26
+ describe "the errors on #{attr_name}" do
27
+ subject { prospect.validate[attr_name] }
28
+
29
+ it { should have(1).error }
30
+ its(:first) { should be_an ArgumentError }
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,16 @@
1
+ shared_examples_for 'a pick list requester' do
2
+ it 'should include the enterprise key when requesting pick lists from the remote service' do
3
+ savon.expects('GetPickLists').with(has_entry(:enterprise_key => enterprise_key)).returns(fixture_name)
4
+ subject
5
+ end
6
+
7
+ it 'should include the community id when requesting pick lists from the remote service' do
8
+ savon.expects('GetPickLists').with(has_entry(:community_id => community_id)).returns(fixture_name)
9
+ subject
10
+ end
11
+
12
+ it 'should order the parameters correctly when requesting pick lists from the remote service' do
13
+ savon.expects('GetPickLists').with(has_entry(:order! => [:enterprise_key,:community_id])).returns(fixture_name)
14
+ subject
15
+ end
16
+ end