Sha256: 9f6ed8775892e174e6aadadf348b86eb6c5f73713da2b4add69ec7348f63d6ce
Contents?: true
Size: 1.61 KB
Versions: 3
Compression:
Stored size: 1.61 KB
Contents
require File.dirname(__FILE__) + '/test_helper' module FriendlyId module Test module AcktiveRecord class CachedSlugTest < ::Test::Unit::TestCase include FriendlyId::Test::Generic include FriendlyId::Test::Slugged include FriendlyId::Test::AcktiveRecord::Slugged include FriendlyId::Test::AcktiveRecord::Core def klass District end def other_class Post end def cached_slug instance.send(cache_column) end def cache_column klass.friendly_id_config.cache_column end test "should have a cached_slug" do assert_equal cached_slug, instance.slug.to_friendly_id end test "should protect the cached slug value" do old_value = cached_slug instance.update_attributes(cache_column => "Madrid") instance.reload assert_equal old_value, cached_slug end test "should update the cached slug when updating the slug" do instance.update_attributes(:name => "new name") assert_equal instance.slug.to_friendly_id, cached_slug end test "should not update the cached slug column if it has not changed" do instance.note = "a note" instance.expects("#{cache_column}=".to_sym).never instance.save! end test "should cache the incremented sequence for duplicate slug names" do instance_2 = klass.create!(:name => instance.name) assert_match(/2\z/, instance_2.send(cache_column)) end end end end end
Version data entries
3 entries across 3 versions & 1 rubygems