Commit 845b2731f0b2f36b941b697bacf38b401eac75fc
1 parent
c395dd2f
Exists in
master
add single-table inheritance tests
Showing
4 changed files
with
32 additions
and
0 deletions
Show diff stats
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/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 | ... | ... |