Permalink
Browse files

Added ability for wizard to schedule emails for now or in the future

  • Loading branch information...
1 parent e89b8be commit 9d409ffea62b6344ab462d68dc5764e44ae680c9 @mikel committed Jun 10, 2009
View
@@ -68,10 +68,20 @@ def next_step
else
'select_recipients'
end
+ when state == 'date_scheduled'
+ 'confirm'
else
'new'
end
end
+
+ def schedule
+ nil
+ end
+
+ def schedule=(value)
+ self.date_scheduled = Time.now if value == 'now'
+ end
def html_file_data=(data)
self.html_part = data.read
@@ -0,0 +1 @@
+<h2>Confirm Mailout</h2>
@@ -1,2 +1,10 @@
<h2>Schedule Mailout</h2>
+<%= f.label :schedule_now, "Send out immediately" %>
+<%= f.radio_button("schedule", "now") %>
+
+<%= f.label :schedule_at, "Send out at" %>
+<%= f.radio_button("schedule", "at") %>
+
+<%= f.datetime_select :date_scheduled %>
+<%= f.hidden_field :state, :value => 'date_scheduled' %>
@@ -0,0 +1,11 @@
+class AddScheduledTimeAndDateSentToMessages < ActiveRecord::Migration
+ def self.up
+ add_column :messages, :date_scheduled, :datetime
+ add_column :messages, :date_sent, :datetime
+ end
+
+ def self.down
+ remove_column :messages, :date_sent
+ remove_column :messages, :date_scheduled
+ end
+end
View
@@ -9,7 +9,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20090606215023) do
+ActiveRecord::Schema.define(:version => 20090610221548) do
create_table "addressees", :force => true do |t|
t.integer "message_id"
@@ -59,6 +59,8 @@
t.string "type"
t.datetime "created_at"
t.datetime "updated_at"
+ t.datetime "date_scheduled"
+ t.datetime "date_sent"
end
create_table "organizations", :force => true do |t|
@@ -232,4 +232,34 @@ Feature: Messages Wizard
And I follow "Remove"
Then I should see "Select Recipients"
And the message called "My Email" should have no groups
-
+
+ Scenario: Scheduling a message
+ Given I am logged in
+ And there is a group in the system called "Public"
+ And there is a message called "My Email" in the system with "Public" as a group
+ When I go to the edit page for "Message" with a "title" of "My Email"
+ And I press "Next"
+ Then I should see "Schedule Mailout"
+
+ Scenario: Scheduling a message to be sent out now
+ Given I am logged in
+ And there is a group in the system called "Public"
+ And there is a message called "My Email" in the system with "Public" as a group
+ When I go to the edit page for "Message" with a "title" of "My Email"
+ And I press "Next"
+ And I choose "Send out immediately"
+ And I press "Next"
+ Then I should see "Confirm Mailout"
+ And the message called "My Email" should have a scheduled time of "now"
+
+ Scenario: Scheduling a message to be sent out in the future
+ Given I am logged in
+ And there is a group in the system called "Public"
+ And there is a message called "My Email" in the system with "Public" as a group
+ When I go to the edit page for "Message" with a "title" of "My Email"
+ And I press "Next"
+ And I choose "Send out at"
+ And I select "December 25, 2010 20:12" as the date and time
+ And I press "Next"
+ Then I should see "Confirm Mailout"
+ And the message called "My Email" should have a scheduled time of "December 25, 2010 20:12"
@@ -25,3 +25,12 @@
Then /^the message called "([^\"]*)" should have no (.*)$/ do |title, collection|
Message.find(:first, :conditions => {:title => title}).send(collection).count.should == 0
end
+
+Then /^the message called "([^\"]*)" should have a scheduled time of "([^\"]*)"$/ do |title, time|
+ @message = Message.find(:first, :conditions => {:title => title})
+ if time == 'now'
+ @message.date_scheduled.should < Time.now
+ else
+ @message.date_scheduled.should == DateTime.parse(time)
+ end
+end
@@ -104,6 +104,22 @@
end
end
+ describe "helper for setting the schedule" do
+ it "should have a virtual attribute called 'schedule'" do
+ @message = Message.new
+ @message.should respond_to(:schedule)
+ @message.should respond_to(:schedule=)
+ end
+
+ it "should rest the date_scheduled to now if schedule is set to 'now'" do
+ @time = Time.now
+ Time.stub!(:now).and_return(@time)
+ @message = Message.new
+ @message.schedule = 'now'
+ @message.date_scheduled.should == @time
+ end
+ end
+
describe "helper for adding a recipient individually" do
it "should have the virtual attribute :add_recipient" do
@message = Message.new
@@ -286,6 +302,12 @@
@message.attachments.first.filename.should == 'rails.png'
end
+ it "should return confirm if the state is set to date_scheduled" do
+ @message = Message.new
+ @message.state = 'date_scheduled'
+ @message.next_step.should == 'confirm'
+ end
+
it "should set return edit_content if the state is set to 'file_uploaded'" do
@message = Message.new
@message.state = 'file_uploaded'

0 comments on commit 9d409ff

Please sign in to comment.