acts-as-messageable 0.4.10 → 0.4.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.rspec +1 -1
- data/.travis.yml +16 -14
- data/Appraisals +30 -27
- data/Gemfile +10 -10
- data/Gemfile.lock +124 -98
- data/README.md +4 -5
- data/Rakefile +8 -10
- data/VERSION +1 -1
- data/acts-as-messageable.gemspec +45 -43
- data/gemfiles/rails_3.2.gemfile +7 -7
- data/gemfiles/rails_3.2.gemfile.lock +153 -0
- data/gemfiles/rails_4.2.11.gemfile +16 -0
- data/gemfiles/rails_4.2.11.gemfile.lock +157 -0
- data/gemfiles/rails_5.2.gemfile +16 -0
- data/gemfiles/rails_5.2.gemfile.lock +155 -0
- data/gemfiles/rails_6.0.gemfile +16 -0
- data/gemfiles/rails_6.0.gemfile.lock +155 -0
- data/lib/acts-as-messageable/message.rb +13 -13
- data/lib/acts-as-messageable/model.rb +46 -46
- data/lib/acts-as-messageable/rails4.rb +1 -3
- data/lib/acts-as-messageable/railtie.rb +0 -1
- data/lib/acts-as-messageable/relation.rb +4 -4
- data/lib/acts-as-messageable/scopes.rb +21 -20
- data/lib/generators/acts-as-messageable/migration/migration_generator.rb +12 -4
- data/spec/acts-as-messageable_spec.rb +155 -160
- data/spec/custom-class_spec.rb +19 -20
- data/spec/custom-required_spec.rb +27 -27
- data/spec/group-messages_spec.rb +17 -19
- data/spec/spec_helper.rb +22 -22
- data/spec/support/admin.rb +3 -3
- data/spec/support/send_message.rb +1 -1
- metadata +23 -21
- data/gemfiles/rails_3.0.gemfile +0 -16
- data/gemfiles/rails_3.1.gemfile +0 -16
- data/gemfiles/rails_4.0.gemfile +0 -16
- data/gemfiles/rails_4.1.gemfile +0 -16
- data/gemfiles/rails_4.1_ProtectedAttributes.gemfile +0 -17
@@ -2,16 +2,16 @@ module ActsAsMessageable
|
|
2
2
|
module Relation
|
3
3
|
attr_accessor :relation_context
|
4
4
|
|
5
|
-
def process(context =
|
6
|
-
|
7
|
-
|
5
|
+
def process(context = relation_context)
|
6
|
+
each do |message|
|
7
|
+
yield(message) if block_given?
|
8
8
|
context.delete_message(message) if message.removed
|
9
9
|
context.restore_message(message) if message.restored
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
13
|
def conversations
|
14
|
-
map { |r| r.root.subtree.order(
|
14
|
+
map { |r| r.root.subtree.order('id desc').first }.uniq
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
@@ -10,27 +10,28 @@ module ActsAsMessageable
|
|
10
10
|
|
11
11
|
module ClassMethods
|
12
12
|
def initialize_scopes
|
13
|
-
scope :are_from,
|
14
|
-
scope :are_to,
|
15
|
-
scope :search,
|
16
|
-
scope :connected_with, lambda { |*args|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
13
|
+
scope :are_from, ->(*args) { where(sent_messageable_id: args.first, sent_messageable_type: args.first.class.name) }
|
14
|
+
scope :are_to, ->(*args) { where(received_messageable_id: args.first, received_messageable_type: args.first.class.name) }
|
15
|
+
scope :search, ->(*args) { where('body like :search_txt or topic like :search_txt', search_txt: "%#{args.first}%") }
|
16
|
+
scope :connected_with, lambda { |*args|
|
17
|
+
where("(sent_messageable_type = :sent_type and
|
18
|
+
sent_messageable_id = :sent_id and
|
19
|
+
sender_delete = :s_delete and sender_permanent_delete = :s_perm_delete) or
|
20
|
+
(received_messageable_type = :received_type and
|
21
|
+
received_messageable_id = :received_id and
|
22
|
+
recipient_delete = :r_delete and recipient_permanent_delete = :r_perm_delete)",
|
23
|
+
sent_type: args.first.class.resolve_active_record_ancestor.to_s,
|
24
|
+
sent_id: args.first.id,
|
25
|
+
received_type: args.first.class.resolve_active_record_ancestor.to_s,
|
26
|
+
received_id: args.first.id,
|
27
|
+
r_delete: args.last,
|
28
|
+
s_delete: args.last,
|
29
|
+
r_perm_delete: false,
|
30
|
+
s_perm_delete: false)
|
30
31
|
}
|
31
|
-
scope :readed,
|
32
|
-
scope :unreaded,
|
33
|
-
scope :deleted,
|
32
|
+
scope :readed, -> { where(opened: true) }
|
33
|
+
scope :unreaded, -> { where(opened: false) }
|
34
|
+
scope :deleted, -> { where(recipient_delete: true, sender_delete: true) }
|
34
35
|
end
|
35
36
|
end
|
36
37
|
end
|
@@ -5,18 +5,26 @@ module ActsAsMessageable
|
|
5
5
|
class MigrationGenerator < Rails::Generators::Base
|
6
6
|
include Rails::Generators::Migration
|
7
7
|
|
8
|
-
namespace
|
8
|
+
namespace 'acts-as-messageable:migration'
|
9
9
|
|
10
10
|
source_root File.join(File.dirname(__FILE__), 'templates')
|
11
|
-
argument :table_name, :
|
11
|
+
argument :table_name, type: :string, default: 'messages'
|
12
12
|
|
13
13
|
def self.next_migration_number(dirname)
|
14
14
|
ActiveRecord::Generators::Base.next_migration_number(dirname)
|
15
15
|
end
|
16
16
|
|
17
17
|
def create_migration_file
|
18
|
-
|
19
|
-
|
18
|
+
begin
|
19
|
+
migration_template 'migration.rb', 'db/migrate/create_messages_table.rb'
|
20
|
+
rescue StandardError
|
21
|
+
nil
|
22
|
+
end
|
23
|
+
begin
|
24
|
+
migration_template 'migration_permanent.rb', 'db/migrate/add_recipient_permanent_delete_and_sender_permanent_delete_to_messages.rb'
|
25
|
+
rescue StandardError
|
26
|
+
nil
|
27
|
+
end
|
20
28
|
end
|
21
29
|
end
|
22
30
|
end
|
@@ -1,293 +1,288 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe 'ActsAsMessageable' do
|
4
4
|
before do
|
5
5
|
User.acts_as_messageable
|
6
6
|
@message = send_message
|
7
7
|
end
|
8
8
|
|
9
|
-
describe
|
10
|
-
it
|
11
|
-
@alice.messages.count.
|
9
|
+
describe 'send messages' do
|
10
|
+
it 'alice should have one message' do
|
11
|
+
expect(@alice.messages.count).to eq(1)
|
12
12
|
end
|
13
13
|
|
14
|
-
it
|
15
|
-
@alice.messages.are_from(@bob).count.
|
14
|
+
it 'alice should have one message from bob' do
|
15
|
+
expect(@alice.messages.are_from(@bob).count).to eq(1)
|
16
16
|
end
|
17
17
|
|
18
|
-
it
|
19
|
-
@bob.messages.count.
|
18
|
+
it 'bob should have one message' do
|
19
|
+
expect(@bob.messages.count).to eq(1)
|
20
20
|
end
|
21
21
|
|
22
|
-
it
|
23
|
-
@bob.sent_messages.are_to(@alice).count.
|
22
|
+
it 'bob should have one message to alice in outbox' do
|
23
|
+
expect(@bob.sent_messages.are_to(@alice).count).to eq(1)
|
24
24
|
end
|
25
25
|
|
26
|
-
it
|
27
|
-
@alice.messages.are_from(@bob).process
|
28
|
-
@alice.messages.readed.count.
|
26
|
+
it 'bob should have one open message from alice' do
|
27
|
+
@alice.messages.are_from(@bob).process(&:open)
|
28
|
+
expect(@alice.messages.readed.count).to eq(1)
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
describe
|
33
|
-
it
|
34
|
-
expect
|
35
|
-
@alice.send_message!(@bob, :
|
36
|
-
|
32
|
+
describe 'send messages with bang' do
|
33
|
+
it 'should raise exception' do
|
34
|
+
expect do
|
35
|
+
@alice.send_message!(@bob, body: 'body')
|
36
|
+
end.to raise_error(ActiveRecord::RecordInvalid)
|
37
37
|
end
|
38
38
|
|
39
|
-
it
|
40
|
-
@alice.send_message!(@bob, :
|
41
|
-
be_kind_of ActsAsMessageable::Message
|
39
|
+
it 'should return message object' do
|
40
|
+
expect(@alice.send_message!(@bob, body: 'body', topic: 'topic')).to be_kind_of(ActsAsMessageable::Message)
|
42
41
|
end
|
43
42
|
end
|
44
43
|
|
45
|
-
describe
|
46
|
-
it
|
44
|
+
describe 'inheritance models' do
|
45
|
+
it 'men send message to alice' do
|
47
46
|
send_message(@men, @alice)
|
48
|
-
@men.sent_messages.size.
|
49
|
-
@alice.received_messages.size.
|
47
|
+
expect(@men.sent_messages.size).to be_equal(1)
|
48
|
+
expect(@alice.received_messages.size).to be_equal(2)
|
50
49
|
end
|
51
50
|
|
52
|
-
it
|
51
|
+
it 'messages method should receive all messages connected with user' do
|
53
52
|
send_message(@men, @alice)
|
54
|
-
@men.messages.size.
|
53
|
+
expect(@men.messages.size).to be_equal(1)
|
55
54
|
end
|
56
55
|
|
57
|
-
it
|
56
|
+
it 'men send message and receive from alice' do
|
58
57
|
send_message(@men, @alice)
|
59
58
|
send_message(@alice, @men)
|
60
59
|
|
61
|
-
@men.messages.size.
|
62
|
-
@men.sent_messages.size.
|
63
|
-
@men.received_messages.size.
|
60
|
+
expect(@men.messages.size).to be_equal(2)
|
61
|
+
expect(@men.sent_messages.size).to be_equal(1)
|
62
|
+
expect(@men.received_messages.size).to be_equal(1)
|
64
63
|
end
|
65
64
|
end
|
66
65
|
|
67
|
-
describe
|
68
|
-
|
69
|
-
|
70
|
-
@reply_message
|
71
|
-
@reply_message.should be_nil
|
66
|
+
describe 'reply to messages' do
|
67
|
+
it 'pat should not be able to reply to a message from bob to alice' do
|
68
|
+
@reply_message = @pat.reply_to(@message, 'Re: Topic', 'Body')
|
69
|
+
expect(@reply_message).to be_nil
|
72
70
|
end
|
73
71
|
|
74
|
-
it
|
75
|
-
@reply_message = @alice.reply_to(@message,
|
76
|
-
@reply_message.
|
77
|
-
@bob.messages.are_from(@alice).count.
|
78
|
-
@alice.sent_messages.are_to(@bob).count.
|
72
|
+
it 'alice should be able to reply to a message from bob to alice' do
|
73
|
+
@reply_message = @alice.reply_to(@message, 'Re: Topic', 'Body')
|
74
|
+
expect(@reply_message).not_to be_nil
|
75
|
+
expect(@bob.messages.are_from(@alice).count).to eq(1)
|
76
|
+
expect(@alice.sent_messages.are_to(@bob).count).to eq(1)
|
79
77
|
end
|
80
78
|
|
81
|
-
it
|
82
|
-
@reply_message = @message.reply(
|
83
|
-
@reply_message.
|
84
|
-
@bob.messages.are_from(@alice).count.
|
85
|
-
@alice.sent_messages.are_to(@bob).count.
|
79
|
+
it 'alice should be able to reply to a message using the message object' do
|
80
|
+
@reply_message = @message.reply('Re: Topic', 'Body')
|
81
|
+
expect(@reply_message).not_to be_nil
|
82
|
+
expect(@bob.messages.are_from(@alice).count).to eq(1)
|
83
|
+
expect(@alice.sent_messages.are_to(@bob).count).to eq(1)
|
86
84
|
end
|
87
85
|
|
88
|
-
it
|
89
|
-
@reply_message = @bob.reply_to(@message,
|
90
|
-
@reply_message.from.
|
91
|
-
@reply_message.to.
|
86
|
+
it 'bob try to add something to conversation' do
|
87
|
+
@reply_message = @bob.reply_to(@message, 'Oh, I Forget', '1+1=2')
|
88
|
+
expect(@reply_message.from).to eq(@message.from)
|
89
|
+
expect(@reply_message.to).to eq(@message.to)
|
92
90
|
end
|
93
91
|
|
94
|
-
it
|
95
|
-
@reply_message = @bob.reply_to(@message,
|
96
|
-
@sec_message = @alice.reply_to(@message,
|
92
|
+
it 'bob try to add something to conversation and should receive proper order' do
|
93
|
+
@reply_message = @bob.reply_to(@message, 'Oh, I Forget', '1+1=2')
|
94
|
+
@sec_message = @alice.reply_to(@message, 'Yeah, right', '1+1=3!')
|
97
95
|
|
98
|
-
@message.conversation.
|
96
|
+
expect(@message.conversation).to eq([@sec_message, @reply_message, @message])
|
99
97
|
end
|
100
98
|
end
|
101
99
|
|
102
|
-
describe
|
103
|
-
|
104
|
-
|
105
|
-
@bob.messages.process do |m|
|
106
|
-
m.delete
|
107
|
-
end
|
100
|
+
describe 'delete messages' do
|
101
|
+
it 'bob should have one deleted message from alice' do
|
102
|
+
@bob.messages.process(&:delete)
|
108
103
|
|
109
104
|
@bob.messages.each do |m|
|
110
|
-
m.recipient_delete.
|
111
|
-
m.sender_delete.
|
105
|
+
expect(m.recipient_delete).to eq(true)
|
106
|
+
expect(m.sender_delete).to eq(false)
|
112
107
|
end
|
113
108
|
|
114
|
-
@bob.deleted_messages.count.
|
115
|
-
@bob.messages.count.
|
109
|
+
expect(@bob.deleted_messages.count).to eq(1)
|
110
|
+
expect(@bob.messages.count).to eq(0)
|
116
111
|
end
|
117
112
|
|
118
|
-
it
|
119
|
-
@bob.sent_messages.count.
|
120
|
-
@alice.received_messages.count.
|
113
|
+
it 'received_messages and sent_messages should work with .process method' do
|
114
|
+
expect(@bob.sent_messages.count).to eq(1)
|
115
|
+
expect(@alice.received_messages.count).to eq(1)
|
121
116
|
|
122
|
-
@bob.sent_messages.process
|
123
|
-
@bob.sent_messages.count.
|
124
|
-
@alice.received_messages.count.
|
117
|
+
@bob.sent_messages.process(&:delete)
|
118
|
+
expect(@bob.sent_messages.count).to eq(0)
|
119
|
+
expect(@alice.received_messages.count).to eq(1)
|
125
120
|
|
126
|
-
@alice.received_messages.process
|
127
|
-
@alice.received_messages.count.
|
121
|
+
@alice.received_messages.process(&:delete)
|
122
|
+
expect(@alice.received_messages.count).to eq(0)
|
128
123
|
end
|
129
124
|
|
130
|
-
it
|
131
|
-
@alice.messages.process
|
132
|
-
@alice.messages.count.
|
125
|
+
it 'message should permanent delete' do
|
126
|
+
@alice.messages.process(&:delete)
|
127
|
+
expect(@alice.messages.count).to eq(0)
|
133
128
|
|
134
|
-
@alice.deleted_messages.count.
|
135
|
-
@alice.deleted_messages.process
|
136
|
-
@alice.deleted_messages.count.
|
129
|
+
expect(@alice.deleted_messages.count).to eq(1)
|
130
|
+
@alice.deleted_messages.process(&:delete)
|
131
|
+
expect(@alice.deleted_messages.count).to eq(0)
|
137
132
|
|
138
133
|
@message.reload
|
139
|
-
@message.recipient_permanent_delete.
|
134
|
+
expect(@message.recipient_permanent_delete).to eq(true)
|
140
135
|
|
141
|
-
@bob.sent_messages.count.
|
136
|
+
expect(@bob.sent_messages.count).to eq(1)
|
142
137
|
end
|
143
138
|
|
144
|
-
it
|
145
|
-
|
139
|
+
it 'pat should not able to delete message' do
|
140
|
+
expect { @pat.delete_message(@message) }.to raise_error(RuntimeError)
|
146
141
|
end
|
147
142
|
end
|
148
143
|
|
149
|
-
describe
|
150
|
-
it
|
151
|
-
@alice.received_messages.process
|
144
|
+
describe 'restore message' do
|
145
|
+
it 'alice should restore message' do
|
146
|
+
@alice.received_messages.process(&:delete)
|
152
147
|
@alice.restore_message(@message.reload)
|
153
|
-
@alice.received_messages.count.
|
148
|
+
expect(@alice.received_messages.count).to eq(1)
|
154
149
|
end
|
155
150
|
|
156
|
-
it
|
157
|
-
@alice.received_messages.process
|
158
|
-
@alice.received_messages.count.
|
159
|
-
@alice.deleted_messages.process
|
160
|
-
@alice.received_messages.count.
|
151
|
+
it 'should works with relation' do
|
152
|
+
@alice.received_messages.process(&:delete)
|
153
|
+
expect(@alice.received_messages.count).to eq(0)
|
154
|
+
@alice.deleted_messages.process(&:restore)
|
155
|
+
expect(@alice.received_messages.count).to eq(1)
|
161
156
|
end
|
162
157
|
|
163
|
-
it
|
164
|
-
|
158
|
+
it 'pat should not able to restore message' do
|
159
|
+
expect { @pat.restore_message(@message) }.to raise_error(RuntimeError)
|
165
160
|
end
|
166
161
|
end
|
167
162
|
|
168
|
-
describe
|
169
|
-
it
|
170
|
-
@alice.messages.are_from(@bob).unreaded.count.
|
171
|
-
@alice.messages.are_from(@bob).readed.count.
|
163
|
+
describe 'read/unread feature' do
|
164
|
+
it 'alice should have one unread message from bob' do
|
165
|
+
expect(@alice.messages.are_from(@bob).unreaded.count).to eq(1)
|
166
|
+
expect(@alice.messages.are_from(@bob).readed.count).to eq(0)
|
172
167
|
end
|
173
168
|
|
174
|
-
it
|
169
|
+
it 'alice should able to read message from bob' do
|
175
170
|
@alice.messages.are_from(@bob).first.read
|
176
|
-
@alice.messages.are_from(@bob).unreaded.count.
|
171
|
+
expect(@alice.messages.are_from(@bob).unreaded.count).to eq(0)
|
177
172
|
end
|
178
173
|
|
179
|
-
it
|
174
|
+
it 'alice should able to unread message from bob' do
|
180
175
|
@alice.messages.are_from(@bob).first.read
|
181
176
|
@alice.messages.are_from(@bob).first.unread
|
182
|
-
@alice.messages.are_from(@bob).unreaded.count.
|
177
|
+
expect(@alice.messages.are_from(@bob).unreaded.count).to eq(1)
|
183
178
|
end
|
184
179
|
|
185
|
-
it
|
180
|
+
it 'alice should able to get datetime when he read bob message' do
|
186
181
|
@alice.messages.are_from(@bob).first.read
|
187
182
|
read_datetime = @alice.messages.are_from(@bob).first.updated_at
|
188
|
-
@alice.messages.are_from(@bob).reorder(
|
183
|
+
expect(@alice.messages.are_from(@bob).reorder('updated_at asc').first.updated_at).to eq(read_datetime)
|
189
184
|
end
|
190
185
|
end
|
191
186
|
|
192
|
-
it
|
187
|
+
it 'finds proper message' do
|
193
188
|
@bob.messages.find(@message.id) == @message
|
194
189
|
end
|
195
190
|
|
196
|
-
it
|
197
|
-
@bob.messages.count.
|
198
|
-
@bob.messages.first.topic ==
|
191
|
+
it 'message should have proper topic' do
|
192
|
+
expect(@bob.messages.count).to eq(1)
|
193
|
+
@bob.messages.first.topic == 'Topic'
|
199
194
|
end
|
200
195
|
|
201
|
-
describe
|
202
|
-
it
|
203
|
-
@reply_message =
|
196
|
+
describe 'conversation' do
|
197
|
+
it 'bob send message to alice, and alice reply to bob message and show proper tree' do
|
198
|
+
@reply_message = @alice.reply_to(@message, 'Re: Topic', 'Body')
|
204
199
|
|
205
|
-
@reply_message.conversation.size.
|
206
|
-
@reply_message.conversation.last.topic.
|
207
|
-
@reply_message.conversation.first.topic.
|
200
|
+
expect(@reply_message.conversation.size).to eq(2)
|
201
|
+
expect(@reply_message.conversation.last.topic).to eq('Topic')
|
202
|
+
expect(@reply_message.conversation.first.topic).to eq('Re: Topic')
|
208
203
|
end
|
209
204
|
|
210
|
-
it
|
211
|
-
@reply_message = @alice.reply_to(@message,
|
212
|
-
@reply_reply_message = @bob.reply_to(@reply_message,
|
205
|
+
it 'bob send message to alice, alice answer, and bob answer for alice answer' do
|
206
|
+
@reply_message = @alice.reply_to(@message, 'Re: Topic', 'Body')
|
207
|
+
@reply_reply_message = @bob.reply_to(@reply_message, 'Re: Re: Topic', 'Body')
|
213
208
|
|
214
209
|
[@message, @reply_message, @reply_reply_message].each do |m|
|
215
|
-
m.conversation.size.
|
210
|
+
expect(m.conversation.size).to eq(3)
|
216
211
|
end
|
217
212
|
|
218
|
-
@message.conversation.first.
|
219
|
-
@reply_reply_message.conversation.first.
|
213
|
+
expect(@message.conversation.first).to eq(@reply_reply_message)
|
214
|
+
expect(@reply_reply_message.conversation.first).to eq(@reply_reply_message)
|
220
215
|
end
|
221
216
|
end
|
222
217
|
|
223
|
-
describe
|
218
|
+
describe 'conversations' do
|
224
219
|
before do
|
225
|
-
@reply_message = @message.reply(
|
226
|
-
@reply_reply_message = @reply_message.reply(
|
220
|
+
@reply_message = @message.reply('Re: Topic', 'Body')
|
221
|
+
@reply_reply_message = @reply_message.reply('Re: Re: Topic', 'Body')
|
227
222
|
end
|
228
223
|
|
229
|
-
it
|
230
|
-
@bob.messages.conversations.
|
231
|
-
@reply_message.conversation.
|
224
|
+
it 'bob send message to alice and alice reply' do
|
225
|
+
expect(@bob.messages.conversations).to eq([@reply_reply_message])
|
226
|
+
expect(@reply_message.conversation).to eq([@reply_reply_message, @reply_message, @message])
|
232
227
|
end
|
233
228
|
|
234
|
-
it
|
235
|
-
@sec_message = @bob.send_message(@alice,
|
236
|
-
@sec_reply = @sec_message.reply(
|
237
|
-
@bob.received_messages.conversations.map(&:id).
|
238
|
-
@sec_reply.conversation.to_a.
|
229
|
+
it 'show conversations in proper order' do
|
230
|
+
@sec_message = @bob.send_message(@alice, 'Hi', 'Alice!')
|
231
|
+
@sec_reply = @sec_message.reply('Re: Hi', 'Fine!')
|
232
|
+
expect(@bob.received_messages.conversations.map(&:id)).to eq([@sec_reply.id, @reply_reply_message.id])
|
233
|
+
expect(@sec_reply.conversation.to_a).to eq([@sec_reply, @sec_message])
|
239
234
|
end
|
240
235
|
end
|
241
236
|
|
242
|
-
describe
|
237
|
+
describe 'search text from messages' do
|
243
238
|
before do
|
244
|
-
@reply_message = @message.reply(
|
245
|
-
@reply_reply_message = @reply_message.reply(
|
239
|
+
@reply_message = @message.reply('Re: Topic', 'Body : I am fine')
|
240
|
+
@reply_reply_message = @reply_message.reply('Re: Re: Topic', 'Fine too')
|
246
241
|
end
|
247
242
|
|
248
|
-
it
|
249
|
-
recordset = @bob.messages.search(
|
250
|
-
recordset.count.
|
251
|
-
recordset.
|
243
|
+
it 'bob should be able to search text from messages' do
|
244
|
+
recordset = @bob.messages.search('I am fine')
|
245
|
+
expect(recordset.count).to eq(1)
|
246
|
+
expect(recordset).not_to be_nil
|
252
247
|
end
|
253
248
|
end
|
254
249
|
|
255
|
-
describe
|
256
|
-
it
|
257
|
-
@message = @bob.send_message(@alice,
|
258
|
-
@message.topic.
|
259
|
-
@message.body.
|
250
|
+
describe 'send messages with hash' do
|
251
|
+
it 'send message with hash' do
|
252
|
+
@message = @bob.send_message(@alice, body: 'Body', topic: 'Topic')
|
253
|
+
expect(@message.topic).to eq('Topic')
|
254
|
+
expect(@message.body).to eq('Body')
|
260
255
|
end
|
261
256
|
end
|
262
257
|
|
263
|
-
it
|
264
|
-
@message = send_message(@bob, @alice,
|
265
|
-
@alice.messages.last.body.
|
258
|
+
it 'messages should return in right order :created_at' do
|
259
|
+
@message = send_message(@bob, @alice, 'Example', 'Example Body')
|
260
|
+
expect(@alice.messages.last.body).to eq('Body')
|
266
261
|
end
|
267
262
|
|
268
|
-
it
|
269
|
-
@alice.received_messages.loaded
|
263
|
+
it 'received_messages should return unloaded messages' do
|
264
|
+
expect(@alice.received_messages.loaded?).to be_falsey
|
270
265
|
end
|
271
266
|
|
272
|
-
it
|
273
|
-
@bob.sent_messages.loaded
|
267
|
+
it 'sent_messages should return unloaded messages' do
|
268
|
+
expect(@bob.sent_messages.loaded?).to be_falsey
|
274
269
|
end
|
275
270
|
|
276
|
-
describe
|
277
|
-
it
|
278
|
-
@alice.id.
|
271
|
+
describe 'send messages between two different models (the same id)' do
|
272
|
+
it 'should have the same id' do
|
273
|
+
expect(@alice.id).to be_equal(@admin.id)
|
279
274
|
end
|
280
275
|
|
281
|
-
it
|
282
|
-
@bob.send_message(@alice,
|
283
|
-
@alice.messages.are_to(@alice).size.
|
284
|
-
@alice.messages.are_to(@admin).size.
|
276
|
+
it 'bob send message to admin (different model) with the same id' do
|
277
|
+
@bob.send_message(@alice, 'hello', 'alice')
|
278
|
+
expect(@alice.messages.are_to(@alice).size).to be_equal(2)
|
279
|
+
expect(@alice.messages.are_to(@admin).size).to be_equal(0)
|
285
280
|
end
|
286
281
|
|
287
|
-
it
|
288
|
-
@admin.send_message(@bob,
|
289
|
-
@bob.messages.are_from(@admin).size.
|
290
|
-
@bob.messages.are_from(@alice).size.
|
282
|
+
it 'admin send message to bob' do
|
283
|
+
@admin.send_message(@bob, 'hello', 'bob')
|
284
|
+
expect(@bob.messages.are_from(@admin).size).to be_equal(1)
|
285
|
+
expect(@bob.messages.are_from(@alice).size).to be_equal(0)
|
291
286
|
end
|
292
287
|
end
|
293
288
|
end
|