slaskis-fleakr 0.5.0
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/README.rdoc +350 -0
- data/Rakefile +41 -0
- data/lib/fleakr.rb +164 -0
- data/lib/fleakr/api.rb +8 -0
- data/lib/fleakr/api/file_parameter.rb +47 -0
- data/lib/fleakr/api/method_request.rb +66 -0
- data/lib/fleakr/api/option.rb +175 -0
- data/lib/fleakr/api/parameter.rb +35 -0
- data/lib/fleakr/api/parameter_list.rb +97 -0
- data/lib/fleakr/api/response.rb +35 -0
- data/lib/fleakr/api/upload_request.rb +75 -0
- data/lib/fleakr/api/value_parameter.rb +36 -0
- data/lib/fleakr/core_ext.rb +3 -0
- data/lib/fleakr/core_ext/false_class.rb +7 -0
- data/lib/fleakr/core_ext/hash.rb +22 -0
- data/lib/fleakr/core_ext/true_class.rb +7 -0
- data/lib/fleakr/objects.rb +13 -0
- data/lib/fleakr/objects/authentication_token.rb +60 -0
- data/lib/fleakr/objects/comment.rb +49 -0
- data/lib/fleakr/objects/contact.rb +31 -0
- data/lib/fleakr/objects/error.rb +22 -0
- data/lib/fleakr/objects/group.rb +36 -0
- data/lib/fleakr/objects/image.rb +50 -0
- data/lib/fleakr/objects/photo.rb +147 -0
- data/lib/fleakr/objects/photo_context.rb +49 -0
- data/lib/fleakr/objects/search.rb +30 -0
- data/lib/fleakr/objects/set.rb +51 -0
- data/lib/fleakr/objects/tag.rb +56 -0
- data/lib/fleakr/objects/user.rb +95 -0
- data/lib/fleakr/support.rb +2 -0
- data/lib/fleakr/support/attribute.rb +46 -0
- data/lib/fleakr/support/object.rb +112 -0
- data/lib/fleakr/version.rb +13 -0
- data/test/fixtures/auth.checkToken.xml +8 -0
- data/test/fixtures/auth.getFullToken.xml +8 -0
- data/test/fixtures/auth.getToken.xml +8 -0
- data/test/fixtures/contacts.getPublicList.xml +7 -0
- data/test/fixtures/groups.pools.getPhotos.xml +7 -0
- data/test/fixtures/people.findByEmail.xml +6 -0
- data/test/fixtures/people.findByUsername.xml +6 -0
- data/test/fixtures/people.getInfo.xml +18 -0
- data/test/fixtures/people.getPublicGroups.xml +7 -0
- data/test/fixtures/people.getPublicPhotos.xml +7 -0
- data/test/fixtures/photos.comments.getList.xml +7 -0
- data/test/fixtures/photos.getContext.xml +6 -0
- data/test/fixtures/photos.getInfo.xml +20 -0
- data/test/fixtures/photos.getSizes.xml +10 -0
- data/test/fixtures/photos.search.xml +7 -0
- data/test/fixtures/photosets.comments.getList.xml +7 -0
- data/test/fixtures/photosets.getList.xml +13 -0
- data/test/fixtures/photosets.getPhotos.xml +7 -0
- data/test/fixtures/tags.getListPhoto.xml +9 -0
- data/test/fixtures/tags.getListUser.xml +10 -0
- data/test/fixtures/tags.getRelated.xml +9 -0
- data/test/test_helper.rb +141 -0
- data/test/unit/fleakr/api/file_parameter_test.rb +63 -0
- data/test/unit/fleakr/api/method_request_test.rb +94 -0
- data/test/unit/fleakr/api/option_test.rb +179 -0
- data/test/unit/fleakr/api/parameter_list_test.rb +176 -0
- data/test/unit/fleakr/api/parameter_test.rb +34 -0
- data/test/unit/fleakr/api/response_test.rb +49 -0
- data/test/unit/fleakr/api/upload_request_test.rb +149 -0
- data/test/unit/fleakr/api/value_parameter_test.rb +41 -0
- data/test/unit/fleakr/core_ext/false_class_test.rb +13 -0
- data/test/unit/fleakr/core_ext/hash_test.rb +32 -0
- data/test/unit/fleakr/core_ext/true_class_test.rb +13 -0
- data/test/unit/fleakr/objects/authentication_token_test.rb +61 -0
- data/test/unit/fleakr/objects/comment_test.rb +66 -0
- data/test/unit/fleakr/objects/contact_test.rb +61 -0
- data/test/unit/fleakr/objects/error_test.rb +21 -0
- data/test/unit/fleakr/objects/group_test.rb +46 -0
- data/test/unit/fleakr/objects/image_test.rb +81 -0
- data/test/unit/fleakr/objects/photo_context_test.rb +80 -0
- data/test/unit/fleakr/objects/photo_test.rb +246 -0
- data/test/unit/fleakr/objects/search_test.rb +74 -0
- data/test/unit/fleakr/objects/set_test.rb +82 -0
- data/test/unit/fleakr/objects/tag_test.rb +98 -0
- data/test/unit/fleakr/objects/user_test.rb +91 -0
- data/test/unit/fleakr/support/attribute_test.rb +126 -0
- data/test/unit/fleakr/support/object_test.rb +129 -0
- data/test/unit/fleakr_test.rb +171 -0
- metadata +175 -0
@@ -0,0 +1,74 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../../test_helper'
|
2
|
+
|
3
|
+
module Fleakr::Objects
|
4
|
+
class SearchTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
context "An instance of the Search class" do
|
7
|
+
|
8
|
+
should "be able to generate a list of tags from a single-valued parameter" do
|
9
|
+
search = Search.new(:tags => 'foo')
|
10
|
+
search.send(:tag_list).should == 'foo'
|
11
|
+
end
|
12
|
+
|
13
|
+
should "be able to generate a list of tags from multi-valued parameters" do
|
14
|
+
search = Search.new(:tags => %w(foo bar))
|
15
|
+
search.send(:tag_list).should == 'foo,bar'
|
16
|
+
end
|
17
|
+
|
18
|
+
should "be able to create parameters for the search" do
|
19
|
+
search = Search.new(:tags => %w(foo bar))
|
20
|
+
search.send(:parameters).should == {:tags => 'foo,bar'}
|
21
|
+
end
|
22
|
+
|
23
|
+
should "preserve the original :tags parameter if it is a comma-separated string" do
|
24
|
+
search = Search.new(:tags => 'one,two')
|
25
|
+
search.send(:parameters).should == {:tags => 'one,two'}
|
26
|
+
end
|
27
|
+
|
28
|
+
should "not have any :tags parameters if none are supplied" do
|
29
|
+
search = Search.new({})
|
30
|
+
search.send(:parameters).should == {}
|
31
|
+
end
|
32
|
+
|
33
|
+
should "convert the search term into the appropriate parameter" do
|
34
|
+
search = Search.new(:text => 'foo')
|
35
|
+
search.send(:parameters).should == {:text => 'foo'}
|
36
|
+
end
|
37
|
+
|
38
|
+
should "be able to search photos based on text" do
|
39
|
+
response = mock_request_cycle :for => 'photos.search', :with => {:text => 'foo'}
|
40
|
+
search = Search.new(:text => 'foo')
|
41
|
+
search.results
|
42
|
+
end
|
43
|
+
|
44
|
+
should "be able to search photos based on tags" do
|
45
|
+
response = mock_request_cycle :for => 'photos.search', :with => {:tags => 'one,two'}
|
46
|
+
|
47
|
+
photo_1, photo_2 = [stub(), stub()]
|
48
|
+
photo_1_doc, photo_2_doc = (response.body/'rsp/photos/photo').map {|doc| doc }
|
49
|
+
|
50
|
+
Photo.expects(:new).with(photo_1_doc).returns(photo_1)
|
51
|
+
Photo.expects(:new).with(photo_2_doc).returns(photo_2)
|
52
|
+
|
53
|
+
search = Search.new(:tags => %w(one two))
|
54
|
+
search.results.should == [photo_1, photo_2]
|
55
|
+
end
|
56
|
+
|
57
|
+
should "memoize the search results" do
|
58
|
+
response = stub(:body => Hpricot.XML(read_fixture('photos.search')))
|
59
|
+
Fleakr::Api::MethodRequest.expects(:with_response!).with(kind_of(String), kind_of(Hash)).once.returns(response)
|
60
|
+
|
61
|
+
(response.body/'rsp/photos/photo').each do |doc|
|
62
|
+
Photo.expects(:new).with(doc).once
|
63
|
+
end
|
64
|
+
|
65
|
+
search = Search.new(:tags => %w(foo))
|
66
|
+
|
67
|
+
2.times { search.results }
|
68
|
+
end
|
69
|
+
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../../test_helper'
|
2
|
+
|
3
|
+
module Fleakr::Objects
|
4
|
+
class SetTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
should_have_many :photos, :comments
|
7
|
+
|
8
|
+
context "The Set class" do
|
9
|
+
|
10
|
+
should_find_all :sets, :by => :user_id, :call => 'photosets.getList', :path => 'rsp/photosets/photoset'
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
context "An instance of the Set class" do
|
15
|
+
|
16
|
+
context "when populating from an XML document" do
|
17
|
+
setup do
|
18
|
+
@object = Set.new(Hpricot.XML(read_fixture('photosets.getList')).at('rsp/photosets/photoset'))
|
19
|
+
end
|
20
|
+
|
21
|
+
should_have_a_value_for :id => '72157609490909659'
|
22
|
+
should_have_a_value_for :title => 'Second Set'
|
23
|
+
should_have_a_value_for :description => 'This is the second set.'
|
24
|
+
should_have_a_value_for :count => '138'
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
context "when saving the set" do
|
29
|
+
setup do
|
30
|
+
@tmp_dir = create_temp_directory
|
31
|
+
@set_title = 'set'
|
32
|
+
|
33
|
+
@set = Set.new
|
34
|
+
@set.stubs(:title).with().returns(@set_title)
|
35
|
+
end
|
36
|
+
|
37
|
+
teardown { FileUtils.rm_rf(@tmp_dir) }
|
38
|
+
|
39
|
+
should "know the prefix string based on the number of photos in the set" do
|
40
|
+
set = Set.new
|
41
|
+
set.stubs(:count).with().returns('5')
|
42
|
+
set.file_prefix(0).should == '1_'
|
43
|
+
|
44
|
+
set.stubs(:count).with().returns('99')
|
45
|
+
set.file_prefix(0).should == '01_'
|
46
|
+
end
|
47
|
+
|
48
|
+
should "save all files of the specified size to the specified directory" do
|
49
|
+
image = mock()
|
50
|
+
image.expects(:save_to).with("#{@tmp_dir}/set", '1_')
|
51
|
+
|
52
|
+
photo = stub(:small => image)
|
53
|
+
|
54
|
+
@set.stubs(:photos).with().returns([photo])
|
55
|
+
@set.stubs(:file_prefix).with(0).returns('1_')
|
56
|
+
|
57
|
+
FileUtils.expects(:mkdir).with("#{@tmp_dir}/set")
|
58
|
+
|
59
|
+
@set.save_to(@tmp_dir, :small)
|
60
|
+
end
|
61
|
+
|
62
|
+
should "not create the directory if it already exists" do
|
63
|
+
FileUtils.mkdir("#{@tmp_dir}/set")
|
64
|
+
|
65
|
+
@set.stubs(:photos).with().returns([])
|
66
|
+
|
67
|
+
FileUtils.expects(:mkdir).with("#{@tmp_dir}/set").never
|
68
|
+
|
69
|
+
@set.save_to(@tmp_dir, :small)
|
70
|
+
end
|
71
|
+
|
72
|
+
should "not raise errors when saving an image size that doesn't exist" do
|
73
|
+
@set.stubs(:photos).with().returns([stub(:large => nil)])
|
74
|
+
lambda { @set.save_to(@tmp_dir, :large) }.should_not raise_error
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../../test_helper'
|
2
|
+
|
3
|
+
module Fleakr::Objects
|
4
|
+
class TagTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
context "The Tag class" do
|
7
|
+
|
8
|
+
should_find_all :tags, :by => :photo_id, :call => 'tags.getListPhoto', :path => 'rsp/photo/tags/tag'
|
9
|
+
should_find_all :tags, :by => :user_id, :call => 'tags.getListUser', :path => 'rsp/who/tags/tag'
|
10
|
+
end
|
11
|
+
|
12
|
+
context "An instance of the Tag class" do
|
13
|
+
|
14
|
+
setup { @tag = Tag.new }
|
15
|
+
|
16
|
+
context "when populating from the tags_getListPhoto XML data" do
|
17
|
+
setup do
|
18
|
+
@object = Tag.new(Hpricot.XML(read_fixture('tags.getListPhoto')).at('rsp/photo/tags/tag'))
|
19
|
+
end
|
20
|
+
|
21
|
+
should_have_a_value_for :id => '1'
|
22
|
+
should_have_a_value_for :author_id => '15498419@N05'
|
23
|
+
should_have_a_value_for :value => 'stu72'
|
24
|
+
should_have_a_value_for :raw => 'stu 72'
|
25
|
+
should_have_a_value_for :machine_flag => '0'
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
should "have an author" do
|
30
|
+
user = stub()
|
31
|
+
|
32
|
+
@tag.expects(:author_id).at_least_once.with().returns('1')
|
33
|
+
|
34
|
+
|
35
|
+
User.expects(:find_by_id).with('1').returns(user)
|
36
|
+
|
37
|
+
@tag.author.should == user
|
38
|
+
end
|
39
|
+
|
40
|
+
should "memoize the author data" do
|
41
|
+
@tag.expects(:author_id).at_least_once.with().returns('1')
|
42
|
+
|
43
|
+
User.expects(:find_by_id).with('1').once.returns(stub())
|
44
|
+
|
45
|
+
2.times { @tag.author }
|
46
|
+
end
|
47
|
+
|
48
|
+
should "return nil for author if author_id is not present" do
|
49
|
+
@tag.expects(:author_id).with().returns(nil)
|
50
|
+
|
51
|
+
@tag.author.should be(nil)
|
52
|
+
end
|
53
|
+
|
54
|
+
should "have related tags" do
|
55
|
+
@tag.expects(:value).with().returns('foo')
|
56
|
+
|
57
|
+
response = mock_request_cycle :for => 'tags.getRelated', :with => {:tag => 'foo'}
|
58
|
+
|
59
|
+
stubs = []
|
60
|
+
elements = (response.body/'rsp/tags/tag').map
|
61
|
+
|
62
|
+
elements.each do |element|
|
63
|
+
stub = stub()
|
64
|
+
stubs << stub
|
65
|
+
|
66
|
+
Tag.expects(:new).with(element).returns(stub)
|
67
|
+
end
|
68
|
+
|
69
|
+
@tag.related.should == stubs
|
70
|
+
end
|
71
|
+
|
72
|
+
should "memoize the data for related tags" do
|
73
|
+
@tag.expects(:value).with().returns('foo')
|
74
|
+
|
75
|
+
mock_request_cycle :for => 'tags.getRelated', :with => {:tag => 'foo'}
|
76
|
+
|
77
|
+
2.times { @tag.related }
|
78
|
+
end
|
79
|
+
|
80
|
+
should "be able to generate a string representation of itself" do
|
81
|
+
@tag.expects(:value).with().returns('foo')
|
82
|
+
@tag.to_s.should == 'foo'
|
83
|
+
end
|
84
|
+
|
85
|
+
should "know that it is not a machine tag" do
|
86
|
+
@tag.expects(:machine_flag).with().returns('0')
|
87
|
+
@tag.machine?.should be(false)
|
88
|
+
end
|
89
|
+
|
90
|
+
should "know that it is a machine tag" do
|
91
|
+
@tag.expects(:machine_flag).with().returns('1')
|
92
|
+
@tag.machine?.should be(true)
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../../test_helper'
|
2
|
+
|
3
|
+
module Fleakr::Objects
|
4
|
+
class UserTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
should_search_by :user_id
|
7
|
+
|
8
|
+
should_have_many :photos, :groups, :sets, :contacts, :tags, :collections
|
9
|
+
|
10
|
+
should_autoload_when_accessing :name, :photos_url, :profile_url, :photos_count, :location, :with => :load_info
|
11
|
+
should_autoload_when_accessing :icon_server, :icon_farm, :pro, :admin, :icon_url, :with => :load_info
|
12
|
+
|
13
|
+
context "The User class" do
|
14
|
+
|
15
|
+
should_find_one :user, :by => :username, :call => 'people.findByUsername', :path => 'rsp/user'
|
16
|
+
should_find_one :user, :by => :email, :with => :find_email, :call => 'people.findByEmail', :path => 'rsp/user'
|
17
|
+
should_find_one :user, :by => :id, :with => :user_id, :call => 'people.getInfo', :path => 'rsp/person'
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
context "An instance of User" do
|
22
|
+
context "when populating the object from an XML document" do
|
23
|
+
setup do
|
24
|
+
@object = User.new(Hpricot.XML(read_fixture('people.findByUsername')))
|
25
|
+
@object.populate_from(Hpricot.XML(read_fixture('people.getInfo')))
|
26
|
+
end
|
27
|
+
|
28
|
+
should_have_a_value_for :id => '31066442@N69'
|
29
|
+
should_have_a_value_for :username => 'frootpantz'
|
30
|
+
should_have_a_value_for :name => 'Sir Froot Pantz'
|
31
|
+
should_have_a_value_for :location => 'The Moon'
|
32
|
+
should_have_a_value_for :photos_url => 'http://www.flickr.com/photos/frootpantz/'
|
33
|
+
should_have_a_value_for :profile_url => 'http://www.flickr.com/people/frootpantz/'
|
34
|
+
should_have_a_value_for :photos_count => '3907'
|
35
|
+
should_have_a_value_for :icon_server => '30'
|
36
|
+
should_have_a_value_for :icon_farm => '1'
|
37
|
+
should_have_a_value_for :pro => '1'
|
38
|
+
should_have_a_value_for :admin => '0'
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
context "in general" do
|
43
|
+
|
44
|
+
setup { @user = User.new }
|
45
|
+
|
46
|
+
should "be able to retrieve additional information about the current user" do
|
47
|
+
response = mock_request_cycle :for => 'people.getInfo', :with => {:user_id => @user.id}
|
48
|
+
@user.expects(:populate_from).with(response.body)
|
49
|
+
|
50
|
+
@user.load_info
|
51
|
+
end
|
52
|
+
|
53
|
+
should "be able to generate an icon URL when the :icon_server value is greater than zero" do
|
54
|
+
@user.stubs(:icon_server).with().returns('1')
|
55
|
+
@user.stubs(:icon_farm).with().returns('2')
|
56
|
+
@user.stubs(:id).with().returns('45')
|
57
|
+
|
58
|
+
@user.icon_url.should == 'http://farm2.static.flickr.com/1/buddyicons/45.jpg'
|
59
|
+
end
|
60
|
+
|
61
|
+
should "return the default icon URL when the :icon_server value is zero" do
|
62
|
+
@user.stubs(:icon_server).with().returns('0')
|
63
|
+
@user.icon_url.should == 'http://www.flickr.com/images/buddyicon.jpg'
|
64
|
+
end
|
65
|
+
|
66
|
+
should "return the default icon URL when the :icon_server value is nil" do
|
67
|
+
@user.stubs(:icon_server).with().returns(nil)
|
68
|
+
@user.icon_url.should == 'http://www.flickr.com/images/buddyicon.jpg'
|
69
|
+
end
|
70
|
+
|
71
|
+
should "return a boolean value for :pro?" do
|
72
|
+
@user.stubs(:pro).with().returns('0')
|
73
|
+
@user.pro?.should be(false)
|
74
|
+
|
75
|
+
@user.stubs(:pro).with().returns('1')
|
76
|
+
@user.pro?.should be(true)
|
77
|
+
end
|
78
|
+
|
79
|
+
should "return a boolean value for :admin?" do
|
80
|
+
@user.stubs(:admin).with().returns('0')
|
81
|
+
@user.admin?.should be(false)
|
82
|
+
|
83
|
+
@user.stubs(:admin).with().returns('1')
|
84
|
+
@user.admin?.should be(true)
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,126 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../../test_helper'
|
2
|
+
|
3
|
+
module Fleakr::Support
|
4
|
+
class AttributeTest < Test::Unit::TestCase
|
5
|
+
context "An instance of the Attribute class" do
|
6
|
+
|
7
|
+
should "know the name of the attribute" do
|
8
|
+
attr = Attribute.new('foo')
|
9
|
+
attr.name.should == :foo
|
10
|
+
end
|
11
|
+
|
12
|
+
should "have a default source" do
|
13
|
+
attr = Attribute.new(:foo)
|
14
|
+
attr.sources.should == ['foo']
|
15
|
+
end
|
16
|
+
|
17
|
+
should "be able to assign multiple sources" do
|
18
|
+
attr = Attribute.new(:foo, ['foo1', 'foo2'])
|
19
|
+
attr.sources.should == ['foo1', 'foo2']
|
20
|
+
end
|
21
|
+
|
22
|
+
should "pull the location from the source" do
|
23
|
+
attr = Attribute.new('foo')
|
24
|
+
attr.location('foo').should == 'foo'
|
25
|
+
end
|
26
|
+
|
27
|
+
should "return the location when splitting" do
|
28
|
+
attr = Attribute.new('foo')
|
29
|
+
attr.split('foo').should == ['foo', nil]
|
30
|
+
end
|
31
|
+
|
32
|
+
should "return the name for the location when splitting if the location isn't specified" do
|
33
|
+
attr = Attribute.new('foo')
|
34
|
+
attr.split('@bar').should == ['foo', 'bar']
|
35
|
+
end
|
36
|
+
|
37
|
+
should "allow the setting of the location information" do
|
38
|
+
attr = Attribute.new('foo', 'bar')
|
39
|
+
attr.sources.should == ['bar']
|
40
|
+
end
|
41
|
+
|
42
|
+
should "allow the setting of the attribute value" do
|
43
|
+
attr = Attribute.new('foo')
|
44
|
+
attr.attribute('@bogon').should == 'bogon'
|
45
|
+
end
|
46
|
+
|
47
|
+
should "use the location as the attribute" do
|
48
|
+
attr = Attribute.new('foo')
|
49
|
+
attr.attribute('foo').should == 'foo'
|
50
|
+
end
|
51
|
+
|
52
|
+
should "use the attribute for the attribute if specified" do
|
53
|
+
attr = Attribute.new(:id, '@nsid')
|
54
|
+
attr.attribute('@nsid').should == 'nsid'
|
55
|
+
end
|
56
|
+
|
57
|
+
should "be able to retrieve the node from the path" do
|
58
|
+
document = Hpricot.XML('<name>Bassdrive</name>')
|
59
|
+
expected = document.at('name')
|
60
|
+
|
61
|
+
attr = Attribute.new(:name)
|
62
|
+
attr.node_for(document, 'name').should == expected
|
63
|
+
end
|
64
|
+
|
65
|
+
should "be able to retrieve the node that contains the specified attribute" do
|
66
|
+
document = Hpricot.XML('<user id="1337" />')
|
67
|
+
expected = document.at('user')
|
68
|
+
|
69
|
+
attr = Attribute.new(:id)
|
70
|
+
attr.node_for(document, '@id').should == expected
|
71
|
+
end
|
72
|
+
|
73
|
+
should "be able to retrieve the node for the specified attribute" do
|
74
|
+
document = Hpricot.XML('<user nsid="1337" />')
|
75
|
+
expected = document.at('user')
|
76
|
+
|
77
|
+
attr = Attribute.new(:id, '@nsid')
|
78
|
+
attr.node_for(document, '@nsid').should == expected
|
79
|
+
end
|
80
|
+
|
81
|
+
should "be able to pull simple values from an XML document" do
|
82
|
+
document = Hpricot.XML('<name>Bassdrive</name>')
|
83
|
+
attr = Attribute.new(:name)
|
84
|
+
attr.value_from(document).should == 'Bassdrive'
|
85
|
+
end
|
86
|
+
|
87
|
+
should "be able to pull an attribute value from the current XML node" do
|
88
|
+
document = Hpricot.XML('<user id="1337" />')
|
89
|
+
attr = Attribute.new(:id)
|
90
|
+
attr.value_from(document).should == '1337'
|
91
|
+
end
|
92
|
+
|
93
|
+
should "be able to pull a specific attribute value from the current XML node" do
|
94
|
+
document = Hpricot.XML('<user nsid="1337" />')
|
95
|
+
attr = Attribute.new(:id, '@nsid')
|
96
|
+
attr.value_from(document).should == '1337'
|
97
|
+
end
|
98
|
+
|
99
|
+
should "be able to pull an attribute value for a node and attribute" do
|
100
|
+
document = Hpricot.XML('<station><genre slug="dnb">Drum & Bass</genre></station>')
|
101
|
+
attr = Attribute.new(:slug, 'station/genre@slug')
|
102
|
+
attr.value_from(document).should == 'dnb'
|
103
|
+
end
|
104
|
+
|
105
|
+
should "be able to pull a value from a nested XML node" do
|
106
|
+
document = Hpricot.XML('<rsp><user>blip</user></rsp>')
|
107
|
+
attr = Attribute.new(:user)
|
108
|
+
attr.value_from(document).should == 'blip'
|
109
|
+
end
|
110
|
+
|
111
|
+
should "return nil if it cannot find the specified node" do
|
112
|
+
document = Hpricot.XML('<user id="1" />')
|
113
|
+
attr = Attribute.new(:photoset, '@nsid')
|
114
|
+
attr.value_from(document).should be(nil)
|
115
|
+
end
|
116
|
+
|
117
|
+
should "be able to try a series of nodes to find a value" do
|
118
|
+
document = Hpricot.XML('<photoid>123</photoid>')
|
119
|
+
|
120
|
+
attr = Attribute.new(:id, ['photo@nsid', 'photoid'])
|
121
|
+
attr.value_from(document).should == '123'
|
122
|
+
end
|
123
|
+
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|