diff options
-rw-r--r-- | app/helpers/public_body_helper.rb | 35 | ||||
-rw-r--r-- | app/views/public_body/show.html.erb | 34 | ||||
-rw-r--r-- | spec/helpers/public_body_helper_spec.rb | 50 |
3 files changed, 98 insertions, 21 deletions
diff --git a/app/helpers/public_body_helper.rb b/app/helpers/public_body_helper.rb new file mode 100644 index 000000000..d8a5d57b5 --- /dev/null +++ b/app/helpers/public_body_helper.rb @@ -0,0 +1,35 @@ +module PublicBodyHelper + + # Public: The reasons a request can't be made to a PublicBody + # The returned reasons are ordered by priority. For example, if the body no + # longer exists there is no reason to ask for its contact details if we don't + # have an email for it. + # + # public_body - Instance of a PublicBody + # + # Returns an Array + def public_body_not_requestable_reasons(public_body) + reasons = [] + + if public_body.defunct? + reasons.push _('This authority no longer exists, so you cannot make a request to it.') + end + + if public_body.not_apply? + reasons.push _('Freedom of Information law does not apply to this authority, so you cannot make a request to it.') + end + + unless public_body.has_request_email? + # Make the authority appear requestable to encourage users to help find + # the authroty's email address + msg = link_to _("Make a request to this authority"), + new_request_to_body_path(:url_name => public_body.url_name), + :class => "link_button_green" + + reasons.push(msg) + end + + reasons.compact + end + +end diff --git a/app/views/public_body/show.html.erb b/app/views/public_body/show.html.erb index a2f202735..e7c5fa2b6 100644 --- a/app/views/public_body/show.html.erb +++ b/app/views/public_body/show.html.erb @@ -39,30 +39,22 @@ <% end %> </p> - <% if !@public_body.special_not_requestable_reason? %> - <% if @public_body.has_notes? %> - <p><%= @public_body.notes_as_html.html_safe %></p> - <% end %> - <% if @public_body.eir_only? %> - <p><%= _('You can only request information about the environment from this authority.')%></p> - <% end %> - <% else %> - <% if @public_body.not_requestable_reason == 'not_apply' %> - <p><%= _('Freedom of Information law does not apply to this authority, so you cannot make - a request to it.')%></p> - <% elsif @public_body.not_requestable_reason == 'defunct' %> - <p><%= _('This authority no longer exists, so you cannot make a request to it.')%></p> - <% end %> - <% end %> - <div id="stepwise_make_request"> - <% if @public_body.is_requestable? %> - <%= link_to _("Make a request to this authority"), new_request_to_body_path(:url_name => @public_body.url_name), :class => "link_button_green" %> - <% end %> + <% if @public_body.has_notes? %> + <%= @public_body.notes_as_html.html_safe %> + <% end %> - <% if @public_body.has_notes? %> - <%= @public_body.notes_as_html.html_safe %> + <% if @public_body.is_requestable? %> + <% if @public_body.eir_only? %> + <p><%= _('You can only request information about the environment from this authority.')%></p> <% end %> + + <%= link_to _("Make a request to this authority"), + new_request_to_body_path(:url_name => @public_body.url_name), + :class => "link_button_green" %> + <% else %> + <p><%= public_body_not_requestable_reasons(@public_body).first %></p> + <% end %> </div> </div> diff --git a/spec/helpers/public_body_helper_spec.rb b/spec/helpers/public_body_helper_spec.rb new file mode 100644 index 000000000..89a4d0641 --- /dev/null +++ b/spec/helpers/public_body_helper_spec.rb @@ -0,0 +1,50 @@ +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') + +describe PublicBodyHelper do + include PublicBodyHelper + + describe :public_body_not_requestable_reasons do + + before do + @body = FactoryGirl.build(:public_body) + end + + it 'returns an empty array if there are no reasons' do + expect(public_body_not_requestable_reasons(@body)).to eq([]) + end + + it 'includes a reason if the law does not apply to the authority' do + @body.tag_string = 'not_apply' + msg = 'Freedom of Information law does not apply to this authority, so you cannot make a request to it.' + expect(public_body_not_requestable_reasons(@body)).to include(msg) + end + + it 'includes a reason if the body no longer exists' do + @body.tag_string = 'defunct' + msg = 'This authority no longer exists, so you cannot make a request to it.' + expect(public_body_not_requestable_reasons(@body)).to include(msg) + end + + it 'links to the request page if the body has no contact email' do + @body.request_email = '' + msg = %Q(<a href="/new/#{ @body.url_name }" + class="link_button_green">Make + a request to this authority</a>).squish + + expect(public_body_not_requestable_reasons(@body)).to include(msg) + end + + it 'returns the reasons in order of importance' do + @body.tag_string = 'defunct not_apply' + @body.request_email = '' + + reasons = public_body_not_requestable_reasons(@body) + + expect(reasons[0]).to match(/no longer exists/) + expect(reasons[1]).to match(/does not apply/) + expect(reasons[2]).to match(/Make a request/) + end + + end + +end |