dawanda_client 0.1.6
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 +2 -0
- data/LICENSE +22 -0
- data/README.rdoc +97 -0
- data/Rakefile +45 -0
- data/VERSION +1 -0
- data/dawanda_client.gemspec +75 -0
- data/lib/dawanda.rb +99 -0
- data/lib/dawanda/category.rb +47 -0
- data/lib/dawanda/channel.rb +26 -0
- data/lib/dawanda/color.rb +23 -0
- data/lib/dawanda/model.rb +79 -0
- data/lib/dawanda/product.rb +80 -0
- data/lib/dawanda/request.rb +56 -0
- data/lib/dawanda/response.rb +47 -0
- data/lib/dawanda/shop.rb +64 -0
- data/lib/dawanda/shop_category.rb +28 -0
- data/lib/dawanda/user.rb +60 -0
- data/test/fixtures/getCategoryDetails.json +21 -0
- data/test/fixtures/getProductDetails.json +71 -0
- data/test/fixtures/getShopDetails.json +72 -0
- data/test/fixtures/getUserDetails.json +31 -0
- data/test/test_helper.rb +53 -0
- data/test/unit/dawanda/category_test.rb +39 -0
- data/test/unit/dawanda/color_test.rb +20 -0
- data/test/unit/dawanda/product_test.rb +55 -0
- data/test/unit/dawanda/shop_category_test.rb +20 -0
- data/test/unit/dawanda/shop_test.rb +67 -0
- data/test/unit/dawanda/user_test.rb +38 -0
- data/test/unit/dawanda_test.rb +54 -0
- metadata +91 -0
@@ -0,0 +1,71 @@
|
|
1
|
+
{
|
2
|
+
"response":{
|
3
|
+
"type":"product",
|
4
|
+
"pages":1,
|
5
|
+
"entries":1,
|
6
|
+
"result":{
|
7
|
+
"product":{
|
8
|
+
"user":{
|
9
|
+
"name":"meko",
|
10
|
+
"id":13008,
|
11
|
+
"restful_path":"\/users\/13008"
|
12
|
+
},
|
13
|
+
"name":"Hoodie \"SUE\"",
|
14
|
+
"category":{
|
15
|
+
"name":"1003",
|
16
|
+
"id":418,
|
17
|
+
"restful_path":"\/categories\/418"
|
18
|
+
},
|
19
|
+
"image_colors":[
|
20
|
+
{
|
21
|
+
"green":0,
|
22
|
+
"blue":0,
|
23
|
+
"hex":"000000",
|
24
|
+
"red":0
|
25
|
+
},{
|
26
|
+
"green":205,
|
27
|
+
"blue":245,
|
28
|
+
"hex":"97cdf5",
|
29
|
+
"red":151
|
30
|
+
}
|
31
|
+
],
|
32
|
+
"price":{
|
33
|
+
"currency_code":"EUR",
|
34
|
+
"cents":6990
|
35
|
+
},
|
36
|
+
"product_url":"http:\/\/de.dawanda.com\/product\/4316882-Hoodie-SUE",
|
37
|
+
"tags":"pullover, carina, meko, Sweat, Hoodie, Karo, shabby chic",
|
38
|
+
"quantity":1,
|
39
|
+
"id":4316882,
|
40
|
+
"materials":"Baumwollmischgewebe",
|
41
|
+
"description":"Farbe: hellblau-t\u00fcrkis, cremewei\u00df, schwarz\r\n\r\nMaterial: karierter Baumwollelasthanmix, Elasticb\u00fcndchen in schwarz, Kapuzenfutter ist schwarzer BW\r\n\r\nlieferbar in den Gr\u00f6\u00dfen: S(36), M(38)\r\n\r\nLieferzeit : 10 - 14 Werktage ab Zahlungseingang (da keine Lagerware sondern Fertigung auf Bestellung)\r\n\r\nInfo: supers\u00fc\u00dfer Kapuzenpullover mit extra hochgeschlossener Kapuze, auf der Front befindet sich eine Tasche in Hosenlatz Optik, das meko Brand und die Kn\u00f6pfe runden die Sache ab!\r\n\r\n!!!BITTE LIES DIR VOR EINEM KAUF UNSERE AGB`S DURCH, UND KAUFE NUR WENN DU DAMIT EINVERSTANDEN BIST!!!\r\n\r\nPflege: Maschinenw\u00e4sche im Woll-oder Schonwaschgang bei 30\u00b0, kein Trockner, auf links b\u00fcgeln!",
|
42
|
+
"images":[
|
43
|
+
{
|
44
|
+
"image_160x120":"http:\/\/img.dawanda.com\/Product\/4316\/4316882\/listview\/1245952642-42.jpg",
|
45
|
+
"image_50x50":"http:\/\/img.dawanda.com\/Product\/4316\/4316882\/listing\/1245952642-42.jpg",
|
46
|
+
"image_100x75":"http:\/\/img.dawanda.com\/Product\/4316\/4316882\/pin\/1245952642-42.jpg",
|
47
|
+
"image_80x80":"http:\/\/img.dawanda.com\/Product\/4316\/4316882\/thumb\/1245952642-42.jpg",
|
48
|
+
"image_800x600":"http:\/\/img.dawanda.com\/Product\/4316\/4316882\/big\/1245952642-42.jpg",
|
49
|
+
"image_25x25":"http:\/\/img.dawanda.com\/Product\/4316\/4316882\/mini\/1245952642-42.jpg"
|
50
|
+
},{
|
51
|
+
"image_160x120":"http:\/\/img.dawanda.com\/Product\/4316\/4316882\/listview\/1245952877-223.jpg",
|
52
|
+
"image_50x50":"http:\/\/img.dawanda.com\/Product\/4316\/4316882\/listing\/1245952877-223.jpg",
|
53
|
+
"image_100x75":"http:\/\/img.dawanda.com\/Product\/4316\/4316882\/pin\/1245952877-223.jpg",
|
54
|
+
"image_80x80":"http:\/\/img.dawanda.com\/Product\/4316\/4316882\/thumb\/1245952877-223.jpg",
|
55
|
+
"image_800x600":"http:\/\/img.dawanda.com\/Product\/4316\/4316882\/big\/1245952877-223.jpg",
|
56
|
+
"image_25x25":"http:\/\/img.dawanda.com\/Product\/4316\/4316882\/mini\/1245952877-223.jpg"
|
57
|
+
}
|
58
|
+
],
|
59
|
+
"ending":"2010/01/27 11:12:39 +0000",
|
60
|
+
"restful_path":"\/products\/4316882",
|
61
|
+
"created_at":"2009/06/25 17:56:27 +0000",
|
62
|
+
"view_count":3769
|
63
|
+
}
|
64
|
+
},
|
65
|
+
"params":{
|
66
|
+
"format":"json",
|
67
|
+
"api_key":"foobar",
|
68
|
+
"id":"4316882"
|
69
|
+
}
|
70
|
+
}
|
71
|
+
}
|
@@ -0,0 +1,72 @@
|
|
1
|
+
{
|
2
|
+
"response": {
|
3
|
+
"type":"shop",
|
4
|
+
"pages":1,
|
5
|
+
"entries":1,
|
6
|
+
"params": {
|
7
|
+
"format":"json",
|
8
|
+
"api_key":"foobar",
|
9
|
+
"user_id":"meko"
|
10
|
+
},
|
11
|
+
"result": {
|
12
|
+
"shop": {
|
13
|
+
"is_vacation":false,
|
14
|
+
"user": {
|
15
|
+
"name":"meko",
|
16
|
+
"id":13008,
|
17
|
+
"restful_path":"\/users\/13008"
|
18
|
+
},
|
19
|
+
"name":"MEKO STORE",
|
20
|
+
"updated_at":"2009/09/29 09:58:46 +0000",
|
21
|
+
"images": [
|
22
|
+
{"banner":"http:\/\/img.dawanda.com.s3.amazonaws.com\/Shop\/1\/1592\/maxbanner\/1253807487-995.jpg"}
|
23
|
+
],
|
24
|
+
"restful_path":"\/shops\/13008",
|
25
|
+
"shop_categories": [
|
26
|
+
{
|
27
|
+
"name":"PIMP IT!",
|
28
|
+
"id":299862,
|
29
|
+
"restful_path":"\/shop_categories\/299862"
|
30
|
+
},{
|
31
|
+
"name":"NEW! LADIES",
|
32
|
+
"id":291170,
|
33
|
+
"restful_path":"\/shop_categories\/291170"
|
34
|
+
},{
|
35
|
+
"name":"NEW! GENTS",
|
36
|
+
"id":202874,
|
37
|
+
"restful_path":"\/shop_categories\/202874"
|
38
|
+
},{
|
39
|
+
"name":"Pullover\/ Shirts LADIES",
|
40
|
+
"id":151494,
|
41
|
+
"restful_path":"\/shop_categories\/151494"
|
42
|
+
},{
|
43
|
+
"name":"Kleider LADIES",
|
44
|
+
"id":144158,
|
45
|
+
"restful_path":"\/shop_categories\/144158"
|
46
|
+
},{
|
47
|
+
"name":"Accessoires LADIES",
|
48
|
+
"id":200386,
|
49
|
+
"restful_path":"\/shop_categories\/200386"
|
50
|
+
},{
|
51
|
+
"name":"GRANNYS",
|
52
|
+
"id":299402,
|
53
|
+
"restful_path":"\/shop_categories\/299402"
|
54
|
+
},{
|
55
|
+
"name":"REDUZIERT LADIES",
|
56
|
+
"id":81978,
|
57
|
+
"restful_path":"\/shop_categories\/81978"
|
58
|
+
},{
|
59
|
+
"name":"REDUZIERT GENTS",
|
60
|
+
"id":82002,
|
61
|
+
"restful_path":"\/shop_categories\/82002"
|
62
|
+
},{
|
63
|
+
"name":"meko real",
|
64
|
+
"id":198326,
|
65
|
+
"restful_path":"\/shop_categories\/198326"
|
66
|
+
}
|
67
|
+
],
|
68
|
+
"created_at":"2007/05/18 10:44:17 +0000"
|
69
|
+
}
|
70
|
+
}
|
71
|
+
}
|
72
|
+
}
|
@@ -0,0 +1,31 @@
|
|
1
|
+
{
|
2
|
+
"response": {
|
3
|
+
"type":"user",
|
4
|
+
"pages":1,
|
5
|
+
"entries":1,
|
6
|
+
"result": {
|
7
|
+
"user": {
|
8
|
+
"city":"auma",
|
9
|
+
"name":"meko",
|
10
|
+
"is_seller":true,
|
11
|
+
"id":13008,
|
12
|
+
"transaction_sold_count":4854,
|
13
|
+
"sex":"female",
|
14
|
+
"images":[
|
15
|
+
{
|
16
|
+
"image_170x":"http:\/\/img.dawanda.com.s3.amazonaws.com\/User\/13\/13008\/full\/1212498265-100.jpg",
|
17
|
+
"image_40x40":"http:\/\/img.dawanda.com.s3.amazonaws.com\/User\/13\/13008\/mini_avatar\/1212498265-100.jpg",
|
18
|
+
"image_80x80":"http:\/\/img.dawanda.com.s3.amazonaws.com\/User\/13\/13008\/avatar\/1212498265-100.jpg"
|
19
|
+
}
|
20
|
+
],
|
21
|
+
"bio":"<p>2006 wurde aus meinem Namen mein Leben: meko.\n \n<br>Mit der Ambition Menschen an meiner Leidenschaft, der Herstellung von Mode,teilhaben zu lassen, gr\u00fcndete ich nach abgeschlossenem Modedesign-Studium eine Plattform auf der ich Kreativit\u00e4t, Individualit\u00e4t und Leidenschaft verbinde. \n\n<br>Die Inspiration? Die urbane Vielfalt Berlin`s (meiner Lieblingsstadt und Schwerpunkt meiner Diplomarbeit), und das bunte Leben an sich. \n\n<br>Die Herstellung der Sachen liegt von Anfang bis Ende in meiner Hand: vom handbezogenen Stoffknopf, \u00fcber das Erstellen und Aufbringen des Brands bis hin zum Design\/ Schnitterstellung und N\u00e4hen der Kollektionsteile. All dies findet in meinem kleinen Atelier in Th\u00fcringen statt. \n\n<br>Dies ist ein Garant daf\u00fcr, dass es sich um reine, mit viel Liebe hergestellte Einzelst\u00fccke und Kleinstserien mit Aversion zur Massenware handelt. Wer das Besondere sucht wird hier f\u00fcndig. Der Focus liegt dabei auf der Authentizit\u00e4t von meko durch die N\u00e4he zum potenziellen Tr\u00e4ger...DIR!? \n\n<br>Also viel Spa\u00df beim schm\u00f6ckern, suchen und finden! \n\n<br>Mehr \u00fcber meko unter: \n\n<br>www.meko-clothing.de oder www.myspace.com\/mekoclothing <\/p>",
|
22
|
+
"restful_path":"\/users\/13008"
|
23
|
+
}
|
24
|
+
},
|
25
|
+
"params": {
|
26
|
+
"format":"json",
|
27
|
+
"api_key":"foobar",
|
28
|
+
"id":"meko"
|
29
|
+
}
|
30
|
+
}
|
31
|
+
}
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# http://sneaq.net/textmate-wtf
|
2
|
+
$:.reject! { |e| e.include? 'TextMate' }
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
require 'throat_punch'
|
6
|
+
|
7
|
+
require File.dirname(__FILE__) + '/../lib/dawanda'
|
8
|
+
|
9
|
+
class Test::Unit::TestCase
|
10
|
+
|
11
|
+
def self.read_fixture(method_name)
|
12
|
+
file = File.dirname(__FILE__) + "/fixtures/#{method_name}.json"
|
13
|
+
JSON.parse(File.read(file))['response']['result']
|
14
|
+
end
|
15
|
+
|
16
|
+
def read_fixture(method_name)
|
17
|
+
self.class.read_fixture(method_name)
|
18
|
+
end
|
19
|
+
|
20
|
+
def mock_request_cycle(options)
|
21
|
+
response = Dawanda::Response.new(stub())
|
22
|
+
|
23
|
+
data = read_fixture(options[:data])
|
24
|
+
data = data.first if data.size == 1
|
25
|
+
|
26
|
+
response.stubs(:result).with().returns(data)
|
27
|
+
Dawanda::Request.stubs(:get).with(options[:for], {}).returns(response)
|
28
|
+
|
29
|
+
response
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.when_populating(klass, options, &block)
|
33
|
+
if options[:from].is_a?(String)
|
34
|
+
puts options[:from]
|
35
|
+
data = read_fixture(options[:from]).values.first
|
36
|
+
else
|
37
|
+
data = options[:from].call
|
38
|
+
end
|
39
|
+
|
40
|
+
context "with data populated for #{klass}" do
|
41
|
+
setup { @object = klass.new(data) }
|
42
|
+
merge_block(&block)
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.value_for(method_name, options)
|
48
|
+
should "have a value for :#{method_name}" do
|
49
|
+
@object.send(method_name).should == options[:is]
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../test_helper'
|
2
|
+
|
3
|
+
module Dawanda
|
4
|
+
class CategoryTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
context "The Category class" do
|
7
|
+
|
8
|
+
should "be able to find a category by :id" do
|
9
|
+
id = 5327518
|
10
|
+
response = mock_request_cycle :for => "/categories/#{id}", :data => 'getCategoryDetails'
|
11
|
+
|
12
|
+
Category.expects(:new).with(response.result).returns('category')
|
13
|
+
|
14
|
+
Category.find_by_id(id, {}).should == 'category'
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
context "An instance of the Category class" do
|
20
|
+
when_populating Category, :from => 'getCategoryDetails' do
|
21
|
+
value_for :name, :is => '1003'
|
22
|
+
value_for :product_count, :is => 754
|
23
|
+
value_for :parent_id, :is => 406
|
24
|
+
value_for :id, :is => 418
|
25
|
+
end
|
26
|
+
|
27
|
+
should "have a collection of products" do
|
28
|
+
category_id = '123'
|
29
|
+
|
30
|
+
category = Category.new
|
31
|
+
category.expects(:id).with().returns(category_id)
|
32
|
+
|
33
|
+
Product.expects(:find_all_by_category_id).with(category_id, {}).returns('products')
|
34
|
+
|
35
|
+
category.products.should == 'products'
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../test_helper'
|
2
|
+
|
3
|
+
module Dawanda
|
4
|
+
class ColorTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
context "The Color class" do
|
7
|
+
|
8
|
+
should "be able to find a shop by :user_id" do
|
9
|
+
user_id = 5327518
|
10
|
+
response = mock_request_cycle :for => "/shops/#{user_id}", :data => 'getShopDetails'
|
11
|
+
|
12
|
+
# Shop.expects(:new).with(response.result).returns('shop')
|
13
|
+
Shop.expects(:find_by_user_id).with(user_id, {}).returns('shop')
|
14
|
+
|
15
|
+
Shop.find_by_user_id(user_id, {}).should == 'shop'
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../test_helper'
|
2
|
+
|
3
|
+
module Dawanda
|
4
|
+
class ProductTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
context "The Product class" do
|
7
|
+
|
8
|
+
should "be able to find a shop by :user_id" do
|
9
|
+
product_id = 5327518
|
10
|
+
response = mock_request_cycle :for => "/products/#{product_id}", :data => 'getProductDetails'
|
11
|
+
|
12
|
+
Product.expects(:new).with(response.result).returns('product')
|
13
|
+
|
14
|
+
Product.find_by_id(product_id, {}).should == 'product'
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
context "An instance of the Product class" do
|
20
|
+
when_populating Product, :from => 'getProductDetails' do
|
21
|
+
value_for :name, :is => 'Hoodie "SUE"'
|
22
|
+
value_for :product_url, :is => 'http://de.dawanda.com/product/4316882-Hoodie-SUE'
|
23
|
+
value_for :tags, :is => "pullover, carina, meko, Sweat, Hoodie, Karo, shabby chic"
|
24
|
+
value_for :quantity, :is => 1
|
25
|
+
value_for :materials, :is => "Baumwollmischgewebe"
|
26
|
+
value_for :view_count, :is => 3769
|
27
|
+
value_for :ending, :is => "2010/01/27 11:12:39 +0000"
|
28
|
+
end
|
29
|
+
|
30
|
+
should "have an associated shop" do
|
31
|
+
user_id = 5327518
|
32
|
+
|
33
|
+
product = Product.new
|
34
|
+
product.expects(:user_id).returns(user_id).at_least_once
|
35
|
+
response = mock_request_cycle :for => "/shops/#{user_id}", :data => 'getShopDetails'
|
36
|
+
|
37
|
+
Shop.expects(:new).with(response.result).returns('shop')
|
38
|
+
|
39
|
+
product.shop.should == 'shop'
|
40
|
+
end
|
41
|
+
|
42
|
+
should "have an associated category" do
|
43
|
+
category_id = 5327518
|
44
|
+
|
45
|
+
product = Product.new
|
46
|
+
product.expects(:category_id).returns(category_id).at_least_once
|
47
|
+
response = mock_request_cycle :for => "/categories/#{category_id}", :data => 'getCategoryDetails'
|
48
|
+
|
49
|
+
Category.expects(:new).with(response.result).returns('category')
|
50
|
+
|
51
|
+
product.category.should == 'category'
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../test_helper'
|
2
|
+
|
3
|
+
module Dawanda
|
4
|
+
class ShopCategoryTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
context "The ShopCategory class" do
|
7
|
+
|
8
|
+
should "be able to find a shop by :user_id" do
|
9
|
+
user_id = 5327518
|
10
|
+
response = mock_request_cycle :for => "/shops/#{user_id}", :data => 'getShopDetails'
|
11
|
+
|
12
|
+
# Shop.expects(:new).with(response.result).returns('shop')
|
13
|
+
Shop.expects(:find_by_user_id).with(user_id, {}).returns('shop')
|
14
|
+
|
15
|
+
Shop.find_by_user_id(user_id, {}).should == 'shop'
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../test_helper'
|
2
|
+
|
3
|
+
module Dawanda
|
4
|
+
class ShopTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
context "The Shop class" do
|
7
|
+
|
8
|
+
should "be able to find a shop by :user_id" do
|
9
|
+
user_id = 5327518
|
10
|
+
response = mock_request_cycle :for => "/shops/#{user_id}", :data => 'getShopDetails'
|
11
|
+
|
12
|
+
Shop.expects(:new).with(response.result).returns('shop')
|
13
|
+
#Shop.expects(:find_by_user_id).with(user_id, {}).returns('shop')
|
14
|
+
|
15
|
+
Shop.find_by_user_id(user_id, {}).should == 'shop'
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
context "An instance of the Shop class" do
|
21
|
+
when_populating Shop, :from => 'getShopDetails' do
|
22
|
+
value_for :name, :is => 'MEKO STORE'
|
23
|
+
value_for :updated, :is => "2009/09/29 09:58:46 +0000"
|
24
|
+
value_for :created, :is => "2007/05/18 10:44:17 +0000"
|
25
|
+
end
|
26
|
+
|
27
|
+
should "know the creation date" do
|
28
|
+
shop = Shop.new
|
29
|
+
shop.stubs(:created_at).with().returns(Time.at(1237430331.15))
|
30
|
+
|
31
|
+
shop.created_at.should == Time.at(1237430331.15)
|
32
|
+
end
|
33
|
+
|
34
|
+
should "know the update date" do
|
35
|
+
shop = Shop.new
|
36
|
+
shop.stubs(:updated_at).with().returns(Time.at(1239717723.36))
|
37
|
+
|
38
|
+
shop.updated_at.should == Time.at(1239717723.36)
|
39
|
+
end
|
40
|
+
|
41
|
+
should "have a collection of products" do
|
42
|
+
user_id = '123'
|
43
|
+
|
44
|
+
shop = Shop.new
|
45
|
+
shop.expects(:user_id).with().returns(user_id)
|
46
|
+
|
47
|
+
Product.expects(:find_all_by_shop_id).with(user_id, {}).returns('products')
|
48
|
+
|
49
|
+
shop.products.should == 'products'
|
50
|
+
end
|
51
|
+
|
52
|
+
should "have an associated user" do
|
53
|
+
user_id = 123
|
54
|
+
|
55
|
+
shop = Shop.new
|
56
|
+
shop.expects(:user_id).returns(user_id).at_least_once
|
57
|
+
response = mock_request_cycle :for => "/users/#{shop.user_id}", :data => 'getUserDetails'
|
58
|
+
|
59
|
+
User.expects(:new).with(response.result).returns('user')
|
60
|
+
|
61
|
+
shop.user.should == 'user'
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../test_helper'
|
2
|
+
|
3
|
+
module Dawanda
|
4
|
+
class UserTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
context "The User class" do
|
7
|
+
|
8
|
+
should "be able to find a user by :user_id" do
|
9
|
+
user_id = 5327518
|
10
|
+
response = mock_request_cycle :for => "/users/#{user_id}", :data => 'getUserDetails'
|
11
|
+
User.expects(:new).with(response.result).returns('user')
|
12
|
+
|
13
|
+
User.find_by_user_id(user_id, {}).should == 'user'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context "An instance of the User class" do
|
18
|
+
when_populating User, :from => 'getUserDetails' do
|
19
|
+
value_for :name, :is => 'meko'
|
20
|
+
value_for :transaction_sold_count, :is => 4854
|
21
|
+
value_for :is_seller, :is => true
|
22
|
+
value_for :city, :is => "auma"
|
23
|
+
value_for :sex, :is => 'female'
|
24
|
+
end
|
25
|
+
|
26
|
+
should "have an associated shop if user is seller" do
|
27
|
+
user_id = 123
|
28
|
+
user = User.new
|
29
|
+
user.expects(:id).returns(user_id).at_least_once
|
30
|
+
user.expects(:seller?).returns(true)
|
31
|
+
response = mock_request_cycle :for => "/shops/#{user.id}", :data => 'getShopDetails'
|
32
|
+
Shop.expects(:new).with(response.result).returns('shop')
|
33
|
+
|
34
|
+
user.shop.should == 'shop'
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|