diff --git a/test/models/book.rb b/test/models/book.rb new file mode 100644 index 000000000..eef8ddcc3 --- /dev/null +++ b/test/models/book.rb @@ -0,0 +1,2 @@ +class Book < ActiveRecord::Base +end \ No newline at end of file diff --git a/test/models/novel.rb b/test/models/novel.rb new file mode 100644 index 000000000..d2fb07fb6 --- /dev/null +++ b/test/models/novel.rb @@ -0,0 +1,3 @@ +class Novel < Book + has_friendly_id :title, :use_slug => true +end \ No newline at end of file diff --git a/test/schema.rb b/test/schema.rb index 22b6ea04e..f89c903e9 100644 --- a/test/schema.rb +++ b/test/schema.rb @@ -1,4 +1,9 @@ ActiveRecord::Schema.define(:version => 1) do + + create_table "books", :force => true do |t| + t.column "title", "string" + t.column "type", "text" + end create_table "posts", :force => true do |t| t.column "title", "string" diff --git a/test/sti_test.rb b/test/sti_test.rb new file mode 100644 index 000000000..e5cae34b4 --- /dev/null +++ b/test/sti_test.rb @@ -0,0 +1,48 @@ +# encoding: utf-8 + +require File.dirname(__FILE__) + '/test_helper' + +class SluggedModelTest < Test::Unit::TestCase + + context "A slugged model using single table inheritance" do + + setup do + Novel.friendly_id_options = FriendlyId::DEFAULT_FRIENDLY_ID_OPTIONS.merge(:column => :title, :use_slug => true) + Novel.delete_all + Slug.delete_all + @novel = Novel.new :title => "Test novel" + @novel.save! + end + + should "have a slug" do + assert_not_nil @novel.slug + end + + context "found by its friendly id" do + + setup do + @novel = Novel.find(@novel.friendly_id) + end + + should "not indicate that it has a better id" do + assert !@novel.has_better_id? + end + + end + + + context "found by its numeric id" do + + setup do + @novel = Novel.find(@novel.id) + end + + should "indicate that it has a better id" do + assert @novel.has_better_id? + end + + end + + end + +end \ No newline at end of file diff --git a/test/test_helper.rb b/test/test_helper.rb index b02552d1d..509f42cd2 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -16,6 +16,8 @@ require 'models/person' require 'models/user' require 'models/country' +require 'models/book' +require 'models/novel' # Borrowed from ActiveSupport def silence_stream(stream)