diff options
470 files changed, 1396 insertions, 935 deletions
diff --git a/.codeclimate.yml b/.codeclimate.yml new file mode 100644 index 000000000..2fb04b670 --- /dev/null +++ b/.codeclimate.yml @@ -0,0 +1,6 @@ +languages: + Ruby: true + JavaScript: true + PHP: true +exclude_paths: +- "lib/strip_attributes/test/*" 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..eed328b34 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. # @@ -20,7 +21,7 @@ class AdminCommentController < AdminController 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 13edec37d..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,28 +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.where(:request_email => "").order(:updated_at).select { |pb| !pb.defunct? } + @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..0565bc775 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]) @@ -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..237cfcf4b 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 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 db20e8dcc..59eb5e6b8 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. # @@ -56,7 +57,7 @@ class AdminRequestController < AdminController 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 }) @@ -175,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..56c4c81e9 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. # 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..bdb309dd8 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 @@ -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 @@ -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 8b8055b55..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. diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb index d66b4aa8e..47041a969 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. # @@ -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 index 0cc1008a1..333a38e86 100644 --- a/app/controllers/widgets_controller.rb +++ b/app/controllers/widgets_controller.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # app/controllers/widget_controller.rb: # Handle widgets, if enabled # 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 f9e4d42df..b2f1f9de5 100644 --- a/app/helpers/health_checks_helper.rb +++ b/app/helpers/health_checks_helper.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- module HealthChecksHelper def check_status(check) diff --git a/app/helpers/highlight_helper.rb b/app/helpers/highlight_helper.rb index a98f6f320..c72d5a64b 100644 --- a/app/helpers/highlight_helper.rb +++ b/app/helpers/highlight_helper.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- module HighlightHelper include ERB::Util 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 index e604954fe..70353ea7c 100644 --- a/app/helpers/widget_helper.rb +++ b/app/helpers/widget_helper.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- module WidgetHelper def status_description(info_request, status) case status @@ -43,4 +44,4 @@ module WidgetHelper end end end -end
\ No newline at end of file +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 bf04b1ab9..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. # @@ -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. @@ -234,8 +200,9 @@ class RequestMailer < ApplicationMailer def requests_matching_email(email) # We deliberately don't use Envelope-to here, so ones that are BCC # drop into the holding pen for checking. + addresses = ((email.to || []) + (email.cc || [])).compact reply_info_requests = [] # TODO: should be set? - for address in (email.to || []) + (email.cc || []) + addresses.each do |address| reply_info_request = InfoRequest.find_by_incoming_email(address) reply_info_requests.push(reply_info_request) if reply_info_request end @@ -267,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' @@ -371,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 @@ -399,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 @@ -466,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 658ee969a..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 @@ -654,7 +655,7 @@ class IncomingMessage < ActiveRecord::Base # Save clipped version for snippets if self.cached_attachment_text_clipped.nil? - self.cached_attachment_text_clipped = text[0..MAX_ATTACHMENT_TEXT_CLIPPED] + self.cached_attachment_text_clipped = text.mb_chars[0..MAX_ATTACHMENT_TEXT_CLIPPED] self.save! end @@ -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 0ca3a1279..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") @@ -194,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 @@ -346,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 @@ -356,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| @@ -368,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 @@ -395,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 @@ -428,6 +420,7 @@ public # A new incoming email to this request def receive(email, raw_email_data, override_stop_new_responses = false, rejected_reason = "") + # Is this request allowing responses? if !override_stop_new_responses allow = nil reason = nil @@ -458,9 +451,15 @@ public raise "Unknown allow_new_responses_from '" + self.allow_new_responses_from + "'" end + # If its not allowing responses, handle the message if !allow if self.handle_rejected_responses == 'bounce' - RequestMailer.stopped_responses(self, email, raw_email_data).deliver if !is_external? + if MailHandler.get_from_address(email).nil? + # do nothing – can't bounce the mail as there's no + # address to send it to + else + RequestMailer.stopped_responses(self, email, raw_email_data).deliver if !is_external? + end elsif self.handle_rejected_responses == 'holding_pen' InfoRequest.holding_pen_request.receive(email, raw_email_data, false, reason) elsif self.handle_rejected_responses == 'blackhole' @@ -528,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( @@ -543,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' }) @@ -558,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 @@ -659,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 @@ -675,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 @@ -692,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 @@ -777,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 @@ -804,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. @@ -867,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."), @@ -925,11 +932,11 @@ public # Called by incoming_email - and used to be called to generate separate # envelope from address until we abandoned it. def magic_email(prefix_part) - raise "id required to make magic" if not self.id + raise "id required to create a magic email" if not self.id 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) @@ -943,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', @@ -957,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'] @@ -977,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' @@ -998,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] @@ -1029,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 @@ -1055,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 @@ -1064,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) @@ -1188,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 @@ -1237,7 +1232,7 @@ public :model => self.class.base_class.to_s, :model_id => self.id) end - req.save() + req.save end end @@ -1267,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 @@ -1289,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, @@ -1306,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 @@ -1353,7 +1341,7 @@ 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') @@ -1383,6 +1371,15 @@ public 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 @@ -1391,7 +1388,7 @@ 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 @@ -1412,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 0ee82d30c..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 @@ -325,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 @@ -418,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 59160381c..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 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 dac77d4c5..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) @@ -356,7 +334,7 @@ class PublicBody < ActiveRecord::Base 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'" @@ -409,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) @@ -422,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 @@ -589,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 @@ -647,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 @@ -764,10 +736,6 @@ class PublicBody < ActiveRecord::Base end end - def empty_translation_in_params?(attributes) - attributes.select { |k, v| !v.blank? && k.to_s != 'locale' }.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 3b466cb81..2a52921f0 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 1fb5d9139..d50000aba 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # == Schema Information # # Table name: users @@ -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 index 021c38b30..dda77007f 100644 --- a/app/models/widget_vote.rb +++ b/app/models/widget_vote.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # == Schema Information # # Table name: widget_votes 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/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/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/commonlib b/commonlib -Subproject 2a0271d3a6aaba9c429261b8c94e0e7acb6bd68 +Subproject dcc2e223ae1f76ed7db80b45ea12297e01bf5d4 diff --git a/config/application.rb b/config/application.rb index 46c4eb93b..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' @@ -70,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" 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/deploy.rb b/config/deploy.rb index d02488bfa..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 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 b334a1e19..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 diff --git a/config/environments/production.rb b/config/environments/production.rb index af2ca15b9..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 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/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 53a9456d2..cda163a9b 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 @@ -10,7 +11,7 @@ load "debug_helpers.rb" load "util.rb" # Application version -ALAVETELI_VERSION = '0.21.0.27' +ALAVETELI_VERSION = '0.21.0.32' # Add new inflection rules using the following format # (all these examples are active by default): 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/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/routes.rb b/config/routes.rb index 7319f92fc..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. # 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 index 0a7b4856a..467f937e2 100644 --- a/db/migrate/20140824191444_create_widget_votes.rb +++ b/db/migrate/20140824191444_create_widget_votes.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class CreateWidgetVotes < ActiveRecord::Migration def change create_table :widget_votes do |t| 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/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 0cd6d74d5..565212904 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,7 +157,7 @@ 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 @@ -193,7 +193,7 @@ module ActsAsXapian end end - def ActsAsXapian.init_values(values) + 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 @@ -225,7 +225,7 @@ module ActsAsXapian end end - def ActsAsXapian.init_terms(terms) + 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" @@ -244,7 +244,7 @@ module ActsAsXapian 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? @@ -260,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 @@ -336,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 @@ -559,7 +559,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) @@ -611,7 +611,7 @@ 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. @@ -655,7 +655,7 @@ module ActsAsXapian ActsAsXapian.writable_db.close end - def ActsAsXapian.run_job(job, flush, verbose) + 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 @@ -682,7 +682,7 @@ module ActsAsXapian job.destroy end - def ActsAsXapian._is_xapian_db(path) + def self._is_xapian_db(path) is_db = File.exist?(File.join(path, "iamflint")) || File.exist?(File.join(path, "iamchert")) return is_db end @@ -694,7 +694,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 @@ -755,7 +755,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/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 5d836f66c..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', diff --git a/lib/attachment_to_html/adapter.rb b/lib/attachment_to_html/adapter.rb new file mode 100644 index 000000000..d8b9f41f7 --- /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 b60cc102b..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 @@ -91,7 +92,7 @@ module AlaveteliConfiguration } 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 9b647e2fa..9e3fbc008 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 @@ -128,7 +129,7 @@ module MailHandler envelope_to = mail['envelope-to'] ? [mail['envelope-to'].value.to_s] : [] ((mail.to || []) + (mail.cc || []) + - (envelope_to || [])).uniq + (envelope_to || [])).compact.uniq end def empty_return_path?(mail) 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 1205a1d9c..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' 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/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/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/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/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/switch-theme.rb b/script/switch-theme.rb index 146d1bf0c..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 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 c15ee77f1..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 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 c4f3c847e..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 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 index 6a58c7c5c..95396671b 100644 --- a/spec/controllers/widgets_controller_spec.rb +++ b/spec/controllers/widgets_controller_spec.rb @@ -1,4 +1,4 @@ -# coding: utf-8 +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe WidgetsController do 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 30fb24c37..a2b6496e8 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 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 index 964bbb20d..7ceb4f7e9 100644 --- a/spec/factories/widget_votes.rb +++ b/spec/factories/widget_votes.rb @@ -1,7 +1,8 @@ +# -*- encoding : utf-8 -*- require 'securerandom' FactoryGirl.define do factory :widget_vote do info_request cookie { SecureRandom.hex(10) } end -end
\ No newline at end of file +end 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 7dbfaf06e..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 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 index c8c41b14f..614ed92ad 100644 --- a/spec/helpers/widget_helper_spec.rb +++ b/spec/helpers/widget_helper_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe WidgetHelper do @@ -25,4 +26,4 @@ describe WidgetHelper do end -end
\ No newline at end of file +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 21011b172..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') 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 a91df341f..eea9893a8 100644 --- a/spec/integration/xapian_search_highlighting_spec.rb +++ b/spec/integration/xapian_search_highlighting_spec.rb @@ -1,4 +1,4 @@ -# encoding: utf-8 +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') 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 102d2582e..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') 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 861302400..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 ) 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 895160670..044fbef4f 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 diff --git a/spec/lib/mail_handler/mail_handler_spec.rb b/spec/lib/mail_handler/mail_handler_spec.rb index ea7a99b05..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) @@ -158,6 +158,16 @@ describe 'when asked for all the addresses a mail has been sent to' do mail = MailHandler.mail_from_raw_email(mail_data) MailHandler.get_all_addresses(mail).should == ["request-5555-xxxxxxxx@whatdotheyknow.com"] end + + it 'should not return invalid addresses' do + mail_data = load_file_fixture('autoresponse-header.email') + mail_data.gsub!('To: FOI Person <EMAIL_TO>', + 'To: <request-5555-xxxxxxxx>') + mail = MailHandler.mail_from_raw_email(mail_data) + MailHandler.get_all_addresses(mail).should == [] + end + + end describe 'when asked for auto_submitted' do 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 6b54c25d2..12d83ca62 100644 --- a/spec/mailers/request_mailer_spec.rb +++ b/spec/mailers/request_mailer_spec.rb @@ -1,4 +1,4 @@ -# 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 @@ -40,6 +40,12 @@ describe RequestMailer, " when receiving incoming mail" do deliveries.clear end + it "puts messages with a malformed To: in the holding pen" do + request = FactoryGirl.create(:info_request) + receive_incoming_mail('incoming-request-plain.email', 'asdfg') + expect(InfoRequest.holding_pen_request.incoming_messages).to have(1).item + end + it "should parse attachments from mails sent with apple mail" do ir = info_requests(:fancy_dog_request) ir.incoming_messages.size.should == 1 @@ -180,6 +186,21 @@ describe RequestMailer, " when receiving incoming mail" do deliveries.clear end + it "discards rejected responses with a malformed From: when set to bounce" do + ir = info_requests(:fancy_dog_request) + ir.allow_new_responses_from = 'nobody' + ir.handle_rejected_responses = 'bounce' + ir.save! + ir.incoming_messages.size.should == 1 + + receive_incoming_mail('incoming-request-plain.email', ir.incoming_email, "") + ir.incoming_messages.size.should == 1 + + deliveries = ActionMailer::Base.deliveries + deliveries.size.should == 0 + deliveries.clear + end + it "should send all new responses to holding pen if a request is marked to do so" do # mark request as anti-spam ir = info_requests(:fancy_dog_request) @@ -280,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| 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 f6e524de3..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" @@ -707,3 +707,15 @@ describe IncomingMessage, 'when getting the body of a message for html display' end end + +describe IncomingMessage, 'when getting clipped attachment text' do + + it 'should clip to characters not bytes' do + incoming_message = FactoryGirl.build(:incoming_message) + # This character is 2 bytes so the string should get sliced unless + # we are handling multibyte chars correctly + multibyte_string = "å" * 500002 + incoming_message.stub!(:_get_attachment_text_internal).and_return(multibyte_string) + incoming_message.get_attachment_text_clipped.length.should == 500002 + end +end
\ No newline at end of file diff --git a/spec/models/info_request_batch_spec.rb b/spec/models/info_request_batch_spec.rb index 701422037..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 diff --git a/spec/models/info_request_event_spec.rb b/spec/models/info_request_event_spec.rb index 1299dfb63..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 @@ -111,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 1ead1e0bf..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 @@ -31,7 +31,7 @@ describe InfoRequest do describe :new do it 'sets the default law used' do - expect(InfoRequest.new().law_used).to eq('foi') + expect(InfoRequest.new.law_used).to eq('foi') end it 'sets the default law used if a body is eir-only' do @@ -658,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 @@ -682,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 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 750e47cc3..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 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 cce017424..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 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/raw_email_spec.rb b/spec/models/raw_email_spec.rb index aa82b0bc3..044c89d3f 100644 --- a/spec/models/raw_email_spec.rb +++ b/spec/models/raw_email_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # == Schema Information # # Table name: raw_emails 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 index b9f990eac..1a6d3833c 100644 --- a/spec/models/widget_vote_spec.rb +++ b/spec/models/widget_vote_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # == Schema Information # # Table name: widget_votes diff --git a/spec/models/xapian_spec.rb b/spec/models/xapian_spec.rb index 678e3a2dc..b3f2e2b3c 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 4df1b5649..d9feba6cd 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require 'rubygems' require 'spork' 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 2a4c21d04..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 @@ -29,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 @@ -47,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 |