Skip to content

Commit

Permalink
Initial events feature
Browse files Browse the repository at this point in the history
  • Loading branch information
djgraham committed Feb 1, 2012
1 parent 6417bde commit 483e567
Show file tree
Hide file tree
Showing 14 changed files with 157 additions and 4 deletions.
3 changes: 3 additions & 0 deletions app/assets/javascripts/admin/events.js.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/admin/events.css.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the admin/events controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
41 changes: 41 additions & 0 deletions app/controllers/admin/events_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
class Admin::EventsController < ApplicationController

before_filter :load_event, :except => [:index, :new, :create]
respond_to :html

def index
@events = Event.all
end

def edit

end

def new
@event = Event.new
end

def update
if @event.update_attributes(params[:event])
redirect_to admin_events_path, :flash => { :info => "Event saved" }
else
render :action => :edit
end
end

def create
@event = Event.new(params[:event])
if @event.save
redirect_to admin_events_path, :flash => { :info => "Event created" }
else
render :action => :edit
end
end

protected

def load_event
@event = Event.find params[:id]
end

end
2 changes: 2 additions & 0 deletions app/helpers/admin/events_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module Admin::EventsHelper
end
15 changes: 15 additions & 0 deletions app/views/admin/events/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<%= semantic_form_for [:admin, @event] do |f| %>
<%= f.inputs do %>
<%= f.input :title %>
<%= f.input :content %>
<%= f.input :status %>
<%= f.input :scheduled_at %>
<% end %>
<%= f.buttons do %>
<%= f.commit_button 'Save' %>
<% end %>
<% end %>

5 changes: 5 additions & 0 deletions app/views/admin/events/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<h1>Edit event</h1>

<%= render :partial => "form" %>


24 changes: 24 additions & 0 deletions app/views/admin/events/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<h1>Events</h1>

<%= link_to "Add new event", new_admin_event_path %>
<% if @events.size > 0 %>
<table>
<thead>
<th>Title</th>
<th>Status</th>
<th>Scheduled at</th>
<th>Resolved?</th>
</thead>
<tbody>
<% @events.each do |event| %>
<tr>
<td><%= link_to event.title, edit_admin_event_path(event) %></td>
<td><%= event.status.try(:name) %></td>
<td><%= event.scheduled_at %></td>
<td><%= event.resolved? ? "Y" : "N" %></td>
</tr>
<% end %>
</tbody>
</table>
<% end %>
5 changes: 5 additions & 0 deletions app/views/admin/events/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<h1>New event</h1>

<%= render :partial => "form" %>


2 changes: 1 addition & 1 deletion app/views/admin/statuses/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<%= link_to "Add new status", new_admin_status_path %>
<% if @statuses.size > 1 %>
<% if @statuses.size > 0 %>
<table>
<thead>
<th>Status name</th>
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace :admin do
resources :statuses
resources :events
end
# The priority is based upon order of creation:
# first created -> highest priority.
Expand Down
10 changes: 7 additions & 3 deletions features/administrator_manages_events.feature
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ Feature: Administrator manages events
Given I am logged in as an administrator
And there are events within the system

# Scenario: ...
# When...
# Then ...
Scenario: Add an event
When I add an event
Then I should see the message "Event created"

Scenario: Edit an event
When I save the event
Then I should see the message "Event saved"
30 changes: 30 additions & 0 deletions features/step_definitions/admin_event_steps.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Given /^there are events within the system$/ do
#@events = Event.all
@status = a_saved Status, :name => "test_status", :colour => "ff0000"
@event = a_saved Event, :title => "test_event", :content => "test content", :status => @status
end

When /^I add an event$/ do
visit '/admin/events'
click_link 'Add new event'
fill_in 'event_title', :with => "My title"
fill_in 'event_content', :with => "My content"
select('test_status', :from => 'event_status_id')
click_button("Save")
end


Then /^I should see the message "([^"]*)"$/ do |arg1|
page.should have_content(arg1)
#pending # express the regexp above with the code you wish you had
end

When /^I save the event$/ do
visit '/admin/events'
click_link 'test_event'
fill_in 'event_title', :with => "My new title"
fill_in 'event_content', :with => "My new content"
#select('test_status', :from => 'event_status_id')
click_button("Save")
end

5 changes: 5 additions & 0 deletions spec/controllers/admin/events_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require 'spec_helper'

describe Admin::EventsController do

end
15 changes: 15 additions & 0 deletions spec/helpers/admin/events_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require 'spec_helper'

# Specs in this file have access to a helper object that includes
# the Admin::EventsHelper. For example:
#
# describe Admin::EventsHelper do
# describe "string concat" do
# it "concats two strings with spaces" do
# helper.concat_strings("this","that").should == "this that"
# end
# end
# end
describe Admin::EventsHelper do
pending "add some examples to (or delete) #{__FILE__}"
end

0 comments on commit 483e567

Please sign in to comment.