mailboxer 0.0.16 → 0.1.0
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/README.rdoc +32 -2
- data/VERSION +1 -1
- data/app/mailers/message_mailer.rb +35 -0
- data/app/mailers/notification_mailer.rb +20 -0
- data/app/models/message.rb +8 -5
- data/app/models/notification.rb +6 -1
- data/app/views/message_mailer/new_message_email.html.erb +20 -0
- data/app/views/message_mailer/new_message_email.text.erb +10 -0
- data/app/views/message_mailer/reply_message_email.html.erb +20 -0
- data/app/views/message_mailer/reply_message_email.text.erb +10 -0
- data/app/views/notification_mailer/new_notification_email.html.erb +20 -0
- data/app/views/notification_mailer/new_notification_email.text.erb +10 -0
- data/lib/generators/mailboxer/install_generator.rb +4 -0
- data/lib/generators/mailboxer/templates/initializer.rb +4 -0
- data/lib/mailboxer.rb +12 -0
- data/lib/mailboxer/exceptions.rb +12 -0
- data/lib/mailboxer/models/messageable.rb +28 -0
- data/mailboxer.gemspec +1 -1
- data/spec/dummy/app/models/cylon.rb +5 -1
- data/spec/dummy/app/models/duck.rb +10 -1
- data/spec/dummy/app/models/user.rb +2 -2
- data/spec/dummy/config/initializers/mailboxer.rb +3 -0
- data/spec/dummy/db/migrate/20110228120600_create_users.rb +1 -0
- data/spec/dummy/db/migrate/20110306002940_create_ducks.rb +1 -0
- data/spec/dummy/db/migrate/20110306015107_create_cylons.rb +1 -0
- data/spec/dummy/db/migrate/{20110407111612_create_mailboxer.rb → 20110427123542_create_mailboxer.rb} +1 -0
- data/spec/dummy/db/schema.rb +38 -1
- data/spec/factories/cylon.rb +1 -0
- data/spec/factories/duck.rb +1 -0
- data/spec/factories/user.rb +1 -0
- data/spec/mailers/message_mailer_spec.rb +110 -0
- data/spec/mailers/notification_mailer_spec.rb +61 -0
- metadata +18 -5
data/README.rdoc
CHANGED
|
@@ -12,15 +12,45 @@ There is a lack of documentaion and it will be solved as soon as the gem is more
|
|
|
12
12
|
Add to your Gemfile:
|
|
13
13
|
|
|
14
14
|
gem 'mailboxer'
|
|
15
|
+
|
|
16
|
+
Then run:
|
|
15
17
|
|
|
16
|
-
|
|
18
|
+
bundle update
|
|
19
|
+
|
|
20
|
+
Run install script:
|
|
17
21
|
|
|
18
22
|
rails g mailboxer:install
|
|
23
|
+
|
|
24
|
+
And don't forget to migrate you database:
|
|
25
|
+
|
|
26
|
+
rake db:migrate
|
|
27
|
+
|
|
28
|
+
= Requirements
|
|
29
|
+
|
|
30
|
+
We are now adding support for sending emails when a Notification or a Message is sent to one o more recipients. So that, we mus assure that Messageable models have some specific methods. This methods are:
|
|
31
|
+
|
|
32
|
+
#Returning any kind of indentification you want for the model
|
|
33
|
+
def name
|
|
34
|
+
return "You should add method :name in your Messageable model"
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
#Returning the email address of the model
|
|
38
|
+
def email
|
|
39
|
+
return "define_email@on_your.model"
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
#Returning whether an email should be sent for this object (Message or Notification)
|
|
43
|
+
def should_email?(object)
|
|
44
|
+
return true
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
If these methods are not present, default ones will be created (the ones above).
|
|
48
|
+
|
|
19
49
|
|
|
20
50
|
= Usage
|
|
21
51
|
|
|
22
52
|
In your model:
|
|
23
53
|
|
|
24
|
-
class User < ActiveRecord::Base
|
|
54
|
+
class User < ActiveRecord::Base
|
|
25
55
|
acts_as_messageable
|
|
26
56
|
end
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.
|
|
1
|
+
0.1.0
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
class MessageMailer < ActionMailer::Base
|
|
2
|
+
default :from => Mailboxer.default_from
|
|
3
|
+
#Sends and email for indicating a new message or a reply to a receiver.
|
|
4
|
+
#It calls new_message_email if notifing a new message and reply_message_email
|
|
5
|
+
#when indicating a reply to an already created conversation.
|
|
6
|
+
def send_email(message,receiver)
|
|
7
|
+
if message.conversation.messages.size > 0
|
|
8
|
+
reply_message_email(message,receiver)
|
|
9
|
+
else
|
|
10
|
+
new_message_email(message,receiver)
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
include ActionView::Helpers::SanitizeHelper
|
|
15
|
+
|
|
16
|
+
#Sends an email for indicating a new message for the receiver
|
|
17
|
+
def new_message_email(message,receiver)
|
|
18
|
+
@message = message
|
|
19
|
+
@receiver = receiver
|
|
20
|
+
mail(:to => receiver.email, :subject => "You have a new message: " + strip_tags(message.subject)) do |format|
|
|
21
|
+
format.html {render __method__}
|
|
22
|
+
format.text {render __method__}
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
#Sends and email for indicating a reply in an already created conversation
|
|
27
|
+
def reply_message_email(message,receiver)
|
|
28
|
+
@message = message
|
|
29
|
+
@receiver = receiver
|
|
30
|
+
mail(:to => receiver.email, :subject => "You have a new reply: " + strip_tags(message.subject)) do |format|
|
|
31
|
+
format.html {render __method__}
|
|
32
|
+
format.text {render __method__}
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
class NotificationMailer < ActionMailer::Base
|
|
2
|
+
default :from => Mailboxer.default_from
|
|
3
|
+
#Sends and email for indicating a new notification to a receiver.
|
|
4
|
+
#It calls new_notification_email.
|
|
5
|
+
def send_email(notification,receiver)
|
|
6
|
+
new_notification_email(notification,receiver)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
include ActionView::Helpers::SanitizeHelper
|
|
10
|
+
|
|
11
|
+
#Sends an email for indicating a new message for the receiver
|
|
12
|
+
def new_notification_email(notification,receiver)
|
|
13
|
+
@notification = notification
|
|
14
|
+
@receiver = receiver
|
|
15
|
+
mail(:to => receiver.email, :subject => "You have a new notification: " + strip_tags(notification.subject)) do |format|
|
|
16
|
+
format.html {render __method__}
|
|
17
|
+
format.text {render __method__}
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
data/app/models/message.rb
CHANGED
|
@@ -8,14 +8,13 @@ class Message < Notification
|
|
|
8
8
|
scope :conversation, lambda { |conversation|
|
|
9
9
|
where(:conversation_id => conversation.id)
|
|
10
10
|
}
|
|
11
|
-
|
|
12
11
|
class << self
|
|
13
12
|
#Sets the on deliver callback method.
|
|
14
13
|
def on_deliver(callback_method)
|
|
15
14
|
self.on_deliver_callback = callback_method
|
|
16
15
|
end
|
|
17
16
|
end
|
|
18
|
-
|
|
17
|
+
|
|
19
18
|
#Delivers a Message. USE NOT RECOMENDED.
|
|
20
19
|
#Use Mailboxer::Models::Message.send_message instead.
|
|
21
20
|
def deliver(reply = false, should_clean = true)
|
|
@@ -29,6 +28,10 @@ class Message < Notification
|
|
|
29
28
|
msg_receipt.receiver = r
|
|
30
29
|
msg_receipt.mailbox_type = "inbox"
|
|
31
30
|
temp_receipts << msg_receipt
|
|
31
|
+
#Should send an email?
|
|
32
|
+
if r.should_email? self
|
|
33
|
+
MessageMailer.send_email(self,r).deliver
|
|
34
|
+
end
|
|
32
35
|
end
|
|
33
36
|
#Sender receipt
|
|
34
37
|
sender_receipt = Receipt.new
|
|
@@ -44,9 +47,9 @@ class Message < Notification
|
|
|
44
47
|
if reply
|
|
45
48
|
self.conversation.update_attribute(:updated_at, Time.now)
|
|
46
49
|
end
|
|
47
|
-
|
|
48
|
-
|
|
50
|
+
self.recipients=nil
|
|
51
|
+
self.on_deliver_callback.call(self) unless self.on_deliver_callback.nil?
|
|
49
52
|
end
|
|
50
53
|
return sender_receipt
|
|
51
|
-
end
|
|
54
|
+
end
|
|
52
55
|
end
|
data/app/models/notification.rb
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
class Notification < ActiveRecord::Base
|
|
2
2
|
|
|
3
3
|
attr_accessor :recipients
|
|
4
|
+
attr_accessor :object
|
|
4
5
|
belongs_to :sender, :polymorphic => :true
|
|
5
6
|
validates_presence_of :subject, :body
|
|
6
7
|
has_many :receipts
|
|
@@ -30,7 +31,11 @@ class Notification < ActiveRecord::Base
|
|
|
30
31
|
msg_receipt.notification = self
|
|
31
32
|
msg_receipt.read = false
|
|
32
33
|
msg_receipt.receiver = r
|
|
33
|
-
temp_receipts << msg_receipt
|
|
34
|
+
temp_receipts << msg_receipt
|
|
35
|
+
#Should send an email?
|
|
36
|
+
if r.should_email? self
|
|
37
|
+
NotificationMailer.send_email(self,r).deliver
|
|
38
|
+
end
|
|
34
39
|
end
|
|
35
40
|
temp_receipts.each(&:valid?)
|
|
36
41
|
if temp_receipts.all? { |t| t.errors.empty? }
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
|
|
5
|
+
</head>
|
|
6
|
+
<body>
|
|
7
|
+
<h1>You have a new message: <%= strip_tags(@message.subject) %></h1>
|
|
8
|
+
<p>
|
|
9
|
+
You have received a new message:
|
|
10
|
+
</p>
|
|
11
|
+
<blockquote>
|
|
12
|
+
<p>
|
|
13
|
+
<%= raw @message.body %>
|
|
14
|
+
</p>
|
|
15
|
+
</blockquote>
|
|
16
|
+
<p>
|
|
17
|
+
Visit <%= link_to root_url,root_url %> and go to your inbox for more info.
|
|
18
|
+
</p>
|
|
19
|
+
</body>
|
|
20
|
+
</html>
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
You have a new message: <%= strip_tags(@message.subject) %>
|
|
2
|
+
===============================================
|
|
3
|
+
|
|
4
|
+
You have received a new message:
|
|
5
|
+
|
|
6
|
+
-----------------------------------------------
|
|
7
|
+
<%= strip_tags @message.body %>
|
|
8
|
+
-----------------------------------------------
|
|
9
|
+
|
|
10
|
+
Visit <%= root_url %> and go to your inbox for more info.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
|
|
5
|
+
</head>
|
|
6
|
+
<body>
|
|
7
|
+
<h1>You have a new reply: <%= strip_tags(@message.subject) %></h1>
|
|
8
|
+
<p>
|
|
9
|
+
You have received a new reply:
|
|
10
|
+
</p>
|
|
11
|
+
<blockquote>
|
|
12
|
+
<p>
|
|
13
|
+
<%= raw @message.body %>
|
|
14
|
+
</p>
|
|
15
|
+
</blockquote>
|
|
16
|
+
<p>
|
|
17
|
+
Visit <%= link_to root_url,root_url %> and go to your inbox for more info.
|
|
18
|
+
</p>
|
|
19
|
+
</body>
|
|
20
|
+
</html>
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
You have a new reply: <%= strip_tags(@message.subject) %>
|
|
2
|
+
===============================================
|
|
3
|
+
|
|
4
|
+
You have received a new reply:
|
|
5
|
+
|
|
6
|
+
-----------------------------------------------
|
|
7
|
+
<%= strip_tags @message.body %>
|
|
8
|
+
-----------------------------------------------
|
|
9
|
+
|
|
10
|
+
Visit <%= root_url %> and go to your inbox for more info.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
|
|
5
|
+
</head>
|
|
6
|
+
<body>
|
|
7
|
+
<h1>You have a new notification: <%= strip_tags(@notification.subject) %></h1>
|
|
8
|
+
<p>
|
|
9
|
+
You have received a new notification:
|
|
10
|
+
</p>
|
|
11
|
+
<blockquote>
|
|
12
|
+
<p>
|
|
13
|
+
<%= raw @notification.body %>
|
|
14
|
+
</p>
|
|
15
|
+
</blockquote>
|
|
16
|
+
<p>
|
|
17
|
+
Visit <%= link_to root_url,root_url %> and go to your notifications for more info.
|
|
18
|
+
</p>
|
|
19
|
+
</body>
|
|
20
|
+
</html>
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
You have a new notification: <%= strip_tags(@notification.subject) %>
|
|
2
|
+
===============================================
|
|
3
|
+
|
|
4
|
+
You have received a new notification:
|
|
5
|
+
|
|
6
|
+
-----------------------------------------------
|
|
7
|
+
<%= strip_tags @notification.body %>
|
|
8
|
+
-----------------------------------------------
|
|
9
|
+
|
|
10
|
+
Visit <%= root_url %> and go to your notifications for more info.
|
|
@@ -9,6 +9,10 @@ class Mailboxer::InstallGenerator < Rails::Generators::Base #:nodoc:
|
|
|
9
9
|
ActiveRecord::Generators::Base.next_migration_number(dirname)
|
|
10
10
|
end
|
|
11
11
|
|
|
12
|
+
def create_initializer_file
|
|
13
|
+
template 'initializer.rb', 'config/initializers/mailboxer.rb'
|
|
14
|
+
end
|
|
15
|
+
|
|
12
16
|
def create_migration_file
|
|
13
17
|
migration_template 'migration.rb', 'db/migrate/create_mailboxer.rb'
|
|
14
18
|
end
|
data/lib/mailboxer.rb
CHANGED
|
@@ -2,6 +2,18 @@ module Mailboxer
|
|
|
2
2
|
module Models
|
|
3
3
|
autoload :Messageable, 'mailboxer/models/messageable'
|
|
4
4
|
end
|
|
5
|
+
module Exceptions
|
|
6
|
+
autoload :NotCompliantModel, 'mailboxer/exceptions'
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
mattr_accessor :default_from
|
|
10
|
+
|
|
11
|
+
class << self
|
|
12
|
+
def setup
|
|
13
|
+
yield self
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
5
17
|
end
|
|
6
18
|
# reopen ActiveRecord and include all the above to make
|
|
7
19
|
# them available to all our models if they want it
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
module Mailboxer
|
|
2
|
+
module Exceptions
|
|
3
|
+
#Mailboxer::Exceptions::NotCompliantModel is raised when your model with acts_as_messageable
|
|
4
|
+
#method is not compliant with the requirements for acting as messageable.
|
|
5
|
+
#
|
|
6
|
+
#These requirements are:
|
|
7
|
+
#* <b>"name" method</b>: Returning any kind of indentification you want for the model
|
|
8
|
+
#* <b>"email" method</b>: Returning the email address of the model.
|
|
9
|
+
#* <b>"should_email?(object)" method</b>: Returning whether an email should be sent for this object (Message or Notification)
|
|
10
|
+
class NotCompliantModel < RuntimeError; end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
@@ -12,6 +12,34 @@ module Mailboxer
|
|
|
12
12
|
has_many :messages
|
|
13
13
|
has_many :receipts, :order => 'created_at DESC', :dependent => :delete_all
|
|
14
14
|
|
|
15
|
+
if self.table_exists?
|
|
16
|
+
if !self.new.respond_to? :name
|
|
17
|
+
self.class_eval do
|
|
18
|
+
#Returning any kind of indentification you want for the model
|
|
19
|
+
def name
|
|
20
|
+
return "You should add method :name in your Messageable model"
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
if !self.new.respond_to? :email
|
|
26
|
+
self.class_eval do
|
|
27
|
+
#Returning the email address of the model
|
|
28
|
+
def email
|
|
29
|
+
return "define_email@on_your.model"
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
if !self.new.respond_to? :should_email?
|
|
35
|
+
self.class_eval do
|
|
36
|
+
#Returning whether an email should be sent for this object (Message or Notification)
|
|
37
|
+
def should_email?(object)
|
|
38
|
+
return true
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
15
43
|
include Mailboxer::Models::Messageable::InstanceMethods
|
|
16
44
|
end
|
|
17
45
|
end
|
data/mailboxer.gemspec
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Gem::Specification.new do |s|
|
|
2
2
|
s.name = "mailboxer"
|
|
3
|
-
s.version = "0.0
|
|
3
|
+
s.version = "0.1.0"
|
|
4
4
|
s.authors = ["Eduardo Casanova Cuesta"]
|
|
5
5
|
s.summary = "Messaging system for rails apps."
|
|
6
6
|
s.description = "A Rails engine that allows any model to act as messageable, permitting it interchange messages with any other messageable model." +
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
class User < ActiveRecord::Base
|
|
2
|
-
acts_as_messageable
|
|
1
|
+
class User < ActiveRecord::Base
|
|
2
|
+
acts_as_messageable
|
|
3
3
|
end
|
data/spec/dummy/db/schema.rb
CHANGED
|
@@ -10,22 +10,59 @@
|
|
|
10
10
|
#
|
|
11
11
|
# It's strongly recommended to check this file into your version control system.
|
|
12
12
|
|
|
13
|
-
ActiveRecord::Schema.define(:version =>
|
|
13
|
+
ActiveRecord::Schema.define(:version => 20110427123542) do
|
|
14
|
+
|
|
15
|
+
create_table "conversations", :force => true do |t|
|
|
16
|
+
t.string "subject", :default => ""
|
|
17
|
+
t.datetime "created_at", :null => false
|
|
18
|
+
t.datetime "updated_at", :null => false
|
|
19
|
+
end
|
|
14
20
|
|
|
15
21
|
create_table "cylons", :force => true do |t|
|
|
16
22
|
t.string "name"
|
|
23
|
+
t.string "email"
|
|
17
24
|
t.datetime "created_at"
|
|
18
25
|
t.datetime "updated_at"
|
|
19
26
|
end
|
|
20
27
|
|
|
21
28
|
create_table "ducks", :force => true do |t|
|
|
22
29
|
t.string "name"
|
|
30
|
+
t.string "email"
|
|
23
31
|
t.datetime "created_at"
|
|
24
32
|
t.datetime "updated_at"
|
|
25
33
|
end
|
|
26
34
|
|
|
35
|
+
create_table "notifications", :force => true do |t|
|
|
36
|
+
t.string "type"
|
|
37
|
+
t.text "body"
|
|
38
|
+
t.string "subject", :default => ""
|
|
39
|
+
t.integer "sender_id"
|
|
40
|
+
t.string "sender_type"
|
|
41
|
+
t.integer "conversation_id"
|
|
42
|
+
t.boolean "draft", :default => false
|
|
43
|
+
t.datetime "updated_at", :null => false
|
|
44
|
+
t.datetime "created_at", :null => false
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
add_index "notifications", ["conversation_id"], :name => "index_notifications_on_conversation_id"
|
|
48
|
+
|
|
49
|
+
create_table "receipts", :force => true do |t|
|
|
50
|
+
t.integer "receiver_id"
|
|
51
|
+
t.string "receiver_type"
|
|
52
|
+
t.integer "notification_id", :null => false
|
|
53
|
+
t.boolean "read", :default => false
|
|
54
|
+
t.boolean "trashed", :default => false
|
|
55
|
+
t.boolean "deleted", :default => false
|
|
56
|
+
t.string "mailbox_type", :limit => 25
|
|
57
|
+
t.datetime "created_at", :null => false
|
|
58
|
+
t.datetime "updated_at", :null => false
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
add_index "receipts", ["notification_id"], :name => "index_receipts_on_notification_id"
|
|
62
|
+
|
|
27
63
|
create_table "users", :force => true do |t|
|
|
28
64
|
t.string "name"
|
|
65
|
+
t.string "email"
|
|
29
66
|
t.datetime "created_at"
|
|
30
67
|
t.datetime "updated_at"
|
|
31
68
|
end
|
data/spec/factories/cylon.rb
CHANGED
data/spec/factories/duck.rb
CHANGED
data/spec/factories/user.rb
CHANGED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
|
2
|
+
|
|
3
|
+
describe MessageMailer do
|
|
4
|
+
describe "when sending new message" do
|
|
5
|
+
before do
|
|
6
|
+
@sender = Factory(:user)
|
|
7
|
+
@entity1 = Factory(:user)
|
|
8
|
+
@entity2 = Factory(:duck)
|
|
9
|
+
@entity3 = Factory(:cylon)
|
|
10
|
+
@receipt1 = @sender.send_message([@entity1,@entity2,@entity3], "Body Body Body Body Body Body Body Body Body Body Body Body","Subject")
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it "should send emails when should_email? is true (1 out of 3)" do
|
|
14
|
+
ActionMailer::Base.deliveries.empty?.should==false
|
|
15
|
+
ActionMailer::Base.deliveries.size.should==1
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it "should send an email to user entity" do
|
|
19
|
+
temp = false
|
|
20
|
+
ActionMailer::Base.deliveries.each do |email|
|
|
21
|
+
if email.to.first.to_s.eql? @entity1.email
|
|
22
|
+
temp = true
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
temp.should==true
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it "shouldn't send an email to duck entity" do
|
|
29
|
+
temp = false
|
|
30
|
+
ActionMailer::Base.deliveries.each do |email|
|
|
31
|
+
if email.to.first.to_s.eql? @entity2.email
|
|
32
|
+
temp = true
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
temp.should==false
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it "shouldn't send an email to cylon entity" do
|
|
39
|
+
temp = false
|
|
40
|
+
ActionMailer::Base.deliveries.each do |email|
|
|
41
|
+
if email.to.first.to_s.eql? @entity3.email
|
|
42
|
+
temp = true
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
temp.should==false
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
describe "when replying" do
|
|
50
|
+
before do
|
|
51
|
+
@sender = Factory(:user)
|
|
52
|
+
@entity1 = Factory(:user)
|
|
53
|
+
@entity2 = Factory(:duck)
|
|
54
|
+
@entity3 = Factory(:cylon)
|
|
55
|
+
@receipt1 = @sender.send_message([@entity1,@entity2,@entity3], "Body","Subject")
|
|
56
|
+
@receipt2 = @sender.reply_to_all(@receipt1, "Body")
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
it "should send emails when should_email? is true (1 out of 3)" do
|
|
60
|
+
ActionMailer::Base.deliveries.empty?.should==false
|
|
61
|
+
ActionMailer::Base.deliveries.size.should==2
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
it "should send an email to user entity" do
|
|
65
|
+
temp = false
|
|
66
|
+
ActionMailer::Base.deliveries.each do |email|
|
|
67
|
+
if email.to.first.to_s.eql? @entity1.email
|
|
68
|
+
temp = true
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
temp.should==true
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
it "shouldn't send an email to duck entity" do
|
|
75
|
+
temp = false
|
|
76
|
+
ActionMailer::Base.deliveries.each do |email|
|
|
77
|
+
if email.to.first.to_s.eql? @entity2.email
|
|
78
|
+
temp = true
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
temp.should==false
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
it "shouldn't send an email to cylon entity" do
|
|
85
|
+
temp = false
|
|
86
|
+
ActionMailer::Base.deliveries.each do |email|
|
|
87
|
+
if email.to.first.to_s.eql? @entity3.email
|
|
88
|
+
temp = true
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
temp.should==false
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def print_emails
|
|
97
|
+
ActionMailer::Base.deliveries.each do |email|
|
|
98
|
+
puts "----------------------------------------------------"
|
|
99
|
+
puts email.to
|
|
100
|
+
puts "---"
|
|
101
|
+
puts email.from
|
|
102
|
+
puts "---"
|
|
103
|
+
puts email.subject
|
|
104
|
+
puts "---"
|
|
105
|
+
puts email.body
|
|
106
|
+
puts "---"
|
|
107
|
+
puts email.encoded
|
|
108
|
+
puts "----------------------------------------------------"
|
|
109
|
+
end
|
|
110
|
+
end
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
|
2
|
+
|
|
3
|
+
describe NotificationMailer do
|
|
4
|
+
before do
|
|
5
|
+
@entity1 = Factory(:user)
|
|
6
|
+
@entity2 = Factory(:duck)
|
|
7
|
+
@entity3 = Factory(:cylon)
|
|
8
|
+
@receipt1 = Notification.notify_all([@entity1,@entity2,@entity3],"Subject", "Body Body Body Body Body Body Body Body Body Body Body Body")
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
it "should send emails when should_email? is true (2 out of 3)" do
|
|
12
|
+
ActionMailer::Base.deliveries.empty?.should==false
|
|
13
|
+
ActionMailer::Base.deliveries.size.should==2
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it "should send an email to user entity" do
|
|
17
|
+
temp = false
|
|
18
|
+
ActionMailer::Base.deliveries.each do |email|
|
|
19
|
+
if email.to.first.to_s.eql? @entity1.email
|
|
20
|
+
temp = true
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
temp.should==true
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it "should send an email to duck entity" do
|
|
27
|
+
temp = false
|
|
28
|
+
ActionMailer::Base.deliveries.each do |email|
|
|
29
|
+
if email.to.first.to_s.eql? @entity2.email
|
|
30
|
+
temp = true
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
temp.should==true
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it "shouldn't send an email to cylon entity" do
|
|
37
|
+
temp = false
|
|
38
|
+
ActionMailer::Base.deliveries.each do |email|
|
|
39
|
+
if email.to.first.to_s.eql? @entity3.email
|
|
40
|
+
temp = true
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
temp.should==false
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def print_emails
|
|
48
|
+
ActionMailer::Base.deliveries.each do |email|
|
|
49
|
+
puts "----------------------------------------------------"
|
|
50
|
+
puts email.to
|
|
51
|
+
puts "---"
|
|
52
|
+
puts email.from
|
|
53
|
+
puts "---"
|
|
54
|
+
puts email.subject
|
|
55
|
+
puts "---"
|
|
56
|
+
puts email.body
|
|
57
|
+
puts "---"
|
|
58
|
+
puts email.encoded
|
|
59
|
+
puts "----------------------------------------------------"
|
|
60
|
+
end
|
|
61
|
+
end
|
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: 27
|
|
5
5
|
prerelease: false
|
|
6
6
|
segments:
|
|
7
7
|
- 0
|
|
8
|
+
- 1
|
|
8
9
|
- 0
|
|
9
|
-
|
|
10
|
-
version: 0.0.16
|
|
10
|
+
version: 0.1.0
|
|
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-04-
|
|
18
|
+
date: 2011-04-27 00:00:00 +02:00
|
|
19
19
|
default_executable:
|
|
20
20
|
dependencies:
|
|
21
21
|
- !ruby/object:Gem::Dependency
|
|
@@ -160,15 +160,25 @@ files:
|
|
|
160
160
|
- README.rdoc
|
|
161
161
|
- Rakefile
|
|
162
162
|
- VERSION
|
|
163
|
+
- app/mailers/message_mailer.rb
|
|
164
|
+
- app/mailers/notification_mailer.rb
|
|
163
165
|
- app/models/conversation.rb
|
|
164
166
|
- app/models/mailbox.rb
|
|
165
167
|
- app/models/message.rb
|
|
166
168
|
- app/models/notification.rb
|
|
167
169
|
- app/models/receipt.rb
|
|
170
|
+
- app/views/message_mailer/new_message_email.html.erb
|
|
171
|
+
- app/views/message_mailer/new_message_email.text.erb
|
|
172
|
+
- app/views/message_mailer/reply_message_email.html.erb
|
|
173
|
+
- app/views/message_mailer/reply_message_email.text.erb
|
|
174
|
+
- app/views/notification_mailer/new_notification_email.html.erb
|
|
175
|
+
- app/views/notification_mailer/new_notification_email.text.erb
|
|
168
176
|
- lib/generators/mailboxer/install_generator.rb
|
|
177
|
+
- lib/generators/mailboxer/templates/initializer.rb
|
|
169
178
|
- lib/generators/mailboxer/templates/migration.rb
|
|
170
179
|
- lib/mailboxer.rb
|
|
171
180
|
- lib/mailboxer/engine.rb
|
|
181
|
+
- lib/mailboxer/exceptions.rb
|
|
172
182
|
- lib/mailboxer/models/messageable.rb
|
|
173
183
|
- mailboxer.gemspec
|
|
174
184
|
- spec/dummy/.project
|
|
@@ -191,6 +201,7 @@ files:
|
|
|
191
201
|
- spec/dummy/config/environments/test.rb
|
|
192
202
|
- spec/dummy/config/initializers/backtrace_silencers.rb
|
|
193
203
|
- spec/dummy/config/initializers/inflections.rb
|
|
204
|
+
- spec/dummy/config/initializers/mailboxer.rb
|
|
194
205
|
- spec/dummy/config/initializers/mime_types.rb
|
|
195
206
|
- spec/dummy/config/initializers/secret_token.rb
|
|
196
207
|
- spec/dummy/config/initializers/session_store.rb
|
|
@@ -199,7 +210,7 @@ files:
|
|
|
199
210
|
- spec/dummy/db/migrate/20110228120600_create_users.rb
|
|
200
211
|
- spec/dummy/db/migrate/20110306002940_create_ducks.rb
|
|
201
212
|
- spec/dummy/db/migrate/20110306015107_create_cylons.rb
|
|
202
|
-
- spec/dummy/db/migrate/
|
|
213
|
+
- spec/dummy/db/migrate/20110427123542_create_mailboxer.rb
|
|
203
214
|
- spec/dummy/db/schema.rb
|
|
204
215
|
- spec/dummy/public/404.html
|
|
205
216
|
- spec/dummy/public/422.html
|
|
@@ -220,6 +231,8 @@ files:
|
|
|
220
231
|
- spec/integration/message_and_receipt_spec.rb
|
|
221
232
|
- spec/integration/navigation_spec.rb
|
|
222
233
|
- spec/mailboxer_spec.rb
|
|
234
|
+
- spec/mailers/message_mailer_spec.rb
|
|
235
|
+
- spec/mailers/notification_mailer_spec.rb
|
|
223
236
|
- spec/models/conversation_spec.rb
|
|
224
237
|
- spec/models/mailbox_spec.rb
|
|
225
238
|
- spec/models/mailboxer_models_messageable_spec.rb
|