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 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)
@@ -1,3 +1,3 @@
1
1
  module Amistad
2
- VERSION = "0.7.2"
2
+ VERSION = "0.7.3"
3
3
  end
@@ -5,5 +5,9 @@ describe Amistad::ActiveRecord::FriendModel do
5
5
  Friendship.delete_all
6
6
  end
7
7
 
8
+ before(:all) do
9
+ create_users
10
+ end
11
+
8
12
  it_should_behave_like "a friend model"
9
13
  end
@@ -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
- before(:all) do
11
- Object.send(:remove_const, :User) if Object.const_defined?(:User)
12
- User = Class.new
13
- User.class_exec do
14
- include Mongoid::Document
15
- include Amistad::FriendModel
16
- field :name, :required => true
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
- it_should_behave_like "a friend model"
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
@@ -8,4 +8,4 @@ Mongoid.configure do |config|
8
8
  config.slaves = [
9
9
  Mongo::Connection.new(host, 27017, :slave_ok => true).db(name)
10
10
  ]
11
- end
11
+ 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/**/*.rb"].each {|f| require f}
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.2
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-16 00:00:00 +01:00
13
+ date: 2011-02-19 00:00:00 +01:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency