diff options
Diffstat (limited to 'spec/helpers')
-rw-r--r-- | spec/helpers/link_to_helper_spec.rb | 75 |
1 files changed, 35 insertions, 40 deletions
diff --git a/spec/helpers/link_to_helper_spec.rb b/spec/helpers/link_to_helper_spec.rb index 030fd612d..2259db6c2 100644 --- a/spec/helpers/link_to_helper_spec.rb +++ b/spec/helpers/link_to_helper_spec.rb @@ -8,70 +8,65 @@ describe LinkToHelper do before do @mock_request = mock_model(InfoRequest, :url_title => 'test_title') - @old_filters = ActionController::Routing::Routes.filters - ActionController::Routing::Routes.filters = RoutingFilter::Chain.new end - after do - ActionController::Routing::Routes.filters = @old_filters - end - it 'should return a path like /request/test_title' do - request_url(@mock_request).should == '/request/test_title' + request_path(@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' + request_path(@mock_request, {:update_status => 1}).should == '/request/test_title?update_status=1' end end - describe "when appending something to a URL" do - it 'should append to things without query strings' do - main_url('/a', '.json').should == 'http://test.host/a.json' - end - it 'should append to things with query strings' do - main_url('/a?z=1', '.json').should == 'http://test.host/a.json?z=1' - end - it 'should fail silently with invalid URLs' do - main_url('/a?z=9%', '.json').should == 'http://test.host/a?z=9%' - end - end - - describe 'when displaying a user admin link for a request' do + describe 'when displaying a user link for a request' do - it 'should return the text "An anonymous user (external)" in the case where there is no external username' do - info_request = mock_model(InfoRequest, :external_user_name => nil, - :is_external? => true) - user_admin_link_for_request(info_request).should == 'Anonymous user (external)' - end + context "for external requests" do + before do + @info_request = mock_model(InfoRequest, :external_user_name => nil, + :is_external? => true) + end - end + it 'should return the text "Anonymous user" with a link to the privacy help pages when there is no external username' do + request_user_link(@info_request).should == '<a href="/help/privacy#anonymous">Anonymous user</a>' + end - describe 'admin_url' do - context 'with no ADMIN_BASE_URL set' do - it 'should prepend the admin general index path to a simple string' do - admin_url('unclassified').should == 'http://test.host/en/admin/unclassified' + it 'should return a link with an alternative text if requested' do + request_user_link(@info_request, 'other text').should == '<a href="/help/privacy#anonymous">other text</a>' end - it 'should prepend the admin general index path to a deeper URL' do - admin_url('request/show/123').should == 'http://test.host/en/admin/request/show/123' + it 'should display an absolute link if requested' do + request_user_link_absolute(@info_request).should == '<a href="http://test.host/help/privacy#anonymous">Anonymous user</a>' end end - context 'with ADMIN_BASE_URL set' do - before(:each) do - Configuration::should_receive(:admin_base_url).and_return('https://www.example.com/secure/alaveteli-admin/') + context "for normal requests" do + + before do + @info_request = FactoryGirl.build(:info_request) end - it 'should prepend the admin base URL to a simple string' do - admin_url('unclassified').should == 'https://www.example.com/secure/alaveteli-admin/unclassified' + it 'should display a relative link by default' do + request_user_link(@info_request).should == '<a href="/user/example_user">Example User</a>' end - it 'should prepend the admin base URL to a deeper URL' do - admin_url('request/show/123').should == 'https://www.example.com/secure/alaveteli-admin/request/show/123' + it 'should display an absolute link if requested' do + request_user_link_absolute(@info_request).should == '<a href="http://test.host/user/example_user">Example User</a>' end + + end + + end + + describe 'when displaying a user admin link for a request' do + + it 'should return the text "An anonymous user (external)" in the case where there is no external username' do + info_request = mock_model(InfoRequest, :external_user_name => nil, + :is_external? => true) + user_admin_link_for_request(info_request).should == 'Anonymous user (external)' end + end describe 'simple_date' do |