twrk-socialization 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +13 -0
- data/.ruby-version +1 -0
- data/.travis.yml +8 -0
- data/Appraisals +23 -0
- data/CHANGELOG.md +67 -0
- data/Gemfile +3 -0
- data/Guardfile +12 -0
- data/LICENSE +20 -0
- data/README.md +298 -0
- data/Rakefile +14 -0
- data/demo/.gitignore +15 -0
- data/demo/Gemfile +35 -0
- data/demo/README.rdoc +261 -0
- data/demo/Rakefile +7 -0
- data/demo/app/assets/images/rails.png +0 -0
- data/demo/app/assets/javascripts/application.js +15 -0
- data/demo/app/assets/stylesheets/application.css +13 -0
- data/demo/app/controllers/application_controller.rb +3 -0
- data/demo/app/helpers/application_helper.rb +2 -0
- data/demo/app/mailers/.gitkeep +0 -0
- data/demo/app/models/.gitkeep +0 -0
- data/demo/app/models/celebrity.rb +4 -0
- data/demo/app/models/comment.rb +5 -0
- data/demo/app/models/follow.rb +3 -0
- data/demo/app/models/like.rb +2 -0
- data/demo/app/models/mention.rb +2 -0
- data/demo/app/models/movie.rb +3 -0
- data/demo/app/models/user.rb +7 -0
- data/demo/app/views/layouts/application.html.erb +14 -0
- data/demo/config/application.rb +59 -0
- data/demo/config/boot.rb +6 -0
- data/demo/config/database.yml +25 -0
- data/demo/config/environment.rb +5 -0
- data/demo/config/environments/development.rb +37 -0
- data/demo/config/environments/production.rb +67 -0
- data/demo/config/environments/test.rb +37 -0
- data/demo/config/initializers/backtrace_silencers.rb +7 -0
- data/demo/config/initializers/inflections.rb +15 -0
- data/demo/config/initializers/mime_types.rb +5 -0
- data/demo/config/initializers/secret_token.rb +7 -0
- data/demo/config/initializers/session_store.rb +8 -0
- data/demo/config/initializers/wrap_parameters.rb +14 -0
- data/demo/config/locales/en.yml +5 -0
- data/demo/config/routes.rb +58 -0
- data/demo/config.ru +4 -0
- data/demo/db/migrate/20120115051222_create_users.rb +9 -0
- data/demo/db/migrate/20120115051234_create_movies.rb +9 -0
- data/demo/db/migrate/20120115051255_create_celebrities.rb +9 -0
- data/demo/db/migrate/20120115054646_create_follows.rb +14 -0
- data/demo/db/migrate/20120115054647_create_likes.rb +14 -0
- data/demo/db/migrate/20120221200644_create_mentions.rb +14 -0
- data/demo/db/migrate/20120221202703_create_comments.rb +9 -0
- data/demo/db/schema.rb +72 -0
- data/demo/db/seeds.rb +17 -0
- data/demo/lib/assets/.gitkeep +0 -0
- data/demo/lib/tasks/.gitkeep +0 -0
- data/demo/public/404.html +26 -0
- data/demo/public/422.html +26 -0
- data/demo/public/500.html +25 -0
- data/demo/public/favicon.ico +0 -0
- data/demo/public/index.html +204 -0
- data/demo/public/robots.txt +5 -0
- data/demo/script/rails +6 -0
- data/demo/test/fixtures/.gitkeep +0 -0
- data/demo/test/fixtures/celebrities.yml +7 -0
- data/demo/test/fixtures/movies.yml +7 -0
- data/demo/test/fixtures/users.yml +7 -0
- data/demo/test/functional/.gitkeep +0 -0
- data/demo/test/integration/.gitkeep +0 -0
- data/demo/test/performance/browsing_test.rb +12 -0
- data/demo/test/test_helper.rb +13 -0
- data/demo/test/unit/.gitkeep +0 -0
- data/demo/test/unit/celebrity_test.rb +7 -0
- data/demo/test/unit/movie_test.rb +7 -0
- data/demo/test/unit/user_test.rb +7 -0
- data/demo/vendor/assets/javascripts/.gitkeep +0 -0
- data/demo/vendor/assets/stylesheets/.gitkeep +0 -0
- data/demo/vendor/plugins/.gitkeep +0 -0
- data/init.rb +1 -0
- data/lib/generators/socialization/socialization_generator.rb +38 -0
- data/lib/generators/socialization/templates/active_record/migration_follows.rb +14 -0
- data/lib/generators/socialization/templates/active_record/migration_likes.rb +14 -0
- data/lib/generators/socialization/templates/active_record/migration_mentions.rb +14 -0
- data/lib/generators/socialization/templates/active_record/model_follow.rb +2 -0
- data/lib/generators/socialization/templates/active_record/model_like.rb +2 -0
- data/lib/generators/socialization/templates/active_record/model_mention.rb +2 -0
- data/lib/generators/socialization/templates/redis/model_follow.rb +2 -0
- data/lib/generators/socialization/templates/redis/model_like.rb +2 -0
- data/lib/generators/socialization/templates/redis/model_mention.rb +2 -0
- data/lib/socialization/actors/follower.rb +88 -0
- data/lib/socialization/actors/liker.rb +88 -0
- data/lib/socialization/actors/mentioner.rb +88 -0
- data/lib/socialization/config/config.rb +39 -0
- data/lib/socialization/helpers/acts_as_helpers.rb +39 -0
- data/lib/socialization/helpers/string.rb +17 -0
- data/lib/socialization/lib/exceptions.rb +3 -0
- data/lib/socialization/stores/active_record/follow.rb +125 -0
- data/lib/socialization/stores/active_record/like.rb +121 -0
- data/lib/socialization/stores/active_record/mention.rb +125 -0
- data/lib/socialization/stores/active_record/mixins/base.rb +12 -0
- data/lib/socialization/stores/mixins/base.rb +22 -0
- data/lib/socialization/stores/mixins/follow.rb +39 -0
- data/lib/socialization/stores/mixins/like.rb +40 -0
- data/lib/socialization/stores/mixins/mention.rb +40 -0
- data/lib/socialization/stores/redis/base.rb +125 -0
- data/lib/socialization/stores/redis/config.rb +11 -0
- data/lib/socialization/stores/redis/follow.rb +22 -0
- data/lib/socialization/stores/redis/like.rb +22 -0
- data/lib/socialization/stores/redis/mention.rb +22 -0
- data/lib/socialization/stores/redis/mixins/base.rb +8 -0
- data/lib/socialization/version.rb +3 -0
- data/lib/socialization/victims/followable.rb +50 -0
- data/lib/socialization/victims/likeable.rb +51 -0
- data/lib/socialization/victims/mentionable.rb +51 -0
- data/lib/socialization.rb +20 -0
- data/socialization.gemspec +32 -0
- 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/spec/spec_support/data_stores.rb +232 -0
- 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 +322 -0
@@ -0,0 +1,148 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Socialization::ActiveRecordStores::Mention do
|
4
|
+
before do
|
5
|
+
@klass = Socialization::ActiveRecordStores::Mention
|
6
|
+
@klass.touch nil
|
7
|
+
@klass.after_mention nil
|
8
|
+
@klass.after_unmention nil
|
9
|
+
@mentioner = ImAMentioner.create
|
10
|
+
@mentionable = ImAMentionable.create
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "data store" do
|
14
|
+
it "inherits Socialization::ActiveRecordStores::Mention" do
|
15
|
+
expect(Socialization.mention_model).to eq Socialization::ActiveRecordStores::Mention
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "#mention!" do
|
20
|
+
it "creates a Mention record" do
|
21
|
+
@klass.mention!(@mentioner, @mentionable)
|
22
|
+
expect(@mentioner).to match_mentioner(@klass.last)
|
23
|
+
expect(@mentionable).to match_mentionable(@klass.last)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "increments counter caches" do
|
27
|
+
mentioner = ImAMentionerWithCounterCache.create
|
28
|
+
mentionable = ImAMentionableWithCounterCache.create
|
29
|
+
@klass.mention!(mentioner, mentionable)
|
30
|
+
expect(mentioner.reload.mentionees_count).to eq 1
|
31
|
+
expect(mentionable.reload.mentioners_count).to eq 1
|
32
|
+
end
|
33
|
+
|
34
|
+
it "touchs mentioner when instructed" do
|
35
|
+
@klass.touch :mentioner
|
36
|
+
expect(@mentioner).to receive(:touch).once
|
37
|
+
expect(@mentionable).to receive(:touch).never
|
38
|
+
@klass.mention!(@mentioner, @mentionable)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "touchs mentionable when instructed" do
|
42
|
+
@klass.touch :mentionable
|
43
|
+
expect(@mentioner).to receive(:touch).never
|
44
|
+
expect(@mentionable).to receive(:touch).once
|
45
|
+
@klass.mention!(@mentioner, @mentionable)
|
46
|
+
end
|
47
|
+
|
48
|
+
it "touchs all when instructed" do
|
49
|
+
@klass.touch :all
|
50
|
+
expect(@mentioner).to receive(:touch).once
|
51
|
+
expect(@mentionable).to receive(:touch).once
|
52
|
+
@klass.mention!(@mentioner, @mentionable)
|
53
|
+
end
|
54
|
+
|
55
|
+
it "calls after mention hook" do
|
56
|
+
@klass.after_mention :after_mention
|
57
|
+
expect(@klass).to receive(:after_mention).once
|
58
|
+
@klass.mention!(@mentioner, @mentionable)
|
59
|
+
end
|
60
|
+
|
61
|
+
it "calls after unmention hook" do
|
62
|
+
@klass.after_mention :after_unmention
|
63
|
+
expect(@klass).to receive(:after_unmention).once
|
64
|
+
@klass.mention!(@mentioner, @mentionable)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe "#unmention!" do
|
69
|
+
it "decrements counter caches" do
|
70
|
+
mentioner = ImAMentionerWithCounterCache.create
|
71
|
+
mentionable = ImAMentionableWithCounterCache.create
|
72
|
+
@klass.mention!(mentioner, mentionable)
|
73
|
+
@klass.unmention!(mentioner, mentionable)
|
74
|
+
expect(mentioner.reload.mentionees_count).to eq 0
|
75
|
+
expect(mentionable.reload.mentioners_count).to eq 0
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
|
80
|
+
describe "#mentions?" do
|
81
|
+
it "returns true when mention exists" do
|
82
|
+
@klass.create! do |f|
|
83
|
+
f.mentioner = @mentioner
|
84
|
+
f.mentionable = @mentionable
|
85
|
+
end
|
86
|
+
expect(@klass.mentions?(@mentioner, @mentionable)).to be true
|
87
|
+
end
|
88
|
+
|
89
|
+
it "returns false when mention doesn't exist" do
|
90
|
+
expect(@klass.mentions?(@mentioner, @mentionable)).to be false
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
describe "#mentioners" do
|
95
|
+
it "returns an array of mentioners" do
|
96
|
+
mentioner1 = ImAMentioner.create
|
97
|
+
mentioner2 = ImAMentioner.create
|
98
|
+
mentioner1.mention!(@mentionable)
|
99
|
+
mentioner2.mention!(@mentionable)
|
100
|
+
expect(@klass.mentioners(@mentionable, mentioner1.class)).to eq [mentioner1, mentioner2]
|
101
|
+
end
|
102
|
+
|
103
|
+
it "returns an array of mentioner ids when plucking" do
|
104
|
+
mentioner1 = ImAMentioner.create
|
105
|
+
mentioner2 = ImAMentioner.create
|
106
|
+
mentioner1.mention!(@mentionable)
|
107
|
+
mentioner2.mention!(@mentionable)
|
108
|
+
expect(@klass.mentioners(@mentionable, mentioner1.class, :pluck => :id)).to eq [mentioner1.id, mentioner2.id]
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
describe "#mentionables" do
|
113
|
+
it "returns an array of mentioners" do
|
114
|
+
mentionable1 = ImAMentionable.create
|
115
|
+
mentionable2 = ImAMentionable.create
|
116
|
+
@mentioner.mention!(mentionable1)
|
117
|
+
@mentioner.mention!(mentionable2)
|
118
|
+
expect(@klass.mentionables(@mentioner, mentionable1.class)).to eq [mentionable1, mentionable2]
|
119
|
+
end
|
120
|
+
|
121
|
+
it "returns an array of mentioner ids when plucking" do
|
122
|
+
mentionable1 = ImAMentionable.create
|
123
|
+
mentionable2 = ImAMentionable.create
|
124
|
+
@mentioner.mention!(mentionable1)
|
125
|
+
@mentioner.mention!(mentionable2)
|
126
|
+
expect(@klass.mentionables(@mentioner, mentionable1.class, :pluck => :id)).to eq [mentionable1.id, mentionable2.id]
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
describe "#remove_mentioners" do
|
131
|
+
it "deletes all mentioners relationships for a mentionable" do
|
132
|
+
@mentioner.mention!(@mentionable)
|
133
|
+
expect(@mentionable.mentioners(@mentioner.class).count).to eq 1
|
134
|
+
@klass.remove_mentioners(@mentionable)
|
135
|
+
expect(@mentionable.mentioners(@mentioner.class).count).to eq 0
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
describe "#remove_mentionables" do
|
140
|
+
it "deletes all mentionables relationships for a mentioner" do
|
141
|
+
@mentioner.mention!(@mentionable)
|
142
|
+
expect(@mentioner.mentionables(@mentionable.class).count).to eq 1
|
143
|
+
@klass.remove_mentionables(@mentioner)
|
144
|
+
expect(@mentioner.mentionables(@mentionable.class).count).to eq 0
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Socialization::ActiveRecordStores::Mixins::Base do
|
4
|
+
describe ".update_counter" do
|
5
|
+
it "increments counter cache if column exists" do
|
6
|
+
followable = ImAFollowableWithCounterCache.create
|
7
|
+
|
8
|
+
update_counter(followable, followers_count: +1)
|
9
|
+
|
10
|
+
expect(followable.reload.followers_count).to eq(1)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "does not raise any errors if column doesn't exist" do
|
14
|
+
followable = ImAFollowable.create
|
15
|
+
update_counter(followable, followers_count: +1)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def update_counter(model, counter)
|
20
|
+
klass = Object.new
|
21
|
+
klass.extend(Socialization::ActiveRecordStores::Mixins::Base)
|
22
|
+
klass.update_counter(model, counter)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
@@ -0,0 +1,195 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Socialization::RedisStores::Base do
|
4
|
+
# Testing through RedisStores::Follow for easy testing
|
5
|
+
before(:each) do
|
6
|
+
use_redis_store
|
7
|
+
@klass = Socialization::RedisStores::Follow
|
8
|
+
@klass.touch nil
|
9
|
+
@klass.after_follow nil
|
10
|
+
@klass.after_unfollow nil
|
11
|
+
@follower1 = ImAFollower.create
|
12
|
+
@follower2 = ImAFollower.create
|
13
|
+
@followable1 = ImAFollowable.create
|
14
|
+
@followable2 = ImAFollowable.create
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "RedisStores::Base through RedisStores::Follow" do
|
18
|
+
describe "Stores" do
|
19
|
+
it "inherits Socialization::RedisStores::Follow" do
|
20
|
+
expect(Socialization.follow_model).to eq(Socialization::RedisStores::Follow)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "#follow!" do
|
25
|
+
it "creates follow records" do
|
26
|
+
@klass.follow!(@follower1, @followable1)
|
27
|
+
expect(Socialization.redis.smembers(forward_key(@followable1))).to match_array ["#{@follower1.class}:#{@follower1.id}"]
|
28
|
+
expect(Socialization.redis.smembers(backward_key(@follower1))).to match_array ["#{@followable1.class}:#{@followable1.id}"]
|
29
|
+
|
30
|
+
@klass.follow!(@follower2, @followable1)
|
31
|
+
expect(Socialization.redis.smembers(forward_key(@followable1))).to match_array ["#{@follower1.class}:#{@follower1.id}", "#{@follower2.class}:#{@follower2.id}"]
|
32
|
+
expect(Socialization.redis.smembers(backward_key(@follower1))).to match_array ["#{@followable1.class}:#{@followable1.id}"]
|
33
|
+
expect(Socialization.redis.smembers(backward_key(@follower2))).to match_array ["#{@followable1.class}:#{@followable1.id}"]
|
34
|
+
end
|
35
|
+
|
36
|
+
it "touches follower when instructed" do
|
37
|
+
@klass.touch :follower
|
38
|
+
expect(@follower1).to receive(:touch).once
|
39
|
+
expect(@followable1).to receive(:touch).never
|
40
|
+
@klass.follow!(@follower1, @followable1)
|
41
|
+
end
|
42
|
+
|
43
|
+
it "touches followable when instructed" do
|
44
|
+
@klass.touch :followable
|
45
|
+
expect(@follower1).to receive(:touch).never
|
46
|
+
expect(@followable1).to receive(:touch).once
|
47
|
+
@klass.follow!(@follower1, @followable1)
|
48
|
+
end
|
49
|
+
|
50
|
+
it "touches all when instructed" do
|
51
|
+
@klass.touch :all
|
52
|
+
expect(@follower1).to receive(:touch).once
|
53
|
+
expect(@followable1).to receive(:touch).once
|
54
|
+
@klass.follow!(@follower1, @followable1)
|
55
|
+
end
|
56
|
+
|
57
|
+
it "calls after follow hook" do
|
58
|
+
@klass.after_follow :after_follow
|
59
|
+
expect(@klass).to receive(:after_follow).once
|
60
|
+
@klass.follow!(@follower1, @followable1)
|
61
|
+
end
|
62
|
+
|
63
|
+
it "calls after unfollow hook" do
|
64
|
+
@klass.after_follow :after_unfollow
|
65
|
+
expect(@klass).to receive(:after_unfollow).once
|
66
|
+
@klass.follow!(@follower1, @followable1)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe "#unfollow!" do
|
71
|
+
before(:each) do
|
72
|
+
@klass.follow!(@follower1, @followable1)
|
73
|
+
end
|
74
|
+
|
75
|
+
it "removes follow records" do
|
76
|
+
@klass.unfollow!(@follower1, @followable1)
|
77
|
+
expect(Socialization.redis.smembers(forward_key(@followable1))).to be_empty
|
78
|
+
expect(Socialization.redis.smembers(backward_key(@follower1))).to be_empty
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe "#follows?" do
|
83
|
+
it "returns true when follow exists" do
|
84
|
+
@klass.follow!(@follower1, @followable1)
|
85
|
+
expect(@klass.follows?(@follower1, @followable1)).to be true
|
86
|
+
end
|
87
|
+
|
88
|
+
it "returns false when follow doesn't exist" do
|
89
|
+
expect(@klass.follows?(@follower1, @followable1)).to be false
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
describe "#followers" do
|
94
|
+
it "returns an array of followers" do
|
95
|
+
follower1 = ImAFollower.create
|
96
|
+
follower2 = ImAFollower.create
|
97
|
+
follower1.follow!(@followable1)
|
98
|
+
follower2.follow!(@followable1)
|
99
|
+
expect(@klass.followers(@followable1, follower1.class)).to match_array [follower1, follower2]
|
100
|
+
end
|
101
|
+
|
102
|
+
it "returns 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
|
+
expect(@klass.followers(@followable1, follower1.class, :pluck => :id)).to match_array ["#{follower1.id}", "#{follower2.id}"]
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
describe "#followables" do
|
112
|
+
it "returns an array of followables" do
|
113
|
+
followable1 = ImAFollowable.create
|
114
|
+
followable2 = ImAFollowable.create
|
115
|
+
@follower1.follow!(followable1)
|
116
|
+
@follower1.follow!(followable2)
|
117
|
+
|
118
|
+
expect(@klass.followables(@follower1, followable1.class)).to match_array [followable1, followable2]
|
119
|
+
end
|
120
|
+
|
121
|
+
it "returns 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
|
+
expect(@klass.followables(@follower1, followable1.class, :pluck => :id)).to match_array ["#{followable1.id}", "#{followable2.id}"]
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
describe "#generate_forward_key" do
|
131
|
+
it "returns valid key when passed an object" do
|
132
|
+
expect(forward_key(@followable1)).to eq("Followers:#{@followable1.class.name}:#{@followable1.id}")
|
133
|
+
end
|
134
|
+
|
135
|
+
it "returns valid key when passed a String" do
|
136
|
+
expect(forward_key("Followable:1")).to eq("Followers:Followable:1")
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
describe "#generate_backward_key" do
|
141
|
+
it "returns valid key when passed an object" do
|
142
|
+
expect(backward_key(@follower1)).to eq("Followables:#{@follower1.class.name}:#{@follower1.id}")
|
143
|
+
end
|
144
|
+
|
145
|
+
it "returns valid key when passed a String" do
|
146
|
+
expect(backward_key("Follower:1")).to eq("Followables:Follower:1")
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
describe "#remove_followers" do
|
151
|
+
it "deletes all followers relationships for a followable" do
|
152
|
+
@follower1.follow!(@followable1)
|
153
|
+
@follower2.follow!(@followable1)
|
154
|
+
expect(@followable1.followers(@follower1.class).count).to eq(2)
|
155
|
+
|
156
|
+
@klass.remove_followers(@followable1)
|
157
|
+
expect(@followable1.followers(@follower1.class).count).to eq(0)
|
158
|
+
expect(Socialization.redis.smembers(forward_key(@followable1))).to be_empty
|
159
|
+
expect(Socialization.redis.smembers(backward_key(@follower1))).to be_empty
|
160
|
+
expect(Socialization.redis.smembers(backward_key(@follower2))).to be_empty
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
describe "#remove_followables" do
|
165
|
+
it "deletes all followables relationships for a follower" do
|
166
|
+
@follower1.follow!(@followable1)
|
167
|
+
@follower1.follow!(@followable2)
|
168
|
+
expect(@follower1.followables(@followable1.class).count).to eq(2)
|
169
|
+
|
170
|
+
@klass.remove_followables(@follower1)
|
171
|
+
expect(@follower1.followables(@followable1.class).count).to eq(0)
|
172
|
+
expect(Socialization.redis.smembers backward_key(@followable1)).to be_empty
|
173
|
+
expect(Socialization.redis.smembers backward_key(@follower2)).to be_empty
|
174
|
+
expect(Socialization.redis.smembers forward_key(@follower1)).to be_empty
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
describe "#key_type_to_type_names" do
|
179
|
+
it "returns the proper arrays" do
|
180
|
+
expect(@klass.send(:key_type_to_type_names, Socialization::RedisStores::Follow)).to eq(['follower', 'followable'])
|
181
|
+
expect(@klass.send(:key_type_to_type_names, Socialization::RedisStores::Mention)).to eq(['mentioner', 'mentionable'])
|
182
|
+
expect(@klass.send(:key_type_to_type_names, Socialization::RedisStores::Like)).to eq(['liker', 'likeable'])
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
# Helpers
|
188
|
+
def forward_key(followable)
|
189
|
+
Socialization::RedisStores::Follow.send(:generate_forward_key, followable)
|
190
|
+
end
|
191
|
+
|
192
|
+
def backward_key(follower)
|
193
|
+
Socialization::RedisStores::Follow.send(:generate_backward_key, follower)
|
194
|
+
end
|
195
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
context "RedisStoreConfigTest" do
|
4
|
+
before do
|
5
|
+
Socialization.instance_eval { @redis = nil }
|
6
|
+
end
|
7
|
+
|
8
|
+
it "returns a new Redis object when none were specified" do
|
9
|
+
expect(Socialization.redis).to be_a Redis
|
10
|
+
end
|
11
|
+
|
12
|
+
it "always returns the same Redis object when none were specified" do
|
13
|
+
redis = Socialization.redis
|
14
|
+
expect(Socialization.redis).to eq(redis)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "is able to set and get a redis instance" do
|
18
|
+
redis = Redis.new
|
19
|
+
Socialization.redis = redis
|
20
|
+
expect(Socialization.redis).to eq(redis)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "always return the same Redis object when it was specified" do
|
24
|
+
redis = Redis.new
|
25
|
+
Socialization.redis = redis
|
26
|
+
expect(Socialization.redis).to eq(redis)
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Socialization::RedisStores::Follow do
|
4
|
+
before do
|
5
|
+
use_redis_store
|
6
|
+
@klass = Socialization::RedisStores::Follow
|
7
|
+
@base = Socialization::RedisStores::Base
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "method aliases" do
|
11
|
+
it "should be set properly and made public" do
|
12
|
+
# TODO: Can't figure out how to test method aliases properly. The following doesn't work:
|
13
|
+
# assert @klass.method(:follow!) == @base.method(:relation!)
|
14
|
+
expect(:follow!).to be_a_public_method_of(@klass)
|
15
|
+
expect(:unfollow!).to be_a_public_method_of(@klass)
|
16
|
+
expect(:follows?).to be_a_public_method_of(@klass)
|
17
|
+
expect(:followers_relation).to be_a_public_method_of(@klass)
|
18
|
+
expect(:followers).to be_a_public_method_of(@klass)
|
19
|
+
expect(:followables_relation).to be_a_public_method_of(@klass)
|
20
|
+
expect(:followables).to be_a_public_method_of(@klass)
|
21
|
+
expect(:remove_followers).to be_a_public_method_of(@klass)
|
22
|
+
expect(:remove_followables).to be_a_public_method_of(@klass)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Socialization::RedisStores::Like do
|
4
|
+
before do
|
5
|
+
use_redis_store
|
6
|
+
@klass = Socialization::RedisStores::Like
|
7
|
+
@base = Socialization::RedisStores::Base
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "method aliases" do
|
11
|
+
it "should be set properly and made public" do
|
12
|
+
expect(:like!).to be_a_public_method_of(@klass)
|
13
|
+
expect(:unlike!).to be_a_public_method_of(@klass)
|
14
|
+
expect(:likes?).to be_a_public_method_of(@klass)
|
15
|
+
expect(:likers_relation).to be_a_public_method_of(@klass)
|
16
|
+
expect(:likers).to be_a_public_method_of(@klass)
|
17
|
+
expect(:likeables_relation).to be_a_public_method_of(@klass)
|
18
|
+
expect(:likeables).to be_a_public_method_of(@klass)
|
19
|
+
expect(:remove_likers).to be_a_public_method_of(@klass)
|
20
|
+
expect(:remove_likeables).to be_a_public_method_of(@klass)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Socialization::RedisStores::Follow do
|
4
|
+
before do
|
5
|
+
use_redis_store
|
6
|
+
@klass = Socialization::RedisStores::Mention
|
7
|
+
@base = Socialization::RedisStores::Base
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "method aliases" do
|
11
|
+
it "should be set properly and made public" do
|
12
|
+
expect(:mention!).to be_a_public_method_of(@klass)
|
13
|
+
expect(:unmention!).to be_a_public_method_of(@klass)
|
14
|
+
expect(:mentions?).to be_a_public_method_of(@klass)
|
15
|
+
expect(:mentioners_relation).to be_a_public_method_of(@klass)
|
16
|
+
expect(:mentioners).to be_a_public_method_of(@klass)
|
17
|
+
expect(:mentionables_relation).to be_a_public_method_of(@klass)
|
18
|
+
expect(:mentionables).to be_a_public_method_of(@klass)
|
19
|
+
expect(:remove_mentioners).to be_a_public_method_of(@klass)
|
20
|
+
expect(:remove_mentionables).to be_a_public_method_of(@klass)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/spec/string_spec.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe String do
|
4
|
+
describe "#deep_const_get" do
|
5
|
+
it "should return a class" do
|
6
|
+
expect("Socialization".deep_const_get).to eq(Socialization)
|
7
|
+
expect("Socialization::ActiveRecordStores".deep_const_get).to eq(Socialization::ActiveRecordStores)
|
8
|
+
expect("Socialization::ActiveRecordStores::Follow".deep_const_get).to eq(Socialization::ActiveRecordStores::Follow)
|
9
|
+
|
10
|
+
expect { "Foo::Bar".deep_const_get }.to raise_error(NameError)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Socialization::Followable do
|
4
|
+
before(:all) do
|
5
|
+
use_ar_store
|
6
|
+
@follower = ImAFollower.new
|
7
|
+
@followable = ImAFollowable.create
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "#is_followable?" do
|
11
|
+
it "returns true" do
|
12
|
+
expect(@followable.is_followable?).to be true
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "#followable?" do
|
17
|
+
it "returns true" do
|
18
|
+
expect(@followable.followable?).to be true
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "#followed_by?" do
|
23
|
+
it "does not accept non-followers" do
|
24
|
+
expect { @followable.followed_by?(:foo) }.to raise_error(Socialization::ArgumentError)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "calls $Follow.follows?" do
|
28
|
+
expect($Follow).to receive(:follows?).with(@follower, @followable).once
|
29
|
+
@followable.followed_by?(@follower)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "#followers" do
|
34
|
+
it "calls $Follow.followers" do
|
35
|
+
expect($Follow).to receive(:followers).with(@followable, @follower.class, { :foo => :bar })
|
36
|
+
@followable.followers(@follower.class, { :foo => :bar })
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "#followers_relation" do
|
41
|
+
it "calls $Follow.followers_relation" do
|
42
|
+
expect($Follow).to receive(:followers_relation).with(@followable, @follower.class, { :foo => :bar })
|
43
|
+
@followable.followers_relation(@follower.class, { :foo => :bar })
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "deleting a followable" do
|
48
|
+
before(:all) do
|
49
|
+
@follower = ImAFollower.create
|
50
|
+
@follower.follow!(@followable)
|
51
|
+
end
|
52
|
+
|
53
|
+
it "removes follow relationships" do
|
54
|
+
expect(Socialization.follow_model).to receive(:remove_followers).with(@followable)
|
55
|
+
@followable.destroy
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Socialization::Likeable do
|
4
|
+
before(:all) do
|
5
|
+
use_ar_store
|
6
|
+
@liker = ImALiker.new
|
7
|
+
@likeable = ImALikeable.create
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "#is_likeable?" do
|
11
|
+
it "returns true" do
|
12
|
+
expect(@likeable.is_likeable?).to be true
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "#likeable?" do
|
17
|
+
it "returns true" do
|
18
|
+
expect(@likeable.likeable?).to be true
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "#liked_by?" do
|
23
|
+
it "does not accept non-likers" do
|
24
|
+
expect { @likeable.liked_by?(:foo) }.to raise_error(Socialization::ArgumentError)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "calls $Like.likes?" do
|
28
|
+
expect($Like).to receive(:likes?).with(@liker, @likeable).once
|
29
|
+
@likeable.liked_by?(@liker)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "#likers" do
|
34
|
+
it "calls $Like.likers" do
|
35
|
+
expect($Like).to receive(:likers).with(@likeable, @liker.class, { :foo => :bar })
|
36
|
+
@likeable.likers(@liker.class, { :foo => :bar })
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "#likers_relation" do
|
41
|
+
it "calls $Like.likers_relation" do
|
42
|
+
expect($Like).to receive(:likers_relation).with(@likeable, @liker.class, { :foo => :bar })
|
43
|
+
@likeable.likers_relation(@liker.class, { :foo => :bar })
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "deleting a likeable" do
|
48
|
+
before(:all) do
|
49
|
+
@liker = ImALiker.create
|
50
|
+
@liker.like!(@likeable)
|
51
|
+
end
|
52
|
+
|
53
|
+
it "removes like relationships" do
|
54
|
+
expect(Socialization.like_model).to receive(:remove_likers).with(@likeable)
|
55
|
+
@likeable.destroy
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Socialization::Mentionable do
|
4
|
+
before(:all) do
|
5
|
+
use_ar_store
|
6
|
+
@mentioner = ImAMentioner.new
|
7
|
+
@mentionable = ImAMentionable.create
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "#is_mentionable?" do
|
11
|
+
it "returns true" do
|
12
|
+
expect(@mentionable.is_mentionable?).to be true
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "#mentionable?" do
|
17
|
+
it "returns true" do
|
18
|
+
expect(@mentionable.mentionable?).to be true
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "#mentioned_by?" do
|
23
|
+
it "does not accept non-mentioners" do
|
24
|
+
expect { @mentionable.mentioned_by?(:foo) }.to raise_error(Socialization::ArgumentError)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "calls $Mention.mentions?" do
|
28
|
+
expect($Mention).to receive(:mentions?).with(@mentioner, @mentionable).once
|
29
|
+
@mentionable.mentioned_by?(@mentioner)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "#mentioners" do
|
34
|
+
it "calls $Mention.mentioners" do
|
35
|
+
expect($Mention).to receive(:mentioners).with(@mentionable, @mentioner.class, { :foo => :bar })
|
36
|
+
@mentionable.mentioners(@mentioner.class, { :foo => :bar })
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "#mentioners_relation" do
|
41
|
+
it "calls $Mention.mentioners" do
|
42
|
+
expect($Mention).to receive(:mentioners_relation).with(@mentionable, @mentioner.class, { :foo => :bar })
|
43
|
+
@mentionable.mentioners_relation(@mentioner.class, { :foo => :bar })
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "deleting a mentionable" do
|
48
|
+
before(:all) do
|
49
|
+
@mentioner = ImAMentioner.create
|
50
|
+
@mentioner.mention!(@mentionable)
|
51
|
+
end
|
52
|
+
|
53
|
+
it "removes mention relationships" do
|
54
|
+
expect(Socialization.mention_model).to receive(:remove_mentioners).with(@mentionable)
|
55
|
+
@mentionable.destroy
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|