mail_engine 0.1.3 → 0.1.4

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 (35) hide show
  1. data/README.mkd +39 -6
  2. data/VERSION +1 -1
  3. data/app/controllers/mail_engine/mail_schedules_controller.rb +16 -0
  4. data/app/helpers/mail_engine/mail_engine_helper.rb +1 -1
  5. data/app/models/mail_engine/mail_schedule.rb +54 -29
  6. data/app/models/mail_engine/mail_template.rb +1 -1
  7. data/app/views/mail_engine/dashboard/index.html.erb +35 -31
  8. data/app/views/mail_engine/mail_schedules/_form.html.erb +5 -0
  9. data/app/views/mail_engine/mail_schedules/index.html.erb +27 -1
  10. data/app/views/mail_engine/reports/index.html.erb +1 -1
  11. data/config/routes.rb +2 -0
  12. data/db/migrate/20110126030525_create_mail_schedules.rb +1 -0
  13. data/lib/mail_engine/action_mailer_patch.rb +8 -3
  14. data/lib/mail_engine/engine.rb +1 -0
  15. data/lib/mail_engine/sendgrid/base.rb +1 -0
  16. data/lib/mail_engine/sendgrid/smtp_api.rb +11 -3
  17. data/lib/mail_engine/tasks/export_mail_engine_database.rake +17 -0
  18. data/lib/mail_engine/tasks/sendmail.rake +1 -1
  19. data/mail_engine.gemspec +11 -3
  20. data/public/images/mail_engine/icons/pause.png +0 -0
  21. data/public/images/mail_engine/icons/play.png +0 -0
  22. data/public/images/mail_engine/icons/start.png +0 -0
  23. data/public/images/mail_engine/icons/stop.png +0 -0
  24. data/test/dummy/app/mailers/user_mailer.rb +1 -1
  25. data/test/dummy/app/views/user_mailer/{notify.text.erb → notify.text.liquid} +0 -0
  26. data/test/dummy/config/environments/development.rb +1 -0
  27. data/test/dummy/db/migrate/20110125094530_create_users.rb +2 -0
  28. data/test/dummy/db/migrate/20110126030525_create_mail_schedules.rb +1 -0
  29. data/test/dummy/db/schema.rb +1 -0
  30. data/test/dummy/public/images/mail_engine/icons/pause.png +0 -0
  31. data/test/dummy/public/images/mail_engine/icons/start.png +0 -0
  32. data/test/dummy/public/images/mail_engine/icons/stop.png +0 -0
  33. data/test/functional/user_mailer_test.rb +16 -6
  34. data/test/unit/mail_engine/mail_schedule_test.rb +34 -3
  35. metadata +13 -5
data/README.mkd CHANGED
@@ -42,21 +42,48 @@ Add management page needed javascript lib and css files, migration files and mai
42
42
  Run migration.
43
43
 
44
44
  rake db:migrate
45
-
45
+
46
46
  ** Step 4: **
47
47
 
48
48
  Add acts_as_mail_receiver definition to "Your User" model.
49
49
 
50
- class User < AR
51
- acts_as_mail_receiver :payload_columns => %w{firstname lastname},
52
- :groups => %w{all english_users chinese_users}
53
- end
54
-
50
+ class User < AR
51
+ acts_as_mail_receiver :payload_columns => %w{firstname lastname},
52
+ :groups => %w{all english_users chinese_users}
53
+ end
54
+
55
55
  1. User model must have 'email' and payload specified columns, or else you can delegate to other model.
56
56
  2. "acts_as_mail_receiver" statement has to place below the scope statements.
57
57
 
58
58
  ** Step 5: **
59
59
 
60
+ Add sendgrid smtp api configure:
61
+
62
+ class UserMailer < ActionMailer::Base
63
+ sendgrid_header do
64
+ category "xxx"
65
+
66
+ filters {
67
+ opentrack "enable" => 1
68
+ clicktrack "enable" => 1
69
+ subscriptiontrack "enable" => 0
70
+ template "enable" => 0
71
+ footer "enable" => 0
72
+ }
73
+ end
74
+ end
75
+
76
+ For the detail information please check sendgrid.com.
77
+
78
+ ** Step 6: **
79
+
80
+ Add below line to production.rb or development.rb for specifing the host.
81
+ it will used when generate resource url when upload zip file.
82
+
83
+ config.action_mailer.default_url_options = { :host => "lvh.me:3000" }
84
+
85
+ ** Step 7: **
86
+
60
87
  Add below line to the crontab list of your sever:
61
88
 
62
89
  ### check mail schedule for every 15 minutes ###
@@ -97,6 +124,12 @@ Notes
97
124
  =====
98
125
  Currently only support above rails3.
99
126
 
127
+ Tips
128
+ ====
129
+ Use below rake task, you can export local mail engine data, then import to production environment.
130
+
131
+ rake mail_engine:export_mail_engine_database
132
+
100
133
  Screenshots
101
134
  ===========
102
135
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.3
1
+ 0.1.4
@@ -49,6 +49,22 @@ class MailEngine::MailSchedulesController < MailEngine::ApplicationController
49
49
  render :text => %Q{alert("Test Mail failed to send to #{params[:recipient]}, due to #{e.to_s}"); $('#recipient').val('');}
50
50
  end
51
51
 
52
+ def start
53
+ if @mail_schedule.update_attribute :available, true
54
+ render :js => %Q{alert('Start schedule successfully.'); showStopScheduleButton(#{@mail_schedule.id});}
55
+ else
56
+ render :js => %Q{alert('Failed to start schedule.')}
57
+ end
58
+ end
59
+
60
+ def stop
61
+ if @mail_schedule.update_attribute :available, false
62
+ render :js => %Q{alert('Stop schedule successfully.'); showStartScheduleButton(#{@mail_schedule.id});}
63
+ else
64
+ render :js => %Q{alert('Failed to stop schedule.')}
65
+ end
66
+ end
67
+
52
68
  private
53
69
  def find_model
54
70
  @mail_schedule = MailSchedule.find(params[:id]) if params[:id]
@@ -2,7 +2,7 @@ module MailEngine
2
2
  module MailEngineHelper
3
3
 
4
4
  def show_no_record collection, &block
5
- if collection.is_a?(Array) ? collection.blank? : collection.all.blank?
5
+ if collection.is_a?(Array) ? collection.blank? : collection.try(:all).blank?
6
6
  return raw("<div class='notice' style='margin-top:10px'>No Record</div>")
7
7
  else
8
8
  block.call
@@ -20,22 +20,67 @@ class MailEngine::MailSchedule < ActiveRecord::Base
20
20
  validates_presence_of :name, :user_group, :mail_template_id, :period, :count, :first_send_at
21
21
  validates_inclusion_of :period, :in => %w( once daily weekly monthly yearly), :message => "period should in 'daily', 'weekly' and 'monthly'"
22
22
  belongs_to :mail_template
23
- scope :available, where("sent_count < count OR count = 0")
23
+ scope :available, where("(sent_count < count OR count = 0) AND available=?", true)
24
24
 
25
25
  PERIOD_TO_UNIT_TABLE = {
26
- "daily" => "day",
27
- "weekly" => "week",
28
- "monthly" => "month",
29
- "yearly" => "year"
26
+ "daily" => ["day", 1],
27
+ "weekly" => ["week", 7],
28
+ "monthly" => ["month", 30],
29
+ "yearly" => ["year", 365]
30
30
  }
31
31
 
32
- def self.future_schedules
32
+ # will return an array like
33
+ #
34
+ # [
35
+ # [MailSchedule#xxx, 2010-01-01 20:15],
36
+ # [MailSchedule#xxx, 2010-01-01 20:15]
37
+ # ]
38
+ #
39
+ def self.future_schedules(schedule_count = 5)
40
+ schedule_count = 5 if schedule_count < 5
33
41
  all_future_schedules = []
34
42
  MailEngine::MailSchedule.available.all.each do |schedule|
35
- next_schedules = [schedule].product(schedule.next_several_schedules)
36
- all_future_schedules << next_schedules.flatten if next_schedules.present?
43
+ next_schedules = [schedule].product(schedule.next_several_schedule_dates(schedule_count))
44
+ all_future_schedules += next_schedules if next_schedules.present?
45
+ end
46
+ # sort by date
47
+ all_future_schedules.sort{|x,y| x[1] <=> y[1]}.slice(1..schedule_count)
48
+ end
49
+
50
+ # FIXME monthly will has some problem due to each month is not exact 30 days.
51
+ # this func will return an array of date.
52
+ def next_several_schedule_dates(schedule_count = 5)
53
+ # check if send count reached the top limit count.
54
+ return [] if (sent_count >= count and count != 0)
55
+ # only send once.
56
+ if period == 'once'
57
+ # check if it is still available.
58
+ if first_send_at > Time.now
59
+ return [first_send_at]
60
+ else
61
+ return []
62
+ end
63
+ end
64
+
65
+ # other periods
66
+ rest_count = (count == 0 ? schedule_count : count - sent_count)
67
+ (1..rest_count).map do |i|
68
+ last_schedule_time + i.send(PERIOD_TO_UNIT_TABLE[period].first)
69
+ end
70
+ end
71
+
72
+ # if a weekly schedule, first send at last monday, and today is tuesday, so the last schedule time should be this monday
73
+ # if a weekly schedule, first send at next monday, and today is tuesday, so the last schedule time should be the first_send_at
74
+ def last_schedule_time
75
+ period_unit = PERIOD_TO_UNIT_TABLE[period].first
76
+ period_days = PERIOD_TO_UNIT_TABLE[period].last
77
+ if first_send_at.past?
78
+ days_past = ((Time.now - first_send_at)/(3600*24)).round
79
+ periods_past = days_past / period_days
80
+ first_send_at + periods_past * 1.send(period_unit)
81
+ else
82
+ first_send_at
37
83
  end
38
- all_future_schedules.sort {|x,y| x[1] <=> y[1]}
39
84
  end
40
85
 
41
86
  # list mail log with the same mail_template_path to current mail_template's path
@@ -62,26 +107,6 @@ class MailEngine::MailSchedule < ActiveRecord::Base
62
107
  end
63
108
  end
64
109
 
65
- def next_several_schedules(schedule_count = 5)
66
- # check if send count reached the total count.
67
- return [] if (sent_count >= count and count != 0)
68
- # only send once.
69
- if period == 'once'
70
- if first_send_at > Time.now
71
- return [first_send_at]
72
- else
73
- return []
74
- end
75
- end
76
-
77
- # other period
78
- rest_count = (count == 0 ? schedule_count : count - sent_count)
79
- start_datetime = Time.parse("#{(last_sent_at||first_send_at).strftime("%D")} #{first_send_at.strftime("%T")}")
80
- (1..rest_count).map do |i|
81
- start_datetime + i.send(PERIOD_TO_UNIT_TABLE[period])
82
- end
83
- end
84
-
85
110
  # If execute sendmail twice very soon(within 14 minutes), it should not be able to send mail again.
86
111
  def ready_to_send?
87
112
  # check if send count reached the total count.
@@ -171,7 +171,7 @@ class MailEngine::MailTemplate < ActiveRecord::Base
171
171
  end
172
172
 
173
173
  # FIXME: remove the hostname
174
- def process_zip_file(hostname = "localhost:3000")
174
+ def process_zip_file(hostname = ActionMailer::Base.default_url_options[:host] || "localhost:3000")
175
175
  return if @extracted_files.blank?
176
176
  self.update_attribute :body, MailEngine::HtmlDocumentAssetsReplacer.process(self, @extracted_files, hostname)
177
177
  # remove the tmp files
@@ -66,46 +66,50 @@
66
66
  </div>
67
67
  <div class="clearer"></div>
68
68
 
69
- <div class="today-report left">
69
+ <div class="today-report left" style="width: 920px;">
70
70
  <h2>Next Scheduled Mail</h2>
71
71
  <div class="clearer"></div>
72
- <table border="0" cellspacing="5" cellpadding="5" class="data-table" style="width: 910px; margin-top: 30px; margin-right: 30px">
73
- <tr>
74
- <th>Schedule Name</th><th width="120">Send Time</th>
75
- </tr>
76
- <% MailEngine::MailSchedule.future_schedules.each do |schedule, scheduled_time| %>
77
- <tr>
78
- <td><%= link_to schedule.name, mail_schedule_path(schedule) %></td><td><%= scheduled_time.to_s(:db) %></td>
79
- </tr>
80
- <% end %>
81
- </table>
72
+ <%= show_no_record(future_schedules = MailEngine::MailSchedule.future_schedules) do %>
73
+ <table border="0" cellspacing="5" cellpadding="5" class="data-table" style="width: 910px; margin-top: 30px; margin-right: 30px">
74
+ <tr>
75
+ <th>Schedule Name</th><th width="120">Send Time</th>
76
+ </tr>
77
+ <% future_schedules.each do |schedule, scheduled_time| %>
78
+ <tr>
79
+ <td><%= link_to schedule.name, mail_schedule_path(schedule) %></td><td><%= scheduled_time.to_s(:db) %></td>
80
+ </tr>
81
+ <% end %>
82
+ </table>
83
+ <% end %>
82
84
  </div>
83
85
  <div class="clearer"></div>
84
86
 
85
- <div class="today-report left">
87
+ <div class="today-report left" style="width: 920px;">
86
88
  <h2>Recently Sent Mails</h2>
87
89
  <div class="clearer"></div>
88
90
 
89
- <table class="data-table" style="width: 910px; margin-top: 30px; margin-right: 30px">
90
- <tr>
91
- <th>Subject</th>
92
- <th>Sender</th>
93
- <th>Recipient</th>
94
- <th>mime_type</th>
95
- <th>Sent at</th>
96
- <th width="20"></th>
97
- </tr>
91
+ <%= show_no_record(mail_log = MailEngine::MailLog.order("id desc").limit(10)) do %>
92
+ <table class="data-table" style="width: 910px; margin-top: 30px; margin-right: 30px">
93
+ <tr>
94
+ <th>Subject</th>
95
+ <th>Sender</th>
96
+ <th>Recipient</th>
97
+ <th>mime_type</th>
98
+ <th>Sent at</th>
99
+ <th width="20"></th>
100
+ </tr>
98
101
 
99
- <% MailEngine::MailLog.order("id desc").limit(10).each do |log| %>
100
- <tr class="even">
101
- <td><%= log.subject %></td>
102
- <td><%= log.sender %></td>
103
- <td><%= log.recipient %></td>
104
- <td><%= log.mime_type %></td>
105
- <td><%= log.created_at %></td>
106
- <td><%= link_to image_tag('mail_engine/icons/show.png'), mail_log_path(log) %></td>
107
- </tr>
102
+ <% mail_log.each do |log| %>
103
+ <tr class="even">
104
+ <td><%= log.subject %></td>
105
+ <td><%= log.sender %></td>
106
+ <td><%= log.recipient %></td>
107
+ <td><%= log.mime_type %></td>
108
+ <td><%= log.created_at %></td>
109
+ <td><%= link_to image_tag('mail_engine/icons/show.png'), mail_log_path(log) %></td>
110
+ </tr>
111
+ <% end %>
112
+ </table>
108
113
  <% end %>
109
- </table>
110
114
  </div>
111
115
  <div class="clearer"></div>
@@ -34,6 +34,11 @@
34
34
  <%= f.label :first_send_at, "First Send At" %><br />
35
35
  <%= f.datetime_select :first_send_at, :start_year => Time.now.year, :include_seconds => false, :minute_step => 15 %>
36
36
  </div>
37
+ <div class="field">
38
+ <%= f.label :available, "Available?" %><br />
39
+ <%= f.check_box :available %>
40
+ <div class="hint">If you don't want to execute this schedule, leave it unchecked.</div>
41
+ </div>
37
42
  <div class="field">
38
43
  <%= f.label :payload %><br />
39
44
  <% MailEngine::USER_MODEL.payload_columns.each do |column| %>
@@ -23,12 +23,24 @@
23
23
  <tr><th>Payload</th>
24
24
  <td><%= raw mail_schedule.payload.gsub(",", "<br/>") %></td>
25
25
  </tr>
26
+ <tr><th>Availability</th><td class="availability_state_of_<%= mail_schedule.id %> loud large"><%= mail_schedule.available? ? "Running" : "Stopped" %></td></tr>
26
27
  </table>
27
28
  </td>
28
29
  <td style="vertical-align:top">
29
30
  <%= link_to image_tag('mail_engine/icons/show.png'), mail_schedule_path(mail_schedule) %>
30
31
  <%= link_to image_tag('mail_engine/icons/edit.gif'), edit_mail_schedule_path(mail_schedule) %>
31
32
  <%= link_to image_tag('mail_engine/icons/delete.png'), mail_schedule_path(mail_schedule), :confirm => 'Are you sure?', :method => :delete %>
33
+ <%= link_to image_tag('mail_engine/icons/start.png'), start_mail_schedule_path(mail_schedule), :confirm => 'Are you sure to start this schedule?', :class => "start_button_#{mail_schedule.id}", :remote => true, :method => :post %>
34
+ <%= link_to image_tag('mail_engine/icons/pause.png'), stop_mail_schedule_path(mail_schedule), :confirm => 'Are you sure to stop this schedule?', :class => "stop_button_#{mail_schedule.id}", :remote => true, :method => :post %>
35
+ <script>
36
+ $(function(){
37
+ if(<%= mail_schedule.available? %>) {
38
+ showStopScheduleButton("<%= mail_schedule.id %>");
39
+ } else {
40
+ showStartScheduleButton("<%= mail_schedule.id %>");
41
+ }
42
+ });
43
+ </script>
32
44
  <br>
33
45
  <%= form_tag send_test_mail_mail_schedule_path(mail_schedule), :remote => true do %>
34
46
  <div>
@@ -54,4 +66,18 @@
54
66
  </h5>
55
67
  <div class="clearer">&nbsp;</div>
56
68
  </div>
57
- </div>
69
+ </div>
70
+
71
+ <script>
72
+ function showStartScheduleButton(id) {
73
+ $(".start_button_" + id).show();
74
+ $(".stop_button_" + id).hide();
75
+ $(".availability_state_of_" + id).html("Stopped");
76
+ }
77
+
78
+ function showStopScheduleButton(id) {
79
+ $(".start_button_" + id).hide();
80
+ $(".stop_button_" + id).show();
81
+ $(".availability_state_of_" + id).html("Running");
82
+ }
83
+ </script>
@@ -67,7 +67,7 @@
67
67
 
68
68
  <div id='line_chart'></div>
69
69
  <div class="history" style="margin-top: 50px;">
70
- <table border="0" cellspacing="5" cellpadding="5" class="data-table" style="width: 95%;">
70
+ <table border="0" cellspacing="5" cellpadding="5" class="data-table" style="width: 910px;">
71
71
  <tr>
72
72
  <th>Date</th>
73
73
  <th>Requests</th>
data/config/routes.rb CHANGED
@@ -33,6 +33,8 @@ module MailEngine
33
33
 
34
34
  resources :mail_schedules do
35
35
  member do
36
+ post :start
37
+ post :stop
36
38
  post :send_test_mail
37
39
  end
38
40
  end
@@ -10,6 +10,7 @@ class CreateMailSchedules < ActiveRecord::Migration
10
10
  t.string :payload
11
11
  t.datetime :first_send_at
12
12
  t.datetime :last_sent_at
13
+ t.boolean :available, :default => false
13
14
 
14
15
  t.timestamps
15
16
  end
@@ -5,7 +5,12 @@ module ActionMailer
5
5
  def mail(headers={}, &block)
6
6
  # order by latest uploaded, for get the latest updated 'subject'
7
7
  current_template = MailEngine::MailTemplate.where(:path => "#{controller_path}/#{action_name}", :locale => I18n.locale, :partial => false).order("updated_at desc").first
8
- headers[:subject] = current_template.subject if headers[:subject].blank? && current_template.present?
8
+
9
+ # {'username' => @username, 'gender' => @gender}
10
+ instance_variable_hash = {}
11
+ self.instance_variables.each { |var| instance_variable_hash[var.sub(/^@/,'')] = self.instance_variable_get(var) }
12
+
13
+ headers[:subject] = Liquid::Template.parse(current_template.subject).render(instance_variable_hash) if current_template.present?
9
14
  headers[:message_id] = "#{controller_path}/#{action_name}"
10
15
 
11
16
  unless block_given?
@@ -18,11 +23,11 @@ module ActionMailer
18
23
  end
19
24
  \e[0m"
20
25
  end
21
-
26
+
22
27
  # Add sendgrid header before sending mail.
23
28
  # Why here but not add to default_params of action_mailer? because the receiver email [:to] only can get here.
24
29
  if self.sendgrid_config
25
- self.sendgrid_config.add_to headers[:to]
30
+ self.sendgrid_config.set_send_to headers[:to]
26
31
  origin_mail(headers.merge(self.sendgrid_config.to_hash), &block)
27
32
  else
28
33
  origin_mail(headers, &block)
@@ -27,6 +27,7 @@ module MailEngine
27
27
 
28
28
  rake_tasks do
29
29
  load "mail_engine/tasks/sendmail.rake"
30
+ load "mail_engine/tasks/export_mail_engine_database.rake"
30
31
  end
31
32
 
32
33
  generators do
@@ -40,6 +40,7 @@ module MailEngine
40
40
 
41
41
  module InstanceMethods
42
42
  end
43
+
43
44
  end
44
45
  end
45
46
  end
@@ -54,17 +54,25 @@ module MailEngine
54
54
  @data["filters"] = filter_setting.data
55
55
  end
56
56
 
57
+ # for now only allow to send to one receiver once.
58
+ # maybe we don't like people received a mail which allow people to view all receivers
59
+ def set_send_to(to)
60
+ @data['to'] ||= []
61
+ @data['to'] = Array.wrap(to)
62
+ @data['to'].uniq!
63
+ end
64
+
57
65
  def add_to(to)
58
66
  @data['to'] ||= []
59
- @data['to'] += to.kind_of?(Array) ? to : [to]
67
+ @data['to'] += Array.wrap(to)
60
68
  @data['to'].uniq!
61
69
  end
62
70
 
63
71
  def add_sub_val(var, val)
64
72
  @data['sub'] ||= {}
65
- @data['sub'][var] = val.instance_of?(Array) ? var : [var]
73
+ @data['sub'][var] = Array.wrap(val)
66
74
  end
67
-
75
+
68
76
  def set_unique_args(val)
69
77
  @data['unique_args'] = val if val.instance_of?(Hash)
70
78
  end
@@ -0,0 +1,17 @@
1
+ namespace :mail_engine do
2
+ desc "Check mail schedule table and send the scheduled mail."
3
+ task :export_mail_engine_database => :environment do
4
+ datetime = Time.now.strftime("%Y%m%d")
5
+
6
+ db_config = YAML.load_file(File.join(Rails.root, 'config', 'database.yml'))[Rails.env]
7
+ db_username = db_config["username"]
8
+ db_password = db_config["password"]
9
+ db_database = db_config["database"]
10
+ db_socket = db_config["socket"]
11
+ tables = ['mail_templates', 'mail_schedules', "mail_template_files", "template_partials"]
12
+ backup_file_path = File.join(Rails.root,"tmp", "mail_engine_backup", "#{db_database}_#{datetime}.sql")
13
+
14
+ system "mkdir -p #{File.join(Rails.root,"tmp", "mail_engine_backup")}"
15
+ system "mysqldump -u #{db_username} -S #{db_socket} -p'#{db_password}' #{db_database} #{tables.join(' ')}> #{backup_file_path}"
16
+ end
17
+ end
@@ -2,7 +2,7 @@ namespace :mail_engine do
2
2
  desc "Check mail schedule table and send the scheduled mail."
3
3
  task :sendmail => :environment do
4
4
  puts "==== Start sending scheduled mail ===="
5
- MailEngine::MailSchedule.all.each { |schedule| schedule.sendmail }
5
+ MailEngine::MailSchedule.available.each { |schedule| schedule.sendmail }
6
6
  puts "==== End sending scheduled mail ===="
7
7
  end
8
8
  end
data/mail_engine.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{mail_engine}
8
- s.version = "0.1.3"
8
+ s.version = "0.1.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["michael he"]
12
- s.date = %q{2011-03-06}
12
+ s.date = %q{2011-03-09}
13
13
  s.description = %q{Rails system mail management solution.}
14
14
  s.email = %q{hlxwell@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -209,6 +209,7 @@ Gem::Specification.new do |s|
209
209
  "lib/mail_engine/sendgrid/base.rb",
210
210
  "lib/mail_engine/sendgrid/rest_api.rb",
211
211
  "lib/mail_engine/sendgrid/smtp_api.rb",
212
+ "lib/mail_engine/tasks/export_mail_engine_database.rake",
212
213
  "lib/mail_engine/tasks/sendmail.rake",
213
214
  "lib/mail_engine/version.rb",
214
215
  "lib/mail_engine/zip_processor.rb",
@@ -219,8 +220,12 @@ Gem::Specification.new do |s|
219
220
  "public/images/mail_engine/icons/delete.png",
220
221
  "public/images/mail_engine/icons/edit.gif",
221
222
  "public/images/mail_engine/icons/missing.png",
223
+ "public/images/mail_engine/icons/pause.png",
224
+ "public/images/mail_engine/icons/play.png",
222
225
  "public/images/mail_engine/icons/save.png",
223
226
  "public/images/mail_engine/icons/show.png",
227
+ "public/images/mail_engine/icons/start.png",
228
+ "public/images/mail_engine/icons/stop.png",
224
229
  "public/images/mail_engine/logo.gif",
225
230
  "public/images/mail_engine/logo.png",
226
231
  "public/images/mail_engine/none_layout.png",
@@ -362,7 +367,7 @@ Gem::Specification.new do |s|
362
367
  "test/dummy/app/mailers/user_mailer.rb",
363
368
  "test/dummy/app/models/user.rb",
364
369
  "test/dummy/app/views/user_mailer/notify.html.erb",
365
- "test/dummy/app/views/user_mailer/notify.text.erb",
370
+ "test/dummy/app/views/user_mailer/notify.text.liquid",
366
371
  "test/dummy/config.ru",
367
372
  "test/dummy/config/application.rb",
368
373
  "test/dummy/config/boot.rb",
@@ -396,8 +401,11 @@ Gem::Specification.new do |s|
396
401
  "test/dummy/public/images/mail_engine/icons/delete.png",
397
402
  "test/dummy/public/images/mail_engine/icons/edit.gif",
398
403
  "test/dummy/public/images/mail_engine/icons/missing.png",
404
+ "test/dummy/public/images/mail_engine/icons/pause.png",
399
405
  "test/dummy/public/images/mail_engine/icons/save.png",
400
406
  "test/dummy/public/images/mail_engine/icons/show.png",
407
+ "test/dummy/public/images/mail_engine/icons/start.png",
408
+ "test/dummy/public/images/mail_engine/icons/stop.png",
401
409
  "test/dummy/public/images/mail_engine/logo.gif",
402
410
  "test/dummy/public/images/mail_engine/logo.png",
403
411
  "test/dummy/public/images/mail_engine/none_layout.png",
@@ -17,7 +17,7 @@ class UserMailer < ActionMailer::Base
17
17
  @username = "Michael He"
18
18
 
19
19
  # html must below text
20
- mail :to => to do |f|
20
+ mail :to => to, :subject => "subject in mailer" do |f|
21
21
  f.html
22
22
  f.text
23
23
  end
@@ -38,6 +38,7 @@ Dummy::Application.configure do
38
38
  :authentication => :plain
39
39
  }
40
40
 
41
+ config.action_mailer.default_url_options = { :host => "lvh.me:3000" }
41
42
  # Print deprecation notices to the Rails logger
42
43
  config.active_support.deprecation = :log
43
44
 
@@ -8,6 +8,8 @@ class CreateUsers < ActiveRecord::Migration
8
8
 
9
9
  t.timestamps
10
10
  end
11
+
12
+ User.create! :email => "m@theplant.jp", :firstname => "Michael", :lastname => "He", :locale => "en"
11
13
  end
12
14
 
13
15
  def self.down
@@ -10,6 +10,7 @@ class CreateMailSchedules < ActiveRecord::Migration
10
10
  t.string :payload
11
11
  t.datetime :first_send_at
12
12
  t.datetime :last_sent_at
13
+ t.boolean :available
13
14
 
14
15
  t.timestamps
15
16
  end
@@ -33,6 +33,7 @@ ActiveRecord::Schema.define(:version => 20110217062316) do
33
33
  t.string "payload"
34
34
  t.datetime "first_send_at"
35
35
  t.datetime "last_sent_at"
36
+ t.boolean "available"
36
37
  t.datetime "created_at"
37
38
  t.datetime "updated_at"
38
39
  end
@@ -1,14 +1,24 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class UserMailerTest < ActionController::TestCase
4
- context "description" do
5
- setup do
6
-
4
+ context "UserMailer" do
5
+ should "has sendgrid header" do
6
+ assert UserMailer.sendgrid_config.to_hash["X-SMTPAPI"].present?
7
7
  end
8
8
 
9
- should "description" do
10
-
9
+ should "only send mail to the receiver" do
10
+ UserMailer.notify("x@x.com").deliver
11
+ assert UserMailer.sendgrid_config.to_hash["X-SMTPAPI"].include?("[\"x@x.com\"]")
12
+
13
+ UserMailer.notify("y@y.com").deliver
14
+ assert UserMailer.sendgrid_config.to_hash["X-SMTPAPI"].include?("[\"y@y.com\"]")
15
+ end
16
+
17
+ should "override subject by db tempate.subject" do
18
+ @template = FactoryGirl.build(:system_mail_template_with_footer, :format => "html")
19
+ assert_equal "subject in mailer", UserMailer.notify("x@x.com").subject
20
+ @template.save
21
+ assert_equal @template.subject, UserMailer.notify("x@x.com").subject
11
22
  end
12
23
  end
13
-
14
24
  end
@@ -33,9 +33,39 @@ class MailEngine::MailScheduleTest < ActiveSupport::TestCase
33
33
  @schedule.send_test_mail_to!("hlxwell@gmail.com", 0)
34
34
  end
35
35
  end
36
-
37
- should "be able to get next_several_schedules" do
38
- assert_equal [], @schedule.next_several_schedules
36
+
37
+ context "when get next_several_schedules" do
38
+ setup do
39
+ @schedule.first_send_at = 2.days.ago
40
+ end
41
+
42
+ should "get correct list for once schedule" do
43
+ @schedule.sent_count = 1
44
+ assert_equal [], @schedule.next_several_schedule_dates
45
+
46
+ @schedule.sent_count = 0
47
+ assert_equal [], @schedule.next_several_schedule_dates
48
+ end
49
+
50
+ should "get correct list for daily schedule" do
51
+ @schedule.period = "daily"
52
+ assert_equal Time.now.tomorrow.day, @schedule.next_several_schedule_dates.first.day
53
+ end
54
+
55
+ should "get correct list for weekly schedule" do
56
+ @schedule.period = "weekly"
57
+ assert_equal (@schedule.first_send_at + 1.week).day, @schedule.next_several_schedule_dates.first.day
58
+ end
59
+
60
+ should "get correct list for monthly schedule" do
61
+ @schedule.period = "monthly"
62
+ assert_equal (@schedule.first_send_at + 1.month).day, @schedule.next_several_schedule_dates.first.day
63
+ end
64
+
65
+ should "get correct list for yearly schedule" do
66
+ @schedule.period = "yearly"
67
+ assert_equal (@schedule.first_send_at + 1.year).day, @schedule.next_several_schedule_dates.first.day
68
+ end
39
69
  end
40
70
  end
41
71
 
@@ -71,6 +101,7 @@ class MailEngine::MailScheduleTest < ActiveSupport::TestCase
71
101
  assert @schedule.ready_to_send?
72
102
  @schedule.sendmail
73
103
  assert !@schedule.ready_to_send?
104
+ Timecop.return
74
105
  end
75
106
  end
76
107
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mail_engine
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 3
10
- version: 0.1.3
9
+ - 4
10
+ version: 0.1.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - michael he
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-03-06 00:00:00 +08:00
18
+ date: 2011-03-09 00:00:00 +08:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -446,6 +446,7 @@ files:
446
446
  - lib/mail_engine/sendgrid/base.rb
447
447
  - lib/mail_engine/sendgrid/rest_api.rb
448
448
  - lib/mail_engine/sendgrid/smtp_api.rb
449
+ - lib/mail_engine/tasks/export_mail_engine_database.rake
449
450
  - lib/mail_engine/tasks/sendmail.rake
450
451
  - lib/mail_engine/version.rb
451
452
  - lib/mail_engine/zip_processor.rb
@@ -456,8 +457,12 @@ files:
456
457
  - public/images/mail_engine/icons/delete.png
457
458
  - public/images/mail_engine/icons/edit.gif
458
459
  - public/images/mail_engine/icons/missing.png
460
+ - public/images/mail_engine/icons/pause.png
461
+ - public/images/mail_engine/icons/play.png
459
462
  - public/images/mail_engine/icons/save.png
460
463
  - public/images/mail_engine/icons/show.png
464
+ - public/images/mail_engine/icons/start.png
465
+ - public/images/mail_engine/icons/stop.png
461
466
  - public/images/mail_engine/logo.gif
462
467
  - public/images/mail_engine/logo.png
463
468
  - public/images/mail_engine/none_layout.png
@@ -599,7 +604,7 @@ files:
599
604
  - test/dummy/app/mailers/user_mailer.rb
600
605
  - test/dummy/app/models/user.rb
601
606
  - test/dummy/app/views/user_mailer/notify.html.erb
602
- - test/dummy/app/views/user_mailer/notify.text.erb
607
+ - test/dummy/app/views/user_mailer/notify.text.liquid
603
608
  - test/dummy/config.ru
604
609
  - test/dummy/config/application.rb
605
610
  - test/dummy/config/boot.rb
@@ -633,8 +638,11 @@ files:
633
638
  - test/dummy/public/images/mail_engine/icons/delete.png
634
639
  - test/dummy/public/images/mail_engine/icons/edit.gif
635
640
  - test/dummy/public/images/mail_engine/icons/missing.png
641
+ - test/dummy/public/images/mail_engine/icons/pause.png
636
642
  - test/dummy/public/images/mail_engine/icons/save.png
637
643
  - test/dummy/public/images/mail_engine/icons/show.png
644
+ - test/dummy/public/images/mail_engine/icons/start.png
645
+ - test/dummy/public/images/mail_engine/icons/stop.png
638
646
  - test/dummy/public/images/mail_engine/logo.gif
639
647
  - test/dummy/public/images/mail_engine/logo.png
640
648
  - test/dummy/public/images/mail_engine/none_layout.png