fix bug with empty queries

Andrew Cantino 11 anos atrás
pai
commit
846ebe707f
2 arquivos alterados com 7 adições e 1 exclusões
  1. 1 1
      app/models/agents/post_agent.rb
  2. 6 0
      spec/models/agents/post_agent_spec.rb

+ 1 - 1
app/models/agents/post_agent.rb

@@ -57,7 +57,7 @@ module Agents
57 57
 
58 58
     def generate_uri(params = nil)
59 59
       uri = URI options[:post_url]
60
-      uri.query = URI.encode_www_form(Hash[URI.decode_www_form(uri.query)].merge(params)) if params
60
+      uri.query = URI.encode_www_form(Hash[URI.decode_www_form(uri.query || '')].merge(params)) if params
61 61
       uri
62 62
     end
63 63
 

+ 6 - 0
spec/models/agents/post_agent_spec.rb

@@ -152,6 +152,12 @@ describe Agents::PostAgent do
152 152
       uri.request_uri.should == "/a/path?existing_param=existing_value&some_param=some_value&another_param=another_value"
153 153
     end
154 154
 
155
+    it "works fine with urls that do not have a query" do
156
+      @checker.options['post_url'] = "http://example.com/a/path"
157
+      uri = @checker.generate_uri("some_param" => "some_value", "another_param" => "another_value")
158
+      uri.request_uri.should == "/a/path?some_param=some_value&another_param=another_value"
159
+    end
160
+
155 161
     it "just returns the post_uri when no params are given" do
156 162
       @checker.options['post_url'] = "http://example.com/a/path?existing_param=existing_value"
157 163
       uri = @checker.generate_uri