aboutsummaryrefslogtreecommitdiffstats
path: root/spec/controllers/user_controller_spec.rb
diff options
context:
space:
mode:
authorLouise Crow <louise.crow@gmail.com>2013-07-29 18:24:17 +0100
committerLouise Crow <louise.crow@gmail.com>2013-07-29 18:48:52 +0100
commit34879219dabe3a9a813a3b30e4391d35e0bc8688 (patch)
treeb0738b3d8fd9bdf43347ab78bc88036566d7869a /spec/controllers/user_controller_spec.rb
parent571004d84f0f5a0705e86d839d0fff62e31ccac2 (diff)
Handle the case of a name that hits the character limits and has been suffixed with a number.
Diffstat (limited to 'spec/controllers/user_controller_spec.rb')
-rw-r--r--spec/controllers/user_controller_spec.rb30
1 files changed, 25 insertions, 5 deletions
diff --git a/spec/controllers/user_controller_spec.rb b/spec/controllers/user_controller_spec.rb
index fe95aa31c..0033309a5 100644
--- a/spec/controllers/user_controller_spec.rb
+++ b/spec/controllers/user_controller_spec.rb
@@ -3,6 +3,31 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
# XXX Use route_for or params_from to check /c/ links better
# http://rspec.rubyforge.org/rspec-rails/1.1.12/classes/Spec/Rails/Example/ControllerExampleGroup.html
+describe UserController, "when redirecting a show request to a canonical url" do
+
+ it "should redirect to lower case name if given one with capital letters" do
+ get :show, :url_name => "Bob_Smith"
+ response.should redirect_to(:controller => 'user', :action => 'show', :url_name => "bob_smith")
+ end
+
+ it 'should redirect a long non-canonical name that has a numerical suffix,
+ retaining the suffix' do
+ get :show, :url_name => 'Bob_SmithBob_SmithBob_SmithBob_S_2'
+ response.should redirect_to(:controller => 'user',
+ :action => 'show',
+ :url_name => 'bob_smithbob_smithbob_smithbob_s_2')
+ end
+
+ it 'should not redirect a long canonical name that has a numerical suffix' do
+ User.stub!(:find).with(:first, anything()).and_return(mock_model(User,
+ :url_name => 'bob_smithbob_smithbob_smithbob_s_2',
+ :name => 'Bob Smith Bob Smith Bob Smith Bob Smith'))
+ User.stub!(:find).with(:all, anything()).and_return([])
+ get :show, :url_name => 'bob_smithbob_smithbob_smithbob_s_2'
+ response.should be_success
+ end
+
+end
describe UserController, "when showing a user" do
render_views
@@ -16,11 +41,6 @@ describe UserController, "when showing a user" do
response.should be_success
end
- it "should redirect to lower case name if given one with capital letters" do
- get :show, :url_name => "Bob_Smith"
- response.should redirect_to(:controller => 'user', :action => 'show', :url_name => "bob_smith")
- end
-
it "should render with 'show' template" do
get :show, :url_name => "bob_smith"
response.should render_template('show')