hubspot-api-ruby 0.8.1 → 0.9.0

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.
@@ -1,6 +1,4 @@
1
1
  RSpec.describe Hubspot::Association do
2
- before { Hubspot.configure(hapikey: 'demo') }
3
-
4
2
  let(:portal_id) { 62515 }
5
3
  let(:company) { create :company }
6
4
  let(:contact) { create :contact }
@@ -8,7 +6,7 @@ RSpec.describe Hubspot::Association do
8
6
  describe '.create' do
9
7
  context 'with a valid ID' do
10
8
  cassette
11
- subject { described_class.create(company.id, contact.id, described_class::COMPANY_TO_CONTACT) }
9
+ subject { described_class.create("Company", company.id, "Contact", contact.id) }
12
10
 
13
11
  it 'associates the resources' do
14
12
  expect(subject).to be true
@@ -18,33 +16,37 @@ RSpec.describe Hubspot::Association do
18
16
 
19
17
  context 'with an invalid ID' do
20
18
  cassette
21
- subject { described_class.create(company.id, 1234, described_class::COMPANY_TO_CONTACT) }
19
+ subject { described_class.create("Company", 1234, "Contact", 1234) }
22
20
 
23
- it 'raises an error' do
24
- expect { subject }.to raise_error(Hubspot::RequestError, /One or more associations are invalid/)
21
+ it 'returns false' do
22
+ expect(subject).to be false
25
23
  end
26
24
  end
27
25
  end
28
26
 
29
27
  describe '.batch_create' do
30
28
  let(:deal) { Hubspot::Deal.create!(portal_id, [], [], {}) }
29
+ let(:contact2) { create :contact }
31
30
 
32
- subject { described_class.batch_create(associations) }
31
+ subject { described_class.batch_create(*associations) }
33
32
 
34
33
  context 'with a valid request' do
35
34
  cassette
36
35
  let(:associations) do
37
36
  [
38
- { from_id: deal.deal_id, to_id: contact.id, definition_id: described_class::DEAL_TO_CONTACT },
39
- { from_id: deal.deal_id, to_id: company.id, definition_id: described_class::DEAL_TO_COMPANY }
37
+ "Deal",
38
+ "Contact",
39
+ [
40
+ { from_id: deal.deal_id, to_id: contact.id},
41
+ { from_id: deal.deal_id, to_id: contact2.id}
42
+ ]
40
43
  ]
41
44
  end
42
45
 
43
46
  it 'associates the resources' do
44
47
  expect(subject).to be true
45
48
  find_deal = Hubspot::Deal.find(deal.deal_id)
46
- expect(find_deal.vids).to eq [contact.id]
47
- expect(find_deal.company_ids).to eq [company.id]
49
+ expect(find_deal.vids).to eq [contact.id, contact2.id]
48
50
  end
49
51
  end
50
52
 
@@ -52,23 +54,25 @@ RSpec.describe Hubspot::Association do
52
54
  cassette
53
55
  let(:associations) do
54
56
  [
55
- { from_id: deal.deal_id, to_id: 1234, definition_id: described_class::DEAL_TO_CONTACT },
56
- { from_id: deal.deal_id, to_id: company.id, definition_id: described_class::DEAL_TO_COMPANY }
57
+ "Deal",
58
+ "Contact",
59
+ [
60
+ { from_id: deal.deal_id, to_id: 1234 }
61
+ ]
57
62
  ]
58
63
  end
59
64
 
60
- it 'raises an error' do
61
- expect { subject }.to raise_error(Hubspot::RequestError, /One or more associations are invalid/)
65
+ it 'returns false' do
66
+ expect(subject).to eq(false)
62
67
  find_deal = Hubspot::Deal.find(deal.deal_id)
63
68
  expect(find_deal.vids).to eq []
64
- expect(find_deal.company_ids).to eq []
65
69
  end
66
70
  end
67
71
  end
68
72
 
69
73
  describe '.delete' do
70
- subject { described_class.delete(company.id, contact_id_to_dissociate, described_class::COMPANY_TO_CONTACT) }
71
- before { described_class.create(company.id, contact.id, described_class::COMPANY_TO_CONTACT) }
74
+ subject { described_class.delete("Company", company.id, "Contact", contact_id_to_dissociate) }
75
+ before { described_class.create("Company", company.id, "Contact", contact.id) }
72
76
 
73
77
  context 'with a valid ID' do
74
78
  cassette
@@ -92,23 +96,23 @@ RSpec.describe Hubspot::Association do
92
96
  end
93
97
 
94
98
  describe '.batch_delete' do
95
- let(:deal) { Hubspot::Deal.create!(portal_id, [company.id], [contact.id], {}) }
99
+ let(:company2) { create(:company) }
100
+ let(:deal) { Hubspot::Deal.create!(portal_id, [company.id, company2.id], [], {}) }
96
101
 
97
- subject { described_class.batch_delete(associations) }
102
+ subject { described_class.batch_delete("Deal", "Company", associations) }
98
103
 
99
104
  context 'with a valid request' do
100
105
  cassette
101
106
  let(:associations) do
102
107
  [
103
- { from_id: deal.deal_id, to_id: contact.id, definition_id: described_class::DEAL_TO_CONTACT },
104
- { from_id: deal.deal_id, to_id: company.id, definition_id: described_class::DEAL_TO_COMPANY }
108
+ { from_id: deal.deal_id, to_id: company.id },
109
+ { from_id: deal.deal_id, to_id: company2.id }
105
110
  ]
106
111
  end
107
112
 
108
113
  it 'dissociates the resources' do
109
114
  expect(subject).to be true
110
115
  find_deal = Hubspot::Deal.find(deal.deal_id)
111
- expect(find_deal.vids).to eq []
112
116
  expect(find_deal.company_ids).to eq []
113
117
  end
114
118
  end
@@ -117,28 +121,28 @@ RSpec.describe Hubspot::Association do
117
121
  cassette
118
122
  let(:associations) do
119
123
  [
120
- { from_id: deal.deal_id, to_id: 1234, definition_id: described_class::DEAL_TO_CONTACT },
121
- { from_id: deal.deal_id, to_id: company.id, definition_id: described_class::DEAL_TO_COMPANY }
124
+ { from_id: deal.deal_id, to_id: 1234 },
125
+ { from_id: deal.deal_id, to_id: company.id }
122
126
  ]
123
127
  end
124
128
 
125
129
  it 'does not raise an error, removes the valid associations' do
126
130
  expect(subject).to be true
127
131
  find_deal = Hubspot::Deal.find(deal.deal_id)
128
- expect(find_deal.vids).to eq [contact.id]
129
- expect(find_deal.company_ids).to eq []
132
+ expect(find_deal.company_ids).to eq [company2.id]
130
133
  end
131
134
  end
132
135
  end
133
136
 
134
137
  describe '.all' do
135
- subject { described_class.all(resource_id, definition_id) }
138
+ subject { described_class.all(resource_type, resource_id, to_object_type) }
136
139
 
137
140
  context 'with valid params' do
138
141
  cassette
139
142
 
143
+ let(:resource_type) { "Deal" }
140
144
  let(:resource_id) { deal.deal_id }
141
- let(:definition_id) { described_class::DEAL_TO_CONTACT }
145
+ let(:to_object_type) { "Contact" }
142
146
  let(:deal) { Hubspot::Deal.create!(portal_id, [], contact_ids, {}) }
143
147
  let(:contact_ids) { [contact.id, second_contact.id] }
144
148
  let(:second_contact) { create :contact }
@@ -148,12 +152,13 @@ RSpec.describe Hubspot::Association do
148
152
  end
149
153
  end
150
154
 
151
- context 'with unsupported definition' do
155
+ context 'with unsupported object_type' do
156
+ let(:resource_type) { "Contact" }
152
157
  let(:resource_id) { 1234 }
153
- let(:definition_id) { -1 }
158
+ let(:to_object_type) { "Foo" }
154
159
 
155
160
  it 'raises an error' do
156
- expect { subject }.to raise_error(Hubspot::InvalidParams, 'Definition not supported')
161
+ expect { subject }.to raise_error(Hubspot::InvalidParams, 'Object type not supported')
157
162
  end
158
163
  end
159
164
  end
@@ -10,13 +10,15 @@ describe Hubspot do
10
10
  Timecop.return
11
11
  end
12
12
 
13
+ let(:last_blog_id) { Hubspot::Blog.list.last['id'] }
14
+ let(:last_blog_post_id) { Hubspot::Blog.list.last.posts.first['id'] }
15
+
13
16
  describe Hubspot::Blog do
14
17
  describe ".list" do
15
18
  it "returns a list of blogs" do
16
19
  VCR.use_cassette("blog_list") do
17
20
  result = Hubspot::Blog.list
18
21
 
19
- assert_requested :get, hubspot_api_url("/content/api/v2/blogs?hapikey=demo")
20
22
  expect(result).to be_kind_of(Array)
21
23
  expect(result.first).to be_a(Hubspot::Blog)
22
24
  end
@@ -26,10 +28,8 @@ describe Hubspot do
26
28
  describe ".find_by_id" do
27
29
  it "retrieves a blog by id" do
28
30
  VCR.use_cassette("blog_list") do
29
- id = 351076997
30
- result = Hubspot::Blog.find_by_id(id)
31
+ result = Hubspot::Blog.find_by_id(last_blog_id)
31
32
 
32
- assert_requested :get, hubspot_api_url("/content/api/v2/blogs/#{id}?hapikey=demo")
33
33
  expect(result).to be_a(Hubspot::Blog)
34
34
  end
35
35
  end
@@ -59,26 +59,23 @@ describe Hubspot do
59
59
  describe "#posts" do
60
60
  it "returns published blog posts created in the last 2 months" do
61
61
  VCR.use_cassette("blog_posts/all_blog_posts") do
62
- blog_id = 123
62
+ blog_id = last_blog_id
63
63
  created_gt = timestamp_in_milliseconds(Time.now - 2.months)
64
64
  blog = Hubspot::Blog.new({ "id" => blog_id })
65
65
 
66
66
  result = blog.posts
67
67
 
68
- assert_requested :get, hubspot_api_url("/content/api/v2/blog-posts?content_group_id=#{blog_id}&created__gt=#{created_gt}&hapikey=demo&order_by=-created&state=PUBLISHED")
69
68
  expect(result).to be_kind_of(Array)
70
69
  end
71
70
  end
72
71
 
73
72
  it "includes given parameters in the request" do
74
73
  VCR.use_cassette("blog_posts/filter_blog_posts") do
75
- blog_id = 123
76
74
  created_gt = timestamp_in_milliseconds(Time.now - 2.months)
77
- blog = Hubspot::Blog.new({ "id" => 123 })
75
+ blog = Hubspot::Blog.new({ "id" => last_blog_id })
78
76
 
79
77
  result = blog.posts({ state: "DRAFT" })
80
78
 
81
- assert_requested :get, hubspot_api_url("/content/api/v2/blog-posts?content_group_id=#{blog_id}&created__gt=#{created_gt}&hapikey=demo&order_by=-created&state=DRAFT")
82
79
  expect(result).to be_kind_of(Array)
83
80
  end
84
81
  end
@@ -106,11 +103,8 @@ describe Hubspot do
106
103
  describe ".find_by_blog_post_id" do
107
104
  it "retrieves a blog post by id" do
108
105
  VCR.use_cassette "blog_posts" do
109
- blog_post_id = 422192866
110
-
111
- result = Hubspot::BlogPost.find_by_blog_post_id(blog_post_id)
106
+ result = Hubspot::BlogPost.find_by_blog_post_id(last_blog_post_id)
112
107
 
113
- assert_requested :get, hubspot_api_url("/content/api/v2/blog-posts/#{blog_post_id}?hapikey=demo")
114
108
  expect(result).to be_a(Hubspot::BlogPost)
115
109
  end
116
110
  end
@@ -119,7 +113,7 @@ describe Hubspot do
119
113
  describe "#topics" do
120
114
  it "returns the list of topics" do
121
115
  VCR.use_cassette "blog_posts" do
122
- blog_post = Hubspot::BlogPost.find_by_blog_post_id(422192866)
116
+ blog_post = Hubspot::BlogPost.find_by_blog_post_id(last_blog_post_id)
123
117
 
124
118
  topics = blog_post.topics
125
119
 
@@ -14,8 +14,6 @@ RSpec.describe Hubspot::CompanyProperties do
14
14
  end
15
15
  end
16
16
 
17
- before { Hubspot.configure(hapikey: ENV.fetch("HUBSPOT_HAPI_KEY", "demo")) }
18
-
19
17
  describe ".all" do
20
18
  it "should return all properties" do
21
19
  VCR.use_cassette "company_properties/all_properties" do
@@ -229,7 +227,7 @@ RSpec.describe Hubspot::CompanyProperties do
229
227
  VCR.use_cassette("company_properties/delete_non_property") do
230
228
  expect {
231
229
  Hubspot::CompanyProperties.delete!("non-existent")
232
- }.to raise_error(Hubspot::RequestError)
230
+ }.to raise_error(Hubspot::NotFoundError)
233
231
  end
234
232
  end
235
233
  end
@@ -240,17 +238,16 @@ RSpec.describe Hubspot::CompanyProperties do
240
238
  describe ".groups" do
241
239
  it "returns all groups" do
242
240
  VCR.use_cassette("company_properties/all_groups") do
243
- group_name = "group_awesome"
244
- Hubspot::CompanyProperties.create_group!(name: group_name)
241
+ group = Hubspot::CompanyProperties.create_group!(name: "group_#{SecureRandom.hex}")
245
242
 
246
243
  response = Hubspot::CompanyProperties.groups
247
244
 
248
245
  assert_hubspot_api_request(:get, "/properties/v1/companies/groups")
249
246
 
250
247
  group_names = response.map { |group| group["name"] }
251
- expect(group_names).to include(group_name)
248
+ expect(group_names).to include(group['name'])
252
249
 
253
- Hubspot::CompanyProperties.delete_group!(group_name)
250
+ Hubspot::CompanyProperties.delete_group!(group['name'])
254
251
  end
255
252
  end
256
253
 
@@ -358,10 +355,10 @@ RSpec.describe Hubspot::CompanyProperties do
358
355
 
359
356
  let(:sub_params) { params.select { |k, _| k != 'displayName' } }
360
357
 
361
- it 'should return the valid parameters' do
362
- params['name'] = 'ff_group235'
358
+ it 'should return the valid parameters' do |example|
359
+ params['name'] = "ff_group_#{SecureRandom.hex}"
363
360
  response = Hubspot::CompanyProperties.create_group!(sub_params)
364
- expect(Hubspot::CompanyProperties.same?(response, sub_params)).to be true
361
+ expect(Hubspot::CompanyProperties.same?(response.except("name"), sub_params.except("name"))).to be true
365
362
  end
366
363
  end
367
364
  end
@@ -402,7 +399,7 @@ RSpec.describe Hubspot::CompanyProperties do
402
399
  cassette 'company_properties/delete_non_group'
403
400
 
404
401
  it 'should raise an error' do
405
- expect { Hubspot::CompanyProperties.delete_group!(name) }.to raise_error(Hubspot::RequestError)
402
+ expect { Hubspot::CompanyProperties.delete_group!(name) }.to raise_error(Hubspot::NotFoundError)
406
403
  end
407
404
  end
408
405
  end
@@ -1,5 +1,4 @@
1
1
  RSpec.describe Hubspot::Company do
2
- before { Hubspot.configure(hapikey: 'demo') }
3
2
 
4
3
  it_behaves_like "a saveable resource", :company do
5
4
  def set_property(company)
@@ -31,7 +30,7 @@ RSpec.describe Hubspot::Company do
31
30
  it 'raises an error' do
32
31
  expect {
33
32
  subject
34
- }.to raise_error(Hubspot::RequestError, /resource not found/)
33
+ }.to raise_error(Hubspot::NotFoundError, /resource not found/)
35
34
  end
36
35
  end
37
36
  end
@@ -164,7 +163,7 @@ RSpec.describe Hubspot::Company do
164
163
 
165
164
  expect {
166
165
  described_class.find subject.id
167
- }.to raise_error(Hubspot::RequestError)
166
+ }.to raise_error(Hubspot::NotFoundError)
168
167
  end
169
168
  end
170
169
  end
@@ -283,8 +282,8 @@ RSpec.describe Hubspot::Company do
283
282
 
284
283
  subject { described_class.add_contact company.id, 1234 }
285
284
 
286
- it 'raises an error' do
287
- expect { subject }.to raise_error(Hubspot::RequestError, /CONTACT=1234 is not valid/)
285
+ it 'returns false' do
286
+ expect(subject).to eq(false)
288
287
  end
289
288
  end
290
289
 
@@ -294,7 +293,7 @@ RSpec.describe Hubspot::Company do
294
293
  subject { described_class.add_contact 1, 1 }
295
294
 
296
295
  it 'raises an error' do
297
- expect { subject }.to raise_error(Hubspot::RequestError, /COMPANY=1 is not valid/)
296
+ expect(subject).to eq(false)
298
297
  end
299
298
  end
300
299
  end
@@ -1,12 +1,13 @@
1
1
  describe Hubspot::ContactList do
2
2
  let(:example_contact_list_hash) do
3
3
  VCR.use_cassette("contact_list_example") do
4
- HTTParty.get("https://api.hubapi.com/contacts/v1/lists/1?hapikey=demo").parsed_response
4
+ HTTParty.get("https://api.hubapi.com/contacts/v1/lists/124897?hapikey=demo").parsed_response
5
5
  end
6
6
  end
7
7
 
8
- let(:static_list) { Hubspot::ContactList.all(static: true, count: 3).last }
9
- let(:dynamic_list) { Hubspot::ContactList.all(dynamic: true, count: 1).first }
8
+ let(:static_list) do
9
+ Hubspot::ContactList.create!(name: "static list #{SecureRandom.hex}")
10
+ end
10
11
 
11
12
  let(:example_contact_hash) do
12
13
  VCR.use_cassette("contact_example") do
@@ -14,6 +15,22 @@ describe Hubspot::ContactList do
14
15
  end
15
16
  end
16
17
 
18
+ shared_examples "count and offset" do |params|
19
+ it 'returns only the number of objects specified by count' do
20
+ result = instance_exec(count: 2, &params[:block])
21
+ expect(result.size).to eql 2
22
+
23
+ result = instance_exec(count: 4, &params[:block])
24
+ expect(result.size).to eql 4
25
+ end
26
+
27
+ it 'returns objects by a specified offset' do
28
+ non_offset_objects = instance_exec(count: 2, &params[:block])
29
+ objects_with_offset = instance_exec(count: 2, offset: 2, &params[:block])
30
+ expect(non_offset_objects).to_not eql objects_with_offset
31
+ end
32
+ end
33
+
17
34
  describe '#initialize' do
18
35
  subject { Hubspot::ContactList.new(example_contact_list_hash) }
19
36
 
@@ -25,12 +42,20 @@ describe Hubspot::ContactList do
25
42
  its(:properties) { should be_a(Hash) }
26
43
  end
27
44
 
28
- before { Hubspot.configure(hapikey: "demo") }
29
-
30
45
  describe '#contacts' do
31
46
  cassette 'contacts_among_list'
32
47
 
33
- let(:list) { Hubspot::ContactList.new(example_contact_list_hash) }
48
+ let(:list) { @list }
49
+
50
+ before(:all) do
51
+ VCR.use_cassette 'create_and_add_all_contacts' do
52
+ @list = Hubspot::ContactList.create!(name: "contacts list #{SecureRandom.hex}")
53
+ 25.times do
54
+ contact = Hubspot::Contact.create("#{SecureRandom.hex}@hubspot.com")
55
+ @list.add(contact)
56
+ end
57
+ end
58
+ end
34
59
 
35
60
  it 'returns by default 20 contact lists' do
36
61
  expect(list.contacts.count).to eql 20
@@ -39,7 +64,7 @@ describe Hubspot::ContactList do
39
64
  end
40
65
 
41
66
  it 'returns by default 20 contact lists with paging data' do
42
- contact_data = list.contacts({paged: true})
67
+ contact_data = list.contacts({bypass_cache: true, paged: true})
43
68
  contacts = contact_data['contacts']
44
69
 
45
70
  expect(contact_data).to have_key 'vid-offset'
@@ -55,9 +80,8 @@ describe Hubspot::ContactList do
55
80
  expect(contact.email).to_not be_empty
56
81
  end
57
82
 
58
- expect_count_and_offset do |params|
59
- Hubspot::ContactList.find(1).contacts(params)
60
- end
83
+ it_behaves_like 'count and offset', {block: ->(r) { Hubspot::ContactList.find(list.id).contacts(r) }}
84
+
61
85
  end
62
86
 
63
87
  describe '.create' do
@@ -66,7 +90,7 @@ describe Hubspot::ContactList do
66
90
  context 'with all required parameters' do
67
91
  cassette 'create_list'
68
92
 
69
- let(:name) { 'testing list' }
93
+ let(:name) { "testing list #{SecureRandom.hex}" }
70
94
  it { should be_an_instance_of Hubspot::ContactList }
71
95
  its(:id) { should be_an(Integer) }
72
96
  its(:portal_id) { should be_an(Integer) }
@@ -76,7 +100,7 @@ describe Hubspot::ContactList do
76
100
  cassette 'create_list_with_filters'
77
101
 
78
102
  it 'returns a ContactList object with filters set' do
79
- name = 'list with filters'
103
+ name = "list with filters #{SecureRandom.hex}"
80
104
  filters_param = [[{ operator: "EQ", value: "@hubspot", property: "twitterhandle", type: "string"}]]
81
105
  list_with_filters = Hubspot::ContactList.create!({ name: name, filters: filters_param })
82
106
  expect(list_with_filters).to be_a(Hubspot::ContactList)
@@ -95,6 +119,13 @@ describe Hubspot::ContactList do
95
119
  end
96
120
 
97
121
  describe '.all' do
122
+ before(:all) do
123
+ VCR.use_cassette("create_all_lists") do
124
+ 25.times { Hubspot::ContactList.create!(name: SecureRandom.hex) }
125
+ 25.times { Hubspot::ContactList.create!(name: SecureRandom.hex, dynamic: true, filters: [[{ operator: "EQ", value: "@hubspot", property: "twitterhandle", type: "string"}]]) }
126
+ end
127
+ end
128
+
98
129
  context 'all list types' do
99
130
  cassette 'find_all_lists'
100
131
 
@@ -107,7 +138,7 @@ describe Hubspot::ContactList do
107
138
  expect(list.id).to be_an(Integer)
108
139
  end
109
140
 
110
- expect_count_and_offset { |params| Hubspot::ContactList.all(params) }
141
+ it_behaves_like 'count and offset', {block: ->(r) { Hubspot::ContactList.all(r) }}
111
142
  end
112
143
 
113
144
  context 'static lists' do
@@ -126,7 +157,7 @@ describe Hubspot::ContactList do
126
157
  context 'dynamic lists' do
127
158
  cassette 'find_all_dynamic_lists'
128
159
 
129
- it 'returns by defaut all the static contact lists' do
160
+ it 'returns by defaut all the dynamic contact lists' do
130
161
  lists = Hubspot::ContactList.all(dynamic: true)
131
162
  expect(lists.count).to be > 20
132
163
 
@@ -142,13 +173,17 @@ describe Hubspot::ContactList do
142
173
  cassette "contact_list_find"
143
174
  subject { Hubspot::ContactList.find(id) }
144
175
 
176
+ let(:list) { Hubspot::ContactList.create!(name: SecureRandom.hex) }
177
+
145
178
  context 'when the contact list is found' do
146
- let(:id) { 1 }
179
+ let(:id) { list.id.to_i }
147
180
  it { should be_an_instance_of Hubspot::ContactList }
148
- its(:name) { should == 'twitterers' }
181
+ its(:name) { should == list.name }
149
182
 
150
- let(:id) { '1' }
151
- it { should be_an_instance_of Hubspot::ContactList }
183
+ context "string id" do
184
+ let(:id) { list.id.to_s }
185
+ it { should be_an_instance_of Hubspot::ContactList }
186
+ end
152
187
  end
153
188
 
154
189
  context 'Wrong parameter type given' do
@@ -159,7 +194,7 @@ describe Hubspot::ContactList do
159
194
 
160
195
  context 'when the contact list is not found' do
161
196
  it 'raises an error' do
162
- expect { Hubspot::ContactList.find(-1) }.to raise_error(Hubspot::RequestError)
197
+ expect { Hubspot::ContactList.find(-1) }.to raise_error(Hubspot::NotFoundError)
163
198
  end
164
199
  end
165
200
  end
@@ -167,13 +202,17 @@ describe Hubspot::ContactList do
167
202
  context 'given a list of ids' do
168
203
  cassette "contact_list_batch_find"
169
204
 
205
+ let(:list1) { Hubspot::ContactList.create!(name: SecureRandom.hex) }
206
+ let(:list2) { Hubspot::ContactList.create!(name: SecureRandom.hex) }
207
+ let(:list3) { Hubspot::ContactList.create!(name: SecureRandom.hex) }
208
+
170
209
  it 'find lists of contacts' do
171
- lists = Hubspot::ContactList.find([2,3,4])
210
+ lists = Hubspot::ContactList.find([list1.id,list2.id,list3.id])
172
211
  list = lists.first
173
212
  expect(list).to be_a(Hubspot::ContactList)
174
- expect(list.id).to be == 2
175
- expect(lists.second.id).to be == 3
176
- expect(lists.last.id).to be == 4
213
+ expect(list.id).to be == list1.id
214
+ expect(lists.second.id).to be == list2.id
215
+ expect(lists.last.id).to be == list3.id
177
216
  end
178
217
  end
179
218
  end
@@ -182,8 +221,8 @@ describe Hubspot::ContactList do
182
221
  context "for a static list" do
183
222
  it "adds the contact to the contact list" do
184
223
  VCR.use_cassette("contact_lists/add_contact") do
185
- contact = Hubspot::Contact.create("email@example.com")
186
- contact_list_params = { name: "my-contacts-list" }
224
+ contact = Hubspot::Contact.create("#{SecureRandom.hex}@example.com")
225
+ contact_list_params = { name: "my-contacts-list-#{SecureRandom.hex}" }
187
226
  contact_list = Hubspot::ContactList.create!(contact_list_params)
188
227
 
189
228
  result = contact_list.add([contact])
@@ -198,15 +237,15 @@ describe Hubspot::ContactList do
198
237
  context "when the contact already exists in the contact list" do
199
238
  it "returns false" do
200
239
  VCR.use_cassette("contact_lists/add_existing_contact") do
201
- contact = Hubspot::Contact.create("email@example.com")
240
+ contact = Hubspot::Contact.create("#{SecureRandom.hex}@example.com")
202
241
 
203
- contact_list_params = { name: "my-contacts-list" }
242
+ contact_list_params = { name: "my-contacts-list-#{SecureRandom.hex}" }
204
243
  contact_list = Hubspot::ContactList.create!(contact_list_params)
205
244
  contact_list.add([contact])
206
245
 
207
246
  result = contact_list.add([contact])
208
247
 
209
- expect(result).to be false
248
+ expect(result).to be true
210
249
 
211
250
  contact.delete
212
251
  contact_list.destroy!
@@ -218,9 +257,9 @@ describe Hubspot::ContactList do
218
257
  context "for a dynamic list" do
219
258
  it "raises an error as dynamic lists add contacts via on filters" do
220
259
  VCR.use_cassette("contact_list/add_contact_to_dynamic_list") do
221
- contact = Hubspot::Contact.create("email@example.com")
260
+ contact = Hubspot::Contact.create("#{SecureRandom.hex}@example.com")
222
261
  contact_list_params = {
223
- name: "my-contacts-list",
262
+ name: "my-contacts-list-#{SecureRandom.hex}",
224
263
  dynamic: true,
225
264
  "filters": [
226
265
  [
@@ -257,45 +296,29 @@ describe Hubspot::ContactList do
257
296
  expect(static_list.remove(contact_not_present_in_list)).to be false
258
297
  end
259
298
  end
260
-
261
- context 'dynamic list' do
262
- it 'raises error if try to remove a contact from a dynamic list' do
263
- contact = dynamic_list.contacts(recent: true, count: 1).first
264
- expect { dynamic_list.remove(contact) }.to raise_error(Hubspot::RequestError)
265
- end
266
- end
267
299
  end
268
300
 
269
301
  describe '#update!' do
270
302
  cassette "contact_list_update"
271
303
 
272
- let(:contact_list) { Hubspot::ContactList.new(example_contact_list_hash) }
273
- let(:params) { { name: "update list name" } }
274
- subject { contact_list.update!(params) }
304
+ let(:params) { { name: "updated list name" } }
305
+ subject { static_list.update!(params) }
275
306
 
276
307
  it { should be_an_instance_of Hubspot::ContactList }
277
- its(:name){ should == "update list name" }
308
+ its(:name){ should == params[:name] }
309
+
310
+ after { static_list.destroy! }
278
311
  end
279
312
 
280
313
  describe '#destroy!' do
281
314
  cassette "contact_list_destroy"
282
315
 
283
- let(:contact_list) { Hubspot::ContactList.create!({ name: "newcontactlist_#{Time.now.to_i}"}) }
284
- subject{ contact_list.destroy! }
316
+ subject{ static_list.destroy! }
285
317
  it { should be true }
286
318
 
287
319
  it "should be destroyed" do
288
320
  subject
289
- expect(contact_list).to be_destroyed
321
+ expect(static_list).to be_destroyed
290
322
  end
291
323
  end
292
-
293
- describe '#refresh' do
294
- cassette "contact_list_refresh"
295
-
296
- let(:contact_list) { Hubspot::ContactList.new(example_contact_list_hash) }
297
- subject { contact_list.refresh }
298
-
299
- it { should be true }
300
- end
301
324
  end