socialization 0.4.0 → 0.5.0.beta

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 (144) hide show
  1. data/.gitignore +5 -1
  2. data/CHANGELOG.md +41 -0
  3. data/README.md +246 -0
  4. data/demo/{demo_app/.gitignore → .gitignore} +0 -0
  5. data/demo/{demo_app/Gemfile → Gemfile} +1 -1
  6. data/demo/{demo_app/README.rdoc → README.rdoc} +0 -0
  7. data/demo/{demo_app/Rakefile → Rakefile} +0 -0
  8. data/demo/{demo_app/app → app}/assets/images/rails.png +0 -0
  9. data/demo/{demo_app/app → app}/assets/javascripts/application.js +0 -0
  10. data/demo/{demo_app/app → app}/assets/stylesheets/application.css +0 -0
  11. data/demo/{demo_app/app → app}/controllers/application_controller.rb +0 -0
  12. data/demo/{demo_app/app → app}/helpers/application_helper.rb +0 -0
  13. data/demo/{demo_app/app → app}/mailers/.gitkeep +0 -0
  14. data/demo/{demo_app/app → app}/models/.gitkeep +0 -0
  15. data/demo/{demo_app/app → app}/models/celebrity.rb +0 -0
  16. data/demo/{demo_app/app → app}/models/comment.rb +0 -0
  17. data/demo/app/models/follow.rb +2 -0
  18. data/demo/app/models/like.rb +2 -0
  19. data/demo/app/models/mention.rb +2 -0
  20. data/demo/{demo_app/app → app}/models/movie.rb +0 -0
  21. data/demo/{demo_app/app → app}/models/user.rb +0 -0
  22. data/demo/{demo_app/app → app}/views/layouts/application.html.erb +0 -0
  23. data/demo/{demo_app/config.ru → config.ru} +0 -0
  24. data/demo/{demo_app/config → config}/application.rb +0 -0
  25. data/demo/{demo_app/config → config}/boot.rb +0 -0
  26. data/demo/{demo_app/config → config}/database.yml +0 -0
  27. data/demo/{demo_app/config → config}/environment.rb +0 -0
  28. data/demo/{demo_app/config → config}/environments/development.rb +0 -0
  29. data/demo/{demo_app/config → config}/environments/production.rb +0 -0
  30. data/demo/{demo_app/config → config}/environments/test.rb +0 -0
  31. data/demo/{demo_app/config → config}/initializers/backtrace_silencers.rb +0 -0
  32. data/demo/{demo_app/config → config}/initializers/inflections.rb +0 -0
  33. data/demo/{demo_app/config → config}/initializers/mime_types.rb +0 -0
  34. data/demo/{demo_app/config → config}/initializers/secret_token.rb +0 -0
  35. data/demo/{demo_app/config → config}/initializers/session_store.rb +1 -1
  36. data/demo/{demo_app/config → config}/initializers/wrap_parameters.rb +1 -1
  37. data/demo/{demo_app/config → config}/locales/en.yml +0 -0
  38. data/demo/{demo_app/config → config}/routes.rb +0 -0
  39. data/demo/{demo_app/db → db}/migrate/20120115051222_create_users.rb +0 -0
  40. data/demo/{demo_app/db → db}/migrate/20120115051234_create_movies.rb +0 -0
  41. data/demo/{demo_app/db → db}/migrate/20120115051255_create_celebrities.rb +0 -0
  42. data/demo/{demo_app/db → db}/migrate/20120115054646_create_follows.rb +0 -0
  43. data/demo/{demo_app/db → db}/migrate/20120115054647_create_likes.rb +0 -0
  44. data/demo/{demo_app/db → db}/migrate/20120221200644_create_mentions.rb +0 -0
  45. data/demo/{demo_app/db → db}/migrate/20120221202703_create_comments.rb +0 -0
  46. data/demo/{demo_app/db → db}/schema.rb +0 -1
  47. data/demo/{demo_app/db → db}/seeds.rb +0 -0
  48. data/demo/{demo_app/lib → lib}/assets/.gitkeep +0 -0
  49. data/demo/{demo_app/lib → lib}/tasks/.gitkeep +0 -0
  50. data/demo/{demo_app/public → public}/404.html +0 -0
  51. data/demo/{demo_app/public → public}/422.html +0 -0
  52. data/demo/{demo_app/public → public}/500.html +0 -0
  53. data/demo/{demo_app/public → public}/favicon.ico +0 -0
  54. data/demo/{demo_app/public → public}/index.html +0 -0
  55. data/demo/{demo_app/public → public}/robots.txt +0 -0
  56. data/demo/{demo_app/script → script}/rails +0 -0
  57. data/demo/{demo_app/test → test}/fixtures/.gitkeep +0 -0
  58. data/demo/{demo_app/test → test}/fixtures/celebrities.yml +0 -0
  59. data/demo/{demo_app/test → test}/fixtures/movies.yml +0 -0
  60. data/demo/{demo_app/test → test}/fixtures/users.yml +0 -0
  61. data/demo/{demo_app/test → test}/functional/.gitkeep +0 -0
  62. data/demo/{demo_app/test → test}/integration/.gitkeep +0 -0
  63. data/demo/{demo_app/test → test}/performance/browsing_test.rb +0 -0
  64. data/demo/{demo_app/test → test}/test_helper.rb +0 -0
  65. data/demo/{demo_app/test → test}/unit/.gitkeep +0 -0
  66. data/demo/{demo_app/test → test}/unit/celebrity_test.rb +0 -0
  67. data/demo/{demo_app/test → test}/unit/movie_test.rb +0 -0
  68. data/demo/{demo_app/test → test}/unit/user_test.rb +0 -0
  69. data/demo/{demo_app/vendor → vendor}/assets/javascripts/.gitkeep +0 -0
  70. data/demo/{demo_app/vendor → vendor}/assets/stylesheets/.gitkeep +0 -0
  71. data/demo/{demo_app/vendor → vendor}/plugins/.gitkeep +0 -0
  72. data/lib/generators/socialization/socialization_generator.rb +20 -9
  73. data/{generators/socialization/templates → lib/generators/socialization/templates/active_record}/migration_follows.rb +0 -0
  74. data/{generators/socialization/templates → lib/generators/socialization/templates/active_record}/migration_likes.rb +0 -0
  75. data/{generators/socialization/templates → lib/generators/socialization/templates/active_record}/migration_mentions.rb +0 -0
  76. data/lib/generators/socialization/templates/active_record/model_follow.rb +2 -0
  77. data/lib/generators/socialization/templates/active_record/model_like.rb +2 -0
  78. data/lib/generators/socialization/templates/active_record/model_mention.rb +2 -0
  79. data/lib/socialization.rb +3 -5
  80. data/lib/socialization/actors/follower.rb +74 -0
  81. data/lib/socialization/actors/liker.rb +74 -0
  82. data/lib/socialization/actors/mentioner.rb +74 -0
  83. data/lib/socialization/acts_as_helpers.rb +43 -0
  84. data/lib/socialization/config.rb +45 -0
  85. data/lib/socialization/helpers/string.rb +17 -0
  86. data/lib/socialization/stores/active_record/follow_store.rb +143 -0
  87. data/lib/socialization/stores/active_record/like_store.rb +143 -0
  88. data/lib/socialization/stores/active_record/mention_store.rb +143 -0
  89. data/lib/socialization/stores/redis/base.rb +8 -0
  90. data/lib/socialization/stores/redis/config.rb +11 -0
  91. data/lib/socialization/stores/redis/follow_store.rb +126 -0
  92. data/lib/socialization/stores/redis/like_store.rb +126 -0
  93. data/lib/socialization/stores/redis/mention_store.rb +126 -0
  94. data/lib/socialization/version.rb +1 -1
  95. data/lib/socialization/victims/followable.rb +38 -0
  96. data/lib/socialization/victims/likeable.rb +38 -0
  97. data/lib/socialization/victims/mentionable.rb +38 -0
  98. data/socialization.gemspec +3 -3
  99. data/test/actors/follower_test.rb +74 -0
  100. data/test/actors/liker_test.rb +74 -0
  101. data/test/actors/mentioner_test.rb +74 -0
  102. data/test/stores/active_record/follow_store_test.rb +121 -0
  103. data/test/stores/active_record/like_store_test.rb +121 -0
  104. data/test/stores/active_record/mention_store_test.rb +121 -0
  105. data/test/stores/redis/config_test.rb +30 -0
  106. data/test/stores/redis/follow_store_test.rb +153 -0
  107. data/test/stores/redis/like_store_test.rb +153 -0
  108. data/test/stores/redis/mention_store_test.rb +153 -0
  109. data/test/string_test.rb +13 -0
  110. data/test/test_helper.rb +70 -12
  111. data/test/victims/followable_test.rb +34 -0
  112. data/test/victims/likeable_test.rb +34 -0
  113. data/test/victims/mentionable_test.rb +34 -0
  114. data/test/world_test.rb +80 -69
  115. metadata +261 -176
  116. data/README.rdoc +0 -186
  117. data/demo/demo_app/app/models/follow.rb +0 -3
  118. data/demo/demo_app/app/models/like.rb +0 -3
  119. data/demo/demo_app/app/models/mention.rb +0 -3
  120. data/demo/demo_app/doc/README_FOR_APP +0 -2
  121. data/gemfiles/activerecord30.gemfile +0 -6
  122. data/gemfiles/activerecord30.gemfile.lock +0 -23
  123. data/gemfiles/activerecord31.gemfile +0 -6
  124. data/gemfiles/activerecord31.gemfile.lock +0 -25
  125. data/gemfiles/activerecord32.gemfile +0 -6
  126. data/gemfiles/activerecord32.gemfile.lock +0 -25
  127. data/generators/socialization/USAGE +0 -1
  128. data/generators/socialization/socialization_generator.rb +0 -15
  129. data/generators/socialization/templates/model_follow.rb +0 -3
  130. data/generators/socialization/templates/model_like.rb +0 -3
  131. data/generators/socialization/templates/model_mention.rb +0 -3
  132. data/lib/socialization/follow_store.rb +0 -14
  133. data/lib/socialization/followable.rb +0 -34
  134. data/lib/socialization/follower.rb +0 -50
  135. data/lib/socialization/hello.rb +0 -53
  136. data/lib/socialization/like_store.rb +0 -14
  137. data/lib/socialization/likeable.rb +0 -34
  138. data/lib/socialization/liker.rb +0 -54
  139. data/lib/socialization/mention_store.rb +0 -14
  140. data/lib/socialization/mentionable.rb +0 -36
  141. data/lib/socialization/mentioner.rb +0 -54
  142. data/test/follow_test.rb +0 -125
  143. data/test/like_test.rb +0 -125
  144. data/test/mention_test.rb +0 -116
@@ -1,53 +0,0 @@
1
- require 'active_support/concern'
2
-
3
- %w{followable follower follow_store likeable liker like_store mentionable mentioner mention_store}.each do |f|
4
- require "#{File.dirname(__FILE__)}/#{f}"
5
- end
6
-
7
- module Socialization
8
- module Hello
9
- extend ActiveSupport::Concern
10
-
11
- module ClassMethods
12
- ## Follow
13
- def acts_as_follower(opts = nil)
14
- include Socialization::Follower
15
- end
16
-
17
- def acts_as_followable(opts = nil)
18
- include Socialization::Followable
19
- end
20
-
21
- def acts_as_follow_store(opts = nil)
22
- include Socialization::FollowStore
23
- end
24
-
25
- ## Like
26
- def acts_as_liker(opts = nil)
27
- include Socialization::Liker
28
- end
29
-
30
- def acts_as_likeable(opts = nil)
31
- include Socialization::Likeable
32
- end
33
-
34
- def acts_as_like_store(opts = nil)
35
- include Socialization::LikeStore
36
- end
37
-
38
- ## Mention
39
- def acts_as_mentioner(opts = nil)
40
- include Socialization::Mentioner
41
- end
42
-
43
- def acts_as_mentionable(opts = nil)
44
- include Socialization::Mentionable
45
- end
46
-
47
- def acts_as_mention_store(opts = nil)
48
- include Socialization::MentionStore
49
- end
50
-
51
- end
52
- end
53
- end
@@ -1,14 +0,0 @@
1
- module Socialization
2
- module LikeStore
3
- extend ActiveSupport::Concern
4
-
5
- included do
6
- belongs_to :liker, :polymorphic => true
7
- belongs_to :likeable, :polymorphic => true
8
-
9
- validates_uniqueness_of :likeable_type, :scope => [:likeable_id, :liker_type, :liker_id], :message => 'You cannot like the same thing twice.'
10
-
11
- def self.human_attribute_name(*args); ''; end
12
- end
13
- end
14
- end
@@ -1,34 +0,0 @@
1
- module ActiveRecord
2
- class Base
3
- def is_likeable?
4
- false
5
- end
6
- end
7
- end
8
-
9
- module Socialization
10
- module Likeable
11
- extend ActiveSupport::Concern
12
-
13
- included do
14
- # A liking is the Like record of the liker liking self.
15
- has_many :likings, :as => :likeable, :dependent => :destroy, :class_name => 'Like'
16
-
17
- def is_likeable?
18
- true
19
- end
20
-
21
- def liked_by?(liker)
22
- raise ArgumentError, "#{liker} is not a liker!" unless liker.is_liker?
23
- !self.likings.where(:liker_type => liker.class.to_s, :liker_id => liker.id).empty?
24
- end
25
-
26
- def likers(klass)
27
- klass = klass.to_s.singularize.camelize.constantize unless klass.is_a?(Class)
28
- klass.joins("INNER JOIN likes ON likes.liker_id = #{klass.to_s.tableize}.id AND likes.liker_type = '#{klass.to_s}'").
29
- where("likes.likeable_type = '#{self.class.to_s}'").
30
- where("likes.likeable_id = #{self.id}")
31
- end
32
- end
33
- end
34
- end
@@ -1,54 +0,0 @@
1
- module ActiveRecord
2
- class Base
3
- def is_liker?
4
- false
5
- end
6
- end
7
- end
8
-
9
- module Socialization
10
- module Liker
11
- extend ActiveSupport::Concern
12
-
13
- included do
14
- # A like is the Like record of self liking a likeable record.
15
- has_many :likes, :as => :liker, :dependent => :destroy, :class_name => 'Like'
16
-
17
- def is_liker?
18
- true
19
- end
20
-
21
- def like!(likeable)
22
- ensure_likeable!(likeable)
23
- raise ArgumentError, "#{self} cannot like itself!" unless self != likeable
24
- Like.create!({ :liker => self, :likeable => likeable }, :without_protection => true)
25
- end
26
-
27
- def unlike!(likeable)
28
- ll = likeable.likings.where(:liker_type => self.class.to_s, :liker_id => self.id)
29
- unless ll.empty?
30
- ll.each { |l| l.destroy }
31
- else
32
- raise ActiveRecord::RecordNotFound
33
- end
34
- end
35
-
36
- def likes?(likeable)
37
- ensure_likeable!(likeable)
38
- !self.likes.where(:likeable_type => likeable.class.to_s, :likeable_id => likeable.id).empty?
39
- end
40
-
41
- def likees(klass)
42
- klass = klass.to_s.singularize.camelize.constantize unless klass.is_a?(Class)
43
- klass.joins("INNER JOIN likes ON likes.likeable_id = #{klass.to_s.tableize}.id AND likes.likeable_type = '#{klass.to_s}'").
44
- where("likes.liker_type = '#{self.class.to_s}'").
45
- where("likes.liker_id = #{self.id}")
46
- end
47
-
48
- private
49
- def ensure_likeable!(likeable)
50
- raise ArgumentError, "#{likeable} is not likeable!" unless likeable.is_likeable?
51
- end
52
- end
53
- end
54
- end
@@ -1,14 +0,0 @@
1
- module Socialization
2
- module MentionStore
3
- extend ActiveSupport::Concern
4
-
5
- included do
6
- belongs_to :mentioner, :polymorphic => true
7
- belongs_to :mentionable, :polymorphic => true
8
-
9
- validates_uniqueness_of :mentionable_type, :scope => [:mentionable_id, :mentioner_type, :mentioner_id], :message => 'You cannot mention the same thing twice in a given object.'
10
-
11
- def self.human_attribute_name(*args); ''; end
12
- end
13
- end
14
- end
@@ -1,36 +0,0 @@
1
- module ActiveRecord
2
- class Base
3
- def is_mentionable?
4
- false
5
- end
6
- end
7
- end
8
-
9
- module Socialization
10
- module Mentionable
11
- extend ActiveSupport::Concern
12
-
13
- included do
14
- # A mentioning is the Mention record of describing the mention relationship between
15
- # the mentioner and the mentionable (self).
16
- has_many :mentionings, :as => :mentionable, :dependent => :destroy, :class_name => 'Mention'
17
-
18
- def is_mentionable?
19
- true
20
- end
21
-
22
- def mentioned_by?(mentioner)
23
- raise ArgumentError, "#{mentioner} is not a mentioner!" unless mentioner.is_mentioner?
24
- !self.mentionings.where(:mentioner_type => mentioner.class.to_s, :mentioner_id => mentioner.id).empty?
25
- end
26
-
27
- def mentioners(klass)
28
- klass = klass.to_s.singularize.camelize.constantize unless klass.is_a?(Class)
29
- klass.joins("INNER JOIN mentions ON mentions.mentioner_id = #{klass.to_s.tableize}.id AND mentions.mentioner_type = '#{klass.to_s}'").
30
- where("mentions.mentionable_type = '#{self.class.to_s}'").
31
- where("mentions.mentionable_id = #{self.id}")
32
- end
33
-
34
- end
35
- end
36
- end
@@ -1,54 +0,0 @@
1
- module ActiveRecord
2
- class Base
3
- def is_mentioner?
4
- false
5
- end
6
- end
7
- end
8
-
9
- module Socialization
10
- module Mentioner
11
- extend ActiveSupport::Concern
12
-
13
- included do
14
- # A mention is the Mention record (self) mentionning a mentionable record.
15
- has_many :mentions, :as => :mentioner, :dependent => :destroy, :class_name => 'Mention'
16
-
17
- def is_mentioner?
18
- true
19
- end
20
-
21
- def mention!(mentionable)
22
- ensure_mentionable!(mentionable)
23
- Mention.create!({ :mentioner => self, :mentionable => mentionable }, :without_protection => true)
24
- end
25
-
26
- def unmention!(mentionable)
27
- mm = mentionable.mentionings.where(:mentioner_type => self.class.to_s, :mentioner_id => self.id)
28
- unless mm.empty?
29
- mm.each { |m| m.destroy }
30
- else
31
- raise ActiveRecord::RecordNotFound
32
- end
33
- end
34
-
35
- def mentions?(mentionable)
36
- ensure_mentionable!(mentionable)
37
- !self.mentions.where(:mentionable_type => mentionable.class.to_s, :mentionable_id => mentionable.id).empty?
38
- end
39
-
40
- def mentionees(klass)
41
- klass = klass.to_s.singularize.camelize.constantize unless klass.is_a?(Class)
42
- klass.joins("INNER JOIN mentions ON mentions.mentionable_id = #{klass.to_s.tableize}.id AND mentions.mentionable_type = '#{klass.to_s}'").
43
- where("mentions.mentioner_type = '#{self.class.to_s}'").
44
- where("mentions.mentioner_id = #{self.id}")
45
- end
46
-
47
- private
48
- def ensure_mentionable!(mentionable)
49
- raise ArgumentError, "#{mentionable} is not mentionable!" unless mentionable.is_mentionable?
50
- end
51
-
52
- end
53
- end
54
- end
data/test/follow_test.rb DELETED
@@ -1,125 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__))+'/test_helper'
2
-
3
- class FollowTest < Test::Unit::TestCase
4
- context "a Follower" do
5
- setup do
6
- seed
7
- end
8
-
9
- should "be follower" do
10
- assert_equal true, @follower1.is_follower?
11
- end
12
-
13
- should "be able to follow a Followable" do
14
- assert @follower1.follow!(@followable1)
15
- assert_equal true, @follower1.follows?(@followable1)
16
- assert_equal false, @follower2.follows?(@followable1)
17
- end
18
-
19
- should "be able to unfollow a Followable" do
20
- Follow.create :follower => @follower1, :followable => @followable1
21
- assert @follower1.unfollow!(@followable1)
22
- assert_equal false, @follower1.follows?(@followable1)
23
- end
24
-
25
- should "not be able to follow the same thing twice" do
26
- assert @follower1.follow!(@followable1)
27
-
28
- assert_raise ActiveRecord::RecordInvalid do
29
- @follower1.follow!(@followable1)
30
- end
31
- end
32
-
33
- should "not be able to unfollow something that is not followed" do
34
- assert_raise ActiveRecord::RecordNotFound do
35
- @follower1.unfollow!(@followable1)
36
- end
37
- end
38
-
39
- should "expose a list of its followees" do
40
- Follow.create :follower => @follower1, :followable => @followable1
41
- assert @follower1.followees(ImAFollowable).is_a?(ActiveRecord::Relation)
42
- assert_equal [@followable1], @follower1.followees(ImAFollowable).all
43
-
44
- assert_equal @follower1.followees(ImAFollowable), @follower1.followees(:im_a_followables)
45
- assert_equal @follower1.followees(ImAFollowable), @follower1.followees("im_a_followable")
46
- end
47
- end
48
-
49
- context "a Followable" do
50
- setup do
51
- seed
52
- end
53
-
54
- should "be followable" do
55
- assert_equal true, @followable1.is_followable?
56
- end
57
-
58
- should "be able to determine who follows it" do
59
- Follow.create :follower => @follower1, :followable => @followable1
60
- assert_equal true, @followable1.followed_by?(@follower1)
61
- assert_equal false, @followable1.followed_by?(@follower2)
62
- end
63
-
64
- should "expose a list of its followers" do
65
- Follow.create :follower => @follower1, :followable => @followable1
66
- assert @followable1.followers(ImAFollower).is_a?(ActiveRecord::Relation)
67
- assert_equal [@follower1], @followable1.followers(ImAFollower).all
68
-
69
- assert_equal @followable1.followers(ImAFollower), @followable1.followers(:im_a_followers)
70
- assert_equal @followable1.followers(ImAFollower), @followable1.followers("im_a_follower")
71
- end
72
-
73
- should "expose followings" do
74
- Follow.create :follower => @follower1, :followable => @followable1
75
- followings = @followable1.followings
76
- assert_equal 1, followings.size
77
- assert followings.first.is_a?(Follow)
78
- end
79
- end
80
-
81
- context "Deleting a Follower" do
82
- setup do
83
- seed
84
- @follower1.follow!(@followable1)
85
- end
86
-
87
- should "delete its Follow records" do
88
- @follower1.destroy
89
- assert_equal false, @followable1.followed_by?(@follower1)
90
- end
91
- end
92
-
93
- context "Deleting a Followable" do
94
- setup do
95
- seed
96
- @follower1.follow!(@followable1)
97
- end
98
-
99
- should "delete its Follow records" do
100
- @followable1.destroy
101
- assert_equal false, @follower1.follows?(@followable1)
102
- end
103
- end
104
-
105
- context "Virgin ActiveRecord::Base objects" do
106
- setup do
107
- @foo = Vanilla.new
108
- end
109
-
110
- should "not be follower" do
111
- assert_equal false, @foo.is_follower?
112
- end
113
-
114
- should "not be followable" do
115
- assert_equal false, @foo.is_followable?
116
- end
117
- end
118
-
119
- def seed
120
- @follower1 = ImAFollower.create
121
- @follower2 = ImAFollower.create
122
- @followable1 = ImAFollowable.create
123
- @followable2 = ImAFollowable.create
124
- end
125
- end
data/test/like_test.rb DELETED
@@ -1,125 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__))+'/test_helper'
2
-
3
- class LikeTest < Test::Unit::TestCase
4
- context "a Liker" do
5
- setup do
6
- seed
7
- end
8
-
9
- should "be liker" do
10
- assert_equal true, @liker1.is_liker?
11
- end
12
-
13
- should "be able to like a Likeable" do
14
- assert @liker1.like!(@likeable1)
15
- assert_equal true, @liker1.likes?(@likeable1)
16
- assert_equal false, @liker2.likes?(@likeable1)
17
- end
18
-
19
- should "be able to unlike a Likeable" do
20
- Like.create :liker => @liker1, :likeable => @likeable1
21
- assert @liker1.unlike!(@likeable1)
22
- assert_equal false, @liker1.likes?(@likeable1)
23
- end
24
-
25
- should "not be able to like the same thing twice" do
26
- assert @liker1.like!(@likeable1)
27
-
28
- assert_raise ActiveRecord::RecordInvalid do
29
- @liker1.like!(@likeable1)
30
- end
31
- end
32
-
33
- should "not be able to unlike something that is not liked" do
34
- assert_raise ActiveRecord::RecordNotFound do
35
- @liker1.unlike!(@likeable1)
36
- end
37
- end
38
-
39
- should "expose a list of its likes" do
40
- Like.create :liker => @liker1, :likeable => @likeable1
41
- assert @liker1.likees(ImALikeable).is_a?(ActiveRecord::Relation)
42
- assert_equal [@likeable1], @liker1.likees(ImALikeable).all
43
-
44
- assert_equal @liker1.likees(ImALikeable), @liker1.likees(:im_a_likeables)
45
- assert_equal @liker1.likees(ImALikeable), @liker1.likees("im_a_likeable")
46
- end
47
- end
48
-
49
- context "a Likeable" do
50
- setup do
51
- seed
52
- end
53
-
54
- should "be likeable" do
55
- assert_equal true, @likeable1.is_likeable?
56
- end
57
-
58
- should "be able to determine who likes it" do
59
- Like.create :liker => @liker1, :likeable => @likeable1
60
- assert_equal true, @likeable1.liked_by?(@liker1)
61
- assert_equal false, @likeable1.liked_by?(@liker2)
62
- end
63
-
64
- should "expose a list of its likers" do
65
- Like.create :liker => @liker1, :likeable => @likeable1
66
- assert @likeable1.likers(ImALiker).is_a?(ActiveRecord::Relation)
67
- assert_equal [@liker1], @likeable1.likers(ImALiker).all
68
-
69
- assert_equal @likeable1.likers(ImALiker), @likeable1.likers(:im_a_likers)
70
- assert_equal @likeable1.likers(ImALiker), @likeable1.likers("im_a_liker")
71
- end
72
-
73
- should "expose likings" do
74
- Like.create :liker => @liker1, :likeable => @likeable1
75
- likings = @likeable1.likings
76
- assert_equal 1, likings.size
77
- assert likings.first.is_a?(Like)
78
- end
79
- end
80
-
81
- context "Deleting a Liker" do
82
- setup do
83
- seed
84
- @liker1.like!(@likeable1)
85
- end
86
-
87
- should "delete its Like records" do
88
- @liker1.destroy
89
- assert_equal false, @likeable1.liked_by?(@liker1)
90
- end
91
- end
92
-
93
- context "Deleting a Likeable" do
94
- setup do
95
- seed
96
- @liker1.like!(@likeable1)
97
- end
98
-
99
- should "delete its Like records" do
100
- @likeable1.destroy
101
- assert_equal false, @liker1.likes?(@likeable1)
102
- end
103
- end
104
-
105
- context "Virgin ActiveRecord::Base objects" do
106
- setup do
107
- @foo = Vanilla.new
108
- end
109
-
110
- should "not be liker" do
111
- assert_equal false, @foo.is_liker?
112
- end
113
-
114
- should "not be likeable" do
115
- assert_equal false, @foo.is_likeable?
116
- end
117
- end
118
-
119
- def seed
120
- @liker1 = ImALiker.create
121
- @liker2 = ImALiker.create
122
- @likeable1 = ImALikeable.create
123
- @likeable2 = ImALikeable.create
124
- end
125
- end