diff options
-rw-r--r-- | app/controllers/application.rb | 4 | ||||
-rw-r--r-- | app/controllers/request_controller.rb | 7 | ||||
-rw-r--r-- | spec/controllers/request_controller_spec.rb | 80 | ||||
-rw-r--r-- | spec/fixtures/public_bodies.yml | 19 | ||||
-rw-r--r-- | spec/fixtures/users.yml | 10 |
5 files changed, 109 insertions, 11 deletions
diff --git a/app/controllers/application.rb b/app/controllers/application.rb index 2affefa96..1410aff29 100644 --- a/app/controllers/application.rb +++ b/app/controllers/application.rb @@ -6,7 +6,7 @@ # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: application.rb,v 1.17 2007-10-30 18:52:27 francis Exp $ +# $Id: application.rb,v 1.18 2007-10-31 12:14:20 francis Exp $ class ApplicationController < ActionController::Base @@ -89,7 +89,7 @@ class ApplicationController < ActionController::Base # Check the user is logged in def authenticated? unless session[:user] - session[:intended_uri] = @request.request_uri + session[:intended_uri] = request.request_uri session[:intended_params] = params redirect_to signin_url return false diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb index a935983ac..2756b9452 100644 --- a/app/controllers/request_controller.rb +++ b/app/controllers/request_controller.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: request_controller.rb,v 1.9 2007-10-30 17:31:31 francis Exp $ +# $Id: request_controller.rb,v 1.10 2007-10-31 12:14:20 francis Exp $ class RequestController < ApplicationController @@ -47,9 +47,12 @@ class RequestController < ApplicationController @outgoing_message.send_message flash[:notice] = "Your Freedom of Information request has been created and sent on its way." redirect_to show_request_url(:id => @info_request) + else + # do nothing - as "authenticated?" has done the redirect to signin page for us end - # Save both models + # Save both models # XXX still fiddling with error reporting here, see Louise's + # email about some better error reporting plugin. # valid = @info_request.valid? # valid &&= @outgoing_message.valid? # XXX maybe there is a nicer way of preventing lazy boolean evaluation than this # if valid diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index 1195db34f..41ff2b6b6 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -17,10 +17,84 @@ describe RequestController, "when listing all requests" do # XXX probably should load more than one page of requests into db here :) get :list - assigns[:info_requests] == [ - info_requests(:fancy_dog_request), - info_requests(:naughty_chicken_request) + assigns[:info_requests].should == [ + info_requests(:naughty_chicken_request), # reverse-chronological order + info_requests(:fancy_dog_request) ] end +end + +describe RequestController, "when showing one request" do + fixtures :info_requests + + it "should be successful" do + get :show, :id => 101 + response.should be_success + end + + it "should render with 'show' template" do + get :show, :id => 101 + response.should render_template('show') + end + + it "should assign the request" do + get :show, :id => 101 + assigns[:info_request].should == info_requests(:fancy_dog_request) + end +end + +# XXX do this for invalid ids +# it "should render 404 file" do +# response.should render_template("#{RAILS_ROOT}/public/404.html") +# response.headers["Status"].should == "404 Not Found" +# end + +describe RequestController, "when creating a new request" do + fixtures :info_requests, :public_bodies, :users + + it "should render with 'new' template" do + get :new + response.should render_template('new') + end + + it "should accept a public body parameter posted from the front page" do + post :new, :info_request => { :public_body_id => public_bodies(:geraldine_public_body).id } + assigns[:info_request].public_body.should == public_bodies(:geraldine_public_body) + response.should render_template('new') + end + + it "should give an error and render 'new' template when a summary isn't given" do + post :create, :info_request => { :public_body_id => public_bodies(:geraldine_public_body).id + }, + :outgoing_message => { :body => "This is a silly letter. It is too short to be interesting." } + response.should render_template('new') + end + + it "should redirect to sign in page when input is good and nobody is logged in" do + post :create, :info_request => { :public_body_id => public_bodies(:geraldine_public_body).id, + :title => "Why is your quango called Geraldine?"}, + :outgoing_message => { :body => "This is a silly letter. It is too short to be interesting." } + response.should redirect_to(:controller => 'user', :action => 'signin') + end + it "should create the request and outgoing message and redirec to request page when input is good and somebody is logged in" do + session[:user] = users(:bob_smith_user) + post :create, :info_request => { :public_body_id => public_bodies(:geraldine_public_body).id, + :title => "Why is your quango called Geraldine?"}, + :outgoing_message => { :body => "This is a silly letter. It is too short to be interesting." } + ir_array = InfoRequest.find(:all, :conditions => ["title = ?", "Why is your quango called Geraldine?"]) + ir_array.size.should == 1 + ir = ir_array[0] + ir.outgoing_messages.size.should == 1 + om = ir.outgoing_messages[0] + om.body.should == "This is a silly letter. It is too short to be interesting." + response.should redirect_to(:controller => 'request', :action => 'show', :id => ir.id) + end end + + + + + + + diff --git a/spec/fixtures/public_bodies.yml b/spec/fixtures/public_bodies.yml index fe0b8b4f4..c8d95afc6 100644 --- a/spec/fixtures/public_bodies.yml +++ b/spec/fixtures/public_bodies.yml @@ -1,12 +1,23 @@ -new_public_body: +geraldine_public_body: name: The Geraldine Quango updated_at: 2007-10-24 10:51:01.161639 last_edit_comment: Mark named this stupid quango. - complaint_email: "" - request_email: francis@flourish.org + complaint_email: geraldine-complaints@localhost + request_email: geraldine-requests@localhost id: "2" version: "1" - last_edit_editor: "*unknown*" + last_edit_editor: "mark" short_name: TGQ created_at: 2007-10-24 10:51:01.161639 +humpadink_public_body: + name: "Department for Humpadinking" + updated_at: 2007-10-25 10:51:01.161639 + last_edit_comment: Not sure what this new department does. + complaint_email: humpadink-complaints@localhost + request_email: humpadink-requests@localhost + id: "3" + version: "1" + last_edit_editor: "francis" + short_name: DfH + created_at: 2007-10-25 10:51:01.161639 diff --git a/spec/fixtures/users.yml b/spec/fixtures/users.yml new file mode 100644 index 000000000..c28c67de2 --- /dev/null +++ b/spec/fixtures/users.yml @@ -0,0 +1,10 @@ +bob_smith_user: + id: "1" + name: Bob Smith + email: bob@localhost + salt: "-6116981980.392287733335677" + hashed_password: 6b7cd45a5f35fd83febc0452a799530398bfb6e8 # jonespassword + updated_at: 2007-10-31 10:39:15.491593 + created_at: 2007-10-31 10:39:15.491593 + + |