aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/controllers/public_body_controller.rb6
-rw-r--r--app/controllers/user_controller.rb6
-rw-r--r--app/models/info_request.rb4
-rw-r--r--app/models/public_body.rb4
-rw-r--r--app/models/user.rb4
-rw-r--r--spec/models/info_request_spec.rb18
6 files changed, 29 insertions, 13 deletions
diff --git a/app/controllers/public_body_controller.rb b/app/controllers/public_body_controller.rb
index 19bb22f67..21ef45677 100644
--- a/app/controllers/public_body_controller.rb
+++ b/app/controllers/public_body_controller.rb
@@ -4,13 +4,13 @@
# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
# Email: francis@mysociety.org; WWW: http://www.mysociety.org/
#
-# $Id: public_body_controller.rb,v 1.5 2009-09-02 14:10:37 francis Exp $
+# $Id: public_body_controller.rb,v 1.6 2009-09-07 17:31:36 francis Exp $
class PublicBodyController < ApplicationController
# XXX tidy this up with better error messages, and a more standard infrastructure for the redirect to canonical URL
def show
- if MySociety::Format.simplify_url_part(params[:url_name]) != params[:url_name]
- redirect_to :url_name => MySociety::Format.simplify_url_part(params[:url_name]), :status => :moved_permanently
+ if MySociety::Format.simplify_url_part(params[:url_name], 'body') != params[:url_name]
+ redirect_to :url_name => MySociety::Format.simplify_url_part(params[:url_name], 'body'), :status => :moved_permanently
return
end
diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb
index c3b2efc03..4b4846ff1 100644
--- a/app/controllers/user_controller.rb
+++ b/app/controllers/user_controller.rb
@@ -4,13 +4,13 @@
# 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.69 2009-09-02 14:10:38 francis Exp $
+# $Id: user_controller.rb,v 1.70 2009-09-07 17:31:38 francis Exp $
class UserController < ApplicationController
# Show page about a user
def show
- if MySociety::Format.simplify_url_part(params[:url_name], 32) != params[:url_name]
- redirect_to :url_name => MySociety::Format.simplify_url_part(params[:url_name], 32), :status => :moved_permanently
+ if MySociety::Format.simplify_url_part(params[:url_name], 'user', 32) != params[:url_name]
+ redirect_to :url_name => MySociety::Format.simplify_url_part(params[:url_name], 'user', 32), :status => :moved_permanently
return
end
diff --git a/app/models/info_request.rb b/app/models/info_request.rb
index da5270c40..2cf3a08b4 100644
--- a/app/models/info_request.rb
+++ b/app/models/info_request.rb
@@ -24,7 +24,7 @@
# 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.202 2009-09-07 16:35:06 francis Exp $
+# $Id: info_request.rb,v 1.203 2009-09-07 17:31:38 francis Exp $
require 'digest/sha1'
require File.join(File.dirname(__FILE__),'../../vendor/plugins/acts_as_xapian/lib/acts_as_xapian')
@@ -154,7 +154,7 @@ public
self.update_url_title
end
def update_url_title
- url_title = MySociety::Format.simplify_url_part(self.title, 32)
+ url_title = MySociety::Format.simplify_url_part(self.title, 'request', 32)
# For request with same title as others, add on arbitary numeric identifier
unique_url_title = url_title
suffix_num = 2 # as there's already one without numeric suffix
diff --git a/app/models/public_body.rb b/app/models/public_body.rb
index 9362ecf20..8eb1b15b0 100644
--- a/app/models/public_body.rb
+++ b/app/models/public_body.rb
@@ -26,7 +26,7 @@
# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
# Email: francis@mysociety.org; WWW: http://www.mysociety.org/
#
-# $Id: public_body.rb,v 1.149 2009-08-26 00:45:38 francis Exp $
+# $Id: public_body.rb,v 1.150 2009-09-07 17:31:38 francis Exp $
require 'csv'
require 'set'
@@ -238,7 +238,7 @@ class PublicBody < ActiveRecord::Base
self.update_url_name
end
def update_url_name
- url_name = MySociety::Format.simplify_url_part(self.short_or_long_name)
+ url_name = MySociety::Format.simplify_url_part(self.short_or_long_name, 'body')
write_attribute(:url_name, url_name)
end
# Return the short name if present, or else long name
diff --git a/app/models/user.rb b/app/models/user.rb
index f18a4e7ab..abf418ff4 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -23,7 +23,7 @@
# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
# Email: francis@mysociety.org; WWW: http://www.mysociety.org/
#
-# $Id: user.rb,v 1.100 2009-08-27 15:44:23 francis Exp $
+# $Id: user.rb,v 1.101 2009-09-07 17:31:38 francis Exp $
require 'digest/sha1'
@@ -153,7 +153,7 @@ class User < ActiveRecord::Base
self.update_url_name
end
def update_url_name
- url_name = MySociety::Format.simplify_url_part(self.name, 32)
+ url_name = MySociety::Format.simplify_url_part(self.name, 'user', 32)
# For user with same name as others, add on arbitary numeric identifier
unique_url_name = url_name
suffix_num = 2 # as there's already one without numeric suffix
diff --git a/spec/models/info_request_spec.rb b/spec/models/info_request_spec.rb
index 6d60f4c25..b5f63e52a 100644
--- a/spec/models/info_request_spec.rb
+++ b/spec/models/info_request_spec.rb
@@ -1,7 +1,23 @@
require File.dirname(__FILE__) + '/../spec_helper'
describe InfoRequest do
-
+
+ describe "making up the URL name" do
+ before do
+ @info_request = InfoRequest.new
+ end
+
+ it 'should remove spaces, and make lower case' do
+ @info_request.title = 'Something True'
+ @info_request.url_title.should == 'something_true'
+ end
+
+ it 'should not allow a numeric name' do
+ @info_request.title = '1234'
+ @info_request.url_title.should == 'request'
+ end
+ end
+
describe "when asked for the last event id that needs description" do
before do