mailboxer 0.14.0 → 0.15.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.
- checksums.yaml +4 -4
- data/.travis.yml +3 -7
- data/Appraisals +2 -2
- data/CHANGELOG.md +66 -0
- data/README.md +21 -1
- data/app/models/mailboxer/conversation.rb +5 -2
- data/app/models/mailboxer/mailbox.rb +1 -1
- data/app/models/mailboxer/notification.rb +6 -6
- data/app/models/mailboxer/receipt.rb +17 -16
- data/db/migrate/20110511145103_create_mailboxer.rb +3 -2
- data/db/migrate/20131206080416_add_conversation_optout.rb +1 -1
- data/db/migrate/20131206080417_add_missing_indices.rb +1 -1
- data/db/migrate/20151103080417_add_delivery_tracking_info_to_mailboxer_receipts.rb +1 -1
- data/gemfiles/rails5.1.gemfile +7 -0
- data/lib/generators/mailboxer/templates/initializer.rb +2 -1
- data/lib/generators/mailboxer/templates/mailboxer_namespacing_compatibility.rb +1 -0
- data/lib/mailboxer.rb +2 -0
- data/lib/mailboxer/mail_dispatcher.rb +13 -1
- data/lib/mailboxer/models/messageable.rb +17 -14
- data/lib/mailboxer/version.rb +1 -1
- data/mailboxer.gemspec +1 -1
- data/spec/dummy/config/initializers/mailboxer.rb +5 -4
- data/spec/dummy/db/migrate/20110228120600_create_users.rb +1 -1
- data/spec/dummy/db/migrate/20110306002940_create_ducks.rb +1 -1
- data/spec/dummy/db/migrate/20110306015107_create_cylons.rb +1 -1
- data/spec/dummy/db/migrate/20120305103200_create_mailboxer.rb +29 -30
- data/spec/dummy/db/migrate/20131206080416_add_conversation_optout.rb +1 -1
- data/spec/dummy/db/migrate/20151103202534_add_missing_indices.mailboxer_engine.rb +1 -2
- data/spec/dummy/db/migrate/20151103202535_add_delivery_tracking_info_to_mailboxer_receipts.mailboxer_engine.rb +1 -2
- data/spec/mailboxer/mail_dispatcher_spec.rb +14 -3
- data/spec/models/mailboxer_models_messageable_spec.rb +8 -8
- data/spec/models/notification_spec.rb +6 -6
- metadata +7 -6
- data/gemfiles/rails4.2.gemfile +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 46c49273efc5f0fe22a30a35bbc7a0e0cd50a88f
|
4
|
+
data.tar.gz: 4683361def08b32438d693116f1cf53864ef76c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 00c8d3afb30b6449c1748e511bb9c14310f46117a018cc81326ea20ca799ec464f11f57336e396500d1780f700b700681a71e096db41670d4b1f0e24e437c0a4
|
7
|
+
data.tar.gz: dcb7b75dbb2f24e8cfeaecc49268b0f1953179992dc0340647190eb66527ab072c0a9c6709c2bbf4cdc59a9d61108b5046203afc03344dbd0c810ecdbbb5b5ad
|
data/.travis.yml
CHANGED
@@ -3,18 +3,14 @@ cache: bundler
|
|
3
3
|
sudo: false
|
4
4
|
|
5
5
|
rvm:
|
6
|
-
- 2.1.10
|
7
6
|
- 2.2.5
|
8
7
|
- 2.3.1
|
8
|
+
- 2.4.1
|
9
|
+
|
9
10
|
|
10
11
|
gemfile:
|
11
|
-
- gemfiles/rails4.2.gemfile
|
12
12
|
- gemfiles/rails5.0.gemfile
|
13
|
-
|
14
|
-
matrix:
|
15
|
-
exclude:
|
16
|
-
- rvm: 2.1.10
|
17
|
-
gemfile: gemfiles/rails5.0.gemfile
|
13
|
+
- gemfiles/rails5.1.gemfile
|
18
14
|
|
19
15
|
env:
|
20
16
|
global:
|
data/Appraisals
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
appraise "
|
2
|
-
gem "rails", "~>
|
1
|
+
appraise "rails5.1" do
|
2
|
+
gem "rails", "~> 5.1.1"
|
3
3
|
end
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
# CHANGELOG
|
2
|
+
|
3
|
+
## Master (Unreleased)
|
4
|
+
|
5
|
+
## 0.15.0 - 2017-05-17
|
6
|
+
|
7
|
+
### Changed
|
8
|
+
|
9
|
+
* Update for Rails 5.1
|
10
|
+
|
11
|
+
* When sorting entries by `created_at`, also sort by `id` descending. This
|
12
|
+
is to ensure proper sorting of items for databases that do not store
|
13
|
+
nanoseconds for timestamp columns.
|
14
|
+
|
15
|
+
### Fixed
|
16
|
+
|
17
|
+
* When trying to delete a Mailboxer object, a `NameError` may be thrown due
|
18
|
+
to a missing namespace
|
19
|
+
|
20
|
+
## 0.14.0 - 2016-07-29
|
21
|
+
|
22
|
+
### Added
|
23
|
+
|
24
|
+
* Rails 5 compatibility.
|
25
|
+
|
26
|
+
### Fixed
|
27
|
+
|
28
|
+
* `Mailboxer::Message` object no longer requires to have a subject.
|
29
|
+
* Objects are now saved before mails are sent, you you can use them in the
|
30
|
+
mailer templates (to build URLs, for example).
|
31
|
+
|
32
|
+
### Changed
|
33
|
+
|
34
|
+
* Errors are now stored in the parent message/notification instead of being
|
35
|
+
stored in the sender receipt. That means you need handle mailboxer related
|
36
|
+
controller and views differently, and study the upgrade case by case (propably
|
37
|
+
by having a look at mailboxer's source code). As an example, if you were
|
38
|
+
previously doing something like this in your controller:
|
39
|
+
|
40
|
+
```
|
41
|
+
@receipt = @actor.send_message(@recipients, params[:body], params[:subject])
|
42
|
+
if (@receipt.errors.blank?)
|
43
|
+
@conversation = @receipt.conversation
|
44
|
+
redirect_to conversation_path(@conversation)
|
45
|
+
else
|
46
|
+
render :action => :new
|
47
|
+
end
|
48
|
+
```
|
49
|
+
|
50
|
+
you now need to do something like
|
51
|
+
|
52
|
+
```
|
53
|
+
@receipt = @actor.send_message(@recipients, params[:body], params[:subject])
|
54
|
+
@message = @receipt.message
|
55
|
+
if (@message.errors.blank?)
|
56
|
+
@conversation = @message.conversation
|
57
|
+
redirect_to conversation_path(@conversation)
|
58
|
+
else
|
59
|
+
render :action => :new
|
60
|
+
end
|
61
|
+
```
|
62
|
+
|
63
|
+
This might look more complicated at first but allows you to build more RESTful
|
64
|
+
resources since you can build forms on messages and/or conversations and
|
65
|
+
directly show errors on them. Less specially handling is now required to
|
66
|
+
propagate errors around models.
|
data/README.md
CHANGED
@@ -104,6 +104,24 @@ Mailboxer.setup do |config|
|
|
104
104
|
end
|
105
105
|
```
|
106
106
|
|
107
|
+
If you have subclassed the Mailboxer::Notification class, you can specify the mailers using a member method:
|
108
|
+
|
109
|
+
```ruby
|
110
|
+
class NewDocumentNotification < Mailboxer::Notification
|
111
|
+
def mailer_class
|
112
|
+
NewDocumentNotificationMailer
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
class NewCommentNotification < Mailboxer::Notification
|
117
|
+
def mailer_class
|
118
|
+
NewDocumentNotificationMailer
|
119
|
+
end
|
120
|
+
end
|
121
|
+
```
|
122
|
+
|
123
|
+
Otherwise, the mailer class will be determined by appending 'Mailer' to the mailable class name.
|
124
|
+
|
107
125
|
### User identities
|
108
126
|
|
109
127
|
Users must have an identity defined by a `name` and an `email`. We must ensure that Messageable models have some specific methods. These methods are:
|
@@ -135,6 +153,7 @@ Mailboxer.setup do |config|
|
|
135
153
|
#Configures the methods needed by mailboxer
|
136
154
|
config.email_method = :mailboxer_email
|
137
155
|
config.name_method = :name
|
156
|
+
config.notify_method = :notify
|
138
157
|
# ...
|
139
158
|
end
|
140
159
|
```
|
@@ -144,9 +163,10 @@ You may change whatever you want or need. For example:
|
|
144
163
|
```ruby
|
145
164
|
config.email_method = :notification_email
|
146
165
|
config.name_method = :display_name
|
166
|
+
config.notify_method = :notify_mailboxer
|
147
167
|
```
|
148
168
|
|
149
|
-
Will use the method `notification_email(object)` instead of `mailboxer_email(object)` and `
|
169
|
+
Will use the method `notification_email(object)` instead of `mailboxer_email(object)`, `display_name` for `name` and `notify_mailboxer` for `notify`.
|
150
170
|
|
151
171
|
Using default or custom method names, if your model doesn't implement them, Mailboxer will use dummy methods so as to notify you of missing methods rather than crashing.
|
152
172
|
|
@@ -32,6 +32,9 @@ class Mailboxer::Conversation < ActiveRecord::Base
|
|
32
32
|
scope :not_trash, lambda {|participant|
|
33
33
|
participant(participant).merge(Mailboxer::Receipt.not_trash)
|
34
34
|
}
|
35
|
+
scope :not_deleted, lambda {|participant|
|
36
|
+
participant(participant).merge(Mailboxer::Receipt.not_deleted)
|
37
|
+
}
|
35
38
|
scope :between, lambda {|participant_one, participant_two|
|
36
39
|
joins("INNER JOIN (#{Mailboxer::Notification.recipient(participant_two).to_sql}) participant_two_notifications " \
|
37
40
|
"ON participant_two_notifications.conversation_id = #{table_name}.id AND participant_two_notifications.type IN ('Mailboxer::Message')").
|
@@ -93,7 +96,7 @@ class Mailboxer::Conversation < ActiveRecord::Base
|
|
93
96
|
|
94
97
|
#First message of the conversation.
|
95
98
|
def original_message
|
96
|
-
@original_message ||= messages.order(
|
99
|
+
@original_message ||= messages.order(:created_at).first
|
97
100
|
end
|
98
101
|
|
99
102
|
#Sender of the last message.
|
@@ -103,7 +106,7 @@ class Mailboxer::Conversation < ActiveRecord::Base
|
|
103
106
|
|
104
107
|
#Last message in the conversation.
|
105
108
|
def last_message
|
106
|
-
@last_message ||= messages.order(
|
109
|
+
@last_message ||= messages.order(:created_at => :desc, :id => :desc).first
|
107
110
|
end
|
108
111
|
|
109
112
|
#Returns the receipts of the conversation for one participants
|
@@ -9,7 +9,7 @@ class Mailboxer::Mailbox
|
|
9
9
|
#Returns the notifications for the messageable
|
10
10
|
def notifications(options = {})
|
11
11
|
#:type => nil is a hack not to give Messages as Notifications
|
12
|
-
notifs = Mailboxer::Notification.recipient(messageable).where(:type => nil).order(
|
12
|
+
notifs = Mailboxer::Notification.recipient(messageable).where(:type => nil).order(:created_at => :desc, :id => :desc)
|
13
13
|
if options[:read] == false || options[:unread]
|
14
14
|
notifs = notifs.unread
|
15
15
|
end
|
@@ -13,21 +13,21 @@ class Mailboxer::Notification < ActiveRecord::Base
|
|
13
13
|
:length => { :maximum => Mailboxer.body_max_length }
|
14
14
|
|
15
15
|
scope :recipient, lambda { |recipient|
|
16
|
-
joins(:receipts).where(
|
16
|
+
joins(:receipts).where(:mailboxer_receipts => { :receiver_id => recipient.id, :receiver_type => recipient.class.base_class.to_s })
|
17
17
|
}
|
18
18
|
scope :with_object, lambda { |obj|
|
19
|
-
where(
|
19
|
+
where(:notified_object_id => obj.id, :notified_object_type => obj.class.to_s)
|
20
20
|
}
|
21
21
|
scope :not_trashed, lambda {
|
22
|
-
joins(:receipts).where(
|
22
|
+
joins(:receipts).where(:mailboxer_receipts => { :trashed => false })
|
23
23
|
}
|
24
24
|
scope :unread, lambda {
|
25
|
-
joins(:receipts).where(
|
25
|
+
joins(:receipts).where(:mailboxer_receipts => { :is_read => false })
|
26
26
|
}
|
27
27
|
scope :global, lambda { where(:global => true) }
|
28
|
-
scope :expired, lambda { where("
|
28
|
+
scope :expired, lambda { where("#{Mailboxer::Notification.quoted_table_name}.expires < ?", Time.now) }
|
29
29
|
scope :unexpired, lambda {
|
30
|
-
where("
|
30
|
+
where("#{Mailboxer::Notification.quoted_table_name}.expires is NULL OR #{Mailboxer::Notification.quoted_table_name}.expires > ?", Time.now)
|
31
31
|
}
|
32
32
|
|
33
33
|
class << self
|
@@ -13,13 +13,13 @@ class Mailboxer::Receipt < ActiveRecord::Base
|
|
13
13
|
}
|
14
14
|
#Notifications Scope checks type to be nil, not Notification because of STI behaviour
|
15
15
|
#with the primary class (no type is saved)
|
16
|
-
scope :notifications_receipts, lambda { joins(:notification).where(
|
17
|
-
scope :messages_receipts, lambda { joins(:notification).where(
|
16
|
+
scope :notifications_receipts, lambda { joins(:notification).where(:mailboxer_notifications => { :type => nil }) }
|
17
|
+
scope :messages_receipts, lambda { joins(:notification).where(:mailboxer_notifications => { :type => Mailboxer::Message.to_s }) }
|
18
18
|
scope :notification, lambda { |notification|
|
19
19
|
where(:notification_id => notification.id)
|
20
20
|
}
|
21
21
|
scope :conversation, lambda { |conversation|
|
22
|
-
joins(:message).where(
|
22
|
+
joins(:message).where(:mailboxer_notifications => { :conversation_id => conversation.id })
|
23
23
|
}
|
24
24
|
scope :sentbox, lambda { where(:mailbox_type => "sentbox") }
|
25
25
|
scope :inbox, lambda { where(:mailbox_type => "inbox") }
|
@@ -72,12 +72,8 @@ class Mailboxer::Receipt < ActiveRecord::Base
|
|
72
72
|
end
|
73
73
|
|
74
74
|
def update_receipts(updates, options={})
|
75
|
-
ids = where(options).
|
76
|
-
unless ids.empty?
|
77
|
-
sql = ids.map { "#{table_name}.id = ? " }.join(' OR ')
|
78
|
-
conditions = [sql].concat(ids)
|
79
|
-
Mailboxer::Receipt.where(conditions).update_all(updates)
|
80
|
-
end
|
75
|
+
ids = where(options).pluck(:id)
|
76
|
+
Mailboxer::Receipt.where(:id => ids).update_all(updates) unless ids.empty?
|
81
77
|
end
|
82
78
|
end
|
83
79
|
|
@@ -140,14 +136,19 @@ class Mailboxer::Receipt < ActiveRecord::Base
|
|
140
136
|
protected
|
141
137
|
|
142
138
|
if Mailboxer.search_enabled
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
139
|
+
if Mailboxer.search_engine == :pg_search
|
140
|
+
include PgSearch
|
141
|
+
pg_search_scope :search, associated_against: { message: { subject: 'A', body: 'B' } }, using: :tsearch
|
142
|
+
else
|
143
|
+
searchable do
|
144
|
+
text :subject, :boost => 5 do
|
145
|
+
message.subject if message
|
146
|
+
end
|
147
|
+
text :body do
|
148
|
+
message.body if message
|
149
|
+
end
|
150
|
+
integer :receiver_id
|
149
151
|
end
|
150
|
-
integer :receiver_id
|
151
152
|
end
|
152
153
|
end
|
153
154
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
class CreateMailboxer < ActiveRecord::Migration
|
1
|
+
class CreateMailboxer < ActiveRecord::Migration[4.2]
|
2
2
|
def self.up
|
3
3
|
#Tables
|
4
4
|
#Conversations
|
@@ -27,7 +27,8 @@ class CreateMailboxer < ActiveRecord::Migration
|
|
27
27
|
t.column :conversation_id, :integer
|
28
28
|
t.column :draft, :boolean, :default => false
|
29
29
|
t.string :notification_code, :default => nil
|
30
|
-
t.references :notified_object, :polymorphic => true
|
30
|
+
t.references :notified_object, :polymorphic => true, index: { name: 'mailboxer_notifications_notified_object' }
|
31
|
+
end
|
31
32
|
t.column :attachment, :string
|
32
33
|
t.column :updated_at, :datetime, :null => false
|
33
34
|
t.column :created_at, :datetime, :null => false
|
@@ -1,4 +1,4 @@
|
|
1
|
-
class AddDeliveryTrackingInfoToMailboxerReceipts < ActiveRecord::Migration
|
1
|
+
class AddDeliveryTrackingInfoToMailboxerReceipts < ActiveRecord::Migration[4.2]
|
2
2
|
def change
|
3
3
|
add_column :mailboxer_receipts, :is_delivered, :boolean, default: false
|
4
4
|
add_column :mailboxer_receipts, :delivery_method, :string
|
@@ -9,9 +9,10 @@ Mailboxer.setup do |config|
|
|
9
9
|
#Configures the methods needed by mailboxer
|
10
10
|
config.email_method = :mailboxer_email
|
11
11
|
config.name_method = :name
|
12
|
+
config.notify_method = :notify
|
12
13
|
|
13
14
|
#Configures if you use or not a search engine and which one you are using
|
14
|
-
#Supported engines: [:solr,:sphinx]
|
15
|
+
#Supported engines: [:solr,:sphinx,:pg_search]
|
15
16
|
config.search_enabled = false
|
16
17
|
config.search_engine = :solr
|
17
18
|
|
@@ -13,6 +13,7 @@ class MailboxerNamespacingCompatibility < ActiveRecord::Migration
|
|
13
13
|
rename_table :mailboxer_notifications, :notifications
|
14
14
|
rename_table :mailboxer_receipts, :receipts
|
15
15
|
|
16
|
+
Mailboxer::Notification.table_name = "notifications"
|
16
17
|
Mailboxer::Notification.where(type: 'Mailboxer::Message').update_all(type: 'Message')
|
17
18
|
end
|
18
19
|
end
|
data/lib/mailboxer.rb
CHANGED
@@ -15,6 +15,8 @@ module Mailboxer
|
|
15
15
|
@@email_method = :mailboxer_email
|
16
16
|
mattr_accessor :name_method
|
17
17
|
@@name_method = :name
|
18
|
+
mattr_accessor :notify_method
|
19
|
+
@@notify_method = :notify
|
18
20
|
mattr_accessor :subject_max_length
|
19
21
|
@@subject_max_length = 255
|
20
22
|
mattr_accessor :body_max_length
|
@@ -18,9 +18,21 @@ module Mailboxer
|
|
18
18
|
private
|
19
19
|
|
20
20
|
def mailer
|
21
|
+
mailer_config_method || mailer_from_mailable || mailer_constant
|
22
|
+
end
|
23
|
+
|
24
|
+
def mailer_from_mailable
|
25
|
+
mailable.mailer_class if mailable.respond_to? :mailer_class
|
26
|
+
end
|
27
|
+
|
28
|
+
def mailer_config_method
|
21
29
|
klass = mailable.class.name.demodulize
|
22
30
|
method = "#{klass.downcase}_mailer".to_sym
|
23
|
-
Mailboxer.send(method)
|
31
|
+
Mailboxer.send(method) if Mailboxer.respond_to? method
|
32
|
+
end
|
33
|
+
|
34
|
+
def mailer_constant
|
35
|
+
"#{mailable.class.name}Mailer".constantize
|
24
36
|
end
|
25
37
|
|
26
38
|
def send_email(receipt)
|
@@ -14,7 +14,7 @@ module Mailboxer
|
|
14
14
|
|
15
15
|
included do
|
16
16
|
has_many :messages, :class_name => "Mailboxer::Message", :as => :sender
|
17
|
-
has_many :receipts, -> { order
|
17
|
+
has_many :receipts, -> { order(:created_at => :desc, :id => :desc) }, :class_name => "Mailboxer::Receipt", dependent: :destroy, as: :receiver
|
18
18
|
end
|
19
19
|
|
20
20
|
unless defined?(Mailboxer.name_method)
|
@@ -40,6 +40,11 @@ module Mailboxer
|
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
|
+
#Sends a notification to the messageable
|
44
|
+
define_method Mailboxer.notify_method do |subject, body, obj=nil, sanitize_text=true, notification_code=nil, send_mail=true, sender=nil|
|
45
|
+
Mailboxer::Notification.notify_all([self],subject,body,obj,sanitize_text,notification_code,send_mail,sender)
|
46
|
+
end
|
47
|
+
|
43
48
|
#Gets the mailbox of the messageable
|
44
49
|
def mailbox
|
45
50
|
@mailbox ||= Mailboxer::Mailbox.new(self)
|
@@ -50,11 +55,6 @@ module Mailboxer
|
|
50
55
|
mailbox.inbox(unread: true).count
|
51
56
|
end
|
52
57
|
|
53
|
-
#Sends a notification to the messageable
|
54
|
-
def notify(subject,body,obj = nil,sanitize_text=true,notification_code=nil,send_mail=true,sender=nil)
|
55
|
-
Mailboxer::Notification.notify_all([self],subject,body,obj,sanitize_text,notification_code,send_mail,sender)
|
56
|
-
end
|
57
|
-
|
58
58
|
#Sends a messages, starting a new conversation, with the messageable
|
59
59
|
#as originator
|
60
60
|
def send_message(recipients, msg_body, subject, sanitize_text=true, attachment=nil, message_timestamp = Time.now)
|
@@ -169,11 +169,11 @@ module Mailboxer
|
|
169
169
|
#* An array with any of them
|
170
170
|
def mark_as_deleted(obj)
|
171
171
|
case obj
|
172
|
-
when Receipt
|
172
|
+
when Mailboxer::Receipt
|
173
173
|
return obj.mark_as_deleted if obj.receiver == self
|
174
|
-
when Message, Notification
|
174
|
+
when Mailboxer::Message, Mailboxer::Notification
|
175
175
|
obj.mark_as_deleted(self)
|
176
|
-
when Conversation
|
176
|
+
when Mailboxer::Conversation
|
177
177
|
obj.mark_as_deleted(self)
|
178
178
|
when Array
|
179
179
|
obj.map{ |sub_obj| mark_as_deleted(sub_obj) }
|
@@ -225,12 +225,15 @@ module Mailboxer
|
|
225
225
|
end
|
226
226
|
|
227
227
|
def search_messages(query)
|
228
|
-
|
229
|
-
|
230
|
-
|
228
|
+
if Mailboxer.search_engine == :pg_search
|
229
|
+
Mailboxer::Receipt.search(query).where(receiver_id: self.id).map(&:conversation).uniq
|
230
|
+
else
|
231
|
+
@search = Mailboxer::Receipt.search do
|
232
|
+
fulltext query
|
233
|
+
with :receiver_id, self.id
|
234
|
+
end
|
235
|
+
@search.results.map { |r| r.conversation }.uniq
|
231
236
|
end
|
232
|
-
|
233
|
-
@search.results.map { |r| r.conversation }.uniq
|
234
237
|
end
|
235
238
|
end
|
236
239
|
end
|
data/lib/mailboxer/version.rb
CHANGED
data/mailboxer.gemspec
CHANGED
@@ -22,7 +22,7 @@ Gem::Specification.new do |s|
|
|
22
22
|
#
|
23
23
|
|
24
24
|
# Development Gem dependencies
|
25
|
-
s.add_runtime_dependency('rails', '>=
|
25
|
+
s.add_runtime_dependency('rails', '>= 5.0.0')
|
26
26
|
s.add_runtime_dependency('carrierwave', '>= 0.5.8')
|
27
27
|
|
28
28
|
if RUBY_ENGINE == "rbx" && RUBY_VERSION >= "2.1.0"
|
@@ -1,17 +1,18 @@
|
|
1
1
|
Mailboxer.setup do |config|
|
2
|
-
|
2
|
+
|
3
3
|
#Configures if you applications uses or no the email sending for Notifications and Messages
|
4
4
|
config.uses_emails = true
|
5
|
-
|
5
|
+
|
6
6
|
#Configures the default from for the email sent for Messages and Notifications of Mailboxer
|
7
7
|
config.default_from = "no-reply@mailboxer.com"
|
8
|
-
|
8
|
+
|
9
9
|
#Configures the methods needed by mailboxer
|
10
10
|
config.email_method = :mailboxer_email
|
11
11
|
config.name_method = :name
|
12
|
+
config.notify_method = :notify
|
12
13
|
|
13
14
|
#Configures if you use or not a search engine and wich one are you using
|
14
|
-
#Supported enignes: [:solr,:sphinx]
|
15
|
+
#Supported enignes: [:solr,:sphinx]
|
15
16
|
config.search_enabled = false
|
16
17
|
config.search_engine = :solr
|
17
18
|
|
@@ -1,13 +1,13 @@
|
|
1
|
-
class CreateMailboxer < ActiveRecord::Migration
|
2
|
-
def self.up
|
1
|
+
class CreateMailboxer < ActiveRecord::Migration[4.2]
|
2
|
+
def self.up
|
3
3
|
#Tables
|
4
|
-
|
4
|
+
#Conversations
|
5
5
|
create_table :mailboxer_conversations do |t|
|
6
6
|
t.column :subject, :string, :default => ""
|
7
7
|
t.column :created_at, :datetime, :null => false
|
8
8
|
t.column :updated_at, :datetime, :null => false
|
9
|
-
end
|
10
|
-
|
9
|
+
end
|
10
|
+
#Receipts
|
11
11
|
create_table :mailboxer_receipts do |t|
|
12
12
|
t.references :receiver, :polymorphic => true
|
13
13
|
t.column :notification_id, :integer, :null => false
|
@@ -17,46 +17,45 @@ class CreateMailboxer < ActiveRecord::Migration
|
|
17
17
|
t.column :mailbox_type, :string, :limit => 25
|
18
18
|
t.column :created_at, :datetime, :null => false
|
19
19
|
t.column :updated_at, :datetime, :null => false
|
20
|
-
end
|
21
|
-
|
20
|
+
end
|
21
|
+
#Notifications and Messages
|
22
22
|
create_table :mailboxer_notifications do |t|
|
23
23
|
t.column :type, :string
|
24
24
|
t.column :body, :text
|
25
25
|
t.column :subject, :string, :default => ""
|
26
26
|
t.references :sender, :polymorphic => true
|
27
|
-
t.references :notified_object, :polymorphic => true
|
28
|
-
t.string :notification_code, :default => nil
|
29
27
|
t.column :conversation_id, :integer
|
30
28
|
t.column :draft, :boolean, :default => false
|
29
|
+
t.string :notification_code, :default => nil
|
30
|
+
t.references :notified_object, :polymorphic => true, index: { name: 'mailboxer_notifications_notified_object' }
|
31
31
|
t.column :attachment, :string
|
32
32
|
t.column :updated_at, :datetime, :null => false
|
33
33
|
t.column :created_at, :datetime, :null => false
|
34
|
-
t.boolean :global, :
|
34
|
+
t.boolean :global, default: false
|
35
35
|
t.datetime :expires
|
36
|
-
end
|
37
|
-
|
38
|
-
|
36
|
+
end
|
37
|
+
|
39
38
|
#Indexes
|
40
|
-
|
41
|
-
|
42
|
-
|
39
|
+
#Conversations
|
40
|
+
#Receipts
|
41
|
+
add_index "mailboxer_receipts","notification_id"
|
42
|
+
|
43
|
+
#Messages
|
44
|
+
add_index "mailboxer_notifications","conversation_id"
|
43
45
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
add_foreign_key "mailboxer_receipts", "mailboxer_notifications", :name => "receipts_on_notification_id", :column => "notification_id"
|
51
|
-
#Messages
|
52
|
-
add_foreign_key "mailboxer_notifications", "mailboxer_conversations", :name => "notifications_on_conversation_id", :column => "conversation_id"
|
46
|
+
#Foreign keys
|
47
|
+
#Conversations
|
48
|
+
#Receipts
|
49
|
+
add_foreign_key "mailboxer_receipts", "mailboxer_notifications", :name => "receipts_on_notification_id", :column => "notification_id"
|
50
|
+
#Messages
|
51
|
+
add_foreign_key "mailboxer_notifications", "mailboxer_conversations", :name => "notifications_on_conversation_id", :column => "conversation_id"
|
53
52
|
end
|
54
|
-
|
53
|
+
|
55
54
|
def self.down
|
56
|
-
#Tables
|
57
|
-
|
58
|
-
|
59
|
-
|
55
|
+
#Tables
|
56
|
+
remove_foreign_key "mailboxer_receipts", :name => "receipts_on_notification_id"
|
57
|
+
remove_foreign_key "mailboxer_notifications", :name => "notifications_on_conversation_id"
|
58
|
+
|
60
59
|
#Indexes
|
61
60
|
drop_table :mailboxer_receipts
|
62
61
|
drop_table :mailboxer_conversations
|
@@ -1,5 +1,4 @@
|
|
1
|
-
|
2
|
-
class AddMissingIndices < ActiveRecord::Migration
|
1
|
+
class AddMissingIndices < ActiveRecord::Migration[4.2]
|
3
2
|
def change
|
4
3
|
# We'll explicitly specify its name, as the auto-generated name is too long and exceeds 63
|
5
4
|
# characters limitation.
|
@@ -1,5 +1,4 @@
|
|
1
|
-
|
2
|
-
class AddDeliveryTrackingInfoToMailboxerReceipts < ActiveRecord::Migration
|
1
|
+
class AddDeliveryTrackingInfoToMailboxerReceipts < ActiveRecord::Migration[4.2]
|
3
2
|
def change
|
4
3
|
add_column :mailboxer_receipts, :is_delivered, :boolean, default: false
|
5
4
|
add_column :mailboxer_receipts, :delivery_method, :string
|
@@ -63,7 +63,7 @@ describe Mailboxer::MailDispatcher do
|
|
63
63
|
describe "mailer" do
|
64
64
|
let(:receipts) { [] }
|
65
65
|
|
66
|
-
context "mailable is a
|
66
|
+
context "mailable is a Notification" do
|
67
67
|
let(:mailable) { Mailboxer::Notification.new }
|
68
68
|
|
69
69
|
its(:mailer) { should be Mailboxer::NotificationMailer }
|
@@ -76,16 +76,27 @@ describe Mailboxer::MailDispatcher do
|
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
79
|
-
context "mailable is a
|
79
|
+
context "mailable is a Message" do
|
80
80
|
let(:mailable) { Mailboxer::Message.new }
|
81
81
|
its(:mailer) { should be Mailboxer::MessageMailer }
|
82
82
|
|
83
|
-
context
|
83
|
+
context 'mailer class is selected using global Mailboxer method' do
|
84
84
|
before { Mailboxer.message_mailer = 'foo' }
|
85
85
|
after { Mailboxer.message_mailer = nil }
|
86
86
|
|
87
87
|
its(:mailer) { should eq 'foo' }
|
88
88
|
end
|
89
|
+
|
90
|
+
context 'mailer class is selected using Mailable#mailer_class' do
|
91
|
+
let(:mailable) { double(mailer_class: :foo) }
|
92
|
+
its(:mailer) { should eq :foo }
|
93
|
+
end
|
94
|
+
|
95
|
+
context 'mailer class is selected by searching for the constant' do
|
96
|
+
before { stub_const 'StringMailer', 1 }
|
97
|
+
let(:mailable) { String.new('I am a string') }
|
98
|
+
its(:mailer) { should eq Object.const_get('StringMailer') }
|
99
|
+
end
|
89
100
|
end
|
90
101
|
end
|
91
102
|
end
|
@@ -170,7 +170,7 @@ describe "Mailboxer::Models::Messageable through User" do
|
|
170
170
|
|
171
171
|
|
172
172
|
it "should be able to unread an owned Notification (mark as unread)" do
|
173
|
-
@receipt = @entity1.
|
173
|
+
@receipt = @entity1.send(Mailboxer.notify_method, "Subject", "Body")
|
174
174
|
@notification = @receipt.notification
|
175
175
|
expect(@receipt.is_read).to eq false
|
176
176
|
@entity1.mark_as_read(@notification)
|
@@ -179,7 +179,7 @@ describe "Mailboxer::Models::Messageable through User" do
|
|
179
179
|
end
|
180
180
|
|
181
181
|
it "should be able to read an owned Notification (mark as read)" do
|
182
|
-
@receipt = @entity1.
|
182
|
+
@receipt = @entity1.send(Mailboxer.notify_method, "Subject", "Body")
|
183
183
|
@notification = @receipt.notification
|
184
184
|
expect(@receipt.is_read).to eq false
|
185
185
|
@entity1.mark_as_read(@notification)
|
@@ -187,7 +187,7 @@ describe "Mailboxer::Models::Messageable through User" do
|
|
187
187
|
end
|
188
188
|
|
189
189
|
it "should not be able to unread a not owned Notification (mark as unread)" do
|
190
|
-
@receipt = @entity1.
|
190
|
+
@receipt = @entity1.send(Mailboxer.notify_method, "Subject", "Body")
|
191
191
|
@notification = @receipt.notification
|
192
192
|
expect(@receipt.is_read).to eq false
|
193
193
|
@entity1.mark_as_read(@notification)
|
@@ -196,7 +196,7 @@ describe "Mailboxer::Models::Messageable through User" do
|
|
196
196
|
end
|
197
197
|
|
198
198
|
it "should not be able to read a not owned Notification (mark as read)" do
|
199
|
-
@receipt = @entity1.
|
199
|
+
@receipt = @entity1.send(Mailboxer.notify_method, "Subject", "Body")
|
200
200
|
@notification = @receipt.notification
|
201
201
|
expect(@receipt.is_read).to eq false
|
202
202
|
@entity2.mark_as_read(@notification)
|
@@ -204,7 +204,7 @@ describe "Mailboxer::Models::Messageable through User" do
|
|
204
204
|
end
|
205
205
|
|
206
206
|
it "should be able to trash an owned Notification" do
|
207
|
-
@receipt = @entity1.
|
207
|
+
@receipt = @entity1.send(Mailboxer.notify_method, "Subject", "Body")
|
208
208
|
@notification = @receipt.notification
|
209
209
|
expect(@receipt.trashed).to eq false
|
210
210
|
@entity1.trash(@notification)
|
@@ -212,7 +212,7 @@ describe "Mailboxer::Models::Messageable through User" do
|
|
212
212
|
end
|
213
213
|
|
214
214
|
it "should be able to untrash an owned Notification" do
|
215
|
-
@receipt = @entity1.
|
215
|
+
@receipt = @entity1.send(Mailboxer.notify_method, "Subject", "Body")
|
216
216
|
@notification = @receipt.notification
|
217
217
|
expect(@receipt.trashed).to eq false
|
218
218
|
@entity1.trash(@notification)
|
@@ -221,7 +221,7 @@ describe "Mailboxer::Models::Messageable through User" do
|
|
221
221
|
end
|
222
222
|
|
223
223
|
it "should not be able to trash a not owned Notification" do
|
224
|
-
@receipt = @entity1.
|
224
|
+
@receipt = @entity1.send(Mailboxer.notify_method, "Subject", "Body")
|
225
225
|
@notification = @receipt.notification
|
226
226
|
expect(@receipt.trashed).to eq false
|
227
227
|
@entity2.trash(@notification)
|
@@ -229,7 +229,7 @@ describe "Mailboxer::Models::Messageable through User" do
|
|
229
229
|
end
|
230
230
|
|
231
231
|
it "should not be able to untrash a not owned Notification" do
|
232
|
-
@receipt = @entity1.
|
232
|
+
@receipt = @entity1.send(Mailboxer.notify_method, "Subject", "Body")
|
233
233
|
@notification = @receipt.notification
|
234
234
|
expect(@receipt.trashed).to eq false
|
235
235
|
@entity1.trash(@notification)
|
@@ -14,7 +14,7 @@ describe Mailboxer::Notification do
|
|
14
14
|
it { should validate_length_of(:body).is_at_most(Mailboxer.body_max_length) }
|
15
15
|
|
16
16
|
it "should notify one user" do
|
17
|
-
@entity1.
|
17
|
+
@entity1.send(Mailboxer.notify_method, "Subject", "Body")
|
18
18
|
|
19
19
|
#Check getting ALL receipts
|
20
20
|
expect(@entity1.mailbox.receipts.size).to eq 1
|
@@ -31,14 +31,14 @@ describe Mailboxer::Notification do
|
|
31
31
|
end
|
32
32
|
|
33
33
|
it "should be unread by default" do
|
34
|
-
@entity1.
|
34
|
+
@entity1.send(Mailboxer.notify_method, "Subject", "Body")
|
35
35
|
expect(@entity1.mailbox.receipts.size).to eq 1
|
36
36
|
notification = @entity1.mailbox.receipts.first.notification
|
37
37
|
expect(notification).to be_is_unread(@entity1)
|
38
38
|
end
|
39
39
|
|
40
40
|
it "should be able to marked as read" do
|
41
|
-
@entity1.
|
41
|
+
@entity1.send(Mailboxer.notify_method, "Subject", "Body")
|
42
42
|
expect(@entity1.mailbox.receipts.size).to eq 1
|
43
43
|
notification = @entity1.mailbox.receipts.first.notification
|
44
44
|
notification.mark_as_read(@entity1)
|
@@ -46,7 +46,7 @@ describe Mailboxer::Notification do
|
|
46
46
|
end
|
47
47
|
|
48
48
|
it "should be able to specify a sender for a notification" do
|
49
|
-
@entity1.
|
49
|
+
@entity1.send(Mailboxer.notify_method, "Subject", "Body", nil, true, nil, true, @entity3)
|
50
50
|
expect(@entity1.mailbox.receipts.size).to eq 1
|
51
51
|
notification = @entity1.mailbox.receipts.first.notification
|
52
52
|
expect(notification.sender).to eq(@entity3)
|
@@ -126,11 +126,11 @@ describe Mailboxer::Notification do
|
|
126
126
|
|
127
127
|
describe "scopes" do
|
128
128
|
let(:scope_user) { FactoryGirl.create(:user) }
|
129
|
-
let!(:notification) { scope_user.
|
129
|
+
let!(:notification) { scope_user.send(Mailboxer.notify_method, "Body", "Subject").notification }
|
130
130
|
|
131
131
|
describe ".unread" do
|
132
132
|
it "finds unread notifications" do
|
133
|
-
unread_notification = scope_user.
|
133
|
+
unread_notification = scope_user.send(Mailboxer.notify_method, "Body", "Subject").notification
|
134
134
|
notification.mark_as_read(scope_user)
|
135
135
|
expect(Mailboxer::Notification.unread.last).to eq unread_notification
|
136
136
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mailboxer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.15.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eduardo Casanova Cuesta
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-05-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 5.0.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 5.0.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: carrierwave
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -180,6 +180,7 @@ files:
|
|
180
180
|
- ".travis.yml"
|
181
181
|
- ".yardopts"
|
182
182
|
- Appraisals
|
183
|
+
- CHANGELOG.md
|
183
184
|
- Gemfile
|
184
185
|
- LICENSE.txt
|
185
186
|
- README.md
|
@@ -210,8 +211,8 @@ files:
|
|
210
211
|
- db/migrate/20131206080416_add_conversation_optout.rb
|
211
212
|
- db/migrate/20131206080417_add_missing_indices.rb
|
212
213
|
- db/migrate/20151103080417_add_delivery_tracking_info_to_mailboxer_receipts.rb
|
213
|
-
- gemfiles/rails4.2.gemfile
|
214
214
|
- gemfiles/rails5.0.gemfile
|
215
|
+
- gemfiles/rails5.1.gemfile
|
215
216
|
- lib/generators/mailboxer/install_generator.rb
|
216
217
|
- lib/generators/mailboxer/namespacing_compatibility_generator.rb
|
217
218
|
- lib/generators/mailboxer/templates/initializer.rb
|
@@ -309,7 +310,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
309
310
|
version: '0'
|
310
311
|
requirements: []
|
311
312
|
rubyforge_project:
|
312
|
-
rubygems_version: 2.
|
313
|
+
rubygems_version: 2.6.12
|
313
314
|
signing_key:
|
314
315
|
specification_version: 4
|
315
316
|
summary: Messaging system for rails apps.
|