socialization 0.4.0 → 0.5.0.beta

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (144) hide show
  1. data/.gitignore +5 -1
  2. data/CHANGELOG.md +41 -0
  3. data/README.md +246 -0
  4. data/demo/{demo_app/.gitignore → .gitignore} +0 -0
  5. data/demo/{demo_app/Gemfile → Gemfile} +1 -1
  6. data/demo/{demo_app/README.rdoc → README.rdoc} +0 -0
  7. data/demo/{demo_app/Rakefile → Rakefile} +0 -0
  8. data/demo/{demo_app/app → app}/assets/images/rails.png +0 -0
  9. data/demo/{demo_app/app → app}/assets/javascripts/application.js +0 -0
  10. data/demo/{demo_app/app → app}/assets/stylesheets/application.css +0 -0
  11. data/demo/{demo_app/app → app}/controllers/application_controller.rb +0 -0
  12. data/demo/{demo_app/app → app}/helpers/application_helper.rb +0 -0
  13. data/demo/{demo_app/app → app}/mailers/.gitkeep +0 -0
  14. data/demo/{demo_app/app → app}/models/.gitkeep +0 -0
  15. data/demo/{demo_app/app → app}/models/celebrity.rb +0 -0
  16. data/demo/{demo_app/app → app}/models/comment.rb +0 -0
  17. data/demo/app/models/follow.rb +2 -0
  18. data/demo/app/models/like.rb +2 -0
  19. data/demo/app/models/mention.rb +2 -0
  20. data/demo/{demo_app/app → app}/models/movie.rb +0 -0
  21. data/demo/{demo_app/app → app}/models/user.rb +0 -0
  22. data/demo/{demo_app/app → app}/views/layouts/application.html.erb +0 -0
  23. data/demo/{demo_app/config.ru → config.ru} +0 -0
  24. data/demo/{demo_app/config → config}/application.rb +0 -0
  25. data/demo/{demo_app/config → config}/boot.rb +0 -0
  26. data/demo/{demo_app/config → config}/database.yml +0 -0
  27. data/demo/{demo_app/config → config}/environment.rb +0 -0
  28. data/demo/{demo_app/config → config}/environments/development.rb +0 -0
  29. data/demo/{demo_app/config → config}/environments/production.rb +0 -0
  30. data/demo/{demo_app/config → config}/environments/test.rb +0 -0
  31. data/demo/{demo_app/config → config}/initializers/backtrace_silencers.rb +0 -0
  32. data/demo/{demo_app/config → config}/initializers/inflections.rb +0 -0
  33. data/demo/{demo_app/config → config}/initializers/mime_types.rb +0 -0
  34. data/demo/{demo_app/config → config}/initializers/secret_token.rb +0 -0
  35. data/demo/{demo_app/config → config}/initializers/session_store.rb +1 -1
  36. data/demo/{demo_app/config → config}/initializers/wrap_parameters.rb +1 -1
  37. data/demo/{demo_app/config → config}/locales/en.yml +0 -0
  38. data/demo/{demo_app/config → config}/routes.rb +0 -0
  39. data/demo/{demo_app/db → db}/migrate/20120115051222_create_users.rb +0 -0
  40. data/demo/{demo_app/db → db}/migrate/20120115051234_create_movies.rb +0 -0
  41. data/demo/{demo_app/db → db}/migrate/20120115051255_create_celebrities.rb +0 -0
  42. data/demo/{demo_app/db → db}/migrate/20120115054646_create_follows.rb +0 -0
  43. data/demo/{demo_app/db → db}/migrate/20120115054647_create_likes.rb +0 -0
  44. data/demo/{demo_app/db → db}/migrate/20120221200644_create_mentions.rb +0 -0
  45. data/demo/{demo_app/db → db}/migrate/20120221202703_create_comments.rb +0 -0
  46. data/demo/{demo_app/db → db}/schema.rb +0 -1
  47. data/demo/{demo_app/db → db}/seeds.rb +0 -0
  48. data/demo/{demo_app/lib → lib}/assets/.gitkeep +0 -0
  49. data/demo/{demo_app/lib → lib}/tasks/.gitkeep +0 -0
  50. data/demo/{demo_app/public → public}/404.html +0 -0
  51. data/demo/{demo_app/public → public}/422.html +0 -0
  52. data/demo/{demo_app/public → public}/500.html +0 -0
  53. data/demo/{demo_app/public → public}/favicon.ico +0 -0
  54. data/demo/{demo_app/public → public}/index.html +0 -0
  55. data/demo/{demo_app/public → public}/robots.txt +0 -0
  56. data/demo/{demo_app/script → script}/rails +0 -0
  57. data/demo/{demo_app/test → test}/fixtures/.gitkeep +0 -0
  58. data/demo/{demo_app/test → test}/fixtures/celebrities.yml +0 -0
  59. data/demo/{demo_app/test → test}/fixtures/movies.yml +0 -0
  60. data/demo/{demo_app/test → test}/fixtures/users.yml +0 -0
  61. data/demo/{demo_app/test → test}/functional/.gitkeep +0 -0
  62. data/demo/{demo_app/test → test}/integration/.gitkeep +0 -0
  63. data/demo/{demo_app/test → test}/performance/browsing_test.rb +0 -0
  64. data/demo/{demo_app/test → test}/test_helper.rb +0 -0
  65. data/demo/{demo_app/test → test}/unit/.gitkeep +0 -0
  66. data/demo/{demo_app/test → test}/unit/celebrity_test.rb +0 -0
  67. data/demo/{demo_app/test → test}/unit/movie_test.rb +0 -0
  68. data/demo/{demo_app/test → test}/unit/user_test.rb +0 -0
  69. data/demo/{demo_app/vendor → vendor}/assets/javascripts/.gitkeep +0 -0
  70. data/demo/{demo_app/vendor → vendor}/assets/stylesheets/.gitkeep +0 -0
  71. data/demo/{demo_app/vendor → vendor}/plugins/.gitkeep +0 -0
  72. data/lib/generators/socialization/socialization_generator.rb +20 -9
  73. data/{generators/socialization/templates → lib/generators/socialization/templates/active_record}/migration_follows.rb +0 -0
  74. data/{generators/socialization/templates → lib/generators/socialization/templates/active_record}/migration_likes.rb +0 -0
  75. data/{generators/socialization/templates → lib/generators/socialization/templates/active_record}/migration_mentions.rb +0 -0
  76. data/lib/generators/socialization/templates/active_record/model_follow.rb +2 -0
  77. data/lib/generators/socialization/templates/active_record/model_like.rb +2 -0
  78. data/lib/generators/socialization/templates/active_record/model_mention.rb +2 -0
  79. data/lib/socialization.rb +3 -5
  80. data/lib/socialization/actors/follower.rb +74 -0
  81. data/lib/socialization/actors/liker.rb +74 -0
  82. data/lib/socialization/actors/mentioner.rb +74 -0
  83. data/lib/socialization/acts_as_helpers.rb +43 -0
  84. data/lib/socialization/config.rb +45 -0
  85. data/lib/socialization/helpers/string.rb +17 -0
  86. data/lib/socialization/stores/active_record/follow_store.rb +143 -0
  87. data/lib/socialization/stores/active_record/like_store.rb +143 -0
  88. data/lib/socialization/stores/active_record/mention_store.rb +143 -0
  89. data/lib/socialization/stores/redis/base.rb +8 -0
  90. data/lib/socialization/stores/redis/config.rb +11 -0
  91. data/lib/socialization/stores/redis/follow_store.rb +126 -0
  92. data/lib/socialization/stores/redis/like_store.rb +126 -0
  93. data/lib/socialization/stores/redis/mention_store.rb +126 -0
  94. data/lib/socialization/version.rb +1 -1
  95. data/lib/socialization/victims/followable.rb +38 -0
  96. data/lib/socialization/victims/likeable.rb +38 -0
  97. data/lib/socialization/victims/mentionable.rb +38 -0
  98. data/socialization.gemspec +3 -3
  99. data/test/actors/follower_test.rb +74 -0
  100. data/test/actors/liker_test.rb +74 -0
  101. data/test/actors/mentioner_test.rb +74 -0
  102. data/test/stores/active_record/follow_store_test.rb +121 -0
  103. data/test/stores/active_record/like_store_test.rb +121 -0
  104. data/test/stores/active_record/mention_store_test.rb +121 -0
  105. data/test/stores/redis/config_test.rb +30 -0
  106. data/test/stores/redis/follow_store_test.rb +153 -0
  107. data/test/stores/redis/like_store_test.rb +153 -0
  108. data/test/stores/redis/mention_store_test.rb +153 -0
  109. data/test/string_test.rb +13 -0
  110. data/test/test_helper.rb +70 -12
  111. data/test/victims/followable_test.rb +34 -0
  112. data/test/victims/likeable_test.rb +34 -0
  113. data/test/victims/mentionable_test.rb +34 -0
  114. data/test/world_test.rb +80 -69
  115. metadata +261 -176
  116. data/README.rdoc +0 -186
  117. data/demo/demo_app/app/models/follow.rb +0 -3
  118. data/demo/demo_app/app/models/like.rb +0 -3
  119. data/demo/demo_app/app/models/mention.rb +0 -3
  120. data/demo/demo_app/doc/README_FOR_APP +0 -2
  121. data/gemfiles/activerecord30.gemfile +0 -6
  122. data/gemfiles/activerecord30.gemfile.lock +0 -23
  123. data/gemfiles/activerecord31.gemfile +0 -6
  124. data/gemfiles/activerecord31.gemfile.lock +0 -25
  125. data/gemfiles/activerecord32.gemfile +0 -6
  126. data/gemfiles/activerecord32.gemfile.lock +0 -25
  127. data/generators/socialization/USAGE +0 -1
  128. data/generators/socialization/socialization_generator.rb +0 -15
  129. data/generators/socialization/templates/model_follow.rb +0 -3
  130. data/generators/socialization/templates/model_like.rb +0 -3
  131. data/generators/socialization/templates/model_mention.rb +0 -3
  132. data/lib/socialization/follow_store.rb +0 -14
  133. data/lib/socialization/followable.rb +0 -34
  134. data/lib/socialization/follower.rb +0 -50
  135. data/lib/socialization/hello.rb +0 -53
  136. data/lib/socialization/like_store.rb +0 -14
  137. data/lib/socialization/likeable.rb +0 -34
  138. data/lib/socialization/liker.rb +0 -54
  139. data/lib/socialization/mention_store.rb +0 -14
  140. data/lib/socialization/mentionable.rb +0 -36
  141. data/lib/socialization/mentioner.rb +0 -54
  142. data/test/follow_test.rb +0 -125
  143. data/test/like_test.rb +0 -125
  144. data/test/mention_test.rb +0 -116
@@ -0,0 +1,153 @@
1
+ require File.expand_path(File.dirname(__FILE__))+'/../../test_helper'
2
+
3
+ class RedisMentionStoreTest < Test::Unit::TestCase
4
+ context "RedisStores::MentionStoreTest" do
5
+ setup do
6
+ use_redis_store
7
+ @klass = Socialization::RedisStores::MentionStore
8
+ @klass.touch nil
9
+ @klass.after_mention nil
10
+ @klass.after_unmention nil
11
+ @mentioner = ImAMentioner.create
12
+ @mentionable = ImAMentionable.create
13
+ end
14
+
15
+ context "Stores" do
16
+ should "inherit Socialization::RedisStores::MentionStore" do
17
+ assert_equal Socialization::RedisStores::MentionStore, Socialization.mention_model
18
+ end
19
+ end
20
+
21
+ context "#mention!" do
22
+ should "create a Mention record" do
23
+ @klass.mention!(@mentioner, @mentionable)
24
+ assert_equal ["#{@mentioner.id}"], Socialization.redis.smembers(mentioners_key)
25
+ assert_equal ["#{@mentionable.id}"], Socialization.redis.smembers(mentionables_key)
26
+ end
27
+
28
+ should "touch mentioner when instructed" do
29
+ @klass.touch :mentioner
30
+ @mentioner.expects(:touch).once
31
+ @mentionable.expects(:touch).never
32
+ @klass.mention!(@mentioner, @mentionable)
33
+ end
34
+
35
+ should "touch mentionable when instructed" do
36
+ @klass.touch :mentionable
37
+ @mentioner.expects(:touch).never
38
+ @mentionable.expects(:touch).once
39
+ @klass.mention!(@mentioner, @mentionable)
40
+ end
41
+
42
+ should "touch all when instructed" do
43
+ @klass.touch :all
44
+ @mentioner.expects(:touch).once
45
+ @mentionable.expects(:touch).once
46
+ @klass.mention!(@mentioner, @mentionable)
47
+ end
48
+
49
+ should "call after mention hook" do
50
+ @klass.after_mention :after_mention
51
+ @klass.expects(:after_mention).once
52
+ @klass.mention!(@mentioner, @mentionable)
53
+ end
54
+
55
+ should "call after unmention hook" do
56
+ @klass.after_mention :after_unmention
57
+ @klass.expects(:after_unmention).once
58
+ @klass.mention!(@mentioner, @mentionable)
59
+ end
60
+ end
61
+
62
+ context "#mentions?" do
63
+ should "return true when mention exists" do
64
+ Socialization.redis.sadd mentioners_key, @mentioner.id
65
+ Socialization.redis.sadd mentionables_key, @mentionable.id
66
+ assert_true @klass.mentions?(@mentioner, @mentionable)
67
+ end
68
+
69
+ should "return false when mention doesn't exist" do
70
+ assert_false @klass.mentions?(@mentioner, @mentionable)
71
+ end
72
+ end
73
+
74
+ context "#mentioners" do
75
+ should "return an array of mentioners" do
76
+ mentioner1 = ImAMentioner.create
77
+ mentioner2 = ImAMentioner.create
78
+ mentioner1.mention!(@mentionable)
79
+ mentioner2.mention!(@mentionable)
80
+ assert_array_similarity [mentioner1, mentioner2], @klass.mentioners(@mentionable, mentioner1.class)
81
+ end
82
+
83
+ should "return an array of mentioner ids when plucking" do
84
+ mentioner1 = ImAMentioner.create
85
+ mentioner2 = ImAMentioner.create
86
+ mentioner1.mention!(@mentionable)
87
+ mentioner2.mention!(@mentionable)
88
+ assert_array_similarity [mentioner1.id, mentioner2.id], @klass.mentioners(@mentionable, mentioner1.class, :pluck => :id)
89
+ end
90
+ end
91
+
92
+ context "#mentionables" do
93
+ should "return an array of mentionables" do
94
+ mentionable1 = ImAMentionable.create
95
+ mentionable2 = ImAMentionable.create
96
+ @mentioner.mention!(mentionable1)
97
+ @mentioner.mention!(mentionable2)
98
+
99
+ assert_array_similarity [mentionable1, mentionable2], @klass.mentionables(@mentioner, mentionable1.class)
100
+ end
101
+
102
+ should "return an array of mentionables ids when plucking" do
103
+ mentionable1 = ImAMentionable.create
104
+ mentionable2 = ImAMentionable.create
105
+ @mentioner.mention!(mentionable1)
106
+ @mentioner.mention!(mentionable2)
107
+ assert_array_similarity [mentionable1.id, mentionable2.id], @klass.mentionables(@mentioner, mentionable1.class, :pluck => :id)
108
+ end
109
+ end
110
+
111
+ context "#generate_mentioners_key" do
112
+ should "return valid key when passed objects" do
113
+ assert_equal "Mentioners:ImAMentionable:#{@mentionable.id}:ImAMentioner", mentioners_key(@mentioner, @mentionable)
114
+ end
115
+
116
+ should "return valid key when mentioner is a class" do
117
+ assert_equal "Mentioners:ImAMentionable:#{@mentionable.id}:ImAMentioner", mentioners_key(@mentioner.class, @mentionable)
118
+ end
119
+ end
120
+
121
+ context "#generate_mentionables_key" do
122
+ should "return valid key when passed objects" do
123
+ assert_equal "Mentionables:ImAMentioner:#{@mentioner.id}:ImAMentionable", mentionables_key(@mentioner, @mentionable)
124
+ end
125
+
126
+ should "return valid key when mentionable is a class" do
127
+ assert_equal "Mentionables:ImAMentioner:#{@mentioner.id}:ImAMentionable", mentionables_key(@mentioner, @mentionable.class)
128
+ end
129
+ end
130
+
131
+ end
132
+
133
+ # Helpers
134
+ def assert_match_mentioner(mention_record, mentioner)
135
+ assert mention_record.mentioner_type == mentioner.class.to_s && mention_record.mentioner_id == mentioner.id
136
+ end
137
+
138
+ def assert_match_mentionable(mention_record, mentionable)
139
+ assert mention_record.mentionable_type == mentionable.class.to_s && mention_record.mentionable_id == mentionable.id
140
+ end
141
+
142
+ def mentioners_key(mentioner = nil, mentionable = nil)
143
+ mentioner ||= @mentioner
144
+ mentionable ||= @mentionable
145
+ @klass.send(:generate_mentioners_key, mentioner, mentionable)
146
+ end
147
+
148
+ def mentionables_key(mentioner = nil, mentionable = nil)
149
+ mentioner ||= @mentioner
150
+ mentionable ||= @mentionable
151
+ @klass.send(:generate_mentionables_key, mentioner, mentionable)
152
+ end
153
+ end
@@ -0,0 +1,13 @@
1
+ require File.expand_path(File.dirname(__FILE__))+'/test_helper'
2
+
3
+ class StringTest < Test::Unit::TestCase
4
+ context "#deep_const_get" do
5
+ should "return a class" do
6
+ assert_equal Socialization, "Socialization".deep_const_get
7
+ assert_equal Socialization::ActiveRecordStores, "Socialization::ActiveRecordStores".deep_const_get
8
+ assert_equal Socialization::ActiveRecordStores::FollowStore, "Socialization::ActiveRecordStores::FollowStore".deep_const_get
9
+
10
+ assert_raise(NameError) { "Foo::Bar".deep_const_get }
11
+ end
12
+ end
13
+ end
data/test/test_helper.rb CHANGED
@@ -1,19 +1,79 @@
1
+ $MOCK_REDIS = true
2
+
1
3
  require 'rubygems'
2
4
  require 'active_record'
3
- require 'mocha'
4
5
  require 'shoulda'
5
6
  require 'test/unit'
6
7
  require 'logger'
8
+ require 'mock_redis' if $MOCK_REDIS
9
+ require 'redis' unless $MOCK_REDIS
10
+ require 'mocha' # mocha always needs to be loaded last! http://stackoverflow.com/questions/3118866/mocha-mock-carries-to-another-test/4375296#4375296
7
11
 
8
12
  $:.push File.expand_path("../lib", __FILE__)
9
13
  require "socialization"
10
14
 
15
+ silence_warnings do
16
+ Redis = MockRedis if $MOCK_REDIS # Magic!
17
+ end
18
+
19
+ module Test::Unit::Assertions
20
+ def assert_true(object, message="")
21
+ assert_equal(true, object, message)
22
+ end
23
+
24
+ def assert_false(object, message="")
25
+ assert_equal(false, object, message)
26
+ end
27
+
28
+ def assert_array_similarity(expected, actual, message=nil)
29
+ full_message = build_message(message, "<?> expected but was\n<?>.\n", expected, actual)
30
+ assert_block(full_message) { (expected.size == actual.size) && (expected - actual == []) }
31
+ end
32
+ end
33
+
34
+ class Test::Unit::TestCase
35
+ def setup
36
+ use_ar_store
37
+ end
38
+
39
+ def teardown
40
+ clear_redis
41
+ end
42
+ end
43
+
44
+ def use_redis_store
45
+ Socialization.follow_model = Socialization::RedisStores::FollowStore
46
+ Socialization.mention_model = Socialization::RedisStores::MentionStore
47
+ Socialization.like_model = Socialization::RedisStores::LikeStore
48
+ setup_model_shortcuts
49
+ end
50
+
51
+ def use_ar_store
52
+ Socialization.follow_model = Socialization::ActiveRecordStores::FollowStore
53
+ Socialization.mention_model = Socialization::ActiveRecordStores::MentionStore
54
+ Socialization.like_model = Socialization::ActiveRecordStores::LikeStore
55
+ setup_model_shortcuts
56
+ end
57
+
58
+ def setup_model_shortcuts
59
+ $Follow = Socialization.follow_model
60
+ $Mention = Socialization.mention_model
61
+ $Like = Socialization.like_model
62
+ end
63
+
64
+ def clear_redis
65
+ Socialization.redis.keys(nil).each do |k|
66
+ Socialization.redis.del k
67
+ end
68
+ end
69
+
11
70
  ActiveRecord::Base.configurations = {'sqlite3' => {:adapter => 'sqlite3', :database => ':memory:'}}
12
71
  ActiveRecord::Base.establish_connection('sqlite3')
13
72
 
14
73
  ActiveRecord::Base.logger = Logger.new(STDERR)
15
74
  ActiveRecord::Base.logger.level = Logger::WARN
16
75
 
76
+ ActiveRecord::Migration.verbose = false
17
77
  ActiveRecord::Schema.define(:version => 0) do
18
78
  create_table :users do |t|
19
79
  t.string :name
@@ -116,41 +176,39 @@ class Movie < ActiveRecord::Base
116
176
  has_many :comments
117
177
  end
118
178
 
119
- class Follow < ActiveRecord::Base
120
- acts_as_follow_store
121
- end
122
-
123
- class Like < ActiveRecord::Base
124
- acts_as_like_store
125
- end
126
-
127
- class Mention < ActiveRecord::Base
128
- acts_as_mention_store
129
- end
179
+ # class Follow < Socialization::ActiveRecordStores::FollowStore; end
180
+ # class Like < Socialization::ActiveRecordStores::LikeStore; end
181
+ # class Mention < Socialization::ActiveRecordStores::MentionStore; end
130
182
 
131
183
  class ImAFollower < ActiveRecord::Base
132
184
  acts_as_follower
133
185
  end
186
+ class ImAFollowerChild < ImAFollower; end
134
187
 
135
188
  class ImAFollowable < ActiveRecord::Base
136
189
  acts_as_followable
137
190
  end
191
+ class ImAFollowableChild < ImAFollowable; end
138
192
 
139
193
  class ImALiker < ActiveRecord::Base
140
194
  acts_as_liker
141
195
  end
196
+ class ImALikerChild < ImALiker; end
142
197
 
143
198
  class ImALikeable < ActiveRecord::Base
144
199
  acts_as_likeable
145
200
  end
201
+ class ImALikeableChild < ImALikeable; end
146
202
 
147
203
  class ImAMentioner < ActiveRecord::Base
148
204
  acts_as_mentioner
149
205
  end
206
+ class ImAMentionerChild < ImAMentioner; end
150
207
 
151
208
  class ImAMentionable < ActiveRecord::Base
152
209
  acts_as_mentionable
153
210
  end
211
+ class ImAMentionableChild < ImAMentionable; end
154
212
 
155
213
  class ImAMentionerAndMentionable < ActiveRecord::Base
156
214
  acts_as_mentioner
@@ -0,0 +1,34 @@
1
+ require File.expand_path(File.dirname(__FILE__))+'/../test_helper'
2
+
3
+ class FollowableTest < Test::Unit::TestCase
4
+ context "Followable" do
5
+ setup do
6
+ @follower = ImAFollower.new
7
+ @followable = ImAFollowable.create
8
+ end
9
+
10
+ context "#is_followable" do
11
+ should "return true" do
12
+ assert_true @followable.is_followable?
13
+ end
14
+ end
15
+
16
+ context "#followed_by?" do
17
+ should "not accept non-followers" do
18
+ assert_raise(ArgumentError) { @followable.followed_by?(:foo) }
19
+ end
20
+
21
+ should "call $Follow.follows?" do
22
+ $Follow.expects(:follows?).with(@follower, @followable).once
23
+ @followable.followed_by?(@follower)
24
+ end
25
+ end
26
+
27
+ context "#followers" do
28
+ should "call $Follow.followers" do
29
+ $Follow.expects(:followers).with(@followable, @follower.class, { :foo => :bar })
30
+ @followable.followers(@follower.class, { :foo => :bar })
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,34 @@
1
+ require File.expand_path(File.dirname(__FILE__))+'/../test_helper'
2
+
3
+ class LikeableTest < Test::Unit::TestCase
4
+ context "Likeable" do
5
+ setup do
6
+ @liker = ImALiker.new
7
+ @likeable = ImALikeable.create
8
+ end
9
+
10
+ context "#is_likeable" do
11
+ should "return true" do
12
+ assert_true @likeable.is_likeable?
13
+ end
14
+ end
15
+
16
+ context "#liked_by?" do
17
+ should "not accept non-likers" do
18
+ assert_raise(ArgumentError) { @likeable.liked_by?(:foo) }
19
+ end
20
+
21
+ should "call $Like.likes?" do
22
+ $Like.expects(:likes?).with(@liker, @likeable).once
23
+ @likeable.liked_by?(@liker)
24
+ end
25
+ end
26
+
27
+ context "#likers" do
28
+ should "call $Like.likers" do
29
+ $Like.expects(:likers).with(@likeable, @liker.class, { :foo => :bar })
30
+ @likeable.likers(@liker.class, { :foo => :bar })
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,34 @@
1
+ require File.expand_path(File.dirname(__FILE__))+'/../test_helper'
2
+
3
+ class MentionableTest < Test::Unit::TestCase
4
+ context "Mentionable" do
5
+ setup do
6
+ @mentioner = ImAMentioner.new
7
+ @mentionable = ImAMentionable.create
8
+ end
9
+
10
+ context "#is_mentionable" do
11
+ should "return true" do
12
+ assert_true @mentionable.is_mentionable?
13
+ end
14
+ end
15
+
16
+ context "#mentioned_by?" do
17
+ should "not accept non-mentioners" do
18
+ assert_raise(ArgumentError) { @mentionable.mentioned_by?(:foo) }
19
+ end
20
+
21
+ should "call $Mention.mentions?" do
22
+ $Mention.expects(:mentions?).with(@mentioner, @mentionable).once
23
+ @mentionable.mentioned_by?(@mentioner)
24
+ end
25
+ end
26
+
27
+ context "#mentioners" do
28
+ should "call $Mentionmentioners" do
29
+ $Mention.expects(:mentioners).with(@mentionable, @mentioner.class, { :foo => :bar })
30
+ @mentionable.mentioners(@mentioner.class, { :foo => :bar })
31
+ end
32
+ end
33
+ end
34
+ end
data/test/world_test.rb CHANGED
@@ -2,99 +2,110 @@ require File.expand_path(File.dirname(__FILE__))+'/test_helper'
2
2
 
3
3
  # Test Socialization as it would be used in a "real world" scenario
4
4
  class WorldTest < Test::Unit::TestCase
5
- attr_reader :users, :movies, :celebs, :comments
5
+ cattr_reader :users, :movies, :celebs, :comments
6
6
 
7
7
  context "The World" do
8
8
  setup do
9
9
  seed
10
10
  end
11
11
 
12
- should "be social" do
13
- john.like!(pulp)
14
- john.follow!(jane)
15
- john.follow!(travolta)
16
-
17
- assert john.likes?(pulp)
18
- assert john.follows?(jane)
19
- assert john.follows?(travolta)
12
+ context "ActiveRecord store" do
13
+ setup { use_ar_store }
14
+ should "be social" do
15
+ test_the_world
16
+ end
17
+ end
20
18
 
21
- assert pulp.liked_by?(john)
22
- assert travolta.followed_by?(john)
19
+ context "Redis store" do
20
+ setup { use_redis_store }
21
+ should "be social" do
22
+ test_the_world
23
+ end
24
+ end
25
+ end
23
26
 
24
- carl.like!(pulp)
25
- camilo.like!(pulp)
26
- assert_equal 3, pulp.likers(User).size
27
+ def test_the_world
28
+ john.like!(pulp)
29
+ john.follow!(jane)
30
+ john.follow!(travolta)
27
31
 
28
- assert pulp.likers(User).include?(carl)
29
- assert pulp.likers(User).include?(john)
30
- assert pulp.likers(User).include?(camilo)
31
- assert !pulp.likers(User).include?(mat)
32
+ assert john.likes?(pulp)
33
+ assert john.follows?(jane)
34
+ assert john.follows?(travolta)
32
35
 
33
- carl.follow!(mat)
34
- mat.follow!(carl)
35
- camilo.follow!(carl)
36
+ assert pulp.liked_by?(john)
37
+ assert travolta.followed_by?(john)
36
38
 
37
- assert carl.follows?(mat)
38
- assert mat.followed_by?(carl)
39
- assert mat.follows?(carl)
40
- assert carl.followed_by?(mat)
41
- assert camilo.follows?(carl)
42
- assert !carl.follows?(camilo)
39
+ carl.like!(pulp)
40
+ camilo.like!(pulp)
41
+ assert_equal 3, pulp.likers(User).size
43
42
 
44
- assert_raise ArgumentError do
45
- john.like!(travolta) # Can't like a Celeb
46
- end
43
+ assert pulp.likers(User).include?(carl)
44
+ assert pulp.likers(User).include?(john)
45
+ assert pulp.likers(User).include?(camilo)
46
+ assert !pulp.likers(User).include?(mat)
47
47
 
48
- assert_raise ArgumentError do
49
- john.follow!(kill_bill) # Can't follow a movie
50
- end
48
+ carl.follow!(mat)
49
+ mat.follow!(carl)
50
+ camilo.follow!(carl)
51
51
 
52
- assert_raise ArgumentError do
53
- john.follow!(john) # Can't follow yourself, duh!
54
- end
52
+ assert carl.follows?(mat)
53
+ assert mat.followed_by?(carl)
54
+ assert mat.follows?(carl)
55
+ assert carl.followed_by?(mat)
56
+ assert camilo.follows?(carl)
57
+ assert !carl.follows?(camilo)
55
58
 
56
- assert_raise ArgumentError do
57
- john.like!(john) # Can't like yourself, duh!
58
- end
59
+ assert_raise ArgumentError do
60
+ john.like!(travolta) # Can't like a Celeb
61
+ end
59
62
 
60
- comment = john.comments.create(:body => "I think Tami and Carl would like this movie!", :movie_id => pulp.id)
61
- comment.mention!(tami)
62
- comment.mention!(carl)
63
- assert comment.mentions?(carl)
64
- assert carl.mentioned_by?(comment)
65
- assert comment.mentions?(tami)
66
- assert tami.mentioned_by?(comment)
63
+ assert_raise ArgumentError do
64
+ john.follow!(kill_bill) # Can't follow a movie
67
65
  end
66
+
67
+ # You can even follow or like yourself if your ego is that big.
68
+ assert john.follow!(john)
69
+ assert john.like!(john)
70
+
71
+ comment = john.comments.create(:body => "I think Tami and Carl would like this movie!", :movie_id => pulp.id)
72
+ comment.mention!(tami)
73
+ comment.mention!(carl)
74
+ assert comment.mentions?(carl)
75
+ assert carl.mentioned_by?(comment)
76
+ assert comment.mentions?(tami)
77
+ assert tami.mentioned_by?(comment)
68
78
  end
69
79
 
70
80
  def seed
71
- @users = {}
72
- @celebs = {}
73
- @movies = {}
74
- @comments = {}
75
-
76
- @users[:john] = User.create :name => 'John Doe'
77
- @users[:jane] = User.create :name => 'Jane Doe'
78
- @users[:mat] = User.create :name => 'Mat'
79
- @users[:carl] = User.create :name => 'Carl'
80
- @users[:camilo] = User.create :name => 'Camilo'
81
- @users[:tami] = User.create :name => 'Tami'
82
-
83
- @movies[:pulp] = Movie.create :name => 'Pulp Fiction'
84
- @movies[:reservoir] = Movie.create :name => 'Reservoir Dogs'
85
- @movies[:kill_bill] = Movie.create :name => 'Kill Bill'
86
-
87
- @celebs[:willis] = Celebrity.create :name => 'Bruce Willis'
88
- @celebs[:travolta] = Celebrity.create :name => 'John Travolta'
89
- @celebs[:jackson] = Celebrity.create :name => 'Samuel L. Jackson'
81
+ @@users = {}
82
+ @@celebs = {}
83
+ @@movies = {}
84
+ @@comments = {}
85
+
86
+ @@users[:john] = User.create :name => 'John Doe'
87
+ @@users[:jane] = User.create :name => 'Jane Doe'
88
+ @@users[:mat] = User.create :name => 'Mat'
89
+ @@users[:carl] = User.create :name => 'Carl'
90
+ @@users[:camilo] = User.create :name => 'Camilo'
91
+ @@users[:tami] = User.create :name => 'Tami'
92
+
93
+ @@movies[:pulp] = Movie.create :name => 'Pulp Fiction'
94
+ @@movies[:reservoir] = Movie.create :name => 'Reservoir Dogs'
95
+ @@movies[:kill_bill] = Movie.create :name => 'Kill Bill'
96
+
97
+ @@celebs[:willis] = Celebrity.create :name => 'Bruce Willis'
98
+ @@celebs[:travolta] = Celebrity.create :name => 'John Travolta'
99
+ @@celebs[:jackson] = Celebrity.create :name => 'Samuel L. Jackson'
90
100
  end
91
101
 
92
102
  def method_missing(meth, *args, &block)
93
103
  sym = meth.to_sym
94
- return users[sym] if users[sym]
95
- return celebs[sym] if celebs[sym]
96
- return movies[sym] if movies[sym]
97
- return comments[sym] if comments[sym]
104
+ return users[sym] if users && users[sym]
105
+ return celebs[sym] if celebs && celebs[sym]
106
+ return movies[sym] if movies && movies[sym]
107
+ return comments[sym] if comments && comments[sym]
108
+ require 'pry'; binding.pry
98
109
  super
99
110
  end
100
111