From d77668a003f8890551039891fe9992724bd596d3 Mon Sep 17 00:00:00 2001 From: Arthur Neves Date: Thu, 22 May 2014 15:58:19 -0400 Subject: [PATCH] Return N/A on to_curl if no url given --- app/models/notice.rb | 3 ++- spec/models/notice_spec.rb | 21 ++++++++++++++++----- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/app/models/notice.rb b/app/models/notice.rb index 14c2e34..917bef4 100644 --- a/app/models/notice.rb +++ b/app/models/notice.rb @@ -79,13 +79,14 @@ class Notice end def to_curl + return "N/A" if url.blank? headers = %w(Accept Accept-Encoding Accept-Language Cookie Referer User-Agent).each_with_object([]) do |name, h| if value = env_vars["HTTP_#{name.underscore.upcase}"] h << "-H '#{name}: #{value}'" end end - "curl -X #{env_vars['REQUEST_METHOD'] || 'GET'} #{headers.join(' ')} #{request['url']}" + "curl -X #{env_vars['REQUEST_METHOD'] || 'GET'} #{headers.join(' ')} #{url}" end def env_vars diff --git a/spec/models/notice_spec.rb b/spec/models/notice_spec.rb index e0085d5..97076ef 100644 --- a/spec/models/notice_spec.rb +++ b/spec/models/notice_spec.rb @@ -35,14 +35,25 @@ describe Notice do end end - context "to_curl" do - let(:request) { {'url' => "http://example.com/resource/12", 'cgi-data' => {'HTTP_USER_AGENT' => 'Mozilla/5.0'}} } + describe "to_curl" do let(:notice) { Fabricate.build(:notice, request: request) } - it 'has a curl representation' do - cmd = notice.to_curl + context "when it has a request url" do + let(:request) { {'url' => "http://example.com/resource/12", 'cgi-data' => {'HTTP_USER_AGENT' => 'Mozilla/5.0'}} } - cmd.should eql(%q[curl -X GET -H 'User-Agent: Mozilla/5.0' http://example.com/resource/12]) + it 'has a curl representation' do + cmd = notice.to_curl + expect(cmd).to eq(%q[curl -X GET -H 'User-Agent: Mozilla/5.0' http://example.com/resource/12]) + end + end + + context "when it has not a request url" do + let(:request) { {'cgi-data' => {'HTTP_USER_AGENT' => 'Mozilla/5.0'}} } + + it 'has a curl representation' do + cmd = notice.to_curl + expect(cmd).to eq "N/A" + end end end -- libgit2 0.21.2