aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/controllers/application.rb4
-rw-r--r--app/controllers/body_controller.rb5
-rw-r--r--app/controllers/user_controller.rb4
-rw-r--r--spec/controllers/body_controller_spec.rb23
-rw-r--r--spec/controllers/user_controller_spec.rb27
-rw-r--r--spec/fixtures/users.yml9
6 files changed, 66 insertions, 6 deletions
diff --git a/app/controllers/application.rb b/app/controllers/application.rb
index 1410aff29..1fde074a9 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.18 2007-10-31 12:14:20 francis Exp $
+# $Id: application.rb,v 1.19 2007-10-31 12:39:58 francis Exp $
class ApplicationController < ActionController::Base
@@ -142,7 +142,7 @@ class ApplicationController < ActionController::Base
# Simplified links to our objects
# XXX See controllers/user_controller.rb controllers/body_controller.rb for inverse
# XXX consolidate somehow with stuff in helpers/application_helper.rb
- # use :helper_method => :your_method_name
+ helper_method :simplify_url_part
def simplify_url_part(text)
text.downcase!
text.gsub!(/ /, "-")
diff --git a/app/controllers/body_controller.rb b/app/controllers/body_controller.rb
index 0a267118a..ba90f317f 100644
--- a/app/controllers/body_controller.rb
+++ b/app/controllers/body_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: body_controller.rb,v 1.2 2007-10-30 18:52:27 francis Exp $
+# $Id: body_controller.rb,v 1.3 2007-10-31 12:39:58 francis Exp $
class BodyController < ApplicationController
# XXX tidy this up with better error messages, and a more standard infrastructure for the redirect to canonical URL
@@ -21,6 +21,9 @@ class BodyController < ApplicationController
if @public_bodies.size > 1
raise "Two bodies with the same historical simplified short name: " . params[:simple_short_name]
end
+ if @public_bodies.size == 0
+ raise "None found" # XXX proper 404
+ end
redirect_to show_public_body_url(:simple_short_name => simplify_url_part(@public_bodies[0].short_name))
end
@public_body = @public_bodies[0]
diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb
index a0ac68443..959630166 100644
--- a/app/controllers/user_controller.rb
+++ b/app/controllers/user_controller.rb
@@ -4,10 +4,10 @@
# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
# Email: francis@mysociety.org; WWW: http://www.mysociety.org/
#
-# $Id: user_controller.rb,v 1.5 2007-10-30 17:31:31 francis Exp $
+# $Id: user_controller.rb,v 1.6 2007-10-31 12:39:58 francis Exp $
class UserController < ApplicationController
- # XXX See helpers/application_helper.rb simplify_url_part fo reverse of expression in SQL below
+ # XXX See controllers/application.rb simplify_url_part for reverse of expression in SQL below
def show
@display_users = User.find(:all, :conditions => [ "regexp_replace(replace(lower(name), ' ', '-'), '[^a-z0-9_-]', '', 'g') = ?", params[:simple_name] ], :order => "created_at desc")
end
diff --git a/spec/controllers/body_controller_spec.rb b/spec/controllers/body_controller_spec.rb
new file mode 100644
index 000000000..bf73a6e19
--- /dev/null
+++ b/spec/controllers/body_controller_spec.rb
@@ -0,0 +1,23 @@
+require File.dirname(__FILE__) + '/../spec_helper'
+
+describe BodyController, "when showing a body" do
+ fixtures :public_bodies
+
+ it "should be successful" do
+ get :show, :simple_short_name => "dfh"
+ response.should be_success
+ end
+
+ it "should render with 'show' template" do
+ get :show, :simple_short_name => "dfh"
+ response.should render_template('show')
+ end
+
+ it "should assign the body" do
+ get :show, :simple_short_name => "dfh"
+ assigns[:public_bodies].should == [ public_bodies(:humpadink_public_body) ]
+ end
+
+ # XXX test for 404s when don't give valid name
+ # XXX test the fancy history searching stuff
+end
diff --git a/spec/controllers/user_controller_spec.rb b/spec/controllers/user_controller_spec.rb
new file mode 100644
index 000000000..8354e774c
--- /dev/null
+++ b/spec/controllers/user_controller_spec.rb
@@ -0,0 +1,27 @@
+require File.dirname(__FILE__) + '/../spec_helper'
+
+describe UserController, "when showing a user" do
+ fixtures :users
+
+ it "should be successful" do
+ get :show, :simple_name => "bob_smith"
+ response.should be_success
+ end
+
+ it "should render with 'show' template" do
+ get :show, :simple_name => "bob_smith"
+ response.should render_template('show')
+ end
+
+ it "should assign the user" do
+ get :show, :simple_name => "bob-smith"
+ assigns[:display_users].should == [ users(:bob_smith_user) ]
+ end
+
+ it "should assign the user for a more complex name" do
+ get :show, :simple_name => "silly-emnameem"
+ assigns[:display_users].should == [ users(:silly_name_user) ]
+ end
+
+ # XXX test for 404s when don't give valid name
+end
diff --git a/spec/fixtures/users.yml b/spec/fixtures/users.yml
index c28c67de2..842c71b68 100644
--- a/spec/fixtures/users.yml
+++ b/spec/fixtures/users.yml
@@ -6,5 +6,12 @@ bob_smith_user:
hashed_password: 6b7cd45a5f35fd83febc0452a799530398bfb6e8 # jonespassword
updated_at: 2007-10-31 10:39:15.491593
created_at: 2007-10-31 10:39:15.491593
-
+silly_name_user:
+ id: "2"
+ name: "Silly <em>Name</em>"
+ email: silly@localhost
+ salt: "-6116981980.392287733335677"
+ hashed_password: 6b7cd45a5f35fd83febc0452a799530398bfb6e8 # jonespassword
+ updated_at: 2007-11-01 10:39:15.491593
+ created_at: 2007-11-01 10:39:15.491593