mailboxer 0.11.0 → 0.12.0.rc1

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.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/.travis.yml +4 -3
  4. data/Appraisals +6 -14
  5. data/Gemfile +1 -1
  6. data/README.md +2 -2
  7. data/app/mailers/mailboxer/base_mailer.rb +14 -0
  8. data/app/mailers/{message_mailer.rb → mailboxer/message_mailer.rb} +9 -14
  9. data/app/mailers/mailboxer/notification_mailer.rb +17 -0
  10. data/app/models/mailboxer/conversation.rb +196 -0
  11. data/app/models/mailboxer/conversation/opt_out.rb +15 -0
  12. data/app/models/{mailbox.rb → mailboxer/mailbox.rb} +10 -10
  13. data/app/models/mailboxer/message.rb +49 -0
  14. data/app/models/{notification.rb → mailboxer/notification.rb} +44 -40
  15. data/app/models/{receipt.rb → mailboxer/receipt.rb} +12 -11
  16. data/app/views/{message_mailer → mailboxer/message_mailer}/new_message_email.html.erb +3 -3
  17. data/app/views/{message_mailer → mailboxer/message_mailer}/new_message_email.text.erb +2 -2
  18. data/app/views/{message_mailer → mailboxer/message_mailer}/reply_message_email.html.erb +3 -3
  19. data/app/views/{message_mailer → mailboxer/message_mailer}/reply_message_email.text.erb +2 -2
  20. data/app/views/{notification_mailer → mailboxer/notification_mailer}/new_notification_email.html.erb +0 -0
  21. data/app/views/{notification_mailer → mailboxer/notification_mailer}/new_notification_email.text.erb +0 -0
  22. data/db/migrate/20110511145103_create_mailboxer.rb +18 -14
  23. data/db/migrate/20131206080416_add_conversation_optout.rb +14 -0
  24. data/gemfiles/rails3.2.gemfile +2 -3
  25. data/gemfiles/rails4.0.gemfile +3 -4
  26. data/gemfiles/rails4.1.gemfile +7 -0
  27. data/lib/generators/mailboxer/install_generator.rb +1 -4
  28. data/lib/generators/mailboxer/namespacing_compatibility_generator.rb +22 -0
  29. data/lib/generators/mailboxer/templates/initializer.rb +8 -4
  30. data/lib/generators/mailboxer/templates/mailboxer_namespacing_compatibility.rb +24 -0
  31. data/lib/mailboxer.rb +7 -1
  32. data/lib/mailboxer/cleaner.rb +9 -0
  33. data/lib/mailboxer/engine.rb +1 -1
  34. data/lib/mailboxer/mail_dispatcher.rb +48 -0
  35. data/lib/mailboxer/models/messageable.rb +21 -20
  36. data/lib/mailboxer/version.rb +3 -0
  37. data/mailboxer.gemspec +16 -8
  38. data/spec/dummy/Gemfile +1 -1
  39. data/spec/dummy/app/models/duck.rb +2 -2
  40. data/spec/dummy/config/initializers/mailboxer.rb +4 -0
  41. data/spec/dummy/db/migrate/20120305103200_create_mailboxer.rb +18 -14
  42. data/spec/dummy/db/migrate/20131206080416_add_conversation_optout.rb +14 -0
  43. data/spec/dummy/db/schema.rb +30 -21
  44. data/spec/integration/message_and_receipt_spec.rb +212 -212
  45. data/spec/mailboxer/mail_dispatcher_spec.rb +114 -0
  46. data/spec/mailers/message_mailer_spec.rb +4 -4
  47. data/spec/mailers/notification_mailer_spec.rb +2 -2
  48. data/spec/models/conversation_spec.rb +148 -47
  49. data/spec/models/mailbox_spec.rb +50 -50
  50. data/spec/models/mailboxer_models_messageable_spec.rb +52 -52
  51. data/spec/models/message_spec.rb +1 -1
  52. data/spec/models/notification_spec.rb +50 -18
  53. data/spec/models/receipt_spec.rb +1 -1
  54. data/spec/spec_helper.rb +3 -0
  55. metadata +68 -57
  56. data/app/mailers/notification_mailer.rb +0 -21
  57. data/app/models/conversation.rb +0 -166
  58. data/app/models/message.rb +0 -68
  59. data/db/migrate/20110719110700_add_notified_object.rb +0 -17
  60. data/db/migrate/20110912163911_add_notification_code.rb +0 -13
  61. data/db/migrate/20111204163911_add_attachments.rb +0 -9
  62. data/db/migrate/20120813110712_rename_receipts_read.rb +0 -9
  63. data/db/migrate/20130305144212_add_global_notification_support.rb +0 -9
  64. data/gemfiles/rails3.0.gemfile +0 -8
  65. data/gemfiles/rails3.1.gemfile +0 -8
  66. data/lib/mailboxer/concerns/configurable_mailer.rb +0 -13
  67. data/spec/dummy/db/migrate/20120305103201_add_notified_object.rb +0 -17
  68. data/spec/dummy/db/migrate/20120305103202_add_notification_code.rb +0 -13
  69. data/spec/dummy/db/migrate/20120305103203_add_attachments.rb +0 -5
  70. data/spec/dummy/db/migrate/20120813110712_rename_receipts_read.rb +0 -9
  71. data/spec/dummy/db/migrate/20130305144212_add_global_notification_support.rb +0 -11
  72. data/spec/mailboxer/concerns/configurable_mailer_spec.rb +0 -27
@@ -1,68 +0,0 @@
1
- class Message < Notification
2
- attr_accessible :attachment if Mailboxer.protected_attributes?
3
-
4
- belongs_to :conversation, :validate => true, :autosave => true
5
- validates_presence_of :sender
6
-
7
- class_attribute :on_deliver_callback
8
- protected :on_deliver_callback
9
- scope :conversation, lambda { |conversation|
10
- where(:conversation_id => conversation.id)
11
- }
12
-
13
- mount_uploader :attachment, AttachmentUploader
14
-
15
- include Concerns::ConfigurableMailer
16
-
17
- class << self
18
- #Sets the on deliver callback method.
19
- def on_deliver(callback_method)
20
- self.on_deliver_callback = callback_method
21
- end
22
- end
23
-
24
- #Delivers a Message. USE NOT RECOMENDED.
25
- #Use Mailboxer::Models::Message.send_message instead.
26
- def deliver(reply = false, should_clean = true)
27
- self.clean if should_clean
28
-
29
- #Receiver receipts
30
- temp_receipts = recipients.map { |r| build_receipt(r, 'inbox') }
31
-
32
- #Sender receipt
33
- sender_receipt = build_receipt(sender, 'sentbox', true)
34
- temp_receipts << sender_receipt
35
-
36
- temp_receipts.each(&:valid?)
37
- if temp_receipts.all? { |t| t.errors.empty? }
38
- temp_receipts.each(&:save!) #Save receipts
39
- #Should send an email?
40
- if Mailboxer.uses_emails
41
- if Mailboxer.mailer_wants_array
42
- get_mailer.send_email(self, recipients).deliver
43
- else
44
- recipients.each do |recipient|
45
- email_to = recipient.send(Mailboxer.email_method, self)
46
- get_mailer.send_email(self, recipient).deliver if email_to.present?
47
- end
48
- end
49
- end
50
- if reply
51
- self.conversation.touch
52
- end
53
- self.recipients=nil
54
- self.on_deliver_callback.call(self) unless self.on_deliver_callback.nil?
55
- end
56
- sender_receipt
57
- end
58
-
59
- private
60
- def build_receipt(receiver, mailbox_type, is_read = false)
61
- Receipt.new.tap do |receipt|
62
- receipt.notification = self
63
- receipt.is_read = is_read
64
- receipt.receiver = receiver
65
- receipt.mailbox_type = mailbox_type
66
- end
67
- end
68
- end
@@ -1,17 +0,0 @@
1
- class AddNotifiedObject < ActiveRecord::Migration
2
- def self.up
3
- change_table :notifications do |t|
4
- t.references :notified_object, :polymorphic => true
5
- t.remove :object_id
6
- t.remove :object_type
7
- end
8
- end
9
-
10
- def self.down
11
- change_table :notifications do |t|
12
- t.remove :notified_object_id
13
- t.remove :notified_object_type
14
- t.references :object, :polymorphic => true
15
- end
16
- end
17
- end
@@ -1,13 +0,0 @@
1
- class AddNotificationCode < ActiveRecord::Migration
2
- def self.up
3
- change_table :notifications do |t|
4
- t.string :notification_code, :default => nil
5
- end
6
- end
7
-
8
- def self.down
9
- change_table :notifications do |t|
10
- t.remove :notification_code
11
- end
12
- end
13
- end
@@ -1,9 +0,0 @@
1
- class AddAttachments < ActiveRecord::Migration
2
- def self.up
3
- add_column :notifications, :attachment, :string
4
- end
5
-
6
- def self.down
7
- remove_column :notifications, :attachment
8
- end
9
- end
@@ -1,9 +0,0 @@
1
- class RenameReceiptsRead < ActiveRecord::Migration
2
- def up
3
- rename_column :receipts, :read, :is_read
4
- end
5
-
6
- def down
7
- rename_column :receipts, :is_read, :read
8
- end
9
- end
@@ -1,9 +0,0 @@
1
- class AddGlobalNotificationSupport < ActiveRecord::Migration
2
-
3
- def change
4
- change_table :notifications do |t|
5
- t.boolean :global, default: false
6
- t.datetime :expires
7
- end
8
- end
9
- end
@@ -1,8 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "http://rubygems.org"
4
-
5
- gem "rails", "~> 3.0.15"
6
- gem "mailboxer", :path=>"../"
7
-
8
- gemspec :path=>"../"
@@ -1,8 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "http://rubygems.org"
4
-
5
- gem "rails", "~> 3.1.6"
6
- gem "mailboxer", :path=>"../"
7
-
8
- gemspec :path=>"../"
@@ -1,13 +0,0 @@
1
- require 'active_support/inflections'
2
-
3
- module Concerns
4
- module ConfigurableMailer
5
-
6
- def get_mailer
7
- return @mailer if @mailer
8
- method = "#{self.class.to_s.downcase}_mailer".to_sym
9
- @mailer = Mailboxer.send(method) || "#{self.class}Mailer".constantize
10
- end
11
-
12
- end
13
- end
@@ -1,17 +0,0 @@
1
- class AddNotifiedObject < ActiveRecord::Migration
2
- def self.up
3
- change_table :notifications do |t|
4
- t.references :notified_object, :polymorphic => true
5
- t.remove :object_id
6
- t.remove :object_type
7
- end
8
- end
9
-
10
- def self.down
11
- change_table :notifications do |t|
12
- t.remove :notified_object_id
13
- t.remove :notified_object_type
14
- t.references :object, :polymorphic => true
15
- end
16
- end
17
- end
@@ -1,13 +0,0 @@
1
- class AddNotificationCode < ActiveRecord::Migration
2
- def self.up
3
- change_table :notifications do |t|
4
- t.string :notification_code, :default => nil
5
- end
6
- end
7
-
8
- def self.down
9
- change_table :notifications do |t|
10
- t.remove :notification_code
11
- end
12
- end
13
- end
@@ -1,5 +0,0 @@
1
- class AddAttachments < ActiveRecord::Migration
2
- def change
3
- add_column :notifications, :attachment, :string
4
- end
5
- end
@@ -1,9 +0,0 @@
1
- class RenameReceiptsRead < ActiveRecord::Migration
2
- def up
3
- rename_column :receipts, :read, :is_read
4
- end
5
-
6
- def down
7
- rename_column :receipts, :is_read, :read
8
- end
9
- end
@@ -1,11 +0,0 @@
1
- class AddGlobalNotificationSupport < ActiveRecord::Migration
2
-
3
- def change
4
- change_table :notifications do |t|
5
- t.boolean :global
6
- t.datetime :expires
7
- end
8
- Notification.update_all ["global = ?", false]
9
- end
10
-
11
- end
@@ -1,27 +0,0 @@
1
- require 'spec_helper'
2
- describe Concerns::ConfigurableMailer do
3
-
4
- describe "Notification instance#get_mailer" do
5
- before { @obj = Notification.new }
6
- it "returns default_mailer" do
7
- @obj.get_mailer.should eq NotificationMailer
8
- end
9
- it "returns 'foo' from Mailerbox.notification_mailer" do
10
- Mailboxer.notification_mailer = 'foo'
11
- @obj.get_mailer.should eq 'foo'
12
- end
13
- after { Mailboxer.notification_mailer = nil }
14
- end
15
-
16
- describe "Message instance#get_mailer" do
17
- before { @obj = Message.new }
18
- it "returns default_mailer" do
19
- @obj.get_mailer.should eq MessageMailer
20
- end
21
- it "returns 'foo' from Mailerbox.message_mailer" do
22
- Mailboxer.message_mailer = 'foo'
23
- @obj.get_mailer.should eq 'foo'
24
- end
25
- after { Mailboxer.message_mailer = nil }
26
- end
27
- end