twrk-socialization 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (138) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +13 -0
  3. data/.ruby-version +1 -0
  4. data/.travis.yml +8 -0
  5. data/Appraisals +23 -0
  6. data/CHANGELOG.md +67 -0
  7. data/Gemfile +3 -0
  8. data/Guardfile +12 -0
  9. data/LICENSE +20 -0
  10. data/README.md +298 -0
  11. data/Rakefile +14 -0
  12. data/demo/.gitignore +15 -0
  13. data/demo/Gemfile +35 -0
  14. data/demo/README.rdoc +261 -0
  15. data/demo/Rakefile +7 -0
  16. data/demo/app/assets/images/rails.png +0 -0
  17. data/demo/app/assets/javascripts/application.js +15 -0
  18. data/demo/app/assets/stylesheets/application.css +13 -0
  19. data/demo/app/controllers/application_controller.rb +3 -0
  20. data/demo/app/helpers/application_helper.rb +2 -0
  21. data/demo/app/mailers/.gitkeep +0 -0
  22. data/demo/app/models/.gitkeep +0 -0
  23. data/demo/app/models/celebrity.rb +4 -0
  24. data/demo/app/models/comment.rb +5 -0
  25. data/demo/app/models/follow.rb +3 -0
  26. data/demo/app/models/like.rb +2 -0
  27. data/demo/app/models/mention.rb +2 -0
  28. data/demo/app/models/movie.rb +3 -0
  29. data/demo/app/models/user.rb +7 -0
  30. data/demo/app/views/layouts/application.html.erb +14 -0
  31. data/demo/config/application.rb +59 -0
  32. data/demo/config/boot.rb +6 -0
  33. data/demo/config/database.yml +25 -0
  34. data/demo/config/environment.rb +5 -0
  35. data/demo/config/environments/development.rb +37 -0
  36. data/demo/config/environments/production.rb +67 -0
  37. data/demo/config/environments/test.rb +37 -0
  38. data/demo/config/initializers/backtrace_silencers.rb +7 -0
  39. data/demo/config/initializers/inflections.rb +15 -0
  40. data/demo/config/initializers/mime_types.rb +5 -0
  41. data/demo/config/initializers/secret_token.rb +7 -0
  42. data/demo/config/initializers/session_store.rb +8 -0
  43. data/demo/config/initializers/wrap_parameters.rb +14 -0
  44. data/demo/config/locales/en.yml +5 -0
  45. data/demo/config/routes.rb +58 -0
  46. data/demo/config.ru +4 -0
  47. data/demo/db/migrate/20120115051222_create_users.rb +9 -0
  48. data/demo/db/migrate/20120115051234_create_movies.rb +9 -0
  49. data/demo/db/migrate/20120115051255_create_celebrities.rb +9 -0
  50. data/demo/db/migrate/20120115054646_create_follows.rb +14 -0
  51. data/demo/db/migrate/20120115054647_create_likes.rb +14 -0
  52. data/demo/db/migrate/20120221200644_create_mentions.rb +14 -0
  53. data/demo/db/migrate/20120221202703_create_comments.rb +9 -0
  54. data/demo/db/schema.rb +72 -0
  55. data/demo/db/seeds.rb +17 -0
  56. data/demo/lib/assets/.gitkeep +0 -0
  57. data/demo/lib/tasks/.gitkeep +0 -0
  58. data/demo/public/404.html +26 -0
  59. data/demo/public/422.html +26 -0
  60. data/demo/public/500.html +25 -0
  61. data/demo/public/favicon.ico +0 -0
  62. data/demo/public/index.html +204 -0
  63. data/demo/public/robots.txt +5 -0
  64. data/demo/script/rails +6 -0
  65. data/demo/test/fixtures/.gitkeep +0 -0
  66. data/demo/test/fixtures/celebrities.yml +7 -0
  67. data/demo/test/fixtures/movies.yml +7 -0
  68. data/demo/test/fixtures/users.yml +7 -0
  69. data/demo/test/functional/.gitkeep +0 -0
  70. data/demo/test/integration/.gitkeep +0 -0
  71. data/demo/test/performance/browsing_test.rb +12 -0
  72. data/demo/test/test_helper.rb +13 -0
  73. data/demo/test/unit/.gitkeep +0 -0
  74. data/demo/test/unit/celebrity_test.rb +7 -0
  75. data/demo/test/unit/movie_test.rb +7 -0
  76. data/demo/test/unit/user_test.rb +7 -0
  77. data/demo/vendor/assets/javascripts/.gitkeep +0 -0
  78. data/demo/vendor/assets/stylesheets/.gitkeep +0 -0
  79. data/demo/vendor/plugins/.gitkeep +0 -0
  80. data/init.rb +1 -0
  81. data/lib/generators/socialization/socialization_generator.rb +38 -0
  82. data/lib/generators/socialization/templates/active_record/migration_follows.rb +14 -0
  83. data/lib/generators/socialization/templates/active_record/migration_likes.rb +14 -0
  84. data/lib/generators/socialization/templates/active_record/migration_mentions.rb +14 -0
  85. data/lib/generators/socialization/templates/active_record/model_follow.rb +2 -0
  86. data/lib/generators/socialization/templates/active_record/model_like.rb +2 -0
  87. data/lib/generators/socialization/templates/active_record/model_mention.rb +2 -0
  88. data/lib/generators/socialization/templates/redis/model_follow.rb +2 -0
  89. data/lib/generators/socialization/templates/redis/model_like.rb +2 -0
  90. data/lib/generators/socialization/templates/redis/model_mention.rb +2 -0
  91. data/lib/socialization/actors/follower.rb +88 -0
  92. data/lib/socialization/actors/liker.rb +88 -0
  93. data/lib/socialization/actors/mentioner.rb +88 -0
  94. data/lib/socialization/config/config.rb +39 -0
  95. data/lib/socialization/helpers/acts_as_helpers.rb +39 -0
  96. data/lib/socialization/helpers/string.rb +17 -0
  97. data/lib/socialization/lib/exceptions.rb +3 -0
  98. data/lib/socialization/stores/active_record/follow.rb +125 -0
  99. data/lib/socialization/stores/active_record/like.rb +121 -0
  100. data/lib/socialization/stores/active_record/mention.rb +125 -0
  101. data/lib/socialization/stores/active_record/mixins/base.rb +12 -0
  102. data/lib/socialization/stores/mixins/base.rb +22 -0
  103. data/lib/socialization/stores/mixins/follow.rb +39 -0
  104. data/lib/socialization/stores/mixins/like.rb +40 -0
  105. data/lib/socialization/stores/mixins/mention.rb +40 -0
  106. data/lib/socialization/stores/redis/base.rb +125 -0
  107. data/lib/socialization/stores/redis/config.rb +11 -0
  108. data/lib/socialization/stores/redis/follow.rb +22 -0
  109. data/lib/socialization/stores/redis/like.rb +22 -0
  110. data/lib/socialization/stores/redis/mention.rb +22 -0
  111. data/lib/socialization/stores/redis/mixins/base.rb +8 -0
  112. data/lib/socialization/version.rb +3 -0
  113. data/lib/socialization/victims/followable.rb +50 -0
  114. data/lib/socialization/victims/likeable.rb +51 -0
  115. data/lib/socialization/victims/mentionable.rb +51 -0
  116. data/lib/socialization.rb +20 -0
  117. data/socialization.gemspec +32 -0
  118. data/spec/actors/follower_spec.rb +113 -0
  119. data/spec/actors/liker_spec.rb +105 -0
  120. data/spec/actors/mentioner_spec.rb +105 -0
  121. data/spec/spec_helper.rb +21 -0
  122. data/spec/spec_support/data_stores.rb +232 -0
  123. data/spec/spec_support/matchers.rb +54 -0
  124. data/spec/stores/active_record/follow_store_spec.rb +147 -0
  125. data/spec/stores/active_record/like_store_spec.rb +146 -0
  126. data/spec/stores/active_record/mention_store_spec.rb +148 -0
  127. data/spec/stores/active_record/mixins/base_spec.rb +25 -0
  128. data/spec/stores/redis/base_spec.rb +195 -0
  129. data/spec/stores/redis/config_spec.rb +28 -0
  130. data/spec/stores/redis/follow_store_spec.rb +26 -0
  131. data/spec/stores/redis/like_store_spec.rb +23 -0
  132. data/spec/stores/redis/mention_store_spec.rb +23 -0
  133. data/spec/string_spec.rb +13 -0
  134. data/spec/victims/followable_spec.rb +59 -0
  135. data/spec/victims/likeable_spec.rb +58 -0
  136. data/spec/victims/mentionable_spec.rb +59 -0
  137. data/spec/world_spec.rb +107 -0
  138. 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
@@ -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