diff --git a/lib/friendly_id/test.rb b/lib/friendly_id/test.rb index 14d6d7f1f..7f83e256d 100644 --- a/lib/friendly_id/test.rb +++ b/lib/friendly_id/test.rb @@ -18,7 +18,6 @@ def setup def teardown klass.send delete_all_method - # other_class.delete_all end def instance @@ -41,6 +40,10 @@ def create_method raise NotImplementedError end + def update_method + raise NotImplementedError + end + def validation_exceptions return RuntimeError end @@ -95,7 +98,7 @@ def validation_exceptions test "creation should succeed if the friendly_id text is nil and allow_nil is true" do klass.friendly_id_config.stubs(:allow_nil?).returns(true) - klass.send(create_method, :name => nil) + assert klass.send(create_method, :name => nil) end test "should allow the same friendly_id across models" do @@ -105,6 +108,18 @@ def validation_exceptions end + module Simple + + test "should allow friendly_id to be nillable if allow_nil is true" do + klass.friendly_id_config.stubs(:allow_nil?).returns(true) + instance = klass.send(create_method, :name => "hello") + assert instance.friendly_id + instance.name = nil + assert instance.send(save_method) + end + + end + # Tests for any model that implements slugs. module Slugged @@ -163,6 +178,16 @@ module Slugged assert_nil instance.slug end + test "should not allow friendly_id to be nillable even if allow_nil is true" do + klass.friendly_id_config.stubs(:allow_nil?).returns(true) + instance = klass.send(create_method, :name => "hello") + assert instance.friendly_id + instance.name = nil + assert_raise(*[validation_exceptions].flatten) do + instance.send(save_method) + end + end + end # Tests for FriendlyId::Status. diff --git a/test/active_record2/simple_test.rb b/test/active_record2/simple_test.rb index 7c7fa9fbe..a0b52dcdb 100644 --- a/test/active_record2/simple_test.rb +++ b/test/active_record2/simple_test.rb @@ -22,6 +22,7 @@ def other_class class StatusTest < ::Test::Unit::TestCase include FriendlyId::Test::Generic + include FriendlyId::Test::Simple include FriendlyId::Test::ActiveRecord2::Core include SimpleTest