aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/helpers/link_to_helper.rb11
-rw-r--r--spec/helpers/link_to_helper_spec.rb23
2 files changed, 31 insertions, 3 deletions
diff --git a/app/helpers/link_to_helper.rb b/app/helpers/link_to_helper.rb
index 3f649f01d..8fdb092ae 100644
--- a/app/helpers/link_to_helper.rb
+++ b/app/helpers/link_to_helper.rb
@@ -5,25 +5,30 @@
# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
# Email: francis@mysociety.org; WWW: http://www.mysociety.org/
#
-# $Id: link_to_helper.rb,v 1.50 2009-02-12 19:50:56 francis Exp $
+# $Id: link_to_helper.rb,v 1.51 2009-04-03 14:07:46 louise Exp $
module LinkToHelper
# Links to various models
# Requests
- def request_url(info_request)
- return show_request_url(:url_title => info_request.url_title, :only_path => true)
+ def request_url(info_request, extra_params={})
+ params = {:url_title => info_request.url_title, :only_path => true}
+ return show_request_url(params.merge(extra_params))
end
+
def request_link(info_request)
link_to h(info_request.title), request_url(info_request)
end
+
def request_admin_url(info_request)
return admin_url('request/show/' + info_request.id.to_s)
end
+
def request_both_links(info_request)
link_to(h(info_request.title), main_url(request_url(info_request))) + " (" + link_to("admin", request_admin_url(info_request)) + ")"
end
+
def request_similar_url(info_request)
return similar_request_url(:url_title => info_request.url_title, :only_path => true)
end
diff --git a/spec/helpers/link_to_helper_spec.rb b/spec/helpers/link_to_helper_spec.rb
new file mode 100644
index 000000000..f211a531d
--- /dev/null
+++ b/spec/helpers/link_to_helper_spec.rb
@@ -0,0 +1,23 @@
+require File.dirname(__FILE__) + '/../spec_helper'
+
+describe LinkToHelper do
+
+ include LinkToHelper
+
+ describe 'when creating a url for a request' do
+
+ before do
+ @mock_request = mock_model(InfoRequest, :url_title => 'test_title')
+ end
+
+ it 'should return a path like /request/test_title' do
+ request_url(@mock_request).should == '/request/test_title'
+ end
+
+ it 'should return a path including any extra parameters passed' do
+ request_url(@mock_request, {:update_status => 1}).should == '/request/test_title?update_status=1'
+ end
+
+ end
+
+end \ No newline at end of file