bassnode-discogs 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. data/.gitignore +5 -0
  2. data/COPYING +619 -0
  3. data/LICENSE +5 -0
  4. data/README.markdown +75 -0
  5. data/Rakefile +27 -0
  6. data/bassnode-discogs.gemspec +18 -0
  7. data/lib/discogs.rb +21 -0
  8. data/lib/wrapper/resource.rb +79 -0
  9. data/lib/wrapper/resource_mappings.rb +84 -0
  10. data/lib/wrapper/resources/artist.rb +37 -0
  11. data/lib/wrapper/resources/artist_release.rb +17 -0
  12. data/lib/wrapper/resources/format.rb +11 -0
  13. data/lib/wrapper/resources/generic_list.rb +29 -0
  14. data/lib/wrapper/resources/image.rb +11 -0
  15. data/lib/wrapper/resources/label.rb +16 -0
  16. data/lib/wrapper/resources/label_release.rb +17 -0
  17. data/lib/wrapper/resources/release.rb +22 -0
  18. data/lib/wrapper/resources/release_artist.rb +18 -0
  19. data/lib/wrapper/resources/release_label.rb +10 -0
  20. data/lib/wrapper/resources/search.rb +61 -0
  21. data/lib/wrapper/resources/search_result.rb +16 -0
  22. data/lib/wrapper/resources/track.rb +15 -0
  23. data/lib/wrapper/wrapper.rb +109 -0
  24. data/spec/resource_spec.rb +27 -0
  25. data/spec/resources/artist_release_spec.rb +59 -0
  26. data/spec/resources/artist_spec.rb +15 -0
  27. data/spec/resources/format_spec.rb +41 -0
  28. data/spec/resources/generic_list_spec.rb +66 -0
  29. data/spec/resources/image_spec.rb +43 -0
  30. data/spec/resources/label_release_spec.rb +55 -0
  31. data/spec/resources/label_spec.rb +15 -0
  32. data/spec/resources/release_artist_spec.rb +43 -0
  33. data/spec/resources/release_label_spec.rb +31 -0
  34. data/spec/resources/release_spec.rb +15 -0
  35. data/spec/resources/search_result_spec.rb +47 -0
  36. data/spec/resources/search_spec.rb +15 -0
  37. data/spec/resources/track_spec.rb +56 -0
  38. data/spec/samples/valid_artist.xml +76 -0
  39. data/spec/samples/valid_artist_release.xml +8 -0
  40. data/spec/samples/valid_description_list.xml +5 -0
  41. data/spec/samples/valid_format.xml +7 -0
  42. data/spec/samples/valid_genre_list.xml +5 -0
  43. data/spec/samples/valid_image.xml +1 -0
  44. data/spec/samples/valid_label.xml +34 -0
  45. data/spec/samples/valid_label_release.xml +8 -0
  46. data/spec/samples/valid_release.xml +99 -0
  47. data/spec/samples/valid_release_artist.xml +8 -0
  48. data/spec/samples/valid_release_label.xml +1 -0
  49. data/spec/samples/valid_search_result.xml +6 -0
  50. data/spec/samples/valid_search_results_1.xml +142 -0
  51. data/spec/samples/valid_search_results_2.xml +206 -0
  52. data/spec/samples/valid_track.xml +16 -0
  53. data/spec/spec_helper.rb +36 -0
  54. data/spec/wrapper_methods/get_artist_spec.rb +109 -0
  55. data/spec/wrapper_methods/get_label_spec.rb +89 -0
  56. data/spec/wrapper_methods/get_release_spec.rb +123 -0
  57. data/spec/wrapper_methods/search_spec.rb +330 -0
  58. data/spec/wrapper_spec.rb +180 -0
  59. metadata +125 -0
@@ -0,0 +1,36 @@
1
+ require 'rubygems'
2
+ require 'spec'
3
+ require File.dirname(__FILE__) + '/../lib/discogs'
4
+
5
+ def valid_release_xml
6
+ read_sample "valid_release.xml"
7
+ end
8
+
9
+ def valid_artist_xml
10
+ read_sample "valid_artist.xml"
11
+ end
12
+
13
+ def valid_label_xml
14
+ read_sample "valid_label.xml"
15
+ end
16
+
17
+ def valid_search_xml(page=1)
18
+ read_sample "valid_search_results_#{page}.xml"
19
+ end
20
+
21
+ def read_sample(filename)
22
+ data = File.read(File.join(File.dirname(__FILE__), "samples", filename))
23
+ data.gsub /\n/, ''
24
+ end
25
+
26
+ def sample_valid_binary
27
+ "\037\213\b\000\325\3054J\002\377\265T\337O\3330\020\376W,?L\233D\353\004(\203\315\215D\3304\020T\233V\006\017\323\036\214}4\036\211\035l\207\222\377~\227_U\v\025C\232\366\344\273\363\335\227/\337\335\231;\360%\361A\204)\265w\224<\200\363\332\232)\215\307\021%\016\356+\360\301\243K\023\356 \a\341\201h\205\376\036m\253*\274;\226\022\312\000\nSt!\026\340\373\223d\240\027\031\002\037D\210\025\352\022\246\324\203\264F\tWSR9=\245Y\b\345\a\306\226\313\345Xi/\355\302\217\245-X\213\303\276\217\342\275Q\034\037\306\373\321\321\321d2\376]\302\242\255\213'\321\337K'\321\326\362\245V!\3539\261\377\302\3640\376'\246\253\362'L;QP\\\341\202\306\246\fF\302\215( \231Ykd\246s\345\300p\326\2068\353R\223\301\300\232\240C\016I\n5\266\201\\\330\a\340\254\v\361\\\334@\216\031\355I\244\b\306N\351\247\375\213x7\212\336S\322 \242\017P\356_\350[\240\004\305cC\r<\006'\266\363:\267\372F\aK\336\210\242\374HR{W\r\354\234E&_C\006\216\374\234\227\332\351P\211\\\207\372\027g\355\325\300\372\311\217\236[Wo@\\Y)r\377r\321I\346\264'_\234\330,\275\306\217\0060\243\264\336!\337\234U\225\004\267Cf\372\021\024I1\365\t\017\266\371\237\267\326\025\242iDg\364\022]iS\347\224\334\207\272[\e\005^:]\006\\+L]\363\222x\227r\266\036\330\3600\231u\300+\003C\v0\270\262\375\231|\316A\006g\215\226\234\2657\230:d\370P\347Mf{&\227 3c9\353\274>\330t\223\234\332\312\343\024\364\027\335\211e\322V&\270:\3711\347l\260\207'@%8\023\321(:\034E\021\212\324\275\v\n\a\321\006\374b/\352\016);E\025\0218kE+*\376\020\312\213\356Lx\217o\005\231U^K\3626\235\235\275\ecW[\000\216\303$\357r\034r\234\327\306Lxi\275n\024L\216c\316V\316\v\323\254*'\232\202vL{\220gX\273\317\261\25630\344\004[%5\352BR|\257\n\360\030)\220zX-\313k\340\323-TOA<4\373\331\357\334\253`\266\260<3\270Q\227\031\220y\300\031|\021\216\255\2119\264\n\247\244y\367\223?4\242\342\264\376\005\000\000"
28
+ end
29
+
30
+ def sample_invalid_data
31
+ <<-EOF
32
+ <resp requests="2" stat="fail">
33
+ <error>Missing or invalid API Key</error>
34
+ </resp>
35
+ EOF
36
+ end
@@ -0,0 +1,109 @@
1
+ require File.dirname(__FILE__) + "/../spec_helper"
2
+
3
+ describe Discogs::Wrapper do
4
+
5
+ before do
6
+ @wrapper = Discogs::Wrapper.new("some_key")
7
+ @artist_name = "Root"
8
+ end
9
+
10
+ describe "when asking for artist information" do
11
+
12
+ before do
13
+ @http_request = mock(Net::HTTP)
14
+ @http_response = mock(Net::HTTPResponse, :code => "200", :body => valid_artist_xml)
15
+ @http_response_as_file = mock(StringIO, :read => valid_artist_xml)
16
+ Zlib::GzipReader.should_receive(:new).and_return(@http_response_as_file)
17
+ @http_request.should_receive(:start).and_return(@http_response)
18
+ Net::HTTP.should_receive(:new).and_return(@http_request)
19
+
20
+ @artist = @wrapper.get_artist(@artist_name)
21
+ end
22
+
23
+ describe "when calling simple artist attributes" do
24
+
25
+ it "should have a name attribute" do
26
+ @artist.name.should == "Root"
27
+ end
28
+
29
+ it "should have a realname attribute" do
30
+ @artist.realname.should == "Rootan"
31
+ end
32
+
33
+ it "should have one or more aliases" do
34
+ @artist.aliases.should be_instance_of(Array)
35
+ @artist.aliases[0].should == "Roooot"
36
+ end
37
+
38
+ it "should have one or more name variations" do
39
+ @artist.namevariations.should be_instance_of(Array)
40
+ @artist.namevariations[0].should == "Rootan"
41
+ end
42
+
43
+ it "should have one or more members" do
44
+ @artist.members.should be_instance_of(Array)
45
+ @artist.members[0].should == "Big Boss"
46
+ end
47
+
48
+ it "should be able to filter non-main releases" do
49
+ @artist.main_releases.should be_instance_of(Array)
50
+ @artist.main_releases.length.should == 4
51
+ end
52
+
53
+ it "should be able to filter non-bootleg releases" do
54
+ @artist.bootlegs.should be_instance_of(Array)
55
+ @artist.bootlegs.length.should == 1
56
+ end
57
+
58
+ it "should be able to filter non-main releases" do
59
+ @artist.appearances.should be_instance_of(Array)
60
+ @artist.appearances.length.should == 1
61
+ end
62
+
63
+ end
64
+
65
+ describe "when calling complex artist attributes" do
66
+
67
+ it "should have a traversible list of URLs" do
68
+ @artist.urls.should be_instance_of(Array)
69
+ @artist.urls[0].should == "http://www.root.net"
70
+ @artist.urls[1].should == "http://www.rootan.com"
71
+ end
72
+
73
+ it "should have a traversible list of images" do
74
+ @artist.images.should be_instance_of(Array)
75
+ @artist.images[0].should be_instance_of(Discogs::Image)
76
+ end
77
+
78
+ it "should have specifications for each image" do
79
+ specs = [ [ '350', '240', 'secondary' ], [ '222', '226', 'secondary' ], [ '600', '600', 'primary' ] ]
80
+ @artist.images.each_with_index do |image, index|
81
+ image.width.should == specs[index][0]
82
+ image.height.should == specs[index][1]
83
+ image.type.should == specs[index][2]
84
+ end
85
+ end
86
+
87
+ it "should have a traversible list of releases" do
88
+ @artist.releases.should be_instance_of(Array)
89
+ @artist.releases.length.should == 6
90
+ @artist.releases[0].should be_instance_of(Discogs::Artist::Release)
91
+ end
92
+
93
+ it "should have an ID for the first release" do
94
+ @artist.releases[0].id.should == "1805661"
95
+ end
96
+
97
+ it "should have a year for the first release" do
98
+ @artist.releases[0].year.should == "1991"
99
+ end
100
+
101
+ it "should have a label for the third release" do
102
+ @artist.releases[2].label.should == "Apollo"
103
+ end
104
+
105
+ end
106
+
107
+ end
108
+
109
+ end
@@ -0,0 +1,89 @@
1
+ require File.dirname(__FILE__) + "/../spec_helper"
2
+
3
+ describe Discogs::Wrapper do
4
+
5
+ before do
6
+ @wrapper = Discogs::Wrapper.new("some_key")
7
+ @artist_name = "Root"
8
+ end
9
+
10
+ describe "when asking for label information" do
11
+
12
+ before do
13
+ @http_request = mock(Net::HTTP)
14
+ @http_response = mock(Net::HTTPResponse, :code => "200", :body => valid_label_xml)
15
+ @http_response_as_file = mock(StringIO, :read => valid_label_xml)
16
+ Zlib::GzipReader.should_receive(:new).and_return(@http_response_as_file)
17
+ @http_request.should_receive(:start).and_return(@http_response)
18
+ Net::HTTP.should_receive(:new).and_return(@http_request)
19
+
20
+ @label = @wrapper.get_label(@label_name)
21
+ end
22
+
23
+ describe "when calling simple label attributes" do
24
+
25
+ it "should have a name attribute" do
26
+ @label.name.should == "Sombre Records"
27
+ end
28
+
29
+ it "should have a contact info attribute" do
30
+ @label.contactinfo.should == "Unknown, Germany"
31
+ end
32
+
33
+ it "should have a profile attribute" do
34
+ @label.profile.should == "Released some OK LPs"
35
+ end
36
+
37
+ it "should have a parent label attribute" do
38
+ @label.parentlabel.should == "SuperSombre"
39
+ end
40
+
41
+ it "should have one or more URLs" do
42
+ @label.urls.should be_instance_of(Array)
43
+ @label.urls[0].should == "http://www.sombrerecords.com"
44
+ @label.urls[1].should == "http://www.discogs.com/label/Sombre+Records"
45
+ end
46
+
47
+ end
48
+
49
+ describe "when calling complex artist attributes" do
50
+
51
+ it "should have a traversible list of images" do
52
+ @label.images.should be_instance_of(Array)
53
+ @label.images[0].should be_instance_of(Discogs::Image)
54
+ end
55
+
56
+ it "should have a traversible list of sub-labels" do
57
+ @label.sublabels.should be_instance_of(Array)
58
+ @label.sublabels[0].should == "SubSombre"
59
+ @label.sublabels[1].should == "Sony BMG"
60
+ end
61
+
62
+ it "should have specifications for each image" do
63
+ specs = [ [ '400', '300', 'primary' ], [ '450', '350', 'secondary' ] ]
64
+
65
+ @label.images.each_with_index do |image, index|
66
+ image.width.should == specs[index][0]
67
+ image.height.should == specs[index][1]
68
+ image.type.should == specs[index][2]
69
+ end
70
+ end
71
+
72
+ it "should have a traversible list of releases" do
73
+ @label.releases.should be_instance_of(Array)
74
+ @label.releases[0].should be_instance_of(Discogs::Label::Release)
75
+ end
76
+
77
+ it "should have a catno for the first release" do
78
+ @label.releases[0].catno.should == "SMB01"
79
+ end
80
+
81
+ it "should have an artist name for the second release" do
82
+ @label.releases[1].artist.should == "Moonblood"
83
+ end
84
+
85
+ end
86
+
87
+ end
88
+
89
+ end
@@ -0,0 +1,123 @@
1
+ require File.dirname(__FILE__) + "/../spec_helper"
2
+
3
+ describe Discogs::Wrapper do
4
+
5
+ before do
6
+ @wrapper = Discogs::Wrapper.new("some_key")
7
+ @release_id = "666666"
8
+ end
9
+
10
+ describe "when asking for release information" do
11
+
12
+ before do
13
+ @http_request = mock(Net::HTTP)
14
+ @http_response = mock(Net::HTTPResponse, :code => "200", :body => valid_release_xml)
15
+ @http_response_as_file = mock(StringIO, :read => valid_release_xml)
16
+ Zlib::GzipReader.should_receive(:new).and_return(@http_response_as_file)
17
+ @http_request.should_receive(:start).and_return(@http_response)
18
+ Net::HTTP.should_receive(:new).and_return(@http_request)
19
+
20
+ @release = @wrapper.get_release(@release_id)
21
+ end
22
+
23
+ describe "when calling simple release attributes" do
24
+
25
+ it "should have a title attribute" do
26
+ @release.title.should == "Into the Abyss"
27
+ end
28
+
29
+ it "should have an ID attribute" do
30
+ @release.id.should == "666666"
31
+ end
32
+
33
+ it "should have one or more extra artists" do
34
+ @release.extraartists.should be_instance_of(Array)
35
+ @release.extraartists[0].should be_instance_of(Discogs::Release::Artist)
36
+ end
37
+
38
+ it "should have one or more tracks" do
39
+ @release.tracklist.should be_instance_of(Array)
40
+ @release.tracklist[0].should be_instance_of(Discogs::Release::Track)
41
+ end
42
+
43
+ it "should have one or more genres" do
44
+ @release.genres.should be_instance_of(Array)
45
+ @release.genres[0].should == "Heavy Metal"
46
+ end
47
+
48
+ it "should have one or more formats" do
49
+ @release.formats.should be_instance_of(Array)
50
+ @release.formats[0].should be_instance_of(Discogs::Release::Format)
51
+ end
52
+
53
+ it "should have one or more images" do
54
+ @release.images.should be_instance_of(Array)
55
+ @release.images[0].should be_instance_of(Discogs::Image)
56
+ end
57
+
58
+ end
59
+
60
+ describe "when calling complex release attributes" do
61
+
62
+ it "should have a duration for the first track" do
63
+ @release.tracklist[0].duration.should == "8:11"
64
+ end
65
+
66
+ it "should have specifications for each image" do
67
+ specs = [ [ '600', '595', 'primary' ], [ '600', '593', 'secondary' ], [ '600', '539', 'secondary' ], [ '600', '452', 'secondary' ], [ '600', '567', 'secondary' ] ]
68
+ @release.images.each_with_index do |image, index|
69
+ image.width.should == specs[index][0]
70
+ image.height.should == specs[index][1]
71
+ image.type.should == specs[index][2]
72
+ end
73
+ end
74
+
75
+ it "should have a traversible list of styles" do
76
+ @release.styles.should be_instance_of(Array)
77
+ @release.styles[0].should == "Black Metal"
78
+ @release.styles[1].should == "Thrash"
79
+ end
80
+
81
+ it "should have a traversible list of labels" do
82
+ @release.styles.should be_instance_of(Array)
83
+ @release.labels[0].should be_instance_of(Discogs::Release::Label)
84
+ @release.labels[0].catno.should == "Death9"
85
+ @release.labels[0].name.should == "Culted"
86
+ end
87
+
88
+ it "should have a name and quantity for the first format" do
89
+ @release.formats[0].name.should == "CD"
90
+ @release.formats[0].qty.should == "1"
91
+ end
92
+
93
+ it "should have an array of descriptions for the first format" do
94
+ @release.formats[0].descriptions.should be_instance_of(Array)
95
+ @release.formats[0].descriptions[0].should == "Album"
96
+ end
97
+
98
+ it "should have an artist associated to the second track" do
99
+ @release.tracklist[1].artists.should be_instance_of(Array)
100
+ @release.tracklist[1].artists[0].should be_instance_of(Discogs::Release::Track::Artist)
101
+ @release.tracklist[1].artists[0].name.should == "Arakain"
102
+ end
103
+
104
+ it "should have an extra artist associated to the second track" do
105
+ @release.tracklist[1].extraartists.should be_instance_of(Array)
106
+ @release.tracklist[1].extraartists[0].should be_instance_of(Discogs::Release::Track::Artist)
107
+ @release.tracklist[1].extraartists[0].name.should == "Debustrol"
108
+ @release.tracklist[1].extraartists[0].role.should == "Sadism"
109
+ end
110
+
111
+ it "should have a role associated to the first extra artist" do
112
+ @release.extraartists[0].role.should == "Lyrics By"
113
+ end
114
+
115
+ it "should have no artist associated to the third track" do
116
+ @release.tracklist[2].artists.should be_nil
117
+ end
118
+
119
+ end
120
+
121
+ end
122
+
123
+ end
@@ -0,0 +1,330 @@
1
+ require File.dirname(__FILE__) + "/../spec_helper"
2
+
3
+ describe Discogs::Wrapper do
4
+
5
+ before do
6
+ @wrapper = Discogs::Wrapper.new("some_key")
7
+ @search_term = "slaughter"
8
+ end
9
+
10
+ def mock_search(page)
11
+ @http_request = mock(Net::HTTP)
12
+ @http_response = mock(Net::HTTPResponse, :code => "200", :body => valid_search_xml(page))
13
+ @http_response_as_file = mock(StringIO, :read => valid_search_xml(page))
14
+ Zlib::GzipReader.should_receive(:new).and_return(@http_response_as_file)
15
+ @http_request.should_receive(:start).and_return(@http_response)
16
+ Net::HTTP.should_receive(:new).and_return(@http_request)
17
+ end
18
+
19
+ describe "when asking for search result information" do
20
+
21
+ before do
22
+ mock_search(1)
23
+
24
+ @search = @wrapper.search(@search_term)
25
+ end
26
+
27
+ describe "when dealing with page information" do
28
+
29
+ it "should have a current_page method" do
30
+ @search.current_page.should == 1
31
+ end
32
+
33
+ it "should be able to report if this is the last page" do
34
+ @search.last_page?.should be_false
35
+ end
36
+
37
+ end
38
+
39
+ describe "when handling exact results" do
40
+
41
+ it "should have the exact results stored as an array" do
42
+ @search.exactresults.should be_instance_of(Array)
43
+ end
44
+
45
+ it "should be stored as result objects" do
46
+ @search.exactresults.each do |result|
47
+ result.should be_instance_of(Discogs::Search::Result)
48
+ end
49
+ end
50
+
51
+ it "should have a incrementing num for each exact result" do
52
+ @search.exactresults.each_with_index do |result, index|
53
+ result.num.should == (index + 1).to_s
54
+ end
55
+ end
56
+
57
+ it "should have a type for the first result" do
58
+ @search.exactresults[0].type.should == "artist"
59
+ end
60
+
61
+ it "should have an anv for the fifth result" do
62
+ @search.exactresults[5].anv.should == "Slaughter"
63
+ end
64
+
65
+ it "should be able to filter all non-artists from exact results" do
66
+ @search.exact(:artist).should be_instance_of(Array)
67
+ @search.exact(:artist).length.should == 6
68
+ end
69
+
70
+ it "should be able to filter all non-releases from exact results" do
71
+ @search.exact(:release).should be_instance_of(Array)
72
+ @search.exact(:release).length.should == 1
73
+ end
74
+
75
+ it "should be able to filter all non-labels from exact results" do
76
+ @search.exact(:label).should be_instance_of(Array)
77
+ @search.exact(:label).length.should == 1
78
+ end
79
+
80
+ it "should return an empty array on a junk filter" do
81
+ @search.exact(:cheesecake).should be_instance_of(Array)
82
+ @search.exact(:cheesecake).should be_empty
83
+ end
84
+
85
+ it "should simply return all exact results without a filter" do
86
+ @search.exact.should be_instance_of(Array)
87
+ @search.exact.length.should == 8
88
+ end
89
+
90
+ it "should have a shortcut for accessing the first exact artist" do
91
+ @search.closest(:artist).should be_instance_of(Discogs::Search::Result)
92
+ @search.closest(:artist).should == @search.exact(:artist)[0]
93
+ end
94
+
95
+ it "should have a shortcut for accessing the first exact release" do
96
+ @search.closest(:release).should be_instance_of(Discogs::Search::Result)
97
+ @search.closest(:release).should == @search.exact(:release)[0]
98
+ end
99
+
100
+ it "should have a shortcut for accessing the first exact label" do
101
+ @search.closest(:label).should be_instance_of(Discogs::Search::Result)
102
+ @search.closest(:label).should == @search.exact(:label)[0]
103
+ end
104
+
105
+ it "should return nil on junk filter for closest match" do
106
+ @search.closest(:alcoholic).should be_nil
107
+ end
108
+
109
+ end
110
+
111
+ describe "when handling search results" do
112
+
113
+ it "should have a start attribute" do
114
+ @search.start.should == "1"
115
+ end
116
+
117
+ it "should have an end attribute" do
118
+ @search.end.should == "20"
119
+ end
120
+
121
+ it "should have number of results attribute" do
122
+ @search.total_results.should == 1846
123
+ end
124
+
125
+ it "should have number of pages attribute" do
126
+ @search.total_pages.should == 93
127
+ end
128
+
129
+ it "should have the search results stored as an array" do
130
+ @search.searchresults.should be_instance_of(Array)
131
+ end
132
+
133
+ it "should be stored as result objects" do
134
+ @search.searchresults.each do |result|
135
+ result.should be_instance_of(Discogs::Search::Result)
136
+ end
137
+ end
138
+
139
+ end
140
+
141
+ describe "when handling search results" do
142
+
143
+ it "should have a start attribute" do
144
+ @search.start.should == "1"
145
+ end
146
+
147
+ it "should have an end attribute" do
148
+ @search.end.should == "20"
149
+ end
150
+
151
+ it "should have number of results attribute" do
152
+ @search.total_results.should == 1846
153
+ end
154
+
155
+ it "should have number of pages attribute" do
156
+ @search.total_pages.should == 93
157
+ end
158
+
159
+ it "should have the search results stored as an array" do
160
+ @search.searchresults.should be_instance_of(Array)
161
+ end
162
+
163
+ it "should be stored as result objects" do
164
+ @search.searchresults.each do |result|
165
+ result.should be_instance_of(Discogs::Search::Result)
166
+ end
167
+ end
168
+
169
+ end
170
+
171
+ describe "when handling search results" do
172
+
173
+ it "should have a start attribute" do
174
+ @search.start.should == "1"
175
+ end
176
+
177
+ it "should have an end attribute" do
178
+ @search.end.should == "20"
179
+ end
180
+
181
+ it "should have number of results attribute" do
182
+ @search.total_results.should == 1846
183
+ end
184
+
185
+ it "should have number of pages attribute" do
186
+ @search.total_pages.should == 93
187
+ end
188
+
189
+ it "should have the search results stored as an array" do
190
+ @search.searchresults.should be_instance_of(Array)
191
+ end
192
+
193
+ it "should be stored as result objects" do
194
+ @search.searchresults.each do |result|
195
+ result.should be_instance_of(Discogs::Search::Result)
196
+ end
197
+ end
198
+
199
+ it "should have a incrementing num for each search result" do
200
+ @search.searchresults.each_with_index do |result, index|
201
+ result.num.should == (index + 1).to_s
202
+ end
203
+ end
204
+
205
+ it "should have a type for the third result" do
206
+ @search.searchresults[2].type.should == "label"
207
+ end
208
+
209
+ it "should have a title for the fourth result" do
210
+ @search.searchresults[3].title.should == "Satanic Slaughter"
211
+ end
212
+
213
+ it "should have a summary for the sixth result" do
214
+ @search.searchresults[5].summary.should == "Gary Slaughter"
215
+ end
216
+
217
+ it "should be able to filter all non-artists from extended results" do
218
+ @search.results(:artist).should be_instance_of(Array)
219
+ @search.results(:artist).length.should == 12
220
+ end
221
+
222
+ it "should be able to filter all non-releases from extended results" do
223
+ @search.results(:release).should be_instance_of(Array)
224
+ @search.results(:release).length.should == 6
225
+ end
226
+
227
+ it "should be able to filter all non-labels from extended results" do
228
+ @search.results(:label).should be_instance_of(Array)
229
+ @search.results(:label).length.should == 2
230
+ end
231
+
232
+ it "should return an empty array on a junk filter" do
233
+ @search.results(:cheesecake).should be_instance_of(Array)
234
+ @search.results(:cheesecake).should be_empty
235
+ end
236
+
237
+ it "should simply return all extended results without a filter" do
238
+ @search.results.should be_instance_of(Array)
239
+ @search.results.length.should == 20
240
+ end
241
+
242
+ end
243
+
244
+ end
245
+
246
+ describe "when getting the next page" do
247
+
248
+ before do
249
+ mock_search(2)
250
+
251
+ @search = @wrapper.search(@search_term, :page => 2)
252
+ end
253
+
254
+ describe "when dealing with page information" do
255
+
256
+ it "should have a current_page method" do
257
+ @search.current_page.should == 2
258
+ end
259
+
260
+ it "should be able to report if this is the last page" do
261
+ @search.last_page?.should be_false
262
+ end
263
+
264
+ end
265
+
266
+ describe "when handling exact results" do
267
+
268
+ it "should not have any exact results" do
269
+ @search.exactresults.should be_nil
270
+ end
271
+
272
+ it "should return empty array for exact filtering" do
273
+ @search.exact.should == []
274
+ end
275
+
276
+ it "should still allow filtering and return an empty array" do
277
+ @search.exact(:artist).should == []
278
+ end
279
+
280
+ it "should return nil for closest matches when no exact results are available" do
281
+ @search.closest(:artist).should be_nil
282
+ @search.closest(:release).should be_nil
283
+ @search.closest(:label).should be_nil
284
+ end
285
+
286
+ it "should return nil on junk filter for closest match" do
287
+ @search.closest(:alcoholic).should be_nil
288
+ end
289
+
290
+ end
291
+
292
+ describe "when handling search results" do
293
+
294
+ it "should have a start attribute" do
295
+ @search.start.should == "21"
296
+ end
297
+
298
+ it "should have an end attribute" do
299
+ @search.end.should == "40"
300
+ end
301
+
302
+ it "should have number of results attribute" do
303
+ @search.total_results.should == 1846
304
+ end
305
+
306
+ it "should have number of pages attribute (still)" do
307
+ @search.total_pages.should == 93
308
+ end
309
+
310
+ it "should have the search results stored as an array" do
311
+ @search.searchresults.should be_instance_of(Array)
312
+ end
313
+
314
+ it "should be stored as result objects" do
315
+ @search.searchresults.each do |result|
316
+ result.should be_instance_of(Discogs::Search::Result)
317
+ end
318
+ end
319
+
320
+ it "should have a incrementing num for each search result" do
321
+ @search.searchresults.each_with_index do |result, index|
322
+ result.num.should == (index + 21).to_s
323
+ end
324
+ end
325
+
326
+ end
327
+
328
+ end
329
+
330
+ end