log_spy 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 34268e22c164c45eca6f47b0b0c36f884fafa44e
4
- data.tar.gz: 60f7eb5ad9eecbf8aa043cccaf29fbd50704756b
3
+ metadata.gz: f2dc87b4c4a64a5e9cca30f4274c31b5410b7658
4
+ data.tar.gz: dd24f18962e75a3efc5c029a9445593e3d7b693e
5
5
  SHA512:
6
- metadata.gz: a02c0a56797fb22b04571a651f5947f02f94daecb9c63569e0ee34b42b3449825c16db65c9f0b32f4b41989336cdfc9dd889d6179ee77d05238c44be5e98a163
7
- data.tar.gz: 382af23783237d1962b0b54b0bd810694457ea956f55c7ea4e037bb02359c9864c7ad384170afb4a08bd7ccbd145ae2a5a8814fabac161c385eee9f9bfc55715
6
+ metadata.gz: 4fffa272cda3094c4c41763040ca61adf3b117628b4cb7be8f399046771a8869bc7e7de0ad8732c6a2f57a52a84d09e64210fec7dce8d9fa02fd163705deb83d
7
+ data.tar.gz: fc708c4642da96e831e8bf4f09ea661e5b5b4d20b25d8c896144aab8031a99e0bb6ddaf4a674760b280b0bd8b84ba886312b92d7051bd787cd8375bb1a6ea2fa
data/History.md CHANGED
@@ -1,4 +1,8 @@
1
1
 
2
+ 0.0.4 / 2014-09-23
3
+ ==================
4
+ * add `controller_action` to payload, if `env['action_dispatch.request.parameter']` exists
5
+
2
6
  0.0.3 / 2014-09-04
3
7
  ==================
4
8
 
@@ -26,6 +26,10 @@ class LogSpy::Payload
26
26
  hash[:error] = { :message => @error.message, :backtrace => @error.backtrace }
27
27
  end
28
28
 
29
+ if controller_params = @req.env['action_dispatch.request.parameters']
30
+ hash[:controller_action] = "#{controller_params['controller']}##{controller_params['action']}"
31
+ end
32
+
29
33
  hash.to_json
30
34
  end
31
35
 
data/lib/log_spy/spy.rb CHANGED
@@ -13,18 +13,23 @@ class LogSpy::Spy
13
13
  end
14
14
 
15
15
  def call env
16
+ @env = env
16
17
  @start_time = Time.now.to_f
17
- @req = Rack::Request.new env
18
- @status, @header, @body = @app.call(env)
18
+ @status, header, body = @app.call(env)
19
19
 
20
20
  @sqs_thread = send_sqs_async
21
- [ @status, @header, @body ]
21
+
22
+ [ @status, header, body ]
22
23
  rescue Exception => err
23
24
  @sqs_thread = send_sqs_async(err)
24
-
25
25
  raise err
26
26
  end
27
27
 
28
+ def req
29
+ Rack::Request.new @env
30
+ end
31
+ private :req
32
+
28
33
  def send_sqs_async(err = nil)
29
34
  @sqs_thread = Thread.new do
30
35
  status = err ? 500 : @status
@@ -34,7 +39,7 @@ class LogSpy::Spy
34
39
  :duration => duration,
35
40
  :status => status
36
41
  })
37
- payload = ::LogSpy::Payload.new(@req, res, @start_time.to_i, err)
42
+ payload = ::LogSpy::Payload.new(req, res, @start_time.to_i, err)
38
43
 
39
44
  sqs.queues[@sqs_url].send_message(payload.to_json)
40
45
  end
@@ -1,3 +1,3 @@
1
1
  module LogSpy
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
data/spec/payload_spec.rb CHANGED
@@ -18,6 +18,7 @@ describe LogSpy::Payload do
18
18
  :request_method => request_method,
19
19
  :ip => ip,
20
20
  :query_string => query_string,
21
+ :env => {},
21
22
  :body => body)
22
23
  end
23
24
 
@@ -79,11 +80,31 @@ describe LogSpy::Payload do
79
80
  allow(request).to receive_messages(:env => { 'RAW_POST_BODY' => 'raw-post-body' })
80
81
  expected_hash[:request][:body] = 'raw-post-body'
81
82
  end
83
+
84
+ end
85
+
86
+ shared_examples "if env['action_dispatch.request.parameters']" do
87
+ before :each do
88
+ controller_params = { 'controller' => 'users', 'action' => 'show' }
89
+ env = { 'action_dispatch.request.parameters' => controller_params }
90
+ allow(request).to receive_messages(:env => env)
91
+ end
92
+
93
+ it 'returns hash with `controller_action`' do
94
+ expected_hash[:controller_action] = "users#show"
95
+ expected_hash[:request][:body] = nil
96
+
97
+ expect(payload.to_json).to eq(expected_hash.to_json)
98
+ end
82
99
  end
83
100
 
84
101
  context "if request ends without error" do
85
102
  let(:payload) { LogSpy::Payload.new request, response, begin_at }
86
103
 
104
+ context "if env['action_dispatch.request.parameters']" do
105
+ include_examples "if env['action_dispatch.request.parameters']"
106
+ end
107
+
87
108
  context "if body can be read" do
88
109
  include_context "if_body_readable"
89
110
  include_examples 'ensure_payload_formats'
@@ -105,6 +126,10 @@ describe LogSpy::Payload do
105
126
  }
106
127
  end
107
128
 
129
+ context "if env['action_dispatch.request.parameters']" do
130
+ include_examples "if env['action_dispatch.request.parameters']"
131
+ end
132
+
108
133
  context "if request body can be read" do
109
134
  include_context 'if_body_readable'
110
135
  include_examples 'ensure_payload_formats'
data/spec/spy_spec.rb CHANGED
@@ -98,6 +98,7 @@ describe LogSpy::Spy do
98
98
 
99
99
  middleware.sqs_thread.join
100
100
  end
101
+
101
102
  end
102
103
 
103
104
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: log_spy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yang-Hsing Lin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-04 00:00:00.000000000 Z
11
+ date: 2014-09-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk
@@ -122,7 +122,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
122
122
  version: '0'
123
123
  requirements: []
124
124
  rubyforge_project:
125
- rubygems_version: 2.0.3
125
+ rubygems_version: 2.2.2
126
126
  signing_key:
127
127
  specification_version: 4
128
128
  summary: send rack application log to Amazon SQS