amistad 0.7.2 → 0.7.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +4 -0
- data/lib/amistad/mongoid/friend_model.rb +18 -13
- data/lib/amistad/version.rb +1 -1
- data/spec/activerecord/activerecord_friend_model_spec.rb +4 -0
- data/spec/mongoid/mongoid_friend_model_spec.rb +35 -9
- data/spec/mongoid/mongoid_spec_helper.rb +1 -1
- data/spec/spec_helper.rb +8 -1
- data/spec/support/friend_examples.rb +0 -6
- metadata +2 -2
data/CHANGELOG
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
Version 0.7.3 (19.02.2011)
|
2
|
+
--------------------------
|
3
|
+
- Fixed a bug occuring with mongoid when the users were created before amistad was activated in the user model (thanks to Drew Baumann for signaling this bug)
|
4
|
+
|
1
5
|
Version 0.7.2 (16.02.2011)
|
2
6
|
--------------------------
|
3
7
|
- Added total_friends() and total_blocked() which count friendships and blocks without loading associations (by David Czarnecki)
|
@@ -3,23 +3,28 @@ module Amistad
|
|
3
3
|
module FriendModel
|
4
4
|
def self.included(receiver)
|
5
5
|
receiver.class_exec do
|
6
|
+
field :friend_ids, :type => Array, :default => [], :accessible => true
|
7
|
+
field :inverse_friend_ids, :type => Array, :default => [], :accessible => true
|
8
|
+
field :pending_friend_ids, :type => Array, :default => [], :accessible => true
|
9
|
+
field :pending_inverse_friend_ids, :type => Array, :default => [], :accessible => true
|
10
|
+
field :blocked_friend_ids, :type => Array, :default => [], :accessible => true
|
11
|
+
field :blocked_inverse_friend_ids, :type => Array, :default => [], :accessible => true
|
12
|
+
field :blocked_pending_friend_ids, :type => Array, :default => [], :accessible => true
|
13
|
+
field :blocked_pending_inverse_friend_ids, :type => Array, :default => [], :accessible => true
|
14
|
+
|
15
|
+
%w(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).each do |attribute|
|
16
|
+
define_method(attribute.to_sym) do
|
17
|
+
value = read_attribute(attribute)
|
18
|
+
write_attribute(attribute, value = []) if value.nil?
|
19
|
+
value
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
6
23
|
include InstanceMethods
|
7
|
-
|
8
|
-
field :friend_ids, :type => Array, :default => []
|
9
|
-
field :inverse_friend_ids, :type => Array, :default => []
|
10
|
-
field :pending_friend_ids, :type => Array, :default => []
|
11
|
-
field :pending_inverse_friend_ids, :type => Array, :default => []
|
12
|
-
|
13
|
-
field :blocked_friend_ids, :type => Array, :default => []
|
14
|
-
field :blocked_inverse_friend_ids, :type => Array, :default => []
|
15
|
-
field :blocked_pending_friend_ids, :type => Array, :default => []
|
16
|
-
field :blocked_pending_inverse_friend_ids, :type => Array, :default => []
|
17
|
-
|
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
24
|
end
|
20
25
|
end
|
21
26
|
|
22
|
-
module InstanceMethods
|
27
|
+
module InstanceMethods
|
23
28
|
# suggest a user to become a friend. If the operation succeeds, the method returns true, else false
|
24
29
|
def invite(user)
|
25
30
|
return false if friendshiped_with?(user) or user == self or blocked?(user)
|
data/lib/amistad/version.rb
CHANGED
@@ -6,16 +6,42 @@ describe Amistad::Mongoid::FriendModel do
|
|
6
6
|
eval "@#{var}.delete_all_friendships.should be_true"
|
7
7
|
end
|
8
8
|
end
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
9
|
+
|
10
|
+
context "When users are created after activating amistad" do
|
11
|
+
before(:all) do
|
12
|
+
# create a user model with amistad activated
|
13
|
+
Object.send(:remove_const, :User) if Object.const_defined?(:User)
|
14
|
+
User = Class.new
|
15
|
+
User.class_exec do
|
16
|
+
include Mongoid::Document
|
17
|
+
include Amistad::FriendModel
|
18
|
+
field :name, :require => true
|
19
|
+
end
|
20
|
+
|
21
|
+
# create the users
|
22
|
+
create_users
|
17
23
|
end
|
24
|
+
|
25
|
+
it_should_behave_like "a friend model"
|
18
26
|
end
|
19
27
|
|
20
|
-
|
28
|
+
context "When users are created before activating amistad" do
|
29
|
+
before(:all) do
|
30
|
+
# create a user model without amistad activated
|
31
|
+
Object.send(:remove_const, :User) if Object.const_defined?(:User)
|
32
|
+
User = Class.new
|
33
|
+
User.class_exec do
|
34
|
+
include Mongoid::Document
|
35
|
+
field :name, :require => true
|
36
|
+
end
|
37
|
+
|
38
|
+
# create the users
|
39
|
+
create_users
|
40
|
+
|
41
|
+
# activate amistad
|
42
|
+
User.class_exec { include Amistad::FriendModel }
|
43
|
+
end
|
44
|
+
|
45
|
+
it_should_behave_like "a friend model"
|
46
|
+
end
|
21
47
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,3 +1,10 @@
|
|
1
1
|
require 'rspec'
|
2
2
|
require 'amistad'
|
3
|
-
Dir["#{File.dirname(__FILE__)}/support
|
3
|
+
Dir["#{File.dirname(__FILE__)}/support/*.rb"].each {|f| require f}
|
4
|
+
|
5
|
+
def create_users
|
6
|
+
User.delete_all
|
7
|
+
%w(John Jane David James Peter Mary Victoria Elisabeth).each do |name|
|
8
|
+
instance_variable_set("@#{name.downcase}".to_sym, User.create(:name => name))
|
9
|
+
end
|
10
|
+
end
|
@@ -1,10 +1,4 @@
|
|
1
1
|
shared_examples_for "a friend model" do
|
2
|
-
before(:all) do
|
3
|
-
%w(John Jane David James Peter Mary Victoria Elisabeth).each do |name|
|
4
|
-
instance_variable_set("@#{name.downcase}".to_sym, User.create(:name => name))
|
5
|
-
end
|
6
|
-
end
|
7
|
-
|
8
2
|
context "when creating friendships" do
|
9
3
|
before(:each) do
|
10
4
|
reset_friendships
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: amistad
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.7.
|
5
|
+
version: 0.7.3
|
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-
|
13
|
+
date: 2011-02-19 00:00:00 +01:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|