aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/admin_censor_rule_controller_spec.rb10
-rw-r--r--spec/controllers/public_body_controller_spec.rb5
-rw-r--r--spec/controllers/request_controller_spec.rb105
-rw-r--r--spec/controllers/track_controller_spec.rb3
-rw-r--r--spec/fixtures/files/incoming-request-empty.email8
-rw-r--r--spec/fixtures/info_request_events.yml11
-rw-r--r--spec/fixtures/info_requests.yml12
-rw-r--r--spec/fixtures/locale/en/app.po4
-rw-r--r--spec/fixtures/locale/en_GB/app.po4
-rw-r--r--spec/fixtures/locale/es/app.po6
-rw-r--r--spec/fixtures/outgoing_messages.yml11
-rw-r--r--spec/fixtures/public_bodies.yml15
-rw-r--r--spec/fixtures/public_body_translations.yml13
-rw-r--r--spec/fixtures/users.yml22
-rw-r--r--spec/helpers/link_to_helper_spec.rb42
-rw-r--r--spec/integration/request_controller_spec.rb41
-rw-r--r--spec/lib/ability_spec.rb51
-rw-r--r--spec/models/info_request_spec.rb4
-rw-r--r--spec/models/purge_request_spec.rb9
-rw-r--r--spec/models/request_mailer_spec.rb23
-rw-r--r--spec/script/mailin_spec.rb22
-rw-r--r--spec/spec_helper.rb82
-rw-r--r--spec/views/public_body/show.rhtml_spec.rb5
-rw-r--r--spec/views/request/show.rhtml_spec.rb4
24 files changed, 337 insertions, 175 deletions
diff --git a/spec/controllers/admin_censor_rule_controller_spec.rb b/spec/controllers/admin_censor_rule_controller_spec.rb
index 8893a858b..fb9ddf594 100644
--- a/spec/controllers/admin_censor_rule_controller_spec.rb
+++ b/spec/controllers/admin_censor_rule_controller_spec.rb
@@ -2,10 +2,14 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe AdminCensorRuleController, "when making censor rules from the admin interface" do
integrate_views
- before { basic_auth_login @request }
-
+ before do
+ basic_auth_login @request
+ PurgeRequest.destroy_all
+ end
+
+
it "should create a censor rule and purge the corresponding request from varnish" do
- ir = info_requests(:fancy_dog_request)
+ ir = info_requests(:fancy_dog_request)
post :create, :censor_rule => {
:text => "meat",
:replacement => "tofu",
diff --git a/spec/controllers/public_body_controller_spec.rb b/spec/controllers/public_body_controller_spec.rb
index 29ece18cb..5f4012737 100644
--- a/spec/controllers/public_body_controller_spec.rb
+++ b/spec/controllers/public_body_controller_spec.rb
@@ -67,6 +67,11 @@ describe PublicBodyController, "when showing a body" do
ActionController::Routing::Routes.filters = old_filters
end
+ it "should remember the filter (view) setting on redirecting" do
+ get :show, :show_locale => "es", :url_name => "tgq", :view => 'successful'
+ response.should redirect_to show_public_body_successful_url(:url_name => "etgq")
+ end
+
it "should redirect to newest name if you use historic name of public body in URL" do
get :show, :url_name => "hdink", :view => 'all'
response.should redirect_to(:controller => 'public_body', :action => 'show', :url_name => "dfh")
diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb
index 6f25b605a..672c2c361 100644
--- a/spec/controllers/request_controller_spec.rb
+++ b/spec/controllers/request_controller_spec.rb
@@ -121,7 +121,9 @@ end
describe RequestController, "when changing things that appear on the request page" do
- integrate_views
+ before do
+ PurgeRequest.destroy_all
+ end
it "should purge the downstream cache when mail is received" do
ir = info_requests(:fancy_dog_request)
@@ -1248,8 +1250,7 @@ describe RequestController, "when classifying an information request" do
end
it 'should redirect to the request page' do
- post :describe_state, :id => @external_request.id,
- :submitted_describe_state => 1
+ post :describe_state, :id => @external_request.id
response.should redirect_to(:action => 'show',
:controller => 'request',
:url_title => @external_request.url_title)
@@ -1269,8 +1270,7 @@ describe RequestController, "when classifying an information request" do
def post_status(status)
post :describe_state, :incoming_message => { :described_state => status },
:id => @dog_request.id,
- :last_info_request_event_id => @dog_request.last_event_id_needing_description,
- :submitted_describe_state => 1
+ :last_info_request_event_id => @dog_request.last_event_id_needing_description
end
it "should require login" do
@@ -1280,6 +1280,7 @@ describe RequestController, "when classifying an information request" do
end
it 'should ask whether the request is old and unclassified' do
+ session[:user_id] = users(:silly_name_user).id
@dog_request.should_receive(:is_old_unclassified?)
post_status('rejected')
end
@@ -1317,7 +1318,7 @@ describe RequestController, "when classifying an information request" do
it 'should classify the request' do
@dog_request.stub!(:calculate_status).and_return('rejected')
- @dog_request.should_receive(:set_described_state).with('rejected')
+ @dog_request.should_receive(:set_described_state).with('rejected', users(:silly_name_user), nil)
post_status('rejected')
end
@@ -1345,6 +1346,26 @@ describe RequestController, "when classifying an information request" do
flash[:notice].should == 'Thank you for updating this request!'
end
+ context "playing the classification game" do
+ before :each do
+ session[:request_game] = true
+ end
+
+ it "should continue the game after classifying a request" do
+ post_status("rejected")
+ flash[:notice].should =~ /There are some more requests below for you to classify/
+ response.should redirect_to categorise_play_url
+ end
+ end
+
+ it "should send a mail from the user who changed the state to requires_admin" do
+ post :describe_state, :incoming_message => { :described_state => "requires_admin", :message => "a message" }, :id => @dog_request.id, :incoming_message_id => incoming_messages(:useless_incoming_message), :last_info_request_event_id => @dog_request.last_event_id_needing_description
+
+ deliveries = ActionMailer::Base.deliveries
+ deliveries.size.should == 1
+ mail = deliveries[0]
+ mail.from_addrs.first.to_s.should == users(:silly_name_user).name_and_email
+ end
end
end
@@ -1360,7 +1381,7 @@ describe RequestController, "when classifying an information request" do
it 'should update the status of the request' do
@dog_request.stub!(:calculate_status).and_return('rejected')
- @dog_request.should_receive(:set_described_state).with('rejected')
+ @dog_request.should_receive(:set_described_state).with('rejected', @admin_user, nil)
post_status('rejected')
end
@@ -1411,7 +1432,7 @@ describe RequestController, "when classifying an information request" do
it 'should update the status of the request' do
@dog_request.stub!(:calculate_status).and_return('rejected')
- @dog_request.should_receive(:set_described_state).with('rejected')
+ @dog_request.should_receive(:set_described_state).with('rejected', @admin_user, nil)
post_status('rejected')
end
@@ -1446,6 +1467,22 @@ describe RequestController, "when classifying an information request" do
@dog_request.stub!(:each).and_return([@dog_request])
end
+ it "should let you know when you forget to select a status" do
+ post :describe_state, :id => @dog_request.id,
+ :last_info_request_event_id => @dog_request.last_event_id_needing_description
+ response.should redirect_to show_request_url(:url_title => @dog_request.url_title)
+ flash[:error].should == _("Please choose whether or not you got some of the information that you wanted.")
+ end
+
+ it "should not change the status if the request has changed while viewing it" do
+ @dog_request.stub!(:last_event_id_needing_description).and_return(2)
+
+ post :describe_state, :incoming_message => { :described_state => "rejected" },
+ :id => @dog_request.id, :last_info_request_event_id => 1
+ response.should redirect_to show_request_url(:url_title => @dog_request.url_title)
+ flash[:error].should =~ /The request has been updated since you originally loaded this page/
+ end
+
it "should successfully classify response if logged in as user controlling request" do
post_status('rejected')
response.should redirect_to(:controller => 'help', :action => 'unhappy', :url_title => @dog_request.url_title)
@@ -1466,22 +1503,34 @@ describe RequestController, "when classifying an information request" do
post_status('rejected')
end
- it "should send email when classified as requires_admin" do
- post :describe_state, :incoming_message => { :described_state => "requires_admin" }, :id => @dog_request.id, :incoming_message_id => incoming_messages(:useless_incoming_message), :last_info_request_event_id => @dog_request.last_event_id_needing_description, :submitted_describe_state => 1
- response.should redirect_to(:controller => 'help', :action => 'contact')
+ it "should go to the page asking for more information when classified as requires_admin" do
+ post :describe_state, :incoming_message => { :described_state => "requires_admin" }, :id => @dog_request.id, :incoming_message_id => incoming_messages(:useless_incoming_message), :last_info_request_event_id => @dog_request.last_event_id_needing_description
+ response.should redirect_to describe_state_message_url(:url_title => @dog_request.url_title, :described_state => "requires_admin")
@dog_request.reload
- @dog_request.awaiting_description.should == false
- @dog_request.described_state.should == 'requires_admin'
- @dog_request.get_last_response_event.calculated_state.should == 'requires_admin'
+ @dog_request.described_state.should_not == 'requires_admin'
- deliveries = ActionMailer::Base.deliveries
- deliveries.size.should == 1
- mail = deliveries[0]
- mail.body.should =~ /as needing admin/
- mail.from_addrs.first.to_s.should == @request_owner.name_and_email
+ ActionMailer::Base.deliveries.should be_empty
end
+ context "message is included when classifying as requires_admin" do
+ it "should send an email including the message" do
+ post :describe_state,
+ :incoming_message => {
+ :described_state => "requires_admin",
+ :message => "Something weird happened" },
+ :id => @dog_request.id,
+ :last_info_request_event_id => @dog_request.last_event_id_needing_description
+
+ deliveries = ActionMailer::Base.deliveries
+ deliveries.size.should == 1
+ mail = deliveries[0]
+ mail.body.should =~ /as needing admin/
+ mail.body.should =~ /Something weird happened/
+ end
+ end
+
+
it 'should say it is showing advice as to what to do next' do
post_status('rejected')
flash[:notice].should match(/Here is what to do now/)
@@ -1592,12 +1641,22 @@ describe RequestController, "when classifying an information request" do
expect_redirect('internal_review', request_url)
end
- it 'should redirect to the "help general url" when status is updated to "requires admin"' do
- expect_redirect('requires_admin', "help/contact")
+ it 'should redirect to the "request url" when status is updated to "requires admin"' do
+ post :describe_state, :incoming_message => {
+ :described_state => 'requires_admin',
+ :message => "A message" },
+ :id => @dog_request.id,
+ :last_info_request_event_id => @dog_request.last_event_id_needing_description
+ response.should redirect_to show_request_url(:url_title => @dog_request.url_title)
end
- it 'should redirect to the "help general url" when status is updated to "error message"' do
- expect_redirect('error_message', "help/contact")
+ it 'should redirect to the "request url" when status is updated to "error message"' do
+ post :describe_state, :incoming_message => {
+ :described_state => 'error_message',
+ :message => "A message" },
+ :id => @dog_request.id,
+ :last_info_request_event_id => @dog_request.last_event_id_needing_description
+ response.should redirect_to show_request_url(:url_title => @dog_request.url_title)
end
it 'should redirect to the "respond to last url url" when status is updated to "user_withdrawn"' do
diff --git a/spec/controllers/track_controller_spec.rb b/spec/controllers/track_controller_spec.rb
index c785960b5..5505afe59 100644
--- a/spec/controllers/track_controller_spec.rb
+++ b/spec/controllers/track_controller_spec.rb
@@ -57,7 +57,6 @@ end
describe TrackController, "when sending alerts for a track" do
integrate_views
- include LinkToHelper # for main_url
before(:each) do
load_raw_emails_data
@@ -105,7 +104,7 @@ describe TrackController, "when sending alerts for a track" do
# Given we can't click the link, check the token is right instead
post_redirect = PostRedirect.find_by_email_token(mail_token)
- expected_url = main_url("/user/" + users(:silly_name_user).url_name + "#email_subscriptions") # XXX can't call URL making functions here, what is correct way to do this?
+ expected_url = show_user_url(:url_name => users(:silly_name_user).url_name, :anchor => "email_subscriptions")
post_redirect.uri.should == expected_url
# Check nothing more is delivered if we try again
diff --git a/spec/fixtures/files/incoming-request-empty.email b/spec/fixtures/files/incoming-request-empty.email
new file mode 100644
index 000000000..890a14f21
--- /dev/null
+++ b/spec/fixtures/files/incoming-request-empty.email
@@ -0,0 +1,8 @@
+From: EMAIL_FROM
+To: FOI Person <EMAIL_TO>
+Bcc:
+Subject: Re: Nothing to see here.
+Reply-To:
+In-Reply-To: <471f1eae5d1cb_7347..fdbe67386163@cat.tmail>
+
+
diff --git a/spec/fixtures/info_request_events.yml b/spec/fixtures/info_request_events.yml
index c1a00ad47..3907703d8 100644
--- a/spec/fixtures/info_request_events.yml
+++ b/spec/fixtures/info_request_events.yml
@@ -171,3 +171,14 @@ anonymous_external_outgoing_message_event:
created_at: 2009-01-03 02:23:45.6789100
described_state: waiting_response
calculated_state: waiting_response
+
+other_request_outgoing_message_event:
+ id: 916
+ params_yaml: "--- \n\
+ :outgoing_message_id: 10\n"
+ outgoing_message_id: 10
+ info_request_id: 111
+ event_type: sent
+ created_at: <%= Time.now %>
+ described_state: waiting_response
+ calculated_state: waiting_response
diff --git a/spec/fixtures/info_requests.yml b/spec/fixtures/info_requests.yml
index 9361ec486..97effd036 100644
--- a/spec/fixtures/info_requests.yml
+++ b/spec/fixtures/info_requests.yml
@@ -107,3 +107,15 @@ anonymous_external_request:
awaiting_description: false
comments_allowed: true
idhash: 7654321a
+other_request:
+ id: 111
+ title: Another request
+ url_title: another_request
+ created_at: 2010-01-01 02:23:45.6789100
+ updated_at: 2010-01-01 02:23:45.6789100
+ public_body_id: 7
+ user_id: 6
+ described_state: waiting_response
+ awaiting_description: false
+ comments_allowed: true
+ idhash: b234567
diff --git a/spec/fixtures/locale/en/app.po b/spec/fixtures/locale/en/app.po
index 91af9b72b..3fe8a569b 100644
--- a/spec/fixtures/locale/en/app.po
+++ b/spec/fixtures/locale/en/app.po
@@ -950,14 +950,14 @@ msgstr ""
#: app/views/request/new.rhtml:128
msgid ""
-"Everything that you enter on this page \n"
+"Everything that you enter on this page\n"
" will be <strong>displayed publicly</strong> on\n"
" this website forever (<a href=\"%s\">why?</a>)."
msgstr ""
#: app/views/request/new.rhtml:120
msgid ""
-"Everything that you enter on this page, including <strong>your name</strong>, \n"
+"Everything that you enter on this page, including <strong>your name</strong>,\n"
" will be <strong>displayed publicly</strong> on\n"
" this website forever (<a href=\"%s\">why?</a>)."
msgstr ""
diff --git a/spec/fixtures/locale/en_GB/app.po b/spec/fixtures/locale/en_GB/app.po
index 91af9b72b..3fe8a569b 100644
--- a/spec/fixtures/locale/en_GB/app.po
+++ b/spec/fixtures/locale/en_GB/app.po
@@ -950,14 +950,14 @@ msgstr ""
#: app/views/request/new.rhtml:128
msgid ""
-"Everything that you enter on this page \n"
+"Everything that you enter on this page\n"
" will be <strong>displayed publicly</strong> on\n"
" this website forever (<a href=\"%s\">why?</a>)."
msgstr ""
#: app/views/request/new.rhtml:120
msgid ""
-"Everything that you enter on this page, including <strong>your name</strong>, \n"
+"Everything that you enter on this page, including <strong>your name</strong>,\n"
" will be <strong>displayed publicly</strong> on\n"
" this website forever (<a href=\"%s\">why?</a>)."
msgstr ""
diff --git a/spec/fixtures/locale/es/app.po b/spec/fixtures/locale/es/app.po
index 4e54a1d40..dbc7ab65b 100644
--- a/spec/fixtures/locale/es/app.po
+++ b/spec/fixtures/locale/es/app.po
@@ -1,7 +1,7 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
-#
+#
# Translators:
# David Cabo <david.cabo@gmail.com>, 2011, 2012.
# skenaja <alex@alexskene.com>, 2011.
@@ -1066,14 +1066,14 @@ msgstr "Historial de eventos"
#: app/views/request/new.rhtml:128
msgid ""
-"Everything that you enter on this page \n"
+"Everything that you enter on this page\n"
" will be <strong>displayed publicly</strong> on\n"
" this website forever (<a href=\"%s\">why?</a>)."
msgstr "Todo lo que escriba en esta página \n estará <strong>disponible públicamente</strong> en\n está web para siempre (<a href=\"%s\">¿por qué?</a>)."
#: app/views/request/new.rhtml:120
msgid ""
-"Everything that you enter on this page, including <strong>your name</strong>, \n"
+"Everything that you enter on this page, including <strong>your name</strong>,\n"
" will be <strong>displayed publicly</strong> on\n"
" this website forever (<a href=\"%s\">why?</a>)."
msgstr "Todo lo que escribas en esta página, incluyendo <strong>tu nombre</strong>, \n estará <strong>disponible públicamente</strong> en\n está web para siempre (<a href=\"%s\">¿por qué?</a>)."
diff --git a/spec/fixtures/outgoing_messages.yml b/spec/fixtures/outgoing_messages.yml
index 55df8473e..c71ee08bf 100644
--- a/spec/fixtures/outgoing_messages.yml
+++ b/spec/fixtures/outgoing_messages.yml
@@ -108,3 +108,14 @@ anonymous_external_outgoing_message:
updated_at: 2009-01-12 01:56:58.586598
what_doing: normal_sort
+other_outgoing_message:
+ id: 10
+ info_request_id: 111
+ message_type: initial_request
+ status: sent
+ body: "Just another request"
+ last_sent_at: <%= Time.now %>
+ created_at: 2009-01-12 01:56:58.586598
+ updated_at: 2009-01-12 01:56:58.586598
+ what_doing: normal_sort
+
diff --git a/spec/fixtures/public_bodies.yml b/spec/fixtures/public_bodies.yml
index 615c4bcb6..65cba4b28 100644
--- a/spec/fixtures/public_bodies.yml
+++ b/spec/fixtures/public_bodies.yml
@@ -72,3 +72,18 @@ sensible_walks_public_body:
created_at: 2008-10-25 10:51:01.161639
api_key: 5
info_requests_count: 1
+other_public_body:
+ id: 7
+ version: 1
+ name: 'Another Public Body'
+ first_letter: A
+ request_email: other@localhost
+ short_name: Another Public Body
+ url_name: another_public_body
+ notes: More notes
+ updated_at: 2008-10-25 10:51:01.161639
+ last_edit_comment: Another edit
+ last_edit_editor: louise
+ created_at: 2008-10-25 10:51:01.161639
+ api_key: 6
+ info_requests_count: 0
diff --git a/spec/fixtures/public_body_translations.yml b/spec/fixtures/public_body_translations.yml
index 24b14c470..61e07fb5b 100644
--- a/spec/fixtures/public_body_translations.yml
+++ b/spec/fixtures/public_body_translations.yml
@@ -88,3 +88,16 @@ sensible_walks_en_public_body_translation:
notes: I bet you’ve never heard of it.
publication_scheme: ""
disclosure_log: ""
+
+other_public_body_translation:
+ id: 8
+ public_body_id: 7
+ locale: en
+ name: "Another Public Body"
+ first_letter: A
+ request_email: other@localhost
+ short_name: Another Public Body
+ url_name: another_public_body
+ notes: More notes
+ publication_scheme: ""
+ disclosure_log: ""
diff --git a/spec/fixtures/users.yml b/spec/fixtures/users.yml
index d6391c5e8..c9730d855 100644
--- a/spec/fixtures/users.yml
+++ b/spec/fixtures/users.yml
@@ -1,4 +1,4 @@
-bob_smith_user:
+bob_smith_user:
id: "1"
name: Bob Smith
url_name: bob_smith
@@ -13,7 +13,7 @@ bob_smith_user:
locale: 'en'
about_me: 'I like making requests about fancy dogs and naughty chickens and stuff.'
receive_email_alerts: true
-silly_name_user:
+silly_name_user:
id: "2"
name: "Silly <em>Name</em>"
url_name: silly_emnameem
@@ -28,7 +28,7 @@ silly_name_user:
locale: 'en'
about_me: ''
receive_email_alerts: true
-admin_user:
+admin_user:
id: "3"
name: Joe Admin
url_name: joe_admin
@@ -43,7 +43,7 @@ admin_user:
locale: ''
about_me: ''
receive_email_alerts: true
-unconfirmed_user:
+unconfirmed_user:
id: "4"
name: "Unconfirmed"
url_name: unconfirmed
@@ -71,3 +71,17 @@ robin_user:
ban_text: ''
about_me: 'I am the best'
receive_email_alerts: true
+another_user:
+ id: 6
+ name: Another User
+ url_name: another_user
+ email: another@localhost
+ salt: "-6116981980.392287733335677"
+ hashed_password: 6b7cd45a5f35fd83febc0452a799530398bfb6e8 # jonespassword
+ updated_at: 2012-01-01 10:39:15.491593
+ created_at: 2012-01-01 10:39:15.491593
+ email_confirmed: true
+ admin_level: 'none'
+ ban_text: ''
+ about_me: 'Just another user'
+ receive_email_alerts: true
diff --git a/spec/helpers/link_to_helper_spec.rb b/spec/helpers/link_to_helper_spec.rb
index 030fd612d..3e997f9f9 100644
--- a/spec/helpers/link_to_helper_spec.rb
+++ b/spec/helpers/link_to_helper_spec.rb
@@ -17,27 +17,15 @@ describe LinkToHelper do
it 'should return a path like /request/test_title' do
- request_url(@mock_request).should == '/request/test_title'
+ request_path(@mock_request).should == '/request/test_title'
end
it 'should return a path including any extra parameters passed' do
- request_url(@mock_request, {:update_status => 1}).should == '/request/test_title?update_status=1'
+ request_path(@mock_request, {:update_status => 1}).should == '/request/test_title?update_status=1'
end
end
- describe "when appending something to a URL" do
- it 'should append to things without query strings' do
- main_url('/a', '.json').should == 'http://test.host/a.json'
- end
- it 'should append to things with query strings' do
- main_url('/a?z=1', '.json').should == 'http://test.host/a.json?z=1'
- end
- it 'should fail silently with invalid URLs' do
- main_url('/a?z=9%', '.json').should == 'http://test.host/a?z=9%'
- end
- end
-
describe 'when displaying a user admin link for a request' do
it 'should return the text "An anonymous user (external)" in the case where there is no external username' do
@@ -48,32 +36,6 @@ describe LinkToHelper do
end
- describe 'admin_url' do
- context 'with no ADMIN_BASE_URL set' do
- it 'should prepend the admin general index path to a simple string' do
- admin_url('unclassified').should == 'http://test.host/en/admin/unclassified'
- end
-
- it 'should prepend the admin general index path to a deeper URL' do
- admin_url('request/show/123').should == 'http://test.host/en/admin/request/show/123'
- end
- end
-
- context 'with ADMIN_BASE_URL set' do
- before(:each) do
- Configuration::should_receive(:admin_base_url).and_return('https://www.example.com/secure/alaveteli-admin/')
- end
-
- it 'should prepend the admin base URL to a simple string' do
- admin_url('unclassified').should == 'https://www.example.com/secure/alaveteli-admin/unclassified'
- end
-
- it 'should prepend the admin base URL to a deeper URL' do
- admin_url('request/show/123').should == 'https://www.example.com/secure/alaveteli-admin/request/show/123'
- end
- end
- end
-
describe 'simple_date' do
it 'should respect time zones' do
Time.use_zone('Australia/Sydney') do
diff --git a/spec/integration/request_controller_spec.rb b/spec/integration/request_controller_spec.rb
new file mode 100644
index 000000000..24667bdf1
--- /dev/null
+++ b/spec/integration/request_controller_spec.rb
@@ -0,0 +1,41 @@
+# -*- coding: utf-8 -*-
+require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
+
+describe RequestController, "when classifying an information request" do
+
+ describe 'when the request is internal' do
+
+ before(:each) do
+ @dog_request = info_requests(:fancy_dog_request)
+ # This should happen automatically before each test but doesn't with these integration
+ # tests for some reason.
+ ActionMailer::Base.deliveries = []
+ end
+
+ describe 'when logged in as the requestor' do
+
+ before :each do
+ @request_owner = @dog_request.user
+ visit signin_path
+ fill_in "Your e-mail:", :with => @request_owner.email
+ fill_in "Password:", :with => "jonespassword"
+ click_button "Sign in"
+ end
+
+ it "should send an email including the message" do
+ visit describe_state_message_path(:url_title => @dog_request.url_title,
+ :described_state => "requires_admin")
+ fill_in "Please tell us more:", :with => "Okay. I don't quite understand."
+ click_button "Submit status and send message"
+
+ response.should contain "Thank you! We'll look into what happened and try and fix it up."
+
+ deliveries = ActionMailer::Base.deliveries
+ deliveries.size.should == 1
+ mail = deliveries[0]
+ mail.body.should =~ /as needing admin/
+ mail.body.should =~ /Okay. I don't quite understand./
+ end
+ end
+ end
+end
diff --git a/spec/lib/ability_spec.rb b/spec/lib/ability_spec.rb
new file mode 100644
index 000000000..f075d0f32
--- /dev/null
+++ b/spec/lib/ability_spec.rb
@@ -0,0 +1,51 @@
+require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
+
+describe Ability do
+ describe ".can_update_request_state?" do
+ context "old and unclassified request" do
+ let(:request) { mock_model(InfoRequest, :is_old_unclassified? => true) }
+
+ context "logged out" do
+ let(:user) { nil }
+ before(:each) { request.stub!(:is_owning_user?).and_return(false) }
+ it { Ability::can_update_request_state?(user, request).should be_false }
+ end
+
+ context "logged in but not owner of request" do
+ let(:user) { mock_model(User) }
+ before(:each) { request.stub!(:is_owning_user?).and_return(false) }
+
+ it { Ability::can_update_request_state?(user, request).should be_true }
+ end
+ end
+
+ context "new request" do
+ let(:request) { mock_model(InfoRequest, :is_old_unclassified? => false) }
+
+ context "logged out" do
+ let(:user) { nil }
+ before(:each) { request.stub!(:is_owning_user?).and_return(false) }
+
+ it { Ability::can_update_request_state?(user, request).should be_false }
+ end
+
+ context "logged in" do
+ let(:user) { mock_model(User) }
+
+ # An owner of a request can also be someone with admin powers
+ context "as owner of request" do
+ before(:each) { request.stub!(:is_owning_user?).and_return(true) }
+
+ it { Ability::can_update_request_state?(user, request).should be_true }
+ end
+
+ context "but not owner of request" do
+ before(:each) { request.stub!(:is_owning_user?).and_return(false) }
+
+ it { Ability::can_update_request_state?(user, request).should be_false }
+ end
+ end
+ end
+ end
+end
+
diff --git a/spec/models/info_request_spec.rb b/spec/models/info_request_spec.rb
index 544852f91..728a538f9 100644
--- a/spec/models/info_request_spec.rb
+++ b/spec/models/info_request_spec.rb
@@ -426,8 +426,8 @@ describe InfoRequest do
before do
Time.stub!(:now).and_return(Time.utc(2007, 11, 9, 23, 59))
- @mock_comment_event = safe_mock_model(InfoRequestEvent, :created_at => Time.now - 23.days, :event_type => 'comment')
- @mock_response_event = safe_mock_model(InfoRequestEvent, :created_at => Time.now - 22.days, :event_type => 'response')
+ @mock_comment_event = safe_mock_model(InfoRequestEvent, :created_at => Time.now - 23.days, :event_type => 'comment', :response? => false)
+ @mock_response_event = safe_mock_model(InfoRequestEvent, :created_at => Time.now - 22.days, :event_type => 'response', :response? => true)
@info_request = InfoRequest.new(:prominence => 'normal',
:awaiting_description => true,
:info_request_events => [@mock_response_event, @mock_comment_event])
diff --git a/spec/models/purge_request_spec.rb b/spec/models/purge_request_spec.rb
index 94fe01317..7b67fca52 100644
--- a/spec/models/purge_request_spec.rb
+++ b/spec/models/purge_request_spec.rb
@@ -1,12 +1,13 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
require 'fakeweb'
-describe PurgeRequest, "purging things" do
+describe PurgeRequest, "purging things" do
before do
+ PurgeRequest.destroy_all
FakeWeb.last_request = nil
end
- it 'should issue purge requests to the server' do
+ it 'should issue purge requests to the server' do
req = PurgeRequest.new(:url => "/begone_from_here",
:model => "don't care",
:model_id => "don't care")
@@ -16,7 +17,7 @@ describe PurgeRequest, "purging things" do
PurgeRequest.all().count.should == 0
end
- it 'should fail silently for a misconfigured server' do
+ it 'should fail silently for a misconfigured server' do
FakeWeb.register_uri(:get, %r|brokenv|, :body => "BROKEN")
config = MySociety::Config.load_default()
config['VARNISH_HOST'] = "brokencache"
@@ -29,4 +30,4 @@ describe PurgeRequest, "purging things" do
PurgeRequest.all().count.should == 0
end
end
-
+
diff --git a/spec/models/request_mailer_spec.rb b/spec/models/request_mailer_spec.rb
index 20d401a63..40133eedc 100644
--- a/spec/models/request_mailer_spec.rb
+++ b/spec/models/request_mailer_spec.rb
@@ -1,3 +1,4 @@
+# encoding: utf-8
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe RequestMailer, " when receiving incoming mail" do
@@ -27,7 +28,7 @@ describe RequestMailer, " when receiving incoming mail" do
receive_incoming_mail('incoming-request-plain.email', 'dummy@localhost')
ir.incoming_messages.size.should == 1
InfoRequest.holding_pen_request.incoming_messages.size.should == 1
- last_event = InfoRequest.holding_pen_request.incoming_messages[0].info_request.get_last_event
+ last_event = InfoRequest.holding_pen_request.incoming_messages[0].info_request.info_request_events.last
last_event.params[:rejected_reason].should == "Could not identify the request from the email address"
deliveries = ActionMailer::Base.deliveries
@@ -47,7 +48,7 @@ describe RequestMailer, " when receiving incoming mail" do
receive_incoming_mail('incoming-request-plain.email', ir.incoming_email, "")
ir.incoming_messages.size.should == 1
InfoRequest.holding_pen_request.incoming_messages.size.should == 1
- last_event = InfoRequest.holding_pen_request.incoming_messages[0].info_request.get_last_event
+ last_event = InfoRequest.holding_pen_request.incoming_messages[0].info_request.info_request_events.last
last_event.params[:rejected_reason].should =~ /there is no "From" address/
deliveries = ActionMailer::Base.deliveries
@@ -67,7 +68,7 @@ describe RequestMailer, " when receiving incoming mail" do
receive_incoming_mail('incoming-request-plain.email', ir.incoming_email, "frob@nowhere.com")
ir.incoming_messages.size.should == 1
InfoRequest.holding_pen_request.incoming_messages.size.should == 1
- last_event = InfoRequest.holding_pen_request.incoming_messages[0].info_request.get_last_event
+ last_event = InfoRequest.holding_pen_request.incoming_messages[0].info_request.info_request_events.last
last_event.params[:rejected_reason].should =~ /Only the authority can reply/
deliveries = ActionMailer::Base.deliveries
@@ -152,7 +153,7 @@ describe RequestMailer, " when receiving incoming mail" do
receive_incoming_mail('incoming-request-plain.email', ir.incoming_email)
ir.incoming_messages.size.should == 1
InfoRequest.holding_pen_request.incoming_messages.size.should == 1 # arrives in holding pen
- last_event = InfoRequest.holding_pen_request.incoming_messages[0].info_request.get_last_event
+ last_event = InfoRequest.holding_pen_request.incoming_messages[0].info_request.info_request_events.last
last_event.params[:rejected_reason].should =~ /allow new responses from nobody/
# should be a message to admin regarding holding pen
@@ -366,15 +367,9 @@ describe RequestMailer, 'requires_admin' do
mail.body.should include('http://test.host/en/admin/request/show/123')
end
- context 'has an ADMIN_BASE_URL set' do
- before(:each) do
- Configuration::should_receive(:admin_base_url).and_return('http://our.proxy.server/admin/alaveteli/')
- end
-
- it 'body should contain the full admin URL' do
- mail = RequestMailer.deliver_requires_admin(@info_request)
-
- mail.body.should include('http://our.proxy.server/admin/alaveteli/request/show/123')
- end
+ it "body should contain the message from the user" do
+ mail = RequestMailer.deliver_requires_admin(@info_request, nil, "Something has gone wrong")
+ mail.body.should include 'Something has gone wrong'
end
+
end
diff --git a/spec/script/mailin_spec.rb b/spec/script/mailin_spec.rb
index d80789635..acd06ff3b 100644
--- a/spec/script/mailin_spec.rb
+++ b/spec/script/mailin_spec.rb
@@ -4,7 +4,11 @@ require "external_command"
def mailin_test(email_filename)
Dir.chdir Rails.root do
xc = ExternalCommand.new("script/mailin")
- xc.run(load_file_fixture(email_filename))
+ mail = load_file_fixture(email_filename)
+ ir = info_requests(:other_request)
+ mail.gsub!('EMAIL_TO', ir.incoming_email)
+ mail.gsub!('EMAIL_FROM', 'responder@localhost')
+ xc.run(mail)
xc.err.should == ""
return xc
end
@@ -12,10 +16,22 @@ end
describe "When importing mail into the application" do
+ # Turn off transactional fixtures for this suite - incoming message is imported
+ # outside the transaction via ExternalCommand, so needs to be destroyed outside the
+ # transaction
+ self.use_transactional_fixtures = false
+
it "should not produce any output and should return a 0 code on importing a plain email" do
- r = mailin_test("incoming-request-plain.email")
+ r = mailin_test("incoming-request-empty.email")
r.status.should == 0
r.out.should == ""
end
-end \ No newline at end of file
+ # Destroy the incoming message so that it doesn't affect other tests
+ after do
+ ir = info_requests(:other_request)
+ incoming_message = ir.incoming_messages[0]
+ incoming_message.fully_destroy
+ end
+
+end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 561a75da6..33e39e6e4 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -1,3 +1,16 @@
+require 'simplecov'
+require 'coveralls'
+
+# Generate coverage locally in html as well as in coveralls.io
+SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
+ SimpleCov::Formatter::HTMLFormatter,
+ Coveralls::SimpleCov::Formatter
+]
+SimpleCov.start('rails') do
+ add_filter 'commonlib'
+ add_filter 'vendor/plugins'
+end
+
# This file is copied to ~/spec when you run 'ruby script/generate rspec'
# from the project root directory.
ENV["RAILS_ENV"] = 'test'
@@ -17,8 +30,9 @@ config['REPLY_LATE_AFTER_DAYS'] = 20
require 'fakeweb'
FakeWeb.register_uri(:purge, %r|varnish.localdomain|, :body => "OK")
-# Uncomment the next line to use webrat's matchers
-#require 'webrat/integrations/rspec-rails'
+Webrat.configure do |config|
+ config.mode = :rails
+end
# Use test-specific translations
FastGettext.add_text_domain 'app', :path => File.join(File.dirname(__FILE__), 'fixtures', 'locale'), :type => :po
@@ -173,76 +187,12 @@ def get_fixtures_xapian_index()
ActsAsXapian.db_path = temp_path
end
-# Validate an entire HTML page
-def validate_html(html)
- $tempfilecount = $tempfilecount + 1
- tempfilename = File.join(Dir::tmpdir, "railshtmlvalidate."+$$.to_s+"."+$tempfilecount.to_s+".html")
- File.open(tempfilename, "w+") do |f|
- f.puts html
- end
- if not system($html_validation_script, *($html_validation_script_options +[tempfilename]))
- raise "HTML validation error in " + tempfilename + " HTTP status: " + @response.response_code.to_s
- end
- File.unlink(tempfilename)
- return true
-end
-
-# Validate HTML fragment by wrapping it as the <body> of a page
-def validate_as_body(html)
- validate_html('<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">' +
- "<html><head><title>Test</title></head><body>#{html}</body></html>")
-end
-
def basic_auth_login(request, username = nil, password = nil)
username = Configuration::admin_username if username.nil?
password = Configuration::admin_password if password.nil?
request.env["HTTP_AUTHORIZATION"] = "Basic " + Base64::encode64("#{username}:#{password}")
end
-# Monkeypatch! Validate HTML in tests.
-$html_validation_script_found = false
-Configuration::utility_search_path.each do |d|
- $html_validation_script = File.join(d, "validate")
- $html_validation_script_options = ["--charset=utf-8"]
- if File.file? $html_validation_script and File.executable? $html_validation_script
- $html_validation_script_found = true
- break
- end
-end
-if $tempfilecount.nil?
- $tempfilecount = 0
- if $html_validation_script_found
- module ActionController
- module TestProcess
- # Hook into the process function, so can automatically get HTML after each request
- alias :original_process :process
- def is_fragment
- # XXX there must be a better way of doing this!
- return @request.query_parameters["action"] == "search_typeahead"
- end
- def process(action, parameters = nil, session = nil, flash = nil, http_method = 'GET')
- self.original_process(action, parameters, session, flash, http_method)
- # don't validate auto-generated HTML
- return if @request.query_parameters["action"] == "get_attachment_as_html"
- # XXX Is there a better way to check this than calling a private method?
- return unless @response.template.controller.instance_eval { integrate_views? }
- # And then if HTML, not a redirect (302, 301)
- if @response.content_type == "text/html" && ! [301,302,401].include?(@response.response_code)
- if !is_fragment
- validate_html(@response.body)
- else
- # it's a partial
- validate_as_body(@response.body)
- end
- end
- end
- end
- end
- else
- puts "WARNING: HTML validation script " + $html_validation_script + " not found"
- end
-end
-
# to_ary differs in Ruby 1.8 and 1.9
# @see http://yehudakatz.com/2010/01/02/the-craziest-fing-bug-ive-ever-seen/
def safe_mock_model(model, args = {})
diff --git a/spec/views/public_body/show.rhtml_spec.rb b/spec/views/public_body/show.rhtml_spec.rb
index b68b3f43b..23e92dedd 100644
--- a/spec/views/public_body/show.rhtml_spec.rb
+++ b/spec/views/public_body/show.rhtml_spec.rb
@@ -38,11 +38,6 @@ describe "when viewing a body" do
response.should be_success
end
- it "should be valid HTML" do
- render "public_body/show"
- validate_as_body response.body
- end
-
it "should show the body's name" do
render "public_body/show"
response.should have_tag("h1", "Test Quango")
diff --git a/spec/views/request/show.rhtml_spec.rb b/spec/views/request/show.rhtml_spec.rb
index 4429e9e58..a22f29951 100644
--- a/spec/views/request/show.rhtml_spec.rb
+++ b/spec/views/request/show.rhtml_spec.rb
@@ -98,7 +98,7 @@ describe 'when viewing an information request' do
it 'should show a link to follow up the last response with clarification' do
request_page
- expected_url = "http://test.host/request/#{@mock_request.id}/response/#{@mock_response.id}#followup"
+ expected_url = "/request/#{@mock_request.id}/response/#{@mock_response.id}#followup"
response.should have_tag("a[href=#{expected_url}]", :text => 'send a follow up message')
end
@@ -118,7 +118,7 @@ describe 'when viewing an information request' do
it 'should show a link to follow up the request without reference to a specific response' do
request_page
- expected_url = "http://test.host/request/#{@mock_request.id}/response#followup"
+ expected_url = "/request/#{@mock_request.id}/response#followup"
response.should have_tag("a[href=#{expected_url}]", :text => 'send a follow up message')
end
end