aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/helpers/application_helper.rb42
-rw-r--r--app/views/request/_request_listing_via_event.html.erb17
-rw-r--r--spec/factories.rb26
-rw-r--r--spec/helpers/application_helper_spec.rb34
4 files changed, 97 insertions, 22 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/views/request/_request_listing_via_event.html.erb b/app/views/request/_request_listing_via_event.html.erb
index 3b0d6795a..20bc5b2c8 100644
--- a/app/views/request/_request_listing_via_event.html.erb
+++ b/app/views/request/_request_listing_via_event.html.erb
@@ -16,22 +16,7 @@ end %>
<% 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(event.info_request.public_body),:info_request_user=>request_user_link_absolute(event.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(event.info_request.public_body),:info_request_user=>request_user_link_absolute(event.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(event.info_request.public_body),:info_request_user=>request_user_link_absolute(event.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(event.info_request.public_body),:info_request_user=>request_user_link_absolute(event.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_<%= event.info_request.calculate_status %>">
<strong>
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