Skip to content

Commit

Permalink
Added tests for history + sti using inheritance rather than duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
norman committed Mar 13, 2012
1 parent 3846ae7 commit a0cdfd9
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 135 deletions.
129 changes: 0 additions & 129 deletions test/history_plus_sti_test.rb

This file was deleted.

15 changes: 15 additions & 0 deletions test/history_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,18 @@ def model_class
end

end

class HistoryTestWithSti < HistoryTest
class Journalist < ActiveRecord::Base
extend FriendlyId
friendly_id :name, :use => [:slugged, :history]
end

class Editorialist < Journalist
friendly_id :name, :use => [:slugged, :history]
end

def model_class
Editorialist
end
end
2 changes: 1 addition & 1 deletion test/shared.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ module Slugged
record.slug = nil
record.save!
assert_nil record.slug
record.save
record.save!
refute_nil record.slug
end
end
Expand Down
27 changes: 22 additions & 5 deletions test/sti_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def self.table_exists?; false end
end

test "the configuration's model_class should be the class, not the base_class" do
assert_equal StiTest::Editorialist, model_class.friendly_id_config.model_class
assert_equal model_class, model_class.friendly_id_config.model_class
end

test "friendly_id should accept a block with single table inheritance" do
Expand All @@ -51,11 +51,28 @@ def self.table_exists?; false end
end

test "friendly_id slugs should not clash with eachother" do
journalist = Journalist.create! :name => 'foo bar'
editoralist = Editorialist.create! :name => 'foo bar'
transaction do
journalist = model_class.base_class.create! :name => 'foo bar'
editoralist = model_class.create! :name => 'foo bar'

assert_equal 'foo-bar', journalist.slug
assert_equal 'foo-bar--2', editoralist.slug
assert_equal 'foo-bar', journalist.slug
assert_equal 'foo-bar--2', editoralist.slug
end
end

end

class StiTestWithHistory < StiTest
class Journalist < ActiveRecord::Base
extend FriendlyId
friendly_id :name, :use => [:slugged, :history]
end

class Editorialist < Journalist
friendly_id :name, :use => [:slugged, :history]
end

def model_class
Editorialist
end
end

0 comments on commit a0cdfd9

Please sign in to comment.