diff options
-rwxr-xr-x | app/helpers/link_to_helper.rb | 8 | ||||
-rw-r--r-- | spec/controllers/request_controller_spec.rb | 2 | ||||
-rw-r--r-- | spec/helpers/link_to_helper_spec.rb | 68 |
3 files changed, 75 insertions, 3 deletions
diff --git a/app/helpers/link_to_helper.rb b/app/helpers/link_to_helper.rb index dd6ffa805..9f63ec583 100755 --- a/app/helpers/link_to_helper.rb +++ b/app/helpers/link_to_helper.rb @@ -28,7 +28,9 @@ module LinkToHelper # Incoming / outgoing messages def incoming_message_url(incoming_message, options = {}) - return request_url(incoming_message.info_request, options.merge(:anchor => "incoming-#{incoming_message.id}")) + default_options = { :anchor => "incoming-#{ incoming_message.id }", + :nocache => "incoming-#{ incoming_message.id }" } + request_url(incoming_message.info_request, options.merge(default_options)) end def incoming_message_path(incoming_message) @@ -36,7 +38,9 @@ module LinkToHelper end def outgoing_message_url(outgoing_message, options = {}) - request_url(outgoing_message.info_request, options.merge(:anchor => "outgoing-#{outgoing_message.id}")) + default_options = { :anchor => "outgoing-#{ outgoing_message.id }", + :nocache => "outgoing-#{ outgoing_message.id }" } + request_url(outgoing_message.info_request, options.merge(default_options)) end def outgoing_message_path(outgoing_message) diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index 070511fb0..bde1c136a 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -567,7 +567,7 @@ describe RequestController, "when showing one request" do get :get_attachment_as_html, :incoming_message_id => im.id, :id => ir.id, :part => 5, :file_name => 'hello world.txt', :skip_cache => 1 response.status.should == 303 new_location = response.header['Location'] - new_location.should match(/request\/#{ir.url_title}#incoming-#{im.id}/) + new_location.should match(/request\/#{ir.url_title}\?nocache=incoming-#{im.id}#incoming-#{im.id}/) end it "should find a uniquely named filename even if the URL part number was wrong" do diff --git a/spec/helpers/link_to_helper_spec.rb b/spec/helpers/link_to_helper_spec.rb index 4a01ec683..08362da6e 100644 --- a/spec/helpers/link_to_helper_spec.rb +++ b/spec/helpers/link_to_helper_spec.rb @@ -20,6 +20,74 @@ describe LinkToHelper do end + describe 'when linking to new incoming messages' do + + before do + @info_request = mock_model(InfoRequest, :id => 123, :url_title => 'test_title') + @incoming_message = mock_model(IncomingMessage, :id => 32, :info_request => @info_request) + end + + context 'for external links' do + + it 'generates the url to the info request of the message' do + incoming_message_url(@incoming_message).should include('http://test.host/request/test_title') + end + + it 'includes an anchor to the new message' do + incoming_message_url(@incoming_message).should include('#incoming-32') + end + + it 'includes a cache busting parameter' do + incoming_message_url(@incoming_message).should include('nocache=incoming-32') + end + + end + + context 'for internal links' do + + it 'generates the incoming_message_url with the path only' do + expected = '/request/test_title?nocache=incoming-32#incoming-32' + incoming_message_path(@incoming_message).should == expected + end + + end + + end + + describe 'when linking to new outgoing messages' do + + before do + @info_request = mock_model(InfoRequest, :id => 123, :url_title => 'test_title') + @outgoing_message = mock_model(OutgoingMessage, :id => 32, :info_request => @info_request) + end + + context 'for external links' do + + it 'generates the url to the info request of the message' do + outgoing_message_url(@outgoing_message).should include('http://test.host/request/test_title') + end + + it 'includes an anchor to the new message' do + outgoing_message_url(@outgoing_message).should include('#outgoing-32') + end + + it 'includes a cache busting parameter' do + outgoing_message_url(@outgoing_message).should include('nocache=outgoing-32') + end + + end + + context 'for internal links' do + + it 'generates the outgoing_message_url with the path only' do + expected = '/request/test_title?nocache=outgoing-32#outgoing-32' + outgoing_message_path(@outgoing_message).should == expected + end + + end + + end + describe 'when displaying a user link for a request' do context "for external requests" do |