aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobin Houston <robin.houston@gmail.com>2012-01-23 21:53:10 +0000
committerRobin Houston <robin.houston@gmail.com>2012-01-23 21:53:10 +0000
commit0e546a79b205124d7b95b89e4a2e9cc520a4fc10 (patch)
tree791ae964c0dd4aba79cc9a3a6537db49c594cedf
parent2c97a42455edb338a4ffeb529c9dd08bdf2864e0 (diff)
parent000a4b3bc2858124301eb36553b018266cfe2cae (diff)
Merge branch 'release/0.5' into develop
-rw-r--r--app/controllers/admin_general_controller.rb4
-rw-r--r--app/controllers/application_controller.rb40
-rw-r--r--app/controllers/general_controller.rb12
-rw-r--r--app/controllers/request_controller.rb15
-rw-r--r--app/models/info_request_event.rb22
-rw-r--r--app/models/raw_email.rb2
-rw-r--r--app/models/track_thing.rb15
-rw-r--r--app/views/admin_general/debug.rhtml4
-rw-r--r--app/views/layouts/default.rhtml20
-rw-r--r--app/views/public_body/_search_ahead.rhtml6
-rw-r--r--app/views/request/_search_ahead.rhtml2
-rw-r--r--app/views/request/list.rhtml4
-rw-r--r--app/views/request/select_authority.rhtml1
m---------commonlib0
-rw-r--r--config/crontab.ugly4
-rw-r--r--doc/THEMES.md2
-rwxr-xr-xscript/spec-all-pairs20
-rw-r--r--spec/controllers/admin_public_body_controller_spec.rb7
-rw-r--r--spec/controllers/admin_request_controller_spec.rb14
-rw-r--r--spec/controllers/application_controller_spec.rb24
-rw-r--r--spec/controllers/general_controller_spec.rb20
-rw-r--r--spec/controllers/public_body_controller_spec.rb9
-rw-r--r--spec/controllers/request_controller_spec.rb30
-rw-r--r--spec/controllers/track_controller_spec.rb7
-rw-r--r--spec/controllers/user_controller_spec.rb24
-rw-r--r--spec/helpers/link_to_helper_spec.rb7
-rw-r--r--spec/models/info_request_event_spec.rb8
-rw-r--r--spec/models/outgoing_mailer_spec.rb8
-rw-r--r--spec/models/track_thing_spec.rb7
-rw-r--r--spec/spec_helper.rb10
-rw-r--r--spec/views/request/list.rhtml_spec.rb2
-rw-r--r--spec/views/request/show.rhtml_spec.rb14
-rw-r--r--vendor/plugins/acts_as_xapian/lib/acts_as_xapian.rb12
33 files changed, 306 insertions, 70 deletions
diff --git a/app/controllers/admin_general_controller.rb b/app/controllers/admin_general_controller.rb
index ae51e0923..0b7e9bec0 100644
--- a/app/controllers/admin_general_controller.rb
+++ b/app/controllers/admin_general_controller.rb
@@ -78,6 +78,10 @@ class AdminGeneralController < AdminController
end
def debug
+ @current_commit = `git log -1 --format="%H"`
+ @current_branch = `git branch | grep "\*" | awk '{print $2}'`
+ repo = `git remote show origin -n | grep Fetch | awk '{print $3}' | sed -re 's/.*:(.*).git/\\1/'`
+ @github_origin = "https://github.com/#{repo.strip}/tree/"
@request_env = request.env
end
end
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 0c8544932..8fc6c3792 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -89,6 +89,7 @@ class ApplicationController < ActionController::Base
def record_memory
record_memory = MySociety::Config.get('DEBUG_RECORD_MEMORY', false)
if record_memory
+ logger.info "Processing request for #{request.url} with Rails process #{Process.pid}"
File.read("/proc/#{Process.pid}/status").match(/VmRSS:\s+(\d+)/)
rss_before_action = $1.to_i
yield
@@ -180,7 +181,10 @@ class ApplicationController < ActionController::Base
path = foi_fragment_cache_part_path(param)
path = "/views" + path
foi_cache_path = File.join(File.dirname(__FILE__), '../../cache')
- return File.join(foi_cache_path, path)
+ max_file_length = 255 - 35 # we subtract 35 because tempfile
+ # adds on a variable number of
+ # characters
+ return File.join(foi_cache_path, path)[0...max_file_length]
end
def foi_fragment_cache_all_for_request(info_request)
# return stub path so admin can expire it
@@ -193,10 +197,12 @@ class ApplicationController < ActionController::Base
return File.exists?(key_path)
end
def foi_fragment_cache_read(key_path)
+ logger.info "Reading from fragment cache #{key_path}"
return File.read(key_path)
end
def foi_fragment_cache_write(key_path, content)
FileUtils.mkdir_p(File.dirname(key_path))
+ logger.info "Writing to fragment cache #{key_path}"
File.atomic_write(key_path) do |f|
f.write(content)
end
@@ -365,7 +371,10 @@ class ApplicationController < ActionController::Base
def get_search_page_from_params
return (params[:page] || "1").to_i
end
+
def perform_search_typeahead(query, model)
+ @page = get_search_page_from_params
+ @per_page = 10
query_words = query.split(/ +(?![-+]+)/)
if query_words.last.nil? || query_words.last.strip.length < 3
xapian_requests = nil
@@ -376,8 +385,8 @@ class ApplicationController < ActionController::Base
collapse = 'request_collapse'
end
options = {
- :offset => 0,
- :limit => 5,
+ :offset => (@page - 1) * @per_page,
+ :limit => @per_page,
:sort_by_prefix => nil,
:sort_by_ascending => true,
:collapse_by_prefix => collapse,
@@ -385,11 +394,24 @@ class ApplicationController < ActionController::Base
ActsAsXapian.readable_init
old_default_op = ActsAsXapian.query_parser.default_op
ActsAsXapian.query_parser.default_op = Xapian::Query::OP_OR
- user_query = ActsAsXapian.query_parser.parse_query(
- query,
- Xapian::QueryParser::FLAG_LOVEHATE | Xapian::QueryParser::FLAG_PARTIAL |
- Xapian::QueryParser::FLAG_SPELLING_CORRECTION)
- xapian_requests = ActsAsXapian::Search.new([model], query, options, user_query)
+ begin
+ user_query = ActsAsXapian.query_parser.parse_query(
+ query.strip + '*',
+ Xapian::QueryParser::FLAG_LOVEHATE | Xapian::QueryParser::FLAG_WILDCARD |
+ Xapian::QueryParser::FLAG_SPELLING_CORRECTION)
+ xapian_requests = ActsAsXapian::Search.new([model], query, options, user_query)
+ rescue RuntimeError => e
+ if e.message =~ /^QueryParserError: Wildcard/
+ # Wildcard expands to too many terms
+ logger.info "Wildcard query '#{query.strip + '*'}' caused: #{e.message}"
+
+ user_query = ActsAsXapian.query_parser.parse_query(
+ query,
+ Xapian::QueryParser::FLAG_LOVEHATE |
+ Xapian::QueryParser::FLAG_SPELLING_CORRECTION)
+ xapian_requests = ActsAsXapian::Search.new([model], query, options, user_query)
+ end
+ end
ActsAsXapian.query_parser.default_op = old_default_op
end
return xapian_requests
@@ -521,7 +543,7 @@ class ApplicationController < ActionController::Base
def quietly_try_to_open(url)
begin
result = open(url).read.strip
- rescue OpenURI::HTTPError, SocketError
+ rescue OpenURI::HTTPError, SocketError, Errno::ETIMEDOUT, Errno::ECONNREFUSED, Errno::EHOSTUNREACH
logger.warn("Unable to open third-party URL #{url}")
result = ""
end
diff --git a/app/controllers/general_controller.rb b/app/controllers/general_controller.rb
index d28f4deec..c715b547d 100644
--- a/app/controllers/general_controller.rb
+++ b/app/controllers/general_controller.rb
@@ -32,12 +32,12 @@ class GeneralController < ApplicationController
if body_short_names.empty?
# This is too slow
@popular_bodies = PublicBody.find(:all,
- :select => "public_bodies.*, (select count(*) from info_requests where info_requests.public_body_id = public_bodies.id) as c",
- :order => "c desc",
- :limit => 32,
- :conditions => conditions,
- :joins => :translations
- )
+ :select => "public_bodies.*, (select count(*) from info_requests where info_requests.public_body_id = public_bodies.id) as c",
+ :order => "c desc",
+ :limit => 32,
+ :conditions => conditions,
+ :joins => :translations
+ )
else
conditions[0] += " and public_bodies.url_name in (" + body_short_names + ")"
@popular_bodies = PublicBody.find(:all,
diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb
index 1c7aeedcc..11812b729 100644
--- a/app/controllers/request_controller.rb
+++ b/app/controllers/request_controller.rb
@@ -13,6 +13,9 @@ require 'open-uri'
class RequestController < ApplicationController
before_filter :check_read_only, :only => [ :new, :show_response, :describe_state, :upload_response ]
protect_from_forgery :only => [ :new, :show_response, :describe_state, :upload_response ] # See ActionController::RequestForgeryProtection for details
+
+ MAX_RESULTS = 500
+ PER_PAGE = 25
@@custom_states_loaded = false
begin
@@ -155,14 +158,21 @@ class RequestController < ApplicationController
if @view == "recent"
return redirect_to request_list_all_path(:action => "list", :view => "all", :page => @page), :status => :moved_permanently
end
+
+ # Later pages are very expensive to load
+ if @page > MAX_RESULTS / PER_PAGE
+ raise ActiveRecord::RecordNotFound.new("Sorry. No pages after #{MAX_RESULTS / PER_PAGE}.")
+ end
+
params[:latest_status] = @view
query = make_query_from_params
@title = _("View and search requests")
sortby = "newest"
- behavior_cache :tag => [@view, @page] do
+ behavior_cache :tag => [@query, @page, I18n.locale] do
xapian_object = perform_search([InfoRequestEvent], query, sortby, 'request_collapse')
@list_results = xapian_object.results.map { |r| r[:model] }
@matches_estimated = xapian_object.matches_estimated
+ @show_no_more_than = (@matches_estimated > MAX_RESULTS) ? MAX_RESULTS : @matches_estimated
end
@title = @title + " (page " + @page.to_s + ")" if (@page > 1)
@@ -682,10 +692,11 @@ class RequestController < ApplicationController
# Internal function
def get_attachment_internal(html_conversion)
@incoming_message = IncomingMessage.find(params[:incoming_message_id])
+ @requested_request = InfoRequest.find(params[:id])
@incoming_message.parse_raw_email!
@info_request = @incoming_message.info_request
if @incoming_message.info_request_id != params[:id].to_i
- raise sprintf("Incoming message %d does not belong to request %d", @incoming_message.info_request_id, params[:id])
+ raise ActiveRecord::RecordNotFound.new(sprintf("Incoming message %d does not belong to request %d", @incoming_message.info_request_id, params[:id]))
end
@part_number = params[:part].to_i
@filename = params[:file_name].join("/")
diff --git a/app/models/info_request_event.rb b/app/models/info_request_event.rb
index e99a0ae2f..99f34cf9e 100644
--- a/app/models/info_request_event.rb
+++ b/app/models/info_request_event.rb
@@ -190,6 +190,26 @@ class InfoRequestEvent < ActiveRecord::Base
return message
end
+ def get_clipped_response_efficiently
+ # XXX this ugly code is an attempt to not always load all the
+ # columns for an incoming message, which can be *very* large
+ # (due to all the cached text). We care particularly in this
+ # case because it's called for every search result on a page
+ # (to show the search snippet). Actually, we should review if we
+ # need all this data to be cached in the database at all, and
+ # then we won't need this horrid workaround.
+ message = self.incoming_message_selective_columns("cached_attachment_text_clipped, cached_main_body_text_folded")
+ clipped_body = message.cached_main_body_text_folded
+ clipped_attachment = message.cached_attachment_text_clipped
+ if clipped_body.nil? || clipped_attachment.nil?
+ # we're going to have to load it anyway
+ text = self.incoming_message.get_text_for_indexing_clipped
+ else
+ text = clipped_body.gsub("FOLDED_QUOTED_SECTION", " ").strip + "\n\n" + clipped_attachment
+ end
+ return text + "\n\n"
+ end
+
# clipped = true - means return shorter text. It is used for snippets fore
# performance reasons. Xapian will take the full text.
def search_text_main(clipped = false)
@@ -200,7 +220,7 @@ class InfoRequestEvent < ActiveRecord::Base
text = text + self.outgoing_message.get_text_for_indexing + "\n\n"
elsif self.event_type == 'response'
if clipped
- text = text + self.incoming_message_selective_columns("cached_attachment_text_clipped").cached_attachment_text_clipped + "\n\n"
+ text = text + self.get_clipped_response_efficiently
else
text = text + self.incoming_message.get_text_for_indexing_full + "\n\n"
end
diff --git a/app/models/raw_email.rb b/app/models/raw_email.rb
index c6f84318b..6e073aa27 100644
--- a/app/models/raw_email.rb
+++ b/app/models/raw_email.rb
@@ -43,7 +43,7 @@ class RawEmail < ActiveRecord::Base
if !File.exists?(self.directory)
FileUtils.mkdir_p self.directory
end
- File.open(self.filepath, "wb") { |file|
+ File.atomic_write(self.filepath) { |file|
file.write d
}
end
diff --git a/app/models/track_thing.rb b/app/models/track_thing.rb
index 6938fade9..58d70ed86 100644
--- a/app/models/track_thing.rb
+++ b/app/models/track_thing.rb
@@ -71,14 +71,13 @@ class TrackThing < ActiveRecord::Base
def track_query_description
# XXX this is very brittle... we should probably ask users
# simply to name their tracks when they make them?
- self.track_query = self.track_query.gsub(/([()]|OR)/, "")
- filters = self.track_query.scan /\b\S+:\S+\b/
- text = self.track_query
+ original_text = parsed_text = self.track_query.gsub(/([()]|OR)/, "")
+ filters = parsed_text.scan /\b\S+:\S+\b/
varieties = Set.new
date = ""
statuses = Set.new
for filter in filters
- text = text.sub(filter, "")
+ parsed_text = parsed_text.sub(filter, "")
if filter =~ /variety:user/
varieties << _("users")
end
@@ -105,7 +104,7 @@ class TrackThing < ActiveRecord::Base
end
end
if filters.empty?
- text = self.track_query
+ parsed_text = original_text
end
descriptions = []
if varieties.include? _("requests")
@@ -116,10 +115,10 @@ class TrackThing < ActiveRecord::Base
varieties << _("anything")
end
descriptions += Array(varieties)
- text = text.strip
+ parsed_text = parsed_text.strip
descriptions = descriptions.join(_(" or "))
- if !text.empty?
- descriptions += _("{{list_of_things}} matching text '{{search_query}}'", :list_of_things => "", :search_query => text)
+ if !parsed_text.empty?
+ descriptions += _("{{list_of_things}} matching text '{{search_query}}'", :list_of_things => "", :search_query => parsed_text)
end
return descriptions
end
diff --git a/app/views/admin_general/debug.rhtml b/app/views/admin_general/debug.rhtml
index b3b06085f..40fe33616 100644
--- a/app/views/admin_general/debug.rhtml
+++ b/app/views/admin_general/debug.rhtml
@@ -7,6 +7,10 @@
<h2>Version numbers</h2>
<p>
+Alaveteli branch: <%= link_to @current_branch, @github_origin + @current_branch %>
+<br>
+Alaveteli commit: <%= link_to @current_commit, @github_origin + @current_commit %>
+<br>
RUBY_VERSION <%=h RUBY_VERSION %>
<br>
Rails::VERSION::STRING <%=h Rails::VERSION::STRING%>
diff --git a/app/views/layouts/default.rhtml b/app/views/layouts/default.rhtml
index ad0560baa..f439b27d2 100644
--- a/app/views/layouts/default.rhtml
+++ b/app/views/layouts/default.rhtml
@@ -10,13 +10,13 @@
</title>
<link rel="shortcut icon" href="/favicon.ico">
- <%= stylesheet_link_tag 'main', :title => "Main", :rel => "stylesheet", :media => "all" %>
- <%= stylesheet_link_tag 'fonts', :rel => "stylesheet", :media => "all" %>
- <%= stylesheet_link_tag 'print', :rel => "stylesheet", :media => "print" %>
- <% if !params[:print_stylesheet].nil? %>
+ <%= stylesheet_link_tag 'main', :title => "Main", :rel => "stylesheet", :media => "all" %>
+ <%= stylesheet_link_tag 'fonts', :rel => "stylesheet", :media => "all" %>
+ <%= stylesheet_link_tag 'print', :rel => "stylesheet", :media => "print" %>
+ <% if !params[:print_stylesheet].nil? %>
<%= stylesheet_link_tag 'print', :rel => "stylesheet", :media => "all" %>
- <% end %>
- <%= javascript_include_tag 'jquery.js', 'jquery-ui.min','jquery.cookie.js', 'general.js' %>
+ <% end %>
+ <%= javascript_include_tag 'jquery.js', 'jquery-ui.min','jquery.cookie.js', 'general.js' %>
<% if @profile_photo_javascript %>
<script type="text/javascript" src="/javascripts/jquery.Jcrop.js"></script>
@@ -24,7 +24,7 @@
<link rel="stylesheet" href="/stylesheets/jquery.Jcrop.css" type="text/css" >
<% end %>
- <%= stylesheet_link_tag 'admin-theme/jquery-ui-1.8.15.custom.css', :rel => 'stylesheet'%>
+ <%= stylesheet_link_tag 'admin-theme/jquery-ui-1.8.15.custom.css', :rel => 'stylesheet'%>
<!--[if LT IE 7]>
<style type="text/css">@import url("/stylesheets/ie6.css");</style>
<![endif]-->
@@ -34,8 +34,8 @@
<!--[if LT IE 8]>
<style type="text/css">@import url("/stylesheets/ie7.css");</style>
<![endif]-->
- <!-- the following method for customising CSS is deprecated; see `doc/THEMES.md` for detail -->
- <%= stylesheet_link_tag 'custom', :title => "Main", :rel => "stylesheet" %>
+ <!-- the following method for customising CSS is deprecated; see `doc/THEMES.md` for detail -->
+ <%= stylesheet_link_tag 'custom', :title => "Main", :rel => "stylesheet" %>
<% if force_registration_on_new_request %>
<%= stylesheet_link_tag 'jquery.fancybox-1.3.4', :rel => "stylesheet" %>
<% end %>
@@ -56,7 +56,7 @@
<meta name="robots" content="noindex, nofollow">
<% end %>
- <%= render :partial => 'general/before_head_end' %>
+ <%= render :partial => 'general/before_head_end' %>
</head>
<body <%= "class='front'" if params[:action] == 'frontpage' %>>
diff --git a/app/views/public_body/_search_ahead.rhtml b/app/views/public_body/_search_ahead.rhtml
index 484d28256..7ade89b8e 100644
--- a/app/views/public_body/_search_ahead.rhtml
+++ b/app/views/public_body/_search_ahead.rhtml
@@ -1,4 +1,4 @@
-<p>
+<div>
<% if !@xapian_requests.nil? %>
<% if @xapian_requests.results.size > 0 %>
<h3><%= _('Top search results:') %></h3>
@@ -13,9 +13,9 @@
<%= render :partial => 'body_listing_single', :locals => { :public_body => result[:model] } %>
<% end %>
</div>
- <%= will_paginate WillPaginate::Collection.new(@page, 10, @xapian_requests.matches_estimated) %>
+ <%= will_paginate WillPaginate::Collection.new(@page, @per_page, @xapian_requests.matches_estimated) %>
<% end %>
-</p>
+</div>
diff --git a/app/views/request/_search_ahead.rhtml b/app/views/request/_search_ahead.rhtml
index d0b19de7d..1e65a5458 100644
--- a/app/views/request/_search_ahead.rhtml
+++ b/app/views/request/_search_ahead.rhtml
@@ -8,7 +8,7 @@
<% end %>
<p>
- <a id="body-site-search-link" target="_blank"><%= _("Or search in their website for this information.") %></a>
+ <a id="body-site-search-link"><%= _("Or search in their website for this information.") %></a>
</p>
<% end %>
</div>
diff --git a/app/views/request/list.rhtml b/app/views/request/list.rhtml
index 63faf3643..42cd41498 100644
--- a/app/views/request/list.rhtml
+++ b/app/views/request/list.rhtml
@@ -14,7 +14,7 @@
<div style="clear:both"></div>
<div class="results_section">
- <% view_cache :ttl => 5.minutes.to_i, :tag => [@view, @page, I18n.locale] do %>
+ <% view_cache :ttl => 5.minutes.to_i, :tag => [@query, @page, I18n.locale] do %>
<% if @list_results.empty? %>
<p> <%= _('No requests of this sort yet.')%></p>
<% else %>
@@ -30,6 +30,6 @@
</div>
<% end %>
- <%= will_paginate WillPaginate::Collection.new(@page, @per_page, @matches_estimated) %>
+ <%= will_paginate WillPaginate::Collection.new(@page, @per_page, @show_no_more_than) %>
<% end %>
</div>
diff --git a/app/views/request/select_authority.rhtml b/app/views/request/select_authority.rhtml
index 0e8df872d..521136f8e 100644
--- a/app/views/request/select_authority.rhtml
+++ b/app/views/request/select_authority.rhtml
@@ -57,7 +57,6 @@
<%= render :partial => 'public_body/body_listing_single', :locals => { :public_body => result[:model] } %>
<% end %>
</div>
- <%= will_paginate WillPaginate::Collection.new(@page, 10, @xapian_requests.matches_estimated) %>
<% end %>
diff --git a/commonlib b/commonlib
-Subproject 200057345e3136fe71f0ead118abb4f68544be5
+Subproject c200fcbb73981113fcb2ccd132e1a2b386823c6
diff --git a/config/crontab.ugly b/config/crontab.ugly
index 43b191fd4..a22d5afd7 100644
--- a/config/crontab.ugly
+++ b/config/crontab.ugly
@@ -10,7 +10,7 @@ PATH=/usr/local/bin:/usr/bin:/bin
MAILTO=cron-!!(*= $site *)!!@mysociety.org
# Every 5 minutes
-*/5 * * * * !!(*= $user *)!! run-with-lockfile -n /data/vhost/!!(*= $vhost *)!!/update-xapian-index.lock "/data/vhost/!!(*= $vhost *)!!/!!(*= $vcspath *)!!/script/update-xapian-index verbose=true" >> /data/vhost/!!(*= $vhost *)!!/logs/update-xapian-index.log || echo "stalled?"
+*/5 * * * * !!(*= $user *)!! run-with-lockfile -n /data/vhost/!!(*= $vhost *)!!/change-xapian-database.lock "/data/vhost/!!(*= $vhost *)!!/!!(*= $vcspath *)!!/script/update-xapian-index verbose=true" >> /data/vhost/!!(*= $vhost *)!!/logs/update-xapian-index.log || echo "stalled?"
# Every 10 minutes
5,15,25,35,45,55 * * * * !!(*= $user *)!! /etc/init.d/foi-alert-tracks check
@@ -28,7 +28,7 @@ MAILTO=cron-!!(*= $site *)!!@mysociety.org
2 4 * * * !!(*= $user *)!! run-with-lockfile -n /data/vhost/!!(*= $vhost *)!!/check-recent-requests-sent.lock /data/vhost/!!(*= $vhost *)!!/!!(*= $vcspath *)!!/script/check-recent-requests-sent || echo "stalled?"
45 3 * * * !!(*= $user *)!! run-with-lockfile -n /data/vhost/!!(*= $vhost *)!!/stop-new-responses-on-old-requests.lock /data/vhost/!!(*= $vhost *)!!/!!(*= $vcspath *)!!/script/stop-new-responses-on-old-requests || echo "stalled?"
# Only root can restart apache
-31 1 * * * root run-with-lockfile -n /data/vhost/!!(*= $vhost *)!!/compact-xapian-database.lock "/data/vhost/!!(*= $vhost *)!!/!!(*= $vcspath *)!!/script/compact-xapian-database production" || echo "stalled?"
+31 1 * * * root run-with-lockfile -n /data/vhost/!!(*= $vhost *)!!/change-xapian-database.lock "/data/vhost/!!(*= $vhost *)!!/!!(*= $vcspath *)!!/script/compact-xapian-database production" || echo "stalled?"
# Once a day on all servers
diff --git a/doc/THEMES.md b/doc/THEMES.md
index c2381b61f..a7dd2d31f 100644
--- a/doc/THEMES.md
+++ b/doc/THEMES.md
@@ -53,7 +53,7 @@ place of the core "about us" file.
Rails expects all its stylesheets to live at `<railshome>/public`,
which presents a problem for plugins. Here's how we solve it: the
stylesheet and associated resources for your theme live (by
-convention) in at `alavatelitheme/public/`. This is symlinked from
+convention) in at `alavetelitheme/public/`. This is symlinked from
the main Rails app -- see `alavetelitheme/install.rb` to see how this
happens.
diff --git a/script/spec-all-pairs b/script/spec-all-pairs
new file mode 100755
index 000000000..0d83f5837
--- /dev/null
+++ b/script/spec-all-pairs
@@ -0,0 +1,20 @@
+#!/bin/bash
+
+# Try all ordered pairs of spec files,
+# to winkle out order-dependent failures.
+
+specs=spec/*/*.rb
+
+for spec1 in $specs
+do
+ seen=false
+ for spec2 in $specs
+ do
+ rake db:test:purge > /dev/null
+ rake db:test:clone_structure > /dev/null
+ if ! ( script/spec "$spec1" "$spec2" ) > /dev/null 2>&1
+ then
+ echo "FAILED: $spec1 $spec2"
+ fi
+ done
+done
diff --git a/spec/controllers/admin_public_body_controller_spec.rb b/spec/controllers/admin_public_body_controller_spec.rb
index 97636023a..2670f2add 100644
--- a/spec/controllers/admin_public_body_controller_spec.rb
+++ b/spec/controllers/admin_public_body_controller_spec.rb
@@ -198,8 +198,13 @@ describe AdminPublicBodyController, "when creating public bodies with i18n" do
password = MySociety::Config.get('ADMIN_PASSWORD', '')
basic_auth_login @request
- ActionController::Routing::Routes.filters.clear # don't auto-insert locale, complicates assertions
+ @old_filters = ActionController::Routing::Routes.filters
+ ActionController::Routing::Routes.filters = RoutingFilter::Chain.new
end
+ after do
+ ActionController::Routing::Routes.filters = @old_filters
+ end
+
it "creates a new public body in one locale" do
PublicBody.count.should == 2
diff --git a/spec/controllers/admin_request_controller_spec.rb b/spec/controllers/admin_request_controller_spec.rb
index 635d73b9e..6d3c955bb 100644
--- a/spec/controllers/admin_request_controller_spec.rb
+++ b/spec/controllers/admin_request_controller_spec.rb
@@ -5,6 +5,15 @@ describe AdminRequestController, "when administering requests" do
fixtures :users, :public_bodies, :public_body_translations, :public_body_versions, :info_requests, :raw_emails, :incoming_messages, :outgoing_messages, :comments, :info_request_events, :track_things
before { basic_auth_login @request }
+ before(:each) do
+ load_raw_emails_data(raw_emails)
+ @old_filters = ActionController::Routing::Routes.filters
+ ActionController::Routing::Routes.filters = RoutingFilter::Chain.new
+ end
+ after do
+ ActionController::Routing::Routes.filters = @old_filters
+ end
+
it "shows the index/list page" do
get :index
end
@@ -45,6 +54,11 @@ describe AdminRequestController, "when administering the holding pen" do
before(:each) do
basic_auth_login @request
load_raw_emails_data(raw_emails)
+ @old_filters = ActionController::Routing::Routes.filters
+ ActionController::Routing::Routes.filters = RoutingFilter::Chain.new
+ end
+ after do
+ ActionController::Routing::Routes.filters = @old_filters
end
it "shows a rejection reason for an incoming message from an invalid address" do
diff --git a/spec/controllers/application_controller_spec.rb b/spec/controllers/application_controller_spec.rb
index 1d6802940..f16cee312 100644
--- a/spec/controllers/application_controller_spec.rb
+++ b/spec/controllers/application_controller_spec.rb
@@ -2,6 +2,19 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
require 'fakeweb'
describe ApplicationController, "when accessing third party services" do
+ before (:each) do
+ FakeWeb.clean_registry
+ end
+ after (:each) do
+ FakeWeb.clean_registry
+ end
+ it "should succeed if the service responds OK" do
+ config = MySociety::Config.load_default()
+ config['GAZE_URL'] = 'http://denmark.com'
+ FakeWeb.register_uri(:get, %r|denmark.com|, :body => "DK")
+ country = self.controller.send :country_from_ip
+ country.should == "DK"
+ end
it "should fail silently if the country_from_ip domain doesn't exist" do
config = MySociety::Config.load_default()
config['GAZE_URL'] = 'http://12123sdf14qsd.com'
@@ -15,7 +28,7 @@ describe ApplicationController, "when accessing third party services" do
country.should == config['ISO_COUNTRY_CODE']
end
it "should fail silently if the country_from_ip service returns an error" do
- FakeWeb.register_uri(:get, %r|.*|, :body => "Error", :status => ["500", "Error"])
+ FakeWeb.register_uri(:get, %r|500.com|, :body => "Error", :status => ["500", "Error"])
config = MySociety::Config.load_default()
config['GAZE_URL'] = 'http://500.com'
country = self.controller.send :country_from_ip
@@ -23,3 +36,12 @@ describe ApplicationController, "when accessing third party services" do
end
end
+describe ApplicationController, "when caching fragments" do
+ it "should not fail with long filenames" do
+ long_name = "blahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblah.txt"
+ path = self.controller.send(:foi_fragment_cache_path, long_name)
+ self.controller.send(:foi_fragment_cache_write, path, "whassap")
+ end
+
+end
+
diff --git a/spec/controllers/general_controller_spec.rb b/spec/controllers/general_controller_spec.rb
index e1539fa68..bcd577484 100644
--- a/spec/controllers/general_controller_spec.rb
+++ b/spec/controllers/general_controller_spec.rb
@@ -2,6 +2,13 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
require 'fakeweb'
describe GeneralController, "when trying to show the blog" do
+ before (:each) do
+ FakeWeb.clean_registry
+ end
+ after (:each) do
+ FakeWeb.clean_registry
+ end
+
it "should fail silently if the blog is returning an error" do
FakeWeb.register_uri(:get, %r|.*|, :body => "Error", :status => ["500", "Error"])
get :blog
@@ -84,23 +91,20 @@ describe GeneralController, "when searching" do
describe "when using different locale settings" do
home_link_regex = /href=".*\/en"/
it "should generate URLs with a locale prepended when there's more than one locale set" do
- ActionController::Routing::Routes.add_filters('conditionallyprependlocale')
get :frontpage
response.should have_text(home_link_regex)
end
it "should generate URLs without a locale prepended when there's only one locale set" do
- ActionController::Routing::Routes.add_filters('conditionallyprependlocale')
- old_available_locales = FastGettext.default_available_locales
- available_locales = ['en']
- FastGettext.default_available_locales = available_locales
- I18n.available_locales = available_locales
+ old_fgt_available_locales = FastGettext.default_available_locales
+ old_i18n_available_locales = I18n.available_locales
+ FastGettext.default_available_locales = I18n.available_locales = ['en']
get :frontpage
response.should_not have_text(home_link_regex)
- FastGettext.default_available_locales = old_available_locales
- I18n.available_locales = old_available_locales
+ FastGettext.default_available_locales = old_fgt_available_locales
+ I18n.available_locales = old_i18n_available_locales
end
end
diff --git a/spec/controllers/public_body_controller_spec.rb b/spec/controllers/public_body_controller_spec.rb
index a563b92ad..131412a90 100644
--- a/spec/controllers/public_body_controller_spec.rb
+++ b/spec/controllers/public_body_controller_spec.rb
@@ -50,9 +50,13 @@ describe PublicBodyController, "when showing a body" do
end
it "should redirect use to the relevant locale even when url_name is for a different locale" do
- ActionController::Routing::Routes.filters.clear
+ old_filters = ActionController::Routing::Routes.filters
+ ActionController::Routing::Routes.filters = RoutingFilter::Chain.new
+
get :show, {:url_name => "edfh", :view => 'all'}
response.should redirect_to "http://test.host/body/dfh"
+
+ ActionController::Routing::Routes.filters = old_filters
end
it "should redirect to newest name if you use historic name of public body in URL" do
@@ -181,6 +185,8 @@ end
describe PublicBodyController, "when doing type ahead searches" do
fixtures :public_bodies, :public_body_translations, :public_body_versions, :users, :info_requests, :raw_emails, :incoming_messages, :outgoing_messages, :comments, :info_request_events, :track_things
+ integrate_views
+
it "should return nothing for the empty query string" do
get :search_typeahead, :query => ""
response.should render_template('public_body/_search_ahead')
@@ -190,6 +196,7 @@ describe PublicBodyController, "when doing type ahead searches" do
it "should return a body matching the given keyword, but not users with a matching description" do
get :search_typeahead, :query => "Geraldine"
response.should render_template('public_body/_search_ahead')
+ response.body.should include('search_ahead')
assigns[:xapian_requests].results.size.should == 1
assigns[:xapian_requests].results[0][:model].name.should == public_bodies(:geraldine_public_body).name
end
diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb
index 86665a793..6c6ccc76a 100644
--- a/spec/controllers/request_controller_spec.rb
+++ b/spec/controllers/request_controller_spec.rb
@@ -53,14 +53,24 @@ describe RequestController, "when listing recent requests" do
it "should assign the first page of results" do
xap_results = mock_model(ActsAsXapian::Search,
:results => (1..25).to_a.map { |m| { :model => m } },
- :matches_estimated => 103)
+ :matches_estimated => 1000000)
InfoRequest.should_receive(:full_search).
with([InfoRequestEvent]," (variety:sent OR variety:followup_sent OR variety:response OR variety:comment)", "created_at", anything, anything, anything, anything).
and_return(xap_results)
get :list, :view => 'all'
assigns[:list_results].size.should == 25
+ assigns[:show_no_more_than].should == RequestController::MAX_RESULTS
end
+ it "should return 404 for pages we don't want to serve up" do
+ xap_results = mock_model(ActsAsXapian::Search,
+ :results => (1..25).to_a.map { |m| { :model => m } },
+ :matches_estimated => 1000000)
+ lambda {
+ get :list, :view => 'all', :page => 100
+ }.should raise_error(ActiveRecord::RecordNotFound)
+ end
+
end
describe RequestController, "when showing one request" do
@@ -171,6 +181,16 @@ describe RequestController, "when showing one request" do
response.should have_text(/Second hello/)
end
+ it "should return 404 for ugly URLs contain a request id that isn't an integer " do
+ ir = info_requests(:fancy_dog_request)
+ receive_incoming_mail('incoming-request-two-same-name.email', ir.incoming_email)
+ ir.reload
+ ugly_id = "55195"
+ lambda {
+ get :get_attachment_as_html, :incoming_message_id => ir.incoming_messages[1].id, :id => ugly_id, :part => 2, :file_name => ['hello.txt.html'], :skip_cache => 1
+ }.should raise_error(ActiveRecord::RecordNotFound)
+ end
+
it "should generate valid HTML verson of PDF attachments " do
ir = info_requests(:fancy_dog_request)
receive_incoming_mail('incoming-request-pdf-attachment.email', ir.incoming_email)
@@ -937,7 +957,11 @@ describe RequestController, "when classifying an information request" do
session[:user_id] = @request_owner.id
@dog_request = info_requests(:fancy_dog_request)
InfoRequest.stub!(:find).and_return(@dog_request)
- ActionController::Routing::Routes.filters.clear
+ @old_filters = ActionController::Routing::Routes.filters
+ ActionController::Routing::Routes.filters = RoutingFilter::Chain.new
+ end
+ after do
+ ActionController::Routing::Routes.filters = @old_filters
end
def request_url
@@ -1493,6 +1517,8 @@ end
describe RequestController, "when doing type ahead searches" do
fixtures :public_bodies, :public_body_translations, :public_body_versions, :users, :info_requests, :raw_emails, :incoming_messages, :outgoing_messages, :comments, :info_request_events, :track_things
+ integrate_views
+
it "should return nothing for the empty query string" do
get :search_typeahead, :q => ""
response.should render_template('request/_search_ahead.rhtml')
diff --git a/spec/controllers/track_controller_spec.rb b/spec/controllers/track_controller_spec.rb
index 90d13495f..ad4d651cb 100644
--- a/spec/controllers/track_controller_spec.rb
+++ b/spec/controllers/track_controller_spec.rb
@@ -46,7 +46,9 @@ describe TrackController, "when sending alerts for a track" do
it "should send alerts" do
# Don't do clever locale-insertion-unto-URL stuff
- ActionController::Routing::Routes.filters.clear
+ old_filters = ActionController::Routing::Routes.filters
+ ActionController::Routing::Routes.filters = RoutingFilter::Chain.new
+
# set the time the comment event happened at to within the last week
ire = info_request_events(:silly_comment_event)
ire.created_at = Time.now - 3.days
@@ -91,6 +93,9 @@ describe TrackController, "when sending alerts for a track" do
TrackMailer.alert_tracks
deliveries = ActionMailer::Base.deliveries
deliveries.size.should == 0
+
+ # Restore the routing filters
+ ActionController::Routing::Routes.filters = old_filters
end
it "should send localised alerts" do
diff --git a/spec/controllers/user_controller_spec.rb b/spec/controllers/user_controller_spec.rb
index 0cf574aa9..d8e92fbd0 100644
--- a/spec/controllers/user_controller_spec.rb
+++ b/spec/controllers/user_controller_spec.rb
@@ -96,7 +96,9 @@ describe UserController, "when signing in" do
end
it "should log in when you give right email/password, and redirect to where you were" do
- ActionController::Routing::Routes.filters.clear
+ old_filters = ActionController::Routing::Routes.filters
+ ActionController::Routing::Routes.filters = RoutingFilter::Chain.new
+
get :signin, :r => "/list"
response.should render_template('sign')
post_redirect = get_last_postredirect
@@ -107,10 +109,14 @@ describe UserController, "when signing in" do
# response doesn't contain /en/ but redirect_to does...
response.should redirect_to(:controller => 'request', :action => 'list', :post_redirect => 1)
response.should_not send_email
+
+ ActionController::Routing::Routes.filters = old_filters
end
it "should not log you in if you use an invalid PostRedirect token, and shouldn't give 500 error either" do
- ActionController::Routing::Routes.filters.clear
+ old_filters = ActionController::Routing::Routes.filters
+ ActionController::Routing::Routes.filters = RoutingFilter::Chain.new
+
post_redirect = "something invalid"
lambda {
post :signin, { :user_signin => { :email => 'bob@localhost', :password => 'jonespassword' },
@@ -121,6 +127,8 @@ describe UserController, "when signing in" do
:token => post_redirect }
response.should render_template('sign')
assigns[:post_redirect].should == nil
+
+ ActionController::Routing::Routes.filters = old_filters
end
# No idea how to test this in the test framework :(
@@ -144,7 +152,9 @@ describe UserController, "when signing in" do
end
it "should confirm your email, log you in and redirect you to where you were after you click an email link" do
- ActionController::Routing::Routes.filters.clear
+ old_filters = ActionController::Routing::Routes.filters
+ ActionController::Routing::Routes.filters = RoutingFilter::Chain.new
+
get :signin, :r => "/list"
post_redirect = get_last_postredirect
@@ -170,6 +180,8 @@ describe UserController, "when signing in" do
get :confirm, :email_token => post_redirect.email_token
session[:user_id].should == users(:unconfirmed_user).id
response.should redirect_to(:controller => 'request', :action => 'list', :post_redirect => 1)
+
+ ActionController::Routing::Routes.filters = old_filters
end
end
@@ -244,11 +256,15 @@ describe UserController, "when signing out" do
end
it "should log you out and redirect you to where you were" do
- ActionController::Routing::Routes.filters.clear
+ old_filters = ActionController::Routing::Routes.filters
+ ActionController::Routing::Routes.filters = RoutingFilter::Chain.new
+
session[:user_id] = users(:bob_smith_user).id
get :signout, :r => '/list'
session[:user_id].should be_nil
response.should redirect_to(:controller => 'request', :action => 'list')
+
+ ActionController::Routing::Routes.filters = old_filters
end
end
diff --git a/spec/helpers/link_to_helper_spec.rb b/spec/helpers/link_to_helper_spec.rb
index f85d2e70d..3fa91a8f8 100644
--- a/spec/helpers/link_to_helper_spec.rb
+++ b/spec/helpers/link_to_helper_spec.rb
@@ -7,9 +7,14 @@ describe LinkToHelper do
describe 'when creating a url for a request' do
before do
- ActionController::Routing::Routes.filters.clear
@mock_request = mock_model(InfoRequest, :url_title => 'test_title')
+ @old_filters = ActionController::Routing::Routes.filters
+ ActionController::Routing::Routes.filters = RoutingFilter::Chain.new
end
+ after do
+ ActionController::Routing::Routes.filters = @old_filters
+ end
+
it 'should return a path like /request/test_title' do
request_url(@mock_request).should == '/request/test_title'
diff --git a/spec/models/info_request_event_spec.rb b/spec/models/info_request_event_spec.rb
index 5423b8da8..a75f4b232 100644
--- a/spec/models/info_request_event_spec.rb
+++ b/spec/models/info_request_event_spec.rb
@@ -73,6 +73,14 @@ describe InfoRequestEvent do
event.search_text_main.strip.should == "No way! I'm not going to tell you that in a month of Thursdays.\n\nThe Geraldine Quango"
end
+ it 'should get clipped text for incoming messages, and cache it too' do
+ event = info_request_events(:useless_incoming_message_event)
+
+ event.incoming_message_selective_columns("cached_main_body_text_folded").cached_main_body_text_folded = nil
+ event.search_text_main(true).strip.should == "No way! I'm not going to tell you that in a month of Thursdays.\n\nThe Geraldine Quango"
+ event.incoming_message_selective_columns("cached_main_body_text_folded").cached_main_body_text_folded.should_not == nil
+ end
+
end
diff --git a/spec/models/outgoing_mailer_spec.rb b/spec/models/outgoing_mailer_spec.rb
index 75c8053b4..c5fde93fc 100644
--- a/spec/models/outgoing_mailer_spec.rb
+++ b/spec/models/outgoing_mailer_spec.rb
@@ -24,6 +24,7 @@ describe OutgoingMailer, " when working out follow up addresses" do
im = ir.incoming_messages[0]
im.raw_email.data = im.raw_email.data.sub("\"FOI Person\" <foiperson@localhost>", "foiperson@localhost")
+ im.parse_raw_email! true
# check the basic entry in the fixture is fine
OutgoingMailer.name_and_email_for_followup(ir, im).should == "foiperson@localhost"
@@ -36,6 +37,7 @@ describe OutgoingMailer, " when working out follow up addresses" do
im = ir.incoming_messages[0]
im.raw_email.data = im.raw_email.data.sub("FOI Person", "FOI [ Person")
+ im.parse_raw_email! true
# check the basic entry in the fixture is fine
OutgoingMailer.name_and_email_for_followup(ir, im).should == "\"FOI [ Person\" <foiperson@localhost>"
@@ -48,6 +50,7 @@ describe OutgoingMailer, " when working out follow up addresses" do
im = ir.incoming_messages[0]
im.raw_email.data = im.raw_email.data.sub("FOI Person", "FOI \\\" Person")
+ im.parse_raw_email! true
# check the basic entry in the fixture is fine
OutgoingMailer.name_and_email_for_followup(ir, im).should == "\"FOI \\\" Person\" <foiperson@localhost>"
@@ -60,6 +63,7 @@ describe OutgoingMailer, " when working out follow up addresses" do
im = ir.incoming_messages[0]
im.raw_email.data = im.raw_email.data.sub("FOI Person", "FOI @ Person")
+ im.parse_raw_email! true
# check the basic entry in the fixture is fine
OutgoingMailer.name_and_email_for_followup(ir, im).should == "\"FOI @ Person\" <foiperson@localhost>"
@@ -116,6 +120,8 @@ describe OutgoingMailer, "when working out follow up subjects" do
om.incoming_message_followup = im
im.raw_email.data = im.raw_email.data.sub("Subject: Geraldine FOI Code AZXB421", "Subject: re: Geraldine FOI Code AZXB421")
+ im.parse_raw_email! true
+
OutgoingMailer.subject_for_followup(ir, om).should == "re: Geraldine FOI Code AZXB421"
end
@@ -127,6 +133,8 @@ describe OutgoingMailer, "when working out follow up subjects" do
im.raw_email.data = im.raw_email.data.sub("foiperson@localhost", "postmaster@localhost")
im.raw_email.data = im.raw_email.data.sub("Subject: Geraldine FOI Code AZXB421", "Subject: Delivery Failed")
+ im.parse_raw_email! true
+
OutgoingMailer.subject_for_followup(ir, om).should == "Re: Freedom of Information request - Why do you have & such a fancy dog?"
end
end
diff --git a/spec/models/track_thing_spec.rb b/spec/models/track_thing_spec.rb
index 4922a96c7..7891bd229 100644
--- a/spec/models/track_thing_spec.rb
+++ b/spec/models/track_thing_spec.rb
@@ -28,6 +28,13 @@ describe TrackThing, "when tracking changes" do
found_track.should == @track_thing
end
+ it "can display the description of a deleted track_thing" do
+ track_thing = TrackThing.create_track_for_search_query('fancy dog')
+ description = track_thing.track_query_description
+ track_thing.destroy
+ track_thing.track_query_description.should == description
+ end
+
it "will make some sane descriptions of search-based tracks" do
tests = [['bob variety:user', "users matching text 'bob'"],
['bob (variety:sent OR variety:followup_sent OR variety:response OR variety:comment) (latest_status:successful OR latest_status:partially_successful OR latest_status:rejected OR latest_status:not_held)', "requests which are successful or unsuccessful or comments matching text 'bob'"],
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index e58c3890a..33a28449e 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -143,7 +143,10 @@ if $tempfilecount.nil?
module TestProcess
# Hook into the process function, so can automatically get HTML after each request
alias :original_process :process
-
+ def is_fragment
+ # XXX there must be a better way of doing this!
+ return @request.query_parameters["action"] == "search_typeahead"
+ end
def process(action, parameters = nil, session = nil, flash = nil, http_method = 'GET')
self.original_process(action, parameters, session, flash, http_method)
# don't validate auto-generated HTML
@@ -152,7 +155,12 @@ if $tempfilecount.nil?
return unless @response.template.controller.instance_eval { integrate_views? }
# And then if HTML, not a redirect (302, 301)
if @response.content_type == "text/html" && ! [301,302,401].include?(@response.response_code)
+ if !is_fragment
validate_html(@response.body)
+ else
+ # it's a partial
+ validate_as_body(@response.body)
+ end
end
end
end
diff --git a/spec/views/request/list.rhtml_spec.rb b/spec/views/request/list.rhtml_spec.rb
index 1f86ec641..c7067294f 100644
--- a/spec/views/request/list.rhtml_spec.rb
+++ b/spec/views/request/list.rhtml_spec.rb
@@ -33,6 +33,7 @@ describe "when listing recent requests" do
it "should be successful" do
assigns[:list_results] = [ make_mock_event, make_mock_event ]
assigns[:matches_estimated] = 2
+ assigns[:show_no_more_than] = 100
render "request/list"
response.should have_tag("div.request_listing")
response.should_not have_tag("p", /No requests of this sort yet/m)
@@ -41,6 +42,7 @@ describe "when listing recent requests" do
it "should cope with no results" do
assigns[:list_results] = [ ]
assigns[:matches_estimated] = 0
+ assigns[:show_no_more_than] = 0
render "request/list"
response.should have_tag("p", /No requests of this sort yet/m)
response.should_not have_tag("div.request_listing")
diff --git a/spec/views/request/show.rhtml_spec.rb b/spec/views/request/show.rhtml_spec.rb
index adb244f47..ef7d1a47c 100644
--- a/spec/views/request/show.rhtml_spec.rb
+++ b/spec/views/request/show.rhtml_spec.rb
@@ -84,10 +84,15 @@ describe 'when viewing an information request' do
describe 'when there is a last response' do
before do
- ActionController::Routing::Routes.filters.clear
@mock_response = mock_model(IncomingMessage)
@mock_request.stub!(:get_last_response).and_return(@mock_response)
+ @old_filters = ActionController::Routing::Routes.filters
+ ActionController::Routing::Routes.filters = RoutingFilter::Chain.new
end
+ after do
+ ActionController::Routing::Routes.filters = @old_filters
+ end
+
it 'should show a link to follow up the last response with clarification' do
request_page
@@ -100,9 +105,14 @@ describe 'when viewing an information request' do
describe 'when there is no last response' do
before do
- ActionController::Routing::Routes.filters.clear
@mock_request.stub!(:get_last_response).and_return(nil)
+ @old_filters = ActionController::Routing::Routes.filters
+ ActionController::Routing::Routes.filters = RoutingFilter::Chain.new
end
+ after do
+ ActionController::Routing::Routes.filters = @old_filters
+ end
+
it 'should show a link to follow up the request without reference to a specific response' do
request_page
diff --git a/vendor/plugins/acts_as_xapian/lib/acts_as_xapian.rb b/vendor/plugins/acts_as_xapian/lib/acts_as_xapian.rb
index 38bfb7c98..ebb3b1cbd 100644
--- a/vendor/plugins/acts_as_xapian/lib/acts_as_xapian.rb
+++ b/vendor/plugins/acts_as_xapian/lib/acts_as_xapian.rb
@@ -143,6 +143,16 @@ module ActsAsXapian
@@query_parser.stemming_strategy = Xapian::QueryParser::STEM_SOME
@@query_parser.database = @@db
@@query_parser.default_op = Xapian::Query::OP_AND
+ begin
+ @@query_parser.set_max_wildcard_expansion(1000)
+ rescue NoMethodError
+ # The set_max_wildcard_expansion method was introduced in Xapian 1.2.7,
+ # so may legitimately not be available.
+ #
+ # Large installations of Alaveteli should consider
+ # upgrading, because uncontrolled wildcard expansion
+ # can crash the whole server: see http://trac.xapian.org/ticket/350
+ end
@@stopper = Xapian::SimpleStopper.new
@@stopper.add("and")
@@ -443,7 +453,7 @@ module ActsAsXapian
user_query = ActsAsXapian.query_parser.parse_query(
self.query_string,
Xapian::QueryParser::FLAG_BOOLEAN | Xapian::QueryParser::FLAG_PHRASE |
- Xapian::QueryParser::FLAG_LOVEHATE | Xapian::QueryParser::FLAG_WILDCARD |
+ Xapian::QueryParser::FLAG_LOVEHATE |
Xapian::QueryParser::FLAG_SPELLING_CORRECTION)
end
self.query = Xapian::Query.new(Xapian::Query::OP_AND, model_query, user_query)