aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.cvsignore5
-rw-r--r--Gemfile.lock2
-rw-r--r--app/controllers/admin_request_controller.rb16
-rw-r--r--app/controllers/request_controller.rb2
-rw-r--r--app/models/incoming_message.rb4
-rw-r--r--app/models/info_request.rb8
-rw-r--r--app/models/profile_photo.rb12
-rw-r--r--app/models/public_body.rb34
-rw-r--r--app/views/admin_public_body/show.html.erb5
-rw-r--r--app/views/admin_request/_some_annotations.html.erb48
-rw-r--r--app/views/admin_request/show.html.erb49
-rw-r--r--app/views/admin_user/show.html.erb6
-rw-r--r--app/views/general/_localised_datepicker.html.erb10
-rw-r--r--app/views/reports/new.html.erb8
-rw-r--r--app/views/user/sign.html.erb2
-rw-r--r--app/views/user/wall.html.erb25
m---------commonlib0
-rw-r--r--lib/alaveteli_external_command.rb6
-rw-r--r--locale/cy/app.po6
-rwxr-xr-xscript/site-specific-install.sh5
-rw-r--r--spec/controllers/api_controller_spec.rb12
-rw-r--r--spec/fixtures/files/email-folding-example-1.txt.expected7
-rw-r--r--spec/fixtures/files/email-folding-example-10.txt12
-rw-r--r--spec/fixtures/files/email-folding-example-10.txt.expected13
-rw-r--r--spec/fixtures/files/email-folding-example-11.txt45
-rw-r--r--spec/fixtures/files/email-folding-example-11.txt.expected8
-rw-r--r--spec/fixtures/files/email-folding-example-2.txt.expected1
-rw-r--r--spec/fixtures/files/email-folding-example-3.txt.expected7
-rw-r--r--spec/fixtures/files/email-folding-example-5.txt.expected12
-rw-r--r--spec/fixtures/files/email-folding-example-7.txt.expected3
-rw-r--r--spec/fixtures/files/email-folding-example-8.txt.expected3
-rw-r--r--spec/fixtures/files/email-folding-example-9.txt.expected6
-rw-r--r--spec/lib/alaveteli_external_command.rb23
-rwxr-xr-xspec/lib/alaveteli_external_command_scripts/error.sh4
-rwxr-xr-xspec/lib/alaveteli_external_command_scripts/segfault.sh3
-rw-r--r--spec/models/incoming_message_spec.rb4
-rw-r--r--spec/models/profile_photo_spec.rb22
-rw-r--r--spec/models/public_body_spec.rb31
-rw-r--r--spec/spec_helper.rb18
39 files changed, 336 insertions, 151 deletions
diff --git a/.cvsignore b/.cvsignore
deleted file mode 100644
index 1e38e022c..000000000
--- a/.cvsignore
+++ /dev/null
@@ -1,5 +0,0 @@
-tmp
-log
-coverage
-sqlitedbs
-cache
diff --git a/Gemfile.lock b/Gemfile.lock
index 62258c0c6..492c855c3 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -266,7 +266,7 @@ GEM
nokogiri (>= 1.2.0)
rack (>= 1.0)
rack-test (>= 0.5.3)
- will_paginate (3.0.4)
+ will_paginate (3.0.5)
xapian-full-alaveteli (1.2.9.5)
xml-simple (1.1.2)
zip (2.0.2)
diff --git a/app/controllers/admin_request_controller.rb b/app/controllers/admin_request_controller.rb
index 4d45ced8b..2f5f51c0f 100644
--- a/app/controllers/admin_request_controller.rb
+++ b/app/controllers/admin_request_controller.rb
@@ -26,15 +26,13 @@ class AdminRequestController < AdminController
def show
@info_request = InfoRequest.find(params[:id])
- # XXX is this *really* the only way to render a template to a
- # variable, rather than to the response?
- vars = OpenStruct.new(:name_to => @info_request.user_name,
- :name_from => AlaveteliConfiguration::contact_name,
- :info_request => @info_request, :reason => params[:reason],
- :info_request_url => 'http://' + AlaveteliConfiguration::domain + request_url(@info_request),
- :site_name => site_name)
- template = File.read(File.join(File.dirname(__FILE__), "..", "views", "admin_request", "hidden_user_explanation.html.erb"))
- @request_hidden_user_explanation = ERB.new(template).result(vars.instance_eval { binding })
+ vars_for_explanation = {:reason => params[:reason],
+ :info_request => @info_request,
+ :name_to => @info_request.user_name,
+ :name_from => AlaveteliConfiguration::contact_name,
+ :info_request_url => request_url(@info_request, :only_path => false)}
+ @request_hidden_user_explanation = render_to_string(:template => "admin_request/hidden_user_explanation",
+ :locals => vars_for_explanation)
end
def resend
diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb
index d982bd391..6f80be7a6 100644
--- a/app/controllers/request_controller.rb
+++ b/app/controllers/request_controller.rb
@@ -326,7 +326,7 @@ class RequestController < ApplicationController
if !authenticated?(
:web => _("To send your FOI request").to_str,
:email => _("Then your FOI request to {{public_body_name}} will be sent.",:public_body_name=>@info_request.public_body.name),
- :email_subject => _("Confirm your FOI request to ") + @info_request.public_body.name
+ :email_subject => _("Confirm your FOI request to {{public_body_name}}",:public_body_name=>@info_request.public_body.name)
)
# do nothing - as "authenticated?" has done the redirect to signin page for us
return
diff --git a/app/models/incoming_message.rb b/app/models/incoming_message.rb
index bcf0b6ec9..59e61952e 100644
--- a/app/models/incoming_message.rb
+++ b/app/models/incoming_message.rb
@@ -385,6 +385,10 @@ class IncomingMessage < ActiveRecord::Base
multiline_original_message = '(' + '''>>>.* \d\d/\d\d/\d\d\d\d\s+\d\d:\d\d(?::\d\d)?\s*>>>''' + ')'
text.gsub!(/^(#{multiline_original_message}\n.*)$/m, replacement)
+ # On Thu, Nov 28, 2013 at 9:08 AM, A User
+ # <[1]request-7-skm40s2ls@xxx.xxxx> wrote:
+ text.gsub!(/^( On [^\n]+\n\s*\<[^>\n]+\> (wrote|said):\s*\n.*)$/m, replacement)
+
# Single line sections
text.gsub!(/^(>.*\n)/, replacement)
text.gsub!(/^(On .+ (wrote|said):\n)/, replacement)
diff --git a/app/models/info_request.rb b/app/models/info_request.rb
index 0a073dc79..4eb64dc13 100644
--- a/app/models/info_request.rb
+++ b/app/models/info_request.rb
@@ -113,8 +113,12 @@ class InfoRequest < ActiveRecord::Base
# Possible reasons that a request could be reported for administrator attention
def report_reasons
- ["Contains defamatory material", "Not a valid request", "Request for personal information",
- "Contains personal information", "Vexatious", "Other"]
+ [_("Contains defamatory material"),
+ _("Not a valid request"),
+ _("Request for personal information"),
+ _("Contains personal information"),
+ _("Vexatious"),
+ _("Other")]
end
def must_be_valid_state
diff --git a/app/models/profile_photo.rb b/app/models/profile_photo.rb
index 322ebe53c..6c3b2cfa0 100644
--- a/app/models/profile_photo.rb
+++ b/app/models/profile_photo.rb
@@ -70,21 +70,25 @@ class ProfilePhoto < ActiveRecord::Base
def data_and_draft_checks
if self.data.nil?
- errors.add(:data, N_("Please choose a file containing your photo."))
+ errors.add(:data, _("Please choose a file containing your photo."))
return
end
if self.image.nil?
- errors.add(:data, N_("Couldn't understand the image file that you uploaded. PNG, JPEG, GIF and many other common image file formats are supported."))
+ errors.add(:data, _("Couldn't understand the image file that you uploaded. PNG, JPEG, GIF and many other common image file formats are supported."))
return
end
if self.image.format != 'PNG'
- errors.add(:data, N_("Failed to convert image to a PNG"))
+ errors.add(:data, _("Failed to convert image to a PNG"))
end
if !self.draft && (self.image.columns != WIDTH || self.image.rows != HEIGHT)
- errors.add(:data, N_("Failed to convert image to the correct size: at {{cols}}x{{rows}}, need {{width}}x{{height}}", :cols => self.image.columns, :rows => self.image.rows, :width => WIDTH, :height => HEIGHT))
+ errors.add(:data, _("Failed to convert image to the correct size: at {{cols}}x{{rows}}, need {{width}}x{{height}}",
+ :cols => self.image.columns,
+ :rows => self.image.rows,
+ :width => WIDTH,
+ :height => HEIGHT))
end
if self.draft && self.user_id
diff --git a/app/models/public_body.rb b/app/models/public_body.rb
index 933825d2a..a78a6677e 100644
--- a/app/models/public_body.rb
+++ b/app/models/public_body.rb
@@ -346,22 +346,26 @@ class PublicBody < ActiveRecord::Base
# The "internal admin" is a special body for internal use.
def PublicBody.internal_admin_body
- I18n.with_locale(I18n.default_locale) do
- pb = PublicBody.find_by_url_name("internal_admin_authority")
- if pb.nil?
- pb = PublicBody.new(
- :name => 'Internal admin authority',
- :short_name => "",
- :request_email => AlaveteliConfiguration::contact_email,
- :home_page => "",
- :notes => "",
- :publication_scheme => "",
- :last_edit_editor => "internal_admin",
- :last_edit_comment => "Made by PublicBody.internal_admin_body"
- )
- pb.save!
+ # Use find_by_sql to avoid the search being specific to a
+ # locale, since url_name is a translated field:
+ sql = "SELECT * FROM public_bodies WHERE url_name = 'internal_admin_authority'"
+ matching_pbs = PublicBody.find_by_sql sql
+ case
+ when matching_pbs.empty? then
+ I18n.with_locale(I18n.default_locale) do
+ PublicBody.create!(:name => 'Internal admin authority',
+ :short_name => "",
+ :request_email => AlaveteliConfiguration::contact_email,
+ :home_page => "",
+ :notes => "",
+ :publication_scheme => "",
+ :last_edit_editor => "internal_admin",
+ :last_edit_comment => "Made by PublicBody.internal_admin_body")
end
- return pb
+ when matching_pbs.length == 1 then
+ matching_pbs[0]
+ else
+ raise "Multiple public bodies (#{matching_pbs.length}) found with url_name 'internal_admin_authority'"
end
end
diff --git a/app/views/admin_public_body/show.html.erb b/app/views/admin_public_body/show.html.erb
index 8262287d5..f8161db26 100644
--- a/app/views/admin_public_body/show.html.erb
+++ b/app/views/admin_public_body/show.html.erb
@@ -67,7 +67,10 @@
</div>
<% if i == versions.length - 1 %>
<div class="span6">
- <%=_("This is the first version.")%>
+ <p>“<%= h(historic_public_body.last_edit_comment) %>”</p>
+ <ul>
+ <li><%=_("This is the first version.")%></li>
+ </ul>
</div>
<% else %>
<div class="span6">
diff --git a/app/views/admin_request/_some_annotations.html.erb b/app/views/admin_request/_some_annotations.html.erb
new file mode 100644
index 000000000..dfd46f828
--- /dev/null
+++ b/app/views/admin_request/_some_annotations.html.erb
@@ -0,0 +1,48 @@
+<% if comments.size > 0 %>
+ <div class="accordion" id="comments">
+ <% for comment in comments %>
+ <div class="accordion-group">
+ <div class="accordion-heading">
+ <a href="#comment_<%=comment.id%>" data-toggle="collapse" data-parent="#comments"><%= chevron_right %></a>
+ <%= link_to admin_request_edit_comment_path(comment) do %>
+ #<%=comment.id%>
+ --
+ <%=h(comment.user.name)%>
+ <%=admin_value(comment.created_at)%>
+ <% end %>
+ <blockquote class="incoming-message">
+ <%= truncate(comment.body, :length => 400) %>
+ </blockquote>
+ </div>
+ <div id="comment_<%=comment.id%>" class="accordion-body collapse">
+ <table class="table table-striped table-condensed">
+ <tbody>
+ <tr>
+ <td colspan="2">
+ By <%= user_both_links(comment.user) %>
+ </td>
+ </tr>
+ <% comment.for_admin_column do |name, value, type, column_name |%>
+ <tr>
+ <td>
+ <b><%=name%></b>
+ </td>
+ <td>
+ <% if column_name == 'body' && !comment.visible %>
+ <s><%=h comment.send(column_name) %></s>
+ <% else %>
+ <%=h comment.send(column_name) %>
+ <% end %>
+ </td>
+ </tr>
+ <% end %>
+ </tbody>
+ </table>
+ </div>
+ </div>
+ <% end %>
+ </div>
+<% else %>
+ <p>None yet.</p>
+<% end %>
+
diff --git a/app/views/admin_request/show.html.erb b/app/views/admin_request/show.html.erb
index 83d9c3764..2589e52b4 100644
--- a/app/views/admin_request/show.html.erb
+++ b/app/views/admin_request/show.html.erb
@@ -325,53 +325,8 @@
<hr>
<h2>Annotations</h2>
-<% if @info_request.comments.size > 0 %>
- <div class="accordion" id="comments">
- <% for comment in @info_request.comments %>
- <div class="accordion-group">
- <div class="accordion-heading">
- <a href="#comment_<%=comment.id%>" data-toggle="collapse" data-parent="#comments"><%= chevron_right %></a>
- <%= link_to admin_request_edit_comment_path(comment) do %>
- #<%=comment.id%>
- --
- <%=h(comment.user.name)%>
- <%=admin_value(comment.created_at)%>
- <% end %>
- <blockquote class="incoming-message">
- <%= truncate(comment.body, :length => 400) %>
- </blockquote>
- </div>
- <div id="comment_<%=comment.id%>" class="accordion-body collapse">
- <table class="table table-striped table-condensed">
- <tbody>
- <tr>
- <td colspan="2">
- By <%= user_both_links(comment.user) %>
- </td>
- </tr>
- <% comment.for_admin_column do |name, value, type, column_name |%>
- <tr>
- <td>
- <b><%=name%></b>
- </td>
- <td>
- <% if column_name == 'body' && !comment.visible %>
- <s><%=h comment.send(column_name) %></s>
- <% else %>
- <%=h comment.send(column_name) %>
- <% end %>
- </td>
- </tr>
- <% end %>
- </tbody>
- </table>
- </div>
- </div>
- <% end %>
- </div>
-<% else %>
- <p>None yet.</p>
-<% end %>
+<%= render :partial => 'admin_request/some_annotations' , :locals => { :comments => @info_request.comments } %>
+
<hr>
<h2>Mail server delivery logs</h2>
diff --git a/app/views/admin_user/show.html.erb b/app/views/admin_user/show.html.erb
index c93c08e50..6d12aeff5 100644
--- a/app/views/admin_user/show.html.erb
+++ b/app/views/admin_user/show.html.erb
@@ -91,6 +91,12 @@
<hr>
+<h2>Annotations</h2>
+
+<%= render :partial => 'admin_request/some_annotations' , :locals => { :comments => @admin_user.comments } %>
+
+<hr>
+
<h2>Censor rules</h2>
<%= render :partial => 'admin_censor_rule/show', :locals => { :censor_rules => @admin_user.censor_rules, :user => @admin_user } %>
diff --git a/app/views/general/_localised_datepicker.html.erb b/app/views/general/_localised_datepicker.html.erb
index ec6593ea0..ee3206957 100644
--- a/app/views/general/_localised_datepicker.html.erb
+++ b/app/views/general/_localised_datepicker.html.erb
@@ -1,16 +1,16 @@
<script type="text/javascript">
$(function() {
$(".use-datepicker").datepicker(
- {closeText: '<%= _("Done") %>',
- prevText: '<%= _("Prev") %>',
- nextText: '<%= _("Next") %>',
- currentText: '<%= _("Today") %>',
+ {closeText: '<%= j _("Done") %>',
+ prevText: '<%= j _("Prev") %>',
+ nextText: '<%= j _("Next") %>',
+ currentText: '<%= j _("Today") %>',
monthNames: <%= raw I18n.translate('date.month_names')[1..-1].to_json %>,
monthNamesShort: <%= raw I18n.translate('date.abbr_month_names')[1..-1].to_json %>,
dayNames: <%= raw I18n.translate('date.day_names').to_json %>,
dayNamesShort: <%= raw I18n.translate('date.abbr_day_names').to_json %>,
dayNamesMin: <%= raw I18n.translate('date.abbr_day_names').collect{|x| x[0..0]}.to_json %>,
- weekHeader: '<%= _("Wk") %>',
+ weekHeader: '<%= j _("Wk") %>',
dateFormat: '<%= I18n.translate('date.formats.default').sub("%Y", "yy").sub("%m", "mm").sub("%d", "dd").gsub("-", "/") %>'}
);
});
diff --git a/app/views/reports/new.html.erb b/app/views/reports/new.html.erb
index 7d558ab4e..1197b2255 100644
--- a/app/views/reports/new.html.erb
+++ b/app/views/reports/new.html.erb
@@ -4,17 +4,17 @@
<p><%= _("This request has already been reported for administrator attention") %></p>
<% else %>
<p>
- Reporting a request notifies the site administrators. They will respond as soon as possible.
+ <%= _("Reporting a request notifies the site administrators. They will respond as soon as possible.") %>
</p>
- <p>Why specifically do you consider this request unsuitable?</p>
+ <p><%= _("Why specifically do you consider this request unsuitable?") %></p>
<%= form_tag request_report_path(:request_id => @info_request.url_title) do %>
<p>
<label class="form_label" for="reason">Reason:</label>
- <%= select_tag :reason, options_for_select(@info_request.report_reasons, @reason), :prompt => "Choose a reason" %>
+ <%= select_tag :reason, options_for_select(@info_request.report_reasons, @reason), :prompt => _("Choose a reason") %>
</p>
<p>
- <label class="form_label" for="message">Please tell us more:</label>
+ <label class="form_label" for="message"><%= _("Please tell us more:") %></label>
<%= text_area_tag :message, @message, :rows => 10, :cols => 60 %>
</p>
diff --git a/app/views/user/sign.html.erb b/app/views/user/sign.html.erb
index 8291cdace..e8c5d5a58 100644
--- a/app/views/user/sign.html.erb
+++ b/app/views/user/sign.html.erb
@@ -13,7 +13,7 @@
</p>
<% if @post_redirect.post_params["controller"] == "admin_general" %>
<% unless AlaveteliConfiguration::disable_emergency_user %>
- <p id="superuser_message">Don't have a superuser account yet? <%= link_to "Sign in as the emergency user", @post_redirect.uri + "?emergency=1" %></p>
+ <p id="superuser_message"><%= _("Don't have a superuser account yet?") %> <%= link_to _("Sign in as the emergency user"), @post_redirect.uri + "?emergency=1" %></p>
<% end %>
<% end %>
diff --git a/app/views/user/wall.html.erb b/app/views/user/wall.html.erb
index 190cc0a6d..6699c55fa 100644
--- a/app/views/user/wall.html.erb
+++ b/app/views/user/wall.html.erb
@@ -1,16 +1,19 @@
<% @title = h(@display_user.name) + _(" - wall") %>
-<% if @is_you %>
<div class="medium_column">
- <p><%= _('You can change the requests and users you are following on <a href="{{profile_url}}">your profile page</a>.', :profile_url => show_user_profile_path) %>
- <%= render :partial => 'change_receive_email' %>
+ <% if @is_you %>
+ <h2><%= _("My wall") %></h2>
+ <p><%= _('You can change the requests and users you are following on <a href="{{profile_url}}">your profile page</a>.', :profile_url => show_user_profile_path) %></p>
+ <%= render :partial => 'change_receive_email' %>
+ <% else %>
+ <h2><%= _("This is <a href=\"{{profile_url}}\">{{user_name}}'s</a> wall", :profile_url => show_user_profile_path, :user_name => h(@display_user.name)) %></h2>
+ <% end %>
</div>
-<% end %>
<div id="user_profile_search">
- <% if !@feed_results.nil? %>
- <% for result in @feed_results %>
- <%= render :partial => 'request/wall_listing', :locals => { :event => result, :info_request => result.info_request } %>
- <% end %>
- <% end %>
-
-
+ <% if !@feed_results.nil? and !@feed_results.empty? %>
+ <% for result in @feed_results %>
+ <%= render :partial => 'request/wall_listing', :locals => { :event => result, :info_request => result.info_request } %>
+ <% end %>
+ <% else %>
+ <p><%= _("There is nothing to display yet.") %></p>
+ <% end %>
</div>
diff --git a/commonlib b/commonlib
-Subproject ad27f5409ef3ed1b800aa08c1d70a018443dcfd
+Subproject 438003985e1bfb90fb83f5bbc5dce3da3fb21ee
diff --git a/lib/alaveteli_external_command.rb b/lib/alaveteli_external_command.rb
index fbdee8a62..086a461c8 100644
--- a/lib/alaveteli_external_command.rb
+++ b/lib/alaveteli_external_command.rb
@@ -44,7 +44,11 @@ module AlaveteliExternalCommand
end
xc.run(opts[:stdin_string] || "", opts[:env] || {})
- if xc.status != 0
+ if !xc.exited
+ # Crash or timeout
+ $stderr.puts("#{program_name} #{args.join(' ')}:exited abnormally")
+ return nil
+ elsif xc.status != 0
# Error
$stderr.puts("Error from #{program_name} #{args.join(' ')}:")
$stderr.print(xc.err)
diff --git a/locale/cy/app.po b/locale/cy/app.po
index 4a82d1f66..88f03a98c 100644
--- a/locale/cy/app.po
+++ b/locale/cy/app.po
@@ -20,7 +20,7 @@ msgstr ""
"Project-Id-Version: alaveteli\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2013-11-08 12:10+0000\n"
-"PO-Revision-Date: 2014-01-24 09:25+0000\n"
+"PO-Revision-Date: 2014-01-27 11:01+0000\n"
"Last-Translator: louisecrow <louise@mysociety.org>\n"
"Language-Team: Welsh (http://www.transifex.com/projects/p/alaveteli/language/cy/)\n"
"Language: cy\n"
@@ -1273,7 +1273,7 @@ msgid "MailServerLog|Order"
msgstr "MailServerLog|Archeb"
msgid "Make a new<br/>\\n <strong>Freedom <span>of</span><br/>\\n Information<br/>\\n request</strong>"
-msgstr "Gwnewch <strong>Cais Rhyddid Gwybodaeth</strong> newydd"
+msgstr "Gwnewch <strong>Cais<br/>Rhyddid<br/>Gwybodaeth</strong><br/>newydd"
msgid "Make a request"
msgstr "Gwneud cais"
@@ -2999,7 +2999,7 @@ msgid "You may be able to find\\n one on their website, or by phoning them up
msgstr "Efallai y byddwch yn gallu dod o hyd i un ar eu gwefan, neu drwy eu ffonio nhw a gofyn. Os llwyddwch i ddod o hyd i un, <a href=\"{{url}}\"> anfonwch e atom</a>."
msgid "You may be able to find\\none on their website, or by phoning them up and asking. If you manage\\nto find one, then please <a href=\"{{help_url}}\">send it to us</a>."
-msgstr "Efallai y byddwch yn gallu dod o hyd i un ar eu gwefan, neu drwy eu ffonio nhw a gofyn. Os llwyddwch i ddod o hyd i un, <a href=\"{{url}}\"> anfonwch e atom</a>."
+msgstr "Efallai y byddwch yn gallu dod o hyd i un ar eu gwefan, neu drwy eu ffonio nhw a gofyn. Os llwyddwch i ddod o hyd i un, <a href=\"{{help_url}}\"> anfonwch e atom</a>."
msgid "You need to be logged in to change the text about you on your profile."
msgstr "Rhaid i chi fod wedi mewngofnodi i newid y testun amdanoch chi ar eich proffil."
diff --git a/script/site-specific-install.sh b/script/site-specific-install.sh
index 8917fd577..7d47a5990 100755
--- a/script/site-specific-install.sh
+++ b/script/site-specific-install.sh
@@ -66,6 +66,11 @@ ensure_line_present \
/etc/postfix/main.cf 644
ensure_line_present \
+ "^ *myhostname *=" \
+ "myhostname = $(hostname --fqdn)" \
+ /etc/postfix/main.cf 644
+
+ensure_line_present \
"^do-not-reply" \
"do-not-reply-to-this-address: :blackhole:" \
/etc/aliases 644
diff --git a/spec/controllers/api_controller_spec.rb b/spec/controllers/api_controller_spec.rb
index 8e9d17fbe..e9a0f0be4 100644
--- a/spec/controllers/api_controller_spec.rb
+++ b/spec/controllers/api_controller_spec.rb
@@ -1,18 +1,6 @@
# coding: utf-8
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
-def normalise_whitespace(s)
- s = s.gsub(/\A\s+|\s+\Z/, "")
- s = s.gsub(/\s+/, " ")
- return s
-end
-
-RSpec::Matchers.define :be_equal_modulo_whitespace_to do |expected|
- match do |actual|
- normalise_whitespace(actual) == normalise_whitespace(expected)
- end
-end
-
describe ApiController, "when using the API" do
describe 'checking API keys' do
diff --git a/spec/fixtures/files/email-folding-example-1.txt.expected b/spec/fixtures/files/email-folding-example-1.txt.expected
index 801542288..45dabf156 100644
--- a/spec/fixtures/files/email-folding-example-1.txt.expected
+++ b/spec/fixtures/files/email-folding-example-1.txt.expected
@@ -8,3 +8,10 @@ On behalf of James Hall, Chief Executive
Identity and Passport Service
<<9032 C Pollard final response.doc>>
+FOLDED_QUOTED_SECTION
+
+FOLDED_QUOTED_SECTION
+
+
+FOLDED_QUOTED_SECTION
+
diff --git a/spec/fixtures/files/email-folding-example-10.txt b/spec/fixtures/files/email-folding-example-10.txt
index 0fabb7f9c..a0773e6ff 100644
--- a/spec/fixtures/files/email-folding-example-10.txt
+++ b/spec/fixtures/files/email-folding-example-10.txt
@@ -3,13 +3,13 @@ Department of Health, please visit the 'Contact us' page on the
Department’s website.
-----------------------------------------------------------------------------------------
-
- Apologies that you were not able to read our previous response of 4
- October. Please find the text of that email below.
-
+
+ Apologies that you were not able to read our previous response of 4
+ October. Please find the text of that email below.
+
Our ref: DE00000642471
-Dear Ms Peters Rock,
+Dear Ms Peters Rock,
You requested your correspondence to be treated under the Freedom of
Information Act.  However, as your correspondence asked for general
@@ -19,7 +19,7 @@ correspondence under the provisions of the Act.
I am sorry I cannot be more helpful.
-Yours sincerely,
+Yours sincerely,
Simon Dove
Customer Service Centre
Department of Health
diff --git a/spec/fixtures/files/email-folding-example-10.txt.expected b/spec/fixtures/files/email-folding-example-10.txt.expected
index e4f704c0e..5b609dc12 100644
--- a/spec/fixtures/files/email-folding-example-10.txt.expected
+++ b/spec/fixtures/files/email-folding-example-10.txt.expected
@@ -3,13 +3,13 @@ Department of Health, please visit the 'Contact us' page on the
Department’s website.
-----------------------------------------------------------------------------------------
-
- Apologies that you were not able to read our previous response of 4
- October. Please find the text of that email below.
-
+
+ Apologies that you were not able to read our previous response of 4
+ October. Please find the text of that email below.
+
Our ref: DE00000642471
-Dear Ms Peters Rock,
+Dear Ms Peters Rock,
You requested your correspondence to be treated under the Freedom of
Information Act.  However, as your correspondence asked for general
@@ -19,7 +19,8 @@ correspondence under the provisions of the Act.
I am sorry I cannot be more helpful.
-Yours sincerely,
+Yours sincerely,
Simon Dove
Customer Service Centre
Department of Health
+FOLDED_QUOTED_SECTION
diff --git a/spec/fixtures/files/email-folding-example-11.txt b/spec/fixtures/files/email-folding-example-11.txt
new file mode 100644
index 000000000..635d7aa4f
--- /dev/null
+++ b/spec/fixtures/files/email-folding-example-11.txt
@@ -0,0 +1,45 @@
+ Hello Example,
+
+ This is a reply to your test request Nov 28.
+
+ Regards.
+
+ On Thu, Nov 28, 2013 at 9:08 AM, Example User
+ <[1]request-x-xxx@xxx.com> wrote:
+
+ Dear Test Authority,
+
+ This is the request body.
+
+ Yours faithfully,
+
+ Example User
+
+ -------------------------------------------------------------------
+
+ Please use this email address for all replies to this request:
+ [2]request-x-xxx@xxx.com
+
+ Is [3]testauthority@example.com the wrong address for Freedom of
+ Information requests to AYG Test Authority? If so, please contact us
+ using this form:
+ [4]http://example.com/help/contact
+
+ Disclaimer: This message and any reply that you make will be published
+ on the internet. Our privacy and copyright policies:
+ [5]http://example.com/help/officers
+
+ If you find this service useful as an FOI officer, please ask your web
+ manager to link to us from your organisation's FOI page.
+
+ -------------------------------------------------------------------
+
+References
+
+ Visible links
+ 1. mailto:request-x-xxx@xxx.com
+ 2. mailto:request-x-xxx@xxx.com
+ 3. mailto:testauthority@example.com
+ 4. http://example.com/help/contact
+ 5. http://example.com/help/officers
+
diff --git a/spec/fixtures/files/email-folding-example-11.txt.expected b/spec/fixtures/files/email-folding-example-11.txt.expected
new file mode 100644
index 000000000..e336062c7
--- /dev/null
+++ b/spec/fixtures/files/email-folding-example-11.txt.expected
@@ -0,0 +1,8 @@
+ Hello Example,
+
+ This is a reply to your test request Nov 28.
+
+ Regards.
+
+
+FOLDED_QUOTED_SECTION
diff --git a/spec/fixtures/files/email-folding-example-2.txt.expected b/spec/fixtures/files/email-folding-example-2.txt.expected
index e52fbe443..df578390d 100644
--- a/spec/fixtures/files/email-folding-example-2.txt.expected
+++ b/spec/fixtures/files/email-folding-example-2.txt.expected
@@ -2,3 +2,4 @@ Preface to the message which we are not interested in
-----------------------------------------------------------------------------------------
Important message about cheese
+FOLDED_QUOTED_SECTION
diff --git a/spec/fixtures/files/email-folding-example-3.txt.expected b/spec/fixtures/files/email-folding-example-3.txt.expected
index e2cca4933..accb40150 100644
--- a/spec/fixtures/files/email-folding-example-3.txt.expected
+++ b/spec/fixtures/files/email-folding-example-3.txt.expected
@@ -3,3 +3,10 @@ Reference : T3241/8
Thank you for your e-mail enquiry of 12th February.
A reply is attached.
+FOLDED_QUOTED_SECTION
+
+FOLDED_QUOTED_SECTION
+
+
+FOLDED_QUOTED_SECTION
+
diff --git a/spec/fixtures/files/email-folding-example-5.txt.expected b/spec/fixtures/files/email-folding-example-5.txt.expected
index fbb0f0f50..46d7f731a 100644
--- a/spec/fixtures/files/email-folding-example-5.txt.expected
+++ b/spec/fixtures/files/email-folding-example-5.txt.expected
@@ -1,11 +1,11 @@
Hi Simon
-My apologies for timescale of response. The data forwarded is a public
-register, and is updated on a frequent and regular basis; your request
-unfortunately coincided with annual leave and a monthly update of the
-spreadsheet. As the definition of an HMO under the Housing Act 2004
-differs to that under planning legislation, I have forwarded this and
-your original request on to Andy England, Development Control Manager to
+My apologies for timescale of response. The data forwarded is a public
+register, and is updated on a frequent and regular basis; your request
+unfortunately coincided with annual leave and a monthly update of the
+spreadsheet. As the definition of an HMO under the Housing Act 2004
+differs to that under planning legislation, I have forwarded this and
+your original request on to Andy England, Development Control Manager to
respond independantly.
If I can be of further assistance please contact me
diff --git a/spec/fixtures/files/email-folding-example-7.txt.expected b/spec/fixtures/files/email-folding-example-7.txt.expected
index 0ef8fd82b..cb6961038 100644
--- a/spec/fixtures/files/email-folding-example-7.txt.expected
+++ b/spec/fixtures/files/email-folding-example-7.txt.expected
@@ -13,4 +13,5 @@ Telephone +44 (0) 116 2222222
Extn 5221 VM No. 8035
Fax + 44 (0) 116 2485217
-<<0001_00035908_Resp_12RESPONSE LETTER_20080408_112311_01.TIF>> \ No newline at end of file
+<<0001_00035908_Resp_12RESPONSE LETTER_20080408_112311_01.TIF>>
+FOLDED_QUOTED_SECTION
diff --git a/spec/fixtures/files/email-folding-example-8.txt.expected b/spec/fixtures/files/email-folding-example-8.txt.expected
index b5dc10c0d..e8c08f4ca 100644
--- a/spec/fixtures/files/email-folding-example-8.txt.expected
+++ b/spec/fixtures/files/email-folding-example-8.txt.expected
@@ -3,4 +3,5 @@ I will be out of the office starting 11/04/2008 and will not return until
I will respond to your message when I return. If you have any urgent
queries please ring 02085419088 for Legal Business Support queries or
-contact Eileen Perren for FOI or DP queries \ No newline at end of file
+contact Eileen Perren for FOI or DP queries
+FOLDED_QUOTED_SECTION
diff --git a/spec/fixtures/files/email-folding-example-9.txt.expected b/spec/fixtures/files/email-folding-example-9.txt.expected
index 2d2381a34..d222e9438 100644
--- a/spec/fixtures/files/email-folding-example-9.txt.expected
+++ b/spec/fixtures/files/email-folding-example-9.txt.expected
@@ -7,3 +7,9 @@ Yours sincerely
MICHAEL HEGARTY
FOI Officer
+FOLDED_QUOTED_SECTION
+
+FOLDED_QUOTED_SECTION
+
+
+FOLDED_QUOTED_SECTION
diff --git a/spec/lib/alaveteli_external_command.rb b/spec/lib/alaveteli_external_command.rb
new file mode 100644
index 000000000..18afeda33
--- /dev/null
+++ b/spec/lib/alaveteli_external_command.rb
@@ -0,0 +1,23 @@
+require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
+
+require 'alaveteli_external_command'
+
+script_dir = File.join(File.dirname(__FILE__), 'alaveteli_external_command_scripts')
+segfault_script = File.join(script_dir, 'segfault.sh')
+error_script = File.join(script_dir, 'error.sh')
+
+describe "when running external commands" do
+
+ it "should detect a non-zero exit status" do
+ $stderr.should_receive(:puts).with(/Error from/)
+ t = AlaveteliExternalCommand.run(error_script)
+ assert_nil t
+ end
+
+ it "should detect when an external command crashes" do
+ $stderr.should_receive(:puts).with(/exited abnormally/)
+ t = AlaveteliExternalCommand.run(segfault_script)
+ assert_nil t
+ end
+
+end
diff --git a/spec/lib/alaveteli_external_command_scripts/error.sh b/spec/lib/alaveteli_external_command_scripts/error.sh
new file mode 100755
index 000000000..65e74b3c6
--- /dev/null
+++ b/spec/lib/alaveteli_external_command_scripts/error.sh
@@ -0,0 +1,4 @@
+#!/bin/sh
+
+echo "this is my error message" >&1
+exit 1
diff --git a/spec/lib/alaveteli_external_command_scripts/segfault.sh b/spec/lib/alaveteli_external_command_scripts/segfault.sh
new file mode 100755
index 000000000..f96ba5be8
--- /dev/null
+++ b/spec/lib/alaveteli_external_command_scripts/segfault.sh
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+kill -11 $$
diff --git a/spec/models/incoming_message_spec.rb b/spec/models/incoming_message_spec.rb
index c0a7e5340..c27870afc 100644
--- a/spec/models/incoming_message_spec.rb
+++ b/spec/models/incoming_message_spec.rb
@@ -165,7 +165,7 @@ describe IncomingMessage, " when dealing with incoming mail" do
message = File.read(file)
parsed = IncomingMessage.remove_quoted_sections(message)
expected = File.read("#{file}.expected")
- parsed.should include(expected)
+ parsed.should be_equal_modulo_whitespace_to expected
end
end
@@ -462,7 +462,7 @@ describe IncomingMessage, " when censoring data" do
data.should == "His email was x\000x\000x\000@\000x\000x\000x\000.\000x\000x\000x\000, indeed"
end
- it 'should handle multibyte characters correctly', :focus => true do
+ it 'should handle multibyte characters correctly' do
orig_data = 'á'
data = orig_data.dup
@regex_censor_rule = CensorRule.new()
diff --git a/spec/models/profile_photo_spec.rb b/spec/models/profile_photo_spec.rb
index 0e157e2c5..e70f474a0 100644
--- a/spec/models/profile_photo_spec.rb
+++ b/spec/models/profile_photo_spec.rb
@@ -10,12 +10,12 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
-describe ProfilePhoto, "when constructing a new photo" do
+describe ProfilePhoto, "when constructing a new photo" do
- before do
+ before do
@mock_user = mock_model(User)
end
-
+
it 'should take no image as invalid' do
profile_photo = ProfilePhoto.new(:data => nil, :user => @mock_user)
profile_photo.valid?.should == false
@@ -26,7 +26,15 @@ describe ProfilePhoto, "when constructing a new photo" do
profile_photo.valid?.should == false
end
- it 'should accept and convert a PNG to right size' do
+ it 'should translate a no image error message' do
+ I18n.with_locale(:es) do
+ profile_photo = ProfilePhoto.new(:data => nil, :user => @mock_user)
+ profile_photo.valid?.should == false
+ profile_photo.errors[:data].should == ['Por favor elige el fichero que contiene tu foto']
+ end
+ end
+
+ it 'should accept and convert a PNG to right size' do
data = load_file_fixture("parrot.png")
profile_photo = ProfilePhoto.new(:data => data, :user => @mock_user)
profile_photo.valid?.should == true
@@ -35,7 +43,7 @@ describe ProfilePhoto, "when constructing a new photo" do
profile_photo.image.rows.should == 96
end
- it 'should accept and convert a JPEG to right format and size' do
+ it 'should accept and convert a JPEG to right format and size' do
data = load_file_fixture("parrot.jpg")
profile_photo = ProfilePhoto.new(:data => data, :user => @mock_user)
profile_photo.valid?.should == true
@@ -44,7 +52,7 @@ describe ProfilePhoto, "when constructing a new photo" do
profile_photo.image.rows.should == 96
end
- it 'should accept a draft PNG and not resize it' do
+ it 'should accept a draft PNG and not resize it' do
data = load_file_fixture("parrot.png")
profile_photo = ProfilePhoto.new(:data => data, :draft => true)
profile_photo.valid?.should == true
@@ -53,6 +61,6 @@ describe ProfilePhoto, "when constructing a new photo" do
profile_photo.image.rows.should == 289
end
-
+
end
diff --git a/spec/models/public_body_spec.rb b/spec/models/public_body_spec.rb
index ed24ced52..dc09bdfa6 100644
--- a/spec/models/public_body_spec.rb
+++ b/spec/models/public_body_spec.rb
@@ -300,6 +300,37 @@ describe PublicBody, "when searching" do
end
end
+describe PublicBody, "when asked for the internal_admin_body" do
+ before(:each) do
+ # Make sure that there's no internal_admin_body before each of
+ # these tests:
+ PublicBody.connection.delete("DELETE FROM public_bodies WHERE url_name = 'internal_admin_body'")
+ PublicBody.connection.delete("DELETE FROM public_body_translations WHERE url_name = 'internal_admin_body'")
+ end
+
+ it "should create the internal_admin_body if it didn't exist" do
+ iab = PublicBody.internal_admin_body
+ iab.should_not be_nil
+ end
+
+ it "should find the internal_admin_body even if the default locale has changed since it was created" do
+ with_default_locale("en") do
+ I18n.with_locale(:en) do
+ iab = PublicBody.internal_admin_body
+ iab.should_not be_nil
+ end
+ end
+ with_default_locale("es") do
+ I18n.with_locale(:es) do
+ iab = PublicBody.internal_admin_body
+ iab.should_not be_nil
+ end
+ end
+ end
+
+end
+
+
describe PublicBody, " when dealing public body locales" do
it "shouldn't fail if it internal_admin_body was created in a locale other than the default" do
# first time, do it with the non-default locale
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 1eeb8603b..dc5a0d6eb 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -187,11 +187,16 @@ Spork.prefork do
end
end
+ # Reset the default locale, making sure that the previous default locale
+ # is also cleared from the fallbacks
def with_default_locale(locale)
original_default_locale = I18n.default_locale
+ original_fallbacks = I18n.fallbacks
+ I18n.fallbacks = nil
I18n.default_locale = locale
yield
ensure
+ I18n.fallbacks = original_fallbacks
I18n.default_locale = original_default_locale
end
@@ -215,3 +220,16 @@ Spork.each_run do
FactoryGirl.reload
# This code will be run each time you run your specs.
end
+
+def normalise_whitespace(s)
+ s = s.gsub(/\A\s+|\s+\Z/, "")
+ s = s.gsub(/\s+/, " ")
+ return s
+end
+
+RSpec::Matchers.define :be_equal_modulo_whitespace_to do |expected|
+ match do |actual|
+ normalise_whitespace(actual) == normalise_whitespace(expected)
+ end
+end
+