Sha256: 99befbda32df3b60ac87269198000d58edbec9dcf658e5ada446b605d76d04f1
Contents?: true
Size: 1.79 KB
Versions: 1
Compression:
Stored size: 1.79 KB
Contents
require File.expand_path("../test_helper", __FILE__) require "friendly_id/slugged" class SluggedTest < Test::Unit::TestCase include FriendlyId::Test::Generic def instance(name = "user") @instance ||= klass.create!(:name => name) end def klass return @@klass if defined?(@@klass) @@klass = make_model("slugged_model", :name) do |t| t.string :name, :unique => true t.string :slug, :unique => true t.boolean :active, :default => true end @@klass.send :include, FriendlyId::Slugged @@klass end def other_class return @@other_class if defined?(@@other_class) @@other_class = make_model("other_slugged_model", :name) do |t| t.string :name, :unique => true t.string :slug, :unique => true t.boolean :active, :default => true end @@other_class.send :include, FriendlyId::Slugged @@other_class end def setup klass.delete_all other_class.delete_all end test "configuration should have a sequence_separator" do assert_not_nil klass.friendly_id_config.sequence_separator end test "should make a new slug if the friendly_id method value has changed" do instance.name = "Changed Value" instance.save! assert_equal "changed-value", instance.slug end test "should increment the slug sequence for duplicate friendly ids" do instance2 = klass.create! :name => instance.name assert_match(/2\z/, instance2.friendly_id) instance3 = klass.create! :name => instance.name assert_match(/3\z/, instance3.friendly_id) end test "should not add slug sequence on update after other conflicting slugs were added" do old = instance.friendly_id instance2 = klass.create! :name => instance.name instance.save! instance.reload assert_equal old, instance.to_param end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
friendly_id4-4.0.0.pre | test/slugged_test.rb |