<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>test/delicious_bookmarks.xml</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -11,10 +11,6 @@ unless reloading?
   # omitted when setting this option.
   set :url, 'http://localhost:4567'
 
-  # A regular expression that matches URLs to your site's content. Used
-  # to detect bookmarks and external content referencing the current site.
-  set :url_regex, /http\:/
-
   # The full name of the site's author.
   set :author, 'Anonymous Coward'
 
@@ -45,6 +41,10 @@ unless reloading?
   # Bookmark.synchronize!
   set :delicious, nil
 
+  # A regular expression that matches URLs to your site's content. Used
+  # to detect bookmarks and external content referencing the current site.
+  set :delicious_filter, nil
+
   # Where to write log messages.
   set :log_stream, STDERR
 </diff>
      <filename>lib/wink.rb</filename>
    </modified>
    <modified>
      <diff>@@ -35,16 +35,17 @@ module Wink
         if cache &amp;&amp; File.exist?(cache)
           File.read(cache)
         else
-          request :all
+          data = request(:all)
+          File.open(cache, 'wb') { |io| io.write(data) } if cache
+          data
         end
-      File.open(cache, 'wb') { |io| io.write(xml) } if cache
       REXML::Document.new(xml)
     end
 
     # The Time of the most recently updated bookmark on del.icio.us.
     def last_updated_at
       if cache
-        @last_updated_at ||= remote_last_updated_at
+        @last_updated_at ||= Time.iso8601(open.root.attributes['update'])
       else
         remote_last_updated_at
       end
@@ -62,23 +63,29 @@ module Wink
     # are yielded.
     def synchronize(options={})
       if since = options[:since]
-        since.utc
+        since = since.to_time if since.respond_to? :to_time
+        since.utc #!
         return false unless updated_since?(since)
       else
         since = Time.at(0)
         since.utc
       end
-      open.elements.each('posts/post') do |el|
-        attributes = el.attributes
-        time = Time.iso8601(attributes['time'])
-        next if time &lt;= since
-        yield :href    =&gt; attributes['href'],
-          :hash        =&gt; attributes['hash'],
-          :description =&gt; attributes['description'],
-          :extended    =&gt; attributes['extended'],
-          :time        =&gt; time,
-          :shared      =&gt; (attributes['shared'] != 'no'),
-          :tags        =&gt; attributes['tag'].split(' ')
+      if block_given?
+        open.elements.each('posts/post') do |el|
+          attributes = el.attributes
+          time = Time.iso8601(attributes['time'])
+          next if time &lt;= since
+          yield :href    =&gt; attributes['href'],
+            :hash        =&gt; attributes['hash'],
+            :description =&gt; attributes['description'],
+            :extended    =&gt; attributes['extended'],
+            :time        =&gt; time,
+            :shared      =&gt; (attributes['shared'] != 'no'),
+            :tags        =&gt; attributes['tag'].split(' ')
+        end
+      else
+        require 'enumerator'
+        to_enum :synchronize, options
       end
     end
 
@@ -145,4 +152,3 @@ if $0 == __FILE__
   assert_equal 5, count
 
 end
-</diff>
      <filename>lib/wink/delicious.rb</filename>
    </modified>
    <modified>
      <diff>@@ -184,13 +184,17 @@ class Bookmark &lt; Entry
   # synchronization is disabled.
   def self.synchronize(options={})
     return nil if Wink[:delicious].nil?
-    require 'wink/delicious'
-    delicious = Wink::Delicious.new(*Wink[:delicious])
     options.each { |key,val| delicious.send(&quot;#{key}=&quot;, val) }
     count = 0
+
     delicious.synchronize :since =&gt; last_updated_at do |source|
-      next if Wink[:url_regex] &amp;&amp; source[:href] =~ Wink[:url_regex]
+
+      # skip URLs matching the delicious_filter regexp
+      next if Wink.delicious_filter &amp;&amp; source[:href] =~ Wink.delicious_filter
+
+      # skip private bookmarks
       next unless source[:shared]
+
       bookmark = find_or_create(:slug =&gt; source[:hash])
       bookmark.attributes = {
         :url        =&gt; source[:href],
@@ -205,10 +209,24 @@ class Bookmark &lt; Entry
       bookmark.tag_names = source[:tags]
       bookmark.save
       count += 1
+
+      # HACK: DataMapper wants to overwrite the created_at date we
+      # set explicitly when creating a new record.
+      bookmark.created_at = source[:time].getlocal
+      bookmark.save
+
     end
+
     count
   end
 
+  def self.delicious
+    require 'wink/delicious'
+    connection = Wink::Delicious.new(*Wink[:delicious])
+    (class &lt;&lt;self;self;end).send(:define_method, :delicious) { connection }
+    connection
+  end
+
   # The Time of the most recently updated Bookmark in UTC.
   def self.last_updated_at
     latest &amp;&amp; latest.created_at</diff>
      <filename>lib/wink/models.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,39 +1,71 @@
 require File.dirname(__FILE__) + &quot;/help&quot;
 require 'wink'
 
-context 'wink/delicious' do
+describe 'wink/delicious' do
 
-  specify 'should be requirable (and not have syntax errors)' do
+  it 'can be required (no syntax errors)' do
     require 'wink/delicious'
   end
 
 end
 
-context 'Wink::Delicious' do
+describe 'Wink::Delicious' do
 
-  specify 'should support synchronizing from cache file' do
-    require 'wink/delicious'
-    delicious = Wink::Delicious.new('test', 'test', :cache =&gt; 'bookmarks.xml')
-    delicious.user.should.not.be.nil
-    delicious.password.should.not.be.nil
+  before { require 'wink/delicious' }
+
+  def cache(username='test', password='test')
+    Wink::Delicious.new username, password,
+      :cache =&gt; &quot;#{File.dirname(__FILE__)}/delicious_bookmarks.xml&quot;
+  end
+
+  it 'should support synchronizing from cache file' do
+    delicious = cache('test_user', 'test_password')
+    delicious.user.should.be == 'test_user'
+    delicious.password.should.be == 'test_password'
     delicious.cache.should.not.be.nil
+  end
+
+  it 'should respond to #last_updated_at from cache' do
+    cache.last_updated_at.should.be == Time.iso8601('2008-06-24T05:24:15Z')
+  end
+
+  it 'should give last_updated_at in utc' do
+    cache.last_updated_at.should.be.utc
+  end
+
+  it 'should yield bookmarks with block to #synchronize' do
+    count = 0
+    cache.synchronize do |bookmark|
+      [ :shared, :tags, :description, :extended, :time, :href, :hash ].each do |key|
+        assert_not_nil bookmark[key], &quot;#{key.inspect} should be set&quot;
+        assert bookmark[:tags].length &gt; 0, &quot;should be some tags&quot;
+      end
+      count += 1
+    end
+    count.should.be == 5
+  end
+
+  it 'should respond with enumerator with no block to #synchronize' do
+    enumerable = cache.synchronize
+    enumerable.should.respond_to :each
+    enumerable.should.respond_to :to_a
+  end
+
+  it 'should synchronize all bookmarks with no :since option' do
+    enumerable = cache.synchronize
+    enumerable.to_a.length.should.be 5
+  end
+
+  it 'should synchronize only new bookmarks with :since option' do
+    updated = Time.iso8601('2008-06-23T20:34:23Z')
+    cache.synchronize(:since =&gt; updated).to_a.length.should.be == 2
+  end
 
-    # TODO: plumb in test bookmark file
-    # assert delicious.last_updated_at.utc?, &quot;should be UTC&quot;
-    # updated = Time.iso8601(&quot;2008-04-03T12:57:15Z&quot;)
-    # assert_equal updated, delicious.last_updated_at
-    # delicious.synchronize :since =&gt; updated do |bookmark|
-    #   flunk &quot;should not yield when up to date&quot;
-    # end
-    # count = 0
-    # delicious.synchronize :since =&gt; Time.iso8601(&quot;2008-04-02T13:33:50Z&quot;) do |bookmark|
-    #   count += 1
-    #   [ :shared, :tags, :description, :extended, :time, :href, :hash ].each do |key|
-    #     assert_not_nil bookmark[key], &quot;#{key.inspect} should be set&quot;
-    #   end
-    #   assert bookmark[:tags].length &gt; 0, &quot;should be some tags&quot;
-    # end
-    # assert_equal 5, count
+  it 'should not synchronize anything when updated is later than most recent' do
+    updated = Time.iso8601('2010-06-23T20:34:23Z')
+    cache.synchronize :since =&gt; updated do |bookmark|
+      flunk &quot;#synchronize should not yield with since in the future&quot;
+    end
   end
 
 end</diff>
      <filename>test/delicious_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -46,6 +46,10 @@ set :begin_date, 2008
 ## The del.icio.us username/password used for bookmark synchronization.
 #set :delicious, %w[username password]
 
+## A regular expression that matches URLs to your site's content. Used
+## to detect bookmarks and external content referencing the current site.
+#set :delicious_filter, nil
+
 ## URL Mapping overrides.  If you don't like /writings or any of the others, override them here.  Be sure they end in /
 #set :writings_url, &quot;/writings/&quot;
 #set :linkings_url, &quot;/linkings/&quot;</diff>
      <filename>wink.conf.example</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>5669e9b4283dc93d234d96b9df86dc638118aa80</id>
    </parent>
  </parents>
  <author>
    <name>Ryan Tomayko</name>
    <email>rtomayko@gmail.com</email>
  </author>
  <url>http://github.com/rtomayko/wink/commit/32f747ce6419e5b1f31aa1401c62d5301a176dce</url>
  <id>32f747ce6419e5b1f31aa1401c62d5301a176dce</id>
  <committed-date>2008-06-25T23:48:56-07:00</committed-date>
  <authored-date>2008-06-25T22:31:59-07:00</authored-date>
  <message>Fix various bookmark synchronization brokeness and add tests</message>
  <tree>5914fc877d6f947abcd9e8df51bf619abb38dd8c</tree>
  <committer>
    <name>Ryan Tomayko</name>
    <email>rtomayko@gmail.com</email>
  </committer>
</commit>
