Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
Checking mergeability… Don't worry, you can still create the pull request.
  • 5 commits
  • 15 files changed
  • 0 commit comments
  • 1 contributor
Commits on May 06, 2011
Luke Crawford and Dave Goddard Further updated style + UX tweaks. c59b71d
Luke Crawford and Dave Goddard Add some flash messages. 936da29
Luke Crawford and Dave Goddard "Enable" messages in UI, add styles, add expiry to messages. fe23083
Luke Crawford and Dave Goddard Add active scope to message. 7545114
Luke Crawford and Dave Goddard Set expiry correctly with new records. 973fed3
View
1  app/controllers/aggregate_projects_controller.rb
@@ -33,6 +33,7 @@ def update
def destroy
@aggregate_project.destroy
+ flash[:notice] = 'Aggregate project was successfully destroyed.'
redirect_to projects_url
end
View
3  app/controllers/messages_controller.rb
@@ -2,7 +2,7 @@ class MessagesController < ApplicationController
before_filter :login_required
def index
- @messages = Message.find(:all)
+ @messages = Message.active
end
def new
@@ -38,6 +38,7 @@ def update
def destroy
@message = Message.find(params[:id])
@message.destroy
+ flash[:notice] = 'Message was successfully destroyed.'
redirect_to(messages_path)
end
end
View
1  app/controllers/projects_controller.rb
@@ -33,6 +33,7 @@ def update
def destroy
@project.destroy
+ flash[:notice] = 'Project was successfully destroyed.'
redirect_to projects_url
end
View
38 app/models/message.rb
@@ -1,3 +1,41 @@
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
+
+ after_create :set_expires_at
+
+ acts_as_taggable
+
+ default_scope order('created_at asc')
+ scope :active, lambda { where("expires_at IS NULL OR expires_at >= ?", Time.now) }
+
+ def expires_in
+ return if expires_at.blank?
+ return if created_at.blank?
+
+ expires_at - created_at
+ end
+
+ def expires_in=(seconds)
+ if seconds.to_i > 0
+ @expires_in = seconds.to_i
+ self.expires_at = (created_at || Time.now) + @expires_in
+ end
+ end
+
+ private
+
+ def set_expires_at
+ return unless @expires_in
+
+ update_attribute(:expires_at, created_at + @expires_in)
+ 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
18 app/views/messages/_form.html.erb
@@ -0,0 +1,18 @@
+<%= f.error_messages %>
+
+<p>
+ <%= f.label :text %>
+ <%= f.text_field :text %>
+</p>
+
+<p>
+ <%= f.label :expires_in %>
+ <%= f.select :expires_in, Message::DURATIONS_SELECT %>
+ <%- if @message.created_at -%>
+ <em>From message creation, <%= @message.created_at %></em>
+ <%- end -%>
+</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 In</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 time_ago_in_words(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
1  app/views/projects/index.html.erb
@@ -47,6 +47,7 @@
<th>&nbsp;</th>
</tr>
+ <% reset_cycle -%>
<% for aggregated_project in @aggregate_projects %>
<tr class="<%= cycle("odd", "even") %>">
<td><%= h aggregated_project.name %></td>
View
28 app/views/sessions/new.html.erb
@@ -1,16 +1,26 @@
<h1>Log In</h1>
<%= form_tag session_path do -%>
-<p><%= label_tag 'login' %><br />
-<%= text_field_tag 'login', @login %></p>
+ <p>
+ <%= label_tag 'login' %>
+ <%= text_field_tag 'login', @login %>
+ </p>
-<p><%= label_tag 'password' %><br/>
-<%= password_field_tag 'password', nil %></p>
+ <p>
+ <%= label_tag 'password' %>
+ <%= password_field_tag 'password', nil %>
+ </p>
-<!-- Uncomment this if you want this functionality
-<p><%= label_tag 'remember_me', 'Remember me' %>
-<%= check_box_tag 'remember_me', '1', @remember_me %></p>
--->
+ <!-- Uncomment this if you want this functionality
+ <p>
+ <%= label_tag 'remember_me', 'Remember me' %>
+ <%= check_box_tag 'remember_me', '1', @remember_me %>
+ </p>
+ -->
-<p><%= submit_tag 'Log in' %></p>
+ <p style="text-align: right; margin-bottom: 0;">
+ <%= submit_tag 'Log In' %>
+ </p>
<% end -%>
+
+<%= javascript_tag "Field.focus('login');" %>
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
9 public/stylesheets/style.css
@@ -294,16 +294,14 @@ a:hover.button {
font-weight: bold;
}
-form.project_edit, form.project_new, form.new_user,
-form.aggregate_project_edit, form.aggregate_project_new {
+form {
background-color: #eeeeee;
margin: 30px;
padding: 30px;
width: 38em;
}
-form.project_edit label, form.project_new label, form.new_user label,
-form.aggregate_project_edit label, form.aggregate_project_new label {
+form label {
width: 9em;
display: inline-table;
vertical-align: top;
@@ -312,8 +310,7 @@ form.aggregate_project_edit label, form.aggregate_project_new label {
margin-right: 2em;
}
-form.project_edit em, form.project_new em,
-form.aggregate_project_edit em, form.aggregate_project_new em {
+form em {
margin-top: .4em;
margin-left: 12em;
display: block;
View
77 spec/models/message_spec.rb
@@ -1,15 +1,76 @@
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
- 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
+ describe ".active" do
+ before do
+ @message_no_expiry = Message.create(:text => "hi")
+ @message_future_expiry = Message.create(:text => "hello", :expires_at => 1.hour.from_now)
+ @message_past_expiry = Message.create(:text => "aloha", :expires_at => 1.hour.ago)
+ end
+
+ it "returns messages that do not have an expiration" do
+ Message.active.should include(@message_no_expiry)
+ end
+
+ it "returns messages with an expiry that haven't yet" do
+ Message.active.should include(@message_future_expiry)
+ end
+
+ it "doesn't return expired messages" do
+ Message.active.should_not include(@message_past_expiry)
+ 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 "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
+
+ message.created_at.should be
+ message.expires_at.should be
+ message.expires_at.should == now + 1.hour
+ end
+
+ it "sets expires_at correctly on message creation" do
+ message = Message.create(:text => "hi")
+
+ message.expires_at.should_not be
+
-end
+ duration = 1.hour
+ message = Message.new(:text => "hi", :expires_in => duration)
+ sleep(2)
+ message.save
+
+ message.expires_at.should == message.created_at + duration
+ end
+ end
+end

No commit comments for this range

Something went wrong with that request. Please try again.