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,51 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
class Base
|
3
|
+
def is_likeable?
|
4
|
+
false
|
5
|
+
end
|
6
|
+
alias likeable? is_likeable?
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
module Socialization
|
11
|
+
module Likeable
|
12
|
+
extend ActiveSupport::Concern
|
13
|
+
|
14
|
+
included do
|
15
|
+
after_destroy { Socialization.like_model.remove_likers(self) }
|
16
|
+
|
17
|
+
# Specifies if self can be liked.
|
18
|
+
#
|
19
|
+
# @return [Boolean]
|
20
|
+
def is_likeable?
|
21
|
+
true
|
22
|
+
end
|
23
|
+
alias likeable? is_likeable?
|
24
|
+
|
25
|
+
# Specifies if self is liked by a {Liker} object.
|
26
|
+
#
|
27
|
+
# @return [Boolean]
|
28
|
+
def liked_by?(liker)
|
29
|
+
raise Socialization::ArgumentError, "#{liker} is not liker!" unless liker.respond_to?(:is_liker?) && liker.is_liker?
|
30
|
+
Socialization.like_model.likes?(liker, self)
|
31
|
+
end
|
32
|
+
|
33
|
+
# Returns an array of {Liker}s liking self.
|
34
|
+
#
|
35
|
+
# @param [Class] klass the {Liker} class to be included. e.g. `User`
|
36
|
+
# @return [Array<Liker, Numeric>] An array of Liker objects or IDs
|
37
|
+
def likers(klass, opts = {})
|
38
|
+
Socialization.like_model.likers(self, klass, opts)
|
39
|
+
end
|
40
|
+
|
41
|
+
# Returns a scope of the {Liker}s liking self.
|
42
|
+
#
|
43
|
+
# @param [Class] klass the {Liker} class to be included in the scope. e.g. `User`
|
44
|
+
# @return ActiveRecord::Relation
|
45
|
+
def likers_relation(klass, opts = {})
|
46
|
+
Socialization.like_model.likers_relation(self, klass, opts)
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
class Base
|
3
|
+
def is_mentionable?
|
4
|
+
false
|
5
|
+
end
|
6
|
+
alias mentionable? is_mentionable?
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
module Socialization
|
11
|
+
module Mentionable
|
12
|
+
extend ActiveSupport::Concern
|
13
|
+
|
14
|
+
included do
|
15
|
+
after_destroy { Socialization.mention_model.remove_mentioners(self) }
|
16
|
+
|
17
|
+
# Specifies if self can be mentioned.
|
18
|
+
#
|
19
|
+
# @return [Boolean]
|
20
|
+
def is_mentionable?
|
21
|
+
true
|
22
|
+
end
|
23
|
+
alias mentionable? is_mentionable?
|
24
|
+
|
25
|
+
# Specifies if self is mentioned by a {Mentioner} object.
|
26
|
+
#
|
27
|
+
# @return [Boolean]
|
28
|
+
def mentioned_by?(mentioner)
|
29
|
+
raise Socialization::ArgumentError, "#{mentioner} is not mentioner!" unless mentioner.respond_to?(:is_mentioner?) && mentioner.is_mentioner?
|
30
|
+
Socialization.mention_model.mentions?(mentioner, self)
|
31
|
+
end
|
32
|
+
|
33
|
+
# Returns an array of {Mentioner}s mentioning self.
|
34
|
+
#
|
35
|
+
# @param [Class] klass the {Mentioner} class to be included. e.g. `User`
|
36
|
+
# @return [Array<Mentioner, Numeric>] An array of Mentioner objects or IDs
|
37
|
+
def mentioners(klass, opts = {})
|
38
|
+
Socialization.mention_model.mentioners(self, klass, opts)
|
39
|
+
end
|
40
|
+
|
41
|
+
# Returns a scope of the {Mentioner}s mentioning self.
|
42
|
+
#
|
43
|
+
# @param [Class] klass the {Mentioner} class to be included in the scope. e.g. `User`
|
44
|
+
# @return ActiveRecord::Relation
|
45
|
+
def mentioners_relation(klass, opts = {})
|
46
|
+
Socialization.mention_model.mentioners_relation(self, klass, opts)
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
%w(
|
2
|
+
lib/*.rb
|
3
|
+
stores/mixins/base.rb
|
4
|
+
stores/mixins/**/*.rb
|
5
|
+
stores/active_record/mixins/base.rb
|
6
|
+
stores/active_record/mixins/**/*.rb
|
7
|
+
stores/redis/mixins/base.rb
|
8
|
+
stores/redis/mixins/**/*.rb
|
9
|
+
stores/active_record/**/*.rb
|
10
|
+
stores/redis/base.rb
|
11
|
+
stores/redis/**/*.rb
|
12
|
+
actors/**/*.rb
|
13
|
+
victims/**/*.rb
|
14
|
+
helpers/**/*.rb
|
15
|
+
config/**/*.rb
|
16
|
+
).each do |path|
|
17
|
+
Dir["#{File.dirname(__FILE__)}/socialization/#{path}"].each { |f| require(f) }
|
18
|
+
end
|
19
|
+
|
20
|
+
ActiveRecord::Base.send :include, Socialization::ActsAsHelpers
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "socialization/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "twrk-socialization"
|
7
|
+
s.version = "0.0.1"
|
8
|
+
s.authors = ["twrk"]
|
9
|
+
s.email = "twrkitrealgood@gmail.com"
|
10
|
+
s.homepage = "https://github.com/twrk/socialization"
|
11
|
+
s.summary = "Easily socialize your app with Likes and Follows"
|
12
|
+
s.description = "A modification of the smer/socialization plugin; currently not being maintained by original authorr. Allows any model to Follow and/or Like any other model. This is accomplished through a double polymorphic relationship on the Follow and Like models. But you don't need to know that since all the complexity is hidden from you."
|
13
|
+
|
14
|
+
s.files = `git ls-files`.split("\n")
|
15
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
|
+
s.require_paths = ["lib"]
|
18
|
+
|
19
|
+
s.has_rdoc = false
|
20
|
+
|
21
|
+
s.add_runtime_dependency "activerecord"
|
22
|
+
|
23
|
+
s.add_development_dependency "appraisal"
|
24
|
+
s.add_development_dependency "logger"
|
25
|
+
s.add_development_dependency "rspec", "~> 3.3.0"
|
26
|
+
s.add_development_dependency "rspec-mocks"
|
27
|
+
s.add_development_dependency "sqlite3"
|
28
|
+
s.add_development_dependency "yard"
|
29
|
+
s.add_development_dependency "mock_redis"
|
30
|
+
s.add_development_dependency "guard"
|
31
|
+
s.add_development_dependency "guard-rspec"
|
32
|
+
end
|
@@ -0,0 +1,113 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Socialization::Follower do
|
4
|
+
before(:all) do
|
5
|
+
use_ar_store
|
6
|
+
@follower = ImAFollower.new
|
7
|
+
@followable = ImAFollowable.create
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "#is_follower?" do
|
11
|
+
it "returns true" do
|
12
|
+
expect(@follower.is_follower?).to be true
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "#follower?" do
|
17
|
+
it "returns true" do
|
18
|
+
expect(@follower.follower?).to be true
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "#follow!" do
|
23
|
+
it "does not accept non-followables" do
|
24
|
+
expect { @follower.follow!(:foo) }.to raise_error(Socialization::ArgumentError)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "calls $Follow.follow!" do
|
28
|
+
expect($Follow).to receive(:follow!).with(@follower, @followable).once
|
29
|
+
@follower.follow!(@followable)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "#unfollow!" do
|
34
|
+
it "does not accept non-followables" do
|
35
|
+
expect { @follower.unfollow!(:foo) }.to raise_error(Socialization::ArgumentError)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "calls $Follow.follow!" do
|
39
|
+
expect($Follow).to receive(:unfollow!).with(@follower, @followable).once
|
40
|
+
@follower.unfollow!(@followable)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "#toggle_follow!" do
|
45
|
+
it "does not accept non-followables" do
|
46
|
+
expect { @follower.unfollow!(:foo) }.to raise_error(Socialization::ArgumentError)
|
47
|
+
end
|
48
|
+
|
49
|
+
it "unfollows when following" do
|
50
|
+
expect(@follower).to receive(:follows?).with(@followable).once.and_return(true)
|
51
|
+
expect(@follower).to receive(:unfollow!).with(@followable).once
|
52
|
+
@follower.toggle_follow!(@followable)
|
53
|
+
end
|
54
|
+
|
55
|
+
it "follows when not following" do
|
56
|
+
expect(@follower).to receive(:follows?).with(@followable).once.and_return(false)
|
57
|
+
expect(@follower).to receive(:follow!).with(@followable).once
|
58
|
+
@follower.toggle_follow!(@followable)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe "#follows?" do
|
63
|
+
it "does not accept non-followables" do
|
64
|
+
expect { @follower.unfollow!(:foo) }.to raise_error(Socialization::ArgumentError)
|
65
|
+
end
|
66
|
+
|
67
|
+
it "calls $Follow.follows?" do
|
68
|
+
expect($Follow).to receive(:follows?).with(@follower, @followable).once
|
69
|
+
@follower.follows?(@followable)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe "#followables" do
|
74
|
+
it "calls $Follow.followables" do
|
75
|
+
expect($Follow).to receive(:followables).with(@follower, @followable.class, { :foo => :bar })
|
76
|
+
@follower.followables(@followable.class, { :foo => :bar })
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe "#followees" do
|
81
|
+
it "calls $Follow.followables" do
|
82
|
+
expect($Follow).to receive(:followables).with(@follower, @followable.class, { :foo => :bar })
|
83
|
+
@follower.followees(@followable.class, { :foo => :bar })
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe "#followables_relation" do
|
88
|
+
it "calls $Follow.followables_relation" do
|
89
|
+
expect($Follow).to receive(:followables_relation).with(@follower, @followable.class, { :foo => :bar })
|
90
|
+
@follower.followables_relation(@followable.class, { :foo => :bar })
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
describe "#followees_relation" do
|
95
|
+
it "calls $Follow.followables_relation" do
|
96
|
+
expect($Follow).to receive(:followables_relation).with(@follower, @followable.class, { :foo => :bar })
|
97
|
+
@follower.followees_relation(@followable.class, { :foo => :bar })
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
describe "deleting a follower" do
|
102
|
+
before(:all) do
|
103
|
+
@follower = ImAFollower.create
|
104
|
+
@follower.follow!(@followable)
|
105
|
+
end
|
106
|
+
|
107
|
+
it "removes follow relationships" do
|
108
|
+
expect(Socialization.follow_model).to receive(:remove_followables).with(@follower)
|
109
|
+
@follower.destroy
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Socialization::Liker do
|
4
|
+
before(:all) do
|
5
|
+
use_ar_store
|
6
|
+
@liker = ImALiker.new
|
7
|
+
@likeable = ImALikeable.create
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "#is_liker?" do
|
11
|
+
it "returns true" do
|
12
|
+
expect(@liker.is_liker?).to be true
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "#liker?" do
|
17
|
+
it "returns true" do
|
18
|
+
expect(@liker.liker?).to be true
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "#like!" do
|
23
|
+
it "does not accept non-likeables" do
|
24
|
+
expect { @liker.like!(:foo) }.to raise_error(Socialization::ArgumentError)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "calls $Like.like!" do
|
28
|
+
expect($Like).to receive(:like!).with(@liker, @likeable).once
|
29
|
+
@liker.like!(@likeable)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "#unlike!" do
|
34
|
+
it "does not accept non-likeables" do
|
35
|
+
expect { @liker.unlike!(:foo) }.to raise_error(Socialization::ArgumentError)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "calls $Like.like!" do
|
39
|
+
expect($Like).to receive(:unlike!).with(@liker, @likeable).once
|
40
|
+
@liker.unlike!(@likeable)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "#toggle_like!" do
|
45
|
+
it "does not accept non-likeables" do
|
46
|
+
expect { @liker.unlike!(:foo) }.to raise_error(Socialization::ArgumentError)
|
47
|
+
end
|
48
|
+
|
49
|
+
it "unlikes when likeing" do
|
50
|
+
expect(@liker).to receive(:likes?).with(@likeable).once.and_return(true)
|
51
|
+
expect(@liker).to receive(:unlike!).with(@likeable).once
|
52
|
+
@liker.toggle_like!(@likeable)
|
53
|
+
end
|
54
|
+
|
55
|
+
it "likes when not likeing" do
|
56
|
+
expect(@liker).to receive(:likes?).with(@likeable).once.and_return(false)
|
57
|
+
expect(@liker).to receive(:like!).with(@likeable).once
|
58
|
+
@liker.toggle_like!(@likeable)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe "#likes?" do
|
63
|
+
it "does not accept non-likeables" do
|
64
|
+
expect { @liker.unlike!(:foo) }.to raise_error(Socialization::ArgumentError)
|
65
|
+
end
|
66
|
+
|
67
|
+
it "calls $Like.likes?" do
|
68
|
+
expect($Like).to receive(:likes?).with(@liker, @likeable).once
|
69
|
+
@liker.likes?(@likeable)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe "#likeables" do
|
74
|
+
it "calls $Like.likeables" do
|
75
|
+
expect($Like).to receive(:likeables).with(@liker, @likeable.class, { :foo => :bar })
|
76
|
+
@liker.likeables(@likeable.class, { :foo => :bar })
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe "#likees" do
|
81
|
+
it "calls $Like.likeables" do
|
82
|
+
expect($Like).to receive(:likeables).with(@liker, @likeable.class, { :foo => :bar })
|
83
|
+
@liker.likees(@likeable.class, { :foo => :bar })
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe "#likeables_relation" do
|
88
|
+
it "calls $Follow.likeables_relation" do
|
89
|
+
expect($Like).to receive(:likeables_relation).with(@liker, @likeable.class, { :foo => :bar })
|
90
|
+
@liker.likeables_relation(@likeable.class, { :foo => :bar })
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
describe "#likees_relation" do
|
95
|
+
it "calls $Follow.likeables_relation" do
|
96
|
+
expect($Like).to receive(:likeables_relation).with(@liker, @likeable.class, { :foo => :bar })
|
97
|
+
@liker.likees_relation(@likeable.class, { :foo => :bar })
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
it "removes like relationships" do
|
102
|
+
expect(Socialization.like_model).to receive(:remove_likeables).with(@liker)
|
103
|
+
@liker.destroy
|
104
|
+
end
|
105
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Socialization::Mentioner do
|
4
|
+
before(:all) do
|
5
|
+
use_ar_store
|
6
|
+
@mentioner = ImAMentioner.new
|
7
|
+
@mentionable = ImAMentionable.create
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "#is_mentioner?" do
|
11
|
+
it "returns true" do
|
12
|
+
expect(@mentioner.is_mentioner?).to be true
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "#mentioner?" do
|
17
|
+
it "returns true" do
|
18
|
+
expect(@mentioner.mentioner?).to be true
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "#mention!" do
|
23
|
+
it "does not accept non-mentionables" do
|
24
|
+
expect { @mentioner.mention!(:foo) }.to raise_error(Socialization::ArgumentError)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "calls $Mention.mention!" do
|
28
|
+
expect($Mention).to receive(:mention!).with(@mentioner, @mentionable).once
|
29
|
+
@mentioner.mention!(@mentionable)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "#unmention!" do
|
34
|
+
it "does not accept non-mentionables" do
|
35
|
+
expect { @mentioner.unmention!(:foo) }.to raise_error(Socialization::ArgumentError)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "calls $Mention.mention!" do
|
39
|
+
expect($Mention).to receive(:unmention!).with(@mentioner, @mentionable).once
|
40
|
+
@mentioner.unmention!(@mentionable)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "#toggle_mention!" do
|
45
|
+
it "does not accept non-mentionables" do
|
46
|
+
expect { @mentioner.unmention!(:foo) }.to raise_error(Socialization::ArgumentError)
|
47
|
+
end
|
48
|
+
|
49
|
+
it "unmentions when mentioning" do
|
50
|
+
expect(@mentioner).to receive(:mentions?).with(@mentionable).once.and_return(true)
|
51
|
+
expect(@mentioner).to receive(:unmention!).with(@mentionable).once
|
52
|
+
@mentioner.toggle_mention!(@mentionable)
|
53
|
+
end
|
54
|
+
|
55
|
+
it "mentions when not mentioning" do
|
56
|
+
expect(@mentioner).to receive(:mentions?).with(@mentionable).once.and_return(false)
|
57
|
+
expect(@mentioner).to receive(:mention!).with(@mentionable).once
|
58
|
+
@mentioner.toggle_mention!(@mentionable)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe "#mentions?" do
|
63
|
+
it "does not accept non-mentionables" do
|
64
|
+
expect { @mentioner.unmention!(:foo) }.to raise_error(Socialization::ArgumentError)
|
65
|
+
end
|
66
|
+
|
67
|
+
it "calls $Mention.mentions?" do
|
68
|
+
expect($Mention).to receive(:mentions?).with(@mentioner, @mentionable).once
|
69
|
+
@mentioner.mentions?(@mentionable)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe "#mentionables" do
|
74
|
+
it "calls $Mention.mentionables" do
|
75
|
+
expect($Mention).to receive(:mentionables).with(@mentioner, @mentionable.class, { :foo => :bar })
|
76
|
+
@mentioner.mentionables(@mentionable.class, { :foo => :bar })
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe "#mentionees" do
|
81
|
+
it "calls $Mention.mentionables" do
|
82
|
+
expect($Mention).to receive(:mentionables).with(@mentioner, @mentionable.class, { :foo => :bar })
|
83
|
+
@mentioner.mentionees(@mentionable.class, { :foo => :bar })
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe "#mentionables_relation" do
|
88
|
+
it "calls $Mention.mentionables_relation" do
|
89
|
+
expect($Mention).to receive(:mentionables_relation).with(@mentioner, @mentionable.class, { :foo => :bar })
|
90
|
+
@mentioner.mentionables_relation(@mentionable.class, { :foo => :bar })
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
describe "#mentionees_relation" do
|
95
|
+
it "calls $Mention.mentionables_relation" do
|
96
|
+
expect($Mention).to receive(:mentionables_relation).with(@mentioner, @mentionable.class, { :foo => :bar })
|
97
|
+
@mentioner.mentionees_relation(@mentionable.class, { :foo => :bar })
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
it "removes mention relationships" do
|
102
|
+
expect(Socialization.mention_model).to receive(:remove_mentionables).with(@mentioner)
|
103
|
+
@mentioner.destroy
|
104
|
+
end
|
105
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
$MOCK_REDIS = true
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
Bundler.setup
|
5
|
+
|
6
|
+
RSpec.configure do |config|
|
7
|
+
config.expect_with(:rspec) { |c| c.syntax = :expect }
|
8
|
+
config.filter_run focus: true
|
9
|
+
config.run_all_when_everything_filtered = true
|
10
|
+
end
|
11
|
+
|
12
|
+
$:.push File.expand_path("../lib", __FILE__)
|
13
|
+
require 'active_record'
|
14
|
+
require "socialization"
|
15
|
+
require 'spec_support/data_stores'
|
16
|
+
require 'spec_support/matchers'
|
17
|
+
require 'logger'
|
18
|
+
|
19
|
+
ActiveSupport::Inflector.inflections do |inflect|
|
20
|
+
inflect.irregular 'cache', 'caches'
|
21
|
+
end
|