Navigation Menu

Skip to content

Commit

Permalink
Added some more tests for allow_nil
Browse files Browse the repository at this point in the history
  • Loading branch information
norman committed Mar 23, 2010
1 parent 4054afa commit 1eb0398
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
29 changes: 27 additions & 2 deletions lib/friendly_id/test.rb
Expand Up @@ -18,7 +18,6 @@ def setup

def teardown
klass.send delete_all_method
# other_class.delete_all
end

def instance
Expand All @@ -41,6 +40,10 @@ def create_method
raise NotImplementedError
end

def update_method
raise NotImplementedError
end

def validation_exceptions
return RuntimeError
end
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions test/active_record2/simple_test.rb
Expand Up @@ -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

Expand Down

0 comments on commit 1eb0398

Please sign in to comment.