aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLouise Crow <louise.crow@gmail.com>2015-05-07 15:49:32 +0100
committerLouise Crow <louise.crow@gmail.com>2015-05-07 15:49:32 +0100
commitcc5dd55a9bd55dbba4dd239d3334493bae2cb3bf (patch)
tree7903ede99984d149d2fa343877e4fc1670a41b22
parentda95c03f9f224ded9e0e3bda2635bcf4f63faf5d (diff)
parentf75b1de52432018c19d9fce04b1127ab114df0ea (diff)
Merge branch 'version-dependent-caching' into rails-3-develop
-rw-r--r--app/models/info_request_event.rb8
-rw-r--r--app/models/post_redirect.rb6
-rw-r--r--config/application.rb3
-rw-r--r--spec/models/info_request_event_spec.rb6
-rw-r--r--spec/models/post_redirect_spec.rb10
5 files changed, 29 insertions, 4 deletions
diff --git a/app/models/info_request_event.rb b/app/models/info_request_event.rb
index 635ba8f58..0ee82d30c 100644
--- a/app/models/info_request_event.rb
+++ b/app/models/info_request_event.rb
@@ -278,9 +278,15 @@ class InfoRequestEvent < ActiveRecord::Base
end
self.params_yaml = params.to_yaml
end
+
def params
- YAML.load(self.params_yaml)
+ param_hash = YAML.load(params_yaml)
+ param_hash.each do |key, value|
+ param_hash[key] = value.force_encoding('UTF-8') if value.respond_to?(:force_encoding)
+ end
+ param_hash
end
+
def params_yaml_as_html
ret = ''
# split out parameters into old/new diffs, and other ones
diff --git a/app/models/post_redirect.rb b/app/models/post_redirect.rb
index 8049349d0..59160381c 100644
--- a/app/models/post_redirect.rb
+++ b/app/models/post_redirect.rb
@@ -71,7 +71,11 @@ class PostRedirect < ActiveRecord::Base
end
def reason_params
- YAML.load(reason_params_yaml)
+ param_hash = YAML.load(reason_params_yaml)
+ param_hash.each do |key, value|
+ param_hash[key] = value.force_encoding('UTF-8') if value.respond_to?(:force_encoding)
+ end
+ param_hash
end
# Extract just local path part, without domain or #
diff --git a/config/application.rb b/config/application.rb
index 472077f06..46c4eb93b 100644
--- a/config/application.rb
+++ b/config/application.rb
@@ -60,7 +60,8 @@ module Alaveteli
config.time_zone = ::AlaveteliConfiguration::time_zone
# Set the cache to use a memcached backend
- config.cache_store = :mem_cache_store, { :namespace => AlaveteliConfiguration::domain }
+ config.cache_store = :mem_cache_store,
+ { :namespace => "#{AlaveteliConfiguration::domain}_#{RUBY_VERSION}" }
config.action_dispatch.rack_cache = nil
config.after_initialize do |app|
diff --git a/spec/models/info_request_event_spec.rb b/spec/models/info_request_event_spec.rb
index 53c83bd46..1299dfb63 100644
--- a/spec/models/info_request_event_spec.rb
+++ b/spec/models/info_request_event_spec.rb
@@ -30,6 +30,12 @@ describe InfoRequestEvent do
ire.params.should == example_params
end
+ it "should restore UTF8-heavy params stored under ruby 1.8 as UTF-8" do
+ ire = InfoRequestEvent.new
+ utf8_params = "--- \n:foo: !binary |\n 0KLQvtCz0LDRiCDR\n"
+ ire.params_yaml = utf8_params
+ ire.params[:foo].encoding.to_s.should == 'UTF-8' if ire.params[:foo].respond_to?(:encoding)
+ end
end
describe 'when deciding if it is indexed by search' do
diff --git a/spec/models/post_redirect_spec.rb b/spec/models/post_redirect_spec.rb
index 73740e914..70b221f10 100644
--- a/spec/models/post_redirect_spec.rb
+++ b/spec/models/post_redirect_spec.rb
@@ -65,11 +65,19 @@ describe PostRedirect, " when accessing values" do
end
it "should convert reason parameters into YAML and back successfully" do
- pr = PostRedirect.new
+ pr = PostRedirect.new
example_reason_params = { :foo => 'this is stuff', :bar => 83, :humbug => "yikes!!!" }
pr.reason_params = example_reason_params
pr.reason_params_yaml.should == example_reason_params.to_yaml
pr.reason_params.should == example_reason_params
end
+
+ it "should restore UTF8-heavy params stored under ruby 1.8 as UTF-8" do
+ pr = PostRedirect.new
+ utf8_params = "--- \n:foo: !binary |\n 0KLQvtCz0LDRiCDR\n"
+ pr.reason_params_yaml = utf8_params
+ puts pr.reason_params
+ pr.reason_params[:foo].encoding.to_s.should == 'UTF-8' if pr.reason_params[:foo].respond_to?(:encoding)
+ end
end