Skip to content

Commit

Permalink
Fixed records not findable by old slug when using cached slugs. Close…
Browse files Browse the repository at this point in the history
…s issue #45.
  • Loading branch information
norman committed Feb 14, 2010
1 parent 7db7c75 commit 02916f0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
6 changes: 6 additions & 0 deletions lib/friendly_id/active_record2/slugged_model.rb
Expand Up @@ -135,6 +135,12 @@ def raise_scoped_error
# circumstances unless the +:scope+ argument is present.
class CachedSingleFinder < SimpleModel::SingleFinder

def find
super
rescue ActiveRecord::RecordNotFound
SingleFinder.new(id, model_class, options).find
end

# The column used to store the cached slug.
def column
"#{table_name}.#{friendly_id_config.cache_column}"
Expand Down
9 changes: 8 additions & 1 deletion lib/friendly_id/test.rb
Expand Up @@ -139,6 +139,13 @@ module Slugged
assert_equal instance2, klass.send(find_method, instance2.friendly_id)
end

test "should remain findable by previous slugs" do
old_friendly_id = instance.friendly_id
instance.update_attributes :name => "#{old_friendly_id} updated"
assert_not_equal old_friendly_id, instance.friendly_id
assert_equal instance, klass.find(old_friendly_id)
end

end

# Tests for models to ensure that they properly implement using the
Expand All @@ -165,4 +172,4 @@ module CustomNormalizer

end
end
end
end

0 comments on commit 02916f0

Please sign in to comment.