aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/admin_public_body_controller_spec.rb116
-rw-r--r--spec/controllers/admin_request_controller_spec.rb160
-rw-r--r--spec/controllers/comment_controller_spec.rb20
-rw-r--r--spec/controllers/general_controller_spec.rb14
-rw-r--r--spec/controllers/request_controller_spec.rb1109
-rw-r--r--spec/controllers/services_controller_spec.rb14
-rw-r--r--spec/controllers/track_controller_spec.rb15
-rw-r--r--spec/fixtures/info_request_events.yml35
-rw-r--r--spec/fixtures/info_requests.yml10
-rw-r--r--spec/fixtures/outgoing_messages.yml11
-rw-r--r--spec/helpers/link_to_helper_spec.rb32
-rw-r--r--spec/integration/create_request_spec.rb12
-rw-r--r--spec/lib/public_body_categories_spec.rb42
-rw-r--r--spec/models/censor_rule_spec.rb206
-rw-r--r--spec/models/incoming_message_spec.rb33
-rw-r--r--spec/models/info_request_spec.rb311
-rw-r--r--spec/models/public_body_spec.rb68
-rw-r--r--spec/models/request_mailer_spec.rb2
-rw-r--r--spec/spec_helper.rb39
-rw-r--r--spec/views/request/_after_actions.rhtml_spec.rb2
-rw-r--r--spec/views/request/_describe_state.rhtml_spec.rb7
-rw-r--r--spec/views/request/show.rhtml_spec.rb2
22 files changed, 1589 insertions, 671 deletions
diff --git a/spec/controllers/admin_public_body_controller_spec.rb b/spec/controllers/admin_public_body_controller_spec.rb
index 55a6649b2..be33802c5 100644
--- a/spec/controllers/admin_public_body_controller_spec.rb
+++ b/spec/controllers/admin_public_body_controller_spec.rb
@@ -50,7 +50,7 @@ describe AdminPublicBodyController, "when administering public bodies" do
response.should redirect_to(:controller=>'admin_public_body', :action=>'show', :id => id)
PublicBody.count.should == n
end
-
+
it "destroys a public body" do
n = PublicBody.count
post :destroy, { :id => public_bodies(:forlorn_public_body).id }
@@ -70,6 +70,86 @@ describe AdminPublicBodyController, "when administering public bodies" do
response.should redirect_to(:action=>'list')
PublicBody.find_by_tag("department").count.should == n
end
+
+ describe 'import_csv' do
+
+ describe 'when handling a GET request' do
+
+ it 'should get the page successfully' do
+ get :import_csv
+ response.should be_success
+ end
+
+ end
+
+ describe 'when handling a POST request' do
+
+ before do
+ PublicBody.stub!(:import_csv).and_return([[],[]])
+ @file_object = mock("a file upload", :read => 'some contents',
+ :original_filename => 'contents.txt')
+ end
+
+ it 'should handle a nil csv file param' do
+ post :import_csv, { :commit => 'Dry run' }
+ response.should be_success
+ end
+
+ describe 'if there is a csv file param' do
+
+ it 'should try to get the contents and original name of a csv file param' do
+ @file_object.should_receive(:read).and_return('some contents')
+ post :import_csv, { :csv_file => @file_object,
+ :commit => 'Dry run'}
+ end
+
+ it 'should assign the original filename to the view' do
+ post :import_csv, { :csv_file => @file_object,
+ :commit => 'Dry run'}
+ assigns[:original_csv_file].should == 'contents.txt'
+ end
+
+ end
+
+ describe 'if there is no csv file param, but there are temporary_csv_file and
+ original_csv_file params' do
+
+ it 'should try and get the file contents from a temporary file whose name
+ is passed as a param' do
+ @controller.should_receive(:retrieve_csv_data).with('csv_upload-2046-12-31-394')
+ post :import_csv, { :temporary_csv_file => 'csv_upload-2046-12-31-394',
+ :original_csv_file => 'original_contents.txt',
+ :commit => 'Dry run'}
+ end
+
+ it 'should raise an error on an invalid temp file name' do
+ params = { :temporary_csv_file => 'bad_name',
+ :original_csv_file => 'original_contents.txt',
+ :commit => 'Dry run'}
+ expected_error = "Invalid filename in upload_csv: bad_name"
+ lambda{ post :import_csv, params }.should raise_error(expected_error)
+ end
+
+ it 'should raise an error if the temp file does not exist' do
+ temp_name = "csv_upload-20461231-394"
+ params = { :temporary_csv_file => temp_name,
+ :original_csv_file => 'original_contents.txt',
+ :commit => 'Dry run'}
+ expected_error = "Missing file in upload_csv: csv_upload-20461231-394"
+ lambda{ post :import_csv, params }.should raise_error(expected_error)
+ end
+
+ it 'should assign the temporary filename to the view' do
+ post :import_csv, { :csv_file => @file_object,
+ :commit => 'Dry run'}
+ temporary_filename = assigns[:temporary_csv_file]
+ temporary_filename.should match(/csv_upload-#{Time.now.strftime("%Y%m%d")}-\d{1,5}/)
+ end
+
+ end
+
+ end
+ end
end
describe AdminPublicBodyController, "when administering public bodies and paying attention to authentication" do
@@ -79,7 +159,7 @@ describe AdminPublicBodyController, "when administering public bodies and paying
before do
config = MySociety::Config.load_default()
config['SKIP_ADMIN_AUTH'] = false
- basic_auth_login @request
+ basic_auth_login @request
end
after do
config = MySociety::Config.load_default()
@@ -106,7 +186,7 @@ describe AdminPublicBodyController, "when administering public bodies and paying
PublicBody.count.should == n - 1
session[:using_admin].should == 1
end
-
+
it "doesn't let people with bad credentials log in" do
config = MySociety::Config.load_default()
config['SKIP_ADMIN_AUTH'] = false
@@ -159,7 +239,7 @@ end
describe AdminPublicBodyController, "when administering public bodies with i18n" do
integrate_views
-
+
it "shows the index page" do
get :index
end
@@ -175,7 +255,7 @@ describe AdminPublicBodyController, "when administering public bodies with i18n"
it "edits a public body" do
get :edit, {:id => 3, :locale => :en}
-
+
# When editing a body, the controller returns all available translations
assigns[:public_body].translation("es").name.should == 'El Department for Humpadinking'
assigns[:public_body].name.should == 'Department for Humpadinking'
@@ -186,20 +266,20 @@ describe AdminPublicBodyController, "when administering public bodies with i18n"
PublicBody.with_locale(:es) do
pb = PublicBody.find(id=3)
pb.name.should == "El Department for Humpadinking"
- post :update, {
- :id => 3,
- :public_body => {
- :name => "Department for Humpadinking",
- :short_name => "",
- :tag_string => "some tags",
- :request_email => 'edited@localhost',
+ post :update, {
+ :id => 3,
+ :public_body => {
+ :name => "Department for Humpadinking",
+ :short_name => "",
+ :tag_string => "some tags",
+ :request_email => 'edited@localhost',
:last_edit_comment => 'From test code',
:translated_versions => {
3 => {:locale => "es", :name => "Renamed",:short_name => "", :request_email => 'edited@localhost'}
}
}
}
- response.flash[:notice].should include('successful')
+ response.flash[:notice].should include('successful')
end
pb = PublicBody.find(public_bodies(:humpadink_public_body).id)
@@ -221,7 +301,7 @@ end
describe AdminPublicBodyController, "when creating public bodies with i18n" do
integrate_views
-
+
before do
@old_filters = ActionController::Routing::Routes.filters
ActionController::Routing::Routes.filters = RoutingFilter::Chain.new
@@ -242,14 +322,14 @@ describe AdminPublicBodyController, "when creating public bodies with i18n" do
it "creates a new public body with multiple locales" do
n = PublicBody.count
- post :create, {
- :public_body => {
+ post :create, {
+ :public_body => {
:name => "New Quango", :short_name => "", :tag_string => "blah", :request_email => 'newquango@localhost', :last_edit_comment => 'From test code',
:translated_versions => [{ :locale => "es", :name => "Mi Nuevo Quango", :short_name => "", :request_email => 'newquango@localhost' }]
}
}
PublicBody.count.should == n + 1
-
+
body = PublicBody.find_by_name("New Quango")
body.translations.map {|t| t.locale.to_s}.sort.should == ["en", "es"]
PublicBody.with_locale(:en) do
@@ -262,7 +342,7 @@ describe AdminPublicBodyController, "when creating public bodies with i18n" do
body.url_name.should == "mi_nuevo_quango"
body.first_letter.should == "M"
end
-
+
response.should redirect_to(:controller=>'admin_public_body', :action=>'show', :id=>body.id)
end
end
diff --git a/spec/controllers/admin_request_controller_spec.rb b/spec/controllers/admin_request_controller_spec.rb
index b0468822a..8a3934685 100644
--- a/spec/controllers/admin_request_controller_spec.rb
+++ b/spec/controllers/admin_request_controller_spec.rb
@@ -21,18 +21,42 @@ describe AdminRequestController, "when administering requests" do
get :show, :id => info_requests(:fancy_dog_request)
end
+ it 'shows an external public body with no username' do
+ get :show, :id => info_requests(:anonymous_external_request)
+ response.should be_success
+ end
+
it "edits a public body" do
get :edit, :id => info_requests(:fancy_dog_request)
end
it "saves edits to a request" do
info_requests(:fancy_dog_request).title.should == "Why do you have & such a fancy dog?"
- post :update, { :id => info_requests(:fancy_dog_request), :info_request => { :title => "Renamed", :prominence => "normal", :described_state => "waiting_response", :awaiting_description => false, :allow_new_responses_from => 'anybody', :handle_rejected_responses => 'bounce' } }
+ post :update, { :id => info_requests(:fancy_dog_request),
+ :info_request => { :title => "Renamed",
+ :prominence => "normal",
+ :described_state => "waiting_response",
+ :awaiting_description => false,
+ :allow_new_responses_from => 'anybody',
+ :handle_rejected_responses => 'bounce' } }
response.flash[:notice].should include('successful')
ir = InfoRequest.find(info_requests(:fancy_dog_request).id)
ir.title.should == "Renamed"
end
+ it 'expires the request cache when saving edits to it' do
+ info_request = info_requests(:fancy_dog_request)
+ @controller.should_receive(:expire_for_request).with(info_request)
+ post :update, { :id => info_request,
+ :info_request => { :title => "Renamed",
+ :prominence => "normal",
+ :described_state => "waiting_response",
+ :awaiting_description => false,
+ :allow_new_responses_from => 'anybody',
+ :handle_rejected_responses => 'bounce' } }
+
+ end
+
it "edits an outgoing message" do
get :edit_outgoing, :id => outgoing_messages(:useless_outgoing_message)
end
@@ -45,6 +69,16 @@ describe AdminRequestController, "when administering requests" do
ir.body.should include("delicious cat")
end
+ describe 'when fully destroying a request' do
+
+ it 'expires the file cache for that request' do
+ info_request = info_requests(:badger_request)
+ @controller.should_receive(:expire_for_request).with(info_request)
+ get :fully_destroy, { :id => info_request }
+ end
+
+ end
+
end
describe AdminRequestController, "when administering the holding pen" do
@@ -80,12 +114,13 @@ describe AdminRequestController, "when administering the holding pen" do
InfoRequest.holding_pen_request.incoming_messages.length.should == 1
new_im = InfoRequest.holding_pen_request.incoming_messages[0]
ir.incoming_messages.length.should == 1
- post :redeliver_incoming, :redeliver_incoming_message_id => new_im.id, :url_title => ir.url_title
+ post :redeliver_incoming, :redeliver_incoming_message_id => new_im.id, :url_title => ir.url_title
ir = InfoRequest.find_by_url_title(ir.url_title)
ir.incoming_messages.length.should == 2
response.should redirect_to(:controller=>'admin_request', :action=>'show', :id=>101)
InfoRequest.holding_pen_request.incoming_messages.length.should == 0
end
+
it "allows redelivery to more than one request" do
ir1 = info_requests(:fancy_dog_request)
ir1.allow_new_responses_from = 'nobody'
@@ -99,7 +134,7 @@ describe AdminRequestController, "when administering the holding pen" do
InfoRequest.holding_pen_request.incoming_messages.length.should == 1
new_im = InfoRequest.holding_pen_request.incoming_messages[0]
- post :redeliver_incoming, :redeliver_incoming_message_id => new_im.id, :url_title => "#{ir1.url_title},#{ir2.url_title}"
+ post :redeliver_incoming, :redeliver_incoming_message_id => new_im.id, :url_title => "#{ir1.url_title},#{ir2.url_title}"
ir1.reload
ir1.incoming_messages.length.should == 2
ir2.reload
@@ -108,6 +143,15 @@ describe AdminRequestController, "when administering the holding pen" do
InfoRequest.holding_pen_request.incoming_messages.length.should == 0
end
+ it 'expires the file cache for the previous request' do
+ current_info_request = info_requests(:fancy_dog_request)
+ destination_info_request = info_requests(:naughty_chicken_request)
+ incoming_message = incoming_messages(:useless_incoming_message)
+ @controller.should_receive(:expire_for_request).with(current_info_request)
+ post :redeliver_incoming, :redeliver_incoming_message_id => incoming_message.id,
+ :url_title => destination_info_request.url_title
+ end
+
it "guesses a misdirected request" do
ir = info_requests(:fancy_dog_request)
ir.handle_rejected_responses = 'holding_pen'
@@ -124,11 +168,31 @@ describe AdminRequestController, "when administering the holding pen" do
assigns[:info_requests][0].should == ir
end
- it "destroys an incoming message" do
- im = incoming_messages(:useless_incoming_message)
- raw_email = im.raw_email.filepath
- post :destroy_incoming, :incoming_message_id => im.id
- assert_equal File.exists?(raw_email), false
+ describe 'when destroying an incoming message' do
+
+ before do
+ @im = incoming_messages(:useless_incoming_message)
+ @controller.stub!(:expire_for_request)
+ end
+
+ it "destroys the raw email file" do
+ raw_email = @im.raw_email.filepath
+ assert_equal File.exists?(raw_email), true
+ post :destroy_incoming, :incoming_message_id => @im.id
+ assert_equal File.exists?(raw_email), false
+ end
+
+ it 'asks the incoming message to fully destroy itself' do
+ IncomingMessage.stub!(:find).and_return(@im)
+ @im.should_receive(:fully_destroy)
+ post :destroy_incoming, :incoming_message_id => @im.id
+ end
+
+ it 'expires the file cache for the associated info_request' do
+ @controller.should_receive(:expire_for_request).with(@im.info_request)
+ post :destroy_incoming, :incoming_message_id => @im.id
+ end
+
end
it "shows a suitable default 'your email has been hidden' message" do
@@ -141,16 +205,76 @@ describe AdminRequestController, "when administering the holding pen" do
assigns[:request_hidden_user_explanation].should include("not a valid FOI")
end
- it "hides requests and sends a notification email that it has done so" do
- ir = info_requests(:fancy_dog_request)
- post :hide_request, :id => ir.id, :explanation => "Foo", :reason => "vexatious"
- ir.reload
- ir.prominence.should == "requester_only"
- ir.described_state.should == "vexatious"
- deliveries = ActionMailer::Base.deliveries
- deliveries.size.should == 1
- mail = deliveries[0]
- mail.body.should =~ /Foo/
+ describe 'when hiding requests' do
+
+ it "hides requests and sends a notification email that it has done so" do
+ ir = info_requests(:fancy_dog_request)
+ post :hide_request, :id => ir.id, :explanation => "Foo", :reason => "vexatious"
+ ir.reload
+ ir.prominence.should == "requester_only"
+ ir.described_state.should == "vexatious"
+ deliveries = ActionMailer::Base.deliveries
+ deliveries.size.should == 1
+ mail = deliveries[0]
+ mail.body.should =~ /Foo/
+ end
+
+ it 'expires the file cache for the request' do
+ ir = info_requests(:fancy_dog_request)
+ @controller.should_receive(:expire_for_request).with(ir)
+ post :hide_request, :id => ir.id, :explanation => "Foo", :reason => "vexatious"
+ end
+
+ describe 'when hiding an external request' do
+
+ before do
+ @controller.stub!(:expire_for_request)
+ @info_request = mock_model(InfoRequest, :prominence= => nil,
+ :log_event => nil,
+ :set_described_state => nil,
+ :save! => nil,
+ :user => nil,
+ :user_name => 'External User',
+ :is_external? => true)
+ InfoRequest.stub!(:find).with(@info_request.id.to_s).and_return(@info_request)
+ @default_params = { :id => @info_request.id,
+ :explanation => 'Foo',
+ :reason => 'vexatious' }
+ end
+
+ def make_request(params=@default_params)
+ post :hide_request, params
+ end
+
+ it 'should redirect the the admin page for the request' do
+ make_request
+ response.should redirect_to(:controller => 'admin_request',
+ :action => 'show',
+ :id => @info_request.id)
+ end
+
+ it 'should set the request prominence to "requester_only"' do
+ @info_request.should_receive(:prominence=).with('requester_only')
+ @info_request.should_receive(:save!)
+ make_request
+ end
+
+ it 'should not send a notification email' do
+ ContactMailer.should_not_receive(:deliver_from_admin_message)
+ make_request
+ end
+
+ it 'should add a notice to the flash saying that the request has been hidden' do
+ make_request
+ response.flash[:notice].should == "This external request has been hidden"
+ end
+
+ it 'should expire the file cache for the request' do
+ @controller.should_receive(:expire_for_request)
+ make_request
+ end
+ end
+
end
end
diff --git a/spec/controllers/comment_controller_spec.rb b/spec/controllers/comment_controller_spec.rb
index 93752537c..b71bc0aea 100644
--- a/spec/controllers/comment_controller_spec.rb
+++ b/spec/controllers/comment_controller_spec.rb
@@ -54,6 +54,26 @@ describe CommentController, "when commenting on a request" do
response.should render_template('new')
end
+ describe 'when commenting on an external request' do
+
+ describe 'when responding to a GET request on a successful request' do
+
+ before do
+ @external_request = info_requests(:external_request)
+ @external_request.described_state = 'successful'
+ @external_request.save!
+ end
+
+ it 'should be successful' do
+ get :new, :url_title => @external_request.url_title,
+ :type => 'request'
+ response.should be_success
+ end
+
+ end
+
+ end
+
end
diff --git a/spec/controllers/general_controller_spec.rb b/spec/controllers/general_controller_spec.rb
index df2c139bd..de8dd8422 100644
--- a/spec/controllers/general_controller_spec.rb
+++ b/spec/controllers/general_controller_spec.rb
@@ -9,7 +9,7 @@ describe GeneralController, "when trying to show the blog" do
FakeWeb.clean_registry
end
- it "should fail silently if the blog is returning an error" do
+ it "should fail silently if the blog is returning an error" do
FakeWeb.register_uri(:get, %r|.*|, :body => "Error", :status => ["500", "Error"])
get :blog
response.status.should == "200 OK"
@@ -76,7 +76,7 @@ describe GeneralController, "when searching" do
response.should redirect_to(:action => 'search', :combined => "mouse", :view => "all") # URL /search/:query/all
end
- describe "when using different locale settings" do
+ describe "when using different locale settings" do
home_link_regex = /href=".*\/en\//
it "should generate URLs with a locale prepended when there's more than one locale set" do
get :frontpage
@@ -117,7 +117,7 @@ describe GeneralController, "when searching" do
I18n.available_locales = old_i18n_available_locales
end
end
-
+
describe 'when constructing the list of recent requests' do
before(:each) do
load_raw_emails_data
@@ -127,7 +127,7 @@ describe GeneralController, "when searching" do
it 'should list the newest successful request first' do
# Make sure the newest is listed first even if an older one
# has a newer comment or was reclassified more recently:
- # https://github.com/sebbacon/alaveteli/issues/370
+ # https://github.com/mysociety/alaveteli/issues/370
#
# This is a deliberate behaviour change, in that the
# previous behaviour (showing more-recently-reclassified
@@ -135,7 +135,7 @@ describe GeneralController, "when searching" do
get :frontpage
assigns[:request_events].first.info_request.should == info_requests(:another_boring_request)
end
-
+
it 'should coalesce duplicate requests' do
get :frontpage
assigns[:request_events].map(&:info_request).select{|x|x.url_title =~ /^spam/}.length.should == 1
@@ -231,7 +231,7 @@ describe GeneralController, "when searching" do
u.email_confirmed = true
u.save!
update_xapian_index
-
+
get :search, :combined => ["unconfirmed", "users"]
response.should render_template('search')
assigns[:xapian_users].results.map{|x|x[:model]}.should == [u]
@@ -239,7 +239,7 @@ describe GeneralController, "when searching" do
it "should show tracking links for requests-only searches" do
get :search, :combined => ['"bob"', "requests"]
- response.body.should include('Track this search')
+ response.body.should include('Track this search')
end
end
diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb
index 530e9b2c3..b8425613c 100644
--- a/spec/controllers/request_controller_spec.rb
+++ b/spec/controllers/request_controller_spec.rb
@@ -7,7 +7,7 @@ describe RequestController, "when listing recent requests" do
load_raw_emails_data
rebuild_xapian_index
end
-
+
it "should be successful" do
get :list, :view => 'all'
response.should be_success
@@ -21,7 +21,7 @@ describe RequestController, "when listing recent requests" do
it "should filter requests" do
get :list, :view => 'all'
assigns[:list_results].map(&:info_request).should =~ InfoRequest.all
-
+
# default sort order is the request with the most recently created event first
assigns[:list_results].map(&:info_request).should == InfoRequest.all(
:order => "(select max(info_request_events.created_at) from info_request_events where info_request_events.info_request_id = info_requests.id) DESC")
@@ -45,15 +45,15 @@ describe RequestController, "when listing recent requests" do
it "should filter requests by date" do
# The semantics of the search are that it finds any InfoRequest
# that has any InfoRequestEvent created in the specified range
-
+
get :list, :view => 'all', :request_date_before => '13/10/2007'
assigns[:list_results].map(&:info_request).should =~ InfoRequest.all(
:conditions => "id in (select info_request_id from info_request_events where created_at < '2007-10-13'::date)")
-
+
get :list, :view => 'all', :request_date_after => '13/10/2007'
assigns[:list_results].map(&:info_request).should =~ InfoRequest.all(
:conditions => "id in (select info_request_id from info_request_events where created_at > '2007-10-13'::date)")
-
+
get :list, :view => 'all', :request_date_after => '13/10/2007', :request_date_before => '01/11/2007'
assigns[:list_results].map(&:info_request).should =~ InfoRequest.all(
:conditions => "id in (select info_request_id from info_request_events where created_at between '2007-10-13'::date and '2007-11-01'::date)")
@@ -74,7 +74,7 @@ describe RequestController, "when listing recent requests" do
it "should list internal_review requests as unresolved ones" do
get :list, :view => 'awaiting'
-
+
# This doesn’t precisely duplicate the logic of the actual
# query, but it is close enough to give the same result with
# the current set of test data.
@@ -88,22 +88,22 @@ describe RequestController, "when listing recent requests" do
where later_events.created_at > info_request_events.created_at
and later_events.info_request_id = info_request_events.info_request_id
)")
-
-
+
+
get :list, :view => 'awaiting'
assigns[:list_results].map(&:info_request).include?(info_requests(:fancy_dog_request)).should == false
-
+
event = info_request_events(:useless_incoming_message_event)
event.described_state = event.calculated_state = "internal_review"
event.save!
rebuild_xapian_index
-
+
get :list, :view => 'awaiting'
assigns[:list_results].map(&:info_request).include?(info_requests(:fancy_dog_request)).should == true
end
it "should assign the first page of results" do
- xap_results = mock_model(ActsAsXapian::Search,
+ xap_results = mock_model(ActsAsXapian::Search,
:results => (1..25).to_a.map { |m| { :model => m } },
:matches_estimated => 1000000)
@@ -114,8 +114,9 @@ describe RequestController, "when listing recent requests" do
assigns[:list_results].size.should == 25
assigns[:show_no_more_than].should == RequestController::MAX_RESULTS
end
+
it "should return 404 for pages we don't want to serve up" do
- xap_results = mock_model(ActsAsXapian::Search,
+ xap_results = mock_model(ActsAsXapian::Search,
:results => (1..25).to_a.map { |m| { :model => m } },
:matches_estimated => 1000000)
lambda {
@@ -123,6 +124,12 @@ describe RequestController, "when listing recent requests" do
}.should raise_error(ActiveRecord::RecordNotFound)
end
+ it 'should not raise an error for a page param of less than zero, but should treat it as
+ a param of 1' do
+ lambda{ get :list, :view => 'all', :page => "-1" }.should_not raise_error
+ assigns[:page].should == 1
+ end
+
end
describe RequestController, "when changing things that appear on the request page" do
@@ -172,7 +179,7 @@ describe RequestController, "when changing things that appear on the request pag
# XXX really, CensorRules should execute expiry logic as part
# of the after_save of the model. Currently this is part of
# the AdminCensorRuleController logic, so must be tested from
- # there. Leaving this stub test in place as a reminder
+ # there. Leaving this stub test in place as a reminder
end
it "should purge the downstream cache when something is hidden by an admin" do
ir = info_requests(:fancy_dog_request)
@@ -194,7 +201,7 @@ end
describe RequestController, "when showing one request" do
integrate_views
-
+
before(:each) do
load_raw_emails_data
FileUtils.rm_rf File.join(File.dirname(__FILE__), "../../cache/zips")
@@ -226,8 +233,177 @@ describe RequestController, "when showing one request" do
response.should redirect_to(:action => 'show', :url_title => info_requests(:naughty_chicken_request).url_title)
end
-
+ it 'should show actions the request owner can take' do
+ get :show, :url_title => 'why_do_you_have_such_a_fancy_dog'
+ response.should have_tag('div#owner_actions')
+ end
+
+ describe 'when the request is being viewed by an admin' do
+
+ describe 'if the request is awaiting description' do
+
+ before do
+ dog_request = info_requests(:fancy_dog_request)
+ dog_request.awaiting_description = true
+ dog_request.save!
+ end
+
+ it 'should show the describe state form' do
+ get :show, { :url_title => 'why_do_you_have_such_a_fancy_dog' },
+ { :user_id => users(:admin_user).id }
+ response.should have_tag('div.describe_state_form')
+ end
+
+ it 'should ask the user to use the describe state from' do
+ get :show, { :url_title => 'why_do_you_have_such_a_fancy_dog' },
+ { :user_id => users(:admin_user).id }
+ response.should have_tag('p#request_status', :text => /answer the question above/)
+ end
+
+ end
+
+ describe 'if the request is waiting for a response and very overdue' do
+
+ before do
+ dog_request = info_requests(:fancy_dog_request)
+ dog_request.awaiting_description = false
+ dog_request.described_state = 'waiting_response'
+ dog_request.save!
+ dog_request.calculate_status.should == 'waiting_response_very_overdue'
+ end
+
+ it 'should give a link to requesting an internal review' do
+ get :show, { :url_title => 'why_do_you_have_such_a_fancy_dog' },
+ { :user_id => users(:admin_user).id }
+ response.should have_tag('p#request_status', :text =>/requesting an internal review/)
+ end
+
+ end
+
+ describe 'if the request is waiting clarification' do
+
+ before do
+ dog_request = info_requests(:fancy_dog_request)
+ dog_request.awaiting_description = false
+ dog_request.described_state = 'waiting_clarification'
+ dog_request.save!
+ dog_request.calculate_status.should == 'waiting_clarification'
+ end
+
+ it 'should give a link to make a followup' do
+ get :show, { :url_title => 'why_do_you_have_such_a_fancy_dog' },
+ { :user_id => users(:admin_user).id }
+ response.should have_tag('p#request_status a', :text =>/send a follow up message/)
+ end
+ end
+
+ end
+
+ describe 'when showing an external request' do
+
+ describe 'when viewing with no logged in user' do
+
+ it 'should be successful' do
+ get :show, { :url_title => 'balalas' }, { :user_id => nil }
+ response.should be_success
+ end
+
+ it 'should not display actions the request owner can take' do
+ get :show, :url_title => 'balalas'
+ response.should_not have_tag('div#owner_actions')
+ end
+
+ end
+
+ describe 'when the request is being viewed by an admin' do
+
+ def make_request
+ get :show, { :url_title => 'balalas' }, { :user_id => users(:admin_user).id }
+ end
+
+ it 'should be successful' do
+ make_request
+ response.should be_success
+ end
+
+ describe 'if the request is awaiting description' do
+
+ before do
+ external_request = info_requests(:external_request)
+ external_request.awaiting_description = true
+ external_request.save!
+ end
+
+ it 'should not show the describe state form' do
+ make_request
+ response.should_not have_tag('div.describe_state_form')
+ end
+
+ it 'should not ask the user to use the describe state form' do
+ make_request
+ response.should_not have_tag('p#request_status', :text => /answer the question above/)
+ end
+
+ end
+
+ describe 'if the request is waiting for a response and very overdue' do
+
+ before do
+ external_request = info_requests(:external_request)
+ external_request.awaiting_description = false
+ external_request.described_state = 'waiting_response'
+ external_request.save!
+ external_request.calculate_status.should == 'waiting_response_very_overdue'
+ end
+
+ it 'should not give a link to requesting an internal review' do
+ make_request
+ response.should_not have_tag('p#request_status', :text =>/requesting an internal review/)
+ end
+ end
+
+ describe 'if the request is waiting clarification' do
+
+ before do
+ external_request = info_requests(:external_request)
+ external_request.awaiting_description = false
+ external_request.described_state = 'waiting_clarification'
+ external_request.save!
+ external_request.calculate_status.should == 'waiting_clarification'
+ end
+
+ it 'should not give a link to make a followup' do
+ make_request
+ response.should_not have_tag('p#request_status a', :text =>/send a follow up message/)
+ end
+
+ it 'should not give a link to sign in (in the request status paragraph)' do
+ make_request
+ response.should_not have_tag('p#request_status a', :text => /sign in/)
+ end
+
+ end
+
+ end
+
+ end
+
describe 'when handling an update_status parameter' do
+
+ describe 'when the request is external' do
+
+ it 'should assign the "update status" flag to the view as false if the parameter is present' do
+ get :show, :url_title => 'balalas', :update_status => 1
+ assigns[:update_status].should be_false
+ end
+
+ it 'should assign the "update status" flag to the view as false if the parameter is not present' do
+ get :show, :url_title => 'balalas'
+ assigns[:update_status].should be_false
+ end
+
+ end
+
it 'should assign the "update status" flag to the view as true if the parameter is present' do
get :show, :url_title => 'why_do_you_have_such_a_fancy_dog', :update_status => 1
assigns[:update_status].should be_true
@@ -237,26 +413,26 @@ describe RequestController, "when showing one request" do
get :show, :url_title => 'why_do_you_have_such_a_fancy_dog'
assigns[:update_status].should be_false
end
-
+
it 'should require login' do
session[:user_id] = nil
get :show, :url_title => 'why_do_you_have_such_a_fancy_dog', :update_status => 1
post_redirect = PostRedirect.get_last_post_redirect
response.should redirect_to(:controller => 'user', :action => 'signin', :token => post_redirect.token)
end
-
+
it 'should work if logged in as the requester' do
session[:user_id] = users(:bob_smith_user).id
get :show, :url_title => 'why_do_you_have_such_a_fancy_dog', :update_status => 1
response.should render_template "request/show"
end
-
+
it 'should not work if logged in as not the requester' do
session[:user_id] = users(:silly_name_user).id
get :show, :url_title => 'why_do_you_have_such_a_fancy_dog', :update_status => 1
response.should render_template "user/wrong_user"
end
-
+
it 'should work if logged in as an admin user' do
session[:user_id] = users(:admin_user).id
get :show, :url_title => 'why_do_you_have_such_a_fancy_dog', :update_status => 1
@@ -264,8 +440,8 @@ describe RequestController, "when showing one request" do
end
end
- describe 'when handling incoming mail' do
-
+ describe 'when handling incoming mail' do
+
integrate_views
it "should receive incoming messages, send email to creator, and show them" do
@@ -284,7 +460,7 @@ describe RequestController, "when showing one request" do
get :show, :url_title => 'why_do_you_have_such_a_fancy_dog'
(assigns[:info_request_events].size - size_before).should == 1
end
-
+
it "should download attachments" do
ir = info_requests(:fancy_dog_request)
ir.incoming_messages.each { |x| x.parse_raw_email!(true) }
@@ -293,31 +469,43 @@ describe RequestController, "when showing one request" do
response.content_type.should == "text/html"
size_before = assigns[:info_request_events].size
- ir = info_requests(:fancy_dog_request)
+ ir = info_requests(:fancy_dog_request)
receive_incoming_mail('incoming-request-two-same-name.email', ir.incoming_email)
get :show, :url_title => 'why_do_you_have_such_a_fancy_dog'
(assigns[:info_request_events].size - size_before).should == 1
ir.reload
-
+
get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => ['hello.txt'], :skip_cache => 1
response.content_type.should == "text/plain"
response.should have_text(/Second hello/)
-
+
get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 3, :file_name => ['hello.txt'], :skip_cache => 1
response.content_type.should == "text/plain"
response.should have_text(/First hello/)
end
+ it 'should cache an attachment on a request with normal prominence' do
+ ir = info_requests(:fancy_dog_request)
+ receive_incoming_mail('incoming-request-two-same-name.email', ir.incoming_email)
+ ir.reload
+ @controller.should_receive(:foi_fragment_cache_write)
+ get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id,
+ :id => ir.id,
+ :part => 2,
+ :file_name => ['hello.txt']
+
+ end
+
it "should convert message body to UTF8" do
- ir = info_requests(:fancy_dog_request)
+ ir = info_requests(:fancy_dog_request)
receive_incoming_mail('iso8859_2_raw_email.email', ir.incoming_email)
get :show, :url_title => 'why_do_you_have_such_a_fancy_dog'
response.should have_text(/tënde/u)
end
it "should generate valid HTML verson of plain text attachments" do
- ir = info_requests(:fancy_dog_request)
+ ir = info_requests(:fancy_dog_request)
receive_incoming_mail('incoming-request-two-same-name.email', ir.incoming_email)
ir.reload
get :get_attachment_as_html, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => ['hello.txt.html'], :skip_cache => 1
@@ -334,9 +522,9 @@ describe RequestController, "when showing one request" do
# error-handling path, causing the wrong sort of error response to be returned in the
# case where the integer prefix referred to the wrong request.)
#
- # https://github.com/sebbacon/alaveteli/issues/351
+ # https://github.com/mysociety/alaveteli/issues/351
it "should return 404 for ugly URLs containing a request id that isn't an integer" do
- ir = info_requests(:fancy_dog_request)
+ ir = info_requests(:fancy_dog_request)
receive_incoming_mail('incoming-request-two-same-name.email', ir.incoming_email)
ir.reload
ugly_id = "55195"
@@ -362,7 +550,7 @@ describe RequestController, "when showing one request" do
receive_incoming_mail('incoming-request-two-same-name.email', ir.incoming_email)
ir.reload
ugly_id = "%d95" % [info_requests(:naughty_chicken_request).id]
-
+
lambda {
get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ugly_id, :part => 2, :file_name => ['hello.txt.html'], :skip_cache => 1
}.should raise_error(ActiveRecord::RecordNotFound)
@@ -382,7 +570,7 @@ describe RequestController, "when showing one request" do
end
it "should generate valid HTML verson of PDF attachments" do
- ir = info_requests(:fancy_dog_request)
+ ir = info_requests(:fancy_dog_request)
receive_incoming_mail('incoming-request-pdf-attachment.email', ir.incoming_email)
ir.reload
get :get_attachment_as_html, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => ['fs_50379341.pdf.html'], :skip_cache => 1
@@ -391,7 +579,7 @@ describe RequestController, "when showing one request" do
end
it "should not cause a reparsing of the raw email, even when the result would be a 404" do
- ir = info_requests(:fancy_dog_request)
+ ir = info_requests(:fancy_dog_request)
receive_incoming_mail('incoming-request-two-same-name.email', ir.incoming_email)
ir.reload
attachment = IncomingMessage.get_attachment_by_url_part_number(ir.incoming_messages[1].get_attachments_for_display, 2)
@@ -405,14 +593,14 @@ describe RequestController, "when showing one request" do
lambda {
get :get_attachment_as_html, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => ['hello.txt.baz.html'], :skip_cache => 1
}.should raise_error(ActiveRecord::RecordNotFound)
-
+
attachment = IncomingMessage.get_attachment_by_url_part_number(ir.incoming_messages[1].get_attachments_for_display, 2)
attachment.body.should have_text(/Second hello/)
# ...nor should asking for it by its correct filename...
get :get_attachment_as_html, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => ['hello.txt.html'], :skip_cache => 1
response.should_not have_text(/Third hello/)
-
+
# ...but if we explicitly ask for attachments to be extracted, then they should be
force = true
ir.incoming_messages[1].parse_raw_email!(force)
@@ -426,14 +614,14 @@ describe RequestController, "when showing one request" do
ir = info_requests(:fancy_dog_request)
receive_incoming_mail('incoming-request-attachment-unknown-extension.email', ir.incoming_email)
ir.reload
-
+
get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => ['hello.qwglhm'], :skip_cache => 1
response.content_type.should == "application/octet-stream"
response.should have_text(/an unusual sort of file/)
end
it "should not download attachments with wrong file name" do
- ir = info_requests(:fancy_dog_request)
+ ir = info_requests(:fancy_dog_request)
receive_incoming_mail('incoming-request-two-same-name.email', ir.incoming_email)
lambda {
@@ -443,7 +631,7 @@ describe RequestController, "when showing one request" do
end
it "should censor attachments downloaded as binary" do
- ir = info_requests(:fancy_dog_request)
+ ir = info_requests(:fancy_dog_request)
censor_rule = CensorRule.new()
censor_rule.text = "Second"
@@ -451,7 +639,7 @@ describe RequestController, "when showing one request" do
censor_rule.last_edit_editor = "unknown"
censor_rule.last_edit_comment = "none"
ir.censor_rules << censor_rule
-
+
begin
receive_incoming_mail('incoming-request-two-same-name.email', ir.incoming_email)
@@ -464,7 +652,7 @@ describe RequestController, "when showing one request" do
end
it "should censor with rules on the user (rather than the request)" do
- ir = info_requests(:fancy_dog_request)
+ ir = info_requests(:fancy_dog_request)
censor_rule = CensorRule.new()
censor_rule.text = "Second"
@@ -486,7 +674,7 @@ describe RequestController, "when showing one request" do
end
it "should censor attachment names" do
- ir = info_requests(:fancy_dog_request)
+ ir = info_requests(:fancy_dog_request)
receive_incoming_mail('incoming-request-two-same-name.email', ir.incoming_email)
# XXX this is horrid, but don't know a better way. If we
@@ -505,7 +693,7 @@ describe RequestController, "when showing one request" do
# so at this point, assigns[:info_request].incoming_messages[1].get_attachments_for_display is returning stuff, but the equivalent thing in the template isn't.
# but something odd is that the above is return a whole load of attachments which aren't there in the controller
- response.body.should have_tag("p.attachment strong", /hello.txt/m)
+ response.body.should have_tag("p.attachment strong", /hello.txt/m)
censor_rule = CensorRule.new()
censor_rule.text = "hello.txt"
@@ -521,38 +709,48 @@ describe RequestController, "when showing one request" do
end
end
- it "should make a zipfile available, which has a different URL when it changes" do
- title = 'why_do_you_have_such_a_fancy_dog'
- ir = info_requests(:fancy_dog_request)
- session[:user_id] = ir.user.id # bob_smith_user
- get :download_entire_request, :url_title => title
- assigns[:url_path].should have_text(/#{title}.zip$/)
- old_path = assigns[:url_path]
- response.location.should have_text(/#{assigns[:url_path]}$/)
- zipfile = Zip::ZipFile.open(File.join(File.dirname(__FILE__), "../../cache/zips", old_path)) { |zipfile|
- zipfile.count.should == 1 # just the message
- }
- receive_incoming_mail('incoming-request-two-same-name.email', ir.incoming_email)
- get :download_entire_request, :url_title => title
- assigns[:url_path].should have_text(/#{title}.zip$/)
- old_path = assigns[:url_path]
- response.location.should have_text(/#{assigns[:url_path]}$/)
- zipfile = Zip::ZipFile.open(File.join(File.dirname(__FILE__), "../../cache/zips", old_path)) { |zipfile|
- zipfile.count.should == 3 # the message plus two "hello.txt" files
- }
-
- # The path of the zip file is based on the hash of the timestamp of the last request
- # in the thread, so we wait for a second to make sure this one will have a different
- # timestamp than the previous.
- sleep 1
- receive_incoming_mail('incoming-request-attachment-unknown-extension.email', ir.incoming_email)
- get :download_entire_request, :url_title => title
- assigns[:url_path].should have_text(/#{title}.zip$/)
- assigns[:url_path].should_not == old_path
- response.location.should have_text(/#{assigns[:url_path]}/)
- zipfile = Zip::ZipFile.open(File.join(File.dirname(__FILE__), "../../cache/zips", assigns[:url_path])) { |zipfile|
- zipfile.count.should == 5 # the message, two hello.txt, the unknown attachment, and its empty message
- }
+ describe 'when making a zipfile available' do
+
+ it "should have a different zipfile URL when the request changes" do
+ title = 'why_do_you_have_such_a_fancy_dog'
+ ir = info_requests(:fancy_dog_request)
+ session[:user_id] = ir.user.id # bob_smith_user
+ get :download_entire_request, :url_title => title
+ assigns[:url_path].should have_text(/#{title}.zip$/)
+ old_path = assigns[:url_path]
+ response.location.should have_text(/#{assigns[:url_path]}$/)
+ zipfile = Zip::ZipFile.open(File.join(File.dirname(__FILE__), "../../cache/zips", old_path)) { |zipfile|
+ zipfile.count.should == 1 # just the message
+ }
+ receive_incoming_mail('incoming-request-two-same-name.email', ir.incoming_email)
+ get :download_entire_request, :url_title => title
+ assigns[:url_path].should have_text(/#{title}.zip$/)
+ old_path = assigns[:url_path]
+ response.location.should have_text(/#{assigns[:url_path]}$/)
+ zipfile = Zip::ZipFile.open(File.join(File.dirname(__FILE__), "../../cache/zips", old_path)) { |zipfile|
+ zipfile.count.should == 3 # the message plus two "hello.txt" files
+ }
+
+ # The path of the zip file is based on the hash of the timestamp of the last request
+ # in the thread, so we wait for a second to make sure this one will have a different
+ # timestamp than the previous.
+ sleep 1
+ receive_incoming_mail('incoming-request-attachment-unknown-extension.email', ir.incoming_email)
+ get :download_entire_request, :url_title => title
+ assigns[:url_path].should have_text(/#{title}.zip$/)
+ assigns[:url_path].should_not == old_path
+ response.location.should have_text(/#{assigns[:url_path]}/)
+ zipfile = Zip::ZipFile.open(File.join(File.dirname(__FILE__), "../../cache/zips", assigns[:url_path])) { |zipfile|
+ zipfile.count.should == 5 # the message, two hello.txt, the unknown attachment, and its empty message
+ }
+ end
+
+ it 'should successfully make a zipfile for an external request' do
+ info_request = info_requests(:external_request)
+ get :download_entire_request, { :url_title => info_request.url_title },
+ { :user_id => users(:bob_smith_user) }
+ response.location.should have_text(/#{assigns[:url_path]}/)
+ end
end
end
end
@@ -617,11 +815,20 @@ describe RequestController, "when changing prominence of a request" do
session[:user_id] = users(:admin_user).id
get :show, :url_title => 'why_do_you_have_such_a_fancy_dog'
response.should render_template('show')
+ end
+ it 'should not cache an attachment on a request whose prominence is requester_only when showing
+ the request to the requester or admin' do
+ ir = info_requests(:fancy_dog_request)
+ ir.prominence = 'requester_only'
+ ir.save!
+ session[:user_id] = ir.user.id # bob_smith_user
+ @controller.should_not_receive(:foi_fragment_cache_write)
+ get :show, :url_title => 'why_do_you_have_such_a_fancy_dog'
end
it "should not download attachments if hidden" do
- ir = info_requests(:fancy_dog_request)
+ ir = info_requests(:fancy_dog_request)
ir.prominence = 'hidden'
ir.save!
receive_incoming_mail('incoming-request-two-same-name.email', ir.incoming_email)
@@ -637,7 +844,7 @@ describe RequestController, "when changing prominence of a request" do
end
end
-
+
# XXX do this for invalid ids
# it "should render 404 file" do
# response.should render_template("#{Rails.root}/public/404.html")
@@ -651,11 +858,11 @@ describe RequestController, "when searching for an authority" do
before do
@user = users(:bob_smith_user)
end
-
+
it "should return nothing for the empty query string" do
session[:user_id] = @user.id
get :select_authority, :query => ""
-
+
response.should render_template('select_authority')
assigns[:xapian_requests].should == nil
end
@@ -663,7 +870,7 @@ describe RequestController, "when searching for an authority" do
it "should return matching bodies" do
session[:user_id] = @user.id
get :select_authority, :query => "Quango"
-
+
response.should render_template('select_authority')
assigns[:xapian_requests].results.size == 1
assigns[:xapian_requests].results[0][:model].name.should == public_bodies(:geraldine_public_body).name
@@ -691,7 +898,7 @@ describe RequestController, "when creating a new request" do
@user = users(:bob_smith_user)
@body = public_bodies(:geraldine_public_body)
end
-
+
it "should redirect to front page if no public body specified" do
get :new
response.should redirect_to(:controller => 'general', :action => 'frontpage')
@@ -725,7 +932,7 @@ describe RequestController, "when creating a new request" do
end
it "should redirect to sign in page when input is good and nobody is logged in" do
- params = { :info_request => { :public_body_id => @body.id,
+ params = { :info_request => { :public_body_id => @body.id,
:title => "Why is your quango called Geraldine?", :tag_string => "" },
:outgoing_message => { :body => "This is a silly letter. It is too short to be interesting." },
:submitted_new_request => 1, :preview => 0
@@ -738,7 +945,7 @@ describe RequestController, "when creating a new request" do
it "should show preview when input is good" do
session[:user_id] = @user.id
- post :new, { :info_request => { :public_body_id => @body.id,
+ post :new, { :info_request => { :public_body_id => @body.id,
:title => "Why is your quango called Geraldine?", :tag_string => "" },
:outgoing_message => { :body => "This is a silly letter. It is too short to be interesting." },
:submitted_new_request => 1, :preview => 1
@@ -757,7 +964,7 @@ describe RequestController, "when creating a new request" do
it "should create the request and outgoing message, and send the outgoing message by email, and redirect to request page when input is good and somebody is logged in" do
session[:user_id] = @user.id
- post :new, :info_request => { :public_body_id => @body.id,
+ post :new, :info_request => { :public_body_id => @body.id,
:title => "Why is your quango called Geraldine?", :tag_string => "" },
:outgoing_message => { :body => "This is a silly letter. It is too short to be interesting." },
:submitted_new_request => 1, :preview => 0
@@ -784,7 +991,7 @@ describe RequestController, "when creating a new request" do
session[:user_id] = @user.id
# We use raw_body here, so white space is the same
- post :new, :info_request => { :public_body_id => info_requests(:fancy_dog_request).public_body_id,
+ post :new, :info_request => { :public_body_id => info_requests(:fancy_dog_request).public_body_id,
:title => info_requests(:fancy_dog_request).title },
:outgoing_message => { :body => info_requests(:fancy_dog_request).outgoing_messages[0].raw_body},
:submitted_new_request => 1, :preview => 0, :mouse_house => 1
@@ -794,12 +1001,12 @@ describe RequestController, "when creating a new request" do
it "should let you submit another request with the same title" do
session[:user_id] = @user.id
- post :new, :info_request => { :public_body_id => @body.id,
+ post :new, :info_request => { :public_body_id => @body.id,
:title => "Why is your quango called Geraldine?", :tag_string => "" },
:outgoing_message => { :body => "This is a silly letter. It is too short to be interesting." },
:submitted_new_request => 1, :preview => 0
- post :new, :info_request => { :public_body_id => @body.id,
+ post :new, :info_request => { :public_body_id => @body.id,
:title => "Why is your quango called Geraldine?", :tag_string => "" },
:outgoing_message => { :body => "This is a sensible letter. It is too long to be boring." },
:submitted_new_request => 1, :preview => 0
@@ -814,32 +1021,32 @@ describe RequestController, "when creating a new request" do
response.should redirect_to(:action => 'show', :url_title => ir2.url_title)
end
-
+
it 'should respect the rate limit' do
# Try to create three requests in succession.
# (The limit set in config/test.yml is two.)
session[:user_id] = users(:robin_user)
- post :new, :info_request => { :public_body_id => @body.id,
+ post :new, :info_request => { :public_body_id => @body.id,
:title => "What is the answer to the ultimate question?", :tag_string => "" },
:outgoing_message => { :body => "Please supply the answer from your files." },
:submitted_new_request => 1, :preview => 0
response.should redirect_to(:action => 'show', :url_title => 'what_is_the_answer_to_the_ultima')
-
- post :new, :info_request => { :public_body_id => @body.id,
+
+ post :new, :info_request => { :public_body_id => @body.id,
:title => "Why did the chicken cross the road?", :tag_string => "" },
:outgoing_message => { :body => "Please send me all the relevant documents you hold." },
:submitted_new_request => 1, :preview => 0
response.should redirect_to(:action => 'show', :url_title => 'why_did_the_chicken_cross_the_ro')
- post :new, :info_request => { :public_body_id => @body.id,
+ post :new, :info_request => { :public_body_id => @body.id,
:title => "What's black and white and red all over?", :tag_string => "" },
:outgoing_message => { :body => "Please send all minutes of meetings and email records that address this question." },
:submitted_new_request => 1, :preview => 0
response.should render_template('user/rate_limited')
end
-
+
it 'should ignore the rate limit for specified users' do
# Try to create three requests in succession.
# (The limit set in config/test.yml is two.)
@@ -847,20 +1054,20 @@ describe RequestController, "when creating a new request" do
users(:robin_user).no_limit = true
users(:robin_user).save!
- post :new, :info_request => { :public_body_id => @body.id,
+ post :new, :info_request => { :public_body_id => @body.id,
:title => "What is the answer to the ultimate question?", :tag_string => "" },
:outgoing_message => { :body => "Please supply the answer from your files." },
:submitted_new_request => 1, :preview => 0
response.should redirect_to(:action => 'show', :url_title => 'what_is_the_answer_to_the_ultima')
-
- post :new, :info_request => { :public_body_id => @body.id,
+
+ post :new, :info_request => { :public_body_id => @body.id,
:title => "Why did the chicken cross the road?", :tag_string => "" },
:outgoing_message => { :body => "Please send me all the relevant documents you hold." },
:submitted_new_request => 1, :preview => 0
response.should redirect_to(:action => 'show', :url_title => 'why_did_the_chicken_cross_the_ro')
- post :new, :info_request => { :public_body_id => @body.id,
+ post :new, :info_request => { :public_body_id => @body.id,
:title => "What's black and white and red all over?", :tag_string => "" },
:outgoing_message => { :body => "Please send all minutes of meetings and email records that address this question." },
:submitted_new_request => 1, :preview => 0
@@ -869,7 +1076,7 @@ describe RequestController, "when creating a new request" do
end
-# These go with the previous set, but use mocks instead of fixtures.
+# These go with the previous set, but use mocks instead of fixtures.
# TODO harmonise these
describe RequestController, "when making a new request" do
@@ -956,7 +1163,7 @@ describe RequestController, "when viewing an individual response for reply/follo
end
it "should not show individual responses if request hidden, even if request owner" do
- ir = info_requests(:fancy_dog_request)
+ ir = info_requests(:fancy_dog_request)
ir.prominence = 'hidden'
ir.save!
@@ -964,348 +1171,383 @@ describe RequestController, "when viewing an individual response for reply/follo
get :show_response, :id => info_requests(:fancy_dog_request).id, :incoming_message_id => incoming_messages(:useless_incoming_message)
response.should render_template('request/hidden')
end
+
+ describe 'when viewing a response for an external request' do
+
+ it 'should show a message saying that external requests cannot be followed up' do
+ get :show_response, :id => info_requests(:external_request).id
+ response.should render_template('request/followup_bad')
+ assigns[:reason].should == 'external'
+ end
+
+ it 'should be successful' do
+ get :show_response, :id => info_requests(:external_request).id
+ response.should be_success
+ end
+
+ end
+
end
describe RequestController, "when classifying an information request" do
- before(:each) do
- @dog_request = info_requests(:fancy_dog_request)
- @dog_request.stub!(:is_old_unclassified?).and_return(false)
- InfoRequest.stub!(:find).and_return(@dog_request)
- load_raw_emails_data
- end
+ describe 'if the request is external' 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
- end
+ before do
+ @external_request = info_requests(:external_request)
+ end
- it "should require login" do
- post_status('rejected')
- post_redirect = PostRedirect.get_last_post_redirect
- response.should redirect_to(:controller => 'user', :action => 'signin', :token => post_redirect.token)
- end
+ it 'should redirect to the request page' do
+ post :describe_state, :id => @external_request.id,
+ :submitted_describe_state => 1
+ response.should redirect_to(:action => 'show',
+ :controller => 'request',
+ :url_title => @external_request.url_title)
+ end
- it 'should ask whether the request is old and unclassified' do
- @dog_request.should_receive(:is_old_unclassified?)
- post_status('rejected')
- end
-
- it "should not classify the request if logged in as the wrong user" do
- session[:user_id] = users(:silly_name_user).id
- post_status('rejected')
- response.should render_template('user/wrong_user')
end
-
+ describe 'when the request is internal' do
+
+ before(:each) do
+ @dog_request = info_requests(:fancy_dog_request)
+ @dog_request.stub!(:is_old_unclassified?).and_return(false)
+ InfoRequest.stub!(:find).and_return(@dog_request)
+ load_raw_emails_data
+ end
- describe 'when the request is old and unclassified' do
-
- before do
- @dog_request.stub!(:is_old_unclassified?).and_return(true)
- RequestMailer.stub!(:deliver_old_unclassified_updated)
+ 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
end
-
- describe 'when the user is not logged in' do
-
- it 'should require login' do
- session[:user_id] = nil
- post_status('rejected')
- post_redirect = PostRedirect.get_last_post_redirect
- response.should redirect_to(:controller => 'user', :action => 'signin', :token => post_redirect.token)
+
+ it "should require login" do
+ post_status('rejected')
+ post_redirect = PostRedirect.get_last_post_redirect
+ response.should redirect_to(:controller => 'user', :action => 'signin', :token => post_redirect.token)
+ end
+
+ it 'should ask whether the request is old and unclassified' do
+ @dog_request.should_receive(:is_old_unclassified?)
+ post_status('rejected')
+ end
+
+ it "should not classify the request if logged in as the wrong user" do
+ session[:user_id] = users(:silly_name_user).id
+ post_status('rejected')
+ response.should render_template('user/wrong_user')
+ end
+
+ describe 'when the request is old and unclassified' do
+
+ before do
+ @dog_request.stub!(:is_old_unclassified?).and_return(true)
+ RequestMailer.stub!(:deliver_old_unclassified_updated)
+ end
+
+ describe 'when the user is not logged in' do
+
+ it 'should require login' do
+ session[:user_id] = nil
+ post_status('rejected')
+ post_redirect = PostRedirect.get_last_post_redirect
+ response.should redirect_to(:controller => 'user', :action => 'signin', :token => post_redirect.token)
+ end
+
+ end
+
+ describe 'when the user is logged in as a different user' do
+
+ before do
+ @other_user = mock_model(User)
+ session[:user_id] = users(:silly_name_user).id
+ end
+
+ it 'should classify the request' do
+ @dog_request.stub!(:calculate_status).and_return('rejected')
+ @dog_request.should_receive(:set_described_state).with('rejected')
+ post_status('rejected')
+ end
+
+ it 'should log a status update event' do
+ expected_params = {:user_id => users(:silly_name_user).id,
+ :old_described_state => 'waiting_response',
+ :described_state => 'rejected'}
+ @dog_request.should_receive(:log_event).with("status_update", expected_params)
+ post_status('rejected')
+ end
+
+ it 'should send an email to the requester letting them know someone has updated the status of their request' do
+ RequestMailer.should_receive(:deliver_old_unclassified_updated)
+ post_status('rejected')
+ end
+
+ it 'should redirect to the request page' do
+ post_status('rejected')
+ response.should redirect_to(:action => 'show', :controller => 'request', :url_title => @dog_request.url_title)
+ end
+
+ it 'should show a message thanking the user for a good deed' do
+ post_status('rejected')
+ flash[:notice].should == 'Thank you for updating this request!'
+ end
+
end
-
end
-
- describe 'when the user is logged in as a different user' do
-
+
+ describe 'when logged in as an admin user who is not the actual requester' do
+
before do
- @other_user = mock_model(User)
- session[:user_id] = users(:silly_name_user).id
+ @admin_user = users(:admin_user)
+ session[:user_id] = @admin_user.id
+ @dog_request = info_requests(:fancy_dog_request)
+ InfoRequest.stub!(:find).and_return(@dog_request)
+ @dog_request.stub!(:each).and_return([@dog_request])
end
-
- it 'should classify the request' do
- @dog_request.stub!(:calculate_status).and_return('rejected')
+
+ 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')
post_status('rejected')
end
-
- it 'should log a status update event' do
- expected_params = {:user_id => users(:silly_name_user).id,
- :old_described_state => 'waiting_response',
+
+ it 'should log a status update event' do
+ expected_params = {:user_id => @admin_user.id,
+ :old_described_state => 'waiting_response',
:described_state => 'rejected'}
@dog_request.should_receive(:log_event).with("status_update", expected_params)
post_status('rejected')
end
-
- it 'should send an email to the requester letting them know someone has updated the status of their request' do
+
+ it 'should send an email to the requester letting them know someone has updated the status of their request' do
RequestMailer.should_receive(:deliver_old_unclassified_updated)
post_status('rejected')
end
-
- it 'should redirect to the request page' do
+
+ it 'should redirect to the request page' do
post_status('rejected')
response.should redirect_to(:action => 'show', :controller => 'request', :url_title => @dog_request.url_title)
end
-
- it 'should show a message thanking the user for a good deed' do
+
+ it 'should show a message thanking the user for a good deed' do
post_status('rejected')
flash[:notice].should == 'Thank you for updating this request!'
end
-
- end
- end
-
- describe 'when logged in as an admin user who is not the actual requester' do
-
- before do
- @admin_user = users(:admin_user)
- session[:user_id] = @admin_user.id
- @dog_request = info_requests(:fancy_dog_request)
- InfoRequest.stub!(:find).and_return(@dog_request)
- @dog_request.stub!(:each).and_return([@dog_request])
- end
+ end
- 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')
- post_status('rejected')
- end
-
- it 'should log a status update event' do
- expected_params = {:user_id => @admin_user.id,
- :old_described_state => 'waiting_response',
- :described_state => 'rejected'}
- @dog_request.should_receive(:log_event).with("status_update", expected_params)
- post_status('rejected')
- end
+ describe 'when logged in as an admin user who is also the actual requester' do
- it 'should send an email to the requester letting them know someone has updated the status of their request' do
- RequestMailer.should_receive(:deliver_old_unclassified_updated)
- post_status('rejected')
- end
+ before do
+ @admin_user = users(:admin_user)
+ session[:user_id] = @admin_user.id
+ @dog_request = info_requests(:fancy_dog_request)
+ @dog_request.user = @admin_user
+ @dog_request.save!
+ InfoRequest.stub!(:find).and_return(@dog_request)
+ @dog_request.stub!(:each).and_return([@dog_request])
+ end
- it 'should redirect to the request page' do
- post_status('rejected')
- response.should redirect_to(:action => 'show', :controller => 'request', :url_title => @dog_request.url_title)
- end
+ 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')
+ post_status('rejected')
+ end
- it 'should show a message thanking the user for a good deed' do
- post_status('rejected')
- flash[:notice].should == 'Thank you for updating this request!'
- end
- end
+ it 'should not log a status update event' do
+ @dog_request.should_not_receive(:log_event)
+ post_status('rejected')
+ end
- describe 'when logged in as an admin user who is also the actual requester' do
-
- before do
- @admin_user = users(:admin_user)
- session[:user_id] = @admin_user.id
- @dog_request = info_requests(:fancy_dog_request)
- @dog_request.user = @admin_user
- @dog_request.save!
- InfoRequest.stub!(:find).and_return(@dog_request)
- @dog_request.stub!(:each).and_return([@dog_request])
- end
+ it 'should not send an email to the requester letting them know someone has updated the status of their request' do
+ RequestMailer.should_not_receive(:deliver_old_unclassified_updated)
+ post_status('rejected')
+ end
- 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')
- post_status('rejected')
- end
-
- it 'should not log a status update event' do
- @dog_request.should_not_receive(:log_event)
- post_status('rejected')
- 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/)
+ end
- it 'should not send an email to the requester letting them know someone has updated the status of their request' do
- RequestMailer.should_not_receive(:deliver_old_unclassified_updated)
- post_status('rejected')
- 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/)
- end
-
- it 'should redirect to the unhappy page' do
- post_status('rejected')
- response.should redirect_to(:controller => 'help', :action => 'unhappy', :url_title => @dog_request.url_title)
- end
+ it 'should redirect to the unhappy page' do
+ post_status('rejected')
+ response.should redirect_to(:controller => 'help', :action => 'unhappy', :url_title => @dog_request.url_title)
+ end
- end
-
- describe 'when logged in as the requestor' do
-
- before do
- @request_owner = users(:bob_smith_user)
- session[:user_id] = @request_owner.id
- @dog_request.awaiting_description.should == true
- @dog_request.stub!(:each).and_return([@dog_request])
- 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)
- @dog_request.reload
- @dog_request.awaiting_description.should == false
- @dog_request.described_state.should == 'rejected'
- @dog_request.get_last_response_event.should == info_request_events(:useless_incoming_message_event)
- @dog_request.get_last_response_event.calculated_state.should == 'rejected'
end
- it 'should not log a status update event' do
- @dog_request.should_not_receive(:log_event)
- post_status('rejected')
- end
-
- it 'should not send an email to the requester letting them know someone has updated the status of their request' do
- RequestMailer.should_not_receive(:deliver_old_unclassified_updated)
- 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')
+ describe 'when logged in as the requestor' do
- @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'
+ before do
+ @request_owner = users(:bob_smith_user)
+ session[:user_id] = @request_owner.id
+ @dog_request.awaiting_description.should == true
+ @dog_request.stub!(:each).and_return([@dog_request])
+ end
- 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
- 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)
+ @dog_request.reload
+ @dog_request.awaiting_description.should == false
+ @dog_request.described_state.should == 'rejected'
+ @dog_request.get_last_response_event.should == info_request_events(:useless_incoming_message_event)
+ @dog_request.get_last_response_event.calculated_state.should == 'rejected'
+ 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/)
- end
-
- it 'should redirect to the unhappy page' do
- post_status('rejected')
- response.should redirect_to(:controller => 'help', :action => 'unhappy', :url_title => @dog_request.url_title)
- end
+ it 'should not log a status update event' do
+ @dog_request.should_not_receive(:log_event)
+ post_status('rejected')
+ end
- it "knows about extended states" do
- InfoRequest.send(:require, File.expand_path(File.join(File.dirname(__FILE__), '..', 'models', 'customstates')))
- InfoRequest.send(:include, InfoRequestCustomStates)
- InfoRequest.class_eval('@@custom_states_loaded = true')
- RequestController.send(:require, File.expand_path(File.join(File.dirname(__FILE__), '..', 'models', 'customstates')))
- RequestController.send(:include, RequestControllerCustomStates)
- RequestController.class_eval('@@custom_states_loaded = true')
- Time.stub!(:now).and_return(Time.utc(2007, 11, 10, 00, 01))
- post_status('deadline_extended')
- flash[:notice].should == 'Authority has requested extension of the deadline.'
- end
- end
-
- describe 'when redirecting after a successful status update by the request owner' do
-
- before do
- @request_owner = users(:bob_smith_user)
- session[:user_id] = @request_owner.id
- @dog_request = info_requests(:fancy_dog_request)
- @dog_request.stub!(:each).and_return([@dog_request])
- InfoRequest.stub!(:find).and_return(@dog_request)
- @old_filters = ActionController::Routing::Routes.filters
- ActionController::Routing::Routes.filters = RoutingFilter::Chain.new
- end
- after do
- ActionController::Routing::Routes.filters = @old_filters
- end
+ it 'should not send an email to the requester letting them know someone has updated the status of their request' do
+ RequestMailer.should_not_receive(:deliver_old_unclassified_updated)
+ post_status('rejected')
+ end
- def request_url
- "request/#{@dog_request.url_title}"
- 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')
- def unhappy_url
- "help/unhappy/#{@dog_request.url_title}"
- end
-
- def expect_redirect(status, redirect_path)
- post_status(status)
- response.should redirect_to("http://test.host/#{redirect_path}")
- end
-
- it 'should redirect to the "request url" with a message in the right tense when status is updated to "waiting response" and the response is not overdue' do
- @dog_request.stub!(:date_response_required_by).and_return(Time.now.to_date+1)
- @dog_request.stub!(:date_very_overdue_after).and_return(Time.now.to_date+40)
+ @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'
- expect_redirect("waiting_response", "request/#{@dog_request.url_title}")
- flash[:notice].should match(/should get a response/)
- end
-
- it 'should redirect to the "request url" with a message in the right tense when status is updated to "waiting response" and the response is overdue' do
- @dog_request.stub!(:date_response_required_by).and_return(Time.now.to_date-1)
- @dog_request.stub!(:date_very_overdue_after).and_return(Time.now.to_date+40)
- expect_redirect('waiting_response', request_url)
- flash[:notice].should match(/should have got a response/)
- end
+ 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
+ end
- it 'should redirect to the "request url" with a message in the right tense when status is updated to "waiting response" and the response is overdue' do
- @dog_request.stub!(:date_response_required_by).and_return(Time.now.to_date-2)
- @dog_request.stub!(:date_very_overdue_after).and_return(Time.now.to_date-1)
- expect_redirect('waiting_response', unhappy_url)
- flash[:notice].should match(/is long overdue/)
- flash[:notice].should match(/by more than 40 working days/)
- flash[:notice].should match(/within 20 working days/)
- end
-
- it 'should redirect to the "request url" when status is updated to "not held"' do
- expect_redirect('not_held', request_url)
- end
-
- it 'should redirect to the "request url" when status is updated to "successful"' do
- expect_redirect('successful', request_url)
- end
-
- it 'should redirect to the "unhappy url" when status is updated to "rejected"' do
- expect_redirect('rejected', "help/unhappy/#{@dog_request.url_title}")
- end
-
- it 'should redirect to the "unhappy url" when status is updated to "partially successful"' do
- expect_redirect('partially_successful', "help/unhappy/#{@dog_request.url_title}")
- end
-
- it 'should redirect to the "response url" when status is updated to "waiting clarification" and there is a last response' do
- incoming_message = mock_model(IncomingMessage)
- @dog_request.stub!(:get_last_response).and_return(incoming_message)
- expect_redirect('waiting_clarification', "request/#{@dog_request.id}/response/#{incoming_message.id}")
- end
-
- it 'should redirect to the "response no followup url" when status is updated to "waiting clarification" and there are no events needing description' do
- @dog_request.stub!(:get_last_response).and_return(nil)
- expect_redirect('waiting_clarification', "request/#{@dog_request.id}/response")
- 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/)
+ end
- it 'should redirect to the "respond to last url" when status is updated to "gone postal"' do
- expect_redirect('gone_postal', "request/#{@dog_request.id}/response/#{@dog_request.get_last_response.id}?gone_postal=1")
- end
-
- it 'should redirect to the "request url" when status is updated to "internal review"' 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")
- 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 unhappy page' do
+ post_status('rejected')
+ response.should redirect_to(:controller => 'help', :action => 'unhappy', :url_title => @dog_request.url_title)
+ end
+
+ it "knows about extended states" do
+ InfoRequest.send(:require, File.expand_path(File.join(File.dirname(__FILE__), '..', 'models', 'customstates')))
+ InfoRequest.send(:include, InfoRequestCustomStates)
+ InfoRequest.class_eval('@@custom_states_loaded = true')
+ RequestController.send(:require, File.expand_path(File.join(File.dirname(__FILE__), '..', 'models', 'customstates')))
+ RequestController.send(:include, RequestControllerCustomStates)
+ RequestController.class_eval('@@custom_states_loaded = true')
+ Time.stub!(:now).and_return(Time.utc(2007, 11, 10, 00, 01))
+ post_status('deadline_extended')
+ flash[:notice].should == 'Authority has requested extension of the deadline.'
+ end
end
-
- it 'should redirect to the "respond to last url url" when status is updated to "user_withdrawn"' do
- expect_redirect('user_withdrawn', "request/#{@dog_request.id}/response/#{@dog_request.get_last_response.id}")
+
+ describe 'when redirecting after a successful status update by the request owner' do
+
+ before do
+ @request_owner = users(:bob_smith_user)
+ session[:user_id] = @request_owner.id
+ @dog_request = info_requests(:fancy_dog_request)
+ @dog_request.stub!(:each).and_return([@dog_request])
+ InfoRequest.stub!(:find).and_return(@dog_request)
+ @old_filters = ActionController::Routing::Routes.filters
+ ActionController::Routing::Routes.filters = RoutingFilter::Chain.new
+ end
+ after do
+ ActionController::Routing::Routes.filters = @old_filters
+ end
+
+ def request_url
+ "request/#{@dog_request.url_title}"
+ end
+
+ def unhappy_url
+ "help/unhappy/#{@dog_request.url_title}"
+ end
+
+ def expect_redirect(status, redirect_path)
+ post_status(status)
+ response.should redirect_to("http://test.host/#{redirect_path}")
+ end
+
+ it 'should redirect to the "request url" with a message in the right tense when status is updated to "waiting response" and the response is not overdue' do
+ @dog_request.stub!(:date_response_required_by).and_return(Time.now.to_date+1)
+ @dog_request.stub!(:date_very_overdue_after).and_return(Time.now.to_date+40)
+
+ expect_redirect("waiting_response", "request/#{@dog_request.url_title}")
+ flash[:notice].should match(/should get a response/)
+ end
+
+ it 'should redirect to the "request url" with a message in the right tense when status is updated to "waiting response" and the response is overdue' do
+ @dog_request.stub!(:date_response_required_by).and_return(Time.now.to_date-1)
+ @dog_request.stub!(:date_very_overdue_after).and_return(Time.now.to_date+40)
+ expect_redirect('waiting_response', request_url)
+ flash[:notice].should match(/should have got a response/)
+ end
+
+ it 'should redirect to the "request url" with a message in the right tense when status is updated to "waiting response" and the response is overdue' do
+ @dog_request.stub!(:date_response_required_by).and_return(Time.now.to_date-2)
+ @dog_request.stub!(:date_very_overdue_after).and_return(Time.now.to_date-1)
+ expect_redirect('waiting_response', unhappy_url)
+ flash[:notice].should match(/is long overdue/)
+ flash[:notice].should match(/by more than 40 working days/)
+ flash[:notice].should match(/within 20 working days/)
+ end
+
+ it 'should redirect to the "request url" when status is updated to "not held"' do
+ expect_redirect('not_held', request_url)
+ end
+
+ it 'should redirect to the "request url" when status is updated to "successful"' do
+ expect_redirect('successful', request_url)
+ end
+
+ it 'should redirect to the "unhappy url" when status is updated to "rejected"' do
+ expect_redirect('rejected', "help/unhappy/#{@dog_request.url_title}")
+ end
+
+ it 'should redirect to the "unhappy url" when status is updated to "partially successful"' do
+ expect_redirect('partially_successful', "help/unhappy/#{@dog_request.url_title}")
+ end
+
+ it 'should redirect to the "response url" when status is updated to "waiting clarification" and there is a last response' do
+ incoming_message = mock_model(IncomingMessage)
+ @dog_request.stub!(:get_last_response).and_return(incoming_message)
+ expect_redirect('waiting_clarification', "request/#{@dog_request.id}/response/#{incoming_message.id}")
+ end
+
+ it 'should redirect to the "response no followup url" when status is updated to "waiting clarification" and there are no events needing description' do
+ @dog_request.stub!(:get_last_response).and_return(nil)
+ expect_redirect('waiting_clarification', "request/#{@dog_request.id}/response")
+ end
+
+ it 'should redirect to the "respond to last url" when status is updated to "gone postal"' do
+ expect_redirect('gone_postal', "request/#{@dog_request.id}/response/#{@dog_request.get_last_response.id}?gone_postal=1")
+ end
+
+ it 'should redirect to the "request url" when status is updated to "internal review"' 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")
+ end
+
+ it 'should redirect to the "help general url" when status is updated to "error message"' do
+ expect_redirect('error_message', "help/contact")
+ end
+
+ it 'should redirect to the "respond to last url url" when status is updated to "user_withdrawn"' do
+ expect_redirect('user_withdrawn', "request/#{@dog_request.id}/response/#{@dog_request.get_last_response.id}")
+ end
+
end
-
+
end
+
end
describe RequestController, "when sending a followup message" do
@@ -1346,7 +1588,7 @@ describe RequestController, "when sending a followup message" do
post :show_response, :outgoing_message => { :body => "What a useless response! You suck.", :what_doing => 'normal_sort'}, :id => info_requests(:fancy_dog_request).id, :incoming_message_id => incoming_messages(:useless_incoming_message), :submitted_followup => 1, :preview => 0, :reedit => "Re-edit this request"
response.should render_template('show_response')
end
-
+
it "should send the follow up message if you are the right user" do
# fake that this is a clarification
info_requests(:fancy_dog_request).set_described_state('waiting_clarification')
@@ -1378,7 +1620,7 @@ describe RequestController, "when sending a followup message" do
# make the followup once
post :show_response, :outgoing_message => { :body => "Stop repeating yourself!", :what_doing => 'normal_sort' }, :id => info_requests(:fancy_dog_request).id, :incoming_message_id => incoming_messages(:useless_incoming_message), :submitted_followup => 1
response.should redirect_to(:action => 'show', :url_title => info_requests(:fancy_dog_request).url_title)
-
+
# second time should give an error
post :show_response, :outgoing_message => { :body => "Stop repeating yourself!", :what_doing => 'normal_sort' }, :id => info_requests(:fancy_dog_request).id, :incoming_message_id => incoming_messages(:useless_incoming_message), :submitted_followup => 1
# XXX how do I check the error message here?
@@ -1392,7 +1634,7 @@ end
describe RequestController, "sending overdue request alerts" do
integrate_views
-
+
before(:each) do
load_raw_emails_data
end
@@ -1407,7 +1649,7 @@ describe RequestController, "sending overdue request alerts" do
chicken_mails = ActionMailer::Base.deliveries.select{|x| x.body =~ /chickens/}
chicken_mails.size.should == 1
mail = chicken_mails[0]
-
+
mail.body.should =~ /promptly, as normally/
mail.to_addrs.first.to_s.should == info_requests(:naughty_chicken_request).user.name_and_email
@@ -1436,7 +1678,7 @@ describe RequestController, "sending overdue request alerts" do
chicken_mails = ActionMailer::Base.deliveries.select{|x| x.body =~ /chickens/}
chicken_mails.size.should == 1
mail = chicken_mails[0]
-
+
mail.body.should =~ /promptly, as normally/
mail.to_addrs.first.to_s.should == info_requests(:naughty_chicken_request).user.name_and_email
end
@@ -1462,7 +1704,7 @@ describe RequestController, "sending overdue request alerts" do
chicken_mails = ActionMailer::Base.deliveries.select{|x| x.body =~ /chickens/}
chicken_mails.size.should == 1
mail = chicken_mails[0]
-
+
mail.body.should =~ /required by law/
mail.to_addrs.first.to_s.should == info_requests(:naughty_chicken_request).user.name_and_email
@@ -1568,9 +1810,9 @@ describe RequestController, "comment alerts" do
before(:each) do
load_raw_emails_data
end
-
+
it "should send an alert (once and once only)" do
- # delete ficture comment and make new one, so is in last month (as
+ # delete fixture comment and make new one, so is in last month (as
# alerts are only for comments in last month, see
# RequestMailer.alert_comment_on_request)
existing_comment = info_requests(:fancy_dog_request).comments[0]
@@ -1586,11 +1828,8 @@ describe RequestController, "comment alerts" do
mail.to_addrs.first.to_s.should == info_requests(:fancy_dog_request).user.name_and_email
mail.body =~ /(http:\/\/.*)/
mail_url = $1
+ mail_url.should match("/request/why_do_you_have_such_a_fancy_dog#comment-#{new_comment.id}")
- # XXX check mail_url here somehow, can't call comment_url like this:
- # mail_url.should == comment_url(comments(:silly_comment))
-
-
# check if we send again, no more go out
deliveries.clear
RequestMailer.alert_comment_on_request
@@ -1599,7 +1838,7 @@ describe RequestController, "comment alerts" do
end
it "should not send an alert when you comment on your own request" do
- # delete ficture comment and make new one, so is in last month (as
+ # delete fixture comment and make new one, so is in last month (as
# alerts are only for comments in last month, see
# RequestMailer.alert_comment_on_request)
existing_comment = info_requests(:fancy_dog_request).comments[0]
@@ -1614,6 +1853,16 @@ describe RequestController, "comment alerts" do
deliveries.size.should == 0
end
+ it 'should not send an alert for a comment on an external request' do
+ external_request = info_requests(:external_request)
+ external_request.add_comment("This external request is interesting", users(:silly_name_user))
+ # try to send comment alert
+ RequestMailer.alert_comment_on_request
+
+ deliveries = ActionMailer::Base.deliveries
+ deliveries.size.should == 0
+ end
+
it "should send an alert when there are two new comments" do
# add two comments - the second one sould be ignored, as is by the user who made the request.
# the new comment here, will cause the one in the fixture to be picked up as a new comment by alert_comment_on_request also.
@@ -1629,9 +1878,7 @@ describe RequestController, "comment alerts" do
mail.to_addrs.first.to_s.should == info_requests(:fancy_dog_request).user.name_and_email
mail.body =~ /(http:\/\/.*)/
mail_url = $1
-
- # XXX check mail_url here somehow, can't call comment_url like this:
- # mail_url.should == comment_url(comments(:silly_comment))
+ mail_url.should match("/request/why_do_you_have_such_a_fancy_dog#comment-#{comments(:silly_comment).id}")
end
@@ -1646,15 +1893,15 @@ describe RequestController, "when viewing comments" do
it "should link to the user who submitted it" do
session[:user_id] = users(:bob_smith_user).id
get :show, :url_title => 'why_do_you_have_such_a_fancy_dog'
- response.body.should have_tag("div#comment-1 h2", /Silly.*left an annotation/m)
- response.body.should_not have_tag("div#comment-1 h2", /You.*left an annotation/m)
+ response.body.should have_tag("div#comment-1 h2", /Silly.*left an annotation/m)
+ response.body.should_not have_tag("div#comment-1 h2", /You.*left an annotation/m)
end
it "should link to the user who submitted to it, even if it is you" do
session[:user_id] = users(:silly_name_user).id
get :show, :url_title => 'why_do_you_have_such_a_fancy_dog'
- response.body.should have_tag("div#comment-1 h2", /Silly.*left an annotation/m)
- response.body.should_not have_tag("div#comment-1 h2", /You.*left an annotation/m)
+ response.body.should have_tag("div#comment-1 h2", /Silly.*left an annotation/m)
+ response.body.should_not have_tag("div#comment-1 h2", /You.*left an annotation/m)
end
end
@@ -1666,17 +1913,17 @@ describe RequestController, "authority uploads a response from the web interface
before(:each) do
# domain after the @ is used for authentication of FOI officers, so to test it
# we need a user which isn't at localhost.
- @normal_user = User.new(:name => "Mr. Normal", :email => "normal-user@flourish.org",
+ @normal_user = User.new(:name => "Mr. Normal", :email => "normal-user@flourish.org",
:password => PostRedirect.generate_random_token)
@normal_user.save!
- @foi_officer_user = User.new(:name => "The Geraldine Quango", :email => "geraldine-requests@localhost",
+ @foi_officer_user = User.new(:name => "The Geraldine Quango", :email => "geraldine-requests@localhost",
:password => PostRedirect.generate_random_token)
@foi_officer_user.save!
end
-
+
it "should require login to view the form to upload" do
- @ir = info_requests(:fancy_dog_request)
+ @ir = info_requests(:fancy_dog_request)
@ir.public_body.is_foi_officer?(@normal_user).should == false
session[:user_id] = @normal_user.id
@@ -1685,7 +1932,7 @@ describe RequestController, "authority uploads a response from the web interface
end
it "should let you view upload form if you are an FOI officer" do
- @ir = info_requests(:fancy_dog_request)
+ @ir = info_requests(:fancy_dog_request)
@ir.public_body.is_foi_officer?(@foi_officer_user).should == true
session[:user_id] = @foi_officer_user.id
@@ -1694,7 +1941,7 @@ describe RequestController, "authority uploads a response from the web interface
end
it "should prevent uploads if you are not a requester" do
- @ir = info_requests(:fancy_dog_request)
+ @ir = info_requests(:fancy_dog_request)
incoming_before = @ir.incoming_messages.size
session[:user_id] = @normal_user.id
@@ -1715,10 +1962,14 @@ describe RequestController, "authority uploads a response from the web interface
flash[:error].should match(/Please type a message/)
end
+ it 'should 404 for non existent requests' do
+ lambda{ post :upload_response, :url_title => 'i_dont_exist'}.should raise_error(ActiveRecord::RecordNotFound)
+ end
+
# How do I test a file upload in rails?
# http://stackoverflow.com/questions/1178587/how-do-i-test-a-file-upload-in-rails
it "should let the authority upload a file" do
- @ir = info_requests(:fancy_dog_request)
+ @ir = info_requests(:fancy_dog_request)
incoming_before = @ir.incoming_messages.size
session[:user_id] = @foi_officer_user.id
@@ -1774,7 +2025,7 @@ describe RequestController, "when doing type ahead searches" do
response.should render_template('request/_search_ahead.rhtml')
assigns[:xapian_requests].should be_nil
end
-
+
it "should return a request matching the given keyword, but not users with a matching description" do
get :search_typeahead, :q => "chicken"
response.should render_template('request/_search_ahead.rhtml')
@@ -1793,13 +2044,13 @@ describe RequestController, "when doing type ahead searches" do
end
it "should not return matches for short words" do
- get :search_typeahead, :q => "a"
+ get :search_typeahead, :q => "a"
response.should render_template('request/_search_ahead.rhtml')
assigns[:xapian_requests].should be_nil
end
it "should do partial matches for longer words" do
- get :search_typeahead, :q => "chick"
+ get :search_typeahead, :q => "chick"
response.should render_template('request/_search_ahead.rhtml')
assigns[:xapian_requests].results.size.should ==1
end
@@ -1836,7 +2087,7 @@ describe RequestController, "when showing similar requests" do
it "should show similar requests" do
badger_request = info_requests(:badger_request)
get :similar, :url_title => badger_request.url_title
-
+
# Xapian seems to think *all* the requests are similar
assigns[:xapian_object].results.map{|x|x[:model].info_request}.should =~ InfoRequest.all.reject {|x| x == badger_request}
end
@@ -1860,21 +2111,27 @@ end
describe RequestController, "when reporting a request (logged in)" do
integrate_views
-
+
before do
@user = users(:robin_user)
session[:user_id] = @user.id
end
+ it "should 404 for non-existent requests" do
+ lambda {
+ post :report_request, :url_title => "hjksfdhjk_louytu_qqxxx"
+ }.should raise_error(ActiveRecord::RecordNotFound)
+ end
+
it "should mark a request as having been reported" do
ir = info_requests(:badger_request)
title = ir.url_title
get :show, :url_title => title
assigns[:info_request].attention_requested.should == false
-
+
post :report_request, :url_title => title
response.should redirect_to(:action => :show, :url_title => title)
-
+
get :show, :url_title => title
response.should be_success
assigns[:info_request].attention_requested.should == true
@@ -1883,13 +2140,13 @@ describe RequestController, "when reporting a request (logged in)" do
it "should not allow a request to be reported twice" do
title = info_requests(:badger_request).url_title
-
+
post :report_request, :url_title => title
response.should redirect_to(:action => :show, :url_title => title)
get :show, :url_title => title
response.should be_success
response.body.should include("has been reported")
-
+
post :report_request, :url_title => title
response.should redirect_to(:action => :show, :url_title => title)
get :show, :url_title => title
@@ -1901,14 +2158,14 @@ describe RequestController, "when reporting a request (logged in)" do
title = info_requests(:badger_request).url_title
get :show, :url_title => title
response.body.should include("Offensive?")
-
+
post :report_request, :url_title => title
response.should redirect_to(:action => :show, :url_title => title)
-
+
get :show, :url_title => title
- response.body.should_not include("Offensive?")
+ response.body.should_not include("Offensive?")
response.body.should include("This request has been reported")
-
+
info_requests(:badger_request).set_described_state("successful")
get :show, :url_title => title
response.body.should_not include("This request has been reported")
diff --git a/spec/controllers/services_controller_spec.rb b/spec/controllers/services_controller_spec.rb
index 2be382258..a701ae247 100644
--- a/spec/controllers/services_controller_spec.rb
+++ b/spec/controllers/services_controller_spec.rb
@@ -2,8 +2,15 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe ServicesController, "when using web services" do
+
integrate_views
-
+
+ # store and restore the locale in the context of the test suite to isolate
+ # changes made in these tests
+ before do
+ @old_locale = FastGettext.locale()
+ end
+
it "should show no alaveteli message when in the deployed country" do
config = MySociety::Config.load_default()
config['ISO_COUNTRY_CODE'] = "DE"
@@ -29,5 +36,8 @@ describe ServicesController, "when using web services" do
response.body.should match(/Puede hacer solicitudes de información en España/)
end
+ after do
+ FastGettext.set_locale(@old_locale)
+ end
-end
+end \ No newline at end of file
diff --git a/spec/controllers/track_controller_spec.rb b/spec/controllers/track_controller_spec.rb
index 1d38b3055..7daa23769 100644
--- a/spec/controllers/track_controller_spec.rb
+++ b/spec/controllers/track_controller_spec.rb
@@ -11,7 +11,13 @@ describe TrackController, "when making a new track on a request" do
TrackThing.stub!(:create_track_for_request).and_return(@track_thing)
TrackThing.stub!(:create_track_for_search_query).and_return(@track_thing)
TrackThing.stub!(:find_by_existing_track).and_return(nil)
- InfoRequest.stub!(:find_by_url_title).and_return(@ir)
+ InfoRequest.stub!(:find_by_url_title!) do |url_title|
+ if url_title == "myrequest"
+ @ir
+ else
+ raise ActiveRecord::RecordNotFound.new("Not found")
+ end
+ end
@user = mock_model(User)
User.stub!(:find).and_return(@user)
@@ -32,6 +38,13 @@ describe TrackController, "when making a new track on a request" do
get :track_request, :url_title => @ir.url_title, :feed => 'track'
response.should redirect_to(:controller => 'request', :action => 'show', :url_title => @ir.url_title)
end
+
+ it "should 404 for non-existent requests" do
+ session[:user_id] = @user.id
+ lambda {
+ get :track_request, :url_title => "hjksfdhjk_louytu_qqxxx", :feed => 'track'
+ }.should raise_error(ActiveRecord::RecordNotFound)
+ end
it "should save a search track and redirect to the right place" do
session[:user_id] = @user.id
diff --git a/spec/fixtures/info_request_events.yml b/spec/fixtures/info_request_events.yml
index e3e8a4460..c1a00ad47 100644
--- a/spec/fixtures/info_request_events.yml
+++ b/spec/fixtures/info_request_events.yml
@@ -16,7 +16,7 @@ silly_outgoing_message_event:
created_at: 2007-10-14 10:41:12.686264
described_state:
outgoing_message_id: 2
-useless_incoming_message_event:
+useless_incoming_message_event:
id: 902
params_yaml: "--- \n\
:incoming_message_id: 1\n"
@@ -25,18 +25,18 @@ useless_incoming_message_event:
created_at: 2007-11-13 18:09:20.042061
described_state:
incoming_message_id: 1
-silly_comment_event:
+silly_comment_event:
id: 903
params_yaml: "--- \n\
:comment_id: 1\n"
- incoming_message_id:
- last_described_at:
- described_state:
+ incoming_message_id:
+ last_described_at:
+ described_state:
info_request_id: 101
comment_id: 1
- calculated_state:
+ calculated_state:
event_type: comment
- outgoing_message_id:
+ outgoing_message_id:
created_at: 2008-08-12 23:05:12.500942
badger_outgoing_message_event:
id: 904
@@ -98,11 +98,11 @@ another_comment_event:
comment_id: 2
params_yaml: "--- \n\
:comment_id: 2\n"
- incoming_message_id:
- outgoing_message_id:
- last_described_at:
- described_state:
- calculated_state:
+ incoming_message_id:
+ outgoing_message_id:
+ last_described_at:
+ described_state:
+ calculated_state:
event_type: comment
created_at: 2008-08-12 12:05:12.879634
@@ -160,3 +160,14 @@ external_outgoing_message_event:
created_at: 2009-01-02 02:23:45.6789100
described_state: waiting_response
calculated_state: waiting_response
+
+anonymous_external_outgoing_message_event:
+ id: 915
+ params_yaml: "--- \n\
+ :outgoing_message_id: 9\n"
+ outgoing_message_id: 9
+ info_request_id: 110
+ event_type: sent
+ created_at: 2009-01-03 02:23:45.6789100
+ described_state: waiting_response
+ calculated_state: waiting_response
diff --git a/spec/fixtures/info_requests.yml b/spec/fixtures/info_requests.yml
index e4f2287c0..079a44cd0 100644
--- a/spec/fixtures/info_requests.yml
+++ b/spec/fixtures/info_requests.yml
@@ -88,3 +88,13 @@ external_request:
described_state: waiting_response
awaiting_description: false
idhash: a1234567
+anonymous_external_request:
+ id: 110
+ title: Anonymous request
+ url_title: anonymous_request
+ external_user_name:
+ external_url: http://www.example.org/request/anonymous_requesr
+ public_body_id: 2
+ described_state: waiting_response
+ awaiting_description: false
+ idhash: 7654321a \ No newline at end of file
diff --git a/spec/fixtures/outgoing_messages.yml b/spec/fixtures/outgoing_messages.yml
index 32b322bd7..55df8473e 100644
--- a/spec/fixtures/outgoing_messages.yml
+++ b/spec/fixtures/outgoing_messages.yml
@@ -97,3 +97,14 @@ external_outgoing_message:
updated_at: 2009-01-12 01:56:58.586598
what_doing: normal_sort
+anonymous_external_outgoing_message:
+ id: 9
+ info_request_id: 110
+ message_type: initial_request
+ status: sent
+ body: "I do not wish to reveal my name, but would like all your information."
+ last_sent_at: 2009-01-12 01:57:58.586598
+ 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/helpers/link_to_helper_spec.rb b/spec/helpers/link_to_helper_spec.rb
index f11f2b5bb..9ec0afce1 100644
--- a/spec/helpers/link_to_helper_spec.rb
+++ b/spec/helpers/link_to_helper_spec.rb
@@ -1,11 +1,11 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
-describe LinkToHelper do
-
+describe LinkToHelper do
+
include LinkToHelper
-
- describe 'when creating a url for a request' do
-
+
+ describe 'when creating a url for a request' do
+
before do
@mock_request = mock_model(InfoRequest, :url_title => 'test_title')
@old_filters = ActionController::Routing::Routes.filters
@@ -15,15 +15,15 @@ describe LinkToHelper do
ActionController::Routing::Routes.filters = @old_filters
end
-
- it 'should return a path like /request/test_title' do
+
+ it 'should return a path like /request/test_title' do
request_url(@mock_request).should == '/request/test_title'
end
-
- it 'should return a path including any extra parameters passed' do
+
+ 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'
end
-
+
end
describe "when appending something to a URL" do
@@ -37,5 +37,15 @@ describe LinkToHelper 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
+ info_request = mock_model(InfoRequest, :external_user_name => nil,
+ :is_external? => true)
+ user_admin_link_for_request(info_request).should == 'Anonymous user (external)'
+ end
+
+ end
+
end
diff --git a/spec/integration/create_request_spec.rb b/spec/integration/create_request_spec.rb
index 6f336d406..56757c7e0 100644
--- a/spec/integration/create_request_spec.rb
+++ b/spec/integration/create_request_spec.rb
@@ -2,14 +2,14 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe "When creating requests" do
it "should associate the request with the requestor, even if it is approved by an admin" do
- # This is a test for https://github.com/sebbacon/alaveteli/issues/446
-
+ # This is a test for https://github.com/mysociety/alaveteli/issues/446
+
params = { :info_request => { :public_body_id => public_bodies(:geraldine_public_body).id,
:title => "Why is your quango called Geraldine?", :tag_string => "" },
:outgoing_message => { :body => "This is a silly letter. It is too short to be interesting." },
:submitted_new_request => 1, :preview => 0
}
-
+
# Initially we are not logged in. Try to create a new request.
post "/new", params
# We expect to be redirected to the login page
@@ -17,13 +17,13 @@ describe "When creating requests" do
response.should redirect_to(:controller => 'user', :action => 'signin', :token => post_redirect.token)
follow_redirect!
response.should render_template("user/sign")
-
+
# Now log in as an unconfirmed user.
post "/profile/sign_in", :user_signin => {:email => users(:unconfirmed_user).email, :password => "jonespassword"}, :token => post_redirect.token
# This will trigger a confirmation mail. Get the PostRedirect for later.
response.should render_template("user/confirm")
post_redirect = PostRedirect.get_last_post_redirect
-
+
# Now log in as an admin user, then follow the confirmation link in the email that was sent to the unconfirmed user
admin_user = users(:admin_user)
admin_user.email_confirmed = true
@@ -37,7 +37,7 @@ describe "When creating requests" do
url_title = $1
info_request = InfoRequest.find_by_url_title(url_title)
info_request.should_not be_nil
-
+
# Make sure the request is still owned by the user who made it, not the admin who confirmed it
info_request.user_id.should == users(:unconfirmed_user).id
end
diff --git a/spec/lib/public_body_categories_spec.rb b/spec/lib/public_body_categories_spec.rb
new file mode 100644
index 000000000..e53d9a028
--- /dev/null
+++ b/spec/lib/public_body_categories_spec.rb
@@ -0,0 +1,42 @@
+require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
+
+describe PublicBodyCategories do
+
+ before do
+ load_test_categories
+ end
+
+ describe 'when asked for categories with headings' do
+
+ it 'should return a list of headings as plain strings, each followed by n tag specifications as
+ lists in the form:
+ ["tag_to_use_as_category", "Sub category title", "Instance description"]' do
+ expected_categories = ["Local and regional", ["local_council",
+ "Local councils",
+ "a local council"],
+ "Miscellaneous", ["other",
+ "Miscellaneous",
+ "miscellaneous"]]
+ PublicBodyCategories::get().with_headings().should == expected_categories
+ end
+
+ end
+
+ describe 'when asked for headings' do
+
+ it 'should return a list of headings' do
+ PublicBodyCategories::get().headings().should == ['Local and regional', 'Miscellaneous']
+ end
+
+ end
+
+ describe 'when asked for tags by headings' do
+
+ it 'should return a hash of tags keyed by heading' do
+ PublicBodyCategories::get().by_heading().should == {'Local and regional' => ['local_council'],
+ 'Miscellaneous' => ['other']}
+ end
+
+ end
+
+end \ No newline at end of file
diff --git a/spec/models/censor_rule_spec.rb b/spec/models/censor_rule_spec.rb
index 44087c5a6..c11b05a03 100644
--- a/spec/models/censor_rule_spec.rb
+++ b/spec/models/censor_rule_spec.rb
@@ -1,25 +1,197 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
-describe CensorRule, "substituting things" do
- before do
- @censor_rule = CensorRule.new
- @censor_rule.text = "goodbye"
- @censor_rule.replacement = "hello"
+describe CensorRule, "substituting things" do
+
+ describe 'when using a text rule' do
+
+ before do
+ @censor_rule = CensorRule.new
+ @censor_rule.text = "goodbye"
+ @censor_rule.replacement = "hello"
+ end
+
+ it 'should do basic text substitution' do
+ body = "I don't know why you say goodbye"
+ @censor_rule.apply_to_text!(body)
+ body.should == "I don't know why you say hello"
+ end
+
+ it 'should keep size same for binary substitution' do
+ body = "I don't know why you say goodbye"
+ orig_body = body.dup
+ @censor_rule.apply_to_binary!(body)
+ body.size.should == orig_body.size
+ body.should == "I don't know why you say xxxxxxx"
+ body.should_not == orig_body # be sure duplicated as expected
+ end
+
end
- it 'should do basic text substitution' do
- body = "I don't know why you say goodbye"
- @censor_rule.apply_to_text!(body)
- body.should == "I don't know why you say hello"
+ describe "when using a regular expression rule" do
+
+ before do
+ @censor_rule = CensorRule.new(:last_edit_editor => 1,
+ :last_edit_comment => 'comment')
+ @censor_rule.text = "--PRIVATE.*--PRIVATE"
+ @censor_rule.replacement = "--REMOVED\nHidden private info\n--REMOVED"
+ @censor_rule.regexp = true
+ @body =
+<<BODY
+Some public information
+--PRIVATE
+Some private information
+--PRIVATE
+BODY
+ end
+
+ it "replaces the regexp with the replacement text when applied to text" do
+ @censor_rule.apply_to_text!(@body)
+ @body.should ==
+<<BODY
+Some public information
+--REMOVED
+Hidden private info
+--REMOVED
+BODY
+ end
+
+ it "replaces the regexp with the same number of 'x' characters as the text replaced
+ when applied to binary" do
+ @censor_rule.apply_to_binary!(@body)
+ @body.should ==
+<<BODY
+Some public information
+xxxxxxxxx
+xxxxxxxxxxxxxxxxxxxxxxxx
+xxxxxxxxx
+BODY
+ end
+
+ end
+
+end
+
+describe 'when validating rules' do
+
+ describe 'should be invalid without text' do
+ censor_rule = CensorRule.new
+ censor_rule.valid?.should == false
+ censor_rule.errors.on(:text).should == "can't be blank"
end
- it 'should keep size same for binary substitution' do
- body = "I don't know why you say goodbye"
- orig_body = body.dup
- @censor_rule.apply_to_binary!(body)
- body.size.should == orig_body.size
- body.should == "I don't know why you say xxxxxxx"
- body.should_not == orig_body # be sure duplicated as expected
+ describe 'when validating a regexp rule' do
+
+ before do
+ @censor_rule = CensorRule.new(:regexp => true,
+ :text => '*')
+ end
+
+ it 'should try to create a regexp from the text' do
+ Regexp.should_receive(:new).with('*', Regexp::MULTILINE)
+ @censor_rule.valid?
+ end
+
+ describe 'if a regexp error is produced' do
+
+ it 'should add an error message to the text field with the regexp error message' do
+ Regexp.stub!(:new).and_raise(RegexpError.new("very bad regexp"))
+ @censor_rule.valid?.should == false
+ @censor_rule.errors.on(:text).should == "very bad regexp"
+ end
+
+ end
+
+ describe 'if no regexp error is produced' do
+
+ it 'should not add any error message to the text field' do
+ Regexp.stub!(:new)
+ @censor_rule.valid?
+ @censor_rule.errors.on(:text).should == nil
+ end
+
+ end
+
end
+
+ describe 'when the allow_global flag has been set' do
+
+ before do
+ @censor_rule = CensorRule.new(:text => 'some text')
+ @censor_rule.allow_global = true
+ end
+
+ it 'should allow a global censor rule (without user_id, request_id or public_body_id)' do
+ @censor_rule.valid?.should == true
+ end
+
+ end
+
+ describe 'when the allow_global flag has not been set' do
+
+ before do
+ @censor_rule = CensorRule.new(:text => '/./')
+ end
+
+ it 'should not allow a global text censor rule (without user_id, request_id or public_body_id)' do
+ @censor_rule.valid?.should == false
+ @expected_error = 'Censor must apply to an info request a user or a body; is invalid'
+ @censor_rule.errors.full_messages.should == [@expected_error]
+ end
+
+ it 'should not allow a global regex censor rule (without user_id, request_id or public_body_id)' do
+ @censor_rule.regexp = true
+ @censor_rule.valid?.should == false
+ @expected_error = 'Censor must apply to an info request a user or a body; is invalid'
+ @censor_rule.errors.full_messages.should == [@expected_error]
+ end
+
+ end
+
end
-
+
+describe 'when handling global rules' do
+
+ describe 'an instance without user_id, request_id or public_body_id' do
+
+ before do
+ @global_rule = CensorRule.new
+ end
+
+ it 'should return a value of true from is_global?' do
+ @global_rule.is_global?.should == true
+ end
+
+ end
+
+ describe 'the scope CensorRule.global.all' do
+
+ before do
+ @global_rule = CensorRule.create!(:allow_global => true,
+ :text => 'hide me',
+ :replacement => 'nothing to see here',
+ :last_edit_editor => 1,
+ :last_edit_comment => 'comment')
+ @user_rule = CensorRule.create!(:user_id => 1,
+ :text => 'hide me',
+ :replacement => 'nothing to see here',
+ :last_edit_editor => 1,
+ :last_edit_comment => 'comment')
+ end
+
+ it 'should include an instance without user_id, request_id or public_body_id' do
+ CensorRule.global.all.include?(@global_rule).should == true
+ end
+
+ it 'should not include a request with user_id' do
+ CensorRule.global.all.include?(@user_rule).should == false
+ end
+
+ after do
+ @global_rule.destroy if @global_rule
+ @user_rule.destroy if @user_rule
+ end
+ end
+
+end
+
+
diff --git a/spec/models/incoming_message_spec.rb b/spec/models/incoming_message_spec.rb
index c6658905c..bc73ef071 100644
--- a/spec/models/incoming_message_spec.rb
+++ b/spec/models/incoming_message_spec.rb
@@ -71,7 +71,7 @@ describe IncomingMessage, " when dealing with incoming mail" do
end
-describe IncomingMessage, "when parsing HTML mail" do
+describe IncomingMessage, "when parsing HTML mail" do
it "should display UTF-8 characters in the plain text version correctly" do
html = "<html><b>foo</b> është"
plain_text = IncomingMessage._get_attachment_text_internal_one_file('text/html', html)
@@ -79,15 +79,15 @@ describe IncomingMessage, "when parsing HTML mail" do
end
end
-describe IncomingMessage, "when getting the attachment text" do
+describe IncomingMessage, "when getting the attachment text" do
- it "should not raise an error if the expansion of a zip file raises an error" do
+ it "should not raise an error if the expansion of a zip file raises an error" do
mock_entry = mock('ZipFile entry', :file? => true)
mock_entry.stub!(:get_input_stream).and_raise("invalid distance too far back")
Zip::ZipFile.stub!(:open).and_return([mock_entry])
IncomingMessage._get_attachment_text_internal_one_file('application/zip', "some string")
end
-
+
end
@@ -196,17 +196,17 @@ describe IncomingMessage, " checking validity to reply to with real emails" do
ActionMailer::Base.deliveries.clear
end
it "should allow a reply to plain emails" do
- ir = info_requests(:fancy_dog_request)
+ ir = info_requests(:fancy_dog_request)
receive_incoming_mail('incoming-request-plain.email', ir.incoming_email)
ir.incoming_messages[1].valid_to_reply_to?.should == true
end
it "should not allow a reply to emails with empty return-paths" do
- ir = info_requests(:fancy_dog_request)
+ ir = info_requests(:fancy_dog_request)
receive_incoming_mail('empty-return-path.email', ir.incoming_email)
ir.incoming_messages[1].valid_to_reply_to?.should == false
end
it "should not allow a reply to emails with autoresponse headers" do
- ir = info_requests(:fancy_dog_request)
+ ir = info_requests(:fancy_dog_request)
receive_incoming_mail('autoresponse-header.email', ir.incoming_email)
ir.incoming_messages[1].valid_to_reply_to?.should == false
end
@@ -234,6 +234,13 @@ describe IncomingMessage, " when censoring data" do
@censor_rule_2.last_edit_comment = "none"
@im.info_request.censor_rules << @censor_rule_2
+ @regex_censor_rule = CensorRule.new()
+ @regex_censor_rule.text = 'm[a-z][a-z][a-z]e'
+ @regex_censor_rule.regexp = true
+ @regex_censor_rule.replacement = 'cat'
+ @regex_censor_rule.last_edit_editor = 'unknown'
+ @regex_censor_rule.last_edit_comment = 'none'
+ @im.info_request.censor_rules << @regex_censor_rule
load_raw_emails_data
end
@@ -246,7 +253,7 @@ describe IncomingMessage, " when censoring data" do
it "should replace censor text in Word documents" do
data = @test_data.dup
@im.binary_mask_stuff!(data, "application/vnd.ms-word")
- data.should == "There was a mouse called xxxxxxx, he wished that he was xxxx."
+ data.should == "There was a xxxxx called xxxxxxx, he wished that he was xxxx."
end
it "should replace ASCII email addresses in Word documents" do
@@ -301,7 +308,7 @@ describe IncomingMessage, " when censoring data" do
it "should apply censor rules to HTML files" do
data = @test_data.dup
@im.html_mask_stuff!(data)
- data.should == "There was a mouse called Jarlsberg, he wished that he was yellow."
+ data.should == "There was a cat called Jarlsberg, he wished that he was yellow."
end
it "should apply hard-coded privacy rules to HTML files" do
@@ -312,8 +319,8 @@ describe IncomingMessage, " when censoring data" do
end
it "should apply censor rules to From: addresses" do
- @im.stub!(:mail_from).and_return("Stilton Mouse")
- @im.stub!(:last_parsed).and_return(Time.now)
+ @im.stub!(:mail_from).and_return("Stilton Mouse")
+ @im.stub!(:last_parsed).and_return(Time.now)
safe_mail_from = @im.safe_mail_from
safe_mail_from.should == "Jarlsberg Mouse"
end
@@ -363,7 +370,7 @@ describe IncomingMessage, " when uudecoding bad messages" do
im = incoming_messages(:useless_incoming_message)
im.stub!(:mail).and_return(mail)
im.extract_attachments!
-
+
attachments = im.foi_attachments
attachments.size.should == 2
attachments[1].filename.should == 'moo.txt'
@@ -407,7 +414,7 @@ describe IncomingMessage, "when messages are attached to messages" do
im = incoming_messages(:useless_incoming_message)
im.stub!(:mail).and_return(mail)
-
+
im.extract_attachments!
attachments = im.get_attachments_for_display
diff --git a/spec/models/info_request_spec.rb b/spec/models/info_request_spec.rb
index a18a4bd1d..c55127992 100644
--- a/spec/models/info_request_spec.rb
+++ b/spec/models/info_request_spec.rb
@@ -1,8 +1,8 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
-describe InfoRequest do
+describe InfoRequest do
- describe "guessing a request from an email" do
+ describe "guessing a request from an email" do
before(:each) do
@im = incoming_messages(:useless_incoming_message)
@@ -17,7 +17,7 @@ describe InfoRequest do
@info_request.idhash.should_not == nil
end
- it 'should find a request based on an email with an intact id and a broken hash' do
+ it 'should find a request based on an email with an intact id and a broken hash' do
ir = info_requests(:fancy_dog_request)
id = ir.id
@im.mail.to = "request-#{id}-asdfg@example.com"
@@ -35,42 +35,42 @@ describe InfoRequest do
end
- describe "making up the URL title" do
+ describe "making up the URL title" do
before do
@info_request = InfoRequest.new
end
- it 'should remove spaces, and make lower case' do
+ it 'should remove spaces, and make lower case' do
@info_request.title = 'Something True'
@info_request.url_title.should == 'something_true'
end
- it 'should not allow a numeric title' do
+ it 'should not allow a numeric title' do
@info_request.title = '1234'
@info_request.url_title.should == 'request'
end
end
-
- describe "when asked for the last event id that needs description" do
-
+
+ describe "when asked for the last event id that needs description" do
+
before do
@info_request = InfoRequest.new
end
-
- it 'should return the last undescribed event id if there is one' do
+
+ it 'should return the last undescribed event id if there is one' do
last_mock_event = mock_model(InfoRequestEvent)
other_mock_event = mock_model(InfoRequestEvent)
@info_request.stub!(:events_needing_description).and_return([other_mock_event, last_mock_event])
@info_request.last_event_id_needing_description.should == last_mock_event.id
- end
-
+ end
+
it 'should return zero if there are no undescribed events' do
@info_request.stub!(:events_needing_description).and_return([])
@info_request.last_event_id_needing_description.should == 0
end
-
+
end
-
+
describe " when emailing" do
before do
@@ -116,7 +116,7 @@ describe InfoRequest do
hash_part = ir.incoming_email.match(/-[0-9a-f]+@/)[0]
break if hash_part.match(/1/)
end
-
+
# Make email with a 1 in the hash part changed to l
test_email = ir.incoming_email
new_hash_part = hash_part.gsub(/1/, "l")
@@ -134,7 +134,7 @@ describe InfoRequest do
end
it "should return nil when receiving email for a deleted request" do
- deleted_request_address = InfoRequest.magic_email_for_id("request-", 98765)
+ deleted_request_address = InfoRequest.magic_email_for_id("request-", 98765)
found_info_request = InfoRequest.find_by_incoming_email(deleted_request_address)
found_info_request.should be_nil
end
@@ -148,7 +148,7 @@ describe InfoRequest do
update_xapian_index
end
- end
+ end
describe "when calculating the status" do
@@ -169,22 +169,22 @@ describe InfoRequest do
end
it "isn't overdue on due date (20 working days after request sent)" do
- Time.stub!(:now).and_return(Time.utc(2007, 11, 9, 23, 59))
+ Time.stub!(:now).and_return(Time.utc(2007, 11, 9, 23, 59))
@ir.calculate_status.should == 'waiting_response'
end
it "is overdue a day after due date (20 working days after request sent)" do
- Time.stub!(:now).and_return(Time.utc(2007, 11, 10, 00, 01))
+ Time.stub!(:now).and_return(Time.utc(2007, 11, 10, 00, 01))
@ir.calculate_status.should == 'waiting_response_overdue'
end
it "is still overdue 40 working days after request sent" do
- Time.stub!(:now).and_return(Time.utc(2007, 12, 10, 23, 59))
+ Time.stub!(:now).and_return(Time.utc(2007, 12, 10, 23, 59))
@ir.calculate_status.should == 'waiting_response_overdue'
end
it "is very overdue the day after 40 working days after request sent" do
- Time.stub!(:now).and_return(Time.utc(2007, 12, 11, 00, 01))
+ Time.stub!(:now).and_return(Time.utc(2007, 12, 11, 00, 01))
@ir.calculate_status.should == 'waiting_response_very_overdue'
end
end
@@ -209,18 +209,18 @@ describe InfoRequest do
it "accepts extended states" do
# this time would normally be "overdue"
- Time.stub!(:now).and_return(Time.utc(2007, 11, 10, 00, 01))
+ Time.stub!(:now).and_return(Time.utc(2007, 11, 10, 00, 01))
@ir.set_described_state("deadline_extended")
@ir.display_status.should == 'Deadline extended.'
@ir.date_deadline_extended
end
-
+
it "is not overdue if it's had the deadline extended" do
when_overdue = Time.utc(2007, 11, 10, 00, 01) + 16.days
- Time.stub!(:now).and_return(when_overdue)
+ Time.stub!(:now).and_return(when_overdue)
@ir.calculate_status.should == 'waiting_response_overdue'
end
-
+
end
@@ -245,160 +245,271 @@ describe InfoRequest do
end
it "isn't overdue on due date (20 working days after request sent)" do
- Time.stub!(:now).and_return(Time.utc(2007, 11, 9, 23, 59))
+ Time.stub!(:now).and_return(Time.utc(2007, 11, 9, 23, 59))
@ir.calculate_status.should == 'waiting_response'
end
it "is overdue a day after due date (20 working days after request sent)" do
- Time.stub!(:now).and_return(Time.utc(2007, 11, 10, 00, 01))
+ Time.stub!(:now).and_return(Time.utc(2007, 11, 10, 00, 01))
@ir.calculate_status.should == 'waiting_response_overdue'
end
it "is still overdue 40 working days after request sent" do
- Time.stub!(:now).and_return(Time.utc(2007, 12, 10, 23, 59))
+ Time.stub!(:now).and_return(Time.utc(2007, 12, 10, 23, 59))
@ir.calculate_status.should == 'waiting_response_overdue'
end
it "is still overdue the day after 40 working days after request sent" do
- Time.stub!(:now).and_return(Time.utc(2007, 12, 11, 00, 01))
+ Time.stub!(:now).and_return(Time.utc(2007, 12, 11, 00, 01))
@ir.calculate_status.should == 'waiting_response_overdue'
end
it "is still overdue 60 working days after request sent" do
- Time.stub!(:now).and_return(Time.utc(2008, 01, 11, 23, 59))
+ Time.stub!(:now).and_return(Time.utc(2008, 01, 11, 23, 59))
@ir.calculate_status.should == 'waiting_response_overdue'
end
it "is very overdue the day after 60 working days after request sent" do
- Time.stub!(:now).and_return(Time.utc(2008, 01, 12, 00, 01))
+ Time.stub!(:now).and_return(Time.utc(2008, 01, 12, 00, 01))
@ir.calculate_status.should == 'waiting_response_very_overdue'
end
end
-
- describe 'when asked if a user is the owning user for this request' do
-
- before do
+
+ describe 'when asked if a user is the owning user for this request' do
+
+ before do
@mock_user = mock_model(User)
@info_request = InfoRequest.new(:user => @mock_user)
@other_mock_user = mock_model(User)
end
-
- it 'should return false if a nil object is passed to it' do
+
+ it 'should return false if a nil object is passed to it' do
@info_request.is_owning_user?(nil).should be_false
end
-
- it 'should return true if the user is the request\'s owner' do
+
+ it 'should return true if the user is the request\'s owner' do
@info_request.is_owning_user?(@mock_user).should be_true
end
-
- it 'should return false for a user that is not the owner and does not own every request' do
+
+ it 'should return false for a user that is not the owner and does not own every request' do
@other_mock_user.stub!(:owns_every_request?).and_return(false)
@info_request.is_owning_user?(@other_mock_user).should be_false
end
-
+
it 'should return true if the user is not the owner but owns every request' do
@other_mock_user.stub!(:owns_every_request?).and_return(true)
@info_request.is_owning_user?(@other_mock_user).should be_true
end
-
+
end
-
- describe 'when asked if it requires admin' do
-
- before do
+
+ describe 'when asked if it requires admin' do
+
+ before do
@info_request = InfoRequest.new
end
-
- it 'should return true if its described state is error_message' do
+
+ it 'should return true if its described state is error_message' do
@info_request.described_state = 'error_message'
@info_request.requires_admin?.should be_true
end
-
- it 'should return true if its described state is requires_admin' do
+
+ it 'should return true if its described state is requires_admin' do
@info_request.described_state = 'requires_admin'
@info_request.requires_admin?.should be_true
end
-
- it 'should return false if its described state is waiting_response' do
+
+ it 'should return false if its described state is waiting_response' do
@info_request.described_state = 'waiting_response'
@info_request.requires_admin?.should be_false
end
-
+
end
-
- describe 'when asked for old unclassified requests' do
-
- before do
+
+ describe 'when asked for old unclassified requests' do
+
+ before do
Time.stub!(:now).and_return(Time.utc(2007, 11, 9, 23, 59))
end
-
- it 'should ask for requests using any limit param supplied' do
- InfoRequest.should_receive(:find).with(:all, {:select => anything,
- :order => anything,
- :conditions=> anything,
+
+ it 'should ask for requests using any limit param supplied' do
+ InfoRequest.should_receive(:find).with(:all, {:select => anything,
+ :order => anything,
+ :conditions=> anything,
:limit => 5})
InfoRequest.find_old_unclassified(:limit => 5)
end
-
- it 'should not limit the number of requests returned by default' do
- InfoRequest.should_not_receive(:find).with(:all, {:select => anything,
- :order => anything,
- :conditions=> anything,
+
+ it 'should not limit the number of requests returned by default' do
+ InfoRequest.should_not_receive(:find).with(:all, {:select => anything,
+ :order => anything,
+ :conditions=> anything,
:limit => anything})
InfoRequest.find_old_unclassified
- end
-
- it 'should add extra conditions if supplied' do
- InfoRequest.should_receive(:find).with(:all,
- {:select=> anything,
- :order=> anything,
- :conditions=>["awaiting_description = ? and (select created_at from info_request_events where info_request_events.info_request_id = info_requests.id and info_request_events.event_type = 'response' order by created_at desc limit 1) < ? and url_title != 'holding_pen' and prominence != 'backpage'",
+ end
+
+ it 'should add extra conditions if supplied' do
+ InfoRequest.should_receive(:find).with(:all,
+ {:select=> anything,
+ :order=> anything,
+ :conditions=>["awaiting_description = ? and (select created_at from info_request_events where info_request_events.info_request_id = info_requests.id and info_request_events.event_type = 'response' order by created_at desc limit 1) < ? and url_title != 'holding_pen' and user_id is not null and prominence != 'backpage'",
true, Time.now - 21.days]})
InfoRequest.find_old_unclassified({:conditions => ["prominence != 'backpage'"]})
end
-
- it 'should ask the database for requests that are awaiting description, have a last response older than 21 days old, are not the holding pen and are not backpaged' do
- InfoRequest.should_receive(:find).with(:all,
- {:select=>"*, (select created_at from info_request_events where info_request_events.info_request_id = info_requests.id and info_request_events.event_type = 'response' order by created_at desc limit 1) as last_response_time",
- :order=>"last_response_time",
- :conditions=>["awaiting_description = ? and (select created_at from info_request_events where info_request_events.info_request_id = info_requests.id and info_request_events.event_type = 'response' order by created_at desc limit 1) < ? and url_title != 'holding_pen'",
+
+ it 'should ask the database for requests that are awaiting description, have a last response older than 21 days old, are not the holding pen and are not backpaged' do
+ InfoRequest.should_receive(:find).with(:all,
+ {:select=>"*, (select created_at from info_request_events where info_request_events.info_request_id = info_requests.id and info_request_events.event_type = 'response' order by created_at desc limit 1) as last_response_time",
+ :order=>"last_response_time",
+ :conditions=>["awaiting_description = ? and (select created_at from info_request_events where info_request_events.info_request_id = info_requests.id and info_request_events.event_type = 'response' order by created_at desc limit 1) < ? and url_title != 'holding_pen' and user_id is not null",
true, Time.now - 21.days]})
InfoRequest.find_old_unclassified
end
-
+
end
-
- describe 'when an instance is asked if it is old and unclassified' do
-
- before do
+
+ describe 'when an instance is asked if it is old and unclassified' 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')
- @info_request = InfoRequest.new(:prominence => 'normal',
- :awaiting_description => true,
+ @info_request = InfoRequest.new(:prominence => 'normal',
+ :awaiting_description => true,
:info_request_events => [@mock_response_event, @mock_comment_event])
end
-
- it 'should return false if it is the holding pen' do
+
+ it 'should return false if it is the holding pen' do
@info_request.stub!(:url_title).and_return('holding_pen')
@info_request.is_old_unclassified?.should be_false
end
-
- it 'should return false if it is not awaiting description' do
+
+ it 'should return false if it is not awaiting description' do
@info_request.stub!(:awaiting_description).and_return(false)
@info_request.is_old_unclassified?.should be_false
end
-
- it 'should return false if its last response event occurred less than 21 days ago' do
+
+ it 'should return false if its last response event occurred less than 21 days ago' do
@mock_response_event.stub!(:created_at).and_return(Time.now - 20.days)
@info_request.is_old_unclassified?.should be_false
end
-
- it 'should return true if it is awaiting description, isn\'t the holding pen and hasn\'t had an event in 21 days' do
- @info_request.is_old_unclassified?.should be_true
+
+ it 'should return true if it is awaiting description, isn\'t the holding pen and hasn\'t had an event in 21 days' do
+ (@info_request.is_external? || @info_request.is_old_unclassified?).should be_true
+ end
+
+ end
+
+ describe 'when applying censor rules' do
+
+ before do
+ @global_rule = mock_model(CensorRule, :apply_to_text! => nil,
+ :apply_to_binary! => nil)
+ @user_rule = mock_model(CensorRule, :apply_to_text! => nil,
+ :apply_to_binary! => nil)
+ @request_rule = mock_model(CensorRule, :apply_to_text! => nil,
+ :apply_to_binary! => nil)
+ @body_rule = mock_model(CensorRule, :apply_to_text! => nil,
+ :apply_to_binary! => nil)
+ @user = mock_model(User, :censor_rules => [@user_rule])
+ @body = mock_model(PublicBody, :censor_rules => [@body_rule])
+ @info_request = InfoRequest.new(:prominence => 'normal',
+ :awaiting_description => true,
+ :title => 'title')
+ @info_request.stub!(:user).and_return(@user)
+ @info_request.stub!(:censor_rules).and_return([@request_rule])
+ @info_request.stub!(:public_body).and_return(@body)
+ @text = 'some text'
+ CensorRule.stub!(:global).and_return(mock('global context', :all => [@global_rule]))
+ end
+
+ context "when applying censor rules to text" do
+
+ it "should apply a global censor rule" do
+ @global_rule.should_receive(:apply_to_text!).with(@text)
+ @info_request.apply_censor_rules_to_text!(@text)
+ end
+
+ it 'should apply a user rule' do
+ @user_rule.should_receive(:apply_to_text!).with(@text)
+ @info_request.apply_censor_rules_to_text!(@text)
+ end
+
+ it 'should not raise an error if there is no user' do
+ @info_request.user_id = nil
+ lambda{ @info_request.apply_censor_rules_to_text!(@text) }.should_not raise_error
+ end
+
+ it 'should apply a rule from the body associated with the request' do
+ @body_rule.should_receive(:apply_to_text!).with(@text)
+ @info_request.apply_censor_rules_to_text!(@text)
+ end
+
+ it 'should apply a request rule' do
+ @request_rule.should_receive(:apply_to_text!).with(@text)
+ @info_request.apply_censor_rules_to_text!(@text)
+ end
+
end
-
+
+ context 'when applying censor rules to binary files' do
+
+ it "should apply a global censor rule" do
+ @global_rule.should_receive(:apply_to_binary!).with(@text)
+ @info_request.apply_censor_rules_to_binary!(@text)
+ end
+
+ it 'should apply a user rule' do
+ @user_rule.should_receive(:apply_to_binary!).with(@text)
+ @info_request.apply_censor_rules_to_binary!(@text)
+ end
+
+ it 'should not raise an error if there is no user' do
+ @info_request.user_id = nil
+ lambda{ @info_request.apply_censor_rules_to_binary!(@text) }.should_not raise_error
+ end
+
+ it 'should apply a rule from the body associated with the request' do
+ @body_rule.should_receive(:apply_to_binary!).with(@text)
+ @info_request.apply_censor_rules_to_binary!(@text)
+ end
+
+ it 'should apply a request rule' do
+ @request_rule.should_receive(:apply_to_binary!).with(@text)
+ @info_request.apply_censor_rules_to_binary!(@text)
+ end
+
+ end
+
+ end
+
+ describe 'when an instance is asked if all can view it' do
+
+ before do
+ @info_request = InfoRequest.new
+ end
+
+ it 'should return true if its prominence is normal' do
+ @info_request.prominence = 'normal'
+ @info_request.all_can_view?.should == true
+ end
+
+ it 'should return true if its prominence is backpage' do
+ @info_request.prominence = 'backpage'
+ @info_request.all_can_view?.should == true
+ end
+
+ it 'should return false if its prominence is hidden' do
+ @info_request.prominence = 'hidden'
+ @info_request.all_can_view?.should == false
+ end
+
+ it 'should return false if its prominence is requester_only' do
+ @info_request.prominence = 'requester_only'
+ @info_request.all_can_view?.should == false
+ end
+
end
-
+
end
diff --git a/spec/models/public_body_spec.rb b/spec/models/public_body_spec.rb
index e30916dff..9e22a9c43 100644
--- a/spec/models/public_body_spec.rb
+++ b/spec/models/public_body_spec.rb
@@ -1,6 +1,6 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
-describe PublicBody, " using tags" do
+describe PublicBody, " using tags" do
before do
@public_body = PublicBody.new(:name => 'Aardvark Monitoring Service',
:short_name => 'AMS',
@@ -9,7 +9,7 @@ describe PublicBody, " using tags" do
:last_edit_comment => '')
end
- it 'should correctly convert a tag string into tags' do
+ it 'should correctly convert a tag string into tags' do
@public_body.tag_string = 'stilton emmental'
@public_body.tag_string.should == 'stilton emmental'
@@ -56,7 +56,7 @@ describe PublicBody, " using tags" do
end
end
-describe PublicBody, " using machine tags" do
+describe PublicBody, " using machine tags" do
before do
@public_body = PublicBody.new(:name => 'Aardvark Monitoring Service',
:short_name => 'AMS',
@@ -114,22 +114,22 @@ describe PublicBody, "when finding_by_tags" do
end
end
-describe PublicBody, " when making up the URL name" do
+describe PublicBody, " when making up the URL name" do
before do
@public_body = PublicBody.new
end
- it 'should remove spaces, and make lower case' do
+ it 'should remove spaces, and make lower case' do
@public_body.name = 'Some Authority'
@public_body.url_name.should == 'some_authority'
end
- it 'should not allow a numeric name' do
+ it 'should not allow a numeric name' do
@public_body.name = '1234'
@public_body.url_name.should == 'body'
end
end
-
+
describe PublicBody, " when saving" do
before do
@public_body = PublicBody.new
@@ -157,14 +157,14 @@ describe PublicBody, " when saving" do
@public_body.last_edit_comment = "This is a test"
@public_body.save!
end
-
+
it "should update first_letter" do
@public_body.name = "Testing Public Body"
@public_body.short_name = "TPB"
@public_body.request_email = "request@localhost"
@public_body.last_edit_editor = "*test*"
@public_body.last_edit_comment = "This is a test"
-
+
@public_body.first_letter.should be_nil
@public_body.save!
@public_body.first_letter.should == 'T'
@@ -208,20 +208,24 @@ describe PublicBody, "when searching" do
body.id.should == 3
body.class.to_s.should == 'PublicBody'
end
-
+
it "should cope with same url_name across multiple locales" do
PublicBody.with_locale(:es) do
# use the unique spanish name to retrieve and edit
body = PublicBody.find_by_url_name_with_historic('etgq')
body.short_name = 'tgq' # Same as english version
- body.save!
-
+ body.save!
+
# now try to retrieve it
body = PublicBody.find_by_url_name_with_historic('tgq')
body.id.should == public_bodies(:geraldine_public_body).id
body.name.should == "El A Geraldine Quango"
end
end
+
+ it 'should not raise an error on a name with a single quote in it' do
+ body = PublicBody.find_by_url_name_with_historic("belfast city council'")
+ end
end
describe PublicBody, " when dealing public body locales" do
@@ -242,7 +246,7 @@ describe PublicBody, " when loading CSV files" do
# depending on the tag used. By accessing it here before every test, it doesn't disturb our checks later on
PublicBody.internal_admin_body
end
-
+
it "should import even if no email is provided" do
errors, notes = PublicBody.import_csv("1,aBody", '', 'replace', true, 'someadmin') # true means dry run
errors.should == []
@@ -250,7 +254,7 @@ describe PublicBody, " when loading CSV files" do
notes[0].should == "line 1: creating new authority 'aBody' (locale: en):\n\t{\"name\":\"aBody\"}"
notes[1].should =~ /Notes: Some bodies are in database, but not in CSV file:\n( [A-Za-z ]+\n)*You may want to delete them manually.\n/
end
-
+
it "should do a dry run successfully" do
original_count = PublicBody.count
@@ -259,8 +263,8 @@ describe PublicBody, " when loading CSV files" do
errors.should == []
notes.size.should == 4
notes[0..2].should == [
- "line 1: creating new authority 'North West Fake Authority' (locale: en):\n\t\{\"name\":\"North West Fake Authority\",\"request_email\":\"north_west_foi@localhost\"\}",
- "line 2: creating new authority 'Scottish Fake Authority' (locale: en):\n\t\{\"name\":\"Scottish Fake Authority\",\"request_email\":\"scottish_foi@localhost\"\}",
+ "line 1: creating new authority 'North West Fake Authority' (locale: en):\n\t\{\"name\":\"North West Fake Authority\",\"request_email\":\"north_west_foi@localhost\"\}",
+ "line 2: creating new authority 'Scottish Fake Authority' (locale: en):\n\t\{\"name\":\"Scottish Fake Authority\",\"request_email\":\"scottish_foi@localhost\"\}",
"line 3: creating new authority 'Fake Authority of Northern Ireland' (locale: en):\n\t\{\"name\":\"Fake Authority of Northern Ireland\",\"request_email\":\"ni_foi@localhost\"\}",
]
notes[3].should =~ /Notes: Some bodies are in database, but not in CSV file:\n( [A-Za-z ]+\n)*You may want to delete them manually.\n/
@@ -276,8 +280,8 @@ describe PublicBody, " when loading CSV files" do
errors.should == []
notes.size.should == 4
notes[0..2].should == [
- "line 1: creating new authority 'North West Fake Authority' (locale: en):\n\t\{\"name\":\"North West Fake Authority\",\"request_email\":\"north_west_foi@localhost\"\}",
- "line 2: creating new authority 'Scottish Fake Authority' (locale: en):\n\t\{\"name\":\"Scottish Fake Authority\",\"request_email\":\"scottish_foi@localhost\"\}",
+ "line 1: creating new authority 'North West Fake Authority' (locale: en):\n\t\{\"name\":\"North West Fake Authority\",\"request_email\":\"north_west_foi@localhost\"\}",
+ "line 2: creating new authority 'Scottish Fake Authority' (locale: en):\n\t\{\"name\":\"Scottish Fake Authority\",\"request_email\":\"scottish_foi@localhost\"\}",
"line 3: creating new authority 'Fake Authority of Northern Ireland' (locale: en):\n\t\{\"name\":\"Fake Authority of Northern Ireland\",\"request_email\":\"ni_foi@localhost\"\}",
]
notes[3].should =~ /Notes: Some bodies are in database, but not in CSV file:\n( [A-Za-z ]+\n)*You may want to delete them manually.\n/
@@ -287,14 +291,14 @@ describe PublicBody, " when loading CSV files" do
it "should do imports without a tag successfully" do
original_count = PublicBody.count
-
+
csv_contents = load_file_fixture("fake-authority-type.csv")
errors, notes = PublicBody.import_csv(csv_contents, '', 'replace', false, 'someadmin') # false means real run
errors.should == []
notes.size.should == 4
notes[0..2].should == [
- "line 1: creating new authority 'North West Fake Authority' (locale: en):\n\t\{\"name\":\"North West Fake Authority\",\"request_email\":\"north_west_foi@localhost\"\}",
- "line 2: creating new authority 'Scottish Fake Authority' (locale: en):\n\t\{\"name\":\"Scottish Fake Authority\",\"request_email\":\"scottish_foi@localhost\"\}",
+ "line 1: creating new authority 'North West Fake Authority' (locale: en):\n\t\{\"name\":\"North West Fake Authority\",\"request_email\":\"north_west_foi@localhost\"\}",
+ "line 2: creating new authority 'Scottish Fake Authority' (locale: en):\n\t\{\"name\":\"Scottish Fake Authority\",\"request_email\":\"scottish_foi@localhost\"\}",
"line 3: creating new authority 'Fake Authority of Northern Ireland' (locale: en):\n\t\{\"name\":\"Fake Authority of Northern Ireland\",\"request_email\":\"ni_foi@localhost\"\}",
]
notes[3].should =~ /Notes: Some bodies are in database, but not in CSV file:\n( [A-Za-z ]+\n)*You may want to delete them manually.\n/
@@ -309,15 +313,15 @@ describe PublicBody, " when loading CSV files" do
errors.should == []
notes.size.should == 4
notes[0..2].should == [
- "line 2: creating new authority 'North West Fake Authority' (locale: en):\n\t\{\"name\":\"North West Fake Authority\",\"request_email\":\"north_west_foi@localhost\",\"home_page\":\"http://northwest.org\"\}",
- "line 3: creating new authority 'Scottish Fake Authority' (locale: en):\n\t\{\"name\":\"Scottish Fake Authority\",\"request_email\":\"scottish_foi@localhost\",\"home_page\":\"http://scottish.org\",\"tag_string\":\"scottish\"\}",
+ "line 2: creating new authority 'North West Fake Authority' (locale: en):\n\t\{\"name\":\"North West Fake Authority\",\"request_email\":\"north_west_foi@localhost\",\"home_page\":\"http://northwest.org\"\}",
+ "line 3: creating new authority 'Scottish Fake Authority' (locale: en):\n\t\{\"name\":\"Scottish Fake Authority\",\"request_email\":\"scottish_foi@localhost\",\"home_page\":\"http://scottish.org\",\"tag_string\":\"scottish\"\}",
"line 4: creating new authority 'Fake Authority of Northern Ireland' (locale: en):\n\t\{\"name\":\"Fake Authority of Northern Ireland\",\"request_email\":\"ni_foi@localhost\",\"tag_string\":\"fake aTag\"\}",
]
notes[3].should =~ /Notes: Some bodies are in database, but not in CSV file:\n( [A-Za-z ]+\n)*You may want to delete them manually.\n/
PublicBody.count.should == original_count
end
-
+
it "should import tags successfully when the import tag is not set" do
csv_contents = load_file_fixture("fake-authority-type-with-field-names.csv")
errors, notes = PublicBody.import_csv(csv_contents, '', 'replace', false, 'someadmin') # false means real run
@@ -344,11 +348,11 @@ describe PublicBody, " when loading CSV files" do
PublicBody.find_by_name('North West Fake Authority').tag_array_for_search.should == ['fake']
PublicBody.find_by_name('Scottish Fake Authority').tag_array_for_search.should == ['fake', 'scottish']
PublicBody.find_by_name('Fake Authority of Northern Ireland').tag_array_for_search.should == ['aTag', 'fake']
-
+
# Import again to check the 'replace' tag functionality works
new_tags_file = load_file_fixture('fake-authority-add-tags.rb')
errors, notes = PublicBody.import_csv(new_tags_file, 'fake', 'replace', false, 'someadmin') # false means real run
-
+
# Check tags were added successfully
PublicBody.find_by_name('North West Fake Authority').tag_array_for_search.should == ['aTag']
PublicBody.find_by_name('Scottish Fake Authority').tag_array_for_search.should == ['aTag']
@@ -363,8 +367,8 @@ describe PublicBody, " when loading CSV files" do
errors.should == []
notes.size.should == 7
notes[0..5].should == [
- "line 2: creating new authority 'North West Fake Authority' (locale: en):\n\t{\"name\":\"North West Fake Authority\",\"request_email\":\"north_west_foi@localhost\",\"home_page\":\"http://northwest.org\"}",
- "line 2: creating new authority 'North West Fake Authority' (locale: es):\n\t{\"name\":\"Autoridad del Nordeste\"}",
+ "line 2: creating new authority 'North West Fake Authority' (locale: en):\n\t{\"name\":\"North West Fake Authority\",\"request_email\":\"north_west_foi@localhost\",\"home_page\":\"http://northwest.org\"}",
+ "line 2: creating new authority 'North West Fake Authority' (locale: es):\n\t{\"name\":\"Autoridad del Nordeste\"}",
"line 3: creating new authority 'Scottish Fake Authority' (locale: en):\n\t{\"name\":\"Scottish Fake Authority\",\"request_email\":\"scottish_foi@localhost\",\"home_page\":\"http://scottish.org\",\"tag_string\":\"scottish\"}",
"line 3: creating new authority 'Scottish Fake Authority' (locale: es):\n\t{\"name\":\"Autoridad Escocesa\"}",
"line 4: creating new authority 'Fake Authority of Northern Ireland' (locale: en):\n\t{\"name\":\"Fake Authority of Northern Ireland\",\"request_email\":\"ni_foi@localhost\",\"tag_string\":\"fake aTag\"}",
@@ -373,8 +377,8 @@ describe PublicBody, " when loading CSV files" do
notes[6].should =~ /Notes: Some bodies are in database, but not in CSV file:\n( [A-Za-z ]+\n)*You may want to delete them manually.\n/
PublicBody.count.should == original_count + 3
-
- # XXX Not sure why trying to do a PublicBody.with_locale fails here. Seems related to
+
+ # XXX Not sure why trying to do a PublicBody.with_locale fails here. Seems related to
# the way categories are loaded every time from the PublicBody class. For now we just
# test some translation was done.
body = PublicBody.find_by_name('North West Fake Authority')
@@ -387,13 +391,13 @@ describe PublicBody, " when loading CSV files" do
csv_contents = load_file_fixture("fake-authority-type-with-field-names.csv")
# Depending on the runtime environment (Ruby version? OS?) the list of available locales
# is made of strings or symbols, so we use 'en' here as a string to test both scenarios.
- # See https://github.com/sebbacon/alaveteli/issues/193
+ # See https://github.com/mysociety/alaveteli/issues/193
errors, notes = PublicBody.import_csv(csv_contents, '', 'replace', true, 'someadmin', ['en', :xx]) # true means dry run
errors.should == []
notes.size.should == 4
notes[0..2].should == [
"line 2: creating new authority 'North West Fake Authority' (locale: en):\n\t{\"name\":\"North West Fake Authority\",\"request_email\":\"north_west_foi@localhost\",\"home_page\":\"http://northwest.org\"}",
- "line 3: creating new authority 'Scottish Fake Authority' (locale: en):\n\t{\"name\":\"Scottish Fake Authority\",\"request_email\":\"scottish_foi@localhost\",\"home_page\":\"http://scottish.org\",\"tag_string\":\"scottish\"}",
+ "line 3: creating new authority 'Scottish Fake Authority' (locale: en):\n\t{\"name\":\"Scottish Fake Authority\",\"request_email\":\"scottish_foi@localhost\",\"home_page\":\"http://scottish.org\",\"tag_string\":\"scottish\"}",
"line 4: creating new authority 'Fake Authority of Northern Ireland' (locale: en):\n\t{\"name\":\"Fake Authority of Northern Ireland\",\"request_email\":\"ni_foi@localhost\",\"tag_string\":\"fake aTag\"}",
]
notes[3].should =~ /Notes: Some bodies are in database, but not in CSV file:\n( [A-Za-z ]+\n)*You may want to delete them manually.\n/
diff --git a/spec/models/request_mailer_spec.rb b/spec/models/request_mailer_spec.rb
index 64ac35cf7..ea75ec765 100644
--- a/spec/models/request_mailer_spec.rb
+++ b/spec/models/request_mailer_spec.rb
@@ -223,7 +223,7 @@ describe RequestMailer, "when sending reminders to requesters to classify a resp
end
it 'should ask for all requests that are awaiting description and whose latest response is older than the number of days given and that are not the holding pen' do
- expected_params = {:conditions => [ "awaiting_description = ? and (select created_at from info_request_events where info_request_events.info_request_id = info_requests.id and info_request_events.event_type = 'response' order by created_at desc limit 1) < ? and url_title != 'holding_pen'",
+ expected_params = {:conditions => [ "awaiting_description = ? and (select created_at from info_request_events where info_request_events.info_request_id = info_requests.id and info_request_events.event_type = 'response' order by created_at desc limit 1) < ? and url_title != 'holding_pen' and user_id is not null",
true, Time.now() - 7.days ],
:include => [ :user ],
:order => "info_requests.id"}
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index a7f3020c1..6a4d0f2d5 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -5,7 +5,7 @@ require File.expand_path(File.join('..', '..', 'config', 'environment'), __FILE_
require 'spec/autorun'
require 'spec/rails'
-# set a default username and password so we can test
+# set a default username and password so we can test
config = MySociety::Config.load_default()
config['ADMIN_USERNAME'] = 'foo'
config['ADMIN_PASSWORD'] = 'baz'
@@ -31,7 +31,21 @@ Spec::Runner.configure do |config|
# fixture_path must end in a separator
config.fixture_path = File.join(Rails.root, 'spec', 'fixtures') + File::SEPARATOR
- config.global_fixtures = :users, :public_bodies, :public_body_translations, :public_body_versions, :info_requests, :raw_emails, :incoming_messages, :outgoing_messages, :comments, :info_request_events, :track_things, :foi_attachments, :has_tag_string_tags, :holidays, :track_things_sent_emails
+ config.global_fixtures = :users,
+ :public_bodies,
+ :public_body_translations,
+ :public_body_versions,
+ :info_requests,
+ :raw_emails,
+ :incoming_messages,
+ :outgoing_messages,
+ :comments,
+ :info_request_events,
+ :track_things,
+ :foi_attachments,
+ :has_tag_string_tags,
+ :holidays,
+ :track_things_sent_emails
# == Fixtures
#
@@ -66,7 +80,7 @@ Spec::Runner.configure do |config|
# For more information take a look at Spec::Runner::Configuration and Spec::Runner
end
-# XXX No idea what namespace/class/module to put this in
+# XXX No idea what namespace/class/module to put this in
def receive_incoming_mail(email_name, email_to, email_from = 'geraldinequango@localhost')
email_name = file_fixture_name(email_name)
content = File.read(email_name)
@@ -97,15 +111,15 @@ def rebuild_xapian_index(terms = true, values = true, texts = true, dropfirst =
end
parse_all_incoming_messages
verbose = false
- # safe_rebuild=true, which involves forking to avoid memory leaks, doesn't work well with rspec.
+ # safe_rebuild=true, which involves forking to avoid memory leaks, doesn't work well with rspec.
# unsafe is significantly faster, and we can afford possible memory leaks while testing.
safe_rebuild = false
- ActsAsXapian.rebuild_index(["PublicBody", "User", "InfoRequestEvent"].map{|m| m.constantize}, verbose, terms, values, texts, safe_rebuild)
+ ActsAsXapian.rebuild_index(["PublicBody", "User", "InfoRequestEvent"].map{|m| m.constantize}, verbose, terms, values, texts, safe_rebuild)
end
def update_xapian_index
verbose = false
- ActsAsXapian.update_index(flush_to_disk=false, verbose)
+ ActsAsXapian.update_index(flush_to_disk=false, verbose)
end
# Validate an entire HTML page
@@ -206,3 +220,16 @@ def load_test_categories
"Miscellaneous",
[ "other", "Miscellaneous", "miscellaneous" ],])
end
+
+
+# Monkeypatch applicationcontroller because the `render_to_string`
+# method in the original breaks all the rspec test assertions such as
+# `should render_template('foo')`. Same problem as
+# http://stackoverflow.com/questions/8174415/is-it-possible-to-assert-template-or-render-template-against-the-same-partial-wi
+# - a bug in either Rails or Rspec I don't have the time to fix :(
+
+class ApplicationController < ActionController::Base
+ def set_popup_banner
+ @popup_banner = nil
+ end
+end
diff --git a/spec/views/request/_after_actions.rhtml_spec.rb b/spec/views/request/_after_actions.rhtml_spec.rb
index 6a56e7a71..d04db3fc2 100644
--- a/spec/views/request/_after_actions.rhtml_spec.rb
+++ b/spec/views/request/_after_actions.rhtml_spec.rb
@@ -9,6 +9,8 @@ describe 'when displaying actions that can be taken with regard to a request' do
:url_name => 'test_user')
@mock_request = mock_model(InfoRequest, :title => 'test request',
:user => @mock_user,
+ :user_name => @mock_user.name,
+ :is_external? => false,
:public_body => @mock_body,
:url_title => 'test_request')
assigns[:info_request] = @mock_request
diff --git a/spec/views/request/_describe_state.rhtml_spec.rb b/spec/views/request/_describe_state.rhtml_spec.rb
index ccf653b1b..18778d5d2 100644
--- a/spec/views/request/_describe_state.rhtml_spec.rb
+++ b/spec/views/request/_describe_state.rhtml_spec.rb
@@ -18,7 +18,12 @@ describe 'when showing the form for describing the state of a request' do
before do
@mock_user = mock_model(User, :name => 'test user', :url_name => 'test_user')
- @mock_request = mock_model(InfoRequest, :described_state => '', :user => @mock_user)
+ @mock_request = mock_model(InfoRequest,
+ :described_state => '',
+ :user => @mock_user,
+ :user_name => @mock_user.name,
+ :is_external? => false
+ )
assigns[:info_request] = @mock_request
end
diff --git a/spec/views/request/show.rhtml_spec.rb b/spec/views/request/show.rhtml_spec.rb
index ef7d1a47c..4429e9e58 100644
--- a/spec/views/request/show.rhtml_spec.rb
+++ b/spec/views/request/show.rhtml_spec.rb
@@ -15,6 +15,8 @@ describe 'when viewing an information request' do
:law_used_full => 'Freedom of Information',
:public_body => @mock_body,
:user => @mock_user,
+ :user_name => @mock_user.name,
+ :is_external? => false,
:calculate_status => 'waiting_response',
:date_response_required_by => Date.today,
:prominence => 'normal')