<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>lib/friendly_id/tasks.rb</filename>
    </added>
    <added>
      <filename>test/tasks_test.rb</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -4,7 +4,6 @@ Manifest.txt
 README.rdoc
 Rakefile
 config/website.yml
-friendly_id.gemspec
 generators/friendly_id/friendly_id_generator.rb
 generators/friendly_id/templates/create_slugs.rb
 generators/friendly_id_20_upgrade/friendly_id_20_upgrade_generator.rb
@@ -17,13 +16,17 @@ lib/friendly_id/non_sluggable_instance_methods.rb
 lib/friendly_id/slug.rb
 lib/friendly_id/sluggable_class_methods.rb
 lib/friendly_id/sluggable_instance_methods.rb
+lib/friendly_id/tasks.rb
 lib/friendly_id/version.rb
 lib/tasks/friendly_id.rake
 lib/tasks/friendly_id.rb
+test/cached_slug_test.rb
 test/contest.rb
 test/custom_slug_normalizer_test.rb
 test/models/book.rb
+test/models/city.rb
 test/models/country.rb
+test/models/district.rb
 test/models/event.rb
 test/models/novel.rb
 test/models/person.rb
@@ -36,4 +39,5 @@ test/scoped_model_test.rb
 test/slug_test.rb
 test/slugged_model_test.rb
 test/sti_test.rb
+test/tasks_test.rb
 test/test_helper.rb</diff>
      <filename>Manifest.txt</filename>
    </modified>
    <modified>
      <diff>@@ -1,50 +1,27 @@
-# encoding: utf-8
+require &quot;friendly_id/tasks&quot;
 
 namespace :friendly_id do
   desc &quot;Make slugs for a model.&quot;
   task :make_slugs =&gt; :environment do
-    raise 'USAGE: rake friendly_id:make_slugs MODEL=MyModelName' if ENV[&quot;MODEL&quot;].nil?
-    if !sluggable_class.friendly_id_options[:use_slug]
-      raise &quot;Class \&quot;#{sluggable_class.to_s}\&quot; doesn't appear to be using slugs&quot;
-    end
-    while records = sluggable_class.find(:all, :include =&gt; :slugs, :conditions =&gt; &quot;slugs.id IS NULL&quot;, :limit =&gt; 1000) do
-      break if records.size == 0
-      records.each do |r|
-        r.send(:set_slug)
-        r.save!
-        puts &quot;#{sluggable_class.to_s}(#{r.id}) friendly_id set to \&quot;#{r.slug.name}\&quot;&quot;
-      end
+    validate_model_given
+    FriendlyId::Tasks.make_slugs(ENV[&quot;MODEL&quot;]) do |r|
+      puts &quot;%s(%d) friendly_id set to '%s'&quot; % [r.class.to_s, r.id, r.slug.name]
     end
   end
 
   desc &quot;Regenereate slugs for a model.&quot;
   task :redo_slugs =&gt; :environment do
-    raise 'USAGE: rake friendly_id:redo_slugs MODEL=MyModelName' if ENV[&quot;MODEL&quot;].nil?
-    if !sluggable_class.friendly_id_options[:use_slug]
-      raise &quot;Class \&quot;#{sluggable_class.to_s}\&quot; doesn't appear to be using slugs&quot;
-    end
-    Slug.destroy_all([&quot;sluggable_type = ?&quot;, sluggable_class.to_s])
+    validate_model_given
+    FriendlyId::Tasks.delete_slugs_for(ENV[&quot;MODEL&quot;])
     Rake::Task[&quot;friendly_id:make_slugs&quot;].invoke
   end
 
-  desc &quot;Kill obsolete slugs older than 45 days.&quot;
+  desc &quot;Kill obsolete slugs older than DAYS=45 days.&quot;
   task :remove_old_slugs =&gt; :environment do
-    if ENV[&quot;DAYS&quot;].nil?
-      @days = 45
-    else
-      @days = ENV[&quot;DAYS&quot;].to_i
-    end
-    slugs = Slug.find(:all, :conditions =&gt; [&quot;created_at &lt; ?&quot;, DateTime.now - @days.days])
-    slugs.each do |s|
-      s.destroy if !s.is_most_recent?
-    end
+    FriendlyId::Task.delete_old_slugs(ENV[&quot;DAYS&quot;], ENV[&quot;MODEL&quot;])
   end
 end
 
-def sluggable_class
-  if (ENV[&quot;MODEL&quot;].split('::').size &gt; 1)
-    ENV[&quot;MODEL&quot;].split('::').inject(Kernel) {|scope, const_name| scope.const_get(const_name)}
-  else
-    Object.const_get(ENV[&quot;MODEL&quot;])
-  end
-end
\ No newline at end of file
+def validate_model_given
+  raise 'USAGE: rake friendly_id:make_slugs MODEL=MyModelName' if ENV[&quot;MODEL&quot;].nil?
+end</diff>
      <filename>lib/tasks/friendly_id.rake</filename>
    </modified>
    <modified>
      <diff>@@ -8,12 +8,15 @@ class CachedSlugModelTest &lt; Test::Unit::TestCase
   context &quot;A slugged model with a cached_slugs column&quot; do
 
     setup do
-      City.delete_all
-      Slug.delete_all
       @paris = City.new(:name =&gt; &quot;Paris&quot;)
       @paris.save!
     end
 
+    teardown do
+      City.delete_all
+      Slug.delete_all
+    end
+
     should &quot;have a slug&quot; do
       assert_not_nil @paris.slug
     end</diff>
      <filename>test/cached_slug_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -8,6 +8,9 @@ class CustomSlugNormalizerTest &lt; Test::Unit::TestCase
 
     setup do
       Thing.friendly_id_options = FriendlyId::DEFAULT_FRIENDLY_ID_OPTIONS.merge(:column =&gt; :name, :use_slug =&gt; true)
+    end
+
+    teardown do
       Thing.delete_all
       Slug.delete_all
     end
@@ -29,7 +32,7 @@ class CustomSlugNormalizerTest &lt; Test::Unit::TestCase
         Thing.create!(:name =&gt; &quot;test&quot;)
       end
     end
-  
+
   end
 
-end
\ No newline at end of file
+end</diff>
      <filename>test/custom_slug_normalizer_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -7,10 +7,13 @@ class NonSluggedTest &lt; Test::Unit::TestCase
   context &quot;A non-slugged model with default FriendlyId options&quot; do
 
     setup do
-      User.delete_all
       @user = User.create!(:login =&gt; &quot;joe&quot;, :email =&gt; &quot;joe@example.org&quot;)
     end
 
+    teardown do
+      User.delete_all
+    end
+
     should &quot;have friendly_id options&quot; do
       assert_not_nil User.friendly_id_options
     end
@@ -95,4 +98,4 @@ class NonSluggedTest &lt; Test::Unit::TestCase
 
   end
 
-end
\ No newline at end of file
+end</diff>
      <filename>test/non_slugged_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -7,15 +7,18 @@ class ScopedModelTest &lt; Test::Unit::TestCase
   context &quot;A slugged model that uses a scope&quot; do
 
     setup do
-      Person.delete_all
-      Country.delete_all
-      Slug.delete_all
       @usa = Country.create!(:name =&gt; &quot;USA&quot;)
       @canada = Country.create!(:name =&gt; &quot;Canada&quot;)
       @person = Person.create!(:name =&gt; &quot;John Smith&quot;, :country =&gt; @usa)
       @person2 = Person.create!(:name =&gt; &quot;John Smith&quot;, :country =&gt; @canada)
     end
 
+    teardown do
+      Person.delete_all
+      Country.delete_all
+      Slug.delete_all
+    end
+
     should &quot;find all scoped records without scope&quot; do
       assert_equal 2, Person.find(:all, @person.friendly_id).size
     end
@@ -50,4 +53,4 @@ class ScopedModelTest &lt; Test::Unit::TestCase
 
   end
 
-end
\ No newline at end of file
+end</diff>
      <filename>test/scoped_model_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -6,7 +6,7 @@ class SlugTest &lt; Test::Unit::TestCase
 
   context &quot;a slug&quot; do
 
-    setup do
+    teardown do
       Slug.delete_all
       Post.delete_all
     end</diff>
      <filename>test/slug_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -8,12 +8,15 @@ class SluggedModelTest &lt; Test::Unit::TestCase
 
     setup do
       Post.friendly_id_options = FriendlyId::DEFAULT_FRIENDLY_ID_OPTIONS.merge(:column =&gt; :title, :use_slug =&gt; true)
+      @post = Post.new :title =&gt; &quot;Test post&quot;, :content =&gt; &quot;Test content&quot;, :published =&gt; true
+      @post.save!
+    end
+
+    teardown do
       Post.delete_all
       Person.delete_all
       Slug.delete_all
       Thing.delete_all
-      @post = Post.new :title =&gt; &quot;Test post&quot;, :content =&gt; &quot;Test content&quot;, :published =&gt; true
-      @post.save!
     end
 
     should &quot;have friendly_id options&quot; do</diff>
      <filename>test/slugged_model_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -8,12 +8,15 @@ class STIModelTest &lt; Test::Unit::TestCase
 
     setup do
       Novel.friendly_id_options = FriendlyId::DEFAULT_FRIENDLY_ID_OPTIONS.merge(:column =&gt; :title, :use_slug =&gt; true)
-      Novel.delete_all
-      Slug.delete_all
       @novel = Novel.new :title =&gt; &quot;Test novel&quot;
       @novel.save!
     end
 
+    teardown do
+      Novel.delete_all
+      Slug.delete_all
+    end
+
     should &quot;have a slug&quot; do
       assert_not_nil @novel.slug
     end</diff>
      <filename>test/sti_test.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>6ec718bb9d90e2041aac0a2ddb8da9139cdb8808</id>
    </parent>
  </parents>
  <author>
    <name>Norman Clarke</name>
    <email>norman@njclarke.com</email>
  </author>
  <url>http://github.com/norman/friendly_id/commit/ba3e5dfc03153e1e542fc0c3cdb0ae1707b6662e</url>
  <id>ba3e5dfc03153e1e542fc0c3cdb0ae1707b6662e</id>
  <committed-date>2009-10-26T14:48:27-07:00</committed-date>
  <authored-date>2009-10-26T14:01:52-07:00</authored-date>
  <message>Moved Rake task logic into class and added tests. Cleaned up setups/teardowns.</message>
  <tree>d8f2c2c946f1c3256b52cdff6b7caf4b451a6238</tree>
  <committer>
    <name>Norman Clarke</name>
    <email>norman@njclarke.com</email>
  </committer>
</commit>
