/
world_test.rb
112 lines (91 loc) · 3.06 KB
/
world_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
require File.expand_path(File.dirname(__FILE__))+'/test_helper'
# Test Socialization as it would be used in a "real world" scenario
class WorldTest < Test::Unit::TestCase
cattr_reader :users, :movies, :celebs, :comments
context "The World" do
setup do
seed
end
context "ActiveRecord store" do
setup { use_ar_store }
should "be social" do
test_the_world
end
end
context "Redis store" do
setup { use_redis_store }
should "be social" do
test_the_world
end
end
end
def test_the_world
john.like!(pulp)
john.follow!(jane)
john.follow!(travolta)
assert john.likes?(pulp)
assert john.follows?(jane)
assert john.follows?(travolta)
assert pulp.liked_by?(john)
assert travolta.followed_by?(john)
carl.like!(pulp)
camilo.like!(pulp)
assert_equal 3, pulp.likers(User).size
assert pulp.likers(User).include?(carl)
assert pulp.likers(User).include?(john)
assert pulp.likers(User).include?(camilo)
assert !pulp.likers(User).include?(mat)
carl.follow!(mat)
mat.follow!(carl)
camilo.follow!(carl)
assert carl.follows?(mat)
assert mat.followed_by?(carl)
assert mat.follows?(carl)
assert carl.followed_by?(mat)
assert camilo.follows?(carl)
assert !carl.follows?(camilo)
assert_raise ArgumentError do
john.like!(travolta) # Can't like a Celeb
end
assert_raise ArgumentError do
john.follow!(kill_bill) # Can't follow a movie
end
# You can even follow or like yourself if your ego is that big.
assert john.follow!(john)
assert john.like!(john)
comment = john.comments.create(:body => "I think Tami and Carl would like this movie!", :movie_id => pulp.id)
comment.mention!(tami)
comment.mention!(carl)
assert comment.mentions?(carl)
assert carl.mentioned_by?(comment)
assert comment.mentions?(tami)
assert tami.mentioned_by?(comment)
end
def seed
@@users = {}
@@celebs = {}
@@movies = {}
@@comments = {}
@@users[:john] = User.create :name => 'John Doe'
@@users[:jane] = User.create :name => 'Jane Doe'
@@users[:mat] = User.create :name => 'Mat'
@@users[:carl] = User.create :name => 'Carl'
@@users[:camilo] = User.create :name => 'Camilo'
@@users[:tami] = User.create :name => 'Tami'
@@movies[:pulp] = Movie.create :name => 'Pulp Fiction'
@@movies[:reservoir] = Movie.create :name => 'Reservoir Dogs'
@@movies[:kill_bill] = Movie.create :name => 'Kill Bill'
@@celebs[:willis] = Celebrity.create :name => 'Bruce Willis'
@@celebs[:travolta] = Celebrity.create :name => 'John Travolta'
@@celebs[:jackson] = Celebrity.create :name => 'Samuel L. Jackson'
end
def method_missing(meth, *args, &block)
sym = meth.to_sym
return users[sym] if users && users[sym]
return celebs[sym] if celebs && celebs[sym]
return movies[sym] if movies && movies[sym]
return comments[sym] if comments && comments[sym]
require 'pry'; binding.pry
super
end
end