Skip to content

Commit

Permalink
add single-table inheritance tests
Browse files Browse the repository at this point in the history
  • Loading branch information
brchristian authored and LeFnord committed Jan 21, 2021
1 parent 9236f2e commit 3f98ff6
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
16 changes: 16 additions & 0 deletions test/acts_as_followable_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class ActsAsFollowableTest < ActiveSupport::TestCase
@jon = FactoryGirl.create(:jon)
@oasis = FactoryGirl.create(:oasis)
@metallica = FactoryGirl.create(:metallica)
@green_day = FactoryGirl.create(:green_day)
@blink_182 = FactoryGirl.create(:blink_182)
@sam.follow(@jon)
end

Expand Down Expand Up @@ -225,6 +227,20 @@ class ActsAsFollowableTest < ActiveSupport::TestCase
end
end

context "followers_with_sti" do
setup do
@sam.follow(@green_day)
@sam.follow(@blink_182)
end

should "return the followers for given type" do
assert_equal @sam.follows_by_type('Band').first.followable, @green_day.becomes(Band)
assert_equal @sam.follows_by_type('Band').second.followable, @blink_182.becomes(Band)
assert @green_day.followers_by_type('User').include?(@sam)
assert @blink_182.followers_by_type('User').include?(@sam)
end
end

context "method_missing" do
setup do
@sam.follow(@oasis)
Expand Down
4 changes: 4 additions & 0 deletions test/dummy30/app/models/band/punk.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Band::Punk < Band
validates_presence_of :name
acts_as_followable
end
4 changes: 4 additions & 0 deletions test/dummy30/app/models/band/punk/pop_punk.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Band::Punk::PopPunk < Band::Punk
validates_presence_of :name
acts_as_followable
end
8 changes: 8 additions & 0 deletions test/factories/bands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,12 @@
factory :metallica, :class => Band do |b|
b.name 'Metallica'
end

factory :green_day, :class => Band::Punk do |b|
b.name 'Green Day'
end

factory :blink_182, :class => Band::Punk::PopPunk do |b|
b.name 'Blink 182'
end
end

0 comments on commit 3f98ff6

Please sign in to comment.