diff options
-rw-r--r-- | app/helpers/widget_helper.rb | 47 | ||||
-rw-r--r-- | app/views/widgets/show.html.erb | 36 | ||||
-rw-r--r-- | spec/helpers/widget_helper_spec.rb | 31 |
3 files changed, 79 insertions, 35 deletions
diff --git a/app/helpers/widget_helper.rb b/app/helpers/widget_helper.rb new file mode 100644 index 000000000..f188f6b08 --- /dev/null +++ b/app/helpers/widget_helper.rb @@ -0,0 +1,47 @@ +module WidgetHelper + def status_description(info_request) + status = info_request.calculate_status + case status + when 'waiting_classification' + _('Awaiting classification') + when 'waiting_response' + _('Awaiting response') + when 'waiting_response_overdue' + _('Delayed') + when 'waiting_response_very_overdue' + _('Long overdue') + when 'not_held' + _('Not held') + when 'rejected' + _('Rejected') + when 'successful' + _('Successful') + when 'partially_successful' + _('Partial success') + when 'waiting_clarification' + _('Awaiting clarification') + when 'gone_postal' + _('Handled by post') + when 'internal_review' + _('Internal review') + when 'error_message' + _('Delivery error') + when 'requires_admin' + _('Unusual response') + when 'user_withdrawn' + _('Withdrawn') + when 'attention_requested' + _('Needs admin attention') + when 'vexatious' + _('Vexatious') + when 'not_foi' + _('Not an FOI request') + else + if info_request.respond_to?(:theme_display_status) + info_request.theme_display_status(status) + else + _('Unknown') + end + end + end +end
\ No newline at end of file diff --git a/app/views/widgets/show.html.erb b/app/views/widgets/show.html.erb index 73b875fa7..fd2391035 100644 --- a/app/views/widgets/show.html.erb +++ b/app/views/widgets/show.html.erb @@ -10,41 +10,7 @@ </div> <div class="alaveteli-widget__status <%= @info_request.calculate_status %>"> <p class="alaveteli-widget__status__status-label">Status</p> - <% if @info_request.awaiting_description %> - <%= _('Unknown Status') %> - <% elsif @status == 'waiting_response' %> - <%= _('Waiting Response') %> - <% elsif @status == 'waiting_response_overdue' %> - <%= _('Waiting Response') %> - <% elsif @status == 'waiting_response_very_overdue' %> - <%= _('Waiting Response') %> - <% elsif @status == 'not_held' %> - <%= _('Not Held') %> - <% elsif @status == 'rejected' %> - <%= _('Rejected') %> - <% elsif @status == 'successful' %> - <%= _('Successful') %> - <% elsif @status == 'partially_successful' %> - <%= _('Partial Success') %> - <% elsif @status == 'waiting_clarification' %> - <%= _('Waiting Clarification') %> - <% elsif @status == 'gone_postal' %> - <%= _('Gone Postal') %> - <% elsif @status == 'internal_review' %> - <%= _('Internal Review') %> - <% elsif @status == 'error_message' %> - <%= _('Error Message') %> - <% elsif @status == 'requires_admin' %> - <%= _('Requires Admin') %> - <% elsif @status == 'user_withdrawn' %> - <%= _('User Withdrawn') %> - <% elsif @status == 'attention_requested' %> - <%= _('Attention Requested') %> - <% elsif @status == 'vexatious' %> - <%= _('Vexatious') %> - <% else %> - <%= render :partial => 'general/custom_state_descriptions', :locals => { :status => @status } %> - <% end %> + <%= status_description(@info_request) %> </div> </div> <div class="alaveteli-widget__people-count"> diff --git a/spec/helpers/widget_helper_spec.rb b/spec/helpers/widget_helper_spec.rb new file mode 100644 index 000000000..b0da20c39 --- /dev/null +++ b/spec/helpers/widget_helper_spec.rb @@ -0,0 +1,31 @@ +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') + +describe WidgetHelper do + + include WidgetHelper + + describe :status_description do + + before do + @info_request = FactoryGirl.build(:info_request) + end + + it 'should return "Awaiting classification" for "waiting_classification' do + @info_request.stub!(:calculate_status).and_return("waiting_classification") + expect(status_description(@info_request)).to eq('Awaiting classification') + end + + it 'should call theme_display_status for a theme status' do + @info_request.stub!(:calculate_status).and_return("special_status") + @info_request.stub!(:theme_display_status).and_return("Special status") + expect(status_description(@info_request)).to eq('Special status') + end + + it 'should return unknown for an unknown status' do + @info_request.stub!(:calculate_status).and_return("special_status") + expect(status_description(@info_request)).to eq('Unknown') + end + + end + +end
\ No newline at end of file |