From e53e0a0ccbb4695dbbb01a56598b7c832a9c5a0c Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Thu, 1 Aug 2013 14:53:10 +0100 Subject: Refactor some common setup steps in integration tests into a DSL. Add a failing test for what should happen on request hiding. --- spec/integration/view_request_spec.rb | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) (limited to 'spec/integration/view_request_spec.rb') diff --git a/spec/integration/view_request_spec.rb b/spec/integration/view_request_spec.rb index 3d646cfe7..79453e4c2 100644 --- a/spec/integration/view_request_spec.rb +++ b/spec/integration/view_request_spec.rb @@ -1,4 +1,5 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') +require File.expand_path(File.dirname(__FILE__) + '/alaveteli_dsl') describe "When viewing requests" do @@ -7,18 +8,32 @@ describe "When viewing requests" do end it "should not make endlessly recursive JSON s" do - @dog_request = info_requests(:fancy_dog_request) - get "request/#{@dog_request.url_title}?unfold=1" - response.body.should_not include("dog?unfold=1.json") - response.body.should include("dog.json?unfold=1") + unregistered = without_login + unregistered.browses_request('why_do_you_have_such_a_fancy_dog?unfold=1') + unregistered.response.body.should_not include("dog?unfold=1.json") + unregistered.response.body.should include("dog.json?unfold=1") end it 'should not raise a routing error when making a json link for a request with an "action" querystring param' do - @dog_request = info_requests(:fancy_dog_request) - get "request/#{@dog_request.url_title}?action=add" - response.should be_success + unregistered = without_login + unregistered.browses_request('why_do_you_have_such_a_fancy_dog?action=add') end + context 'when a response is hidden' do + + before do + useless_message = incoming_messages(:useless_incoming_message) + useless_message.prominence = 'hidden' + useless_message.save! + end + + it 'should show a hidden notice to an unregistered user' do + unregistered = without_login + response = unregistered.browses_request('why_do_you_have_such_a_fancy_dog') + response.body.should include("This message has been hidden.") + end + + end end -- cgit v1.2.3 From 9fc829822bf805131b8fd3175627d48aed902e17 Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Thu, 1 Aug 2013 16:34:56 +0100 Subject: Add messages for hidden and requester_only states. Different messages for normal user, requester and admin user. --- spec/integration/view_request_spec.rb | 97 +++++++++++++++++++++++++++++++++-- 1 file changed, 93 insertions(+), 4 deletions(-) (limited to 'spec/integration/view_request_spec.rb') diff --git a/spec/integration/view_request_spec.rb b/spec/integration/view_request_spec.rb index 79453e4c2..6f02cff7c 100644 --- a/spec/integration/view_request_spec.rb +++ b/spec/integration/view_request_spec.rb @@ -20,7 +20,41 @@ describe "When viewing requests" do unregistered.browses_request('why_do_you_have_such_a_fancy_dog?action=add') end - context 'when a response is hidden' do + context 'when a response has prominence "normal"' do + + before do + useless_message = incoming_messages(:useless_incoming_message) + useless_message.prominence = 'normal' + useless_message.save! + end + + it 'should show the message itself to any user' do + + # unregistered + unregistered = without_login + unregistered.browses_request('why_do_you_have_such_a_fancy_dog') + unregistered.response.body.should include("No way!") + unregistered.response.body.should_not include("This message has been hidden.") + unregistered.response.body.should_not include("sign in to view the message.") + + # requester + bob = login(:bob_smith_user) + bob.browses_request('why_do_you_have_such_a_fancy_dog') + bob.response.body.should include("No way!") + bob.response.body.should_not include("This message has been hidden.") + + # admin + confirm(:admin_user) + admin_user = login(:admin_user) + admin_user.browses_request('why_do_you_have_such_a_fancy_dog') + admin_user.response.body.should include('No way!') + admin_user.response.body.should_not include("This message has prominence \'hidden\'.") + + end + + end + + context 'when a response has prominence "hidden"' do before do useless_message = incoming_messages(:useless_incoming_message) @@ -28,12 +62,67 @@ describe "When viewing requests" do useless_message.save! end - it 'should show a hidden notice to an unregistered user' do + it 'should show a hidden notice, not the message, to an unregistered user or the requester and + the message itself to an admin ' do + + # unregistered + unregistered = without_login + unregistered.browses_request('why_do_you_have_such_a_fancy_dog') + unregistered.response.body.should include("This message has been hidden.") + unregistered.response.body.should_not include("sign in to view the message.") + unregistered.response.body.should_not include("No way!") + + # requester + bob = login(:bob_smith_user) + bob.browses_request('why_do_you_have_such_a_fancy_dog') + bob.response.body.should include("This message has been hidden.") + bob.response.body.should_not include("No way!") + + # admin + confirm(:admin_user) + admin_user = login(:admin_user) + admin_user.browses_request('why_do_you_have_such_a_fancy_dog') + admin_user.response.body.should include('No way!') + admin_user.response.body.should include("This message has prominence \'hidden\'. You can only see it because you are logged in as a super user.") + + end + + end + + context 'when as response has prominence "requester_only"' do + + before do + useless_message = incoming_messages(:useless_incoming_message) + useless_message.prominence = 'requester_only' + useless_message.save! + end + + it 'should show a hidden notice with login link to an unregistered user, and the message itself + with a hidden note to the requester or an admin' do + + # unregistered unregistered = without_login - response = unregistered.browses_request('why_do_you_have_such_a_fancy_dog') - response.body.should include("This message has been hidden.") + unregistered.browses_request('why_do_you_have_such_a_fancy_dog') + unregistered.response.body.should include("This message has been hidden.") + unregistered.response.body.should include("sign in to view the message.") + unregistered.response.body.should_not include("No way!") + + # requester + bob = login(:bob_smith_user) + bob.browses_request('why_do_you_have_such_a_fancy_dog') + bob.response.body.should include("No way!") + bob.response.body.should include("This message is hidden, so that only you, the requester, can see it.") + + # admin + confirm(:admin_user) + admin_user = login(:admin_user) + admin_user.browses_request('why_do_you_have_such_a_fancy_dog') + admin_user.response.body.should include('No way!') + admin_user.response.body.should_not include("This message has been hidden.") + admin_user.response.body.should include("This message is hidden, so that only you, the requester, can see it.") end end + end -- cgit v1.2.3 From b8151bc4b13affeb7ec66146327961c35ef7e136 Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Mon, 16 Sep 2013 12:41:37 +0100 Subject: Add prominence reason. Conflicts: app/views/request/_incoming_correspondence.html.erb Conflicts: spec/integration/view_request_spec.rb --- spec/integration/view_request_spec.rb | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'spec/integration/view_request_spec.rb') diff --git a/spec/integration/view_request_spec.rb b/spec/integration/view_request_spec.rb index 6f02cff7c..f8be4a938 100644 --- a/spec/integration/view_request_spec.rb +++ b/spec/integration/view_request_spec.rb @@ -59,6 +59,7 @@ describe "When viewing requests" do before do useless_message = incoming_messages(:useless_incoming_message) useless_message.prominence = 'hidden' + useless_message.prominence_reason = 'It is too irritating.' useless_message.save! end @@ -68,14 +69,14 @@ describe "When viewing requests" do # unregistered unregistered = without_login unregistered.browses_request('why_do_you_have_such_a_fancy_dog') - unregistered.response.body.should include("This message has been hidden.") + unregistered.response.body.should include("This message has been hidden. It is too irritating.") unregistered.response.body.should_not include("sign in to view the message.") unregistered.response.body.should_not include("No way!") # requester bob = login(:bob_smith_user) bob.browses_request('why_do_you_have_such_a_fancy_dog') - bob.response.body.should include("This message has been hidden.") + bob.response.body.should include("This message has been hidden. It is too irritating") bob.response.body.should_not include("No way!") # admin @@ -83,7 +84,7 @@ describe "When viewing requests" do admin_user = login(:admin_user) admin_user.browses_request('why_do_you_have_such_a_fancy_dog') admin_user.response.body.should include('No way!') - admin_user.response.body.should include("This message has prominence \'hidden\'. You can only see it because you are logged in as a super user.") + admin_user.response.body.should include("This message has prominence \'hidden\'. It is too irritating. You can only see it because you are logged in as a super user.") end @@ -94,6 +95,7 @@ describe "When viewing requests" do before do useless_message = incoming_messages(:useless_incoming_message) useless_message.prominence = 'requester_only' + useless_message.prominence_reason = 'It is too irritating.' useless_message.save! end @@ -103,7 +105,7 @@ describe "When viewing requests" do # unregistered unregistered = without_login unregistered.browses_request('why_do_you_have_such_a_fancy_dog') - unregistered.response.body.should include("This message has been hidden.") + unregistered.response.body.should include("This message has been hidden. It is too irritating") unregistered.response.body.should include("sign in to view the message.") unregistered.response.body.should_not include("No way!") @@ -111,7 +113,7 @@ describe "When viewing requests" do bob = login(:bob_smith_user) bob.browses_request('why_do_you_have_such_a_fancy_dog') bob.response.body.should include("No way!") - bob.response.body.should include("This message is hidden, so that only you, the requester, can see it.") + bob.response.body.should include("This message is hidden, so that only you, the requester, can see it. It is too irritating.") # admin confirm(:admin_user) -- cgit v1.2.3 From ebee053ec8514f70f94309f306bf1e82050c4c33 Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Mon, 16 Sep 2013 12:42:14 +0100 Subject: Split up translated messages. Each part is a separate sentence, and we're going to reuse some of them in the text view. Conflicts: spec/integration/view_request_spec.rb --- spec/integration/view_request_spec.rb | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'spec/integration/view_request_spec.rb') diff --git a/spec/integration/view_request_spec.rb b/spec/integration/view_request_spec.rb index f8be4a938..2de961200 100644 --- a/spec/integration/view_request_spec.rb +++ b/spec/integration/view_request_spec.rb @@ -69,14 +69,16 @@ describe "When viewing requests" do # unregistered unregistered = without_login unregistered.browses_request('why_do_you_have_such_a_fancy_dog') - unregistered.response.body.should include("This message has been hidden. It is too irritating.") + unregistered.response.body.should include("This message has been hidden.") + unregistered.response.body.should include("It is too irritating.") unregistered.response.body.should_not include("sign in to view the message.") unregistered.response.body.should_not include("No way!") # requester bob = login(:bob_smith_user) bob.browses_request('why_do_you_have_such_a_fancy_dog') - bob.response.body.should include("This message has been hidden. It is too irritating") + bob.response.body.should include("This message has been hidden.") + bob.response.body.should include("It is too irritating") bob.response.body.should_not include("No way!") # admin @@ -84,7 +86,9 @@ describe "When viewing requests" do admin_user = login(:admin_user) admin_user.browses_request('why_do_you_have_such_a_fancy_dog') admin_user.response.body.should include('No way!') - admin_user.response.body.should include("This message has prominence \'hidden\'. It is too irritating. You can only see it because you are logged in as a super user.") + admin_user.response.body.should include("This message has prominence \'hidden\'.") + admin_user.response.body.should include("It is too irritating.") + admin_user.response.body.should include("You can only see it because you are logged in as a super user.") end @@ -105,7 +109,8 @@ describe "When viewing requests" do # unregistered unregistered = without_login unregistered.browses_request('why_do_you_have_such_a_fancy_dog') - unregistered.response.body.should include("This message has been hidden. It is too irritating") + unregistered.response.body.should include("This message has been hidden.") + unregistered.response.body.should include("It is too irritating") unregistered.response.body.should include("sign in to view the message.") unregistered.response.body.should_not include("No way!") @@ -113,7 +118,8 @@ describe "When viewing requests" do bob = login(:bob_smith_user) bob.browses_request('why_do_you_have_such_a_fancy_dog') bob.response.body.should include("No way!") - bob.response.body.should include("This message is hidden, so that only you, the requester, can see it. It is too irritating.") + bob.response.body.should include("This message is hidden, so that only you, the requester, can see it.") + bob.response.body.should include("It is too irritating.") # admin confirm(:admin_user) -- cgit v1.2.3 From b8ac4f8b21fecc003512ae19898018b13959f6e4 Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Mon, 16 Sep 2013 12:42:45 +0100 Subject: Convert specs to factories from fixtures. Conflicts: spec/integration/view_request_spec.rb --- spec/integration/view_request_spec.rb | 100 ++++++++++++++++------------------ 1 file changed, 48 insertions(+), 52 deletions(-) (limited to 'spec/integration/view_request_spec.rb') diff --git a/spec/integration/view_request_spec.rb b/spec/integration/view_request_spec.rb index 2de961200..e79937bef 100644 --- a/spec/integration/view_request_spec.rb +++ b/spec/integration/view_request_spec.rb @@ -3,51 +3,47 @@ require File.expand_path(File.dirname(__FILE__) + '/alaveteli_dsl') describe "When viewing requests" do - before(:each) do - load_raw_emails_data + before do + @info_request = FactoryGirl.create(:info_request) + @unregistered = without_login end it "should not make endlessly recursive JSON s" do - unregistered = without_login - unregistered.browses_request('why_do_you_have_such_a_fancy_dog?unfold=1') - unregistered.response.body.should_not include("dog?unfold=1.json") - unregistered.response.body.should include("dog.json?unfold=1") + @unregistered.browses_request("#{@info_request.url_title}?unfold=1") + @unregistered.response.body.should_not include("#{@info_request.url_title}?unfold=1.json") + @unregistered.response.body.should include("#{@info_request.url_title}.json?unfold=1") end it 'should not raise a routing error when making a json link for a request with an "action" querystring param' do - unregistered = without_login - unregistered.browses_request('why_do_you_have_such_a_fancy_dog?action=add') + @unregistered.browses_request("#{@info_request.url_title}?action=add") end context 'when a response has prominence "normal"' do before do - useless_message = incoming_messages(:useless_incoming_message) - useless_message.prominence = 'normal' - useless_message.save! + @info_request = FactoryGirl.create(:info_request_with_incoming) end it 'should show the message itself to any user' do # unregistered unregistered = without_login - unregistered.browses_request('why_do_you_have_such_a_fancy_dog') - unregistered.response.body.should include("No way!") + unregistered.browses_request(@info_request.url_title) + unregistered.response.body.should include("hereisthetext") unregistered.response.body.should_not include("This message has been hidden.") unregistered.response.body.should_not include("sign in to view the message.") # requester - bob = login(:bob_smith_user) - bob.browses_request('why_do_you_have_such_a_fancy_dog') - bob.response.body.should include("No way!") - bob.response.body.should_not include("This message has been hidden.") + owner = login(@info_request.user) + owner.browses_request(@info_request.url_title) + owner.response.body.should include("hereisthetext") + owner.response.body.should_not include("This message has been hidden.") # admin - confirm(:admin_user) - admin_user = login(:admin_user) - admin_user.browses_request('why_do_you_have_such_a_fancy_dog') - admin_user.response.body.should include('No way!') + admin_user = login(FactoryGirl.create(:admin_user)) + admin_user.browses_request(@info_request.url_title) + admin_user.response.body.should include("hereisthetext") admin_user.response.body.should_not include("This message has prominence \'hidden\'.") end @@ -57,10 +53,11 @@ describe "When viewing requests" do context 'when a response has prominence "hidden"' do before do - useless_message = incoming_messages(:useless_incoming_message) - useless_message.prominence = 'hidden' - useless_message.prominence_reason = 'It is too irritating.' - useless_message.save! + @info_request = FactoryGirl.create(:info_request_with_incoming) + message = @info_request.incoming_messages.first + message.prominence = 'hidden' + message.prominence_reason = 'It is too irritating.' + message.save! end it 'should show a hidden notice, not the message, to an unregistered user or the requester and @@ -68,24 +65,23 @@ describe "When viewing requests" do # unregistered unregistered = without_login - unregistered.browses_request('why_do_you_have_such_a_fancy_dog') + unregistered.browses_request(@info_request.url_title) unregistered.response.body.should include("This message has been hidden.") unregistered.response.body.should include("It is too irritating.") unregistered.response.body.should_not include("sign in to view the message.") - unregistered.response.body.should_not include("No way!") + unregistered.response.body.should_not include("hereisthetext") # requester - bob = login(:bob_smith_user) - bob.browses_request('why_do_you_have_such_a_fancy_dog') - bob.response.body.should include("This message has been hidden.") - bob.response.body.should include("It is too irritating") - bob.response.body.should_not include("No way!") + owner = login(@info_request.user) + owner.browses_request(@info_request.url_title) + owner.response.body.should include("This message has been hidden.") + owner.response.body.should include("It is too irritating") + owner.response.body.should_not include("hereisthetext") # admin - confirm(:admin_user) - admin_user = login(:admin_user) - admin_user.browses_request('why_do_you_have_such_a_fancy_dog') - admin_user.response.body.should include('No way!') + admin_user = login(FactoryGirl.create(:admin_user)) + admin_user.browses_request(@info_request.url_title) + admin_user.response.body.should include('hereisthetext') admin_user.response.body.should include("This message has prominence \'hidden\'.") admin_user.response.body.should include("It is too irritating.") admin_user.response.body.should include("You can only see it because you are logged in as a super user.") @@ -94,13 +90,14 @@ describe "When viewing requests" do end - context 'when as response has prominence "requester_only"' do + context 'when a response has prominence "requester_only"' do before do - useless_message = incoming_messages(:useless_incoming_message) - useless_message.prominence = 'requester_only' - useless_message.prominence_reason = 'It is too irritating.' - useless_message.save! + @info_request = FactoryGirl.create(:info_request_with_incoming) + message = @info_request.incoming_messages.first + message.prominence = 'requester_only' + message.prominence_reason = 'It is too irritating.' + message.save! end it 'should show a hidden notice with login link to an unregistered user, and the message itself @@ -108,24 +105,23 @@ describe "When viewing requests" do # unregistered unregistered = without_login - unregistered.browses_request('why_do_you_have_such_a_fancy_dog') + unregistered.browses_request(@info_request.url_title) unregistered.response.body.should include("This message has been hidden.") unregistered.response.body.should include("It is too irritating") unregistered.response.body.should include("sign in to view the message.") - unregistered.response.body.should_not include("No way!") + unregistered.response.body.should_not include("hereisthetext") # requester - bob = login(:bob_smith_user) - bob.browses_request('why_do_you_have_such_a_fancy_dog') - bob.response.body.should include("No way!") - bob.response.body.should include("This message is hidden, so that only you, the requester, can see it.") - bob.response.body.should include("It is too irritating.") + owner = login(@info_request.user) + owner.browses_request(@info_request.url_title) + owner.response.body.should include("hereisthetext") + owner.response.body.should include("This message is hidden, so that only you, the requester, can see it.") + owner.response.body.should include("It is too irritating.") # admin - confirm(:admin_user) - admin_user = login(:admin_user) - admin_user.browses_request('why_do_you_have_such_a_fancy_dog') - admin_user.response.body.should include('No way!') + admin_user = login(FactoryGirl.create(:admin_user)) + admin_user.browses_request(@info_request.url_title) + admin_user.response.body.should include('hereisthetext') admin_user.response.body.should_not include("This message has been hidden.") admin_user.response.body.should include("This message is hidden, so that only you, the requester, can see it.") end -- cgit v1.2.3 From c510b25ff93d2fc0ec597891dbd9315b4b325bf2 Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Mon, 16 Sep 2013 12:21:03 +0100 Subject: Add hidden messages for outgoing message. Conflicts: app/views/request/_incoming_correspondence.html.erb --- spec/integration/view_request_spec.rb | 38 +++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'spec/integration/view_request_spec.rb') diff --git a/spec/integration/view_request_spec.rb b/spec/integration/view_request_spec.rb index e79937bef..814e20fb3 100644 --- a/spec/integration/view_request_spec.rb +++ b/spec/integration/view_request_spec.rb @@ -128,5 +128,43 @@ describe "When viewing requests" do end + context 'when an outgoing message has prominence "requester_only"' do + + before do + @info_request = FactoryGirl.create(:info_request) + message = @info_request.outgoing_messages.first + message.prominence = 'requester_only' + message.prominence_reason = 'It is too irritating.' + message.save! + end + + it 'should show a hidden notice with login link to an unregistered user, and the message itself + with a hidden note to the requester or an admin' do + + # unregistered + unregistered = without_login + unregistered.browses_request(@info_request.url_title) + unregistered.response.body.should include("This message has been hidden.") + unregistered.response.body.should include("It is too irritating") + unregistered.response.body.should include("sign in to view the message.") + unregistered.response.body.should_not include("Some information please") + + # requester + owner = login(@info_request.user) + owner.browses_request(@info_request.url_title) + owner.response.body.should include("Some information please") + owner.response.body.should include("This message is hidden, so that only you, the requester, can see it.") + owner.response.body.should include("It is too irritating.") + + # admin + admin_user = login(FactoryGirl.create(:admin_user)) + admin_user.browses_request(@info_request.url_title) + admin_user.response.body.should include('Some information please') + admin_user.response.body.should_not include("This message has been hidden.") + admin_user.response.body.should include("This message is hidden, so that only you, the requester, can see it.") + end + + end + end -- cgit v1.2.3