Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added confirm mailout and basic messages index page

  • Loading branch information...
commit 8cc90e442574388b2eabc919ba33ea2eef8e32f2 1 parent 9d409ff
@mikel authored
View
8 app/controllers/messages_controller.rb
@@ -1,4 +1,8 @@
class MessagesController < ApplicationController
+
+ def index
+ @messages = Message.find(:all)
+ end
def new
@message = Message.new
@@ -19,8 +23,8 @@ def update
@message.attributes = params[:message]
@message.save
case @message.next_step
- when "finished"
-
+ when "ready_to_send"
+ redirect_to messages_path
else
render :action => :edit
end
View
10 app/models/message.rb
@@ -70,18 +70,12 @@ def next_step
end
when state == 'date_scheduled'
'confirm'
+ when state == 'confirmed'
+ 'ready_to_send'
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
View
25 app/views/messages/_confirm.html.erb
@@ -1 +1,24 @@
-<h2>Confirm Mailout</h2>
+<h2>Confirm Mailout</h2>
+<p>
+ Title:
+ <%= message.title %>
+</p>
+<p>
+ Date Scheduled:
+ <%= message.date_scheduled %>
+</p>
+<p>
+ Groups:
+ <ul>
+ <%= render :partial => "group", :collection => message.groups, :locals => {:message => message} %>
+ </ul>
+</p>
+<p>
+ Recipients:
+ <ul>
+ <%= render :partial => "recipient", :collection => message.recipients, :locals => {:message => message} %>
+ </ul>
+</p>
+<%= f.hidden_field :state, :value => 'confirmed' %>
+
+<%= f.submit "Confirm Mailout" %>
View
1  app/views/messages/_edit_content.html.erb
@@ -18,3 +18,4 @@
<%- end -%>
+<%= f.submit "Next" %>
View
2  app/views/messages/_group.html.erb
@@ -1,4 +1,4 @@
<li>
<%= group.name %>,
- <%= link_to "Remove", message_group_path(:id => group.to_param, :message_id => @message.to_param), :method => 'delete' %>
+ <%= link_to "Remove", message_group_path(:id => group.to_param, :message_id => message.to_param), :method => 'delete' %>
</li>
View
5 app/views/messages/_message.html.erb
@@ -0,0 +1,5 @@
+<li>
+ <%= message.title %>&nbsp;
+ <%= message.date_scheduled %>&nbsp;
+ <%= message.state %>&nbsp;
+</li>
View
2  app/views/messages/_recipient.html.erb
@@ -1,4 +1,4 @@
<li>
<%= recipient.name %>,
- <%= link_to "Remove", message_recipient_path(:id => recipient.to_param, :message_id => @message.to_param), :method => 'delete' %>
+ <%= link_to "Remove", message_recipient_path(:id => recipient.to_param, :message_id => message.to_param), :method => 'delete' %>
</li>
View
9 app/views/messages/_schedule_mailout.html.erb
@@ -1,10 +1,7 @@
<h2>Schedule Mailout</h2>
-<%= f.label :schedule_now, "Send out immediately" %>
-<%= f.radio_button("schedule", "now") %>
+<%= f.datetime_select :date_scheduled, :default => Time.now %>
-<%= f.label :schedule_at, "Send out at" %>
-<%= f.radio_button("schedule", "at") %>
+<%= f.hidden_field :state, :value => 'date_scheduled' %>
-<%= f.datetime_select :date_scheduled %>
-<%= f.hidden_field :state, :value => 'date_scheduled' %>
+<%= f.submit "Next" %>
View
4 app/views/messages/_select_files.html.erb
@@ -6,4 +6,6 @@
<%= f.label :file_data, "Zip File" %>:
<%= f.file_field :zip_file_data %>
</p>
-<%= f.hidden_field :state, :value => 'file_uploaded' %>
+<%= f.hidden_field :state, :value => 'file_uploaded' %>
+
+<%= f.submit "Next" %>
View
8 app/views/messages/_select_recipients.html.erb
@@ -1,17 +1,19 @@
<h2>Select Recipients</h2>
<ul>
- <%= render :partial => "group", :collection => @message.groups %>
+ <%= render :partial => "group", :collection => message.groups, :locals => {:message => message} %>
</ul>
<%= f.label :add_group_id, "Add Group" %>
<%= f.collection_select :add_group_id, Group.all(:order => 'name'), :id, :name, :include_blank => true -%>
<ul>
- <%= render :partial => "recipient", :collection => @message.recipients %>
+ <%= render :partial => "recipient", :collection => message.recipients, :locals => {:message => message} %>
</ul>
<%= f.label :add_recipient, "Add Recipient" %>
<%= f.text_field :add_recipient -%>
Enter name or email address
-<%= f.hidden_field :state, :value => 'recipients_selected' %>
+<%= f.hidden_field :state, :value => 'recipients_selected' %>
+
+<%= f.submit "Next" %>
View
4 app/views/messages/_select_template.html.erb
@@ -2,4 +2,6 @@
<%= f.label :email_template_id, "Select Template" %>
<%= f.collection_select :email_template_id, current_user.email_templates.all(:order => 'title'), :id, :title, :include_blank => 'Please select template' %><br />
</p>
-<%= f.hidden_field :state, :value => 'template_selected' %>
+<%= f.hidden_field :state, :value => 'template_selected' %>
+
+<%= f.submit "Next" %>
View
3  app/views/messages/edit.html.erb
@@ -1,7 +1,6 @@
<% form_for @message, :html => { :multipart => (@message.next_step == 'select_files') } do |f| -%>
<%= f.error_messages %>
- <%= render :partial => @message.next_step, :locals => { :f => f } %>
+ <%= render :partial => @message.next_step, :locals => { :f => f, :message => @message } %>
- <%= f.submit "Next" %>
<% end -%>
View
9 app/views/messages/index.html.erb
@@ -0,0 +1,9 @@
+<%- if @messages.empty? -%>
+ No messages created
+<% else -%>
+ <ul>
+ <%= render :partial => 'message', :collection => @messages %>
+ </ul>
+<%- end -%>
+
+<%= link_to "Make a new message", new_message_path %>
View
27 features/messages_wizard.feature → features/manage_messages.feature
@@ -241,25 +241,38 @@ Feature: Messages Wizard
And I press "Next"
Then I should see "Schedule Mailout"
- Scenario: Scheduling a message to be sent out 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 immediately"
+ 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 "now"
-
- Scenario: Scheduling a message to be sent out in the future
+ And the message called "My Email" should have a scheduled time of "December 25, 2010 20:12"
+
+ Scenario: Confirming a mailout
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"
+ And I should see "Title"
+ And I should see "My Email"
+ And I should see "Date Scheduled"
+ And I should see "2010-12-25 20:12:00 UTC"
+ And I should see "Groups"
+ And I should see "Public"
+ And I should see "Recipients"
+
+ Scenario: Approving a mailout
+ 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 that has been scheduled
+ When I go to the edit page for "Message" with a "title" of "My Email"
+ And I press "Confirm Mailout"
+ Then I should be on the messages page
View
12 features/step_definitions/manage_messages.rb → ...step_definitions/manage_messages_steps.rb
@@ -13,6 +13,15 @@
message.groups << group
end
+When /^there is a message called "([^\"]*)" in the system with "([^\"]*)" as a group that has been scheduled$/ do |title, group|
+ message = Factory(:message, :title => title, :state => 'content_edited', :user => User.first)
+ group = Factory(:group, :name => group, :user => User.find(:first))
+ message.date_scheduled = 1.day.from_now
+ message.state = "date_scheduled"
+ message.save!
+ message.groups << group
+end
+
When /^there is a message called "([^\"]*)" in the system$/ do |title|
message = Factory(:message, :title => title, :state => 'content_edited', :user => User.first)
message.save!
@@ -29,7 +38,8 @@
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
+ # Don't want to stub Time, so just see if it is within 10 seconds of now
+ (@message.date_scheduled.to_i - Time.now.to_i).abs.should < 10
else
@message.date_scheduled.should == DateTime.parse(time)
end
View
2  features/support/paths.rb
@@ -70,7 +70,7 @@ def path_to(page_name)
new_message_path
when /the messages page/
- new_message_path
+ messages_path
when /the groups page/
groups_path
View
23 spec/models/message_spec.rb
@@ -35,6 +35,7 @@
@message.add_group_id = @group
@message.should be_valid
end
+
end
describe "associations" do
@@ -104,22 +105,6 @@
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
@@ -326,6 +311,12 @@
@message.next_step.should == 'select_recipients'
end
+ it "should return 'ready_to_send' if it's state is 'confirmed' " do
+ @message = Message.new
+ @message.state = 'confirmed'
+ @message.next_step.should == 'ready_to_send'
+ end
+
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.