socialization 1.1.0 → 1.2.0
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.
- 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,30 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__))+'/../../test_helper'
|
2
|
-
|
3
|
-
class RedisStoreConfigTest < Test::Unit::TestCase
|
4
|
-
context "redis" do
|
5
|
-
setup do
|
6
|
-
Socialization.instance_eval { @redis = nil }
|
7
|
-
end
|
8
|
-
|
9
|
-
should "return a new Redis object when none were specified" do
|
10
|
-
assert_instance_of Redis, Socialization.redis
|
11
|
-
end
|
12
|
-
|
13
|
-
should "always return the same Redis object when none were specified" do
|
14
|
-
redis = Socialization.redis
|
15
|
-
assert_same redis, Socialization.redis
|
16
|
-
end
|
17
|
-
|
18
|
-
should "be able to set and get a redis instance" do
|
19
|
-
redis = Redis.new
|
20
|
-
Socialization.redis = redis
|
21
|
-
assert_same redis, Socialization.redis
|
22
|
-
end
|
23
|
-
|
24
|
-
should "always return the same Redis object when it was specified" do
|
25
|
-
redis = Redis.new
|
26
|
-
Socialization.redis = redis
|
27
|
-
assert_same redis, Socialization.redis
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__))+'/../../test_helper'
|
2
|
-
|
3
|
-
class RedisFollowStoreTest < Test::Unit::TestCase
|
4
|
-
context "RedisStores::Follow" do
|
5
|
-
setup do
|
6
|
-
use_redis_store
|
7
|
-
@klass = Socialization::RedisStores::Follow
|
8
|
-
@base = Socialization::RedisStores::Base
|
9
|
-
end
|
10
|
-
|
11
|
-
context "method aliases" do
|
12
|
-
should "be set properly and made public" do
|
13
|
-
# TODO: Can't figure out how to test method aliases properly. The following doesn't work:
|
14
|
-
# assert @klass.method(:follow!) == @base.method(:relation!)
|
15
|
-
assert_method_public @klass, :follow!
|
16
|
-
assert_method_public @klass, :unfollow!
|
17
|
-
assert_method_public @klass, :follows?
|
18
|
-
assert_method_public @klass, :followers_relation
|
19
|
-
assert_method_public @klass, :followers
|
20
|
-
assert_method_public @klass, :followables_relation
|
21
|
-
assert_method_public @klass, :followables
|
22
|
-
assert_method_public @klass, :remove_followers
|
23
|
-
assert_method_public @klass, :remove_followables
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__))+'/../../test_helper'
|
2
|
-
|
3
|
-
class RedisLikeStoreTest < Test::Unit::TestCase
|
4
|
-
context "RedisStores::Like" do
|
5
|
-
setup do
|
6
|
-
use_redis_store
|
7
|
-
@klass = Socialization::RedisStores::Like
|
8
|
-
@base = Socialization::RedisStores::Base
|
9
|
-
end
|
10
|
-
|
11
|
-
context "method aliases" do
|
12
|
-
should "be set properly and made public" do
|
13
|
-
assert_method_public @klass, :like!
|
14
|
-
assert_method_public @klass, :unlike!
|
15
|
-
assert_method_public @klass, :likes?
|
16
|
-
assert_method_public @klass, :likers_relation
|
17
|
-
assert_method_public @klass, :likers
|
18
|
-
assert_method_public @klass, :likeables_relation
|
19
|
-
assert_method_public @klass, :likeables
|
20
|
-
assert_method_public @klass, :remove_likers
|
21
|
-
assert_method_public @klass, :remove_likeables
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__))+'/../../test_helper'
|
2
|
-
|
3
|
-
class RedisMentionStoreTest < Test::Unit::TestCase
|
4
|
-
context "RedisStores::Mention" do
|
5
|
-
setup do
|
6
|
-
use_redis_store
|
7
|
-
@klass = Socialization::RedisStores::Mention
|
8
|
-
@base = Socialization::RedisStores::Base
|
9
|
-
end
|
10
|
-
|
11
|
-
context "method aliases" do
|
12
|
-
should "be set properly and made public" do
|
13
|
-
assert_method_public @klass, :mention!
|
14
|
-
assert_method_public @klass, :unmention!
|
15
|
-
assert_method_public @klass, :mentions?
|
16
|
-
assert_method_public @klass, :mentioners_relation
|
17
|
-
assert_method_public @klass, :mentioners
|
18
|
-
assert_method_public @klass, :mentionables_relation
|
19
|
-
assert_method_public @klass, :mentionables
|
20
|
-
assert_method_public @klass, :remove_mentioners
|
21
|
-
assert_method_public @klass, :remove_mentionables
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
data/test/string_test.rb
DELETED
@@ -1,13 +0,0 @@
|
|
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::Follow, "Socialization::ActiveRecordStores::Follow".deep_const_get
|
9
|
-
|
10
|
-
assert_raise(NameError) { "Foo::Bar".deep_const_get }
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
@@ -1,60 +0,0 @@
|
|
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 "#followable?" do
|
17
|
-
should "return true" do
|
18
|
-
assert_true @followable.followable?
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
context "#followed_by?" do
|
23
|
-
should "not accept non-followers" do
|
24
|
-
assert_raise(Socialization::ArgumentError) { @followable.followed_by?(:foo) }
|
25
|
-
end
|
26
|
-
|
27
|
-
should "call $Follow.follows?" do
|
28
|
-
$Follow.expects(:follows?).with(@follower, @followable).once
|
29
|
-
@followable.followed_by?(@follower)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
context "#followers" do
|
34
|
-
should "call $Follow.followers" do
|
35
|
-
$Follow.expects(:followers).with(@followable, @follower.class, { :foo => :bar })
|
36
|
-
@followable.followers(@follower.class, { :foo => :bar })
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
context "#followers_relation" do
|
41
|
-
should "call $Follow.followers_relation" do
|
42
|
-
$Follow.expects(:followers_relation).with(@followable, @follower.class, { :foo => :bar })
|
43
|
-
@followable.followers_relation(@follower.class, { :foo => :bar })
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
context "deleting a followable" do
|
48
|
-
setup do
|
49
|
-
@follower = ImAFollower.create
|
50
|
-
@follower.follow!(@followable)
|
51
|
-
end
|
52
|
-
|
53
|
-
should "remove follow relationships" do
|
54
|
-
Socialization.follow_model.expects(:remove_followers).with(@followable)
|
55
|
-
@followable.destroy
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
end
|
60
|
-
end
|
@@ -1,60 +0,0 @@
|
|
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 "#likeable?" do
|
17
|
-
should "return true" do
|
18
|
-
assert_true @likeable.likeable?
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
context "#liked_by?" do
|
23
|
-
should "not accept non-likers" do
|
24
|
-
assert_raise(Socialization::ArgumentError) { @likeable.liked_by?(:foo) }
|
25
|
-
end
|
26
|
-
|
27
|
-
should "call $Like.likes?" do
|
28
|
-
$Like.expects(:likes?).with(@liker, @likeable).once
|
29
|
-
@likeable.liked_by?(@liker)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
context "#likers" do
|
34
|
-
should "call $Like.likers" do
|
35
|
-
$Like.expects(:likers).with(@likeable, @liker.class, { :foo => :bar })
|
36
|
-
@likeable.likers(@liker.class, { :foo => :bar })
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
context "#likers_relation" do
|
41
|
-
should "call $Like.likers_relation" do
|
42
|
-
$Like.expects(:likers_relation).with(@likeable, @liker.class, { :foo => :bar })
|
43
|
-
@likeable.likers_relation(@liker.class, { :foo => :bar })
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
context "deleting a likeable" do
|
48
|
-
setup do
|
49
|
-
@liker = ImALiker.create
|
50
|
-
@liker.like!(@likeable)
|
51
|
-
end
|
52
|
-
|
53
|
-
should "remove like relationships" do
|
54
|
-
Socialization.like_model.expects(:remove_likers).with(@likeable)
|
55
|
-
@likeable.destroy
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
end
|
60
|
-
end
|
@@ -1,60 +0,0 @@
|
|
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 "#mentionable?" do
|
17
|
-
should "return true" do
|
18
|
-
assert_true @mentionable.mentionable?
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
context "#mentioned_by?" do
|
23
|
-
should "not accept non-mentioners" do
|
24
|
-
assert_raise(Socialization::ArgumentError) { @mentionable.mentioned_by?(:foo) }
|
25
|
-
end
|
26
|
-
|
27
|
-
should "call $Mention.mentions?" do
|
28
|
-
$Mention.expects(:mentions?).with(@mentioner, @mentionable).once
|
29
|
-
@mentionable.mentioned_by?(@mentioner)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
context "#mentioners" do
|
34
|
-
should "call $Mention.mentioners" do
|
35
|
-
$Mention.expects(:mentioners).with(@mentionable, @mentioner.class, { :foo => :bar })
|
36
|
-
@mentionable.mentioners(@mentioner.class, { :foo => :bar })
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
context "#mentioners_relation" do
|
41
|
-
should "call $Mention.mentioners" do
|
42
|
-
$Mention.expects(:mentioners_relation).with(@mentionable, @mentioner.class, { :foo => :bar })
|
43
|
-
@mentionable.mentioners_relation(@mentioner.class, { :foo => :bar })
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
context "deleting a mentionable" do
|
48
|
-
setup do
|
49
|
-
@mentioner = ImAMentioner.create
|
50
|
-
@mentioner.mention!(@mentionable)
|
51
|
-
end
|
52
|
-
|
53
|
-
should "remove mention relationships" do
|
54
|
-
Socialization.mention_model.expects(:remove_mentioners).with(@mentionable)
|
55
|
-
@mentionable.destroy
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
end
|
60
|
-
end
|
data/test/world_test.rb
DELETED
@@ -1,112 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__))+'/test_helper'
|
2
|
-
|
3
|
-
# Test Socialization as it would be used in a "real world" scenario
|
4
|
-
class WorldTest < Test::Unit::TestCase
|
5
|
-
cattr_reader :users, :movies, :celebs, :comments
|
6
|
-
|
7
|
-
context "The World" do
|
8
|
-
setup do
|
9
|
-
seed
|
10
|
-
end
|
11
|
-
|
12
|
-
context "ActiveRecord store" do
|
13
|
-
setup { use_ar_store }
|
14
|
-
should "be social" do
|
15
|
-
test_the_world
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
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
|
26
|
-
|
27
|
-
def test_the_world
|
28
|
-
john.like!(pulp)
|
29
|
-
john.follow!(jane)
|
30
|
-
john.follow!(travolta)
|
31
|
-
|
32
|
-
assert john.likes?(pulp)
|
33
|
-
assert john.follows?(jane)
|
34
|
-
assert john.follows?(travolta)
|
35
|
-
|
36
|
-
assert pulp.liked_by?(john)
|
37
|
-
assert travolta.followed_by?(john)
|
38
|
-
|
39
|
-
carl.like!(pulp)
|
40
|
-
camilo.like!(pulp)
|
41
|
-
assert_equal 3, pulp.likers(User).size
|
42
|
-
|
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
|
-
|
48
|
-
carl.follow!(mat)
|
49
|
-
mat.follow!(carl)
|
50
|
-
camilo.follow!(carl)
|
51
|
-
|
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)
|
58
|
-
|
59
|
-
assert_raise Socialization::ArgumentError do
|
60
|
-
john.like!(travolta) # Can't like a Celeb
|
61
|
-
end
|
62
|
-
|
63
|
-
assert_raise Socialization::ArgumentError do
|
64
|
-
john.follow!(kill_bill) # Can't follow a movie
|
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)
|
78
|
-
end
|
79
|
-
|
80
|
-
def seed
|
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'
|
100
|
-
end
|
101
|
-
|
102
|
-
def method_missing(meth, *args, &block)
|
103
|
-
sym = meth.to_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
|
109
|
-
super
|
110
|
-
end
|
111
|
-
|
112
|
-
end
|