acts_as_followable 0.1.7 → 0.1.8

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.
data/README.rdoc CHANGED
@@ -17,8 +17,12 @@ Run the generator which will generate a migration file.
17
17
  rails g acts_as_followable
18
18
  rake db:migrate
19
19
 
20
- The plugin comes with a Follow model file. You can override the default model definition by creating a new
21
- app/models/follow.rb file. You can copy the content of a model from {here}[https://github.com/xpepermint/acts_as_followable/blob/master/app/models/follow.rb].
20
+ The plugin comes with a Follow model file. You can extend the default model by creating the
21
+ app/models/follow.rb file with content.
22
+
23
+ class Follow
24
+ ... your extension here ...
25
+ end
22
26
 
23
27
  == Setup
24
28
 
@@ -116,3 +120,4 @@ You can also query Follow model records like this:
116
120
 
117
121
  * {xpepermint}[http://github.com/xpepermint] (Author)
118
122
  * {afhammad}[http://github.com/afhammad]
123
+ * (jeanmartin)[http://github.com/jeanmartin]
@@ -1,9 +1,6 @@
1
1
  %w( acts_as_followable/version
2
- acts_as_followable/followable
3
- ../app/models/follow
2
+ acts_as_followable/followable
3
+ acts_as_followable/railtie
4
4
  ).each do |lib|
5
5
  require File.join(File.dirname(__FILE__), lib)
6
- end
7
- require File.join(Rails.root||RAILS_ROOT, 'app', 'models', 'follow') rescue nil
8
-
9
- ActiveRecord::Base.send(:include, ActsAsFollowable::Followable)
6
+ end
@@ -0,0 +1,24 @@
1
+ require 'rails'
2
+
3
+ module ActsAsFollowable
4
+ if defined? Rails::Railtie
5
+ class Railtie < Rails::Railtie
6
+ initializer "acts_as_followable.extend_action_controller_base" do |app|
7
+ ActiveSupport.on_load(:active_record) do
8
+ ActsAsFollowable::Railtie.insert
9
+ end
10
+ end
11
+ end
12
+ end
13
+
14
+ class Railtie
15
+ def self.insert
16
+ require File.join(File.dirname(__FILE__), '..', '..', 'app', 'models', 'follow')
17
+ begin
18
+ require File.join(Rails.root||RAILS_ROOT, 'app', 'models', 'follow')
19
+ rescue LoadError
20
+ end
21
+ ActiveRecord::Base.send(:include, ActsAsFollowable::Followable)
22
+ end
23
+ end
24
+ end
@@ -2,7 +2,7 @@ module ActsAsFollowable
2
2
  module Version
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
- TINY = 7
5
+ TINY = 8
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -8,8 +8,8 @@ class ActsAsFollowableTest < ActiveSupport::TestCase
8
8
  end
9
9
 
10
10
  should "be defined" do
11
- assert @sam.respond_to?(:followers_count)
12
- assert @sam.respond_to?(:followers)
11
+ assert @sam.respond_to?(:followings)
12
+ assert @sam.respond_to?(:follows)
13
13
  assert @sam.respond_to?(:followed_by?)
14
14
  end
15
15
  end
@@ -25,46 +25,40 @@ class ActsAsFollowableTest < ActiveSupport::TestCase
25
25
 
26
26
  context "followers_count" do
27
27
  should "return the number of followers" do
28
- assert_equal 0, @sam.followers_count
29
- assert_equal 1, @jon.followers_count
28
+ assert_equal 0, @sam.followings.count
29
+ assert_equal 1, @jon.followings.count
30
30
  end
31
31
 
32
32
  should "return the proper number of multiple followers" do
33
33
  @bob = Factory(:bob)
34
34
  @sam.follow(@bob)
35
- assert_equal 0, @sam.followers_count
36
- assert_equal 1, @jon.followers_count
37
- assert_equal 1, @bob.followers_count
35
+ assert_equal 0, @sam.followings.count
36
+ assert_equal 1, @jon.followings.count
37
+ assert_equal 1, @bob.followings.count
38
38
  end
39
39
  end
40
40
 
41
41
  context "followers" do
42
42
  should "return users" do
43
- assert_equal [], @sam.followers
44
- assert_equal [@sam], @jon.followers
43
+ assert_equal [], User.following(@sam)
44
+ assert_equal [@sam], User.following(@jon)
45
45
  end
46
46
 
47
47
  should "return users (multiple followers)" do
48
48
  @bob = Factory(:bob)
49
49
  @sam.follow(@bob)
50
- assert_equal [], @sam.followers
51
- assert_equal [@sam], @jon.followers
52
- assert_equal [@sam], @bob.followers
50
+ assert_equal [], @sam.followings
51
+ assert_equal [@sam], User.following(@jon)
52
+ assert_equal [@sam], User.following(@bob)
53
53
  end
54
54
 
55
55
  should "return users (multiple followers, complex)" do
56
56
  @bob = Factory(:bob)
57
57
  @sam.follow(@bob)
58
58
  @jon.follow(@bob)
59
- assert_equal [], @sam.followers
60
- assert_equal [@sam], @jon.followers
61
- assert_equal [@sam, @jon], @bob.followers
62
- end
63
-
64
- should "accept AR options" do
65
- @bob = Factory(:bob)
66
- @bob.follow(@jon)
67
- assert_equal 1, @jon.followers(:limit => 1).count
59
+ assert_equal [], User.following(@sam)
60
+ assert_equal [@sam], User.following(@jon)
61
+ assert_equal [@sam, @jon], User.following(@bob)
68
62
  end
69
63
  end
70
64
 
@@ -76,110 +70,12 @@ class ActsAsFollowableTest < ActiveSupport::TestCase
76
70
  end
77
71
 
78
72
  context "destroying a followable" do
79
- setup do
73
+ should "also destroy the Follow" do
74
+ assert_equal 1, Follow.count
75
+ assert_equal 1, @sam.follows.count
80
76
  @jon.destroy
81
- end
82
-
83
- should_change("follow count", :by => -1) { Follow.count }
84
- should_change("@sam.all_following.size", :by => -1) { @sam.all_following.size }
85
- end
86
-
87
- context "blocks" do
88
- setup do
89
- @bob = Factory(:bob)
90
- @jon.block(@sam)
91
- @jon.block(@bob)
92
- end
93
-
94
- should "accept AR options" do
95
- assert_equal 1, @jon.blocks(:limit => 1).count
96
- end
97
- end
98
-
99
- context "blocking a follower" do
100
- context "in my following list" do
101
- setup do
102
- @jon.block(@sam)
103
- end
104
-
105
- should "remove him from followers" do
106
- assert_equal 0, @jon.followers_count
107
- end
108
-
109
- should "add him to the blocked followers" do
110
- assert_equal 1, @jon.blocked_followers_count
111
- end
112
-
113
- should "not be able to follow again" do
114
- @jon.follow(@sam)
115
- assert_equal 0, @jon.followers_count
116
- end
117
-
118
- should "not be present when listing followers" do
119
- assert_equal [], @jon.followers
120
- end
121
-
122
- should "be in the list of blocks" do
123
- assert_equal [@sam], @jon.blocks
124
- end
125
- end
126
-
127
- context "not in my following list" do
128
- setup do
129
- @sam.block(@jon)
130
- end
131
-
132
- should "add him to the blocked followers" do
133
- assert_equal 1, @sam.blocked_followers_count
134
- end
135
-
136
- should "not be able to follow again" do
137
- @sam.follow(@jon)
138
- assert_equal 0, @sam.followers_count
139
- end
140
-
141
- should "not be present when listing followers" do
142
- assert_equal [], @sam.followers
143
- end
144
-
145
- should "be in the list of blocks" do
146
- assert_equal [@jon], @sam.blocks
147
- end
148
- end
149
- end
150
-
151
- context "unblocking a blocked follow" do
152
- setup do
153
- @jon.block(@sam)
154
- @jon.unblock(@sam)
155
- end
156
-
157
- should "not include the unblocked user in the list of followers" do
158
- assert_equal [], @jon.followers
159
- end
160
-
161
- should "remove him from the blocked followers" do
162
- assert_equal 0, @jon.blocked_followers_count
163
- assert_equal [], @jon.blocks
164
- end
165
- end
166
-
167
- context "unblock a non-existent follow" do
168
- setup do
169
- @sam.stop_following(@jon)
170
- @jon.unblock(@sam)
171
- end
172
-
173
- should "not be in the list of followers" do
174
- assert_equal [], @jon.followers
175
- end
176
-
177
- should "not be in the blockked followers count" do
178
- assert_equal 0, @jon.blocked_followers_count
179
- end
180
-
181
- should "not be in the blocks list" do
182
- assert_equal [], @jon.blocks
77
+ assert_equal 0, Follow.count
78
+ assert_equal 0, @sam.follows.count
183
79
  end
184
80
  end
185
81
 
@@ -194,19 +90,9 @@ class ActsAsFollowableTest < ActiveSupport::TestCase
194
90
  assert_equal [@sam,@jon], @oasis.followers_by_type('User')
195
91
  end
196
92
 
197
- should "not return block followers in the followers for a given type" do
198
- @oasis.block(@jon)
199
- assert_equal [@sam], @oasis.followers_by_type('User')
200
- end
201
-
202
93
  should "return the count for followers_by_type_count for a given type" do
203
- assert_equal 1, @jon.followers_by_type_count('User')
204
- assert_equal 2, @oasis.followers_by_type_count('User')
205
- end
206
-
207
- should "not count blocked follows in the count" do
208
- @oasis.block(@sam)
209
- assert_equal 1, @oasis.followers_by_type_count('User')
94
+ assert_equal 1, @jon.followers_by_type('User').count
95
+ assert_equal 2, @oasis.followers_by_type('User').count
210
96
  end
211
97
  end
212
98
 
@@ -221,19 +107,9 @@ class ActsAsFollowableTest < ActiveSupport::TestCase
221
107
  assert_equal [@sam,@jon], @oasis.user_followers
222
108
  end
223
109
 
224
- should "not return block followers in the followers for a given type" do
225
- @oasis.block(@jon)
226
- assert_equal [@sam], @oasis.user_followers
227
- end
228
-
229
110
  should "return the count for followers_by_type_count for a given type" do
230
- assert_equal 1, @jon.count_user_followers
231
- assert_equal 2, @oasis.count_user_followers
232
- end
233
-
234
- should "not count blocked follows in the count" do
235
- @oasis.block(@sam)
236
- assert_equal 1, @oasis.count_user_followers
111
+ assert_equal 1, @jon.user_followers.count
112
+ assert_equal 2, @oasis.user_followers.count
237
113
  end
238
114
  end
239
115
  end
@@ -0,0 +1,8 @@
1
+
2
+ Factory.define :oasis, :class => Band do |b|
3
+ b.name 'Oasis'
4
+ end
5
+
6
+ Factory.define :metallica, :class => Band do |b|
7
+ b.name 'Metallica'
8
+ end
@@ -0,0 +1,13 @@
1
+
2
+ Factory.define :sam, :class => User do |u|
3
+ u.name 'Sam'
4
+ end
5
+
6
+ Factory.define :jon, :class => User do |u|
7
+ u.name 'Jon'
8
+ end
9
+
10
+
11
+ Factory.define :bob, :class => User do |u|
12
+ u.name 'Bob'
13
+ end
data/test/test_helper.rb CHANGED
@@ -1,19 +1,28 @@
1
+ ENV["RAILS_ENV"] = "test"
2
+
1
3
  require 'rubygems'
4
+ require 'test/unit'
5
+ require 'shoulda'
2
6
  require 'logger'
7
+
8
+ gem 'activerecord', '~>3.0.0'
9
+ gem 'activesupport', '~>3.0.0'
10
+ gem 'actionpack', '~>3.0.0'
11
+
3
12
  require 'active_record'
13
+ require 'active_record/version'
14
+ require 'active_support'
15
+
16
+ require 'acts_as_followable'
17
+ require File.dirname(__FILE__) + '/../rails/init'
18
+ require File.dirname(__FILE__) + '/models/band'
19
+ require File.dirname(__FILE__) + '/models/user'
20
+ require File.dirname(__FILE__) + '/../app/models/follow.rb'
4
21
 
5
22
  ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + '/debug.log')
6
23
  ActiveRecord::Base.configurations = YAML::load(File.open(File.dirname(__FILE__) + '/database.yml'))
7
24
  ActiveRecord::Base.establish_connection(ENV['DB'] || 'mysql')
8
25
 
9
- require File.dirname(__FILE__) + '/../init.rb'
10
- require File.dirname(__FILE__) + '/models/band'
11
- require File.dirname(__FILE__) + '/models/user'
12
- require File.dirname(__FILE__) + '/../lib/generators/templates/model.rb'
13
-
14
- require 'test/unit'
15
- require 'active_support'
16
- require 'shoulda'
17
26
  require 'factory_girl'
18
27
  Factory.find_definitions
19
28
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_followable
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 11
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 7
10
- version: 0.1.7
9
+ - 8
10
+ version: 0.1.8
11
11
  platform: ruby
12
12
  authors:
13
13
  - Kristijan Sedlak
@@ -15,8 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-03-09 00:00:00 +01:00
19
- default_executable:
18
+ date: 2011-03-09 00:00:00 Z
20
19
  dependencies: []
21
20
 
22
21
  description: Implements the following functionality where one model can be followed by other models and and vice versa.
@@ -32,6 +31,7 @@ files:
32
31
  - Rakefile
33
32
  - app/models/follow.rb
34
33
  - lib/acts_as_followable/followable.rb
34
+ - lib/acts_as_followable/railtie.rb
35
35
  - lib/acts_as_followable/version.rb
36
36
  - lib/acts_as_followable.rb
37
37
  - lib/generators/acts_as_followable_generator.rb
@@ -49,7 +49,6 @@ files:
49
49
  - test/TESTING
50
50
  - README.rdoc
51
51
  - MIT-LICENSE
52
- has_rdoc: true
53
52
  homepage: http://github.com/xpepermint/acts_as_followable
54
53
  licenses: []
55
54
 
@@ -81,7 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
81
80
  requirements: []
82
81
 
83
82
  rubyforge_project:
84
- rubygems_version: 1.6.1
83
+ rubygems_version: 1.7.2
85
84
  signing_key:
86
85
  specification_version: 3
87
86
  summary: ActsAsFollowable - Model following.