Commit 845b2731f0b2f36b941b697bacf38b401eac75fc

Authored by Brian Christian
1 parent c395dd2f
Exists in master

add single-table inheritance tests

test/acts_as_followable_test.rb
... ... @@ -20,6 +20,8 @@ class ActsAsFollowableTest < ActiveSupport::TestCase
20 20 @jon = FactoryGirl.create(:jon)
21 21 @oasis = FactoryGirl.create(:oasis)
22 22 @metallica = FactoryGirl.create(:metallica)
  23 + @green_day = FactoryGirl.create(:green_day)
  24 + @blink_182 = FactoryGirl.create(:blink_182)
23 25 @sam.follow(@jon)
24 26 end
25 27  
... ... @@ -225,6 +227,20 @@ class ActsAsFollowableTest < ActiveSupport::TestCase
225 227 end
226 228 end
227 229  
  230 + context "followers_with_sti" do
  231 + setup do
  232 + @sam.follow(@green_day)
  233 + @sam.follow(@blink_182)
  234 + end
  235 +
  236 + should "return the followers for given type" do
  237 + assert_equal @sam.follows_by_type('Band').first.followable, @green_day.becomes(Band)
  238 + assert_equal @sam.follows_by_type('Band').second.followable, @blink_182.becomes(Band)
  239 + assert @green_day.followers_by_type('User').include?(@sam)
  240 + assert @blink_182.followers_by_type('User').include?(@sam)
  241 + end
  242 + end
  243 +
228 244 context "method_missing" do
229 245 setup do
230 246 @sam.follow(@oasis)
... ...
test/dummy30/app/models/band/punk.rb 0 → 100644
... ... @@ -0,0 +1,4 @@
  1 +class Band::Punk < Band
  2 + validates_presence_of :name
  3 + acts_as_followable
  4 +end
... ...
test/dummy30/app/models/band/punk/pop_punk.rb 0 → 100644
... ... @@ -0,0 +1,4 @@
  1 +class Band::Punk::PopPunk < Band::Punk
  2 + validates_presence_of :name
  3 + acts_as_followable
  4 +end
... ...
test/factories/bands.rb
... ... @@ -6,4 +6,12 @@ FactoryGirl.define do
6 6 factory :metallica, :class => Band do |b|
7 7 b.name 'Metallica'
8 8 end
  9 +
  10 + factory :green_day, :class => Band::Punk do |b|
  11 + b.name 'Green Day'
  12 + end
  13 +
  14 + factory :blink_182, :class => Band::Punk::PopPunk do |b|
  15 + b.name 'Blink 182'
  16 + end
9 17 end
... ...