aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/helpers/application_helper.rb42
-rwxr-xr-xapp/helpers/link_to_helper.rb6
-rw-r--r--app/views/general/search.html.erb2
-rw-r--r--app/views/info_request_batch/show.html.erb2
-rw-r--r--app/views/public_body/show.html.erb2
-rw-r--r--app/views/request/_list_results.html.erb2
-rw-r--r--app/views/request/_request_listing_via_event.html.erb29
-rw-r--r--app/views/request/similar.html.erb2
-rw-r--r--app/views/track/atom_feed.atom.erb2
-rw-r--r--app/views/user/river.html.erb3
-rw-r--r--app/views/user/show.html.erb4
-rw-r--r--spec/factories.rb26
-rw-r--r--spec/helpers/application_helper_spec.rb34
13 files changed, 115 insertions, 41 deletions
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 154697377..33525cb3d 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -136,5 +136,47 @@ module ApplicationHelper
nil
end
end
+
+ def event_description(event)
+ body_link = public_body_link_absolute(event.info_request.public_body)
+ user_link = request_user_link_absolute(event.info_request)
+ date = simple_date(event.created_at)
+ case event.event_type
+ when 'sent'
+ _('Request sent to {{public_body_name}} by {{info_request_user}} on {{date}}.',
+ :public_body_name => body_link,
+ :info_request_user => user_link,
+ :date => date)
+ when 'followup_sent'
+ case event.calculated_state
+ when 'internal_review'
+ _('Internal review request sent to {{public_body_name}} by {{info_request_user}} on {{date}}.',
+ :public_body_name => body_link,
+ :info_request_user => user_link,
+ :date => date)
+ when 'waiting_response'
+ _('Clarification sent to {{public_body_name}} by {{info_request_user}} on {{date}}.',
+ :public_body_name => body_link,
+ :info_request_user => user_link,
+ :date => date)
+ else
+ _('Follow up sent to {{public_body_name}} by {{info_request_user}} on {{date}}.',
+ :public_body_name => body_link,
+ :info_request_user => user_link,
+ :date => date)
+ end
+ when 'response'
+ _('Response by {{public_body_name}} to {{info_request_user}} on {{date}}.',
+ :public_body_name => body_link,
+ :info_request_user => user_link,
+ :date => date)
+ when 'comment'
+ _('Request to {{public_body_name}} by {{info_request_user}}. Annotated by {{event_comment_user}} on {{date}}.',
+ :public_body_name => body_link,
+ :info_request_user => user_link,
+ :event_comment_user => user_link_absolute(event.comment.user),
+ :date => date)
+ end
+ end
end
diff --git a/app/helpers/link_to_helper.rb b/app/helpers/link_to_helper.rb
index bf70f9140..594296e77 100755
--- a/app/helpers/link_to_helper.rb
+++ b/app/helpers/link_to_helper.rb
@@ -75,15 +75,15 @@ module LinkToHelper
end
def public_body_link_short(public_body)
- link_to h(public_body.short_or_long_name), public_body_path(public_body)
+ link_to public_body.short_or_long_name, public_body_path(public_body)
end
def public_body_link(public_body, cls=nil)
- link_to h(public_body.name), public_body_path(public_body), :class => cls
+ link_to public_body.name, public_body_path(public_body), :class => cls
end
def public_body_link_absolute(public_body) # e.g. for in RSS
- link_to h(public_body.name), public_body_url(public_body)
+ link_to public_body.name, public_body_url(public_body)
end
# Users
diff --git a/app/views/general/search.html.erb b/app/views/general/search.html.erb
index 18f258444..45268d7f0 100644
--- a/app/views/general/search.html.erb
+++ b/app/views/general/search.html.erb
@@ -191,7 +191,7 @@
<div class="results_block">
<% for result in @xapian_requests.results %>
- <%= render :partial => 'request/request_listing_via_event', :locals => { :event => result[:model], :info_request => result[:model].info_request } %>
+ <%= render :partial => 'request/request_listing_via_event', :locals => { :event => result[:model] } %>
<% end %>
</div>
diff --git a/app/views/info_request_batch/show.html.erb b/app/views/info_request_batch/show.html.erb
index aaecdd45d..2c7e42072 100644
--- a/app/views/info_request_batch/show.html.erb
+++ b/app/views/info_request_batch/show.html.erb
@@ -5,7 +5,7 @@
<div class="results_section">
<div class="results_block">
<% @info_requests.each do |info_request| %>
- <%= render :partial => 'request/request_listing_via_event', :locals => { :event => info_request.last_event_forming_initial_request, :info_request => info_request } %>
+ <%= render :partial => 'request/request_listing_via_event', :locals => { :event => info_request.last_event_forming_initial_request } %>
<% end %>
</div>
<%= will_paginate WillPaginate::Collection.new(@page, @per_page, @info_request_batch.info_requests.visible.count) %>
diff --git a/app/views/public_body/show.html.erb b/app/views/public_body/show.html.erb
index c36396149..a9c50e657 100644
--- a/app/views/public_body/show.html.erb
+++ b/app/views/public_body/show.html.erb
@@ -119,7 +119,7 @@
<% if !@xapian_requests.nil? %>
<% for result in @xapian_requests.results %>
- <%= render :partial => 'request/request_listing_via_event', :locals => { :event => result[:model], :info_request => result[:model].info_request } %>
+ <%= render :partial => 'request/request_listing_via_event', :locals => { :event => result[:model] } %>
<% end %>
<%= will_paginate WillPaginate::Collection.new(@page, @per_page, @xapian_requests.matches_estimated) %>
diff --git a/app/views/request/_list_results.html.erb b/app/views/request/_list_results.html.erb
index 4da042816..9e6b07c79 100644
--- a/app/views/request/_list_results.html.erb
+++ b/app/views/request/_list_results.html.erb
@@ -5,7 +5,7 @@
<h2 class="foi_results"><%= _('{{count}} FOI requests found', :count => @results[:matches_estimated]) %></h2>
<div class="results_block">
<% @results[:results].each do |result| %>
- <%= render :partial => 'request/request_listing_via_event', :locals => { :event => result, :info_request => result.info_request } %>
+ <%= render :partial => 'request/request_listing_via_event', :locals => { :event => result } %>
<% end %>
</div>
<% end %>
diff --git a/app/views/request/_request_listing_via_event.html.erb b/app/views/request/_request_listing_via_event.html.erb
index cc8bae8a9..20bc5b2c8 100644
--- a/app/views/request/_request_listing_via_event.html.erb
+++ b/app/views/request/_request_listing_via_event.html.erb
@@ -6,36 +6,21 @@ end %>
<div class="request_left">
<span class="head">
<% if event.is_incoming_message? %>
- <%= link_to highlight_words(info_request.title, @highlight_words), incoming_message_path(event.incoming_message_selective_columns("incoming_messages.id")) %>
+ <%= link_to highlight_words(event.info_request.title, @highlight_words), incoming_message_path(event.incoming_message_selective_columns("incoming_messages.id")) %>
<% elsif event.is_outgoing_message? and event.event_type == 'followup_sent' %>
- <%= link_to highlight_words(info_request.title, @highlight_words), outgoing_message_path(event.outgoing_message) %>
+ <%= link_to highlight_words(event.info_request.title, @highlight_words), outgoing_message_path(event.outgoing_message) %>
<% elsif event.is_comment? %>
- <%= link_to highlight_words(info_request.title, @highlight_words), comment_path(event.comment) %>
+ <%= link_to highlight_words(event.info_request.title, @highlight_words), comment_path(event.comment) %>
<% else %>
- <%= link_to highlight_words(info_request.title, @highlight_words), request_path(info_request) %>
+ <%= link_to highlight_words(event.info_request.title, @highlight_words), request_path(event.info_request) %>
<% end %>
</span>
<div class="requester">
- <% if event.event_type == 'sent' %>
- <%= _('Request sent to {{public_body_name}} by {{info_request_user}} on {{date}}.',:public_body_name=>public_body_link_absolute(info_request.public_body),:info_request_user=>request_user_link_absolute(info_request),:date=>simple_date(event.created_at )) %>
- <% elsif event.event_type == 'followup_sent' %>
- <%=event.display_status %>
- <%= _('sent to {{public_body_name}} by {{info_request_user}} on {{date}}.',:public_body_name=>public_body_link_absolute(info_request.public_body),:info_request_user=>request_user_link_absolute(info_request),:date=>simple_date(event.created_at )) %>
- <% elsif event.event_type == 'response' %>
- <%=event.display_status %>
- <%= _('by {{public_body_name}} to {{info_request_user}} on {{date}}.',:public_body_name=>public_body_link_absolute(info_request.public_body),:info_request_user=>request_user_link_absolute(info_request),:date=>simple_date(event.created_at )) %>
- <% elsif event.event_type == 'comment' %>
- <%= _('Request to {{public_body_name}} by {{info_request_user}}. Annotated by {{event_comment_user}} on {{date}}.',:public_body_name=>public_body_link_absolute(info_request.public_body),:info_request_user=>request_user_link_absolute(info_request),:event_comment_user=>user_link_absolute(event.comment.user),:date=>simple_date(event.created_at)) %>
- <% else %>
- <%# Events of other types will not be indexed: see InfoRequestEvent#indexed_by_search?
- However, it can happen that we see other types of event transiently here in the period
- between a change being made and the update-xapian-index job being run. %>
- <!-- Event of type '<%= event.event_type %>', id=<%= event.id %> -->
- <% end %>
+ <%= event_description(event) %>
</div>
- <span class="bottomline icon_<%= info_request.calculate_status %>">
+ <span class="bottomline icon_<%= event.info_request.calculate_status %>">
<strong>
- <%= info_request.display_status(cached_value_ok=true) %>
+ <%= event.info_request.display_status(cached_value_ok=true) %>
</strong><br>
</span>
</div>
diff --git a/app/views/request/similar.html.erb b/app/views/request/similar.html.erb
index 5bdefc494..4ce4bf9ba 100644
--- a/app/views/request/similar.html.erb
+++ b/app/views/request/similar.html.erb
@@ -22,7 +22,7 @@
-->
<% for result in @xapian_object.results %>
<% if result[:model].class.to_s == 'InfoRequestEvent' %>
- <%= render :partial => 'request/request_listing_via_event', :locals => { :event => result[:model], :info_request => result[:model].info_request } %>
+ <%= render :partial => 'request/request_listing_via_event', :locals => { :event => result[:model] } %>
<% else %>
<p><strong><%= _('Unexpected search result type ')%><%=result[:model].class.to_s%></strong></p>
<% end %>
diff --git a/app/views/track/atom_feed.atom.erb b/app/views/track/atom_feed.atom.erb
index be9c39e72..892727aef 100644
--- a/app/views/track/atom_feed.atom.erb
+++ b/app/views/track/atom_feed.atom.erb
@@ -9,7 +9,7 @@
# Get the HTML content from the same partial template as website search does
content = ''
if result[:model].class.to_s == 'InfoRequestEvent'
- content += render :partial => 'request/request_listing_via_event', :formats => ['html'], :locals => { :event => result[:model], :info_request => result[:model].info_request }
+ content += render :partial => 'request/request_listing_via_event', :formats => ['html'], :locals => { :event => result[:model] }
else
content = "<p><strong>Unknown search result type " + result[:model].class.to_s + "</strong></p>"
end
diff --git a/app/views/user/river.html.erb b/app/views/user/river.html.erb
index 9618e0aa8..7277e5ee5 100644
--- a/app/views/user/river.html.erb
+++ b/app/views/user/river.html.erb
@@ -4,8 +4,7 @@
<h1><%=@title%></h1>
<% for result in @results %>
- <%= render :partial => 'request/request_listing_via_event', :locals => {
- :event => result[:model], :info_request => result[:model].info_request } %>
+ <%= render :partial => 'request/request_listing_via_event', :locals => { :event => result[:model] } %>
<% end %>
</div>
diff --git a/app/views/user/show.html.erb b/app/views/user/show.html.erb
index 76ecdeda0..1ccb1d649 100644
--- a/app/views/user/show.html.erb
+++ b/app/views/user/show.html.erb
@@ -147,7 +147,7 @@
<% for result in @xapian_requests.results %>
- <%= render :partial => 'request/request_listing_via_event', :locals => { :event => result[:model], :info_request => result[:model].info_request } %>
+ <%= render :partial => 'request/request_listing_via_event', :locals => { :event => result[:model] } %>
<% end %>
<%= will_paginate WillPaginate::Collection.new(@page, @per_page, @display_user.info_requests.size) %>
@@ -175,7 +175,7 @@
</h2>
<% for result in @xapian_comments.results %>
- <%= render :partial => 'request/request_listing_via_event', :locals => { :event => result[:model], :info_request => result[:model].info_request } %>
+ <%= render :partial => 'request/request_listing_via_event', :locals => { :event => result[:model] } %>
<% end %>
<%= will_paginate WillPaginate::Collection.new(@page, @per_page, @display_user.visible_comments.size) %>
diff --git a/spec/factories.rb b/spec/factories.rb
index 8efc53033..4ae99be5b 100644
--- a/spec/factories.rb
+++ b/spec/factories.rb
@@ -69,14 +69,22 @@ FactoryGirl.define do
body 'Some information please'
what_doing 'normal_sort'
end
- initialize_with { OutgoingMessage.new({ :status => status,
- :message_type => message_type,
- :body => body,
- :what_doing => what_doing }) }
- after_create do |outgoing_message|
- outgoing_message.send_message
+ end
+ factory :internal_review_request do
+ ignore do
+ status 'ready'
+ message_type 'followup'
+ body 'I want a review'
+ what_doing 'internal_review'
end
end
+ initialize_with { OutgoingMessage.new({ :status => status,
+ :message_type => message_type,
+ :body => body,
+ :what_doing => what_doing }) }
+ after_create do |outgoing_message|
+ outgoing_message.send_message
+ end
end
factory :info_request do
@@ -109,6 +117,12 @@ FactoryGirl.define do
end
end
+ factory :info_request_with_internal_review_request do
+ after_create do |info_request, evaluator|
+ outgoing_message = FactoryGirl.create(:internal_review_request, :info_request => info_request)
+ end
+ end
+
factory :external_request do
user nil
external_user_name 'External User'
diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb
new file mode 100644
index 000000000..6407eaf3a
--- /dev/null
+++ b/spec/helpers/application_helper_spec.rb
@@ -0,0 +1,34 @@
+require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
+
+describe ApplicationHelper do
+
+ include ApplicationHelper
+ include LinkToHelper
+
+ describe 'when creating an event description' do
+
+ it 'should generate a description for a request' do
+ @info_request = FactoryGirl.create(:info_request)
+ @sent_event = @info_request.get_last_event
+ expected = "Request sent to #{public_body_link_absolute(@info_request.public_body)} by #{request_user_link_absolute(@info_request)}"
+ event_description(@sent_event).should match(expected)
+
+ end
+
+ it 'should generate a description for a response' do
+ @info_request_with_incoming = FactoryGirl.create(:info_request_with_incoming)
+ @response_event = @info_request_with_incoming.get_last_event
+ expected = "Response by #{public_body_link_absolute(@info_request_with_incoming.public_body)} to #{request_user_link_absolute(@info_request_with_incoming)}"
+ event_description(@response_event).should match(expected)
+ end
+
+ it 'should generate a description for a request where an internal review has been requested' do
+ @info_request_with_internal_review_request = FactoryGirl.create(:info_request_with_internal_review_request)
+ @response_event = @info_request_with_internal_review_request.get_last_event
+ expected = "Internal review request sent to #{public_body_link_absolute(@info_request_with_internal_review_request.public_body)} by #{request_user_link_absolute(@info_request_with_internal_review_request)}"
+ event_description(@response_event).should match(expected)
+ end
+
+ end
+
+end