razsell 0.0.4
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/.document +5 -0
- data/.gitignore +7 -0
- data/LICENSE +20 -0
- data/README.rdoc +10 -0
- data/Rakefile +68 -0
- data/VERSION +1 -0
- data/docs/RSSGuide1.02.pdf +0 -0
- data/features/product_lines.feature +13 -0
- data/features/razsell.feature +18 -0
- data/features/step_definitions/product_line_steps.rb +28 -0
- data/features/step_definitions/razsell_steps.rb +40 -0
- data/features/support/env.rb +13 -0
- data/features/support/razsell_mixed_in.rb +5 -0
- data/lib/constants/image_sizes.rb +10 -0
- data/lib/constants/product_types.rb +30 -0
- data/lib/constants/sort_methods.rb +7 -0
- data/lib/constants/sort_periods.rb +9 -0
- data/lib/constants.rb +5 -0
- data/lib/engine.rb +35 -0
- data/lib/http_service.rb +15 -0
- data/lib/item.rb +19 -0
- data/lib/product_line.rb +14 -0
- data/lib/product_line_parser.rb +19 -0
- data/lib/query.rb +107 -0
- data/lib/razsell.rb +17 -0
- data/lib/results.rb +70 -0
- data/razsell.gemspec +97 -0
- data/test/engine_test.rb +55 -0
- data/test/fixtures/page_1.rss +125 -0
- data/test/fixtures/page_2.rss +87 -0
- data/test/fixtures/productlines.htm +960 -0
- data/test/fixtures/rockstar.rss +125 -0
- data/test/fixtures.rb +12 -0
- data/test/product_line_parser_test.rb +33 -0
- data/test/product_types_test.rb +35 -0
- data/test/query_test.rb +176 -0
- data/test/razsell_test.rb +19 -0
- data/test/results_test.rb +103 -0
- data/test/test_helper.rb +15 -0
- metadata +140 -0
@@ -0,0 +1,125 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
2
|
+
<rss version="2.0" xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:media="http://search.yahoo.com/mrss/">
|
3
|
+
<channel><title>Kung Fu Tees: Zazzle.com Gallery: Products Matching "rockstar"</title>
|
4
|
+
<link>http://feed.zazzle.com/z.2/api/find.aspx?ft=rss&bg=FFFFFF&ch=kungfutees&ft=rss&isz=large&opensearch=1&ou=/kungfutees/rss?bg=FFFFFF&ft=rss&isz=large&opensearch=1&pg=1&qs=rockstar&ps=50&src=razsell&st=popularity&pg=1&ps=50&qs=rockstar&src=razsell&st=popularity</link>
|
5
|
+
|
6
|
+
<description></description>
|
7
|
+
<language>en-us</language>
|
8
|
+
<pubDate>Tue, 30 Jun 2009 02:23:26 GMT</pubDate>
|
9
|
+
<ttl>60</ttl>
|
10
|
+
<opensearch:totalResults>3</opensearch:totalResults>
|
11
|
+
<opensearch:startIndex>1</opensearch:startIndex>
|
12
|
+
|
13
|
+
<opensearch:itemsPerPage>50</opensearch:itemsPerPage>
|
14
|
+
<opensearch:Query role="request" searchTerms="rockstar" />
|
15
|
+
<item>
|
16
|
+
<guid isPermaLink="false">http://www.zazzle.com/ladies_rockstar_tshirt-235898004129790991?gl=kungfutees</guid>
|
17
|
+
<pubDate>Sat, 02 May 2009 13:06:08 GMT</pubDate>
|
18
|
+
<title><![CDATA[Ladies Rockstar TShirt]]></title>
|
19
|
+
<link>http://www.zazzle.com/ladies_rockstar_tshirt-235898004129790991?gl=kungfutees</link>
|
20
|
+
<author>kungfutees</author>
|
21
|
+
<description>
|
22
|
+
<![CDATA[<div class="gridCell " id="_assetCell1">
|
23
|
+
<div style="position:relative" class="clearfix">
|
24
|
+
<a href="http://www.zazzle.com/ladies_rockstar_tshirt-235898004129790991?gl=kungfutees" id="_assetCell1-imageLink" class="realviewLink"><img id="_assetCell1-preview" src="http://rlv.zcache.com/ladies_rockstar_tshirt-p235898004129790991ojnq_210.jpg" alt="Ladies Rockstar TShirt" title="Ladies Rockstar TShirt by kungfutees" class="realviewImage"/></a>
|
25
|
+
<div id="_assetCell1-productTypeIcon" class="shirtIcon"></div>
|
26
|
+
<a href="javascript://" id="_assetCell1-nextviewLink" class="nextviewLink"></a>
|
27
|
+
</div>
|
28
|
+
<div class="gridCellInfo" id="_assetCell1-info">
|
29
|
+
<a
|
30
|
+
href="http://www.zazzle.com/ladies_rockstar_tshirt-235898004129790991?gl=kungfutees"
|
31
|
+
id="_assetCell1-title"
|
32
|
+
class="productTitle" title="Ladies Rockstar TShirt"
|
33
|
+
>Ladies Rockstar TShirt</a><br />
|
34
|
+
<span class="byLine">by <a href="http://www.zazzle.com/kungfutees" id="_assetCell1-contributorLink" rel="nofollow">kungfutees</a><br /></span>
|
35
|
+
<span class="extraInfo">
|
36
|
+
<br />
|
37
|
+
|
38
|
+
</span>
|
39
|
+
</div>
|
40
|
+
</div>]]>
|
41
|
+
</description>
|
42
|
+
<media:title><![CDATA[Ladies Rockstar TShirt]]></media:title>
|
43
|
+
<media:description><![CDATA[Ladies are Rockstar Coders too!]]></media:description>
|
44
|
+
<media:thumbnail url="http://rlv.zcache.com/ladies_rockstar_tshirt-p235898004129790991ojnq_125.jpg" />
|
45
|
+
<media:content url="http://rlv.zcache.com/ladies_rockstar_tshirt-p235898004129790991ojnq_500.jpg" />
|
46
|
+
<media:keywords>rockstar, coder, ror, ruby, on, rails</media:keywords>
|
47
|
+
<media:rating scheme="urn:mpaa">g</media:rating>
|
48
|
+
</item>
|
49
|
+
<item>
|
50
|
+
<guid isPermaLink="false">http://www.zazzle.com/rockstar_coder_mug-168427986526885635?gl=kungfutees</guid>
|
51
|
+
<pubDate>Sat, 02 May 2009 13:09:16 GMT</pubDate>
|
52
|
+
<title><![CDATA[Rockstar Coder Mug]]></title>
|
53
|
+
<link>http://www.zazzle.com/rockstar_coder_mug-168427986526885635?gl=kungfutees</link>
|
54
|
+
<author>kungfutees</author>
|
55
|
+
<description>
|
56
|
+
<![CDATA[
|
57
|
+
<div class="gridCell " id="_assetCell2">
|
58
|
+
<div style="position:relative" class="clearfix">
|
59
|
+
<a href="http://www.zazzle.com/rockstar_coder_mug-168427986526885635?gl=kungfutees" id="_assetCell2-imageLink" class="realviewLink"
|
60
|
+
><img id="_assetCell2-preview" src="http://rlv.zcache.com/rockstar_coder_mug-p168427986526885635tda5_210.jpg" alt="Rockstar Coder Mug" title="Rockstar Coder Mug by kungfutees" class="realviewImage"
|
61
|
+
/></a>
|
62
|
+
<div id="_assetCell2-productTypeIcon" class="mugIcon"></div>
|
63
|
+
<a href="javascript://" id="_assetCell2-nextviewLink" class="nextviewLink"></a>
|
64
|
+
</div>
|
65
|
+
<div class="gridCellInfo" id="_assetCell2-info">
|
66
|
+
<a
|
67
|
+
href="http://www.zazzle.com/rockstar_coder_mug-168427986526885635?gl=kungfutees"
|
68
|
+
id="_assetCell2-title"
|
69
|
+
class="productTitle" title="Rockstar Coder Mug"
|
70
|
+
>Rockstar Coder Mug</a><br />
|
71
|
+
<span class="byLine">by <a href="http://www.zazzle.com/kungfutees" id="_assetCell2-contributorLink" rel="nofollow">kungfutees</a><br /></span>
|
72
|
+
<span class="extraInfo">
|
73
|
+
<br />
|
74
|
+
|
75
|
+
</span>
|
76
|
+
</div>
|
77
|
+
</div>]]>
|
78
|
+
</description>
|
79
|
+
<media:title><![CDATA[Rockstar Coder Mug]]></media:title>
|
80
|
+
<media:description><![CDATA[Want to show your inner rockstar in the break room? Here is the perfect way.]]></media:description>
|
81
|
+
<media:thumbnail url="http://rlv.zcache.com/rockstar_coder_mug-p168427986526885635tda5_125.jpg" />
|
82
|
+
<media:content url="http://rlv.zcache.com/rockstar_coder_mug-p168427986526885635tda5_500.jpg" />
|
83
|
+
<media:keywords>rockstar, coder, ror, ruby, on, rails</media:keywords>
|
84
|
+
<media:rating scheme="urn:mpaa">g</media:rating>
|
85
|
+
</item>
|
86
|
+
|
87
|
+
<item>
|
88
|
+
<guid isPermaLink="false">http://www.zazzle.com/rockstar_coder_tshirt-235670521587248636?gl=kungfutees</guid>
|
89
|
+
<pubDate>Sat, 02 May 2009 04:43:47 GMT</pubDate>
|
90
|
+
<title><![CDATA[Rockstar Coder]]></title>
|
91
|
+
<link>http://www.zazzle.com/rockstar_coder_tshirt-235670521587248636?gl=kungfutees</link>
|
92
|
+
<author>kungfutees</author>
|
93
|
+
<description>
|
94
|
+
<![CDATA[
|
95
|
+
<div class="gridCell " id="_assetCell3">
|
96
|
+
<div style="position:relative" class="clearfix">
|
97
|
+
<a href="http://www.zazzle.com/rockstar_coder_tshirt-235670521587248636?gl=kungfutees" id="_assetCell3-imageLink" class="realviewLink"
|
98
|
+
><img id="_assetCell3-preview" src="http://rlv.zcache.com/rockstar_coder_tshirt-p235670521587248636cxhe_210.jpg" alt="Rockstar Coder t-shirts" title="Rockstar Coder t-shirts by kungfutees" class="realviewImage"
|
99
|
+
/></a>
|
100
|
+
<div id="_assetCell3-productTypeIcon" class="shirtIcon"></div>
|
101
|
+
<a href="javascript://" id="_assetCell3-nextviewLink" class="nextviewLink"></a>
|
102
|
+
</div>
|
103
|
+
<div class="gridCellInfo" id="_assetCell3-info">
|
104
|
+
<a
|
105
|
+
href="http://www.zazzle.com/rockstar_coder_tshirt-235670521587248636?gl=kungfutees"
|
106
|
+
id="_assetCell3-title"
|
107
|
+
class="productTitle" title="Rockstar Coder"
|
108
|
+
>Rockstar Coder</a><br />
|
109
|
+
<span class="byLine">by <a href="http://www.zazzle.com/kungfutees" id="_assetCell3-contributorLink" rel="nofollow">kungfutees</a><br /></span>
|
110
|
+
<span class="extraInfo">
|
111
|
+
<br />
|
112
|
+
|
113
|
+
</span>
|
114
|
+
</div>
|
115
|
+
</div>]]>
|
116
|
+
</description>
|
117
|
+
<media:title><![CDATA[Rockstar Coder]]></media:title>
|
118
|
+
<media:description><![CDATA[Want to show the world that you are a Rockstar Coder? What better way than a Nutritional Information label. Shirt is blank on front, with Rockstar Coder pattern on the back.]]>
|
119
|
+
</media:description><media:thumbnail url="http://rlv.zcache.com/rockstar_coder_tshirt-p235670521587248636cxhe_125.jpg" />
|
120
|
+
<media:content url="http://rlv.zcache.com/rockstar_coder_tshirt-p235670521587248636cxhe_500.jpg" />
|
121
|
+
<media:keywords>ruby, rockstar, coder, ruby, on, rails</media:keywords>
|
122
|
+
<media:rating scheme="urn:mpaa">g</media:rating>
|
123
|
+
</item>
|
124
|
+
</channel>
|
125
|
+
</rss>
|
data/test/fixtures.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
module Fixtures
|
2
|
+
def feed name
|
3
|
+
filename = File.join(File.dirname(__FILE__), 'fixtures', "#{name}.rss")
|
4
|
+
|
5
|
+
filename = File.join(File.dirname(__FILE__), 'fixtures', "#{name}.htm") unless File.exist? filename
|
6
|
+
|
7
|
+
feed_file = File.open(filename, "r")
|
8
|
+
feed = feed_file.read
|
9
|
+
feed_file.close
|
10
|
+
feed
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'product_line_parser'
|
2
|
+
|
3
|
+
class ProductLineParserTest < Test::Unit::TestCase
|
4
|
+
context "parsing the document" do
|
5
|
+
setup do
|
6
|
+
@parser = Razsell::ProductLineParser.new
|
7
|
+
end
|
8
|
+
|
9
|
+
should "return an empty array when passed nil" do
|
10
|
+
section = @parser.parse nil
|
11
|
+
assert_equal Array, section.class
|
12
|
+
assert_equal 0, section.length
|
13
|
+
end
|
14
|
+
|
15
|
+
should "get the relevent text from the document" do
|
16
|
+
section = @parser.get_elements feed("productlines")
|
17
|
+
assert_equal '<a href="http://www.zazzle.com/kungfutees/gifts?cg=196854021783912655">Cheeze</a>', section[0].to_html
|
18
|
+
assert_equal '<a href="http://www.zazzle.com/kungfutees/gifts?cg=196596454716712290">New Products</a>', section[1].to_html
|
19
|
+
assert_equal '<a href="http://www.zazzle.com/kungfutees/gifts?cg=196983228798280961">Smim</a>', section[2].to_html
|
20
|
+
end
|
21
|
+
|
22
|
+
should "populate the array with ProductLine objects" do
|
23
|
+
section = @parser.parse feed("productlines")
|
24
|
+
assert_equal '196854021783912655', section[0].id
|
25
|
+
assert_equal '196596454716712290', section[1].id
|
26
|
+
assert_equal '196983228798280961', section[2].id
|
27
|
+
|
28
|
+
assert_equal 'Cheeze', section[0].name
|
29
|
+
assert_equal 'New Products', section[1].name
|
30
|
+
assert_equal 'Smim', section[2].name
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'constants/product_types'
|
3
|
+
|
4
|
+
class ProductTypesTest < Test::Unit::TestCase
|
5
|
+
include Razsell::ProductTypes
|
6
|
+
|
7
|
+
should "have constants for values" do
|
8
|
+
assert_equal "128", BUMPER_STICKER
|
9
|
+
assert_equal "137", CARD
|
10
|
+
assert_equal "144", MOUSE_PAD
|
11
|
+
assert_equal "145", BUTTON
|
12
|
+
assert_equal "146", KEYCHAIN
|
13
|
+
assert_equal "147", MAGNET
|
14
|
+
assert_equal "148", HAT
|
15
|
+
assert_equal "149", BAG
|
16
|
+
assert_equal "151", TIE
|
17
|
+
assert_equal "153", PHOTO_SCULPTURE
|
18
|
+
assert_equal "154", APRON
|
19
|
+
assert_equal "156", PHOTO_PRINT
|
20
|
+
assert_equal "158", CALENDAR
|
21
|
+
assert_equal "167", SHOES
|
22
|
+
assert_equal "168", MUG
|
23
|
+
assert_equal "172", POSTAGE_STAMP
|
24
|
+
assert_equal "186", SKATEBOARD
|
25
|
+
assert_equal "217", STICKER
|
26
|
+
assert_equal "228", POSTER
|
27
|
+
assert_equal "231", EMBROIDERED_SHIRT
|
28
|
+
assert_equal "232", EMBROIDERED_BAG
|
29
|
+
assert_equal "233", EMBROIDERED_HAT
|
30
|
+
assert_equal "235", T_SHIRT
|
31
|
+
assert_equal "239", POSTCARD
|
32
|
+
assert_equal "240", PROFILE_CARD
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
data/test/query_test.rb
ADDED
@@ -0,0 +1,176 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'constants'
|
3
|
+
|
4
|
+
class QueryTest < Test::Unit::TestCase
|
5
|
+
context "has defaulted parameters" do
|
6
|
+
setup do
|
7
|
+
@query = Razsell::Query.new
|
8
|
+
end
|
9
|
+
|
10
|
+
should "default sort to popularity" do
|
11
|
+
assert_equal Razsell::SortMethods::POPULARITY, @query.sort_type
|
12
|
+
end
|
13
|
+
|
14
|
+
should "default page to 1" do
|
15
|
+
assert_equal 1, @query.page
|
16
|
+
end
|
17
|
+
|
18
|
+
should "default items per page to 50" do
|
19
|
+
assert_equal 50, @query.items_per_page
|
20
|
+
end
|
21
|
+
|
22
|
+
should "default page limit to 5" do
|
23
|
+
assert_equal 5, @query.page_limit
|
24
|
+
end
|
25
|
+
|
26
|
+
should "default product type to nil" do
|
27
|
+
assert_nil @query.product_type
|
28
|
+
end
|
29
|
+
|
30
|
+
should "default image background color to white" do
|
31
|
+
assert_equal "FFFFFF", @query.image_background_color
|
32
|
+
end
|
33
|
+
|
34
|
+
should "default source to razsell" do
|
35
|
+
assert_equal "razsell", @query.source
|
36
|
+
end
|
37
|
+
|
38
|
+
should "default opensearch to 1" do
|
39
|
+
assert_equal 1, @query.opensearch
|
40
|
+
end
|
41
|
+
|
42
|
+
should "default feed type to rss" do
|
43
|
+
assert_equal "rss", @query.feed_type
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context "can set parameters" do
|
48
|
+
setup do
|
49
|
+
@query = Razsell::Query.new
|
50
|
+
end
|
51
|
+
|
52
|
+
should "set sort type" do
|
53
|
+
@query.sort_type = Razsell::SortMethods::DATE_CREATED
|
54
|
+
assert_equal Razsell::SortMethods::DATE_CREATED, @query.sort_type
|
55
|
+
end
|
56
|
+
|
57
|
+
should "set image size" do
|
58
|
+
@query.image_size = Razsell::ImageSizes::SMALL
|
59
|
+
assert_equal Razsell::ImageSizes::SMALL, @query.image_size
|
60
|
+
end
|
61
|
+
|
62
|
+
should "set grid cell background color" do
|
63
|
+
@query.image_background_color = "FFFFFF"
|
64
|
+
assert_equal "FFFFFF", @query.image_background_color
|
65
|
+
end
|
66
|
+
|
67
|
+
should "set keywords" do
|
68
|
+
@query.keywords = "bar"
|
69
|
+
assert_equal "bar", @query.keywords
|
70
|
+
end
|
71
|
+
|
72
|
+
should "set product type" do
|
73
|
+
@query.product_type = Razsell::ProductTypes::MUG
|
74
|
+
assert_equal Razsell::ProductTypes::MUG, @query.product_type
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
context "base url" do
|
79
|
+
should "know base url" do
|
80
|
+
@query = Razsell::Query.new
|
81
|
+
assert_equal "http://feed.zazzle.com/rss", @query.send(:base_url)
|
82
|
+
end
|
83
|
+
|
84
|
+
should "include artist in base url if supplied" do
|
85
|
+
@query = Razsell::Query.new.for_artist("kungfutees")
|
86
|
+
assert_equal "http://feed.zazzle.com/kungfutees/rss", @query.send(:base_url)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
context "querystring" do
|
91
|
+
setup do
|
92
|
+
@query = Razsell::Query.new
|
93
|
+
end
|
94
|
+
|
95
|
+
should "be alphabetical" do
|
96
|
+
qs = @query.to_querystring
|
97
|
+
expected = "bg=FFFFFF&ft=rss&isz=large&opensearch=1&pg=1&ps=50&src=razsell&st=popularity"
|
98
|
+
assert_equal expected, qs
|
99
|
+
end
|
100
|
+
|
101
|
+
should "remove nils" do
|
102
|
+
@query.product_type = nil
|
103
|
+
qs = @query.to_querystring
|
104
|
+
expected = "bg=FFFFFF&ft=rss&isz=large&opensearch=1&pg=1&ps=50&src=razsell&st=popularity"
|
105
|
+
assert_equal expected, qs
|
106
|
+
end
|
107
|
+
|
108
|
+
should "encode values" do
|
109
|
+
@query.keywords = "bar baz"
|
110
|
+
qs = @query.to_querystring
|
111
|
+
expected = "bg=FFFFFF&ft=rss&isz=large&opensearch=1&pg=1&ps=50&qs=bar+baz&src=razsell&st=popularity"
|
112
|
+
assert_equal expected, qs
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
context "url" do
|
117
|
+
setup do
|
118
|
+
@query = Razsell::Query.new
|
119
|
+
end
|
120
|
+
|
121
|
+
should "build url" do
|
122
|
+
qs = @query.to_url
|
123
|
+
expected = "http://feed.zazzle.com/rss?bg=FFFFFF&ft=rss&isz=large&opensearch=1&pg=1&ps=50&src=razsell&st=popularity"
|
124
|
+
assert_equal expected, qs
|
125
|
+
end
|
126
|
+
|
127
|
+
should "build url with all parameters" do
|
128
|
+
@query.keywords = "foo bar"
|
129
|
+
@query.product_line = 1234567890123456
|
130
|
+
@query.product_type = Razsell::ProductTypes::SHOES
|
131
|
+
@query.sort_type = Razsell::SortMethods::POPULARITY
|
132
|
+
@query.sort_period = Razsell::SortPeriods::THIS_WEEK
|
133
|
+
@query.image_size = Razsell::ImageSizes::LARGE
|
134
|
+
@query.image_background_color = "000000"
|
135
|
+
qs = @query.to_url
|
136
|
+
expected = "http://feed.zazzle.com/rss?bg=000000&cg=1234567890123456&ft=rss&isz=large&opensearch=1&pg=1&ps=50&pt=167&qs=foo+bar&sp=7&src=razsell&st=popularity"
|
137
|
+
assert_equal expected, qs
|
138
|
+
end
|
139
|
+
|
140
|
+
should "build url for a specific artist" do
|
141
|
+
query = Razsell::Query.new.for_artist("kungfutees")
|
142
|
+
qs = query.to_url
|
143
|
+
expected = "http://feed.zazzle.com/kungfutees/rss?bg=FFFFFF&ft=rss&isz=large&opensearch=1&pg=1&ps=50&src=razsell&st=popularity"
|
144
|
+
assert_equal expected, qs
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
context "advancing the page" do
|
149
|
+
setup do
|
150
|
+
@query = Razsell::Query.new
|
151
|
+
end
|
152
|
+
|
153
|
+
should "start on page one" do
|
154
|
+
assert_equal 1, @query.page
|
155
|
+
end
|
156
|
+
|
157
|
+
should "increment with each page advance" do
|
158
|
+
@query.advance_page
|
159
|
+
assert_equal 2, @query.page
|
160
|
+
end
|
161
|
+
|
162
|
+
should "default page limit to 5" do
|
163
|
+
assert_equal 5, @query.page_limit
|
164
|
+
end
|
165
|
+
|
166
|
+
should "return true if next page is less than the page limit" do
|
167
|
+
@query.page_limit = 2
|
168
|
+
assert_equal true, @query.advance_page
|
169
|
+
end
|
170
|
+
|
171
|
+
should "return false if advance page attempts to advence beyond the page limit" do
|
172
|
+
@query.page_limit = 1
|
173
|
+
assert_equal false, @query.advance_page
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class RazsellTest < Test::Unit::TestCase
|
4
|
+
include Razsell
|
5
|
+
|
6
|
+
context "basic operations" do
|
7
|
+
setup do
|
8
|
+
@query = Razsell::Query.new
|
9
|
+
end
|
10
|
+
|
11
|
+
should "return results" do
|
12
|
+
http_service = Razsell::HttpService.new
|
13
|
+
http_service.expects(:get).once.returns("")
|
14
|
+
|
15
|
+
result = request @query, :http_service => http_service
|
16
|
+
assert_equal Razsell::Results, result.class
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ResultsTest < Test::Unit::TestCase
|
4
|
+
context "parsing the rockstar search" do
|
5
|
+
setup do
|
6
|
+
@results = Razsell::Results.new feed("rockstar")
|
7
|
+
end
|
8
|
+
|
9
|
+
should "have an item_count of 3" do
|
10
|
+
assert_equal 3, @results.item_count
|
11
|
+
end
|
12
|
+
|
13
|
+
should "have 3 itmes" do
|
14
|
+
assert_equal 3, @results.items.length
|
15
|
+
end
|
16
|
+
|
17
|
+
context "first item" do
|
18
|
+
setup do
|
19
|
+
@item = @results.items[0]
|
20
|
+
end
|
21
|
+
|
22
|
+
should "have the correct title" do
|
23
|
+
assert_equal "Ladies Rockstar TShirt", @item.title
|
24
|
+
end
|
25
|
+
|
26
|
+
should "have the correct guid" do
|
27
|
+
assert_equal "http://www.zazzle.com/ladies_rockstar_tshirt-235898004129790991?gl=kungfutees", @item.guid
|
28
|
+
end
|
29
|
+
|
30
|
+
should "have the correct pubDate" do
|
31
|
+
assert_equal DateTime.parse("Sat, 02 May 2009 13:06:08 GMT").to_s, @item.pub_date.to_s
|
32
|
+
end
|
33
|
+
|
34
|
+
should "have the correct link" do
|
35
|
+
assert_equal "http://www.zazzle.com/ladies_rockstar_tshirt-235898004129790991?gl=kungfutees", @item.link
|
36
|
+
end
|
37
|
+
|
38
|
+
should "have the correct author" do
|
39
|
+
assert_equal "kungfutees", @item.author
|
40
|
+
end
|
41
|
+
|
42
|
+
should "have the correct description" do
|
43
|
+
assert_equal "Ladies are Rockstar Coders too!", @item.description
|
44
|
+
end
|
45
|
+
|
46
|
+
should "have the correct thumbnail url" do
|
47
|
+
assert_equal "http://rlv.zcache.com/ladies_rockstar_tshirt-p235898004129790991ojnq_125.jpg", @item.thumbnail_url
|
48
|
+
end
|
49
|
+
|
50
|
+
should "have the correct content url" do
|
51
|
+
assert_equal "http://rlv.zcache.com/ladies_rockstar_tshirt-p235898004129790991ojnq_500.jpg", @item.content_url
|
52
|
+
end
|
53
|
+
|
54
|
+
should "have the correct keywords" do
|
55
|
+
assert_contains @item.keywords, 'rockstar'
|
56
|
+
assert_contains @item.keywords, 'coder'
|
57
|
+
assert_contains @item.keywords, 'ror'
|
58
|
+
assert_contains @item.keywords, 'ruby'
|
59
|
+
assert_contains @item.keywords, 'on'
|
60
|
+
assert_contains @item.keywords, 'rails'
|
61
|
+
end
|
62
|
+
|
63
|
+
should "have the correct rating" do
|
64
|
+
assert_equal "g", @item.rating
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context "multiple pages" do
|
70
|
+
|
71
|
+
should "know total result count" do
|
72
|
+
results = Razsell::Results.new feed("page_1")
|
73
|
+
assert 5, results.result_count
|
74
|
+
end
|
75
|
+
|
76
|
+
should "know items per page" do
|
77
|
+
results = Razsell::Results.new feed("page_1")
|
78
|
+
assert 3, results.items_per_page
|
79
|
+
end
|
80
|
+
|
81
|
+
should "know if another page exists" do
|
82
|
+
results = Razsell::Results.new feed("page_1")
|
83
|
+
assert results.has_more_pages?
|
84
|
+
end
|
85
|
+
|
86
|
+
should "know if there is only one page" do
|
87
|
+
results = Razsell::Results.new feed("rockstar")
|
88
|
+
assert !results.has_more_pages?
|
89
|
+
end
|
90
|
+
|
91
|
+
should "know if it's on the last page" do
|
92
|
+
results = Razsell::Results.new feed("page_2")
|
93
|
+
assert !results.has_more_pages?
|
94
|
+
end
|
95
|
+
|
96
|
+
should "add additional pages" do
|
97
|
+
results = Razsell::Results.new feed("page_1")
|
98
|
+
assert_equal 3, results.items.length
|
99
|
+
results.add feed("page_2")
|
100
|
+
assert_equal 5, results.items.length
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'test/unit'
|
3
|
+
require 'shoulda'
|
4
|
+
require 'fixtures'
|
5
|
+
|
6
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
7
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
8
|
+
require 'razsell'
|
9
|
+
|
10
|
+
require 'mocha'
|
11
|
+
|
12
|
+
class Test::Unit::TestCase
|
13
|
+
include Fixtures
|
14
|
+
end
|
15
|
+
|
metadata
ADDED
@@ -0,0 +1,140 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: razsell
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.4
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jamal Hansen
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-12-22 00:00:00 -06:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: hpricot
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.8.1
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: cucumber
|
27
|
+
type: :development
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.3.11
|
34
|
+
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: mocha
|
37
|
+
type: :development
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: "0"
|
44
|
+
version:
|
45
|
+
- !ruby/object:Gem::Dependency
|
46
|
+
name: technicalpickles-shoulda
|
47
|
+
type: :development
|
48
|
+
version_requirement:
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: "0"
|
54
|
+
version:
|
55
|
+
description:
|
56
|
+
email: jamal.hansen@gmail.com
|
57
|
+
executables: []
|
58
|
+
|
59
|
+
extensions: []
|
60
|
+
|
61
|
+
extra_rdoc_files:
|
62
|
+
- LICENSE
|
63
|
+
- README.rdoc
|
64
|
+
files:
|
65
|
+
- .document
|
66
|
+
- .gitignore
|
67
|
+
- LICENSE
|
68
|
+
- README.rdoc
|
69
|
+
- Rakefile
|
70
|
+
- VERSION
|
71
|
+
- docs/RSSGuide1.02.pdf
|
72
|
+
- features/product_lines.feature
|
73
|
+
- features/razsell.feature
|
74
|
+
- features/step_definitions/product_line_steps.rb
|
75
|
+
- features/step_definitions/razsell_steps.rb
|
76
|
+
- features/support/env.rb
|
77
|
+
- features/support/razsell_mixed_in.rb
|
78
|
+
- lib/constants.rb
|
79
|
+
- lib/constants/image_sizes.rb
|
80
|
+
- lib/constants/product_types.rb
|
81
|
+
- lib/constants/sort_methods.rb
|
82
|
+
- lib/constants/sort_periods.rb
|
83
|
+
- lib/engine.rb
|
84
|
+
- lib/http_service.rb
|
85
|
+
- lib/item.rb
|
86
|
+
- lib/product_line.rb
|
87
|
+
- lib/product_line_parser.rb
|
88
|
+
- lib/query.rb
|
89
|
+
- lib/razsell.rb
|
90
|
+
- lib/results.rb
|
91
|
+
- razsell.gemspec
|
92
|
+
- test/engine_test.rb
|
93
|
+
- test/fixtures.rb
|
94
|
+
- test/fixtures/page_1.rss
|
95
|
+
- test/fixtures/page_2.rss
|
96
|
+
- test/fixtures/productlines.htm
|
97
|
+
- test/fixtures/rockstar.rss
|
98
|
+
- test/product_line_parser_test.rb
|
99
|
+
- test/product_types_test.rb
|
100
|
+
- test/query_test.rb
|
101
|
+
- test/razsell_test.rb
|
102
|
+
- test/results_test.rb
|
103
|
+
- test/test_helper.rb
|
104
|
+
has_rdoc: true
|
105
|
+
homepage: http://github.com/rubyyot/razsell
|
106
|
+
licenses: []
|
107
|
+
|
108
|
+
post_install_message:
|
109
|
+
rdoc_options:
|
110
|
+
- --charset=UTF-8
|
111
|
+
require_paths:
|
112
|
+
- lib
|
113
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: "0"
|
118
|
+
version:
|
119
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: "0"
|
124
|
+
version:
|
125
|
+
requirements: []
|
126
|
+
|
127
|
+
rubyforge_project:
|
128
|
+
rubygems_version: 1.3.5
|
129
|
+
signing_key:
|
130
|
+
specification_version: 3
|
131
|
+
summary: A gem for getting info about products on a website that has a similar name
|
132
|
+
test_files:
|
133
|
+
- test/product_types_test.rb
|
134
|
+
- test/fixtures.rb
|
135
|
+
- test/test_helper.rb
|
136
|
+
- test/results_test.rb
|
137
|
+
- test/product_line_parser_test.rb
|
138
|
+
- test/razsell_test.rb
|
139
|
+
- test/query_test.rb
|
140
|
+
- test/engine_test.rb
|