cardmagic-etsy 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/.travis.yml +13 -0
- data/Gemfile +11 -0
- data/LICENSE +9 -0
- data/README.md +348 -0
- data/Rakefile +12 -0
- data/etsy.gemspec +34 -0
- data/lib/etsy.rb +223 -0
- data/lib/etsy/about.rb +15 -0
- data/lib/etsy/address.rb +47 -0
- data/lib/etsy/attribute_value.rb +46 -0
- data/lib/etsy/basic_client.rb +32 -0
- data/lib/etsy/category.rb +84 -0
- data/lib/etsy/country.rb +27 -0
- data/lib/etsy/favorite_listing.rb +26 -0
- data/lib/etsy/image.rb +44 -0
- data/lib/etsy/listing.rb +296 -0
- data/lib/etsy/model.rb +127 -0
- data/lib/etsy/payment_template.rb +33 -0
- data/lib/etsy/profile.rb +49 -0
- data/lib/etsy/receipt.rb +37 -0
- data/lib/etsy/request.rb +150 -0
- data/lib/etsy/response.rb +128 -0
- data/lib/etsy/section.rb +16 -0
- data/lib/etsy/secure_client.rb +131 -0
- data/lib/etsy/shipping_info.rb +27 -0
- data/lib/etsy/shipping_template.rb +41 -0
- data/lib/etsy/shop.rb +88 -0
- data/lib/etsy/transaction.rb +29 -0
- data/lib/etsy/user.rb +109 -0
- data/lib/etsy/variation/property_set.rb +71 -0
- data/lib/etsy/verification_request.rb +17 -0
- data/lib/etsy/version.rb +3 -0
- data/test/fixtures/about/getAbout.json +16 -0
- data/test/fixtures/address/getUserAddresses.json +12 -0
- data/test/fixtures/attribute_value/findAllListingPropertyValues.json +44 -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/favorite_listing/findAllFavoriteListings.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.includeImages.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/receipt/findAllShopReceipts.json +28 -0
- data/test/fixtures/section/getShopSection.json +18 -0
- data/test/fixtures/shipping_info/getShippingInfo.json +1 -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 +34 -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 +45 -0
- data/test/unit/etsy/address_test.rb +61 -0
- data/test/unit/etsy/attribute_value_test.rb +67 -0
- data/test/unit/etsy/basic_client_test.rb +30 -0
- data/test/unit/etsy/category_test.rb +106 -0
- data/test/unit/etsy/country_test.rb +64 -0
- data/test/unit/etsy/favorite_listing_test.rb +44 -0
- data/test/unit/etsy/image_test.rb +51 -0
- data/test/unit/etsy/listing_test.rb +268 -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/receipt_test.rb +107 -0
- data/test/unit/etsy/request_test.rb +190 -0
- data/test/unit/etsy/response_test.rb +175 -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_info_test.rb +24 -0
- data/test/unit/etsy/shipping_template_test.rb +24 -0
- data/test/unit/etsy/shop_about_test.rb +43 -0
- data/test/unit/etsy/shop_test.rb +116 -0
- data/test/unit/etsy/transaction_test.rb +61 -0
- data/test/unit/etsy/user_test.rb +250 -0
- data/test/unit/etsy/verification_request_test.rb +26 -0
- data/test/unit/etsy_test.rb +173 -0
- metadata +293 -0
@@ -0,0 +1,67 @@
|
|
1
|
+
require File.expand_path('../../../test_helper', __FILE__)
|
2
|
+
|
3
|
+
module Etsy
|
4
|
+
class AttributeValueTest < Test::Unit::TestCase
|
5
|
+
context 'The AttributeValue class' do
|
6
|
+
context 'without oauth' do
|
7
|
+
should 'be able to find all images for a listing' do
|
8
|
+
property_values = mock_request(
|
9
|
+
'/listings/1/attributes',
|
10
|
+
{},
|
11
|
+
'AttributeValue',
|
12
|
+
'findAllListingPropertyValues.json'
|
13
|
+
)
|
14
|
+
AttributeValue.find_all_by_listing_id(1, {}).should == property_values
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'with options' do
|
19
|
+
should 'be able to find all property_values for a listing with options in request' do
|
20
|
+
property_values = mock_request(
|
21
|
+
'/listings/1/attributes',
|
22
|
+
{ foo: 'bar' },
|
23
|
+
'AttributeValue',
|
24
|
+
'findAllListingPropertyValues.json'
|
25
|
+
)
|
26
|
+
AttributeValue.find_all_by_listing_id(1, foo: 'bar').should == property_values
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'An instance of the AttributeValue class' do
|
32
|
+
context 'with response data' do
|
33
|
+
setup do
|
34
|
+
data = read_fixture('attribute_value/findAllListingPropertyValues.json')
|
35
|
+
@primary_color = AttributeValue.new(data[0])
|
36
|
+
@secondary_color = AttributeValue.new(data[1])
|
37
|
+
@height = AttributeValue.new(data[2])
|
38
|
+
@width = AttributeValue.new(data[3])
|
39
|
+
end
|
40
|
+
|
41
|
+
should 'have a value for :scale_name for width' do
|
42
|
+
@width.scale_name.should == 'Inches'
|
43
|
+
end
|
44
|
+
|
45
|
+
should 'have a value for :scale_id for width' do
|
46
|
+
@width.scale_id.should == 5
|
47
|
+
end
|
48
|
+
|
49
|
+
should 'have a value for :scale_name for height' do
|
50
|
+
@height.scale_name.should == 'Inches'
|
51
|
+
end
|
52
|
+
|
53
|
+
should 'have a value for :scale_id for height' do
|
54
|
+
@height.scale_id.should == 5
|
55
|
+
end
|
56
|
+
|
57
|
+
should 'have an array of :values with color name for primary_color' do
|
58
|
+
@primary_color.values.should == ['Beige']
|
59
|
+
end
|
60
|
+
|
61
|
+
should 'have an array of :values with color name for secondary_color' do
|
62
|
+
@secondary_color.values.should == ['Black']
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require File.expand_path('../../../test_helper', __FILE__)
|
2
|
+
|
3
|
+
module Etsy
|
4
|
+
class BasicClientTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
context "An instance of the BasicClient class" do
|
7
|
+
|
8
|
+
should "be able to construct a client" do
|
9
|
+
Etsy.stubs(:host).returns 'example.com'
|
10
|
+
Etsy.stubs(:protocol).returns 'http'
|
11
|
+
client = BasicClient.new
|
12
|
+
Net::HTTP.stubs(:new).with('example.com', 80).returns('client')
|
13
|
+
|
14
|
+
client.client.should == 'client'
|
15
|
+
end
|
16
|
+
|
17
|
+
should "be able to perform a GET request" do
|
18
|
+
http_client = stub()
|
19
|
+
http_client.stubs(:get).with('endpoint').returns('response')
|
20
|
+
|
21
|
+
client = BasicClient.new
|
22
|
+
client.stubs(:client).returns(http_client)
|
23
|
+
|
24
|
+
client.get('endpoint').should == 'response'
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,106 @@
|
|
1
|
+
require File.expand_path('../../../test_helper', __FILE__)
|
2
|
+
|
3
|
+
module Etsy
|
4
|
+
class CategoryTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
context "The Category class" do
|
7
|
+
|
8
|
+
should "be able to find a single top-level category" do
|
9
|
+
categories = mock_request('/categories/accessories', {}, 'Category', 'getCategory.single.json')
|
10
|
+
Category.find_top('accessories').should == categories.first
|
11
|
+
end
|
12
|
+
|
13
|
+
should "be able to find multiple categories" do
|
14
|
+
categories = mock_request('/categories/accessories,art', {}, 'Category', 'getCategory.multiple.json')
|
15
|
+
Category.find_top('accessories', 'art').should == categories
|
16
|
+
end
|
17
|
+
|
18
|
+
should "be able to find all top-level categories" do
|
19
|
+
categories = mock_request('/taxonomy/categories', {}, 'Category', 'findAllTopCategory.json')
|
20
|
+
Category.all_top.should == categories
|
21
|
+
end
|
22
|
+
|
23
|
+
should "return an array of categories if there is only 1 result returned" do
|
24
|
+
categories = mock_request('/taxonomy/categories', {}, 'Category', 'findAllTopCategory.single.json')
|
25
|
+
Category.all_top.should == categories
|
26
|
+
end
|
27
|
+
|
28
|
+
context "within the scope of a top-level category" do
|
29
|
+
|
30
|
+
should "be able to find all subcategories" do
|
31
|
+
categories = mock_request('/taxonomy/categories/accessories', {}, 'Category', 'findAllTopCategoryChildren.json')
|
32
|
+
Category.find_all_subcategories('accessories').should == categories
|
33
|
+
end
|
34
|
+
|
35
|
+
should "be able to find the subcategories of a subcategory" do
|
36
|
+
categories = mock_request('/taxonomy/categories/accessories/apron', {}, 'Category', 'findAllSubCategoryChildren.json')
|
37
|
+
Category.find_all_subcategories('accessories/apron').should == categories
|
38
|
+
end
|
39
|
+
|
40
|
+
should "return nil when trying to find the subcategories of a subcategory of a subcategory" do
|
41
|
+
Category.find_all_subcategories('accessories/apron/women').should be_nil
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
context "An instance of the Category class" do
|
49
|
+
|
50
|
+
context "with response data" do
|
51
|
+
setup do
|
52
|
+
data = read_fixture('category/getCategory.single.json')
|
53
|
+
@category = Category.new(data.first)
|
54
|
+
end
|
55
|
+
|
56
|
+
should "have a value for :id" do
|
57
|
+
@category.id.should == 69150467
|
58
|
+
end
|
59
|
+
|
60
|
+
should "have a value for :page_description" do
|
61
|
+
@category.page_description.should == "Shop for unique, handmade accessories from our artisan community"
|
62
|
+
end
|
63
|
+
|
64
|
+
should "have a value for :page_title" do
|
65
|
+
@category.page_title.should == "Handmade accessories"
|
66
|
+
end
|
67
|
+
|
68
|
+
should "have a value for :category_name" do
|
69
|
+
@category.category_name.should == "accessories"
|
70
|
+
end
|
71
|
+
|
72
|
+
should "have a value for :short_name" do
|
73
|
+
@category.short_name.should == "Accessories"
|
74
|
+
end
|
75
|
+
|
76
|
+
should "have a value for :long_name" do
|
77
|
+
@category.long_name.should == "Accessories"
|
78
|
+
end
|
79
|
+
|
80
|
+
should "have a value for :children_count" do
|
81
|
+
@category.children_count.should == 27
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
should "have a collection of active listings" do
|
86
|
+
category = Category.new
|
87
|
+
category.stubs(:category_name).with().returns('accessories')
|
88
|
+
|
89
|
+
Listing.stubs(:find_all_active_by_category).with('accessories').returns('listings')
|
90
|
+
|
91
|
+
category.active_listings.should == 'listings'
|
92
|
+
end
|
93
|
+
|
94
|
+
should "have a collection of subcategories" do
|
95
|
+
category = Category.new
|
96
|
+
category.stubs(:category_name).with().returns('accessories')
|
97
|
+
|
98
|
+
Category.stubs(:find_all_subcategories).with('accessories').returns('categories')
|
99
|
+
|
100
|
+
category.subcategories.should == 'categories'
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
106
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require File.expand_path('../../../test_helper', __FILE__)
|
2
|
+
|
3
|
+
module Etsy
|
4
|
+
class CountryTest < Test::Unit::TestCase
|
5
|
+
context "The Country class" do
|
6
|
+
should "be findable by ISO3166-1 Alpha-2 codes" do
|
7
|
+
united_states = mock
|
8
|
+
united_states.stubs(:iso_country_code => "US")
|
9
|
+
|
10
|
+
great_britain = mock
|
11
|
+
great_britain.stubs(:iso_country_code => "GB")
|
12
|
+
|
13
|
+
Country.stubs(:find_all).returns([great_britain, united_states])
|
14
|
+
Country.find_by_alpha2("us").should == united_states
|
15
|
+
end
|
16
|
+
|
17
|
+
should "be findable by world bank country codes" do
|
18
|
+
united_states = mock
|
19
|
+
united_states.stubs(:world_bank_country_code => "USA")
|
20
|
+
|
21
|
+
great_britain = mock
|
22
|
+
great_britain.stubs(:world_bank_country_code => "GBR")
|
23
|
+
|
24
|
+
Country.stubs(:find_all).returns([great_britain, united_states])
|
25
|
+
Country.find_by_world_bank_country_code("gbr").should == great_britain
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context "An instance of the Country class" do
|
30
|
+
setup do
|
31
|
+
data = read_fixture('country/getCountry.json')
|
32
|
+
@listing = Country.new(data.first)
|
33
|
+
end
|
34
|
+
|
35
|
+
should "have an id" do
|
36
|
+
@listing.id.should == 55
|
37
|
+
end
|
38
|
+
|
39
|
+
should "have an iso_country_code" do
|
40
|
+
@listing.iso_country_code.should == "AF"
|
41
|
+
end
|
42
|
+
|
43
|
+
should "have an world_bank_country_code" do
|
44
|
+
@listing.world_bank_country_code.should == "AFG"
|
45
|
+
end
|
46
|
+
|
47
|
+
should "have an name" do
|
48
|
+
@listing.name.should == "Afghanistan"
|
49
|
+
end
|
50
|
+
|
51
|
+
should "have an slug" do
|
52
|
+
@listing.slug.should == "afghanistan"
|
53
|
+
end
|
54
|
+
|
55
|
+
should "have an lat" do
|
56
|
+
@listing.lat.should == 33.78
|
57
|
+
end
|
58
|
+
|
59
|
+
should "have an lon" do
|
60
|
+
@listing.lon.should == 66.17
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require File.expand_path('../../../test_helper', __FILE__)
|
2
|
+
|
3
|
+
module Etsy
|
4
|
+
class FavoriteListingTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
context "The FavoriteListing class" do
|
7
|
+
|
8
|
+
should "be able to find favorite listings for a user" do
|
9
|
+
favorite_listings = mock_request('/users/1/favorites/listings', {'key' => 'value'}, 'FavoriteListing', 'findAllFavoriteListings.json')
|
10
|
+
FavoriteListing.find_all_user_favorite_listings(1, {'key' => 'value'}).should == favorite_listings
|
11
|
+
end
|
12
|
+
|
13
|
+
should "be able to find favorite listings associated to a listing" do
|
14
|
+
favorite_listings = mock_request('/listings/1/favored-by', {'key' => 'value'}, 'FavoriteListing', 'findAllFavoriteListings.json')
|
15
|
+
FavoriteListing.find_all_listings_favored_by(1, {'key' => 'value'}).should == favorite_listings
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
context "An instance of the FavoriteListing class" do
|
21
|
+
|
22
|
+
context "with response data" do
|
23
|
+
setup do
|
24
|
+
data = read_fixture('favorite_listing/findAllFavoriteListings.json')
|
25
|
+
@favorite_listing = FavoriteListing.new(data.first)
|
26
|
+
end
|
27
|
+
|
28
|
+
should "have a value for :listing_id" do
|
29
|
+
@favorite_listing.listing_id.should == 27230877
|
30
|
+
end
|
31
|
+
|
32
|
+
should "have a value for :user_id" do
|
33
|
+
@favorite_listing.user_id.should == 1
|
34
|
+
end
|
35
|
+
|
36
|
+
should "have a value for :listing_state" do
|
37
|
+
@favorite_listing.listing_state.should == "active"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require File.expand_path('../../../test_helper', __FILE__)
|
2
|
+
|
3
|
+
module Etsy
|
4
|
+
class ImageTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
context "The Image class" do
|
7
|
+
|
8
|
+
context "without oauth" do
|
9
|
+
should "be able to find all images for a listing" do
|
10
|
+
images = mock_request('/listings/1/images', {}, 'Image', 'findAllListingImages.json')
|
11
|
+
Image.find_all_by_listing_id(1, {}).should == images
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context "with options" do
|
16
|
+
should "be able to find all images for a listing with options in request" do
|
17
|
+
images = mock_request('/listings/1/images', {foo: "bar"}, 'Image', 'findAllListingImages.json')
|
18
|
+
Image.find_all_by_listing_id(1, {foo: "bar"}).should == images
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context "An instance of the Image class" do
|
24
|
+
|
25
|
+
context "with response data" do
|
26
|
+
setup do
|
27
|
+
data = read_fixture('image/findAllListingImages.json')
|
28
|
+
@image = Image.new(data.first)
|
29
|
+
end
|
30
|
+
|
31
|
+
should "have a value for :square" do
|
32
|
+
@image.square.should == "http://ny-image0.etsy.com/il_75x75.185073072.jpg"
|
33
|
+
end
|
34
|
+
|
35
|
+
should "have a value for :small" do
|
36
|
+
@image.small.should == "http://ny-image0.etsy.com/il_170x135.185073072.jpg"
|
37
|
+
end
|
38
|
+
|
39
|
+
should "have a value for :thumbnail" do
|
40
|
+
@image.thumbnail.should == "http://ny-image0.etsy.com/il_570xN.185073072.jpg"
|
41
|
+
end
|
42
|
+
|
43
|
+
should "have a value for :full" do
|
44
|
+
@image.full.should == "http://ny-image0.etsy.com/il_fullxfull.185073072.jpg"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,268 @@
|
|
1
|
+
require File.expand_path('../../../test_helper', __FILE__)
|
2
|
+
|
3
|
+
module Etsy
|
4
|
+
class ListingTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
context "The Listing class" do
|
7
|
+
|
8
|
+
should "be able to find a single listing" do
|
9
|
+
listings = mock_request('/listings/123', {}, 'Listing', 'getListing.single.json')
|
10
|
+
Listing.find(123).should == listings.first
|
11
|
+
end
|
12
|
+
|
13
|
+
should "be able to find multiple listings" do
|
14
|
+
listings = mock_request('/listings/123,456', {}, 'Listing', 'getListing.multiple.json')
|
15
|
+
Listing.find('123', '456').should == listings
|
16
|
+
end
|
17
|
+
|
18
|
+
context "within the scope of a shop" do
|
19
|
+
|
20
|
+
should "be able to find the first 25 active listings" do
|
21
|
+
listings = mock_request('/shops/1/listings/active', {}, 'Listing', 'findAllShopListings.json')
|
22
|
+
Listing.find_all_by_shop_id(1).should == listings
|
23
|
+
end
|
24
|
+
|
25
|
+
should "be able to find expired listings" do
|
26
|
+
listings = mock_request('/shops/1/listings/expired', {}, 'Listing', 'findAllShopListings.json')
|
27
|
+
Listing.find_all_by_shop_id(1, :state => :expired).should == listings
|
28
|
+
end
|
29
|
+
|
30
|
+
should "be able to find inactive listings" do
|
31
|
+
listings = mock_request('/shops/1/listings/inactive', {}, 'Listing', 'findAllShopListings.json')
|
32
|
+
Listing.find_all_by_shop_id(1, :state => :inactive).should == listings
|
33
|
+
end
|
34
|
+
|
35
|
+
should "be able to find draft listings" do
|
36
|
+
listings = mock_request('/shops/1/listings/draft', {}, 'Listing', 'findAllShopListings.json')
|
37
|
+
Listing.find_all_by_shop_id(1, :state => :draft).should == listings
|
38
|
+
end
|
39
|
+
|
40
|
+
should "be able to find sold_out listings" do
|
41
|
+
listings = mock_request('/shops/1/listings/sold_out', {}, 'Listing', 'findAllShopListings.json')
|
42
|
+
Listing.find_all_by_shop_id(1, :state => :sold_out).should == listings
|
43
|
+
end
|
44
|
+
|
45
|
+
should "be able to find featured listings" do
|
46
|
+
listings = mock_request('/shops/1/listings/featured', {}, 'Listing', 'findAllShopListings.json')
|
47
|
+
Listing.find_all_by_shop_id(1, :state => :featured).should == listings
|
48
|
+
end
|
49
|
+
|
50
|
+
should "be able to find sold listings" do
|
51
|
+
transaction_1 = stub(:listing_id => 1)
|
52
|
+
transaction_2 = stub(:listing_id => 2)
|
53
|
+
transaction_3 = stub(:listing_id => 1)
|
54
|
+
|
55
|
+
transactions = [transaction_1, transaction_2, transaction_3]
|
56
|
+
|
57
|
+
Transaction.stubs(:find_all_by_shop_id).with(1, {}).returns(transactions)
|
58
|
+
Listing.stubs(:find).with([1, 2], {}).returns(['listings'])
|
59
|
+
|
60
|
+
Listing.find_all_by_shop_id(1, :state => :sold).should == ['listings']
|
61
|
+
end
|
62
|
+
|
63
|
+
should "defer associations to listings from transaction (sold listings)" do
|
64
|
+
transaction_1 = stub(:listing_id => 1)
|
65
|
+
transaction_2 = stub(:listing_id => 2)
|
66
|
+
|
67
|
+
Transaction.stubs(:find_all_by_shop_id).with(1, {}).returns [transaction_1, transaction_2]
|
68
|
+
Listing.stubs(:find).with([1, 2], {:includes => :an_association}).returns(['listings'])
|
69
|
+
|
70
|
+
Listing.find_all_by_shop_id(1, :state => :sold, :includes => :an_association).should == ['listings']
|
71
|
+
end
|
72
|
+
|
73
|
+
should "pass options through to the listing call" do
|
74
|
+
transaction_1 = stub(:listing_id => 1)
|
75
|
+
transaction_2 = stub(:listing_id => 2)
|
76
|
+
|
77
|
+
Transaction.stubs(:find_all_by_shop_id).with(1, {:other => :params}).returns [transaction_1, transaction_2]
|
78
|
+
Listing.stubs(:find).with([1, 2], {:other => :params}).returns(['listings'])
|
79
|
+
|
80
|
+
Listing.find_all_by_shop_id(1, :state => :sold, :other => :params).should == ['listings']
|
81
|
+
|
82
|
+
end
|
83
|
+
|
84
|
+
should "not ask the API for listings if there are no transactions" do
|
85
|
+
Transaction.stubs(:find_all_by_shop_id).with(1, {}).returns([])
|
86
|
+
Listing.expects(:find).never
|
87
|
+
Listing.sold_listings(1, {})
|
88
|
+
end
|
89
|
+
|
90
|
+
should "be able to override limit and offset" do
|
91
|
+
options = {:limit => 100, :offset => 100}
|
92
|
+
listings = mock_request('/shops/1/listings/active', options, 'Listing', 'findAllShopListings.json')
|
93
|
+
Listing.find_all_by_shop_id(1, options).should == listings
|
94
|
+
end
|
95
|
+
|
96
|
+
should "raise an exception when calling with an invalid state" do
|
97
|
+
options = {:state => :awesome}
|
98
|
+
lambda { Listing.find_all_by_shop_id(1, options) }.should raise_error(ArgumentError)
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
|
103
|
+
context "within the scope of a category" do
|
104
|
+
should "be able to find active listings" do
|
105
|
+
active_listings = mock_request('/listings/active', {:category => 'accessories'}, 'Listing', 'findAllListingActive.category.json')
|
106
|
+
Listing.find_all_active_by_category('accessories').should == active_listings
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
111
|
+
|
112
|
+
context "An instance of the Listing class" do
|
113
|
+
|
114
|
+
context "with response data" do
|
115
|
+
setup do
|
116
|
+
data = read_fixture('listing/findAllShopListings.json')
|
117
|
+
@listing = Listing.new(data.first)
|
118
|
+
end
|
119
|
+
|
120
|
+
should "have a value for :id" do
|
121
|
+
@listing.id.should == 59495892
|
122
|
+
end
|
123
|
+
|
124
|
+
should "have a value for :state" do
|
125
|
+
@listing.state.should == 'active'
|
126
|
+
end
|
127
|
+
|
128
|
+
should "have a value for :title" do
|
129
|
+
@listing.title.should == "initials carved into tree love stamp"
|
130
|
+
end
|
131
|
+
|
132
|
+
should "have a value for :description" do
|
133
|
+
@listing.description.should == "there! our initials are now carved deeply into this rough tree bark of memory"
|
134
|
+
end
|
135
|
+
|
136
|
+
should "have a value for :url" do
|
137
|
+
@listing.url.should == "http://www.etsy.com/listing/59495892/initials-carved-into-tree-love-stamp"
|
138
|
+
end
|
139
|
+
|
140
|
+
should "have a value for :view_count" do
|
141
|
+
@listing.view_count.should == 37
|
142
|
+
end
|
143
|
+
|
144
|
+
should "have a value for :created_at" do
|
145
|
+
@listing.created_at.should == Time.at(1287602289)
|
146
|
+
end
|
147
|
+
|
148
|
+
should "have a value for :modified_at" do
|
149
|
+
@listing.modified_at.should == Time.at(1287602289)
|
150
|
+
end
|
151
|
+
|
152
|
+
should "have a value for :price" do
|
153
|
+
@listing.price.should == "15.00"
|
154
|
+
end
|
155
|
+
|
156
|
+
should "have a value for :quantity" do
|
157
|
+
@listing.quantity.should == 1
|
158
|
+
end
|
159
|
+
|
160
|
+
should "have a value for :currency" do
|
161
|
+
@listing.currency.should == "USD"
|
162
|
+
end
|
163
|
+
|
164
|
+
should "have a value for :ending_at" do
|
165
|
+
@listing.ending_at.should == Time.at(1298178000)
|
166
|
+
end
|
167
|
+
|
168
|
+
should "have a value for :tags" do
|
169
|
+
@listing.tags.should == %w(tag_1 tag_2)
|
170
|
+
end
|
171
|
+
|
172
|
+
should "have a value for :materials" do
|
173
|
+
@listing.materials.should == %w(material_1 material_2)
|
174
|
+
end
|
175
|
+
|
176
|
+
should "have a value for :hue" do
|
177
|
+
@listing.hue.should == 0
|
178
|
+
end
|
179
|
+
|
180
|
+
should "have a value for :saturation" do
|
181
|
+
@listing.saturation.should == 0
|
182
|
+
end
|
183
|
+
|
184
|
+
should "have a value for :brightness" do
|
185
|
+
@listing.brightness.should == 100
|
186
|
+
end
|
187
|
+
|
188
|
+
should "have a value for :black_and_white?" do
|
189
|
+
@listing.black_and_white?.should == false
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
%w(active removed sold_out expired alchemy).each do |state|
|
194
|
+
should "know that the listing is #{state}" do
|
195
|
+
listing = Listing.new
|
196
|
+
listing.expects(:state).with().returns(state.sub('_', ''))
|
197
|
+
|
198
|
+
listing.send("#{state}?".to_sym).should be(true)
|
199
|
+
end
|
200
|
+
|
201
|
+
should "know that the listing is not #{state}" do
|
202
|
+
listing = Listing.new
|
203
|
+
listing.expects(:state).with().returns(state.reverse)
|
204
|
+
|
205
|
+
listing.send("#{state}?".to_sym).should be(false)
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
context "with oauth" do
|
210
|
+
should "have a collection of images" do
|
211
|
+
listing = Listing.new
|
212
|
+
listing.stubs(:id).with().returns(1)
|
213
|
+
listing.stubs(:token).with().returns("token")
|
214
|
+
listing.stubs(:secret).with().returns("secret")
|
215
|
+
|
216
|
+
Image.stubs(:find_all_by_listing_id).with(1, {access_token: "token", access_secret: "secret"}).returns('images')
|
217
|
+
|
218
|
+
listing.images.should == 'images'
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
context "without oauth" do
|
223
|
+
should "have a collection of images" do
|
224
|
+
listing = Listing.new
|
225
|
+
listing.stubs(:id).with().returns(1)
|
226
|
+
|
227
|
+
Image.stubs(:find_all_by_listing_id).with(1, {}).returns('images')
|
228
|
+
|
229
|
+
listing.images.should == 'images'
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
context "with included images" do
|
234
|
+
should "not hit the API to get images" do
|
235
|
+
data = read_fixture('listing/getListing.single.includeImages.json')
|
236
|
+
listing = Listing.new(data.first)
|
237
|
+
Request.expects(:get).never
|
238
|
+
|
239
|
+
listing.images
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
should "have a default image" do
|
244
|
+
listing = Listing.new
|
245
|
+
listing.stubs(:images).with().returns(%w(image_1 image_2))
|
246
|
+
|
247
|
+
listing.image.should == 'image_1'
|
248
|
+
end
|
249
|
+
|
250
|
+
end
|
251
|
+
|
252
|
+
context "with favorite listings data" do
|
253
|
+
setup do
|
254
|
+
data = read_fixture('listing/findAllShopListings.json')
|
255
|
+
@listing = Listing.new(data.first)
|
256
|
+
listing_1 = stub(:listing_id => @listing.id, :user_id => 1)
|
257
|
+
listing_2 = stub(:listing_id => @listing.id, :user_id => 2)
|
258
|
+
@favorite_listings = [listing_1, listing_2]
|
259
|
+
end
|
260
|
+
|
261
|
+
should "have all listings" do
|
262
|
+
FavoriteListing.stubs(:find_all_listings_favored_by).with(@listing.id, {:access_token => nil, :access_secret => nil}).returns(@favorite_listings)
|
263
|
+
User.stubs(:find).with([1, 2], {:access_token => nil, :access_secret => nil}).returns(['users'])
|
264
|
+
@listing.admirers({:access_token => nil, :access_secret => nil}).should == ['users']
|
265
|
+
end
|
266
|
+
end
|
267
|
+
end
|
268
|
+
end
|