aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/user_controller_spec.rb2
-rw-r--r--spec/fixtures/files/no-part-charset-bad-utf8.email38
-rw-r--r--spec/fixtures/locale/en/app.po4
-rw-r--r--spec/fixtures/locale/en_GB/app.po4
-rw-r--r--spec/fixtures/locale/es/app.po4
-rw-r--r--spec/fixtures/theme_views/core/application_mailer/core_only.rhtml1
-rw-r--r--spec/fixtures/theme_views/core/application_mailer/multipart_core_only.rhtml1
-rw-r--r--spec/fixtures/theme_views/core/application_mailer/simple.rhtml1
-rw-r--r--spec/fixtures/theme_views/theme_one/application_mailer/multipart_theme_only.rhtml1
-rw-r--r--spec/fixtures/theme_views/theme_one/application_mailer/simple.rhtml1
-rw-r--r--spec/fixtures/theme_views/theme_one/application_mailer/theme_only.rhtml1
-rw-r--r--spec/helpers/link_to_helper_spec.rb25
-rw-r--r--spec/integration/admin_spec.rb4
-rw-r--r--spec/models/application_mailer_spec.rb156
-rw-r--r--spec/models/customstates.rb4
-rw-r--r--spec/models/holiday_spec.rb99
-rw-r--r--spec/models/incoming_message_spec.rb13
-rw-r--r--spec/models/public_body_spec.rb8
-rw-r--r--spec/models/request_mailer_spec.rb43
-rw-r--r--spec/spec_helper.rb7
-rw-r--r--spec/views/public_body/show.rhtml_spec.rb1
21 files changed, 362 insertions, 56 deletions
diff --git a/spec/controllers/user_controller_spec.rb b/spec/controllers/user_controller_spec.rb
index 32398c053..386d1b04b 100644
--- a/spec/controllers/user_controller_spec.rb
+++ b/spec/controllers/user_controller_spec.rb
@@ -337,7 +337,7 @@ describe UserController, "when sending another user a message" do
deliveries = ActionMailer::Base.deliveries
deliveries.size.should == 1
mail = deliveries[0]
- mail.body.should include("Bob Smith has used #{MySociety::Config.get('SITE_NAME')} to send you the message below")
+ mail.body.should include("Bob Smith has used #{Configuration::site_name} to send you the message below")
mail.body.should include("Just a test!")
#mail.to_addrs.first.to_s.should == users(:silly_name_user).name_and_email # XXX fix some nastiness with quoting name_and_email
mail.from_addrs.first.to_s.should == users(:bob_smith_user).name_and_email
diff --git a/spec/fixtures/files/no-part-charset-bad-utf8.email b/spec/fixtures/files/no-part-charset-bad-utf8.email
new file mode 100644
index 000000000..7e67d0063
--- /dev/null
+++ b/spec/fixtures/files/no-part-charset-bad-utf8.email
@@ -0,0 +1,38 @@
+From xxxx@yahoo.cn Mon Oct 08 14:01:34 2012
+Return-path: <xxxx@yahoo.cn>
+Envelope-to: foi@atlas.ukcod.org.uk
+Delivery-date: Mon, 08 Oct 2012 14:01:34 +0100
+Received: (qmail 63864 invoked from network); 8 Oct 2012 13:01:12 -0000
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.cn; s=s1024; t=1349701272; bh=T/mtlIYvhB/L5RO+CvTazeAdGf1n1zsGXBoA8EKGT9M=; h=Message-ID:X-Yahoo-Newman-Property:X-YMail-OSG:X-Yahoo-SMTP:Received:X-mailer:From:Subject:To:Content-Transfer-Encoding:Content-Type:Date; b=LYI/PXvA7DA746bmyprChUg7N8YDvN9XE/bhfTt5MW7siOmxHHzn1w+s5X33PvLI0x0UfJLo+MCkTnGPKnG5BYY38US8PkocJYyphrvF/eaUl3ALf8UvxHBOJX1iIi89Xp2NnfbS8lz9kZAWifb9GOnOA5/kLDcL5/WJXliit2k=
+Message-ID: <xxxx@xxxx.yahoo.com>
+X-Yahoo-Newman-Property: ymail-5
+X-YMail-OSG: nPs5jgsVM1myUoKjeEPTxxalz4BM6BZMEUYu.E8NPMPQyo_
+ Yej8T2WCTurn767NOwhuDIqNxC2QGZINqfjmKcdyW7a1P_Zxqr9GsjgxODci
+ ihwr7qYAGDDbcsrB.PX4epnJZHl3yAwoGW.1ReEZnXQANFcNep7.zNEbZ_2k
+ RU1IhI9aHYvxPxt5RWugwOoFRh9P8Ym35A88IMazNtVaBiBEXF6Vk8Aqr9XP
+ 3Vh9xOT9Pn6X8qOUjNXkdb3xB4S5AAIRSE9mqhL1KzHBwdVQs25IoM_2FV2b
+ gPsQGgL4_mwBH0WcEMhdj7Kn6Nfb44L.50E_V3DH.8P7KzDK8zNVXSbAqohX
+ Qi6MzUK2frr8IyZyYzHb.ekff7kAcJgUoHvhnyPar8tRYxhQT3_xsUTzsx8N
+ oWckVPh_i3OT7U4ObgekqgtteMoYqPH2eF1SZXamGBAs-
+X-Yahoo-SMTP: YUQHwRWswBDjbw_M.D6EP4KpT9khlJErDRBQi4ySZQ--
+X-mailer: MIME::Lite 3.027 (F2.74; T1.31; A2.07; B3.13; Q3.13)
+From: =?GB2312?B?zsJKaWFu?= Bing <xxxx@yahoo.cn>
+Subject: =?GB2312?B?yM7A1svJ?=
+To: FOI Person <EMAIL_TO>
+Content-Transfer-Encoding: base64
+Content-Type: text/plain
+Date: Tue, 9 Oct 2012 20:53:06 +0800
+
+DQogICAgICAgICAgufO5q8u+uLrU8MjLKL6twO0vssbO8SnE+rrDo7oNCiAgICAgICAgICAgILG+
+uavLvtTaMTk5N8Tqs8nBorn6vNK5pMnM16Ky4S7KtcGm0Nu68aGj09C2wMGiy7DO8Q0KICAgICAg
+ICAgINeo0rXIy9SxO9TayKu5+rj3s8fK0MnowaK31rmry76jqNXjva2hosnPuqOhornj1t2hor2t
+y9W1yA0KICAgICAgICAgILXYt72jqdLyvfjP7r3PtuDP1s3qs8myu8HLw7/Uws/6ytu27rbIoaPD
+v9TC09DSu7K/t9YNCiAgICAgICAgICDU9ta1tpCjqDYtNyXX89PSKbrNxtXGsaOoMC41JS0yJSDX
+89PSo6nTxbvdtPq/qrvyus/X96OsDQogICAgICAgICAgtePK/b3Ptc2ho7T6wO23ts6nyOfPwqO6
+DQogICAgICAgICAg1PbWtcuwOjEuMTcl16jTw9T21rWjuzI6xtXNqNT21rWjuzM6uqO52MBVv+6V
++CANCiAgICAgICAgICAgNC65+suwzajTw7v6tPI7IDUutdjLsM2o08O7+rTyDQogICAgICAgICAg
+ICAgPT09Pdaj1tiz0MW1PT09PSANCiAgICAgICAgICDGsb7dvvnOqraQhNW+1sHss/a78tPJxvPS
+tdaxvdO/qrP2o6zR6dakuvO4tr/uoaMNCiAgICAgICAgICAgICAgIMGqIMLnIDq7xr6twO0gICAg
+ICAgICAgICAgyMjP3zoxMzgtMjQzNi0wNTE1DQogICAgICAgICAgICDStc7xUVE6OTc4My05Njg5
+OCAgIEUtbWFpbDp3d3dheDg4QDEyNi5jb20NCg==
+
diff --git a/spec/fixtures/locale/en/app.po b/spec/fixtures/locale/en/app.po
index 5c40446d8..91af9b72b 100644
--- a/spec/fixtures/locale/en/app.po
+++ b/spec/fixtures/locale/en/app.po
@@ -356,7 +356,7 @@ msgstr ""
#: app/views/general/_advanced_search_tips.rhtml:16
msgid ""
-"<strong><code>tag:charity</code></strong> to find all public bodies or requests with a given tag. You can include multiple tags, \n"
+"<strong><code>tag:charity</code></strong> to find all public authorities or requests with a given tag. You can include multiple tags, \n"
" and tag values, e.g. <code>tag:openlylocal AND tag:financial_transaction:335633</code>. Note that by default any of the tags\n"
" can be present, you have to put <code>AND</code> explicitly if you only want results them all present."
msgstr ""
@@ -1098,7 +1098,7 @@ msgid "Forgotten your password?"
msgstr ""
#: app/views/public_body/list.rhtml:47
-msgid "Found {{count}} public bodies {{description}}"
+msgid "Found {{count}} public authorities {{description}}"
msgstr ""
#: app/models/info_request.rb:257
diff --git a/spec/fixtures/locale/en_GB/app.po b/spec/fixtures/locale/en_GB/app.po
index 5c40446d8..91af9b72b 100644
--- a/spec/fixtures/locale/en_GB/app.po
+++ b/spec/fixtures/locale/en_GB/app.po
@@ -356,7 +356,7 @@ msgstr ""
#: app/views/general/_advanced_search_tips.rhtml:16
msgid ""
-"<strong><code>tag:charity</code></strong> to find all public bodies or requests with a given tag. You can include multiple tags, \n"
+"<strong><code>tag:charity</code></strong> to find all public authorities or requests with a given tag. You can include multiple tags, \n"
" and tag values, e.g. <code>tag:openlylocal AND tag:financial_transaction:335633</code>. Note that by default any of the tags\n"
" can be present, you have to put <code>AND</code> explicitly if you only want results them all present."
msgstr ""
@@ -1098,7 +1098,7 @@ msgid "Forgotten your password?"
msgstr ""
#: app/views/public_body/list.rhtml:47
-msgid "Found {{count}} public bodies {{description}}"
+msgid "Found {{count}} public authorities {{description}}"
msgstr ""
#: app/models/info_request.rb:257
diff --git a/spec/fixtures/locale/es/app.po b/spec/fixtures/locale/es/app.po
index dd8e10969..4e54a1d40 100644
--- a/spec/fixtures/locale/es/app.po
+++ b/spec/fixtures/locale/es/app.po
@@ -424,7 +424,7 @@ msgstr "<strong><code>status:</code></strong> para filtrar en función del estad
#: app/views/general/_advanced_search_tips.rhtml:16
msgid ""
-"<strong><code>tag:charity</code></strong> to find all public bodies or requests with a given tag. You can include multiple tags, \n"
+"<strong><code>tag:charity</code></strong> to find all public authorities or requests with a given tag. You can include multiple tags, \n"
" and tag values, e.g. <code>tag:openlylocal AND tag:financial_transaction:335633</code>. Note that by default any of the tags\n"
" can be present, you have to put <code>AND</code> explicitly if you only want results them all present."
msgstr "<strong><code>tag:salud</code></strong> para buscar todos los organismos públicos o solicitudes con la etiqueta dada. Puedes incluir múltiples etiquetas, \n y valores, e.g. <code>tag:salud AND tag:financial_transaction:335633</code>. Por defecto, basta con que cualquiera de las etiquetas\n esté presente, añade <code>AND</code> explícitamente si sólo quiere resultados con todas ellas presentes."
@@ -1221,7 +1221,7 @@ msgid "Forgotten your password?"
msgstr "¿Has olvidado tu contraseña?"
#: app/views/public_body/list.rhtml:47
-msgid "Found {{count}} public bodies {{description}}"
+msgid "Found {{count}} public authorities {{description}}"
msgstr "Encontrados {{count}} organismos públicos {{description}}"
#: app/models/info_request.rb:257
diff --git a/spec/fixtures/theme_views/core/application_mailer/core_only.rhtml b/spec/fixtures/theme_views/core/application_mailer/core_only.rhtml
new file mode 100644
index 000000000..53b7798ec
--- /dev/null
+++ b/spec/fixtures/theme_views/core/application_mailer/core_only.rhtml
@@ -0,0 +1 @@
+Core only \ No newline at end of file
diff --git a/spec/fixtures/theme_views/core/application_mailer/multipart_core_only.rhtml b/spec/fixtures/theme_views/core/application_mailer/multipart_core_only.rhtml
new file mode 100644
index 000000000..646a349f8
--- /dev/null
+++ b/spec/fixtures/theme_views/core/application_mailer/multipart_core_only.rhtml
@@ -0,0 +1 @@
+Core multipart \ No newline at end of file
diff --git a/spec/fixtures/theme_views/core/application_mailer/simple.rhtml b/spec/fixtures/theme_views/core/application_mailer/simple.rhtml
new file mode 100644
index 000000000..a3937c940
--- /dev/null
+++ b/spec/fixtures/theme_views/core/application_mailer/simple.rhtml
@@ -0,0 +1 @@
+Core simple \ No newline at end of file
diff --git a/spec/fixtures/theme_views/theme_one/application_mailer/multipart_theme_only.rhtml b/spec/fixtures/theme_views/theme_one/application_mailer/multipart_theme_only.rhtml
new file mode 100644
index 000000000..d6423fbb4
--- /dev/null
+++ b/spec/fixtures/theme_views/theme_one/application_mailer/multipart_theme_only.rhtml
@@ -0,0 +1 @@
+Theme multipart \ No newline at end of file
diff --git a/spec/fixtures/theme_views/theme_one/application_mailer/simple.rhtml b/spec/fixtures/theme_views/theme_one/application_mailer/simple.rhtml
new file mode 100644
index 000000000..ad43e0c87
--- /dev/null
+++ b/spec/fixtures/theme_views/theme_one/application_mailer/simple.rhtml
@@ -0,0 +1 @@
+Theme simple \ No newline at end of file
diff --git a/spec/fixtures/theme_views/theme_one/application_mailer/theme_only.rhtml b/spec/fixtures/theme_views/theme_one/application_mailer/theme_only.rhtml
new file mode 100644
index 000000000..865445815
--- /dev/null
+++ b/spec/fixtures/theme_views/theme_one/application_mailer/theme_only.rhtml
@@ -0,0 +1 @@
+Theme only \ No newline at end of file
diff --git a/spec/helpers/link_to_helper_spec.rb b/spec/helpers/link_to_helper_spec.rb
index 9ec0afce1..ef89e8bf9 100644
--- a/spec/helpers/link_to_helper_spec.rb
+++ b/spec/helpers/link_to_helper_spec.rb
@@ -48,4 +48,29 @@ describe LinkToHelper do
end
+ describe 'admin_url' do
+ context 'with no ADMIN_BASE_URL set' do
+ it 'should prepend the admin general index path to a simple string' do
+ admin_url('unclassified').should == 'http://test.host/en/admin/unclassified'
+ end
+
+ it 'should prepend the admin general index path to a deeper URL' do
+ admin_url('request/show/123').should == 'http://test.host/en/admin/request/show/123'
+ end
+ end
+
+ context 'with ADMIN_BASE_URL set' do
+ before(:each) do
+ Configuration::should_receive(:admin_base_url).and_return('https://www.example.com/secure/alaveteli-admin/')
+ end
+
+ it 'should prepend the admin base URL to a simple string' do
+ admin_url('unclassified').should == 'https://www.example.com/secure/alaveteli-admin/unclassified'
+ end
+
+ it 'should prepend the admin base URL to a deeper URL' do
+ admin_url('request/show/123').should == 'https://www.example.com/secure/alaveteli-admin/request/show/123'
+ end
+ end
+ end
end
diff --git a/spec/integration/admin_spec.rb b/spec/integration/admin_spec.rb
index caf741749..e148ea3ca 100644
--- a/spec/integration/admin_spec.rb
+++ b/spec/integration/admin_spec.rb
@@ -12,10 +12,8 @@ describe "When administering the site" do
response.should be_success
# Now fetch the "log in as" link to log in as Bob
- admin_username = MySociety::Config.get('ADMIN_USERNAME')
- admin_password = MySociety::Config.get('ADMIN_PASSWORD')
get_via_redirect "/admin/user/login_as/#{users(:bob_smith_user).id}", nil, {
- "Authorization" => "Basic " + Base64.encode64("#{admin_username}:#{admin_password}").strip
+ "Authorization" => "Basic " + Base64.encode64("#{Configuration::admin_username}:#{Configuration::admin_password}").strip
}
response.should be_success
session[:user_id].should == users(:bob_smith_user).id
diff --git a/spec/models/application_mailer_spec.rb b/spec/models/application_mailer_spec.rb
index 12527c6e8..a90f79c01 100644
--- a/spec/models/application_mailer_spec.rb
+++ b/spec/models/application_mailer_spec.rb
@@ -1,8 +1,160 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
-describe ApplicationMailer, " when blah" do
- before do
+
+describe ApplicationMailer do
+
+ context 'when using plugins' do
+
+ def set_base_views
+ ApplicationMailer.class_eval do
+ @previous_view_paths = self.view_paths.dup
+ self.view_paths.clear
+ self.view_paths << File.join(Rails.root, 'spec', 'fixtures', 'theme_views', 'core')
+ end
+ end
+
+ def add_mail_methods(method_names)
+ method_names.each{ |method_name| ApplicationMailer.send(:define_method, method_name){} }
+ end
+
+ def remove_mail_methods(method_names)
+ method_names.each do |method_name|
+ if ApplicationMailer.respond_to?(method_name)
+ ApplicationMailer.send(:remove_method, method_name)
+ end
+ end
+ end
+
+ def prepend_theme_views(theme_name)
+ ApplicationMailer.class_eval do
+ view_paths.unshift File.join(Rails.root, 'spec', 'fixtures', 'theme_views', theme_name)
+ end
+ end
+
+ def append_theme_views(theme_name)
+ ApplicationMailer.class_eval do
+ view_paths << File.join(Rails.root, 'spec', 'fixtures', 'theme_views', theme_name)
+ end
+ end
+
+ def reset_views
+ ApplicationMailer.class_eval do
+ self.view_paths = @previous_view_paths
+ end
+ end
+
+ def create_multipart_method(method_name)
+ ApplicationMailer.send(:define_method, method_name) do
+ attachment :content_type => 'message/rfc822',
+ :body => 'xxx',
+ :filename => "original.eml",
+ :transfer_encoding => '7bit',
+ :content_disposition => 'inline'
+ end
+ end
+
+ before do
+ set_base_views
+ add_mail_methods(['simple', 'theme_only', 'core_only', 'neither'])
+ end
+
+ describe 'when a plugin prepends its mail templates to the view paths' do
+
+ it 'should render a theme template in preference to a core template' do
+ prepend_theme_views('theme_one')
+ @mail = ApplicationMailer.create_simple()
+ @mail.body.should match('Theme simple')
+ end
+
+ it 'should render the template provided by the theme if no template is available in core' do
+ prepend_theme_views('theme_one')
+ @mail = ApplicationMailer.create_theme_only()
+ @mail.body.should match('Theme only')
+ end
+
+ it 'should render the template provided by core if there is no theme template' do
+ prepend_theme_views('theme_one')
+ @mail = ApplicationMailer.create_core_only()
+ @mail.body.should match('Core only')
+ end
+
+ it 'should raise an error if the template is in neither core nor theme' do
+ prepend_theme_views('theme_one')
+ lambda{ ApplicationMailer.create_neither() }.should raise_error('Missing template application_mailer/neither.erb in view path spec/fixtures/theme_views/theme_one:spec/fixtures/theme_views/core')
+ end
+
+ it 'should render a multipart email using a theme template' do
+ prepend_theme_views('theme_one')
+ create_multipart_method('multipart_theme_only')
+ @mail = ApplicationMailer.create_multipart_theme_only()
+ @mail.parts.size.should == 2
+ message_part = @mail.parts[0].to_s
+ message_part.should match("Theme multipart")
+ end
+
+ it 'should render a multipart email using a core template' do
+ prepend_theme_views('theme_one')
+ create_multipart_method('multipart_core_only')
+ @mail = ApplicationMailer.create_multipart_core_only()
+ @mail.parts.size.should == 2
+ message_part = @mail.parts[0].to_s
+ message_part.should match("Core multipart")
+ end
+
+ end
+
+ describe 'when a plugin appends its mail templates to the view paths' do
+
+ it 'should render a core template in preference to a theme template' do
+ append_theme_views('theme_one')
+ @mail = ApplicationMailer.create_simple()
+ @mail.body.should match('Core simple')
+ end
+
+ it 'should render the template provided by the theme if no template is available in core' do
+ append_theme_views('theme_one')
+ @mail = ApplicationMailer.create_theme_only()
+ @mail.body.should match('Theme only')
+ end
+
+ it 'should render the template provided by core if there is no theme template' do
+ append_theme_views('theme_one')
+ @mail = ApplicationMailer.create_core_only()
+ @mail.body.should match('Core only')
+ end
+
+ it 'should raise an error if the template is in neither core nor theme' do
+ append_theme_views('theme_one')
+ lambda{ ApplicationMailer.create_neither() }.should raise_error('Missing template application_mailer/neither.erb in view path spec/fixtures/theme_views/core:spec/fixtures/theme_views/theme_one')
+ end
+
+ it 'should render a multipart email using a core template' do
+ append_theme_views('theme_one')
+ create_multipart_method('multipart_core_only')
+ @mail = ApplicationMailer.create_multipart_core_only()
+ @mail.parts.size.should == 2
+ message_part = @mail.parts[0].to_s
+ message_part.should match("Core multipart")
+ end
+
+ it 'should render a multipart email using a theme template' do
+ append_theme_views('theme_one')
+ create_multipart_method('multipart_theme_only')
+ @mail = ApplicationMailer.create_multipart_theme_only()
+ @mail.parts.size.should == 2
+ message_part = @mail.parts[0].to_s
+ message_part.should match("Theme multipart")
+ end
+
+ end
+
+ after do
+ reset_views
+ remove_mail_methods(['simple', 'theme_only', 'core_only', 'neither', 'multipart'])
+ end
end
+
end
+
diff --git a/spec/models/customstates.rb b/spec/models/customstates.rb
index 3488e6730..bffbe86fb 100644
--- a/spec/models/customstates.rb
+++ b/spec/models/customstates.rb
@@ -13,7 +13,7 @@ module InfoRequestCustomStates
return 'deadline_extended' if
Time.now.strftime("%Y-%m-%d") < self.date_deadline_extended.strftime("%Y-%m-%d")
return 'waiting_response_very_overdue' if
- Time.now.strftime("%Y-%m-%d") > Holiday.due_date_from(self.date_deadline_extended, 15).strftime("%Y-%m-%d")
+ Time.now.strftime("%Y-%m-%d") > Holiday.due_date_from_working_days(self.date_deadline_extended, 15).strftime("%Y-%m-%d")
return 'waiting_response_overdue'
end
return 'waiting_response_very_overdue' if
@@ -27,7 +27,7 @@ module InfoRequestCustomStates
# XXX shouldn't this be 15 days after the date the status was
# changed to "deadline extended"? Or perhaps 15 days ater the
# initial request due date?
- return Holiday.due_date_from(self.date_response_required_by, 15)
+ return Holiday.due_date_from_working_days(self.date_response_required_by, 15)
end
module ClassMethods
diff --git a/spec/models/holiday_spec.rb b/spec/models/holiday_spec.rb
index 00ebc7279..5d3f76d24 100644
--- a/spec/models/holiday_spec.rb
+++ b/spec/models/holiday_spec.rb
@@ -3,47 +3,84 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe Holiday, " when calculating due date" do
def due_date(ymd)
- return Holiday.due_date_from(Date.strptime(ymd), 20).strftime("%F")
+ return Holiday.due_date_from_working_days(Date.strptime(ymd), 20).strftime("%F")
end
- it "handles no holidays" do
- due_date('2008-10-01').should == '2008-10-29'
- end
+ context "in working days" do
+ it "handles no holidays" do
+ due_date('2008-10-01').should == '2008-10-29'
+ end
- it "handles non leap years" do
- due_date('2007-02-01').should == '2007-03-01'
- end
+ it "handles non leap years" do
+ due_date('2007-02-01').should == '2007-03-01'
+ end
- it "handles leap years" do
- due_date('2008-02-01').should == '2008-02-29'
- end
+ it "handles leap years" do
+ due_date('2008-02-01').should == '2008-02-29'
+ end
- it "handles Thursday start" do
- due_date('2009-03-12').should == '2009-04-14'
- end
+ it "handles Thursday start" do
+ due_date('2009-03-12').should == '2009-04-14'
+ end
- it "handles Friday start" do
- due_date('2009-03-13').should == '2009-04-15'
- end
+ it "handles Friday start" do
+ due_date('2009-03-13').should == '2009-04-15'
+ end
- # Delivery at the weekend ends up the same due day as if it had arrived on
- # the Friday before. This is because the next working day (Monday) counts
- # as day 1.
- # See http://www.whatdotheyknow.com/help/officers#days
- it "handles Saturday start" do
- due_date('2009-03-14').should == '2009-04-15'
- end
- it "handles Sunday start" do
- due_date('2009-03-15').should == '2009-04-15'
- end
+ # Delivery at the weekend ends up the same due day as if it had arrived on
+ # the Friday before. This is because the next working day (Monday) counts
+ # as day 1.
+ # See http://www.whatdotheyknow.com/help/officers#days
+ it "handles Saturday start" do
+ due_date('2009-03-14').should == '2009-04-15'
+ end
+ it "handles Sunday start" do
+ due_date('2009-03-15').should == '2009-04-15'
+ end
- it "handles Monday start" do
- due_date('2009-03-16').should == '2009-04-16'
- end
+ it "handles Monday start" do
+ due_date('2009-03-16').should == '2009-04-16'
+ end
- it "handles Time objects" do
- Holiday.due_date_from(Time.utc(2009, 03, 16, 12, 0, 0), 20).strftime('%F').should == '2009-04-16'
+ it "handles Time objects" do
+ Holiday.due_date_from_working_days(Time.utc(2009, 03, 16, 12, 0, 0), 20).strftime('%F').should == '2009-04-16'
+ end
end
+ context "in calendar days" do
+ it "handles no holidays" do
+ Holiday.due_date_from_calendar_days(Date.new(2008, 10, 1), 20).should == Date.new(2008, 10, 21)
+ end
+
+ it "handles the due date falling on a Friday" do
+ Holiday.due_date_from_calendar_days(Date.new(2008, 10, 4), 20).should == Date.new(2008, 10, 24)
+ end
+
+ # If the due date would fall on a Saturday it should in fact fall on the next day that isn't a weekend
+ # or a holiday
+ it "handles the due date falling on a Saturday" do
+ Holiday.due_date_from_calendar_days(Date.new(2008, 10, 5), 20).should == Date.new(2008, 10, 27)
+ end
+
+ it "handles the due date falling on a Sunday" do
+ Holiday.due_date_from_calendar_days(Date.new(2008, 10, 6), 20).should == Date.new(2008, 10, 27)
+ end
+
+ it "handles the due date falling on a Monday" do
+ Holiday.due_date_from_calendar_days(Date.new(2008, 10, 7), 20).should == Date.new(2008, 10, 27)
+ end
+
+ it "handles the due date falling on a day before a Holiday" do
+ Holiday.due_date_from_calendar_days(Date.new(2008, 12, 4), 20).should == Date.new(2008, 12, 24)
+ end
+
+ it "handles the due date falling on a Holiday" do
+ Holiday.due_date_from_calendar_days(Date.new(2008, 12, 5), 20).should == Date.new(2008, 12, 29)
+ end
+
+ it "handles Time objects" do
+ Holiday.due_date_from_calendar_days(Time.utc(2009, 03, 17, 12, 0, 0), 20).should == Date.new(2009, 4, 6)
+ end
+ end
end
diff --git a/spec/models/incoming_message_spec.rb b/spec/models/incoming_message_spec.rb
index bc73ef071..cf84b4595 100644
--- a/spec/models/incoming_message_spec.rb
+++ b/spec/models/incoming_message_spec.rb
@@ -56,6 +56,15 @@ describe IncomingMessage, " when dealing with incoming mail" do
message.subject.should == "Câmara Responde: Banco de ideias"
end
+ it 'should not error on display of a message which has no charset set on the body part and
+ is not good utf-8' do
+ ir = info_requests(:fancy_dog_request)
+ receive_incoming_mail('no-part-charset-bad-utf8.email', ir.incoming_email)
+ puts ir.incoming_messages.inspect
+ message = ir.incoming_messages[1]
+ message.parse_raw_email!
+ message.get_main_body_text_internal.should include("The above text was badly encoded")
+ end
it "should fold multiline sections" do
{
@@ -77,6 +86,7 @@ describe IncomingMessage, "when parsing HTML mail" do
plain_text = IncomingMessage._get_attachment_text_internal_one_file('text/html', html)
plain_text.should match(/është/)
end
+
end
describe IncomingMessage, "when getting the attachment text" do
@@ -312,8 +322,7 @@ describe IncomingMessage, " when censoring data" do
end
it "should apply hard-coded privacy rules to HTML files" do
- domain = MySociety::Config.get('DOMAIN')
- data = "http://#{domain}/c/cheese"
+ data = "http://#{Configuration::domain}/c/cheese"
@im.html_mask_stuff!(data)
data.should == "[WDTK login link]"
end
diff --git a/spec/models/public_body_spec.rb b/spec/models/public_body_spec.rb
index 011824190..c2e0a6353 100644
--- a/spec/models/public_body_spec.rb
+++ b/spec/models/public_body_spec.rb
@@ -453,3 +453,11 @@ describe PublicBody do
end
end
+
+describe PublicBody, " when override all public body request emails set" do
+ it "should return the overridden request email" do
+ MySociety::Config.should_receive(:get).with("OVERRIDE_ALL_PUBLIC_BODY_REQUEST_EMAILS", "").twice.and_return("catch_all_test_email@foo.com")
+ @geraldine = public_bodies(:geraldine_public_body)
+ @geraldine.request_email.should == "catch_all_test_email@foo.com"
+ end
+end
diff --git a/spec/models/request_mailer_spec.rb b/spec/models/request_mailer_spec.rb
index 98681a9e9..906756784 100644
--- a/spec/models/request_mailer_spec.rb
+++ b/spec/models/request_mailer_spec.rb
@@ -33,7 +33,7 @@ describe RequestMailer, " when receiving incoming mail" do
deliveries = ActionMailer::Base.deliveries
deliveries.size.should == 1
mail = deliveries[0]
- mail.to.should == [ MySociety::Config.get("CONTACT_EMAIL", 'contact@localhost') ]
+ mail.to.should == [ Configuration::contact_email ]
deliveries.clear
end
@@ -53,7 +53,7 @@ describe RequestMailer, " when receiving incoming mail" do
deliveries = ActionMailer::Base.deliveries
deliveries.size.should == 1
mail = deliveries[0]
- mail.to.should == [ MySociety::Config.get("CONTACT_EMAIL", 'contact@localhost') ]
+ mail.to.should == [ Configuration::contact_email ]
deliveries.clear
end
@@ -73,7 +73,7 @@ describe RequestMailer, " when receiving incoming mail" do
deliveries = ActionMailer::Base.deliveries
deliveries.size.should == 1
mail = deliveries[0]
- mail.to.should == [ MySociety::Config.get("CONTACT_EMAIL", 'contact@localhost') ]
+ mail.to.should == [ Configuration::contact_email ]
deliveries.clear
end
@@ -97,10 +97,12 @@ describe RequestMailer, " when receiving incoming mail" do
# check attached bounce is good copy of incoming-request-plain.email
mail.multipart?.should == true
mail.parts.size.should == 2
+ message_part = mail.parts[0].to_s
bounced_mail = TMail::Mail.parse(mail.parts[1].body)
bounced_mail.to.should == [ ir.incoming_email ]
bounced_mail.from.should == [ 'geraldinequango@localhost' ]
- bounced_mail.body.include?("That's so totally a rubbish question")
+ bounced_mail.body.include?("That's so totally a rubbish question").should be_true
+ message_part.include?("marked to no longer receive responses").should be_true
deliveries.clear
end
@@ -157,7 +159,7 @@ describe RequestMailer, " when receiving incoming mail" do
deliveries = ActionMailer::Base.deliveries
deliveries.size.should == 1
mail = deliveries[0]
- mail.to.should == [ MySociety::Config.get("CONTACT_EMAIL", 'contact@localhost') ]
+ mail.to.should == [ Configuration::contact_email ]
deliveries.clear
end
@@ -324,3 +326,34 @@ describe RequestMailer, 'when sending mail when someone has updated an old uncla
end
end
+
+describe RequestMailer, 'requires_admin' do
+ before(:each) do
+ user = mock_model(User, :name_and_email => 'Bruce Jones',
+ :name => 'Bruce Jones')
+ @info_request = mock_model(InfoRequest, :user => user,
+ :described_state => 'error_message',
+ :title => 'Test request',
+ :url_title => 'test_request',
+ :law_used_short => 'FOI',
+ :id => 123)
+ end
+
+ it 'body should contain the full admin URL' do
+ mail = RequestMailer.deliver_requires_admin(@info_request)
+
+ mail.body.should include('http://test.host/en/admin/request/show/123')
+ end
+
+ context 'has an ADMIN_BASE_URL set' do
+ before(:each) do
+ Configuration::should_receive(:admin_base_url).and_return('http://our.proxy.server/admin/alaveteli/')
+ end
+
+ it 'body should contain the full admin URL' do
+ mail = RequestMailer.deliver_requires_admin(@info_request)
+
+ mail.body.should include('http://our.proxy.server/admin/alaveteli/request/show/123')
+ end
+ end
+end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 6a4d0f2d5..248dff70e 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -143,15 +143,14 @@ def validate_as_body(html)
end
def basic_auth_login(request, username = nil, password = nil)
- username = MySociety::Config.get('ADMIN_USERNAME') if username.nil?
- password = MySociety::Config.get('ADMIN_PASSWORD') if password.nil?
+ username = Configuration::admin_username if username.nil?
+ password = Configuration::admin_password if password.nil?
request.env["HTTP_AUTHORIZATION"] = "Basic " + Base64::encode64("#{username}:#{password}")
end
# Monkeypatch! Validate HTML in tests.
-utility_search_path = MySociety::Config.get("UTILITY_SEARCH_PATH", ["/usr/bin", "/usr/local/bin"])
$html_validation_script_found = false
-utility_search_path.each do |d|
+Configuration::utility_search_path.each do |d|
$html_validation_script = File.join(d, "validate")
$html_validation_script_options = ["--charset=utf-8"]
if File.file? $html_validation_script and File.executable? $html_validation_script
diff --git a/spec/views/public_body/show.rhtml_spec.rb b/spec/views/public_body/show.rhtml_spec.rb
index 1d21f80c4..a42516d72 100644
--- a/spec/views/public_body/show.rhtml_spec.rb
+++ b/spec/views/public_body/show.rhtml_spec.rb
@@ -12,6 +12,7 @@ describe "when viewing a body" do
:info_requests => [1, 2, 3, 4], # out of sync with Xapian
:publication_scheme => '',
:calculated_home_page => '')
+ @pb.stub!(:override_request_email).and_return(nil)
@pb.stub!(:is_requestable?).and_return(true)
@pb.stub!(:has_notes?).and_return(false)
@pb.stub!(:has_tag?).and_return(false)