Commit 95b2202f7419d9571cc6a6a1d2b533dac5950c60
Exists in
master
and in
1 other branch
Merge pull request #697 from phoet/add_to_curl_to_summary
Add to curl to summary
Showing
4 changed files
with
26 additions
and
1 deletions
Show diff stats
app/models/notice.rb
... | ... | @@ -78,6 +78,16 @@ class Notice |
78 | 78 | "N/A" |
79 | 79 | end |
80 | 80 | |
81 | + def to_curl | |
82 | + 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 | + h << "-H '#{name}: #{value}'" | |
85 | + end | |
86 | + end | |
87 | + | |
88 | + "curl -X #{env_vars['REQUEST_METHOD'] || 'GET'} #{headers.join(' ')} #{request['url']}" | |
89 | + end | |
90 | + | |
81 | 91 | def env_vars |
82 | 92 | request['cgi-data'] || {} |
83 | 93 | end | ... | ... |
app/views/notices/_summary.html.haml
lib/tasks/errbit/demo.rake
... | ... | @@ -49,7 +49,8 @@ namespace :errbit do |
49 | 49 | :backtrace => random_backtrace, |
50 | 50 | :request => { |
51 | 51 | 'component' => 'main', |
52 | - 'action' => 'error' | |
52 | + 'action' => 'error', | |
53 | + 'url' => "http://example.com/post/#{[111, 222, 333].sample}", | |
53 | 54 | }, |
54 | 55 | :server_environment => {'environment-name' => Rails.env.to_s}, |
55 | 56 | :notifier => {:name => "seeds.rb"}, | ... | ... |
spec/models/notice_spec.rb
... | ... | @@ -35,6 +35,17 @@ 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'}} } | |
40 | + let(:notice) { Fabricate.build(:notice, request: request) } | |
41 | + | |
42 | + it 'has a curl representation' do | |
43 | + cmd = notice.to_curl | |
44 | + | |
45 | + cmd.should eql(%q[curl -X GET -H 'User-Agent: Mozilla/5.0' http://example.com/resource/12]) | |
46 | + end | |
47 | + end | |
48 | + | |
38 | 49 | describe "user agent" do |
39 | 50 | it "should be parsed and human-readable" do |
40 | 51 | notice = Fabricate.build(:notice, :request => {'cgi-data' => { | ... | ... |