Commit 2eb1fea21c9e9cf6e4ed2af9db4df5ad962ba321
Exists in
master
and in
1 other branch
Merge pull request #442 from iFixit/notice-xml-parsing-fix-blank
Notice API: properly transform <var> tags
Showing
2 changed files
with
32 additions
and
0 deletions
Show diff stats
lib/hoptoad/v2.rb
... | ... | @@ -18,6 +18,8 @@ module Hoptoad |
18 | 18 | {normalize_key(node['key']) => rekey(node['__content__'])} |
19 | 19 | elsif node.has_key?('__content__') |
20 | 20 | rekey(node['__content__']) |
21 | + elsif node.has_key?('key') | |
22 | + {normalize_key(node['key']) => nil} | |
21 | 23 | else |
22 | 24 | node.inject({}) {|rekeyed, (key, val)| rekeyed.merge(normalize_key(key) => rekey(val))} |
23 | 25 | end | ... | ... |
spec/controllers/notices_controller_spec.rb
... | ... | @@ -24,6 +24,36 @@ describe NoticesController do |
24 | 24 | response.body.should match(%r{<url[^>]*>(.+)#{locate_path(@notice.id)}</url>}) |
25 | 25 | end |
26 | 26 | |
27 | + it "should trnasform xml <va> tags to hashes correctly" do | |
28 | + App.should_receive(:report_error!).with(@xml).and_return(@notice) | |
29 | + request.should_receive(:raw_post).and_return(@xml) | |
30 | + post :create, :format => :xml | |
31 | + | |
32 | + # XML: <var key="SCRIPT_NAME"/> | |
33 | + @notice.env_vars.should have_key('SCRIPT_NAME') | |
34 | + @notice.env_vars['SCRIPT_NAME'].should be_nil # blank ends up nil | |
35 | + | |
36 | + # XML representation: | |
37 | + # <var key="rack.session.options"> | |
38 | + # <var key="secure">false</var> | |
39 | + # <var key="httponly">true</var> | |
40 | + # <var key="path">/</var> | |
41 | + # <var key="expire_after"/> | |
42 | + # <var key="domain"/> | |
43 | + # <var key="id"/> | |
44 | + # </var> | |
45 | + expected = { | |
46 | + 'secure' => 'false', | |
47 | + 'httponly' => 'true', | |
48 | + 'path' => '/', | |
49 | + 'expire_after' => nil, | |
50 | + 'domain' => nil, | |
51 | + 'id' => nil | |
52 | + } | |
53 | + @notice.env_vars.should have_key('rack_session_options') | |
54 | + @notice.env_vars['rack_session_options'].should eql(expected) | |
55 | + end | |
56 | + | |
27 | 57 | it "generates a notice from xml in a data param [POST]" do |
28 | 58 | App.should_receive(:report_error!).with(@xml).and_return(@notice) |
29 | 59 | post :create, :data => @xml, :format => :xml | ... | ... |