smailer 0.8.0 → 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d2e3772412ea4ae474b3e81fdb40a1b283b4c483
4
- data.tar.gz: 8c99e9cb73c3c259d97127c0c8f612eb8e779dab
3
+ metadata.gz: 6bf1b2eaf8471b07434e71803ce46eb6d971ad81
4
+ data.tar.gz: 3c761ccfcf13f68a90d57590c541e3935b6895dd
5
5
  SHA512:
6
- metadata.gz: c65340fc1022af2ddcd1b21d71f4246fea5eef4ac4981f13c7a971889cce38709226acff5d293620fd1b328bffc2b35eedfec188ea80bcf661f8731fb9f012b3
7
- data.tar.gz: 3790bc6d1bf551eb588cec59da2ae1b00969780e3609550b2b7e9570e8824db185884d4a79412d66b43e74e834eb5b37c042ae0da874bb5761b780eef7f04567
6
+ metadata.gz: 6b98a822ebfcce95f8ece649ed0b99a3522dc8e2c924e7fa8faf8f55f706bc8d97cc55d15e54b5b83c13877f07dcb0393ec8b5437644137d07721b40a0d3389f
7
+ data.tar.gz: 58cde2ebfc9c01c7d2d5d36655e50143f815157a9c72c51ef21c98318081f1d061d9c8be48474bab319d1787624f2742e72f54ea3be4e03870259c357d128294
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## Version v0.8.1
2
+
3
+ - Adds support for 'reply-to'
4
+
5
+ **Major Bug Fixes:**
6
+
7
+ - `QueuedMail.new(to: …, from: …, mail_campaign: …)` will work as expected 9ff2d80
8
+ - `QueuedMail#body_text=` now works as expected
9
+
1
10
  ## Version v0.8.0
2
11
 
3
12
  - Adds support for one-off emails to be send via the same queueing mechanism.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- smailer (0.7.8)
4
+ smailer (0.8.1)
5
5
  bounce_email (~> 0.2)
6
6
  mail (~> 2.3)
7
7
 
data/README.md CHANGED
@@ -68,6 +68,7 @@ Here is an example how you could proceed with creating and issuing a newsletter:
68
68
  # create a corresponding mail campaign
69
69
  campaign_params = {
70
70
  :from => 'noreply@example.org',
71
+ :reply_to => 'contact@example.org',
71
72
  :subject => 'My First Campaign!',
72
73
  :body_html => '<h1>Hello</h1><p>World</p>',
73
74
  :body_text => 'Hello, world!',
@@ -105,9 +106,9 @@ You can send one-off emails that each have a different mail template:
105
106
  # Changing the campaign now won't change anything in the one-off queued mails.
106
107
 
107
108
  # Sending two mails to the same person for a single campaign:
108
- campaign.queued_mails.create! :to => 'subscriber@domain.com', :body_html => 'second custom body', :body_text => 'second custom body', require_uniqueness => false
109
+ campaign.queued_mails.create! :to => 'subscriber@domain.com', :body_html => 'second custom body', :body_text => 'second custom body', :require_uniqueness => false
109
110
 
110
- You can change the `from`, `subject`, `body_html`, `body_text` and you can also call `add_attachment`. For more info check [Smailer::Models::QueuedMail](lib/smailer/models/queued_mail.rb).
111
+ You can change the `from`, `reply_to`, `subject`, `body_html`, `body_text` and you can also call `add_attachment`. For more info check [Smailer::Models::QueuedMail](lib/smailer/models/queued_mail.rb).
111
112
 
112
113
  ### Attachments
113
114
 
@@ -62,6 +62,7 @@ class CreateSmailerTables < ActiveRecord::Migration
62
62
  t.text "body_text"
63
63
  t.datetime "created_at"
64
64
  t.datetime "updated_at"
65
+ t.string "reply_to"
65
66
  end
66
67
 
67
68
  add_index "mail_templates", ["mail_campaign_id"], :name => "index_mail_templates_on_mail_campaign_id"
@@ -62,6 +62,7 @@ class CreateSmailerTables < ActiveRecord::Migration
62
62
  t.text "body_text"
63
63
  t.datetime "created_at"
64
64
  t.datetime "updated_at"
65
+ t.string "reply_to"
65
66
  end
66
67
 
67
68
  add_index "mail_templates", ["mail_campaign_id"], :name => "index_mail_templates_on_mail_campaign_id"
@@ -13,15 +13,15 @@ module Smailer
13
13
 
14
14
  has_one :mail_template, :dependent => :destroy, :autosave => true, :inverse_of => :mail_campaign
15
15
 
16
- delegate :from, :subject, :body_html, :body_text, :to => :my_mail_template, :allow_nil => true
17
- delegate :from=, :subject=, :body_html=, :body_text=, :to => :my_mail_template
16
+ delegate :from, :reply_to, :subject, :body_html, :body_text, :to => :my_mail_template, :allow_nil => true
17
+ delegate :from=, :reply_to=, :subject=, :body_html=, :body_text=, :to => :my_mail_template
18
18
 
19
19
  validates_presence_of :mailing_list_id, :from
20
20
  validates_numericality_of :mailing_list_id, :unsubscribe_methods, :only_integer => true, :allow_nil => true
21
21
  validates_length_of :from, :subject, :maximum => 255, :allow_nil => true
22
22
 
23
23
  unless Smailer::Compatibility.rails_4?
24
- attr_accessible :mailing_list_id, :from, :subject, :body_html, :body_text
24
+ attr_accessible :mailing_list_id, :from, :reply_to, :subject, :body_html, :body_text
25
25
  end
26
26
 
27
27
  def add_unsubscribe_method(method_specification)
@@ -16,7 +16,7 @@ module Smailer
16
16
  validates_length_of :to, :last_error, :maximum => 255, :allow_nil => true
17
17
 
18
18
  unless Smailer::Compatibility.rails_4?
19
- attr_accessible :mail_campaign_id, :to, :from, :subject, :body_html, :body_text, :require_uniqueness
19
+ attr_accessible :mail_campaign, :mail_campaign_id, :to, :from, :reply_to, :subject, :body_html, :body_text, :require_uniqueness
20
20
  end
21
21
 
22
22
  before_validation :initialize_message_key
@@ -25,8 +25,8 @@ module Smailer
25
25
  before_save :nullify_false_require_uniqueness
26
26
 
27
27
  delegate :mailing_list, :to => :mail_campaign, :allow_nil => true
28
- delegate :from, :subject, :to => :active_mail_template, :allow_nil => true
29
- delegate :from=, :subject=, :body_html=, :body_text, :to => :my_mail_template
28
+ delegate :from, :reply_to, :subject, :to => :active_mail_template, :allow_nil => true
29
+ delegate :from=, :reply_to=, :subject=, :body_html=, :body_text=, :to => :my_mail_template
30
30
 
31
31
  def body_html
32
32
  interpolate active_mail_template.body_html
@@ -49,6 +49,22 @@ module Smailer
49
49
  my_mail_template.attachments.build(:filename => filename, :path => path)
50
50
  end
51
51
 
52
+ def mail_campaign_id=(campaign_id)
53
+ write_attribute(:mail_campaign_id, campaign_id)
54
+
55
+ fill_from_campaign_template
56
+
57
+ mail_campaign_id
58
+ end
59
+
60
+ def mail_campaign=(campaign)
61
+ write_attribute(:mail_campaign_id, campaign.try(:id))
62
+
63
+ fill_from_campaign_template
64
+
65
+ mail_campaign
66
+ end
67
+
52
68
  protected
53
69
 
54
70
  def active_mail_template
@@ -58,16 +74,21 @@ module Smailer
58
74
  def my_mail_template
59
75
  return mail_template if mail_template.present?
60
76
 
61
- build_mail_template.tap do |template|
62
- if mail_campaign.present?
63
- campaign_template = mail_campaign.mail_template
77
+ build_mail_template.tap { fill_from_campaign_template }
78
+ end
79
+
80
+ def fill_from_campaign_template
81
+ if mail_campaign.present? and mail_template.present?
82
+ campaign_template = mail_campaign.mail_template
64
83
 
65
- template.from = campaign_template.from
66
- template.subject = campaign_template.subject
67
- template.body_html = campaign_template.body_html
68
- template.body_text = campaign_template.body_text
84
+ mail_template.from ||= campaign_template.from
85
+ mail_template.reply_to ||= campaign_template.reply_to
86
+ mail_template.subject ||= campaign_template.subject
87
+ mail_template.body_html ||= campaign_template.body_html
88
+ mail_template.body_text ||= campaign_template.body_text
69
89
 
70
- template.attachments = campaign_template.attachments.map(&:dup)
90
+ if mail_template.attachments.blank?
91
+ mail_template.attachments = campaign_template.attachments.map(&:dup)
71
92
  end
72
93
  end
73
94
  end
@@ -47,9 +47,10 @@ module Smailer
47
47
  items_to_process.each do |queue_item|
48
48
  # try to send the email
49
49
  mail = Mail.new do
50
- from queue_item.from
51
- to queue_item.to
52
- subject queue_item.subject
50
+ from queue_item.from
51
+ reply_to queue_item.reply_to if queue_item.reply_to.present?
52
+ to queue_item.to
53
+ subject queue_item.subject
53
54
  queue_item.attachments.each do |attachment|
54
55
  cached_attachments[attachment.id] ||= attachment.body
55
56
  add_file :filename => attachment.filename,
@@ -1,7 +1,7 @@
1
1
  module Smailer
2
2
  MAJOR = 0
3
3
  MINOR = 8
4
- PATCH = 0
4
+ PATCH = 1
5
5
 
6
6
  VERSION = [MAJOR, MINOR, PATCH].join('.')
7
7
  end
@@ -4,8 +4,9 @@ FactoryGirl.define do
4
4
  end
5
5
 
6
6
  factory :mail_template, class: Smailer::Models::MailTemplate do
7
- from { generate(:email) }
8
- subject 'Hi there'
7
+ from { generate(:email) }
8
+ reply_to { generate(:email) }
9
+ subject 'Hi there'
9
10
  body_html '<h1>Hi there</h1>'
10
11
  body_text 'Hi there'
11
12
  end
@@ -14,6 +14,7 @@ describe 'Issuing a newsletter' do
14
14
  # create a corresponding mail campaign
15
15
  campaign_params = {
16
16
  :from => 'noreply@example.org',
17
+ :reply_to => 'contact@example.org',
17
18
  :subject => 'My First Campaign!',
18
19
  :body_html => '<h1>Hello</h1><p>World</p>',
19
20
  :body_text => 'Hello, world!',
@@ -17,7 +17,7 @@ describe 'Sending one-off emails' do
17
17
  # if you change the campaign now it won't change the one-off queued_mails
18
18
 
19
19
  # sending two mails to the same person
20
- campaign.queued_mails.create! :to => 'subscriber@domain.com', :body_html => '<h1>second custom body</h1>', :body_text => 'second custom body', require_uniqueness => false
20
+ campaign.queued_mails.create! :to => 'subscriber@domain.com', :body_html => '<h1>second custom body</h1>', :body_text => 'second custom body', :require_uniqueness => false
21
21
 
22
22
  expect(Smailer::Models::MailCampaign.count).to eq(1)
23
23
  expect(Smailer::Models::MailTemplate.count).to eq(3) # 1 for the campaign and 2 for the one-off emails
@@ -33,8 +33,8 @@ describe 'Sending one-off emails' do
33
33
 
34
34
  second_mail = campaign.queued_mails.last
35
35
 
36
- expect(second_mail.from).to eq(campaign_params.from)
37
- expect(second_mail.subject).to eq(campaign_params.subject)
36
+ expect(second_mail.from).to eq(campaign.from)
37
+ expect(second_mail.subject).to eq(campaign.subject)
38
38
  expect(second_mail.body_html).to eq('<h1>second custom body</h1>')
39
39
  expect(second_mail.body_text).to eq('second custom body')
40
40
  end
@@ -7,8 +7,9 @@ describe Smailer::Models::MailCampaign do
7
7
 
8
8
  mail_campaign.mailing_list = FactoryGirl.create(:mailing_list)
9
9
 
10
- mail_campaign.from = '"test" <test@example.com>'
11
- mail_campaign.subject = 'This is my test'
10
+ mail_campaign.from = '"test" <test@example.com>'
11
+ mail_campaign.reply_to = '"contacts" <contacts@example.com>'
12
+ mail_campaign.subject = 'This is my test'
12
13
  mail_campaign.body_html = 'Hello html'
13
14
  mail_campaign.body_text = 'Hello text'
14
15
 
@@ -23,6 +24,14 @@ describe Smailer::Models::MailCampaign do
23
24
  expect(Smailer::Models::MailCampaign.count).to eq(1)
24
25
  expect(Smailer::Models::MailTemplate.count).to eq(1)
25
26
  expect(Smailer::Models::MailAttachment.count).to eq(1)
27
+
28
+ mail_campaign.reload
29
+
30
+ expect(mail_campaign.from).to eq ('"test" <test@example.com>')
31
+ expect(mail_campaign.reply_to).to eq ('"contacts" <contacts@example.com>')
32
+ expect(mail_campaign.subject).to eq ('This is my test')
33
+ expect(mail_campaign.body_html).to eq ('Hello html')
34
+ expect(mail_campaign.body_text).to eq ('Hello text')
26
35
  end
27
36
  end
28
37
  end
@@ -1,6 +1,29 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Smailer::Models::QueuedMail do
4
+ describe '.new' do
5
+ it 'will fill the mail_template from the mail_campaign as expected' do
6
+ mail_campaign = FactoryGirl.create(:mail_campaign, :subject => 'Campaign subject', :from => 'from@campaign.com')
7
+
8
+ queued_mail = Smailer::Models::QueuedMail.new(
9
+ :to => 'someone@world.com',
10
+ :reply_to => 'reply@world.com',
11
+ :body_html => 'Custom html body',
12
+ :body_text => 'Custom text body',
13
+ :mail_campaign => mail_campaign
14
+ )
15
+
16
+ queued_mail.valid?
17
+ expect(queued_mail.errors).to be_blank
18
+
19
+ expect(queued_mail.from).to eq('from@campaign.com')
20
+ expect(queued_mail.subject).to eq('Campaign subject')
21
+ expect(queued_mail.reply_to).to eq('reply@world.com')
22
+ expect(queued_mail.body_html).to eq('Custom html body')
23
+ expect(queued_mail.body_text).to eq('Custom text body')
24
+ end
25
+ end
26
+
4
27
  describe '#save' do
5
28
  it 'could be made only with mail_campaign and to (recipient)' do
6
29
  mail_campaign = FactoryGirl.create(:mail_campaign)
@@ -25,40 +48,91 @@ describe Smailer::Models::QueuedMail do
25
48
  expect(queued_mail.to).to eq('test@example.com')
26
49
  end
27
50
 
28
- it 'would create its own template if you change any of the template attributes and will copy the mail_campaign template' do
29
- mail_campaign = FactoryGirl.create(:mail_campaign)
30
- mail_campaign.add_attachment 'foo.pdf', '/tmp/foo.pdf'
31
- mail_campaign.save!
32
-
33
- queued_mail = Smailer::Models::QueuedMail.new
34
-
35
- queued_mail.mail_campaign = mail_campaign
36
- queued_mail.to = 'text@example.com'
37
-
38
- queued_mail.from = 'sender@example.com'
39
-
40
- queued_mail.save!
41
-
42
- mail_campaign.reload
43
- queued_mail.reload
44
-
45
- expect(queued_mail.from).to eq('sender@example.com')
46
- expect(queued_mail.body_html).to eq(mail_campaign.body_html)
47
- expect(queued_mail.body_text).to eq(mail_campaign.body_text)
48
- expect(queued_mail.subject).to eq(mail_campaign.subject)
49
-
50
- expect(queued_mail.attachments).to be_present
51
- expect(mail_campaign.attachments).to be_present
52
- expect(queued_mail.attachments.first.path).to eq(mail_campaign.attachments.first.path)
53
- expect(queued_mail.attachments.first.filename).to eq(mail_campaign.attachments.first.filename)
54
-
55
- expect(queued_mail.mail_template).to_not eq(mail_campaign.mail_template)
56
- expect(queued_mail.attachments.first).to_not eq(mail_campaign.attachments.first)
57
-
58
- expect(Smailer::Models::MailCampaign.count).to eq(1)
59
- expect(Smailer::Models::MailTemplate.count).to eq(2)
60
- expect(Smailer::Models::MailAttachment.count).to eq(2)
61
- expect(Smailer::Models::QueuedMail.count).to eq(1)
51
+ describe 'when changing the mail_template' do
52
+ [
53
+ {:from => 'sender@example.com'},
54
+ {:reply_to => 'reply@example.com'},
55
+ {:subject => 'MY NEW SUBJECT'},
56
+ {:body_html => 'NEW HTML BODY'},
57
+ {:body_text => 'NEW TEXT BODY'},
58
+ ].each do |changes|
59
+ it "would copy the mail_campaign template and modify the copy - changing #{changes}" do
60
+ mail_campaign = FactoryGirl.create(:mail_campaign)
61
+ mail_campaign.add_attachment 'foo.pdf', '/tmp/foo.pdf'
62
+ mail_campaign.save!
63
+
64
+ queued_mail = Smailer::Models::QueuedMail.new
65
+
66
+ queued_mail.mail_campaign = mail_campaign
67
+ queued_mail.to = 'text@example.com'
68
+
69
+ changes.each do |key, value|
70
+ queued_mail.public_send("#{key}=", value)
71
+ end
72
+
73
+ queued_mail.save!
74
+
75
+ mail_campaign.reload
76
+ queued_mail.reload
77
+
78
+ expect(queued_mail.from).to eq(changes[:from] || mail_campaign.from)
79
+ expect(queued_mail.reply_to).to eq(changes[:reply_to] || mail_campaign.reply_to)
80
+ expect(queued_mail.body_html).to eq(changes[:body_html] || mail_campaign.body_html)
81
+ expect(queued_mail.body_text).to eq(changes[:body_text] || mail_campaign.body_text)
82
+ expect(queued_mail.subject).to eq(changes[:subject] || mail_campaign.subject)
83
+
84
+ expect(queued_mail.attachments).to be_present
85
+ expect(mail_campaign.attachments).to be_present
86
+ expect(queued_mail.attachments.first.filename).to eq(mail_campaign.attachments.first.filename)
87
+ expect(queued_mail.attachments.first.path).to eq(mail_campaign.attachments.first.path)
88
+
89
+ expect(queued_mail.mail_template).to_not eq(mail_campaign.mail_template)
90
+ expect(queued_mail.attachments.first).to_not eq(mail_campaign.attachments.first)
91
+
92
+ expect(Smailer::Models::MailCampaign.count).to eq(1)
93
+ expect(Smailer::Models::MailTemplate.count).to eq(2)
94
+ expect(Smailer::Models::MailAttachment.count).to eq(2)
95
+ expect(Smailer::Models::QueuedMail.count).to eq(1)
96
+ end
97
+ end
98
+
99
+ it "would copy the mail_campaign template when adding an attachment" do
100
+ mail_campaign = FactoryGirl.create(:mail_campaign)
101
+ mail_campaign.add_attachment 'foo.pdf', '/tmp/foo.pdf'
102
+ mail_campaign.save!
103
+
104
+ queued_mail = Smailer::Models::QueuedMail.new
105
+
106
+ queued_mail.mail_campaign = mail_campaign
107
+ queued_mail.to = 'text@example.com'
108
+
109
+ queued_mail.add_attachment('bar.pdf', '/tmp/bar.pdf')
110
+
111
+ queued_mail.save!
112
+
113
+ mail_campaign.reload
114
+ queued_mail.reload
115
+
116
+ expect(queued_mail.from).to eq(mail_campaign.from)
117
+ expect(queued_mail.body_html).to eq(mail_campaign.body_html)
118
+ expect(queued_mail.body_text).to eq(mail_campaign.body_text)
119
+ expect(queued_mail.subject).to eq(mail_campaign.subject)
120
+
121
+ expect(queued_mail.attachments).to be_present
122
+ expect(mail_campaign.attachments).to be_present
123
+ expect(queued_mail.attachments.first.filename).to eq(mail_campaign.attachments.first.filename)
124
+ expect(queued_mail.attachments.first.path).to eq(mail_campaign.attachments.first.path)
125
+ expect(queued_mail.attachments.last.filename).to eq('bar.pdf')
126
+ expect(queued_mail.attachments.last.path).to eq('/tmp/bar.pdf')
127
+
128
+ expect(queued_mail.mail_template).to_not eq(mail_campaign.mail_template)
129
+ expect(queued_mail.attachments.first).to_not eq(mail_campaign.attachments.first)
130
+
131
+ expect(Smailer::Models::MailCampaign.count).to eq(1)
132
+ expect(Smailer::Models::MailTemplate.count).to eq(2)
133
+ expect(Smailer::Models::MailAttachment.count).to eq(3)
134
+ expect(Smailer::Models::QueuedMail.count).to eq(1)
135
+ end
62
136
  end
63
137
  end
64
138
 
@@ -0,0 +1,9 @@
1
+ class SmailerV080ToV081 < ActiveRecord::Migration
2
+ def self.up
3
+ add_column :mail_templates, :reply_to, :string
4
+ end
5
+
6
+ def self.down
7
+ remove_column :mail_templates, :reply_to
8
+ end
9
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smailer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dimitar Dimitrov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-26 00:00:00.000000000 Z
11
+ date: 2015-07-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -133,11 +133,12 @@ files:
133
133
  - spec/factories/common.rb
134
134
  - spec/factories/models.rb
135
135
  - spec/features/issuing_a_newsletter_spec.rb
136
- - spec/features/sending_oneoff_emails.rb
136
+ - spec/features/sending_oneoff_emails_spec.rb
137
137
  - spec/models/mail_campaign_spec.rb
138
138
  - spec/models/queued_mail_spec.rb
139
139
  - spec/spec_helper.rb
140
140
  - upgrading/migrations/smailer_v0_7_3_to_v0_8_0.rb
141
+ - upgrading/migrations/smailer_v0_8_0_to_v0_8_1.rb
141
142
  homepage: http://github.com/livebg/smailer
142
143
  licenses: []
143
144
  metadata: {}