mailboxer 0.0.14 → 0.0.15
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +20 -1
- data/app/models/conversation.rb +15 -16
- data/app/models/mailbox.rb +6 -1
- data/app/models/message.rb +31 -63
- data/app/models/notification.rb +65 -0
- data/app/models/receipt.rb +15 -6
- data/lib/generators/mailboxer/templates/migration.rb +12 -10
- data/lib/mailboxer/engine.rb +3 -0
- data/lib/mailboxer/models/messageable.rb +17 -2
- data/mailboxer.gemspec +3 -2
- data/spec/dummy/db/migrate/{20110322000127_create_mailboxer.rb → 20110407111612_create_mailboxer.rb} +28 -6
- data/spec/integration/message_and_receipt_spec.rb +72 -72
- data/spec/models/conversation_spec.rb +6 -6
- data/spec/models/mailbox_spec.rb +2 -2
- data/spec/models/message_spec.rb +6 -6
- data/spec/models/notification_spec.rb +68 -0
- data/spec/models/receipt_spec.rb +1 -1
- metadata +8 -6
data/README.rdoc
CHANGED
@@ -4,4 +4,23 @@ This project is based on the need of a private message system for {ging / social
|
|
4
4
|
|
5
5
|
It is born from the great, but old, code from {lpsergi / acts_as_messageable}[https://github.com/psergi/acts_as_messageable].
|
6
6
|
|
7
|
-
There is a lack of documentaion and it will be solved as soon as the gem is more stable and had proved to be useful integrated with SocialStream.
|
7
|
+
There is a lack of documentaion and it will be solved as soon as the gem is more stable and had proved to be useful integrated with SocialStream.
|
8
|
+
|
9
|
+
|
10
|
+
= Installation
|
11
|
+
|
12
|
+
Add to your Gemfile:
|
13
|
+
|
14
|
+
gem 'mailboxer'
|
15
|
+
|
16
|
+
Migrations:
|
17
|
+
|
18
|
+
rails g mailboxer:install
|
19
|
+
|
20
|
+
= Usage
|
21
|
+
|
22
|
+
In your model:
|
23
|
+
|
24
|
+
class User < ActiveRecord::Base
|
25
|
+
acts_as_messageable
|
26
|
+
end
|
data/app/models/conversation.rb
CHANGED
@@ -9,19 +9,19 @@ class Conversation < ActiveRecord::Base
|
|
9
9
|
|
10
10
|
# before_create :clean
|
11
11
|
scope :participant, lambda {|participant|
|
12
|
-
joins(:receipts).select('DISTINCT conversations.*').where('receipts.receiver_id' => participant.id,'receipts.receiver_type' => participant.class.to_s).order("conversations.updated_at DESC")
|
12
|
+
joins(:receipts).select('DISTINCT conversations.*').where('notifications.type'=> Message.to_s,'receipts.receiver_id' => participant.id,'receipts.receiver_type' => participant.class.to_s).order("conversations.updated_at DESC")
|
13
13
|
}
|
14
14
|
scope :inbox, lambda {|participant|
|
15
|
-
joins(:receipts).select('DISTINCT conversations.*').where('receipts.receiver_id' => participant.id,'receipts.receiver_type' => participant.class.to_s, 'receipts.mailbox_type' => 'inbox','receipts.trashed' => false).order("conversations.updated_at DESC")
|
15
|
+
joins(:receipts).select('DISTINCT conversations.*').where('notifications.type'=> Message.to_s,'receipts.receiver_id' => participant.id,'receipts.receiver_type' => participant.class.to_s, 'receipts.mailbox_type' => 'inbox','receipts.trashed' => false).order("conversations.updated_at DESC")
|
16
16
|
}
|
17
17
|
scope :sentbox, lambda {|participant|
|
18
|
-
joins(:receipts).select('DISTINCT conversations.*').where('receipts.receiver_id' => participant.id,'receipts.receiver_type' => participant.class.to_s, 'receipts.mailbox_type' => 'sentbox','receipts.trashed' => false).order("conversations.updated_at DESC")
|
18
|
+
joins(:receipts).select('DISTINCT conversations.*').where('notifications.type'=> Message.to_s,'receipts.receiver_id' => participant.id,'receipts.receiver_type' => participant.class.to_s, 'receipts.mailbox_type' => 'sentbox','receipts.trashed' => false).order("conversations.updated_at DESC")
|
19
19
|
}
|
20
20
|
scope :trash, lambda {|participant|
|
21
|
-
joins(:receipts).select('DISTINCT conversations.*').where('receipts.receiver_id' => participant.id,'receipts.receiver_type' => participant.class.to_s,'receipts.trashed' => true).order("conversations.updated_at DESC")
|
21
|
+
joins(:receipts).select('DISTINCT conversations.*').where('notifications.type'=> Message.to_s,'receipts.receiver_id' => participant.id,'receipts.receiver_type' => participant.class.to_s,'receipts.trashed' => true).order("conversations.updated_at DESC")
|
22
22
|
}
|
23
23
|
scope :unread, lambda {|participant|
|
24
|
-
joins(:receipts).select('DISTINCT conversations.*').where('receipts.receiver_id' => participant.id,'receipts.receiver_type' => participant.class.to_s,'receipts.read' => false).order("conversations.updated_at DESC")
|
24
|
+
joins(:receipts).select('DISTINCT conversations.*').where('notifications.type'=> Message.to_s,'receipts.receiver_id' => participant.id,'receipts.receiver_type' => participant.class.to_s,'receipts.read' => false).order("conversations.updated_at DESC")
|
25
25
|
}
|
26
26
|
class << self
|
27
27
|
def total
|
@@ -31,22 +31,22 @@ class Conversation < ActiveRecord::Base
|
|
31
31
|
|
32
32
|
def mark_as_read(participant)
|
33
33
|
return if participant.nil?
|
34
|
-
return self.
|
34
|
+
return self.receipts_for(participant).mark_as_read
|
35
35
|
end
|
36
36
|
|
37
37
|
def mark_as_unread(participant)
|
38
38
|
return if participant.nil?
|
39
|
-
return self.
|
39
|
+
return self.receipts_for(participant).mark_as_unread
|
40
40
|
end
|
41
41
|
|
42
42
|
def move_to_trash(participant)
|
43
43
|
return if participant.nil?
|
44
|
-
return self.
|
44
|
+
return self.receipts_for(participant).move_to_trash
|
45
45
|
end
|
46
46
|
|
47
47
|
def untrash(participant)
|
48
48
|
return if participant.nil?
|
49
|
-
return self.
|
49
|
+
return self.receipts_for(participant).untrash
|
50
50
|
end
|
51
51
|
|
52
52
|
def recipients
|
@@ -82,9 +82,8 @@ class Conversation < ActiveRecord::Base
|
|
82
82
|
return @last_message
|
83
83
|
end
|
84
84
|
|
85
|
-
def
|
86
|
-
return Receipt.conversation(self).receiver(participant)
|
87
|
-
return Receipt.conversation(self)
|
85
|
+
def receipts_for(participant)
|
86
|
+
return Receipt.conversation(self).receiver(participant)
|
88
87
|
end
|
89
88
|
|
90
89
|
def count_messages
|
@@ -93,22 +92,22 @@ class Conversation < ActiveRecord::Base
|
|
93
92
|
|
94
93
|
def is_participant?(participant)
|
95
94
|
return false if participant.nil?
|
96
|
-
return self.
|
95
|
+
return self.receipts_for(participant).count != 0
|
97
96
|
end
|
98
97
|
|
99
98
|
def is_trashed?(participant)
|
100
99
|
return false if participant.nil?
|
101
|
-
return self.
|
100
|
+
return self.receipts_for(participant).trash.count!=0
|
102
101
|
end
|
103
102
|
|
104
103
|
def is_completely_trashed?(participant)
|
105
104
|
return false if participant.nil?
|
106
|
-
return self.
|
105
|
+
return self.receipts_for(participant).trash.count==self.receipts(participant).count
|
107
106
|
end
|
108
107
|
|
109
108
|
def is_unread?(participant)
|
110
109
|
return false if participant.nil?
|
111
|
-
return self.
|
110
|
+
return self.receipts_for(participant).unread.count!=0
|
112
111
|
end
|
113
112
|
# protected
|
114
113
|
# #[empty method]
|
data/app/models/mailbox.rb
CHANGED
@@ -4,6 +4,10 @@ class Mailbox
|
|
4
4
|
def initialize(recipient, box = :all)
|
5
5
|
@messageable = recipient
|
6
6
|
end
|
7
|
+
|
8
|
+
def notifications(options = {})
|
9
|
+
return Receipt.where(options).receiver(@messageable).notifications
|
10
|
+
end
|
7
11
|
|
8
12
|
def conversations(options = {})
|
9
13
|
conv = Conversation.participant(@messageable)
|
@@ -22,7 +26,7 @@ class Mailbox
|
|
22
26
|
if (options[:read].present? and options[:read]==false) or (options[:unread].present? and options[:unread]==true)
|
23
27
|
conv = conv.unread(@messageable)
|
24
28
|
end
|
25
|
-
|
29
|
+
|
26
30
|
return conv.uniq
|
27
31
|
end
|
28
32
|
|
@@ -46,6 +50,7 @@ class Mailbox
|
|
46
50
|
end
|
47
51
|
|
48
52
|
def empty_trash(options = {})
|
53
|
+
#TODO
|
49
54
|
return false
|
50
55
|
end
|
51
56
|
|
data/app/models/message.rb
CHANGED
@@ -1,82 +1,50 @@
|
|
1
|
-
class Message <
|
2
|
-
#
|
3
|
-
attr_accessor :recipients
|
4
|
-
belongs_to :sender, :polymorphic => :true
|
1
|
+
class Message < Notification
|
2
|
+
#
|
5
3
|
belongs_to :conversation, :validate => true, :autosave => true
|
6
|
-
validates_presence_of :
|
7
|
-
|
4
|
+
validates_presence_of :sender
|
5
|
+
|
8
6
|
class_inheritable_accessor :on_deliver_callback
|
9
|
-
protected :on_deliver_callback
|
10
|
-
|
11
|
-
scope :conversation, lambda { |conversation|
|
7
|
+
protected :on_deliver_callback
|
8
|
+
scope :conversation, lambda { |conversation|
|
12
9
|
where(:conversation_id => conversation.id)
|
13
10
|
}
|
14
|
-
|
15
11
|
class << self
|
16
12
|
def on_deliver(callback_method)
|
17
13
|
self.on_deliver_callback = callback_method
|
18
14
|
end
|
19
|
-
end
|
20
|
-
|
15
|
+
end
|
16
|
+
|
21
17
|
def deliver(reply = false, should_clean = true)
|
22
18
|
self.clean if should_clean
|
23
19
|
temp_receipts = Array.new
|
24
20
|
#Receiver receipts
|
25
21
|
self.recipients.each do |r|
|
26
22
|
msg_receipt = Receipt.new
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
23
|
+
msg_receipt.notification = self
|
24
|
+
msg_receipt.read = false
|
25
|
+
msg_receipt.receiver = r
|
26
|
+
msg_receipt.mailbox_type = "inbox"
|
27
|
+
temp_receipts << msg_receipt
|
32
28
|
end
|
33
29
|
#Sender receipt
|
34
30
|
sender_receipt = Receipt.new
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
return sender_receipt
|
51
|
-
end
|
52
|
-
|
53
|
-
def recipients
|
54
|
-
if @recipients.blank?
|
55
|
-
recipients_array = Array.new
|
56
|
-
self.receipts.each do |receipt|
|
57
|
-
recipients_array << receipt.receiver
|
58
|
-
end
|
59
|
-
return recipients_array
|
60
|
-
end
|
61
|
-
return @recipients
|
62
|
-
end
|
31
|
+
sender_receipt.notification = self
|
32
|
+
sender_receipt.read = true
|
33
|
+
sender_receipt.receiver = self.sender
|
34
|
+
sender_receipt.mailbox_type = "sentbox"
|
35
|
+
temp_receipts << sender_receipt
|
36
|
+
|
37
|
+
temp_receipts.each(&:valid?)
|
38
|
+
if temp_receipts.all? { |t| t.errors.empty? }
|
39
|
+
temp_receipts.each(&:save!) #Save receipts
|
40
|
+
if reply
|
41
|
+
self.conversation.update_attribute(:updated_at, Time.now)
|
42
|
+
end
|
43
|
+
self.recipients=nil
|
44
|
+
self.on_deliver_callback.call(self) unless self.on_deliver_callback.nil?
|
45
|
+
end
|
46
|
+
return sender_receipt
|
47
|
+
end
|
48
|
+
|
63
49
|
|
64
|
-
def receipts(participant=nil)
|
65
|
-
return Receipt.message(self).receiver(participant) if participant
|
66
|
-
return Receipt.message(self)
|
67
|
-
end
|
68
|
-
|
69
|
-
def is_unread?(participant)
|
70
|
-
return false if participant.nil?
|
71
|
-
return self.receipts(participant).unread.count!=0
|
72
|
-
end
|
73
|
-
|
74
|
-
include ActionView::Helpers::SanitizeHelper
|
75
|
-
def clean
|
76
|
-
unless self.subject.nil?
|
77
|
-
self.subject = sanitize self.subject
|
78
|
-
end
|
79
|
-
self.body = sanitize self.body
|
80
|
-
end
|
81
|
-
|
82
50
|
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
class Notification < ActiveRecord::Base
|
2
|
+
|
3
|
+
attr_accessor :recipients
|
4
|
+
belongs_to :sender, :polymorphic => :true
|
5
|
+
validates_presence_of :subject, :body
|
6
|
+
has_many :receipts
|
7
|
+
|
8
|
+
class << self
|
9
|
+
def notify_all(recipients,subject,body)
|
10
|
+
notification = Notification.new({:body => body, :subject => subject})
|
11
|
+
notification.recipients = recipients.is_a?(Array) ? recipients : [recipients]
|
12
|
+
notification.recipients = notification.recipients.uniq
|
13
|
+
return notification.deliver
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def deliver(should_clean = true)
|
18
|
+
self.clean if should_clean
|
19
|
+
temp_receipts = Array.new
|
20
|
+
#Receiver receipts
|
21
|
+
self.recipients.each do |r|
|
22
|
+
msg_receipt = Receipt.new
|
23
|
+
msg_receipt.notification = self
|
24
|
+
msg_receipt.read = false
|
25
|
+
msg_receipt.receiver = r
|
26
|
+
temp_receipts << msg_receipt
|
27
|
+
end
|
28
|
+
temp_receipts.each(&:valid?)
|
29
|
+
if temp_receipts.all? { |t| t.errors.empty? }
|
30
|
+
temp_receipts.each(&:save!) #Save receipts
|
31
|
+
self.recipients=nil
|
32
|
+
end
|
33
|
+
return temp_receipts
|
34
|
+
end
|
35
|
+
|
36
|
+
def recipients
|
37
|
+
if @recipients.blank?
|
38
|
+
recipients_array = Array.new
|
39
|
+
self.receipts.each do |receipt|
|
40
|
+
recipients_array << receipt.receiver
|
41
|
+
end
|
42
|
+
return recipients_array
|
43
|
+
end
|
44
|
+
return @recipients
|
45
|
+
end
|
46
|
+
|
47
|
+
def receipt_for(participant)
|
48
|
+
return Receipt.notification(self).receiver(participant)
|
49
|
+
end
|
50
|
+
|
51
|
+
def is_unread?(participant)
|
52
|
+
return false if participant.nil?
|
53
|
+
return self.receipt_for(participant).unread.count!=0
|
54
|
+
end
|
55
|
+
|
56
|
+
include ActionView::Helpers::SanitizeHelper
|
57
|
+
|
58
|
+
def clean
|
59
|
+
unless self.subject.nil?
|
60
|
+
self.subject = sanitize self.subject
|
61
|
+
end
|
62
|
+
self.body = sanitize self.body
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
data/app/models/receipt.rb
CHANGED
@@ -1,18 +1,22 @@
|
|
1
1
|
class Receipt < ActiveRecord::Base
|
2
|
-
belongs_to :
|
3
|
-
has_one :conversation, :through => :message
|
2
|
+
belongs_to :notification, :validate => true, :autosave => true
|
4
3
|
belongs_to :receiver, :polymorphic => :true
|
5
|
-
|
4
|
+
belongs_to :message, :foreign_key => "notification_id"
|
5
|
+
|
6
6
|
validates_presence_of :receiver
|
7
7
|
|
8
8
|
scope :receiver, lambda { |receiver|
|
9
9
|
where(:receiver_id => receiver.id,:receiver_type => receiver.class.to_s)
|
10
10
|
}
|
11
|
-
|
12
|
-
|
11
|
+
#Notifications Scope checks type to be nil, not Notification because of STI behaviour
|
12
|
+
#with the primary class (no type is saved)
|
13
|
+
scope :notifications, joins(:notification).where('notifications.type' => nil)
|
14
|
+
scope :messages, joins(:notification).where('notifications.type' => Message.to_s)
|
15
|
+
scope :notification, lambda { |notification|
|
16
|
+
where(:notification_id => notification.id)
|
13
17
|
}
|
14
18
|
scope :conversation, lambda { |conversation|
|
15
|
-
joins(:
|
19
|
+
joins(:notification).where('notifications.conversation_id' => conversation.id)
|
16
20
|
}
|
17
21
|
scope :sentbox, where(:mailbox_type => "sentbox")
|
18
22
|
scope :inbox, where(:mailbox_type => "inbox")
|
@@ -72,6 +76,11 @@ class Receipt < ActiveRecord::Base
|
|
72
76
|
update_attributes(:mailbox_type => :sentbox, :trashed => false)
|
73
77
|
end
|
74
78
|
|
79
|
+
def conversation
|
80
|
+
return nil if notification.class == Notification
|
81
|
+
return notification.conversation if notification.class == Message
|
82
|
+
end
|
83
|
+
|
75
84
|
protected
|
76
85
|
|
77
86
|
def remove_duplicate_errors
|
@@ -10,7 +10,7 @@ class CreateMailboxer < ActiveRecord::Migration
|
|
10
10
|
#Receipts
|
11
11
|
create_table :receipts do |t|
|
12
12
|
t.references :receiver, :polymorphic => true
|
13
|
-
t.column :
|
13
|
+
t.column :notification_id, :integer, :null => false
|
14
14
|
t.column :read, :boolean, :default => false
|
15
15
|
t.column :trashed, :boolean, :default => false
|
16
16
|
t.column :deleted, :boolean, :default => false
|
@@ -18,8 +18,9 @@ class CreateMailboxer < ActiveRecord::Migration
|
|
18
18
|
t.column :created_at, :datetime, :null => false
|
19
19
|
t.column :updated_at, :datetime, :null => false
|
20
20
|
end
|
21
|
-
#Messages
|
22
|
-
create_table :
|
21
|
+
#Notifications and Messages
|
22
|
+
create_table :notifications do |t|
|
23
|
+
t.column :type, :string
|
23
24
|
t.column :body, :text
|
24
25
|
t.column :subject, :string, :default => ""
|
25
26
|
t.references :sender, :polymorphic => true
|
@@ -33,26 +34,27 @@ class CreateMailboxer < ActiveRecord::Migration
|
|
33
34
|
#Indexes
|
34
35
|
#Conversations
|
35
36
|
#Receipts
|
36
|
-
add_index "receipts","
|
37
|
+
add_index "receipts","notification_id"
|
38
|
+
|
37
39
|
#Messages
|
38
|
-
add_index "
|
40
|
+
add_index "notifications","conversation_id"
|
39
41
|
|
40
42
|
#Foreign keys
|
41
43
|
#Conversations
|
42
44
|
#Receipts
|
43
|
-
add_foreign_key "receipts", "
|
45
|
+
add_foreign_key "receipts", "notifications", :name => "receipts_on_notification_id"
|
44
46
|
#Messages
|
45
|
-
add_foreign_key "
|
47
|
+
add_foreign_key "notifications", "conversations", :name => "notifications_on_conversation_id"
|
46
48
|
end
|
47
49
|
|
48
50
|
def self.down
|
49
51
|
#Tables
|
50
|
-
remove_foreign_key "receipts", :name => "
|
51
|
-
remove_foreign_key "
|
52
|
+
remove_foreign_key "receipts", :name => "receipts_on_notification_id"
|
53
|
+
remove_foreign_key "notifications", :name => "notifications_on_conversation_id"
|
52
54
|
|
53
55
|
#Indexes
|
54
56
|
drop_table :receipts
|
55
57
|
drop_table :conversations
|
56
|
-
drop_table :
|
58
|
+
drop_table :notifications
|
57
59
|
end
|
58
60
|
end
|
data/lib/mailboxer/engine.rb
CHANGED
@@ -15,11 +15,24 @@ module Mailboxer
|
|
15
15
|
end
|
16
16
|
|
17
17
|
module InstanceMethods
|
18
|
+
|
19
|
+
################################### MAILBOXES
|
20
|
+
|
18
21
|
def mailbox
|
19
22
|
@mailbox = Mailbox.new(self) if @mailbox.nil?
|
20
23
|
@mailbox.type = :all
|
21
24
|
return @mailbox
|
22
25
|
end
|
26
|
+
|
27
|
+
################################### NOTIFICATIONS
|
28
|
+
|
29
|
+
def notify(subject,body)
|
30
|
+
notification = Notification.new({:body => body, :subject => subject})
|
31
|
+
notification.recipients = [self]
|
32
|
+
return notification.deliver
|
33
|
+
end
|
34
|
+
|
35
|
+
################################### MESSAGES
|
23
36
|
|
24
37
|
def send_message(recipients, msg_body, subject)
|
25
38
|
convo = Conversation.new({:subject => subject})
|
@@ -39,11 +52,11 @@ module Mailboxer
|
|
39
52
|
end
|
40
53
|
|
41
54
|
def reply_to_sender(receipt, reply_body, subject = nil)
|
42
|
-
return reply(receipt.conversation, receipt.
|
55
|
+
return reply(receipt.conversation, receipt.notification.sender, reply_body, subject)
|
43
56
|
end
|
44
57
|
|
45
58
|
def reply_to_all(receipt, reply_body, subject = nil)
|
46
|
-
return reply(receipt.conversation, receipt.
|
59
|
+
return reply(receipt.conversation, receipt.notification.recipients, reply_body, subject)
|
47
60
|
end
|
48
61
|
|
49
62
|
def reply_to_conversation(conversation, reply_body, subject = nil)
|
@@ -81,6 +94,8 @@ module Mailboxer
|
|
81
94
|
end
|
82
95
|
return nil
|
83
96
|
end
|
97
|
+
|
98
|
+
|
84
99
|
end
|
85
100
|
end
|
86
101
|
end
|
data/mailboxer.gemspec
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "mailboxer"
|
3
|
-
s.version = "0.0.
|
3
|
+
s.version = "0.0.15"
|
4
4
|
s.authors = ["Eduardo Casanova Cuesta"]
|
5
5
|
s.summary = "Messaging system for rails apps."
|
6
|
-
s.description = "A Rails engine that allows any model to act as messageable, permitting it interchange messages with any other messageable model."
|
6
|
+
s.description = "A Rails engine that allows any model to act as messageable, permitting it interchange messages with any other messageable model." +
|
7
|
+
"It also supports sending system notifications to messageable models."
|
7
8
|
s.email = "ecasanovac@gmail.com"
|
8
9
|
s.homepage = "http://github.com/ging/mailboxer"
|
9
10
|
s.files = `git ls-files`.split("\n")
|
data/spec/dummy/db/migrate/{20110322000127_create_mailboxer.rb → 20110407111612_create_mailboxer.rb}
RENAMED
@@ -1,13 +1,16 @@
|
|
1
1
|
class CreateMailboxer < ActiveRecord::Migration
|
2
2
|
def self.up
|
3
|
+
#Tables
|
4
|
+
#Conversations
|
3
5
|
create_table :conversations do |t|
|
4
6
|
t.column :subject, :string, :default => ""
|
5
7
|
t.column :created_at, :datetime, :null => false
|
6
8
|
t.column :updated_at, :datetime, :null => false
|
7
9
|
end
|
10
|
+
#Receipts
|
8
11
|
create_table :receipts do |t|
|
9
12
|
t.references :receiver, :polymorphic => true
|
10
|
-
t.column :
|
13
|
+
t.column :notification_id, :integer, :null => false
|
11
14
|
t.column :read, :boolean, :default => false
|
12
15
|
t.column :trashed, :boolean, :default => false
|
13
16
|
t.column :deleted, :boolean, :default => false
|
@@ -15,23 +18,42 @@ class CreateMailboxer < ActiveRecord::Migration
|
|
15
18
|
t.column :created_at, :datetime, :null => false
|
16
19
|
t.column :updated_at, :datetime, :null => false
|
17
20
|
end
|
18
|
-
|
21
|
+
#Notifications and Messages
|
22
|
+
create_table :notifications do |t|
|
23
|
+
t.column :type, :string
|
19
24
|
t.column :body, :text
|
20
25
|
t.column :subject, :string, :default => ""
|
21
|
-
t.column :headers, :text
|
22
26
|
t.references :sender, :polymorphic => true
|
23
27
|
t.column :conversation_id, :integer
|
24
|
-
t.column :sent, :boolean, :default => false
|
25
28
|
t.column :draft, :boolean, :default => false
|
26
|
-
t.column :system, :boolean, :default => false
|
27
29
|
t.column :updated_at, :datetime, :null => false
|
28
30
|
t.column :created_at, :datetime, :null => false
|
29
31
|
end
|
32
|
+
|
33
|
+
|
34
|
+
#Indexes
|
35
|
+
#Conversations
|
36
|
+
#Receipts
|
37
|
+
add_index "receipts","notification_id"
|
38
|
+
#Messages
|
39
|
+
add_index "notifications","conversation_id"
|
40
|
+
|
41
|
+
#Foreign keys
|
42
|
+
#Conversations
|
43
|
+
#Receipts
|
44
|
+
add_foreign_key "receipts", "notifications", :name => "receipts_on_notification_id"
|
45
|
+
#Messages
|
46
|
+
add_foreign_key "notifications", "conversations", :name => "notifications_on_conversation_id"
|
30
47
|
end
|
31
48
|
|
32
49
|
def self.down
|
50
|
+
#Tables
|
51
|
+
remove_foreign_key "receipts", :name => "receipts_on_notification_id"
|
52
|
+
remove_foreign_key "notifications", :name => "notifications_on_conversation_id"
|
53
|
+
|
54
|
+
#Indexes
|
33
55
|
drop_table :receipts
|
34
56
|
drop_table :conversations
|
35
|
-
drop_table :
|
57
|
+
drop_table :notifications
|
36
58
|
end
|
37
59
|
end
|
@@ -11,8 +11,8 @@ describe "Messages And Receipts" do
|
|
11
11
|
describe "message sending" do
|
12
12
|
|
13
13
|
before do
|
14
|
-
@
|
15
|
-
@message1 = @
|
14
|
+
@receipt1 = @entity1.send_message(@entity2,"Body","Subject")
|
15
|
+
@message1 = @receipt1.notification
|
16
16
|
end
|
17
17
|
|
18
18
|
it "should create proper message" do
|
@@ -24,7 +24,7 @@ describe "Messages And Receipts" do
|
|
24
24
|
|
25
25
|
it "should create proper mails" do
|
26
26
|
#Sender Mail
|
27
|
-
mail = Receipt.receiver(@entity1).
|
27
|
+
mail = Receipt.receiver(@entity1).notification(@message1).first
|
28
28
|
assert mail
|
29
29
|
if mail
|
30
30
|
mail.read.should==true
|
@@ -32,7 +32,7 @@ describe "Messages And Receipts" do
|
|
32
32
|
mail.mailbox_type.should=="sentbox"
|
33
33
|
end
|
34
34
|
#Receiver Mail
|
35
|
-
mail = Receipt.receiver(@entity2).
|
35
|
+
mail = Receipt.receiver(@entity2).notification(@message1).first
|
36
36
|
assert mail
|
37
37
|
if mail
|
38
38
|
mail.read.should==false
|
@@ -52,10 +52,10 @@ describe "Messages And Receipts" do
|
|
52
52
|
|
53
53
|
describe "message replying to sender" do
|
54
54
|
before do
|
55
|
-
@
|
56
|
-
@
|
57
|
-
@message1 = @
|
58
|
-
@message2 = @
|
55
|
+
@receipt1 = @entity1.send_message(@entity2,"Body","Subject")
|
56
|
+
@receipt2 = @entity2.reply_to_sender(@receipt1,"Reply body")
|
57
|
+
@message1 = @receipt1.notification
|
58
|
+
@message2 = @receipt2.notification
|
59
59
|
end
|
60
60
|
|
61
61
|
it "should create proper message" do
|
@@ -67,7 +67,7 @@ describe "Messages And Receipts" do
|
|
67
67
|
|
68
68
|
it "should create proper mails" do
|
69
69
|
#Sender Mail
|
70
|
-
mail = Receipt.receiver(@entity2).
|
70
|
+
mail = Receipt.receiver(@entity2).notification(@message2).first
|
71
71
|
assert mail
|
72
72
|
if mail
|
73
73
|
mail.read.should==true
|
@@ -75,7 +75,7 @@ describe "Messages And Receipts" do
|
|
75
75
|
mail.mailbox_type.should=="sentbox"
|
76
76
|
end
|
77
77
|
#Receiver Mail
|
78
|
-
mail = Receipt.receiver(@entity1).
|
78
|
+
mail = Receipt.receiver(@entity1).notification(@message2).first
|
79
79
|
assert mail
|
80
80
|
if mail
|
81
81
|
mail.read.should==false
|
@@ -98,10 +98,10 @@ describe "Messages And Receipts" do
|
|
98
98
|
|
99
99
|
describe "message replying to all" do
|
100
100
|
before do
|
101
|
-
@
|
102
|
-
@
|
103
|
-
@message1 = @
|
104
|
-
@message2 = @
|
101
|
+
@receipt1 = @entity1.send_message(@entity2,"Body","Subject")
|
102
|
+
@receipt2 = @entity2.reply_to_all(@receipt1,"Reply body")
|
103
|
+
@message1 = @receipt1.notification
|
104
|
+
@message2 = @receipt2.notification
|
105
105
|
end
|
106
106
|
|
107
107
|
it "should create proper message" do
|
@@ -113,7 +113,7 @@ describe "Messages And Receipts" do
|
|
113
113
|
|
114
114
|
it "should create proper mails" do
|
115
115
|
#Sender Mail
|
116
|
-
mail = Receipt.receiver(@entity2).
|
116
|
+
mail = Receipt.receiver(@entity2).notification(@message2).first
|
117
117
|
assert mail
|
118
118
|
if mail
|
119
119
|
mail.read.should==true
|
@@ -121,7 +121,7 @@ describe "Messages And Receipts" do
|
|
121
121
|
mail.mailbox_type.should=="sentbox"
|
122
122
|
end
|
123
123
|
#Receiver Mail
|
124
|
-
mail = Receipt.receiver(@entity1).
|
124
|
+
mail = Receipt.receiver(@entity1).notification(@message2).first
|
125
125
|
assert mail
|
126
126
|
if mail
|
127
127
|
mail.read.should==false
|
@@ -143,10 +143,10 @@ describe "Messages And Receipts" do
|
|
143
143
|
end
|
144
144
|
describe "message replying to conversation" do
|
145
145
|
before do
|
146
|
-
@
|
147
|
-
@
|
148
|
-
@message1 = @
|
149
|
-
@message2 = @
|
146
|
+
@receipt1 = @entity1.send_message(@entity2,"Body","Subject")
|
147
|
+
@receipt2 = @entity2.reply_to_conversation(@receipt1.conversation,"Reply body")
|
148
|
+
@message1 = @receipt1.notification
|
149
|
+
@message2 = @receipt2.notification
|
150
150
|
end
|
151
151
|
|
152
152
|
it "should create proper message" do
|
@@ -158,7 +158,7 @@ describe "Messages And Receipts" do
|
|
158
158
|
|
159
159
|
it "should create proper mails" do
|
160
160
|
#Sender Mail
|
161
|
-
mail = Receipt.receiver(@entity2).
|
161
|
+
mail = Receipt.receiver(@entity2).notification(@message2).first
|
162
162
|
assert mail
|
163
163
|
if mail
|
164
164
|
mail.read.should==true
|
@@ -166,7 +166,7 @@ describe "Messages And Receipts" do
|
|
166
166
|
mail.mailbox_type.should=="sentbox"
|
167
167
|
end
|
168
168
|
#Receiver Mail
|
169
|
-
mail = Receipt.receiver(@entity1).
|
169
|
+
mail = Receipt.receiver(@entity1).notification(@message2).first
|
170
170
|
assert mail
|
171
171
|
if mail
|
172
172
|
mail.read.should==false
|
@@ -197,8 +197,8 @@ describe "Messages And Receipts" do
|
|
197
197
|
describe "message sending" do
|
198
198
|
|
199
199
|
before do
|
200
|
-
@
|
201
|
-
@message1 = @
|
200
|
+
@receipt1 = @entity1.send_message(@entity2,"Body","Subject")
|
201
|
+
@message1 = @receipt1.notification
|
202
202
|
end
|
203
203
|
|
204
204
|
it "should create proper message" do
|
@@ -210,7 +210,7 @@ describe "Messages And Receipts" do
|
|
210
210
|
|
211
211
|
it "should create proper mails" do
|
212
212
|
#Sender Mail
|
213
|
-
mail = Receipt.receiver(@entity1).
|
213
|
+
mail = Receipt.receiver(@entity1).notification(@message1).first
|
214
214
|
assert mail
|
215
215
|
if mail
|
216
216
|
mail.read.should==true
|
@@ -218,7 +218,7 @@ describe "Messages And Receipts" do
|
|
218
218
|
mail.mailbox_type.should=="sentbox"
|
219
219
|
end
|
220
220
|
#Receiver Mail
|
221
|
-
mail = Receipt.receiver(@entity2).
|
221
|
+
mail = Receipt.receiver(@entity2).notification(@message1).first
|
222
222
|
assert mail
|
223
223
|
if mail
|
224
224
|
mail.read.should==false
|
@@ -238,10 +238,10 @@ describe "Messages And Receipts" do
|
|
238
238
|
|
239
239
|
describe "message replying to sender" do
|
240
240
|
before do
|
241
|
-
@
|
242
|
-
@
|
243
|
-
@message1 = @
|
244
|
-
@message2 = @
|
241
|
+
@receipt1 = @entity1.send_message(@entity2,"Body","Subject")
|
242
|
+
@receipt2 = @entity2.reply_to_sender(@receipt1,"Reply body")
|
243
|
+
@message1 = @receipt1.notification
|
244
|
+
@message2 = @receipt2.notification
|
245
245
|
end
|
246
246
|
|
247
247
|
it "should create proper message" do
|
@@ -253,7 +253,7 @@ describe "Messages And Receipts" do
|
|
253
253
|
|
254
254
|
it "should create proper mails" do
|
255
255
|
#Sender Mail
|
256
|
-
mail = Receipt.receiver(@entity2).
|
256
|
+
mail = Receipt.receiver(@entity2).notification(@message2).first
|
257
257
|
assert mail
|
258
258
|
if mail
|
259
259
|
mail.read.should==true
|
@@ -261,7 +261,7 @@ describe "Messages And Receipts" do
|
|
261
261
|
mail.mailbox_type.should=="sentbox"
|
262
262
|
end
|
263
263
|
#Receiver Mail
|
264
|
-
mail = Receipt.receiver(@entity1).
|
264
|
+
mail = Receipt.receiver(@entity1).notification(@message2).first
|
265
265
|
assert mail
|
266
266
|
if mail
|
267
267
|
mail.read.should==false
|
@@ -284,10 +284,10 @@ describe "Messages And Receipts" do
|
|
284
284
|
|
285
285
|
describe "message replying to all" do
|
286
286
|
before do
|
287
|
-
@
|
288
|
-
@
|
289
|
-
@message1 = @
|
290
|
-
@message2 = @
|
287
|
+
@receipt1 = @entity1.send_message(@entity2,"Body","Subject")
|
288
|
+
@receipt2 = @entity2.reply_to_all(@receipt1,"Reply body")
|
289
|
+
@message1 = @receipt1.notification
|
290
|
+
@message2 = @receipt2.notification
|
291
291
|
end
|
292
292
|
|
293
293
|
it "should create proper message" do
|
@@ -299,7 +299,7 @@ describe "Messages And Receipts" do
|
|
299
299
|
|
300
300
|
it "should create proper mails" do
|
301
301
|
#Sender Mail
|
302
|
-
mail = Receipt.receiver(@entity2).
|
302
|
+
mail = Receipt.receiver(@entity2).notification(@message2).first
|
303
303
|
assert mail
|
304
304
|
if mail
|
305
305
|
mail.read.should==true
|
@@ -307,7 +307,7 @@ describe "Messages And Receipts" do
|
|
307
307
|
mail.mailbox_type.should=="sentbox"
|
308
308
|
end
|
309
309
|
#Receiver Mail
|
310
|
-
mail = Receipt.receiver(@entity1).
|
310
|
+
mail = Receipt.receiver(@entity1).notification(@message2).first
|
311
311
|
assert mail
|
312
312
|
if mail
|
313
313
|
mail.read.should==false
|
@@ -363,8 +363,8 @@ describe "Messages And Receipts" do
|
|
363
363
|
describe "message sending" do
|
364
364
|
|
365
365
|
before do
|
366
|
-
@
|
367
|
-
@message1 = @
|
366
|
+
@receipt1 = @entity1.send_message(@recipients,"Body","Subject")
|
367
|
+
@message1 = @receipt1.notification
|
368
368
|
end
|
369
369
|
|
370
370
|
it "should create proper message" do
|
@@ -376,7 +376,7 @@ describe "Messages And Receipts" do
|
|
376
376
|
|
377
377
|
it "should create proper mails" do
|
378
378
|
#Sender Mail
|
379
|
-
mail = Receipt.receiver(@entity1).
|
379
|
+
mail = Receipt.receiver(@entity1).notification(@message1).first
|
380
380
|
assert mail
|
381
381
|
if mail
|
382
382
|
mail.read.should==true
|
@@ -385,7 +385,7 @@ describe "Messages And Receipts" do
|
|
385
385
|
end
|
386
386
|
#Receiver Mails
|
387
387
|
@recipients.each do |receiver|
|
388
|
-
mail = Receipt.receiver(receiver).
|
388
|
+
mail = Receipt.receiver(receiver).notification(@message1).first
|
389
389
|
assert mail
|
390
390
|
if mail
|
391
391
|
mail.read.should==false
|
@@ -407,10 +407,10 @@ describe "Messages And Receipts" do
|
|
407
407
|
|
408
408
|
describe "message replying to sender" do
|
409
409
|
before do
|
410
|
-
@
|
411
|
-
@
|
412
|
-
@message1 = @
|
413
|
-
@message2 = @
|
410
|
+
@receipt1 = @entity1.send_message(@recipients,"Body","Subject")
|
411
|
+
@receipt2 = @entity2.reply_to_sender(@receipt1,"Reply body")
|
412
|
+
@message1 = @receipt1.notification
|
413
|
+
@message2 = @receipt2.notification
|
414
414
|
end
|
415
415
|
|
416
416
|
it "should create proper message" do
|
@@ -422,7 +422,7 @@ describe "Messages And Receipts" do
|
|
422
422
|
|
423
423
|
it "should create proper mails" do
|
424
424
|
#Sender Mail
|
425
|
-
mail = Receipt.receiver(@entity2).
|
425
|
+
mail = Receipt.receiver(@entity2).notification(@message2).first
|
426
426
|
assert mail
|
427
427
|
if mail
|
428
428
|
mail.read.should==true
|
@@ -430,7 +430,7 @@ describe "Messages And Receipts" do
|
|
430
430
|
mail.mailbox_type.should=="sentbox"
|
431
431
|
end
|
432
432
|
#Receiver Mail
|
433
|
-
mail = Receipt.receiver(@entity1).
|
433
|
+
mail = Receipt.receiver(@entity1).notification(@message2).first
|
434
434
|
assert mail
|
435
435
|
if mail
|
436
436
|
mail.read.should==false
|
@@ -439,7 +439,7 @@ describe "Messages And Receipts" do
|
|
439
439
|
end
|
440
440
|
|
441
441
|
#No Receiver, No Mail
|
442
|
-
mail = Receipt.receiver(@entity3).
|
442
|
+
mail = Receipt.receiver(@entity3).notification(@message2).first
|
443
443
|
assert mail.nil?
|
444
444
|
|
445
445
|
end
|
@@ -459,10 +459,10 @@ describe "Messages And Receipts" do
|
|
459
459
|
|
460
460
|
describe "message replying to all" do
|
461
461
|
before do
|
462
|
-
@
|
463
|
-
@
|
464
|
-
@message1 = @
|
465
|
-
@message2 = @
|
462
|
+
@receipt1 = @entity1.send_message(@recipients,"Body","Subject")
|
463
|
+
@receipt2 = @entity2.reply_to_all(@receipt1,"Reply body")
|
464
|
+
@message1 = @receipt1.notification
|
465
|
+
@message2 = @receipt2.notification
|
466
466
|
@recipients2 = Array.new
|
467
467
|
@recipients2 << @entity1
|
468
468
|
@recipients2 << @entity3
|
@@ -478,7 +478,7 @@ describe "Messages And Receipts" do
|
|
478
478
|
|
479
479
|
it "should create proper mails" do
|
480
480
|
#Sender Mail
|
481
|
-
mail = Receipt.receiver(@entity2).
|
481
|
+
mail = Receipt.receiver(@entity2).notification(@message2).first
|
482
482
|
assert mail
|
483
483
|
if mail
|
484
484
|
mail.read.should==true
|
@@ -487,7 +487,7 @@ describe "Messages And Receipts" do
|
|
487
487
|
end
|
488
488
|
#Receiver Mails
|
489
489
|
@recipients2.each do |receiver|
|
490
|
-
mail = Receipt.receiver(receiver).
|
490
|
+
mail = Receipt.receiver(receiver).notification(@message2).first
|
491
491
|
assert mail
|
492
492
|
if mail
|
493
493
|
mail.read.should==false
|
@@ -545,8 +545,8 @@ describe "Messages And Receipts" do
|
|
545
545
|
describe "message sending" do
|
546
546
|
|
547
547
|
before do
|
548
|
-
@
|
549
|
-
@message1 = @
|
548
|
+
@receipt1 = @entity1.send_message(@recipients,"Body","Subject")
|
549
|
+
@message1 = @receipt1.notification
|
550
550
|
end
|
551
551
|
|
552
552
|
it "should create proper message" do
|
@@ -558,7 +558,7 @@ describe "Messages And Receipts" do
|
|
558
558
|
|
559
559
|
it "should create proper mails" do
|
560
560
|
#Sender Mail
|
561
|
-
mail = Receipt.receiver(@entity1).
|
561
|
+
mail = Receipt.receiver(@entity1).notification(@message1).first
|
562
562
|
assert mail
|
563
563
|
if mail
|
564
564
|
mail.read.should==true
|
@@ -567,7 +567,7 @@ describe "Messages And Receipts" do
|
|
567
567
|
end
|
568
568
|
#Receiver Mails
|
569
569
|
@recipients.each do |receiver|
|
570
|
-
mail = Receipt.receiver(receiver).
|
570
|
+
mail = Receipt.receiver(receiver).notification(@message1).first
|
571
571
|
assert mail
|
572
572
|
if mail
|
573
573
|
mail.read.should==false
|
@@ -589,10 +589,10 @@ describe "Messages And Receipts" do
|
|
589
589
|
|
590
590
|
describe "message replying to sender" do
|
591
591
|
before do
|
592
|
-
@
|
593
|
-
@
|
594
|
-
@message1 = @
|
595
|
-
@message2 = @
|
592
|
+
@receipt1 = @entity1.send_message(@recipients,"Body","Subject")
|
593
|
+
@receipt2 = @entity2.reply_to_sender(@receipt1,"Reply body")
|
594
|
+
@message1 = @receipt1.notification
|
595
|
+
@message2 = @receipt2.notification
|
596
596
|
end
|
597
597
|
|
598
598
|
it "should create proper message" do
|
@@ -604,7 +604,7 @@ describe "Messages And Receipts" do
|
|
604
604
|
|
605
605
|
it "should create proper mails" do
|
606
606
|
#Sender Mail
|
607
|
-
mail = Receipt.receiver(@entity2).
|
607
|
+
mail = Receipt.receiver(@entity2).notification(@message2).first
|
608
608
|
assert mail
|
609
609
|
if mail
|
610
610
|
mail.read.should==true
|
@@ -612,7 +612,7 @@ describe "Messages And Receipts" do
|
|
612
612
|
mail.mailbox_type.should=="sentbox"
|
613
613
|
end
|
614
614
|
#Receiver Mail
|
615
|
-
mail = Receipt.receiver(@entity1).
|
615
|
+
mail = Receipt.receiver(@entity1).notification(@message2).first
|
616
616
|
assert mail
|
617
617
|
if mail
|
618
618
|
mail.read.should==false
|
@@ -621,7 +621,7 @@ describe "Messages And Receipts" do
|
|
621
621
|
end
|
622
622
|
|
623
623
|
#No Receiver, No Mail
|
624
|
-
mail = Receipt.receiver(@entity3).
|
624
|
+
mail = Receipt.receiver(@entity3).notification(@message2).first
|
625
625
|
assert mail.nil?
|
626
626
|
|
627
627
|
end
|
@@ -641,10 +641,10 @@ describe "Messages And Receipts" do
|
|
641
641
|
|
642
642
|
describe "message replying to all" do
|
643
643
|
before do
|
644
|
-
@
|
645
|
-
@
|
646
|
-
@message1 = @
|
647
|
-
@message2 = @
|
644
|
+
@receipt1 = @entity1.send_message(@recipients,"Body","Subject")
|
645
|
+
@receipt2 = @entity2.reply_to_all(@receipt1,"Reply body")
|
646
|
+
@message1 = @receipt1.notification
|
647
|
+
@message2 = @receipt2.notification
|
648
648
|
@recipients2 = Array.new
|
649
649
|
@recipients2 << @entity1
|
650
650
|
@recipients2 << @entity3
|
@@ -660,7 +660,7 @@ describe "Messages And Receipts" do
|
|
660
660
|
|
661
661
|
it "should create proper mails" do
|
662
662
|
#Sender Mail
|
663
|
-
mail = Receipt.receiver(@entity2).
|
663
|
+
mail = Receipt.receiver(@entity2).notification(@message2).first
|
664
664
|
assert mail
|
665
665
|
if mail
|
666
666
|
mail.read.should==true
|
@@ -669,7 +669,7 @@ describe "Messages And Receipts" do
|
|
669
669
|
end
|
670
670
|
#Receiver Mails
|
671
671
|
@recipients2.each do |receiver|
|
672
|
-
mail = Receipt.receiver(receiver).
|
672
|
+
mail = Receipt.receiver(receiver).notification(@message2).first
|
673
673
|
assert mail
|
674
674
|
if mail
|
675
675
|
mail.read.should==false
|
@@ -5,12 +5,12 @@ describe Conversation do
|
|
5
5
|
before do
|
6
6
|
@entity1 = Factory(:user)
|
7
7
|
@entity2 = Factory(:user)
|
8
|
-
@
|
9
|
-
@
|
10
|
-
@
|
11
|
-
@
|
12
|
-
@message1 = @
|
13
|
-
@message4 = @
|
8
|
+
@receipt1 = @entity1.send_message(@entity2,"Body","Subject")
|
9
|
+
@receipt2 = @entity2.reply_to_all(@receipt1,"Reply body 1")
|
10
|
+
@receipt3 = @entity1.reply_to_all(@receipt2,"Reply body 2")
|
11
|
+
@receipt4 = @entity2.reply_to_all(@receipt3,"Reply body 3")
|
12
|
+
@message1 = @receipt1.notification
|
13
|
+
@message4 = @receipt4.notification
|
14
14
|
@conversation = @message1.conversation
|
15
15
|
end
|
16
16
|
|
data/spec/models/mailbox_spec.rb
CHANGED
@@ -9,8 +9,8 @@ describe Mailbox do
|
|
9
9
|
@receipt2 = @entity2.reply_to_all(@receipt1,"Reply body 1")
|
10
10
|
@receipt3 = @entity1.reply_to_all(@receipt2,"Reply body 2")
|
11
11
|
@receipt4 = @entity2.reply_to_all(@receipt3,"Reply body 3")
|
12
|
-
@message1 = @receipt1.
|
13
|
-
@message4 = @receipt4.
|
12
|
+
@message1 = @receipt1.notification
|
13
|
+
@message4 = @receipt4.notification
|
14
14
|
@conversation = @message1.conversation
|
15
15
|
end
|
16
16
|
|
data/spec/models/message_spec.rb
CHANGED
@@ -9,16 +9,16 @@ describe Message do
|
|
9
9
|
@receipt2 = @entity2.reply_to_all(@receipt1,"Reply body 1")
|
10
10
|
@receipt3 = @entity1.reply_to_all(@receipt2,"Reply body 2")
|
11
11
|
@receipt4 = @entity2.reply_to_all(@receipt3,"Reply body 3")
|
12
|
-
@message1 = @receipt1.
|
13
|
-
@message4 = @receipt4.
|
12
|
+
@message1 = @receipt1.notification
|
13
|
+
@message4 = @receipt4.notification
|
14
14
|
@conversation = @message1.conversation
|
15
15
|
end
|
16
16
|
|
17
17
|
it "should have right recipients" do
|
18
|
-
@receipt1.
|
19
|
-
@receipt2.
|
20
|
-
@receipt3.
|
21
|
-
@receipt4.
|
18
|
+
@receipt1.notification.recipients.count.should==2
|
19
|
+
@receipt2.notification.recipients.count.should==2
|
20
|
+
@receipt3.notification.recipients.count.should==2
|
21
|
+
@receipt4.notification.recipients.count.should==2
|
22
22
|
end
|
23
23
|
|
24
24
|
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe Message do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@entity1 = Factory(:user)
|
7
|
+
@entity2 = Factory(:user)
|
8
|
+
@entity3 = Factory(:user)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should notify one user" do
|
12
|
+
@entity1.notify("Subject","Body")
|
13
|
+
|
14
|
+
#Check getting ALL receipts
|
15
|
+
@entity1.mailbox.receipts.size.should==1
|
16
|
+
receipt = @entity1.mailbox.receipts.first
|
17
|
+
notification = receipt.notification
|
18
|
+
notification.subject.should=="Subject"
|
19
|
+
notification.body.should=="Body"
|
20
|
+
|
21
|
+
#Check getting NOTIFICATION receipts only
|
22
|
+
@entity1.mailbox.notifications.size.should==1
|
23
|
+
receipt = @entity1.mailbox.notifications.first
|
24
|
+
notification = receipt.notification
|
25
|
+
notification.subject.should=="Subject"
|
26
|
+
notification.body.should=="Body"
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should notify several users" do
|
30
|
+
Notification.notify_all([@entity1,@entity2,@entity3],"Subject","Body")
|
31
|
+
|
32
|
+
#Check getting ALL receipts
|
33
|
+
@entity1.mailbox.receipts.size.should==1
|
34
|
+
receipt = @entity1.mailbox.receipts.first
|
35
|
+
notification = receipt.notification
|
36
|
+
notification.subject.should=="Subject"
|
37
|
+
notification.body.should=="Body"
|
38
|
+
@entity2.mailbox.receipts.size.should==1
|
39
|
+
receipt = @entity2.mailbox.receipts.first
|
40
|
+
notification = receipt.notification
|
41
|
+
notification.subject.should=="Subject"
|
42
|
+
notification.body.should=="Body"
|
43
|
+
@entity3.mailbox.receipts.size.should==1
|
44
|
+
receipt = @entity3.mailbox.receipts.first
|
45
|
+
notification = receipt.notification
|
46
|
+
notification.subject.should=="Subject"
|
47
|
+
notification.body.should=="Body"
|
48
|
+
|
49
|
+
#Check getting NOTIFICATION receipts only
|
50
|
+
@entity1.mailbox.notifications.size.should==1
|
51
|
+
receipt = @entity1.mailbox.notifications.first
|
52
|
+
notification = receipt.notification
|
53
|
+
notification.subject.should=="Subject"
|
54
|
+
notification.body.should=="Body"
|
55
|
+
@entity2.mailbox.notifications.size.should==1
|
56
|
+
receipt = @entity2.mailbox.notifications.first
|
57
|
+
notification = receipt.notification
|
58
|
+
notification.subject.should=="Subject"
|
59
|
+
notification.body.should=="Body"
|
60
|
+
@entity3.mailbox.notifications.size.should==1
|
61
|
+
receipt = @entity3.mailbox.notifications.first
|
62
|
+
notification = receipt.notification
|
63
|
+
notification.subject.should=="Subject"
|
64
|
+
notification.body.should=="Body"
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
data/spec/models/receipt_spec.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mailboxer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 1
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 15
|
10
|
+
version: 0.0.15
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Eduardo Casanova Cuesta
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-04-12 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -144,7 +144,7 @@ dependencies:
|
|
144
144
|
version: 0.3.9
|
145
145
|
type: :development
|
146
146
|
version_requirements: *id008
|
147
|
-
description: A Rails engine that allows any model to act as messageable, permitting it interchange messages with any other messageable model.
|
147
|
+
description: A Rails engine that allows any model to act as messageable, permitting it interchange messages with any other messageable model.It also supports sending system notifications to messageable models.
|
148
148
|
email: ecasanovac@gmail.com
|
149
149
|
executables: []
|
150
150
|
|
@@ -163,6 +163,7 @@ files:
|
|
163
163
|
- app/models/conversation.rb
|
164
164
|
- app/models/mailbox.rb
|
165
165
|
- app/models/message.rb
|
166
|
+
- app/models/notification.rb
|
166
167
|
- app/models/receipt.rb
|
167
168
|
- lib/generators/mailboxer/install_generator.rb
|
168
169
|
- lib/generators/mailboxer/templates/migration.rb
|
@@ -198,7 +199,7 @@ files:
|
|
198
199
|
- spec/dummy/db/migrate/20110228120600_create_users.rb
|
199
200
|
- spec/dummy/db/migrate/20110306002940_create_ducks.rb
|
200
201
|
- spec/dummy/db/migrate/20110306015107_create_cylons.rb
|
201
|
-
- spec/dummy/db/migrate/
|
202
|
+
- spec/dummy/db/migrate/20110407111612_create_mailboxer.rb
|
202
203
|
- spec/dummy/db/schema.rb
|
203
204
|
- spec/dummy/public/404.html
|
204
205
|
- spec/dummy/public/422.html
|
@@ -223,6 +224,7 @@ files:
|
|
223
224
|
- spec/models/mailbox_spec.rb
|
224
225
|
- spec/models/mailboxer_models_messageable_spec.rb
|
225
226
|
- spec/models/message_spec.rb
|
227
|
+
- spec/models/notification_spec.rb
|
226
228
|
- spec/models/receipt_spec.rb
|
227
229
|
- spec/spec_helper.rb
|
228
230
|
has_rdoc: true
|