aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/controllers/admin_public_body_controller.rb51
-rw-r--r--app/helpers/admin_public_body_helper.rb2
-rw-r--r--app/models/public_body.rb4
-rw-r--r--app/views/admin_public_body/_form.rhtml15
-rw-r--r--app/views/admin_public_body/edit.rhtml9
-rw-r--r--app/views/admin_public_body/list.rhtml27
-rw-r--r--app/views/admin_public_body/new.rhtml8
-rw-r--r--app/views/admin_public_body/show.rhtml8
-rw-r--r--app/views/file_request/index.rhtml13
-rw-r--r--app/views/layouts/admin_public_body.rhtml17
-rw-r--r--config/routes.rb3
-rw-r--r--db/migrate/005_create_public_bodies.rb16
-rw-r--r--db/schema.rb9
-rw-r--r--public/stylesheets/scaffold.css74
-rw-r--r--test/fixtures/public_bodies.yml5
-rw-r--r--test/functional/admin_public_body_controller_test.rb92
-rw-r--r--test/unit/public_body_test.rb10
17 files changed, 353 insertions, 10 deletions
diff --git a/app/controllers/admin_public_body_controller.rb b/app/controllers/admin_public_body_controller.rb
new file mode 100644
index 000000000..a982857c0
--- /dev/null
+++ b/app/controllers/admin_public_body_controller.rb
@@ -0,0 +1,51 @@
+class AdminPublicBodyController < ApplicationController
+ def index
+ list
+ render :action => 'list'
+ end
+
+ # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
+ verify :method => :post, :only => [ :destroy, :create, :update ],
+ :redirect_to => { :action => :list }
+
+ def list
+ @public_body_pages, @public_bodies = paginate :public_bodies, :per_page => 10
+ end
+
+ def show
+ @public_body = PublicBody.find(params[:id])
+ end
+
+ def new
+ @public_body = PublicBody.new
+ end
+
+ def create
+ @public_body = PublicBody.new(params[:public_body])
+ if @public_body.save
+ flash[:notice] = 'PublicBody was successfully created.'
+ redirect_to :action => 'list'
+ else
+ render :action => 'new'
+ end
+ end
+
+ def edit
+ @public_body = PublicBody.find(params[:id])
+ end
+
+ def update
+ @public_body = PublicBody.find(params[:id])
+ if @public_body.update_attributes(params[:public_body])
+ flash[:notice] = 'PublicBody was successfully updated.'
+ redirect_to :action => 'show', :id => @public_body
+ else
+ render :action => 'edit'
+ end
+ end
+
+ def destroy
+ PublicBody.find(params[:id]).destroy
+ redirect_to :action => 'list'
+ end
+end
diff --git a/app/helpers/admin_public_body_helper.rb b/app/helpers/admin_public_body_helper.rb
new file mode 100644
index 000000000..e00fe3e0f
--- /dev/null
+++ b/app/helpers/admin_public_body_helper.rb
@@ -0,0 +1,2 @@
+module AdminPublicBodyHelper
+end
diff --git a/app/models/public_body.rb b/app/models/public_body.rb
new file mode 100644
index 000000000..332468fee
--- /dev/null
+++ b/app/models/public_body.rb
@@ -0,0 +1,4 @@
+class PublicBody < ActiveRecord::Base
+ validates_presence_of :request_email
+
+end
diff --git a/app/views/admin_public_body/_form.rhtml b/app/views/admin_public_body/_form.rhtml
new file mode 100644
index 000000000..e088ef5c2
--- /dev/null
+++ b/app/views/admin_public_body/_form.rhtml
@@ -0,0 +1,15 @@
+<%= error_messages_for 'public_body' %>
+
+<!--[form:public_body]-->
+<p><label for="public_body_name">Name</label><br/>
+<%= text_field 'public_body', 'name', :size => 60 %></p>
+<p><label for="public_body_short_name">Short name</label><br/>
+<%= text_field 'public_body', 'short_name', :size => 60 %></p>
+
+<p><label for="public_body_request_email">Request email</label><br/>
+<%= text_field 'public_body', 'request_email', :size => 40 %></p>
+
+<p><label for="public_body_complaint_email">Complaint email</label><br/>
+<%= text_field 'public_body', 'complaint_email', :size => 40 %></p>
+<!--[eoform:public_body]-->
+
diff --git a/app/views/admin_public_body/edit.rhtml b/app/views/admin_public_body/edit.rhtml
new file mode 100644
index 000000000..f5c469757
--- /dev/null
+++ b/app/views/admin_public_body/edit.rhtml
@@ -0,0 +1,9 @@
+<h1>Editing public body</h1>
+
+<% form_tag :action => 'update', :id => @public_body do %>
+ <%= render :partial => 'form' %>
+ <%= submit_tag 'Edit' %>
+<% end %>
+
+<%= link_to 'Show', :action => 'show', :id => @public_body %> |
+<%= link_to 'Back', :action => 'list' %>
diff --git a/app/views/admin_public_body/list.rhtml b/app/views/admin_public_body/list.rhtml
new file mode 100644
index 000000000..ec1c5c431
--- /dev/null
+++ b/app/views/admin_public_body/list.rhtml
@@ -0,0 +1,27 @@
+<h1>Listing public_bodies</h1>
+
+<table>
+ <tr>
+ <% for column in PublicBody.content_columns %>
+ <th><%= column.human_name %></th>
+ <% end %>
+ </tr>
+
+<% for public_body in @public_bodies %>
+ <tr>
+ <% for column in PublicBody.content_columns %>
+ <td><%=h public_body.send(column.name) %></td>
+ <% end %>
+ <td><%= link_to 'Show', :action => 'show', :id => public_body %></td>
+ <td><%= link_to 'Edit', :action => 'edit', :id => public_body %></td>
+ <td><%= link_to 'Destroy', { :action => 'destroy', :id => public_body }, :confirm => 'Are you sure?', :method => :post %></td>
+ </tr>
+<% end %>
+</table>
+
+<%= link_to 'Previous page', { :page => @public_body_pages.current.previous } if @public_body_pages.current.previous %>
+<%= link_to 'Next page', { :page => @public_body_pages.current.next } if @public_body_pages.current.next %>
+
+<br />
+
+<%= link_to 'New public_body', :action => 'new' %>
diff --git a/app/views/admin_public_body/new.rhtml b/app/views/admin_public_body/new.rhtml
new file mode 100644
index 000000000..ee6ce8d81
--- /dev/null
+++ b/app/views/admin_public_body/new.rhtml
@@ -0,0 +1,8 @@
+<h1>New public body</h1>
+
+<% form_tag :action => 'create' do %>
+ <%= render :partial => 'form' %>
+ <%= submit_tag "Create" %>
+<% end %>
+
+<%= link_to 'Back', :action => 'list' %>
diff --git a/app/views/admin_public_body/show.rhtml b/app/views/admin_public_body/show.rhtml
new file mode 100644
index 000000000..4e1aa2ad3
--- /dev/null
+++ b/app/views/admin_public_body/show.rhtml
@@ -0,0 +1,8 @@
+<% for column in PublicBody.content_columns %>
+<p>
+ <b><%= column.human_name %>:</b> <%=h @public_body.send(column.name) %>
+</p>
+<% end %>
+
+<%= link_to 'Edit', :action => 'edit', :id => @public_body %> |
+<%= link_to 'Back', :action => 'list' %>
diff --git a/app/views/file_request/index.rhtml b/app/views/file_request/index.rhtml
index c1f686bd7..dec0103fc 100644
--- a/app/views/file_request/index.rhtml
+++ b/app/views/file_request/index.rhtml
@@ -35,14 +35,11 @@ displayed publically on this website.</p>
<!-- (a one line summary of the information you are requesting, e.g. 'Crime statistics by ward level for Wales') -->
</p>
-<%
-=begin %>
- <p>
- <%= f.text_area :body %>
- </p>
-<%
-=end
-%>
+ <% fields_for :outgoing_message do |o| %>
+ <p>
+ <%= o.text_area :body %>
+ </p>
+ <% end %>
<p>
<%= submit_tag "Create" %>
diff --git a/app/views/layouts/admin_public_body.rhtml b/app/views/layouts/admin_public_body.rhtml
new file mode 100644
index 000000000..18d3caa61
--- /dev/null
+++ b/app/views/layouts/admin_public_body.rhtml
@@ -0,0 +1,17 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+ <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
+ <title>AdminPublicBody: <%= controller.action_name %></title>
+ <%= stylesheet_link_tag 'scaffold' %>
+</head>
+<body>
+
+<p style="color: green"><%= flash[:notice] %></p>
+
+<%= yield %>
+
+</body>
+</html>
diff --git a/config/routes.rb b/config/routes.rb
index d0f5cc971..63dfd665e 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -4,7 +4,7 @@
# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
# Email: francis@mysociety.org; WWW: http://www.mysociety.org/
#
-# $Id: routes.rb,v 1.4 2007-08-04 11:10:26 francis Exp $
+# $Id: routes.rb,v 1.5 2007-08-29 12:12:45 francis Exp $
ActionController::Routing::Routes.draw do |map|
# The priority is based upon order of creation: first created -> highest priority.
@@ -14,6 +14,7 @@ ActionController::Routing::Routes.draw do |map|
# Keep in mind you can assign values other than :controller and :action
map.connect "/new/:action", :controller => 'file_request', :action => 'index'
map.connect "/:action/:id", :controller => 'frontpage'
+ map.connect '/admin/body/:action/:id', :controller => 'admin_public_body'
# Sample of named route:
# map.purchase 'products/:id/purchase', :controller => 'catalog', :action => 'purchase'
diff --git a/db/migrate/005_create_public_bodies.rb b/db/migrate/005_create_public_bodies.rb
new file mode 100644
index 000000000..d37def301
--- /dev/null
+++ b/db/migrate/005_create_public_bodies.rb
@@ -0,0 +1,16 @@
+class CreatePublicBodies < ActiveRecord::Migration
+ def self.up
+ create_table :public_bodies do |t|
+ t.column :name, :text
+ t.column :short_name, :text
+ # address for making initial FOI requests
+ t.column :request_email, :text
+ # address for complaining about an FOI request
+ t.column :complaint_email, :text
+ end
+ end
+
+ def self.down
+ drop_table :public_bodies
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index de6ac6216..eaabdc961 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -2,13 +2,20 @@
# migrations feature of ActiveRecord to incrementally modify your database, and
# then regenerate this schema definition.
-ActiveRecord::Schema.define(:version => 4) do
+ActiveRecord::Schema.define(:version => 5) do
create_table "info_requests", :force => true do |t|
t.column "title", :text
t.column "user_id", :integer
end
+ create_table "public_bodies", :force => true do |t|
+ t.column "name", :text
+ t.column "short_name", :text
+ t.column "request_email", :text
+ t.column "complaint_email", :text
+ end
+
create_table "sessions", :force => true do |t|
t.column "session_id", :string
t.column "data", :text
diff --git a/public/stylesheets/scaffold.css b/public/stylesheets/scaffold.css
new file mode 100644
index 000000000..8f239a359
--- /dev/null
+++ b/public/stylesheets/scaffold.css
@@ -0,0 +1,74 @@
+body { background-color: #fff; color: #333; }
+
+body, p, ol, ul, td {
+ font-family: verdana, arial, helvetica, sans-serif;
+ font-size: 13px;
+ line-height: 18px;
+}
+
+pre {
+ background-color: #eee;
+ padding: 10px;
+ font-size: 11px;
+}
+
+a { color: #000; }
+a:visited { color: #666; }
+a:hover { color: #fff; background-color:#000; }
+
+.fieldWithErrors {
+ padding: 2px;
+ background-color: red;
+ display: table;
+}
+
+#errorExplanation {
+ width: 400px;
+ border: 2px solid red;
+ padding: 7px;
+ padding-bottom: 12px;
+ margin-bottom: 20px;
+ background-color: #f0f0f0;
+}
+
+#errorExplanation h2 {
+ text-align: left;
+ font-weight: bold;
+ padding: 5px 5px 5px 15px;
+ font-size: 12px;
+ margin: -7px;
+ background-color: #c00;
+ color: #fff;
+}
+
+#errorExplanation p {
+ color: #333;
+ margin-bottom: 0;
+ padding: 5px;
+}
+
+#errorExplanation ul li {
+ font-size: 12px;
+ list-style: square;
+}
+
+div.uploadStatus {
+ margin: 5px;
+}
+
+div.progressBar {
+ margin: 5px;
+}
+
+div.progressBar div.border {
+ background-color: #fff;
+ border: 1px solid grey;
+ width: 100%;
+}
+
+div.progressBar div.background {
+ background-color: #333;
+ height: 18px;
+ width: 0%;
+}
+
diff --git a/test/fixtures/public_bodies.yml b/test/fixtures/public_bodies.yml
new file mode 100644
index 000000000..b49c4eb4e
--- /dev/null
+++ b/test/fixtures/public_bodies.yml
@@ -0,0 +1,5 @@
+# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
+one:
+ id: 1
+two:
+ id: 2
diff --git a/test/functional/admin_public_body_controller_test.rb b/test/functional/admin_public_body_controller_test.rb
new file mode 100644
index 000000000..80628aff9
--- /dev/null
+++ b/test/functional/admin_public_body_controller_test.rb
@@ -0,0 +1,92 @@
+require File.dirname(__FILE__) + '/../test_helper'
+require 'admin_public_body_controller'
+
+# Re-raise errors caught by the controller.
+class AdminPublicBodyController; def rescue_action(e) raise e end; end
+
+class AdminPublicBodyControllerTest < Test::Unit::TestCase
+ fixtures :public_bodies
+
+ def setup
+ @controller = AdminPublicBodyController.new
+ @request = ActionController::TestRequest.new
+ @response = ActionController::TestResponse.new
+
+ @first_id = public_bodies(:first).id
+ end
+
+ def test_index
+ get :index
+ assert_response :success
+ assert_template 'list'
+ end
+
+ def test_list
+ get :list
+
+ assert_response :success
+ assert_template 'list'
+
+ assert_not_nil assigns(:public_bodies)
+ end
+
+ def test_show
+ get :show, :id => @first_id
+
+ assert_response :success
+ assert_template 'show'
+
+ assert_not_nil assigns(:public_body)
+ assert assigns(:public_body).valid?
+ end
+
+ def test_new
+ get :new
+
+ assert_response :success
+ assert_template 'new'
+
+ assert_not_nil assigns(:public_body)
+ end
+
+ def test_create
+ num_public_bodies = PublicBody.count
+
+ post :create, :public_body => {}
+
+ assert_response :redirect
+ assert_redirected_to :action => 'list'
+
+ assert_equal num_public_bodies + 1, PublicBody.count
+ end
+
+ def test_edit
+ get :edit, :id => @first_id
+
+ assert_response :success
+ assert_template 'edit'
+
+ assert_not_nil assigns(:public_body)
+ assert assigns(:public_body).valid?
+ end
+
+ def test_update
+ post :update, :id => @first_id
+ assert_response :redirect
+ assert_redirected_to :action => 'show', :id => @first_id
+ end
+
+ def test_destroy
+ assert_nothing_raised {
+ PublicBody.find(@first_id)
+ }
+
+ post :destroy, :id => @first_id
+ assert_response :redirect
+ assert_redirected_to :action => 'list'
+
+ assert_raise(ActiveRecord::RecordNotFound) {
+ PublicBody.find(@first_id)
+ }
+ end
+end
diff --git a/test/unit/public_body_test.rb b/test/unit/public_body_test.rb
new file mode 100644
index 000000000..84dda398c
--- /dev/null
+++ b/test/unit/public_body_test.rb
@@ -0,0 +1,10 @@
+require File.dirname(__FILE__) + '/../test_helper'
+
+class PublicBodyTest < Test::Unit::TestCase
+ fixtures :public_bodies
+
+ # Replace this with your real tests.
+ def test_truth
+ assert true
+ end
+end