Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

"Enable" messages in UI, add styles, add expiry to messages.

  • Loading branch information...
commit fe2308318a9165ee3bfd8445cdcdc49789fa8fa7 1 parent 936da29
Luke Crawford and Dave Goddard authored
View
26 app/models/message.rb
@@ -1,3 +1,29 @@
class Message < ActiveRecord::Base
+ DURATIONS_SELECT = [
+ ["30 minutes", 30.minutes],
+ ["1 hour", 1.hour],
+ ["2 hours", 2.hours],
+ ["8 hours", 8.hours],
+ ["1 day", 1.day],
+ ["2 days", 2.days]
+ ]
+
validates_presence_of :text
+
+ acts_as_taggable
+
+ def expires_in
+ return if expires_at.blank?
+ return if created_at.blank?
+
+ expires_at - created_at
+ end
+
+ def expires_in=(seconds)
+ self.expires_at = if seconds.to_i > 0 && created_at.present?
+ created_at + seconds.to_i
+ else
+ Time.now
+ end
+ end
end
View
9 app/views/layouts/application.html.erb
@@ -23,12 +23,15 @@
<div id="top_right">
<% if current_user.present? %>
Hello, <%= current_user.login %>
+ <%= link_to "(log out)", logout_path, :class=>'smaller_text' %>
<br />
- <%= link_to "Projects", projects_path %> |
+ <%= link_to "Projects", projects_path %>
+ |
+ <%= link_to "Messages", messages_path %>
+ |
<% if AuthConfig.password? %>
- <%= link_to "Add User", new_user_path %> |
+ <%= link_to "Add User", new_user_path %>
<% end %>
- <%= link_to "Log Out", logout_path %>
<% else %>
<%= link_to "Log In", AuthConfig.openid? ? new_openid_path : login_path %>
<% end %>
View
15 app/views/messages/_form.html.erb
@@ -0,0 +1,15 @@
+<%= f.error_messages %>
+
+<p>
+ <%= f.label :text %>
+ <%= f.text_field :text %>
+</p>
+
+<p>
+ <%= f.label :expires_in %>
+ <%= f.select :expires_in, Message::DURATIONS_SELECT %>
+</p>
+
+<p style="text-align: right; margin-bottom: 0;">
+ <%= f.submit @message.new_record? ? "Create" : "Update" %>
+</p>
View
21 app/views/messages/edit.html.erb
@@ -1,16 +1,13 @@
-<h1>Editing message</h1>
+<%= link_to '&larr; Back to Messages'.html_safe, messages_path %>
-<%= form_for(@message) do |f| %>
- <%= f.error_messages %>
+<h1>Edit Message</h1>
+
+<%= error_messages_for :message %>
- <p>
- <%= f.label :text %><br />
- <%= f.text_field :text %>
- </p>
- <p>
- <%= f.submit "Update" %>
- </p>
+<%= form_for(@message) do |f| %>
+ <%= render :partial => 'form', :locals => {:f => f} %>
<% end %>
-<%= link_to 'Show', @message %> |
-<%= link_to 'Back', messages_path %>
+<div style="margin-left: 30px;">
+ <%= link_to 'Remove Message -', message_path(@message), :confirm => 'Are you sure?', :method => :delete, :class => "button" %>
+</div>
View
16 app/views/messages/index.html.erb
@@ -1,19 +1,19 @@
-<h1>Listing messages</h1>
+<h1>Messages</h1>
-<table>
+<%= link_to 'Add Message +', new_message_path, :class => "button add_button" %>
+
+<table class="projects">
<tr>
<th>Text</th>
+ <th>Expires</th>
</tr>
<% for message in @messages %>
- <tr>
+ <tr class="<%= cycle("odd", "even") %>">
<td><%=h message.text %></td>
- <td><%= link_to 'Edit', edit_message_path(message) %></td>
- <td><%= link_to 'Delete', message, :confirm => 'Are you sure?', :method => :delete %></td>
+ <td><%=h message.expires_at %></td>
+ <td><%= link_to 'Edit', edit_message_path(message), :class => "button" %></td>
</tr>
<% end %>
</table>
-<br />
-
-<%= link_to 'New message', new_message_path %>
View
16 app/views/messages/new.html.erb
@@ -1,15 +1,7 @@
-<h1>New message</h1>
+<%= link_to '&larr; Back to Messages'.html_safe, messages_path %>
-<%= form_for(@message) do |f| %>
- <%= f.error_messages %>
+<h1>Add Message</h1>
- <p>
- <%= f.label :text %><br />
- <%= f.text_field :text %>
- </p>
- <p>
- <%= f.submit "Create" %>
- </p>
+<%= form_for(@message) do |f| %>
+ <%= render :partial => 'form', :locals => { :f => f } %>
<% end %>
-
-<%= link_to 'Back', messages_path %>
View
9 db/migrate/20110506140319_add_expiry_to_messages.rb
@@ -0,0 +1,9 @@
+class AddExpiryToMessages < ActiveRecord::Migration
+ def self.up
+ add_column :messages, :expires_at, :datetime
+ end
+
+ def self.down
+ remove_column :messages, :expires_at
+ end
+end
View
3  db/schema.rb
@@ -10,7 +10,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20110505140551) do
+ActiveRecord::Schema.define(:version => 20110506140319) do
create_table "aggregate_projects", :force => true do |t|
t.string "name"
@@ -38,6 +38,7 @@
t.string "text"
t.datetime "created_at"
t.datetime "updated_at"
+ t.datetime "expires_at"
end
create_table "project_statuses", :force => true do |t|
View
43 spec/models/message_spec.rb
@@ -1,15 +1,42 @@
require 'spec_helper'
describe Message do
+ describe "validations" do
+ it "should require text" do
+ message = Message.new
+ message.should_not be_valid
+ message.errors[:text].should_not be_nil
+
+ message.text = "foo"
+ message.should be_valid
+ end
+ end
+
+ describe "#expires_in" do
+ it "returns nil when expires_at is blank" do
+ message = Message.new(:expires_at => nil)
+
+ message.expires_in.should be_nil
+ end
- it "should require text" do
- message = Message.new
- message.should_not be_valid
- message.errors[:text].should_not be_nil
-
- message.text = "foo"
- message.should be_valid
+ it "returns seconds between expires_at and created_at if expires_at is present" do
+ now = Time.now
+ expiry = now + 1.hour
+ message = Message.new(:created_at => now, :expires_at => expiry)
+
+ message.expires_in.should == (expiry - message.created_at)
+ end
end
+ describe "#expires_in=" do
+ it "sets expires_at to n seconds after the message was created" do
+ now = Time.now
+ message = Message.new(:created_at => now)
+ message.expires_in = 1.hour
-end
+ message.created_at.should be
+ message.expires_at.should be
+ message.expires_at.should == now + 1.hour
+ end
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.