aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/general_controller_spec.rb53
-rw-r--r--spec/controllers/public_body_controller_spec.rb14
-rw-r--r--spec/controllers/services_controller_spec.rb2
-rw-r--r--spec/fixtures/files/document-pdf.email110
-rw-r--r--spec/fixtures/public_body_translations.yml20
-rw-r--r--spec/lib/mail_handler/mail_handler_spec.rb8
-rw-r--r--spec/lib/sendmail_return_path_spec.rb88
-rw-r--r--spec/mailers/application_mailer_spec.rb2
-rw-r--r--spec/mailers/request_mailer_spec.rb21
-rw-r--r--spec/models/info_request_spec.rb58
-rw-r--r--spec/models/public_body_spec.rb32
-rw-r--r--spec/models/xapian_spec.rb2
-rw-r--r--spec/spec_helper.rb4
13 files changed, 278 insertions, 136 deletions
diff --git a/spec/controllers/general_controller_spec.rb b/spec/controllers/general_controller_spec.rb
index 116dbe07a..7590a5b42 100644
--- a/spec/controllers/general_controller_spec.rb
+++ b/spec/controllers/general_controller_spec.rb
@@ -42,6 +42,17 @@ describe GeneralController, 'when getting the blog feed' do
assigns[:blog_items].count.should == 1
end
+ context 'if no feed is configured' do
+
+ before do
+ AlaveteliConfiguration.stub!(:blog_feed).and_return('')
+ end
+
+ it 'should raise an ActiveRecord::RecordNotFound error' do
+ lambda{ get :blog }.should raise_error(ActiveRecord::RecordNotFound)
+ end
+ end
+
end
describe GeneralController, "when showing the frontpage" do
@@ -116,49 +127,7 @@ describe GeneralController, "when showing the frontpage" do
end
end
-describe GeneralController, "when showing the front page with fixture data" do
-
- describe 'when constructing the list of recent requests' do
-
- before(:each) do
- get_fixtures_xapian_index
- end
-
- describe 'when there are fewer than five successful requests' do
-
- it 'should list the most recently sent and successful requests by the creation date of the
- request event' do
- # Make sure the newest response is listed first even if a request
- # with an older response has a newer comment or was reclassified more recently:
- # https://github.com/mysociety/alaveteli/issues/370
- #
- # This is a deliberate behaviour change, in that the
- # previous behaviour (showing more-recently-reclassified
- # requests first) was intentional.
- get :frontpage
-
- request_events = assigns[:request_events]
- previous = nil
- request_events.each do |event|
- if previous
- previous.created_at.should be >= event.created_at
- end
- ['sent', 'response'].include?(event.event_type).should be_true
- if event.event_type == 'response'
- ['successful', 'partially_successful'].include?(event.calculated_state).should be_true
- end
- previous = event
- end
- end
- end
-
- it 'should coalesce duplicate requests' do
- get :frontpage
- assigns[:request_events].map(&:info_request).select{|x|x.url_title =~ /^spam/}.length.should == 1
- end
- end
-end
describe GeneralController, 'when using xapian search' do
diff --git a/spec/controllers/public_body_controller_spec.rb b/spec/controllers/public_body_controller_spec.rb
index 0e0b0a575..63989baaa 100644
--- a/spec/controllers/public_body_controller_spec.rb
+++ b/spec/controllers/public_body_controller_spec.rb
@@ -275,6 +275,20 @@ describe PublicBodyController, "when showing JSON version for API" do
end
+describe PublicBodyController, "when asked to export public bodies as CSV" do
+
+ it "should return a valid CSV file with the right number of rows" do
+ get :list_all_csv
+ all_data = CSV.parse response.body
+ all_data.length.should == 8
+ # Check that the header has the right number of columns:
+ all_data[0].length.should == 11
+ # And an actual line of data:
+ all_data[1].length.should == 11
+ end
+
+end
+
describe PublicBodyController, "when showing public body statistics" do
it "should render the right template with the right data" do
diff --git a/spec/controllers/services_controller_spec.rb b/spec/controllers/services_controller_spec.rb
index 399f48acb..14731f090 100644
--- a/spec/controllers/services_controller_spec.rb
+++ b/spec/controllers/services_controller_spec.rb
@@ -58,7 +58,7 @@ describe ServicesController, "when returning a message for people in other count
FakeWeb.register_uri(:get, %r|denmark.com|, :body => "DK")
get :other_country_message
response.should be_success
- response.body.should == 'Hello! We have an <a href="/help/alaveteli?country_name=Deutschland">important message</a> for visitors outside Deutschland <span class="close-button">X</span>'
+ response.body.should == 'Hello! We have an <a href="/help/alaveteli?country_name=Deutschland">important message</a> for visitors outside Deutschland'
end
it "should default to no message if the country_from_ip domain doesn't exist" do
AlaveteliConfiguration.stub!(:gaze_url).and_return('http://12123sdf14qsd.com')
diff --git a/spec/fixtures/files/document-pdf.email b/spec/fixtures/files/document-pdf.email
new file mode 100644
index 000000000..f4fc6f0fe
--- /dev/null
+++ b/spec/fixtures/files/document-pdf.email
@@ -0,0 +1,110 @@
+From authority@example.org Tue Dec 3 11:13:02 2013
+Return-path: <authority@example.org>
+Envelope-to: requester@example.org
+Delivery-date: Tue, 03 Dec 2013 11:13:00 +0000
+From: Test Authority <authority@example.org>
+To: requester@example.org
+Subject: testing a PDF attachment with the wrong content-type
+Date: Tue, 03 Dec 2013 11:12:45 +0000
+Message-ID: <87li09xuasdfasdfpoija@blahblah>
+MIME-Version: 1.0
+Content-Type: multipart/mixed; boundary="=-=-="
+
+--=-=-=
+Content-Type: text/plain
+
+Here's a PDF attachement which has a document/pdf content-type,
+when it really should be application/pdf.
+
+
+--=-=-=
+Content-Type: application/pdf
+Content-Disposition: attachment; filename=tiny-example.pdf
+Content-Transfer-Encoding: base64
+Content-Description: a very small example PDF
+
+JVBERi0xLjUKJbXtrvsKMyAwIG9iago8PCAvTGVuZ3RoIDQgMCBSCiAgIC9GaWx0ZXIgL0ZsYXRl
+RGVjb2RlCj4+CnN0cmVhbQp4nCvkMlAAwaJ0Bf1EA4X0Yi6nEC5DA1M9IwNLYzNjsBwS18hIz9TI
+0tBSwdzIQs/Y3MLAzEQhJJdLP03XQBeoUCEkjStawyM1JydfUTM2xIvLNYQrkAsAJG8VmQplbmRz
+dHJlYW0KZW5kb2JqCjQgMCBvYmoKICAgOTIKZW5kb2JqCjIgMCBvYmoKPDwKICAgL0V4dEdTdGF0
+ZSA8PAogICAgICAvYTAgPDwgL0NBIDEgL2NhIDEgPj4KICAgPj4KICAgL0ZvbnQgPDwKICAgICAg
+L2YtMC0wIDUgMCBSCiAgID4+Cj4+CmVuZG9iago2IDAgb2JqCjw8IC9UeXBlIC9QYWdlCiAgIC9Q
+YXJlbnQgMSAwIFIKICAgL01lZGlhQm94IFsgMCAwIDU5NS4yNzU1NzQgODQxLjg4OTc3MSBdCiAg
+IC9Db250ZW50cyAzID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wIG4gCjAwMDAwMDAyMDUgMDAwMDAgbiAKMDAwMDAwMDAx
+NSAwMDAwMCBuIAowMDAwMDAwMTg0IDAwMDAwIG4gCjAwMDAwMDM2NzkgMDAwMDAgbiAKMDAwMDAw
+MDMxNCAwMDAwMCBuIAowMDAwMDAwNTQyIDAwMDAwIG4gCjAwMDAwMDMwMzggMDAwMDAgbiAKMDAw
+MDAwMzA2MSAwMDAwMCBuIAowMDAwMDAzMzg1IDAwMDAwIG4gCjAwMDAwMDM0MDggMDAwMDAgbiAK
+MDAwMDAwNDEyNyAwMDAwMCBuIAowMDAwMDA0MjU3IDAwMDAwIG4gCnRyYWlsZXIKPDwgL1NpemUg
+MTQKICAgL1Jvb3QgMTMgMCBSCiAgIC9JbmZvIDEyIDAgUgo+PgpzdGFydHhyZWYKNDMxMAolJUVP
+Rgo=
+--=-=-=--
+
diff --git a/spec/fixtures/public_body_translations.yml b/spec/fixtures/public_body_translations.yml
index 2030804ac..225bd74e2 100644
--- a/spec/fixtures/public_body_translations.yml
+++ b/spec/fixtures/public_body_translations.yml
@@ -10,6 +10,8 @@ geraldine_es_public_body_translation:
notes: ""
publication_scheme: ""
disclosure_log: ""
+ created_at: 2007-10-24 10:51:01.161639
+ updated_at: 2007-10-24 10:51:01.161639
geraldine_en_public_body_translation:
name: Geraldine Quango
@@ -23,6 +25,8 @@ geraldine_en_public_body_translation:
notes: ""
publication_scheme: ""
disclosure_log: ""
+ created_at: 2007-10-24 10:51:01.161639
+ updated_at: 2007-10-24 10:51:01.161639
humpadink_es_public_body_translation:
name: "El Department for Humpadinking"
@@ -36,6 +40,8 @@ humpadink_es_public_body_translation:
notes: Baguette
publication_scheme: ""
disclosure_log: ""
+ created_at: 2007-10-24 10:51:01.161639
+ updated_at: 2007-10-24 10:51:01.161639
humpadink_en_public_body_translation:
name: "Department for Humpadinking"
@@ -49,6 +55,8 @@ humpadink_en_public_body_translation:
notes: An albatross told me!!!
publication_scheme: ""
disclosure_log: ""
+ created_at: 2007-10-24 10:51:01.161639
+ updated_at: 2007-10-24 10:51:01.161639
forlorn_en_public_body_translation:
name: "Department of Loneliness"
@@ -62,6 +70,8 @@ forlorn_en_public_body_translation:
notes: A very lonely public body that no one has corresponded with
publication_scheme: ""
disclosure_log: ""
+ created_at: 2007-10-24 10:51:01.161639
+ updated_at: 2007-10-24 10:51:01.161639
silly_walks_en_public_body_translation:
id: 6
@@ -75,6 +85,8 @@ silly_walks_en_public_body_translation:
notes: You know the one.
publication_scheme: ""
disclosure_log: ""
+ created_at: 2007-10-24 10:51:01.161639
+ updated_at: 2007-10-24 10:51:01.161639
sensible_walks_en_public_body_translation:
id: 7
@@ -88,6 +100,8 @@ sensible_walks_en_public_body_translation:
notes: I bet you’ve never heard of it.
publication_scheme: ""
disclosure_log: ""
+ created_at: 2008-10-25 10:51:01.161639
+ updated_at: 2008-10-25 10:51:01.161639
other_public_body_translation:
id: 8
@@ -101,6 +115,8 @@ other_public_body_translation:
notes: More notes
publication_scheme: ""
disclosure_log: ""
+ created_at: 2008-10-25 10:51:01.161639
+ updated_at: 2008-10-25 10:51:01.161639
humpadink_he_IL_public_body_translation:
name: "Hebrew Humpadinking"
@@ -114,6 +130,8 @@ humpadink_he_IL_public_body_translation:
notes: An albatross told me!!!
publication_scheme: ""
disclosure_log: ""
+ created_at: 2007-10-24 10:51:01.161639
+ updated_at: 2007-10-24 10:51:01.161639
accented_public_body_translation:
id: 10
@@ -127,3 +145,5 @@ accented_public_body_translation:
notes: This is to test unicode handling in body names
publication_scheme: ""
disclosure_log: ""
+ created_at: 2008-10-25 10:51:01.161639
+ updated_at: 2008-10-25 10:51:01.161639
diff --git a/spec/lib/mail_handler/mail_handler_spec.rb b/spec/lib/mail_handler/mail_handler_spec.rb
index aa351bd94..49a65dade 100644
--- a/spec/lib/mail_handler/mail_handler_spec.rb
+++ b/spec/lib/mail_handler/mail_handler_spec.rb
@@ -235,7 +235,7 @@ describe 'when deriving a name, email and formatted address from a message from
it 'should quote a name with quotes in it' do
should_render_from_address('"FOI \" Person" <foiperson@localhost>',
- ['FOI \" Person',
+ ['FOI " Person',
'foiperson@localhost',
'"FOI \" Person" <foiperson@localhost>'])
end
@@ -409,6 +409,12 @@ describe 'when getting attachment attributes' do
attributes[1][:body].length.should == 7769
end
+ it 'should treat a document/pdf attachment as application/pdf' do
+ mail = get_fixture_mail('document-pdf.email')
+ attributes = MailHandler.get_attachment_attributes(mail)
+ attributes[1][:content_type].should == "application/pdf"
+ end
+
it 'should produce a consistent set of url_part_numbers, content_types, within_rfc822_subjects
and filenames from an example mail with lots of attachments' do
mail = get_fixture_mail('many-attachments-date-header.email')
diff --git a/spec/lib/sendmail_return_path_spec.rb b/spec/lib/sendmail_return_path_spec.rb
deleted file mode 100644
index 83436c2bd..000000000
--- a/spec/lib/sendmail_return_path_spec.rb
+++ /dev/null
@@ -1,88 +0,0 @@
-# This is a test of the monkey patches in sendmail_return_path.rb
-
-# In Rails 3 the monkeypatches are not needed anymore because sendmail now has the "-f" flag
-# set correctly. So, strictly these tests are testing the Rails internals. So, that means we really
-# should delete them. Let's do that later when things have settled down. For the time being leave
-# them in
-
-require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
-
-describe "when sending email with an altered return path" do
- before(:each) { ActionMailer::Base.deliveries = [] }
-
- it "should default to delivery method test" do
- ActionMailer::Base.delivery_method.should == :test
- end
-
- it "should let the helper change the method" do
- with_delivery_method :smtp do
- ActionMailer::Base.delivery_method.should == :smtp
- end
- ActionMailer::Base.delivery_method.should == :test
- end
-
- # Documentation for fancy mock functions: http://rspec.info/documentation/mocks/message_expectations.html
- it "should set the return path when sending email using SMTP" do
- mock_smtp = mock("smtp")
- mock_smtp_session = mock("smtp_session")
-
- mock_smtp.should_receive(:start).once.and_yield(mock_smtp_session)
- # the second parameter to the SMTP session is the sender (return path)
- mock_smtp_session.should_receive(:sendmail).once.with(anything(), "test@localhost", anything())
-
- Net::SMTP.stub!(:new).and_return(mock_smtp)
-
- with_delivery_method :smtp do
- ContactMailer.to_admin_message(
- "Mr. Test", "test@localhost", "Test script spec/lib/sendmail_return_path_spec.rb",
- "This is just a test for a test script", nil, nil, nil
- ).deliver
- end
-
- deliveries = ActionMailer::Base.deliveries
- deliveries.size.should == 0
- end
-
- it "should set the return path when sending email using sendmail" do
- with_stub_popen do
- IO.should_receive(:popen).once.with('/usr/sbin/sendmail -i -t -f "test@localhost" postmaster@localhost', "w+")
- with_delivery_method :sendmail do
- ContactMailer.to_admin_message(
- "Mr. Test", "test@localhost", "Test script spec/lib/sendmail_return_path_spec.rb",
- "This is just a test for a test script", nil, nil, nil
- ).deliver
- end
- end
-
- deliveries = ActionMailer::Base.deliveries
- deliveries.size.should == 0
- end
-
-
- protected
- # Change the way Rails delivers memory, just for current scope
- def with_delivery_method(new_delivery_method)
- old_delivery_method, ActionMailer::Base.delivery_method = ActionMailer::Base.delivery_method, new_delivery_method
- yield
- ensure
- ActionMailer::Base.delivery_method = old_delivery_method
- end
-
- # By default, we can't stub popen, presumably because it is a builtin written in C.
- # Replace it entirely with a normal method that just calls the C one, so we can stub it -
- # this leaves IO working afterwards (for other tests that run in the same instance).
- def with_stub_popen()
- IO.class_eval "@orig_popen = self.method(:popen); def self.popen(a, b, &c); @orig_popen.call(a, b, &c); end"
- begin
- yield
- ensure
- # in theory would undo the popen alterations and return IO to a pristine state, but
- # don't know how to (much fiddling with alias bind and the like didn't help). It
- # doesn't matter - the new popen should behave just the same.
- end
- end
-
-
-end
-
-
diff --git a/spec/mailers/application_mailer_spec.rb b/spec/mailers/application_mailer_spec.rb
index d8993f78f..718ac47fb 100644
--- a/spec/mailers/application_mailer_spec.rb
+++ b/spec/mailers/application_mailer_spec.rb
@@ -13,7 +13,7 @@ describe ApplicationMailer do
end
def add_mail_methods(method_names)
- method_names.each{ |method_name| ApplicationMailer.send(:define_method, method_name){} }
+ method_names.each{ |method_name| ApplicationMailer.send(:define_method, method_name){ mail() } }
end
def remove_mail_methods(method_names)
diff --git a/spec/mailers/request_mailer_spec.rb b/spec/mailers/request_mailer_spec.rb
index 4e0765921..516d13127 100644
--- a/spec/mailers/request_mailer_spec.rb
+++ b/spec/mailers/request_mailer_spec.rb
@@ -332,6 +332,27 @@ describe RequestMailer, 'when sending mail when someone has updated an old uncla
end
+describe RequestMailer, 'when generating a fake response for an upload' do
+
+ before do
+ @foi_officer = mock_model(User, :name_and_email => "FOI officer's name and email")
+ @request_user = mock_model(User)
+ @public_body = mock_model(PublicBody, :name => 'Test public body')
+ @info_request = mock_model(InfoRequest, :user => @request_user,
+ :email_subject_followup => 'Re: Freedom of Information - Test request',
+ :incoming_name_and_email => 'Someone <someone@example.org>')
+ end
+
+ it 'should should generate a "fake response" email with a reasonable subject line' do
+ fake_email = RequestMailer.fake_response(@info_request,
+ @foi_officer,
+ "The body of the email...",
+ "blah.txt",
+ "The content of blah.txt")
+ fake_email.subject.should == "Re: Freedom of Information - Test request"
+ end
+
+end
describe RequestMailer, 'when sending a new response email' do
diff --git a/spec/models/info_request_spec.rb b/spec/models/info_request_spec.rb
index 64ad1972e..dcc94e967 100644
--- a/spec/models/info_request_spec.rb
+++ b/spec/models/info_request_spec.rb
@@ -27,7 +27,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe InfoRequest do
- describe 'when validating', :focus => true do
+ describe 'when validating' do
it 'should accept a summary with ascii characters' do
info_request = InfoRequest.new(:title => 'abcde')
@@ -1030,7 +1030,7 @@ describe InfoRequest do
end
end
- context "another series of events on a request", :focus => true do
+ context "another series of events on a request" do
it "should have sensible event states" do
# An initial request is sent
request.log_event('sent', {})
@@ -1122,5 +1122,59 @@ describe InfoRequest do
end
+ describe InfoRequest, 'when getting similar requests' do
+
+ before(:each) do
+ get_fixtures_xapian_index
+ end
+
+ it 'should return similar requests' do
+ similar, more = info_requests(:spam_1_request).similar_requests(1)
+ similar.results.first[:model].info_request.should == info_requests(:spam_2_request)
+ end
+
+ it 'should return a flag set to true' do
+ similar, more = info_requests(:spam_1_request).similar_requests(1)
+ more.should be_true
+ end
+
+ end
+
+ describe InfoRequest, 'when constructing the list of recent requests' do
+ before(:each) do
+ get_fixtures_xapian_index
+ end
+
+ describe 'when there are fewer than five successful requests' do
+
+ it 'should list the most recently sent and successful requests by the creation date of the
+ request event' do
+ # Make sure the newest response is listed first even if a request
+ # with an older response has a newer comment or was reclassified more recently:
+ # https://github.com/mysociety/alaveteli/issues/370
+ #
+ # This is a deliberate behaviour change, in that the
+ # previous behaviour (showing more-recently-reclassified
+ # requests first) was intentional.
+ request_events, request_events_all_successful = InfoRequest.recent_requests
+ previous = nil
+ request_events.each do |event|
+ if previous
+ previous.created_at.should be >= event.created_at
+ end
+ ['sent', 'response'].include?(event.event_type).should be_true
+ if event.event_type == 'response'
+ ['successful', 'partially_successful'].include?(event.calculated_state).should be_true
+ end
+ previous = event
+ end
+ end
+ end
+
+ it 'should coalesce duplicate requests' do
+ request_events, request_events_all_successful = InfoRequest.recent_requests
+ request_events.map(&:info_request).select{|x|x.url_title =~ /^spam/}.length.should == 1
+ end
+ end
end
diff --git a/spec/models/public_body_spec.rb b/spec/models/public_body_spec.rb
index 23842ccff..ed24ced52 100644
--- a/spec/models/public_body_spec.rb
+++ b/spec/models/public_body_spec.rb
@@ -213,6 +213,15 @@ describe PublicBody, " when saving" do
public_body.name.should == "Mark's Public Body"
end
+ it 'should update the right translation when in a locale with an underscore' do
+ AlaveteliLocalization.set_locales('he_IL', 'he_IL')
+ public_body = public_bodies(:humpadink_public_body)
+ translation_count = public_body.translations.size
+ public_body.name = 'Renamed'
+ public_body.save!
+ public_body.translations.size.should == translation_count
+ end
+
it 'should not create a new version when nothing has changed' do
@public_body.versions.size.should == 0
set_default_attributes(@public_body)
@@ -473,6 +482,20 @@ describe PublicBody, " when loading CSV files" do
PublicBody.count.should == original_count
end
+
+ it "should be able to load CSV from a file as well as a string" do
+ # Essentially the same code is used for import_csv_from_file
+ # as import_csv, so this is just a basic check that
+ # import_csv_from_file can load from a file at all. (It would
+ # be easy to introduce a regression that broke this, because
+ # of the confusing change in behaviour of CSV.parse between
+ # Ruby 1.8 and 1.9.)
+ original_count = PublicBody.count
+ filename = file_fixture_name('fake-authority-type-with-field-names.csv')
+ PublicBody.import_csv_from_file(filename, '', 'replace', false, 'someadmin')
+ PublicBody.count.should == original_count + 3
+ end
+
end
describe PublicBody do
@@ -604,3 +627,12 @@ describe PublicBody, "when calculating statistics" do
end
end
+
+describe PublicBody, 'when asked for popular bodies' do
+
+ it 'should return bodies correctly when passed the hyphenated version of the locale' do
+ AlaveteliConfiguration.stub!(:frontpage_publicbody_examples).and_return('')
+ PublicBody.popular_bodies('he-IL').should == [public_bodies(:humpadink_public_body)]
+ end
+
+end
diff --git a/spec/models/xapian_spec.rb b/spec/models/xapian_spec.rb
index 3c9fff784..a1e060d8e 100644
--- a/spec/models/xapian_spec.rb
+++ b/spec/models/xapian_spec.rb
@@ -370,7 +370,7 @@ describe PublicBody, " when only indexing selected things on a rebuild" do
end
end
-# I would expect ActsAsXapian to have some tests under vendor/plugins/acts_as_xapian, but
+# I would expect ActsAsXapian to have some tests under lib/acts_as_xapian, but
# it looks like this is not the case. Putting a test here instead.
describe ActsAsXapian::Search, "#words_to_highlight" do
before(:each) do
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index d22f3c0ff..1eeb8603b 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -13,6 +13,10 @@ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
SimpleCov.start('rails') do
add_filter 'commonlib'
add_filter 'vendor/plugins'
+ add_filter 'lib/strip_attributes'
+ add_filter 'lib/has_tag_string'
+ add_filter 'lib/acts_as_xapian'
+ add_filter 'lib/themes'
end
Spork.prefork do