Browse files

Added test

  • Loading branch information...
1 parent a2f9403 commit 06cb67efbe160abae68a9377a5ab4766362c6c85 @christianhellsten committed Dec 18, 2010
Showing with 28 additions and 4 deletions.
  1. +3 −0 README.textile
  2. +25 −4 delicious.rb
View
3 README.textile
@@ -26,3 +26,6 @@ h4. Parameters
|count|Number of boomkarks to fetch|15|
|ttl|The number of seconds the feed is cached|3600 caches the feed for one hour. Leave empty to always fetch feed.|
+h2. Author
+
+"Christian Hellsten":http://christianhellsten.com ("Aktagon Ltd.":http://aktagon.com)
View
29 delicious.rb
@@ -2,6 +2,7 @@
require 'pp'
require 'ostruct'
require 'yaml'
+require 'jekyll'
require 'hpricot'
require 'digest/md5'
@@ -59,11 +60,11 @@ def tag(username, name, count = 15, ttl = DEFAULT_TTL)
# p "old #{cache_file} #{age_in_seconds} < #{ttl}"
result = super(username, name, count)
File.open(cache_file, 'w') { |out| YAML.dump(result, out) }
- result
else
# p "fresh"
- YAML::load_file(cache_file)
+ result = YAML::load_file(cache_file)
end
+ result
end
end
end
@@ -80,8 +81,8 @@ def tag(username, name, count = 15, ttl = DEFAULT_TTL)
# This will fetch the last 15 bookmarks tagged with 'design' from account 'x' and cache them for 3600 seconds.
#
# Parameters:
-# username: delicious username. For example: jebus.
-# tag: delicious tag. For example design. Separate multiple tags with a plus character.
+# username: delicious username. For example, jebus.
+# tag: delicious tag. For example, design. Separate multiple tags with a plus character.
# For example, business+tosite, will fetch boomarks tagged both business and tosite.
# count: The number of bookmarks to fetch.
# ttl: The number of seconds to cache the feed. If not set, the feed will be fetched always.
@@ -152,3 +153,23 @@ def render(context)
Liquid::Template.register_tag('delicious', Jekyll::DeliciousTag)
+if __FILE__ == $0
+ require 'test/unit'
+
+ class TC_MyTest < Test::Unit::TestCase
+ def setup
+ @result = Delicious::tag('37signals', 'svn', 5)
+ end
+
+ def test_size
+ assert_equal(@result.size, 5)
+ end
+
+ def test_bookmark
+ bookmark = @result.first
+ assert_equal(bookmark.title, 'Mike Rundle: "I now realize why larger weblogs are switching to WordPress...')
+ assert_equal(bookmark.description, "...when a site posts a dozen or more entries per day for the past few years, rebuilding the individual entry archives takes a long time. A long, long time. &amp;lt;strong&amp;gt;About 32 minutes each rebuild.&amp;lt;/strong&amp;gt;&amp;quot;")
+ assert_equal(bookmark.link, "http://businesslogs.com/business_logs/launch_a_socialites_life.php")
+ end
+ end
+end

0 comments on commit 06cb67e

Please sign in to comment.