aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/controllers/application_controller.rb1
-rw-r--r--app/models/public_body.rb12
-rw-r--r--app/views/request/new_bad_contact.html.erb2
-rw-r--r--config/initializers/alaveteli.rb2
-rw-r--r--lib/acts_as_xapian/acts_as_xapian.rb72
-rwxr-xr-xscript/switch-theme.rb2
-rw-r--r--spec/controllers/general_controller_spec.rb1
-rw-r--r--spec/integration/xapian_search_highlighting_spec.rb11
-rw-r--r--spec/models/info_request_spec.rb1
-rw-r--r--spec/models/public_body_spec.rb27
-rw-r--r--spec/views/public_body/show.html.erb_spec.rb1
11 files changed, 82 insertions, 50 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 044f8e10f..e80c6a823 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -132,7 +132,6 @@ class ApplicationController < ActionController::Base
def validate_session_timestamp
if session[:user_id] && session.key?(:ttl) && session[:ttl] < SESSION_TTL.ago
clear_session_credentials
- redirect_to signin_path
end
end
diff --git a/app/models/public_body.rb b/app/models/public_body.rb
index cb412f9dc..5bce8ecc7 100644
--- a/app/models/public_body.rb
+++ b/app/models/public_body.rb
@@ -577,17 +577,11 @@ class PublicBody < ActiveRecord::Base
return self.request_email_domain
end
- # Returns nil if configuration variable not set
- def override_request_email
- e = AlaveteliConfiguration::override_all_public_body_request_emails
- e if e != ""
- end
-
def request_email
- if override_request_email
- override_request_email
- else
+ if AlaveteliConfiguration::override_all_public_body_request_emails.blank? || read_attribute(:request_email).blank?
read_attribute(:request_email)
+ else
+ AlaveteliConfiguration::override_all_public_body_request_emails
end
end
diff --git a/app/views/request/new_bad_contact.html.erb b/app/views/request/new_bad_contact.html.erb
index 56f3f4168..f9881b62b 100644
--- a/app/views/request/new_bad_contact.html.erb
+++ b/app/views/request/new_bad_contact.html.erb
@@ -5,6 +5,6 @@
<p><%= _('Unfortunately, we do not have a working {{info_request_law_used_full}}
address for', :info_request_law_used_full => @info_request.law_used_full) %> <%=h @info_request.public_body.name %>. <%= _('You may be able to find
one on their website, or by phoning them up and asking. If you manage
-to find one, then please <a href="{{help_url}}">send it to us</a>.', :help_url => help_contact_path) %>
+to find one, then please <a href="{{help_url}}">send it to us</a>.', :help_url => new_change_request_path(:body => @info_request.public_body.url_name)) %>
</p>
diff --git a/config/initializers/alaveteli.rb b/config/initializers/alaveteli.rb
index 9787785db..7a7b35230 100644
--- a/config/initializers/alaveteli.rb
+++ b/config/initializers/alaveteli.rb
@@ -10,7 +10,7 @@ load "debug_helpers.rb"
load "util.rb"
# Application version
-ALAVETELI_VERSION = '0.21.0.20'
+ALAVETELI_VERSION = '0.21.0.21'
# Add new inflection rules using the following format
# (all these examples are active by default):
diff --git a/lib/acts_as_xapian/acts_as_xapian.rb b/lib/acts_as_xapian/acts_as_xapian.rb
index 6520a20a4..f742bae52 100644
--- a/lib/acts_as_xapian/acts_as_xapian.rb
+++ b/lib/acts_as_xapian/acts_as_xapian.rb
@@ -487,41 +487,37 @@ module ActsAsXapian
# date ranges or similar. Use this for cheap highlighting with
# TextHelper::highlight, and excerpt.
def words_to_highlight(opts = {})
- default_opts = { :include_original => false, :regex => false }
- opts = default_opts.merge(opts)
-
- # Reject all prefixes other than Z, which we know is reserved for stems
- terms = query.terms.reject { |t| t.term.first.match(/^[A-Y]$/) }
- # Collect the stems including the Z prefix
- raw_stems = terms.map { |t| t.term if t.term.start_with?('Z') }.compact.uniq.sort
- # Collect stems, chopping the Z prefix off
- stems = raw_stems.map { |t| t[1..-1] }.compact.sort
- # Collect the non-stem terms
- words = terms.map { |t| t.term unless t.term.start_with?('Z') }.compact.sort
-
- # Add the unstemmed words from the original query
- # Sometimes stems can be unhelpful with the :regex option, for example
- # stemming 'boring' results in us trying to highlight 'bore'.
- if opts[:include_original]
- raw_stems.each do |raw_stem|
- words << ActsAsXapian.query_parser.unstem(raw_stem).uniq
- end
-
- words = words.any? ? words.flatten.uniq : []
- end
-
- if opts[:regex]
- stems.map! { |w| /\b(#{ w })\w*\b/iu }
- words.map! { |w| /\b(#{ w })\b/iu }
- end
-
- if RUBY_VERSION.to_f >= 1.9
- (stems + words).map! do |term|
- term.is_a?(String) ? term.force_encoding('UTF-8') : term
- end
- else
- stems + words
- end
+ default_opts = { :include_original => false, :regex => false }
+ opts = default_opts.merge(opts)
+
+ # Reject all prefixes other than Z, which we know is reserved for stems
+ terms = query.terms.reject { |t| t.term.first.match(/^[A-Y]$/) }
+ # Collect the stems including the Z prefix
+ raw_stems = terms.map { |t| t.term if t.term.start_with?('Z') }.compact.uniq.sort
+ # Collect stems, chopping the Z prefix off
+ stems = raw_stems.map { |t| t[1..-1] }.compact.sort
+ # Collect the non-stem terms
+ words = terms.map { |t| t.term unless t.term.start_with?('Z') }.compact.sort
+
+ # Add the unstemmed words from the original query
+ # Sometimes stems can be unhelpful with the :regex option, for example
+ # stemming 'boring' results in us trying to highlight 'bore'.
+ if opts[:include_original]
+ raw_stems.each do |raw_stem|
+ words << ActsAsXapian.query_parser.unstem(raw_stem).uniq
+ end
+
+ words = words.any? ? words.flatten.uniq : []
+ end
+
+ if opts[:regex]
+ stems.map! { |w| /\b(#{ correctly_encode(w) })\w*\b/iu }
+ words.map! { |w| /\b(#{ correctly_encode(w) })\b/iu }
+ end
+
+ (stems + words).map! do |term|
+ term.is_a?(String) ? correctly_encode(term) : term
+ end
end
# Text for lines in log file
@@ -529,6 +525,12 @@ module ActsAsXapian
"Search: " + self.query_string
end
+ private
+
+ def correctly_encode(w)
+ RUBY_VERSION.to_f >= 1.9 ? w.force_encoding('UTF-8') : w
+ end
+
end
# Search for models which contain theimportant terms taken from a specified
diff --git a/script/switch-theme.rb b/script/switch-theme.rb
index 980853687..146d1bf0c 100755
--- a/script/switch-theme.rb
+++ b/script/switch-theme.rb
@@ -129,5 +129,5 @@ STDERR.puts """Switched to #{requested_theme}!
You will need to:
1. restart any development server you have running.
2. run: bundle exec rake assets:clean
- 3. run: bundle exec rake assets:precompile
+ 3. run: bundle exec rake assets:precompile (if running in production mode)
"""
diff --git a/spec/controllers/general_controller_spec.rb b/spec/controllers/general_controller_spec.rb
index ae8d4f256..844fcd4e6 100644
--- a/spec/controllers/general_controller_spec.rb
+++ b/spec/controllers/general_controller_spec.rb
@@ -169,7 +169,6 @@ describe GeneralController, "when showing the frontpage" do
it 'should end a logged-in session whose ttl has expired' do
session[:ttl] = Time.now - 4.hours
get :frontpage
- response.should redirect_to signin_path
session[:user_id].should be_nil
end
diff --git a/spec/integration/xapian_search_highlighting_spec.rb b/spec/integration/xapian_search_highlighting_spec.rb
index b2994eb31..a91df341f 100644
--- a/spec/integration/xapian_search_highlighting_spec.rb
+++ b/spec/integration/xapian_search_highlighting_spec.rb
@@ -1,3 +1,5 @@
+# encoding: utf-8
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe 'highlighting search results' do
@@ -40,4 +42,13 @@ describe 'highlighting search results' do
highlight_matches(phrase, matches).should == '<mark>boring</mark>'
end
+ it 'handles macrons correctly' do
+ phrase = 'Māori'
+
+ search = ActsAsXapian::Search.new([PublicBody], phrase, :limit => 1)
+ matches = search.words_to_highlight(:regex => true, :include_original => true)
+
+ highlight_matches(phrase, matches).should == '<mark>Māori</mark>'
+ end
+
end
diff --git a/spec/models/info_request_spec.rb b/spec/models/info_request_spec.rb
index c8bd2c338..d8c0c59b1 100644
--- a/spec/models/info_request_spec.rb
+++ b/spec/models/info_request_spec.rb
@@ -1221,6 +1221,7 @@ describe InfoRequest do
describe InfoRequest, "when constructing a list of requests by query" do
before(:each) do
+ load_raw_emails_data
get_fixtures_xapian_index
end
diff --git a/spec/models/public_body_spec.rb b/spec/models/public_body_spec.rb
index 7b55efda1..cce017424 100644
--- a/spec/models/public_body_spec.rb
+++ b/spec/models/public_body_spec.rb
@@ -1237,6 +1237,33 @@ describe PublicBody do
end
+ describe :request_email do
+ context "when the email is set" do
+ subject(:public_body) { FactoryGirl.create(:public_body, :request_email => "request@example.com") }
+
+ it "should return the set email address" do
+ expect(public_body.request_email).to eq("request@example.com")
+ end
+
+ it "should return a different email address when overridden in configuration" do
+ AlaveteliConfiguration.stub!(:override_all_public_body_request_emails).and_return("tester@example.com")
+ expect(public_body.request_email).to eq("tester@example.com")
+ end
+ end
+
+ context "when no email is set" do
+ subject(:public_body) { FactoryGirl.create(:public_body, :request_email => "") }
+
+ it "should return a blank email address" do
+ expect(public_body.request_email).to be_blank
+ end
+
+ it "should still return a blank email address when overridden in configuration" do
+ AlaveteliConfiguration.stub!(:override_all_public_body_request_emails).and_return("tester@example.com")
+ expect(public_body.request_email).to be_blank
+ end
+ end
+ end
end
describe PublicBody::Translation do
diff --git a/spec/views/public_body/show.html.erb_spec.rb b/spec/views/public_body/show.html.erb_spec.rb
index 6ebc39caa..2a4c21d04 100644
--- a/spec/views/public_body/show.html.erb_spec.rb
+++ b/spec/views/public_body/show.html.erb_spec.rb
@@ -13,7 +13,6 @@ describe "public_body/show" do
:publication_scheme => '',
:disclosure_log => '',
:calculated_home_page => '')
- @pb.stub!(:override_request_email).and_return(nil)
@pb.stub!(:is_requestable?).and_return(true)
@pb.stub!(:special_not_requestable_reason?).and_return(false)
@pb.stub!(:has_notes?).and_return(false)