www-delicious 0.1.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/CHANGELOG +5 -0
- data/MIT-LICENSE +21 -0
- data/README +210 -0
- data/Rakefile +137 -0
- data/lib/www/delicious.rb +868 -0
- data/lib/www/delicious/bundle.rb +54 -0
- data/lib/www/delicious/errors.rb +45 -0
- data/lib/www/delicious/post.rb +113 -0
- data/lib/www/delicious/tag.rb +120 -0
- data/lib/www/delicious/version.rb +28 -0
- data/setup.rb +1585 -0
- data/test/helper.rb +108 -0
- data/test/unit/delicious_bundle_test.rb +90 -0
- data/test/unit/delicious_online_test.rb +143 -0
- data/test/unit/delicious_post_test.rb +102 -0
- data/test/unit/delicious_tag_test.rb +140 -0
- data/test/unit/delicious_test.rb +420 -0
- metadata +90 -0
data/test/helper.rb
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
#
|
2
|
+
# = WWW::Delicious
|
3
|
+
#
|
4
|
+
# Ruby client for del.icio.us API.
|
5
|
+
#
|
6
|
+
#
|
7
|
+
# Category:: WWW
|
8
|
+
# Package:: WWW::Delicious
|
9
|
+
# Author:: Simone Carletti <weppos@weppos.net>
|
10
|
+
#
|
11
|
+
#--
|
12
|
+
# SVN: $Id$
|
13
|
+
#++
|
14
|
+
|
15
|
+
|
16
|
+
# prepend lib folder
|
17
|
+
$:.unshift(File.dirname(__FILE__) + '/../lib')
|
18
|
+
|
19
|
+
require 'test/unit'
|
20
|
+
require 'www/delicious'
|
21
|
+
|
22
|
+
# testcase file path
|
23
|
+
TESTCASE_PATH = File.dirname(__FILE__) + '/_files' unless defined?(TESTCASE_PATH)
|
24
|
+
TEST_REAL_TESTS = ENV['DUSERNAME'] && ENV['DPASSWORD'] unless defined?(TEST_REAL_TESTS)
|
25
|
+
|
26
|
+
|
27
|
+
module WWW
|
28
|
+
class Delicious
|
29
|
+
module TestCase
|
30
|
+
|
31
|
+
TEST_USERNAME = 'u' unless defined? TEST_USERNAME
|
32
|
+
TEST_PASSWORD = 'p' unless defined? TEST_PASSWORD
|
33
|
+
|
34
|
+
def setup
|
35
|
+
@default_username = ENV['DUSERNAME'] || TEST_USERNAME
|
36
|
+
@default_password = ENV['DPASSWORD'] || TEST_PASSWORD
|
37
|
+
@run_online_tests = false
|
38
|
+
@run_real_tests = TEST_REAL_TESTS
|
39
|
+
end
|
40
|
+
|
41
|
+
protected
|
42
|
+
#
|
43
|
+
# Returns a valid instance of <tt>WWW::Delicious</tt>
|
44
|
+
# initialized with given +options+.
|
45
|
+
#
|
46
|
+
def instance(options = {}, &block)
|
47
|
+
username = options.delete(:username) || @default_username
|
48
|
+
password = options.delete(:password) || @default_password
|
49
|
+
return WWW::Delicious.new(username, password, options, &block)
|
50
|
+
end
|
51
|
+
|
52
|
+
protected
|
53
|
+
#
|
54
|
+
# Returns true if tests that requires an HTTP connection must be skipped.
|
55
|
+
#
|
56
|
+
def skip_online?
|
57
|
+
return !@run_online_tests
|
58
|
+
end
|
59
|
+
|
60
|
+
protected
|
61
|
+
#
|
62
|
+
# Loads a marshaled response for given +path+.
|
63
|
+
#
|
64
|
+
def load_response(path)
|
65
|
+
return Marshal.load(File.read(path))
|
66
|
+
end
|
67
|
+
|
68
|
+
protected
|
69
|
+
#
|
70
|
+
# Loads a marshaled response for given +path+.
|
71
|
+
#
|
72
|
+
def set_response(content, path = nil)
|
73
|
+
path ||= TESTCASE_PATH + '/marshaled_response'
|
74
|
+
response = Marshal.load(File.read(path))
|
75
|
+
response.instance_variable_set(:@body, content)
|
76
|
+
Net::HTTP.response = response
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
module Net
|
84
|
+
class HTTP < Protocol
|
85
|
+
@@offline_response = nil
|
86
|
+
|
87
|
+
class << self
|
88
|
+
def response()
|
89
|
+
r = @@offline_response ||= Marshal.load(File.read(TESTCASE_PATH + '/marshaled_response'))
|
90
|
+
@@offline_response = nil
|
91
|
+
r
|
92
|
+
end
|
93
|
+
def response=(r)
|
94
|
+
@@offline_response = r
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
alias :request_online :request
|
99
|
+
def request_offline(req, body = nil, &block)
|
100
|
+
return self.class.response
|
101
|
+
end
|
102
|
+
|
103
|
+
# prepare for offline tests
|
104
|
+
remove_method :request
|
105
|
+
alias :request :request_offline
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
@@ -0,0 +1,90 @@
|
|
1
|
+
#
|
2
|
+
# = WWW::Delicious
|
3
|
+
#
|
4
|
+
# Ruby client for del.icio.us API.
|
5
|
+
#
|
6
|
+
#
|
7
|
+
# Category:: WWW
|
8
|
+
# Package:: WWW::Delicious
|
9
|
+
# Author:: Simone Carletti <weppos@weppos.net>
|
10
|
+
#
|
11
|
+
#--
|
12
|
+
# SVN: $Id$
|
13
|
+
#++
|
14
|
+
|
15
|
+
|
16
|
+
require File.dirname(__FILE__) + '/../helper'
|
17
|
+
require 'www/delicious/bundle'
|
18
|
+
|
19
|
+
|
20
|
+
class DeliciousBundleTest < Test::Unit::TestCase
|
21
|
+
|
22
|
+
|
23
|
+
# =========================================================================
|
24
|
+
# These tests check object constructor behavior
|
25
|
+
# =========================================================================
|
26
|
+
|
27
|
+
def test_initialize
|
28
|
+
obj = nil
|
29
|
+
assert_nothing_raised() { obj = WWW::Delicious::Bundle.new('name') }
|
30
|
+
assert_instance_of(WWW::Delicious::Bundle, obj)
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_initialize_with_tags
|
34
|
+
obj = nil
|
35
|
+
assert_nothing_raised() { obj = WWW::Delicious::Bundle.new('name', []) }
|
36
|
+
assert_instance_of(WWW::Delicious::Bundle, obj)
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_initialize_raises_without_name
|
40
|
+
assert_raise(ArgumentError) { WWW::Delicious::Bundle.new() }
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
# =========================================================================
|
45
|
+
# These tests check constructor options
|
46
|
+
# =========================================================================
|
47
|
+
|
48
|
+
def test_initialize_name
|
49
|
+
obj = nil
|
50
|
+
name = 'test_name'
|
51
|
+
assert_nothing_raised() { obj = instance(name) }
|
52
|
+
assert_instance_of(WWW::Delicious::Bundle, obj)
|
53
|
+
assert_equal(name, obj.name)
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_initialize_tags
|
57
|
+
obj = nil
|
58
|
+
name = 'test_name'
|
59
|
+
tags = %w(foo bar)
|
60
|
+
assert_nothing_raised() { obj = instance(name, tags) }
|
61
|
+
assert_instance_of(WWW::Delicious::Bundle, obj)
|
62
|
+
assert_equal(tags, obj.tags)
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_initialize_raises_without_tags_kind_of_array
|
66
|
+
assert_raise(ArgumentError) { instance('foo', 'foo') }
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
def test_from_rexml
|
71
|
+
xml = '<bundle name="music" tags="ipod mp3 music" />'
|
72
|
+
dom = REXML::Document.new(xml)
|
73
|
+
obj = WWW::Delicious::Bundle.from_rexml(dom.root)
|
74
|
+
assert_instance_of(WWW::Delicious::Bundle, obj)
|
75
|
+
assert_equal('music', obj.name)
|
76
|
+
assert_equal(%w(ipod mp3 music), obj.tags)
|
77
|
+
end
|
78
|
+
|
79
|
+
|
80
|
+
protected
|
81
|
+
#
|
82
|
+
# Returns a valid instance of <tt>WWW::Delicious::Bundle</tt>
|
83
|
+
# initialized with given +options+.
|
84
|
+
#
|
85
|
+
def instance(name, tags = [], &block)
|
86
|
+
return WWW::Delicious::Bundle.new(name, tags, &block)
|
87
|
+
end
|
88
|
+
|
89
|
+
|
90
|
+
end
|
@@ -0,0 +1,143 @@
|
|
1
|
+
#
|
2
|
+
# = WWW::Delicious
|
3
|
+
#
|
4
|
+
# Ruby client for del.icio.us API.
|
5
|
+
#
|
6
|
+
#
|
7
|
+
# Category:: WWW
|
8
|
+
# Package:: WWW::Delicious
|
9
|
+
# Author:: Simone Carletti <weppos@weppos.net>
|
10
|
+
#
|
11
|
+
#--
|
12
|
+
# SVN: $Id$
|
13
|
+
#++
|
14
|
+
|
15
|
+
|
16
|
+
require File.dirname(__FILE__) + '/../helper'
|
17
|
+
|
18
|
+
|
19
|
+
if TEST_REAL_TESTS
|
20
|
+
puts "*WARNING* Running real online tests with account #{ENV['DUSERNAME']} => #{ENV['DPASSWORD']}."
|
21
|
+
else
|
22
|
+
puts "Real online tests skipped. Set 'DUSERNAME' and 'DPASSWORD' env variables to run them."
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
module Net
|
27
|
+
class HTTP < Protocol
|
28
|
+
# prepare for online tests
|
29
|
+
remove_method :request
|
30
|
+
alias :request :request_online
|
31
|
+
puts 'Changed :request for online tests'
|
32
|
+
end
|
33
|
+
end if TEST_REAL_TESTS
|
34
|
+
|
35
|
+
|
36
|
+
class DeliciousOnlineTest < Test::Unit::TestCase
|
37
|
+
include WWW::Delicious::TestCase
|
38
|
+
|
39
|
+
def test_valid_account
|
40
|
+
obj = instance(:username => 'foo', :password => 'bar')
|
41
|
+
assert(!obj.valid_account?)
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_update
|
45
|
+
result = nil
|
46
|
+
assert_nothing_raised() { result = instance.update() }
|
47
|
+
assert_not_nil(result)
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_bundles_all
|
51
|
+
result = nil
|
52
|
+
assert_nothing_raised() { result = instance.bundles_all() }
|
53
|
+
assert_not_nil(result)
|
54
|
+
result.each do |bundle|
|
55
|
+
assert_instance_of(WWW::Delicious::Bundle, bundle)
|
56
|
+
assert_not_nil(bundle.name)
|
57
|
+
assert_instance_of(Array, bundle.tags)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_bundles_set
|
62
|
+
bundle = WWW::Delicious::Bundle.new('test_bundle', %w(ruby python).sort)
|
63
|
+
obj = instance()
|
64
|
+
|
65
|
+
# create the bundle
|
66
|
+
assert_nothing_raised() { obj.bundles_set(bundle) }
|
67
|
+
# search for the bundle
|
68
|
+
#assert_not_nil(search_for_bundle(bundle, obj))
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_bundles_delete
|
72
|
+
bundle = WWW::Delicious::Bundle.new('test_bundle', %w(ruby python).sort)
|
73
|
+
obj = instance()
|
74
|
+
|
75
|
+
# search for the bundle
|
76
|
+
#assert_not_nil(search_for_bundle(bundle, obj))
|
77
|
+
# delete the bundle
|
78
|
+
assert_nothing_raised() { obj.bundles_delete(bundle) }
|
79
|
+
# search for the bundle again
|
80
|
+
#assert_nil(search_for_bundle(bundle, obj))
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_tags_get
|
84
|
+
result = nil
|
85
|
+
assert_nothing_raised() { result = instance.tags_get() }
|
86
|
+
assert_not_nil(result)
|
87
|
+
result.each do |tag|
|
88
|
+
assert_instance_of(WWW::Delicious::Tag, tag)
|
89
|
+
assert_not_nil(tag.name)
|
90
|
+
assert_not_nil(tag.count)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_tags_rename
|
95
|
+
ftag = WWW::Delicious::Tag.new(:name => 'old_tag')
|
96
|
+
otag = WWW::Delicious::Tag.new(:name => 'new_tag')
|
97
|
+
obj = instance()
|
98
|
+
|
99
|
+
assert_nothing_raised() { obj.tags_rename(ftag, otag) }
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_posts_get
|
103
|
+
obj = instance()
|
104
|
+
results = nil
|
105
|
+
assert_nothing_raised() { results = obj.posts_get() }
|
106
|
+
|
107
|
+
assert_kind_of(Array, results)
|
108
|
+
results.each do |post|
|
109
|
+
assert_kind_of(WWW::Delicious::Post, result)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def test_posts_recent
|
114
|
+
obj = instance()
|
115
|
+
results = nil
|
116
|
+
assert_nothing_raised() { results = obj.posts_recent() }
|
117
|
+
|
118
|
+
assert_kind_of(Array, results)
|
119
|
+
results.each do |post|
|
120
|
+
assert_kind_of(WWW::Delicious::Post, result)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
|
125
|
+
protected
|
126
|
+
def search_for_bundle(bundle, obj)
|
127
|
+
bundles = obj.bundles_all()
|
128
|
+
return bundles.detect { |b| b.name == bundle.name && b.tags.sort == bundle.tags }
|
129
|
+
end
|
130
|
+
|
131
|
+
end if TEST_REAL_TESTS
|
132
|
+
|
133
|
+
|
134
|
+
module Net
|
135
|
+
class HTTP < Protocol
|
136
|
+
# prepare for offline tests
|
137
|
+
remove_method :request
|
138
|
+
alias :request :request_offline
|
139
|
+
puts 'Changed :request for offline tests'
|
140
|
+
end
|
141
|
+
end if TEST_REAL_TESTS
|
142
|
+
|
143
|
+
|
@@ -0,0 +1,102 @@
|
|
1
|
+
#
|
2
|
+
# = WWW::Delicious
|
3
|
+
#
|
4
|
+
# Ruby client for del.icio.us API.
|
5
|
+
#
|
6
|
+
#
|
7
|
+
# Category:: WWW
|
8
|
+
# Package:: WWW::Delicious
|
9
|
+
# Author:: Simone Carletti <weppos@weppos.net>
|
10
|
+
#
|
11
|
+
#--
|
12
|
+
# SVN: $Id$
|
13
|
+
#++
|
14
|
+
|
15
|
+
|
16
|
+
require File.dirname(__FILE__) + '/../helper'
|
17
|
+
require 'www/delicious/post'
|
18
|
+
|
19
|
+
|
20
|
+
class DeliciousPostTest < Test::Unit::TestCase
|
21
|
+
|
22
|
+
|
23
|
+
# =========================================================================
|
24
|
+
# These tests check object constructor behavior
|
25
|
+
# =========================================================================
|
26
|
+
|
27
|
+
def test_initialize
|
28
|
+
assert_nothing_raised() do
|
29
|
+
obj = WWW::Delicious::Post.new(:url => 'http://localhost', :title => 'foo')
|
30
|
+
assert_instance_of(WWW::Delicious::Post, obj)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_initialize_with_block
|
35
|
+
assert_nothing_raised() do
|
36
|
+
obj = WWW::Delicious::Post.new(:url => 'http://localhost', :title => 'foo') do |tag|
|
37
|
+
assert_instance_of(WWW::Delicious::Post, tag)
|
38
|
+
end
|
39
|
+
assert_instance_of(WWW::Delicious::Post, obj)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_initialize_raises_without_values
|
44
|
+
assert_raise(ArgumentError) do
|
45
|
+
obj = WWW::Delicious::Post.new()
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_initialize_raises_without_values_hash_or_rexml
|
50
|
+
exception = assert_raise(ArgumentError) do
|
51
|
+
obj = WWW::Delicious::Post.new('foo')
|
52
|
+
end
|
53
|
+
assert_match(/`hash` or `REXML::Element`/i, exception.message)
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
# =========================================================================
|
58
|
+
# These tests check constructor options
|
59
|
+
# =========================================================================
|
60
|
+
|
61
|
+
def test_initialize_values_kind_of_hash
|
62
|
+
params = {
|
63
|
+
# TODO
|
64
|
+
}
|
65
|
+
obj = WWW::Delicious::Post.new(params)
|
66
|
+
assert_instance_of(WWW::Delicious::Post, obj)
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
def test_initialize_values_kind_of_rexml
|
71
|
+
xml = <<-EOS
|
72
|
+
<post href="http://www.howtocreate.co.uk/tutorials/texterise.php?dom=1"
|
73
|
+
description="JavaScript DOM reference"
|
74
|
+
extended="dom reference"
|
75
|
+
hash="c0238dc0c44f07daedd9a1fd9bbdeebd"
|
76
|
+
others="55" tag="dom javascript webdev" time="2005-11-28T05:26:09Z" />
|
77
|
+
EOS
|
78
|
+
dom = REXML::Document.new(xml)
|
79
|
+
obj = WWW::Delicious::Post.new(dom.root)
|
80
|
+
assert_instance_of(WWW::Delicious::Post, obj)
|
81
|
+
# check all attrs
|
82
|
+
assert_equal(URI.parse('http://www.howtocreate.co.uk/tutorials/texterise.php?dom=1'), obj.url)
|
83
|
+
assert_equal("JavaScript DOM reference", obj.title)
|
84
|
+
assert_equal("dom reference", obj.notes)
|
85
|
+
assert_equal("c0238dc0c44f07daedd9a1fd9bbdeebd", obj.uid)
|
86
|
+
assert_equal(55, obj.others)
|
87
|
+
assert_equal(%w(dom javascript webdev), obj.tags)
|
88
|
+
assert_equal(Time.parse("2005-11-28T05:26:09Z"), obj.time)
|
89
|
+
end
|
90
|
+
|
91
|
+
|
92
|
+
protected
|
93
|
+
#
|
94
|
+
# Returns a valid instance of <tt>WWW::Delicious::Tag</tt>
|
95
|
+
# initialized with given +options+.
|
96
|
+
#
|
97
|
+
def instance(values, &block)
|
98
|
+
return WWW::Delicious::Post.new(values, &block)
|
99
|
+
end
|
100
|
+
|
101
|
+
|
102
|
+
end
|
@@ -0,0 +1,140 @@
|
|
1
|
+
#
|
2
|
+
# = WWW::Delicious
|
3
|
+
#
|
4
|
+
# Ruby client for del.icio.us API.
|
5
|
+
#
|
6
|
+
#
|
7
|
+
# Category:: WWW
|
8
|
+
# Package:: WWW::Delicious
|
9
|
+
# Author:: Simone Carletti <weppos@weppos.net>
|
10
|
+
#
|
11
|
+
#--
|
12
|
+
# SVN: $Id$
|
13
|
+
#++
|
14
|
+
|
15
|
+
|
16
|
+
require File.dirname(__FILE__) + '/../helper'
|
17
|
+
require 'www/delicious/tag'
|
18
|
+
|
19
|
+
|
20
|
+
class DeliciousTagTest < Test::Unit::TestCase
|
21
|
+
|
22
|
+
|
23
|
+
# =========================================================================
|
24
|
+
# These tests check object constructor behavior
|
25
|
+
# =========================================================================
|
26
|
+
|
27
|
+
def test_initialize
|
28
|
+
assert_nothing_raised() do
|
29
|
+
obj = WWW::Delicious::Tag.new(:name => 'name')
|
30
|
+
assert_instance_of(WWW::Delicious::Tag, obj)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_initialize_with_block
|
35
|
+
assert_nothing_raised() do
|
36
|
+
obj = WWW::Delicious::Tag.new(:name => 'name') do |tag|
|
37
|
+
assert_instance_of(WWW::Delicious::Tag, tag)
|
38
|
+
end
|
39
|
+
assert_instance_of(WWW::Delicious::Tag, obj)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_initialize_raises_without_values
|
44
|
+
assert_raise(ArgumentError) do
|
45
|
+
obj = WWW::Delicious::Tag.new()
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_initialize_raises_without_values_hash_or_rexml
|
50
|
+
exception = assert_raise(ArgumentError) do
|
51
|
+
obj = WWW::Delicious::Tag.new('foo')
|
52
|
+
end
|
53
|
+
assert_match(/`hash` or `REXML::Element`/i, exception.message)
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
# =========================================================================
|
58
|
+
# These tests check constructor options
|
59
|
+
# =========================================================================
|
60
|
+
|
61
|
+
def test_initialize_values_kind_of_hash
|
62
|
+
name = 'test'; count = 20
|
63
|
+
assert_nothing_raised() do
|
64
|
+
obj = instance(:name => name, :count => count) do |t|
|
65
|
+
assert_instance_of(WWW::Delicious::Tag, t)
|
66
|
+
assert_equal(name, t.name)
|
67
|
+
assert_equal(count, t.count)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_initialize_values_kind_of_rexml
|
73
|
+
xml = '<tag count="1" tag="activedesktop" />'
|
74
|
+
dom = REXML::Document.new(xml)
|
75
|
+
obj = WWW::Delicious::Tag.new(dom.root)
|
76
|
+
assert_instance_of(WWW::Delicious::Tag, obj)
|
77
|
+
assert_equal('activedesktop', obj.name)
|
78
|
+
assert_equal(1, obj.count)
|
79
|
+
end
|
80
|
+
|
81
|
+
|
82
|
+
def test_name_setter_getter
|
83
|
+
instance('foo') do |tag|
|
84
|
+
assert_equal('foo', tag.name)
|
85
|
+
tag.name = 12
|
86
|
+
assert_equal('12', tag.name)
|
87
|
+
tag.name = :foo
|
88
|
+
assert_equal('foo', tag.name)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_name_strip_whitespaces
|
93
|
+
[' foo ', 'foo ', ' foo ', ' foo'].each do |v|
|
94
|
+
assert_equal(v.strip, instance(v).name) # => 'foo'
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def test_count_setter_getter
|
99
|
+
instance('foo') do |tag|
|
100
|
+
assert_equal(0, tag.count)
|
101
|
+
tag.count = 12
|
102
|
+
assert_equal(12, tag.count)
|
103
|
+
tag.count = '23'
|
104
|
+
assert_equal(23, tag.count)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_to_s
|
109
|
+
instance('foobar') do |tag|
|
110
|
+
assert_equal('foobar', tag.to_s)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_api_valid
|
115
|
+
['foo', ' foo '].each do |v|
|
116
|
+
assert(instance(v).api_valid?)
|
117
|
+
end
|
118
|
+
['', ' '].each do |v|
|
119
|
+
assert(!instance(v).api_valid?)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
|
124
|
+
protected
|
125
|
+
#
|
126
|
+
# Returns a valid instance of <tt>WWW::Delicious::Tag</tt>
|
127
|
+
# initialized with given +options+.
|
128
|
+
#
|
129
|
+
def instance(args, &block)
|
130
|
+
values = case args
|
131
|
+
when Hash
|
132
|
+
args
|
133
|
+
else
|
134
|
+
{ :name => args.to_s() }
|
135
|
+
end
|
136
|
+
return WWW::Delicious::Tag.new(values, &block)
|
137
|
+
end
|
138
|
+
|
139
|
+
|
140
|
+
end
|