diff options
author | francis <francis> | 2007-09-10 18:58:42 +0000 |
---|---|---|
committer | francis <francis> | 2007-09-10 18:58:42 +0000 |
commit | 2f61ce926c4311ff95597c1c871081a1fb46a4d6 (patch) | |
tree | e59a0e989b31e51a6069c8426840ec4db95dc26b | |
parent | 022f7a0d72a7742875d9ba94ce33a4ec069d36dd (diff) |
Model for outgoing messages.
Save body of initial request as an outgoing message.
Try and validate and save the pair of models correctly.
-rw-r--r-- | app/controllers/file_request_controller.rb | 18 | ||||
-rw-r--r-- | app/models/info_request.rb | 3 | ||||
-rw-r--r-- | app/models/outgoing_message.rb | 23 | ||||
-rw-r--r-- | app/views/file_request/index.rhtml | 2 | ||||
-rw-r--r-- | db/migrate/009_create_outgoing_messages.rb | 20 | ||||
-rw-r--r-- | db/schema.rb | 12 | ||||
-rw-r--r-- | public/stylesheets/main.css | 5 | ||||
-rw-r--r-- | test/fixtures/outgoing_messages.yml | 11 | ||||
-rw-r--r-- | test/unit/outgoing_message_test.rb | 10 | ||||
-rw-r--r-- | todo.txt | 16 |
10 files changed, 106 insertions, 14 deletions
diff --git a/app/controllers/file_request_controller.rb b/app/controllers/file_request_controller.rb index f062f0da8..8424c83b0 100644 --- a/app/controllers/file_request_controller.rb +++ b/app/controllers/file_request_controller.rb @@ -4,26 +4,28 @@ # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: file_request_controller.rb,v 1.4 2007-09-10 01:16:35 francis Exp $ +# $Id: file_request_controller.rb,v 1.5 2007-09-10 18:58:43 francis Exp $ class FileRequestController < ApplicationController def index end def create -# raise params[:info_request][:public_body_id] -# params[:info_request][:public_body] = PublicBody.find(params[:info_request][:public_body_id]) -# params[:info_request].delete(:public_body_id) @info_request = InfoRequest.new(params[:info_request]) + @outgoing_message = OutgoingMessage.new(params[:outgoing_message].merge({ :status => 'ready', + :message_type => 'initial_request'})) - if not @info_request.save - render :action => 'index' - else + InfoRequest.transaction do + @info_request.save! + @outgoing_message.info_request_id = @info_request.id + @outgoing_message.save! # render create action end + rescue ActiveRecord::RecordInvalid => e + @outgoing_message.valid? # force cecking of errors even if info_request fails + render :action => 'index' end - end diff --git a/app/models/info_request.rb b/app/models/info_request.rb index 21f9e47cb..c354fb3af 100644 --- a/app/models/info_request.rb +++ b/app/models/info_request.rb @@ -4,11 +4,12 @@ # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: info_request.rb,v 1.3 2007-09-10 01:16:35 francis Exp $ +# $Id: info_request.rb,v 1.4 2007-09-10 18:58:43 francis Exp $ class InfoRequest < ActiveRecord::Base belongs_to :user belongs_to :public_body + has_many :outgoing_message # validates_presence_of :user # validates_numericality_of :user diff --git a/app/models/outgoing_message.rb b/app/models/outgoing_message.rb new file mode 100644 index 000000000..186bb2147 --- /dev/null +++ b/app/models/outgoing_message.rb @@ -0,0 +1,23 @@ +# models/outgoing_message.rb: +# A message, associated with a request, from the user of the site to somebody +# else. e.g. An initial request for information, or a complaint. +# +# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. +# Email: francis@mysociety.org; WWW: http://www.mysociety.org/ +# +# $Id: outgoing_message.rb,v 1.1 2007-09-10 18:58:43 francis Exp $ + +class OutgoingMessage < ActiveRecord::Base + belongs_to :info_request + validates_presence_of :info_request_id + + validates_presence_of :body + validates_inclusion_of :status, :in => ['ready', 'sent', 'failed'] + + belongs_to :public_body + validates_inclusion_of :message_type, :in => ['initial_request'] #, 'complaint'] + + belongs_to :recipient, :polymorphic => true + +end + diff --git a/app/views/file_request/index.rhtml b/app/views/file_request/index.rhtml index 8e4955463..84d0198bc 100644 --- a/app/views/file_request/index.rhtml +++ b/app/views/file_request/index.rhtml @@ -1,6 +1,6 @@ <% @title = "New FOI request" %> -<%= foi_error_messages_for :info_request %> +<%= foi_error_messages_for :info_request, :outgoing_message %> <% form_for(:info_request, @info_request, :url => { :action => :create }, :html => { :id => 'writeForm' } ) do |f| %> diff --git a/db/migrate/009_create_outgoing_messages.rb b/db/migrate/009_create_outgoing_messages.rb new file mode 100644 index 000000000..62bf25392 --- /dev/null +++ b/db/migrate/009_create_outgoing_messages.rb @@ -0,0 +1,20 @@ +class CreateOutgoingMessages < ActiveRecord::Migration + def self.up + create_table :outgoing_messages do |t| + t.column :info_request_id, :integer + + t.column :body, :text + t.column :status, :string + + t.column :public_body_id, :integer + t.column :message_type, :string + + t.column :created_at, :datetime + t.column :updated_at, :datetime + end + end + + def self.down + drop_table :outgoing_messages + end +end diff --git a/db/schema.rb b/db/schema.rb index 08043cd76..a0e867be9 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -2,7 +2,7 @@ # migrations feature of ActiveRecord to incrementally modify your database, and # then regenerate this schema definition. -ActiveRecord::Schema.define(:version => 8) do +ActiveRecord::Schema.define(:version => 9) do create_table "info_requests", :force => true do |t| t.column "title", :text @@ -10,6 +10,16 @@ ActiveRecord::Schema.define(:version => 8) do t.column "public_body_id", :integer end + create_table "outgoing_messages", :force => true do |t| + t.column "info_request_id", :integer + t.column "body", :text + t.column "status", :string + t.column "public_body_id", :integer + t.column "message_type", :string + t.column "created_at", :datetime + t.column "updated_at", :datetime + end + create_table "public_bodies", :force => true do |t| t.column "name", :text t.column "short_name", :text diff --git a/public/stylesheets/main.css b/public/stylesheets/main.css index f5b8b76b8..39b04d6cf 100644 --- a/public/stylesheets/main.css +++ b/public/stylesheets/main.css @@ -65,7 +65,10 @@ label { /* Form error highlighting */ -.fieldWithErrors input, .fieldWithErrors input[type=text], .fieldWithErrors select, .fieldWithErrors input[type=radio]{ +.fieldWithErrors input, .fieldWithErrors input[type=text], +.fieldWithErrors select, .fieldWithErrors input[type=radio], +.fieldWithErrors textarea +{ border: solid 1px #cc0000; background-color: #ffcccc; } diff --git a/test/fixtures/outgoing_messages.yml b/test/fixtures/outgoing_messages.yml new file mode 100644 index 000000000..e6b5d7e2a --- /dev/null +++ b/test/fixtures/outgoing_messages.yml @@ -0,0 +1,11 @@ +# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html +one: + id: 1 + body: MyText + created_at: 2007-09-10 09:55:11 + updated_at: 2007-09-10 09:55:11 +two: + id: 2 + body: MyText + created_at: 2007-09-10 09:55:11 + updated_at: 2007-09-10 09:55:11 diff --git a/test/unit/outgoing_message_test.rb b/test/unit/outgoing_message_test.rb new file mode 100644 index 000000000..12b55e5d0 --- /dev/null +++ b/test/unit/outgoing_message_test.rb @@ -0,0 +1,10 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class OutgoingMessageTest < Test::Unit::TestCase + fixtures :outgoing_messages + + # Replace this with your real tests. + def test_truth + assert true + end +end @@ -1,12 +1,24 @@ +Store the letter +Give a better login dialog +public_body_id not set in outgoing_message (maybe not needed) +Check validation for saving info request / outgoing message pair works with transactions fine +Tidy up error message text (like "body must be filled in" on info request form) +Add created_at / updated_at to every model that might need it +Make sure that constraints / foreign keys in model are in same order as data in schema +Check have validates_presence_of for every belongs_to +Check using :string rather than :text for definitely limited fields like "status" Redirect the front page to the new FOI request page Make it say "dear" as default letter +Write some tests (try it their way, at every level) + Tidying ======= -Rename file_request to new ? -Add foreign keys to database +Rename "file_request" controller to "new" ? +Add SQL foreign keys to database schema +Call "delete from sessions where now() - updated_at > 3600" (one hour) or whatever |