2
2
import json
3
3
import re
4
4
from describe import expect
5
- from intercom .admin import Admin
6
- from intercom . collection_proxy import CollectionProxy
5
+ from intercom .user import User
6
+ from tests . unit import page_of_users
7
7
8
8
get = httpretty .GET
9
9
r = re .compile
@@ -13,43 +13,31 @@ class DescribeIntercomCollectionProxy:
13
13
14
14
@httpretty .activate
15
15
def it_stops_iterating_if_no_next_link (self ):
16
- body = json .dumps ({} )
16
+ body = json .dumps (page_of_users ( include_next_link = False ) )
17
17
httpretty .register_uri (get , r (r"/users" ), body = body )
18
- all = Admin . all ()
19
- expect (all ). to . be_instance_of ( CollectionProxy )
18
+ emails = [ user . email for user in User . all ()]
19
+ expect (emails ) == [ 'user1@example.com' , 'user2@example.com' , 'user3@example.com' ]
20
20
21
+ @httpretty .activate
22
+ def it_keeps_iterating_if_next_link (self ):
23
+ page1 = json .dumps (page_of_users (include_next_link = True ))
24
+ page2 = json .dumps (page_of_users (include_next_link = False ))
25
+ httpretty .register_uri (get , r (r"/users$" ), body = page1 )
26
+ httpretty .register_uri (
27
+ get , r (r'https://api.intercom.io/users\?per_page=50&page=2' ), body = page2 ,
28
+ match_querystring = True )
29
+ emails = [user .email for user in User .all ()]
30
+ expect (emails ) == ['user1@example.com' , 'user2@example.com' , 'user3@example.com' ] * 2
21
31
22
- # require "spec_helper"
23
-
24
- # describe Intercom::CollectionProxy do
25
-
26
- # it "stops iterating if no next link" do
27
- # Intercom.expects(:get).with("/users", {}).returns(page_of_users(include_next_link:false))
28
- # emails = []
29
- # Intercom::User.all.each { |user| emails << user.email }
30
- # emails.must_equal %W(user1@example.com user2@example.com user3@example.com)
31
- # end
32
-
33
- # it "keeps iterating if next link" do
34
- # Intercom.expects(:get).with("/users", {}).returns(page_of_users(include_next_link:true))
35
- # Intercom.expects(:get).with('https://api.intercom.io/users?per_page=50&page=2', {}).returns(page_of_users(include_next_link:false))
36
- # emails = []
37
- # Intercom::User.all.each { |user| emails << user.email }
38
- # end
39
-
40
- # it "supports indexed array access" do
41
- # Intercom.expects(:get).with("/users", {}).returns(page_of_users(include_next_link:false))
42
- # Intercom::User.all[0].email.must_equal 'user1@example.com'
43
- # end
44
-
45
- # it "supports map" do
46
- # Intercom.expects(:get).with("/users", {}).returns(page_of_users(include_next_link:false))
47
- # emails = Intercom::User.all.map { |user| user.email }
48
- # emails.must_equal %W(user1@example.com user2@example.com user3@example.com)
49
- # end
32
+ @httpretty .activate
33
+ def it_supports_indexed_array_access (self ):
34
+ body = json .dumps (page_of_users (include_next_link = False ))
35
+ httpretty .register_uri (get , r (r"/users" ), body = body )
36
+ expect (User .all ()[0 ].email ) == 'user1@example.com'
50
37
51
- # it "supports querying" do
52
- # Intercom.expects(:get).with("/users", {:tag_name => 'Taggart J'}).returns(page_of_users(include_next_link:false))
53
- # Intercom::User.find_all(:tag_name => 'Taggart J').map(&:email).must_equal %W(user1@example.com user2@example.com user3@example.com)
54
- # end
55
- # end
38
+ @httpretty .activate
39
+ def it_supports_querying (self ):
40
+ body = json .dumps (page_of_users (include_next_link = False ))
41
+ httpretty .register_uri (get , r (r"/users" ), body = body )
42
+ emails = [user .email for user in User .find_all (tag_name = 'Taggart J' )]
43
+ expect (emails ) == ['user1@example.com' , 'user2@example.com' , 'user3@example.com' ]
0 commit comments