amistad 0.4.1 → 0.5.0

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.markdown CHANGED
@@ -98,6 +98,17 @@ The __remove()__ method allow a user to remove its friendships :
98
98
  @john.remove @peter
99
99
  @john.remove @victoria
100
100
 
101
+ ### Blocking friendships ###
102
+
103
+ The __block()__ method allow a user to block a friendship with another user :
104
+
105
+ @john.invite @jane
106
+ @jane.block @john
107
+
108
+ To get the blocked users :
109
+
110
+ @jane.blocked #=> [@john]
111
+
101
112
  ## Testing the gem ##
102
113
 
103
114
  It is possible to test amistad by running the following command from the gem directory:
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.1
1
+ 0.5.0
@@ -9,24 +9,29 @@ module Amistad
9
9
  has_many :pending_invited,
10
10
  :through => :friendships,
11
11
  :source => :friend,
12
- :conditions => { :'friendships.pending' => true }
12
+ :conditions => { :'friendships.pending' => true, :'friendships.blocked' => false }
13
13
 
14
14
  has_many :invited,
15
15
  :through => :friendships,
16
16
  :source => :friend,
17
- :conditions => { :'friendships.pending' => false }
17
+ :conditions => { :'friendships.pending' => false, :'friendships.blocked' => false }
18
18
 
19
19
  has_many :inverse_friendships, :class_name => "Friendship", :foreign_key => "friend_id"
20
20
 
21
21
  has_many :pending_invited_by,
22
22
  :through => :inverse_friendships,
23
23
  :source => :user,
24
- :conditions => {:'friendships.pending' => true}
24
+ :conditions => { :'friendships.pending' => true, :'friendships.blocked' => false }
25
25
 
26
26
  has_many :invited_by,
27
27
  :through => :inverse_friendships,
28
28
  :source => :user,
29
- :conditions => {:'friendships.pending' => false}
29
+ :conditions => { :'friendships.pending' => false, :'friendships.blocked' => false }
30
+
31
+ has_many :blocked,
32
+ :through => :inverse_friendships,
33
+ :source => :user,
34
+ :conditions => { :'friendships.blocked' => true }
30
35
  end
31
36
  end
32
37
 
@@ -55,6 +60,15 @@ module Amistad
55
60
  self.invited(true) + self.invited_by(true)
56
61
  end
57
62
 
63
+ # blocks a friendship request
64
+ def block(user)
65
+ friendship = find_any_friendship_with(user)
66
+ return false if friendship.nil?
67
+ friendship.blocked = true
68
+ friendship.pending = false
69
+ friendship.save
70
+ end
71
+
58
72
  # deletes a friendship
59
73
  def remove(user)
60
74
  friendship = find_any_friendship_with(user)
@@ -18,6 +18,11 @@ module Amistad
18
18
  def pending?
19
19
  self.pending
20
20
  end
21
+
22
+ # returns true if a friendship has been blocked, else false
23
+ def blocked?
24
+ self.blocked
25
+ end
21
26
  end
22
27
 
23
28
  end
@@ -4,6 +4,7 @@ class CreateFriendships < ActiveRecord::Migration
4
4
  t.integer :user_id
5
5
  t.integer :friend_id
6
6
  t.boolean :pending, :default => true
7
+ t.boolean :blocked, :default => false
7
8
  end
8
9
  end
9
10
 
@@ -153,5 +153,43 @@ describe Amistad::FriendModel do
153
153
  @peter.pending_invited.should_not include(@victoria)
154
154
  end
155
155
  end
156
+
157
+ context "when blocking friendships" do
158
+ before(:each) do
159
+ Friendship.delete_all
160
+
161
+ @john.invite(@jane).should == true
162
+ @john.invite(@james).should == true
163
+ @john.invite(@david).should == true
164
+ @james.approve(@john).should == true
165
+ @david.block(@john).should == true
166
+ @david.block(@victoria).should == false
167
+ end
168
+
169
+ it "should return the correct number of friends blocked" do
170
+ @david.blocked.count.should == 1
171
+ @david.blocked.should include(@john)
172
+ end
173
+
174
+ it "should not return any blocked friends in friends or invited or pending invites" do
175
+ @john.friends.count.should == 1
176
+ @john.friends.should include(@james)
177
+ @john.friends.should_not include(@david)
178
+
179
+ @john.invited.count.should == 1
180
+ @john.invited.should_not include(@david)
181
+ @john.invited.should include(@james)
182
+
183
+ @john.pending_invited.count.should == 1
184
+ @john.pending_invited.should_not include(@david)
185
+ @john.pending_invited.should include(@jane)
186
+
187
+ @david.friends.count.should == 0
188
+ end
189
+
190
+ it "should not return any blocked friends for the friend who was blocked" do
191
+ @john.blocked.count.should == 0
192
+ end
193
+ end
156
194
 
157
195
  end
@@ -18,4 +18,9 @@ describe Amistad::FriendshipModel do
18
18
  friendship = Friendship.create(:user_id => 1, :friend_id => 2)
19
19
  friendship.pending?.should == true
20
20
  end
21
+
22
+ it "is not in a blocked state when created" do
23
+ friendship = Friendship.create(:user_id => 1, :friend_id => 2)
24
+ friendship.blocked?.should == false
25
+ end
21
26
  end
data/spec/spec_helper.rb CHANGED
@@ -22,6 +22,7 @@ ActiveRecord::Schema.define do
22
22
  t.integer :user_id
23
23
  t.integer :friend_id
24
24
  t.boolean :pending, :default => true
25
+ t.boolean :blocked, :default => false
25
26
  end
26
27
  end
27
28
 
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 4
8
- - 1
9
- version: 0.4.1
7
+ - 5
8
+ - 0
9
+ version: 0.5.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Rawane ZOSSOU
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-09-12 00:00:00 +02:00
17
+ date: 2010-10-24 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies: []
20
20
 
@@ -46,8 +46,8 @@ homepage: http://github.com/raw1z/amistad
46
46
  licenses: []
47
47
 
48
48
  post_install_message:
49
- rdoc_options:
50
- - --charset=UTF-8
49
+ rdoc_options: []
50
+
51
51
  require_paths:
52
52
  - lib
53
53
  required_ruby_version: !ruby/object:Gem::Requirement