aboutsummaryrefslogtreecommitdiffstats
path: root/spec/models
diff options
context:
space:
mode:
authorLouise Crow <louise.crow@gmail.com>2015-05-07 11:41:12 +0100
committerLouise Crow <louise.crow@gmail.com>2015-05-08 14:15:27 +0100
commit87f0630a216b8be1cf1e3905580892fe038b9965 (patch)
treed138839607e80f9fb0e985ca4cdec9ab0fe10b8b /spec/models
parent1b1a8aab7e7615627a62327e32fe617e90d3571d (diff)
Force the encoding of values returned from YAML.
This is a workaround for an issue where YAML in ruby 1.8 tags UTF-8 heavy strings as binary, resulting in them being retrieved under 1.9 as ASCII-8BIT which can't be concatenated with UTF-8. Described as "Deep deep YAML oddness" in https://www.zendesk.com/blog/upgrade-the-road-to-1-9/.
Diffstat (limited to 'spec/models')
-rw-r--r--spec/models/info_request_event_spec.rb6
-rw-r--r--spec/models/post_redirect_spec.rb10
2 files changed, 15 insertions, 1 deletions
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