<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -136,26 +136,23 @@ module FriendlyId
       end
     end
 
-    # Finds the record using only the friendly id. If it can't be found
-    # using the friendly id, then it returns false. If you pass in any
-    # argument other than an instance of String or Array, then it also
-    # returns false. When given as an array will try to find any of the
-    # records and return those that can be found.
+    # Finds a single record using the friendly_id, or the record's id.
     def find_one_with_friendly(id_or_name, options)
       conditions = Slug.with_name id_or_name
 
-      result = with_scope :find =&gt; {:joins =&gt; :slugs, :conditions =&gt; conditions} do
-        find_every(options).first
+      result = with_scope :find =&gt; {:select =&gt; &quot;#{self.table_name}.*&quot;, :joins =&gt; :slugs, :conditions =&gt; conditions} do
+        find_initial(options)
       end
-
+      
       if result
-        result.init_finder_slug result.slugs.find_by_name(id_or_name)
+        result.finder_slug_name = id_or_name
       else
         result = find_one_without_friendly id_or_name, options
       end
-
       result
     end
+
+    # Finds multiple records using the friendly_ids, or the records' ids.
     def find_some_with_friendly(ids_and_names, options)
       slugs = Slug.find_all_by_names_and_sluggable_type ids_and_names, base_class.name
 
@@ -165,8 +162,8 @@ module FriendlyId
 
       # search in slugs and own table
       results = []
-      results += with_scope(:find =&gt; {:joins =&gt; :slugs, :conditions =&gt; Slug.with_names(names)}) { find_every options } unless names.empty?
-      results += with_scope(:find =&gt; {:conditions =&gt; [&quot;#{ quoted_table_name }.#{ primary_key } IN (?)&quot;, ids]}) { find_every options } unless ids.empty?
+      results += with_scope(:find =&gt; {:select =&gt; &quot;#{self.table_name}.*&quot;, :joins =&gt; :slugs, :conditions =&gt; Slug.with_names(names)}) { find_every options } unless names.empty?
+      results += with_scope(:find =&gt; {:select =&gt; &quot;#{self.table_name}.*&quot;, :conditions =&gt; [&quot;#{ quoted_table_name }.#{ primary_key } IN (?)&quot;, ids]}) { find_every options } unless ids.empty?
 
       # calculate expected size, taken from active_record/base.rb
       expected_size = options[:offset] ? ids_and_names.size - options[:offset] : ids_and_names.size
@@ -177,7 +174,7 @@ module FriendlyId
       # assign finder slugs
       slugs.each do |slug|
         result = results.find { |r| r.id == slug.sluggable_id } and
-        result.init_finder_slug slug
+        result.finder_slug_name = slug.name
       end
 
       results
@@ -186,11 +183,16 @@ module FriendlyId
 
   module SluggableInstanceMethods
 
-    attr :finder_slug
+    attr :finder_slug 
+    attr_accessor :finder_slug_name
 
+    def finder_slug
+      @finder_slug ||= init_finder_slug
+    end
+    
     # Was the record found using one of its friendly ids?
     def found_using_friendly_id?
-      !!@finder_slug
+      @finder_slug_name
     end
 
     # Was the record found using its numeric id?
@@ -200,7 +202,7 @@ module FriendlyId
 
     # Was the record found using an old friendly id?
     def found_using_outdated_friendly_id?
-      @finder_slug.id != slug.id
+      finder_slug.id != slug.id
     end
 
     # Was the record found using an old friendly id, or its numeric id?
@@ -210,7 +212,7 @@ module FriendlyId
 
     # Returns the friendly id.
     def friendly_id
-      slug.name
+      finder_slug_name or slug.name
     end
     alias best_id friendly_id
 
@@ -263,17 +265,17 @@ module FriendlyId
       end
     end
 
-    # Sets the slug that was used to find the record. This can be used to
-    # determine whether the record was found using the most recent friendly
-    # id.
-    def init_finder_slug(finder_slug)
-      raise RuntimeError, 'Slug already introduced' if @finder_slug
-      @finder_slug = finder_slug
-      @finder_slug.sluggable = self
-    end
-
     private
+
     NUM_CHARS_RESERVED_FOR_FRIENDLY_ID_EXTENSION = 2
+
+    def init_finder_slug
+      raise RuntimeError, 'No slug name is set' if !@finder_slug_name
+      slug = Slug.find(:first, :conditions =&gt; {:sluggable_id =&gt; id, :name =&gt; @finder_slug_name})
+      slug.sluggable = self
+      return slug
+    end
+
     def truncated_friendly_id_base
       max_length = friendly_id_options[:max_length]
       slug_text = friendly_id_base[0, max_length - NUM_CHARS_RESERVED_FOR_FRIENDLY_ID_EXTENSION]</diff>
      <filename>lib/friendly_id.rb</filename>
    </modified>
    <modified>
      <diff>@@ -17,8 +17,7 @@ class Slug &lt; ActiveRecord::Base
     def find_all_by_names_and_sluggable_type(names, type)
       names = with_names names
       type  = &quot;#{ quoted_table_name }.sluggable_type = #{ quote_value type, columns_hash['sluggable_type'] }&quot;
-
-      all :conditions =&gt; &quot;#{ names } AND #{ type }&quot;
+      find :all, :conditions =&gt; &quot;#{ names } AND #{ type }&quot;
     end
 
     # Count exact matches for a slug. Matches include slugs with the same name
@@ -42,9 +41,17 @@ class Slug &lt; ActiveRecord::Base
     #
     # Example:
     #   slug.normalize('This... is an example!') # =&gt; &quot;this-is-an-example&quot;
+    #
+    # Note that Rails 2.2.x offers a parameterize method for stripping
+    # diacritics. This is not used here because at the time of writing, it
+    # handles several characters incorrectly, for instance replacing
+    # Icelandic's &quot;thorn&quot; character with &quot;y&quot; rather than &quot;d.&quot; This might be
+    # pedantic, but I don't want to piss off the Vikings. The last time anyone
+    # pissed them off, they uleashed a wave of terror in Europe unlike
+    # anything ever seen before or after. I'm not taking any chances.
     def normalize(slug_text)
-      # As of Oct 9 2008, this is in Edge Rails (http://github.com/rails/rails/commit/90366a1521659d07a3b75936b3231adeb376f1a4)
-      return slug_text.parameterize if slug_text.respond_to?(:parameterize)
+      # Use this onces it starts working reliably
+      # return slug_text.parameterize.to_s if slug_text.respond_to?(:parameterize)
       s = slug_text.clone
       s.gsub!(/[\?`^~&#8216;&#8217;'&#8220;&#8221;&quot;,.;:]/, '')
       s.gsub!(/&amp;/, 'and')
@@ -64,6 +71,7 @@ class Slug &lt; ActiveRecord::Base
 
   # Whether or not this slug is the most recent of its owner's slugs.
   def is_most_recent?
+    debugger
     sluggable.slug == self
   end
 </diff>
      <filename>lib/slug.rb</filename>
    </modified>
    <modified>
      <diff>@@ -8,130 +8,126 @@ class SluggableTest &lt; Test::Unit::TestCase
     Post.friendly_id_options[:max_length] = FriendlyId::ClassMethods::DEFAULT_FRIENDLY_ID_OPTIONS[:max_length]
   end
 
-  # This test fails right now because this fix has not been implemented
-  # for sluggable models, only non-sluggable models. The failing test is here
-  # as a reminder to FIX THE CODE, but I don't have time to do it right now.
-  # The test is temporarily commented out so as not to break anybody's build.
-  # def test_finder_options_are_not_ignored
-  #   assert_raises ActiveRecord::RecordNotFound do
-  #     Post.find_using_friendly_id(slugs(:one).name, :conditions =&gt; &quot;1 = 2&quot;)
-  #   end
-  # end
-
+  def test_finder_options_are_not_ignored
+    assert_raises ActiveRecord::RecordNotFound do
+      Post.find(slugs(:one).name, :conditions =&gt; &quot;1 = 2&quot;)
+    end
+  end
+  
   def test_post_should_generate_friendly_id
    @post = Post.new(:name =&gt; &quot;Test post&quot;, :content =&gt; &quot;Test content&quot;)
    assert_equal &quot;test-post&quot;, @post.generate_friendly_id
    assert_equal &quot;Test post&quot;, @post.name
   end
-
+  
   def test_post_should_have_friendly_id_options
     assert_not_nil Post.friendly_id_options
   end
-
+  
   def test_slug_should_not_have_friendly_id_options
     assert_raises NoMethodError do
       Slug.friendly_id_options
     end
   end
-
+  
   def test_post_should_not_be_found_using_friendly_id_unless_it_really_was
     @post = Post.new
     assert !@post.found_using_friendly_id?
   end
-
+  
   def test_posts_should_be_using_friendly_id_when_given_as_array
     @posts = Post.find([posts(:with_one_slug).slug.name, posts(:with_two_slugs).slug.name])
     assert @posts.all? { |post| post.found_using_friendly_id? }
   end
-
+  
   def test_posts_raises_active_record_not_found_when_not_all_records_found
     assert_raises(ActiveRecord::RecordNotFound) do
       Post.find([posts(:with_one_slug).slug.name, 'non-existant-slug-record'])
     end
   end
-
+  
   def test_post_should_be_considered_found_by_numeric_id_as_default
     @post = Post.new
     assert @post.found_using_numeric_id?
   end
-
+  
   def test_post_should_indicate_if_it_was_found_using_numeric_id
     @post = Post.find(posts(:with_two_slugs).id)
     assert @post.found_using_numeric_id?
   end
-
+  
   def test_post_should_indicate_if_it_was_found_using_friendly_id
     @post = Post.find(posts(:with_two_slugs).slug.name)
     assert @post.found_using_friendly_id?
   end
-
+  
   def test_post_should_indicate_if_it_was_found_using_outdated_friendly_id
     @post = Post.find(posts(:with_two_slugs).slugs.last.name)
     assert @post.found_using_outdated_friendly_id?
   end
-
+  
   def test_should_indicate_there_is_a_better_id_if_found_by_numeric_id
     @post = Post.find(posts(:with_one_slug).id)
     assert @post.has_better_id?
   end
-
+  
   def test_should_indicate_there_is_a_better_id_if_found_by_outdated_friendly_id
     @post = Post.find(posts(:with_two_slugs).slugs.last.name)
     assert @post.has_better_id?
   end
-
+  
   def test_should_indicate_correct_best_id
     @post = Post.find(posts(:with_two_slugs).slug.name)
     assert !@post.has_better_id?
     assert slugs(:two_new).name, @post.slug.name
   end
-
+  
   def test_should_strip_diactics_from_slug
     Post.friendly_id_options[:strip_diacritics] = true
     @post = Post.new(:name =&gt; &quot;&#192;&#193;&#194;&#195;&#196;&#197;&#198;&#199;&#200;&#202;&#203;&#204;&#205;&#206;&#207;&#208;&#209;&#210;&#211;&#212;&#213;&#214;&#216;&#217;&#218;&#219;&#220;&#221;&#222;&#223;&#224;&#225;&#226;&#227;&#228;&#229;&#230;&#231;&#232;&#233;&#234;&#235;&#236;&#237;&#238;&#239;&#240;&#241;&#242;&#243;&#244;&#245;&#246;&#248;&#249;&#250;&#251;&#252;&#253;&#254;&#255;&quot;, :content =&gt; &quot;Test content&quot;)
     assert_equal &quot;aaaaaaaeceeeiiiidnoooooouuuuythssaaaaaaaeceeeeiiiidnoooooouuuuythy&quot;, @post.generate_friendly_id
   end
-
+  
   def test_should_not_strip_diactics_from_slug
     Post.friendly_id_options[:strip_diacritics] = false
     @post = Post.new(:name =&gt; &quot;&#192;&#193;&#194;&#195;&#196;&#197;&#198;&#199;&#200;&#202;&#203;&#204;&#205;&#206;&#207;&#208;&#209;&#210;&#211;&#212;&#213;&#214;&#216;&#217;&#218;&#219;&#220;&#221;&#222;&#223;&#224;&#225;&#226;&#227;&#228;&#229;&#230;&#231;&#232;&#233;&#234;&#235;&#236;&#237;&#238;&#239;&#240;&#241;&#242;&#243;&#244;&#245;&#246;&#248;&#249;&#250;&#251;&#252;&#253;&#254;&#255;&quot;, :content =&gt; &quot;Test content&quot;)
     assert_equal &quot;&#192;&#193;&#194;&#195;&#196;&#197;&#198;&#199;&#200;&#202;&#203;&#204;&#205;&#206;&#207;&#208;&#209;&#210;&#211;&#212;&#213;&#214;&#216;&#217;&#218;&#219;&#220;&#221;&#222;&#223;&#224;&#225;&#226;&#227;&#228;&#229;&#230;&#231;&#232;&#233;&#234;&#235;&#236;&#237;&#238;&#239;&#240;&#241;&#242;&#243;&#244;&#245;&#246;&#248;&#249;&#250;&#251;&#252;&#253;&#254;&#255;&quot;, @post.generate_friendly_id
   end
-
+  
   def test_post_should_not_make_new_slug_if_name_is_unchanged
     posts(:with_one_slug).content = &quot;Edited content&quot;
     posts(:with_one_slug).save!
     assert_equal 1, posts(:with_one_slug).slugs.size
   end
-
+  
   def test_post_should_make_new_slug_if_name_is_changed
     posts(:with_one_slug).name = &quot;Edited name&quot;
     posts(:with_one_slug).save!
     assert_equal 2, posts(:with_one_slug).slugs.size
   end
-
+  
   def test_should_not_consider_substrings_as_duplicate_slugs
     @substring = slugs(:one).name[0, slugs(:one).name.length - 1]
     @post = Post.new(:name =&gt; @substring, :content =&gt; &quot;stuff&quot;)
     assert_equal @substring, @post.generate_friendly_id
   end
-
+  
   def test_should_append_extension_to_duplicate_slugs
     @post = Post.new(:name =&gt; slugs(:one).name, :content =&gt; &quot;stuff&quot;)
     assert_equal slugs(:one).name + &quot;-2&quot;, @post.generate_friendly_id
   end
-
+  
   def test_should_create_post_with_slug
     @post = Post.create(:name =&gt; &quot;Test post&quot;, :content =&gt; &quot;Test content&quot;)
     assert_not_nil @post.slug
   end
-
+  
   def test_should_truncate_slugs_longer_than_maxlength
     Post.friendly_id_options[:max_length] = 10
     @post = Post.new(:name =&gt; &quot;x&quot; * 11, :content =&gt; &quot;Test content&quot;)
     assert @post.generate_friendly_id.length &lt;= Post.friendly_id_options[:max_length]
   end
-
+  
   def test_should_ensure_truncated_slugs_are_unique
     max_length = posts(:with_one_slug).friendly_id.length
     Post.friendly_id_options[:max_length] = max_length
@@ -141,7 +137,7 @@ class SluggableTest &lt; Test::Unit::TestCase
     assert_not_equal posts(:with_one_slug).friendly_id, q.friendly_id
     assert_not_equal p.friendly_id, q.friendly_id
   end
-
+  
   def test_should_be_able_to_rename_back_to_old_friendly_id
     p = Post.create!(:name =&gt; &quot;value&quot;)
     assert_equal &quot;value&quot;, p.friendly_id
@@ -154,7 +150,7 @@ class SluggableTest &lt; Test::Unit::TestCase
     p.reload
     assert_equal &quot;value&quot;, p.friendly_id
   end
-
+  
   def test_should_avoid_extention_collisions
     Post.create!(:name =&gt; &quot;Post 2/4&quot;)
     assert Post.create!(:name =&gt; &quot;Post&quot;)
@@ -164,17 +160,17 @@ class SluggableTest &lt; Test::Unit::TestCase
     assert Post.create!(:name =&gt; &quot;Post-2-2&quot;)
     assert Post.create!(:name =&gt; &quot;Post 2/4&quot;)
   end
-
+  
   def test_slug_should_indicate_if_it_is_the_most_recent
     assert slugs(:two_new).is_most_recent?
   end
-
+  
   def test_should_raise_error_if_friendly_is_base_is_blank
     assert_raises(FriendlyId::SlugGenerationError) do
       Post.create(:name =&gt; nil)
     end
   end
-
+  
   def test_should_not_use_reserved_slugs
     post = Post.create!(:name =&gt; 'new')
     assert_not_equal 'new', post.friendly_id</diff>
      <filename>test/sluggable_test.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>acdad26a87096b8724871f3df366f2525b40f8fe</id>
    </parent>
  </parents>
  <author>
    <name>Norman Clarke</name>
    <email>norman@randomba.org</email>
  </author>
  <url>http://github.com/norman/friendly_id/commit/64f7bf2d7d0601c876c6798f03b1c4ffef9fbb7a</url>
  <id>64f7bf2d7d0601c876c6798f03b1c4ffef9fbb7a</id>
  <committed-date>2008-10-31T07:42:01-07:00</committed-date>
  <authored-date>2008-10-30T14:49:14-07:00</authored-date>
  <message>Fixed some compatibility issues with Rails 2.0.x. Fixed generated join syntax
(closes ticket #3). Made some access to slugs load more lazily to improve
performance. Removed usage of Edge Rails' parameterize method since it doesn't
properly support the full western character set yet. Removed some extra
whitespace.</message>
  <tree>fde4b9bdc7225fcb81221b167f29e9f25ca1e1cb</tree>
  <committer>
    <name>Norman Clarke</name>
    <email>norman@randomba.org</email>
  </committer>
</commit>
