Commit d77668a003f8890551039891fe9992724bd596d3
1 parent
95b2202f
Exists in
master
and in
1 other branch
Return N/A on to_curl if no url given
Showing
2 changed files
with
18 additions
and
6 deletions
Show diff stats
app/models/notice.rb
| ... | ... | @@ -79,13 +79,14 @@ class Notice |
| 79 | 79 | end |
| 80 | 80 | |
| 81 | 81 | def to_curl |
| 82 | + return "N/A" if url.blank? | |
| 82 | 83 | headers = %w(Accept Accept-Encoding Accept-Language Cookie Referer User-Agent).each_with_object([]) do |name, h| |
| 83 | 84 | if value = env_vars["HTTP_#{name.underscore.upcase}"] |
| 84 | 85 | h << "-H '#{name}: #{value}'" |
| 85 | 86 | end |
| 86 | 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 | 90 | end |
| 90 | 91 | |
| 91 | 92 | def env_vars | ... | ... |
spec/models/notice_spec.rb
| ... | ... | @@ -35,14 +35,25 @@ describe Notice do |
| 35 | 35 | end |
| 36 | 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 | 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 | 57 | end |
| 47 | 58 | end |
| 48 | 59 | ... | ... |