Skip to content

Commit

Permalink
Added STI model test.
Browse files Browse the repository at this point in the history
  • Loading branch information
Norman Clarke committed Feb 9, 2009
1 parent 5bb5cf2 commit 8d46285
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 0 deletions.
2 changes: 2 additions & 0 deletions test/models/book.rb
@@ -0,0 +1,2 @@
class Book < ActiveRecord::Base
end
3 changes: 3 additions & 0 deletions test/models/novel.rb
@@ -0,0 +1,3 @@
class Novel < Book
has_friendly_id :title, :use_slug => true
end
5 changes: 5 additions & 0 deletions 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"
Expand Down
48 changes: 48 additions & 0 deletions 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
2 changes: 2 additions & 0 deletions test/test_helper.rb
Expand Up @@ -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)
Expand Down

0 comments on commit 8d46285

Please sign in to comment.