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
Fix for serializing with YAML #579
Conversation
Hi @AvaelKross, sorry if I get in the middle, but I just come across your PR and noticed something interesting. I made a quick research, and I found this SO answer: http://stackoverflow.com/a/12922463/4194669 I understand you went for the simplest solution, but I'm not sure it's a proper implementation.
|
Thanks, @iMacTia ! I added only |
Looks strange to be honest, but I don't know how the YAML serialisation/deserialisation works exactly, so happy that it works now :)! |
@AvaelKross please add a test that demonstrates your fix in action. Thanks! |
@AvaelKross Do you think you will be able to add a test to this PR? It's the only thing that's preventing it from being merged. Thanks! |
Yes, sure. I'll try to find some time later this week.
|
Hi @AvaelKross, any chance you can add the missing test? I would be happy to add your PR to faraday v0.10.1 release :) |
Hi @AvaelKross, it would be nice to have your input on this. |
Using this naive test, I noted that I got the NoMethodError when missing the # YAML parsing
def test_yaml_roundtrip
begin
YAML.load(Faraday::Utils::Headers.new("User-Agent" => "safari").to_yaml)
assert_equal true, true
rescue => e
assert_equal true, false, "Failed when loading YAML: #{e.message}"
end
end Adding the Edit: But that does not prove much yet. I'll edit this to something that I can use. Update: It was possible to add a simpler-yet test. # YAML parsing
def test_headers_yaml_roundtrip
headers = Faraday::Utils::Headers.new('User-Agent' => 'safari', 'Content-type' => 'text/html')
result = YAML.load(headers.to_yaml)
assert result.include?('user-agent'), 'Unable to hydrate to a correct Headers'
assert result.include?('content-type'), 'Unable to hydrate to a correct Headers'
end |
Closing as #634 was merged |
Way to reproduce bug with current code:
YAML.load(Faraday::Utils::Headers.new("User-Agent" => "safari").to_yaml)
YAML is a standard tool for serializing, so I guess it should be supported. I believe that this bug can't be fixed outside of Faraday. I found this bug when I tried to serialize Faraday::Response instance for further storing in DB.