tailored-etsy 0.2.2
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/.travis.yml +8 -0
- data/Gemfile +3 -0
- data/LICENSE +9 -0
- data/README.md +280 -0
- data/Rakefile +12 -0
- data/etsy.gemspec +28 -0
- data/lib/etsy.rb +172 -0
- data/lib/etsy/address.rb +47 -0
- data/lib/etsy/basic_client.rb +26 -0
- data/lib/etsy/category.rb +84 -0
- data/lib/etsy/country.rb +27 -0
- data/lib/etsy/image.rb +34 -0
- data/lib/etsy/listing.rb +178 -0
- data/lib/etsy/model.rb +123 -0
- data/lib/etsy/payment_template.rb +33 -0
- data/lib/etsy/profile.rb +49 -0
- data/lib/etsy/request.rb +148 -0
- data/lib/etsy/response.rb +112 -0
- data/lib/etsy/section.rb +16 -0
- data/lib/etsy/secure_client.rb +128 -0
- data/lib/etsy/shipping_template.rb +32 -0
- data/lib/etsy/shop.rb +83 -0
- data/lib/etsy/transaction.rb +18 -0
- data/lib/etsy/user.rb +91 -0
- data/lib/etsy/verification_request.rb +17 -0
- data/lib/etsy/version.rb +3 -0
- data/test/fixtures/address/getUserAddresses.json +12 -0
- data/test/fixtures/category/findAllSubCategoryChildren.json +78 -0
- data/test/fixtures/category/findAllTopCategory.json +347 -0
- data/test/fixtures/category/findAllTopCategory.single.json +18 -0
- data/test/fixtures/category/findAllTopCategoryChildren.json +308 -0
- data/test/fixtures/category/getCategory.multiple.json +28 -0
- data/test/fixtures/category/getCategory.single.json +18 -0
- data/test/fixtures/country/getCountry.json +1 -0
- data/test/fixtures/image/findAllListingImages.json +102 -0
- data/test/fixtures/listing/findAllListingActive.category.json +827 -0
- data/test/fixtures/listing/findAllShopListings.json +69 -0
- data/test/fixtures/listing/getListing.multiple.json +1 -0
- data/test/fixtures/listing/getListing.single.json +1 -0
- data/test/fixtures/payment_template/getPaymentTemplate.json +1 -0
- data/test/fixtures/profile/new.json +28 -0
- data/test/fixtures/section/getShopSection.json +18 -0
- data/test/fixtures/shipping_template/getShippingTemplate.json +1 -0
- data/test/fixtures/shop/findAllShop.json +1 -0
- data/test/fixtures/shop/findAllShop.single.json +1 -0
- data/test/fixtures/shop/getShop.multiple.json +1 -0
- data/test/fixtures/shop/getShop.single.json +33 -0
- data/test/fixtures/transaction/findAllShopTransactions.json +1 -0
- data/test/fixtures/user/getUser.multiple.json +29 -0
- data/test/fixtures/user/getUser.single.json +13 -0
- data/test/fixtures/user/getUser.single.private.json +18 -0
- data/test/fixtures/user/getUser.single.withProfile.json +38 -0
- data/test/fixtures/user/getUser.single.withShops.json +41 -0
- data/test/test_helper.rb +44 -0
- data/test/unit/etsy/address_test.rb +61 -0
- data/test/unit/etsy/basic_client_test.rb +28 -0
- data/test/unit/etsy/category_test.rb +106 -0
- data/test/unit/etsy/country_test.rb +64 -0
- data/test/unit/etsy/image_test.rb +43 -0
- data/test/unit/etsy/listing_test.rb +217 -0
- data/test/unit/etsy/model_test.rb +64 -0
- data/test/unit/etsy/payment_template_test.rb +68 -0
- data/test/unit/etsy/profile_test.rb +111 -0
- data/test/unit/etsy/request_test.rb +192 -0
- data/test/unit/etsy/response_test.rb +164 -0
- data/test/unit/etsy/section_test.rb +28 -0
- data/test/unit/etsy/secure_client_test.rb +132 -0
- data/test/unit/etsy/shipping_template_test.rb +24 -0
- data/test/unit/etsy/shop_test.rb +104 -0
- data/test/unit/etsy/transaction_test.rb +52 -0
- data/test/unit/etsy/user_test.rb +218 -0
- data/test/unit/etsy/verification_request_test.rb +26 -0
- data/test/unit/etsy_test.rb +114 -0
- metadata +269 -0
@@ -0,0 +1,28 @@
|
|
1
|
+
require File.expand_path('../../../test_helper', __FILE__)
|
2
|
+
|
3
|
+
module Etsy
|
4
|
+
class SectionTest < Test::Unit::TestCase
|
5
|
+
context "An instance of the Section class" do
|
6
|
+
setup do
|
7
|
+
data = read_fixture('section/getShopSection.json')
|
8
|
+
@section = Section.new(data.first)
|
9
|
+
end
|
10
|
+
|
11
|
+
should "have an id" do
|
12
|
+
@section.id.should == 11045327
|
13
|
+
end
|
14
|
+
|
15
|
+
should "have an title" do
|
16
|
+
@section.title.should == "Blue Items"
|
17
|
+
end
|
18
|
+
|
19
|
+
should "have an user_id" do
|
20
|
+
@section.user_id.should == 9569349
|
21
|
+
end
|
22
|
+
|
23
|
+
should "have an active_listing_count" do
|
24
|
+
@section.active_listing_count.should == 7
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,132 @@
|
|
1
|
+
require File.expand_path('../../../test_helper', __FILE__)
|
2
|
+
|
3
|
+
module Etsy
|
4
|
+
class SecureClientTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
context "An instance of the SecureClient class" do
|
7
|
+
|
8
|
+
should "be able to generate an OAuth consumer for the sandbox" do
|
9
|
+
Etsy.stubs(:environment).returns :sandbox
|
10
|
+
Etsy.stubs(:host).returns 'sandbox'
|
11
|
+
Etsy.stubs(:api_key).returns('key')
|
12
|
+
Etsy.stubs(:api_secret).returns('secret')
|
13
|
+
Etsy.stubs(:permission_scopes).returns(['scope_one', 'scope_two'])
|
14
|
+
|
15
|
+
OAuth::Consumer.stubs(:new).with('key', 'secret', {
|
16
|
+
:site => 'http://sandbox',
|
17
|
+
:request_token_path => '/v2/oauth/request_token?scope=scope_one+scope_two',
|
18
|
+
:access_token_path => '/v2/oauth/access_token',
|
19
|
+
}).returns('consumer')
|
20
|
+
|
21
|
+
client = SecureClient.new
|
22
|
+
|
23
|
+
client.consumer.should == 'consumer'
|
24
|
+
end
|
25
|
+
|
26
|
+
should "be able to generate an OAuth consumer in production" do
|
27
|
+
Etsy.stubs(:environment).returns :production
|
28
|
+
Etsy.stubs(:host).returns 'production'
|
29
|
+
Etsy.stubs(:api_key).returns('key')
|
30
|
+
Etsy.stubs(:api_secret).returns('secret')
|
31
|
+
Etsy.stubs(:permission_scopes).returns(['scope_one', 'scope_two'])
|
32
|
+
|
33
|
+
OAuth::Consumer.stubs(:new).with('key', 'secret', {
|
34
|
+
:site => 'http://production',
|
35
|
+
:request_token_path => '/v2/oauth/request_token?scope=scope_one+scope_two',
|
36
|
+
:access_token_path => '/v2/oauth/access_token',
|
37
|
+
}).returns('consumer')
|
38
|
+
|
39
|
+
client = SecureClient.new
|
40
|
+
|
41
|
+
client.consumer.should == 'consumer'
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
|
46
|
+
should "be able to generate a request token" do
|
47
|
+
Etsy.stubs(:callback_url).with().returns('callback_url')
|
48
|
+
consumer = stub() {|c| c.stubs(:get_request_token).with(:oauth_callback => 'callback_url').returns('toke') }
|
49
|
+
|
50
|
+
client = SecureClient.new
|
51
|
+
client.stubs(:consumer).returns(consumer)
|
52
|
+
|
53
|
+
client.request_token.should == 'toke'
|
54
|
+
end
|
55
|
+
|
56
|
+
context "with request data" do
|
57
|
+
setup do
|
58
|
+
@client = SecureClient.new(:request_token => 'toke', :request_secret => 'secret', :verifier => 'verify')
|
59
|
+
@client.stubs(:consumer).returns('consumer')
|
60
|
+
end
|
61
|
+
|
62
|
+
should "be able to generate an oauth client" do
|
63
|
+
request_token = stub()
|
64
|
+
request_token.stubs(:get_access_token).with(:oauth_verifier => 'verify').returns('client')
|
65
|
+
|
66
|
+
OAuth::RequestToken.stubs(:new).with('consumer', 'toke', 'secret').returns(request_token)
|
67
|
+
|
68
|
+
@client.client_from_request_data.should == 'client'
|
69
|
+
end
|
70
|
+
|
71
|
+
should "know to generate a client from request data" do
|
72
|
+
@client.stubs(:client_from_request_data).returns('client')
|
73
|
+
@client.client.should == 'client'
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
context "with access data" do
|
78
|
+
setup do
|
79
|
+
@client = SecureClient.new(:access_token => 'toke', :access_secret => 'secret')
|
80
|
+
@client.stubs(:consumer).returns('consumer')
|
81
|
+
end
|
82
|
+
|
83
|
+
should "know the :access_token" do
|
84
|
+
@client.access_token.should == 'toke'
|
85
|
+
end
|
86
|
+
|
87
|
+
should "know the access secret" do
|
88
|
+
@client.access_secret.should == 'secret'
|
89
|
+
end
|
90
|
+
|
91
|
+
should "be able to generate an oauth client" do
|
92
|
+
OAuth::AccessToken.stubs(:new).with('consumer', 'toke', 'secret').returns('client')
|
93
|
+
@client.client_from_access_data.should == 'client'
|
94
|
+
end
|
95
|
+
|
96
|
+
should "be able to generate a client" do
|
97
|
+
@client.stubs(:client_from_access_data).returns('client')
|
98
|
+
@client.client.should == 'client'
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
context "with a client" do
|
103
|
+
setup do
|
104
|
+
@client = SecureClient.new
|
105
|
+
@client.stubs(:client).returns(stub(:token => 'toke', :secret => 'secret'))
|
106
|
+
end
|
107
|
+
|
108
|
+
should "know the access token" do
|
109
|
+
@client.access_token.should == 'toke'
|
110
|
+
end
|
111
|
+
|
112
|
+
should "know the access_secret" do
|
113
|
+
@client.access_secret.should == 'secret'
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
should "delegate :get to :client" do
|
118
|
+
url = 'http://etsy.com/'
|
119
|
+
|
120
|
+
oauth_client = stub()
|
121
|
+
oauth_client.stubs(:get).with(url).returns('something')
|
122
|
+
|
123
|
+
client = SecureClient.new
|
124
|
+
client.stubs(:client).returns(oauth_client)
|
125
|
+
|
126
|
+
client.get(url).should == 'something'
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
130
|
+
|
131
|
+
end
|
132
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require File.expand_path('../../../test_helper', __FILE__)
|
2
|
+
|
3
|
+
module Etsy
|
4
|
+
class ShippingTemplateTest < Test::Unit::TestCase
|
5
|
+
context "An instance of the ShippingTemplate class" do
|
6
|
+
setup do
|
7
|
+
data = read_fixture('shipping_template/getShippingTemplate.json')
|
8
|
+
@shipping_template = ShippingTemplate.new(data.first)
|
9
|
+
end
|
10
|
+
|
11
|
+
should "have an id" do
|
12
|
+
@shipping_template.id.should == 212
|
13
|
+
end
|
14
|
+
|
15
|
+
should "have an title" do
|
16
|
+
@shipping_template.title.should == "Small Items"
|
17
|
+
end
|
18
|
+
|
19
|
+
should "have an user_id" do
|
20
|
+
@shipping_template.user_id.should == 14888443
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
require File.expand_path('../../../test_helper', __FILE__)
|
2
|
+
|
3
|
+
module Etsy
|
4
|
+
class ShopTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
context "The Shop class" do
|
7
|
+
|
8
|
+
should "be able to find a single shop" do
|
9
|
+
shops = mock_request('/shops/littletjane', {}, 'Shop', 'getShop.single.json')
|
10
|
+
Shop.find('littletjane').should == shops.first
|
11
|
+
end
|
12
|
+
|
13
|
+
should "be able to find multiple shops" do
|
14
|
+
shops = mock_request('/shops/littletjane,reagent', {}, 'Shop', 'getShop.multiple.json')
|
15
|
+
Shop.find('littletjane', 'reagent').should == shops
|
16
|
+
end
|
17
|
+
|
18
|
+
should "be able to find all shops" do
|
19
|
+
shops = mock_request('/shops', {}, 'Shop', 'findAllShop.json')
|
20
|
+
Shop.all.should == shops
|
21
|
+
end
|
22
|
+
|
23
|
+
should "return an array of shops if there is only 1 result returned" do
|
24
|
+
shops = mock_request('/shops', {}, 'Shop', 'findAllShop.single.json')
|
25
|
+
Shop.all.should == shops
|
26
|
+
end
|
27
|
+
|
28
|
+
should "allow a configurable limit when finding all shops" do
|
29
|
+
shops = mock_request('/shops', {:limit => 100, :offset => 0}, 'Shop', 'findAllShop.json')
|
30
|
+
Shop.all(:limit => 100).should == shops
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
context "An instance of the Shop class" do
|
36
|
+
|
37
|
+
context "with response data" do
|
38
|
+
setup do
|
39
|
+
data = read_fixture('shop/getShop.single.json')
|
40
|
+
@shop = Shop.new(data.first)
|
41
|
+
end
|
42
|
+
|
43
|
+
should "have a value for :id" do
|
44
|
+
@shop.id.should == 5500349
|
45
|
+
end
|
46
|
+
|
47
|
+
should "have a value for :user_id" do
|
48
|
+
@shop.user_id.should == 5327518
|
49
|
+
end
|
50
|
+
|
51
|
+
should "have a value for :image_url" do
|
52
|
+
@shop.image_url.should == "http://ny-image3.etsy.com/iusb_760x100.8484779.jpg"
|
53
|
+
end
|
54
|
+
|
55
|
+
should "have a value for :url" do
|
56
|
+
@shop.url.should == "http://www.etsy.com/shop/littletjane"
|
57
|
+
end
|
58
|
+
|
59
|
+
should "have a value for :favorers_count" do
|
60
|
+
@shop.favorers_count.should == 684
|
61
|
+
end
|
62
|
+
|
63
|
+
should "have a value for :active_listings_count" do
|
64
|
+
@shop.active_listings_count.should == 0
|
65
|
+
end
|
66
|
+
|
67
|
+
should "have a value for :updated_at" do
|
68
|
+
@shop.updated_at.should == Time.at(1274923984)
|
69
|
+
end
|
70
|
+
|
71
|
+
should "have a value for :created_at" do
|
72
|
+
@shop.created_at.should == Time.at(1237430331)
|
73
|
+
end
|
74
|
+
|
75
|
+
should "have a value for :name" do
|
76
|
+
@shop.name.should == "littletjane"
|
77
|
+
end
|
78
|
+
|
79
|
+
should "have a value for :title" do
|
80
|
+
@shop.title.should == "a cute and crafty mix of handmade goods."
|
81
|
+
end
|
82
|
+
|
83
|
+
should "have a value for :message" do
|
84
|
+
@shop.message.should == "thanks!"
|
85
|
+
end
|
86
|
+
|
87
|
+
should "have a value for :announcement" do
|
88
|
+
@shop.announcement.should == "announcement"
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
should "have a collection of listings" do
|
94
|
+
shop = Shop.new
|
95
|
+
shop.stubs(:id).with().returns(1)
|
96
|
+
|
97
|
+
Listing.stubs(:find_all_by_shop_id).with(1, {}).returns('listings')
|
98
|
+
|
99
|
+
shop.listings.should == 'listings'
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require File.expand_path('../../../test_helper', __FILE__)
|
2
|
+
|
3
|
+
module Etsy
|
4
|
+
class TransactionTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
context "The Transaction class" do
|
7
|
+
|
8
|
+
should "be able to find transactions for a shop" do
|
9
|
+
transactions = mock_request('/shops/1/transactions', {'key' => 'value'}, 'Transaction', 'findAllShopTransactions.json')
|
10
|
+
Transaction.find_all_by_shop_id(1, {'key' => 'value'}).should == transactions
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
context "An instance of the Transaction class" do
|
16
|
+
|
17
|
+
context "with response data" do
|
18
|
+
setup do
|
19
|
+
data = read_fixture('transaction/findAllShopTransactions.json')
|
20
|
+
@transaction = Transaction.new(data.first)
|
21
|
+
end
|
22
|
+
|
23
|
+
should "have a value for :id" do
|
24
|
+
@transaction.id.should == 27230877
|
25
|
+
end
|
26
|
+
|
27
|
+
should "have a value for :quantity" do
|
28
|
+
@transaction.quantity.should == 1
|
29
|
+
end
|
30
|
+
|
31
|
+
should "have a value for :buyer_id" do
|
32
|
+
@transaction.buyer_id.should == 9641557
|
33
|
+
end
|
34
|
+
|
35
|
+
should "have a value for :listing_id" do
|
36
|
+
@transaction.listing_id.should == 41680579
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
should "know the buyer" do
|
41
|
+
User.stubs(:find).with(1).returns('user')
|
42
|
+
|
43
|
+
transaction = Transaction.new
|
44
|
+
transaction.stubs(:buyer_id).with().returns(1)
|
45
|
+
|
46
|
+
transaction.buyer.should == 'user'
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,218 @@
|
|
1
|
+
require File.expand_path('../../../test_helper', __FILE__)
|
2
|
+
|
3
|
+
module Etsy
|
4
|
+
class UserTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
context "The User class" do
|
7
|
+
|
8
|
+
should "be able to find a single user" do
|
9
|
+
users = mock_request('/users/littletjane', {}, 'User', 'getUser.single.json')
|
10
|
+
User.find('littletjane').should == users.first
|
11
|
+
end
|
12
|
+
|
13
|
+
should "be able to find multiple users" do
|
14
|
+
users = mock_request('/users/littletjane,reagent', {}, 'User', 'getUser.multiple.json')
|
15
|
+
User.find('littletjane', 'reagent').should == users
|
16
|
+
end
|
17
|
+
|
18
|
+
should "be able to pass options when finding a user" do
|
19
|
+
options = {:limit => 90, :offset => 90}
|
20
|
+
users = mock_request('/users/littletjane', options, 'User', 'getUser.single.json')
|
21
|
+
User.find('littletjane', options).should == users.first
|
22
|
+
end
|
23
|
+
|
24
|
+
should "be able to find the authenticated user" do
|
25
|
+
options = {:access_token => 'token', :access_secret => 'secret'}
|
26
|
+
users = mock_request('/users/__SELF__', options, 'User', 'getUser.single.json')
|
27
|
+
User.myself('token', 'secret', options).should == users.first
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context "An instance of the User class" do
|
32
|
+
|
33
|
+
context "requested with oauth access token" do
|
34
|
+
setup do
|
35
|
+
options = {:access_token => 'token', :access_secret => 'secret'}
|
36
|
+
|
37
|
+
data = read_fixture('user/getUser.single.json')
|
38
|
+
response = 'response'
|
39
|
+
response.stubs(:result).with().returns [data]
|
40
|
+
Request.stubs(:get).with('/users/__SELF__', options).returns response
|
41
|
+
|
42
|
+
@user = User.find('__SELF__', options)
|
43
|
+
end
|
44
|
+
|
45
|
+
should "persist the token" do
|
46
|
+
@user.token.should == 'token'
|
47
|
+
end
|
48
|
+
|
49
|
+
should "persist the secret" do
|
50
|
+
@user.secret.should == 'secret'
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context "with public response data" do
|
55
|
+
setup do
|
56
|
+
data = read_fixture('user/getUser.single.json')
|
57
|
+
@user = User.new(data.first)
|
58
|
+
end
|
59
|
+
|
60
|
+
should "have an ID" do
|
61
|
+
@user.id.should == 5327518
|
62
|
+
end
|
63
|
+
|
64
|
+
should "have a :username" do
|
65
|
+
@user.username.should == 'littletjane'
|
66
|
+
end
|
67
|
+
|
68
|
+
should "have a value for :created" do
|
69
|
+
@user.created.should == 1191381578
|
70
|
+
end
|
71
|
+
|
72
|
+
should "not have an email address" do
|
73
|
+
@user.email.should be_nil
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
context "with private response data" do
|
78
|
+
setup do
|
79
|
+
data = read_fixture('user/getUser.single.private.json')
|
80
|
+
@user = User.new(data.first, 'token', 'secret')
|
81
|
+
end
|
82
|
+
|
83
|
+
should "have an email address" do
|
84
|
+
@user.email.should == 'reaganpr@gmail.com'
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
context "requested with associated shops" do
|
89
|
+
setup do
|
90
|
+
data = read_fixture('user/getUser.single.withShops.json')
|
91
|
+
@user = User.new(data.first)
|
92
|
+
end
|
93
|
+
|
94
|
+
should "have shops" do
|
95
|
+
@user.shops.each do |shop|
|
96
|
+
shop.class.should == Shop
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
# This assumes for now that a user can have only one shop belonging to them
|
101
|
+
should "return the first shop belonging to the user" do
|
102
|
+
@user.shop.should == @user.shops.first
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
context "requested without associated shops" do
|
107
|
+
setup do
|
108
|
+
@data_without_shops = read_fixture('user/getUser.single.json')
|
109
|
+
@data_with_shops = read_fixture('user/getUser.single.withShops.json')
|
110
|
+
@options = {:fields => 'user_id', :includes => 'Shops'}
|
111
|
+
|
112
|
+
@user_without_shops = User.new(@data_without_shops.first)
|
113
|
+
@user_with_shops = User.new(@data_with_shops.first)
|
114
|
+
end
|
115
|
+
|
116
|
+
should "make a call to the API to retrieve it if requested" do
|
117
|
+
User.expects(:find).with('littletjane', @options).returns @user_with_shops
|
118
|
+
@user_without_shops.shops
|
119
|
+
end
|
120
|
+
|
121
|
+
should "not call the api twice" do
|
122
|
+
User.expects(:find).once.with('littletjane', @options).returns @user_with_shops
|
123
|
+
@user_without_shops.shops
|
124
|
+
@user_without_shops.shops
|
125
|
+
end
|
126
|
+
|
127
|
+
should "return a list of populated shop instances" do
|
128
|
+
User.stubs(:find).with('littletjane', @options).returns @user_with_shops
|
129
|
+
@user_without_shops.shops.first.name.should == 'LittleJane'
|
130
|
+
end
|
131
|
+
|
132
|
+
should "make the call with authentication if oauth is used" do
|
133
|
+
user = User.new(@data_without_shops.first, 'token', 'secret')
|
134
|
+
oauth = {:access_token => 'token', :access_secret => 'secret'}
|
135
|
+
User.expects(:find).with('littletjane', @options.merge(oauth)).returns @user_with_shops
|
136
|
+
user.shops
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
context "requested with an associated profile" do
|
141
|
+
setup do
|
142
|
+
data = read_fixture('user/getUser.single.withProfile.json')
|
143
|
+
@user = User.new(data.first)
|
144
|
+
end
|
145
|
+
|
146
|
+
should "have a profile" do
|
147
|
+
@user.profile.class.should == Profile
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
context "requested without an associated profile" do
|
152
|
+
setup do
|
153
|
+
@data_without_profile = read_fixture('user/getUser.single.json')
|
154
|
+
@data_with_profile = read_fixture('user/getUser.single.withProfile.json')
|
155
|
+
@options = {:fields => 'user_id', :includes => 'Profile'}
|
156
|
+
|
157
|
+
@user_without_profile = User.new(@data_without_profile.first)
|
158
|
+
@user_with_profile = User.new(@data_with_profile.first)
|
159
|
+
end
|
160
|
+
|
161
|
+
should "make a call to the API to retrieve it if requested" do
|
162
|
+
User.expects(:find).with('littletjane', @options).returns @user_with_profile
|
163
|
+
@user_without_profile.profile
|
164
|
+
end
|
165
|
+
|
166
|
+
should "not call the api twice" do
|
167
|
+
User.expects(:find).once.with('littletjane', @options).returns @user_with_profile
|
168
|
+
@user_without_profile.profile
|
169
|
+
@user_without_profile.profile
|
170
|
+
end
|
171
|
+
|
172
|
+
should "return a populated profile instance" do
|
173
|
+
User.stubs(:find).with('littletjane', @options).returns @user_with_profile
|
174
|
+
@user_without_profile.profile.bio.should == 'I make stuff'
|
175
|
+
end
|
176
|
+
|
177
|
+
should "make the call with authentication if oauth is used" do
|
178
|
+
user = User.new(@data_without_profile.first, 'token', 'secret')
|
179
|
+
oauth = {:access_token => 'token', :access_secret => 'secret'}
|
180
|
+
User.expects(:find).with('littletjane', @options.merge(oauth)).returns @user_with_profile
|
181
|
+
user.profile
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
context "instantiated with oauth token" do
|
186
|
+
setup do
|
187
|
+
@user = User.new(nil, 'token', 'secret')
|
188
|
+
end
|
189
|
+
|
190
|
+
should "have the token" do
|
191
|
+
@user.token.should == 'token'
|
192
|
+
end
|
193
|
+
|
194
|
+
should "have the secret" do
|
195
|
+
@user.secret.should == 'secret'
|
196
|
+
end
|
197
|
+
|
198
|
+
end
|
199
|
+
|
200
|
+
should "know when the user was created" do
|
201
|
+
user = User.new
|
202
|
+
user.stubs(:created).returns(1)
|
203
|
+
|
204
|
+
user.created_at.should == Time.at(1)
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
should "know the addresses for a user" do
|
209
|
+
user = User.new
|
210
|
+
user.stubs(:username).with().returns('username')
|
211
|
+
|
212
|
+
Address.stubs(:find).with('username', {}).returns('addresses')
|
213
|
+
|
214
|
+
user.addresses.should == 'addresses'
|
215
|
+
end
|
216
|
+
|
217
|
+
end
|
218
|
+
end
|