socialization 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -0
- data/.travis.yml +2 -1
- data/Appraisals +13 -1
- data/CHANGELOG.md +12 -0
- data/Guardfile +12 -0
- data/LICENSE +2 -2
- data/README.md +46 -1
- data/Rakefile +8 -10
- data/lib/socialization/stores/active_record/follow.rb +4 -0
- data/lib/socialization/stores/active_record/like.rb +4 -0
- data/lib/socialization/stores/active_record/mention.rb +4 -0
- data/lib/socialization/stores/active_record/mixins/base.rb +4 -0
- data/lib/socialization/stores/mixins/follow.rb +1 -1
- data/lib/socialization/version.rb +1 -1
- data/socialization.gemspec +5 -3
- data/spec/actors/follower_spec.rb +113 -0
- data/spec/actors/liker_spec.rb +105 -0
- data/spec/actors/mentioner_spec.rb +105 -0
- data/spec/spec_helper.rb +21 -0
- data/{test/test_helper.rb → spec/spec_support/data_stores.rb} +76 -81
- data/spec/spec_support/matchers.rb +54 -0
- data/spec/stores/active_record/follow_store_spec.rb +147 -0
- data/spec/stores/active_record/like_store_spec.rb +146 -0
- data/spec/stores/active_record/mention_store_spec.rb +148 -0
- data/spec/stores/active_record/mixins/base_spec.rb +25 -0
- data/spec/stores/redis/base_spec.rb +195 -0
- data/spec/stores/redis/config_spec.rb +28 -0
- data/spec/stores/redis/follow_store_spec.rb +26 -0
- data/spec/stores/redis/like_store_spec.rb +23 -0
- data/spec/stores/redis/mention_store_spec.rb +23 -0
- data/spec/string_spec.rb +13 -0
- data/spec/victims/followable_spec.rb +59 -0
- data/spec/victims/likeable_spec.rb +58 -0
- data/spec/victims/mentionable_spec.rb +59 -0
- data/spec/world_spec.rb +107 -0
- metadata +79 -42
- data/test/actors/follower_test.rb +0 -114
- data/test/actors/liker_test.rb +0 -106
- data/test/actors/mentioner_test.rb +0 -106
- data/test/stores/active_record/follow_store_test.rb +0 -138
- data/test/stores/active_record/like_store_test.rb +0 -139
- data/test/stores/active_record/mention_store_test.rb +0 -138
- data/test/stores/redis/base_test.rb +0 -203
- data/test/stores/redis/config_test.rb +0 -30
- data/test/stores/redis/follow_store_test.rb +0 -27
- data/test/stores/redis/like_store_test.rb +0 -25
- data/test/stores/redis/mention_store_test.rb +0 -25
- data/test/string_test.rb +0 -13
- data/test/victims/followable_test.rb +0 -60
- data/test/victims/likeable_test.rb +0 -60
- data/test/victims/mentionable_test.rb +0 -60
- data/test/world_test.rb +0 -112
@@ -1,114 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__))+'/../test_helper'
|
2
|
-
|
3
|
-
class FollowerTest < Test::Unit::TestCase
|
4
|
-
context "Follower" do
|
5
|
-
setup do
|
6
|
-
@follower = ImAFollower.new
|
7
|
-
@followable = ImAFollowable.create
|
8
|
-
end
|
9
|
-
|
10
|
-
context "#is_follower?" do
|
11
|
-
should "return true" do
|
12
|
-
assert_true @follower.is_follower?
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
context "#follower?" do
|
17
|
-
should "return true" do
|
18
|
-
assert_true @follower.follower?
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
context "#follow!" do
|
23
|
-
should "not accept non-followables" do
|
24
|
-
assert_raise(Socialization::ArgumentError) { @follower.follow!(:foo) }
|
25
|
-
end
|
26
|
-
|
27
|
-
should "call $Follow.follow!" do
|
28
|
-
$Follow.expects(:follow!).with(@follower, @followable).once
|
29
|
-
@follower.follow!(@followable)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
context "#unfollow!" do
|
34
|
-
should "not accept non-followables" do
|
35
|
-
assert_raise(Socialization::ArgumentError) { @follower.unfollow!(:foo) }
|
36
|
-
end
|
37
|
-
|
38
|
-
should "call $Follow.follow!" do
|
39
|
-
$Follow.expects(:unfollow!).with(@follower, @followable).once
|
40
|
-
@follower.unfollow!(@followable)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
context "#toggle_follow!" do
|
45
|
-
should "not accept non-followables" do
|
46
|
-
assert_raise(Socialization::ArgumentError) { @follower.unfollow!(:foo) }
|
47
|
-
end
|
48
|
-
|
49
|
-
should "unfollow when following" do
|
50
|
-
@follower.expects(:follows?).with(@followable).once.returns(true)
|
51
|
-
@follower.expects(:unfollow!).with(@followable).once
|
52
|
-
@follower.toggle_follow!(@followable)
|
53
|
-
end
|
54
|
-
|
55
|
-
should "follow when not following" do
|
56
|
-
@follower.expects(:follows?).with(@followable).once.returns(false)
|
57
|
-
@follower.expects(:follow!).with(@followable).once
|
58
|
-
@follower.toggle_follow!(@followable)
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
context "#follows?" do
|
63
|
-
should "not accept non-followables" do
|
64
|
-
assert_raise(Socialization::ArgumentError) { @follower.unfollow!(:foo) }
|
65
|
-
end
|
66
|
-
|
67
|
-
should "call $Follow.follows?" do
|
68
|
-
$Follow.expects(:follows?).with(@follower, @followable).once
|
69
|
-
@follower.follows?(@followable)
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
context "#followables" do
|
74
|
-
should "call $Follow.followables" do
|
75
|
-
$Follow.expects(:followables).with(@follower, @followable.class, { :foo => :bar })
|
76
|
-
@follower.followables(@followable.class, { :foo => :bar })
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
context "#followees" do
|
81
|
-
should "call $Follow.followables" do
|
82
|
-
$Follow.expects(:followables).with(@follower, @followable.class, { :foo => :bar })
|
83
|
-
@follower.followees(@followable.class, { :foo => :bar })
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
context "#followables_relation" do
|
88
|
-
should "call $Follow.followables_relation" do
|
89
|
-
$Follow.expects(:followables_relation).with(@follower, @followable.class, { :foo => :bar })
|
90
|
-
@follower.followables_relation(@followable.class, { :foo => :bar })
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
context "#followees_relation" do
|
95
|
-
should "call $Follow.followables_relation" do
|
96
|
-
$Follow.expects(:followables_relation).with(@follower, @followable.class, { :foo => :bar })
|
97
|
-
@follower.followees_relation(@followable.class, { :foo => :bar })
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
context "deleting a follower" do
|
102
|
-
setup do
|
103
|
-
@follower = ImAFollower.create
|
104
|
-
@follower.follow!(@followable)
|
105
|
-
end
|
106
|
-
|
107
|
-
should "remove follow relationships" do
|
108
|
-
Socialization.follow_model.expects(:remove_followables).with(@follower)
|
109
|
-
@follower.destroy
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
end
|
114
|
-
end
|
data/test/actors/liker_test.rb
DELETED
@@ -1,106 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__))+'/../test_helper'
|
2
|
-
|
3
|
-
class LikerTest < Test::Unit::TestCase
|
4
|
-
context "Liker" do
|
5
|
-
setup do
|
6
|
-
@liker = ImALiker.new
|
7
|
-
@likeable = ImALikeable.create
|
8
|
-
end
|
9
|
-
|
10
|
-
context "#is_liker?" do
|
11
|
-
should "return true" do
|
12
|
-
assert_true @liker.is_liker?
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
context "#liker?" do
|
17
|
-
should "return true" do
|
18
|
-
assert_true @liker.liker?
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
context "#like!" do
|
23
|
-
should "not accept non-likeables" do
|
24
|
-
assert_raise(Socialization::ArgumentError) { @liker.like!(:foo) }
|
25
|
-
end
|
26
|
-
|
27
|
-
should "call $Like.like!" do
|
28
|
-
$Like.expects(:like!).with(@liker, @likeable).once
|
29
|
-
@liker.like!(@likeable)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
context "#unlike!" do
|
34
|
-
should "not accept non-likeables" do
|
35
|
-
assert_raise(Socialization::ArgumentError) { @liker.unlike!(:foo) }
|
36
|
-
end
|
37
|
-
|
38
|
-
should "call $Like.like!" do
|
39
|
-
$Like.expects(:unlike!).with(@liker, @likeable).once
|
40
|
-
@liker.unlike!(@likeable)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
context "#toggle_like!" do
|
45
|
-
should "not accept non-likeables" do
|
46
|
-
assert_raise(Socialization::ArgumentError) { @liker.unlike!(:foo) }
|
47
|
-
end
|
48
|
-
|
49
|
-
should "unlike when likeing" do
|
50
|
-
@liker.expects(:likes?).with(@likeable).once.returns(true)
|
51
|
-
@liker.expects(:unlike!).with(@likeable).once
|
52
|
-
@liker.toggle_like!(@likeable)
|
53
|
-
end
|
54
|
-
|
55
|
-
should "like when not likeing" do
|
56
|
-
@liker.expects(:likes?).with(@likeable).once.returns(false)
|
57
|
-
@liker.expects(:like!).with(@likeable).once
|
58
|
-
@liker.toggle_like!(@likeable)
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
context "#likes?" do
|
63
|
-
should "not accept non-likeables" do
|
64
|
-
assert_raise(Socialization::ArgumentError) { @liker.unlike!(:foo) }
|
65
|
-
end
|
66
|
-
|
67
|
-
should "call $Like.likes?" do
|
68
|
-
$Like.expects(:likes?).with(@liker, @likeable).once
|
69
|
-
@liker.likes?(@likeable)
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
context "#likeables" do
|
74
|
-
should "call $Like.likeables" do
|
75
|
-
$Like.expects(:likeables).with(@liker, @likeable.class, { :foo => :bar })
|
76
|
-
@liker.likeables(@likeable.class, { :foo => :bar })
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
context "#likees" do
|
81
|
-
should "call $Like.likeables" do
|
82
|
-
$Like.expects(:likeables).with(@liker, @likeable.class, { :foo => :bar })
|
83
|
-
@liker.likees(@likeable.class, { :foo => :bar })
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
context "#likeables_relation" do
|
88
|
-
should "call $Follow.likeables_relation" do
|
89
|
-
$Like.expects(:likeables_relation).with(@liker, @likeable.class, { :foo => :bar })
|
90
|
-
@liker.likeables_relation(@likeable.class, { :foo => :bar })
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
context "#likees_relation" do
|
95
|
-
should "call $Follow.likeables_relation" do
|
96
|
-
$Like.expects(:likeables_relation).with(@liker, @likeable.class, { :foo => :bar })
|
97
|
-
@liker.likees_relation(@likeable.class, { :foo => :bar })
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
should "remove like relationships" do
|
102
|
-
Socialization.like_model.expects(:remove_likeables).with(@liker)
|
103
|
-
@liker.destroy
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
@@ -1,106 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__))+'/../test_helper'
|
2
|
-
|
3
|
-
class MentionerTest < Test::Unit::TestCase
|
4
|
-
context "Mentioner" do
|
5
|
-
setup do
|
6
|
-
@mentioner = ImAMentioner.new
|
7
|
-
@mentionable = ImAMentionable.create
|
8
|
-
end
|
9
|
-
|
10
|
-
context "#is_mentioner?" do
|
11
|
-
should "return true" do
|
12
|
-
assert_true @mentioner.is_mentioner?
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
context "#mentioner?" do
|
17
|
-
should "return true" do
|
18
|
-
assert_true @mentioner.mentioner?
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
context "#mention!" do
|
23
|
-
should "not accept non-mentionables" do
|
24
|
-
assert_raise(Socialization::ArgumentError) { @mentioner.mention!(:foo) }
|
25
|
-
end
|
26
|
-
|
27
|
-
should "call $Mention.mention!" do
|
28
|
-
$Mention.expects(:mention!).with(@mentioner, @mentionable).once
|
29
|
-
@mentioner.mention!(@mentionable)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
context "#unmention!" do
|
34
|
-
should "not accept non-mentionables" do
|
35
|
-
assert_raise(Socialization::ArgumentError) { @mentioner.unmention!(:foo) }
|
36
|
-
end
|
37
|
-
|
38
|
-
should "call $Mention.mention!" do
|
39
|
-
$Mention.expects(:unmention!).with(@mentioner, @mentionable).once
|
40
|
-
@mentioner.unmention!(@mentionable)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
context "#toggle_mention!" do
|
45
|
-
should "not accept non-mentionables" do
|
46
|
-
assert_raise(Socialization::ArgumentError) { @mentioner.unmention!(:foo) }
|
47
|
-
end
|
48
|
-
|
49
|
-
should "unmention when mentioning" do
|
50
|
-
@mentioner.expects(:mentions?).with(@mentionable).once.returns(true)
|
51
|
-
@mentioner.expects(:unmention!).with(@mentionable).once
|
52
|
-
@mentioner.toggle_mention!(@mentionable)
|
53
|
-
end
|
54
|
-
|
55
|
-
should "mention when not mentioning" do
|
56
|
-
@mentioner.expects(:mentions?).with(@mentionable).once.returns(false)
|
57
|
-
@mentioner.expects(:mention!).with(@mentionable).once
|
58
|
-
@mentioner.toggle_mention!(@mentionable)
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
context "#mentions?" do
|
63
|
-
should "not accept non-mentionables" do
|
64
|
-
assert_raise(Socialization::ArgumentError) { @mentioner.unmention!(:foo) }
|
65
|
-
end
|
66
|
-
|
67
|
-
should "call $Mention.mentions?" do
|
68
|
-
$Mention.expects(:mentions?).with(@mentioner, @mentionable).once
|
69
|
-
@mentioner.mentions?(@mentionable)
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
context "#mentionables" do
|
74
|
-
should "call $Mention.mentionables" do
|
75
|
-
$Mention.expects(:mentionables).with(@mentioner, @mentionable.class, { :foo => :bar })
|
76
|
-
@mentioner.mentionables(@mentionable.class, { :foo => :bar })
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
context "#mentionees" do
|
81
|
-
should "call $Mention.mentionables" do
|
82
|
-
$Mention.expects(:mentionables).with(@mentioner, @mentionable.class, { :foo => :bar })
|
83
|
-
@mentioner.mentionees(@mentionable.class, { :foo => :bar })
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
context "#mentionables_relation" do
|
88
|
-
should "call $Mention.mentionables_relation" do
|
89
|
-
$Mention.expects(:mentionables_relation).with(@mentioner, @mentionable.class, { :foo => :bar })
|
90
|
-
@mentioner.mentionables_relation(@mentionable.class, { :foo => :bar })
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
context "#mentionees_relation" do
|
95
|
-
should "call $Mention.mentionables_relation" do
|
96
|
-
$Mention.expects(:mentionables_relation).with(@mentioner, @mentionable.class, { :foo => :bar })
|
97
|
-
@mentioner.mentionees_relation(@mentionable.class, { :foo => :bar })
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
should "remove mention relationships" do
|
102
|
-
Socialization.mention_model.expects(:remove_mentionables).with(@mentioner)
|
103
|
-
@mentioner.destroy
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
@@ -1,138 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__))+'/../../test_helper'
|
2
|
-
|
3
|
-
class ActiveRecordFollowStoreTest < Test::Unit::TestCase
|
4
|
-
context "ActiveRecordStores::FollowStoreTest" do
|
5
|
-
setup do
|
6
|
-
@klass = Socialization::ActiveRecordStores::Follow
|
7
|
-
@klass.touch nil
|
8
|
-
@klass.after_follow nil
|
9
|
-
@klass.after_unfollow nil
|
10
|
-
@follower = ImAFollower.create
|
11
|
-
@followable = ImAFollowable.create
|
12
|
-
end
|
13
|
-
|
14
|
-
context "data store" do
|
15
|
-
should "inherit Socialization::ActiveRecordStores::Follow" do
|
16
|
-
assert_equal Socialization::ActiveRecordStores::Follow, Socialization.follow_model
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
context "#follow!" do
|
21
|
-
should "create a Follow record" do
|
22
|
-
@klass.follow!(@follower, @followable)
|
23
|
-
assert_match_follower @klass.last, @follower
|
24
|
-
assert_match_followable @klass.last, @followable
|
25
|
-
end
|
26
|
-
|
27
|
-
should "touch follower when instructed" do
|
28
|
-
@klass.touch :follower
|
29
|
-
@follower.expects(:touch).once
|
30
|
-
@followable.expects(:touch).never
|
31
|
-
@klass.follow!(@follower, @followable)
|
32
|
-
end
|
33
|
-
|
34
|
-
should "touch followable when instructed" do
|
35
|
-
@klass.touch :followable
|
36
|
-
@follower.expects(:touch).never
|
37
|
-
@followable.expects(:touch).once
|
38
|
-
@klass.follow!(@follower, @followable)
|
39
|
-
end
|
40
|
-
|
41
|
-
should "touch all when instructed" do
|
42
|
-
@klass.touch :all
|
43
|
-
@follower.expects(:touch).once
|
44
|
-
@followable.expects(:touch).once
|
45
|
-
@klass.follow!(@follower, @followable)
|
46
|
-
end
|
47
|
-
|
48
|
-
should "call after follow hook" do
|
49
|
-
@klass.after_follow :after_follow
|
50
|
-
@klass.expects(:after_follow).once
|
51
|
-
@klass.follow!(@follower, @followable)
|
52
|
-
end
|
53
|
-
|
54
|
-
should "call after unfollow hook" do
|
55
|
-
@klass.after_follow :after_unfollow
|
56
|
-
@klass.expects(:after_unfollow).once
|
57
|
-
@klass.follow!(@follower, @followable)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
context "#follows?" do
|
62
|
-
should "return true when follow exists" do
|
63
|
-
@klass.create! do |f|
|
64
|
-
f.follower = @follower
|
65
|
-
f.followable = @followable
|
66
|
-
end
|
67
|
-
assert_true @klass.follows?(@follower, @followable)
|
68
|
-
end
|
69
|
-
|
70
|
-
should "return false when follow doesn't exist" do
|
71
|
-
assert_false @klass.follows?(@follower, @followable)
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
context "#followers" do
|
76
|
-
should "return an array of followers" do
|
77
|
-
follower1 = ImAFollower.create
|
78
|
-
follower2 = ImAFollower.create
|
79
|
-
follower1.follow!(@followable)
|
80
|
-
follower2.follow!(@followable)
|
81
|
-
assert_equal [follower1, follower2], @klass.followers(@followable, follower1.class)
|
82
|
-
end
|
83
|
-
|
84
|
-
should "return an array of follower ids when plucking" do
|
85
|
-
follower1 = ImAFollower.create
|
86
|
-
follower2 = ImAFollower.create
|
87
|
-
follower1.follow!(@followable)
|
88
|
-
follower2.follow!(@followable)
|
89
|
-
assert_equal [follower1.id, follower2.id], @klass.followers(@followable, follower1.class, :pluck => :id)
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
context "#followables" do
|
94
|
-
should "return an array of followers" do
|
95
|
-
followable1 = ImAFollowable.create
|
96
|
-
followable2 = ImAFollowable.create
|
97
|
-
@follower.follow!(followable1)
|
98
|
-
@follower.follow!(followable2)
|
99
|
-
assert_equal [followable1, followable2], @klass.followables(@follower, followable1.class)
|
100
|
-
end
|
101
|
-
|
102
|
-
should "return an array of follower ids when plucking" do
|
103
|
-
followable1 = ImAFollowable.create
|
104
|
-
followable2 = ImAFollowable.create
|
105
|
-
@follower.follow!(followable1)
|
106
|
-
@follower.follow!(followable2)
|
107
|
-
assert_equal [followable1.id, followable2.id], @klass.followables(@follower, followable1.class, :pluck => :id)
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
context "#remove_followers" do
|
112
|
-
should "delete all followers relationships for a followable" do
|
113
|
-
@follower.follow!(@followable)
|
114
|
-
assert_equal 1, @followable.followers(@follower.class).count
|
115
|
-
@klass.remove_followers(@followable)
|
116
|
-
assert_equal 0, @followable.followers(@follower.class).count
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
context "#remove_followables" do
|
121
|
-
should "delete all followables relationships for a follower" do
|
122
|
-
@follower.follow!(@followable)
|
123
|
-
assert_equal 1, @follower.followables(@followable.class).count
|
124
|
-
@klass.remove_followables(@follower)
|
125
|
-
assert_equal 0, @follower.followables(@followable.class).count
|
126
|
-
end
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
|
-
# Helpers
|
131
|
-
def assert_match_follower(follow_record, follower)
|
132
|
-
assert follow_record.follower_type == follower.class.to_s && follow_record.follower_id == follower.id
|
133
|
-
end
|
134
|
-
|
135
|
-
def assert_match_followable(follow_record, followable)
|
136
|
-
assert follow_record.followable_type == followable.class.to_s && follow_record.followable_id == followable.id
|
137
|
-
end
|
138
|
-
end
|