reps_client 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +8 -0
- data/.rspec +1 -0
- data/.rvmrc +2 -0
- data/Gemfile +4 -0
- data/README.md +62 -0
- data/Rakefile +14 -0
- data/lib/reps_client.rb +12 -0
- data/lib/reps_client/client.rb +95 -0
- data/lib/reps_client/community.rb +23 -0
- data/lib/reps_client/configuration.rb +83 -0
- data/lib/reps_client/errors.rb +36 -0
- data/lib/reps_client/lead.rb +291 -0
- data/lib/reps_client/pick_list.rb +62 -0
- data/lib/reps_client/version.rb +3 -0
- data/reps_client.gemspec +36 -0
- data/spec/fixtures/faults/client_fault.xml +28 -0
- data/spec/fixtures/faults/invalid_enterprise_key_fault.xml +25 -0
- data/spec/fixtures/faults/server_fault.xml +25 -0
- data/spec/fixtures/get_communities/multiple_communities.xml +59 -0
- data/spec/fixtures/get_communities/single_community.xml +54 -0
- data/spec/fixtures/get_pick_lists/full_pick_lists.xml +100 -0
- data/spec/fixtures/get_pick_lists/single_prefix.xml +70 -0
- data/spec/fixtures/get_pick_lists/single_relationship_type.xml +70 -0
- data/spec/fixtures/get_pick_lists/single_source.xml +71 -0
- data/spec/fixtures/get_pick_lists/single_suffix.xml +70 -0
- data/spec/reps_client/client_spec.rb +217 -0
- data/spec/reps_client/community_spec.rb +139 -0
- data/spec/reps_client/configuration_spec.rb +132 -0
- data/spec/reps_client/errors_spec.rb +56 -0
- data/spec/reps_client/lead_spec.rb +906 -0
- data/spec/reps_client/pick_list_spec.rb +320 -0
- data/spec/reps_client_spec.rb +11 -0
- data/spec/spec_helper.rb +21 -0
- data/spec/support/fault_handler_shared_examples.rb +51 -0
- data/spec/support/lead_shared_examples.rb +33 -0
- data/spec/support/pick_list_shared_examples.rb +16 -0
- metadata +259 -0
@@ -0,0 +1,132 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RepsClient::Configuration do
|
4
|
+
let(:test_module) do
|
5
|
+
module TestModule
|
6
|
+
extend RepsClient::Configuration
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
subject { test_module }
|
11
|
+
|
12
|
+
let(:endpoint) { 'http://configured.endpoint.com' }
|
13
|
+
let(:username) { 'configured user' }
|
14
|
+
let(:password) { 'configured password' }
|
15
|
+
let(:namespace) { 'http://configured.namespace.com' }
|
16
|
+
let(:enterprise_key) { 'my_enterprise_key' }
|
17
|
+
|
18
|
+
after { test_module.reset }
|
19
|
+
|
20
|
+
it { should respond_to(:configure) }
|
21
|
+
|
22
|
+
context 'with default configuration' do
|
23
|
+
its(:endpoint) { should == RepsClient::DEFAULT_ENDPOINT }
|
24
|
+
its(:namespace) { should == RepsClient::DEFAULT_NAMESPACE }
|
25
|
+
its(:username) { should_not be }
|
26
|
+
its(:password) { should_not be }
|
27
|
+
its(:enterprise_key) { should_not be }
|
28
|
+
end
|
29
|
+
|
30
|
+
describe '.configure' do
|
31
|
+
subject { test_module.configure(&config_block) }
|
32
|
+
|
33
|
+
context 'with full configuration' do
|
34
|
+
let(:config_block) do
|
35
|
+
lambda do |config|
|
36
|
+
config.endpoint = endpoint
|
37
|
+
config.username = username
|
38
|
+
config.password = password
|
39
|
+
config.namespace = namespace
|
40
|
+
config.enterprise_key = enterprise_key
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
it { should == test_module }
|
45
|
+
|
46
|
+
its(:endpoint) { should == endpoint }
|
47
|
+
its(:username) { should == username }
|
48
|
+
its(:password) { should == password }
|
49
|
+
its(:namespace) { should == namespace }
|
50
|
+
its(:enterprise_key) { should == enterprise_key }
|
51
|
+
end
|
52
|
+
|
53
|
+
context 'with partial configuration' do
|
54
|
+
let(:config_block) do
|
55
|
+
lambda do |config|
|
56
|
+
config.username = username
|
57
|
+
config.password = password
|
58
|
+
config.enterprise_key = enterprise_key
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
it { should == test_module }
|
63
|
+
|
64
|
+
its(:endpoint) { should == RepsClient::DEFAULT_ENDPOINT }
|
65
|
+
its(:namespace) { should == RepsClient::DEFAULT_NAMESPACE }
|
66
|
+
its(:username) { should == username }
|
67
|
+
its(:password) { should == password }
|
68
|
+
its(:enterprise_key) { should == enterprise_key }
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
it { should respond_to(:reset) }
|
73
|
+
|
74
|
+
describe '.reset' do
|
75
|
+
before do
|
76
|
+
test_module.configure do |config|
|
77
|
+
config.endpoint = endpoint
|
78
|
+
config.username = username
|
79
|
+
config.password = password
|
80
|
+
config.namespace = namespace
|
81
|
+
config.enterprise_key = enterprise_key
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
subject { test_module.reset }
|
86
|
+
|
87
|
+
it 'should change the endpoint to the default value' do
|
88
|
+
expect { subject }.to change { test_module.endpoint }.from(endpoint).to(RepsClient::DEFAULT_ENDPOINT)
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'should change the namespace to the default value' do
|
92
|
+
expect { subject }.to change { test_module.namespace }.from(namespace).to(RepsClient::DEFAULT_NAMESPACE)
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'should clear the username' do
|
96
|
+
expect { subject }.to change { test_module.username }.from(username).to(nil)
|
97
|
+
end
|
98
|
+
|
99
|
+
it 'should clear the password' do
|
100
|
+
expect { subject }.to change { test_module.password }.from(password).to(nil)
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'should clear the enterprise key' do
|
104
|
+
expect { subject }.to change { test_module.enterprise_key }.from(enterprise_key).to(nil)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
describe '.options' do
|
109
|
+
before do
|
110
|
+
test_module.configure do |config|
|
111
|
+
config.endpoint = endpoint
|
112
|
+
config.username = username
|
113
|
+
config.password = password
|
114
|
+
config.namespace = namespace
|
115
|
+
config.enterprise_key = enterprise_key
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
subject { test_module.options }
|
120
|
+
|
121
|
+
it { should have_key(:endpoint) }
|
122
|
+
its([:endpoint]) { should == endpoint }
|
123
|
+
it { should have_key(:namespace) }
|
124
|
+
its([:namespace]) { should == namespace }
|
125
|
+
it { should have_key(:username) }
|
126
|
+
its([:username]) { should == username }
|
127
|
+
it { should have_key(:password) }
|
128
|
+
its([:password]) { should == password }
|
129
|
+
it { should have_key(:enterprise_key) }
|
130
|
+
its([:enterprise_key]) { should == enterprise_key }
|
131
|
+
end
|
132
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RepsClient::ServiceError do
|
4
|
+
subject { error }
|
5
|
+
let(:error) { RepsClient::ServiceError.new(message, code) }
|
6
|
+
let(:code) { 'my code' }
|
7
|
+
let(:message) { 'my message' }
|
8
|
+
|
9
|
+
context 'default initialization' do
|
10
|
+
let(:error) { RepsClient::ServiceError.new }
|
11
|
+
|
12
|
+
its(:code) { should be_nil }
|
13
|
+
its(:message) { should == error.class.name }
|
14
|
+
end
|
15
|
+
|
16
|
+
context 'with message' do
|
17
|
+
let(:error) { RepsClient::ServiceError.new(message) }
|
18
|
+
|
19
|
+
its(:code) { should be_nil }
|
20
|
+
its(:message) { should == message }
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'full initialization' do
|
24
|
+
its(:code) { should == code }
|
25
|
+
its(:message) { should == message }
|
26
|
+
end
|
27
|
+
|
28
|
+
describe ".translate_fault" do
|
29
|
+
subject { RepsClient::ServiceError.translate_fault(fault) }
|
30
|
+
let(:fault) { Savon::SOAP::Fault.new(response) }
|
31
|
+
let(:response) { mock(:body => Savon::Spec::Fixture[:faults, fault_type]) }
|
32
|
+
|
33
|
+
context 'with an invalid enterprise key fault' do
|
34
|
+
let(:fault_type) { :invalid_enterprise_key_fault }
|
35
|
+
|
36
|
+
it { should be_a RepsClient::InvalidEnterpriseKeyError }
|
37
|
+
its(:code) { should == fault.to_hash[:fault][:faultcode] }
|
38
|
+
its(:message) { should == fault.to_hash[:fault][:faultstring] }
|
39
|
+
end
|
40
|
+
|
41
|
+
context 'with a soap client fault' do
|
42
|
+
let(:fault_type) { :client_fault }
|
43
|
+
|
44
|
+
it { should be_a RepsClient::ServiceError }
|
45
|
+
it { should_not be_a RepsClient::InvalidEnterpriseKeyError }
|
46
|
+
its(:code) { should == fault.to_hash[:fault][:faultcode] }
|
47
|
+
its(:message) { should == fault.to_hash[:fault][:faultstring] }
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe RepsClient::InvalidEnterpriseKeyError do
|
53
|
+
subject { RepsClient::InvalidEnterpriseKeyError.new }
|
54
|
+
|
55
|
+
it { should be_a_kind_of RepsClient::ServiceError }
|
56
|
+
end
|
@@ -0,0 +1,906 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RepsClient::Contact do
|
4
|
+
subject { contact }
|
5
|
+
|
6
|
+
let(:contact) { RepsClient::Contact.new(attributes) }
|
7
|
+
|
8
|
+
let(:prefix) { 'Dr.' }
|
9
|
+
let(:first_name) { 'Alice' }
|
10
|
+
let(:middle_name) { 'Amelia' }
|
11
|
+
let(:last_name) { 'Apple' }
|
12
|
+
let(:suffix) { 'M.D.' }
|
13
|
+
let(:address1) { '555 NW Park Ave' }
|
14
|
+
let(:address2) { 'Suite A' }
|
15
|
+
let(:city) { 'Portland' }
|
16
|
+
let(:state) { 'OR' }
|
17
|
+
let(:zip_code) { '97209' }
|
18
|
+
let(:country) { 'USA' }
|
19
|
+
let(:phone) { '5035555555' }
|
20
|
+
let(:phone_extension) { 'x555' }
|
21
|
+
let(:email) { 'dr.alice@appleaday.com' }
|
22
|
+
let(:relationship_to_prospect_id) { 42 }
|
23
|
+
let(:include_in_mailings) { true }
|
24
|
+
let(:include_in_emailings) { true }
|
25
|
+
let(:source_id) { 11235 }
|
26
|
+
|
27
|
+
context 'with minimal initialization' do
|
28
|
+
let(:attributes) do
|
29
|
+
{:source_id => source_id,
|
30
|
+
:first_name => first_name,
|
31
|
+
:last_name => last_name}
|
32
|
+
end
|
33
|
+
|
34
|
+
its(:prefix) { should be_nil }
|
35
|
+
its(:first_name) { should == first_name }
|
36
|
+
its(:middle_name) { should be_nil }
|
37
|
+
its(:last_name) { should == last_name }
|
38
|
+
its(:suffix) { should be_nil }
|
39
|
+
its(:address1) { should be_nil }
|
40
|
+
its(:address2) { should be_nil }
|
41
|
+
its(:city) { should be_nil }
|
42
|
+
its(:state) { should be_nil }
|
43
|
+
its(:zip_code) { should be_nil }
|
44
|
+
its(:country) { should be_nil }
|
45
|
+
its(:phone) { should be_nil }
|
46
|
+
its(:phone_extension) { should be_nil }
|
47
|
+
its(:email) { should be_nil }
|
48
|
+
its(:relationship_to_prospect_id) { should be_nil }
|
49
|
+
its(:include_in_mailings) { should == false }
|
50
|
+
its(:include_in_emailings) { should == false }
|
51
|
+
its(:source_id) { should == source_id }
|
52
|
+
|
53
|
+
context 'with email' do
|
54
|
+
before { attributes[:email] = email }
|
55
|
+
|
56
|
+
its(:email) { should == email }
|
57
|
+
it { should be_valid }
|
58
|
+
it { should have_contact_method }
|
59
|
+
|
60
|
+
describe '#validate!' do
|
61
|
+
subject { contact.validate! }
|
62
|
+
|
63
|
+
it 'should not raise an error' do
|
64
|
+
expect { subject }.to_not raise_error
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe "#to_soap_hash" do
|
69
|
+
subject { contact.to_soap_hash }
|
70
|
+
|
71
|
+
it { should_not have_key('Prefix') }
|
72
|
+
its(['FirstName']) { should == first_name }
|
73
|
+
it { should_not have_key('MiddleName') }
|
74
|
+
its(['LastName']) { should == last_name }
|
75
|
+
it { should_not have_key('Suffix') }
|
76
|
+
it { should_not have_key('Address1') }
|
77
|
+
it { should_not have_key('Address2') }
|
78
|
+
it { should_not have_key('City') }
|
79
|
+
it { should_not have_key('State') }
|
80
|
+
it { should_not have_key('ZipCode') }
|
81
|
+
it { should_not have_key('Country') }
|
82
|
+
it { should_not have_key('Phone') }
|
83
|
+
it { should_not have_key('PhoneExtension') }
|
84
|
+
its(['Email']) { should == email }
|
85
|
+
it { should_not have_key('RelationshipToProspectId') }
|
86
|
+
its(['IncludeInMailings']) { should == false }
|
87
|
+
its(['IncludeInEmailings']) { should == false }
|
88
|
+
its(['SourceIDY']) { should == source_id }
|
89
|
+
its([:order!]) { should == ['FirstName','LastName','Email','IncludeInMailings','IncludeInEmailings','SourceIDY'] }
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
context 'with phone' do
|
95
|
+
before { attributes[:phone] = phone }
|
96
|
+
|
97
|
+
its(:phone) { should == phone }
|
98
|
+
it { should be_valid }
|
99
|
+
it { should have_contact_method }
|
100
|
+
|
101
|
+
describe '#validate!' do
|
102
|
+
subject { contact.validate! }
|
103
|
+
|
104
|
+
it 'should not raise an error' do
|
105
|
+
expect { subject }.to_not raise_error
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
context 'with mailing address' do
|
111
|
+
before do
|
112
|
+
attributes.merge!(:address1 => address1,
|
113
|
+
:city => city,
|
114
|
+
:state => state,
|
115
|
+
:zip_code => zip_code)
|
116
|
+
end
|
117
|
+
|
118
|
+
its(:address1) { should == address1 }
|
119
|
+
its(:city) { should == city }
|
120
|
+
its(:state) { should == state }
|
121
|
+
its(:zip_code) { should == zip_code }
|
122
|
+
|
123
|
+
it { should be_valid }
|
124
|
+
it { should have_contact_method }
|
125
|
+
|
126
|
+
describe '#validate!' do
|
127
|
+
subject { contact.validate! }
|
128
|
+
|
129
|
+
it 'should not raise an error' do
|
130
|
+
expect { subject }.to_not raise_error
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
context 'when there is no street address' do
|
135
|
+
let(:address1) { nil }
|
136
|
+
|
137
|
+
its(:address1) { should be_nil }
|
138
|
+
it { should_not be_valid }
|
139
|
+
it_should_behave_like 'a contact attribute validator', :address1
|
140
|
+
it { should_not have_contact_method }
|
141
|
+
|
142
|
+
describe '#validate!' do
|
143
|
+
subject { contact.validate! }
|
144
|
+
|
145
|
+
it 'should raise an error' do
|
146
|
+
expect { subject }.to raise_error(ArgumentError)
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
context 'when there is no city' do
|
152
|
+
let(:city) { nil }
|
153
|
+
|
154
|
+
its(:city) { should be_nil }
|
155
|
+
it { should_not be_valid }
|
156
|
+
it_should_behave_like 'a contact attribute validator', :city
|
157
|
+
it { should_not have_contact_method }
|
158
|
+
|
159
|
+
describe '#validate!' do
|
160
|
+
subject { contact.validate! }
|
161
|
+
|
162
|
+
it 'should raise an error' do
|
163
|
+
expect { subject }.to raise_error(ArgumentError)
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
context 'when there is no state' do
|
169
|
+
let(:state) { nil }
|
170
|
+
|
171
|
+
its(:state) { should be_nil }
|
172
|
+
it { should_not be_valid }
|
173
|
+
it_should_behave_like 'a contact attribute validator', :state
|
174
|
+
it { should_not have_contact_method }
|
175
|
+
|
176
|
+
describe '#validate!' do
|
177
|
+
subject { contact.validate! }
|
178
|
+
|
179
|
+
it 'should raise an error' do
|
180
|
+
expect { subject }.to raise_error(ArgumentError)
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
context 'when there is no zip code' do
|
186
|
+
let(:zip_code) { nil }
|
187
|
+
|
188
|
+
its(:zip_code) { should be_nil }
|
189
|
+
it { should_not be_valid }
|
190
|
+
it_should_behave_like 'a contact attribute validator', :zip_code
|
191
|
+
it { should_not have_contact_method }
|
192
|
+
|
193
|
+
describe '#validate!' do
|
194
|
+
subject { contact.validate! }
|
195
|
+
|
196
|
+
it 'should raise an error' do
|
197
|
+
expect { subject }.to raise_error(ArgumentError)
|
198
|
+
end
|
199
|
+
end
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
context 'without any method of contact' do
|
204
|
+
it { should_not be_valid }
|
205
|
+
it { should_not have_contact_method }
|
206
|
+
|
207
|
+
describe "#validate!" do
|
208
|
+
subject { contact.validate! }
|
209
|
+
|
210
|
+
it 'should raise an error' do
|
211
|
+
expect { subject }.to raise_error(ArgumentError)
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
describe '#validate' do
|
216
|
+
subject { contact.validate }
|
217
|
+
|
218
|
+
it { should have(6).error_mappings }
|
219
|
+
|
220
|
+
it { should have_key(:email) }
|
221
|
+
|
222
|
+
describe 'the errors on email' do
|
223
|
+
subject { contact.validate[:email] }
|
224
|
+
|
225
|
+
it { should have(1).error }
|
226
|
+
its(:first) { should be_an ArgumentError }
|
227
|
+
end
|
228
|
+
|
229
|
+
it { should have_key(:phone) }
|
230
|
+
|
231
|
+
describe 'the errors on phone' do
|
232
|
+
subject { contact.validate[:phone] }
|
233
|
+
|
234
|
+
it { should have(1).error }
|
235
|
+
its(:first) { should be_an ArgumentError }
|
236
|
+
end
|
237
|
+
|
238
|
+
it { should have_key(:address1) }
|
239
|
+
|
240
|
+
describe 'the errors on address1' do
|
241
|
+
subject { contact.validate[:address1] }
|
242
|
+
|
243
|
+
it { should have(1).error }
|
244
|
+
its(:first) { should be_an ArgumentError }
|
245
|
+
end
|
246
|
+
|
247
|
+
it { should have_key(:city) }
|
248
|
+
|
249
|
+
describe 'the errors on city' do
|
250
|
+
subject { contact.validate[:city] }
|
251
|
+
|
252
|
+
it { should have(1).error }
|
253
|
+
its(:first) { should be_an ArgumentError }
|
254
|
+
end
|
255
|
+
|
256
|
+
it { should have_key(:state) }
|
257
|
+
|
258
|
+
describe 'the errors on state' do
|
259
|
+
subject { contact.validate[:state] }
|
260
|
+
|
261
|
+
it { should have(1).error }
|
262
|
+
its(:first) { should be_an ArgumentError }
|
263
|
+
end
|
264
|
+
|
265
|
+
it { should have_key(:zip_code) }
|
266
|
+
|
267
|
+
describe 'the errors on zip_code' do
|
268
|
+
subject { contact.validate[:zip_code] }
|
269
|
+
|
270
|
+
it { should have(1).error }
|
271
|
+
its(:first) { should be_an ArgumentError }
|
272
|
+
end
|
273
|
+
end
|
274
|
+
end
|
275
|
+
end
|
276
|
+
|
277
|
+
|
278
|
+
context 'when fully initialized' do
|
279
|
+
let(:attributes) do
|
280
|
+
{:prefix => " #{prefix} ",
|
281
|
+
:first_name => " #{first_name} ",
|
282
|
+
:middle_name => " #{middle_name} ",
|
283
|
+
:last_name => " #{last_name} ",
|
284
|
+
:suffix => " #{suffix} ",
|
285
|
+
:address1 => " #{address1} ",
|
286
|
+
:address2 => " #{address2} ",
|
287
|
+
:city => " #{city} ",
|
288
|
+
:state => " #{state} ",
|
289
|
+
:zip_code => " #{zip_code} ",
|
290
|
+
:country => " #{country} ",
|
291
|
+
:phone => " #{phone} ",
|
292
|
+
:phone_extension => " #{phone_extension} ",
|
293
|
+
:email => " #{email} ",
|
294
|
+
:relationship_to_prospect_id => " #{relationship_to_prospect_id} ",
|
295
|
+
:include_in_mailings => include_in_mailings,
|
296
|
+
:include_in_emailings => include_in_emailings,
|
297
|
+
:source_id => source_id}
|
298
|
+
end
|
299
|
+
|
300
|
+
its(:prefix) { should == prefix }
|
301
|
+
|
302
|
+
context 'when prefix is too long' do
|
303
|
+
let(:prefix) { 'a' * 31 }
|
304
|
+
it_should_behave_like 'a contact attribute validator', :prefix
|
305
|
+
end
|
306
|
+
|
307
|
+
its(:first_name) { should == first_name }
|
308
|
+
|
309
|
+
context 'without a first name' do
|
310
|
+
before { attributes[:first_name] = nil }
|
311
|
+
|
312
|
+
it 'should raise an ArgumentError' do
|
313
|
+
expect { subject }.to raise_error ArgumentError
|
314
|
+
end
|
315
|
+
end
|
316
|
+
|
317
|
+
context 'when first name is too long' do
|
318
|
+
let(:first_name) { 'a' * 35 }
|
319
|
+
it_should_behave_like 'a contact attribute validator', :first_name
|
320
|
+
end
|
321
|
+
|
322
|
+
its(:middle_name) { should == middle_name }
|
323
|
+
|
324
|
+
context 'when middle name is too long' do
|
325
|
+
let(:middle_name) { 'a' * 31 }
|
326
|
+
it_should_behave_like 'a contact attribute validator', :middle_name
|
327
|
+
end
|
328
|
+
|
329
|
+
its(:last_name) { should == last_name }
|
330
|
+
|
331
|
+
context 'without a last name' do
|
332
|
+
before { attributes[:last_name] = nil }
|
333
|
+
|
334
|
+
it 'should raise an ArgumentError' do
|
335
|
+
expect { subject }.to raise_error ArgumentError
|
336
|
+
end
|
337
|
+
end
|
338
|
+
|
339
|
+
context 'when last name is too long' do
|
340
|
+
let(:last_name) { 'a' * 31 }
|
341
|
+
it_should_behave_like 'a contact attribute validator', :last_name
|
342
|
+
end
|
343
|
+
|
344
|
+
its(:suffix) { should == suffix }
|
345
|
+
|
346
|
+
context 'when suffix is too long' do
|
347
|
+
let(:suffix) { 'a' * 31 }
|
348
|
+
it_should_behave_like 'a contact attribute validator', :suffix
|
349
|
+
end
|
350
|
+
|
351
|
+
its(:address1) { should == address1 }
|
352
|
+
|
353
|
+
context 'when address1 is too long' do
|
354
|
+
let(:address1) { 'a' * 101 }
|
355
|
+
it_should_behave_like 'a contact attribute validator', :address1
|
356
|
+
end
|
357
|
+
|
358
|
+
its(:address2) { should == address2 }
|
359
|
+
|
360
|
+
context 'when address2 is too long' do
|
361
|
+
let(:address2) { 'a' * 101 }
|
362
|
+
it_should_behave_like 'a contact attribute validator', :address2
|
363
|
+
end
|
364
|
+
|
365
|
+
its(:city) { should == city }
|
366
|
+
|
367
|
+
context 'when city is too long' do
|
368
|
+
let(:city) { 'a' * 51 }
|
369
|
+
it_should_behave_like 'a contact attribute validator', :city
|
370
|
+
end
|
371
|
+
|
372
|
+
its(:state) { should == state }
|
373
|
+
|
374
|
+
context 'when state is too long' do
|
375
|
+
let(:state) { 'Ore' }
|
376
|
+
it_should_behave_like 'a contact attribute validator', :state
|
377
|
+
end
|
378
|
+
|
379
|
+
its(:zip_code) { should == zip_code }
|
380
|
+
|
381
|
+
context 'when zip_code is too long' do
|
382
|
+
let(:zip_code) { '9' * 11 }
|
383
|
+
it_should_behave_like 'a contact attribute validator', :zip_code
|
384
|
+
end
|
385
|
+
|
386
|
+
its(:country) { should == country }
|
387
|
+
its(:phone) { should == phone }
|
388
|
+
|
389
|
+
context 'when phone is too long' do
|
390
|
+
let(:phone) { '5' * 21 }
|
391
|
+
it_should_behave_like 'a contact attribute validator', :phone
|
392
|
+
end
|
393
|
+
|
394
|
+
its(:phone_extension) { should == phone_extension }
|
395
|
+
|
396
|
+
context 'when phone_extension is too long' do
|
397
|
+
let(:phone_extension) { '5' * 6 }
|
398
|
+
it_should_behave_like 'a contact attribute validator', :phone_extension
|
399
|
+
end
|
400
|
+
|
401
|
+
its(:email) { should == email }
|
402
|
+
|
403
|
+
context 'when email is too long' do
|
404
|
+
let(:email) { "#{'a' * 50}@#{'b' * 50}" }
|
405
|
+
it_should_behave_like 'a contact attribute validator', :email
|
406
|
+
end
|
407
|
+
|
408
|
+
its(:relationship_to_prospect_id) { should == relationship_to_prospect_id }
|
409
|
+
|
410
|
+
its(:include_in_mailings) { should == include_in_mailings }
|
411
|
+
|
412
|
+
context 'when include_in_mailings is not true or false' do
|
413
|
+
let(:include_in_mailings) { 'foo' }
|
414
|
+
|
415
|
+
its(:include_in_mailings) { should be_true }
|
416
|
+
it { should be_valid }
|
417
|
+
end
|
418
|
+
|
419
|
+
context 'when include_in_mailings is nil' do
|
420
|
+
let(:include_in_mailings) { nil }
|
421
|
+
|
422
|
+
its(:include_in_mailings) { should be_false }
|
423
|
+
it { should be_valid }
|
424
|
+
end
|
425
|
+
|
426
|
+
its(:include_in_emailings) { should == include_in_emailings }
|
427
|
+
|
428
|
+
context 'when include_in_emailings is not true or false' do
|
429
|
+
let(:include_in_emailings) { 'foo' }
|
430
|
+
|
431
|
+
its(:include_in_emailings) { should be_true }
|
432
|
+
it { should be_valid }
|
433
|
+
end
|
434
|
+
|
435
|
+
context 'when include_in_emailings is nil' do
|
436
|
+
let(:include_in_emailings) { nil }
|
437
|
+
|
438
|
+
its(:include_in_emailings) { should be_false }
|
439
|
+
it { should be_valid }
|
440
|
+
end
|
441
|
+
|
442
|
+
its(:source_id) { should == source_id }
|
443
|
+
|
444
|
+
context 'when source id is a string representing an integer' do
|
445
|
+
let(:source_id) { '99' }
|
446
|
+
|
447
|
+
its(:source_id) { should == 99 }
|
448
|
+
it { should be_valid }
|
449
|
+
end
|
450
|
+
|
451
|
+
context 'when source id is not an integer' do
|
452
|
+
let(:source_id) { 'foo' }
|
453
|
+
|
454
|
+
its(:source_id) { should == source_id }
|
455
|
+
it_should_behave_like 'a contact attribute validator', :source_id
|
456
|
+
end
|
457
|
+
|
458
|
+
context 'when source id is nil' do
|
459
|
+
let(:source_id) { nil }
|
460
|
+
|
461
|
+
it 'should raise an error upon initialization' do
|
462
|
+
expect { subject }.to raise_error ArgumentError
|
463
|
+
end
|
464
|
+
end
|
465
|
+
|
466
|
+
it { should be_valid }
|
467
|
+
it { should have_contact_method }
|
468
|
+
|
469
|
+
describe "#validate!" do
|
470
|
+
subject { contact.validate! }
|
471
|
+
|
472
|
+
it 'should not raise any errors' do
|
473
|
+
expect { subject }.to_not raise_error
|
474
|
+
end
|
475
|
+
end
|
476
|
+
|
477
|
+
describe "#to_soap_hash" do
|
478
|
+
subject { contact.to_soap_hash }
|
479
|
+
|
480
|
+
its(['Prefix']) { should == prefix }
|
481
|
+
its(['FirstName']) { should == first_name }
|
482
|
+
its(['MiddleName']) { should == middle_name }
|
483
|
+
its(['LastName']) { should == last_name }
|
484
|
+
its(['Suffix']) { should == suffix }
|
485
|
+
its(['Address1']) { should == address1 }
|
486
|
+
its(['Address2']) { should == address2 }
|
487
|
+
its(['City']) { should == city }
|
488
|
+
its(['State']) { should == state }
|
489
|
+
its(['ZipCode']) { should == zip_code }
|
490
|
+
its(['Country']) { should == country }
|
491
|
+
its(['Phone']) { should == phone }
|
492
|
+
its(['PhoneExtension']) { should == phone_extension }
|
493
|
+
its(['Email']) { should == email }
|
494
|
+
its(['RelationshipToProspectId']) { should == relationship_to_prospect_id }
|
495
|
+
its(['IncludeInMailings']) { should == include_in_mailings }
|
496
|
+
its(['IncludeInEmailings']) { should == include_in_emailings }
|
497
|
+
its(['SourceIDY']) { should == source_id }
|
498
|
+
its([:order!]) { should == ['Prefix','FirstName','MiddleName','LastName','Suffix','Address1','Address2','City','State','ZipCode','Country','Phone','PhoneExtension','Email','RelationshipToProspectId','IncludeInMailings','IncludeInEmailings','SourceIDY'] }
|
499
|
+
end
|
500
|
+
end
|
501
|
+
end
|
502
|
+
|
503
|
+
describe RepsClient::Prospect do
|
504
|
+
subject { prospect }
|
505
|
+
|
506
|
+
let(:prefix) { 'Mr.' }
|
507
|
+
let(:first_name) { 'Fred' }
|
508
|
+
let(:middle_name) { 'McFeely' }
|
509
|
+
let(:last_name) { 'Rogers' }
|
510
|
+
let(:suffix) { 'Jr.' }
|
511
|
+
let(:nickname) { 'Neighbor' }
|
512
|
+
let(:address1) { '123 Anywhere Ln' }
|
513
|
+
let(:address2) { 'Unit 42' }
|
514
|
+
let(:city) { 'Land of Make Believe' }
|
515
|
+
let(:state) { 'CA' }
|
516
|
+
let(:zip_code) { '90210' }
|
517
|
+
let(:country) { 'USA' }
|
518
|
+
let(:phone) { '(123) 456-7890' }
|
519
|
+
let(:phone_extension) { '123' }
|
520
|
+
let(:email) { 'fred@theneighborhood.org' }
|
521
|
+
let(:notes) { 'Dad is suffering from advanced dementia characterized by a preoccupation with trolleys.' }
|
522
|
+
let(:include_in_mailings) { true }
|
523
|
+
let(:include_in_emailings) { true }
|
524
|
+
|
525
|
+
context 'when initialized with defaults' do
|
526
|
+
let(:prospect) { RepsClient::Prospect.new }
|
527
|
+
|
528
|
+
its(:prefix) { should be_nil }
|
529
|
+
its(:first_name) { should be_nil }
|
530
|
+
its(:middle_name) { should be_nil }
|
531
|
+
its(:last_name) { should be_nil }
|
532
|
+
its(:suffix) { should be_nil }
|
533
|
+
its(:nickname) { should be_nil }
|
534
|
+
its(:address1) { should be_nil }
|
535
|
+
its(:address2) { should be_nil }
|
536
|
+
its(:city) { should be_nil }
|
537
|
+
its(:state) { should be_nil }
|
538
|
+
its(:zip_code) { should be_nil }
|
539
|
+
its(:country) { should be_nil }
|
540
|
+
its(:phone) { should be_nil }
|
541
|
+
its(:phone_extension) { should be_nil }
|
542
|
+
its(:email) { should be_nil }
|
543
|
+
its(:notes) { should be_nil }
|
544
|
+
its(:include_in_mailings) { should == false }
|
545
|
+
its(:include_in_emailings) { should == false }
|
546
|
+
|
547
|
+
it { should be_valid }
|
548
|
+
|
549
|
+
describe "#to_soap_hash" do
|
550
|
+
subject { prospect.to_soap_hash }
|
551
|
+
|
552
|
+
it { should_not have_key('Prefix') }
|
553
|
+
it { should_not have_key('FirstName') }
|
554
|
+
it { should_not have_key('MiddleName') }
|
555
|
+
it { should_not have_key('LastName') }
|
556
|
+
it { should_not have_key('Suffix') }
|
557
|
+
it { should_not have_key('Nickname') }
|
558
|
+
it { should_not have_key('Address1') }
|
559
|
+
it { should_not have_key('Address2') }
|
560
|
+
it { should_not have_key('City') }
|
561
|
+
it { should_not have_key('State') }
|
562
|
+
it { should_not have_key('ZipCode') }
|
563
|
+
it { should_not have_key('Country') }
|
564
|
+
it { should_not have_key('Phone') }
|
565
|
+
it { should_not have_key('PhoneExtension') }
|
566
|
+
it { should_not have_key('Email') }
|
567
|
+
it { should_not have_key('Notes') }
|
568
|
+
its(['IncludeInMailings']) { should == false }
|
569
|
+
its(['IncludeInEmailings']) { should == false }
|
570
|
+
its([:order!]) { should == ['IncludeInMailings','IncludeInEmailings'] }
|
571
|
+
end
|
572
|
+
end
|
573
|
+
|
574
|
+
context 'when fully initialized' do
|
575
|
+
let(:prospect) { RepsClient::Prospect.new(attributes) }
|
576
|
+
let(:attributes) do
|
577
|
+
{:prefix => " #{prefix} ",
|
578
|
+
:first_name => " #{first_name}",
|
579
|
+
:middle_name => "#{middle_name} ",
|
580
|
+
:last_name => "\t#{last_name}",
|
581
|
+
:suffix => " #{suffix} ",
|
582
|
+
:nickname => "#{nickname} ",
|
583
|
+
:address1 => "#{address1}\n",
|
584
|
+
:address2 => "#{address2}\t\n",
|
585
|
+
:city => " #{city} ",
|
586
|
+
:state => " #{state} ",
|
587
|
+
:zip_code => " #{zip_code} ",
|
588
|
+
:country => "#{country} ",
|
589
|
+
:phone => "#{phone} ",
|
590
|
+
:phone_extension => " #{phone_extension} ",
|
591
|
+
:email => "#{email} ",
|
592
|
+
:notes => "#{notes}\n",
|
593
|
+
:include_in_mailings => include_in_mailings,
|
594
|
+
:include_in_emailings => include_in_emailings}
|
595
|
+
end
|
596
|
+
|
597
|
+
its(:prefix) { should == prefix }
|
598
|
+
|
599
|
+
context 'when prefix is too long' do
|
600
|
+
let(:prefix) { 'a' * 31 }
|
601
|
+
it_should_behave_like 'a prospect attribute validator', :prefix
|
602
|
+
end
|
603
|
+
|
604
|
+
its(:first_name) { should == first_name }
|
605
|
+
|
606
|
+
context 'when first name is too long' do
|
607
|
+
let(:first_name) { 'a' * 31 }
|
608
|
+
it_should_behave_like 'a prospect attribute validator', :first_name
|
609
|
+
end
|
610
|
+
|
611
|
+
its(:middle_name) { should == middle_name }
|
612
|
+
|
613
|
+
context 'when middle name is too long' do
|
614
|
+
let(:middle_name) { 'a' * 31 }
|
615
|
+
it_should_behave_like 'a prospect attribute validator', :middle_name
|
616
|
+
end
|
617
|
+
|
618
|
+
its(:last_name) { should == last_name }
|
619
|
+
|
620
|
+
context 'when last name is too long' do
|
621
|
+
let(:last_name) { 'a' * 31 }
|
622
|
+
it_should_behave_like 'a prospect attribute validator', :last_name
|
623
|
+
end
|
624
|
+
|
625
|
+
its(:suffix) { should == suffix }
|
626
|
+
|
627
|
+
context 'when suffix is too long' do
|
628
|
+
let(:suffix) { 'a' * 31 }
|
629
|
+
it_should_behave_like 'a prospect attribute validator', :suffix
|
630
|
+
end
|
631
|
+
|
632
|
+
its(:nickname) { should == nickname }
|
633
|
+
|
634
|
+
context 'when nickname is too long' do
|
635
|
+
let(:nickname) { 'a' * 31 }
|
636
|
+
it_should_behave_like 'a prospect attribute validator', :nickname
|
637
|
+
end
|
638
|
+
|
639
|
+
its(:address1) { should == address1 }
|
640
|
+
|
641
|
+
context 'when address1 is too long' do
|
642
|
+
let(:address1) { 'a' * 101 }
|
643
|
+
it_should_behave_like 'a prospect attribute validator', :address1
|
644
|
+
end
|
645
|
+
|
646
|
+
its(:address2) { should == address2 }
|
647
|
+
|
648
|
+
context 'when address2 is too long' do
|
649
|
+
let(:address2) { 'a' * 101 }
|
650
|
+
it_should_behave_like 'a prospect attribute validator', :address2
|
651
|
+
end
|
652
|
+
|
653
|
+
its(:city) { should == city }
|
654
|
+
|
655
|
+
context 'when city is too long' do
|
656
|
+
let(:city) { 'a' * 51 }
|
657
|
+
it_should_behave_like 'a prospect attribute validator', :city
|
658
|
+
end
|
659
|
+
|
660
|
+
its(:state) { should == state }
|
661
|
+
|
662
|
+
context 'when state is too long' do
|
663
|
+
let(:state) { 'Washington' }
|
664
|
+
it_should_behave_like 'a prospect attribute validator', :state
|
665
|
+
end
|
666
|
+
|
667
|
+
its(:zip_code) { should == zip_code }
|
668
|
+
|
669
|
+
context 'when zip_code is too long' do
|
670
|
+
let(:zip_code) { '1' * 11 }
|
671
|
+
it_should_behave_like 'a prospect attribute validator', :zip_code
|
672
|
+
end
|
673
|
+
|
674
|
+
its(:phone) { should == phone }
|
675
|
+
|
676
|
+
context 'when phone is too long' do
|
677
|
+
let(:phone) { '5' * 21 }
|
678
|
+
it_should_behave_like 'a prospect attribute validator', :phone
|
679
|
+
end
|
680
|
+
|
681
|
+
its(:phone_extension) { should == phone_extension }
|
682
|
+
|
683
|
+
context 'when phone extension is too long' do
|
684
|
+
let(:phone_extension) { 'a' * 6 }
|
685
|
+
it_should_behave_like 'a prospect attribute validator', :phone_extension
|
686
|
+
end
|
687
|
+
|
688
|
+
its(:email) { should == email }
|
689
|
+
|
690
|
+
context 'when email is too long' do
|
691
|
+
let(:email) { 'a' * 101 }
|
692
|
+
it_should_behave_like 'a prospect attribute validator', :email
|
693
|
+
end
|
694
|
+
|
695
|
+
its(:notes) { should == notes }
|
696
|
+
|
697
|
+
its(:include_in_mailings) { should == include_in_mailings }
|
698
|
+
|
699
|
+
context 'when include_in_mailings is a non-boolean' do
|
700
|
+
let(:include_in_mailings) { 'foo' }
|
701
|
+
its(:include_in_mailings) { should be_true }
|
702
|
+
it { should be_valid }
|
703
|
+
end
|
704
|
+
|
705
|
+
context 'when include_in_mailings is nil' do
|
706
|
+
let(:include_in_mailings) { nil }
|
707
|
+
its(:include_in_mailings) { should be_false }
|
708
|
+
it { should be_valid }
|
709
|
+
end
|
710
|
+
|
711
|
+
its(:include_in_emailings) { should == include_in_emailings }
|
712
|
+
|
713
|
+
context 'when include_in_emailings is a non-boolean' do
|
714
|
+
let(:include_in_emailings) { 'false' }
|
715
|
+
its(:include_in_emailings) { should be_true }
|
716
|
+
it { should be_valid }
|
717
|
+
end
|
718
|
+
|
719
|
+
context 'when include_in_emailings is nil' do
|
720
|
+
let(:include_in_emailings) { nil }
|
721
|
+
its(:include_in_emailings) { should be_false }
|
722
|
+
it { should be_valid }
|
723
|
+
end
|
724
|
+
|
725
|
+
it { should be_valid }
|
726
|
+
|
727
|
+
describe "#to_soap_hash" do
|
728
|
+
subject { prospect.to_soap_hash }
|
729
|
+
|
730
|
+
its(['Prefix']) { should == prefix }
|
731
|
+
its(['FirstName']) { should == first_name }
|
732
|
+
its(['MiddleName']) { should == middle_name }
|
733
|
+
its(['LastName']) { should == last_name }
|
734
|
+
its(['Suffix']) { should == suffix }
|
735
|
+
its(['Nickname']) { should == nickname }
|
736
|
+
its(['Address1']) { should == address1 }
|
737
|
+
its(['Address2']) { should == address2 }
|
738
|
+
its(['City']) { should == city }
|
739
|
+
its(['State']) { should == state }
|
740
|
+
its(['ZipCode']) { should == zip_code }
|
741
|
+
its(['Country']) { should == country }
|
742
|
+
its(['Phone']) { should == phone }
|
743
|
+
its(['PhoneExtension']) { should == phone_extension }
|
744
|
+
its(['Email']) { should == email }
|
745
|
+
its(['Notes']) { should == notes }
|
746
|
+
its(['IncludeInMailings']) { should == include_in_mailings }
|
747
|
+
its(['IncludeInEmailings']) { should == include_in_emailings }
|
748
|
+
its([:order!]) { should == ['Prefix','FirstName','MiddleName','LastName','Suffix','Nickname','Address1','Address2','City','State','ZipCode','Country','Phone','PhoneExtension','Email','Notes','IncludeInMailings','IncludeInEmailings'] }
|
749
|
+
end
|
750
|
+
end
|
751
|
+
end
|
752
|
+
|
753
|
+
describe 'lead methods mixin' do
|
754
|
+
let(:test_object) { RepsClient::Client.new(:enterprise_key => enterprise_key) }
|
755
|
+
let(:enterprise_key) { 'foo' }
|
756
|
+
|
757
|
+
describe "#save_lead" do
|
758
|
+
subject { save_lead }
|
759
|
+
|
760
|
+
let(:save_lead) { test_object.save_lead(community_id, contact, prospect) }
|
761
|
+
|
762
|
+
let(:community_id) { 42 }
|
763
|
+
|
764
|
+
let(:contact) { RepsClient::Contact.new(contact_attributes) }
|
765
|
+
let(:contact_attributes) do
|
766
|
+
{:first_name => contact_first_name,
|
767
|
+
:last_name => contact_last_name,
|
768
|
+
:source_id => contact_source_id,
|
769
|
+
:phone => contact_phone}
|
770
|
+
end
|
771
|
+
let(:contact_first_name) { 'Sam' }
|
772
|
+
let(:contact_last_name) { 'Stark' }
|
773
|
+
let(:contact_source_id) { 42 }
|
774
|
+
let(:contact_phone) { '555-555-5555' }
|
775
|
+
|
776
|
+
let(:prospect) { nil }
|
777
|
+
|
778
|
+
before { savon.stubs('SaveLead').returns(nil) }
|
779
|
+
|
780
|
+
context 'without a community id' do
|
781
|
+
let(:community_id) { nil }
|
782
|
+
|
783
|
+
it 'should raise an ArgumentError without calling the remote service' do
|
784
|
+
savon.expects('SaveLead').never
|
785
|
+
expect { subject }.to raise_error(ArgumentError)
|
786
|
+
end
|
787
|
+
end
|
788
|
+
|
789
|
+
context 'with a non-integer community id' do
|
790
|
+
let(:community_id) { 'foo' }
|
791
|
+
|
792
|
+
it 'should raise an ArgumentError without calling the remote service' do
|
793
|
+
savon.expects('SaveLead').never
|
794
|
+
expect { subject }.to raise_error(ArgumentError)
|
795
|
+
end
|
796
|
+
end
|
797
|
+
|
798
|
+
context 'without a contact' do
|
799
|
+
let(:contact) { nil }
|
800
|
+
|
801
|
+
it 'should raise an ArgumentError without calling the remote service' do
|
802
|
+
savon.expects('SaveLead').never
|
803
|
+
expect { subject }.to raise_error(ArgumentError)
|
804
|
+
end
|
805
|
+
end
|
806
|
+
|
807
|
+
context 'when contact is invalid' do
|
808
|
+
let(:contact_attributes) { Hash.new }
|
809
|
+
|
810
|
+
it 'should raise an ArgumentError without calling the remote service' do
|
811
|
+
savon.expects('SaveLead').never
|
812
|
+
expect { subject }.to raise_error(ArgumentError)
|
813
|
+
end
|
814
|
+
end
|
815
|
+
|
816
|
+
context 'when contact is valid' do
|
817
|
+
context 'without a prospect' do
|
818
|
+
let(:save_lead) { test_object.save_lead(community_id, contact) }
|
819
|
+
|
820
|
+
it 'should not raise an ArgumentError' do
|
821
|
+
expect { subject }.to_not raise_error
|
822
|
+
end
|
823
|
+
|
824
|
+
it 'should call the remote service with the correct enterprise key' do
|
825
|
+
savon.expects('SaveLead').with(has_entry(:enterprise_key => enterprise_key)).returns(nil)
|
826
|
+
subject
|
827
|
+
end
|
828
|
+
|
829
|
+
it 'should call the remote service with the correct community id' do
|
830
|
+
savon.expects('SaveLead').with(has_entry(:community_id => community_id)).returns(nil)
|
831
|
+
subject
|
832
|
+
end
|
833
|
+
|
834
|
+
it 'should call the remote service with the correct contact parameters' do
|
835
|
+
savon.expects('SaveLead').with(has_entry(:new_contact => contact.to_soap_hash)).returns(nil)
|
836
|
+
subject
|
837
|
+
end
|
838
|
+
|
839
|
+
it 'should call the remote service with the correct parameter order' do
|
840
|
+
savon.expects('SaveLead').with(has_entry(:order! => [:enterprise_key,:community_id,:new_contact])).returns(nil)
|
841
|
+
subject
|
842
|
+
end
|
843
|
+
|
844
|
+
it_should_behave_like 'a fault handler', 'SaveLead'
|
845
|
+
|
846
|
+
# TODO: assert result
|
847
|
+
end
|
848
|
+
|
849
|
+
context 'with a prospect' do
|
850
|
+
let(:prospect) { RepsClient::Prospect.new(prospect_attributes) }
|
851
|
+
|
852
|
+
context 'when prospect is invalid' do
|
853
|
+
let(:prospect_attributes) { {:first_name => 'a' * 200} }
|
854
|
+
|
855
|
+
it 'should raise an ArgumentError without calling the remote service' do
|
856
|
+
savon.expects('SaveLead').never
|
857
|
+
expect { subject }.to raise_error(ArgumentError)
|
858
|
+
end
|
859
|
+
end
|
860
|
+
|
861
|
+
context 'when prospect is valid' do
|
862
|
+
let(:prospect_attributes) do
|
863
|
+
{:first_name => 'Tara',
|
864
|
+
:last_name => 'Thompson',
|
865
|
+
:notes => 'requests a brochure'}
|
866
|
+
end
|
867
|
+
|
868
|
+
before { contact.relationship_to_prospect_id = 99 }
|
869
|
+
|
870
|
+
it 'should not raise an ArgumentError' do
|
871
|
+
expect { subject }.to_not raise_error
|
872
|
+
end
|
873
|
+
|
874
|
+
it 'should call the remote service with the correct enterprise key' do
|
875
|
+
savon.expects('SaveLead').with(has_entry(:enterprise_key => enterprise_key)).returns(nil)
|
876
|
+
subject
|
877
|
+
end
|
878
|
+
|
879
|
+
it 'should call the remote service with the correct community id' do
|
880
|
+
savon.expects('SaveLead').with(has_entry(:community_id => community_id)).returns(nil)
|
881
|
+
subject
|
882
|
+
end
|
883
|
+
|
884
|
+
it 'should call the remote service with the correct contact parameters' do
|
885
|
+
savon.expects('SaveLead').with(has_entry(:new_contact => contact.to_soap_hash)).returns(nil)
|
886
|
+
subject
|
887
|
+
end
|
888
|
+
|
889
|
+
it 'should call the remote service with the correct prospect parameters' do
|
890
|
+
savon.expects('SaveLead').with(has_entry(:new_prospect => prospect.to_soap_hash)).returns(nil)
|
891
|
+
subject
|
892
|
+
end
|
893
|
+
|
894
|
+
it 'should call the remote service with the correct parameter order' do
|
895
|
+
savon.expects('SaveLead').with(has_entry(:order! => [:enterprise_key,:community_id,:new_contact,:new_prospect])).returns(nil)
|
896
|
+
subject
|
897
|
+
end
|
898
|
+
|
899
|
+
it_should_behave_like 'a fault handler', 'SaveLead'
|
900
|
+
|
901
|
+
# TODO: assert result
|
902
|
+
end
|
903
|
+
end
|
904
|
+
end
|
905
|
+
end
|
906
|
+
end
|