Last active
January 4, 2016 00:29
-
-
Save carmi/8542415 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper' | |
describe "ripple encoding" do | |
it 'should fix a bad encoding' do | |
robj = PersonalProfile.bucket.new | |
robj.raw_data = "BAD ASCII-8BIT STUFF".force_encoding("ASCII-8BIT") | |
robj.store | |
expect{ robj.data }.to raise_error(Yajl::ParseError) | |
robj.reload(force: true) | |
cleaned_data = robj.raw_data.bytes.to_a.pack("U*").force_encoding("UTF-8") | |
expect(cleaned_data.encoding.name).to eq("UTF-8") | |
expect(cleaned_data.valid_encoding?).to be_true | |
robj.raw_data = cleaned_data | |
robj.store | |
robj.reload(force: true) | |
# Now robj.data still raises error, and the encoding is US-ASCII instead of UTF-8 | |
expect(robj.raw_data.encoding.name).to eq("UTF-8") | |
expect{ robj.data }.to_not raise_error(Yajl::ParseError) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment