Testing Object Classification Implementation in friendly_id
This test suite validates the ObjectUtils functionality in FriendlyId, focusing on ID type validation and classification. It ensures proper handling of friendly and unfriendly identifiers across different data types including strings, integers, and ActiveRecord instances.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
norman/friendly_id
test/object_utils_test.rb
require "helper"
class ObjectUtilsTest < TestCaseClass
include FriendlyId::Test
test "strings with letters are friendly_ids" do
assert "a".friendly_id?
end
test "integers should be unfriendly ids" do
assert 1.unfriendly_id?
end
test "numeric strings are neither friendly nor unfriendly" do
assert_nil "1".friendly_id?
assert_nil "1".unfriendly_id?
end
test "ActiveRecord::Base instances should be unfriendly_ids" do
FriendlyId.mark_as_unfriendly(ActiveRecord::Base)
model_class = Class.new(ActiveRecord::Base) do
self.table_name = "authors"
end
assert model_class.new.unfriendly_id?
end
end