reagent-fleakr 0.4.3 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/lib/fleakr/api/option.rb +6 -6
- data/lib/fleakr/version.rb +2 -2
- data/lib/fleakr.rb +2 -1
- data/test/test_helper.rb +9 -8
- data/test/unit/fleakr/api/file_parameter_test.rb +8 -8
- data/test/unit/fleakr/api/method_request_test.rb +11 -10
- data/test/unit/fleakr/api/option_test.rb +29 -29
- data/test/unit/fleakr/api/parameter_list_test.rb +22 -22
- data/test/unit/fleakr/api/parameter_test.rb +5 -5
- data/test/unit/fleakr/api/response_test.rb +6 -6
- data/test/unit/fleakr/api/upload_request_test.rb +28 -24
- data/test/unit/fleakr/api/value_parameter_test.rb +6 -6
- data/test/unit/fleakr/core_ext/false_class_test.rb +2 -2
- data/test/unit/fleakr/core_ext/hash_test.rb +6 -6
- data/test/unit/fleakr/core_ext/true_class_test.rb +2 -2
- data/test/unit/fleakr/objects/authentication_token_test.rb +6 -6
- data/test/unit/fleakr/objects/comment_test.rb +8 -8
- data/test/unit/fleakr/objects/contact_test.rb +8 -5
- data/test/unit/fleakr/objects/error_test.rb +2 -2
- data/test/unit/fleakr/objects/group_test.rb +5 -5
- data/test/unit/fleakr/objects/image_test.rb +6 -6
- data/test/unit/fleakr/objects/photo_context_test.rb +11 -11
- data/test/unit/fleakr/objects/photo_test.rb +32 -29
- data/test/unit/fleakr/objects/search_test.rb +9 -9
- data/test/unit/fleakr/objects/set_test.rb +9 -9
- data/test/unit/fleakr/objects/tag_test.rb +12 -12
- data/test/unit/fleakr/objects/user_test.rb +10 -10
- data/test/unit/fleakr/support/attribute_test.rb +21 -21
- data/test/unit/fleakr/support/object_test.rb +17 -17
- data/test/unit/fleakr_test.rb +24 -24
- metadata +3 -3
@@ -8,7 +8,7 @@ module Fleakr::Objects
|
|
8
8
|
should_autoload_when_accessing :posted, :taken, :updated, :comment_count, :with => :load_info
|
9
9
|
should_autoload_when_accessing :url, :description, :with => :load_info
|
10
10
|
|
11
|
-
|
11
|
+
context "The Photo class" do
|
12
12
|
|
13
13
|
should_find_all :photos, :by => :user_id, :call => 'people.getPublicPhotos', :path => 'rsp/photos/photo'
|
14
14
|
should_find_all :photos, :by => :set_id, :using => :photoset_id, :call => 'photosets.getPhotos', :path => 'rsp/photoset/photo'
|
@@ -17,13 +17,12 @@ module Fleakr::Objects
|
|
17
17
|
should_find_one :photo, :by => :id, :with => :photo_id, :call => 'photos.getInfo'
|
18
18
|
|
19
19
|
# TODO: refactor these 2 tests
|
20
|
-
|
20
|
+
should "be able to upload a photo and return the new photo information" do
|
21
21
|
filename = '/path/to/mugshot.jpg'
|
22
22
|
photo = stub()
|
23
23
|
|
24
|
-
response = stub
|
25
|
-
|
26
|
-
end
|
24
|
+
response = stub()
|
25
|
+
response.stubs(:body).with().returns(Hpricot.XML('<photoid>123</photoid>'))
|
27
26
|
|
28
27
|
Fleakr::Api::UploadRequest.expects(:with_response!).with(filename, :create, {}).returns(response)
|
29
28
|
Photo.expects(:find_by_id).with('123').returns(photo)
|
@@ -31,13 +30,12 @@ module Fleakr::Objects
|
|
31
30
|
Photo.upload(filename).should == photo
|
32
31
|
end
|
33
32
|
|
34
|
-
|
33
|
+
should "be able to pass additional options when uploading a new file" do
|
35
34
|
filename = '/path/to/mugshot.jpg'
|
36
35
|
photo = stub()
|
37
36
|
|
38
|
-
response = stub
|
39
|
-
|
40
|
-
end
|
37
|
+
response = stub()
|
38
|
+
response.stubs(:body).with().returns(Hpricot.XML('<photoid>123</photoid>'))
|
41
39
|
|
42
40
|
Fleakr::Api::UploadRequest.expects(:with_response!).with(filename, :create, {:title => 'foo'}).returns(response)
|
43
41
|
Photo.expects(:find_by_id).with('123').returns(photo)
|
@@ -47,9 +45,9 @@ module Fleakr::Objects
|
|
47
45
|
|
48
46
|
end
|
49
47
|
|
50
|
-
|
48
|
+
context "An instance of the Photo class" do
|
51
49
|
|
52
|
-
|
50
|
+
should "be able to replace the associated photo data" do
|
53
51
|
filename = '/path/to/file.jpg'
|
54
52
|
response = stub(:body => 'body')
|
55
53
|
|
@@ -65,7 +63,7 @@ module Fleakr::Objects
|
|
65
63
|
end
|
66
64
|
|
67
65
|
context "when populating from the people_getPublicPhotos XML data" do
|
68
|
-
|
66
|
+
setup do
|
69
67
|
@object = Photo.new(Hpricot.XML(read_fixture('people.getPublicPhotos')).at('rsp/photos/photo'))
|
70
68
|
end
|
71
69
|
|
@@ -79,7 +77,7 @@ module Fleakr::Objects
|
|
79
77
|
end
|
80
78
|
|
81
79
|
context "when populating from the photo upload XML data" do
|
82
|
-
|
80
|
+
setup do
|
83
81
|
@object = Photo.new(Hpricot.XML('<photoid>123</photoid>'))
|
84
82
|
end
|
85
83
|
|
@@ -87,7 +85,7 @@ module Fleakr::Objects
|
|
87
85
|
end
|
88
86
|
|
89
87
|
context "when populating from the photos_getInfo XML data" do
|
90
|
-
|
88
|
+
setup do
|
91
89
|
@object = Photo.new(Hpricot.XML(read_fixture('photos.getInfo')))
|
92
90
|
|
93
91
|
end
|
@@ -109,12 +107,12 @@ module Fleakr::Objects
|
|
109
107
|
|
110
108
|
context "in general" do
|
111
109
|
|
112
|
-
|
110
|
+
setup do
|
113
111
|
@photo = Photo.new
|
114
112
|
@time = Time.parse('2009-08-01 00:00:00')
|
115
113
|
end
|
116
114
|
|
117
|
-
|
115
|
+
should "be able to retrieve additional information about the current user" do
|
118
116
|
photo_id = '1'
|
119
117
|
photo = Photo.new
|
120
118
|
photo.expects(:id).with().returns(photo_id)
|
@@ -125,22 +123,22 @@ module Fleakr::Objects
|
|
125
123
|
photo.load_info
|
126
124
|
end
|
127
125
|
|
128
|
-
|
126
|
+
should "have a value for :posted_at" do
|
129
127
|
@photo.expects(:posted).with().returns("#{@time.to_i}")
|
130
128
|
@photo.posted_at.to_s.should == @time.to_s
|
131
129
|
end
|
132
130
|
|
133
|
-
|
131
|
+
should "have a value for :taken_at" do
|
134
132
|
@photo.expects(:taken).with().returns(@time.strftime('%Y-%m-%d %H:%M:%S'))
|
135
133
|
@photo.taken_at.to_s.should == @time.to_s
|
136
134
|
end
|
137
135
|
|
138
|
-
|
136
|
+
should "have a value for :updated_at" do
|
139
137
|
@photo.expects(:updated).with().returns("#{@time.to_i}")
|
140
138
|
@photo.updated_at.to_s.should == @time.to_s
|
141
139
|
end
|
142
140
|
|
143
|
-
|
141
|
+
should "have a collection of images by size" do
|
144
142
|
photo = Photo.new
|
145
143
|
|
146
144
|
small_image, large_image = [stub(:size => 'Small'), stub(:size => 'Large')]
|
@@ -160,7 +158,7 @@ module Fleakr::Objects
|
|
160
158
|
end
|
161
159
|
|
162
160
|
[:square, :thumbnail, :small, :medium, :large, :original].each do |method|
|
163
|
-
|
161
|
+
should "have a reader for the :#{method} image" do
|
164
162
|
photo = Photo.new
|
165
163
|
image = stub()
|
166
164
|
|
@@ -169,7 +167,7 @@ module Fleakr::Objects
|
|
169
167
|
end
|
170
168
|
end
|
171
169
|
|
172
|
-
|
170
|
+
should "be able to retrieve the context for this photo" do
|
173
171
|
id = '1'
|
174
172
|
|
175
173
|
context = stub()
|
@@ -183,7 +181,7 @@ module Fleakr::Objects
|
|
183
181
|
photo.context.should == context
|
184
182
|
end
|
185
183
|
|
186
|
-
|
184
|
+
should "memoize the context data" do
|
187
185
|
id = '1'
|
188
186
|
|
189
187
|
context = stub()
|
@@ -197,25 +195,30 @@ module Fleakr::Objects
|
|
197
195
|
2.times { photo.context }
|
198
196
|
end
|
199
197
|
|
200
|
-
|
198
|
+
should "be able to retrieve the next photo" do
|
201
199
|
next_photo = stub()
|
200
|
+
context = mock()
|
201
|
+
context.expects(:next).with().returns(next_photo)
|
202
202
|
|
203
203
|
photo = Photo.new
|
204
|
-
|
204
|
+
|
205
|
+
photo.expects(:context).with().returns(context)
|
205
206
|
|
206
207
|
photo.next.should == next_photo
|
207
208
|
end
|
208
209
|
|
209
|
-
|
210
|
+
should "be able to retrieve the previous photo" do
|
210
211
|
previous_photo = stub()
|
212
|
+
context = mock()
|
213
|
+
context.expects(:previous).with().returns(previous_photo)
|
211
214
|
|
212
215
|
photo = Photo.new
|
213
|
-
photo.expects(:context).with().returns(
|
216
|
+
photo.expects(:context).with().returns(context)
|
214
217
|
|
215
218
|
photo.previous.should == previous_photo
|
216
219
|
end
|
217
220
|
|
218
|
-
|
221
|
+
should "be able to find the owner of the photo" do
|
219
222
|
owner = stub()
|
220
223
|
|
221
224
|
photo = Photo.new
|
@@ -226,7 +229,7 @@ module Fleakr::Objects
|
|
226
229
|
photo.owner.should == owner
|
227
230
|
end
|
228
231
|
|
229
|
-
|
232
|
+
should "memoize the owner information" do
|
230
233
|
photo = Photo.new
|
231
234
|
photo.stubs(:owner_id).with().returns('1')
|
232
235
|
|
@@ -3,45 +3,45 @@ require File.dirname(__FILE__) + '/../../../test_helper'
|
|
3
3
|
module Fleakr::Objects
|
4
4
|
class SearchTest < Test::Unit::TestCase
|
5
5
|
|
6
|
-
|
6
|
+
context "An instance of the Search class" do
|
7
7
|
|
8
|
-
|
8
|
+
should "be able to generate a list of tags from a single-valued parameter" do
|
9
9
|
search = Search.new(:tags => 'foo')
|
10
10
|
search.send(:tag_list).should == 'foo'
|
11
11
|
end
|
12
12
|
|
13
|
-
|
13
|
+
should "be able to generate a list of tags from multi-valued parameters" do
|
14
14
|
search = Search.new(:tags => %w(foo bar))
|
15
15
|
search.send(:tag_list).should == 'foo,bar'
|
16
16
|
end
|
17
17
|
|
18
|
-
|
18
|
+
should "be able to create parameters for the search" do
|
19
19
|
search = Search.new(:tags => %w(foo bar))
|
20
20
|
search.send(:parameters).should == {:tags => 'foo,bar'}
|
21
21
|
end
|
22
22
|
|
23
|
-
|
23
|
+
should "preserve the original :tags parameter if it is a comma-separated string" do
|
24
24
|
search = Search.new(:tags => 'one,two')
|
25
25
|
search.send(:parameters).should == {:tags => 'one,two'}
|
26
26
|
end
|
27
27
|
|
28
|
-
|
28
|
+
should "not have any :tags parameters if none are supplied" do
|
29
29
|
search = Search.new({})
|
30
30
|
search.send(:parameters).should == {}
|
31
31
|
end
|
32
32
|
|
33
|
-
|
33
|
+
should "convert the search term into the appropriate parameter" do
|
34
34
|
search = Search.new(:text => 'foo')
|
35
35
|
search.send(:parameters).should == {:text => 'foo'}
|
36
36
|
end
|
37
37
|
|
38
|
-
|
38
|
+
should "be able to search photos based on text" do
|
39
39
|
response = mock_request_cycle :for => 'photos.search', :with => {:text => 'foo'}
|
40
40
|
search = Search.new(:text => 'foo')
|
41
41
|
search.results
|
42
42
|
end
|
43
43
|
|
44
|
-
|
44
|
+
should "be able to search photos based on tags" do
|
45
45
|
response = mock_request_cycle :for => 'photos.search', :with => {:tags => 'one,two'}
|
46
46
|
|
47
47
|
photo_1, photo_2 = [stub(), stub()]
|
@@ -5,16 +5,16 @@ module Fleakr::Objects
|
|
5
5
|
|
6
6
|
should_have_many :photos, :comments
|
7
7
|
|
8
|
-
|
8
|
+
context "The Set class" do
|
9
9
|
|
10
10
|
should_find_all :sets, :by => :user_id, :call => 'photosets.getList', :path => 'rsp/photosets/photoset'
|
11
11
|
|
12
12
|
end
|
13
13
|
|
14
|
-
|
14
|
+
context "An instance of the Set class" do
|
15
15
|
|
16
16
|
context "when populating from an XML document" do
|
17
|
-
|
17
|
+
setup do
|
18
18
|
@object = Set.new(Hpricot.XML(read_fixture('photosets.getList')).at('rsp/photosets/photoset'))
|
19
19
|
end
|
20
20
|
|
@@ -26,7 +26,7 @@ module Fleakr::Objects
|
|
26
26
|
end
|
27
27
|
|
28
28
|
context "when saving the set" do
|
29
|
-
|
29
|
+
setup do
|
30
30
|
@tmp_dir = create_temp_directory
|
31
31
|
@set_title = 'set'
|
32
32
|
|
@@ -34,9 +34,9 @@ module Fleakr::Objects
|
|
34
34
|
@set.stubs(:title).with().returns(@set_title)
|
35
35
|
end
|
36
36
|
|
37
|
-
|
37
|
+
teardown { FileUtils.rm_rf(@tmp_dir) }
|
38
38
|
|
39
|
-
|
39
|
+
should "know the prefix string based on the number of photos in the set" do
|
40
40
|
set = Set.new
|
41
41
|
set.stubs(:count).with().returns('5')
|
42
42
|
set.file_prefix(0).should == '1_'
|
@@ -45,7 +45,7 @@ module Fleakr::Objects
|
|
45
45
|
set.file_prefix(0).should == '01_'
|
46
46
|
end
|
47
47
|
|
48
|
-
|
48
|
+
should "save all files of the specified size to the specified directory" do
|
49
49
|
image = mock()
|
50
50
|
image.expects(:save_to).with("#{@tmp_dir}/set", '1_')
|
51
51
|
|
@@ -59,7 +59,7 @@ module Fleakr::Objects
|
|
59
59
|
@set.save_to(@tmp_dir, :small)
|
60
60
|
end
|
61
61
|
|
62
|
-
|
62
|
+
should "not create the directory if it already exists" do
|
63
63
|
FileUtils.mkdir("#{@tmp_dir}/set")
|
64
64
|
|
65
65
|
@set.stubs(:photos).with().returns([])
|
@@ -69,7 +69,7 @@ module Fleakr::Objects
|
|
69
69
|
@set.save_to(@tmp_dir, :small)
|
70
70
|
end
|
71
71
|
|
72
|
-
|
72
|
+
should "not raise errors when saving an image size that doesn't exist" do
|
73
73
|
@set.stubs(:photos).with().returns([stub(:large => nil)])
|
74
74
|
lambda { @set.save_to(@tmp_dir, :large) }.should_not raise_error
|
75
75
|
end
|
@@ -3,18 +3,18 @@ require File.dirname(__FILE__) + '/../../../test_helper'
|
|
3
3
|
module Fleakr::Objects
|
4
4
|
class TagTest < Test::Unit::TestCase
|
5
5
|
|
6
|
-
|
6
|
+
context "The Tag class" do
|
7
7
|
|
8
8
|
should_find_all :tags, :by => :photo_id, :call => 'tags.getListPhoto', :path => 'rsp/photo/tags/tag'
|
9
9
|
should_find_all :tags, :by => :user_id, :call => 'tags.getListUser', :path => 'rsp/who/tags/tag'
|
10
10
|
end
|
11
11
|
|
12
|
-
|
12
|
+
context "An instance of the Tag class" do
|
13
13
|
|
14
|
-
|
14
|
+
setup { @tag = Tag.new }
|
15
15
|
|
16
16
|
context "when populating from the tags_getListPhoto XML data" do
|
17
|
-
|
17
|
+
setup do
|
18
18
|
@object = Tag.new(Hpricot.XML(read_fixture('tags.getListPhoto')).at('rsp/photo/tags/tag'))
|
19
19
|
end
|
20
20
|
|
@@ -26,7 +26,7 @@ module Fleakr::Objects
|
|
26
26
|
|
27
27
|
end
|
28
28
|
|
29
|
-
|
29
|
+
should "have an author" do
|
30
30
|
user = stub()
|
31
31
|
|
32
32
|
@tag.expects(:author_id).at_least_once.with().returns('1')
|
@@ -37,7 +37,7 @@ module Fleakr::Objects
|
|
37
37
|
@tag.author.should == user
|
38
38
|
end
|
39
39
|
|
40
|
-
|
40
|
+
should "memoize the author data" do
|
41
41
|
@tag.expects(:author_id).at_least_once.with().returns('1')
|
42
42
|
|
43
43
|
User.expects(:find_by_id).with('1').once.returns(stub())
|
@@ -45,13 +45,13 @@ module Fleakr::Objects
|
|
45
45
|
2.times { @tag.author }
|
46
46
|
end
|
47
47
|
|
48
|
-
|
48
|
+
should "return nil for author if author_id is not present" do
|
49
49
|
@tag.expects(:author_id).with().returns(nil)
|
50
50
|
|
51
51
|
@tag.author.should be(nil)
|
52
52
|
end
|
53
53
|
|
54
|
-
|
54
|
+
should "have related tags" do
|
55
55
|
@tag.expects(:value).with().returns('foo')
|
56
56
|
|
57
57
|
response = mock_request_cycle :for => 'tags.getRelated', :with => {:tag => 'foo'}
|
@@ -69,7 +69,7 @@ module Fleakr::Objects
|
|
69
69
|
@tag.related.should == stubs
|
70
70
|
end
|
71
71
|
|
72
|
-
|
72
|
+
should "memoize the data for related tags" do
|
73
73
|
@tag.expects(:value).with().returns('foo')
|
74
74
|
|
75
75
|
mock_request_cycle :for => 'tags.getRelated', :with => {:tag => 'foo'}
|
@@ -77,17 +77,17 @@ module Fleakr::Objects
|
|
77
77
|
2.times { @tag.related }
|
78
78
|
end
|
79
79
|
|
80
|
-
|
80
|
+
should "be able to generate a string representation of itself" do
|
81
81
|
@tag.expects(:value).with().returns('foo')
|
82
82
|
@tag.to_s.should == 'foo'
|
83
83
|
end
|
84
84
|
|
85
|
-
|
85
|
+
should "know that it is not a machine tag" do
|
86
86
|
@tag.expects(:machine_flag).with().returns('0')
|
87
87
|
@tag.machine?.should be(false)
|
88
88
|
end
|
89
89
|
|
90
|
-
|
90
|
+
should "know that it is a machine tag" do
|
91
91
|
@tag.expects(:machine_flag).with().returns('1')
|
92
92
|
@tag.machine?.should be(true)
|
93
93
|
end
|
@@ -10,7 +10,7 @@ module Fleakr::Objects
|
|
10
10
|
should_autoload_when_accessing :name, :photos_url, :profile_url, :photos_count, :location, :with => :load_info
|
11
11
|
should_autoload_when_accessing :icon_server, :icon_farm, :pro, :admin, :icon_url, :with => :load_info
|
12
12
|
|
13
|
-
|
13
|
+
context "The User class" do
|
14
14
|
|
15
15
|
should_find_one :user, :by => :username, :call => 'people.findByUsername', :path => 'rsp/user'
|
16
16
|
should_find_one :user, :by => :email, :with => :find_email, :call => 'people.findByEmail', :path => 'rsp/user'
|
@@ -18,9 +18,9 @@ module Fleakr::Objects
|
|
18
18
|
|
19
19
|
end
|
20
20
|
|
21
|
-
|
21
|
+
context "An instance of User" do
|
22
22
|
context "when populating the object from an XML document" do
|
23
|
-
|
23
|
+
setup do
|
24
24
|
@object = User.new(Hpricot.XML(read_fixture('people.findByUsername')))
|
25
25
|
@object.populate_from(Hpricot.XML(read_fixture('people.getInfo')))
|
26
26
|
end
|
@@ -41,16 +41,16 @@ module Fleakr::Objects
|
|
41
41
|
|
42
42
|
context "in general" do
|
43
43
|
|
44
|
-
|
44
|
+
setup { @user = User.new }
|
45
45
|
|
46
|
-
|
46
|
+
should "be able to retrieve additional information about the current user" do
|
47
47
|
response = mock_request_cycle :for => 'people.getInfo', :with => {:user_id => @user.id}
|
48
48
|
@user.expects(:populate_from).with(response.body)
|
49
49
|
|
50
50
|
@user.load_info
|
51
51
|
end
|
52
52
|
|
53
|
-
|
53
|
+
should "be able to generate an icon URL when the :icon_server value is greater than zero" do
|
54
54
|
@user.stubs(:icon_server).with().returns('1')
|
55
55
|
@user.stubs(:icon_farm).with().returns('2')
|
56
56
|
@user.stubs(:id).with().returns('45')
|
@@ -58,17 +58,17 @@ module Fleakr::Objects
|
|
58
58
|
@user.icon_url.should == 'http://farm2.static.flickr.com/1/buddyicons/45.jpg'
|
59
59
|
end
|
60
60
|
|
61
|
-
|
61
|
+
should "return the default icon URL when the :icon_server value is zero" do
|
62
62
|
@user.stubs(:icon_server).with().returns('0')
|
63
63
|
@user.icon_url.should == 'http://www.flickr.com/images/buddyicon.jpg'
|
64
64
|
end
|
65
65
|
|
66
|
-
|
66
|
+
should "return the default icon URL when the :icon_server value is nil" do
|
67
67
|
@user.stubs(:icon_server).with().returns(nil)
|
68
68
|
@user.icon_url.should == 'http://www.flickr.com/images/buddyicon.jpg'
|
69
69
|
end
|
70
70
|
|
71
|
-
|
71
|
+
should "return a boolean value for :pro?" do
|
72
72
|
@user.stubs(:pro).with().returns('0')
|
73
73
|
@user.pro?.should be(false)
|
74
74
|
|
@@ -76,7 +76,7 @@ module Fleakr::Objects
|
|
76
76
|
@user.pro?.should be(true)
|
77
77
|
end
|
78
78
|
|
79
|
-
|
79
|
+
should "return a boolean value for :admin?" do
|
80
80
|
@user.stubs(:admin).with().returns('0')
|
81
81
|
@user.admin?.should be(false)
|
82
82
|
|
@@ -2,59 +2,59 @@ require File.dirname(__FILE__) + '/../../../test_helper'
|
|
2
2
|
|
3
3
|
module Fleakr::Support
|
4
4
|
class AttributeTest < Test::Unit::TestCase
|
5
|
-
|
5
|
+
context "An instance of the Attribute class" do
|
6
6
|
|
7
|
-
|
7
|
+
should "know the name of the attribute" do
|
8
8
|
attr = Attribute.new('foo')
|
9
9
|
attr.name.should == :foo
|
10
10
|
end
|
11
11
|
|
12
|
-
|
12
|
+
should "have a default source" do
|
13
13
|
attr = Attribute.new(:foo)
|
14
14
|
attr.sources.should == ['foo']
|
15
15
|
end
|
16
16
|
|
17
|
-
|
17
|
+
should "be able to assign multiple sources" do
|
18
18
|
attr = Attribute.new(:foo, ['foo1', 'foo2'])
|
19
19
|
attr.sources.should == ['foo1', 'foo2']
|
20
20
|
end
|
21
21
|
|
22
|
-
|
22
|
+
should "pull the location from the source" do
|
23
23
|
attr = Attribute.new('foo')
|
24
24
|
attr.location('foo').should == 'foo'
|
25
25
|
end
|
26
26
|
|
27
|
-
|
27
|
+
should "return the location when splitting" do
|
28
28
|
attr = Attribute.new('foo')
|
29
29
|
attr.split('foo').should == ['foo', nil]
|
30
30
|
end
|
31
31
|
|
32
|
-
|
32
|
+
should "return the name for the location when splitting if the location isn't specified" do
|
33
33
|
attr = Attribute.new('foo')
|
34
34
|
attr.split('@bar').should == ['foo', 'bar']
|
35
35
|
end
|
36
36
|
|
37
|
-
|
37
|
+
should "allow the setting of the location information" do
|
38
38
|
attr = Attribute.new('foo', 'bar')
|
39
39
|
attr.sources.should == ['bar']
|
40
40
|
end
|
41
41
|
|
42
|
-
|
42
|
+
should "allow the setting of the attribute value" do
|
43
43
|
attr = Attribute.new('foo')
|
44
44
|
attr.attribute('@bogon').should == 'bogon'
|
45
45
|
end
|
46
46
|
|
47
|
-
|
47
|
+
should "use the location as the attribute" do
|
48
48
|
attr = Attribute.new('foo')
|
49
49
|
attr.attribute('foo').should == 'foo'
|
50
50
|
end
|
51
51
|
|
52
|
-
|
52
|
+
should "use the attribute for the attribute if specified" do
|
53
53
|
attr = Attribute.new(:id, '@nsid')
|
54
54
|
attr.attribute('@nsid').should == 'nsid'
|
55
55
|
end
|
56
56
|
|
57
|
-
|
57
|
+
should "be able to retrieve the node from the path" do
|
58
58
|
document = Hpricot.XML('<name>Bassdrive</name>')
|
59
59
|
expected = document.at('name')
|
60
60
|
|
@@ -62,7 +62,7 @@ module Fleakr::Support
|
|
62
62
|
attr.node_for(document, 'name').should == expected
|
63
63
|
end
|
64
64
|
|
65
|
-
|
65
|
+
should "be able to retrieve the node that contains the specified attribute" do
|
66
66
|
document = Hpricot.XML('<user id="1337" />')
|
67
67
|
expected = document.at('user')
|
68
68
|
|
@@ -70,7 +70,7 @@ module Fleakr::Support
|
|
70
70
|
attr.node_for(document, '@id').should == expected
|
71
71
|
end
|
72
72
|
|
73
|
-
|
73
|
+
should "be able to retrieve the node for the specified attribute" do
|
74
74
|
document = Hpricot.XML('<user nsid="1337" />')
|
75
75
|
expected = document.at('user')
|
76
76
|
|
@@ -78,43 +78,43 @@ module Fleakr::Support
|
|
78
78
|
attr.node_for(document, '@nsid').should == expected
|
79
79
|
end
|
80
80
|
|
81
|
-
|
81
|
+
should "be able to pull simple values from an XML document" do
|
82
82
|
document = Hpricot.XML('<name>Bassdrive</name>')
|
83
83
|
attr = Attribute.new(:name)
|
84
84
|
attr.value_from(document).should == 'Bassdrive'
|
85
85
|
end
|
86
86
|
|
87
|
-
|
87
|
+
should "be able to pull an attribute value from the current XML node" do
|
88
88
|
document = Hpricot.XML('<user id="1337" />')
|
89
89
|
attr = Attribute.new(:id)
|
90
90
|
attr.value_from(document).should == '1337'
|
91
91
|
end
|
92
92
|
|
93
|
-
|
93
|
+
should "be able to pull a specific attribute value from the current XML node" do
|
94
94
|
document = Hpricot.XML('<user nsid="1337" />')
|
95
95
|
attr = Attribute.new(:id, '@nsid')
|
96
96
|
attr.value_from(document).should == '1337'
|
97
97
|
end
|
98
98
|
|
99
|
-
|
99
|
+
should "be able to pull an attribute value for a node and attribute" do
|
100
100
|
document = Hpricot.XML('<station><genre slug="dnb">Drum & Bass</genre></station>')
|
101
101
|
attr = Attribute.new(:slug, 'station/genre@slug')
|
102
102
|
attr.value_from(document).should == 'dnb'
|
103
103
|
end
|
104
104
|
|
105
|
-
|
105
|
+
should "be able to pull a value from a nested XML node" do
|
106
106
|
document = Hpricot.XML('<rsp><user>blip</user></rsp>')
|
107
107
|
attr = Attribute.new(:user)
|
108
108
|
attr.value_from(document).should == 'blip'
|
109
109
|
end
|
110
110
|
|
111
|
-
|
111
|
+
should "return nil if it cannot find the specified node" do
|
112
112
|
document = Hpricot.XML('<user id="1" />')
|
113
113
|
attr = Attribute.new(:photoset, '@nsid')
|
114
114
|
attr.value_from(document).should be(nil)
|
115
115
|
end
|
116
116
|
|
117
|
-
|
117
|
+
should "be able to try a series of nodes to find a value" do
|
118
118
|
document = Hpricot.XML('<photoid>123</photoid>')
|
119
119
|
|
120
120
|
attr = Attribute.new(:id, ['photo@nsid', 'photoid'])
|