acts-as-messageable 0.4.7 → 0.4.8
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/.rspec +1 -1
- data/Gemfile +12 -12
- data/README.md +278 -265
- data/VERSION +1 -1
- data/acts-as-messageable.gemspec +2 -2
- data/lib/acts-as-messageable.rb +7 -7
- data/lib/acts-as-messageable/message.rb +97 -95
- data/lib/acts-as-messageable/model.rb +165 -157
- data/lib/acts-as-messageable/relation.rb +4 -0
- data/spec/acts-as-messageable_spec.rb +266 -234
- data/spec/custom-class_spec.rb +19 -4
- data/spec/spec_helper.rb +65 -61
- data/spec/support/admin.rb +3 -3
- data/spec/support/user.rb +7 -7
- metadata +3 -3
@@ -1,234 +1,266 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe "ActsAsMessageable" do
|
4
|
-
before do
|
5
|
-
User.acts_as_messageable
|
6
|
-
@message = send_message
|
7
|
-
end
|
8
|
-
|
9
|
-
describe "send messages" do
|
10
|
-
it "alice should have one message" do
|
11
|
-
@alice.messages.count.should == 1
|
12
|
-
end
|
13
|
-
|
14
|
-
it "alice should have one message from bob" do
|
15
|
-
@alice.messages.are_from(@bob).count.should == 1
|
16
|
-
end
|
17
|
-
|
18
|
-
it "bob should have one message" do
|
19
|
-
@bob.messages.count.should == 1
|
20
|
-
end
|
21
|
-
|
22
|
-
it "bob should have one message to alice in outbox" do
|
23
|
-
@bob.sent_messages.are_to(@alice).count.should == 1
|
24
|
-
end
|
25
|
-
|
26
|
-
it "bob should have one open message from alice" do
|
27
|
-
@alice.messages.are_from(@bob).process { |m| m.open }
|
28
|
-
@alice.messages.readed.count.should == 1
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
describe "inheritance models" do
|
33
|
-
it "men send message to alice" do
|
34
|
-
send_message(@men, @alice)
|
35
|
-
@men.sent_messages.size.should be_equal(1)
|
36
|
-
@alice.received_messages.size.should be_equal(2)
|
37
|
-
end
|
38
|
-
|
39
|
-
it "messages method should receive all messages connected with user" do
|
40
|
-
send_message(@men, @alice)
|
41
|
-
@men.messages.size.should be_equal(1)
|
42
|
-
end
|
43
|
-
|
44
|
-
it "men send message and receive from alice" do
|
45
|
-
send_message(@men, @alice)
|
46
|
-
send_message(@alice, @men)
|
47
|
-
|
48
|
-
@men.messages.size.should be_equal(2)
|
49
|
-
@men.sent_messages.size.should be_equal(1)
|
50
|
-
@men.received_messages.size.should be_equal(1)
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
describe "reply to messages" do
|
55
|
-
it "pat should not be able to reply to a message from bob to alice" do
|
56
|
-
@reply_message = @pat.reply_to(@message, "Re: Topic", "Body")
|
57
|
-
@reply_message.should be_nil
|
58
|
-
end
|
59
|
-
|
60
|
-
it "alice should be able to reply to a message from bob to alice" do
|
61
|
-
@reply_message = @alice.reply_to(@message, "Re: Topic", "Body")
|
62
|
-
@reply_message.should_not be_nil
|
63
|
-
@bob.messages.are_from(@alice).count.should == 1
|
64
|
-
@alice.sent_messages.are_to(@bob).count.should == 1
|
65
|
-
end
|
66
|
-
|
67
|
-
it "alice should be able to reply to a message using the message object" do
|
68
|
-
@reply_message = @message.reply("Re: Topic", "Body")
|
69
|
-
@reply_message.should_not be_nil
|
70
|
-
@bob.messages.are_from(@alice).count.should == 1
|
71
|
-
@alice.sent_messages.are_to(@bob).count.should == 1
|
72
|
-
end
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
@
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
@bob.
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
@
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
@
|
106
|
-
|
107
|
-
|
108
|
-
@
|
109
|
-
@
|
110
|
-
|
111
|
-
|
112
|
-
@
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
@
|
125
|
-
@
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
@
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
it "
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
it "
|
143
|
-
@alice.
|
144
|
-
@alice.
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
@
|
191
|
-
@
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
@
|
198
|
-
|
199
|
-
@message.
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
end
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
@bob.
|
223
|
-
@
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
@bob.
|
230
|
-
@
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "ActsAsMessageable" do
|
4
|
+
before do
|
5
|
+
User.acts_as_messageable
|
6
|
+
@message = send_message
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "send messages" do
|
10
|
+
it "alice should have one message" do
|
11
|
+
@alice.messages.count.should == 1
|
12
|
+
end
|
13
|
+
|
14
|
+
it "alice should have one message from bob" do
|
15
|
+
@alice.messages.are_from(@bob).count.should == 1
|
16
|
+
end
|
17
|
+
|
18
|
+
it "bob should have one message" do
|
19
|
+
@bob.messages.count.should == 1
|
20
|
+
end
|
21
|
+
|
22
|
+
it "bob should have one message to alice in outbox" do
|
23
|
+
@bob.sent_messages.are_to(@alice).count.should == 1
|
24
|
+
end
|
25
|
+
|
26
|
+
it "bob should have one open message from alice" do
|
27
|
+
@alice.messages.are_from(@bob).process { |m| m.open }
|
28
|
+
@alice.messages.readed.count.should == 1
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "inheritance models" do
|
33
|
+
it "men send message to alice" do
|
34
|
+
send_message(@men, @alice)
|
35
|
+
@men.sent_messages.size.should be_equal(1)
|
36
|
+
@alice.received_messages.size.should be_equal(2)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "messages method should receive all messages connected with user" do
|
40
|
+
send_message(@men, @alice)
|
41
|
+
@men.messages.size.should be_equal(1)
|
42
|
+
end
|
43
|
+
|
44
|
+
it "men send message and receive from alice" do
|
45
|
+
send_message(@men, @alice)
|
46
|
+
send_message(@alice, @men)
|
47
|
+
|
48
|
+
@men.messages.size.should be_equal(2)
|
49
|
+
@men.sent_messages.size.should be_equal(1)
|
50
|
+
@men.received_messages.size.should be_equal(1)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "reply to messages" do
|
55
|
+
it "pat should not be able to reply to a message from bob to alice" do
|
56
|
+
@reply_message = @pat.reply_to(@message, "Re: Topic", "Body")
|
57
|
+
@reply_message.should be_nil
|
58
|
+
end
|
59
|
+
|
60
|
+
it "alice should be able to reply to a message from bob to alice" do
|
61
|
+
@reply_message = @alice.reply_to(@message, "Re: Topic", "Body")
|
62
|
+
@reply_message.should_not be_nil
|
63
|
+
@bob.messages.are_from(@alice).count.should == 1
|
64
|
+
@alice.sent_messages.are_to(@bob).count.should == 1
|
65
|
+
end
|
66
|
+
|
67
|
+
it "alice should be able to reply to a message using the message object" do
|
68
|
+
@reply_message = @message.reply("Re: Topic", "Body")
|
69
|
+
@reply_message.should_not be_nil
|
70
|
+
@bob.messages.are_from(@alice).count.should == 1
|
71
|
+
@alice.sent_messages.are_to(@bob).count.should == 1
|
72
|
+
end
|
73
|
+
|
74
|
+
it "bob try to add something to conversation" do
|
75
|
+
@reply_message = @bob.reply_to(@message, "Oh, I Forget", "1+1=2")
|
76
|
+
@reply_message.from.should == @message.from
|
77
|
+
@reply_message.to.should == @message.to
|
78
|
+
end
|
79
|
+
|
80
|
+
it "bob try to add something to conversation and should receive proper order" do
|
81
|
+
@reply_message = @bob.reply_to(@message, "Oh, I Forget", "1+1=2")
|
82
|
+
@sec_message = @alice.reply_to(@message, "Yeah, right", "1+1=3!")
|
83
|
+
|
84
|
+
@message.conversation.should == [@sec_message, @reply_message, @message]
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe "delete messages" do
|
89
|
+
|
90
|
+
it "bob should have one deleted message from alice" do
|
91
|
+
@bob.messages.process do |m|
|
92
|
+
m.delete
|
93
|
+
end
|
94
|
+
|
95
|
+
@bob.messages.each do |m|
|
96
|
+
m.recipient_delete.should == true
|
97
|
+
m.sender_delete.should == false
|
98
|
+
end
|
99
|
+
|
100
|
+
@bob.deleted_messages.count.should == 1
|
101
|
+
@bob.messages.count.should == 0
|
102
|
+
end
|
103
|
+
|
104
|
+
it "received_messages and sent_messages should work with .process method" do
|
105
|
+
@bob.sent_messages.count.should == 1
|
106
|
+
@alice.received_messages.count.should == 1
|
107
|
+
|
108
|
+
@bob.sent_messages.process { |m| m.delete }
|
109
|
+
@bob.sent_messages.count.should == 0
|
110
|
+
@alice.received_messages.count.should == 1
|
111
|
+
|
112
|
+
@alice.received_messages.process { |m| m.delete }
|
113
|
+
@alice.received_messages.count.should == 0
|
114
|
+
end
|
115
|
+
|
116
|
+
it "message should permanent delete" do
|
117
|
+
@alice.messages.process { |m| m.delete }
|
118
|
+
@alice.messages.count.should == 0
|
119
|
+
|
120
|
+
@alice.deleted_messages.count.should == 1
|
121
|
+
@alice.deleted_messages.process { |m| m.delete }
|
122
|
+
@alice.deleted_messages.count.should == 0
|
123
|
+
|
124
|
+
@message.reload
|
125
|
+
@message.recipient_permanent_delete.should == true
|
126
|
+
|
127
|
+
@bob.sent_messages.count.should == 1
|
128
|
+
end
|
129
|
+
|
130
|
+
it "pat should not able to delete message" do
|
131
|
+
lambda { @pat.delete_message(@message) }.should raise_error
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
describe "restore message" do
|
136
|
+
it "alice should restore message" do
|
137
|
+
@alice.received_messages.process { |m| m.delete }
|
138
|
+
@alice.restore_message(@message.reload)
|
139
|
+
@alice.received_messages.count.should == 1
|
140
|
+
end
|
141
|
+
|
142
|
+
it "should works with relation" do
|
143
|
+
@alice.received_messages.process { |m| m.delete }
|
144
|
+
@alice.received_messages.count.should == 0
|
145
|
+
@alice.deleted_messages.process { |m| m.restore }
|
146
|
+
@alice.received_messages.count.should == 1
|
147
|
+
end
|
148
|
+
|
149
|
+
it "pat should not able to restore message" do
|
150
|
+
lambda { @pat.restore_message(@message) }.should raise_error
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
describe "read/unread feature" do
|
155
|
+
it "alice should have one unread message from bob" do
|
156
|
+
@alice.messages.are_from(@bob).unreaded.count.should == 1
|
157
|
+
@alice.messages.are_from(@bob).readed.count.should == 0
|
158
|
+
end
|
159
|
+
|
160
|
+
it "alice should able to read message from bob" do
|
161
|
+
@alice.messages.are_from(@bob).first.read
|
162
|
+
@alice.messages.are_from(@bob).unreaded.count.should == 0
|
163
|
+
end
|
164
|
+
|
165
|
+
it "alice should able to unread message from bob" do
|
166
|
+
@alice.messages.are_from(@bob).first.read
|
167
|
+
@alice.messages.are_from(@bob).first.unread
|
168
|
+
@alice.messages.are_from(@bob).unreaded.count.should == 1
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
it "should be in database message with id ..." do
|
173
|
+
message_id = send_message.id
|
174
|
+
@bob.messages.with_id(message_id).count.should == 1
|
175
|
+
end
|
176
|
+
|
177
|
+
it "finds proper message" do
|
178
|
+
@bob.messages.find(@message.id) == @message
|
179
|
+
end
|
180
|
+
|
181
|
+
it "message should have proper topic" do
|
182
|
+
@bob.messages.count.should == 1
|
183
|
+
@bob.messages.first.topic == "Topic"
|
184
|
+
end
|
185
|
+
|
186
|
+
describe "conversation" do
|
187
|
+
it "bob send message to alice, and alice reply to bob message and show proper tree" do
|
188
|
+
@reply_message = @alice.reply_to(@message, "Re: Topic", "Body")
|
189
|
+
|
190
|
+
@reply_message.conversation.size.should == 2
|
191
|
+
@reply_message.conversation.last.topic.should == "Topic"
|
192
|
+
@reply_message.conversation.first.topic.should == "Re: Topic"
|
193
|
+
end
|
194
|
+
|
195
|
+
it "bob send message to alice, alice answer, and bob answer for alice answer" do
|
196
|
+
@reply_message = @alice.reply_to(@message, "Re: Topic", "Body")
|
197
|
+
@reply_reply_message = @bob.reply_to(@reply_message, "Re: Re: Topic", "Body")
|
198
|
+
|
199
|
+
[@message, @reply_message, @reply_reply_message].each do |m|
|
200
|
+
m.conversation.size.should == 3
|
201
|
+
end
|
202
|
+
|
203
|
+
@message.conversation.first.should == @reply_reply_message
|
204
|
+
@reply_reply_message.conversation.first.should == @reply_reply_message
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
describe "conversations" do
|
209
|
+
before do
|
210
|
+
@reply_message = @message.reply("Re: Topic", "Body")
|
211
|
+
@reply_reply_message = @reply_message.reply("Re: Re: Topic", "Body")
|
212
|
+
end
|
213
|
+
|
214
|
+
it "bob send message to alice and alice reply" do
|
215
|
+
@bob.messages.conversations.should == [@reply_reply_message]
|
216
|
+
@reply_message.conversation.should == [@reply_reply_message, @reply_message, @message]
|
217
|
+
end
|
218
|
+
|
219
|
+
it "show conversations in proper order" do
|
220
|
+
@sec_message = @bob.send_message(@alice, "Hi", "Alice!")
|
221
|
+
@sec_reply = @sec_message.reply("Re: Hi", "Fine!")
|
222
|
+
@bob.received_messages.conversations.should == [@sec_reply, @reply_reply_message]
|
223
|
+
@sec_reply.conversation.should == [@sec_reply, @sec_message]
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
describe "send messages with hash" do
|
228
|
+
it "send message with hash" do
|
229
|
+
@message = @bob.send_message(@alice, {:body => "Body", :topic => "Topic"})
|
230
|
+
@message.topic.should == "Topic"
|
231
|
+
@message.body.should == "Body"
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
235
|
+
it "messages should return in right order :created_at" do
|
236
|
+
@message = send_message(@bob, @alice, "Example", "Example Body")
|
237
|
+
@alice.messages.last.body.should == "Body"
|
238
|
+
end
|
239
|
+
|
240
|
+
it "received_messages should return ActiveRecord::Relation" do
|
241
|
+
@alice.received_messages.class.should == ActiveRecord::Relation
|
242
|
+
end
|
243
|
+
|
244
|
+
it "sent_messages should return ActiveRecord::Relation" do
|
245
|
+
@bob.sent_messages.class.should == ActiveRecord::Relation
|
246
|
+
end
|
247
|
+
|
248
|
+
describe "send messages between two different models (the same id)" do
|
249
|
+
it "should have the same id" do
|
250
|
+
@alice.id.should be_equal(@admin.id)
|
251
|
+
end
|
252
|
+
|
253
|
+
it "bob send message to admin (different model) with the same id" do
|
254
|
+
@bob.send_message(@alice, "hello", "alice")
|
255
|
+
@alice.messages.are_to(@alice).size.should be_equal(2)
|
256
|
+
@alice.messages.are_to(@admin).size.should be_equal(0)
|
257
|
+
end
|
258
|
+
|
259
|
+
it "admin send message to bob" do
|
260
|
+
@admin.send_message(@bob, "hello", "bob")
|
261
|
+
@bob.messages.are_from(@admin).size.should be_equal(1)
|
262
|
+
@bob.messages.are_from(@alice).size.should be_equal(0)
|
263
|
+
end
|
264
|
+
end
|
265
|
+
|
266
|
+
end
|