socialization 0.5.0.beta → 0.5.0.beta2

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.
Files changed (48) hide show
  1. data/CHANGELOG.md +5 -2
  2. data/demo/app/models/follow.rb +2 -1
  3. data/demo/app/models/like.rb +1 -1
  4. data/demo/app/models/mention.rb +1 -1
  5. data/lib/generators/socialization/templates/active_record/model_follow.rb +1 -1
  6. data/lib/generators/socialization/templates/active_record/model_like.rb +1 -1
  7. data/lib/generators/socialization/templates/active_record/model_mention.rb +1 -1
  8. data/lib/generators/socialization/templates/redis/model_follow.rb +2 -0
  9. data/lib/generators/socialization/templates/redis/model_like.rb +2 -0
  10. data/lib/generators/socialization/templates/redis/model_mention.rb +2 -0
  11. data/lib/socialization.rb +17 -2
  12. data/lib/socialization/actors/follower.rb +13 -3
  13. data/lib/socialization/actors/liker.rb +13 -3
  14. data/lib/socialization/actors/mentioner.rb +13 -3
  15. data/lib/socialization/{config.rb → config/config.rb} +0 -0
  16. data/lib/socialization/{acts_as_helpers.rb → helpers/acts_as_helpers.rb} +0 -4
  17. data/lib/socialization/stores/active_record/{follow_store.rb → follow.rb} +4 -8
  18. data/lib/socialization/stores/active_record/{like_store.rb → like.rb} +4 -8
  19. data/lib/socialization/stores/active_record/{mention_store.rb → mention.rb} +4 -8
  20. data/lib/socialization/stores/active_record/mixins/base.rb +9 -0
  21. data/lib/socialization/stores/mixins/base.rb +10 -0
  22. data/lib/socialization/stores/mixins/follow.rb +8 -0
  23. data/lib/socialization/stores/mixins/like.rb +8 -0
  24. data/lib/socialization/stores/mixins/mention.rb +8 -0
  25. data/lib/socialization/stores/redis/base.rb +0 -2
  26. data/lib/socialization/stores/redis/{follow_store.rb → follow.rb} +5 -2
  27. data/lib/socialization/stores/redis/{like_store.rb → like.rb} +5 -2
  28. data/lib/socialization/stores/redis/{mention_store.rb → mention.rb} +5 -2
  29. data/lib/socialization/stores/redis/mixins/base.rb +8 -0
  30. data/lib/socialization/version.rb +1 -1
  31. data/lib/socialization/victims/followable.rb +10 -2
  32. data/lib/socialization/victims/likeable.rb +11 -2
  33. data/lib/socialization/victims/mentionable.rb +11 -2
  34. data/test/actors/follower_test.rb +22 -0
  35. data/test/actors/liker_test.rb +22 -0
  36. data/test/actors/mentioner_test.rb +21 -0
  37. data/test/stores/active_record/follow_store_test.rb +3 -3
  38. data/test/stores/active_record/like_store_test.rb +4 -4
  39. data/test/stores/active_record/mention_store_test.rb +3 -3
  40. data/test/stores/redis/follow_store_test.rb +3 -3
  41. data/test/stores/redis/like_store_test.rb +3 -3
  42. data/test/stores/redis/mention_store_test.rb +3 -3
  43. data/test/string_test.rb +1 -1
  44. data/test/test_helper.rb +9 -9
  45. data/test/victims/followable_test.rb +8 -0
  46. data/test/victims/likeable_test.rb +7 -0
  47. data/test/victims/mentionable_test.rb +8 -1
  48. metadata +21 -11
@@ -2,11 +2,14 @@
2
2
 
3
3
  ## 0.5.0.beta (June 6, 2012)
4
4
 
5
- * **MAJOR REFACTORING:** Your Like, Follow and Mention models should now inherit the Socialization store base class instead of using the acts_as helper. (e.g.: class Follow < Socialization::ActiveRecordStores::FollowStore). See demo app for an example. Your code should be mostly unaffected.
6
- * Changed: The persistence logic has now been moved to the Socialization::ActiveRecordStores namespace. More stores such as Redis or MongoDB can be easily added.
5
+ * **IMPORTANT:** This release includes many changes, some breaking. Make sure to test your code carefully after upgrading.
6
+ * **BREAKING CHANGE:** Your Like, Follow and Mention models should now inherit the Socialization store base class instead of using the acts_as helper. (e.g.: class Follow < Socialization::ActiveRecordStores::Follow). See demo app for an example.
7
+ * **BREAKING CHANGE:** the `followers`, `followables` etc methods now return an array of objects. Use methods such as `followers_relation` for an ActiveRecord::Relation.
8
+ * Changed: The persistence logic has now been moved to the Socialization::ActiveRecordStores namespace. More stores can be easily added.
7
9
  * Changed: `like!`, `follow!`, and `mention!` now return a boolean. True when the action was successful, false when it wasn't (e.g.: the relationship already exists).
8
10
  * Changed: `unlike!`, `unfollow!` and `unmention!` will now return false if there is no record to destroy rather than raising `ActiveRecord::RecordNotFound`.
9
11
  * Changed: Records can now like, follow or mention themselves. If you want to prevent this, it should be enforced directly in your application.
12
+ * Added: Data can now be stored in Redis.
10
13
  * Added: `toggle_like!`, `toggle_follow!` and `toggle_mention!` methods. Thanks to [@balvig](https://github.com/balvig).
11
14
  * Added: support for single table inheritance. Thanks to [@balvig](https://github.com/balvig).
12
15
 
@@ -1,2 +1,3 @@
1
- class Follow < Socialization::ActiveRecordStores::FollowStore
1
+ class Follow < Socialization::ActiveRecordStores::Follow
2
+ self.table_name = 'follows'
2
3
  end
@@ -1,2 +1,2 @@
1
- class Like < Socialization::ActiveRecordStores::LikeStore
1
+ class Like < Socialization::ActiveRecordStores::Like
2
2
  end
@@ -1,2 +1,2 @@
1
- class Mention < Socialization::ActiveRecordStores::MentionStore
1
+ class Mention < Socialization::ActiveRecordStores::Mention
2
2
  end
@@ -1,2 +1,2 @@
1
- class Follow < Socialization::ActiveRecordStores::FollowStore
1
+ class Follow < Socialization::ActiveRecordStores::Follow
2
2
  end
@@ -1,2 +1,2 @@
1
- class Like < Socialization::ActiveRecordStores::LikeStore
1
+ class Like < Socialization::ActiveRecordStores::Like
2
2
  end
@@ -1,2 +1,2 @@
1
- class Mention < Socialization::ActiveRecordStores::MentionStore
1
+ class Mention < Socialization::ActiveRecordStores::Mention
2
2
  end
@@ -0,0 +1,2 @@
1
+ class Follow < Socialization::RedisStores::Follow
2
+ end
@@ -0,0 +1,2 @@
1
+ class Like < Socialization::RedisStores::Like
2
+ end
@@ -0,0 +1,2 @@
1
+ class Mention < Socialization::RedisStores::Mention
2
+ end
@@ -1,4 +1,19 @@
1
- require 'socialization/config'
2
- require 'socialization/acts_as_helpers'
1
+ %w(
2
+ stores/mixins/base.rb
3
+ stores/mixins/**/*.rb
4
+ stores/active_record/mixins/base.rb
5
+ stores/active_record/mixins/**/*.rb
6
+ stores/redis/mixins/base.rb
7
+ stores/redis/mixins/**/*.rb
8
+ stores/active_record/**/*.rb
9
+ stores/redis/base.rb
10
+ stores/redis/**/*.rb
11
+ actors/**/*.rb
12
+ victims/**/*.rb
13
+ helpers/**/*.rb
14
+ config/**/*.rb
15
+ ).each do |path|
16
+ Dir["#{File.dirname(__FILE__)}/socialization/#{path}"].each { |f| require(f) }
17
+ end
3
18
 
4
19
  ActiveRecord::Base.send :include, Socialization::ActsAsHelpers
@@ -18,7 +18,7 @@ module Socialization
18
18
  true
19
19
  end
20
20
 
21
- # Create a new {FollowStores follow} relationship.
21
+ # Create a new {Follow follow} relationship.
22
22
  #
23
23
  # @param [Followable] followable the object to be followed.
24
24
  # @return [Boolean]
@@ -27,7 +27,7 @@ module Socialization
27
27
  Socialization.follow_model.follow!(self, followable)
28
28
  end
29
29
 
30
- # Delete a {FollowStores follow} relationship.
30
+ # Delete a {Follow follow} relationship.
31
31
  #
32
32
  # @param [Followable] followable the object to unfollow.
33
33
  # @return [Boolean]
@@ -36,7 +36,7 @@ module Socialization
36
36
  Socialization.follow_model.unfollow!(self, followable)
37
37
  end
38
38
 
39
- # Toggles a {FollowStores follow} relationship.
39
+ # Toggles a {Follow follow} relationship.
40
40
  #
41
41
  # @param [Followable] followable the object to follow/unfollow.
42
42
  # @return [Boolean]
@@ -68,7 +68,17 @@ module Socialization
68
68
  def followables(klass, opts = {})
69
69
  Socialization.follow_model.followables(self, klass, opts)
70
70
  end
71
+ alias :followees :followables
71
72
 
73
+ # Returns a relation for all the followables of a certain type that are followed by self
74
+ #
75
+ # @params [Followable] klass the type of {Followable} you want
76
+ # @params [Hash] opts a hash of options
77
+ # @return ActiveRecord::Relation
78
+ def followables_relation(klass, opts = {})
79
+ Socialization.follow_model.followables_relation(self, klass, opts)
80
+ end
81
+ alias :followees_relation :followables_relation
72
82
  end
73
83
  end
74
84
  end
@@ -18,7 +18,7 @@ module Socialization
18
18
  true
19
19
  end
20
20
 
21
- # Create a new {LikeStores like} relationship.
21
+ # Create a new {Like like} relationship.
22
22
  #
23
23
  # @param [Likeable] likeable the object to be liked.
24
24
  # @return [Boolean]
@@ -27,7 +27,7 @@ module Socialization
27
27
  Socialization.like_model.like!(self, likeable)
28
28
  end
29
29
 
30
- # Delete a {LikeStores like} relationship.
30
+ # Delete a {Like like} relationship.
31
31
  #
32
32
  # @param [Likeable] likeable the object to unlike.
33
33
  # @return [Boolean]
@@ -36,7 +36,7 @@ module Socialization
36
36
  Socialization.like_model.unlike!(self, likeable)
37
37
  end
38
38
 
39
- # Toggles a {LikeStores like} relationship.
39
+ # Toggles a {Like like} relationship.
40
40
  #
41
41
  # @param [Likeable] likeable the object to like/unlike.
42
42
  # @return [Boolean]
@@ -68,7 +68,17 @@ module Socialization
68
68
  def likeables(klass, opts = {})
69
69
  Socialization.like_model.likeables(self, klass, opts)
70
70
  end
71
+ alias :likees :likeables
71
72
 
73
+ # Returns a relation for all the likeables of a certain type that are liked by self
74
+ #
75
+ # @params [Likeable] klass the type of {Likeable} you want
76
+ # @params [Hash] opts a hash of options
77
+ # @return ActiveRecord::Relation
78
+ def likeables_relation(klass, opts = {})
79
+ Socialization.like_model.likeables_relation(self, klass, opts)
80
+ end
81
+ alias :likees_relation :likeables_relation
72
82
  end
73
83
  end
74
84
  end
@@ -18,7 +18,7 @@ module Socialization
18
18
  true
19
19
  end
20
20
 
21
- # Create a new {MentionStores mention} relationship.
21
+ # Create a new {Mention mention} relationship.
22
22
  #
23
23
  # @param [Mentionable] mentionable the object to be mentioned.
24
24
  # @return [Boolean]
@@ -27,7 +27,7 @@ module Socialization
27
27
  Socialization.mention_model.mention!(self, mentionable)
28
28
  end
29
29
 
30
- # Delete a {MentionStores mention} relationship.
30
+ # Delete a {Mention mention} relationship.
31
31
  #
32
32
  # @param [Mentionable] mentionable the object to unmention.
33
33
  # @return [Boolean]
@@ -36,7 +36,7 @@ module Socialization
36
36
  Socialization.mention_model.unmention!(self, mentionable)
37
37
  end
38
38
 
39
- # Toggles a {MentionStores mention} relationship.
39
+ # Toggles a {Mention mention} relationship.
40
40
  #
41
41
  # @param [Mentionable] mentionable the object to mention/unmention.
42
42
  # @return [Boolean]
@@ -68,7 +68,17 @@ module Socialization
68
68
  def mentionables(klass, opts = {})
69
69
  Socialization.mention_model.mentionables(self, klass, opts)
70
70
  end
71
+ alias :mentionees :mentionables
71
72
 
73
+ # Returns a relation for all the mentionables of a certain type that are mentioned by self
74
+ #
75
+ # @params [Mentionable] klass the type of {Mentionable} you want
76
+ # @params [Hash] opts a hash of options
77
+ # @return ActiveRecord::Relation
78
+ def mentionables_relation(klass, opts = {})
79
+ Socialization.mention_model.mentionables_relation(self, klass, opts)
80
+ end
81
+ alias :mentionees_relation :mentionables_relation
72
82
  end
73
83
  end
74
84
  end
@@ -1,9 +1,5 @@
1
1
  require 'active_support/concern'
2
2
 
3
- %w(helpers stores actors victims).each do |path|
4
- Dir["#{File.dirname(__FILE__)}/#{path}/**/*.rb"].each { |f| require(f) }
5
- end
6
-
7
3
  module Socialization
8
4
  module ActsAsHelpers
9
5
  extend ActiveSupport::Concern
@@ -1,6 +1,9 @@
1
1
  module Socialization
2
2
  module ActiveRecordStores
3
- class FollowStore < ActiveRecord::Base
3
+ class Follow < ActiveRecord::Base
4
+ include Socialization::ActiveRecordStores::Mixins::Base
5
+ include Socialization::Stores::Mixins::Follow
6
+
4
7
  belongs_to :follower, :polymorphic => true
5
8
  belongs_to :followable, :polymorphic => true
6
9
 
@@ -14,14 +17,7 @@ module Socialization
14
17
  :followable_id => followable.id)
15
18
  }
16
19
 
17
- @@after_create_hook = nil
18
- @@after_destroy_hook = nil
19
-
20
20
  class << self
21
- def table_name
22
- 'follows'
23
- end
24
-
25
21
  def follow!(follower, followable)
26
22
  unless follows?(follower, followable)
27
23
  self.create! do |follow|
@@ -1,6 +1,9 @@
1
1
  module Socialization
2
2
  module ActiveRecordStores
3
- class LikeStore < ActiveRecord::Base
3
+ class Like < ActiveRecord::Base
4
+ include Socialization::ActiveRecordStores::Mixins::Base
5
+ include Socialization::Stores::Mixins::Like
6
+
4
7
  belongs_to :liker, :polymorphic => true
5
8
  belongs_to :likeable, :polymorphic => true
6
9
 
@@ -14,14 +17,7 @@ module Socialization
14
17
  :likeable_id => likeable.id)
15
18
  }
16
19
 
17
- @@after_create_hook = nil
18
- @@after_destroy_hook = nil
19
-
20
20
  class << self
21
- def table_name
22
- 'likes'
23
- end
24
-
25
21
  def like!(liker, likeable)
26
22
  unless likes?(liker, likeable)
27
23
  self.create! do |like|
@@ -1,6 +1,9 @@
1
1
  module Socialization
2
2
  module ActiveRecordStores
3
- class MentionStore < ActiveRecord::Base
3
+ class Mention < ActiveRecord::Base
4
+ include Socialization::ActiveRecordStores::Mixins::Base
5
+ include Socialization::Stores::Mixins::Mention
6
+
4
7
  belongs_to :mentioner, :polymorphic => true
5
8
  belongs_to :mentionable, :polymorphic => true
6
9
 
@@ -14,14 +17,7 @@ module Socialization
14
17
  :mentionable_id => mentionable.id)
15
18
  }
16
19
 
17
- @@after_create_hook = nil
18
- @@after_destroy_hook = nil
19
-
20
20
  class << self
21
- def table_name
22
- 'mentions'
23
- end
24
-
25
21
  def mention!(mentioner, mentionable)
26
22
  unless mentions?(mentioner, mentionable)
27
23
  self.create! do |mention|
@@ -0,0 +1,9 @@
1
+ module Socialization
2
+ module ActiveRecordStores
3
+ module Mixins
4
+ module Base
5
+ include Socialization::Stores::Mixins::Base
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,10 @@
1
+ module Socialization
2
+ module Stores
3
+ module Mixins
4
+ module Base
5
+ @@after_create_hook = nil
6
+ @@after_destroy_hook = nil
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,8 @@
1
+ module Socialization
2
+ module Stores
3
+ module Mixins
4
+ module Follow
5
+ end
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module Socialization
2
+ module Stores
3
+ module Mixins
4
+ module Like
5
+ end
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module Socialization
2
+ module Stores
3
+ module Mixins
4
+ module Mention
5
+ end
6
+ end
7
+ end
8
+ end
@@ -1,8 +1,6 @@
1
1
  module Socialization
2
2
  module RedisStores
3
3
  class Base
4
- @@after_create_hook = nil
5
- @@after_destroy_hook = nil
6
4
  end
7
5
  end
8
6
  end
@@ -1,8 +1,11 @@
1
- require File.expand_path(File.dirname(__FILE__)) + '/base'
1
+ # require File.expand_path(File.dirname(__FILE__)) + '/base'
2
2
 
3
3
  module Socialization
4
4
  module RedisStores
5
- class FollowStore < Socialization::RedisStores::Base
5
+ class Follow < Socialization::RedisStores::Base
6
+ include Socialization::RedisStores::Mixins::Base
7
+ include Socialization::Stores::Mixins::Follow
8
+
6
9
  class << self
7
10
  def follow!(follower, followable)
8
11
  unless follows?(follower, followable)
@@ -1,8 +1,11 @@
1
- require File.expand_path(File.dirname(__FILE__)) + '/base'
1
+ # require File.expand_path(File.dirname(__FILE__)) + '/base'
2
2
 
3
3
  module Socialization
4
4
  module RedisStores
5
- class LikeStore < Socialization::RedisStores::Base
5
+ class Like < Socialization::RedisStores::Base
6
+ include Socialization::RedisStores::Mixins::Base
7
+ include Socialization::Stores::Mixins::Follow
8
+
6
9
  class << self
7
10
  def like!(liker, likeable)
8
11
  unless likes?(liker, likeable)
@@ -1,8 +1,11 @@
1
- require File.expand_path(File.dirname(__FILE__)) + '/base'
1
+ # require File.expand_path(File.dirname(__FILE__)) + '/base'
2
2
 
3
3
  module Socialization
4
4
  module RedisStores
5
- class MentionStore < Socialization::RedisStores::Base
5
+ class Mention < Socialization::RedisStores::Base
6
+ include Socialization::RedisStores::Mixins::Base
7
+ include Socialization::Stores::Mixins::Mention
8
+
6
9
  class << self
7
10
  def mention!(mentioner, mentionable)
8
11
  unless mentions?(mentioner, mentionable)
@@ -0,0 +1,8 @@
1
+ module Socialization
2
+ module RedisStores
3
+ module Mixins
4
+ module Base
5
+ end
6
+ end
7
+ end
8
+ end
@@ -1,3 +1,3 @@
1
1
  module Socialization
2
- VERSION = "0.5.0.beta"
2
+ VERSION = "0.5.0.beta2"
3
3
  end
@@ -26,13 +26,21 @@ module Socialization
26
26
  Socialization.follow_model.follows?(follower, self)
27
27
  end
28
28
 
29
- # Returns a scope of the {Follower}s following self.
29
+ # Returns an array of {Follower}s following self.
30
30
  #
31
- # @param [Class] klass the {Follower} class to be included in the scope. e.g. `User`
31
+ # @param [Class] klass the {Follower} class to be included. e.g. `User`
32
32
  # @return [Array<Follower, Numeric>] An array of Follower objects or IDs
33
33
  def followers(klass, opts = {})
34
34
  Socialization.follow_model.followers(self, klass, opts)
35
35
  end
36
+
37
+ # Returns a scope of the {Follower}s following self.
38
+ #
39
+ # @param [Class] klass the {Follower} class to be included in the scope. e.g. `User`
40
+ # @return ActiveRecord::Relation
41
+ def followers_relation(klass, opts = {})
42
+ Socialization.follow_model.followers_relation(self, klass, opts)
43
+ end
36
44
  end
37
45
  end
38
46
  end
@@ -26,13 +26,22 @@ module Socialization
26
26
  Socialization.like_model.likes?(liker, self)
27
27
  end
28
28
 
29
- # Returns a scope of the {Liker}s likeing self.
29
+ # Returns an array of {Liker}s liking self.
30
30
  #
31
- # @param [Class] klass the {Liker} class to be included in the scope. e.g. `User`.
31
+ # @param [Class] klass the {Liker} class to be included. e.g. `User`
32
32
  # @return [Array<Liker, Numeric>] An array of Liker objects or IDs
33
33
  def likers(klass, opts = {})
34
34
  Socialization.like_model.likers(self, klass, opts)
35
35
  end
36
+
37
+ # Returns a scope of the {Liker}s liking self.
38
+ #
39
+ # @param [Class] klass the {Liker} class to be included in the scope. e.g. `User`
40
+ # @return ActiveRecord::Relation
41
+ def likers_relation(klass, opts = {})
42
+ Socialization.like_model.likers_relation(self, klass, opts)
43
+ end
44
+
36
45
  end
37
46
  end
38
47
  end
@@ -26,13 +26,22 @@ module Socialization
26
26
  Socialization.mention_model.mentions?(mentioner, self)
27
27
  end
28
28
 
29
- # Returns a scope of the {Mentioner}s mentioning self.
29
+ # Returns an array of {Mentioner}s mentioning self.
30
30
  #
31
- # @param [Class] klass the {Mentioner} class to be included in the scope. e.g. `User`.
31
+ # @param [Class] klass the {Mentioner} class to be included. e.g. `User`
32
32
  # @return [Array<Mentioner, Numeric>] An array of Mentioner objects or IDs
33
33
  def mentioners(klass, opts = {})
34
34
  Socialization.mention_model.mentioners(self, klass, opts)
35
35
  end
36
+
37
+ # Returns a scope of the {Mentioner}s mentioning self.
38
+ #
39
+ # @param [Class] klass the {Mentioner} class to be included in the scope. e.g. `User`
40
+ # @return ActiveRecord::Relation
41
+ def mentioners_relation(klass, opts = {})
42
+ Socialization.mention_model.mentioners_relation(self, klass, opts)
43
+ end
44
+
36
45
  end
37
46
  end
38
47
  end
@@ -70,5 +70,27 @@ class FollowerTest < Test::Unit::TestCase
70
70
  @follower.followables(@followable.class, { :foo => :bar })
71
71
  end
72
72
  end
73
+
74
+ context "#followees" do
75
+ should "call $Follow.followables" do
76
+ $Follow.expects(:followables).with(@follower, @followable.class, { :foo => :bar })
77
+ @follower.followees(@followable.class, { :foo => :bar })
78
+ end
79
+ end
80
+
81
+ context "#followables_relation" do
82
+ should "call $Follow.followables_relation" do
83
+ $Follow.expects(:followables_relation).with(@follower, @followable.class, { :foo => :bar })
84
+ @follower.followables_relation(@followable.class, { :foo => :bar })
85
+ end
86
+ end
87
+
88
+ context "#followees_relation" do
89
+ should "call $Follow.followables_relation" do
90
+ $Follow.expects(:followables_relation).with(@follower, @followable.class, { :foo => :bar })
91
+ @follower.followees_relation(@followable.class, { :foo => :bar })
92
+ end
93
+ end
94
+
73
95
  end
74
96
  end
@@ -70,5 +70,27 @@ class LikerTest < Test::Unit::TestCase
70
70
  @liker.likeables(@likeable.class, { :foo => :bar })
71
71
  end
72
72
  end
73
+
74
+ context "#likees" do
75
+ should "call $Like.likeables" do
76
+ $Like.expects(:likeables).with(@liker, @likeable.class, { :foo => :bar })
77
+ @liker.likees(@likeable.class, { :foo => :bar })
78
+ end
79
+ end
80
+
81
+ context "#likeables_relation" do
82
+ should "call $Follow.likeables_relation" do
83
+ $Like.expects(:likeables_relation).with(@liker, @likeable.class, { :foo => :bar })
84
+ @liker.likeables_relation(@likeable.class, { :foo => :bar })
85
+ end
86
+ end
87
+
88
+ context "#likees_relation" do
89
+ should "call $Follow.likeables_relation" do
90
+ $Like.expects(:likeables_relation).with(@liker, @likeable.class, { :foo => :bar })
91
+ @liker.likees_relation(@likeable.class, { :foo => :bar })
92
+ end
93
+ end
94
+
73
95
  end
74
96
  end
@@ -70,5 +70,26 @@ class MentionerTest < Test::Unit::TestCase
70
70
  @mentioner.mentionables(@mentionable.class, { :foo => :bar })
71
71
  end
72
72
  end
73
+
74
+ context "#mentionees" do
75
+ should "call $Mention.mentionables" do
76
+ $Mention.expects(:mentionables).with(@mentioner, @mentionable.class, { :foo => :bar })
77
+ @mentioner.mentionees(@mentionable.class, { :foo => :bar })
78
+ end
79
+ end
80
+
81
+ context "#mentionables_relation" do
82
+ should "call $Mention.mentionables_relation" do
83
+ $Mention.expects(:mentionables_relation).with(@mentioner, @mentionable.class, { :foo => :bar })
84
+ @mentioner.mentionables_relation(@mentionable.class, { :foo => :bar })
85
+ end
86
+ end
87
+
88
+ context "#mentionees_relation" do
89
+ should "call $Mention.mentionables_relation" do
90
+ $Mention.expects(:mentionables_relation).with(@mentioner, @mentionable.class, { :foo => :bar })
91
+ @mentioner.mentionees_relation(@mentionable.class, { :foo => :bar })
92
+ end
93
+ end
73
94
  end
74
95
  end
@@ -3,7 +3,7 @@ require File.expand_path(File.dirname(__FILE__))+'/../../test_helper'
3
3
  class ActiveRecordFollowStoreTest < Test::Unit::TestCase
4
4
  context "ActiveRecordStores::FollowStoreTest" do
5
5
  setup do
6
- @klass = Socialization::ActiveRecordStores::FollowStore
6
+ @klass = Socialization::ActiveRecordStores::Follow
7
7
  @klass.touch nil
8
8
  @klass.after_follow nil
9
9
  @klass.after_unfollow nil
@@ -12,8 +12,8 @@ class ActiveRecordFollowStoreTest < Test::Unit::TestCase
12
12
  end
13
13
 
14
14
  context "data store" do
15
- should "inherit Socialization::ActiveRecordStores::FollowStore" do
16
- assert_equal Socialization::ActiveRecordStores::FollowStore, Socialization.follow_model
15
+ should "inherit Socialization::ActiveRecordStores::Follow" do
16
+ assert_equal Socialization::ActiveRecordStores::Follow, Socialization.follow_model
17
17
  end
18
18
  end
19
19
 
@@ -1,9 +1,9 @@
1
1
  require File.expand_path(File.dirname(__FILE__))+'/../../test_helper'
2
2
 
3
3
  class ActiveRecordLikeStoreTest < Test::Unit::TestCase
4
- context "ActiveRecordStore::LikeStoreTest" do
4
+ context "ActiveRecordStores::LikeStoreTest" do
5
5
  setup do
6
- @klass = Socialization::ActiveRecordStores::LikeStore
6
+ @klass = Socialization::ActiveRecordStores::Like
7
7
  @klass.touch nil
8
8
  @klass.after_like nil
9
9
  @klass.after_unlike nil
@@ -12,8 +12,8 @@ class ActiveRecordLikeStoreTest < Test::Unit::TestCase
12
12
  end
13
13
 
14
14
  context "data store" do
15
- should "inherit Socialization::ActiveRecordStores::LikeStore" do
16
- assert_equal Socialization::ActiveRecordStores::LikeStore, Socialization.like_model
15
+ should "inherit Socialization::ActiveRecordStores::Like" do
16
+ assert_equal Socialization::ActiveRecordStores::Like, Socialization.like_model
17
17
  end
18
18
  end
19
19
 
@@ -3,7 +3,7 @@ require File.expand_path(File.dirname(__FILE__))+'/../../test_helper'
3
3
  class ActiveRecordMentionStoreTest < Test::Unit::TestCase
4
4
  context "ActiveRecordStores::MentionStoreTest" do
5
5
  setup do
6
- @klass = Socialization::ActiveRecordStores::MentionStore
6
+ @klass = Socialization::ActiveRecordStores::Mention
7
7
  @klass.touch nil
8
8
  @klass.after_mention nil
9
9
  @klass.after_unmention nil
@@ -12,8 +12,8 @@ class ActiveRecordMentionStoreTest < Test::Unit::TestCase
12
12
  end
13
13
 
14
14
  context "data store" do
15
- should "inherit Socialization::ActiveRecordStores::MentionStore" do
16
- assert_equal Socialization::ActiveRecordStores::MentionStore, Socialization.mention_model
15
+ should "inherit Socialization::ActiveRecordStores::Mention" do
16
+ assert_equal Socialization::ActiveRecordStores::Mention, Socialization.mention_model
17
17
  end
18
18
  end
19
19
 
@@ -4,7 +4,7 @@ class RedisFollowStoreTest < Test::Unit::TestCase
4
4
  context "RedisStores::FollowStoreTest" do
5
5
  setup do
6
6
  use_redis_store
7
- @klass = Socialization::RedisStores::FollowStore
7
+ @klass = Socialization::RedisStores::Follow
8
8
  @klass.touch nil
9
9
  @klass.after_follow nil
10
10
  @klass.after_unfollow nil
@@ -13,8 +13,8 @@ class RedisFollowStoreTest < Test::Unit::TestCase
13
13
  end
14
14
 
15
15
  context "Stores" do
16
- should "inherit Socialization::RedisStores::FollowStore" do
17
- assert_equal Socialization::RedisStores::FollowStore, Socialization.follow_model
16
+ should "inherit Socialization::RedisStores::Follow" do
17
+ assert_equal Socialization::RedisStores::Follow, Socialization.follow_model
18
18
  end
19
19
  end
20
20
 
@@ -4,7 +4,7 @@ class RedisLikeStoreTest < Test::Unit::TestCase
4
4
  context "RedisStores::LikeStoreTest" do
5
5
  setup do
6
6
  use_redis_store
7
- @klass = Socialization::RedisStores::LikeStore
7
+ @klass = Socialization::RedisStores::Like
8
8
  @klass.touch nil
9
9
  @klass.after_like nil
10
10
  @klass.after_unlike nil
@@ -13,8 +13,8 @@ class RedisLikeStoreTest < Test::Unit::TestCase
13
13
  end
14
14
 
15
15
  context "Stores" do
16
- should "inherit Socialization::RedisStores::LikeStore" do
17
- assert_equal Socialization::RedisStores::LikeStore, Socialization.like_model
16
+ should "inherit Socialization::RedisStores::Like" do
17
+ assert_equal Socialization::RedisStores::Like, Socialization.like_model
18
18
  end
19
19
  end
20
20
 
@@ -4,7 +4,7 @@ class RedisMentionStoreTest < Test::Unit::TestCase
4
4
  context "RedisStores::MentionStoreTest" do
5
5
  setup do
6
6
  use_redis_store
7
- @klass = Socialization::RedisStores::MentionStore
7
+ @klass = Socialization::RedisStores::Mention
8
8
  @klass.touch nil
9
9
  @klass.after_mention nil
10
10
  @klass.after_unmention nil
@@ -13,8 +13,8 @@ class RedisMentionStoreTest < Test::Unit::TestCase
13
13
  end
14
14
 
15
15
  context "Stores" do
16
- should "inherit Socialization::RedisStores::MentionStore" do
17
- assert_equal Socialization::RedisStores::MentionStore, Socialization.mention_model
16
+ should "inherit Socialization::RedisStores::Mention" do
17
+ assert_equal Socialization::RedisStores::Mention, Socialization.mention_model
18
18
  end
19
19
  end
20
20
 
@@ -5,7 +5,7 @@ class StringTest < Test::Unit::TestCase
5
5
  should "return a class" do
6
6
  assert_equal Socialization, "Socialization".deep_const_get
7
7
  assert_equal Socialization::ActiveRecordStores, "Socialization::ActiveRecordStores".deep_const_get
8
- assert_equal Socialization::ActiveRecordStores::FollowStore, "Socialization::ActiveRecordStores::FollowStore".deep_const_get
8
+ assert_equal Socialization::ActiveRecordStores::Follow, "Socialization::ActiveRecordStores::Follow".deep_const_get
9
9
 
10
10
  assert_raise(NameError) { "Foo::Bar".deep_const_get }
11
11
  end
@@ -42,16 +42,16 @@ class Test::Unit::TestCase
42
42
  end
43
43
 
44
44
  def use_redis_store
45
- Socialization.follow_model = Socialization::RedisStores::FollowStore
46
- Socialization.mention_model = Socialization::RedisStores::MentionStore
47
- Socialization.like_model = Socialization::RedisStores::LikeStore
45
+ Socialization.follow_model = Socialization::RedisStores::Follow
46
+ Socialization.mention_model = Socialization::RedisStores::Mention
47
+ Socialization.like_model = Socialization::RedisStores::Like
48
48
  setup_model_shortcuts
49
49
  end
50
50
 
51
51
  def use_ar_store
52
- Socialization.follow_model = Socialization::ActiveRecordStores::FollowStore
53
- Socialization.mention_model = Socialization::ActiveRecordStores::MentionStore
54
- Socialization.like_model = Socialization::ActiveRecordStores::LikeStore
52
+ Socialization.follow_model = Socialization::ActiveRecordStores::Follow
53
+ Socialization.mention_model = Socialization::ActiveRecordStores::Mention
54
+ Socialization.like_model = Socialization::ActiveRecordStores::Like
55
55
  setup_model_shortcuts
56
56
  end
57
57
 
@@ -176,9 +176,9 @@ class Movie < ActiveRecord::Base
176
176
  has_many :comments
177
177
  end
178
178
 
179
- # class Follow < Socialization::ActiveRecordStores::FollowStore; end
180
- # class Like < Socialization::ActiveRecordStores::LikeStore; end
181
- # class Mention < Socialization::ActiveRecordStores::MentionStore; end
179
+ # class Follow < Socialization::ActiveRecordStores::Follow; end
180
+ # class Like < Socialization::ActiveRecordStores::Like; end
181
+ # class Mention < Socialization::ActiveRecordStores::Mention; end
182
182
 
183
183
  class ImAFollower < ActiveRecord::Base
184
184
  acts_as_follower
@@ -30,5 +30,13 @@ class FollowableTest < Test::Unit::TestCase
30
30
  @followable.followers(@follower.class, { :foo => :bar })
31
31
  end
32
32
  end
33
+
34
+ context "#followers_relation" do
35
+ should "call $Follow.followers_relation" do
36
+ $Follow.expects(:followers_relation).with(@followable, @follower.class, { :foo => :bar })
37
+ @followable.followers_relation(@follower.class, { :foo => :bar })
38
+ end
39
+ end
40
+
33
41
  end
34
42
  end
@@ -30,5 +30,12 @@ class LikeableTest < Test::Unit::TestCase
30
30
  @likeable.likers(@liker.class, { :foo => :bar })
31
31
  end
32
32
  end
33
+
34
+ context "#likers_relation" do
35
+ should "call $Like.likers_relation" do
36
+ $Like.expects(:likers_relation).with(@likeable, @liker.class, { :foo => :bar })
37
+ @likeable.likers_relation(@liker.class, { :foo => :bar })
38
+ end
39
+ end
33
40
  end
34
41
  end
@@ -25,10 +25,17 @@ class MentionableTest < Test::Unit::TestCase
25
25
  end
26
26
 
27
27
  context "#mentioners" do
28
- should "call $Mentionmentioners" do
28
+ should "call $Mention.mentioners" do
29
29
  $Mention.expects(:mentioners).with(@mentionable, @mentioner.class, { :foo => :bar })
30
30
  @mentionable.mentioners(@mentioner.class, { :foo => :bar })
31
31
  end
32
32
  end
33
+
34
+ context "#mentioners_relation" do
35
+ should "call $Mention.mentioners" do
36
+ $Mention.expects(:mentioners_relation).with(@mentionable, @mentioner.class, { :foo => :bar })
37
+ @mentionable.mentioners_relation(@mentioner.class, { :foo => :bar })
38
+ end
39
+ end
33
40
  end
34
41
  end
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: socialization
3
3
  version: !ruby/object:Gem::Version
4
- hash: 2135628231
4
+ hash: -1564876628
5
5
  prerelease: 6
6
6
  segments:
7
7
  - 0
8
8
  - 5
9
9
  - 0
10
10
  - beta
11
- version: 0.5.0.beta
11
+ - 2
12
+ version: 0.5.0.beta2
12
13
  platform: ruby
13
14
  authors:
14
15
  - Carl Mercier
@@ -16,7 +17,7 @@ autorequire:
16
17
  bindir: bin
17
18
  cert_chain: []
18
19
 
19
- date: 2012-06-06 00:00:00 -04:00
20
+ date: 2012-06-08 00:00:00 -04:00
20
21
  default_executable:
21
22
  dependencies:
22
23
  - !ruby/object:Gem::Dependency
@@ -224,21 +225,30 @@ files:
224
225
  - lib/generators/socialization/templates/active_record/model_follow.rb
225
226
  - lib/generators/socialization/templates/active_record/model_like.rb
226
227
  - lib/generators/socialization/templates/active_record/model_mention.rb
228
+ - lib/generators/socialization/templates/redis/model_follow.rb
229
+ - lib/generators/socialization/templates/redis/model_like.rb
230
+ - lib/generators/socialization/templates/redis/model_mention.rb
227
231
  - lib/socialization.rb
228
232
  - lib/socialization/actors/follower.rb
229
233
  - lib/socialization/actors/liker.rb
230
234
  - lib/socialization/actors/mentioner.rb
231
- - lib/socialization/acts_as_helpers.rb
232
- - lib/socialization/config.rb
235
+ - lib/socialization/config/config.rb
236
+ - lib/socialization/helpers/acts_as_helpers.rb
233
237
  - lib/socialization/helpers/string.rb
234
- - lib/socialization/stores/active_record/follow_store.rb
235
- - lib/socialization/stores/active_record/like_store.rb
236
- - lib/socialization/stores/active_record/mention_store.rb
238
+ - lib/socialization/stores/active_record/follow.rb
239
+ - lib/socialization/stores/active_record/like.rb
240
+ - lib/socialization/stores/active_record/mention.rb
241
+ - lib/socialization/stores/active_record/mixins/base.rb
242
+ - lib/socialization/stores/mixins/base.rb
243
+ - lib/socialization/stores/mixins/follow.rb
244
+ - lib/socialization/stores/mixins/like.rb
245
+ - lib/socialization/stores/mixins/mention.rb
237
246
  - lib/socialization/stores/redis/base.rb
238
247
  - lib/socialization/stores/redis/config.rb
239
- - lib/socialization/stores/redis/follow_store.rb
240
- - lib/socialization/stores/redis/like_store.rb
241
- - lib/socialization/stores/redis/mention_store.rb
248
+ - lib/socialization/stores/redis/follow.rb
249
+ - lib/socialization/stores/redis/like.rb
250
+ - lib/socialization/stores/redis/mention.rb
251
+ - lib/socialization/stores/redis/mixins/base.rb
242
252
  - lib/socialization/version.rb
243
253
  - lib/socialization/victims/followable.rb
244
254
  - lib/socialization/victims/likeable.rb