Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the namespace for memcached dependent on ruby version. #2410

Merged
merged 2 commits into from
May 7, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion app/models/info_request_event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,15 @@ def params=(params)
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
Expand Down
6 changes: 5 additions & 1 deletion app/models/post_redirect.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ def reason_params=(reason_params)
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 #
Expand Down
3 changes: 2 additions & 1 deletion config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ class Application < Rails::Application
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|
Expand Down
6 changes: 6 additions & 0 deletions spec/models/info_request_event_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@
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
Expand Down
10 changes: 9 additions & 1 deletion spec/models/post_redirect_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,19 @@
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