mm-friendable 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0
1
+ 1.0.1
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{mm-friendable}
8
- s.version = "1.0.0"
8
+ s.version = "1.0.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Luke Cunningham"]
@@ -31,6 +31,12 @@ describe "MongoMapper::Plugins::Friendable" do
31
31
 
32
32
  describe "add_friend!" do
33
33
 
34
+ it "should error if on_add_friend callback is not implemented" do
35
+ @friendable = UserNoCallbacks.create
36
+
37
+ lambda { @friendable.add_friend!(@friend) }.should raise_error(NotImplementedError)
38
+ end
39
+
34
40
  it "should increment the following_count attribute" do
35
41
  lambda {
36
42
  @friendable.add_friend!(@friend)
@@ -61,4 +67,70 @@ describe "MongoMapper::Plugins::Friendable" do
61
67
 
62
68
  end
63
69
 
70
+ describe "remove_friend!" do
71
+
72
+ before(:each) do
73
+ @friendable.add_friend!(@friend)
74
+ end
75
+
76
+ it "should error if on_add_friend callback is not implemented" do
77
+ @friendable = UserNoCallbacks.create
78
+ @friendable.class_eval {
79
+ def on_add_friend(friend)
80
+ reload
81
+ friend.reload
82
+ end
83
+ }
84
+ @friendable.add_friend!(@friend)
85
+
86
+ lambda { @friendable.remove_friend!(@friend) }.should raise_error(NotImplementedError)
87
+ end
88
+
89
+
90
+ it "should decrement the following_count attribute" do
91
+ lambda {
92
+ @friendable.remove_friend!(@friend)
93
+
94
+ }.should change(@friendable, :following_count).by(-1)
95
+ end
96
+
97
+ it "should decrement the followers_count attribute" do
98
+ lambda {
99
+ @friendable.remove_friend!(@friend)
100
+
101
+ }.should change(@friend, :followers_count).by(-1)
102
+ end
103
+
104
+ it "should remove the friend" do
105
+ @friendable.remove_friend!(@friend)
106
+
107
+ @friendable.friend_list.following_ids.should_not include(@friend.id)
108
+ @friendable.following.should_not include(@friend)
109
+ end
110
+
111
+ it "should remove the follower" do
112
+ @friendable.remove_friend!(@friend)
113
+
114
+ @friend.friend_list.followers_ids.should_not include(@friendable.id)
115
+ @friend.followers.should_not include(@friendable)
116
+ end
117
+
118
+ end
119
+
120
+ describe "following?" do
121
+
122
+ before(:each) do
123
+ @friendable.add_friend!(@friend)
124
+ end
125
+
126
+ it "should return true if following" do
127
+ @friendable.following?(@friend).should be_true
128
+ end
129
+
130
+ it "should return false if not following" do
131
+ @friend.following?(@friendable).should be_false
132
+ end
133
+
134
+ end
135
+
64
136
  end
@@ -9,4 +9,15 @@ class User
9
9
  friend.reload
10
10
  end
11
11
 
12
+ def on_remove_friend(friend)
13
+ reload
14
+ friend.reload
15
+ end
16
+ end
17
+
18
+ class UserNoCallbacks
19
+ include MongoMapper::Document
20
+ plugin MongoMapper::Plugins::Friendable
21
+
22
+ key :email, String
12
23
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mm-friendable
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 0
10
- version: 1.0.0
9
+ - 1
10
+ version: 1.0.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Luke Cunningham