socialization 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -0
  3. data/.travis.yml +2 -1
  4. data/Appraisals +13 -1
  5. data/CHANGELOG.md +12 -0
  6. data/Guardfile +12 -0
  7. data/LICENSE +2 -2
  8. data/README.md +46 -1
  9. data/Rakefile +8 -10
  10. data/lib/socialization/stores/active_record/follow.rb +4 -0
  11. data/lib/socialization/stores/active_record/like.rb +4 -0
  12. data/lib/socialization/stores/active_record/mention.rb +4 -0
  13. data/lib/socialization/stores/active_record/mixins/base.rb +4 -0
  14. data/lib/socialization/stores/mixins/follow.rb +1 -1
  15. data/lib/socialization/version.rb +1 -1
  16. data/socialization.gemspec +5 -3
  17. data/spec/actors/follower_spec.rb +113 -0
  18. data/spec/actors/liker_spec.rb +105 -0
  19. data/spec/actors/mentioner_spec.rb +105 -0
  20. data/spec/spec_helper.rb +21 -0
  21. data/{test/test_helper.rb → spec/spec_support/data_stores.rb} +76 -81
  22. data/spec/spec_support/matchers.rb +54 -0
  23. data/spec/stores/active_record/follow_store_spec.rb +147 -0
  24. data/spec/stores/active_record/like_store_spec.rb +146 -0
  25. data/spec/stores/active_record/mention_store_spec.rb +148 -0
  26. data/spec/stores/active_record/mixins/base_spec.rb +25 -0
  27. data/spec/stores/redis/base_spec.rb +195 -0
  28. data/spec/stores/redis/config_spec.rb +28 -0
  29. data/spec/stores/redis/follow_store_spec.rb +26 -0
  30. data/spec/stores/redis/like_store_spec.rb +23 -0
  31. data/spec/stores/redis/mention_store_spec.rb +23 -0
  32. data/spec/string_spec.rb +13 -0
  33. data/spec/victims/followable_spec.rb +59 -0
  34. data/spec/victims/likeable_spec.rb +58 -0
  35. data/spec/victims/mentionable_spec.rb +59 -0
  36. data/spec/world_spec.rb +107 -0
  37. metadata +79 -42
  38. data/test/actors/follower_test.rb +0 -114
  39. data/test/actors/liker_test.rb +0 -106
  40. data/test/actors/mentioner_test.rb +0 -106
  41. data/test/stores/active_record/follow_store_test.rb +0 -138
  42. data/test/stores/active_record/like_store_test.rb +0 -139
  43. data/test/stores/active_record/mention_store_test.rb +0 -138
  44. data/test/stores/redis/base_test.rb +0 -203
  45. data/test/stores/redis/config_test.rb +0 -30
  46. data/test/stores/redis/follow_store_test.rb +0 -27
  47. data/test/stores/redis/like_store_test.rb +0 -25
  48. data/test/stores/redis/mention_store_test.rb +0 -25
  49. data/test/string_test.rb +0 -13
  50. data/test/victims/followable_test.rb +0 -60
  51. data/test/victims/likeable_test.rb +0 -60
  52. data/test/victims/mentionable_test.rb +0 -60
  53. data/test/world_test.rb +0 -112
@@ -1,139 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__))+'/../../test_helper'
2
-
3
- class ActiveRecordLikeStoreTest < Test::Unit::TestCase
4
- context "ActiveRecordStores::LikeStoreTest" do
5
- setup do
6
- @klass = Socialization::ActiveRecordStores::Like
7
- @klass.touch nil
8
- @klass.after_like nil
9
- @klass.after_unlike nil
10
- @liker = ImALiker.create
11
- @likeable = ImALikeable.create
12
- end
13
-
14
- context "data store" do
15
- should "inherit Socialization::ActiveRecordStores::Like" do
16
- assert_equal Socialization::ActiveRecordStores::Like, Socialization.like_model
17
- end
18
- end
19
-
20
- context "#like!" do
21
- should "create a Like record" do
22
- @klass.like!(@liker, @likeable)
23
- assert_match_liker @klass.last, @liker
24
- assert_match_likeable @klass.last, @likeable
25
- end
26
-
27
- should "touch liker when instructed" do
28
- @klass.touch :liker
29
- @liker.expects(:touch).once
30
- @likeable.expects(:touch).never
31
- @klass.like!(@liker, @likeable)
32
- end
33
-
34
- should "touch likeable when instructed" do
35
- @klass.touch :likeable
36
- @liker.expects(:touch).never
37
- @likeable.expects(:touch).once
38
- @klass.like!(@liker, @likeable)
39
- end
40
-
41
- should "touch all when instructed" do
42
- @klass.touch :all
43
- @liker.expects(:touch).once
44
- @likeable.expects(:touch).once
45
- @klass.like!(@liker, @likeable)
46
- end
47
-
48
- should "call after like hook" do
49
- @klass.after_like :after_like
50
- @klass.expects(:after_like).once
51
- @klass.like!(@liker, @likeable)
52
- end
53
-
54
- should "call after unlike hook" do
55
- @klass.after_like :after_unlike
56
- @klass.expects(:after_unlike).once
57
- @klass.like!(@liker, @likeable)
58
- end
59
- end
60
-
61
- context "#likes?" do
62
- should "return true when like exists" do
63
- @klass.create! do |f|
64
- f.liker = @liker
65
- f.likeable = @likeable
66
- end
67
- assert_true @klass.likes?(@liker, @likeable)
68
- end
69
-
70
- should "return false when like doesn't exist" do
71
- assert_false @klass.likes?(@liker, @likeable)
72
- end
73
- end
74
-
75
- context "#likers" do
76
- should "return an array of likers" do
77
- liker1 = ImALiker.create
78
- liker2 = ImALiker.create
79
- liker1.like!(@likeable)
80
- liker2.like!(@likeable)
81
- assert_equal [liker1, liker2], @klass.likers(@likeable, liker1.class)
82
- end
83
-
84
- should "return an array of liker ids when plucking" do
85
- liker1 = ImALiker.create
86
- liker2 = ImALiker.create
87
- liker1.like!(@likeable)
88
- liker2.like!(@likeable)
89
- assert_equal [liker1.id, liker2.id], @klass.likers(@likeable, liker1.class, :pluck => :id)
90
- end
91
- end
92
-
93
- context "#likeables" do
94
- should "return an array of likers" do
95
- likeable1 = ImALikeable.create
96
- likeable2 = ImALikeable.create
97
- @liker.like!(likeable1)
98
- @liker.like!(likeable2)
99
- assert_equal [likeable1, likeable2], @klass.likeables(@liker, likeable1.class)
100
- end
101
-
102
- should "return an array of liker ids when plucking" do
103
- likeable1 = ImALikeable.create
104
- likeable2 = ImALikeable.create
105
- @liker.like!(likeable1)
106
- @liker.like!(likeable2)
107
- assert_equal [likeable1.id, likeable2.id], @klass.likeables(@liker, likeable1.class, :pluck => :id)
108
- end
109
- end
110
-
111
- context "#remove_likers" do
112
- should "delete all likers relationships for a likeable" do
113
- @liker.like!(@likeable)
114
- assert_equal 1, @likeable.likers(@liker.class).count
115
- @klass.remove_likers(@likeable)
116
- assert_equal 0, @likeable.likers(@liker.class).count
117
- end
118
- end
119
-
120
- context "#remove_likeables" do
121
- should "delete all likeables relationships for a liker" do
122
- @liker.like!(@likeable)
123
- assert_equal 1, @liker.likeables(@likeable.class).count
124
- @klass.remove_likeables(@liker)
125
- assert_equal 0, @liker.likeables(@likeable.class).count
126
- end
127
- end
128
-
129
- end
130
-
131
- # Helpers
132
- def assert_match_liker(like_record, liker)
133
- assert like_record.liker_type == liker.class.to_s && like_record.liker_id == liker.id
134
- end
135
-
136
- def assert_match_likeable(like_record, likeable)
137
- assert like_record.likeable_type == likeable.class.to_s && like_record.likeable_id == likeable.id
138
- end
139
- end
@@ -1,138 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__))+'/../../test_helper'
2
-
3
- class ActiveRecordMentionStoreTest < Test::Unit::TestCase
4
- context "ActiveRecordStores::MentionStoreTest" do
5
- setup do
6
- @klass = Socialization::ActiveRecordStores::Mention
7
- @klass.touch nil
8
- @klass.after_mention nil
9
- @klass.after_unmention nil
10
- @mentioner = ImAMentioner.create
11
- @mentionable = ImAMentionable.create
12
- end
13
-
14
- context "data store" do
15
- should "inherit Socialization::ActiveRecordStores::Mention" do
16
- assert_equal Socialization::ActiveRecordStores::Mention, Socialization.mention_model
17
- end
18
- end
19
-
20
- context "#mention!" do
21
- should "create a Mention record" do
22
- @klass.mention!(@mentioner, @mentionable)
23
- assert_match_mentioner @klass.last, @mentioner
24
- assert_match_mentionable @klass.last, @mentionable
25
- end
26
-
27
- should "touch mentioner when instructed" do
28
- @klass.touch :mentioner
29
- @mentioner.expects(:touch).once
30
- @mentionable.expects(:touch).never
31
- @klass.mention!(@mentioner, @mentionable)
32
- end
33
-
34
- should "touch mentionable when instructed" do
35
- @klass.touch :mentionable
36
- @mentioner.expects(:touch).never
37
- @mentionable.expects(:touch).once
38
- @klass.mention!(@mentioner, @mentionable)
39
- end
40
-
41
- should "touch all when instructed" do
42
- @klass.touch :all
43
- @mentioner.expects(:touch).once
44
- @mentionable.expects(:touch).once
45
- @klass.mention!(@mentioner, @mentionable)
46
- end
47
-
48
- should "call after mention hook" do
49
- @klass.after_mention :after_mention
50
- @klass.expects(:after_mention).once
51
- @klass.mention!(@mentioner, @mentionable)
52
- end
53
-
54
- should "call after unmention hook" do
55
- @klass.after_mention :after_unmention
56
- @klass.expects(:after_unmention).once
57
- @klass.mention!(@mentioner, @mentionable)
58
- end
59
- end
60
-
61
- context "#mentions?" do
62
- should "return true when mention exists" do
63
- @klass.create! do |f|
64
- f.mentioner = @mentioner
65
- f.mentionable = @mentionable
66
- end
67
- assert_true @klass.mentions?(@mentioner, @mentionable)
68
- end
69
-
70
- should "return false when mention doesn't exist" do
71
- assert_false @klass.mentions?(@mentioner, @mentionable)
72
- end
73
- end
74
-
75
- context "#mentioners" do
76
- should "return an array of mentioners" do
77
- mentioner1 = ImAMentioner.create
78
- mentioner2 = ImAMentioner.create
79
- mentioner1.mention!(@mentionable)
80
- mentioner2.mention!(@mentionable)
81
- assert_equal [mentioner1, mentioner2], @klass.mentioners(@mentionable, mentioner1.class)
82
- end
83
-
84
- should "return an array of mentioner ids when plucking" do
85
- mentioner1 = ImAMentioner.create
86
- mentioner2 = ImAMentioner.create
87
- mentioner1.mention!(@mentionable)
88
- mentioner2.mention!(@mentionable)
89
- assert_equal [mentioner1.id, mentioner2.id], @klass.mentioners(@mentionable, mentioner1.class, :pluck => :id)
90
- end
91
- end
92
-
93
- context "#mentionables" do
94
- should "return an array of mentioners" do
95
- mentionable1 = ImAMentionable.create
96
- mentionable2 = ImAMentionable.create
97
- @mentioner.mention!(mentionable1)
98
- @mentioner.mention!(mentionable2)
99
- assert_equal [mentionable1, mentionable2], @klass.mentionables(@mentioner, mentionable1.class)
100
- end
101
-
102
- should "return an array of mentioner ids when plucking" do
103
- mentionable1 = ImAMentionable.create
104
- mentionable2 = ImAMentionable.create
105
- @mentioner.mention!(mentionable1)
106
- @mentioner.mention!(mentionable2)
107
- assert_equal [mentionable1.id, mentionable2.id], @klass.mentionables(@mentioner, mentionable1.class, :pluck => :id)
108
- end
109
- end
110
-
111
- context "#remove_mentioners" do
112
- should "delete all mentioners relationships for a mentionable" do
113
- @mentioner.mention!(@mentionable)
114
- assert_equal 1, @mentionable.mentioners(@mentioner.class).count
115
- @klass.remove_mentioners(@mentionable)
116
- assert_equal 0, @mentionable.mentioners(@mentioner.class).count
117
- end
118
- end
119
-
120
- context "#remove_mentionables" do
121
- should "delete all mentionables relationships for a mentioner" do
122
- @mentioner.mention!(@mentionable)
123
- assert_equal 1, @mentioner.mentionables(@mentionable.class).count
124
- @klass.remove_mentionables(@mentioner)
125
- assert_equal 0, @mentioner.mentionables(@mentionable.class).count
126
- end
127
- end
128
- end
129
-
130
- # Helpers
131
- def assert_match_mentioner(mention_record, mentioner)
132
- assert mention_record.mentioner_type == mentioner.class.to_s && mention_record.mentioner_id == mentioner.id
133
- end
134
-
135
- def assert_match_mentionable(mention_record, mentionable)
136
- assert mention_record.mentionable_type == mentionable.class.to_s && mention_record.mentionable_id == mentionable.id
137
- end
138
- end
@@ -1,203 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__))+'/../../test_helper'
2
-
3
- class RedisBaseStoreTest < Test::Unit::TestCase
4
- # Testing through RedisStores::Follow for easy testing
5
- context "RedisStores::Base through RedisStores::Follow" do
6
- setup do
7
- use_redis_store
8
- @klass = Socialization::RedisStores::Follow
9
- @klass.touch nil
10
- @klass.after_follow nil
11
- @klass.after_unfollow nil
12
- @follower1 = ImAFollower.create
13
- @follower2 = ImAFollower.create
14
- @followable1 = ImAFollowable.create
15
- @followable2 = ImAFollowable.create
16
- end
17
-
18
- context "Stores" do
19
- should "inherit Socialization::RedisStores::Follow" do
20
- assert_equal Socialization::RedisStores::Follow, Socialization.follow_model
21
- end
22
- end
23
-
24
- context "#follow!" do
25
- should "create follow records" do
26
- @klass.follow!(@follower1, @followable1)
27
- assert_array_similarity ["#{@follower1.class}:#{@follower1.id}"], Socialization.redis.smembers(forward_key(@followable1))
28
- assert_array_similarity ["#{@followable1.class}:#{@followable1.id}"], Socialization.redis.smembers(backward_key(@follower1))
29
-
30
- @klass.follow!(@follower2, @followable1)
31
- assert_array_similarity ["#{@follower1.class}:#{@follower1.id}", "#{@follower2.class}:#{@follower2.id}"], Socialization.redis.smembers(forward_key(@followable1))
32
- assert_array_similarity ["#{@followable1.class}:#{@followable1.id}"], Socialization.redis.smembers(backward_key(@follower1))
33
- assert_array_similarity ["#{@followable1.class}:#{@followable1.id}"], Socialization.redis.smembers(backward_key(@follower2))
34
- end
35
-
36
- should "touch follower when instructed" do
37
- @klass.touch :follower
38
- @follower1.expects(:touch).once
39
- @followable1.expects(:touch).never
40
- @klass.follow!(@follower1, @followable1)
41
- end
42
-
43
- should "touch followable when instructed" do
44
- @klass.touch :followable
45
- @follower1.expects(:touch).never
46
- @followable1.expects(:touch).once
47
- @klass.follow!(@follower1, @followable1)
48
- end
49
-
50
- should "touch all when instructed" do
51
- @klass.touch :all
52
- @follower1.expects(:touch).once
53
- @followable1.expects(:touch).once
54
- @klass.follow!(@follower1, @followable1)
55
- end
56
-
57
- should "call after follow hook" do
58
- @klass.after_follow :after_follow
59
- @klass.expects(:after_follow).once
60
- @klass.follow!(@follower1, @followable1)
61
- end
62
-
63
- should "call after unfollow hook" do
64
- @klass.after_follow :after_unfollow
65
- @klass.expects(:after_unfollow).once
66
- @klass.follow!(@follower1, @followable1)
67
- end
68
- end
69
-
70
- context "#unfollow!" do
71
- setup do
72
- @klass.follow!(@follower1, @followable1)
73
- end
74
-
75
- should "remove follow records" do
76
- @klass.unfollow!(@follower1, @followable1)
77
- assert_empty Socialization.redis.smembers forward_key(@followable1)
78
- assert_empty Socialization.redis.smembers backward_key(@follower1)
79
- end
80
- end
81
-
82
- context "#follows?" do
83
- should "return true when follow exists" do
84
- @klass.follow!(@follower1, @followable1)
85
- assert_true @klass.follows?(@follower1, @followable1)
86
- end
87
-
88
- should "return false when follow doesn't exist" do
89
- assert_false @klass.follows?(@follower1, @followable1)
90
- end
91
- end
92
-
93
- context "#followers" do
94
- should "return an array of followers" do
95
- follower1 = ImAFollower.create
96
- follower2 = ImAFollower.create
97
- follower1.follow!(@followable1)
98
- follower2.follow!(@followable1)
99
- assert_array_similarity [follower1, follower2], @klass.followers(@followable1, follower1.class)
100
- end
101
-
102
- should "return an array of follower ids when plucking" do
103
- follower1 = ImAFollower.create
104
- follower2 = ImAFollower.create
105
- follower1.follow!(@followable1)
106
- follower2.follow!(@followable1)
107
- assert_array_similarity ["#{follower1.id}", "#{follower2.id}"], @klass.followers(@followable1, follower1.class, :pluck => :id)
108
- end
109
- end
110
-
111
- context "#followables" do
112
- should "return an array of followables" do
113
- followable1 = ImAFollowable.create
114
- followable2 = ImAFollowable.create
115
- @follower1.follow!(followable1)
116
- @follower1.follow!(followable2)
117
-
118
- assert_array_similarity [followable1, followable2], @klass.followables(@follower1, followable1.class)
119
- end
120
-
121
- should "return an array of followables ids when plucking" do
122
- followable1 = ImAFollowable.create
123
- followable2 = ImAFollowable.create
124
- @follower1.follow!(followable1)
125
- @follower1.follow!(followable2)
126
- assert_array_similarity ["#{followable1.id}", "#{followable2.id}"], @klass.followables(@follower1, followable1.class, :pluck => :id)
127
- end
128
- end
129
-
130
- context "#generate_forward_key" do
131
- should "return valid key when passed an object" do
132
- assert_equal "Followers:#{@followable1.class.name}:#{@followable1.id}", forward_key(@followable1)
133
- end
134
-
135
- should "return valid key when passed a String" do
136
- assert_equal "Followers:Followable:1", forward_key("Followable:1")
137
- end
138
- end
139
-
140
- context "#generate_backward_key" do
141
- should "return valid key when passed an object" do
142
- assert_equal "Followables:#{@follower1.class.name}:#{@follower1.id}", backward_key(@follower1)
143
- end
144
-
145
- should "return valid key when passed a String" do
146
- assert_equal "Followables:Follower:1", backward_key("Follower:1")
147
- end
148
- end
149
-
150
- context "#remove_followers" do
151
- should "delete all followers relationships for a followable" do
152
- @follower1.follow!(@followable1)
153
- @follower2.follow!(@followable1)
154
- assert_equal 2, @followable1.followers(@follower1.class).count
155
-
156
- @klass.remove_followers(@followable1)
157
- assert_equal 0, @followable1.followers(@follower1.class).count
158
- assert_empty Socialization.redis.smembers forward_key(@followable1)
159
- assert_empty Socialization.redis.smembers backward_key(@follower1)
160
- assert_empty Socialization.redis.smembers backward_key(@follower2)
161
- end
162
- end
163
-
164
- context "#remove_followables" do
165
- should "delete all followables relationships for a follower" do
166
- @follower1.follow!(@followable1)
167
- @follower1.follow!(@followable2)
168
- assert_equal 2, @follower1.followables(@followable1.class).count
169
-
170
- @klass.remove_followables(@follower1)
171
- assert_equal 0, @follower1.followables(@followable1.class).count
172
- assert_empty Socialization.redis.smembers backward_key(@followable1)
173
- assert_empty Socialization.redis.smembers backward_key(@follower2)
174
- assert_empty Socialization.redis.smembers forward_key(@follower1)
175
- end
176
- end
177
-
178
- context "#key_type_to_type_names" do
179
- should "return the proper arrays" do
180
- assert_equal ['follower', 'followable'], @klass.send(:key_type_to_type_names, Socialization::RedisStores::Follow)
181
- assert_equal ['mentioner', 'mentionable'], @klass.send(:key_type_to_type_names, Socialization::RedisStores::Mention)
182
- assert_equal ['liker', 'likeable'], @klass.send(:key_type_to_type_names, Socialization::RedisStores::Like)
183
- end
184
- end
185
- end
186
-
187
- # Helpers
188
- def assert_match_follower(follow_record, follower)
189
- assert follow_record.follower_type == follower.class.to_s && follow_record.follower_id == follower.id
190
- end
191
-
192
- def assert_match_followable(follow_record, followable)
193
- assert follow_record.followable_type == followable.class.to_s && follow_record.followable_id == followable.id
194
- end
195
-
196
- def forward_key(followable)
197
- Socialization::RedisStores::Follow.send(:generate_forward_key, followable)
198
- end
199
-
200
- def backward_key(follower)
201
- Socialization::RedisStores::Follow.send(:generate_backward_key, follower)
202
- end
203
- end