diff options
533 files changed, 2745 insertions, 1210 deletions
diff --git a/.codeclimate.yml b/.codeclimate.yml new file mode 100644 index 000000000..215d81196 --- /dev/null +++ b/.codeclimate.yml @@ -0,0 +1,5 @@ +languages: + Ruby: true + PHP: true +exclude_paths: +- "lib/strip_attributes/test/*" diff --git a/.gitignore b/.gitignore index 994f9a3a1..78a06c661 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,9 @@ ._* .DS_Store .autotest +.ruby-version +.rbenv-version +.rvmrc *#*# TAGS /lib/themes @@ -25,7 +28,7 @@ config/httpd.conf config/general*.yml config/deploy.yml.* .sass-cache -alaveteli.sublime* +alaveteli*.sublime* webrat.log /.rbenv-version /db/development_structure.sql diff --git a/.ruby-version b/.ruby-version.example index 7fa1d1ef4..7fa1d1ef4 100644 --- a/.ruby-version +++ b/.ruby-version.example @@ -5,7 +5,7 @@ gem 'rails', '3.2.21' gem 'pg', '~> 0.17.1' # New gem releases aren't being done. master is newer and supports Rails > 3.0 -gem 'acts_as_versioned', :git => 'git://github.com/technoweenie/acts_as_versioned.git', :ref => '63b1fc8529d028' +gem 'acts_as_versioned', :git => 'https://github.com/technoweenie/acts_as_versioned.git', :ref => '63b1fc8529d028' gem 'charlock_holmes', '~> 0.6.9.4' gem 'dynamic_form', '~> 1.1.4' gem 'exception_notification', '~> 3.0.1' @@ -15,7 +15,7 @@ gem 'icalendar', '1.4.3' gem 'jquery-rails', '~> 3.0.4' gem 'jquery-ui-rails', '~> 4.1.0' gem 'json', '~> 1.8.1' -gem 'holidays', '~> 1.0.8' +gem 'holidays', '~> 1.2.0' gem 'iso_country_codes', '~> 0.6.1' gem 'mahoro', '~> 0.4' gem 'memcache-client', '~> 1.8.5' @@ -26,17 +26,16 @@ gem 'rack', '~> 1.4.5' gem 'rake', '0.9.2.2' gem 'rails-i18n', '~> 0.7.3' gem 'recaptcha', '~> 0.3.1', :require => 'recaptcha/rails' -# :require avoids "already initialized constant" warnings -gem 'rmagick', '~> 2.13.2', :require => 'RMagick' -gem 'ruby-msg', '~> 1.5.0', :git => 'git://github.com/mysociety/ruby-msg.git' -gem 'secure_headers', '~> 1.3.4' +gem 'rmagick', '~> 2.14.0' +gem 'ruby-msg', '~> 1.5.0', :git => 'https://github.com/mysociety/ruby-msg.git' +gem 'secure_headers', '~> 2.0.2' gem 'statistics2', '~> 0.54' gem 'syslog_protocol', '~> 0.9.2' gem 'thin', '~> 1.5.1' gem 'vpim', '~> 13.11.11' gem 'will_paginate', '~> 3.0.5' # when 1.2.9 is released by the maintainer, we can stop using this fork: -gem 'xapian-full-alaveteli', '~> 1.2.9.5' +gem 'xapian-full-alaveteli', '~> 1.2.9.7' gem 'xml-simple', '~> 1.1.2', :require => 'xmlsimple' gem 'zip', '~> 2.0.2' @@ -44,7 +43,7 @@ gem 'zip', '~> 2.0.2' gem 'fast_gettext', '~> 0.7.0' gem 'gettext_i18n_rails', '~> 0.9.4' gem 'gettext', '~> 2.3.9' -gem 'globalize3', :git => 'git://github.com/globalize/globalize.git', :ref => '5fd95f2389dff1' +gem 'globalize3', :git => 'https://github.com/globalize/globalize.git', :ref => '5fd95f2389dff1' gem 'locale', '~> 2.0.8' gem 'routing-filter', '~> 0.3.1' gem 'unicode', '~> 0.4.4' @@ -71,6 +70,7 @@ group :test do end group :test, :development do + gem 'bullet', '~> 4.14.6' gem 'factory_girl_rails', '~> 1.7' gem 'rspec-rails', '~> 2.13.2' gem 'spork-rails', '~> 3.2.1' diff --git a/Gemfile.lock b/Gemfile.lock index 2f88a474e..9353b9145 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,5 +1,5 @@ GIT - remote: git://github.com/globalize/globalize.git + remote: https://github.com/globalize/globalize.git revision: 5fd95f2389dff13c9368fb2e08c96c8a48798c72 ref: 5fd95f2389dff1 specs: @@ -9,7 +9,7 @@ GIT paper_trail (~> 2) GIT - remote: git://github.com/mysociety/ruby-msg.git + remote: https://github.com/mysociety/ruby-msg.git revision: ee0086add16c755d2eaf8dbcb90ba65809061cef specs: ruby-msg (1.5.2) @@ -17,7 +17,7 @@ GIT vpim (>= 0.360) GIT - remote: git://github.com/technoweenie/acts_as_versioned.git + remote: https://github.com/technoweenie/acts_as_versioned.git revision: 63b1fc8529d028fae632fe80ec0cb25df56cd76b ref: 63b1fc8529d028 specs: @@ -60,6 +60,9 @@ GEM bootstrap-sass (2.3.1.2) sass (~> 3.2) builder (3.0.4) + bullet (4.14.6) + activesupport (>= 3.0.0) + uniform_notifier (~> 1.9.0) capistrano (2.15.4) highline net-scp (>= 1.0.0) @@ -127,7 +130,7 @@ GEM tilt highline (1.6.19) hike (1.2.3) - holidays (1.0.8) + holidays (1.2.0) i18n (0.6.11) icalendar (1.4.3) iso_country_codes (0.6.1) @@ -216,7 +219,7 @@ GEM ref (1.0.5) rest-client (1.6.7) mime-types (>= 1.16) - rmagick (2.13.2) + rmagick (2.14.0) routing-filter (0.3.1) actionpack rspec-core (2.13.1) @@ -241,7 +244,7 @@ GEM railties (~> 3.2.0) sass (>= 3.1.10) tilt (~> 1.3) - secure_headers (1.3.4) + secure_headers (2.0.2) simplecov (0.7.1) multi_json (~> 1.0) simplecov-html (~> 0.7.1) @@ -285,13 +288,14 @@ GEM multi_json (~> 1.0, >= 1.0.2) unicode (0.4.4) unidecoder (1.1.2) + uniform_notifier (1.9.0) vpim (13.11.11) webrat (0.7.3) nokogiri (>= 1.2.0) rack (>= 1.0) rack-test (>= 0.5.3) will_paginate (3.0.5) - xapian-full-alaveteli (1.2.9.5) + xapian-full-alaveteli (1.2.9.7) xml-simple (1.1.2) zip (2.0.2) @@ -302,6 +306,7 @@ DEPENDENCIES acts_as_versioned! annotate (~> 2.5.0) bootstrap-sass (~> 2.3.1.2) + bullet (~> 4.14.6) capistrano (~> 2.15.4) charlock_holmes (~> 0.6.9.4) coffee-rails (~> 3.2.1) @@ -318,7 +323,7 @@ DEPENDENCIES gettext (~> 2.3.9) gettext_i18n_rails (~> 0.9.4) globalize3! - holidays (~> 1.0.8) + holidays (~> 1.2.0) icalendar (= 1.4.3) iso_country_codes (~> 0.6.1) jquery-rails (~> 3.0.4) @@ -342,13 +347,13 @@ DEPENDENCIES rake (= 0.9.2.2) rdoc (~> 3.12.2) recaptcha (~> 0.3.1) - rmagick (~> 2.13.2) + rmagick (~> 2.14.0) routing-filter (~> 0.3.1) rspec-rails (~> 2.13.2) ruby-debug (~> 0.10.4) ruby-msg (~> 1.5.0)! sass-rails (~> 3.2.3) - secure_headers (~> 1.3.4) + secure_headers (~> 2.0.2) spork-rails (~> 3.2.1) statistics2 (~> 0.54) syslog_protocol (~> 0.9.2) @@ -360,6 +365,6 @@ DEPENDENCIES vpim (~> 13.11.11) webrat (~> 0.7.3) will_paginate (~> 3.0.5) - xapian-full-alaveteli (~> 1.2.9.5) + xapian-full-alaveteli (~> 1.2.9.7) xml-simple (~> 1.1.2) zip (~> 2.0.2) @@ -25,6 +25,22 @@ wiki](https://github.com/mysociety/alaveteli/wiki/Home/), and upgrade notes in the [`doc/` folder](https://github.com/mysociety/alaveteli/tree/master/doc/CHANGES.md) +## Installing + +We've been working hard to make Alaveteli easy to install and re-use anywhere. Please +see [the project website](http://alaveteli.org) for instructions on installing Alaveteli. + +## Compatibility + +Every Alaveteli commit is tested by Travis on the [following Ruby platforms](https://github.com/mysociety/alaveteli/blob/master/.travis.yml#L7) + +* ruby-1.8.7 +* ruby-1.9.3 +* ruby-2.0.0 + + +If you use a ruby version management tool (such as RVM or .rbenv) and want to use the default development version used by the alaveteli team (currently 2.0.0), you can create a `.ruby-version` symlink with a target of `.ruby-version.example` to switch to that automatically in the project directory. + ## How to contribute If you find what looks like a bug: @@ -44,3 +60,11 @@ If you want to contribute an enhancement or a fix: Looking for the latest stable release? It's on the [master branch](https://github.com/mysociety/alaveteli/tree/master). +We have some more notes for developers [on the project site](http://alaveteli.org/docs/developers/). + +## Examples + +* [WhatDoTheyKnow](https://www.whatdotheyknow.com) +* [KiMitTud](http://kimittud.atlatszo.hu) +* [Informace Pro Všechny](http://www.infoprovsechny.cz) +* [fyi.org.nz](https://fyi.org.nz) diff --git a/app/assets/images/icon_application_octet-stream_large.png b/app/assets/images/icon_application_octet-stream_large.png Binary files differindex a239862e1..a23916e9c 100644 --- a/app/assets/images/icon_application_octet-stream_large.png +++ b/app/assets/images/icon_application_octet-stream_large.png diff --git a/app/assets/images/icon_application_pdf_large.png b/app/assets/images/icon_application_pdf_large.png Binary files differindex 9a38ca33c..990b96c0a 100644 --- a/app/assets/images/icon_application_pdf_large.png +++ b/app/assets/images/icon_application_pdf_large.png diff --git a/app/assets/images/icon_application_rtf_large.png b/app/assets/images/icon_application_rtf_large.png Binary files differindex 2ad990608..977972124 100644 --- a/app/assets/images/icon_application_rtf_large.png +++ b/app/assets/images/icon_application_rtf_large.png diff --git a/app/assets/images/icon_application_vnd.ms-excel_large.png b/app/assets/images/icon_application_vnd.ms-excel_large.png Binary files differindex 3f346f5ef..acca5d92c 100644 --- a/app/assets/images/icon_application_vnd.ms-excel_large.png +++ b/app/assets/images/icon_application_vnd.ms-excel_large.png diff --git a/app/assets/images/icon_application_vnd.ms-powerpoint_large.png b/app/assets/images/icon_application_vnd.ms-powerpoint_large.png Binary files differindex 82c225059..9a1582930 100644 --- a/app/assets/images/icon_application_vnd.ms-powerpoint_large.png +++ b/app/assets/images/icon_application_vnd.ms-powerpoint_large.png diff --git a/app/assets/images/icon_application_vnd.ms-word_large.png b/app/assets/images/icon_application_vnd.ms-word_large.png Binary files differindex 91a696ab5..2f3cb8efa 100644 --- a/app/assets/images/icon_application_vnd.ms-word_large.png +++ b/app/assets/images/icon_application_vnd.ms-word_large.png diff --git a/app/assets/images/icon_application_zip_large.png b/app/assets/images/icon_application_zip_large.png Binary files differindex 0a14e978e..c52d6d5aa 100644 --- a/app/assets/images/icon_application_zip_large.png +++ b/app/assets/images/icon_application_zip_large.png diff --git a/app/assets/images/icon_image_bmp_large.png b/app/assets/images/icon_image_bmp_large.png Binary files differindex f6e8dbaed..347bdaaf1 100644..120000 --- a/app/assets/images/icon_image_bmp_large.png +++ b/app/assets/images/icon_image_bmp_large.png diff --git a/app/assets/images/icon_image_gif_large.png b/app/assets/images/icon_image_gif_large.png Binary files differindex 424d1e0fd..347bdaaf1 100644..120000 --- a/app/assets/images/icon_image_gif_large.png +++ b/app/assets/images/icon_image_gif_large.png diff --git a/app/assets/images/icon_image_img_large.png b/app/assets/images/icon_image_img_large.png Binary files differnew file mode 100644 index 000000000..e19e7553c --- /dev/null +++ b/app/assets/images/icon_image_img_large.png diff --git a/app/assets/images/icon_image_jpeg_large.png b/app/assets/images/icon_image_jpeg_large.png Binary files differindex fd50a889d..347bdaaf1 100644..120000 --- a/app/assets/images/icon_image_jpeg_large.png +++ b/app/assets/images/icon_image_jpeg_large.png diff --git a/app/assets/images/icon_image_png_large.png b/app/assets/images/icon_image_png_large.png Binary files differindex f16edb08e..347bdaaf1 100644..120000 --- a/app/assets/images/icon_image_png_large.png +++ b/app/assets/images/icon_image_png_large.png diff --git a/app/assets/images/icon_image_tiff_large.png b/app/assets/images/icon_image_tiff_large.png Binary files differindex 356f63478..000bd0318 100644 --- a/app/assets/images/icon_image_tiff_large.png +++ b/app/assets/images/icon_image_tiff_large.png diff --git a/app/assets/images/icon_message_delivery-status_large.png b/app/assets/images/icon_message_delivery-status_large.png Binary files differindex a239862e1..dccdbbccd 100644 --- a/app/assets/images/icon_message_delivery-status_large.png +++ b/app/assets/images/icon_message_delivery-status_large.png diff --git a/app/assets/images/icon_text_html_large.png b/app/assets/images/icon_text_html_large.png Binary files differindex 914502cf4..3813d2582 100644 --- a/app/assets/images/icon_text_html_large.png +++ b/app/assets/images/icon_text_html_large.png diff --git a/app/assets/images/icon_text_plain_large.png b/app/assets/images/icon_text_plain_large.png Binary files differindex f74a997ba..f15b0dbdc 100644 --- a/app/assets/images/icon_text_plain_large.png +++ b/app/assets/images/icon_text_plain_large.png diff --git a/app/assets/images/icon_text_x-vcard_large.png b/app/assets/images/icon_text_x-vcard_large.png Binary files differindex cc44d3edc..804066af8 100644 --- a/app/assets/images/icon_text_x-vcard_large.png +++ b/app/assets/images/icon_text_x-vcard_large.png diff --git a/app/assets/images/icon_unknown.png b/app/assets/images/icon_unknown.png Binary files differindex 992c646c0..9a06d9baa 100644 --- a/app/assets/images/icon_unknown.png +++ b/app/assets/images/icon_unknown.png diff --git a/app/assets/images/widget-base.png b/app/assets/images/widget-base.png Binary files differnew file mode 100644 index 000000000..872244543 --- /dev/null +++ b/app/assets/images/widget-base.png diff --git a/app/assets/javascripts/general.js b/app/assets/javascripts/general.js index 002eef760..639a6917b 100644 --- a/app/assets/javascripts/general.js +++ b/app/assets/javascripts/general.js @@ -34,12 +34,12 @@ $(document).ready(function() { box.width(location.length + " em"); box.find('input').val(location).attr('size', location.length + " em"); box.show(); - box.find('input').select(); box.position({ my: "right center", at: "left bottom", of: this, collision: "fit" }); + box.find('input').select(); return false; }); @@ -57,4 +57,12 @@ $(document).ready(function() { $('#everypage').hide(); } + // "Create widget" page + $("#widgetbox").select() + // Chrome workaround + $("widgetbox").mouseup(function() { + // Prevent further mouseup intervention + $this.unbind("mouseup"); + return false; + }); }) diff --git a/app/assets/stylesheets/responsive/_global_layout.scss b/app/assets/stylesheets/responsive/_global_layout.scss index d7b24df41..b34a6af74 100644 --- a/app/assets/stylesheets/responsive/_global_layout.scss +++ b/app/assets/stylesheets/responsive/_global_layout.scss @@ -98,3 +98,10 @@ textarea{ padding-right: 0.9375em; } } +.box { + padding: 1em; + + @include respond-min( $main_menu-mobile_menu_cutoff ){ + padding: 1.2em; + } +} diff --git a/app/assets/stylesheets/responsive/_global_style.scss b/app/assets/stylesheets/responsive/_global_style.scss index 24cddc0d9..27d238962 100644 --- a/app/assets/stylesheets/responsive/_global_style.scss +++ b/app/assets/stylesheets/responsive/_global_style.scss @@ -84,9 +84,6 @@ dd { dt + dd { margin-top: 0.5em; - > p { - margin-top: 0; - } } diff --git a/app/assets/stylesheets/responsive/_header_layout.scss b/app/assets/stylesheets/responsive/_header_layout.scss index b3103e3a9..7c7bdfe97 100644 --- a/app/assets/stylesheets/responsive/_header_layout.scss +++ b/app/assets/stylesheets/responsive/_header_layout.scss @@ -131,25 +131,25 @@ } form{ @include grid-row; - padding-right: 1em; + padding: 1em 1em 0; @include lte-ie7 { display: inline; } + @include respond-min( $main_menu-mobile_menu_cutoff ){ + padding-top: 0; + } } input{ - @include grid-column($columns:9); - margin:0; + @include grid-column($columns:10); + margin-right:0; @include lte-ie7 { width: 10.063em; } } - label{ + button[type="submit"]{ @include prefix-postfix-base; - @include grid-column($columns:3,$float:left); + @include grid-column($columns:2,$float:right); border:none; - img{ - max-width: 100%; - } @include lte-ie7 { width: 2.125em; } diff --git a/app/assets/stylesheets/responsive/_header_style.scss b/app/assets/stylesheets/responsive/_header_style.scss index 9008a73a7..ec1e8ea5c 100644 --- a/app/assets/stylesheets/responsive/_header_style.scss +++ b/app/assets/stylesheets/responsive/_header_style.scss @@ -2,3 +2,9 @@ #navigation { border-bottom: 1px solid #e9e9e9; } + +#navigation_search { + button[type="submit"] { + background:image-url('/assets/search.png') transparent no-repeat center center; + } +} diff --git a/app/assets/stylesheets/responsive/_request_style.scss b/app/assets/stylesheets/responsive/_request_style.scss index e6f36674a..44ca9a288 100644 --- a/app/assets/stylesheets/responsive/_request_style.scss +++ b/app/assets/stylesheets/responsive/_request_style.scss @@ -3,12 +3,9 @@ div.correspondence { border: 1px solid #ccc; margin: 0 0 1em; - padding: 1em; - @include respond-min( $main_menu-mobile_menu_cutoff ){ - padding: 1.5em; - } h2 { + margin-top: 0; text-align:right; font-size:1em; } @@ -31,7 +28,6 @@ div.correspondence { div.comment_in_request { border: 1px dotted #ccc; margin:0 0 1em 3em; - padding:0 0.5em; h2 { font-size:1em; @@ -42,13 +38,9 @@ div.comment_in_request { } .event_actions { + margin-bottom: 0; text-align:right; line-height: 1em; - margin-bottom: 1em; -} - -.comment_in_request_text { - margin:0 1.2em 0 0.9em; } .user_photo_on_request img { @@ -64,7 +56,6 @@ div.comment_in_request { height:36px; float:left; vertical-align:middle; - margin-top: 0.5em; margin-right:0.5em; } @@ -86,11 +77,9 @@ a img.attachment_image { } .describe_state_form,#other_recipients { - border-radius:3px; -moz-border-radius:3px; margin:1em 0; - padding:0.5em 1em; } .describe_state_form { diff --git a/app/assets/stylesheets/responsive/_utils.scss b/app/assets/stylesheets/responsive/_utils.scss index 68884fa7a..e19201475 100644 --- a/app/assets/stylesheets/responsive/_utils.scss +++ b/app/assets/stylesheets/responsive/_utils.scss @@ -33,3 +33,18 @@ $lte-ie7: false !default; @content; } } + +// Hide content visually, but keep it available to screen readers +// source: http://a11yproject.com/posts/how-to-hide-content/ +.visually-hidden { + // http://developer.yahoo.com/blogs/ydn/posts/2012/10/clip-your-hidden-content-for-better-accessibility/ + position: absolute !important; + clip: rect(1px 1px 1px 1px); /* IE6, IE7 */ + clip: rect(1px, 1px, 1px, 1px); + padding:0 !important; + border:0 !important; + height: 1px !important; + width: 1px !important; + overflow: hidden; +} +body:hover .visually-hidden a, body:hover .visually-hidden input, body:hover .visually-hidden button { display: none !important; } diff --git a/app/assets/stylesheets/widget.scss b/app/assets/stylesheets/widget.scss new file mode 100644 index 000000000..a67e1f3f0 --- /dev/null +++ b/app/assets/stylesheets/widget.scss @@ -0,0 +1,109 @@ +/* CSS Mini Reset */ + +html, body, div, form, fieldset, legend, label +{ + margin: 0; + padding: 0; +} + +table +{ + border-collapse: collapse; + border-spacing: 0; +} + +th, td +{ + text-align: left; + vertical-align: top; +} + +h1, h2, h3, h4, h5, h6, th, td, caption { font-weight:normal; } + +img { border: 0; } + +body { + background-color: #ffffff; + color: #333333; + padding: 0; + margin: 0; + font-family: "Helvetica Neue", Arial, Helvetica, Helmet, Freesans, sans-serif; + font-weight: normal; + font-style: normal; + line-height: 1.5em; + position: relative; + cursor: default; + font-size: 1em; +} + +a:hover, +a:focus, +a:active { + color: #333; +} + +.alaveteli-widget { + width: 318px; + height: 213px; + border: 1px solid #e9e9e9; + background: #e9e9e9 url("widget-base.png") top left no-repeat; + position: relative; + border: 1px solid #eee; +} + +.alaveteli-widget__title { + position: absolute; + top: 1em; + left: 16px; + width: 160px; + height: 75px; + overflow: hidden; +} + +.alaveteli-widget__status { + position: absolute; + top: 97px; + left: 16px; + font-weight: bold; + text-transform: uppercase; +} + +.alaveteli-widget__status__status-label { + margin: 0; + font-weight: normal; + font-size: 0.875em; + line-height: 1.1em; + color: #555; + text-transform: capitalize; +} + +.alaveteli-widget__left { + position: absolute; + width: 145px; +} + +.alaveteli-widget__people-count { + position: absolute; + left: 192px; + top: 44px; + width: 100px; + text-align: center; + line-height: 1.3em; +} +.alaveteli-widget__count { + font-size: 55px; + line-height: 55px; + text-align: center; +} + +.alaveteli-widget__bottom a { + text-decoration: none; +} + +.alaveteli-widget__button { + position: absolute; + top: 173px; + left: 16px; + text-align: center; +} + diff --git a/app/controllers/admin_censor_rule_controller.rb b/app/controllers/admin_censor_rule_controller.rb index 3387fd832..6c060a610 100644 --- a/app/controllers/admin_censor_rule_controller.rb +++ b/app/controllers/admin_censor_rule_controller.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # app/controllers/admin_censor_rule_controller.rb: # For modifying requests. # diff --git a/app/controllers/admin_comment_controller.rb b/app/controllers/admin_comment_controller.rb index 0aafb122a..030afb645 100644 --- a/app/controllers/admin_comment_controller.rb +++ b/app/controllers/admin_comment_controller.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # app/controllers/admin_comment_controller.rb: # Controller for editing comments from the admin interface. # @@ -15,12 +16,12 @@ class AdminCommentController < AdminController old_body = @comment.body old_visible = @comment.visible - @comment.visible = params[:comment][:visible] == "true" ? true : false + @comment.visible = params[:comment][:visible] == "true" if @comment.update_attributes(params[:comment]) @comment.info_request.log_event("edit_comment", { :comment_id => @comment.id, - :editor => admin_current_user(), + :editor => admin_current_user, :old_body => old_body, :body => @comment.body, :old_visible => old_visible, diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index 7760c372b..400047215 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # controllers/admin.rb: # All admin controllers are dervied from this. # diff --git a/app/controllers/admin_general_controller.rb b/app/controllers/admin_general_controller.rb index f2414eeab..8efe0c7b9 100644 --- a/app/controllers/admin_general_controller.rb +++ b/app/controllers/admin_general_controller.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # app/controllers/admin_controller.rb: # Controller for main admin pages. # @@ -7,29 +8,29 @@ class AdminGeneralController < AdminController def index - # Overview counts of things - @public_body_count = PublicBody.count - - @info_request_count = InfoRequest.count - @outgoing_message_count = OutgoingMessage.count - @incoming_message_count = IncomingMessage.count - - @user_count = User.count - @track_thing_count = TrackThing.count - - @comment_count = Comment.count - # Tasks to do @requires_admin_requests = InfoRequest.find_in_state('requires_admin') @error_message_requests = InfoRequest.find_in_state('error_message') @attention_requests = InfoRequest.find_in_state('attention_requested') - @blank_contacts = PublicBody.find(:all, :conditions => ["request_email = ''"], - :order => "updated_at") + @blank_contacts = PublicBody. + includes(:tags, :translations). + where(:request_email => ""). + order(:updated_at). + select { |pb| !pb.defunct? } @old_unclassified = InfoRequest.find_old_unclassified(:limit => 20, :conditions => ["prominence = 'normal'"]) - @holding_pen_messages = InfoRequest.holding_pen_request.incoming_messages - @new_body_requests = PublicBodyChangeRequest.new_body_requests.open - @body_update_requests = PublicBodyChangeRequest.body_update_requests.open + @holding_pen_messages = InfoRequest. + includes(:incoming_messages => :raw_email). + holding_pen_request. + incoming_messages + @new_body_requests = PublicBodyChangeRequest. + includes(:public_body, :user). + new_body_requests. + open + @body_update_requests = PublicBodyChangeRequest. + includes(:public_body, :user). + body_update_requests. + open end def timeline diff --git a/app/controllers/admin_holiday_imports_controller.rb b/app/controllers/admin_holiday_imports_controller.rb index 8596936f0..a740caa2b 100644 --- a/app/controllers/admin_holiday_imports_controller.rb +++ b/app/controllers/admin_holiday_imports_controller.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AdminHolidayImportsController < AdminController def new diff --git a/app/controllers/admin_holidays_controller.rb b/app/controllers/admin_holidays_controller.rb index 9177ebd44..cd93a21b6 100644 --- a/app/controllers/admin_holidays_controller.rb +++ b/app/controllers/admin_holidays_controller.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AdminHolidaysController < AdminController def index diff --git a/app/controllers/admin_incoming_message_controller.rb b/app/controllers/admin_incoming_message_controller.rb index bc653bf53..db7bed34c 100644 --- a/app/controllers/admin_incoming_message_controller.rb +++ b/app/controllers/admin_incoming_message_controller.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AdminIncomingMessageController < AdminController def edit @@ -13,7 +14,7 @@ class AdminIncomingMessageController < AdminController if @incoming_message.save @incoming_message.info_request.log_event('edit_incoming', :incoming_message_id => @incoming_message.id, - :editor => admin_current_user(), + :editor => admin_current_user, :old_prominence => old_prominence, :prominence => @incoming_message.prominence, :old_prominence_reason => old_prominence_reason, @@ -33,7 +34,7 @@ class AdminIncomingMessageController < AdminController @incoming_message.fully_destroy @incoming_message.info_request.log_event("destroy_incoming", - { :editor => admin_current_user(), :deleted_incoming_message_id => incoming_message_id }) + { :editor => admin_current_user, :deleted_incoming_message_id => incoming_message_id }) # expire cached files expire_for_request(@info_request) flash[:notice] = 'Incoming message successfully destroyed.' @@ -63,7 +64,7 @@ class AdminIncomingMessageController < AdminController incoming_message_id = incoming_message.id incoming_message.info_request.log_event("redeliver_incoming", { - :editor => admin_current_user(), + :editor => admin_current_user, :destination_request => destination_request.id, :deleted_incoming_message_id => incoming_message_id }) diff --git a/app/controllers/admin_info_request_event_controller.rb b/app/controllers/admin_info_request_event_controller.rb index 17d147582..6862ff116 100644 --- a/app/controllers/admin_info_request_event_controller.rb +++ b/app/controllers/admin_info_request_event_controller.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # app/controllers/admin_info_request_event_controller.rb: # Controller for FOI request event manipulation from the admin interface. # diff --git a/app/controllers/admin_outgoing_message_controller.rb b/app/controllers/admin_outgoing_message_controller.rb index 2ee811dc0..56e27b108 100644 --- a/app/controllers/admin_outgoing_message_controller.rb +++ b/app/controllers/admin_outgoing_message_controller.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AdminOutgoingMessageController < AdminController def edit @@ -11,7 +12,7 @@ class AdminOutgoingMessageController < AdminController @outgoing_message.fully_destroy @outgoing_message.info_request.log_event("destroy_outgoing", - { :editor => admin_current_user(), :deleted_outgoing_message_id => outgoing_message_id }) + { :editor => admin_current_user, :deleted_outgoing_message_id => outgoing_message_id }) flash[:notice] = 'Outgoing message successfully destroyed.' redirect_to admin_request_url(@info_request) @@ -29,7 +30,7 @@ class AdminOutgoingMessageController < AdminController if @outgoing_message.save @outgoing_message.info_request.log_event("edit_outgoing", { :outgoing_message_id => @outgoing_message.id, - :editor => admin_current_user(), + :editor => admin_current_user, :old_body => old_body, :body => @outgoing_message.body, :old_prominence => old_prominence, diff --git a/app/controllers/admin_public_body_categories_controller.rb b/app/controllers/admin_public_body_categories_controller.rb index a86171c76..e365255f8 100644 --- a/app/controllers/admin_public_body_categories_controller.rb +++ b/app/controllers/admin_public_body_categories_controller.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AdminPublicBodyCategoriesController < AdminController def index @locale = self.locale_from_params diff --git a/app/controllers/admin_public_body_change_requests_controller.rb b/app/controllers/admin_public_body_change_requests_controller.rb index 6ff03a2bd..be632b6cd 100644 --- a/app/controllers/admin_public_body_change_requests_controller.rb +++ b/app/controllers/admin_public_body_change_requests_controller.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AdminPublicBodyChangeRequestsController < AdminController def edit diff --git a/app/controllers/admin_public_body_controller.rb b/app/controllers/admin_public_body_controller.rb index 7de27121a..b3c2c1dfd 100644 --- a/app/controllers/admin_public_body_controller.rb +++ b/app/controllers/admin_public_body_controller.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # app/controllers/admin_public_body_controller.rb: # Controller for editing public bodies from the admin interface. # @@ -11,7 +12,7 @@ class AdminPublicBodyController < AdminController end def show - @locale = self.locale_from_params() + @locale = locale_from_params I18n.with_locale(@locale) do @public_body = PublicBody.find(params[:id]) @info_requests = @public_body.info_requests.paginate :order => "created_at desc", @@ -43,7 +44,7 @@ class AdminPublicBodyController < AdminController if params[:change_request_id] @change_request = PublicBodyChangeRequest.find(params[:change_request_id]) end - params[:public_body][:last_edit_editor] = admin_current_user() + params[:public_body][:last_edit_editor] = admin_current_user @public_body = PublicBody.new(params[:public_body]) if @public_body.save if @change_request @@ -84,7 +85,7 @@ class AdminPublicBodyController < AdminController @change_request = PublicBodyChangeRequest.find(params[:change_request_id]) end I18n.with_locale(I18n.default_locale) do - params[:public_body][:last_edit_editor] = admin_current_user() + params[:public_body][:last_edit_editor] = admin_current_user @public_body = PublicBody.find(params[:id]) if @public_body.update_attributes(params[:public_body]) if @change_request @@ -101,7 +102,7 @@ class AdminPublicBodyController < AdminController end def destroy - @locale = self.locale_from_params() + @locale = locale_from_params I18n.with_locale(@locale) do public_body = PublicBody.find(params[:id]) @@ -158,7 +159,7 @@ class AdminPublicBodyController < AdminController @notes = "" @errors = "" if request.post? - dry_run_only = (params['commit'] == 'Upload' ? false : true) + dry_run_only = params['commit'] != 'Upload' # (FIXME: both of these cases could now be changed to use # PublicBody.import_csv_from_file.) # Read file from params @@ -177,7 +178,7 @@ class AdminPublicBodyController < AdminController params[:tag], params[:tag_behaviour], true, - admin_current_user(), + admin_current_user, I18n.available_locales) if errors.size == 0 @@ -191,7 +192,7 @@ class AdminPublicBodyController < AdminController params[:tag], params[:tag_behaviour], false, - admin_current_user(), + admin_current_user, I18n.available_locales) if errors.size != 0 raise "dry run mismatched real run" @@ -234,7 +235,7 @@ class AdminPublicBodyController < AdminController end def lookup_query - @locale = self.locale_from_params() + @locale = locale_from_params underscore_locale = @locale.gsub '-', '_' I18n.with_locale(@locale) do @query = params[:query] diff --git a/app/controllers/admin_public_body_headings_controller.rb b/app/controllers/admin_public_body_headings_controller.rb index a7fe27390..f0568510a 100644 --- a/app/controllers/admin_public_body_headings_controller.rb +++ b/app/controllers/admin_public_body_headings_controller.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AdminPublicBodyHeadingsController < AdminController def new @@ -84,7 +85,7 @@ class AdminPublicBodyHeadingsController < AdminController end end end - { :success => error.nil? ? true : false, :error => error } + { :success => error.nil?, :error => error } end def reorder_categories_for_heading(heading_id, categories) @@ -105,7 +106,7 @@ class AdminPublicBodyHeadingsController < AdminController end end end - { :success => error.nil? ? true : false, :error => error } + { :success => error.nil?, :error => error } end end diff --git a/app/controllers/admin_raw_email_controller.rb b/app/controllers/admin_raw_email_controller.rb index 1b3ee2871..7a802d914 100644 --- a/app/controllers/admin_raw_email_controller.rb +++ b/app/controllers/admin_raw_email_controller.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # app/controllers/admin_raw_email_controller.rb: # Controller for managing raw emails from the admin interface. # diff --git a/app/controllers/admin_request_controller.rb b/app/controllers/admin_request_controller.rb index 1e083f57e..eaf6c337d 100644 --- a/app/controllers/admin_request_controller.rb +++ b/app/controllers/admin_request_controller.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # app/controllers/admin_request_controller.rb: # Controller for viewing FOI requests from the admin interface. # @@ -47,16 +48,16 @@ class AdminRequestController < AdminController @info_request.title = params[:info_request][:title] @info_request.prominence = params[:info_request][:prominence] - @info_request.awaiting_description = params[:info_request][:awaiting_description] == "true" ? true : false + @info_request.awaiting_description = params[:info_request][:awaiting_description] == "true" @info_request.allow_new_responses_from = params[:info_request][:allow_new_responses_from] @info_request.handle_rejected_responses = params[:info_request][:handle_rejected_responses] @info_request.tag_string = params[:info_request][:tag_string] - @info_request.comments_allowed = params[:info_request][:comments_allowed] == "true" ? true : false + @info_request.comments_allowed = params[:info_request][:comments_allowed] == "true" if @info_request.valid? @info_request.save! @info_request.log_event("edit", - { :editor => admin_current_user(), + { :editor => admin_current_user, :old_title => old_title, :title => @info_request.title, :old_prominence => old_prominence, :prominence => @info_request.prominence, :old_described_state => old_described_state, :described_state => params[:info_request][:described_state], @@ -104,7 +105,7 @@ class AdminRequestController < AdminController info_request.user = destination_user info_request.save! info_request.log_event("move_request", { - :editor => admin_current_user(), + :editor => admin_current_user, :old_user_url_name => old_user.url_name, :user_url_name => destination_user.url_name }) @@ -114,21 +115,14 @@ class AdminRequestController < AdminController end redirect_to admin_request_url(info_request) elsif params[:commit] == 'Move request to authority' && !params[:public_body_url_name].blank? - old_public_body = info_request.public_body destination_public_body = PublicBody.find_by_url_name(params[:public_body_url_name]) - if destination_public_body.nil? - flash[:error] = "Couldn't find public body '" + params[:public_body_url_name] + "'" - else - info_request.public_body = destination_public_body - info_request.save! - info_request.log_event("move_request", { - :editor => admin_current_user(), - :old_public_body_url_name => old_public_body.url_name, - :public_body_url_name => destination_public_body.url_name - }) - info_request.reindex_request_events - flash[:notice] = "Request has been moved to new body" + if info_request.move_to_public_body(destination_public_body, + :editor => admin_current_user, + :reindex => true) + flash[:notice] = "Request has been moved to new body" + else + flash[:error] = "Couldn't find public body '#{ params[:public_body_url_name] }'" end redirect_to admin_request_url(info_request) @@ -182,7 +176,7 @@ class AdminRequestController < AdminController info_request.prominence = "requester_only" info_request.log_event("hide", { - :editor => admin_current_user(), + :editor => admin_current_user, :reason => params[:reason], :subject => subject, :explanation => explanation diff --git a/app/controllers/admin_spam_addresses_controller.rb b/app/controllers/admin_spam_addresses_controller.rb index fff7e2a4a..d8be52bc7 100644 --- a/app/controllers/admin_spam_addresses_controller.rb +++ b/app/controllers/admin_spam_addresses_controller.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AdminSpamAddressesController < AdminController def index diff --git a/app/controllers/admin_track_controller.rb b/app/controllers/admin_track_controller.rb index 63ee5c12e..e6e5835e6 100644 --- a/app/controllers/admin_track_controller.rb +++ b/app/controllers/admin_track_controller.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # app/controllers/admin_track_controller.rb: # Show email alerts / RSS feeds from admin interface. # diff --git a/app/controllers/admin_user_controller.rb b/app/controllers/admin_user_controller.rb index 7ef461594..8ebc450f6 100644 --- a/app/controllers/admin_user_controller.rb +++ b/app/controllers/admin_user_controller.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # app/controllers/admin_user_controller.rb: # Controller for viewing user accounts from the admin interface. # @@ -85,8 +86,7 @@ class AdminUserController < AdminController end def modify_comment_visibility - @visibility_value = params.key?(:hide_selected) ? false : true - Comment.update_all(["visible=?", @visibility_value], :id => params[:comment_ids]) + Comment.update_all(["visible = ?", !params[:hide_selected]], :id => params[:comment_ids]) redirect_to :back end diff --git a/app/controllers/api_controller.rb b/app/controllers/api_controller.rb index 6f83d89d6..3b8991f28 100644 --- a/app/controllers/api_controller.rb +++ b/app/controllers/api_controller.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class ApiController < ApplicationController before_filter :check_api_key before_filter :check_external_request, @@ -41,7 +42,7 @@ class ApiController < ApplicationController :status => 'ready', :message_type => 'initial_request', :body => json["body"], - :last_sent_at => Time.now(), + :last_sent_at => Time.now, :what_doing => 'normal_sort', :info_request => request ) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index e80c6a823..a76e6630a 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# -*- encoding : utf-8 -*- # controllers/application.rb: # Parent class of all controllers in FOI site. Filters added to this controller # apply to all controllers in the application. Likewise, all the methods added @@ -206,7 +206,7 @@ class ApplicationController < ActionController::Base def foi_fragment_cache_part_path(param) path = url_for(param) id = param['id'] || param[:id] - first_three_digits = id.to_s()[0..2] + first_three_digits = id.to_s[0..2] path = path.sub("/request/", "/request/" + first_three_digits + "/") return path end diff --git a/app/controllers/comment_controller.rb b/app/controllers/comment_controller.rb index 890e9faaa..b5c438c95 100644 --- a/app/controllers/comment_controller.rb +++ b/app/controllers/comment_controller.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # app/controllers/comment_controller.rb: # Show annotations upon a request or other object. # diff --git a/app/controllers/general_controller.rb b/app/controllers/general_controller.rb index 380da285e..53288c2f4 100644 --- a/app/controllers/general_controller.rb +++ b/app/controllers/general_controller.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # app/controllers/general_controller.rb: # For pages like front page, general search, that aren't specific to a # particular model. @@ -14,7 +15,7 @@ class GeneralController < ApplicationController # New, improved front page! def frontpage medium_cache - @locale = self.locale_from_params() + @locale = locale_from_params successful_query = InfoRequestEvent.make_query_from_params( :latest_status => ['successful'] ) @track_thing = TrackThing.create_track_for_search_query(successful_query) @feed_autodetect = [ { :url => do_track_url(@track_thing, 'feed'), @@ -32,7 +33,7 @@ class GeneralController < ApplicationController @feed_autodetect = [] @feed_url = AlaveteliConfiguration::blog_feed separator = @feed_url.include?('?') ? '&' : '?' - @feed_url = "#{@feed_url}#{separator}lang=#{self.locale_from_params()}" + @feed_url = "#{@feed_url}#{separator}lang=#{locale_from_params}" @blog_items = [] if not @feed_url.empty? content = quietly_try_to_open(@feed_url) diff --git a/app/controllers/health_checks_controller.rb b/app/controllers/health_checks_controller.rb index 473a1aacc..122a02193 100644 --- a/app/controllers/health_checks_controller.rb +++ b/app/controllers/health_checks_controller.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class HealthChecksController < ApplicationController def index diff --git a/app/controllers/help_controller.rb b/app/controllers/help_controller.rb index 93215ccad..cfe1b6ad5 100644 --- a/app/controllers/help_controller.rb +++ b/app/controllers/help_controller.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # app/controllers/help_controller.rb: # Show information about one particular request. # diff --git a/app/controllers/holiday_controller.rb b/app/controllers/holiday_controller.rb index efc20701d..422612fc7 100644 --- a/app/controllers/holiday_controller.rb +++ b/app/controllers/holiday_controller.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # app/controllers/holiday_controller.rb: # Calculate dates # diff --git a/app/controllers/info_request_batch_controller.rb b/app/controllers/info_request_batch_controller.rb index b66658757..e1b684f30 100644 --- a/app/controllers/info_request_batch_controller.rb +++ b/app/controllers/info_request_batch_controller.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class InfoRequestBatchController < ApplicationController def show diff --git a/app/controllers/public_body_change_requests_controller.rb b/app/controllers/public_body_change_requests_controller.rb index 773308546..d43f9398a 100644 --- a/app/controllers/public_body_change_requests_controller.rb +++ b/app/controllers/public_body_change_requests_controller.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class PublicBodyChangeRequestsController < ApplicationController before_filter :catch_spam, :only => [:create] diff --git a/app/controllers/public_body_controller.rb b/app/controllers/public_body_controller.rb index 854e79a19..1b01dc837 100644 --- a/app/controllers/public_body_controller.rb +++ b/app/controllers/public_body_controller.rb @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# -*- encoding : utf-8 -*- # app/controllers/public_body_controller.rb: # Show information about a public body. # @@ -24,7 +24,7 @@ class PublicBodyController < ApplicationController redirect_to :url_name => MySociety::Format.simplify_url_part(params[:url_name], 'body'), :status => :moved_permanently return end - @locale = self.locale_from_params() + @locale = locale_from_params I18n.with_locale(@locale) do @public_body = PublicBody.find_by_url_name_with_historic(params[:url_name]) raise ActiveRecord::RecordNotFound.new("None found") if @public_body.nil? @@ -40,6 +40,8 @@ class PublicBodyController < ApplicationController set_last_body(@public_body) + @number_of_visible_requests = @public_body.info_requests.visible.count + top_url = frontpage_url @searched_to_send_request = false referrer = request.env['HTTP_REFERER'] @@ -83,7 +85,7 @@ class PublicBodyController < ApplicationController @public_body = PublicBody.find_by_url_name_with_historic(params[:url_name]) raise ActiveRecord::RecordNotFound.new("None found") if @public_body.nil? - I18n.with_locale(self.locale_from_params()) do + I18n.with_locale(locale_from_params) do if params[:submitted_view_email] if verify_recaptcha flash.discard(:error) @@ -106,7 +108,7 @@ class PublicBodyController < ApplicationController @tag = params[:tag] - @locale = self.locale_from_params + @locale = locale_from_params underscore_locale = @locale.gsub '-', '_' underscore_default_locale = I18n.default_locale.to_s.gsub '-', '_' diff --git a/app/controllers/reports_controller.rb b/app/controllers/reports_controller.rb index a1dd53125..83474ad65 100644 --- a/app/controllers/reports_controller.rb +++ b/app/controllers/reports_controller.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class ReportsController < ApplicationController def create @info_request = InfoRequest.find_by_url_title!(params[:request_id]) diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb index e847cae1e..45229fd7e 100644 --- a/app/controllers/request_controller.rb +++ b/app/controllers/request_controller.rb @@ -1,4 +1,4 @@ -# encoding: UTF-8 +# -*- encoding : utf-8 -*- # app/controllers/request_controller.rb: # Show information about one particular request. # @@ -75,7 +75,7 @@ class RequestController < ApplicationController else medium_cache end - @locale = self.locale_from_params() + @locale = locale_from_params I18n.with_locale(@locale) do # Look up by old style numeric identifiers @@ -96,12 +96,12 @@ class RequestController < ApplicationController set_last_request(@info_request) # assign variables from request parameters - @collapse_quotes = params[:unfold] ? false : true + @collapse_quotes = !params[:unfold] # Don't allow status update on external requests, otherwise accept param if @info_request.is_external? @update_status = false else - @update_status = params[:update_status] ? true : false + @update_status = params[:update_status] end assign_variables_for_show_template(@info_request) @@ -164,7 +164,7 @@ class RequestController < ApplicationController def list medium_cache @view = params[:view] - @locale = self.locale_from_params() + @locale = locale_from_params @page = get_search_page_from_params if !@page # used in cache case, as perform_search sets @page as side effect @per_page = PER_PAGE @max_results = MAX_RESULTS @@ -566,9 +566,9 @@ class RequestController < ApplicationController @info_request = InfoRequest.find(params[:id].to_i) set_last_request(@info_request) - @collapse_quotes = params[:unfold] ? false : true + @collapse_quotes = !params[:unfold] @is_owning_user = @info_request.is_owning_user?(authenticated_user) - @gone_postal = params[:gone_postal] ? true : false + @gone_postal = params[:gone_postal] if !@is_owning_user @gone_postal = false end @@ -848,7 +848,7 @@ class RequestController < ApplicationController # FOI officers can upload a response def upload_response - @locale = self.locale_from_params() + @locale = locale_from_params I18n.with_locale(@locale) do @info_request = InfoRequest.find_by_url_title!(params[:url_title]) @@ -914,7 +914,7 @@ class RequestController < ApplicationController end def download_entire_request - @locale = self.locale_from_params() + @locale = locale_from_params I18n.with_locale(@locale) do @info_request = InfoRequest.find_by_url_title!(params[:url_title]) if authenticated?( diff --git a/app/controllers/request_game_controller.rb b/app/controllers/request_game_controller.rb index 7eadc1204..2915b5c2f 100644 --- a/app/controllers/request_game_controller.rb +++ b/app/controllers/request_game_controller.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # app/controllers/request_game_controller.rb: # The 'categorise old requests' game # @@ -22,7 +23,7 @@ class RequestGameController < ApplicationController :site_name => site_name) end - @league_table_28_days = RequestClassification.league_table(10, [ "created_at >= ?", Time.now() - 28.days ]) + @league_table_28_days = RequestClassification.league_table(10, [ "created_at >= ?", Time.now - 28.days ]) @league_table_all_time = RequestClassification.league_table(10) @play_urls = true end diff --git a/app/controllers/services_controller.rb b/app/controllers/services_controller.rb index 9b3a3396f..4d06072df 100644 --- a/app/controllers/services_controller.rb +++ b/app/controllers/services_controller.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # controllers/services_controller.rb: require 'open-uri' diff --git a/app/controllers/track_controller.rb b/app/controllers/track_controller.rb index 4b272797f..cbefb6291 100644 --- a/app/controllers/track_controller.rb +++ b/app/controllers/track_controller.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # app/controllers/track_controller.rb: # Publically visible email alerts and RSS - think an alert system crossed with # social bookmarking. @@ -214,6 +215,4 @@ class TrackController < ApplicationController redirect_to URI.parse(params[:r]).path end - end - diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb index d66b4aa8e..bb4ba28d1 100644 --- a/app/controllers/user_controller.rb +++ b/app/controllers/user_controller.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # app/controllers/user_controller.rb: # Show information about a user. # @@ -176,7 +177,7 @@ class UserController < ApplicationController return else if !@post_redirect.nil? - @user_signin = User.authenticate_from_form(params[:user_signin], @post_redirect.reason_params[:user_name] ? true : false) + @user_signin = User.authenticate_from_form(params[:user_signin], @post_redirect.reason_params[:user_name]) end if @post_redirect.nil? || @user_signin.errors.size > 0 # Failed to authenticate @@ -372,7 +373,7 @@ class UserController < ApplicationController if (not session[:user_circumstance]) or (session[:user_circumstance] != "change_email") # don't store the password in the db params[:signchangeemail].delete(:password) - post_redirect = PostRedirect.new(:uri => signchangeemail_url(), + post_redirect = PostRedirect.new(:uri => signchangeemail_url, :post_params => params, :circumstance => "change_email" # special login that lets you change your email ) @@ -509,7 +510,7 @@ class UserController < ApplicationController else flash[:notice] = _("<p>Thanks for updating your profile photo.</p> <p><strong>Next...</strong> You can put some text about you and your research on your profile.</p>") - redirect_to set_profile_about_me_url() + redirect_to set_profile_about_me_url end else render :template => 'user/set_draft_profile_photo' @@ -595,7 +596,7 @@ class UserController < ApplicationController else flash[:notice] = _("<p>Thanks for changing the text about you on your profile.</p> <p><strong>Next...</strong> You can upload a profile photograph too.</p>") - redirect_to set_profile_photo_url() + redirect_to set_profile_photo_url end end diff --git a/app/controllers/widgets_controller.rb b/app/controllers/widgets_controller.rb new file mode 100644 index 000000000..333a38e86 --- /dev/null +++ b/app/controllers/widgets_controller.rb @@ -0,0 +1,64 @@ +# -*- encoding : utf-8 -*- +# app/controllers/widget_controller.rb: +# Handle widgets, if enabled +# +# Copyright (c) 2014 UK Citizens Online Democracy. All rights reserved. +# Email: hello@mysociety.org; WWW: http://www.mysociety.org/ + +require 'securerandom' + +class WidgetsController < ApplicationController + + before_filter :check_widget_config, :find_info_request, :check_prominence + skip_before_filter :set_x_frame_options_header, :only => [:show] + + def show + medium_cache + @track_thing = TrackThing.create_track_for_request(@info_request) + @status = @info_request.calculate_status + @count = @info_request.track_things.count + @info_request.widget_votes.count + 1 + + if @user + @existing_track = TrackThing.find_existing(@user, @track_thing) + end + unless @user || cookies[:widget_vote] + cookies.permanent[:widget_vote] = SecureRandom.hex(10) + end + render :action => 'show', :layout => false + end + + def new + long_cache + end + + # Track interest in a request from a non-logged in user + def update + if !@user && cookies[:widget_vote] + @info_request.widget_votes. + where(:cookie => cookies[:widget_vote]). + first_or_create + end + + track_thing = TrackThing.create_track_for_request(@info_request) + redirect_to do_track_path(track_thing), status => :temporary_redirect + end + + private + + def find_info_request + @info_request = InfoRequest.find(params[:request_id]) + end + + def check_widget_config + unless AlaveteliConfiguration::enable_widgets + raise ActiveRecord::RecordNotFound.new("Page not enabled") + end + end + + def check_prominence + unless @info_request.prominence == 'normal' + render :nothing => true, :status => :forbidden + end + end + +end diff --git a/app/helpers/admin_helper.rb b/app/helpers/admin_helper.rb index d13fea79b..9d63b1cad 100644 --- a/app/helpers/admin_helper.rb +++ b/app/helpers/admin_helper.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- module AdminHelper def icon(name) content_tag(:i, "", :class => "icon-#{name}") diff --git a/app/helpers/admin_public_body_category_helper.rb b/app/helpers/admin_public_body_category_helper.rb index 9c5e5cc5e..2d8842562 100644 --- a/app/helpers/admin_public_body_category_helper.rb +++ b/app/helpers/admin_public_body_category_helper.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- module AdminPublicBodyCategoryHelper def heading_is_selected?(heading) if params[:headings] diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 49ce94951..2f51f5684 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # app/helpers/application_helper.rb: # Methods added to this helper will be available to all views (i.e. templates) # in the application. diff --git a/app/helpers/config_helper.rb b/app/helpers/config_helper.rb index 026600ff1..9953c4fe0 100644 --- a/app/helpers/config_helper.rb +++ b/app/helpers/config_helper.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- module ConfigHelper def site_name AlaveteliConfiguration::site_name diff --git a/app/helpers/date_time_helper.rb b/app/helpers/date_time_helper.rb index 5f129e590..09b5b2a76 100644 --- a/app/helpers/date_time_helper.rb +++ b/app/helpers/date_time_helper.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- module DateTimeHelper # Public: Usually-correct format for a DateTime-ish object # To define a new new format define the `simple_date_{FORMAT}` method diff --git a/app/helpers/health_checks_helper.rb b/app/helpers/health_checks_helper.rb index f5769a9ba..b2f1f9de5 100644 --- a/app/helpers/health_checks_helper.rb +++ b/app/helpers/health_checks_helper.rb @@ -1,7 +1,8 @@ +# -*- encoding : utf-8 -*- module HealthChecksHelper def check_status(check) - style = check.ok? ? {} : "color: red" + style = check.ok? ? '' : 'color: red' content_tag(:b, check.message, :style => style) end diff --git a/app/helpers/link_to_helper.rb b/app/helpers/link_to_helper.rb index 44d6c6f5f..21eb39c0e 100755 --- a/app/helpers/link_to_helper.rb +++ b/app/helpers/link_to_helper.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # app/helpers/link_to_helper.rb: # This module is included into all controllers via controllers/application.rb # - diff --git a/app/helpers/mailer_helper.rb b/app/helpers/mailer_helper.rb index 3d4bbac71..573f7d8a8 100644 --- a/app/helpers/mailer_helper.rb +++ b/app/helpers/mailer_helper.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- module MailerHelper def contact_from_name_and_email "#{AlaveteliConfiguration::contact_name} <#{AlaveteliConfiguration::contact_email}>" diff --git a/app/helpers/public_body_helper.rb b/app/helpers/public_body_helper.rb index 57c90a9ba..e094d98b4 100644 --- a/app/helpers/public_body_helper.rb +++ b/app/helpers/public_body_helper.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- module PublicBodyHelper # Public: The reasons a request can't be made to a PublicBody @@ -40,8 +41,8 @@ module PublicBodyHelper def type_of_authority(public_body) first = true types = public_body.tags.each.map do |tag| - if PublicBodyCategory.get().by_tag().include?(tag.name) - desc = PublicBodyCategory.get().singular_by_tag()[tag.name] + if PublicBodyCategory.get.by_tag.include?(tag.name) + desc = PublicBodyCategory.get.singular_by_tag[tag.name] if first desc = desc.sub(/\S/) { |m| Unicode.upcase(m) } first = false diff --git a/app/helpers/track_helper.rb b/app/helpers/track_helper.rb index ca698926c..75ff784f3 100644 --- a/app/helpers/track_helper.rb +++ b/app/helpers/track_helper.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- module TrackHelper def already_subscribed_notice(track_thing) diff --git a/app/helpers/widget_helper.rb b/app/helpers/widget_helper.rb new file mode 100644 index 000000000..70353ea7c --- /dev/null +++ b/app/helpers/widget_helper.rb @@ -0,0 +1,47 @@ +# -*- encoding : utf-8 -*- +module WidgetHelper + def status_description(info_request, status) + case status + when 'waiting_classification' + _('Awaiting classification') + when 'waiting_response' + _('Awaiting response') + when 'waiting_response_overdue' + _('Delayed') + when 'waiting_response_very_overdue' + _('Long overdue') + when 'not_held' + _('Not held') + when 'rejected' + _('Rejected') + when 'successful' + _('Successful') + when 'partially_successful' + _('Partial success') + when 'waiting_clarification' + _('Awaiting clarification') + when 'gone_postal' + _('Handled by post') + when 'internal_review' + _('Internal review') + when 'error_message' + _('Delivery error') + when 'requires_admin' + _('Unusual response') + when 'user_withdrawn' + _('Withdrawn') + when 'attention_requested' + _('Needs admin attention') + when 'vexatious' + _('Vexatious') + when 'not_foi' + _('Not an FOI request') + else + if info_request.respond_to?(:theme_display_status) + info_request.theme_display_status(status) + else + _('Unknown') + end + end + end +end diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb index d2230bb82..cfa5603fe 100644 --- a/app/mailers/application_mailer.rb +++ b/app/mailers/application_mailer.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # models/application_mailer.rb: # Shared code between different mailers. # diff --git a/app/mailers/contact_mailer.rb b/app/mailers/contact_mailer.rb index 27e04ca4b..7c48bfd4b 100644 --- a/app/mailers/contact_mailer.rb +++ b/app/mailers/contact_mailer.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # models/contact_mailer.rb: # Sends contact form mails. # diff --git a/app/mailers/info_request_batch_mailer.rb b/app/mailers/info_request_batch_mailer.rb index a2becfb24..ba853db95 100644 --- a/app/mailers/info_request_batch_mailer.rb +++ b/app/mailers/info_request_batch_mailer.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # models/info_request_batch_mailer.rb: # Emails relating to user accounts. e.g. Confirming a new account # diff --git a/app/mailers/outgoing_mailer.rb b/app/mailers/outgoing_mailer.rb index 19054b4e2..78041d04b 100644 --- a/app/mailers/outgoing_mailer.rb +++ b/app/mailers/outgoing_mailer.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # models/outgoing_mailer.rb: # Emails which go to public bodies on behalf of users. # @@ -40,7 +41,7 @@ class OutgoingMailer < ApplicationMailer # TODO: also OutgoingMessage.get_salutation # TODO: these look like they should be members of IncomingMessage, but logically they # need to work even when IncomingMessage is nil - def OutgoingMailer.name_and_email_for_followup(info_request, incoming_message_followup) + def self.name_and_email_for_followup(info_request, incoming_message_followup) if incoming_message_followup.nil? || !incoming_message_followup.valid_to_reply_to? return info_request.recipient_name_and_email else @@ -50,7 +51,7 @@ class OutgoingMailer < ApplicationMailer end end # Used in the preview of followup - def OutgoingMailer.name_for_followup(info_request, incoming_message_followup) + def self.name_for_followup(info_request, incoming_message_followup) if incoming_message_followup.nil? || !incoming_message_followup.valid_to_reply_to? return info_request.public_body.name else @@ -59,7 +60,7 @@ class OutgoingMailer < ApplicationMailer end end # Used when making list of followup places to remove duplicates - def OutgoingMailer.email_for_followup(info_request, incoming_message_followup) + def self.email_for_followup(info_request, incoming_message_followup) if incoming_message_followup.nil? || !incoming_message_followup.valid_to_reply_to? return info_request.recipient_email else @@ -67,7 +68,7 @@ class OutgoingMailer < ApplicationMailer end end # Subject to use for followup - def OutgoingMailer.subject_for_followup(info_request, outgoing_message, options = {}) + def self.subject_for_followup(info_request, outgoing_message, options = {}) if outgoing_message.what_doing == 'internal_review' return "Internal review of " + info_request.email_subject_request(:html => options[:html]) else @@ -76,7 +77,7 @@ class OutgoingMailer < ApplicationMailer end end # Whether we have a valid email address for a followup - def OutgoingMailer.is_followupable?(info_request, incoming_message_followup) + def self.is_followupable?(info_request, incoming_message_followup) if incoming_message_followup.nil? || !incoming_message_followup.valid_to_reply_to? return info_request.recipient_email_valid_for_followup? else @@ -85,7 +86,7 @@ class OutgoingMailer < ApplicationMailer end end # Message-ID to use - def OutgoingMailer.id_for_message(outgoing_message) + def self.id_for_message(outgoing_message) message_id = "ogm-" + outgoing_message.id.to_s t = Time.now message_id += "+" + '%08x%05x-%04x' % [t.to_i, t.tv_usec, rand(0xffff)] diff --git a/app/mailers/request_mailer.rb b/app/mailers/request_mailer.rb index 252df861c..f12b4a0d6 100644 --- a/app/mailers/request_mailer.rb +++ b/app/mailers/request_mailer.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # models/request_mailer.rb: # Alerts relating to requests. # @@ -64,7 +65,7 @@ class RequestMailer < ApplicationMailer mail(:from => user.name_and_email, :to => contact_from_name_and_email, - :subject => _("FOI response requires admin ({{reason}}) - {{title}}", :reason => info_request.described_state, :title => info_request.title).html_safe) + :subject => _("FOI response requires admin ({{reason}}) - {{title}}", :reason => info_request.described_state, :title => info_request.title.html_safe)) end # Tell the requester that a new response has arrived @@ -80,7 +81,7 @@ class RequestMailer < ApplicationMailer mail(:from => contact_from_name_and_email, :to => info_request.user.name_and_email, - :subject => (_("New response to your FOI request - ") + info_request.title).html_safe, + :subject => _("New response to your FOI request - ") + info_request.title.html_safe, :charset => "UTF-8", # not much we can do if the user's email is broken :reply_to => contact_from_name_and_email) @@ -99,13 +100,8 @@ class RequestMailer < ApplicationMailer @url = confirm_url(:email_token => post_redirect.email_token) @info_request = info_request - headers('Return-Path' => blackhole_email, 'Reply-To' => contact_from_name_and_email, # not much we can do if the user's email is broken - 'Auto-Submitted' => 'auto-generated', # http://tools.ietf.org/html/rfc3834 - 'X-Auto-Response-Suppress' => 'OOF') - - mail(:from => contact_from_name_and_email, - :to => user.name_and_email, - :subject => (_("Delayed response to your FOI request - ") + info_request.title).html_safe) + auto_generated_headers + mail_user_with_info_request_title(user, _("Delayed response to your FOI request - "), info_request) end # Tell the requester that the public body is very late in replying @@ -119,13 +115,8 @@ class RequestMailer < ApplicationMailer @url = confirm_url(:email_token => post_redirect.email_token) @info_request = info_request - headers('Return-Path' => blackhole_email, 'Reply-To' => contact_from_name_and_email, # not much we can do if the user's email is broken - 'Auto-Submitted' => 'auto-generated', # http://tools.ietf.org/html/rfc3834 - 'X-Auto-Response-Suppress' => 'OOF') - - mail(:from => contact_from_name_and_email, - :to => user.name_and_email, - :subject => (_("You're long overdue a response to your FOI request - ") + info_request.title).html_safe) + auto_generated_headers + mail_user_with_info_request_title(user, _("You're long overdue a response to your FOI request - "), info_request) end # Tell the requester that they need to say if the new response @@ -141,13 +132,8 @@ class RequestMailer < ApplicationMailer @incoming_message = incoming_message @info_request = info_request - headers('Return-Path' => blackhole_email, 'Reply-To' => contact_from_name_and_email, # not much we can do if the user's email is broken - 'Auto-Submitted' => 'auto-generated', # http://tools.ietf.org/html/rfc3834 - 'X-Auto-Response-Suppress' => 'OOF') - - mail(:from => contact_from_name_and_email, - :to => info_request.user.name_and_email, - :subject => _("Was the response you got to your FOI request any good?")) + auto_generated_headers + mail_user(info_request.user, _("Was the response you got to your FOI request any good?")) end # Tell the requester that someone updated their old unclassified request @@ -155,13 +141,8 @@ class RequestMailer < ApplicationMailer @url = request_url(info_request) @info_request = info_request - headers('Return-Path' => blackhole_email, 'Reply-To' => contact_from_name_and_email, # not much we can do if the user's email is broken - 'Auto-Submitted' => 'auto-generated', # http://tools.ietf.org/html/rfc3834 - 'X-Auto-Response-Suppress' => 'OOF') - - mail(:from => contact_from_name_and_email, - :to => info_request.user.name_and_email, - :subject => _("Someone has updated the status of your request")) + auto_generated_headers + mail_user(info_request.user, _("Someone has updated the status of your request")) end # Tell the requester that they need to clarify their request @@ -177,13 +158,8 @@ class RequestMailer < ApplicationMailer @incoming_message = incoming_message @info_request = info_request - headers('Return-Path' => blackhole_email, 'Reply-To' => contact_from_name_and_email, # not much we can do if the user's email is broken - 'Auto-Submitted' => 'auto-generated', # http://tools.ietf.org/html/rfc3834 - 'X-Auto-Response-Suppress' => 'OOF') - - mail(:from => contact_from_name_and_email, - :to => info_request.user.name_and_email, - :subject => (_("Clarify your FOI request - ") + info_request.title).html_safe) + auto_generated_headers + mail_user_with_info_request_title(info_request.user, _("Clarify your FOI request - "), info_request) end # Tell requester that somebody add an annotation to their request @@ -191,25 +167,15 @@ class RequestMailer < ApplicationMailer @comment, @info_request = comment, info_request @url = comment_url(comment) - headers('Return-Path' => blackhole_email, 'Reply-To' => contact_from_name_and_email, # not much we can do if the user's email is broken - 'Auto-Submitted' => 'auto-generated', # http://tools.ietf.org/html/rfc3834 - 'X-Auto-Response-Suppress' => 'OOF') - - mail(:from => contact_from_name_and_email, - :to => info_request.user.name_and_email, - :subject => (_("Somebody added a note to your FOI request - ") + info_request.title).html_safe) + auto_generated_headers + mail_user_with_info_request_title(info_request.user, _("Somebody added a note to your FOI request - "), info_request) end def comment_on_alert_plural(info_request, count, earliest_unalerted_comment) @count, @info_request = count, info_request @url = comment_url(earliest_unalerted_comment) - headers('Return-Path' => blackhole_email, 'Reply-To' => contact_from_name_and_email, # not much we can do if the user's email is broken - 'Auto-Submitted' => 'auto-generated', # http://tools.ietf.org/html/rfc3834 - 'X-Auto-Response-Suppress' => 'OOF') - - mail(:from => contact_from_name_and_email, - :to => info_request.user.name_and_email, - :subject => (_("Some notes have been added to your FOI request - ") + info_request.title).html_safe) + auto_generated_headers + mail_user_with_info_request_title(info_request.user, _("Some notes have been added to your FOI request - "), info_request) end # Class function, called by script/mailin with all incoming responses. @@ -268,7 +234,7 @@ class RequestMailer < ApplicationMailer end # Send email alerts for overdue requests - def self.alert_overdue_requests() + def self.alert_overdue_requests info_requests = InfoRequest.find(:all, :conditions => [ "described_state = 'waiting_response' @@ -372,8 +338,8 @@ class RequestMailer < ApplicationMailer # Send email alerts for requests which need clarification. Goes out 3 days # after last update of event. - def self.alert_not_clarified_request() - info_requests = InfoRequest.find(:all, :conditions => [ "awaiting_description = ? and described_state = 'waiting_clarification' and info_requests.updated_at < ?", false, Time.now() - 3.days ], :include => [ :user ], :order => "info_requests.id" ) + def self.alert_not_clarified_request + info_requests = InfoRequest.find(:all, :conditions => [ "awaiting_description = ? and described_state = 'waiting_clarification' and info_requests.updated_at < ?", false, Time.now - 3.days ], :include => [ :user ], :order => "info_requests.id" ) for info_request in info_requests alert_event_id = info_request.get_last_public_response_event_id last_response_message = info_request.get_last_public_response @@ -400,7 +366,7 @@ class RequestMailer < ApplicationMailer end # Send email alert to request submitter for new comments on the request. - def self.alert_comment_on_request() + def self.alert_comment_on_request # We only check comments made in the last month - this means if the # cron jobs broke for more than a month events would be lost, but no @@ -467,7 +433,27 @@ class RequestMailer < ApplicationMailer end end + private -end + def auto_generated_headers + headers({ + 'Return-Path' => blackhole_email, + 'Reply-To' => contact_from_name_and_email, # not much we can do if the user's email is broken + 'Auto-Submitted' => 'auto-generated', # http://tools.ietf.org/html/rfc3834 + 'X-Auto-Response-Suppress' => 'OOF', + }) + end + def mail_user_with_info_request_title(user, subject, info_request) + mail_user(user, subject + info_request.title.html_safe) + end + + def mail_user(user, subject) + mail({ + :from => contact_from_name_and_email, + :to => user.name_and_email, + :subject => subject, + }) + end +end diff --git a/app/mailers/track_mailer.rb b/app/mailers/track_mailer.rb index 8e9beded6..3f5de6a1b 100644 --- a/app/mailers/track_mailer.rb +++ b/app/mailers/track_mailer.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # models/track_mailer.rb: # Emails which go to users who are tracking things. # @@ -38,7 +39,7 @@ class TrackMailer < ApplicationMailer # User.find(:all, :conditions => [ "last_daily_track_email < ?", Time.now - 1.day ]).size def self.alert_tracks done_something = false - now = Time.now() + now = Time.now one_week_ago = now - 7.days User.find_each(:conditions => [ "last_daily_track_email < ?", now - 1.day ]) do |user| diff --git a/app/mailers/user_mailer.rb b/app/mailers/user_mailer.rb index a351147f9..a6fed693e 100644 --- a/app/mailers/user_mailer.rb +++ b/app/mailers/user_mailer.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # models/user_mailer.rb: # Emails relating to user accounts. e.g. Confirming a new account # diff --git a/app/models/about_me_validator.rb b/app/models/about_me_validator.rb index 8c24cfd67..8465b0716 100644 --- a/app/models/about_me_validator.rb +++ b/app/models/about_me_validator.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # models/about_me_validator.rb: # Validates editing about me text on user profile pages. # @@ -9,20 +10,11 @@ class AboutMeValidator attr_accessor :about_me - # TODO: Switch to built in validations - validate :length_of_about_me + validates_length_of :about_me, :maximum => 500, :message => _("Please keep it shorter than 500 characters") def initialize(attributes = {}) attributes.each do |name, value| send("#{name}=", value) end end - - private - - def length_of_about_me - if !about_me.blank? && about_me.size > 500 - errors.add(:about_me, _("Please keep it shorter than 500 characters")) - end - end end diff --git a/app/models/censor_rule.rb b/app/models/censor_rule.rb index 3b5c2d805..f1f1a0d70 100644 --- a/app/models/censor_rule.rb +++ b/app/models/censor_rule.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # == Schema Information # # Table name: censor_rules @@ -22,6 +23,7 @@ # Email: hello@mysociety.org; WWW: http://www.mysociety.org/ class CensorRule < ActiveRecord::Base + include AdminColumn belongs_to :info_request belongs_to :user belongs_to :public_body @@ -42,6 +44,11 @@ class CensorRule < ActiveRecord::Base :user_id => nil, :public_body_id => nil } } + def apply_to_text(text_to_censor) + return nil if text_to_censor.nil? + text_to_censor.gsub(to_replace, replacement) + end + def apply_to_text!(text_to_censor) return nil if text_to_censor.nil? text_to_censor.gsub!(to_replace, replacement) @@ -52,12 +59,6 @@ class CensorRule < ActiveRecord::Base binary_to_censor.gsub!(to_replace) { |match| match.gsub(/./, 'x') } end - def for_admin_column - self.class.content_columns.each do |column| - yield(column.human_name, send(column.name), column.type.to_s, column.name) - end - end - def is_global? info_request_id.nil? && user_id.nil? && public_body_id.nil? end diff --git a/app/models/change_email_validator.rb b/app/models/change_email_validator.rb index 65f2fd81c..f5b31f038 100644 --- a/app/models/change_email_validator.rb +++ b/app/models/change_email_validator.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # models/changeemail_validator.rb: # Validates email change form submissions. # diff --git a/app/models/comment.rb b/app/models/comment.rb index cc8d0e94b..59f91ffb7 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # == Schema Information # # Table name: comments @@ -20,6 +21,7 @@ # Email: hello@mysociety.org; WWW: http://www.mysociety.org/ class Comment < ActiveRecord::Base + include AdminColumn strip_attributes! belongs_to :user @@ -31,6 +33,8 @@ class Comment < ActiveRecord::Base validate :check_body_has_content, :check_body_uses_mixed_capitals + scope :visible, where(:visible => true) + after_save :event_xapian_update # When posting a new comment, use this to check user hasn't double @@ -57,10 +61,6 @@ class Comment < ActiveRecord::Base ret end - def raw_body - read_attribute(:body) - end - # So when takes changes it updates, or when made invisble it vanishes def event_xapian_update info_request_events.each { |event| event.xapian_mark_needs_index } @@ -75,12 +75,6 @@ class Comment < ActiveRecord::Base text.html_safe end - def for_admin_column - self.class.content_columns.each do |column| - yield(column.human_name, send(column.name), column.type.to_s, column.name) - end - end - private def check_body_has_content diff --git a/app/models/concerns/admin_column.rb b/app/models/concerns/admin_column.rb new file mode 100644 index 000000000..6e19f5aa5 --- /dev/null +++ b/app/models/concerns/admin_column.rb @@ -0,0 +1,17 @@ +module AdminColumn + extend ActiveSupport::Concern + + included do + class << self + attr_reader :non_admin_columns + end + + @non_admin_columns = [] + end + + def for_admin_column + self.class.content_columns.reject { |c| self.class.non_admin_columns.include?(c.name) }.each do |column| + yield(column.human_name, send(column.name), column.type.to_s, column.name) + end + end +end diff --git a/app/models/concerns/translatable.rb b/app/models/concerns/translatable.rb new file mode 100644 index 000000000..bc89e4c3b --- /dev/null +++ b/app/models/concerns/translatable.rb @@ -0,0 +1,43 @@ +module Translatable + extend ActiveSupport::Concern + + included do + accepts_nested_attributes_for :translations, :reject_if => :empty_translation_in_params? + end + + def find_translation_by_locale(locale) + translations.find_by_locale(locale) + end + + def translated_versions + translations + end + + def ordered_translations + translations.select do |translation| + I18n.available_locales.include?(translation.locale) + end.sort_by do |translation| + I18n.available_locales.index(translation.locale) + end + end + + def build_all_translations + I18n.available_locales.each do |locale| + if translations.none? { |translation| translation.locale == locale } + translations.build(:locale => locale) + end + end + end + + def translated_versions=(translation_attrs) + warn "[DEPRECATION] #{self.class.name}#translated_versions= will be replaced " \ + "by #{self.class.name}#translations_attributes= as of release 0.22" + self.translations_attributes = translation_attrs + end + + private + + def empty_translation_in_params?(attributes) + attributes.select { |k, v| v.present? && k.to_s != 'locale' }.empty? + end +end diff --git a/app/models/contact_validator.rb b/app/models/contact_validator.rb index 8d7e4ff08..1d50bf603 100644 --- a/app/models/contact_validator.rb +++ b/app/models/contact_validator.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # models/contact_validator.rb: # Validates contact form submissions. # diff --git a/app/models/foi_attachment.rb b/app/models/foi_attachment.rb index a8d105f52..0af47b26e 100644 --- a/app/models/foi_attachment.rb +++ b/app/models/foi_attachment.rb @@ -1,4 +1,4 @@ -# encoding: UTF-8 +# -*- encoding : utf-8 -*- # == Schema Information # # Table name: foi_attachments @@ -244,36 +244,32 @@ class FoiAttachment < ActiveRecord::Base # The full list of supported types can be found at # https://docs.google.com/support/bin/answer.py?hl=en&answer=1189935 def has_google_docs_viewer? - return !! { - "application/pdf" => true, # .pdf - "image/tiff" => true, # .tiff + [ + "application/pdf", # .pdf + "image/tiff", # .tiff - "application/vnd.ms-word" => true, # .doc - "application/vnd.openxmlformats-officedocument.wordprocessingml.document" => true, # .docx + "application/vnd.ms-word", # .doc + "application/vnd.openxmlformats-officedocument.wordprocessingml.document", # .docx - "application/vnd.ms-powerpoint" => true, # .ppt - "application/vnd.openxmlformats-officedocument.presentationml.presentation" => true, # .pptx + "application/vnd.ms-powerpoint", # .ppt + "application/vnd.openxmlformats-officedocument.presentationml.presentation", # .pptx - "application/vnd.ms-excel" => true, # .xls - "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" => true, # .xlsx - - } [self.content_type] + "application/vnd.ms-excel", # .xls + "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", # .xlsx + ].include?(content_type) end # Whether this type has a "View as HTML" def has_body_as_html? - return ( - !!{ - "text/plain" => true, - "application/rtf" => true, - }[self.content_type] or - self.has_google_docs_viewer? - ) + [ + "text/plain", + "application/rtf", + ].include?(content_type) || has_google_docs_viewer? end # Name of type of attachment type - only valid for things that has_body_as_html? def name_of_content_type - return { + { "text/plain" => "Text file", 'application/rtf' => "RTF file", diff --git a/app/models/holiday.rb b/app/models/holiday.rb index 34044683a..538e77051 100644 --- a/app/models/holiday.rb +++ b/app/models/holiday.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # == Schema Information # # Table name: holidays diff --git a/app/models/holiday_import.rb b/app/models/holiday_import.rb index 98a9b96fc..58ea0b1f7 100644 --- a/app/models/holiday_import.rb +++ b/app/models/holiday_import.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class HolidayImport include ActiveModel::Validations diff --git a/app/models/incoming_message.rb b/app/models/incoming_message.rb index 4feee7637..dff516f0e 100644 --- a/app/models/incoming_message.rb +++ b/app/models/incoming_message.rb @@ -1,4 +1,4 @@ -# coding: utf-8 +# -*- encoding : utf-8 -*- # == Schema Information # # Table name: incoming_messages @@ -38,6 +38,7 @@ require 'zip/zip' require 'iconv' unless String.method_defined?(:encode) class IncomingMessage < ActiveRecord::Base + include AdminColumn extend MessageProminence belongs_to :info_request validates_presence_of :info_request @@ -725,7 +726,7 @@ class IncomingMessage < ActiveRecord::Base end # Search all info requests for - def IncomingMessage.find_all_unknown_mime_types + def self.find_all_unknown_mime_types for incoming_message in IncomingMessage.find(:all) for attachment in incoming_message.get_attachments_for_display raise "internal error incoming_message " + incoming_message.id.to_s if attachment.content_type.nil? @@ -751,16 +752,9 @@ class IncomingMessage < ActiveRecord::Base return ret.keys.join(" ") end # Return space separated list of all file extensions known - def IncomingMessage.get_all_file_extensions + def self.get_all_file_extensions return AlaveteliFileTypes.all_extensions.join(" ") end - - def for_admin_column - self.class.content_columns.each do |column| - yield(column.human_name, self.send(column.name), column.type.to_s, column.name) - end - end - end diff --git a/app/models/info_request.rb b/app/models/info_request.rb index c203f75c3..3ce0e3cd2 100644 --- a/app/models/info_request.rb +++ b/app/models/info_request.rb @@ -1,4 +1,4 @@ -# encoding: utf-8 +# -*- encoding : utf-8 -*- # == Schema Information # Schema version: 20131024114346 # @@ -28,8 +28,11 @@ require 'digest/sha1' class InfoRequest < ActiveRecord::Base + include AdminColumn include Rails.application.routes.url_helpers + @non_admin_columns = %w(title url_title) + strip_attributes! validates_presence_of :title, :message => N_("Please enter a summary of your request") @@ -50,6 +53,7 @@ class InfoRequest < ActiveRecord::Base has_many :info_request_events, :order => 'created_at' has_many :user_info_request_sent_alerts has_many :track_things, :order => 'created_at desc' + has_many :widget_votes has_many :comments, :order => 'created_at' has_many :censor_rules, :order => 'created_at desc' has_many :mail_server_logs, :order => 'mail_server_log_done_id' @@ -193,23 +197,12 @@ class InfoRequest < ActiveRecord::Base rescue MissingSourceFile, NameError end - # only check on create, so existing models with mixed case are allowed - def validate_on_create - if !self.title.nil? && !MySociety::Validate.uses_mixed_capitals(self.title, 10) - errors.add(:title, _('Please write the summary using a mixture of capital and lower case letters. This makes it easier for others to read.')) - end - if !self.title.nil? && title.size > 200 - errors.add(:title, _('Please keep the summary short, like in the subject of an email. You can use a phrase, rather than a full sentence.')) - end - if !self.title.nil? && self.title =~ /^(FOI|Freedom of Information)\s*requests?$/i - errors.add(:title, _('Please describe more what the request is about in the subject. There is no need to say it is an FOI request, we add that on anyway.')) - end - end - OLD_AGE_IN_DAYS = 21.days def visible_comments - self.comments.find(:all, :conditions => 'visible') + warn %q([DEPRECATION] InfoRequest#visible_comments will be replaced with + InfoRequest#comments.visible as of 0.23).squish + comments.visible end # If the URL name has changed, then all request: queries will break unless @@ -345,7 +338,7 @@ public # only they are sent the email address with the has in it. (We don't check # the prefix and domain, as sometimes those change, or might be elided by # copying an email, and that doesn't matter) - def InfoRequest.find_by_incoming_email(incoming_email) + def self.find_by_incoming_email(incoming_email) id, hash = InfoRequest._extract_id_hash_from_email(incoming_email) if hash_from_id(id) == hash # Not using find(id) because we don't exception raised if nothing found @@ -355,7 +348,7 @@ public # Return list of info requests which *might* be right given email address # e.g. For the id-hash email addresses, don't match the hash. - def InfoRequest.guess_by_incoming_email(incoming_message) + def self.guess_by_incoming_email(incoming_message) guesses = [] # 1. Try to guess based on the email address(es) incoming_message.addresses.each do |address| @@ -367,7 +360,7 @@ public end # Internal function used by find_by_magic_email and guess_by_incoming_email - def InfoRequest._extract_id_hash_from_email(incoming_email) + def self._extract_id_hash_from_email(incoming_email) # Match case insensitively, FOI officers often write Request with capital R. incoming_email = incoming_email.downcase @@ -394,7 +387,7 @@ public # repeated requests, say once a quarter for time information, then might need to do that. # TODO: this *should* also check outgoing message joined to is an initial # request (rather than follow up) - def InfoRequest.find_existing(title, public_body_id, body) + def self.find_existing(title, public_body_id, body) return InfoRequest.find(:first, :conditions => [ "title = ? and public_body_id = ? and outgoing_messages.body = ?", title, public_body_id, body ], :include => [ :outgoing_messages ] ) end @@ -534,7 +527,7 @@ public # The "holding pen" is a special request which stores incoming emails whose # destination request is unknown. - def InfoRequest.holding_pen_request + def self.holding_pen_request ir = InfoRequest.find_by_url_title("holding_pen") if ir.nil? ir = InfoRequest.new( @@ -549,7 +542,7 @@ public :status => 'ready', :message_type => 'initial_request', :body => 'This is the holding pen request. It shows responses that were sent to invalid addresses, and need moving to the correct request by an adminstrator.', - :last_sent_at => Time.now(), + :last_sent_at => Time.now, :what_doing => 'normal_sort' }) @@ -564,7 +557,7 @@ public # states which require administrator action (hence email administrators # when they are entered, and offer state change dialog to them) - def InfoRequest.requires_admin_states + def self.requires_admin_states return ['requires_admin', 'error_message', 'attention_requested'] end @@ -665,11 +658,11 @@ public if !curr_state.nil? && event.event_type == 'response' if event.calculated_state != curr_state event.calculated_state = curr_state - event.last_described_at = Time.now() + event.last_described_at = Time.now event.save! end if event.last_described_at.nil? # TODO: actually maybe this isn't needed - event.last_described_at = Time.now() + event.last_described_at = Time.now event.save! end curr_state = nil @@ -681,7 +674,7 @@ public # indexed. if event.calculated_state != event.described_state event.calculated_state = event.described_state - event.last_described_at = Time.now() + event.last_described_at = Time.now event.save! end @@ -698,7 +691,7 @@ public # case there is a preceding response that the described state should be applied to. if event.calculated_state != event.described_state event.calculated_state = event.described_state - event.last_described_at = Time.now() + event.last_described_at = Time.now event.save! end end @@ -783,7 +776,14 @@ public end def public_response_events - self.info_request_events.select{|e| e.response? && e.incoming_message.all_can_view? } + condition = <<-SQL + info_request_events.event_type = ? + AND incoming_messages.prominence = ? + SQL + + info_request_events. + joins(:incoming_message). + where(condition, 'response', 'normal') end # The last public response is the default one people might want to reply to @@ -810,8 +810,9 @@ public # Text from the the initial request, for use in summary display def initial_request_text - return '' if outgoing_messages.empty? # mainly for use with incomplete fixtures - outgoing_messages.first.get_text_for_indexing + return '' if outgoing_messages.empty? + body_opts = { :censor_rules => applicable_censor_rules } + outgoing_messages.first.try(:get_text_for_indexing, true, body_opts) or '' end # Returns index of last event which is described or nil if none described. @@ -873,7 +874,7 @@ public # Display version of status - def InfoRequest.get_status_description(status) + def self.get_status_description(status) descriptions = { 'waiting_classification' => _("Awaiting classification."), 'waiting_response' => _("Awaiting response."), @@ -908,21 +909,24 @@ public # Completely delete this request and all objects depending on it def fully_destroy - self.track_things.each do |track_thing| + track_things.each do |track_thing| track_thing.track_things_sent_emails.each { |a| a.destroy } track_thing.destroy end - self.user_info_request_sent_alerts.each { |a| a.destroy } - self.info_request_events.each do |info_request_event| + user_info_request_sent_alerts.each { |a| a.destroy } + info_request_events.each do |info_request_event| info_request_event.track_things_sent_emails.each { |a| a.destroy } info_request_event.destroy end - self.mail_server_logs.each do |mail_server_log| + mail_server_logs.each do |mail_server_log| mail_server_log.destroy end - self.outgoing_messages.each { |a| a.destroy } - self.incoming_messages.each { |a| a.destroy } - self.destroy + outgoing_messages.each { |a| a.destroy } + incoming_messages.each { |a| a.destroy } + comments.each { |comment| comment.destroy } + censor_rules.each{ |censor_rule| censor_rule.destroy } + + destroy end # Called by incoming_email - and used to be called to generate separate @@ -932,7 +936,7 @@ public return InfoRequest.magic_email_for_id(prefix_part, self.id) end - def InfoRequest.magic_email_for_id(prefix_part, id) + def self.magic_email_for_id(prefix_part, id) magic_email = AlaveteliConfiguration::incoming_email_prefix magic_email += prefix_part + id.to_s magic_email += "-" + InfoRequest.hash_from_id(id) @@ -946,7 +950,7 @@ public self.idhash = InfoRequest.hash_from_id(self.id) end - def InfoRequest.create_from_attributes(info_request_atts, outgoing_message_atts, user=nil) + def self.create_from_attributes(info_request_atts, outgoing_message_atts, user=nil) info_request = new(info_request_atts) default_message_params = { :status => 'ready', @@ -960,12 +964,12 @@ public info_request end - def InfoRequest.hash_from_id(id) + def self.hash_from_id(id) return Digest::SHA1.hexdigest(id.to_s + AlaveteliConfiguration::incoming_email_secret)[0,8] end # Used to find when event last changed - def InfoRequest.last_event_time_clause(event_type=nil, join_table=nil, join_clause=nil) + def self.last_event_time_clause(event_type=nil, join_table=nil, join_clause=nil) event_type_clause = '' event_type_clause = " AND info_request_events.event_type = '#{event_type}'" if event_type tables = ['info_request_events'] @@ -980,20 +984,20 @@ public LIMIT 1)" end - def InfoRequest.last_public_response_clause() + def self.last_public_response_clause join_clause = "incoming_messages.id = info_request_events.incoming_message_id AND incoming_messages.prominence = 'normal'" last_event_time_clause('response', 'incoming_messages', join_clause) end - def InfoRequest.old_unclassified_params(extra_params, include_last_response_time=false) - last_response_created_at = last_public_response_clause() + def self.old_unclassified_params(extra_params, include_last_response_time=false) + last_response_created_at = last_public_response_clause age = extra_params[:age_in_days] ? extra_params[:age_in_days].days : OLD_AGE_IN_DAYS params = { :conditions => ["awaiting_description = ? AND #{last_response_created_at} < ? AND url_title != 'holding_pen' AND user_id IS NOT NULL", - true, Time.now() - age] } + true, Time.now - age] } if include_last_response_time params[:select] = "*, #{last_response_created_at} AS last_response_time" params[:order] = 'last_response_time' @@ -1001,29 +1005,21 @@ public return params end - def InfoRequest.count_old_unclassified(extra_params={}) + def self.count_old_unclassified(extra_params={}) params = old_unclassified_params(extra_params) - if extra_params[:conditions] - condition_string = extra_params[:conditions].shift - params[:conditions][0] += " AND #{condition_string}" - params[:conditions] += extra_params[:conditions] - end + add_conditions_from_extra_params(params, extra_params) count(:all, params) end - def InfoRequest.get_random_old_unclassified(limit, extra_params) + def self.get_random_old_unclassified(limit, extra_params) params = old_unclassified_params({}) - if extra_params[:conditions] - condition_string = extra_params[:conditions].shift - params[:conditions][0] += " AND #{condition_string}" - params[:conditions] += extra_params[:conditions] - end + add_conditions_from_extra_params(params, extra_params) params[:limit] = limit params[:order] = "random()" find(:all, params) end - def InfoRequest.find_old_unclassified(extra_params={}) + def self.find_old_unclassified(extra_params={}) params = old_unclassified_params(extra_params, include_last_response_time=true) [:limit, :include, :offset].each do |extra| params[extra] = extra_params[extra] if extra_params[extra] @@ -1032,15 +1028,11 @@ public params[:order] = extra_params[:order] params.delete(:select) end - if extra_params[:conditions] - condition_string = extra_params[:conditions].shift - params[:conditions][0] += " AND #{condition_string}" - params[:conditions] += extra_params[:conditions] - end + add_conditions_from_extra_params(params, extra_params) find(:all, params) end - def InfoRequest.download_zip_dir() + def self.download_zip_dir File.join(Rails.root, "cache", "zips", "#{Rails.env}") end @@ -1058,7 +1050,7 @@ public end def request_dirs - first_three_digits = id.to_s()[0..2] + first_three_digits = id.to_s[0..2] File.join(first_three_digits.to_s, id.to_s) end @@ -1067,7 +1059,7 @@ public end def make_zip_cache_path(user) - cache_file_dir = File.join(InfoRequest.download_zip_dir(), + cache_file_dir = File.join(InfoRequest.download_zip_dir, "download", request_dirs, last_update_hash) @@ -1191,7 +1183,7 @@ public end # This is called from cron regularly. - def InfoRequest.stop_new_responses_on_old_requests + def self.stop_new_responses_on_old_requests # 6 months since last change to request, only allow new incoming messages from authority domains InfoRequest.update_all "allow_new_responses_from = 'authority_only' where updated_at < (now() - interval '6 months') and allow_new_responses_from = 'anybody' and url_title <> 'holding_pen'" # 1 year since last change requests, don't allow any new incoming messages @@ -1240,7 +1232,7 @@ public :model => self.class.base_class.to_s, :model_id => self.id) end - req.save() + req.save end end @@ -1270,13 +1262,6 @@ public PublicBody.set_callback(:save, :after, :purge_in_cache) end - def for_admin_column - self.class.content_columns.map{|c| c unless %w(title url_title).include?(c.name) }.compact.each do |column| - yield(column.human_name, self.send(column.name), column.type.to_s, column.name) - end - end - - # Get requests that have similar important terms def similar_requests(limit=10) xapian_similar = nil @@ -1292,7 +1277,7 @@ public return [xapian_similar, xapian_similar_more] end - def InfoRequest.request_list(filters, page, per_page, max_results) + def self.request_list(filters, page, per_page, max_results) xapian_object = ActsAsXapian::Search.new([InfoRequestEvent], InfoRequestEvent.make_query_from_params(filters), :offset => (page - 1) * per_page, @@ -1309,7 +1294,7 @@ public :show_no_more_than => show_no_more_than } end - def InfoRequest.recent_requests + def self.recent_requests request_events = [] request_events_all_successful = false # Get some successful requests @@ -1356,12 +1341,45 @@ public return [request_events, request_events_all_successful] end - def InfoRequest.find_in_state(state) + def self.find_in_state(state) select("*, #{ last_event_time_clause } as last_event_time"). where(:described_state => state). order('last_event_time') end + def move_to_public_body(destination_public_body, opts = {}) + old_body = public_body + editor = opts.fetch(:editor) + + attrs = { :public_body => destination_public_body } + + if destination_public_body + attrs.merge!({ + :law_used => destination_public_body.law_only_short.downcase + }) + end + + if update_attributes(attrs) + log_event('move_request', + :editor => editor, + :public_body_url_name => public_body.url_name, + :old_public_body_url_name => old_body.url_name) + + reindex_request_events + + public_body + end + end + + # The DateTime of the last InfoRequestEvent belonging to the InfoRequest + # Only available if the last_event_time attribute has been set. This is + # currentlt only set through .find_in_state + # + # Returns a DateTime + def last_event_time + attributes['last_event_time'].try(:to_datetime) + end + private def set_defaults @@ -1370,11 +1388,12 @@ public self.described_state = 'waiting_response' end rescue ActiveModel::MissingAttributeError - # this should only happen on Model.exists?() call. It can be safely ignored. + # this should only happen on Model.exists? call. It can be safely ignored. # See http://www.tatvartha.com/2011/03/activerecordmissingattributeerror-missing-attribute-a-bug-or-a-features/ end + # FOI or EIR? - if !self.public_body.nil? && self.public_body.eir_only? + if new_record? && public_body && public_body.eir_only? self.law_used = 'eir' end end @@ -1390,5 +1409,13 @@ public errors.add(:title, _('Please describe more what the request is about in the subject. There is no need to say it is an FOI request, we add that on anyway.')) end end + + def self.add_conditions_from_extra_params(params, extra_params) + if extra_params[:conditions] + condition_string = extra_params[:conditions].shift + params[:conditions][0] += " AND #{condition_string}" + params[:conditions] += extra_params[:conditions] + end + end end diff --git a/app/models/info_request_batch.rb b/app/models/info_request_batch.rb index 8a5ebeaba..684467c61 100644 --- a/app/models/info_request_batch.rb +++ b/app/models/info_request_batch.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # == Schema Information # # Table name: info_request_batches @@ -21,7 +22,7 @@ class InfoRequestBatch < ActiveRecord::Base validates_presence_of :body # When constructing a new batch, use this to check user hasn't double submitted. - def InfoRequestBatch.find_existing(user, title, body, public_body_ids) + def self.find_existing(user, title, body, public_body_ids) find(:first, :conditions => ['user_id = ? AND title = ? AND body = ? @@ -69,7 +70,7 @@ class InfoRequestBatch < ActiveRecord::Base info_request end - def InfoRequestBatch.send_batches() + def self.send_batches find_each(:conditions => "sent_at IS NULL") do |info_request_batch| unrequestable = info_request_batch.create_batch! mail_message = InfoRequestBatchMailer.batch_sent(info_request_batch, diff --git a/app/models/info_request_event.rb b/app/models/info_request_event.rb index 635ba8f58..29c1ce965 100644 --- a/app/models/info_request_event.rb +++ b/app/models/info_request_event.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # == Schema Information # # Table name: info_request_events @@ -21,7 +22,7 @@ # Email: hello@mysociety.org; WWW: http://www.mysociety.org/ class InfoRequestEvent < ActiveRecord::Base - + include AdminColumn extend XapianQueries belongs_to :info_request @@ -278,9 +279,15 @@ class InfoRequestEvent < ActiveRecord::Base end self.params_yaml = params.to_yaml end + def params - YAML.load(self.params_yaml) + param_hash = YAML.load(params_yaml) + param_hash.each do |key, value| + param_hash[key] = value.force_encoding('UTF-8') if value.respond_to?(:force_encoding) + end + param_hash end + def params_yaml_as_html ret = '' # split out parameters into old/new diffs, and other ones @@ -319,9 +326,17 @@ class InfoRequestEvent < ActiveRecord::Base end - def is_incoming_message?() not self.incoming_message_selective_columns("incoming_messages.id").nil? end - def is_outgoing_message?() not self.outgoing_message.nil? end - def is_comment?() not self.comment.nil? end + def is_incoming_message? + !self.incoming_message_selective_columns("incoming_messages.id").nil? + end + + def is_outgoing_message? + !self.outgoing_message.nil? + end + + def is_comment? + !self.comment.nil? + end # Display version of status def display_status @@ -412,11 +427,4 @@ class InfoRequestEvent < ActiveRecord::Base return ret end - - def for_admin_column - self.class.content_columns.each do |column| - yield(column.human_name, self.send(column.name), column.type.to_s, column.name) - end - end - end diff --git a/app/models/mail_server_log.rb b/app/models/mail_server_log.rb index 07d2fdac0..64a740e1d 100644 --- a/app/models/mail_server_log.rb +++ b/app/models/mail_server_log.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # == Schema Information # # Table name: mail_server_logs @@ -25,7 +26,7 @@ class MailServerLog < ActiveRecord::Base # Doesn't do anything if file hasn't been modified since it was last loaded. # Note: If you do use rotated log files (rather than files named by date), at some # point old loaded log lines will get deleted in the database. - def MailServerLog.load_file(file_name) + def self.load_file(file_name) is_gz = file_name.include?(".gz") file_name_db = is_gz ? file_name.gsub(".gz", "") : file_name @@ -62,23 +63,16 @@ class MailServerLog < ActiveRecord::Base end # Scan the file - def MailServerLog.load_exim_log_data(f, done) + def self.load_exim_log_data(f, done) order = 0 f.each do |line| order = order + 1 emails = email_addresses_on_line(line) - for email in emails - info_request = InfoRequest.find_by_incoming_email(email) - if info_request - info_request.mail_server_logs.create!(:line => line, :order => order, :mail_server_log_done => done) - else - puts "Warning: Could not find request with email #{email}" - end - end + create_mail_server_logs(emails, line, order, done) end end - def MailServerLog.load_postfix_log_data(f, done) + def self.load_postfix_log_data(f, done) order = 0 emails = scan_for_postfix_queue_ids(f) # Go back to the beginning of the file @@ -87,19 +81,12 @@ class MailServerLog < ActiveRecord::Base order = order + 1 queue_id = extract_postfix_queue_id_from_syslog_line(line) if emails.has_key?(queue_id) - emails[queue_id].each do |email| - info_request = InfoRequest.find_by_incoming_email(email) - if info_request - info_request.mail_server_logs.create!(:line => line, :order => order, :mail_server_log_done => done) - else - puts "Warning: Could not find request with email #{email}" - end - end + create_mail_server_logs(emails[queue_id], line, order, done) end end end - def MailServerLog.scan_for_postfix_queue_ids(f) + def self.scan_for_postfix_queue_ids(f) result = {} f.each do |line| emails = email_addresses_on_line(line) @@ -111,7 +98,7 @@ class MailServerLog < ActiveRecord::Base end # Retuns nil if there is no queue id - def MailServerLog.extract_postfix_queue_id_from_syslog_line(line) + def self.extract_postfix_queue_id_from_syslog_line(line) # Assume the log file was written using syslog and parse accordingly m = SyslogProtocol.parse("<13>" + line).content.match(/^\S+: (\S+):/) m[1] if m @@ -119,13 +106,13 @@ class MailServerLog < ActiveRecord::Base # We also check the email prefix so that we could, for instance, separately handle a staging and production # instance running on the same server with different email prefixes. - def MailServerLog.email_addresses_on_line(line) + def self.email_addresses_on_line(line) prefix = Regexp::quote(AlaveteliConfiguration::incoming_email_prefix) domain = Regexp::quote(AlaveteliConfiguration::incoming_email_domain) line.scan(/#{prefix}request-[^\s]+@#{domain}/).sort.uniq end - def MailServerLog.request_sent?(ir) + def self.request_sent?(ir) case(AlaveteliConfiguration::mta_log_type.to_sym) when :exim request_exim_sent?(ir) @@ -137,7 +124,7 @@ class MailServerLog < ActiveRecord::Base end # Look at the log for a request and check that an email was delivered - def MailServerLog.request_exim_sent?(ir) + def self.request_exim_sent?(ir) # Look for line showing request was sent found = false ir.mail_server_logs.each do |mail_server_log| @@ -156,7 +143,7 @@ class MailServerLog < ActiveRecord::Base found end - def MailServerLog.request_postfix_sent?(ir) + def self.request_postfix_sent?(ir) # dsn=2.0.0 is the magic word that says that postfix delivered the email # See http://tools.ietf.org/html/rfc3464 ir.mail_server_logs.any? { |l| l.line.include?("dsn=2.0.0") } @@ -173,11 +160,11 @@ class MailServerLog < ActiveRecord::Base # NB: There can be several emails involved in a request. This just checks that # at least one of them has been succesfully sent. # - def MailServerLog.check_recent_requests_have_been_sent + def self.check_recent_requests_have_been_sent # Get all requests sent for from 2 to 10 days ago. The 2 day gap is # because we load mail server log lines via cron at best an hour after they # are made) - irs = InfoRequest.find(:all, :conditions => [ "created_at < ? and created_at > ? and user_id is not null", Time.now() - 2.day, Time.now() - 10.days ] ) + irs = InfoRequest.find(:all, :conditions => [ "created_at < ? and created_at > ? and user_id is not null", Time.now - 2.day, Time.now - 10.days ] ) # Go through each request and check it ok = true @@ -192,7 +179,17 @@ class MailServerLog < ActiveRecord::Base ok end -end - + private + def self.create_mail_server_logs(emails, line, order, done) + emails.each do |email| + info_request = InfoRequest.find_by_incoming_email(email) + if info_request + info_request.mail_server_logs.create!(:line => line, :order => order, :mail_server_log_done => done) + else + puts "Warning: Could not find request with email #{email}" + end + end + end +end diff --git a/app/models/mail_server_log_done.rb b/app/models/mail_server_log_done.rb index 1bbb23ac4..542c3db3a 100644 --- a/app/models/mail_server_log_done.rb +++ b/app/models/mail_server_log_done.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # == Schema Information # # Table name: mail_server_log_dones diff --git a/app/models/outgoing_message.rb b/app/models/outgoing_message.rb index c2c8ef4f2..2e1b27fba 100644 --- a/app/models/outgoing_message.rb +++ b/app/models/outgoing_message.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # == Schema Information # Schema version: 20131024114346 # @@ -25,6 +26,7 @@ # Email: hello@mysociety.org; WWW: http://www.mysociety.org/ class OutgoingMessage < ActiveRecord::Base + include AdminColumn extend MessageProminence include Rails.application.routes.url_helpers include LinkToHelper @@ -140,22 +142,28 @@ class OutgoingMessage < ActiveRecord::Base end end - def body - ret = read_attribute(:body) - if ret.nil? - return ret + # Public: The body text of the OutgoingMessage. The text is cleaned and + # CensorRules are applied. + # + # options - Hash of options + # :censor_rules - Array of CensorRules to apply. Defaults to the + # applicable_censor_rules of the associated + # InfoRequest. (optional) + # + # Returns a String + def body(options = {}) + text = raw_body.dup + return text if text.nil? + + text = clean_text(text) + + # Use the given censor_rules; otherwise fetch them from the associated + # info_request + censor_rules = options.fetch(:censor_rules) do + info_request.try(:applicable_censor_rules) or [] end - ret = ret.dup - ret.strip! - ret.gsub!(/(?:\n\s*){2,}/, "\n\n") # remove excess linebreaks that unnecessarily space it out - - # Remove things from censor rules - unless info_request.nil? - self.info_request.apply_censor_rules_to_text!(ret) - end - - ret + censor_rules.reduce(text) { |text, rule| rule.apply_to_text(text) } end def raw_body @@ -227,8 +235,12 @@ class OutgoingMessage < ActiveRecord::Base end # Returns text for indexing / text display - def get_text_for_indexing(strip_salutation = true) - text = body.strip + def get_text_for_indexing(strip_salutation = true, opts = {}) + if opts.empty? + text = body.strip + else + text = body(opts).strip + end # Remove salutation text.sub!(/Dear .+,/, "") if strip_salutation @@ -272,12 +284,6 @@ class OutgoingMessage < ActiveRecord::Base info_request.purge_in_cache end - def for_admin_column - self.class.content_columns.each do |column| - yield(column.human_name, self.send(column.name), column.type.to_s, column.name) - end - end - def xapian_reindex_after_update if changes.include?('body') info_request_events.each do |event| @@ -332,6 +338,11 @@ class OutgoingMessage < ActiveRecord::Base errors.add(:what_doing_dummy, _('Please choose what sort of reply you are making.')) end end + + # remove excess linebreaks that unnecessarily space it out + def clean_text(text) + text.strip.gsub(/(?:\n\s*){2,}/, "\n\n") + end end diff --git a/app/models/post_redirect.rb b/app/models/post_redirect.rb index 8049349d0..3cdc69995 100644 --- a/app/models/post_redirect.rb +++ b/app/models/post_redirect.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # == Schema Information # # Table name: post_redirects @@ -71,7 +72,11 @@ class PostRedirect < ActiveRecord::Base end def reason_params - YAML.load(reason_params_yaml) + param_hash = YAML.load(reason_params_yaml) + param_hash.each do |key, value| + param_hash[key] = value.force_encoding('UTF-8') if value.respond_to?(:force_encoding) + end + param_hash end # Extract just local path part, without domain or # diff --git a/app/models/profile_photo.rb b/app/models/profile_photo.rb index 61f88faf3..94edc2967 100644 --- a/app/models/profile_photo.rb +++ b/app/models/profile_photo.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # == Schema Information # # Table name: profile_photos diff --git a/app/models/public_body.rb b/app/models/public_body.rb index 232c0ffa1..fec1cefb6 100644 --- a/app/models/public_body.rb +++ b/app/models/public_body.rb @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# -*- encoding : utf-8 -*- # == Schema Information # Schema version: 20131024114346 # @@ -32,6 +32,10 @@ require 'securerandom' require 'set' class PublicBody < ActiveRecord::Base + include AdminColumn + + @non_admin_columns = %w(name last_edit_comment) + strip_attributes! validates_presence_of :name, :message => N_("Name can't be blank") @@ -64,7 +68,6 @@ class PublicBody < ActiveRecord::Base } translates :name, :short_name, :request_email, :url_name, :notes, :first_letter, :publication_scheme - accepts_nested_attributes_for :translations, :reject_if => :empty_translation_in_params? # Default fields available for importing from CSV, in the format # [field_name, 'short description of field (basic html allowed)'] @@ -96,6 +99,8 @@ class PublicBody < ActiveRecord::Base self.non_versioned_columns << 'info_requests_not_held_count' << 'info_requests_overdue' self.non_versioned_columns << 'info_requests_overdue_count' + include Translatable + # Public: Search for Public Bodies whose name, short_name, request_email or # tags contain the given query # @@ -124,11 +129,6 @@ class PublicBody < ActiveRecord::Base uniq end - # Convenience methods for creating/editing translations via forms - def find_translation_by_locale(locale) - self.translations.find_by_locale(locale) - end - # TODO: - Don't like repeating this! def calculate_cached_fields(t) PublicBody.set_first_letter(t) @@ -138,7 +138,7 @@ class PublicBody < ActiveRecord::Base end # Set the first letter on a public body or translation - def PublicBody.set_first_letter(instance) + def self.set_first_letter(instance) unless instance.name.nil? or instance.name.empty? # we use a regex to ensure it works with utf-8/multi-byte first_letter = Unicode.upcase instance.name.scan(/^./mu)[0] @@ -148,28 +148,6 @@ class PublicBody < ActiveRecord::Base end end - def translated_versions - translations - end - - def ordered_translations - translations. - select { |t| I18n.available_locales.include?(t.locale) }. - sort_by { |t| I18n.available_locales.index(t.locale) } - end - - def build_all_translations - I18n.available_locales.each do |locale| - translations.build(:locale => locale) unless translations.detect{ |t| t.locale == locale } - end - end - - def translated_versions=(translation_attrs) - warn "[DEPRECATION] PublicBody#translated_versions= will be replaced " \ - "by PublicBody#translations_attributes= as of release 0.22" - self.translations_attributes = translation_attrs - end - def set_default_publication_scheme # Make sure publication_scheme gets the correct default value. # (This would work automatically, were publication_scheme not a translated attribute) @@ -339,23 +317,24 @@ class PublicBody < ActiveRecord::Base # Are all requests to this body under the Environmental Information Regulations? def eir_only? - return self.has_tag?('eir_only') + has_tag?('eir_only') end + def law_only_short - if self.eir_only? - return "EIR" - else - return "FOI" - end + eir_only? ? 'EIR' : 'FOI' end # Schools are allowed more time in holidays, so we change some wordings def is_school? - return self.has_tag?('school') + has_tag?('school') + end + + def site_administration? + has_tag?('site_administration') end # The "internal admin" is a special body for internal use. - def PublicBody.internal_admin_body + def self.internal_admin_body # 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'" @@ -379,10 +358,6 @@ class PublicBody < ActiveRecord::Base end end - def site_administration? - has_tag?('site_administration') - end - class ImportCSVDryRun < StandardError end @@ -412,7 +387,7 @@ class PublicBody < ActiveRecord::Base # matching names won't work afterwards, and we'll create new bodies instead # of updating them bodies_by_name = {} - set_of_existing = Set.new() + set_of_existing = Set.new internal_admin_body_id = PublicBody.internal_admin_body.id I18n.with_locale(I18n.default_locale) do bodies = (tag.nil? || tag.empty?) ? PublicBody.find(:all, :include => :translations) : PublicBody.find_by_tag(tag) @@ -425,7 +400,7 @@ class PublicBody < ActiveRecord::Base end end - set_of_importing = Set.new() + set_of_importing = Set.new # Default values in case no field list is given field_names = { 'name' => 1, 'request_email' => 2 } line = 0 @@ -577,17 +552,11 @@ class PublicBody < ActiveRecord::Base return self.request_email_domain end - # Returns nil if configuration variable not set - def override_request_email - e = AlaveteliConfiguration::override_all_public_body_request_emails - e if e != "" - end - def request_email - if override_request_email - override_request_email - else + if AlaveteliConfiguration::override_all_public_body_request_emails.blank? || read_attribute(:request_email).blank? read_attribute(:request_email) + else + AlaveteliConfiguration::override_all_public_body_request_emails end end @@ -598,7 +567,7 @@ class PublicBody < ActiveRecord::Base # Return the domain part of an email address, canonicalised and with common # extra UK Government server name parts removed. - def PublicBody.extract_domain_from_email(email) + def self.extract_domain_from_email(email) email =~ /@(.*)/ if $1.nil? return nil @@ -656,12 +625,6 @@ class PublicBody < ActiveRecord::Base self.info_requests.each {|x| x.purge_in_cache} end - def for_admin_column - self.class.content_columns.map{|c| c unless %w(name last_edit_comment).include?(c.name)}.compact.each do |column| - yield(column.human_name, self.send(column.name), column.type.to_s, column.name) - end - end - def self.where_clause_for_stats(minimum_requests, total_column) # When producing statistics for public bodies, we want to # exclude any that are tagged with 'test' - we use a @@ -773,13 +736,6 @@ class PublicBody < ActiveRecord::Base end end - def empty_translation_in_params?(attributes) - attrs_with_values = attributes.select do |key, value| - value != '' and key.to_s != 'locale' - end - attrs_with_values.empty? - end - def request_email_if_requestable # Request_email can be blank, meaning we don't have details if self.is_requestable? diff --git a/app/models/public_body_category.rb b/app/models/public_body_category.rb index b88c683de..0a64172c1 100644 --- a/app/models/public_body_category.rb +++ b/app/models/public_body_category.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # == Schema Information # # Table name: public_body_categories @@ -17,13 +18,14 @@ class PublicBodyCategory < ActiveRecord::Base has_many :public_body_headings, :through => :public_body_category_links translates :title, :description - accepts_nested_attributes_for :translations, :reject_if => :empty_translation_in_params? validates_uniqueness_of :category_tag, :message => 'Tag is already taken' validates_presence_of :title, :message => "Title can't be blank" validates_presence_of :category_tag, :message => "Tag can't be blank" validates_presence_of :description, :message => "Description can't be blank" + include Translatable + def self.get locale = I18n.locale.to_s || default_locale.to_s || "" categories = CategoryCollection.new @@ -51,43 +53,6 @@ class PublicBodyCategory < ActiveRecord::Base ) | PublicBodyCategory.find_by_sql(sql) end - - # Convenience methods for creating/editing translations via forms - def find_translation_by_locale(locale) - translations.find_by_locale(locale) - end - - def translated_versions - translations - end - - def translated_versions=(translation_attrs) - warn "[DEPRECATION] PublicBodyCategory#translated_versions= will be replaced " \ - "by PublicBodyCategory#translations_attributes= as of release 0.22" - self.translations_attributes = translation_attrs - end - - def ordered_translations - translations. - select { |t| I18n.available_locales.include?(t.locale) }. - sort_by { |t| I18n.available_locales.index(t.locale) } - end - - def build_all_translations - I18n.available_locales.each do |locale| - translations.build(:locale => locale) unless translations.detect{ |t| t.locale == locale } - end - end - - private - - def empty_translation_in_params?(attributes) - attrs_with_values = attributes.select do |key, value| - value != '' and key.to_s != 'locale' - end - attrs_with_values.empty? - end - end PublicBodyCategory::Translation.class_eval do diff --git a/app/models/public_body_category/category_collection.rb b/app/models/public_body_category/category_collection.rb index 8286e2710..7d5732a82 100644 --- a/app/models/public_body_category/category_collection.rb +++ b/app/models/public_body_category/category_collection.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # replicate original file-based PublicBodyCategories functionality class PublicBodyCategory::CategoryCollection include Enumerable @@ -13,19 +14,19 @@ class PublicBodyCategory::CategoryCollection end def with_description - @categories.select() { |a| a.instance_of?(Array) } + @categories.select { |a| a.instance_of?(Array) } end def tags - tags = with_description.map() { |a| a[0] } + tags = with_description.map { |a| a[0] } end def by_tag - Hash[*with_description.map() { |a| a[0..1] }.flatten] + Hash[*with_description.map { |a| a[0..1] }.flatten] end def singular_by_tag - Hash[*with_description.map() { |a| [a[0],a[2]] }.flatten] + Hash[*with_description.map { |a| [a[0],a[2]] }.flatten] end def by_heading diff --git a/app/models/public_body_category_link.rb b/app/models/public_body_category_link.rb index 8c3eb8060..be73a9afa 100644 --- a/app/models/public_body_category_link.rb +++ b/app/models/public_body_category_link.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # == Schema Information # # Table name: public_body_category_links diff --git a/app/models/public_body_change_request.rb b/app/models/public_body_change_request.rb index 0e59cbecc..88a24dbd9 100644 --- a/app/models/public_body_change_request.rb +++ b/app/models/public_body_change_request.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # == Schema Information # # Table name: public_body_change_requests diff --git a/app/models/public_body_heading.rb b/app/models/public_body_heading.rb index 8c160ba8b..d49b388bb 100644 --- a/app/models/public_body_heading.rb +++ b/app/models/public_body_heading.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # == Schema Information # # Table name: public_body_headings @@ -15,7 +16,6 @@ class PublicBodyHeading < ActiveRecord::Base default_scope order('display_order ASC') translates :name - accepts_nested_attributes_for :translations, :reject_if => :empty_translation_in_params? validates_uniqueness_of :name, :message => 'Name is already taken' validates_presence_of :name, :message => 'Name can\'t be blank' @@ -28,32 +28,7 @@ class PublicBodyHeading < ActiveRecord::Base end end - # Convenience methods for creating/editing translations via forms - def find_translation_by_locale(locale) - translations.find_by_locale(locale) - end - - def translated_versions - translations - end - - def translated_versions=(translation_attrs) - warn "[DEPRECATION] PublicBodyHeading#translated_versions= will be replaced " \ - "by PublicBodyHeading#translations_attributes= as of release 0.22" - self.translations_attributes = translation_attrs - end - - def ordered_translations - translations. - select { |t| I18n.available_locales.include?(t.locale) }. - sort_by { |t| I18n.available_locales.index(t.locale) } - end - - def build_all_translations - I18n.available_locales.each do |locale| - translations.build(:locale => locale) unless translations.detect{ |t| t.locale == locale } - end - end + include Translatable def add_category(category) unless public_body_categories.include?(category) @@ -68,14 +43,4 @@ class PublicBodyHeading < ActiveRecord::Base 0 end end - - private - - def empty_translation_in_params?(attributes) - attrs_with_values = attributes.select do |key, value| - value != '' and key.to_s != 'locale' - end - attrs_with_values.empty? - end - end diff --git a/app/models/purge_request.rb b/app/models/purge_request.rb index 81980188d..39dae6a74 100644 --- a/app/models/purge_request.rb +++ b/app/models/purge_request.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # == Schema Information # # Table name: purge_requests diff --git a/app/models/raw_email.rb b/app/models/raw_email.rb index 907d3c7a0..58ae29a3b 100644 --- a/app/models/raw_email.rb +++ b/app/models/raw_email.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # == Schema Information # # Table name: raw_emails diff --git a/app/models/request_classification.rb b/app/models/request_classification.rb index 478a543d3..ab0cd1f21 100644 --- a/app/models/request_classification.rb +++ b/app/models/request_classification.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # == Schema Information # # Table name: request_classifications @@ -15,7 +16,7 @@ class RequestClassification < ActiveRecord::Base # return classification instances representing the top n # users, with a 'cnt' attribute representing the number # of classifications the user has made. - def RequestClassification.league_table(size, conditions=[]) + def self.league_table(size, conditions=[]) find(:all, :select => 'user_id, count(*) as cnt', :conditions => conditions, :group => 'user_id', diff --git a/app/models/spam_address.rb b/app/models/spam_address.rb index 2c84beaa0..893826a96 100644 --- a/app/models/spam_address.rb +++ b/app/models/spam_address.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # == Schema Information # # Table name: spam_addresses diff --git a/app/models/track_thing.rb b/app/models/track_thing.rb index cd90c4a9e..aad7cc51b 100644 --- a/app/models/track_thing.rb +++ b/app/models/track_thing.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # == Schema Information # # Table name: track_things diff --git a/app/models/track_things_sent_email.rb b/app/models/track_things_sent_email.rb index 072d3bdea..d4f3f3f04 100644 --- a/app/models/track_things_sent_email.rb +++ b/app/models/track_things_sent_email.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # == Schema Information # # Table name: track_things_sent_emails diff --git a/app/models/user.rb b/app/models/user.rb index 8fd7851e0..d50000aba 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -39,6 +39,7 @@ class User < ActiveRecord::Base has_one :profile_photo has_many :censor_rules, :order => 'created_at desc' has_many :info_request_batches, :order => 'created_at desc' + has_many :request_classifications validates_presence_of :email, :message => _("Please enter your email address") validates_presence_of :name, :message => _("Please enter your name") @@ -197,7 +198,9 @@ class User < ActiveRecord::Base end def visible_comments - comments.find(:all, :conditions => 'visible') + warn %q([DEPRECATION] User#visible_comments will be replaced with + User#comments.visible as of 0.23).squish + comments.visible end # Don't display any leading/trailing spaces diff --git a/app/models/user_info_request_sent_alert.rb b/app/models/user_info_request_sent_alert.rb index cd163d14b..e6a6405ef 100644 --- a/app/models/user_info_request_sent_alert.rb +++ b/app/models/user_info_request_sent_alert.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # == Schema Information # # Table name: user_info_request_sent_alerts diff --git a/app/models/widget_vote.rb b/app/models/widget_vote.rb new file mode 100644 index 000000000..dda77007f --- /dev/null +++ b/app/models/widget_vote.rb @@ -0,0 +1,20 @@ +# -*- encoding : utf-8 -*- +# == Schema Information +# +# Table name: widget_votes +# +# id :integer not null, primary key +# cookie :string(255) +# info_request_id :integer not null +# created_at :datetime not null +# updated_at :datetime not null +# + +class WidgetVote < ActiveRecord::Base + belongs_to :info_request + validates :info_request, :presence => true + + attr_accessible :cookie + validates :cookie, :length => { :is => 20 } + validates_uniqueness_of :cookie, :scope => :info_request_id +end diff --git a/app/views/admin_general/index.html.erb b/app/views/admin_general/index.html.erb index ba0563bb6..8840bce74 100644 --- a/app/views/admin_general/index.html.erb +++ b/app/views/admin_general/index.html.erb @@ -2,17 +2,10 @@ <div class="row"> <div class="span12"> - <h1><%=@title%></h1> - - <ul> - <li><%=@public_body_count%> public authorities</li> - <li> - <%=@info_request_count%> requests, <%=@outgoing_message_count%> outgoing messages, - <%=@incoming_message_count%> incoming messages - </li> - <li><%=@user_count%> users, <%=@track_thing_count%> tracked things</li> - <li><%=@comment_count%> annotations</li> - </ul> + <h1><%= @title %></h1> + <p> + <%= link_to 'Summary stats have moved →', admin_stats_path %> + </p> </div> </div> @@ -28,8 +21,14 @@ <% if @holding_pen_messages.size > 0 %> <div class="accordion-group"> <div class="accordion-heading"> - <a class="accordion-toggle" href="#holding-pen" data-toggle="collapse" data-parent="things-to-do"><span class="label label-important"><%=@holding_pen_messages.size%></span><%= chevron_right %> Put misdelivered responses with the right request</a> + <a class="accordion-toggle" href="#holding-pen" data-toggle="collapse" data-parent="things-to-do"> + <span class="label label-important"> + <%= @holding_pen_messages.size %> + </span> + <%= chevron_right %> Put misdelivered responses with the right request + </a> </div> + <div id="holding-pen" class="accordion-body collapse"> <table class="table table-striped table-condensed"> <tbody> @@ -39,11 +38,13 @@ <% if message.get_body_for_quoting.strip.size == 0 %> <%= link_to "(no body)", admin_raw_email_path(message.raw_email_id) %> <% else %> - <%= link_to excerpt(message.get_body_for_quoting, "", :radius => 60), admin_raw_email_path(message.raw_email_id) %> + <%= link_to admin_raw_email_path(message.raw_email_id) do %> + <%= excerpt(message.get_body_for_quoting, "", :radius => 60) %> + <% end %> <% end %> </td> <td class="span2"> - <%=simple_date(message.sent_at)%> + <%= simple_date(message.sent_at) %> </td> </tr> <% end %> @@ -67,7 +68,7 @@ <%= request_both_links(@request) %> </td> <td class="span2"> - <%=simple_date(@request.info_request_events.last.created_at)%> + <%= simple_date(@request.last_event_time) %> </td> </tr> <% end %> @@ -92,7 +93,7 @@ <%= request_both_links(@request) %> </td> <td class="span2"> - <%=simple_date(@request.info_request_events.last.created_at)%> + <%= simple_date(@request.last_event_time) %> </td> </tr> <% end %> @@ -116,7 +117,7 @@ <%= request_both_links(@request) %> </td> <td class="span2"> - <%=simple_date(@request.info_request_events.last.created_at)%> + <%= simple_date(@request.last_event_time) %> </td> </tr> <% end %> @@ -178,18 +179,33 @@ <% if @new_body_requests.size > 0 %> <div class="accordion-group"> <div class="accordion-heading"> - <a class="accordion-toggle" href="#new-authorities" data-toggle="collapse" data-parent="things-to-do"><span class="label label-important"><%= @new_body_requests.size %></span><%= chevron_right %> Add new authorities</a> + <a class="accordion-toggle" href="#new-authorities" data-toggle="collapse" data-parent="things-to-do"> + <span class="label label-important"> + <%= @new_body_requests.size %> + </span> + <%= chevron_right %> Add new authorities + </a> </div> + <div id="new-authorities" class="accordion-body collapse"> - <% for @change_request in @new_body_requests %> - <%= render :partial => 'change_request_summary'%> - <%= form_tag admin_change_request_path(@change_request), :method => 'put', :class => "form form-horizontal" do %> - <%= submit_tag 'Close', :class => "btn btn-danger" %> - <%= link_to("Close and respond", edit_admin_change_request_path(@change_request), :class => 'btn') %> - <%= link_to("Add authority", new_admin_body_path(:change_request_id => @change_request.id), :class => 'btn btn-primary') %> - <% end %> + <% for @change_request in @new_body_requests %> + <%= render :partial => 'change_request_summary'%> - <% end %> + <%= form_tag admin_change_request_path(@change_request), + :method => 'put', + :class => "form form-horizontal" do %> + + <%= submit_tag 'Close', :class => "btn btn-danger" %> + + <%= link_to "Close and respond", + edit_admin_change_request_path(@change_request), + :class => 'btn' %> + + <%= link_to "Add authority", + new_admin_body_path(:change_request_id => @change_request.id), + :class => 'btn btn-primary' %> + <% end %> + <% end %> </div> </div> <% end %> @@ -197,17 +213,34 @@ <% if @body_update_requests.size > 0 %> <div class="accordion-group"> <div class="accordion-heading"> - <a class="accordion-toggle" href="#update-authorities" data-toggle="collapse" data-parent="things-to-do"><span class="label label-important"><%= @body_update_requests.size %></span><%= chevron_right %> Update authorities</a> + <a class="accordion-toggle" href="#update-authorities" data-toggle="collapse" data-parent="things-to-do"> + <span class="label label-important"> + <%= @body_update_requests.size %> + </span> + <%= chevron_right %> Update authorities + </a> </div> + <div id="update-authorities" class="accordion-body collapse"> <% for @change_request in @body_update_requests %> - <%= render :partial => 'change_request_summary' %> - <%= form_tag admin_change_request_path(@change_request), :class => "form form-horizontal", :method => 'put' do %> - <%= submit_tag 'Close', :class => "btn btn-danger" %> - <%= link_to("Close and respond", edit_admin_change_request_path(@change_request), :class => 'btn') %> - <%= link_to("Make update", edit_admin_body_path(@change_request.public_body, :change_request_id => @change_request.id), :class => 'btn btn-primary') %> - <% end %> + <%= render :partial => 'change_request_summary' %> + + <%= form_tag admin_change_request_path(@change_request), + :class => "form form-horizontal", + :method => 'put' do %> + + <%= submit_tag 'Close', :class => "btn btn-danger" %> + + <%= link_to "Close and respond", + edit_admin_change_request_path(@change_request), + :class => 'btn' %> + + <%= link_to "Make update", + edit_admin_body_path(@change_request.public_body, + :change_request_id => @change_request.id), + :class => 'btn btn-primary' %> <% end %> + <% end %> </div> </div> <% end %> diff --git a/app/views/admin_public_body/edit.html.erb b/app/views/admin_public_body/edit.html.erb index dcafbd270..fc9c25e8f 100644 --- a/app/views/admin_public_body/edit.html.erb +++ b/app/views/admin_public_body/edit.html.erb @@ -13,7 +13,7 @@ <div class="row"> <div class="span8"> <div class="well"> - <%= link_to 'Show', admin_bodies_path(@public_body), :class => "btn" %> + <%= link_to 'Show', admin_body_path(@public_body), :class => "btn" %> <%= link_to 'List all', admin_bodies_path, :class => "btn" %> </div> </div> diff --git a/app/views/comment/_comment_form.html.erb b/app/views/comment/_comment_form.html.erb index 6ca3f4c9f..0a6712af5 100644 --- a/app/views/comment/_comment_form.html.erb +++ b/app/views/comment/_comment_form.html.erb @@ -5,7 +5,7 @@ <% if !TrackThing.find_existing(@user, track_thing) && (!@user || @info_request.user != @user) %> <p> - <%= check_box_tag 'subscribe_to_request', "1", params[:subscribe_to_request] ? true : false %> <label for="subscribe_to_request"><%= _('Email me future updates to this request') %></label> + <%= check_box_tag 'subscribe_to_request', "1", params[:subscribe_to_request] %> <label for="subscribe_to_request"><%= _('Email me future updates to this request') %></label> </p> <% end %> diff --git a/app/views/comment/_single_comment.html.erb b/app/views/comment/_single_comment.html.erb index 07017dabf..badc39d9a 100644 --- a/app/views/comment/_single_comment.html.erb +++ b/app/views/comment/_single_comment.html.erb @@ -1,4 +1,4 @@ -<div class="comment_in_request" id="comment-<%=comment.id.to_s%>"> +<div class="comment_in_request box" id="comment-<%=comment.id.to_s%>"> <% if comment.user && comment.user.profile_photo && !@render_to_file %> <div class="user_photo_on_comment"> <img src="<%= get_profile_photo_url(:url_name => comment.user.url_name) %>" alt=""> diff --git a/app/views/general/_responsive_topnav.html.erb b/app/views/general/_responsive_topnav.html.erb index 0af6629c8..c99864cab 100644 --- a/app/views/general/_responsive_topnav.html.erb +++ b/app/views/general/_responsive_topnav.html.erb @@ -21,11 +21,16 @@ </li> <li id="navigation_search"> - <form id="navigation_search_form" method="get" action="<%= search_redirect_path %>"> - <label for="navigation_search_button"> - <img src="/assets/search.png" alt="Search:"> + <form id="navigation_search_form" method="get" action="<%= search_redirect_path %>" role="search"> + <label class="visually-hidden" for="navigation_search_button"> + <%= _("Search") %> </label> - <%= text_field_tag 'query', params[:query], { :id => "navigation_search_button", :title => "type your search term here" } %> + <%= text_field_tag 'query', params[:query], { :id => "navigation_search_button", :type => "search", :placeholder => _("Search"), :title => _("type your search term here") } %> + <button type="submit"> + <span class="visually-hidden"> + <%= _("Submit Search") %> + </span> + </button> </form> </li> </ul> diff --git a/app/views/help/unhappy.html.erb b/app/views/help/unhappy.html.erb index 79e3f8273..c0444fb54 100644 --- a/app/views/help/unhappy.html.erb +++ b/app/views/help/unhappy.html.erb @@ -101,9 +101,8 @@ contact any registered user from their page. There may be an Internet forum or group that they hang out in. If it is a local matter, use <a href="http://www.groupsnearyou.com">GroupsNearYou</a> to find such a forum.</li> -<li><strong>Start a pledge</strong> on <a href="http://www.pledgebank.com">PledgeBank</a> to get -others to act together with you. For example, you could arrange a meeting with -staff from the authority. Or you could form a small local campaigns group. +<li>You could form a small local campaign group and arrange a meeting +with staff from the authority.</li> </ul> diff --git a/app/views/public_body/show.html.erb b/app/views/public_body/show.html.erb index 016c2460d..9dd3dc7cb 100644 --- a/app/views/public_body/show.html.erb +++ b/app/views/public_body/show.html.erb @@ -42,12 +42,12 @@ </div> <% end %> - <% if @public_body.info_requests.size > 0 %> + <% if @number_of_visible_requests > 0 %> <div class="authority__header__stats"> <%= n_('{{count}} request', '{{count}} requests', - @public_body.info_requests.size, - :count => @public_body.info_requests.size) %> + @number_of_visible_requests, + :count => @number_of_visible_requests) %> </div> <% end %> @@ -81,7 +81,7 @@ <div class="authority__body"> <div class="authority__body__foi-results"> - <% if @public_body.info_requests.size == 0 %> + <% if @number_of_visible_requests == 0 %> <% if @public_body.is_requestable? or @public_body.not_requestable_reason != 'defunct' %> <% if @public_body.eir_only? %> <h2><%= _('Environmental Information Regulations requests made using this site') %></h2> @@ -99,7 +99,7 @@ <% end %> <a name="results"></a> - <% if @public_body.info_requests.size > 4 %> + <% if @number_of_visible_requests > 4 %> <%= render :partial => 'request/request_filter_form' %> <% end %> <% end %> @@ -132,7 +132,7 @@ </div> <div class="authority__body__sidebar"> - <% if @public_body.info_requests.size > 4 %> + <% if @number_of_visible_requests > 4 %> <%= render :partial => 'request/request_search_form' %> <% end %> <%= render :partial => 'more_info', :locals => { :public_body => @public_body } %> diff --git a/app/views/public_body_change_requests/new.html.erb b/app/views/public_body_change_requests/new.html.erb index b52d583be..9abe03732 100644 --- a/app/views/public_body_change_requests/new.html.erb +++ b/app/views/public_body_change_requests/new.html.erb @@ -12,7 +12,7 @@ <p> <label class="form_label" for="user_email"> - <%= ("Your email:") %> + <%= _("Your email:") %> </label> <%= f.text_field :user_email %> </p> diff --git a/app/views/request/_act.html.erb b/app/views/request/_act.html.erb index 878cdf4ff..c7bbd287f 100644 --- a/app/views/request/_act.html.erb +++ b/app/views/request/_act.html.erb @@ -20,3 +20,8 @@ <% end %> <%= link_to _("Start your own blog"), "http://wordpress.com/"%> </div> +<% if AlaveteliConfiguration::enable_widgets %> + <div class="act_link"> + <%= link_to _("Create a widget for this request"), new_request_widget_path(@info_request) %> + </div> +<% end %> diff --git a/app/views/request/_followup.html.erb b/app/views/request/_followup.html.erb index 2643b767f..24cede824 100644 --- a/app/views/request/_followup.html.erb +++ b/app/views/request/_followup.html.erb @@ -20,7 +20,7 @@ </h2> <% end %> <% if @info_request.who_can_followup_to(incoming_message).count > 0 %> -<div id="other_recipients"> +<div id="other_recipients" class="box"> <%= _("Don't want to address your message to {{person_or_body}}? You can also write to:", :person_or_body => name_for_followup) %> <ul> <% @info_request.who_can_followup_to(incoming_message).each do |name, email, id| %> diff --git a/app/views/request/_incoming_correspondence.html.erb b/app/views/request/_incoming_correspondence.html.erb index 70bd25c7f..9d205204e 100644 --- a/app/views/request/_incoming_correspondence.html.erb +++ b/app/views/request/_incoming_correspondence.html.erb @@ -1,4 +1,4 @@ -<div class="incoming correspondence <%= incoming_message.prominence %>" id="incoming-<%=incoming_message.id.to_s%>"> +<div class="incoming correspondence box <%= incoming_message.prominence %>" id="incoming-<%=incoming_message.id.to_s%>"> <%- if not incoming_message.user_can_view?(@user) %> <%= render :partial => 'request/hidden_correspondence', :locals => { :message => incoming_message }%> <%- else %> diff --git a/app/views/request/_outgoing_correspondence.html.erb b/app/views/request/_outgoing_correspondence.html.erb index dced5c94c..3b85cae7f 100644 --- a/app/views/request/_outgoing_correspondence.html.erb +++ b/app/views/request/_outgoing_correspondence.html.erb @@ -1,4 +1,4 @@ -<div class="outgoing correspondence" id="outgoing-<%=outgoing_message.id.to_s%>"> +<div class="outgoing correspondence box" id="outgoing-<%=outgoing_message.id.to_s%>"> <%- if not outgoing_message.user_can_view?(@user) %> <%= render :partial => 'request/hidden_correspondence', :locals => { :message => outgoing_message }%> <%- else %> diff --git a/app/views/request/_resent_outgoing_correspondence.html.erb b/app/views/request/_resent_outgoing_correspondence.html.erb index 17b6b635b..287a5cac5 100644 --- a/app/views/request/_resent_outgoing_correspondence.html.erb +++ b/app/views/request/_resent_outgoing_correspondence.html.erb @@ -1,4 +1,4 @@ -<div class="outgoing correspondence" id="outgoing-<%=outgoing_message.id.to_s%>"> +<div class="outgoing correspondence box" id="outgoing-<%=outgoing_message.id.to_s%>"> <h2> <%= simple_date(info_request_event.created_at) %> </h2> diff --git a/app/views/request/new.html.erb b/app/views/request/new.html.erb index 486a89d45..23f7ad76a 100644 --- a/app/views/request/new.html.erb +++ b/app/views/request/new.html.erb @@ -144,7 +144,7 @@ <% if @info_request.public_body.info_requests.size > 0 %> <%= _("Browse <a href='{{url}}'>other requests</a> to '{{public_body_name}}' for examples of how to word your request.", :public_body_name=>h(@info_request.public_body.name), :url=>public_body_path(@info_request.public_body)) %> <% else %> - <%= _("Browse <a href='{{url}}'>other requests</a> for examples of how to word your request.", :url=>request_list_url) %> + <%= _("Browse <a href='{{url}}'>other requests</a> for examples of how to word your request.", :url=>request_list_successful_url) %> <% end %> </p> <% end %> @@ -156,7 +156,7 @@ this website <a href="{{url}}">forever</a>', :url => (help_privacy_path+"#public_request").html_safe)) %>. </p> <p> - <%= raw(_('<a href="{{url}}">Thinking of using a pseudonym?</a>.', :url => (help_privacy_path+"#real_name").html_safe)) %> + <%= raw(_('<a href="{{url}}">Thinking of using a pseudonym?</a>', :url => (help_privacy_path+"#real_name").html_safe)) %> </p> <% else %> <p> diff --git a/app/views/request/new_bad_contact.html.erb b/app/views/request/new_bad_contact.html.erb index 56f3f4168..f9881b62b 100644 --- a/app/views/request/new_bad_contact.html.erb +++ b/app/views/request/new_bad_contact.html.erb @@ -5,6 +5,6 @@ <p><%= _('Unfortunately, we do not have a working {{info_request_law_used_full}} address for', :info_request_law_used_full => @info_request.law_used_full) %> <%=h @info_request.public_body.name %>. <%= _('You may be able to find one on their website, or by phoning them up and asking. If you manage -to find one, then please <a href="{{help_url}}">send it to us</a>.', :help_url => help_contact_path) %> +to find one, then please <a href="{{help_url}}">send it to us</a>.', :help_url => new_change_request_path(:body => @info_request.public_body.url_name)) %> </p> diff --git a/app/views/request/show.html.erb b/app/views/request/show.html.erb index 78e022aa9..5862413de 100644 --- a/app/views/request/show.html.erb +++ b/app/views/request/show.html.erb @@ -22,7 +22,7 @@ <% if ( @update_status || @info_request.awaiting_description ) && ! @info_request.is_external? %> - <div class="describe_state_form" id="describe_state_form_1"> + <div class="describe_state_form box" id="describe_state_form_1"> <%= render :partial => 'describe_state', :locals => { :id_suffix => "1" } %> </div> <% end %> @@ -146,7 +146,7 @@ <% end %> <% if @info_request.awaiting_description && ! @info_request.is_external? %> - <div class="describe_state_form" id="describe_state_form_2"> + <div class="describe_state_form box" id="describe_state_form_2"> <%= render :partial => 'describe_state', :locals => { :id_suffix => "2" } %> </div> <% end %> diff --git a/app/views/request_game/play.html.erb b/app/views/request_game/play.html.erb index 471a0e09e..44fe641f9 100644 --- a/app/views/request_game/play.html.erb +++ b/app/views/request_game/play.html.erb @@ -2,7 +2,12 @@ <div id="game_sidebar"> <p style="text-align: center"> - <img width=250 height=125 src="http://chart.apis.google.com/chart?chs=250x125&cht=gom&chd=t:<%=@percentage%>" alt="<%=@percentage%>% of requests have been categorised"> + <%= + image_tag "https://chart.googleapis.com/chart?chs=250x125&cht=gom&chd=t:#{@percentage}", + :size => "250x125", + :alt => "A chart showing #{@percentage}% of requests have been categorised", + :title => "#{@percentage}% of requests have been categorised" + %> <br><%=pluralize(@missing, 'request')%> left to categorise / <%=@total %> total </p> diff --git a/app/views/user/_user_listing_single.html.erb b/app/views/user/_user_listing_single.html.erb index 3cb0d283f..03ac7347b 100644 --- a/app/views/user/_user_listing_single.html.erb +++ b/app/views/user/_user_listing_single.html.erb @@ -17,7 +17,7 @@ end %> <span class="bottomline"> <%= pluralize(display_user.info_requests.size, "request") %> <%= _('made.')%> - <%= pluralize(display_user.visible_comments.size, "annotation") %> <%= _('made.')%> + <%= pluralize(display_user.comments.visible.size, "annotation") %> <%= _('made.')%> <%= _('Joined in')%> <%= display_user.created_at.year %>. </span> diff --git a/app/views/user/show.html.erb b/app/views/user/show.html.erb index 78b513d6a..a67663389 100644 --- a/app/views/user/show.html.erb +++ b/app/views/user/show.html.erb @@ -173,7 +173,7 @@ <% end %> <% else %> <h2 id="annotations"> - <%= @is_you ? n_('Your {{count}} annotation', 'Your {{count}} annotations', @display_user.visible_comments.size, :count => @display_user.visible_comments.size) : n_("This person's {{count}} annotation", "This person's {{count}} annotations", @display_user.visible_comments.size, :count => @display_user.visible_comments.size) %> + <%= @is_you ? n_('Your {{count}} annotation', 'Your {{count}} annotations', @display_user.comments.visible.size, :count => @display_user.comments.visible.size) : n_("This person's {{count}} annotation", "This person's {{count}} annotations", @display_user.comments.visible.size, :count => @display_user.comments.visible.size) %> <!-- matches_estimated <%=@xapian_comments.matches_estimated%> --> <%= @page_desc %> </h2> @@ -182,7 +182,7 @@ <%= render :partial => 'request/request_listing_via_event', :locals => { :event => result[:model] } %> <% end %> - <%= will_paginate WillPaginate::Collection.new(@page, @per_page, @display_user.visible_comments.size) %> + <%= will_paginate WillPaginate::Collection.new(@page, @per_page, @display_user.comments.visible.size) %> <% end %> <% end %> diff --git a/app/views/widgets/new.html.erb b/app/views/widgets/new.html.erb new file mode 100644 index 000000000..c706155a5 --- /dev/null +++ b/app/views/widgets/new.html.erb @@ -0,0 +1,15 @@ +<h1>Add a widget</h1> + +<p> +To add a widget for <b><%= @info_request.title %></b>, copy and paste the +following code to your web page: +<textarea autofocus readonly rows='4' cols='60' id='widgetbox'> +<iframe src='<%= request_widget_url(@info_request) %>' width='320' height='215' frameborder='0' marginwidth='0' marginheight='0'></iframe> +</textarea> +</p> + +<p> +The widget will look like this: +<br> +<iframe src='<%= request_widget_url(@info_request) %>' width='320' height='215' frameborder='0' marginwidth='0' marginheight='0'></iframe> +</p> diff --git a/app/views/widgets/show.html.erb b/app/views/widgets/show.html.erb new file mode 100644 index 000000000..07c7b1908 --- /dev/null +++ b/app/views/widgets/show.html.erb @@ -0,0 +1,48 @@ +<head> + <%= stylesheet_link_tag "widget" %> +</head> +<body> + <div class="alaveteli-widget"> + <div class="alaveteli-widget__top"> + <div class="alaveteli-widget__left"> + <div class="alaveteli-widget__title"> + <%= link_to @info_request.title, request_path(@info_request), :target => "_top" %> + </div> + <div class="alaveteli-widget__status <%= @status %>"> + <p class="alaveteli-widget__status__status-label">Status</p> + <%= status_description(@info_request, @status) %> + </div> + </div> + <div class="alaveteli-widget__people-count"> + <%= n_('<div class="alaveteli-widget__count">{{count}}</div> person wants to know', '<div class="alaveteli-widget__count">{{count}}</div> people want to know', @count, :count => @count) %> + </div> + </div> + + + <div class="alaveteli-widget__bottom"> + <% if @info_request.user && @info_request.user == @user %> + <div class="alaveteli-widget__button alaveteli-widget__button--down"> + <%= _('This is your request') %> + </div> + <% elsif @existing_track %> + <a href="<%= url_for :controller => 'track', :action => 'update', :track_id => @existing_track.id, :track_medium => "delete", :r => request.fullpath %>"> + <div class="alaveteli-widget__button--down"> + <%= _('You are tracking this request') %> + </div> + </a> + <% else %> + <% if @user %> + <a href="<%= url_for do_track_path(@track_thing) %>" target="_blank"> + <div class="alaveteli-widget__button"> + <%= _('I also want to know!') %> + </div> + </a> + <% else %> + <%= form_tag request_widget_url(@info_request), :method => 'put', :target => '_blank' do %> + <%= submit_tag _('I also want to know!'), :class => 'alaveteli-widget__button' %> + <% end %> + <% end %> + <% end %> + </div> + </div> +</body> diff --git a/commonlib b/commonlib -Subproject 2a0271d3a6aaba9c429261b8c94e0e7acb6bd68 +Subproject dcc2e223ae1f76ed7db80b45ea12297e01bf5d4 diff --git a/config/.cvsignore b/config/.cvsignore deleted file mode 100644 index 2539dd3cd..000000000 --- a/config/.cvsignore +++ /dev/null @@ -1,3 +0,0 @@ -general -database.yml -rails_env.rb diff --git a/config/alert-tracks-debian.ugly b/config/alert-tracks-debian.example index f1ca68b03..a098bc332 100755 --- a/config/alert-tracks-debian.ugly +++ b/config/alert-tracks-debian.example @@ -41,7 +41,7 @@ start_daemon() { } stop_daemon() { - /sbin/start-stop-daemon --stop --oknodo --pidfile "$PIDFILE" + /sbin/start-stop-daemon --stop --oknodo --retry 5 --pidfile "$PIDFILE" } restart() { stop; start; } diff --git a/config/application.rb b/config/application.rb index 3c01e26c4..eccf0937c 100644 --- a/config/application.rb +++ b/config/application.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path('../boot', __FILE__) require 'rails/all' @@ -60,7 +61,8 @@ module Alaveteli config.time_zone = ::AlaveteliConfiguration::time_zone # Set the cache to use a memcached backend - config.cache_store = :mem_cache_store, { :namespace => AlaveteliConfiguration::domain } + config.cache_store = :mem_cache_store, + { :namespace => "#{AlaveteliConfiguration::domain}_#{RUBY_VERSION}" } config.action_dispatch.rack_cache = nil config.after_initialize do |app| @@ -69,6 +71,7 @@ module Alaveteli app.routes.append{ match '*path', :to => 'general#not_found' } end + config.autoload_paths << "#{Rails.root.to_s}/app/models/concerns" config.autoload_paths << "#{Rails.root.to_s}/lib/mail_handler" config.autoload_paths << "#{Rails.root.to_s}/lib/attachment_to_html" config.autoload_paths << "#{Rails.root.to_s}/lib/health_checks" @@ -116,6 +119,7 @@ module Alaveteli 'ie6.css', 'ie7.css', 'bootstrap-dropdown.js', + 'widget.css', 'responsive/print.css', 'responsive/application-lte-ie7.css', 'responsive/application-ie8.css'] diff --git a/config/boot.rb b/config/boot.rb index a810be358..25da6546e 100644 --- a/config/boot.rb +++ b/config/boot.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require 'rubygems' # Set up gems listed in the Gemfile. diff --git a/config/crontab-example b/config/crontab-example index f65555b11..bfcba0568 100644 --- a/config/crontab-example +++ b/config/crontab-example @@ -16,9 +16,7 @@ MAILTO=!!(*= $mailto *)!! # Once an hour 09 * * * * !!(*= $user *)!! !!(*= $vhost_dir *)!!/!!(*= $vcspath *)!!/commonlib/bin/run-with-lockfile.sh -n !!(*= $vhost_dir *)!!/alert-comment-on-request.lock !!(*= $vhost_dir *)!!/!!(*= $vcspath *)!!/script/alert-comment-on-request || echo "stalled?" - -# Only root can read the log files -31 * * * * root !!(*= $vhost_dir *)!!/!!(*= $vcspath *)!!/commonlib/bin/run-with-lockfile.sh -n !!(*= $vhost_dir *)!!/load-mail-server-logs.lock !!(*= $vhost_dir *)!!/!!(*= $vcspath *)!!/script/load-mail-server-logs || echo "stalled?" +31 * * * * !!(*= $user *)!! !!(*= $vhost_dir *)!!/!!(*= $vcspath *)!!/commonlib/bin/run-with-lockfile.sh -n !!(*= $vhost_dir *)!!/load-mail-server-logs.lock !!(*= $vhost_dir *)!!/!!(*= $vcspath *)!!/script/load-mail-server-logs || echo "stalled?" # Once a day, early morning 31 1 * * * !!(*= $user *)!! !!(*= $vhost_dir *)!!/!!(*= $vcspath *)!!/commonlib/bin/run-with-lockfile.sh -n !!(*= $vhost_dir *)!!/change-xapian-database.lock "!!(*= $vhost_dir *)!!/!!(*= $vcspath *)!!/script/compact-xapian-database production !!(*= $site *)!!" || echo "stalled?" diff --git a/config/deploy.rb b/config/deploy.rb index f4a0b536a..6998b3ed7 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require 'bundler/capistrano' set :stage, 'staging' unless exists? :stage @@ -58,6 +59,7 @@ namespace :deploy do "#{release_path}/log" => "#{shared_path}/log", "#{release_path}/tmp/pids" => "#{shared_path}/tmp/pids", "#{release_path}/lib/acts_as_xapian/xapiandbs" => "#{shared_path}/xapiandbs", + "#{release_path}/lib/themes" => "#{shared_path}/themes", } # "ln -sf <a> <b>" creates a symbolic link but deletes <b> if it already exists @@ -70,6 +72,7 @@ namespace :deploy do run "mkdir -p #{shared_path}/log" run "mkdir -p #{shared_path}/tmp/pids" run "mkdir -p #{shared_path}/xapiandbs" + run "mkdir -p #{shared_path}/themes" end end diff --git a/config/environment.rb b/config/environment.rb index 196680b23..ca436cc29 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # Load the rails application require File.expand_path('../application', __FILE__) diff --git a/config/environments/development.rb b/config/environments/development.rb index dbf8d7b2a..39bd98da1 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- Alaveteli::Application.configure do # Settings specified here will take precedence over those in config/environment.rb @@ -46,4 +47,12 @@ Alaveteli::Application.configure do # with SQLite, MySQL, and PostgreSQL) config.active_record.auto_explain_threshold_in_seconds = 0.5 + if AlaveteliConfiguration.use_bullet_in_development + config.after_initialize do + Bullet.enable = true + Bullet.bullet_logger = true + Bullet.console = true + Bullet.add_footer = true + end + end end diff --git a/config/environments/production.rb b/config/environments/production.rb index a3e3cebd2..bc5b724d0 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- Alaveteli::Application.configure do # Settings specified here will take precedence over those in config/environment.rb @@ -17,7 +18,20 @@ Alaveteli::Application.configure do # Disable delivery errors, bad email addresses will be ignored # config.action_mailer.raise_delivery_errors = false - config.action_mailer.delivery_method = :sendmail # so is queued, rather than giving immediate errors + + config.action_mailer.delivery_method = AlaveteliConfiguration::production_mailer_delivery_method.to_sym + + if AlaveteliConfiguration::production_mailer_delivery_method.to_sym == :smtp + config.action_mailer.smtp_settings = { + :address => AlaveteliConfiguration::smtp_mailer_address, + :port => AlaveteliConfiguration.smtp_mailer_port, + :domain => AlaveteliConfiguration.smtp_mailer_domain, + :user_name => AlaveteliConfiguration.smtp_mailer_user_name, + :password => AlaveteliConfiguration.smtp_mailer_password, + :authentication => AlaveteliConfiguration.smtp_mailer_authentication, + :enable_starttls_auto => AlaveteliConfiguration.smtp_mailer_enable_starttls_auto + } + end config.active_support.deprecation = :notify diff --git a/config/environments/staging.rb b/config/environments/staging.rb index 0bb0db71a..0d791e03e 100644 --- a/config/environments/staging.rb +++ b/config/environments/staging.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- Alaveteli::Application.configure do # Settings specified here will take precedence over those in config/environment.rb diff --git a/config/environments/test.rb b/config/environments/test.rb index 97c2d4f7c..483a4874f 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- Alaveteli::Application.configure do # Settings specified here will take precedence over those in config/environment.rb diff --git a/config/general.yml-example b/config/general.yml-example index 8acea374b..a6980b71c 100644 --- a/config/general.yml-example +++ b/config/general.yml-example @@ -673,6 +673,14 @@ PUBLIC_BODY_LIST_FALLBACK_TO_DEFAULT_LOCALE: false # --- USE_MAILCATCHER_IN_DEVELOPMENT: true +# Bullet is a tool to help to kill N+1 queries and unused eager loading +# https://github.com/flyerhzm/bullet +# +# USE_BULLET_IN_DEVELOPMENT - Boolean (default: false) +# +# --- +USE_BULLET_IN_DEVELOPMENT: false + # Use memcached to cache HTML fragments for better performance. This will # only have an effect in environments where # config.action_controller.perform_caching is set to true @@ -775,3 +783,38 @@ ALLOW_BATCH_REQUESTS: false # # --- RESPONSIVE_STYLING: true + +# Define the mailer delivery method to be used only in the production environment. +# By default, use sendmail. +# +# The list of accepted options are available in the Rails ActionMailer configuration +# documentation: http://guides.rubyonrails.org/action_mailer_basics.html#example-action-mailer-configuration +# +# The most common alternative is to use 'smtp' +# If you choose to use an external SMTP service then you will need to also include the SMTP configuration settings. +# +# As a string this is coerced into a symbol in config/environments/production.rb +# +# PRODUCTION_MAILER_DELIVERY_METHOD - String (default: sendmail) +# +# Examples: +# +# PRODUCTION_MAILER_DELIVERY_METHOD: smtp +# SMTP_MAILER_ADDRESS: smtp.gmail.com +# SMTP_MAILER_PORT: 587 +# SMTP_MAILER_DOMAIN: example.com +# SMTP_MAILER_USER_NAME: jane322 +# SMTP_MAILER_PASSWORD: supersecretpassword +# SMTP_MAILER_AUTHENTICATION: 'plain' +# SMTP_MAILER_ENABLE_STARTTLS_AUTO: true +# --- +PRODUCTION_MAILER_DELIVERY_METHOD: sendmail + +# If ENABLE_WIDGETS is set to true, Alaveteli will allow the embedding of a +# 'widget' linking to a request on other sites. This widget will record +# how many people click on an 'I also want to know' button. +# +# ENABLE_WIDGETS - Boolean (default: false) +# +# --- +ENABLE_WIDGETS: false diff --git a/config/initializers/acts_as_xapian.rb b/config/initializers/acts_as_xapian.rb index f82193c85..56eb75ed3 100644 --- a/config/initializers/acts_as_xapian.rb +++ b/config/initializers/acts_as_xapian.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # acts_as_xapian/init.rb: # # Copyright (c) 2008 UK Citizens Online Democracy. All rights reserved. diff --git a/config/initializers/alaveteli.rb b/config/initializers/alaveteli.rb index b71942e30..fe385b146 100644 --- a/config/initializers/alaveteli.rb +++ b/config/initializers/alaveteli.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # MySociety specific helper functions $:.push(File.join(File.dirname(__FILE__), '../../commonlib/rblib')) # ... if these fail to include, you need the commonlib submodule from git @@ -35,7 +36,6 @@ end # Load monkey patches and other things from lib/ -require 'ruby19.rb' require 'activesupport_cache_extensions.rb' require 'use_spans_for_errors.rb' require 'activerecord_errors_extensions.rb' diff --git a/config/initializers/backtrace_silencers.rb b/config/initializers/backtrace_silencers.rb index 59385cdf3..b5e9a55a2 100644 --- a/config/initializers/backtrace_silencers.rb +++ b/config/initializers/backtrace_silencers.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # Be sure to restart your server when you modify this file. # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. diff --git a/config/initializers/fast_gettext.rb b/config/initializers/fast_gettext.rb index b00524993..c7fcc480b 100644 --- a/config/initializers/fast_gettext.rb +++ b/config/initializers/fast_gettext.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- AlaveteliLocalization.set_default_text_domain('app', File.join(Rails.root, 'locale')) I18n::Backend::Simple.send(:include, I18n::Backend::Fallbacks) diff --git a/config/initializers/gettext_i18n_rails.rb b/config/initializers/gettext_i18n_rails.rb index ef306682b..3beb2e58b 100644 --- a/config/initializers/gettext_i18n_rails.rb +++ b/config/initializers/gettext_i18n_rails.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # FIXME: Audit the translations for XSS opportunities. Ultimately it would be # good to get rid of this and explicitly mark strings as html_safe GettextI18nRails.translations_are_html_safe = true diff --git a/config/initializers/has_tag_string.rb b/config/initializers/has_tag_string.rb index 5fa33cc70..c9f66414f 100644 --- a/config/initializers/has_tag_string.rb +++ b/config/initializers/has_tag_string.rb @@ -1,2 +1,3 @@ +# -*- encoding : utf-8 -*- require 'has_tag_string/has_tag_string' diff --git a/config/initializers/health_checks.rb b/config/initializers/health_checks.rb index 7fd1d3dda..f85b7b272 100644 --- a/config/initializers/health_checks.rb +++ b/config/initializers/health_checks.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- Rails.application.config.after_initialize do user_last_created = HealthChecks::Checks::DaysAgoCheck.new( :failure_message => _('The last user was created over a day ago'), diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb index 9e8b0131f..e3c680d36 100644 --- a/config/initializers/inflections.rb +++ b/config/initializers/inflections.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # Be sure to restart your server when you modify this file. # Add new inflection rules using the following format diff --git a/config/initializers/mime_types.rb b/config/initializers/mime_types.rb index 72aca7e44..9070e0caa 100644 --- a/config/initializers/mime_types.rb +++ b/config/initializers/mime_types.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # Be sure to restart your server when you modify this file. # Add new mime types for use in respond_to blocks: diff --git a/config/initializers/secret_token.rb b/config/initializers/secret_token.rb index d120b94ae..78b86f92c 100644 --- a/config/initializers/secret_token.rb +++ b/config/initializers/secret_token.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # Be sure to restart your server when you modify this file. # Your secret key for verifying the integrity of signed cookies. diff --git a/config/initializers/secure_headers.rb b/config/initializers/secure_headers.rb index 99730e6b2..af476c78c 100644 --- a/config/initializers/secure_headers.rb +++ b/config/initializers/secure_headers.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- ::SecureHeaders::Configuration.configure do |config| # https://tools.ietf.org/html/rfc6797 diff --git a/config/initializers/session_store.rb b/config/initializers/session_store.rb index ca283d4e0..c582ebc87 100644 --- a/config/initializers/session_store.rb +++ b/config/initializers/session_store.rb @@ -1,2 +1,3 @@ +# -*- encoding : utf-8 -*- # Be sure to restart your server when you modify this file. Rails.application.config.session_store :cookie_store, :key => '_wdtk_cookie_session' diff --git a/config/initializers/strip_attributes.rb b/config/initializers/strip_attributes.rb index 25f70b2f3..2bdc17f21 100644 --- a/config/initializers/strip_attributes.rb +++ b/config/initializers/strip_attributes.rb @@ -1,2 +1,3 @@ +# -*- encoding : utf-8 -*- require 'strip_attributes/strip_attributes' ActiveRecord::Base.extend(StripAttributes) diff --git a/config/initializers/theme_loader.rb b/config/initializers/theme_loader.rb index 9c79e513c..cdc34fe31 100644 --- a/config/initializers/theme_loader.rb +++ b/config/initializers/theme_loader.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # This is a global array of route extensions. Alaveteli modules may add to it. # It is used by our config/routes.rb to decide which route extension files to load. $alaveteli_route_extensions = [] diff --git a/config/packages.debian-wheezy b/config/packages.debian-wheezy index 4129aa930..ff1a55d84 100644 --- a/config/packages.debian-wheezy +++ b/config/packages.debian-wheezy @@ -35,3 +35,4 @@ wkhtmltopdf-static wv xapian-tools xlhtml +ttf-bitstream-vera diff --git a/config/preinitializer.rb b/config/preinitializer.rb index 3ad02415d..71112a28e 100644 --- a/config/preinitializer.rb +++ b/config/preinitializer.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- begin require "rubygems" require "bundler" diff --git a/config/purge-varnish-debian.ugly b/config/purge-varnish-debian.example index dc3f74ff6..457a77ed8 100755 --- a/config/purge-varnish-debian.ugly +++ b/config/purge-varnish-debian.example @@ -43,7 +43,7 @@ start_daemon() { } stop_daemon() { - /sbin/start-stop-daemon --stop --oknodo --pidfile "$PIDFILE" + /sbin/start-stop-daemon --stop --oknodo --retry 5 --pidfile "$PIDFILE" } restart() { stop; start; } diff --git a/config/routes.rb b/config/routes.rb index c975d6007..ba378119e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,4 @@ -# encoding: UTF-8 +# -*- encoding : utf-8 -*- # config/routes.rb: # Mapping URLs to controllers for FOIFA. # @@ -65,6 +65,7 @@ Alaveteli::Application.routes.draw do resources :request, :only => [] do resource :report, :only => [:new, :create] + resource :widget, :only => [:new, :show, :update] end resources :info_request_batch, :only => :show @@ -142,6 +143,7 @@ Alaveteli::Application.routes.draw do match '/track/update/:track_id' => 'track#update', :as => :update match '/track/delete_all_type' => 'track#delete_all_type', :as => :delete_all_type match '/track/feed/:track_id' => 'track#atom_feed', :as => :atom_feed + match '/track/widget_vote/:info_request_id' => 'track#widget_vote', :as => :widget_vote #### #### Help controller diff --git a/config/sysvinit-passenger.ugly b/config/sysvinit-passenger.example index 0940a4d63..0940a4d63 100755 --- a/config/sysvinit-passenger.ugly +++ b/config/sysvinit-passenger.example diff --git a/config/sysvinit-thin.ugly b/config/sysvinit-thin.example index 0155ff8c3..0155ff8c3 100755 --- a/config/sysvinit-thin.ugly +++ b/config/sysvinit-thin.example diff --git a/config/varnish-alaveteli.vcl b/config/varnish-alaveteli.vcl index d3726682c..59d76b0d1 100644 --- a/config/varnish-alaveteli.vcl +++ b/config/varnish-alaveteli.vcl @@ -2,10 +2,10 @@ # of Alaveteli. See the vcl(7) man page for details on VCL syntax and # semantics. -# +# # Default backend definition. Set this to point to your content # server. In this case, apache + Passenger running on port 80 -# +# backend default { .host = "127.0.0.1"; @@ -32,7 +32,7 @@ sub vcl_recv { # Sanitise X-Forwarded-For... remove req.http.X-Forwarded-For; set req.http.X-Forwarded-For = client.ip; - + # Remove Google Analytics, has_js, and last-seen cookies set req.http.Cookie = regsuball(req.http.Cookie, "(^|;\s*)(__[a-z]+|has_js|has_seen_country_message|seen_foi2)=[^;]*", ""); @@ -50,14 +50,14 @@ sub vcl_recv { remove req.http.Accept-Encoding; } } - + # Ignore empty cookies if (req.http.Cookie ~ "^\s*$") { remove req.http.Cookie; } - + if (req.request != "GET" && - req.request != "HEAD" && + req.request != "HEAD" && req.request != "POST" && req.request != "PUT" && req.request != "PURGE" && @@ -70,9 +70,9 @@ sub vcl_recv { /* We only deal with GET and HEAD by default, the rest get passed direct to backend */ return (pass); } - + # Ignore Cookies on images... - if (req.url ~ "\.(png|gif|jpg|jpeg|swf|css|js|rdf|ico|txt)(\?.*|)$") { + if (req.url ~ "\.(png|gif|jpg|jpeg|swf|css|js|rdf|ico)(\?.*|)$") { remove req.http.Cookie; return (lookup); } diff --git a/db/migrate/001_create_users.rb b/db/migrate/001_create_users.rb index ba528c038..4181a37d4 100644 --- a/db/migrate/001_create_users.rb +++ b/db/migrate/001_create_users.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class CreateUsers < ActiveRecord::Migration def self.up create_table :users do |t| diff --git a/db/migrate/002_add_sessions.rb b/db/migrate/002_add_sessions.rb index 22b4a0065..571321683 100644 --- a/db/migrate/002_add_sessions.rb +++ b/db/migrate/002_add_sessions.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AddSessions < ActiveRecord::Migration def self.up create_table :sessions do |t| diff --git a/db/migrate/004_create_info_requests.rb b/db/migrate/004_create_info_requests.rb index 29a3a9f22..7de918c3f 100644 --- a/db/migrate/004_create_info_requests.rb +++ b/db/migrate/004_create_info_requests.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class CreateInfoRequests < ActiveRecord::Migration def self.up create_table :info_requests do |t| diff --git a/db/migrate/005_create_public_bodies.rb b/db/migrate/005_create_public_bodies.rb index d37def301..9d51e4942 100644 --- a/db/migrate/005_create_public_bodies.rb +++ b/db/migrate/005_create_public_bodies.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class CreatePublicBodies < ActiveRecord::Migration def self.up create_table :public_bodies do |t| diff --git a/db/migrate/006_version_public_body.rb b/db/migrate/006_version_public_body.rb index 0e4527133..3656f738f 100644 --- a/db/migrate/006_version_public_body.rb +++ b/db/migrate/006_version_public_body.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class VersionPublicBody < ActiveRecord::Migration def self.up PublicBody.create_versioned_table diff --git a/db/migrate/007_add_public_body_editor_notes.rb b/db/migrate/007_add_public_body_editor_notes.rb index 7500ee649..d07e02b2e 100644 --- a/db/migrate/007_add_public_body_editor_notes.rb +++ b/db/migrate/007_add_public_body_editor_notes.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AddPublicBodyEditorNotes < ActiveRecord::Migration def self.up add_column :public_bodies, :last_edit_editor, :string diff --git a/db/migrate/008_request_has_public_body.rb b/db/migrate/008_request_has_public_body.rb index c7a2e9f34..95fa2731a 100644 --- a/db/migrate/008_request_has_public_body.rb +++ b/db/migrate/008_request_has_public_body.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class RequestHasPublicBody < ActiveRecord::Migration def self.up add_column :info_requests, :public_body_id, :integer diff --git a/db/migrate/009_create_outgoing_messages.rb b/db/migrate/009_create_outgoing_messages.rb index 62bf25392..a36d37cf2 100644 --- a/db/migrate/009_create_outgoing_messages.rb +++ b/db/migrate/009_create_outgoing_messages.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class CreateOutgoingMessages < ActiveRecord::Migration def self.up create_table :outgoing_messages do |t| diff --git a/db/migrate/010_remove_public_body_id_from_outgoing_messages.rb b/db/migrate/010_remove_public_body_id_from_outgoing_messages.rb index da5ffc87e..5599d6131 100644 --- a/db/migrate/010_remove_public_body_id_from_outgoing_messages.rb +++ b/db/migrate/010_remove_public_body_id_from_outgoing_messages.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class RemovePublicBodyIdFromOutgoingMessages < ActiveRecord::Migration def self.up remove_column :outgoing_messages, :public_body_id diff --git a/db/migrate/011_add_created_updated_fields.rb b/db/migrate/011_add_created_updated_fields.rb index 47bb27b78..0152ec842 100644 --- a/db/migrate/011_add_created_updated_fields.rb +++ b/db/migrate/011_add_created_updated_fields.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AddCreatedUpdatedFields < ActiveRecord::Migration def self.up # InfoRequest diff --git a/db/migrate/012_add_sent_outgoing_message.rb b/db/migrate/012_add_sent_outgoing_message.rb index 8b3059347..c7b42951c 100644 --- a/db/migrate/012_add_sent_outgoing_message.rb +++ b/db/migrate/012_add_sent_outgoing_message.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AddSentOutgoingMessage < ActiveRecord::Migration def self.up add_column :outgoing_messages, :sent_at, :datetime diff --git a/db/migrate/013_create_incoming_messages.rb b/db/migrate/013_create_incoming_messages.rb index c747fcb8c..bd7dc20cd 100644 --- a/db/migrate/013_create_incoming_messages.rb +++ b/db/migrate/013_create_incoming_messages.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class CreateIncomingMessages < ActiveRecord::Migration def self.up create_table :incoming_messages do |t| diff --git a/db/migrate/014_create_post_redirects.rb b/db/migrate/014_create_post_redirects.rb index 26c561dac..1f5c8f146 100644 --- a/db/migrate/014_create_post_redirects.rb +++ b/db/migrate/014_create_post_redirects.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class CreatePostRedirects < ActiveRecord::Migration def self.up create_table :post_redirects do |t| diff --git a/db/migrate/015_add_email_token_to_post_redirects.rb b/db/migrate/015_add_email_token_to_post_redirects.rb index 47d070533..991df8cfd 100644 --- a/db/migrate/015_add_email_token_to_post_redirects.rb +++ b/db/migrate/015_add_email_token_to_post_redirects.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AddEmailTokenToPostRedirects < ActiveRecord::Migration def self.up add_column :post_redirects, :email_token, :text diff --git a/db/migrate/016_add_reasons_to_post_redirects.rb b/db/migrate/016_add_reasons_to_post_redirects.rb index 622e1173b..e0d4af5e3 100644 --- a/db/migrate/016_add_reasons_to_post_redirects.rb +++ b/db/migrate/016_add_reasons_to_post_redirects.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AddReasonsToPostRedirects < ActiveRecord::Migration def self.up add_column :post_redirects, :reason_params_yaml, :text diff --git a/db/migrate/017_add_email_confirmed_to_users.rb b/db/migrate/017_add_email_confirmed_to_users.rb index b552e853e..56b3dacb4 100644 --- a/db/migrate/017_add_email_confirmed_to_users.rb +++ b/db/migrate/017_add_email_confirmed_to_users.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AddEmailConfirmedToUsers < ActiveRecord::Migration def self.up add_column :users, :email_confirmed, :boolean, :default => false diff --git a/db/migrate/018_add_response_type_to_incoming_message.rb b/db/migrate/018_add_response_type_to_incoming_message.rb index c841b599a..8ef2c7dd4 100644 --- a/db/migrate/018_add_response_type_to_incoming_message.rb +++ b/db/migrate/018_add_response_type_to_incoming_message.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AddResponseTypeToIncomingMessage < ActiveRecord::Migration def self.up add_column :incoming_messages, :user_classified, :boolean, :default => false diff --git a/db/migrate/021_remove_contains_information_default.rb b/db/migrate/021_remove_contains_information_default.rb index 9969cbc2c..a50e06299 100644 --- a/db/migrate/021_remove_contains_information_default.rb +++ b/db/migrate/021_remove_contains_information_default.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class RemoveContainsInformationDefault < ActiveRecord::Migration def self.up change_column :incoming_messages, :contains_information, :boolean, :default => nil diff --git a/db/migrate/022_create_info_request_events.rb b/db/migrate/022_create_info_request_events.rb index 858444298..3efc69ccf 100644 --- a/db/migrate/022_create_info_request_events.rb +++ b/db/migrate/022_create_info_request_events.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class CreateInfoRequestEvents < ActiveRecord::Migration def self.up create_table :info_request_events do |t| diff --git a/db/migrate/023_outgoing_message_last_sent_at.rb b/db/migrate/023_outgoing_message_last_sent_at.rb index 24cb55257..2a2fd4eac 100644 --- a/db/migrate/023_outgoing_message_last_sent_at.rb +++ b/db/migrate/023_outgoing_message_last_sent_at.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class OutgoingMessageLastSentAt < ActiveRecord::Migration def self.up rename_column(:outgoing_messages, :sent_at, :last_sent_at) diff --git a/db/migrate/024_add_is_bounce_to_incoming_messages.rb b/db/migrate/024_add_is_bounce_to_incoming_messages.rb index f81ff4401..54ac6d334 100644 --- a/db/migrate/024_add_is_bounce_to_incoming_messages.rb +++ b/db/migrate/024_add_is_bounce_to_incoming_messages.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AddIsBounceToIncomingMessages < ActiveRecord::Migration def self.up add_column :incoming_messages, :is_bounce, :boolean, :default => false diff --git a/db/migrate/025_add_followup_to_outgoing_message.rb b/db/migrate/025_add_followup_to_outgoing_message.rb index d3bd7444c..2e50ced27 100644 --- a/db/migrate/025_add_followup_to_outgoing_message.rb +++ b/db/migrate/025_add_followup_to_outgoing_message.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AddFollowupToOutgoingMessage < ActiveRecord::Migration def self.up add_column :outgoing_messages, :incoming_message_followup_id, :integer diff --git a/db/migrate/026_add_many_null_constraints.rb b/db/migrate/026_add_many_null_constraints.rb index 7abd2e8f2..8ff01fe1f 100644 --- a/db/migrate/026_add_many_null_constraints.rb +++ b/db/migrate/026_add_many_null_constraints.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AddManyNullConstraints < ActiveRecord::Migration def self.up change_column :users, :email, :string, :null => false diff --git a/db/migrate/027_change_classification_system.rb b/db/migrate/027_change_classification_system.rb index d9e6ad844..d1f68500a 100644 --- a/db/migrate/027_change_classification_system.rb +++ b/db/migrate/027_change_classification_system.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class ChangeClassificationSystem < ActiveRecord::Migration def self.up remove_column :incoming_messages, :contains_information diff --git a/db/migrate/028_give_incoming_messages_events.rb b/db/migrate/028_give_incoming_messages_events.rb index 46acd831e..f2f5e7706 100644 --- a/db/migrate/028_give_incoming_messages_events.rb +++ b/db/migrate/028_give_incoming_messages_events.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # TODO: If this one fails with errors about described_state on save, then you need # to temporarily modify the model for InfoRequestEvents to remove this part: # validates_inclusion_of :described_state, :in => [ diff --git a/db/migrate/029_add_describe_status_history.rb b/db/migrate/029_add_describe_status_history.rb index 0c6095d69..8b448284c 100644 --- a/db/migrate/029_add_describe_status_history.rb +++ b/db/migrate/029_add_describe_status_history.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AddDescribeStatusHistory < ActiveRecord::Migration def self.up add_column :info_request_events, :described_state, :string diff --git a/db/migrate/030_add_some_indices.rb b/db/migrate/030_add_some_indices.rb index 066fc29cb..0c58617e9 100644 --- a/db/migrate/030_add_some_indices.rb +++ b/db/migrate/030_add_some_indices.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AddSomeIndices < ActiveRecord::Migration def self.up if ActiveRecord::Base.connection.adapter_name == "PostgreSQL" diff --git a/db/migrate/031_add_indices_for_session_deletion.rb b/db/migrate/031_add_indices_for_session_deletion.rb index 9a6f6b326..2a263fece 100644 --- a/db/migrate/031_add_indices_for_session_deletion.rb +++ b/db/migrate/031_add_indices_for_session_deletion.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AddIndicesForSessionDeletion < ActiveRecord::Migration def self.up add_index :post_redirects, :updated_at diff --git a/db/migrate/032_addforeignkeys.rb b/db/migrate/032_addforeignkeys.rb index f8d8f8b0d..5cff3b9d0 100644 --- a/db/migrate/032_addforeignkeys.rb +++ b/db/migrate/032_addforeignkeys.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class Addforeignkeys < ActiveRecord::Migration def self.up if ActiveRecord::Base.connection.adapter_name == "PostgreSQL" diff --git a/db/migrate/033_add_prominence.rb b/db/migrate/033_add_prominence.rb index 15d548f37..e192044b2 100644 --- a/db/migrate/033_add_prominence.rb +++ b/db/migrate/033_add_prominence.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AddProminence < ActiveRecord::Migration def self.up add_column :info_requests, :prominence, :string, :null => false, :default => 'normal' diff --git a/db/migrate/034_run_solr_indexing.rb b/db/migrate/034_run_solr_indexing.rb index 3cdfdbde9..c48fd4702 100644 --- a/db/migrate/034_run_solr_indexing.rb +++ b/db/migrate/034_run_solr_indexing.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class RunSolrIndexing < ActiveRecord::Migration def self.up # Not using SOLR yet after all diff --git a/db/migrate/035_track_overdue_alerts.rb b/db/migrate/035_track_overdue_alerts.rb index 7ef164271..48dc23e7d 100644 --- a/db/migrate/035_track_overdue_alerts.rb +++ b/db/migrate/035_track_overdue_alerts.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class TrackOverdueAlerts < ActiveRecord::Migration def self.up create_table :user_info_request_sent_alerts do |t| diff --git a/db/migrate/036_add_public_body_tags.rb b/db/migrate/036_add_public_body_tags.rb index f7fefdf48..523b7a05b 100644 --- a/db/migrate/036_add_public_body_tags.rb +++ b/db/migrate/036_add_public_body_tags.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AddPublicBodyTags < ActiveRecord::Migration def self.up create_table :public_body_tags do |t| diff --git a/db/migrate/037_add_url_name.rb b/db/migrate/037_add_url_name.rb index 84aad9cc8..b1141e176 100644 --- a/db/migrate/037_add_url_name.rb +++ b/db/migrate/037_add_url_name.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AddUrlName < ActiveRecord::Migration def self.up add_column :public_bodies, :url_name, :text diff --git a/db/migrate/038_add_more_url_names.rb b/db/migrate/038_add_more_url_names.rb index 9798f4b4b..568610417 100644 --- a/db/migrate/038_add_more_url_names.rb +++ b/db/migrate/038_add_more_url_names.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AddMoreUrlNames < ActiveRecord::Migration def self.up add_column :users, :url_name, :text diff --git a/db/migrate/039_request_url_names.rb b/db/migrate/039_request_url_names.rb index 5227b887a..999e7c290 100644 --- a/db/migrate/039_request_url_names.rb +++ b/db/migrate/039_request_url_names.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class RequestUrlNames < ActiveRecord::Migration def self.up add_column :info_requests, :url_title, :text diff --git a/db/migrate/040_email_is_unique.rb b/db/migrate/040_email_is_unique.rb index c61362de2..aba1ef28d 100644 --- a/db/migrate/040_email_is_unique.rb +++ b/db/migrate/040_email_is_unique.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class EmailIsUnique < ActiveRecord::Migration def self.up if ActiveRecord::Base.connection.adapter_name == "PostgreSQL" diff --git a/db/migrate/041_index_requests_with_solr.rb b/db/migrate/041_index_requests_with_solr.rb index f18b947a6..8b95e6604 100644 --- a/db/migrate/041_index_requests_with_solr.rb +++ b/db/migrate/041_index_requests_with_solr.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class IndexRequestsWithSolr < ActiveRecord::Migration def self.up add_column :info_requests, :solr_up_to_date, :boolean, :default => false, :null => false diff --git a/db/migrate/042_unique_user_urls.rb b/db/migrate/042_unique_user_urls.rb index 45e4fd11d..39a7a4849 100644 --- a/db/migrate/042_unique_user_urls.rb +++ b/db/migrate/042_unique_user_urls.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class UniqueUserUrls < ActiveRecord::Migration def self.up # do last registered ones first, so the last ones get rubbish URLs diff --git a/db/migrate/043_remove_complaint_email.rb b/db/migrate/043_remove_complaint_email.rb index cc03f6507..7c57ce2fc 100644 --- a/db/migrate/043_remove_complaint_email.rb +++ b/db/migrate/043_remove_complaint_email.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class RemoveComplaintEmail < ActiveRecord::Migration def self.up remove_column :public_body_versions, :complaint_email diff --git a/db/migrate/044_remove_is_bounce.rb b/db/migrate/044_remove_is_bounce.rb index 8e2307060..6656a237c 100644 --- a/db/migrate/044_remove_is_bounce.rb +++ b/db/migrate/044_remove_is_bounce.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class RemoveIsBounce < ActiveRecord::Migration def self.up remove_column :incoming_messages, :is_bounce diff --git a/db/migrate/045_add_circumstance_to_post_redirect.rb b/db/migrate/045_add_circumstance_to_post_redirect.rb index e6e7ca513..bddd5b24a 100644 --- a/db/migrate/045_add_circumstance_to_post_redirect.rb +++ b/db/migrate/045_add_circumstance_to_post_redirect.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AddCircumstanceToPostRedirect < ActiveRecord::Migration def self.up add_column :post_redirects, :circumstance, :text, :default => "normal" diff --git a/db/migrate/046_add_last_event_id_to_alert_table.rb b/db/migrate/046_add_last_event_id_to_alert_table.rb index 361bd0af4..aab547a63 100644 --- a/db/migrate/046_add_last_event_id_to_alert_table.rb +++ b/db/migrate/046_add_last_event_id_to_alert_table.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AddLastEventIdToAlertTable < ActiveRecord::Migration def self.up add_column :user_info_request_sent_alerts, :info_request_event_id, :integer, :default => nil diff --git a/db/migrate/047_add_calculated_state.rb b/db/migrate/047_add_calculated_state.rb index 5e5b93512..ad77b366d 100644 --- a/db/migrate/047_add_calculated_state.rb +++ b/db/migrate/047_add_calculated_state.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AddCalculatedState < ActiveRecord::Migration def self.up add_column :info_request_events, :calculated_state, :string, :default => nil diff --git a/db/migrate/048_add_calculated_state_at.rb b/db/migrate/048_add_calculated_state_at.rb index 63f7e996d..8a4ffa4ef 100644 --- a/db/migrate/048_add_calculated_state_at.rb +++ b/db/migrate/048_add_calculated_state_at.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AddCalculatedStateAt < ActiveRecord::Migration def self.up # This is for use in RSS feeds diff --git a/db/migrate/049_track_things.rb b/db/migrate/049_track_things.rb index aad50a69e..8d94602b9 100644 --- a/db/migrate/049_track_things.rb +++ b/db/migrate/049_track_things.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class TrackThings < ActiveRecord::Migration def self.up create_table :track_things do |t| diff --git a/db/migrate/050_improve_track_things.rb b/db/migrate/050_improve_track_things.rb index 430dd5946..5d621ad36 100644 --- a/db/migrate/050_improve_track_things.rb +++ b/db/migrate/050_improve_track_things.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class ImproveTrackThings < ActiveRecord::Migration def self.up # SQLite at least needs a default for this diff --git a/db/migrate/051_add_track_things_unique_indices.rb b/db/migrate/051_add_track_things_unique_indices.rb index 27d901734..3ff90d79e 100644 --- a/db/migrate/051_add_track_things_unique_indices.rb +++ b/db/migrate/051_add_track_things_unique_indices.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AddTrackThingsUniqueIndices < ActiveRecord::Migration def self.up add_index :track_things, [:tracking_user_id, :track_query], :unique => true diff --git a/db/migrate/052_include_event_foreign_references.rb b/db/migrate/052_include_event_foreign_references.rb index 5dfcce4a7..c48a65a6f 100644 --- a/db/migrate/052_include_event_foreign_references.rb +++ b/db/migrate/052_include_event_foreign_references.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class IncludeEventForeignReferences < ActiveRecord::Migration def self.up add_column :info_request_events, :incoming_message_id, :integer diff --git a/db/migrate/053_acts_as_xapian_migration.rb b/db/migrate/053_acts_as_xapian_migration.rb index cc2680533..291e0bb4e 100644 --- a/db/migrate/053_acts_as_xapian_migration.rb +++ b/db/migrate/053_acts_as_xapian_migration.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class ActsAsXapianMigration < ActiveRecord::Migration def self.up create_table :acts_as_xapian_jobs do |t| diff --git a/db/migrate/054_allow_longer_comments.rb b/db/migrate/054_allow_longer_comments.rb index 35f2bee9c..fb19a1045 100644 --- a/db/migrate/054_allow_longer_comments.rb +++ b/db/migrate/054_allow_longer_comments.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AllowLongerComments < ActiveRecord::Migration def self.up change_column :public_body_versions, :last_edit_comment, :text diff --git a/db/migrate/055_stop_new_responses.rb b/db/migrate/055_stop_new_responses.rb index 1ebe2142a..dce034b95 100644 --- a/db/migrate/055_stop_new_responses.rb +++ b/db/migrate/055_stop_new_responses.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class StopNewResponses < ActiveRecord::Migration def self.up add_column :info_requests, :stop_new_responses, :boolean, :default => false, :null => false diff --git a/db/migrate/056_add_attachment_text.rb b/db/migrate/056_add_attachment_text.rb index adcb97d5f..f9c0801cf 100644 --- a/db/migrate/056_add_attachment_text.rb +++ b/db/migrate/056_add_attachment_text.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AddAttachmentText < ActiveRecord::Migration def self.up add_column :incoming_messages, :cached_attachment_text, :text diff --git a/db/migrate/057_add_law_used.rb b/db/migrate/057_add_law_used.rb index ec4efd0bc..1ed73bee0 100644 --- a/db/migrate/057_add_law_used.rb +++ b/db/migrate/057_add_law_used.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AddLawUsed < ActiveRecord::Migration def self.up add_column :info_requests, :law_used, :string, :null => false, :default => 'foi' diff --git a/db/migrate/058_remove_sessions.rb b/db/migrate/058_remove_sessions.rb index 316fcfdda..d94865eb7 100644 --- a/db/migrate/058_remove_sessions.rb +++ b/db/migrate/058_remove_sessions.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class RemoveSessions < ActiveRecord::Migration def self.up drop_table :sessions diff --git a/db/migrate/059_add_url_notes.rb b/db/migrate/059_add_url_notes.rb index ae6a998aa..c0e708e12 100644 --- a/db/migrate/059_add_url_notes.rb +++ b/db/migrate/059_add_url_notes.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AddUrlNotes < ActiveRecord::Migration def self.up add_column :public_bodies, :home_page, :text, :null => false, :default => "" diff --git a/db/migrate/060_add_cached_main_text.rb b/db/migrate/060_add_cached_main_text.rb index c372b471c..2317de1ad 100644 --- a/db/migrate/060_add_cached_main_text.rb +++ b/db/migrate/060_add_cached_main_text.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AddCachedMainText < ActiveRecord::Migration def self.up add_column :incoming_messages, :cached_main_body_text, :text diff --git a/db/migrate/061_include_responses_in_tracks.rb b/db/migrate/061_include_responses_in_tracks.rb index c7a3b26cf..8ebee5a1f 100644 --- a/db/migrate/061_include_responses_in_tracks.rb +++ b/db/migrate/061_include_responses_in_tracks.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class IncludeResponsesInTracks < ActiveRecord::Migration def self.up TrackThing.update_all "track_query = replace(track_query, 'variety:sent ', '') where track_type in ('public_body_updates', 'user_updates')" diff --git a/db/migrate/062_add_comments.rb b/db/migrate/062_add_comments.rb index d523dd808..da42786d8 100644 --- a/db/migrate/062_add_comments.rb +++ b/db/migrate/062_add_comments.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AddComments < ActiveRecord::Migration def self.up create_table :comments do |t| diff --git a/db/migrate/063_add_admin_users.rb b/db/migrate/063_add_admin_users.rb index 9daa64a35..ca6acc679 100644 --- a/db/migrate/063_add_admin_users.rb +++ b/db/migrate/063_add_admin_users.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AddAdminUsers < ActiveRecord::Migration def self.up add_column :users, :admin_level, :string, :null => false, :default => 'none' diff --git a/db/migrate/064_indices_for_annotations.rb b/db/migrate/064_indices_for_annotations.rb index 5b89271fe..88e267c64 100644 --- a/db/migrate/064_indices_for_annotations.rb +++ b/db/migrate/064_indices_for_annotations.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class IndicesForAnnotations < ActiveRecord::Migration def self.up add_index :info_request_events, :created_at diff --git a/db/migrate/065_add_comments_to_user_track.rb b/db/migrate/065_add_comments_to_user_track.rb index 50d1f9d5d..9b2ef8747 100644 --- a/db/migrate/065_add_comments_to_user_track.rb +++ b/db/migrate/065_add_comments_to_user_track.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AddCommentsToUserTrack < ActiveRecord::Migration def self.up TrackThing.update_all "track_query = replace(track_query, 'variety:sent ', '') where track_type in ('public_body_updates', 'user_updates')" diff --git a/db/migrate/066_add_first_letter.rb b/db/migrate/066_add_first_letter.rb index 7878098e0..e29dfef37 100644 --- a/db/migrate/066_add_first_letter.rb +++ b/db/migrate/066_add_first_letter.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AddFirstLetter < ActiveRecord::Migration def self.up add_column :public_bodies, :first_letter, :string diff --git a/db/migrate/067_factor_out_raw_email.rb b/db/migrate/067_factor_out_raw_email.rb index be4153938..869430e05 100644 --- a/db/migrate/067_factor_out_raw_email.rb +++ b/db/migrate/067_factor_out_raw_email.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class FactorOutRawEmail < ActiveRecord::Migration def self.up create_table :raw_emails do |t| diff --git a/db/migrate/068_add_censor_table.rb b/db/migrate/068_add_censor_table.rb index 92a17d2bc..8bfc4fbd6 100644 --- a/db/migrate/068_add_censor_table.rb +++ b/db/migrate/068_add_censor_table.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AddCensorTable < ActiveRecord::Migration def self.up create_table :censor_rules do |t| diff --git a/db/migrate/069_add_what_doing.rb b/db/migrate/069_add_what_doing.rb index be8039fec..2ede40603 100644 --- a/db/migrate/069_add_what_doing.rb +++ b/db/migrate/069_add_what_doing.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AddWhatDoing < ActiveRecord::Migration def self.up add_column :outgoing_messages, :what_doing, :string diff --git a/db/migrate/070_sent_are_waiting_response.rb b/db/migrate/070_sent_are_waiting_response.rb index af66705b5..a2c2278ee 100644 --- a/db/migrate/070_sent_are_waiting_response.rb +++ b/db/migrate/070_sent_are_waiting_response.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class SentAreWaitingResponse < ActiveRecord::Migration def self.up InfoRequestEvent.update_all "described_state = 'waiting_response', calculated_state = 'waiting_response', last_described_at = created_at where event_type = 'sent'" diff --git a/db/migrate/071_add_exim_log.rb b/db/migrate/071_add_exim_log.rb index d3780affa..94924569c 100644 --- a/db/migrate/071_add_exim_log.rb +++ b/db/migrate/071_add_exim_log.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AddEximLog < ActiveRecord::Migration def self.up create_table :exim_logs do |t| diff --git a/db/migrate/072_add_publication_scheme.rb b/db/migrate/072_add_publication_scheme.rb index 5040d1709..16507411d 100644 --- a/db/migrate/072_add_publication_scheme.rb +++ b/db/migrate/072_add_publication_scheme.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AddPublicationScheme < ActiveRecord::Migration def self.up add_column :public_bodies, :publication_scheme, :text, :null => false, :default => "" diff --git a/db/migrate/073_add_ban_user.rb b/db/migrate/073_add_ban_user.rb index 15a1ea121..045c65fcd 100644 --- a/db/migrate/073_add_ban_user.rb +++ b/db/migrate/073_add_ban_user.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AddBanUser < ActiveRecord::Migration def self.up add_column :users, :ban_text, :text, :null => false, :default => "" diff --git a/db/migrate/074_create_holidays.rb b/db/migrate/074_create_holidays.rb index f2197e89e..406b9c44e 100644 --- a/db/migrate/074_create_holidays.rb +++ b/db/migrate/074_create_holidays.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class CreateHolidays < ActiveRecord::Migration def self.up create_table :holidays do |t| diff --git a/db/migrate/075_add_charity_number.rb b/db/migrate/075_add_charity_number.rb index 41743a922..af0208b44 100644 --- a/db/migrate/075_add_charity_number.rb +++ b/db/migrate/075_add_charity_number.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AddCharityNumber < ActiveRecord::Migration def self.up add_column :public_bodies, :charity_number, :text, :null => false, :default => "" diff --git a/db/migrate/076_add_indices.rb b/db/migrate/076_add_indices.rb index fd102caba..50fc1e3ea 100644 --- a/db/migrate/076_add_indices.rb +++ b/db/migrate/076_add_indices.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AddIndices < ActiveRecord::Migration def self.up add_index :track_things_sent_emails, :track_thing_id diff --git a/db/migrate/077_add_exim_log_index.rb b/db/migrate/077_add_exim_log_index.rb index c2d04d7ca..c7526c252 100644 --- a/db/migrate/077_add_exim_log_index.rb +++ b/db/migrate/077_add_exim_log_index.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AddEximLogIndex < ActiveRecord::Migration def self.up add_index :exim_logs, :exim_log_done_id diff --git a/db/migrate/078_expand_stop_new_responses.rb b/db/migrate/078_expand_stop_new_responses.rb index ae0d4db91..24b384ea1 100644 --- a/db/migrate/078_expand_stop_new_responses.rb +++ b/db/migrate/078_expand_stop_new_responses.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class ExpandStopNewResponses < ActiveRecord::Migration def self.up add_column :info_requests, :allow_new_responses_from, :string diff --git a/db/migrate/079_add_profile_photo.rb b/db/migrate/079_add_profile_photo.rb index a6c031d89..9777b1948 100644 --- a/db/migrate/079_add_profile_photo.rb +++ b/db/migrate/079_add_profile_photo.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AddProfilePhoto < ActiveRecord::Migration def self.up create_table :profile_photos do |t| diff --git a/db/migrate/080_cache_only_clipped_attachment_text.rb b/db/migrate/080_cache_only_clipped_attachment_text.rb index 0cd835e49..71b801e53 100644 --- a/db/migrate/080_cache_only_clipped_attachment_text.rb +++ b/db/migrate/080_cache_only_clipped_attachment_text.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class CacheOnlyClippedAttachmentText < ActiveRecord::Migration def self.up remove_column :incoming_messages, :cached_attachment_text diff --git a/db/migrate/081_add_event_prominence.rb b/db/migrate/081_add_event_prominence.rb index 184e1a267..2b0d3a8ea 100644 --- a/db/migrate/081_add_event_prominence.rb +++ b/db/migrate/081_add_event_prominence.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AddEventProminence < ActiveRecord::Migration def self.up add_column :info_request_events, :prominence, :string, :null => false, :default => 'normal' diff --git a/db/migrate/082_change_raw_email_to_binary.rb b/db/migrate/082_change_raw_email_to_binary.rb index ec16d54a0..5123f2825 100644 --- a/db/migrate/082_change_raw_email_to_binary.rb +++ b/db/migrate/082_change_raw_email_to_binary.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class ChangeRawEmailToBinary < ActiveRecord::Migration def self.up change_column :raw_emails, :data, :text, :null => true # allow null diff --git a/db/migrate/083_add_indices_track_sent.rb b/db/migrate/083_add_indices_track_sent.rb index 2b0908af8..f292b02ab 100644 --- a/db/migrate/083_add_indices_track_sent.rb +++ b/db/migrate/083_add_indices_track_sent.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AddIndicesTrackSent < ActiveRecord::Migration def self.up add_index :track_things_sent_emails, :created_at diff --git a/db/migrate/084_alter_profile_photo.rb b/db/migrate/084_alter_profile_photo.rb index d2717b047..14c84ac99 100644 --- a/db/migrate/084_alter_profile_photo.rb +++ b/db/migrate/084_alter_profile_photo.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AlterProfilePhoto < ActiveRecord::Migration def self.up remove_column :users, :profile_photo_id diff --git a/db/migrate/085_draft_profile_photo.rb b/db/migrate/085_draft_profile_photo.rb index c0b507485..98c08a35e 100644 --- a/db/migrate/085_draft_profile_photo.rb +++ b/db/migrate/085_draft_profile_photo.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class DraftProfilePhoto < ActiveRecord::Migration def self.up add_column :profile_photos, :draft, :boolean, :default => false, :null => false diff --git a/db/migrate/086_allow_null_profile_photo_user.rb b/db/migrate/086_allow_null_profile_photo_user.rb index f4e107848..a070df560 100644 --- a/db/migrate/086_allow_null_profile_photo_user.rb +++ b/db/migrate/086_allow_null_profile_photo_user.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AllowNullProfilePhotoUser < ActiveRecord::Migration def self.up change_column :profile_photos, :user_id, :integer, :null => true diff --git a/db/migrate/087_add_about_me.rb b/db/migrate/087_add_about_me.rb index 9916454f3..907cd472b 100644 --- a/db/migrate/087_add_about_me.rb +++ b/db/migrate/087_add_about_me.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AddAboutMe < ActiveRecord::Migration def self.up add_column :users, :about_me, :text, :null => false, :default => "" diff --git a/db/migrate/088_public_body_machine_tags.rb b/db/migrate/088_public_body_machine_tags.rb index 6a0815568..33f035a8e 100644 --- a/db/migrate/088_public_body_machine_tags.rb +++ b/db/migrate/088_public_body_machine_tags.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class PublicBodyMachineTags < ActiveRecord::Migration def self.up add_column :public_body_tags, :value, :text diff --git a/db/migrate/089_remove_charity_number.rb b/db/migrate/089_remove_charity_number.rb index 9b7d0935b..0d67bef04 100644 --- a/db/migrate/089_remove_charity_number.rb +++ b/db/migrate/089_remove_charity_number.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class RemoveCharityNumber < ActiveRecord::Migration def self.up remove_column :public_bodies, :charity_number diff --git a/db/migrate/090_remove_tag_uniqueness.rb b/db/migrate/090_remove_tag_uniqueness.rb index d1affade3..37b9a39b4 100644 --- a/db/migrate/090_remove_tag_uniqueness.rb +++ b/db/migrate/090_remove_tag_uniqueness.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class RemoveTagUniqueness < ActiveRecord::Migration def self.up # MySQL cannot index text blobs like this diff --git a/db/migrate/091_add_censor_rules_indices.rb b/db/migrate/091_add_censor_rules_indices.rb index 59f5db6cc..88869be1c 100644 --- a/db/migrate/091_add_censor_rules_indices.rb +++ b/db/migrate/091_add_censor_rules_indices.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AddCensorRulesIndices < ActiveRecord::Migration def self.up add_index :censor_rules, :info_request_id diff --git a/db/migrate/092_cache_only_marked_body_text.rb b/db/migrate/092_cache_only_marked_body_text.rb index e05e23e74..5ce26f1c1 100644 --- a/db/migrate/092_cache_only_marked_body_text.rb +++ b/db/migrate/092_cache_only_marked_body_text.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class CacheOnlyMarkedBodyText < ActiveRecord::Migration def self.up remove_column :incoming_messages, :cached_main_body_text diff --git a/db/migrate/093_move_to_has_tag_string.rb b/db/migrate/093_move_to_has_tag_string.rb index 58f36c224..f819045a9 100644 --- a/db/migrate/093_move_to_has_tag_string.rb +++ b/db/migrate/093_move_to_has_tag_string.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class MoveToHasTagString < ActiveRecord::Migration def self.up rename_table :public_body_tags, :has_tag_string_tags diff --git a/db/migrate/094_remove_old_tags_foreign_key.rb b/db/migrate/094_remove_old_tags_foreign_key.rb index 5a6a00acc..1e9abaff6 100644 --- a/db/migrate/094_remove_old_tags_foreign_key.rb +++ b/db/migrate/094_remove_old_tags_foreign_key.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class RemoveOldTagsForeignKey < ActiveRecord::Migration def self.up if ActiveRecord::Base.connection.adapter_name == "PostgreSQL" diff --git a/db/migrate/095_add_post_redirect_user_index.rb b/db/migrate/095_add_post_redirect_user_index.rb index 05d5f7a35..d6e9162d1 100644 --- a/db/migrate/095_add_post_redirect_user_index.rb +++ b/db/migrate/095_add_post_redirect_user_index.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AddPostRedirectUserIndex < ActiveRecord::Migration # This index is for admin interface diff --git a/db/migrate/096_create_translation_tables.rb b/db/migrate/096_create_translation_tables.rb index 4b47c11f7..fe076cbfd 100644 --- a/db/migrate/096_create_translation_tables.rb +++ b/db/migrate/096_create_translation_tables.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class CreateTranslationTables < ActiveRecord::Migration def self.up fields = {:name => :text, diff --git a/db/migrate/097_add_comment_locale.rb b/db/migrate/097_add_comment_locale.rb index 92ac7c4a5..8a47351a6 100644 --- a/db/migrate/097_add_comment_locale.rb +++ b/db/migrate/097_add_comment_locale.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AddCommentLocale < ActiveRecord::Migration def self.up add_column :comments, :locale, :text, :null => false, :default => "" diff --git a/db/migrate/098_fix_public_body_translations.rb b/db/migrate/098_fix_public_body_translations.rb index 25f36336f..53d62ab7e 100644 --- a/db/migrate/098_fix_public_body_translations.rb +++ b/db/migrate/098_fix_public_body_translations.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # The PublicBody model class had a bug that meant the # translations for first_letter and publication_scheme # were not being correctly populated. diff --git a/db/migrate/099_move_raw_email_to_filesystem.rb b/db/migrate/099_move_raw_email_to_filesystem.rb index ea77580e1..bd9e8efb4 100644 --- a/db/migrate/099_move_raw_email_to_filesystem.rb +++ b/db/migrate/099_move_raw_email_to_filesystem.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class MoveRawEmailToFilesystem < ActiveRecord::Migration def self.up batch_size = 10 diff --git a/db/migrate/100_remove_redundant_raw_email_columns.rb b/db/migrate/100_remove_redundant_raw_email_columns.rb index edf6006d7..d974e78df 100644 --- a/db/migrate/100_remove_redundant_raw_email_columns.rb +++ b/db/migrate/100_remove_redundant_raw_email_columns.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class RemoveRedundantRawEmailColumns < ActiveRecord::Migration def self.up remove_column :raw_emails, :data_text diff --git a/db/migrate/101_add_hash_to_info_request.rb b/db/migrate/101_add_hash_to_info_request.rb index e38384cd6..564067438 100644 --- a/db/migrate/101_add_hash_to_info_request.rb +++ b/db/migrate/101_add_hash_to_info_request.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require 'digest/sha1' class AddHashToInfoRequest < ActiveRecord::Migration diff --git a/db/migrate/102_add_locale_to_users.rb b/db/migrate/102_add_locale_to_users.rb index a299a8561..eff9f60da 100644 --- a/db/migrate/102_add_locale_to_users.rb +++ b/db/migrate/102_add_locale_to_users.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AddLocaleToUsers < ActiveRecord::Migration def self.up add_column :users, :locale, :string diff --git a/db/migrate/103_add_user_bounce_columns.rb b/db/migrate/103_add_user_bounce_columns.rb index a16ecde75..81daf3ed5 100644 --- a/db/migrate/103_add_user_bounce_columns.rb +++ b/db/migrate/103_add_user_bounce_columns.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require 'digest/sha1' class AddUserBounceColumns < ActiveRecord::Migration diff --git a/db/migrate/104_create_foi_attachments.rb b/db/migrate/104_create_foi_attachments.rb index c53cd4f64..bcef00985 100644 --- a/db/migrate/104_create_foi_attachments.rb +++ b/db/migrate/104_create_foi_attachments.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class CreateFoiAttachments < ActiveRecord::Migration def self.up diff --git a/db/migrate/105_extend_incoming_message.rb b/db/migrate/105_extend_incoming_message.rb index 9db8649a0..bb244e777 100644 --- a/db/migrate/105_extend_incoming_message.rb +++ b/db/migrate/105_extend_incoming_message.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class ExtendIncomingMessage < ActiveRecord::Migration def self.up add_column :incoming_messages, :sent_at, :time diff --git a/db/migrate/106_add_hex_digest_to_foi_attachment.rb b/db/migrate/106_add_hex_digest_to_foi_attachment.rb index d9520a934..20a9d5fb2 100644 --- a/db/migrate/106_add_hex_digest_to_foi_attachment.rb +++ b/db/migrate/106_add_hex_digest_to_foi_attachment.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AddHexDigestToFoiAttachment < ActiveRecord::Migration def self.up add_column :foi_attachments, :hexdigest, :string, :limit => 32 diff --git a/db/migrate/107_add_date_parsed_field_to_incoming_message.rb b/db/migrate/107_add_date_parsed_field_to_incoming_message.rb index fbc017134..e13f7b776 100644 --- a/db/migrate/107_add_date_parsed_field_to_incoming_message.rb +++ b/db/migrate/107_add_date_parsed_field_to_incoming_message.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AddDateParsedFieldToIncomingMessage < ActiveRecord::Migration def self.up add_column :incoming_messages, :last_parsed, :datetime diff --git a/db/migrate/108_change_safe_mail_from_to_mail_from.rb b/db/migrate/108_change_safe_mail_from_to_mail_from.rb index 57997f674..7bc5e47b6 100644 --- a/db/migrate/108_change_safe_mail_from_to_mail_from.rb +++ b/db/migrate/108_change_safe_mail_from_to_mail_from.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class ChangeSafeMailFromToMailFrom < ActiveRecord::Migration def self.up remove_column :incoming_messages, :safe_mail_from diff --git a/db/migrate/109_change_sent_at_to_datetime.rb b/db/migrate/109_change_sent_at_to_datetime.rb index 5fc9b29ae..4ce1831c0 100644 --- a/db/migrate/109_change_sent_at_to_datetime.rb +++ b/db/migrate/109_change_sent_at_to_datetime.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class ChangeSentAtToDatetime < ActiveRecord::Migration def self.up remove_column :incoming_messages, :sent_at diff --git a/db/migrate/110_add_user_no_limit.rb b/db/migrate/110_add_user_no_limit.rb index d78a05f75..4d8274fbf 100644 --- a/db/migrate/110_add_user_no_limit.rb +++ b/db/migrate/110_add_user_no_limit.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require 'digest/sha1' class AddUserNoLimit < ActiveRecord::Migration diff --git a/db/migrate/111_create_purge_requests.rb b/db/migrate/111_create_purge_requests.rb index 0b4fd1d1d..c5ddaf4a2 100644 --- a/db/migrate/111_create_purge_requests.rb +++ b/db/migrate/111_create_purge_requests.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class CreatePurgeRequests < ActiveRecord::Migration def self.up create_table :purge_requests do |t| diff --git a/db/migrate/112_add_api_key_to_public_bodies.rb b/db/migrate/112_add_api_key_to_public_bodies.rb index 43dccb198..a7b3903f1 100644 --- a/db/migrate/112_add_api_key_to_public_bodies.rb +++ b/db/migrate/112_add_api_key_to_public_bodies.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require "securerandom" class AddApiKeyToPublicBodies < ActiveRecord::Migration diff --git a/db/migrate/113_add_external_fields_to_info_requests.rb b/db/migrate/113_add_external_fields_to_info_requests.rb index 1ad7634ff..c350f432b 100644 --- a/db/migrate/113_add_external_fields_to_info_requests.rb +++ b/db/migrate/113_add_external_fields_to_info_requests.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AddExternalFieldsToInfoRequests < ActiveRecord::Migration def self.up change_column_null :info_requests, :user_id, true diff --git a/db/migrate/114_add_attention_requested_flag_to_info_requests.rb b/db/migrate/114_add_attention_requested_flag_to_info_requests.rb index 48c98e5a9..61a3b5e5e 100644 --- a/db/migrate/114_add_attention_requested_flag_to_info_requests.rb +++ b/db/migrate/114_add_attention_requested_flag_to_info_requests.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require 'digest/sha1' class AddAttentionRequestedFlagToInfoRequests < ActiveRecord::Migration diff --git a/db/migrate/115_add_receive_email_alerts_to_user.rb b/db/migrate/115_add_receive_email_alerts_to_user.rb index 7e06dd275..0f3747294 100644 --- a/db/migrate/115_add_receive_email_alerts_to_user.rb +++ b/db/migrate/115_add_receive_email_alerts_to_user.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AddReceiveEmailAlertsToUser < ActiveRecord::Migration def self.up add_column :users, :receive_email_alerts, :boolean, :default => true, :null => false diff --git a/db/migrate/116_add_censor_rule_regexp.rb b/db/migrate/116_add_censor_rule_regexp.rb index d9c4664cd..235a3a0cc 100644 --- a/db/migrate/116_add_censor_rule_regexp.rb +++ b/db/migrate/116_add_censor_rule_regexp.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AddCensorRuleRegexp < ActiveRecord::Migration def self.up add_column :censor_rules, :regexp, :boolean diff --git a/db/migrate/117_create_sessions.rb b/db/migrate/117_create_sessions.rb index 4ccc353b1..7d95f8935 100644 --- a/db/migrate/117_create_sessions.rb +++ b/db/migrate/117_create_sessions.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class CreateSessions < ActiveRecord::Migration def self.up create_table :sessions do |t| diff --git a/db/migrate/118_remove_sessions_again.rb b/db/migrate/118_remove_sessions_again.rb index dc5a63df7..88e896c08 100644 --- a/db/migrate/118_remove_sessions_again.rb +++ b/db/migrate/118_remove_sessions_again.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class RemoveSessionsAgain < ActiveRecord::Migration def self.up drop_table :sessions diff --git a/db/migrate/20120822145640_correct_external_request_constraint.rb b/db/migrate/20120822145640_correct_external_request_constraint.rb index 6902f3cb2..6d6b58f28 100644 --- a/db/migrate/20120822145640_correct_external_request_constraint.rb +++ b/db/migrate/20120822145640_correct_external_request_constraint.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class CorrectExternalRequestConstraint < ActiveRecord::Migration def self.up if ActiveRecord::Base.connection.adapter_name == "PostgreSQL" diff --git a/db/migrate/20120910153022_create_request_classifications.rb b/db/migrate/20120910153022_create_request_classifications.rb index 7c6270c9e..253e45909 100644 --- a/db/migrate/20120910153022_create_request_classifications.rb +++ b/db/migrate/20120910153022_create_request_classifications.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class CreateRequestClassifications < ActiveRecord::Migration def self.up create_table :request_classifications do |t| diff --git a/db/migrate/20120912111713_add_raw_email_index_to_incoming_messages.rb b/db/migrate/20120912111713_add_raw_email_index_to_incoming_messages.rb index 14174935e..b69006e88 100644 --- a/db/migrate/20120912111713_add_raw_email_index_to_incoming_messages.rb +++ b/db/migrate/20120912111713_add_raw_email_index_to_incoming_messages.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AddRawEmailIndexToIncomingMessages < ActiveRecord::Migration def self.up add_index :incoming_messages, :raw_email_id diff --git a/db/migrate/20120912112036_add_info_request_id_index_to_exim_logs.rb b/db/migrate/20120912112036_add_info_request_id_index_to_exim_logs.rb index 81e2a7946..e926b110e 100644 --- a/db/migrate/20120912112036_add_info_request_id_index_to_exim_logs.rb +++ b/db/migrate/20120912112036_add_info_request_id_index_to_exim_logs.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AddInfoRequestIdIndexToEximLogs < ActiveRecord::Migration def self.up add_index :exim_logs, :info_request_id diff --git a/db/migrate/20120912112312_add_info_request_id_index_to_incoming_and_outgoing_messages.rb b/db/migrate/20120912112312_add_info_request_id_index_to_incoming_and_outgoing_messages.rb index 814fa7540..d77196062 100644 --- a/db/migrate/20120912112312_add_info_request_id_index_to_incoming_and_outgoing_messages.rb +++ b/db/migrate/20120912112312_add_info_request_id_index_to_incoming_and_outgoing_messages.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AddInfoRequestIdIndexToIncomingAndOutgoingMessages < ActiveRecord::Migration def self.up add_index :incoming_messages, :info_request_id diff --git a/db/migrate/20120912112655_add_incoming_message_id_index_to_foi_attachments.rb b/db/migrate/20120912112655_add_incoming_message_id_index_to_foi_attachments.rb index be0bf76c3..c6d8008cf 100644 --- a/db/migrate/20120912112655_add_incoming_message_id_index_to_foi_attachments.rb +++ b/db/migrate/20120912112655_add_incoming_message_id_index_to_foi_attachments.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AddIncomingMessageIdIndexToFoiAttachments < ActiveRecord::Migration def self.up add_index :foi_attachments, :incoming_message_id diff --git a/db/migrate/20120912113004_add_indexes_to_info_request_events.rb b/db/migrate/20120912113004_add_indexes_to_info_request_events.rb index b3780322f..49178e4ce 100644 --- a/db/migrate/20120912113004_add_indexes_to_info_request_events.rb +++ b/db/migrate/20120912113004_add_indexes_to_info_request_events.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AddIndexesToInfoRequestEvents < ActiveRecord::Migration def self.up add_index :info_request_events, :incoming_message_id diff --git a/db/migrate/20120912113720_add_public_body_index_to_info_requests.rb b/db/migrate/20120912113720_add_public_body_index_to_info_requests.rb index a56cad1f9..a105fbc6d 100644 --- a/db/migrate/20120912113720_add_public_body_index_to_info_requests.rb +++ b/db/migrate/20120912113720_add_public_body_index_to_info_requests.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AddPublicBodyIndexToInfoRequests < ActiveRecord::Migration def self.up add_index :info_requests, :public_body_id diff --git a/db/migrate/20120912114022_add_user_index_to_info_requests.rb b/db/migrate/20120912114022_add_user_index_to_info_requests.rb index 8be51c0c8..b44934feb 100644 --- a/db/migrate/20120912114022_add_user_index_to_info_requests.rb +++ b/db/migrate/20120912114022_add_user_index_to_info_requests.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AddUserIndexToInfoRequests < ActiveRecord::Migration def self.up add_index :info_requests, :user_id diff --git a/db/migrate/20120912170035_add_info_requests_count_to_public_bodies.rb b/db/migrate/20120912170035_add_info_requests_count_to_public_bodies.rb index d187dcfa5..5cc82106f 100644 --- a/db/migrate/20120912170035_add_info_requests_count_to_public_bodies.rb +++ b/db/migrate/20120912170035_add_info_requests_count_to_public_bodies.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AddInfoRequestsCountToPublicBodies < ActiveRecord::Migration def self.up add_column :public_bodies, :info_requests_count, :integer, :null => false, :default => 0 diff --git a/db/migrate/20120913074940_add_incoming_message_index_to_outgoing_messages.rb b/db/migrate/20120913074940_add_incoming_message_index_to_outgoing_messages.rb index 893395f41..a2a855d9d 100644 --- a/db/migrate/20120913074940_add_incoming_message_index_to_outgoing_messages.rb +++ b/db/migrate/20120913074940_add_incoming_message_index_to_outgoing_messages.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AddIncomingMessageIndexToOutgoingMessages < ActiveRecord::Migration def self.up add_index :outgoing_messages, :incoming_message_followup_id diff --git a/db/migrate/20120913080807_add_info_request_event_index_to_track_things_sent_emails.rb b/db/migrate/20120913080807_add_info_request_event_index_to_track_things_sent_emails.rb index d119f55b3..0270c3e1e 100644 --- a/db/migrate/20120913080807_add_info_request_event_index_to_track_things_sent_emails.rb +++ b/db/migrate/20120913080807_add_info_request_event_index_to_track_things_sent_emails.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AddInfoRequestEventIndexToTrackThingsSentEmails < ActiveRecord::Migration def self.up add_index :track_things_sent_emails, :info_request_event_id diff --git a/db/migrate/20120913081136_add_info_request_event_index_to_user_info_request_sent_alerts.rb b/db/migrate/20120913081136_add_info_request_event_index_to_user_info_request_sent_alerts.rb index aa9f404f7..1b789c4e9 100644 --- a/db/migrate/20120913081136_add_info_request_event_index_to_user_info_request_sent_alerts.rb +++ b/db/migrate/20120913081136_add_info_request_event_index_to_user_info_request_sent_alerts.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AddInfoRequestEventIndexToUserInfoRequestSentAlerts < ActiveRecord::Migration def self.up add_index :user_info_request_sent_alerts, :info_request_event_id diff --git a/db/migrate/20120913135745_add_updated_at_index_to_public_body_versions.rb b/db/migrate/20120913135745_add_updated_at_index_to_public_body_versions.rb index 6ae58c884..ceeee6efd 100644 --- a/db/migrate/20120913135745_add_updated_at_index_to_public_body_versions.rb +++ b/db/migrate/20120913135745_add_updated_at_index_to_public_body_versions.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AddUpdatedAtIndexToPublicBodyVersions < ActiveRecord::Migration def self.up add_index :public_body_versions, :updated_at diff --git a/db/migrate/20120919140404_add_comments_allowed_to_info_request.rb b/db/migrate/20120919140404_add_comments_allowed_to_info_request.rb index 4ae0bce18..a7671507f 100644 --- a/db/migrate/20120919140404_add_comments_allowed_to_info_request.rb +++ b/db/migrate/20120919140404_add_comments_allowed_to_info_request.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AddCommentsAllowedToInfoRequest < ActiveRecord::Migration def self.up add_column :info_requests, :comments_allowed, :boolean, :null => false, :default => true diff --git a/db/migrate/20121010214348_rename_exim_log_tables.rb b/db/migrate/20121010214348_rename_exim_log_tables.rb index 75fcff065..5c8ee8297 100644 --- a/db/migrate/20121010214348_rename_exim_log_tables.rb +++ b/db/migrate/20121010214348_rename_exim_log_tables.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class RenameEximLogTables < ActiveRecord::Migration def self.up rename_table :exim_logs, :mail_server_logs diff --git a/db/migrate/20121022031914_add_disclosure_log.rb b/db/migrate/20121022031914_add_disclosure_log.rb index 82ea7dbcd..65ab7162d 100644 --- a/db/migrate/20121022031914_add_disclosure_log.rb +++ b/db/migrate/20121022031914_add_disclosure_log.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AddDisclosureLog < ActiveRecord::Migration def self.up add_column :public_bodies, :disclosure_log, :text, :null => false, :default => "" diff --git a/db/migrate/20130731142632_remove_prominence_from_info_request_event.rb b/db/migrate/20130731142632_remove_prominence_from_info_request_event.rb index df0278c20..c0509e2e4 100644 --- a/db/migrate/20130731142632_remove_prominence_from_info_request_event.rb +++ b/db/migrate/20130731142632_remove_prominence_from_info_request_event.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class RemoveProminenceFromInfoRequestEvent < ActiveRecord::Migration def up remove_column :info_request_events, :prominence diff --git a/db/migrate/20130731145325_add_prominence_to_incoming_message.rb b/db/migrate/20130731145325_add_prominence_to_incoming_message.rb index 01c4906a7..89d2eb26c 100644 --- a/db/migrate/20130731145325_add_prominence_to_incoming_message.rb +++ b/db/migrate/20130731145325_add_prominence_to_incoming_message.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AddProminenceToIncomingMessage < ActiveRecord::Migration def change add_column :incoming_messages, :prominence, :string, :null => false, :default => 'normal' diff --git a/db/migrate/20130801154033_add_prominence_reason_to_incoming_message.rb b/db/migrate/20130801154033_add_prominence_reason_to_incoming_message.rb index 2d189f658..9f6ecac27 100644 --- a/db/migrate/20130801154033_add_prominence_reason_to_incoming_message.rb +++ b/db/migrate/20130801154033_add_prominence_reason_to_incoming_message.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AddProminenceReasonToIncomingMessage < ActiveRecord::Migration def change add_column :incoming_messages, :prominence_reason, :text diff --git a/db/migrate/20130816150110_add_statistics_to_public_body.rb b/db/migrate/20130816150110_add_statistics_to_public_body.rb index fb3a67e83..aaa7b0f27 100644 --- a/db/migrate/20130816150110_add_statistics_to_public_body.rb +++ b/db/migrate/20130816150110_add_statistics_to_public_body.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AddStatisticsToPublicBody < ActiveRecord::Migration def self.up add_column :public_bodies, :info_requests_successful_count, :integer diff --git a/db/migrate/20130822161803_add_prominence_fields_to_outgoing_message.rb b/db/migrate/20130822161803_add_prominence_fields_to_outgoing_message.rb index a75e0d426..fc4c5540f 100644 --- a/db/migrate/20130822161803_add_prominence_fields_to_outgoing_message.rb +++ b/db/migrate/20130822161803_add_prominence_fields_to_outgoing_message.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AddProminenceFieldsToOutgoingMessage < ActiveRecord::Migration def change add_column :outgoing_messages, :prominence, :string, :null => false, :default => 'normal' diff --git a/db/migrate/20130919151140_add_can_make_batch_requests_to_user.rb b/db/migrate/20130919151140_add_can_make_batch_requests_to_user.rb index cc9d8e76f..5bf1db6de 100644 --- a/db/migrate/20130919151140_add_can_make_batch_requests_to_user.rb +++ b/db/migrate/20130919151140_add_can_make_batch_requests_to_user.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AddCanMakeBatchRequestsToUser < ActiveRecord::Migration def change add_column :users, :can_make_batch_requests, :boolean, :default => false, :null => false diff --git a/db/migrate/20131024114346_create_info_request_batches.rb b/db/migrate/20131024114346_create_info_request_batches.rb index 09c6f467b..bb56be6d2 100644 --- a/db/migrate/20131024114346_create_info_request_batches.rb +++ b/db/migrate/20131024114346_create_info_request_batches.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class CreateInfoRequestBatches < ActiveRecord::Migration def up create_table :info_request_batches do |t| diff --git a/db/migrate/20131024152540_add_body_to_info_request_batches.rb b/db/migrate/20131024152540_add_body_to_info_request_batches.rb index 5f9b3af10..ad547c467 100644 --- a/db/migrate/20131024152540_add_body_to_info_request_batches.rb +++ b/db/migrate/20131024152540_add_body_to_info_request_batches.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AddBodyToInfoRequestBatches < ActiveRecord::Migration def up add_column :info_request_batches, :body, :text diff --git a/db/migrate/20131101155844_add_stats_denominator.rb b/db/migrate/20131101155844_add_stats_denominator.rb index 7df4c8200..05920084b 100644 --- a/db/migrate/20131101155844_add_stats_denominator.rb +++ b/db/migrate/20131101155844_add_stats_denominator.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AddStatsDenominator < ActiveRecord::Migration def up add_column :public_bodies, :info_requests_visible_classified_count, :integer diff --git a/db/migrate/20131127105438_create_info_request_batch_public_bodies_join_table.rb b/db/migrate/20131127105438_create_info_request_batch_public_bodies_join_table.rb index 11a9c7066..8e75eb9bf 100644 --- a/db/migrate/20131127105438_create_info_request_batch_public_bodies_join_table.rb +++ b/db/migrate/20131127105438_create_info_request_batch_public_bodies_join_table.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class CreateInfoRequestBatchPublicBodiesJoinTable < ActiveRecord::Migration def change create_table :info_request_batches_public_bodies, :id => false do |t| diff --git a/db/migrate/20131127135622_add_sent_at_to_info_request_batch.rb b/db/migrate/20131127135622_add_sent_at_to_info_request_batch.rb index 27d4aecee..2d485a065 100644 --- a/db/migrate/20131127135622_add_sent_at_to_info_request_batch.rb +++ b/db/migrate/20131127135622_add_sent_at_to_info_request_batch.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AddSentAtToInfoRequestBatch < ActiveRecord::Migration def change add_column :info_request_batches, :sent_at, :datetime diff --git a/db/migrate/20131211152641_create_public_body_change_requests.rb b/db/migrate/20131211152641_create_public_body_change_requests.rb index e3fb560a6..76e24d589 100644 --- a/db/migrate/20131211152641_create_public_body_change_requests.rb +++ b/db/migrate/20131211152641_create_public_body_change_requests.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class CreatePublicBodyChangeRequests < ActiveRecord::Migration def up create_table :public_body_change_requests do |t| diff --git a/db/migrate/20140325120619_create_spam_addresses.rb b/db/migrate/20140325120619_create_spam_addresses.rb index 7c730a5c7..0258e01b9 100644 --- a/db/migrate/20140325120619_create_spam_addresses.rb +++ b/db/migrate/20140325120619_create_spam_addresses.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class CreateSpamAddresses < ActiveRecord::Migration def change create_table :spam_addresses do |t| diff --git a/db/migrate/20140408145616_add_default_short_name_to_public_bodies.rb b/db/migrate/20140408145616_add_default_short_name_to_public_bodies.rb index 5fb239ebd..0a4ce19b3 100644 --- a/db/migrate/20140408145616_add_default_short_name_to_public_bodies.rb +++ b/db/migrate/20140408145616_add_default_short_name_to_public_bodies.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AddDefaultShortNameToPublicBodies < ActiveRecord::Migration def up diff --git a/db/migrate/20140528110536_update_track_things_index.rb b/db/migrate/20140528110536_update_track_things_index.rb index 55ee0b70b..209beecce 100644 --- a/db/migrate/20140528110536_update_track_things_index.rb +++ b/db/migrate/20140528110536_update_track_things_index.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class UpdateTrackThingsIndex < ActiveRecord::Migration def up diff --git a/db/migrate/20140710094405_create_public_body_headings_and_categories.rb b/db/migrate/20140710094405_create_public_body_headings_and_categories.rb index 0ba7f64a0..b65d2078b 100644 --- a/db/migrate/20140710094405_create_public_body_headings_and_categories.rb +++ b/db/migrate/20140710094405_create_public_body_headings_and_categories.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class CreatePublicBodyHeadingsAndCategories < ActiveRecord::Migration def up create_table :public_body_headings, :force => true do |t| @@ -24,4 +25,4 @@ class CreatePublicBodyHeadingsAndCategories < ActiveRecord::Migration drop_table :public_body_headings drop_table :public_body_categories_public_body_headings end -end
\ No newline at end of file +end diff --git a/db/migrate/20140716131107_create_category_translation_tables.rb b/db/migrate/20140716131107_create_category_translation_tables.rb index f4b90b330..95591caf2 100644 --- a/db/migrate/20140716131107_create_category_translation_tables.rb +++ b/db/migrate/20140716131107_create_category_translation_tables.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class CreateCategoryTranslationTables < ActiveRecord::Migration class PublicBodyCategory < ActiveRecord::Base translates :title, :description diff --git a/db/migrate/20140801132719_add_index_to_info_request_events.rb b/db/migrate/20140801132719_add_index_to_info_request_events.rb index 5f0a77eac..48c36f2b4 100644 --- a/db/migrate/20140801132719_add_index_to_info_request_events.rb +++ b/db/migrate/20140801132719_add_index_to_info_request_events.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AddIndexToInfoRequestEvents < ActiveRecord::Migration def change add_index :info_request_events, :event_type diff --git a/db/migrate/20140804120601_add_display_order_to_categories_and_headings.rb b/db/migrate/20140804120601_add_display_order_to_categories_and_headings.rb index c2e7e2ac3..a7160995d 100644 --- a/db/migrate/20140804120601_add_display_order_to_categories_and_headings.rb +++ b/db/migrate/20140804120601_add_display_order_to_categories_and_headings.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AddDisplayOrderToCategoriesAndHeadings < ActiveRecord::Migration def up add_column :public_body_categories_public_body_headings, :category_display_order, :integer diff --git a/db/migrate/20140824191444_create_widget_votes.rb b/db/migrate/20140824191444_create_widget_votes.rb new file mode 100644 index 000000000..467f937e2 --- /dev/null +++ b/db/migrate/20140824191444_create_widget_votes.rb @@ -0,0 +1,12 @@ +# -*- encoding : utf-8 -*- +class CreateWidgetVotes < ActiveRecord::Migration + def change + create_table :widget_votes do |t| + t.string :cookie + t.belongs_to :info_request, :null => false + + t.timestamps + end + add_index :widget_votes, :info_request_id + end +end diff --git a/db/seeds.rb b/db/seeds.rb index 664d8c74c..d12490d17 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # This file should contain all the record creation needed to seed the database with its default values. # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup). # diff --git a/doc/CHANGES.md b/doc/CHANGES.md index a654f3b6a..f4f75ce2b 100644 --- a/doc/CHANGES.md +++ b/doc/CHANGES.md @@ -1,3 +1,19 @@ +# rails-3-develop + +## Highlighted Features +* There is experimental support for using an STMP server, rather than sendmail, + for outgoing mail. There is not yet any ability to retry if the SMTP server is + unavailable. +* HTML 'widgets' advertising requests can be displayed on other sites in iframes. + If 'ENABLE_WIDGETS' is set to true in `general.yml` (the default is false), a link + to the widget code will appear in the right hand sidebar of a request page. +* Capistrano now caches themes (Henare Degan). + +## Upgrade Notes + +* Capistrano now caches themes in `shared/themes`. Run the `deploy:setup` task + to create the shared directory before making a new code deploy. + # Version 0.21 ## Highlighted Features diff --git a/lib/ability.rb b/lib/ability.rb index f63845e84..607f55286 100644 --- a/lib/ability.rb +++ b/lib/ability.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- module Ability def self.can_update_request_state?(user, request) (user && request.is_old_unclassified?) || request.is_owning_user?(user) diff --git a/lib/activerecord_errors_extensions.rb b/lib/activerecord_errors_extensions.rb index 8135d34f7..19bede539 100644 --- a/lib/activerecord_errors_extensions.rb +++ b/lib/activerecord_errors_extensions.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # Monkeypatch! activerecord/lib/active_record/validations.rb # Method to remove individual error messages from an ActiveRecord. module ActiveRecord diff --git a/lib/activesupport_cache_extensions.rb b/lib/activesupport_cache_extensions.rb index 2791d5996..4e9a6a69c 100644 --- a/lib/activesupport_cache_extensions.rb +++ b/lib/activesupport_cache_extensions.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # lib/activesupport_cache_extensions.rb: # Extensions / fixes to ActiveSupport::Cache # diff --git a/lib/acts_as_xapian/acts_as_xapian.rb b/lib/acts_as_xapian/acts_as_xapian.rb index 9194e8cc4..e0c7c6ae7 100644 --- a/lib/acts_as_xapian/acts_as_xapian.rb +++ b/lib/acts_as_xapian/acts_as_xapian.rb @@ -1,4 +1,4 @@ -# encoding: utf-8 +# -*- encoding : utf-8 -*- # acts_as_xapian/lib/acts_as_xapian.rb: # Xapian full text search in Ruby on Rails. # @@ -39,7 +39,7 @@ module ActsAsXapian ###################################################################### # Module level variables # TODO: must be some kind of cattr_accessor that can do this better - def ActsAsXapian.bindings_available + def self.bindings_available $acts_as_xapian_bindings_available end class NoXapianRubyBindingsError < StandardError @@ -58,40 +58,40 @@ module ActsAsXapian $acts_as_xapian_class_var_init = true end - def ActsAsXapian.db + def self.db @@db end - def ActsAsXapian.db_path=(db_path) + def self.db_path=(db_path) @@db_path = db_path end - def ActsAsXapian.db_path + def self.db_path @@db_path end - def ActsAsXapian.writable_db + def self.writable_db @@writable_db end - def ActsAsXapian.stemmer + def self.stemmer @@stemmer end - def ActsAsXapian.term_generator + def self.term_generator @@term_generator end - def ActsAsXapian.enquire + def self.enquire @@enquire end - def ActsAsXapian.query_parser + def self.query_parser @@query_parser end - def ActsAsXapian.values_by_prefix + def self.values_by_prefix @@values_by_prefix end - def ActsAsXapian.config + def self.config @@config end ###################################################################### # Initialisation - def ActsAsXapian.init(classname = nil, options = nil) + def self.init(classname = nil, options = nil) if not classname.nil? # store class and options for use later, when we open the db in readable_init @@init_values.push([classname,options]) @@ -99,7 +99,7 @@ module ActsAsXapian end # Reads the config file (if any) and sets up the path to the database we'll be using - def ActsAsXapian.prepare_environment + def self.prepare_environment return unless @@db_path.nil? # barf if we can't figure out the environment @@ -130,17 +130,17 @@ module ActsAsXapian # Opens / reopens the db for reading # TODO: we perhaps don't need to rebuild database and enquire and queryparser - # but db.reopen wasn't enough by itself, so just do everything it's easier. - def ActsAsXapian.readable_init + def self.readable_init raise NoXapianRubyBindingsError.new("Xapian Ruby bindings not installed") unless ActsAsXapian.bindings_available raise "acts_as_xapian hasn't been called in any models" if @@init_values.empty? prepare_environment # We need to reopen the database each time, so Xapian gets changes to it. - # Calling reopen() does not always pick up changes for reasons that I can + # Calling reopen does not always pick up changes for reasons that I can # only speculate about at the moment. (It is easy to reproduce this by - # changing the code below to use reopen() rather than open() followed by - # close(), and running rake spec.) + # changing the code below to use reopen rather than open followed by + # close, and running rake spec.) if !@@db.nil? @@db.close end @@ -157,23 +157,20 @@ module ActsAsXapian end # Make a new query parser - def ActsAsXapian.init_query_parser + def self.init_query_parser # for queries @@query_parser = Xapian::QueryParser.new @@query_parser.stemmer = @@stemmer @@query_parser.stemming_strategy = Xapian::QueryParser::STEM_SOME @@query_parser.database = @@db @@query_parser.default_op = Xapian::Query::OP_AND - begin - @@query_parser.set_max_wildcard_expansion(1000) - rescue NoMethodError - # The set_max_wildcard_expansion method was introduced in Xapian 1.2.7, - # so may legitimately not be available. - # - # Large installations of Alaveteli should consider - # upgrading, because uncontrolled wildcard expansion - # can crash the whole server: see http://trac.xapian.org/ticket/350 - end + # The set_max_wildcard_expansion method was introduced in Xapian 1.2.7, + # so may legitimately not be available. + # + # Large installations of Alaveteli should consider + # upgrading, because uncontrolled wildcard expansion + # can crash the whole server: see http://trac.xapian.org/ticket/350 + @@query_parser.set_max_wildcard_expansion(1000) if @@query_parser.respond_to? :set_max_wildcard_expansion @@stopper = Xapian::SimpleStopper.new @@stopper.add("and") @@ -186,61 +183,68 @@ module ActsAsXapian @@values_by_prefix = {} @@value_ranges_store = [] - for init_value_pair in @@init_values - classname = init_value_pair[0] - options = init_value_pair[1] - + @@init_values.each do |classname, options| # go through the various field types, and tell query parser about them, # and error check them - i.e. check for consistency between models @@query_parser.add_boolean_prefix("model", "M") @@query_parser.add_boolean_prefix("modelid", "I") - if options[:terms] - for term in options[:terms] - raise "Use a single capital letter for term code" if not term[1].match(/^[A-Z]$/) - raise "M and I are reserved for use as the model/id term" if term[1] == "M" or term[1] == "I" - raise "model and modelid are reserved for use as the model/id prefixes" if term[2] == "model" or term[2] == "modelid" - raise "Z is reserved for stemming terms" if term[1] == "Z" - raise "Already have code '" + term[1] + "' in another model but with different prefix '" + @@terms_by_capital[term[1]] + "'" if @@terms_by_capital.include?(term[1]) && @@terms_by_capital[term[1]] != term[2] - @@terms_by_capital[term[1]] = term[2] - # TODO: use boolean here so doesn't stem our URL names in WhatDoTheyKnow - # If making acts_as_xapian generic, would really need to make the :terms have - # another option that lets people choose non-boolean for terms that need it - # (i.e. searching explicitly within a free text field) - @@query_parser.add_boolean_prefix(term[2], term[1]) - end + init_terms(options[:terms]) if options[:terms] + init_values(options[:values]) if options[:values] + end + end + + def self.init_values(values) + values.each do |method, index, prefix, value_type| + raise "Value index '#{index}' must be an Integer, is #{index.class}" unless index.is_a? Integer + if @@values_by_number.include?(index) && @@values_by_number[index] != prefix + raise "Already have value index '#{index}' in another model " \ + "but with different prefix '#{@@values_by_number[index]}'" end - if options[:values] - for value in options[:values] - raise "Value index '"+value[1].to_s+"' must be an integer, is " + value[1].class.to_s if value[1].class != 1.class - raise "Already have value index '" + value[1].to_s + "' in another model but with different prefix '" + @@values_by_number[value[1]].to_s + "'" if @@values_by_number.include?(value[1]) && @@values_by_number[value[1]] != value[2] - - # date types are special, mark them so the first model they're seen for - if !@@values_by_number.include?(value[1]) - if value[3] == :date - value_range = Xapian::DateValueRangeProcessor.new(value[1]) - elsif value[3] == :string - value_range = Xapian::StringValueRangeProcessor.new(value[1]) - elsif value[3] == :number - value_range = Xapian::NumberValueRangeProcessor.new(value[1]) - else - raise "Unknown value type '" + value[3].to_s + "'" - end - - @@query_parser.add_valuerangeprocessor(value_range) - - # stop it being garbage collected, as - # add_valuerangeprocessor ref is outside Ruby's GC - @@value_ranges_store.push(value_range) - end + # date types are special, mark them so the first model they're seen for + unless @@values_by_number.include?(index) + case value_type + when :date + value_range = Xapian::DateValueRangeProcessor.new(index) + when :string + value_range = Xapian::StringValueRangeProcessor.new(index) + when :number + value_range = Xapian::NumberValueRangeProcessor.new(index) + else + raise "Unknown value type '#{value_type}'" + end - @@values_by_number[value[1]] = value[2] - @@values_by_prefix[value[2]] = value[1] - end + @@query_parser.add_valuerangeprocessor(value_range) + + # stop it being garbage collected, as + # add_valuerangeprocessor ref is outside Ruby's GC + @@value_ranges_store.push(value_range) + end + + @@values_by_number[index] = prefix + @@values_by_prefix[prefix] = index + end + end + + def self.init_terms(terms) + terms.each do |method, term_code, prefix| + raise "Use a single capital letter for term code" if not term_code.match(/^[A-Z]$/) + raise "M and I are reserved for use as the model/id term" if term_code == "M" || term_code == "I" + raise "model and modelid are reserved for use as the model/id prefixes" if prefix == "model" || prefix == "modelid" + raise "Z is reserved for stemming terms" if term_code == "Z" + if @@terms_by_capital.include?(term_code) && @@terms_by_capital[term_code] != prefix + raise "Already have code '#{term_code}' in another model but with different prefix " \ + "'#{@@terms_by_capital[term_code]}'" end + @@terms_by_capital[term_code] = prefix + # TODO: use boolean here so doesn't stem our URL names in WhatDoTheyKnow + # If making acts_as_xapian generic, would really need to make the :terms have + # another option that lets people choose non-boolean for terms that need it + # (i.e. searching explicitly within a free text field) + @@query_parser.add_boolean_prefix(prefix, term_code) end end - def ActsAsXapian.writable_init(suffix = "") + def self.writable_init(suffix = "") raise NoXapianRubyBindingsError.new("Xapian Ruby bindings not installed") unless ActsAsXapian.bindings_available raise "acts_as_xapian hasn't been called in any models" if @@init_values.empty? @@ -256,7 +260,7 @@ module ActsAsXapian # for indexing @@writable_db = Xapian::WritableDatabase.new(full_path, Xapian::DB_CREATE_OR_OPEN) @@enquire = Xapian::Enquire.new(@@writable_db) - @@term_generator = Xapian::TermGenerator.new() + @@term_generator = Xapian::TermGenerator.new @@term_generator.set_flags(Xapian::TermGenerator::FLAG_SPELLING, 0) @@term_generator.database = @@writable_db @@term_generator.stemmer = @@stemmer @@ -332,7 +336,7 @@ module ActsAsXapian delay *= 2 delay = MSET_MAX_DELAY if delay > MSET_MAX_DELAY - ActsAsXapian.db.reopen() + ActsAsXapian.db.reopen retry else raise @@ -558,7 +562,7 @@ module ActsAsXapian matches = ActsAsXapian.enquire.mset(0, 100, 100) # TODO: so this whole method will only work with 100 docs # Get set of relevant terms for those documents - selection = Xapian::RSet.new() + selection = Xapian::RSet.new iter = matches._begin while not iter.equals(matches._end) selection.add_document(iter) @@ -610,30 +614,29 @@ module ActsAsXapian # flush your changes. Specifying flush will reduce performance, but make # sure that each index update is definitely saved to disk before # logging in the database that it has been. - def ActsAsXapian.update_index(flush = false, verbose = false) + def self.update_index(flush = false, verbose = false) # STDOUT.puts("start of ActsAsXapian.update_index") if verbose # Before calling writable_init we have to make sure every model class has been initialized. # i.e. has had its class code loaded, so acts_as_xapian has been called inside it, and # we have the info from acts_as_xapian. - model_classes = ActsAsXapianJob.find_by_sql("select model from acts_as_xapian_jobs group by model").map {|a| a.model.constantize} + model_classes = ActsAsXapianJob.pluck("DISTINCT model").map { |a| a.constantize } # If there are no models in the queue, then nothing to do - return if model_classes.size == 0 + return if model_classes.empty? ActsAsXapian.writable_init # Abort if full rebuild is going on new_path = ActsAsXapian.db_path + ".new" if File.exist?(new_path) - raise "aborting incremental index update while full index rebuild happens; found existing " + new_path + raise "aborting incremental index update while full index rebuild happens; found existing #{new_path}" end - ids_to_refresh = ActsAsXapianJob.find(:all).map() { |i| i.id } - for id in ids_to_refresh + ActsAsXapianJob.pluck(:id).each do |id| job = nil begin ActiveRecord::Base.transaction do begin - job = ActsAsXapianJob.find(id, :lock =>true) + job = ActsAsXapianJob.find(id, :lock => true) rescue ActiveRecord::RecordNotFound => e # This could happen if while we are working the model # was updated a second time by another process. In that case @@ -642,30 +645,7 @@ module ActsAsXapian #STDERR.puts("job with #{id} vanished under foot") if verbose next end - STDOUT.puts("ActsAsXapian.update_index #{job.action} #{job.model} #{job.model_id.to_s} #{Time.now.to_s}") if verbose - - begin - if job.action == 'update' - # TODO: Index functions may reference other models, so we could eager load here too? - model = job.model.constantize.find(job.model_id) # :include => cls.constantize.xapian_options[:include] - model.xapian_index - elsif job.action == 'destroy' - # Make dummy model with right id, just for destruction - model = job.model.constantize.new - model.id = job.model_id - model.xapian_destroy - else - raise "unknown ActsAsXapianJob action '" + job.action + "'" - end - rescue ActiveRecord::RecordNotFound => e - # this can happen if the record was hand deleted in the database - job.action = 'destroy' - retry - end - if flush - ActsAsXapian.writable_db.flush - end - job.destroy + run_job(job, flush, verbose) end rescue => detail # print any error, and carry on so other things are indexed @@ -678,7 +658,34 @@ module ActsAsXapian ActsAsXapian.writable_db.close end - def ActsAsXapian._is_xapian_db(path) + def self.run_job(job, flush, verbose) + STDOUT.puts("ActsAsXapian.update_index #{job.action} #{job.model} #{job.model_id.to_s} #{Time.now.to_s}") if verbose + + begin + if job.action == 'update' + # TODO: Index functions may reference other models, so we could eager load here too? + model = job.model.constantize.find(job.model_id) # :include => cls.constantize.xapian_options[:include] + model.xapian_index + elsif job.action == 'destroy' + # Make dummy model with right id, just for destruction + model = job.model.constantize.new + model.id = job.model_id + model.xapian_destroy + else + raise "unknown ActsAsXapianJob action '#{job.action}'" + end + rescue ActiveRecord::RecordNotFound => e + # this can happen if the record was hand deleted in the database + job.action = 'destroy' + retry + end + if flush + ActsAsXapian.writable_db.flush + end + job.destroy + end + + def self._is_xapian_db(path) is_db = File.exist?(File.join(path, "iamflint")) || File.exist?(File.join(path, "iamchert")) return is_db end @@ -690,7 +697,7 @@ module ActsAsXapian # happens (i.e. while the .new database is there) - any index update jobs # are left in the database, and will run after the rebuild has finished. - def ActsAsXapian.rebuild_index(model_classes, verbose = false, terms = true, values = true, texts = true, safe_rebuild = true) + def self.rebuild_index(model_classes, verbose = false, terms = true, values = true, texts = true, safe_rebuild = true) #raise "when rebuilding all, please call as first and only thing done in process / task" if not ActsAsXapian.writable_db.nil? prepare_environment @@ -751,7 +758,7 @@ module ActsAsXapian @@db_path = old_path end - def ActsAsXapian._rebuild_index_safely(model_classes, verbose, terms, values, texts) + def self._rebuild_index_safely(model_classes, verbose, terms, values, texts) batch_size = 1000 for model_class in model_classes model_class_count = model_class.count diff --git a/lib/acts_as_xapian/tasks/xapian.rake b/lib/acts_as_xapian/tasks/xapian.rake index c1986ce1e..52d94011a 100644 --- a/lib/acts_as_xapian/tasks/xapian.rake +++ b/lib/acts_as_xapian/tasks/xapian.rake @@ -9,7 +9,7 @@ namespace :xapian do # "verbose=true" to print model name as it is run. desc 'Updates Xapian search index with changes to models since last call' task :update_index => :environment do - ActsAsXapian.update_index(ENV['flush'] ? true : false, ENV['verbose'] ? true : false) + ActsAsXapian.update_index(ENV['flush'], ENV['verbose']) end # Parameters - specify 'models="PublicBody User"' to say which models diff --git a/lib/alaveteli_external_command.rb b/lib/alaveteli_external_command.rb index ddf968f90..36a709c16 100644 --- a/lib/alaveteli_external_command.rb +++ b/lib/alaveteli_external_command.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require 'external_command' module AlaveteliExternalCommand diff --git a/lib/alaveteli_file_types.rb b/lib/alaveteli_file_types.rb index 617048c05..2b5aa3efb 100644 --- a/lib/alaveteli_file_types.rb +++ b/lib/alaveteli_file_types.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AlaveteliFileTypes # To add an image, create a file with appropriate name corresponding to the # mime type in public/images e.g. icon_image_tiff_large.png @@ -87,4 +88,4 @@ class AlaveteliFileTypes return nil end end -end
\ No newline at end of file +end diff --git a/lib/alaveteli_localization.rb b/lib/alaveteli_localization.rb index 2b6978c92..6e9dbeac3 100644 --- a/lib/alaveteli_localization.rb +++ b/lib/alaveteli_localization.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AlaveteliLocalization class << self def set_locales(available_locales, default_locale) diff --git a/lib/alaveteli_text_masker.rb b/lib/alaveteli_text_masker.rb index 68ff0d318..3c2bcf825 100644 --- a/lib/alaveteli_text_masker.rb +++ b/lib/alaveteli_text_masker.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- module AlaveteliTextMasker extend self DoNotBinaryMask = [ 'image/tiff', @@ -28,9 +29,7 @@ module AlaveteliTextMasker end def apply_pdf_masks!(text, options = {}) - uncompressed_text = nil - uncompressed_text = AlaveteliExternalCommand.run("pdftk", "-", "output", "-", "uncompress", - :stdin_string => text) + uncompressed_text = uncompress_pdf(text) # if we managed to uncompress the PDF... if !uncompressed_text.blank? # then censor stuff (making a copy so can compare again in a bit) @@ -39,19 +38,13 @@ module AlaveteliTextMasker # if the censor rule removed something... if censored_uncompressed_text != uncompressed_text # then use the altered file (recompressed) - recompressed_text = nil - if AlaveteliConfiguration::use_ghostscript_compression == true - command = ["gs", "-sDEVICE=pdfwrite", "-dCompatibilityLevel=1.4", "-dPDFSETTINGS=/screen", "-dNOPAUSE", "-dQUIET", "-dBATCH", "-sOutputFile=-", "-"] - else - command = ["pdftk", "-", "output", "-", "compress"] - end - recompressed_text = AlaveteliExternalCommand.run(*(command + [{:stdin_string=>censored_uncompressed_text}])) + recompressed_text = compress_pdf(censored_uncompressed_text) if recompressed_text.blank? # buggy versions of pdftk sometimes fail on # compression, I don't see it's a disaster in # these cases to save an uncompressed version? recompressed_text = censored_uncompressed_text - logger.warn "Unable to compress PDF; problem with your pdftk version?" + Rails.logger.warn "Unable to compress PDF; problem with your pdftk version?" end if !recompressed_text.blank? text.replace recompressed_text @@ -62,6 +55,27 @@ module AlaveteliTextMasker private + def uncompress_pdf(text) + AlaveteliExternalCommand.run("pdftk", "-", "output", "-", "uncompress", :stdin_string => text) + end + + def compress_pdf(text) + if AlaveteliConfiguration::use_ghostscript_compression + command = ["gs", + "-sDEVICE=pdfwrite", + "-dCompatibilityLevel=1.4", + "-dPDFSETTINGS=/screen", + "-dNOPAUSE", + "-dQUIET", + "-dBATCH", + "-sOutputFile=-", + "-"] + else + command = ["pdftk", "-", "output", "-", "compress"] + end + AlaveteliExternalCommand.run(*(command + [ :stdin_string => text ])) + end + # Replace text in place def apply_binary_masks!(text, options = {}) # Keep original size, so can check haven't resized it diff --git a/lib/attachment_to_html/adapter.rb b/lib/attachment_to_html/adapter.rb new file mode 100644 index 000000000..058fb2a01 --- /dev/null +++ b/lib/attachment_to_html/adapter.rb @@ -0,0 +1,67 @@ +module AttachmentToHTML + class Adapter + attr_reader :attachment + + # Public: Initialize a converter + # + # attachment - the FoiAttachment to convert to HTML + # opts - a Hash of options (default: {}): + # No options currently accepted + def initialize(attachment, opts = {}) + @attachment = attachment + end + + # Public: The title to use in the <title> tag + # + # Returns a String + def title + @title ||= attachment.display_filename + end + + # Public: The contents of the extracted html <body> tag + # + # Returns a String + def body + @body ||= parse_body + end + + def parse_body + convert + end + + # Public: Was the document conversion successful? + # + # Returns true + def success? + true + end + + def has_content? + !body.gsub(/\s+/,"").gsub(/\<[^\>]*\>/, "").empty? + end + + def contains_images? + body.match(/<img[^>]*>/mi) + end + + def create_tempfile(text) + tempfile = if RUBY_VERSION.to_f >= 1.9 + Tempfile.new('foiextract', '.', :encoding => text.encoding) + else + Tempfile.new('foiextract', '.') + end + tempfile.print(text) + tempfile.flush + tempfile + end + + def cleanup_tempfile(tempfile) + tempfile.close + tempfile.delete + end + + def attachment_body + @attachment_body ||= attachment.body + end + end +end diff --git a/lib/attachment_to_html/adapters/could_not_convert.rb b/lib/attachment_to_html/adapters/could_not_convert.rb index 8e4bf39dc..745a54114 100644 --- a/lib/attachment_to_html/adapters/could_not_convert.rb +++ b/lib/attachment_to_html/adapters/could_not_convert.rb @@ -1,49 +1,15 @@ +# -*- encoding : utf-8 -*- module AttachmentToHTML module Adapters - class CouldNotConvert - - attr_reader :attachment - - # Public: Initialize a PDF converter - # - # attachment - the FoiAttachment to convert to HTML - # opts - a Hash of options (default: {}): - # No options currently accepted - def initialize(attachment, opts = {}) - @attachment = attachment - end - - # Public: The title to use in the <title> tag - # - # Returns a String - def title - @title ||= attachment.display_filename - end - - # Public: The contents of the extracted html <body> tag - # - # Returns a String - def body - @body ||= parse_body - end - - - # Public: Was the document conversion successful? - # As this is a fallback option and not doing anything dynamic - # we're assuming this is successful whatever the case - # - # Returns true - def success? - true - end - + # As this is a fallback option and not doing anything dynamic + # we're assuming this is successful whatever the case + class CouldNotConvert < Adapter private def parse_body "<p>Sorry, we were unable to convert this file to HTML. " \ "Please use the download link at the top right.</p>" end - end end -end
\ No newline at end of file +end diff --git a/lib/attachment_to_html/adapters/google_docs_viewer.rb b/lib/attachment_to_html/adapters/google_docs_viewer.rb index 991fbb757..0817d08fd 100644 --- a/lib/attachment_to_html/adapters/google_docs_viewer.rb +++ b/lib/attachment_to_html/adapters/google_docs_viewer.rb @@ -1,9 +1,14 @@ +# -*- encoding : utf-8 -*- module AttachmentToHTML module Adapters # Renders the attachment in a Google Docs Viewer - class GoogleDocsViewer - - attr_reader :attachment, :attachment_url + # + # We can't really tell whether the document conversion has been + # successful as such; We're assuming that given a correctly + # constructed iframe (which is tested) that Google will make this + # Just Work. + class GoogleDocsViewer < Adapter + attr_reader :attachment_url # Public: Initialize a GoogleDocsViewer converter # @@ -12,35 +17,10 @@ module AttachmentToHTML # :attachment_url - a String url to the attachment for # Google to render (default: nil) def initialize(attachment, opts = {}) - @attachment = attachment + super @attachment_url = opts.fetch(:attachment_url, nil) end - # Public: The title to use in the <title> tag - # - # Returns a String - def title - @title ||= attachment.display_filename - end - - # Public: The contents of the extracted html <body> tag - # - # Returns a String - def body - @body ||= parse_body - end - - # Public: Was the document conversion successful? - # We can't really tell whether the document conversion has been - # successful as such; We're assuming that given a correctly - # constructed iframe (which is tested) that Google will make this - # Just Work. - # - # Returns true - def success? - true - end - private def parse_body @@ -50,7 +30,6 @@ module AttachmentToHTML def protocol AlaveteliConfiguration.force_ssl ? 'https' : 'http' end - end end end diff --git a/lib/attachment_to_html/adapters/pdf.rb b/lib/attachment_to_html/adapters/pdf.rb index a010b0342..afc8fbcb0 100644 --- a/lib/attachment_to_html/adapters/pdf.rb +++ b/lib/attachment_to_html/adapters/pdf.rb @@ -1,10 +1,11 @@ +# -*- encoding : utf-8 -*- module AttachmentToHTML module Adapters # Convert application/pdf documents in to HTML - class PDF + class PDF < Adapter TOO_MANY_IMAGES = 51 - attr_reader :attachment, :tmpdir + attr_reader :tmpdir # Public: Initialize a PDF converter # @@ -13,24 +14,10 @@ module AttachmentToHTML # :tmpdir - String name of directory to store the # converted document def initialize(attachment, opts = {}) - @attachment = attachment + super @tmpdir = opts.fetch(:tmpdir, ::Rails.root.join('tmp')) end - # Public: The title to use in the <title> tag - # - # Returns a String - def title - @title ||= attachment.display_filename - end - - # Public: The contents of the extracted html <body> tag - # - # Returns a String - def body - @body ||= parse_body - end - # Public: Was the document conversion successful? # # Returns a Boolean @@ -47,14 +34,6 @@ module AttachmentToHTML match ? match[1] : '' end - def has_content? - !body.gsub(/\s+/,"").gsub(/\<[^\>]*\>/, "").empty? - end - - def contains_images? - body.match(/<img[^>]*>/mi) ? true : false - end - # Works around https://bugs.freedesktop.org/show_bug.cgi?id=77932 in pdftohtml def contains_too_many_images? number_of_images_in_body >= TOO_MANY_IMAGES @@ -81,28 +60,6 @@ module AttachmentToHTML html end end - - def create_tempfile(text) - tempfile = if RUBY_VERSION.to_f >= 1.9 - Tempfile.new('foiextract', '.', - :encoding => text.encoding) - else - Tempfile.new('foiextract', '.') - end - tempfile.print(text) - tempfile.flush - tempfile - end - - def cleanup_tempfile(tempfile) - tempfile.close - tempfile.delete - end - - def attachment_body - @attachment_body ||= attachment.body - end - end end end diff --git a/lib/attachment_to_html/adapters/rtf.rb b/lib/attachment_to_html/adapters/rtf.rb index 95f499689..4a08bf618 100644 --- a/lib/attachment_to_html/adapters/rtf.rb +++ b/lib/attachment_to_html/adapters/rtf.rb @@ -1,9 +1,10 @@ +# -*- encoding : utf-8 -*- module AttachmentToHTML module Adapters # Convert application/rtf documents in to HTML - class RTF + class RTF < Adapter - attr_reader :attachment, :tmpdir + attr_reader :tmpdir # Public: Initialize a RTF converter # @@ -12,24 +13,10 @@ module AttachmentToHTML # :tmpdir - String name of directory to store the # converted document def initialize(attachment, opts = {}) - @attachment = attachment + super @tmpdir = opts.fetch(:tmpdir, ::Rails.root.join('tmp')) end - # Public: The title to use in the <title> tag - # - # Returns a String - def title - @title ||= attachment.display_filename - end - - # Public: The contents of the extracted html <body> tag - # - # Returns a String - def body - @body ||= parse_body - end - # Public: Was the document conversion successful? # # Returns a Boolean @@ -44,14 +31,6 @@ module AttachmentToHTML match ? match[1] : '' end - def has_content? - !body.gsub(/\s+/,"").gsub(/\<[^\>]*\>/, "").empty? - end - - def contains_images? - body.match(/<img[^>]*>/mi) ? true : false - end - def convert # Get the attachment body outside of the chdir call as getting # the body may require opening files too @@ -82,28 +61,6 @@ module AttachmentToHTML end html end - - def create_tempfile(text) - tempfile = if RUBY_VERSION.to_f >= 1.9 - Tempfile.new('foiextract', '.', - :encoding => text.encoding) - else - Tempfile.new('foiextract', '.') - end - tempfile.print(text) - tempfile.flush - tempfile - end - - def cleanup_tempfile(tempfile) - tempfile.close - tempfile.delete - end - - def attachment_body - @attachment_body ||= attachment.body - end - end end end diff --git a/lib/attachment_to_html/adapters/text.rb b/lib/attachment_to_html/adapters/text.rb index e99183f0e..61e4e57a8 100644 --- a/lib/attachment_to_html/adapters/text.rb +++ b/lib/attachment_to_html/adapters/text.rb @@ -1,33 +1,8 @@ +# -*- encoding : utf-8 -*- module AttachmentToHTML module Adapters # Convert text/plain documents in to HTML - class Text - - attr_reader :attachment - - # Public: Initialize a Text converter - # - # attachment - the FoiAttachment to convert to HTML - # opts - a Hash of options (default: {}): - # No options currently accepted - def initialize(attachment, opts = {}) - @attachment = attachment - end - - # Public: The title to use in the <title> tag - # - # Returns a String - def title - @title ||= attachment.display_filename - end - - # Public: The contents of the extracted html <body> tag - # - # Returns a String - def body - @body ||= parse_body - end - + class Text < Adapter # Public: Was the document conversion successful? # # Returns a Boolean @@ -43,19 +18,6 @@ module AttachmentToHTML text = MySociety::Format.make_clickable(text) text = text.gsub(/\n/, '<br>') end - - def parse_body - convert - end - - def has_content? - !body.gsub(/\s+/,"").gsub(/\<[^\>]*\>/, "").empty? - end - - def contains_images? - body.match(/<img[^>]*>/mi) ? true : false - end - end end end diff --git a/lib/attachment_to_html/attachment_to_html.rb b/lib/attachment_to_html/attachment_to_html.rb index 2f7c08264..2e8d35ca9 100644 --- a/lib/attachment_to_html/attachment_to_html.rb +++ b/lib/attachment_to_html/attachment_to_html.rb @@ -1,5 +1,8 @@ +# -*- encoding : utf-8 -*- require 'view' +require 'attachment_to_html/adapter' + Dir[File.dirname(__FILE__) + '/adapters/*.rb'].each do |file| require file end diff --git a/lib/attachment_to_html/view.rb b/lib/attachment_to_html/view.rb index e6991d44e..0d5b205b7 100644 --- a/lib/attachment_to_html/view.rb +++ b/lib/attachment_to_html/view.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- module AttachmentToHTML class View < ERB diff --git a/lib/confidence_intervals.rb b/lib/confidence_intervals.rb index 9fe38045a..83f736c63 100644 --- a/lib/confidence_intervals.rb +++ b/lib/confidence_intervals.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # Calculate the confidence interval for a samples from a binonial # distribution using Wilson's score interval. For more theoretical # details, please see: diff --git a/lib/configuration.rb b/lib/configuration.rb index 90fd30d5f..ab7d1a65c 100644 --- a/lib/configuration.rb +++ b/lib/configuration.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.dirname(__FILE__) + '/../commonlib/rblib/config' # Load intial mySociety config @@ -32,8 +33,9 @@ module AlaveteliConfiguration :DISABLE_EMERGENCY_USER => false, :DOMAIN => 'localhost:3000', :DONATION_URL => '', - :EXCEPTION_NOTIFICATIONS_FROM => '', - :EXCEPTION_NOTIFICATIONS_TO => '', + :ENABLE_WIDGETS => false, + :EXCEPTION_NOTIFICATIONS_FROM => 'errors@localhost', + :EXCEPTION_NOTIFICATIONS_TO => 'user-support@localhost', :FORCE_REGISTRATION_ON_NEW_REQUEST => false, :FORCE_SSL => true, :FORWARD_NONBOUNCE_RESPONSES_TO => 'user-support@localhost', @@ -52,6 +54,7 @@ module AlaveteliConfiguration :MTA_LOG_TYPE => 'exim', :NEW_RESPONSE_REMINDER_AFTER_DAYS => [3, 10, 24], :OVERRIDE_ALL_PUBLIC_BODY_REQUEST_EMAILS => '', + :PRODUCTION_MAILER_DELIVERY_METHOD => 'sendmail', :PUBLIC_BODY_STATISTICS_PAGE => false, :PUBLIC_BODY_LIST_FALLBACK_TO_DEFAULT_LOCALE => false, :RAW_EMAILS_LOCATION => 'files/raw_emails', @@ -63,6 +66,13 @@ module AlaveteliConfiguration :RESPONSIVE_STYLING => true, :SITE_NAME => 'Alaveteli', :SKIP_ADMIN_AUTH => false, + :SMTP_MAILER_ADDRESS => 'localhost', + :SMTP_MAILER_PORT => 25, + :SMTP_MAILER_DOMAIN => '', + :SMTP_MAILER_USER_NAME => '', + :SMTP_MAILER_PASSWORD => '', + :SMTP_MAILER_AUTHENTICATION => 'plain', + :SMTP_MAILER_ENABLE_STARTTLS_AUTO => true, :SPECIAL_REPLY_VERY_LATE_AFTER_DAYS => 60, :THEME_BRANCH => false, :THEME_URL => "", @@ -78,10 +88,11 @@ module AlaveteliConfiguration :UTILITY_SEARCH_PATH => ["/usr/bin", "/usr/local/bin"], :VARNISH_HOST => '', :WORKING_OR_CALENDAR_DAYS => 'working', + :USE_BULLET_IN_DEVELOPMENT => false } - end + end - def AlaveteliConfiguration.method_missing(name) + def self.method_missing(name) key = name.to_s.upcase if DEFAULTS.has_key?(key.to_sym) MySociety::Config.get(key, DEFAULTS[key.to_sym]) diff --git a/lib/date_quarter.rb b/lib/date_quarter.rb index ac159b420..b8cb03593 100644 --- a/lib/date_quarter.rb +++ b/lib/date_quarter.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- module DateQuarter extend self diff --git a/lib/generators/acts_as_xapian/acts_as_xapian_generator.rb b/lib/generators/acts_as_xapian/acts_as_xapian_generator.rb index 434c02cb5..0e525d868 100644 --- a/lib/generators/acts_as_xapian/acts_as_xapian_generator.rb +++ b/lib/generators/acts_as_xapian/acts_as_xapian_generator.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require 'rails/generators/active_record/migration' class ActsAsXapianGenerator < Rails::Generators::Base diff --git a/lib/generators/acts_as_xapian/templates/migration.rb b/lib/generators/acts_as_xapian/templates/migration.rb index 84a9dd766..b390cd933 100644 --- a/lib/generators/acts_as_xapian/templates/migration.rb +++ b/lib/generators/acts_as_xapian/templates/migration.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class CreateActsAsXapian < ActiveRecord::Migration def self.up create_table :acts_as_xapian_jobs do |t| diff --git a/lib/has_tag_string/has_tag_string.rb b/lib/has_tag_string/has_tag_string.rb index c28720f04..42d6c8898 100644 --- a/lib/has_tag_string/has_tag_string.rb +++ b/lib/has_tag_string/has_tag_string.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # lib/has_tag_string.rb: # Lets a model have tags, represented as space separate strings in a public # interface, but stored in the database as keys. Each tag can have a value @@ -31,7 +32,7 @@ module HasTagString # Parses a text version of one single tag, such as "a:b" and returns # the name and value, with nil for value if there isn't one. - def HasTagStringTag.split_tag_into_name_value(tag) + def self.split_tag_into_name_value(tag) sections = tag.split(/:/) name = sections[0] if sections[1] @@ -151,7 +152,7 @@ module HasTagString ###################################################################### # Main entry point, add has_tag_string to your model. module HasMethods - def has_tag_string() + def has_tag_string has_many :tags, :conditions => "model = '" + self.to_s + "'", :foreign_key => "model_id", :class_name => 'HasTagString::HasTagStringTag' include InstanceMethods diff --git a/lib/health_checks/checks/days_ago_check.rb b/lib/health_checks/checks/days_ago_check.rb index 793fff586..3c1cb784f 100644 --- a/lib/health_checks/checks/days_ago_check.rb +++ b/lib/health_checks/checks/days_ago_check.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- module HealthChecks module Checks class DaysAgoCheck @@ -19,7 +20,7 @@ module HealthChecks "#{ super }: #{ subject.call }" end - def check + def ok? subject.call >= days.days.ago end diff --git a/lib/health_checks/health_checkable.rb b/lib/health_checks/health_checkable.rb index 5d674ca32..1e324c1c7 100644 --- a/lib/health_checks/health_checkable.rb +++ b/lib/health_checks/health_checkable.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- module HealthChecks module HealthCheckable @@ -12,12 +13,8 @@ module HealthChecks self.class.to_s end - def check - raise NotImplementedError - end - def ok? - check ? true : false + raise NotImplementedError end def message diff --git a/lib/health_checks/health_checks.rb b/lib/health_checks/health_checks.rb index 6f0c9de8e..6c98365fc 100644 --- a/lib/health_checks/health_checks.rb +++ b/lib/health_checks/health_checks.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require 'health_checkable' Dir[File.dirname(__FILE__) + '/checks/*.rb'].each do |file| @@ -31,7 +32,7 @@ module HealthChecks private def assert_valid_check(check) - check.respond_to?(:check) + check.respond_to?(:ok?) end end diff --git a/lib/i18n_fixes.rb b/lib/i18n_fixes.rb index 64c370477..6c7cb8877 100644 --- a/lib/i18n_fixes.rb +++ b/lib/i18n_fixes.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # Some of the monkeypatches in this file should possibly be submitted # as patches, but most are here because they should go away when we # upgrade to Rails 3.x diff --git a/lib/languages.rb b/lib/languages.rb index a45071a67..4f51f9bee 100644 --- a/lib/languages.rb +++ b/lib/languages.rb @@ -1,4 +1,4 @@ -# coding: utf-8 +# -*- encoding : utf-8 -*- class LanguageNames def self.get_language_name(locale) language_names = { @@ -32,6 +32,7 @@ class LanguageNames 'ce' => 'нохчийн мотт', 'ny' => 'chiCheŵa', 'zh' => '中文 (Zhōngwén)', + 'zh-HK' => '中文(香港)', 'cv' => 'чӑваш чӗлхи', 'kw' => 'Kernewek', 'co' => 'corsu', @@ -188,6 +189,7 @@ class LanguageNames 'zu' => 'isiZulu' } locale = locale.sub("_", "-") # normalize + return language_names[locale] if language_names[locale] main_part = I18n::Locale::Tag::Simple.tag(locale).subtags[0] return language_names[main_part] end diff --git a/lib/mail_handler/backends/mail_backend.rb b/lib/mail_handler/backends/mail_backend.rb index 974873b30..34fbc91ab 100644 --- a/lib/mail_handler/backends/mail_backend.rb +++ b/lib/mail_handler/backends/mail_backend.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require 'mail' require 'mapi/msg' require 'mapi/convert' @@ -35,7 +36,7 @@ module MailHandler module Backends module MailBackend - def backend() + def backend 'Mail' end @@ -64,7 +65,12 @@ module MailHandler # Return a copy of the file name for the mail part def get_part_file_name(part) part_file_name = part.filename - part_file_name.nil? ? nil : part_file_name.dup + part_file_name = part_file_name.nil? ? nil : part_file_name.dup + if part_file_name + part_file_name = CGI.unescape(part_file_name) + part_file_name = convert_string_to_utf8(part_file_name, part.charset) + end + part_file_name end # Get the body of a mail part diff --git a/lib/mail_handler/backends/mail_extensions.rb b/lib/mail_handler/backends/mail_extensions.rb index f778cbc14..b39e54d08 100644 --- a/lib/mail_handler/backends/mail_extensions.rb +++ b/lib/mail_handler/backends/mail_extensions.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require 'mail/message' require 'mail/part' require 'mail/fields/common/parameter_hash' @@ -37,7 +38,7 @@ module Mail # Can be removed when we no longer support Ruby 1.8 class Ruby18 - def Ruby18.b_value_decode(str) + def self.b_value_decode(str) match = str.match(/\=\?(.+)?\?[Bb]\?(.+)?\?\=/m) if match encoding = match[1] @@ -55,7 +56,7 @@ module Mail str end - def Ruby18.q_value_decode(str) + def self.q_value_decode(str) match = str.match(/\=\?(.+)?\?[Qq]\?(.+)?\?\=/m) if match encoding = match[1] @@ -75,7 +76,7 @@ module Mail private - def Ruby18.fix_encoding(encoding) + def self.fix_encoding(encoding) case encoding.upcase when 'UTF8' 'UTF-8' @@ -86,7 +87,7 @@ module Mail end class Ruby19 - def Ruby19.b_value_decode(str) + def self.b_value_decode(str) match = str.match(/\=\?(.+)?\?[Bb]\?(.+)?\?\=/m) if match charset = match[1] diff --git a/lib/mail_handler/mail_handler.rb b/lib/mail_handler/mail_handler.rb index 33d939e22..313869d16 100644 --- a/lib/mail_handler/mail_handler.rb +++ b/lib/mail_handler/mail_handler.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # Handles the parsing of email require 'tmpdir' @@ -133,7 +134,7 @@ module MailHandler begin zip_file = Zip::ZipFile.open(tempfile.path) text += get_attachment_text_from_zip_file(zip_file) - zip_file.close() + zip_file.close rescue $stderr.puts("Error processing zip file: #{$!.inspect}") end diff --git a/lib/memory_profiler.rb b/lib/memory_profiler.rb index 15e8457ee..fd056dc0d 100644 --- a/lib/memory_profiler.rb +++ b/lib/memory_profiler.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # Taken from # http://scottstuff.net/blog/2006/08/17/memory-leak-profiling-with-rails diff --git a/lib/message_prominence.rb b/lib/message_prominence.rb index 8f54fcc95..8f8008784 100644 --- a/lib/message_prominence.rb +++ b/lib/message_prominence.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- module MessageProminence def has_prominence diff --git a/lib/no_constraint_disabling.rb b/lib/no_constraint_disabling.rb index 32a4a6bfe..539b491b3 100644 --- a/lib/no_constraint_disabling.rb +++ b/lib/no_constraint_disabling.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # In order to work around the problem of the database use not having # the permission to disable referential integrity when loading fixtures, # we redefine disable_referential_integrity so that it doesn't try to diff --git a/lib/normalize_string.rb b/lib/normalize_string.rb index 3b6116970..d850d7e05 100644 --- a/lib/normalize_string.rb +++ b/lib/normalize_string.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require 'iconv' unless String.method_defined?(:encode) require 'charlock_holmes' @@ -72,6 +73,20 @@ def convert_string_to_utf8_or_binary(s, suggested_character_encoding=nil) result end +def convert_string_to_utf8(s, suggested_character_encoding=nil) + begin + result = normalize_string_to_utf8 s, suggested_character_encoding + rescue EncodingNormalizationError + result = s + if String.method_defined?(:encode) + result = s.force_encoding("utf-8").encode("utf-8", :invalid => :replace, + :undef => :replace, + :replace => "") + end + end + result +end + def log_text_details(message, text) if String.method_defined?(:encode) STDERR.puts "#{message}, we have text: #{text}, of class #{text.class} and encoding #{text.encoding}" diff --git a/lib/public_body_csv.rb b/lib/public_body_csv.rb index afb5d9043..3dab7b805 100644 --- a/lib/public_body_csv.rb +++ b/lib/public_body_csv.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require 'csv' # Public: Generate a CSV representation of PublicBody instances diff --git a/lib/quiet_opener.rb b/lib/quiet_opener.rb index c6e259b93..9745e22a4 100644 --- a/lib/quiet_opener.rb +++ b/lib/quiet_opener.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require 'open-uri' require 'net-purge' if RUBY_VERSION.to_f < 2.0 diff --git a/lib/routing_filters.rb b/lib/routing_filters.rb index 5b5da6870..2aad6f437 100644 --- a/lib/routing_filters.rb +++ b/lib/routing_filters.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- module RoutingFilter class Conditionallyprependlocale < RoutingFilter::Locale # Override core Locale filter not to prepend locale path segment diff --git a/lib/ruby19.rb b/lib/ruby19.rb deleted file mode 100644 index 39f48d74e..000000000 --- a/lib/ruby19.rb +++ /dev/null @@ -1,8 +0,0 @@ -if RUBY_VERSION.to_f == 1.9 - class String - # @see syck/lib/syck/rubytypes.rb - def is_binary_data? - self.count("\x00-\x7F", "^ -~\t\r\n").fdiv(self.size) > 0.3 || self.index("\x00") unless self.empty? - end - end -end
\ No newline at end of file diff --git a/lib/strip_attributes/strip_attributes.rb b/lib/strip_attributes/strip_attributes.rb index 12350277d..2e4383194 100644 --- a/lib/strip_attributes/strip_attributes.rb +++ b/lib/strip_attributes/strip_attributes.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- module StripAttributes # Strips whitespace from model fields and leaves nil values as nil. # TODO: this differs from official StripAttributes, as it doesn't make blank cells null. diff --git a/lib/strip_attributes/test/strip_attributes_test.rb b/lib/strip_attributes/test/strip_attributes_test.rb index 8158dc664..d06ef0671 100644 --- a/lib/strip_attributes/test/strip_attributes_test.rb +++ b/lib/strip_attributes/test/strip_attributes_test.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require "#{File.dirname(__FILE__)}/test_helper" module MockAttributes diff --git a/lib/strip_attributes/test/test_helper.rb b/lib/strip_attributes/test/test_helper.rb index 7d06c40db..6a4f6136a 100644 --- a/lib/strip_attributes/test/test_helper.rb +++ b/lib/strip_attributes/test/test_helper.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require 'test/unit' require 'rubygems' require 'active_record' @@ -9,7 +10,7 @@ require "#{PLUGIN_ROOT}/init" class ActiveRecord::Base alias_method :save, :valid? - def self.columns() + def self.columns @columns ||= [] end diff --git a/lib/tasks/config_files.rake b/lib/tasks/config_files.rake index 1528d7324..f6b25185e 100644 --- a/lib/tasks/config_files.rake +++ b/lib/tasks/config_files.rake @@ -11,7 +11,7 @@ namespace :config_files do var = $1.to_sym replacement = replacements[var] if replacement == nil - raise "Unhandled variable in .ugly file: $#{var}" + raise "Unhandled variable in example file: $#{var}" else replacements[var] end @@ -21,9 +21,9 @@ namespace :config_files do converted_lines end - desc 'Convert Debian .ugly init script in config to a form suitable for installing in /etc/init.d' + desc 'Convert Debian example init script in config to a form suitable for installing in /etc/init.d' task :convert_init_script => :environment do - example = 'rake config_files:convert_init_script DEPLOY_USER=deploy VHOST_DIR=/dir/above/alaveteli VCSPATH=alaveteli SITE=alaveteli SCRIPT_FILE=config/alert-tracks-debian.ugly' + example = 'rake config_files:convert_init_script DEPLOY_USER=deploy VHOST_DIR=/dir/above/alaveteli VCSPATH=alaveteli SITE=alaveteli SCRIPT_FILE=config/alert-tracks-debian.example' check_for_env_vars(['DEPLOY_USER', 'VHOST_DIR', 'SCRIPT_FILE'], example) @@ -37,7 +37,7 @@ namespace :config_files do } # Use the filename for the $daemon_name ugly variable - daemon_name = File.basename(ENV['SCRIPT_FILE'], '-debian.ugly') + daemon_name = File.basename(ENV['SCRIPT_FILE'], '-debian.example') replacements.update(:daemon_name => "#{ replacements[:site] }-#{ daemon_name }") # Generate the template for potential further processing @@ -57,7 +57,7 @@ namespace :config_files do end end - desc 'Convert Debian .ugly crontab file in config to a form suitable for installing in /etc/cron.d' + desc 'Convert Debian example crontab file in config to a form suitable for installing in /etc/cron.d' task :convert_crontab => :environment do example = 'rake config_files:convert_crontab DEPLOY_USER=deploy VHOST_DIR=/dir/above/alaveteli VCSPATH=alaveteli SITE=alaveteli CRONTAB=config/crontab-example MAILTO=cron-alaveteli@example.org' check_for_env_vars(['DEPLOY_USER', diff --git a/lib/tasks/usage.rb b/lib/tasks/usage.rb index d6aac454d..350a6b07e 100644 --- a/lib/tasks/usage.rb +++ b/lib/tasks/usage.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- module Usage def usage_message message @@ -23,4 +24,4 @@ module Usage end end -end
\ No newline at end of file +end diff --git a/lib/theme.rb b/lib/theme.rb index 4f03b5d99..f2d4ba8b3 100644 --- a/lib/theme.rb +++ b/lib/theme.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- def theme_url_to_theme_name(theme_url) File.basename theme_url, '.git' end diff --git a/lib/use_spans_for_errors.rb b/lib/use_spans_for_errors.rb index 135453f78..ecc117964 100644 --- a/lib/use_spans_for_errors.rb +++ b/lib/use_spans_for_errors.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # Monkeypatch! Use SPAN instead of DIV. # # Rails core refuse to fix this properly, by making it an official option. diff --git a/lib/whatdotheyknow/strip_empty_sessions.rb b/lib/whatdotheyknow/strip_empty_sessions.rb index 6d175ca98..1e5078172 100644 --- a/lib/whatdotheyknow/strip_empty_sessions.rb +++ b/lib/whatdotheyknow/strip_empty_sessions.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- module WhatDoTheyKnow class StripEmptySessions diff --git a/lib/world_foi_websites.rb b/lib/world_foi_websites.rb index fc2395986..a1e705c82 100644 --- a/lib/world_foi_websites.rb +++ b/lib/world_foi_websites.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # -*- coding: utf-8 -*- class WorldFOIWebsites def self.world_foi_websites @@ -77,7 +78,11 @@ class WorldFOIWebsites {:name => "Слободен пристап", :country_name => "Република Македонија", :country_iso_code => "MK", - :url => "http://www.slobodenpristap.mk/"} + :url => "http://www.slobodenpristap.mk/"}, + {:name => "Imamo pravo znati", + :country_name => "Republika Hrvatska", + :country_iso_code => "HR", + :url => "http://imamopravoznati.org/"} ] return world_foi_websites end diff --git a/lib/xapian_queries.rb b/lib/xapian_queries.rb index b3599740a..5c02ba788 100644 --- a/lib/xapian_queries.rb +++ b/lib/xapian_queries.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- module XapianQueries # These methods take some filter criteria expressed in a hash and convert them diff --git a/locale/model_attributes.rb b/locale/model_attributes.rb index 89a85aac3..332b67ede 100644 --- a/locale/model_attributes.rb +++ b/locale/model_attributes.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- #DO NOT MODIFY! AUTOMATICALLY GENERATED FILE! _('Acts as xapian/acts as xapian job') _('ActsAsXapian::ActsAsXapianJob|Action') diff --git a/public/.cvsignore b/public/.cvsignore deleted file mode 100644 index 9fc54a4a6..000000000 --- a/public/.cvsignore +++ /dev/null @@ -1,5 +0,0 @@ -down.html -down.current.html -foi-live-creation.png -foi-user-use.png -google*.html diff --git a/script/handle-mail-replies.rb b/script/handle-mail-replies.rb index cbff03acb..5cd6d4576 100755 --- a/script/handle-mail-replies.rb +++ b/script/handle-mail-replies.rb @@ -1,5 +1,5 @@ #!/usr/bin/env ruby -# -*- coding: utf-8 -*- +# -*- encoding : utf-8 -*- # Handle email responses sent to us. # diff --git a/script/mailin b/script/mailin index 65f9d06f2..5f2a9c243 100755 --- a/script/mailin +++ b/script/mailin @@ -23,7 +23,7 @@ then SUBJ="Mail import error for $OPTION_DOMAIN" BODY="There was an error code $ERROR_CODE returned by the RequestMailer.receive command in script/mailin. See attached for details. This might be quite serious, such as the database was down, or might be an email with corrupt headers that Rails is choking on. We returned the email with an exit code 75, which for Exim at least instructs the MTA to try again later. A well configured installation of this code will separately have had Exim make a backup copy of the email in a separate mailbox, just in case." FROM="$OPTION_BLACKHOLE_PREFIX@$OPTION_INCOMING_EMAIL_DOMAIN" - /usr/bin/mutt -e "set use_envelope_from" -e "set envelope_from_address=$FROM" -s "$SUBJ" -a "$OUTPUT" "$INPUT" -- "$OPTION_FORWARD_NONBOUNCE_RESPONSES_TO" <<<"$BODY" + /usr/bin/mutt -e "set use_envelope_from" -e "set envelope_from_address=$FROM" -s "$SUBJ" -a "$OUTPUT" "$INPUT" -- "$OPTION_EXCEPTION_NOTIFICATIONS_TO" <<<"$BODY" # tell exim error was temporary, so try again later (no point bouncing message to authority) rm -f "$INPUT" "$OUTPUT" diff --git a/script/request-creation-graph b/script/request-creation-graph index 7d347a7d2..f3baa2326 100755 --- a/script/request-creation-graph +++ b/script/request-creation-graph @@ -51,6 +51,12 @@ function grab_data { # rather nastily, work out the cumulative heights in reverse, so can plot impulses on top of each other grab_data "where (1 = 1)" $SOURCEA +if [ ! -s $SOURCEA ] ; then + # No data yet, skip graphing + echo "warning: no data to graph, skipping task" + exit +fi + grab_data "where described_state not in ('waiting_response')" $SOURCEB grab_data "where described_state not in ('waiting_response', 'waiting_clarification')" $SOURCEC grab_data "where described_state not in ('waiting_response', 'waiting_clarification', 'not_held')" $SOURCED diff --git a/script/site-specific-install.sh b/script/site-specific-install.sh index fba164213..9358103b2 100755 --- a/script/site-specific-install.sh +++ b/script/site-specific-install.sh @@ -180,6 +180,9 @@ postfix reload install_website_packages +# Give the unix user membership of the adm group so that they can read the mail log files +usermod -a -G adm "$UNIX_USER" + # Make the PostgreSQL user a superuser to avoid the irritating error: # PG::Error: ERROR: permission denied: "RI_ConstraintTrigger_16564" is a system trigger # This is only needed for loading the sample data, so the superuser @@ -208,14 +211,14 @@ echo $DONE_MSG if [ ! "$DEVELOPMENT_INSTALL" = true ]; then echo -n "Creating /etc/init.d/$SITE... " - (su -l -c "cd '$REPOSITORY' && bundle exec rake config_files:convert_init_script DEPLOY_USER='$UNIX_USER' VHOST_DIR='$DIRECTORY' VCSPATH='$SITE' SITE='$SITE' SCRIPT_FILE=config/sysvinit-thin.ugly" "$UNIX_USER") > /etc/init.d/"$SITE" + (su -l -c "cd '$REPOSITORY' && bundle exec rake config_files:convert_init_script DEPLOY_USER='$UNIX_USER' VHOST_DIR='$DIRECTORY' VCSPATH='$SITE' SITE='$SITE' SCRIPT_FILE=config/sysvinit-thin.example" "$UNIX_USER") > /etc/init.d/"$SITE" chgrp "$UNIX_USER" /etc/init.d/"$SITE" chmod 754 /etc/init.d/"$SITE" echo $DONE_MSG fi echo -n "Creating /etc/init.d/$SITE-alert-tracks... " -(su -l -c "cd '$REPOSITORY' && bundle exec rake config_files:convert_init_script DEPLOY_USER='$UNIX_USER' VHOST_DIR='$DIRECTORY' SCRIPT_FILE=config/alert-tracks-debian.ugly" "$UNIX_USER") > /etc/init.d/"$SITE-alert-tracks" +(su -l -c "cd '$REPOSITORY' && bundle exec rake config_files:convert_init_script DEPLOY_USER='$UNIX_USER' VHOST_DIR='$DIRECTORY' SCRIPT_FILE=config/alert-tracks-debian.example" "$UNIX_USER") > /etc/init.d/"$SITE-alert-tracks" chgrp "$UNIX_USER" /etc/init.d/"$SITE-alert-tracks" chmod 754 /etc/init.d/"$SITE-alert-tracks" echo $DONE_MSG diff --git a/script/switch-theme.rb b/script/switch-theme.rb index 980853687..47b3991c1 100755 --- a/script/switch-theme.rb +++ b/script/switch-theme.rb @@ -1,5 +1,5 @@ #!/usr/bin/env ruby -# -*- coding: utf-8 -*- +# -*- encoding : utf-8 -*- # A simple script to swap around your Alaveteli themes when you're # hacking on Alaveteli. By default this assumes that you have an @@ -129,5 +129,5 @@ STDERR.puts """Switched to #{requested_theme}! You will need to: 1. restart any development server you have running. 2. run: bundle exec rake assets:clean - 3. run: bundle exec rake assets:precompile + 3. run: bundle exec rake assets:precompile (if running in production mode) """ diff --git a/spec/controllers/admin_censor_rule_controller_spec.rb b/spec/controllers/admin_censor_rule_controller_spec.rb index 68eaecd6a..b9f936836 100644 --- a/spec/controllers/admin_censor_rule_controller_spec.rb +++ b/spec/controllers/admin_censor_rule_controller_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe AdminCensorRuleController do @@ -584,7 +585,7 @@ describe AdminCensorRuleController, "when making censor rules from the admin int :replacement => "tofu", :last_edit_comment => "none" } - PurgeRequest.all().first.model_id.should == ir.id + PurgeRequest.all.first.model_id.should == ir.id end end diff --git a/spec/controllers/admin_comment_controller_spec.rb b/spec/controllers/admin_comment_controller_spec.rb index f87231e3b..00b6e6cc9 100644 --- a/spec/controllers/admin_comment_controller_spec.rb +++ b/spec/controllers/admin_comment_controller_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe AdminCommentController do diff --git a/spec/controllers/admin_general_controller_spec.rb b/spec/controllers/admin_general_controller_spec.rb index cc2ec41b4..b2e8b233f 100644 --- a/spec/controllers/admin_general_controller_spec.rb +++ b/spec/controllers/admin_general_controller_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe AdminGeneralController do diff --git a/spec/controllers/admin_holiday_imports_controller_spec.rb b/spec/controllers/admin_holiday_imports_controller_spec.rb index dd23a022f..42dfadd47 100644 --- a/spec/controllers/admin_holiday_imports_controller_spec.rb +++ b/spec/controllers/admin_holiday_imports_controller_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require 'spec_helper' describe AdminHolidayImportsController do diff --git a/spec/controllers/admin_holidays_controller_spec.rb b/spec/controllers/admin_holidays_controller_spec.rb index 21cb51d29..93f51707b 100644 --- a/spec/controllers/admin_holidays_controller_spec.rb +++ b/spec/controllers/admin_holidays_controller_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require 'spec_helper' describe AdminHolidaysController do diff --git a/spec/controllers/admin_incoming_message_controller_spec.rb b/spec/controllers/admin_incoming_message_controller_spec.rb index 24a526ca4..39355c054 100644 --- a/spec/controllers/admin_incoming_message_controller_spec.rb +++ b/spec/controllers/admin_incoming_message_controller_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe AdminIncomingMessageController, "when administering incoming messages" do diff --git a/spec/controllers/admin_info_request_event_controller_spec.rb b/spec/controllers/admin_info_request_event_controller_spec.rb index 23300a0b8..dfa425374 100644 --- a/spec/controllers/admin_info_request_event_controller_spec.rb +++ b/spec/controllers/admin_info_request_event_controller_spec.rb @@ -1,4 +1,4 @@ -# coding: utf-8 +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe AdminInfoRequestEventController do diff --git a/spec/controllers/admin_outgoing_message_controller_spec.rb b/spec/controllers/admin_outgoing_message_controller_spec.rb index a46a077da..f231311ae 100644 --- a/spec/controllers/admin_outgoing_message_controller_spec.rb +++ b/spec/controllers/admin_outgoing_message_controller_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe AdminOutgoingMessageController do diff --git a/spec/controllers/admin_public_body_categories_controller_spec.rb b/spec/controllers/admin_public_body_categories_controller_spec.rb index 1131b3c0b..1aa8a145e 100644 --- a/spec/controllers/admin_public_body_categories_controller_spec.rb +++ b/spec/controllers/admin_public_body_categories_controller_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require 'spec_helper' describe AdminPublicBodyCategoriesController do @@ -310,7 +311,7 @@ describe AdminPublicBodyCategoriesController do post :update, :id => category.id, :public_body_category => category.serializable_hash.except(:title, :description) - expect(assigns(:tagged_public_bodies)).to eq(expected_bodies) + expect(assigns(:tagged_public_bodies)).to match_array(expected_bodies) end it "saves edits to a public body category's heading associations" do diff --git a/spec/controllers/admin_public_body_change_requests_controller_spec.rb b/spec/controllers/admin_public_body_change_requests_controller_spec.rb index 003510e60..b0a9ebd79 100644 --- a/spec/controllers/admin_public_body_change_requests_controller_spec.rb +++ b/spec/controllers/admin_public_body_change_requests_controller_spec.rb @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe AdminPublicBodyChangeRequestsController, "editing a change request" do diff --git a/spec/controllers/admin_public_body_controller_spec.rb b/spec/controllers/admin_public_body_controller_spec.rb index 50a373d9d..1b960ccc3 100644 --- a/spec/controllers/admin_public_body_controller_spec.rb +++ b/spec/controllers/admin_public_body_controller_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe AdminPublicBodyController, "when showing the index of public bodies" do @@ -650,17 +651,17 @@ describe AdminPublicBodyController, "when administering public bodies and paying render_views before do - config = MySociety::Config.load_default() + config = MySociety::Config.load_default config['SKIP_ADMIN_AUTH'] = false basic_auth_login @request end after do - config = MySociety::Config.load_default() + config = MySociety::Config.load_default config['SKIP_ADMIN_AUTH'] = true end def setup_emergency_credentials(username, password) - config = MySociety::Config.load_default() + config = MySociety::Config.load_default config['SKIP_ADMIN_AUTH'] = false config['ADMIN_USERNAME'] = username config['ADMIN_PASSWORD'] = password @@ -677,7 +678,7 @@ describe AdminPublicBodyController, "when administering public bodies and paying end it "skips admin authorisation when SKIP_ADMIN_AUTH set" do - config = MySociety::Config.load_default() + config = MySociety::Config.load_default config['SKIP_ADMIN_AUTH'] = true @request.env["HTTP_AUTHORIZATION"] = "" n = PublicBody.count @@ -757,7 +758,7 @@ describe AdminPublicBodyController, "when administering public bodies and paying end it 'returns the REMOTE_USER value from the request environment when skipping admin auth' do - config = MySociety::Config.load_default() + config = MySociety::Config.load_default config['SKIP_ADMIN_AUTH'] = true @request.env["HTTP_AUTHORIZATION"] = "" @request.env["REMOTE_USER"] = "i_am_admin" diff --git a/spec/controllers/admin_public_body_headings_controller_spec.rb b/spec/controllers/admin_public_body_headings_controller_spec.rb index ccdfdecfb..0e0337e3e 100644 --- a/spec/controllers/admin_public_body_headings_controller_spec.rb +++ b/spec/controllers/admin_public_body_headings_controller_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require 'spec_helper' describe AdminPublicBodyHeadingsController do diff --git a/spec/controllers/admin_raw_email_controller_spec.rb b/spec/controllers/admin_raw_email_controller_spec.rb index 77c57c38b..9039286bc 100644 --- a/spec/controllers/admin_raw_email_controller_spec.rb +++ b/spec/controllers/admin_raw_email_controller_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe AdminRawEmailController do diff --git a/spec/controllers/admin_request_controller_spec.rb b/spec/controllers/admin_request_controller_spec.rb index 4eb463963..61827bfd1 100644 --- a/spec/controllers/admin_request_controller_spec.rb +++ b/spec/controllers/admin_request_controller_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe AdminRequestController, "when administering requests" do diff --git a/spec/controllers/admin_spam_addresses_controller_spec.rb b/spec/controllers/admin_spam_addresses_controller_spec.rb index a1e434159..8f6d57b01 100644 --- a/spec/controllers/admin_spam_addresses_controller_spec.rb +++ b/spec/controllers/admin_spam_addresses_controller_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require 'spec_helper' describe AdminSpamAddressesController do diff --git a/spec/controllers/admin_track_controller_spec.rb b/spec/controllers/admin_track_controller_spec.rb index d29db4966..b77570a27 100644 --- a/spec/controllers/admin_track_controller_spec.rb +++ b/spec/controllers/admin_track_controller_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe AdminTrackController, "when administering tracks" do diff --git a/spec/controllers/admin_user_controller_spec.rb b/spec/controllers/admin_user_controller_spec.rb index e979355cf..9341feec6 100644 --- a/spec/controllers/admin_user_controller_spec.rb +++ b/spec/controllers/admin_user_controller_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe AdminUserController, "when administering users" do diff --git a/spec/controllers/api_controller_spec.rb b/spec/controllers/api_controller_spec.rb index 323ef4cd4..d8af59ad8 100644 --- a/spec/controllers/api_controller_spec.rb +++ b/spec/controllers/api_controller_spec.rb @@ -1,4 +1,4 @@ -# coding: utf-8 +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe ApiController, "when using the API" do diff --git a/spec/controllers/comment_controller_spec.rb b/spec/controllers/comment_controller_spec.rb index 480c85ad7..cfd7166f4 100644 --- a/spec/controllers/comment_controller_spec.rb +++ b/spec/controllers/comment_controller_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe CommentController, "when commenting on a request" do diff --git a/spec/controllers/general_controller_spec.rb b/spec/controllers/general_controller_spec.rb index 844fcd4e6..495624403 100644 --- a/spec/controllers/general_controller_spec.rb +++ b/spec/controllers/general_controller_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') require 'fakeweb' @@ -111,7 +112,7 @@ describe GeneralController, "when showing the frontpage" do it "should render the front page with default language and ignore the browser setting" do - config = MySociety::Config.load_default() + config = MySociety::Config.load_default config['USE_DEFAULT_BROWSER_LANGUAGE'] = false accept_language = "en-GB,en-US;q=0.8,en;q=0.6" request.env['HTTP_ACCEPT_LANGUAGE'] = accept_language @@ -122,7 +123,7 @@ describe GeneralController, "when showing the frontpage" do end it "should render the front page with browser-selected language when there's no default set" do - config = MySociety::Config.load_default() + config = MySociety::Config.load_default config['USE_DEFAULT_BROWSER_LANGUAGE'] = true accept_language = "es-ES,en-GB,en-US;q=0.8,en;q=0.6" request.env['HTTP_ACCEPT_LANGUAGE'] = accept_language diff --git a/spec/controllers/health_checks_controller_spec.rb b/spec/controllers/health_checks_controller_spec.rb index f7ad6d6a4..2403fb3c8 100644 --- a/spec/controllers/health_checks_controller_spec.rb +++ b/spec/controllers/health_checks_controller_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe HealthChecksController do diff --git a/spec/controllers/help_controller_spec.rb b/spec/controllers/help_controller_spec.rb index 9453c9461..338a86380 100644 --- a/spec/controllers/help_controller_spec.rb +++ b/spec/controllers/help_controller_spec.rb @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe HelpController do diff --git a/spec/controllers/info_request_batch_controller_spec.rb b/spec/controllers/info_request_batch_controller_spec.rb index d08f02e10..866a1d0dc 100644 --- a/spec/controllers/info_request_batch_controller_spec.rb +++ b/spec/controllers/info_request_batch_controller_spec.rb @@ -1,4 +1,4 @@ -# coding: utf-8 +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe InfoRequestBatchController, "when showing a request" do diff --git a/spec/controllers/public_body_change_requests_controller_spec.rb b/spec/controllers/public_body_change_requests_controller_spec.rb index 4053b2f40..a8f149cc6 100644 --- a/spec/controllers/public_body_change_requests_controller_spec.rb +++ b/spec/controllers/public_body_change_requests_controller_spec.rb @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe PublicBodyChangeRequestsController, "making a new change request" do diff --git a/spec/controllers/public_body_controller_spec.rb b/spec/controllers/public_body_controller_spec.rb index ff0a70a6f..c5c94a45c 100644 --- a/spec/controllers/public_body_controller_spec.rb +++ b/spec/controllers/public_body_controller_spec.rb @@ -1,4 +1,4 @@ -# coding: utf-8 +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') require 'nokogiri' @@ -336,7 +336,7 @@ end describe PublicBodyController, "when showing public body statistics" do it "should render the right template with the right data" do - config = MySociety::Config.load_default() + config = MySociety::Config.load_default config['MINIMUM_REQUESTS_FOR_STATISTICS'] = 1 config['PUBLIC_BODY_STATISTICS_PAGE'] = true get :statistics diff --git a/spec/controllers/reports_controller_spec.rb b/spec/controllers/reports_controller_spec.rb index fa8c72eaa..91be67fd8 100644 --- a/spec/controllers/reports_controller_spec.rb +++ b/spec/controllers/reports_controller_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require 'spec_helper' describe ReportsController, "when reporting a request when not logged in" do diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index 02237b29d..a5534e9ff 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe RequestController, "when listing recent requests" do @@ -40,41 +40,41 @@ describe RequestController, "when changing things that appear on the request pag it "should purge the downstream cache when mail is received" do ir = info_requests(:fancy_dog_request) receive_incoming_mail('incoming-request-plain.email', ir.incoming_email) - PurgeRequest.all().first.model_id.should == ir.id + PurgeRequest.all.first.model_id.should == ir.id end it "should purge the downstream cache when a comment is added" do ir = info_requests(:fancy_dog_request) new_comment = info_requests(:fancy_dog_request).add_comment('I also love making annotations.', users(:bob_smith_user)) - PurgeRequest.all().first.model_id.should == ir.id + PurgeRequest.all.first.model_id.should == ir.id end it "should purge the downstream cache when a followup is made" do session[:user_id] = users(:bob_smith_user).id ir = info_requests(:fancy_dog_request) post :show_response, :outgoing_message => { :body => "What a useless response! You suck.", :what_doing => 'normal_sort' }, :id => ir.id, :submitted_followup => 1 - PurgeRequest.all().first.model_id.should == ir.id + PurgeRequest.all.first.model_id.should == ir.id end it "should purge the downstream cache when the request is categorised" do ir = info_requests(:fancy_dog_request) ir.set_described_state('waiting_clarification') - PurgeRequest.all().first.model_id.should == ir.id + PurgeRequest.all.first.model_id.should == ir.id end it "should purge the downstream cache when the authority data is changed" do ir = info_requests(:fancy_dog_request) ir.public_body.name = "Something new" ir.public_body.save! - PurgeRequest.all().map{|x| x.model_id}.should =~ ir.public_body.info_requests.map{|x| x.id} + PurgeRequest.all.map{|x| x.model_id}.should =~ ir.public_body.info_requests.map{|x| x.id} end it "should purge the downstream cache when the user name is changed" do ir = info_requests(:fancy_dog_request) ir.user.name = "Something new" ir.user.save! - PurgeRequest.all().map{|x| x.model_id}.should =~ ir.user.info_requests.map{|x| x.id} + PurgeRequest.all.map{|x| x.model_id}.should =~ ir.user.info_requests.map{|x| x.id} end it "should not purge the downstream cache when non-visible user details are changed" do ir = info_requests(:fancy_dog_request) ir.user.hashed_password = "some old hash" ir.user.save! - PurgeRequest.all().count.should == 0 + PurgeRequest.all.count.should == 0 end it "should purge the downstream cache when censor rules have changed" do # TODO: really, CensorRules should execute expiry logic as part @@ -86,17 +86,17 @@ describe RequestController, "when changing things that appear on the request pag ir = info_requests(:fancy_dog_request) ir.prominence = 'hidden' ir.save! - PurgeRequest.all().first.model_id.should == ir.id + PurgeRequest.all.first.model_id.should == ir.id end it "should not create more than one entry for any given resource" do ir = info_requests(:fancy_dog_request) ir.prominence = 'hidden' ir.save! - PurgeRequest.all().count.should == 1 + PurgeRequest.all.count.should == 1 ir = info_requests(:fancy_dog_request) ir.prominence = 'hidden' ir.save! - PurgeRequest.all().count.should == 1 + PurgeRequest.all.count.should == 1 end end @@ -611,7 +611,7 @@ describe RequestController, "when showing one request" do it "should censor attachments downloaded as binary" do ir = info_requests(:fancy_dog_request) - censor_rule = CensorRule.new() + censor_rule = CensorRule.new censor_rule.text = "Second" censor_rule.replacement = "Mouse" censor_rule.last_edit_editor = "unknown" @@ -632,7 +632,7 @@ describe RequestController, "when showing one request" do it "should censor with rules on the user (rather than the request)" do ir = info_requests(:fancy_dog_request) - censor_rule = CensorRule.new() + censor_rule = CensorRule.new censor_rule.text = "Second" censor_rule.replacement = "Mouse" censor_rule.last_edit_editor = "unknown" @@ -675,7 +675,7 @@ describe RequestController, "when showing one request" do s.should contain /hello world.txt/m end - censor_rule = CensorRule.new() + censor_rule = CensorRule.new # Note that the censor rule applies to the original filename, # not the display_filename: censor_rule.text = "hello-world.txt" @@ -1471,7 +1471,7 @@ describe RequestController, "when classifying an information request" do it 'should record a classification' do event = mock_model(InfoRequestEvent) - @dog_request.stub!(:log_event).with("status_update", anything()).and_return(event) + @dog_request.stub!(:log_event).with("status_update", anything).and_return(event) RequestClassification.should_receive(:create!).with(:user_id => @admin_user.id, :info_request_event_id => event.id) post_status('rejected') @@ -1915,7 +1915,7 @@ describe RequestController, "sending overdue request alerts" do it "should send an overdue alert mail to creators of overdue requests" do chicken_request = info_requests(:naughty_chicken_request) - chicken_request.outgoing_messages[0].last_sent_at = Time.now() - 30.days + chicken_request.outgoing_messages[0].last_sent_at = Time.now - 30.days chicken_request.outgoing_messages[0].save! RequestMailer.alert_overdue_requests @@ -1941,7 +1941,7 @@ describe RequestController, "sending overdue request alerts" do it "should include clause for schools when sending an overdue alert mail to creators of overdue requests" do chicken_request = info_requests(:naughty_chicken_request) - chicken_request.outgoing_messages[0].last_sent_at = Time.now() - 30.days + chicken_request.outgoing_messages[0].last_sent_at = Time.now - 30.days chicken_request.outgoing_messages[0].save! chicken_request.public_body.tag_string = "school" @@ -1972,7 +1972,7 @@ describe RequestController, "sending overdue request alerts" do it "should send a very overdue alert mail to creators of very overdue requests" do chicken_request = info_requests(:naughty_chicken_request) - chicken_request.outgoing_messages[0].last_sent_at = Time.now() - 60.days + chicken_request.outgoing_messages[0].last_sent_at = Time.now - 60.days chicken_request.outgoing_messages[0].save! RequestMailer.alert_overdue_requests @@ -1998,7 +1998,7 @@ describe RequestController, "sending overdue request alerts" do it "should not resend alerts to people who've already received them" do chicken_request = info_requests(:naughty_chicken_request) - chicken_request.outgoing_messages[0].last_sent_at = Time.now() - 60.days + chicken_request.outgoing_messages[0].last_sent_at = Time.now - 60.days chicken_request.outgoing_messages[0].save! RequestMailer.alert_overdue_requests chicken_mails = ActionMailer::Base.deliveries.select{|x| x.body =~ /chickens/} @@ -2011,7 +2011,7 @@ describe RequestController, "sending overdue request alerts" do it 'should send alerts for requests where the last event forming the initial request is a followup being sent following a request for clarification' do chicken_request = info_requests(:naughty_chicken_request) - chicken_request.outgoing_messages[0].last_sent_at = Time.now() - 60.days + chicken_request.outgoing_messages[0].last_sent_at = Time.now - 60.days chicken_request.outgoing_messages[0].save! RequestMailer.alert_overdue_requests chicken_mails = ActionMailer::Base.deliveries.select{|x| x.body =~ /chickens/} @@ -2048,7 +2048,7 @@ describe RequestController, "sending overdue request alerts" do chicken_mails.size.should == 1 # Make the followup older - outgoing_message.last_sent_at = Time.now() - 60.days + outgoing_message.last_sent_at = Time.now - 60.days outgoing_message.save! # Now it should be alerted on @@ -2764,4 +2764,3 @@ describe RequestController, "#select_authorities" do end end - diff --git a/spec/controllers/request_game_controller_spec.rb b/spec/controllers/request_game_controller_spec.rb index 7247cd388..c3f00d58d 100644 --- a/spec/controllers/request_game_controller_spec.rb +++ b/spec/controllers/request_game_controller_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe RequestGameController, "when playing the game" do diff --git a/spec/controllers/services_controller_spec.rb b/spec/controllers/services_controller_spec.rb index 621dbaaac..6ab527bc9 100644 --- a/spec/controllers/services_controller_spec.rb +++ b/spec/controllers/services_controller_spec.rb @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') require 'fakeweb' @@ -9,7 +9,7 @@ describe ServicesController, "when returning a message for people in other count # 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() + @old_locale = FastGettext.locale end it 'keeps the flash' do @@ -21,7 +21,7 @@ describe ServicesController, "when returning a message for people in other count end it "should show no alaveteli message when in the deployed country" do - config = MySociety::Config.load_default() + config = MySociety::Config.load_default config['ISO_COUNTRY_CODE'] = "DE" controller.stub!(:country_from_ip).and_return('DE') get :other_country_message @@ -29,7 +29,7 @@ describe ServicesController, "when returning a message for people in other count end it "should show an alaveteli message when not in the deployed country and in a country with no FOI website" do - config = MySociety::Config.load_default() + config = MySociety::Config.load_default config['ISO_COUNTRY_CODE'] = "DE" controller.stub!(:country_from_ip).and_return('ZZ') get :other_country_message @@ -37,7 +37,7 @@ describe ServicesController, "when returning a message for people in other count end it "should show link to other FOI website when not in the deployed country" do - config = MySociety::Config.load_default() + config = MySociety::Config.load_default config['ISO_COUNTRY_CODE'] = "ZZ" controller.stub!(:country_from_ip).and_return('ES') request.env['HTTP_ACCEPT_LANGUAGE'] = "es" @@ -60,7 +60,7 @@ describe ServicesController, "when returning a message for people in other count end it "should return the 'another country' message if the service responds OK" do - config = MySociety::Config.load_default() + config = MySociety::Config.load_default config['ISO_COUNTRY_CODE'] = "DE" AlaveteliConfiguration.stub!(:gaze_url).and_return('http://denmark.com') FakeWeb.register_uri(:get, %r|denmark.com|, :body => "DK") diff --git a/spec/controllers/track_controller_spec.rb b/spec/controllers/track_controller_spec.rb index 29f5c7fe1..b453fde8c 100644 --- a/spec/controllers/track_controller_spec.rb +++ b/spec/controllers/track_controller_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe TrackController, "when making a new track on a request" do diff --git a/spec/controllers/user_controller_spec.rb b/spec/controllers/user_controller_spec.rb index 443856cf3..fb03615f8 100644 --- a/spec/controllers/user_controller_spec.rb +++ b/spec/controllers/user_controller_spec.rb @@ -1,4 +1,4 @@ -# coding: utf-8 +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe UserController do @@ -76,11 +76,11 @@ describe UserController, "when redirecting a show request to a canonical url" do end it 'should not redirect a long canonical name that has a numerical suffix' do - User.stub!(:find).with(:first, anything()).and_return(mock_model(User, + User.stub!(:find).with(:first, anything).and_return(mock_model(User, :url_name => 'bob_smithbob_smithbob_smithbob_s_2', :name => 'Bob Smith Bob Smith Bob Smith Bob Smith', :info_requests => [])) - User.stub!(:find).with(:all, anything()).and_return([]) + User.stub!(:find).with(:all, anything).and_return([]) get :show, :url_name => 'bob_smithbob_smithbob_smithbob_s_2' response.should be_success end diff --git a/spec/controllers/widgets_controller_spec.rb b/spec/controllers/widgets_controller_spec.rb new file mode 100644 index 000000000..95396671b --- /dev/null +++ b/spec/controllers/widgets_controller_spec.rb @@ -0,0 +1,181 @@ +# -*- encoding : utf-8 -*- +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') + +describe WidgetsController do + + include LinkToHelper + + describe "#show" do + + before do + @info_request = FactoryGirl.create(:info_request) + AlaveteliConfiguration.stub!(:enable_widgets).and_return(true) + end + + it 'should render the widget template' do + get :show, :request_id => @info_request.id + expect(response).to render_template('show') + end + + it 'should find the info request' do + get :show, :request_id => @info_request.id + assigns[:info_request].should == @info_request + end + + it 'should create a track thing for the request' do + get :show, :request_id => @info_request.id + assigns[:track_thing].info_request.should == @info_request + end + + it 'should assign the request status' do + get :show, :request_id => @info_request.id + assigns[:status].should == @info_request.calculate_status + end + + it 'should not send an x-frame-options header' do + get :show, :request_id => @info_request.id + response.headers["X-Frame-Options"].should be_nil + end + + context 'for a non-logged-in user' do + + context 'if no widget-vote cookie is set' do + + it 'should set a widget-vote cookie' do + cookies[:widget_vote].should be_nil + get :show, :request_id => @info_request.id + cookies[:widget_vote].should_not be_nil + end + + end + + end + + context 'when widgets are not enabled' do + + it 'should return a 404' do + AlaveteliConfiguration.stub!(:enable_widgets).and_return(false) + lambda{ get :show, :request_id => @info_request.id }.should + raise_error(ActiveRecord::RecordNotFound) + end + + end + + context "when the request's prominence is not 'normal'" do + + it 'should return a 403' do + @info_request.prominence = 'hidden' + @info_request.save! + get :show, :request_id => @info_request.id + response.code.should == "403" + end + + end + + end + + describe "#new" do + + before do + @info_request = FactoryGirl.create(:info_request) + AlaveteliConfiguration.stub!(:enable_widgets).and_return(true) + end + + it 'should render the create widget template' do + get :new, :request_id => @info_request.id + expect(response).to render_template('new') + end + + it 'should find the info request' do + get :new, :request_id => @info_request.id + assigns[:info_request].should == @info_request + end + + context 'when widgets are not enabled' do + + it 'should return a 404' do + AlaveteliConfiguration.stub!(:enable_widgets).and_return(false) + lambda{ get :new, :request_id => @info_request.id }.should + raise_error(ActiveRecord::RecordNotFound) + end + + end + + context "when the request's prominence is not 'normal'" do + + it 'should return a 403' do + @info_request.prominence = 'hidden' + @info_request.save! + get :show, :request_id => @info_request.id + response.code.should == "403" + end + + end + + end + + describe :update do + + before do + @info_request = FactoryGirl.create(:info_request) + AlaveteliConfiguration.stub!(:enable_widgets).and_return(true) + end + + it 'should find the info request' do + get :update, :request_id => @info_request.id + assigns[:info_request].should == @info_request + end + + it 'should redirect to the track path for the info request' do + get :update, :request_id => @info_request.id + track_thing = TrackThing.create_track_for_request(@info_request) + expect(response).to redirect_to(do_track_path(track_thing)) + end + + context 'when there is no logged-in user and a widget vote cookie' do + + before do + @cookie_value = 'x' * 20 + end + + it 'should create a widget vote if none exists for the info request and cookie' do + @info_request.widget_votes.where(:cookie => @cookie_value).size.should == 0 + request.cookies['widget_vote'] = @cookie_value + get :update, :request_id => @info_request.id + @info_request.widget_votes.where(:cookie => @cookie_value).size.should == 1 + end + + it 'should not create a widget vote if one exists for the info request and cookie' do + @info_request.widget_votes.create(:cookie => @cookie_value) + request.cookies['widget_vote'] = @cookie_value + get :update, :request_id => @info_request.id + @info_request.widget_votes.where(:cookie => @cookie_value).size.should == 1 + end + + end + + context 'when widgets are not enabled' do + + it 'should raise ActiveRecord::RecordNotFound' do + AlaveteliConfiguration.stub!(:enable_widgets).and_return(false) + lambda{ get :update, :request_id => @info_request.id }.should + raise_error(ActiveRecord::RecordNotFound) + end + + end + + context "when the request's prominence is not 'normal'" do + + it 'should return a 403' do + @info_request.prominence = 'hidden' + @info_request.save! + get :show, :request_id => @info_request.id + response.code.should == "403" + end + + end + + end + +end + diff --git a/spec/factories/censor_rules.rb b/spec/factories/censor_rules.rb index 2c0b2c822..5ae60b1f1 100644 --- a/spec/factories/censor_rules.rb +++ b/spec/factories/censor_rules.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- FactoryGirl.define do factory :censor_rule do diff --git a/spec/factories/comments.rb b/spec/factories/comments.rb index 1e0861dad..905d7580f 100644 --- a/spec/factories/comments.rb +++ b/spec/factories/comments.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- FactoryGirl.define do factory :comment do diff --git a/spec/factories/foi_attchments.rb b/spec/factories/foi_attchments.rb index a1d04ccf0..64486dcda 100644 --- a/spec/factories/foi_attchments.rb +++ b/spec/factories/foi_attchments.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- FactoryGirl.define do factory :foi_attachment do diff --git a/spec/factories/holidays.rb b/spec/factories/holidays.rb index 531130c8a..28bbe6c52 100644 --- a/spec/factories/holidays.rb +++ b/spec/factories/holidays.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- FactoryGirl.define do factory :holiday do diff --git a/spec/factories/incoming_messages.rb b/spec/factories/incoming_messages.rb index b29fe8ce9..127e0f94e 100644 --- a/spec/factories/incoming_messages.rb +++ b/spec/factories/incoming_messages.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- FactoryGirl.define do factory :incoming_message do diff --git a/spec/factories/info_request_batches.rb b/spec/factories/info_request_batches.rb index 960db6ec5..c92aa76cc 100644 --- a/spec/factories/info_request_batches.rb +++ b/spec/factories/info_request_batches.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- FactoryGirl.define do factory :info_request_batch do diff --git a/spec/factories/info_request_events.rb b/spec/factories/info_request_events.rb index cdd303ad6..d585049e7 100644 --- a/spec/factories/info_request_events.rb +++ b/spec/factories/info_request_events.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- FactoryGirl.define do factory :info_request_event do diff --git a/spec/factories/info_requests.rb b/spec/factories/info_requests.rb index 8052625cd..084712243 100644 --- a/spec/factories/info_requests.rb +++ b/spec/factories/info_requests.rb @@ -1,7 +1,8 @@ +# -*- encoding : utf-8 -*- FactoryGirl.define do factory :info_request do - title "Example Title" + sequence(:title) { |n| "Example Title #{n}" } public_body user diff --git a/spec/factories/outgoing_messages.rb b/spec/factories/outgoing_messages.rb index e11cbdfb9..6e88085b4 100644 --- a/spec/factories/outgoing_messages.rb +++ b/spec/factories/outgoing_messages.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- FactoryGirl.define do factory :outgoing_message do diff --git a/spec/factories/public_bodies.rb b/spec/factories/public_bodies.rb index 44769f7c2..a823d536a 100644 --- a/spec/factories/public_bodies.rb +++ b/spec/factories/public_bodies.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- FactoryGirl.define do factory :public_body do diff --git a/spec/factories/public_body_categories.rb b/spec/factories/public_body_categories.rb index baa474c6b..da7dec65c 100644 --- a/spec/factories/public_body_categories.rb +++ b/spec/factories/public_body_categories.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- FactoryGirl.define do factory :public_body_category do diff --git a/spec/factories/public_body_category_links.rb b/spec/factories/public_body_category_links.rb index 7663b1f52..7e796a08d 100644 --- a/spec/factories/public_body_category_links.rb +++ b/spec/factories/public_body_category_links.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- FactoryGirl.define do factory :public_body_category_link do association :public_body_category diff --git a/spec/factories/public_body_change_requests.rb b/spec/factories/public_body_change_requests.rb index 2bacb9b9b..a074c6feb 100644 --- a/spec/factories/public_body_change_requests.rb +++ b/spec/factories/public_body_change_requests.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- FactoryGirl.define do factory :public_body_change_request do diff --git a/spec/factories/public_body_headings.rb b/spec/factories/public_body_headings.rb index ed54ddada..b7f83ffda 100644 --- a/spec/factories/public_body_headings.rb +++ b/spec/factories/public_body_headings.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- FactoryGirl.define do factory :public_body_heading do sequence(:name) { |n| "Example Public Body Heading #{n}" } diff --git a/spec/factories/raw_emails.rb b/spec/factories/raw_emails.rb index b271515d2..a6e3c21ac 100644 --- a/spec/factories/raw_emails.rb +++ b/spec/factories/raw_emails.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- FactoryGirl.define do factory :raw_email end diff --git a/spec/factories/spam_addresses.rb b/spec/factories/spam_addresses.rb index bafb7cd50..6853c7f2e 100644 --- a/spec/factories/spam_addresses.rb +++ b/spec/factories/spam_addresses.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- FactoryGirl.define do factory :spam_address do sequence(:email) { |n| "spam-#{ n }@example.org" } diff --git a/spec/factories/track_things.rb b/spec/factories/track_things.rb index cf76b00b3..f8e4dce69 100644 --- a/spec/factories/track_things.rb +++ b/spec/factories/track_things.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- FactoryGirl.define do factory :track_thing do diff --git a/spec/factories/users.rb b/spec/factories/users.rb index ab782fbf7..1f7eba530 100644 --- a/spec/factories/users.rb +++ b/spec/factories/users.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- FactoryGirl.define do factory :user do diff --git a/spec/factories/widget_votes.rb b/spec/factories/widget_votes.rb new file mode 100644 index 000000000..7ceb4f7e9 --- /dev/null +++ b/spec/factories/widget_votes.rb @@ -0,0 +1,8 @@ +# -*- encoding : utf-8 -*- +require 'securerandom' +FactoryGirl.define do + factory :widget_vote do + info_request + cookie { SecureRandom.hex(10) } + end +end diff --git a/spec/fixtures/files/non-utf8-filename.email b/spec/fixtures/files/non-utf8-filename.email new file mode 100644 index 000000000..ed1f1a9f5 --- /dev/null +++ b/spec/fixtures/files/non-utf8-filename.email @@ -0,0 +1,52 @@ +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> +Content-Type: multipart/mixed; + boundary="_006_939C1F941DBEE94A9BEF493DF88519F71F13B5FCWDCEXMAIL02woki_" +MIME-Version: 1.0 +X-GlobalCerts-Milter: WDC-SECUREMAIL02.wokingham.gov.uk 13Feb2014-16:41:39.109 +X-Scanned-By: MailControl 26514.0 (www.mailcontrol.com) on 10.70.0.132 + +--_006_939C1F941DBEE94A9BEF493DF88519F71F13B5FCWDCEXMAIL02woki_ +Content-Type: multipart/alternative; + boundary="_000_939C1F941DBEE94A9BEF493DF88519F71F13B5FCWDCEXMAIL02woki_" + +--_000_939C1F941DBEE94A9BEF493DF88519F71F13B5FCWDCEXMAIL02woki_ +Content-Type: text/plain; charset="iso-8859-1" +Content-Transfer-Encoding: quoted-printable + +Some text + +--_000_939C1F941DBEE94A9BEF493DF88519F71F13B5FCWDCEXMAIL02woki_ +Content-Type: text/html; charset="iso-8859-1" +Content-Transfer-Encoding: quoted-printable + +Some html + +--_000_939C1F941DBEE94A9BEF493DF88519F71F13B5FCWDCEXMAIL02woki_-- + + +--_006_939C1F941DBEE94A9BEF493DF88519F71F13B5FCWDCEXMAIL02woki_ +Content-Type: application/vnd.ms-excel; + name="RV %A312000 or more.xls" +Content-Description: RV %A312000 or more.xls +Content-Disposition: attachment; creation-date="Thu, 13 Feb 2014 16:36:59 GMT"; filename="RV %A312000 or more.xls"; modification-date="Thu, 13 Feb 2014 16:41:36 GMT"; size="332288" +Content-Transfer-Encoding: base64 + +some base 64as;dm mklasd + +--_006_939C1F941DBEE94A9BEF493DF88519F71F13B5FCWDCEXMAIL02woki_ +Content-Type: application/vnd.ms-excel; name="other.xls" +Content-Description: other.xls +Content-Disposition: attachment; creation-date="Thu, 13 Feb 2014 16:37:02 GMT"; filename="other.xls"; modification-date="Thu, 13 Feb 2014 16:41:36 GMT"; size="33280" +Content-Transfer-Encoding: base64 + +some base 64 + +--_006_939C1F941DBEE94A9BEF493DF88519F71F13B5FCWDCEXMAIL02woki_--
\ No newline at end of file diff --git a/spec/helpers/admin_helper_spec.rb b/spec/helpers/admin_helper_spec.rb index 804fcc7fd..1f0155c98 100644 --- a/spec/helpers/admin_helper_spec.rb +++ b/spec/helpers/admin_helper_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe AdminHelper do diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb index 6407eaf3a..2035c343a 100644 --- a/spec/helpers/application_helper_spec.rb +++ b/spec/helpers/application_helper_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe ApplicationHelper do diff --git a/spec/helpers/date_time_helper_spec.rb b/spec/helpers/date_time_helper_spec.rb index c4fdee1d1..f69a0ef80 100644 --- a/spec/helpers/date_time_helper_spec.rb +++ b/spec/helpers/date_time_helper_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe DateTimeHelper do diff --git a/spec/helpers/health_checks_helper_spec.rb b/spec/helpers/health_checks_helper_spec.rb index 7d4083da5..9418864b5 100644 --- a/spec/helpers/health_checks_helper_spec.rb +++ b/spec/helpers/health_checks_helper_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe HealthChecksHelper do @@ -10,6 +11,11 @@ describe HealthChecksHelper do expect(check_status(check)).to include('red') end + it 'sets style to a blank string if ok' do + check = double(:message => '', :ok? => true) + expect(check_status(check)).to include('style=""') + end + end end diff --git a/spec/helpers/highlight_helper_spec.rb b/spec/helpers/highlight_helper_spec.rb index e1be7e153..2641a4400 100644 --- a/spec/helpers/highlight_helper_spec.rb +++ b/spec/helpers/highlight_helper_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe HighlightHelper do diff --git a/spec/helpers/link_to_helper_spec.rb b/spec/helpers/link_to_helper_spec.rb index 261e1ef3e..fbb0c2313 100644 --- a/spec/helpers/link_to_helper_spec.rb +++ b/spec/helpers/link_to_helper_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe LinkToHelper do diff --git a/spec/helpers/public_body_helper_spec.rb b/spec/helpers/public_body_helper_spec.rb index d4f3acf78..8db07b979 100644 --- a/spec/helpers/public_body_helper_spec.rb +++ b/spec/helpers/public_body_helper_spec.rb @@ -1,4 +1,4 @@ -# encoding: UTF-8 +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe PublicBodyHelper do diff --git a/spec/helpers/track_helper_spec.rb b/spec/helpers/track_helper_spec.rb index b6252ab39..bc1266338 100644 --- a/spec/helpers/track_helper_spec.rb +++ b/spec/helpers/track_helper_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe TrackHelper do diff --git a/spec/helpers/widget_helper_spec.rb b/spec/helpers/widget_helper_spec.rb new file mode 100644 index 000000000..614ed92ad --- /dev/null +++ b/spec/helpers/widget_helper_spec.rb @@ -0,0 +1,29 @@ +# -*- encoding : utf-8 -*- +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') + +describe WidgetHelper do + + include WidgetHelper + + describe :status_description do + + before do + @info_request = FactoryGirl.build(:info_request) + end + + it 'should return "Awaiting classification" for "waiting_classification' do + expect(status_description(@info_request, 'waiting_classification')).to eq('Awaiting classification') + end + + it 'should call theme_display_status for a theme status' do + @info_request.stub!(:theme_display_status).and_return("Special status") + expect(status_description(@info_request, 'special_status')).to eq('Special status') + end + + it 'should return unknown for an unknown status' do + expect(status_description(@info_request, 'special_status')).to eq('Unknown') + end + + end + +end diff --git a/spec/integration/admin_public_body_category_edit_spec.rb b/spec/integration/admin_public_body_category_edit_spec.rb index 043524189..4e210de82 100644 --- a/spec/integration/admin_public_body_category_edit_spec.rb +++ b/spec/integration/admin_public_body_category_edit_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') require File.expand_path(File.dirname(__FILE__) + '/alaveteli_dsl') diff --git a/spec/integration/admin_public_body_edit_spec.rb b/spec/integration/admin_public_body_edit_spec.rb index aeec3e65a..ed51f414b 100644 --- a/spec/integration/admin_public_body_edit_spec.rb +++ b/spec/integration/admin_public_body_edit_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') require File.expand_path(File.dirname(__FILE__) + '/alaveteli_dsl') @@ -39,7 +40,7 @@ describe 'Editing a Public Body' do end end - it 'can add a translation for multiple locales', :focus => true do + it 'can add a translation for multiple locales' do @admin.visit edit_admin_body_path(@body) @admin.fill_in 'public_body_name__en', :with => 'New Quango EN' @admin.click_button 'Save' diff --git a/spec/integration/admin_public_body_heading_edit_spec.rb b/spec/integration/admin_public_body_heading_edit_spec.rb index 6c7a5a74b..f37d033f3 100644 --- a/spec/integration/admin_public_body_heading_edit_spec.rb +++ b/spec/integration/admin_public_body_heading_edit_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') require File.expand_path(File.dirname(__FILE__) + '/alaveteli_dsl') diff --git a/spec/integration/admin_spec.rb b/spec/integration/admin_spec.rb index bdd6e9d8c..552b465bd 100644 --- a/spec/integration/admin_spec.rb +++ b/spec/integration/admin_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') require File.expand_path(File.dirname(__FILE__) + '/alaveteli_dsl') diff --git a/spec/integration/alaveteli_dsl.rb b/spec/integration/alaveteli_dsl.rb index d7485a094..1ff60664c 100644 --- a/spec/integration/alaveteli_dsl.rb +++ b/spec/integration/alaveteli_dsl.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- module AlaveteliDsl def browses_request(url_title) diff --git a/spec/integration/cookie_stripping_spec.rb b/spec/integration/cookie_stripping_spec.rb index 897899fd5..e28e7b8e4 100644 --- a/spec/integration/cookie_stripping_spec.rb +++ b/spec/integration/cookie_stripping_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') require File.expand_path(File.dirname(__FILE__) + '/alaveteli_dsl') diff --git a/spec/integration/create_request_spec.rb b/spec/integration/create_request_spec.rb index 84fad12f9..9b579c448 100644 --- a/spec/integration/create_request_spec.rb +++ b/spec/integration/create_request_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') require File.expand_path(File.dirname(__FILE__) + '/alaveteli_dsl') diff --git a/spec/integration/download_request_spec.rb b/spec/integration/download_request_spec.rb index 48b42b11d..1050e6792 100644 --- a/spec/integration/download_request_spec.rb +++ b/spec/integration/download_request_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') require File.expand_path(File.dirname(__FILE__) + '/alaveteli_dsl') @@ -143,7 +144,8 @@ describe 'when making a zipfile available' do it "should update the contents of the zipfile when the request changes" do - info_request = FactoryGirl.create(:info_request_with_incoming) + info_request = FactoryGirl.create(:info_request_with_incoming, + :title => 'Example Title') request_owner = login(info_request.user) inspect_zip_download(request_owner, info_request) do |zip| zip.count.should == 1 # just the message diff --git a/spec/integration/errors_spec.rb b/spec/integration/errors_spec.rb index 39f1279ce..64145cce0 100644 --- a/spec/integration/errors_spec.rb +++ b/spec/integration/errors_spec.rb @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe "When errors occur" do diff --git a/spec/integration/ip_spoofing_spec.rb b/spec/integration/ip_spoofing_spec.rb index 073f71ad6..ce11bcf0b 100644 --- a/spec/integration/ip_spoofing_spec.rb +++ b/spec/integration/ip_spoofing_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe 'when getting a country message' do diff --git a/spec/integration/localisation_spec.rb b/spec/integration/localisation_spec.rb index 037603ad5..f96cd4c3a 100644 --- a/spec/integration/localisation_spec.rb +++ b/spec/integration/localisation_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe "when generating urls" do diff --git a/spec/integration/request_controller_spec.rb b/spec/integration/request_controller_spec.rb index f5de692b8..1ef6814f9 100644 --- a/spec/integration/request_controller_spec.rb +++ b/spec/integration/request_controller_spec.rb @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') require File.expand_path(File.dirname(__FILE__) + '/alaveteli_dsl') diff --git a/spec/integration/search_request_spec.rb b/spec/integration/search_request_spec.rb index 699eb2c6c..7a09c78fb 100644 --- a/spec/integration/search_request_spec.rb +++ b/spec/integration/search_request_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') require File.expand_path(File.dirname(__FILE__) + '/alaveteli_dsl') diff --git a/spec/integration/view_request_spec.rb b/spec/integration/view_request_spec.rb index 4d04c97d7..ed84ec2e2 100644 --- a/spec/integration/view_request_spec.rb +++ b/spec/integration/view_request_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') require File.expand_path(File.dirname(__FILE__) + '/alaveteli_dsl') diff --git a/spec/integration/xapian_search_highlighting_spec.rb b/spec/integration/xapian_search_highlighting_spec.rb index c0834a2c1..eea9893a8 100644 --- a/spec/integration/xapian_search_highlighting_spec.rb +++ b/spec/integration/xapian_search_highlighting_spec.rb @@ -1,10 +1,14 @@ -# encoding: utf-8 +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe 'highlighting search results' do include HighlightHelper + before do + get_fixtures_xapian_index + end + it 'ignores stopwords' do phrase = 'department of humpadinking' search = ActsAsXapian::Search.new([PublicBody], phrase, :limit => 1) diff --git a/spec/lib/ability_spec.rb b/spec/lib/ability_spec.rb index f075d0f32..4c5d50990 100644 --- a/spec/lib/ability_spec.rb +++ b/spec/lib/ability_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe Ability do diff --git a/spec/lib/alaveteli_external_command_spec.rb b/spec/lib/alaveteli_external_command_spec.rb index 18afeda33..f76e26152 100644 --- a/spec/lib/alaveteli_external_command_spec.rb +++ b/spec/lib/alaveteli_external_command_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') require 'alaveteli_external_command' diff --git a/spec/lib/alaveteli_text_masker_spec.rb b/spec/lib/alaveteli_text_masker_spec.rb index 1a4782a83..f2d52c1cc 100644 --- a/spec/lib/alaveteli_text_masker_spec.rb +++ b/spec/lib/alaveteli_text_masker_spec.rb @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe AlaveteliTextMasker do @@ -60,7 +60,7 @@ describe AlaveteliTextMasker do end def pdf_replacement_test(use_ghostscript_compression) - config = MySociety::Config.load_default() + config = MySociety::Config.load_default previous = config['USE_GHOSTSCRIPT_COMPRESSION'] config['USE_GHOSTSCRIPT_COMPRESSION'] = use_ghostscript_compression orig_pdf = load_file_fixture('tfl.pdf') @@ -92,6 +92,23 @@ describe AlaveteliTextMasker do pdf.should_not == "" end + it 'should keep the uncensored original if uncompression of a PDF fails' do + orig_pdf = load_file_fixture('tfl.pdf') + pdf = orig_pdf.dup + stub!(:uncompress_pdf).and_return nil + apply_masks!(pdf, "application/pdf") + pdf.should == orig_pdf + end + + it 'should use the uncompressed PDF text if re-compression of a compressed PDF fails' do + orig_pdf = load_file_fixture('tfl.pdf') + pdf = orig_pdf.dup + stub!(:uncompress_pdf).and_return "something about foi@tfl.gov.uk" + stub!(:compress_pdf).and_return nil + apply_masks!(pdf, "application/pdf") + pdf.should match "something about xxx@xxx.xxx.xx" + end + it "should apply hard-coded privacy rules to HTML files" do data = "http://test.host/c/cheese" apply_masks!(data, 'text/html') diff --git a/spec/lib/attachment_to_html/adapters/could_not_convert_spec.rb b/spec/lib/attachment_to_html/adapters/could_not_convert_spec.rb index afdc5c552..040f02bae 100644 --- a/spec/lib/attachment_to_html/adapters/could_not_convert_spec.rb +++ b/spec/lib/attachment_to_html/adapters/could_not_convert_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') describe AttachmentToHTML::Adapters::CouldNotConvert do diff --git a/spec/lib/attachment_to_html/adapters/google_docs_viewer_spec.rb b/spec/lib/attachment_to_html/adapters/google_docs_viewer_spec.rb index e7aafb40d..b1a97ea9b 100644 --- a/spec/lib/attachment_to_html/adapters/google_docs_viewer_spec.rb +++ b/spec/lib/attachment_to_html/adapters/google_docs_viewer_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') describe AttachmentToHTML::Adapters::GoogleDocsViewer do diff --git a/spec/lib/attachment_to_html/adapters/pdf_spec.rb b/spec/lib/attachment_to_html/adapters/pdf_spec.rb index ceb438be8..f4b60fb93 100644 --- a/spec/lib/attachment_to_html/adapters/pdf_spec.rb +++ b/spec/lib/attachment_to_html/adapters/pdf_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') describe AttachmentToHTML::Adapters::PDF do diff --git a/spec/lib/attachment_to_html/adapters/rtf_spec.rb b/spec/lib/attachment_to_html/adapters/rtf_spec.rb index 2c53b5272..59aef69d1 100644 --- a/spec/lib/attachment_to_html/adapters/rtf_spec.rb +++ b/spec/lib/attachment_to_html/adapters/rtf_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') describe AttachmentToHTML::Adapters::RTF do diff --git a/spec/lib/attachment_to_html/adapters/text_spec.rb b/spec/lib/attachment_to_html/adapters/text_spec.rb index b2e8141e0..0eddacb05 100644 --- a/spec/lib/attachment_to_html/adapters/text_spec.rb +++ b/spec/lib/attachment_to_html/adapters/text_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') describe AttachmentToHTML::Adapters::Text do diff --git a/spec/lib/attachment_to_html/attachment_to_html_spec.rb b/spec/lib/attachment_to_html/attachment_to_html_spec.rb index 1cf7debb7..59c13f501 100644 --- a/spec/lib/attachment_to_html/attachment_to_html_spec.rb +++ b/spec/lib/attachment_to_html/attachment_to_html_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') describe AttachmentToHTML do diff --git a/spec/lib/attachment_to_html/view_spec.rb b/spec/lib/attachment_to_html/view_spec.rb index 50179b0f7..ffe2c0d2d 100644 --- a/spec/lib/attachment_to_html/view_spec.rb +++ b/spec/lib/attachment_to_html/view_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') describe AttachmentToHTML::View do diff --git a/spec/lib/basic_encoding_spec.rb b/spec/lib/basic_encoding_spec.rb index 43a65eab9..d77465ad8 100644 --- a/spec/lib/basic_encoding_spec.rb +++ b/spec/lib/basic_encoding_spec.rb @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') def bytes_to_binary_string( bytes, claimed_encoding = nil ) @@ -103,7 +103,7 @@ end describe "convert_string_to_utf8_or_binary" do - describe "when passed uniterpretable character data" do + describe "when passed uninterpretable character data" do it "should return it as a binary string" do @@ -155,3 +155,58 @@ describe "convert_string_to_utf8_or_binary" do end end + +describe "convert_string_to_utf8" do + + describe "when passed uninterpretable character data" do + + it "should return it as a utf8 string" do + + converted = convert_string_to_utf8 random_string + converted.should == random_string + + if String.method_defined?(:encode) + converted.encoding.to_s.should == 'UTF-8' + end + + converted = convert_string_to_utf8 random_string,'UTF-8' + converted.should == random_string + + if String.method_defined?(:encode) + converted.encoding.to_s.should == 'UTF-8' + end + + end + end + + describe "when passed unlabelled Windows 1252 data" do + + it "should correctly convert it to UTF-8" do + + converted = convert_string_to_utf8 windows_1252_string + + converted.should == "DASH – DASH" + + if String.method_defined?(:encode) + converted.encoding.to_s.should == 'UTF-8' + end + end + + end + + describe "when passed GB 18030 data" do + + it "should correctly convert it to UTF-8 if unlabelled" do + + converted = convert_string_to_utf8 gb_18030_spam_string + + converted.should start_with("贵公司负责人") + + if String.method_defined?(:encode) + converted.encoding.to_s.should == 'UTF-8' + end + end + + end + +end
\ No newline at end of file diff --git a/spec/lib/confidence_intervals_spec.rb b/spec/lib/confidence_intervals_spec.rb index cb8717f3d..58f1f3d79 100644 --- a/spec/lib/confidence_intervals_spec.rb +++ b/spec/lib/confidence_intervals_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require 'confidence_intervals' describe "ci_bounds" do diff --git a/spec/lib/date_quarter_spec.rb b/spec/lib/date_quarter_spec.rb index 5af6fa334..02d2c2551 100644 --- a/spec/lib/date_quarter_spec.rb +++ b/spec/lib/date_quarter_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe DateQuarter do diff --git a/spec/lib/health_checks/checks/days_ago_check_spec.rb b/spec/lib/health_checks/checks/days_ago_check_spec.rb index 33b4642cd..4fbc1913b 100644 --- a/spec/lib/health_checks/checks/days_ago_check_spec.rb +++ b/spec/lib/health_checks/checks/days_ago_check_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') describe HealthChecks::Checks::DaysAgoCheck do @@ -15,16 +16,16 @@ describe HealthChecks::Checks::DaysAgoCheck do expect(check.days).to eq(4) end - describe :check do + describe :ok? do it 'is successful if the subject is in the last day' do check = HealthChecks::Checks::DaysAgoCheck.new { Time.now } - expect(check.check).to be_true + expect(check.ok?).to be_true end it 'fails if the subject is over a day ago' do check = HealthChecks::Checks::DaysAgoCheck.new { 2.days.ago } - expect(check.check).to be_false + expect(check.ok?).to be_false end end diff --git a/spec/lib/health_checks/health_checkable_spec.rb b/spec/lib/health_checks/health_checkable_spec.rb index abfeb5c21..59d76c337 100644 --- a/spec/lib/health_checks/health_checkable_spec.rb +++ b/spec/lib/health_checks/health_checkable_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') describe HealthChecks::HealthCheckable do @@ -31,24 +32,10 @@ describe HealthChecks::HealthCheckable do end - describe :check do - - it 'is intended to be overridden by the includer' do - expect{ @subject.check }.to raise_error(NotImplementedError) - end - - end - describe :ok? do - it 'returns true if the check was successful' do - @subject.stub(:check => true) - expect(@subject.ok?).to be_true - end - - it 'returns false if the check failed' do - @subject.stub(:check => false) - expect(@subject.ok?).to be_false + it 'is intended to be overridden by the includer' do + expect{ @subject.ok? }.to raise_error(NotImplementedError) end end @@ -92,7 +79,7 @@ describe HealthChecks::HealthCheckable do context 'if the check succeeds' do before(:each) do - @subject.stub(:check => true) + @subject.stub(:ok? => true) end it 'returns the default success message' do @@ -109,7 +96,7 @@ describe HealthChecks::HealthCheckable do context 'if the check fails' do before(:each) do - @subject.stub(:check => false) + @subject.stub(:ok? => false) end it 'returns the default failure message' do diff --git a/spec/lib/health_checks/health_checks_spec.rb b/spec/lib/health_checks/health_checks_spec.rb index c7037b813..0b97725db 100644 --- a/spec/lib/health_checks/health_checks_spec.rb +++ b/spec/lib/health_checks/health_checks_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') describe HealthChecks do @@ -6,7 +7,7 @@ describe HealthChecks do describe :add do it 'adds a check to the collection and returns the check' do - check = double('MockCheck', :check => true) + check = double('MockCheck', :ok? => true) expect(add(check)).to eq(check) end @@ -20,8 +21,8 @@ describe HealthChecks do describe :all do it 'returns all the checks' do - check1 = double('MockCheck', :check => true) - check2 = double('AnotherCheck', :check => false) + check1 = double('MockCheck', :ok? => true) + check2 = double('AnotherCheck', :ok? => false) add(check1) add(check2) expect(all).to include(check1, check2) diff --git a/spec/lib/i18n_interpolation_spec.rb b/spec/lib/i18n_interpolation_spec.rb index 47037ecdb..8c5b8d1b5 100644 --- a/spec/lib/i18n_interpolation_spec.rb +++ b/spec/lib/i18n_interpolation_spec.rb @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe "when using i18n" do @@ -58,7 +58,7 @@ describe "gettext_interpolate" do result = gettext_interpolate(string, :a => "foo".html_safe) result.should == "Hello foo" result.should_not be_html_safe - end + end end context "html safe string" do @@ -74,6 +74,6 @@ describe "gettext_interpolate" do result = gettext_interpolate(string, :a => "foo&".html_safe) result.should == "Hello foo&" result.should be_html_safe - end + end end end diff --git a/spec/lib/languages_spec.rb b/spec/lib/languages_spec.rb new file mode 100644 index 000000000..38f611087 --- /dev/null +++ b/spec/lib/languages_spec.rb @@ -0,0 +1,22 @@ +# -*- encoding : utf-8 -*- +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') + +describe LanguageNames do + + describe :get_language_name do + + it 'should return the name assigned to the language' do + LanguageNames.get_language_name('en').should == 'English' + end + + it 'should return the name assigned to the language when there is no specific location' do + LanguageNames.get_language_name('pt_BR').should == 'Português' + end + + it 'should return the name assigned to the language/location combination' do + LanguageNames.get_language_name('zh_HK').should == '中文(香港)' + end + + end + +end diff --git a/spec/lib/mail_handler/backends/mail_backend_spec.rb b/spec/lib/mail_handler/backends/mail_backend_spec.rb index eb1d4b167..91d9e1b5a 100644 --- a/spec/lib/mail_handler/backends/mail_backend_spec.rb +++ b/spec/lib/mail_handler/backends/mail_backend_spec.rb @@ -1,4 +1,4 @@ -# coding: utf-8 +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '../../../../spec_helper') describe MailHandler::Backends::MailBackend do @@ -37,6 +37,15 @@ describe MailHandler::Backends::MailBackend do get_part_file_name(part).should be_nil end + it 'turns an invalid UTF-8 name into a valid one' do + mail = get_fixture_mail('non-utf8-filename.email') + part = mail.attachments.first + filename = get_part_file_name(part) + if filename.respond_to?(:valid_encoding) + filename.valid_encoding?.should == true + end + end + end describe :get_part_body do diff --git a/spec/lib/mail_handler/mail_handler_spec.rb b/spec/lib/mail_handler/mail_handler_spec.rb index be6da5c4f..27a7a3db4 100644 --- a/spec/lib/mail_handler/mail_handler_spec.rb +++ b/spec/lib/mail_handler/mail_handler_spec.rb @@ -1,4 +1,4 @@ -# coding: utf-8 +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '../../../spec_helper') def create_message_from(from_field) @@ -9,7 +9,7 @@ end describe 'when creating a mail object from raw data' do - it "should be able to parse a large email without raising an exception", :focus => true do + it "should be able to parse a large email without raising an exception" do m = Mail.new m.add_file(:filename => "attachment.data", :content => "a" * (8 * 1024 * 1024)) raw_email = "From jamis_buck@byu.edu Mon May 2 16:07:05 2005\r\n#{m.to_s}" @@ -22,7 +22,7 @@ describe 'when creating a mail object from raw data' do mail.multipart?.should == true end - it "should not fail on invalid byte sequence in content-disposition header", :focus => true do + it "should not fail on invalid byte sequence in content-disposition header" do part = Mail::Part.new("Content-Disposition: inline; filename=a\xB8z\r\n\r\nThis is the body text.") lambda { part.inline? }.should_not raise_error end diff --git a/spec/lib/public_body_csv_spec.rb b/spec/lib/public_body_csv_spec.rb index e3cc4be6e..5c57c9533 100644 --- a/spec/lib/public_body_csv_spec.rb +++ b/spec/lib/public_body_csv_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe PublicBodyCSV do diff --git a/spec/lib/theme_spec.rb b/spec/lib/theme_spec.rb index 829c1a269..b7259078f 100644 --- a/spec/lib/theme_spec.rb +++ b/spec/lib/theme_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe "theme_url_to_theme_name" do diff --git a/spec/lib/timezone_fixes_spec.rb b/spec/lib/timezone_fixes_spec.rb index 8a9a3bf31..c44479fd7 100644 --- a/spec/lib/timezone_fixes_spec.rb +++ b/spec/lib/timezone_fixes_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # This is a test of the monkey patches in timezone_fixes.rb # We use MailServerLogDone here just as a totally random model that has a datetime type. diff --git a/spec/lib/whatdotheyknow/strip_empty_sessions_spec.rb b/spec/lib/whatdotheyknow/strip_empty_sessions_spec.rb index fcd729b48..d4f668671 100644 --- a/spec/lib/whatdotheyknow/strip_empty_sessions_spec.rb +++ b/spec/lib/whatdotheyknow/strip_empty_sessions_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') describe WhatDoTheyKnow::StripEmptySessions do diff --git a/spec/mailers/application_mailer_spec.rb b/spec/mailers/application_mailer_spec.rb index 718ac47fb..1854e4741 100644 --- a/spec/mailers/application_mailer_spec.rb +++ b/spec/mailers/application_mailer_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') @@ -13,7 +14,7 @@ describe ApplicationMailer do end def add_mail_methods(method_names) - method_names.each{ |method_name| ApplicationMailer.send(:define_method, method_name){ mail() } } + method_names.each{ |method_name| ApplicationMailer.send(:define_method, method_name){ mail } } end def remove_mail_methods(method_names) diff --git a/spec/mailers/info_request_batch_mailer_spec.rb b/spec/mailers/info_request_batch_mailer_spec.rb index 19791e163..146735e73 100644 --- a/spec/mailers/info_request_batch_mailer_spec.rb +++ b/spec/mailers/info_request_batch_mailer_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe InfoRequestBatchMailer do diff --git a/spec/mailers/outgoing_mailer_spec.rb b/spec/mailers/outgoing_mailer_spec.rb index 3df5018fe..d2bdc49dd 100644 --- a/spec/mailers/outgoing_mailer_spec.rb +++ b/spec/mailers/outgoing_mailer_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe OutgoingMailer, " when working out follow up names and addresses" do diff --git a/spec/mailers/request_mailer_spec.rb b/spec/mailers/request_mailer_spec.rb index 6a45d0e94..12d83ca62 100644 --- a/spec/mailers/request_mailer_spec.rb +++ b/spec/mailers/request_mailer_spec.rb @@ -1,6 +1,8 @@ -# encoding: utf-8 +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') +# TODO: Combine all these separate "describe" blocks to tidy things up + describe RequestMailer, " when receiving incoming mail" do before(:each) do load_raw_emails_data @@ -299,7 +301,7 @@ describe RequestMailer, "when sending reminders to requesters to classify a resp ORDER BY created_at desc LIMIT 1) < ? AND url_title != 'holding_pen' AND user_id IS NOT NULL".split(' ').join(' '), - true, Time.now() - 7.days ] + true, Time.now - 7.days ] # compare the query string ignoring any spacing differences InfoRequest.should_receive(:find) do |all, query_params| @@ -432,6 +434,10 @@ describe RequestMailer, 'when sending a new response email' do @mail = RequestMailer.new_response(@info_request, @incoming_message) end + it 'should not create HTML entities in the subject line' do + mail = RequestMailer.new_response(FactoryGirl.create(:info_request, :title => "Here's a request"), FactoryGirl.create(:incoming_message)) + expect(mail.subject).to eq "New response to your FOI request - Here's a request" + end end describe RequestMailer, 'requires_admin' do @@ -440,7 +446,7 @@ describe RequestMailer, 'requires_admin' do :name => 'Bruce Jones') @info_request = mock_model(InfoRequest, :user => user, :described_state => 'error_message', - :title => 'Test request', + :title => "It's a Test request", :url_title => 'test_request', :law_used_short => 'FOI', :id => 123) @@ -456,4 +462,42 @@ describe RequestMailer, 'requires_admin' do mail.body.should include 'Something has gone wrong' end + it 'should not create HTML entities in the subject line' do + expect(RequestMailer.requires_admin(@info_request).subject).to eq "FOI response requires admin (error_message) - It's a Test request" + end +end + +describe RequestMailer, "overdue_alert" do + it 'should not create HTML entities in the subject line' do + mail = RequestMailer.overdue_alert(FactoryGirl.create(:info_request, :title => "Here's a request"), FactoryGirl.create(:user)) + expect(mail.subject).to eq "Delayed response to your FOI request - Here's a request" + end +end + +describe RequestMailer, "very_overdue_alert" do + it 'should not create HTML entities in the subject line' do + mail = RequestMailer.very_overdue_alert(FactoryGirl.create(:info_request, :title => "Here's a request"), FactoryGirl.create(:user)) + expect(mail.subject).to eq "You're long overdue a response to your FOI request - Here's a request" + end +end + +describe RequestMailer, "not_clarified_alert" do + it 'should not create HTML entities in the subject line' do + mail = RequestMailer.not_clarified_alert(FactoryGirl.create(:info_request, :title => "Here's a request"), FactoryGirl.create(:incoming_message)) + expect(mail.subject).to eq "Clarify your FOI request - Here's a request" + end +end + +describe RequestMailer, "comment_on_alert" do + it 'should not create HTML entities in the subject line' do + mail = RequestMailer.comment_on_alert(FactoryGirl.create(:info_request, :title => "Here's a request"), FactoryGirl.create(:comment)) + expect(mail.subject).to eq "Somebody added a note to your FOI request - Here's a request" + end +end + +describe RequestMailer, "comment_on_alert_plural" do + it 'should not create HTML entities in the subject line' do + mail = RequestMailer.comment_on_alert_plural(FactoryGirl.create(:info_request, :title => "Here's a request"), 2, FactoryGirl.create(:comment)) + expect(mail.subject).to eq "Some notes have been added to your FOI request - Here's a request" + end end diff --git a/spec/mailers/track_mailer_spec.rb b/spec/mailers/track_mailer_spec.rb index e8094b692..56e0c18f6 100644 --- a/spec/mailers/track_mailer_spec.rb +++ b/spec/mailers/track_mailer_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe TrackMailer do diff --git a/spec/models/about_me_validator_spec.rb b/spec/models/about_me_validator_spec.rb index 5610cead8..c8078f44a 100644 --- a/spec/models/about_me_validator_spec.rb +++ b/spec/models/about_me_validator_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe AboutMeValidator do diff --git a/spec/models/censor_rule_spec.rb b/spec/models/censor_rule_spec.rb index 4ecd2d3e1..314b060d2 100644 --- a/spec/models/censor_rule_spec.rb +++ b/spec/models/censor_rule_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # == Schema Information # # Table name: censor_rules @@ -17,6 +18,42 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') +describe CensorRule do + + describe :apply_to_text do + + it 'applies the rule to the text' do + rule = FactoryGirl.build(:censor_rule, :text => 'secret') + text = 'Some secret text' + expect(rule.apply_to_text(text)).to eq('Some [REDACTED] text') + end + + it 'does not mutate the input' do + rule = FactoryGirl.build(:censor_rule, :text => 'secret') + text = 'Some secret text' + rule.apply_to_text(text) + expect(text).to eq('Some secret text') + end + + it 'returns the text if the rule is unmatched' do + rule = FactoryGirl.build(:censor_rule, :text => 'secret') + text = 'Some text' + expect(rule.apply_to_text(text)).to eq('Some text') + end + end + + describe :apply_to_text! do + + it 'mutates the input' do + rule = FactoryGirl.build(:censor_rule, :text => 'secret') + text = 'Some secret text' + rule.apply_to_text!(text) + expect(text).to eq('Some [REDACTED] text') + end + + end +end + describe CensorRule, "substituting things" do describe 'when using a text rule' do diff --git a/spec/models/change_email_validator_spec.rb b/spec/models/change_email_validator_spec.rb index b667a23d1..efa8ca819 100644 --- a/spec/models/change_email_validator_spec.rb +++ b/spec/models/change_email_validator_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') def validator_with_user_and_params(user, params = {}) diff --git a/spec/models/contact_validator_spec.rb b/spec/models/contact_validator_spec.rb index 0f5403967..9d7c192a3 100644 --- a/spec/models/contact_validator_spec.rb +++ b/spec/models/contact_validator_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe ContactValidator do diff --git a/spec/models/customstates.rb b/spec/models/customstates.rb index 942e1fcde..453453f20 100644 --- a/spec/models/customstates.rb +++ b/spec/models/customstates.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- module InfoRequestCustomStates def self.included(base) diff --git a/spec/models/foi_attachment_spec.rb b/spec/models/foi_attachment_spec.rb index 882723d1e..9583f4c76 100644 --- a/spec/models/foi_attachment_spec.rb +++ b/spec/models/foi_attachment_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # == Schema Information # # Table name: foi_attachments @@ -17,45 +18,59 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe FoiAttachment do - before(:each) do - load_raw_emails_data - end + describe :body= do + + it "sets the body" do + attachment = FoiAttachment.new + attachment.body = "baz" + attachment.body.should == "baz" + end + + it "sets the size" do + attachment = FoiAttachment.new + attachment.body = "baz" + attachment.body.should == "baz" + attachment.display_size.should == "0K" + end + + it "reparses the body if it disappears" do + load_raw_emails_data + im = incoming_messages(:useless_incoming_message) + im.extract_attachments! + main = im.get_main_body_text_part + orig_body = main.body + main.delete_cached_file! + lambda { + im.get_main_body_text_part.body + }.should_not raise_error(Errno::ENOENT) + main.delete_cached_file! + main = im.get_main_body_text_part + main.body.should == orig_body + end - it "sets the body" do - attachment = FoiAttachment.new - attachment.body = "baz" - attachment.body.should == "baz" - end - it "sets the size" do - attachment = FoiAttachment.new - attachment.body = "baz" - attachment.body.should == "baz" - attachment.update_display_size! - attachment.display_size.should == "0K" end - it "reparses the body if it disappears" do - im = incoming_messages(:useless_incoming_message) - im.extract_attachments! - main = im.get_main_body_text_part - orig_body = main.body - main.delete_cached_file! - lambda { - im.get_main_body_text_part.body - }.should_not raise_error(Errno::ENOENT) - main.delete_cached_file! - main = im.get_main_body_text_part - main.body.should == orig_body + + describe :ensure_filename! do + + it 'should create a filename for an instance with a blank filename' do + attachment = FoiAttachment.new + attachment.filename = '' + attachment.ensure_filename! + attachment.filename.should == 'attachment.bin' + end end -end -describe FoiAttachment, "when ensuring a filename is present" do + describe :has_body_as_html? do + + it 'should be true for a pdf attachment' do + FactoryGirl.build(:pdf_attachment).has_body_as_html?.should be_true + end + + it 'should be false for an html attachment' do + FactoryGirl.build(:html_attachment).has_body_as_html?.should be_false + end - it 'should create a filename for an instance with a blank filename' do - attachment = FoiAttachment.new - attachment.filename = '' - attachment.ensure_filename! - attachment.filename.should == 'attachment.bin' end end diff --git a/spec/models/has_tag_string_tag_spec.rb b/spec/models/has_tag_string_tag_spec.rb index 759b3396f..bbcb00ca2 100644 --- a/spec/models/has_tag_string_tag_spec.rb +++ b/spec/models/has_tag_string_tag_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe HasTagString::HasTagStringTag, " when fiddling with tag strings" do diff --git a/spec/models/holiday_import_spec.rb b/spec/models/holiday_import_spec.rb index 7ec5c04d5..eb0b33e0e 100644 --- a/spec/models/holiday_import_spec.rb +++ b/spec/models/holiday_import_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe HolidayImport do diff --git a/spec/models/holiday_spec.rb b/spec/models/holiday_spec.rb index 2f8eeabd9..bd73e672b 100644 --- a/spec/models/holiday_spec.rb +++ b/spec/models/holiday_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # == Schema Information # # Table name: holidays diff --git a/spec/models/incoming_message_spec.rb b/spec/models/incoming_message_spec.rb index ca9bbe39e..10bb3de62 100644 --- a/spec/models/incoming_message_spec.rb +++ b/spec/models/incoming_message_spec.rb @@ -1,4 +1,4 @@ -# coding: utf-8 +# -*- encoding : utf-8 -*- # == Schema Information # # Table name: incoming_messages @@ -263,7 +263,7 @@ describe IncomingMessage, " when dealing with incoming mail" do incoming_message = InfoRequest.holding_pen_request.incoming_messages[0] # This will raise an error if the bug in TMail hasn't been fixed - incoming_message.get_body_for_html_display() + incoming_message.get_body_for_html_display end @@ -282,7 +282,7 @@ end describe IncomingMessage, " display attachments" do it "should not show slashes in filenames" do - foi_attachment = FoiAttachment.new() + foi_attachment = FoiAttachment.new # http://www.whatdotheyknow.com/request/post_commercial_manager_librarie#incoming-17233 foi_attachment.filename = "FOI/09/066 RESPONSE TO FOI REQUEST RECEIVED 21st JANUARY 2009.txt" expected_display_filename = foi_attachment.filename.gsub(/\//, " ") @@ -290,7 +290,7 @@ describe IncomingMessage, " display attachments" do end it "should not show slashes in subject generated filenames" do - foi_attachment = FoiAttachment.new() + foi_attachment = FoiAttachment.new # http://www.whatdotheyknow.com/request/post_commercial_manager_librarie#incoming-17233 foi_attachment.within_rfc822_subject = "FOI/09/066 RESPONSE TO FOI REQUEST RECEIVED 21st JANUARY 2009" foi_attachment.content_type = 'text/plain' @@ -312,20 +312,20 @@ describe IncomingMessage, " folding quoted parts of emails" do it 'should fold a plain text lotus notes quoted part correctly' do text = "FOI Team\n\n\nInfo Requester <xxx@whatdotheyknow.com>=20\nSent by: Info Requester <request-bounce-xxxxx@whatdotheyknow.com>\n06/03/08 10:00\nPlease respond to\nInfo Requester <request-xxxx@whatdotheyknow.com>" - @incoming_message = IncomingMessage.new() + @incoming_message = IncomingMessage.new @incoming_message.stub_chain(:info_request, :user_name).and_return("Info Requester") @incoming_message.remove_lotus_quoting(text).should match(/FOLDED_QUOTED_SECTION/) end it 'should not error when trying to fold lotus notes quoted parts on a request with no user_name' do text = "hello" - @incoming_message = IncomingMessage.new() + @incoming_message = IncomingMessage.new @incoming_message.stub_chain(:info_request, :user_name).and_return(nil) @incoming_message.remove_lotus_quoting(text).should == 'hello' end it "cope with [ in user names properly" do - @incoming_message = IncomingMessage.new() + @incoming_message = IncomingMessage.new @incoming_message.stub_chain(:info_request, :user_name).and_return("Sir [ Bobble") # this gives a warning if [ is in the name text = @incoming_message.remove_lotus_quoting("Sir [ Bobble \nSent by: \n") @@ -357,7 +357,7 @@ describe IncomingMessage, " checking validity to reply to" do MailHandler.stub!(:get_from_address).and_return(email) MailHandler.stub!(:empty_return_path?).with(@mail).and_return(empty_return_path) MailHandler.stub!(:get_auto_submitted).with(@mail).and_return(autosubmitted) - @incoming_message = IncomingMessage.new() + @incoming_message = IncomingMessage.new @incoming_message.stub!(:mail).and_return(@mail) @incoming_message._calculate_valid_to_reply_to.should == result end @@ -431,21 +431,21 @@ describe IncomingMessage, " when censoring data" do @im = incoming_messages(:useless_incoming_message) - @censor_rule_1 = CensorRule.new() + @censor_rule_1 = CensorRule.new @censor_rule_1.text = "Stilton" @censor_rule_1.replacement = "Jarlsberg" @censor_rule_1.last_edit_editor = "unknown" @censor_rule_1.last_edit_comment = "none" @im.info_request.censor_rules << @censor_rule_1 - @censor_rule_2 = CensorRule.new() + @censor_rule_2 = CensorRule.new @censor_rule_2.text = "blue" @censor_rule_2.replacement = "yellow" @censor_rule_2.last_edit_editor = "unknown" @censor_rule_2.last_edit_comment = "none" @im.info_request.censor_rules << @censor_rule_2 - @regex_censor_rule = CensorRule.new() + @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' @@ -477,7 +477,7 @@ describe IncomingMessage, " when censoring whole users" do @im = incoming_messages(:useless_incoming_message) - @censor_rule_1 = CensorRule.new() + @censor_rule_1 = CensorRule.new @censor_rule_1.text = "Stilton" @censor_rule_1.replacement = "Gorgonzola" @censor_rule_1.last_edit_editor = "unknown" @@ -534,7 +534,7 @@ describe IncomingMessage, " when uudecoding bad messages" do im.stub!(:mail).and_return(mail) ir = info_requests(:fancy_dog_request) - @censor_rule = CensorRule.new() + @censor_rule = CensorRule.new @censor_rule.text = "moo" @censor_rule.replacement = "bah" @censor_rule.last_edit_editor = "unknown" diff --git a/spec/models/info_request_batch_spec.rb b/spec/models/info_request_batch_spec.rb index 2881e7745..a8572e7ba 100644 --- a/spec/models/info_request_batch_spec.rb +++ b/spec/models/info_request_batch_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # == Schema Information # # Table name: info_request_batches @@ -80,7 +81,7 @@ describe InfoRequestBatch, "when finding an existing batch" do end end -describe InfoRequestBatch, "when creating a batch", :focus => true do +describe InfoRequestBatch, "when creating a batch" do before do @title = 'A test title' diff --git a/spec/models/info_request_event_spec.rb b/spec/models/info_request_event_spec.rb index 53c83bd46..ff20ab059 100644 --- a/spec/models/info_request_event_spec.rb +++ b/spec/models/info_request_event_spec.rb @@ -1,4 +1,4 @@ -# coding: utf-8 +# -*- encoding : utf-8 -*- # == Schema Information # # Table name: info_request_events @@ -30,6 +30,12 @@ describe InfoRequestEvent do ire.params.should == example_params end + it "should restore UTF8-heavy params stored under ruby 1.8 as UTF-8" do + ire = InfoRequestEvent.new + utf8_params = "--- \n:foo: !binary |\n 0KLQvtCz0LDRiCDR\n" + ire.params_yaml = utf8_params + ire.params[:foo].encoding.to_s.should == 'UTF-8' if ire.params[:foo].respond_to?(:encoding) + end end describe 'when deciding if it is indexed by search' do @@ -105,7 +111,7 @@ describe InfoRequestEvent do describe "should know" do it "that it's an incoming message" do - event = InfoRequestEvent.new() + event = InfoRequestEvent.new event.stub!(:incoming_message_selective_columns).and_return(1) event.is_incoming_message?.should be_true event.is_outgoing_message?.should be_false diff --git a/spec/models/info_request_spec.rb b/spec/models/info_request_spec.rb index 9d1e02442..18120fbb5 100644 --- a/spec/models/info_request_spec.rb +++ b/spec/models/info_request_spec.rb @@ -1,4 +1,4 @@ -# encoding: utf-8 +# -*- encoding : utf-8 -*- # == Schema Information # # Table name: info_requests @@ -28,6 +28,117 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe InfoRequest do + describe :new do + + it 'sets the default law used' do + expect(InfoRequest.new.law_used).to eq('foi') + end + + it 'sets the default law used if a body is eir-only' do + body = FactoryGirl.create(:public_body, :tag_string => 'eir_only') + expect(body.info_requests.build.law_used).to eq('eir') + end + + it 'does not try to set the law used for existing requests' do + info_request = FactoryGirl.create(:info_request) + body = FactoryGirl.create(:public_body, :tag_string => 'eir_only') + info_request.update_attributes(:public_body_id => body.id) + InfoRequest.any_instance.should_not_receive(:law_used=).and_call_original + InfoRequest.find(info_request.id) + end + end + + describe :move_to_public_body do + + context 'with no options' do + + it 'requires an :editor option' do + request = FactoryGirl.create(:info_request) + new_body = FactoryGirl.create(:public_body) + expect { + request.move_to_public_body(new_body) + }.to raise_error IndexError + end + + end + + context 'with the :editor option' do + + it 'moves the info request to the new public body' do + request = FactoryGirl.create(:info_request) + new_body = FactoryGirl.create(:public_body) + user = FactoryGirl.create(:user) + request.move_to_public_body(new_body, :editor => user) + request.reload + expect(request.public_body).to eq(new_body) + end + + it 'logs the move' do + request = FactoryGirl.create(:info_request) + old_body = request.public_body + new_body = FactoryGirl.create(:public_body) + user = FactoryGirl.create(:user) + request.move_to_public_body(new_body, :editor => user) + request.reload + event = request.info_request_events.last + + expect(event.event_type).to eq('move_request') + expect(event.params[:editor]).to eq(user) + expect(event.params[:public_body_url_name]).to eq(new_body.url_name) + expect(event.params[:old_public_body_url_name]).to eq(old_body.url_name) + end + + it 'updates the law_used to the new body law' do + request = FactoryGirl.create(:info_request) + new_body = FactoryGirl.create(:public_body, :tag_string => 'eir_only') + user = FactoryGirl.create(:user) + request.move_to_public_body(new_body, :editor => user) + request.reload + expect(request.law_used).to eq('eir') + end + + it 'returns the new public body' do + request = FactoryGirl.create(:info_request) + new_body = FactoryGirl.create(:public_body) + user = FactoryGirl.create(:user) + expect(request.move_to_public_body(new_body, :editor => user)).to eq(new_body) + end + + it 'retains the existing body if the new body does not exist' do + request = FactoryGirl.create(:info_request) + user = FactoryGirl.create(:user) + existing_body = request.public_body + request.move_to_public_body(nil, :editor => user) + request.reload + expect(request.public_body).to eq(existing_body) + end + + it 'returns nil if the body cannot be updated' do + request = FactoryGirl.create(:info_request) + user = FactoryGirl.create(:user) + expect(request.move_to_public_body(nil, :editor => user)).to eq(nil) + end + + it 'reindexes the info request' do + request = FactoryGirl.create(:info_request) + new_body = FactoryGirl.create(:public_body) + user = FactoryGirl.create(:user) + reindex_job = ActsAsXapian::ActsAsXapianJob. + where(:model => 'InfoRequestEvent'). + delete_all + + request.move_to_public_body(new_body, :editor => user) + request.reload + + reindex_job = ActsAsXapian::ActsAsXapianJob. + where(:model => 'InfoRequestEvent'). + last + expect(reindex_job.model_id).to eq(request.info_request_events.last.id) + end + + end + end + describe 'when validating' do it 'should accept a summary with ascii characters' do @@ -42,7 +153,7 @@ describe InfoRequest do info_request.errors[:title].should be_empty end - it 'should not accept a summary with no ascii or unicode characters' do + it 'should not accept a summary with no ascii or unicode characters' do info_request = InfoRequest.new(:title => '55555') info_request.valid? info_request.errors[:title].should_not be_empty @@ -547,17 +658,22 @@ describe InfoRequest do before do Time.stub!(:now).and_return(Time.utc(2007, 11, 9, 23, 59)) - @mock_comment_event = mock_model(InfoRequestEvent, :created_at => Time.now - 23.days, - :event_type => 'comment', - :response? => false) - mock_incoming_message = mock_model(IncomingMessage, :all_can_view? => true) - @mock_response_event = mock_model(InfoRequestEvent, :created_at => Time.now - 22.days, - :event_type => 'response', - :response? => true, - :incoming_message => mock_incoming_message) - @info_request = InfoRequest.new(:prominence => 'normal', - :awaiting_description => true, - :info_request_events => [@mock_response_event, @mock_comment_event]) + @info_request = FactoryGirl.create(:info_request, + :prominence => 'normal', + :awaiting_description => true) + @comment_event = FactoryGirl.create(:info_request_event, + :created_at => Time.now - 23.days, + :event_type => 'comment', + :info_request => @info_request) + @incoming_message = FactoryGirl.create(:incoming_message, + :prominence => 'normal', + :info_request => @info_request) + @response_event = FactoryGirl.create(:info_request_event, + :info_request => @info_request, + :created_at => Time.now - 22.days, + :event_type => 'response', + :incoming_message => @incoming_message) + @info_request.update_attribute(:awaiting_description, true) end it 'should return false if it is the holding pen' do @@ -571,7 +687,7 @@ describe InfoRequest do end 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) + @response_event.update_attribute(:created_at, Time.now - 20.days) @info_request.is_old_unclassified?.should be_false end @@ -1314,4 +1430,20 @@ describe InfoRequest do end + + describe 'when destroying a message' do + + it 'can destroy a request with comments and censor rules' do + info_request = FactoryGirl.create(:info_request) + censor_rule = FactoryGirl.create(:censor_rule, :info_request => info_request) + comment = FactoryGirl.create(:comment, :info_request => info_request) + info_request.reload + info_request.fully_destroy + + InfoRequest.where(:id => info_request.id).should be_empty + CensorRule.where(:id => censor_rule.id).should be_empty + Comment.where(:id => comment.id).should be_empty + end + + end end diff --git a/spec/models/mail_server_log_spec.rb b/spec/models/mail_server_log_spec.rb index 67709b130..6b38e1270 100644 --- a/spec/models/mail_server_log_spec.rb +++ b/spec/models/mail_server_log_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # == Schema Information # # Table name: mail_server_logs diff --git a/spec/models/outgoing_message_spec.rb b/spec/models/outgoing_message_spec.rb index a3e2d1c68..8d43e2ef1 100644 --- a/spec/models/outgoing_message_spec.rb +++ b/spec/models/outgoing_message_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # == Schema Information # # Table name: outgoing_messages @@ -18,6 +19,93 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') +describe OutgoingMessage do + + describe :initialize do + + it 'does not censor the #body' do + attrs = { :status => 'ready', + :message_type => 'initial_request', + :body => 'abc', + :what_doing => 'normal_sort' } + + message = FactoryGirl.create(:outgoing_message, attrs) + + OutgoingMessage.any_instance.should_not_receive(:body).and_call_original + OutgoingMessage.find(message.id) + end + + end + + describe :body do + + it 'returns the body attribute' do + attrs = { :status => 'ready', + :message_type => 'initial_request', + :body => 'abc', + :what_doing => 'normal_sort' } + + message = FactoryGirl.build(:outgoing_message, attrs) + expect(message.body).to eq('abc') + end + + it 'strips the body of leading and trailing whitespace' do + attrs = { :status => 'ready', + :message_type => 'initial_request', + :body => ' abc ', + :what_doing => 'normal_sort' } + + message = FactoryGirl.build(:outgoing_message, attrs) + expect(message.body).to eq('abc') + end + + it 'removes excess linebreaks that unnecessarily space it out' do + attrs = { :status => 'ready', + :message_type => 'initial_request', + :body => "ab\n\nc\n\n", + :what_doing => 'normal_sort' } + + message = FactoryGirl.build(:outgoing_message, attrs) + expect(message.body).to eq("ab\n\nc") + end + + it "applies the associated request's censor rules to the text" do + attrs = { :status => 'ready', + :message_type => 'initial_request', + :body => 'This sensitive text contains secret info!', + :what_doing => 'normal_sort' } + message = FactoryGirl.build(:outgoing_message, attrs) + + rules = [FactoryGirl.build(:censor_rule, :text => 'secret'), + FactoryGirl.build(:censor_rule, :text => 'sensitive')] + InfoRequest.any_instance.stub(:censor_rules).and_return(rules) + + expected = 'This [REDACTED] text contains [REDACTED] info!' + expect(message.body).to eq(expected) + end + + it "applies the given censor rules to the text" do + attrs = { :status => 'ready', + :message_type => 'initial_request', + :body => 'This sensitive text contains secret info!', + :what_doing => 'normal_sort' } + message = FactoryGirl.build(:outgoing_message, attrs) + + request_rules = [FactoryGirl.build(:censor_rule, :text => 'secret'), + FactoryGirl.build(:censor_rule, :text => 'sensitive')] + InfoRequest.any_instance.stub(:censor_rules).and_return(request_rules) + + censor_rules = [FactoryGirl.build(:censor_rule, :text => 'text'), + FactoryGirl.build(:censor_rule, :text => 'contains')] + + expected = 'This sensitive [REDACTED] [REDACTED] secret info!' + expect(message.body(:censor_rules => censor_rules)).to eq(expected) + end + + end + +end + describe OutgoingMessage, " when making an outgoing message" do before do @@ -26,7 +114,7 @@ describe OutgoingMessage, " when making an outgoing message" do :status => 'ready', :message_type => 'initial_request', :body => 'This request contains a foo@bar.com email address', - :last_sent_at => Time.now(), + :last_sent_at => Time.now, :what_doing => 'normal_sort' }) end @@ -57,6 +145,7 @@ describe OutgoingMessage, " when making an outgoing message" do info_request = mock_model(InfoRequest, :public_body => public_body, :url_title => 'a_test_title', :title => 'A test title', + :applicable_censor_rules => [], :apply_censor_rules_to_text! => nil, :is_batch_request_template? => false) outgoing_message = OutgoingMessage.new({ @@ -155,27 +244,6 @@ describe OutgoingMessage, " when making an outgoing message" do end end - -describe OutgoingMessage, " when censoring data" do - - before do - @om = outgoing_messages(:useless_outgoing_message) - - @censor_rule = CensorRule.new() - @censor_rule.text = "dog" - @censor_rule.replacement = "cat" - @censor_rule.last_edit_editor = "unknown" - @censor_rule.last_edit_comment = "none" - - @om.info_request.censor_rules << @censor_rule - end - - it "should apply censor rules to outgoing messages" do - @om.read_attribute(:body).should match(/fancy dog/) - @om.body.should match(/fancy cat/) - end -end - describe OutgoingMessage, "when validating the format of the message body" do it 'should handle a salutation with a bracket in it' do diff --git a/spec/models/post_redirect_spec.rb b/spec/models/post_redirect_spec.rb index 73740e914..7d0dfe395 100644 --- a/spec/models/post_redirect_spec.rb +++ b/spec/models/post_redirect_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # == Schema Information # # Table name: post_redirects @@ -65,11 +66,18 @@ describe PostRedirect, " when accessing values" do end it "should convert reason parameters into YAML and back successfully" do - pr = PostRedirect.new + pr = PostRedirect.new example_reason_params = { :foo => 'this is stuff', :bar => 83, :humbug => "yikes!!!" } pr.reason_params = example_reason_params pr.reason_params_yaml.should == example_reason_params.to_yaml pr.reason_params.should == example_reason_params end + + it "should restore UTF8-heavy params stored under ruby 1.8 as UTF-8" do + pr = PostRedirect.new + utf8_params = "--- \n:foo: !binary |\n 0KLQvtCz0LDRiCDR\n" + pr.reason_params_yaml = utf8_params + pr.reason_params[:foo].encoding.to_s.should == 'UTF-8' if pr.reason_params[:foo].respond_to?(:encoding) + end end diff --git a/spec/models/profile_photo_spec.rb b/spec/models/profile_photo_spec.rb index e70f474a0..199c87500 100644 --- a/spec/models/profile_photo_spec.rb +++ b/spec/models/profile_photo_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # == Schema Information # # Table name: profile_photos diff --git a/spec/models/public_body_category/category_collection_spec.rb b/spec/models/public_body_category/category_collection_spec.rb index 1fbcbe739..9ee684982 100644 --- a/spec/models/public_body_category/category_collection_spec.rb +++ b/spec/models/public_body_category/category_collection_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') describe PublicBodyCategory::CategoryCollection do @@ -15,7 +16,7 @@ describe PublicBodyCategory::CategoryCollection do describe 'when asked for headings' do it 'should return a list of headings' do - @categories.headings().should == ['Local and regional', 'Miscellaneous'] + @categories.headings.should == ['Local and regional', 'Miscellaneous'] end end @@ -30,7 +31,7 @@ describe PublicBodyCategory::CategoryCollection do "Miscellaneous", ["other", "Miscellaneous", "miscellaneous"]] - @categories.with_headings().should == expected_categories + @categories.with_headings.should == expected_categories end end @@ -38,7 +39,7 @@ describe PublicBodyCategory::CategoryCollection do describe 'when asked for tags by headings' do it 'should return a hash of tags keyed by heading' do - @categories.by_heading().should == {'Local and regional' => ['local_council'], + @categories.by_heading.should == {'Local and regional' => ['local_council'], 'Miscellaneous' => ['other']} end end @@ -50,19 +51,19 @@ describe PublicBodyCategory::CategoryCollection do ["local_council", "Local councils", "a local council"], ["other", "Miscellaneous", "miscellaneous"] ] - @categories.with_description().should == expected_categories + @categories.with_description.should == expected_categories end end describe 'when asked for tags' do it 'should return a list of tags' do - @categories.tags().should == ["local_council", "other"] + @categories.tags.should == ["local_council", "other"] end end describe 'when asked for categories by tag' do it 'should return a hash of categories keyed by tag' do - @categories.by_tag().should == { + @categories.by_tag.should == { "local_council" => "Local councils", "other" => "Miscellaneous" } @@ -71,7 +72,7 @@ describe PublicBodyCategory::CategoryCollection do describe 'when asked for singular_by_tag' do it 'should return a hash of category descriptions keyed by tag' do - @categories.singular_by_tag().should == { + @categories.singular_by_tag.should == { "local_council" => "a local council", "other" => "miscellaneous" } diff --git a/spec/models/public_body_category_link_spec.rb b/spec/models/public_body_category_link_spec.rb index fd5608480..564f4126f 100644 --- a/spec/models/public_body_category_link_spec.rb +++ b/spec/models/public_body_category_link_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # == Schema Information # # Table name: public_body_category_links diff --git a/spec/models/public_body_category_spec.rb b/spec/models/public_body_category_spec.rb index 297bd096a..c6b2a8fde 100644 --- a/spec/models/public_body_category_spec.rb +++ b/spec/models/public_body_category_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # == Schema Information # # Table name: public_body_categories diff --git a/spec/models/public_body_change_request_spec.rb b/spec/models/public_body_change_request_spec.rb index 0c4cea67b..e35ffa692 100644 --- a/spec/models/public_body_change_request_spec.rb +++ b/spec/models/public_body_change_request_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # == Schema Information # # Table name: public_body_change_requests @@ -21,7 +22,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe PublicBodyChangeRequest, 'when validating' do it 'should not be valid without a public body name' do - change_request = PublicBodyChangeRequest.new() + change_request = PublicBodyChangeRequest.new change_request.valid?.should be_false change_request.errors[:public_body_name].should == ['Please enter the name of the authority'] end diff --git a/spec/models/public_body_heading_spec.rb b/spec/models/public_body_heading_spec.rb index be3e7c7d2..8b46181b6 100644 --- a/spec/models/public_body_heading_spec.rb +++ b/spec/models/public_body_heading_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # == Schema Information # # Table name: public_body_headings diff --git a/spec/models/public_body_spec.rb b/spec/models/public_body_spec.rb index 7b55efda1..d6abf7b5f 100644 --- a/spec/models/public_body_spec.rb +++ b/spec/models/public_body_spec.rb @@ -1,4 +1,4 @@ -# encoding: UTF-8 +# -*- encoding : utf-8 -*- # == Schema Information # # Table name: public_bodies @@ -1237,6 +1237,33 @@ describe PublicBody do end + describe :request_email do + context "when the email is set" do + subject(:public_body) { FactoryGirl.create(:public_body, :request_email => "request@example.com") } + + it "should return the set email address" do + expect(public_body.request_email).to eq("request@example.com") + end + + it "should return a different email address when overridden in configuration" do + AlaveteliConfiguration.stub!(:override_all_public_body_request_emails).and_return("tester@example.com") + expect(public_body.request_email).to eq("tester@example.com") + end + end + + context "when no email is set" do + subject(:public_body) { FactoryGirl.create(:public_body, :request_email => "") } + + it "should return a blank email address" do + expect(public_body.request_email).to be_blank + end + + it "should still return a blank email address when overridden in configuration" do + AlaveteliConfiguration.stub!(:override_all_public_body_request_emails).and_return("tester@example.com") + expect(public_body.request_email).to be_blank + end + end + end end describe PublicBody::Translation do diff --git a/spec/models/purge_request_spec.rb b/spec/models/purge_request_spec.rb index 02b3d685d..642d5d2e2 100644 --- a/spec/models/purge_request_spec.rb +++ b/spec/models/purge_request_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # == Schema Information # # Table name: purge_requests @@ -22,23 +23,23 @@ describe PurgeRequest, "purging things" do req = PurgeRequest.new(:url => "/begone_from_here", :model => "don't care", :model_id => "don't care") - req.save() - PurgeRequest.all().count.should == 1 - PurgeRequest.purge_all() - PurgeRequest.all().count.should == 0 + req.save + PurgeRequest.all.count.should == 1 + PurgeRequest.purge_all + PurgeRequest.all.count.should == 0 end it 'should fail silently for a misconfigured server' do FakeWeb.register_uri(:get, %r|brokenv|, :body => "BROKEN") - config = MySociety::Config.load_default() + config = MySociety::Config.load_default config['VARNISH_HOST'] = "brokencache" req = PurgeRequest.new(:url => "/begone_from_here", :model => "don't care", :model_id => "don't care") - req.save() - PurgeRequest.all().count.should == 1 - PurgeRequest.purge_all() - PurgeRequest.all().count.should == 0 + req.save + PurgeRequest.all.count.should == 1 + PurgeRequest.purge_all + PurgeRequest.all.count.should == 0 end end diff --git a/spec/models/spam_address_spec.rb b/spec/models/spam_address_spec.rb index f28440121..670b969b0 100644 --- a/spec/models/spam_address_spec.rb +++ b/spec/models/spam_address_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # == Schema Information # # Table name: spam_addresses @@ -15,7 +16,7 @@ describe SpamAddress do describe :new do it 'requres an email address' do - SpamAddress.new().should_not be_valid + SpamAddress.new.should_not be_valid SpamAddress.new(:email => 'spam@example.org').should be_valid end diff --git a/spec/models/track_thing_spec.rb b/spec/models/track_thing_spec.rb index 3edf2d1ad..251a50803 100644 --- a/spec/models/track_thing_spec.rb +++ b/spec/models/track_thing_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # == Schema Information # # Table name: track_things diff --git a/spec/models/track_things_sent_email_spec.rb b/spec/models/track_things_sent_email_spec.rb index 4675d0847..b31a989db 100644 --- a/spec/models/track_things_sent_email_spec.rb +++ b/spec/models/track_things_sent_email_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # == Schema Information # # Table name: track_things_sent_emails diff --git a/spec/models/user_info_request_sent_alert_spec.rb b/spec/models/user_info_request_sent_alert_spec.rb index 69be1092b..6b4efa575 100644 --- a/spec/models/user_info_request_sent_alert_spec.rb +++ b/spec/models/user_info_request_sent_alert_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # == Schema Information # # Table name: user_info_request_sent_alerts diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 2245a024f..009045bdf 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # == Schema Information # # Table name: users diff --git a/spec/models/widget_vote_spec.rb b/spec/models/widget_vote_spec.rb new file mode 100644 index 000000000..1a6d3833c --- /dev/null +++ b/spec/models/widget_vote_spec.rb @@ -0,0 +1,54 @@ +# -*- encoding : utf-8 -*- +# == Schema Information +# +# Table name: widget_votes +# +# id :integer not null, primary key +# cookie :string(255) +# info_request_id :integer +# created_at :datetime not null +# updated_at :datetime not null +# + +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') + +describe WidgetVote do + + describe :new do + + it 'requires an info request' do + widget_vote = WidgetVote.new + widget_vote.should_not be_valid + widget_vote.errors[:info_request].should == ["can't be blank"] + end + + it 'validates the cookie length' do + widget_vote = WidgetVote.new + widget_vote.should_not be_valid + widget_vote.errors[:cookie].should == ["is the wrong length (should be 20 characters)"] + end + + it 'is valid with a cookie and info request' do + widget_vote = FactoryGirl.create(:widget_vote) + widget_vote.should be_valid + end + + it 'enforces uniqueness of cookie per info request' do + info_request = FactoryGirl.create(:info_request) + widget_vote = info_request.widget_votes.create(:cookie => 'x' * 20) + duplicate_vote = info_request.widget_votes.build(:cookie => 'x' * 20) + duplicate_vote.should_not be_valid + duplicate_vote.errors[:cookie].should == ["has already been taken"] + end + + it 'allows the same cookie to be used across info requests' do + info_request = FactoryGirl.create(:info_request) + second_info_request = FactoryGirl.create(:info_request) + widget_vote = info_request.widget_votes.create(:cookie => 'x' * 20) + second_request_vote = second_info_request.widget_votes.build(:cookie => 'x' * 20) + second_request_vote.should be_valid + end + + end + +end diff --git a/spec/models/xapian_spec.rb b/spec/models/xapian_spec.rb index ca6cd7db7..212a1cc7e 100644 --- a/spec/models/xapian_spec.rb +++ b/spec/models/xapian_spec.rb @@ -1,4 +1,4 @@ -# encoding: utf-8 +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe User, " when indexing users with Xapian" do @@ -102,7 +102,7 @@ describe PublicBody, " when indexing requests by body they are to" do end # if you index via the Xapian TermGenerator, it ignores terms of this length, - # this checks we're using Document:::add_term() instead + # this checks we're using Document:::add_term instead it "should work with URL names that are longer than 64 characters" do # change the URL name of the body body = public_bodies(:geraldine_public_body) diff --git a/spec/script/handle-mail-replies_spec.rb b/spec/script/handle-mail-replies_spec.rb index 62d5c1dab..399d0d51d 100644 --- a/spec/script/handle-mail-replies_spec.rb +++ b/spec/script/handle-mail-replies_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') require "external_command" diff --git a/spec/script/mailin_spec.rb b/spec/script/mailin_spec.rb index 0ff094c2b..6cdc1308e 100644 --- a/spec/script/mailin_spec.rb +++ b/spec/script/mailin_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') require "external_command" diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 93bcfa1ba..d9feba6cd 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require 'rubygems' require 'spork' @@ -124,13 +125,6 @@ Spork.prefork do end end - # TODO: No idea what namespace/class/module to put this in - # Create a clean xapian index based on the fixture files and the raw_email data. - def create_fixtures_xapian_index - load_raw_emails_data - rebuild_xapian_index - end - # Use the before create job hook to simulate a race condition with # another process by creating an acts_as_xapian_job record for the # same model: diff --git a/spec/support/email_helpers.rb b/spec/support/email_helpers.rb index 252b1f137..8f2abdbfa 100644 --- a/spec/support/email_helpers.rb +++ b/spec/support/email_helpers.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- def load_raw_emails_data raw_emails_yml = File.join(RSpec.configuration.fixture_path, "raw_emails.yml") for raw_email_id in YAML::load_file(raw_emails_yml).map{|k,v| v["id"]} do diff --git a/spec/support/load_file_fixtures.rb b/spec/support/load_file_fixtures.rb index a54505e99..4370a1b3d 100644 --- a/spec/support/load_file_fixtures.rb +++ b/spec/support/load_file_fixtures.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- def file_fixture_name(file_name) return File.join(RSpec.configuration.fixture_path, "files", file_name) end diff --git a/spec/support/xapian_index.rb b/spec/support/xapian_index.rb index 344c28ebb..3f5f900fd 100644 --- a/spec/support/xapian_index.rb +++ b/spec/support/xapian_index.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # Rebuild the current xapian index def rebuild_xapian_index(terms = true, values = true, texts = true, dropfirst = true) if dropfirst @@ -22,7 +23,7 @@ end # Copy the xapian index created in create_fixtures_xapian_index to a temporary # copy at the same level and point xapian at the copy -def get_fixtures_xapian_index() +def get_fixtures_xapian_index # Create a base index for the fixtures if not already created $existing_xapian_db ||= create_fixtures_xapian_index # Store whatever the xapian db path is originally diff --git a/spec/views/public_body/show.html.erb_spec.rb b/spec/views/public_body/show.html.erb_spec.rb index 6ebc39caa..a4edcfc22 100644 --- a/spec/views/public_body/show.html.erb_spec.rb +++ b/spec/views/public_body/show.html.erb_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.join('..', '..', '..', 'spec_helper'), __FILE__) describe "public_body/show" do @@ -13,7 +14,6 @@ describe "public_body/show" do :publication_scheme => '', :disclosure_log => '', :calculated_home_page => '') - @pb.stub!(:override_request_email).and_return(nil) @pb.stub!(:is_requestable?).and_return(true) @pb.stub!(:special_not_requestable_reason?).and_return(false) @pb.stub!(:has_notes?).and_return(false) @@ -30,6 +30,7 @@ describe "public_body/show" do assign(:xapian_requests, @xap) assign(:page, 1) assign(:per_page, 10) + assign(:number_of_visible_requests, 4) end it "should be successful" do @@ -48,7 +49,7 @@ describe "public_body/show" do end it "should cope with no results" do - @pb.stub!(:info_requests).and_return([]) + assign(:number_of_visible_requests, 0) render response.should have_selector('p', :content => "Nobody has made any Freedom of Information requests") end diff --git a/spec/views/reports/new.erb_spec.rb b/spec/views/reports/new.erb_spec.rb index 66b738261..d599100b9 100644 --- a/spec/views/reports/new.erb_spec.rb +++ b/spec/views/reports/new.erb_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.join('..', '..', '..', 'spec_helper'), __FILE__) describe 'reports/new.html.erb' do diff --git a/spec/views/request/_after_actions.html.erb_spec.rb b/spec/views/request/_after_actions.html.erb_spec.rb index 833323d68..7a58731ce 100644 --- a/spec/views/request/_after_actions.html.erb_spec.rb +++ b/spec/views/request/_after_actions.html.erb_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.join('..', '..', '..', 'spec_helper'), __FILE__) describe 'when displaying actions that can be taken with regard to a request' do diff --git a/spec/views/request/_describe_state.html.erb_spec.rb b/spec/views/request/_describe_state.html.erb_spec.rb index 88dea53c5..1026ad2f3 100644 --- a/spec/views/request/_describe_state.html.erb_spec.rb +++ b/spec/views/request/_describe_state.html.erb_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.join('..', '..', '..', 'spec_helper'), __FILE__) describe 'when showing the form for describing the state of a request' do diff --git a/spec/views/request/show.html.erb_spec.rb b/spec/views/request/show.html.erb_spec.rb index 6e63b9b43..71057f028 100644 --- a/spec/views/request/show.html.erb_spec.rb +++ b/spec/views/request/show.html.erb_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.join('..', '..', '..', 'spec_helper'), __FILE__) describe 'request/show' do diff --git a/spec/views/request_game/play.html.erb_spec.rb b/spec/views/request_game/play.html.erb_spec.rb index b5cf57c23..37a84b211 100644 --- a/spec/views/request_game/play.html.erb_spec.rb +++ b/spec/views/request_game/play.html.erb_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.join('..', '..', '..', 'spec_helper'), __FILE__) describe 'request_game/play' do |