amistad 0.7.1 → 0.7.2

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/CHANGELOG CHANGED
@@ -1,3 +1,9 @@
1
+ Version 0.7.2 (16.02.2011)
2
+ --------------------------
3
+ - Added total_friends() and total_blocked() which count friendships and blocks without loading associations (by David Czarnecki)
4
+ - Added namespaced rake tasks spec:activerecord and spec:mongoid (suggested by Adrian Dulić)
5
+ - Use fuubar
6
+
1
7
  Version 0.7.1 (12.02.2011)
2
8
  --------------------------
3
9
  - Totally mess the previous relase. This one fix it.
data/README.markdown CHANGED
@@ -28,7 +28,7 @@ It also creates a new migration for the friendship model so don't forget to migr
28
28
 
29
29
  rake db:migrate
30
30
 
31
- If you are using Mongoig, you don't need a friendship model. Finally, activate __amistad__ in your user model :
31
+ If you are using Mongoid, you don't need a friendship model. Finally, activate __amistad__ in your user model :
32
32
 
33
33
  class User < ActiveRecord::Base
34
34
  include Amistad::FriendModel
@@ -139,17 +139,18 @@ The __unblock()__ method allow a user to unblock previously blocked friendship w
139
139
  @jane.unblock @john
140
140
  @jane.blocked #=> []
141
141
 
142
- ## Testing the gem ##
142
+ ## Testing ##
143
143
 
144
- It is possible to test amistad by running the following command from the gem directory:
144
+ It is possible to test amistad by running one of the following commands from the gem directory:
145
145
 
146
- rake spec
146
+ rake spec:activerecord # activerecord tests
147
+ rake spec:mongoid # mongoid tests
147
148
 
148
- Remember that amistad is only compatible with ActiveRecord 3.x.
149
+ Remember that amistad is only compatible with ActiveRecord 3.x and Mongoid.
149
150
 
150
- ## Acknowledgement ##
151
+ ## Contributors ##
151
152
 
152
- * David Czarnecki : block friendships
153
+ * David Czarnecki : block friendships (and many other improvements)
153
154
  * Adrian Dulić : unblock friendships (and many other improvements)
154
155
 
155
156
  ## Note on Patches/Pull Requests ##
data/Rakefile CHANGED
@@ -4,4 +4,15 @@ Bundler::GemHelper.install_tasks
4
4
  require 'rspec'
5
5
  require 'rspec/core/rake_task'
6
6
 
7
- Rspec::Core::RakeTask.new(:spec)
7
+ namespace :spec do
8
+ Rspec::Core::RakeTask.new(:activerecord) do |t|
9
+ t.pattern = "./spec/activerecord/**/*_spec.rb"
10
+ t.rspec_opts = "--format Fuubar"
11
+ end
12
+
13
+ Rspec::Core::RakeTask.new(:mongoid) do |t|
14
+ t.pattern = "./spec/mongoid/**/*_spec.rb"
15
+ t.rspec_opts = "--format Fuubar"
16
+ end
17
+ end
18
+
data/amistad.gemspec CHANGED
@@ -20,6 +20,7 @@ Gem::Specification.new do |s|
20
20
  s.add_development_dependency "sqlite3-ruby", "1.3.2"
21
21
  s.add_development_dependency "mongoid", "~> 2.0.0.rc.7"
22
22
  s.add_development_dependency "bson_ext", "~> 1.2"
23
+ s.add_development_dependency "fuubar", "~> 0.0.3"
23
24
 
24
25
  s.files = `git ls-files`.split("\n")
25
26
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
@@ -8,38 +8,38 @@ module Amistad
8
8
  has_many :friendships
9
9
 
10
10
  has_many :pending_invited,
11
- :through => :friendships,
12
- :source => :friend,
13
- :conditions => { :'friendships.pending' => true, :'friendships.blocker_id' => nil }
11
+ :through => :friendships,
12
+ :source => :friend,
13
+ :conditions => { :'friendships.pending' => true, :'friendships.blocker_id' => nil }
14
14
 
15
15
  has_many :invited,
16
- :through => :friendships,
17
- :source => :friend,
18
- :conditions => { :'friendships.pending' => false, :'friendships.blocker_id' => nil }
16
+ :through => :friendships,
17
+ :source => :friend,
18
+ :conditions => { :'friendships.pending' => false, :'friendships.blocker_id' => nil }
19
19
 
20
20
  has_many :inverse_friendships, :class_name => "Friendship", :foreign_key => "friend_id"
21
21
 
22
22
  has_many :pending_invited_by,
23
- :through => :inverse_friendships,
24
- :source => :user,
25
- :conditions => { :'friendships.pending' => true, :'friendships.blocker_id' => nil }
23
+ :through => :inverse_friendships,
24
+ :source => :user,
25
+ :conditions => { :'friendships.pending' => true, :'friendships.blocker_id' => nil }
26
26
 
27
27
  has_many :invited_by,
28
- :through => :inverse_friendships,
29
- :source => :user,
30
- :conditions => { :'friendships.pending' => false, :'friendships.blocker_id' => nil }
28
+ :through => :inverse_friendships,
29
+ :source => :user,
30
+ :conditions => { :'friendships.pending' => false, :'friendships.blocker_id' => nil }
31
31
 
32
32
  has_many :blocked_friendships, :class_name => "Friendship", :foreign_key => "blocker_id"
33
33
 
34
34
  has_many :blockades,
35
- :through => :blocked_friendships,
36
- :source => :friend,
37
- :conditions => "friend_id <> blocker_id"
35
+ :through => :blocked_friendships,
36
+ :source => :friend,
37
+ :conditions => "friend_id <> blocker_id"
38
38
 
39
39
  has_many :blockades_by,
40
- :through => :blocked_friendships,
41
- :source => :user,
42
- :conditions => "user_id <> blocker_id"
40
+ :through => :blocked_friendships,
41
+ :source => :user,
42
+ :conditions => "user_id <> blocker_id"
43
43
  end
44
44
  end
45
45
 
@@ -69,6 +69,11 @@ module Amistad
69
69
  self.invited(true) + self.invited_by(true)
70
70
  end
71
71
 
72
+ # total # of invited and invited_by without association loading
73
+ def total_friends
74
+ self.invited(false).count + self.invited_by(false).count
75
+ end
76
+
72
77
  # blocks a friendship
73
78
  def block(user)
74
79
  friendship = find_any_friendship_with(user)
@@ -88,6 +93,11 @@ module Amistad
88
93
  self.blockades(true) + self.blockades_by(true)
89
94
  end
90
95
 
96
+ # total # of blockades and blockedes_by without association loading
97
+ def total_blocked
98
+ self.blockades(false).count + self.blockades_by(false).count
99
+ end
100
+
91
101
  # checks if a user is blocked
92
102
  def blocked?(user)
93
103
  blocked.include?(user)
@@ -9,12 +9,12 @@ module Amistad
9
9
  field :inverse_friend_ids, :type => Array, :default => []
10
10
  field :pending_friend_ids, :type => Array, :default => []
11
11
  field :pending_inverse_friend_ids, :type => Array, :default => []
12
-
12
+
13
13
  field :blocked_friend_ids, :type => Array, :default => []
14
14
  field :blocked_inverse_friend_ids, :type => Array, :default => []
15
15
  field :blocked_pending_friend_ids, :type => Array, :default => []
16
16
  field :blocked_pending_inverse_friend_ids, :type => Array, :default => []
17
-
17
+
18
18
  attr_accessible :friend_ids, :inverse_friend_ids, :pending_friend_ids, :pending_inverse_friend_ids, :blocked_friend_ids, :blocked_inverse_friend_ids, :blocked_pending_friend_ids, :blocked_pending_inverse_friend_ids
19
19
  end
20
20
  end
@@ -43,6 +43,11 @@ module Amistad
43
43
  self.invited + self.invited_by
44
44
  end
45
45
 
46
+ # total # of invited and invited_by without association loading
47
+ def total_friends
48
+ (friend_ids + inverse_friend_ids).count
49
+ end
50
+
46
51
  # return the list of invited friends
47
52
  def invited
48
53
  self.class.find(friend_ids)
@@ -119,7 +124,7 @@ module Amistad
119
124
  else
120
125
  return false
121
126
  end
122
-
127
+
123
128
  self.save
124
129
  end
125
130
 
@@ -142,16 +147,21 @@ module Amistad
142
147
  else
143
148
  return false
144
149
  end
145
-
150
+
146
151
  self.save && user.save
147
152
  end
148
-
153
+
149
154
  # returns the list of blocked friends
150
155
  def blocked
151
156
  blocked_ids = blocked_friend_ids + blocked_inverse_friend_ids + blocked_pending_inverse_friend_ids
152
157
  self.class.find(blocked_ids)
153
158
  end
154
159
 
160
+ # total # of blockades and blockedes_by without association loading
161
+ def total_blocked
162
+ (blocked_friend_ids + blocked_inverse_friend_ids + blocked_pending_inverse_friend_ids).count
163
+ end
164
+
155
165
  # checks if a user is blocked
156
166
  def blocked?(user)
157
167
  (blocked_friend_ids + blocked_inverse_friend_ids + blocked_pending_inverse_friend_ids).include?(user.id) or user.blocked_pending_inverse_friend_ids.include?(self.id)
@@ -1,3 +1,3 @@
1
1
  module Amistad
2
- VERSION = "0.7.1"
2
+ VERSION = "0.7.2"
3
3
  end
@@ -1,4 +1,4 @@
1
- require 'activerecord_spec_helper'
1
+ require File.dirname(__FILE__) + "/activerecord_spec_helper"
2
2
 
3
3
  describe Amistad::ActiveRecord::FriendModel do
4
4
  def reset_friendships
@@ -1,4 +1,4 @@
1
- require 'activerecord_spec_helper'
1
+ require File.dirname(__FILE__) + "/activerecord_spec_helper"
2
2
 
3
3
  describe Amistad::ActiveRecord::FriendshipModel do
4
4
 
@@ -1,4 +1,4 @@
1
- require 'mongoid_spec_helper'
1
+ require File.dirname(__FILE__) + '/mongoid_spec_helper'
2
2
 
3
3
  describe Amistad::Mongoid::FriendModel do
4
4
  def reset_friendships
@@ -389,4 +389,33 @@ shared_examples_for "a friend model" do
389
389
  @david.pending_invited_by.should == [@victoria]
390
390
  end
391
391
  end
392
+
393
+ context "when counting friendships and blocks" do
394
+ before do
395
+ reset_friendships
396
+ @john.invite(@james).should be_true
397
+ @james.approve(@john).should be_true
398
+ @john.invite(@victoria).should be_true
399
+ @victoria.approve(@john).should be_true
400
+ @elisabeth.invite(@john).should be_true
401
+ @john.approve(@elisabeth).should be_true
402
+
403
+ @victoria.invite(@david).should be_true
404
+ @david.block(@victoria).should be_true
405
+ @mary.invite(@victoria).should be_true
406
+ @victoria.block(@mary).should be_true
407
+ end
408
+
409
+ it "should return the correct count for total_friends" do
410
+ @john.total_friends.should == 3
411
+ @elisabeth.total_friends.should == 1
412
+ @james.total_friends.should == 1
413
+ @victoria.total_friends.should == 1
414
+ end
415
+
416
+ it "should return the correct count for total_blocked" do
417
+ @david.total_blocked.should == 1
418
+ @victoria.total_blocked.should == 1
419
+ end
420
+ end
392
421
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: amistad
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.7.1
5
+ version: 0.7.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Rawane ZOSSOU
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-02-12 00:00:00 +01:00
13
+ date: 2011-02-16 00:00:00 +01:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -79,6 +79,17 @@ dependencies:
79
79
  version: "1.2"
80
80
  type: :development
81
81
  version_requirements: *id006
82
+ - !ruby/object:Gem::Dependency
83
+ name: fuubar
84
+ prerelease: false
85
+ requirement: &id007 !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ~>
89
+ - !ruby/object:Gem::Version
90
+ version: 0.0.3
91
+ type: :development
92
+ version_requirements: *id007
82
93
  description: Extends your user model with friendships management methods
83
94
  email:
84
95
  - dev@raw1z.fr
@@ -106,11 +117,11 @@ files:
106
117
  - lib/generators/amistad/install/install_generator.rb
107
118
  - lib/generators/amistad/install/templates/create_friendships.rb
108
119
  - lib/generators/amistad/install/templates/friendship.rb
109
- - spec/activerecord_friend_model_spec.rb
110
- - spec/activerecord_friendship_model_spec.rb
111
- - spec/activerecord_spec_helper.rb
112
- - spec/mongoid_friend_model_spec.rb
113
- - spec/mongoid_spec_helper.rb
120
+ - spec/activerecord/activerecord_friend_model_spec.rb
121
+ - spec/activerecord/activerecord_friendship_model_spec.rb
122
+ - spec/activerecord/activerecord_spec_helper.rb
123
+ - spec/mongoid/mongoid_friend_model_spec.rb
124
+ - spec/mongoid/mongoid_spec_helper.rb
114
125
  - spec/spec_helper.rb
115
126
  - spec/support/friend_examples.rb
116
127
  has_rdoc: true
@@ -142,10 +153,10 @@ signing_key:
142
153
  specification_version: 3
143
154
  summary: Adds friendships management into a rails 3.0 application
144
155
  test_files:
145
- - spec/activerecord_friend_model_spec.rb
146
- - spec/activerecord_friendship_model_spec.rb
147
- - spec/activerecord_spec_helper.rb
148
- - spec/mongoid_friend_model_spec.rb
149
- - spec/mongoid_spec_helper.rb
156
+ - spec/activerecord/activerecord_friend_model_spec.rb
157
+ - spec/activerecord/activerecord_friendship_model_spec.rb
158
+ - spec/activerecord/activerecord_spec_helper.rb
159
+ - spec/mongoid/mongoid_friend_model_spec.rb
160
+ - spec/mongoid/mongoid_spec_helper.rb
150
161
  - spec/spec_helper.rb
151
162
  - spec/support/friend_examples.rb