aboutsummaryrefslogtreecommitdiffstats
path: root/spec/helpers
diff options
context:
space:
mode:
authorGareth Rees <gareth@mysociety.org>2015-02-05 14:13:51 +0000
committerGareth Rees <gareth@mysociety.org>2015-02-20 11:59:05 +0000
commit8648236927ae030452d2ff2e18e6ce37b8c2f955 (patch)
treef4505a553844c7a4659258397e5461f56f7fc8c4 /spec/helpers
parent7886e830d8a20f80ec2516aaab021cc9546d1871 (diff)
Refactor showing the Make Request button
The code here was hard to follow. Now we have a cleaner path to decide whether to show the Make Request button or not. - Always show any notes associated with the body - If a request can be made to the body - Show any tag-specific notes that may affect the request - Show the Make Request button - If a request cannot be made to the body - Show the most relevant reason why a request cannot be made Added PublicBodyHelper#public_body_not_requestable_reasons to extract the logic of finding the reason a user can’t request out of the template
Diffstat (limited to 'spec/helpers')
-rw-r--r--spec/helpers/public_body_helper_spec.rb50
1 files changed, 50 insertions, 0 deletions
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