Commit d77668a003f8890551039891fe9992724bd596d3

Authored by Arthur Neves
1 parent 95b2202f
Exists in master and in 1 other branch production

Return N/A on to_curl if no url given

app/models/notice.rb
@@ -79,13 +79,14 @@ class Notice @@ -79,13 +79,14 @@ class Notice
79 end 79 end
80 80
81 def to_curl 81 def to_curl
  82 + return "N/A" if url.blank?
82 headers = %w(Accept Accept-Encoding Accept-Language Cookie Referer User-Agent).each_with_object([]) do |name, h| 83 headers = %w(Accept Accept-Encoding Accept-Language Cookie Referer User-Agent).each_with_object([]) do |name, h|
83 if value = env_vars["HTTP_#{name.underscore.upcase}"] 84 if value = env_vars["HTTP_#{name.underscore.upcase}"]
84 h << "-H '#{name}: #{value}'" 85 h << "-H '#{name}: #{value}'"
85 end 86 end
86 end 87 end
87 88
88 - "curl -X #{env_vars['REQUEST_METHOD'] || 'GET'} #{headers.join(' ')} #{request['url']}" 89 + "curl -X #{env_vars['REQUEST_METHOD'] || 'GET'} #{headers.join(' ')} #{url}"
89 end 90 end
90 91
91 def env_vars 92 def env_vars
spec/models/notice_spec.rb
@@ -35,14 +35,25 @@ describe Notice do @@ -35,14 +35,25 @@ describe Notice do
35 end 35 end
36 end 36 end
37 37
38 - context "to_curl" do  
39 - let(:request) { {'url' => "http://example.com/resource/12", 'cgi-data' => {'HTTP_USER_AGENT' => 'Mozilla/5.0'}} } 38 + describe "to_curl" do
40 let(:notice) { Fabricate.build(:notice, request: request) } 39 let(:notice) { Fabricate.build(:notice, request: request) }
41 40
42 - it 'has a curl representation' do  
43 - cmd = notice.to_curl 41 + context "when it has a request url" do
  42 + let(:request) { {'url' => "http://example.com/resource/12", 'cgi-data' => {'HTTP_USER_AGENT' => 'Mozilla/5.0'}} }
44 43
45 - cmd.should eql(%q[curl -X GET -H 'User-Agent: Mozilla/5.0' http://example.com/resource/12]) 44 + it 'has a curl representation' do
  45 + cmd = notice.to_curl
  46 + expect(cmd).to eq(%q[curl -X GET -H 'User-Agent: Mozilla/5.0' http://example.com/resource/12])
  47 + end
  48 + end
  49 +
  50 + context "when it has not a request url" do
  51 + let(:request) { {'cgi-data' => {'HTTP_USER_AGENT' => 'Mozilla/5.0'}} }
  52 +
  53 + it 'has a curl representation' do
  54 + cmd = notice.to_curl
  55 + expect(cmd).to eq "N/A"
  56 + end
46 end 57 end
47 end 58 end
48 59