justlogging-rails 0.0.5 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.travis.yml ADDED
@@ -0,0 +1,28 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ # - 1.9.2
5
+ - 1.9.3
6
+ - 1.8.7
7
+ - ree
8
+ # - ruby-head
9
+ # - jruby-18mode
10
+ - jruby-19mode
11
+ # - jruby-head
12
+ # - rbx-18mode
13
+ - rbx-19mode
14
+
15
+ gemfile:
16
+ - gemfiles/3.0.gemfile
17
+ - gemfiles/3.1.gemfile
18
+ - gemfiles/3.2.gemfile
19
+ - gemfiles/edge.gemfile
20
+
21
+ matrix:
22
+ exclude:
23
+ - rvm: 1.8.7
24
+ gemfile: gemfiles/edge.gemfile
25
+ allow_failures:
26
+ - gemfile: gemfiles/edge.gemfile
27
+
28
+ script: RAILS_ENV=test bundle exec rspec spec
data/Gemfile.lock CHANGED
@@ -1,8 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- justlogging-rails (0.0.4)
5
- activesupport
4
+ justlogging-rails (0.0.5)
6
5
  rails
7
6
  rake
8
7
  rspec
@@ -10,31 +9,31 @@ PATH
10
9
  GEM
11
10
  remote: https://rubygems.org/
12
11
  specs:
13
- actionmailer (3.2.7)
14
- actionpack (= 3.2.7)
12
+ actionmailer (3.2.6)
13
+ actionpack (= 3.2.6)
15
14
  mail (~> 2.4.4)
16
- actionpack (3.2.7)
17
- activemodel (= 3.2.7)
18
- activesupport (= 3.2.7)
15
+ actionpack (3.2.6)
16
+ activemodel (= 3.2.6)
17
+ activesupport (= 3.2.6)
19
18
  builder (~> 3.0.0)
20
19
  erubis (~> 2.7.0)
21
- journey (~> 1.0.4)
20
+ journey (~> 1.0.1)
22
21
  rack (~> 1.4.0)
23
22
  rack-cache (~> 1.2)
24
23
  rack-test (~> 0.6.1)
25
24
  sprockets (~> 2.1.3)
26
- activemodel (3.2.7)
27
- activesupport (= 3.2.7)
25
+ activemodel (3.2.6)
26
+ activesupport (= 3.2.6)
28
27
  builder (~> 3.0.0)
29
- activerecord (3.2.7)
30
- activemodel (= 3.2.7)
31
- activesupport (= 3.2.7)
28
+ activerecord (3.2.6)
29
+ activemodel (= 3.2.6)
30
+ activesupport (= 3.2.6)
32
31
  arel (~> 3.0.2)
33
32
  tzinfo (~> 0.3.29)
34
- activeresource (3.2.7)
35
- activemodel (= 3.2.7)
36
- activesupport (= 3.2.7)
37
- activesupport (3.2.7)
33
+ activeresource (3.2.6)
34
+ activemodel (= 3.2.6)
35
+ activesupport (= 3.2.6)
36
+ activesupport (3.2.6)
38
37
  i18n (~> 0.6)
39
38
  multi_json (~> 1.0)
40
39
  arel (3.0.2)
@@ -44,7 +43,7 @@ GEM
44
43
  hike (1.2.1)
45
44
  i18n (0.6.0)
46
45
  journey (1.0.4)
47
- json (1.7.5)
46
+ json (1.7.3)
48
47
  mail (2.4.4)
49
48
  i18n (>= 0.4.0)
50
49
  mime-types (~> 1.16)
@@ -59,17 +58,17 @@ GEM
59
58
  rack
60
59
  rack-test (0.6.1)
61
60
  rack (>= 1.0)
62
- rails (3.2.7)
63
- actionmailer (= 3.2.7)
64
- actionpack (= 3.2.7)
65
- activerecord (= 3.2.7)
66
- activeresource (= 3.2.7)
67
- activesupport (= 3.2.7)
61
+ rails (3.2.6)
62
+ actionmailer (= 3.2.6)
63
+ actionpack (= 3.2.6)
64
+ activerecord (= 3.2.6)
65
+ activeresource (= 3.2.6)
66
+ activesupport (= 3.2.6)
68
67
  bundler (~> 1.0)
69
- railties (= 3.2.7)
70
- railties (3.2.7)
71
- actionpack (= 3.2.7)
72
- activesupport (= 3.2.7)
68
+ railties (= 3.2.6)
69
+ railties (3.2.6)
70
+ actionpack (= 3.2.6)
71
+ activesupport (= 3.2.6)
73
72
  rack-ssl (~> 1.3.2)
74
73
  rake (>= 0.8.7)
75
74
  rdoc (~> 3.4)
@@ -77,19 +76,19 @@ GEM
77
76
  rake (0.9.2.2)
78
77
  rdoc (3.12)
79
78
  json (~> 1.4)
80
- rspec (2.11.0)
81
- rspec-core (~> 2.11.0)
82
- rspec-expectations (~> 2.11.0)
83
- rspec-mocks (~> 2.11.0)
84
- rspec-core (2.11.1)
85
- rspec-expectations (2.11.2)
79
+ rspec (2.10.0)
80
+ rspec-core (~> 2.10.0)
81
+ rspec-expectations (~> 2.10.0)
82
+ rspec-mocks (~> 2.10.0)
83
+ rspec-core (2.10.1)
84
+ rspec-expectations (2.10.0)
86
85
  diff-lcs (~> 1.1.3)
87
- rspec-mocks (2.11.2)
86
+ rspec-mocks (2.10.1)
88
87
  sprockets (2.1.3)
89
88
  hike (~> 1.2)
90
89
  rack (~> 1.0)
91
90
  tilt (~> 1.1, != 1.3.0)
92
- thor (0.16.0)
91
+ thor (0.15.3)
93
92
  tilt (1.3.3)
94
93
  treetop (1.4.10)
95
94
  polyglot
data/README.md CHANGED
@@ -1,2 +1,15 @@
1
1
  justlogging-gem
2
- ===============
2
+ ===============
3
+
4
+ ## Pulllrequests / issues
5
+
6
+ New features should be made in an issue or pullrequest. Title format is as follows:
7
+
8
+
9
+ name [request_count]
10
+
11
+ example
12
+
13
+ tagging [2]
14
+
15
+
@@ -1,4 +1,6 @@
1
- development:
2
- endpoint: "http://localhost:3000/api/1/log_entries"
1
+ development: &development
2
+ endpoint: "http://localhost:3000/api/1"
3
3
  api_key: "abc"
4
4
  active: true
5
+ test:
6
+ <<: *development
@@ -0,0 +1,6 @@
1
+ # encoding: utf-8
2
+ source :rubygems
3
+
4
+ gem 'rails', '~> 3.0.17'
5
+ gem 'rspec'
6
+ gem 'rake'
@@ -0,0 +1,6 @@
1
+ # encoding: utf-8
2
+ source :rubygems
3
+
4
+ gem 'rails', '~> 3.1.8'
5
+ gem 'rspec'
6
+ gem 'rake'
@@ -0,0 +1,6 @@
1
+ # encoding: utf-8
2
+ source :rubygems
3
+
4
+ gem 'rails', '~> 3.2.8'
5
+ gem 'rspec'
6
+ gem 'rake'
@@ -0,0 +1,6 @@
1
+ # encoding: utf-8
2
+ source :rubygems
3
+
4
+ gem 'rails', :git => 'git://github.com/rails/rails.git'
5
+ gem 'rspec'
6
+ gem 'rake'
@@ -2,8 +2,8 @@
2
2
  require File.expand_path('../lib/justlogging/version', __FILE__)
3
3
 
4
4
  Gem::Specification.new do |gem|
5
- gem.authors = ["Robert Beekman"]
6
- gem.email = ["robert@80beans.com"]
5
+ gem.authors = ["Robert Beekman", "Steven Weller"]
6
+ gem.email = ["robert@80beans.com", "steven@80beans.com"]
7
7
  gem.description = %q{The official justlogging.com gem}
8
8
  gem.summary = %q{Logs rails's notifications to justlogging.com}
9
9
  gem.homepage = "http://github.com/80beans/justlogging-rails"
@@ -17,6 +17,5 @@ Gem::Specification.new do |gem|
17
17
 
18
18
  gem.add_dependency 'rails'
19
19
  gem.add_dependency 'rspec'
20
- gem.add_dependency 'activesupport'
21
20
  gem.add_dependency 'rake'
22
21
  end
data/lib/justlogging.rb CHANGED
@@ -1,11 +1,8 @@
1
1
  raise 'This justlogging gem only works with rails' unless defined?(Rails)
2
- require 'net/http'
3
- require 'net/https'
4
- require 'uri'
5
2
 
6
3
  module Justlogging
7
-
8
4
  class << self
5
+
9
6
  attr_accessor :subscriber
10
7
 
11
8
  def transactions
@@ -17,12 +14,15 @@ module Justlogging
17
14
  end
18
15
 
19
16
  def config
20
- @config ||= {:ignore_exceptions => []}.merge(YAML.load_file("#{Rails.root}/config/justlogging.yml")[Rails.env].symbolize_keys)
17
+ @config ||= {:ignore_exceptions => []}.merge(
18
+ YAML.load_file("#{Rails.root}/config/justlogging.yml")[Rails.env].
19
+ symbolize_keys)
21
20
  end
22
- end
23
21
 
22
+ end
24
23
  end
25
24
 
25
+ require 'justlogging/transmitter'
26
26
  require 'justlogging/agent'
27
27
  require 'justlogging/middleware'
28
28
  require 'justlogging/transaction'
@@ -1,8 +1,8 @@
1
1
  module Justlogging
2
-
3
2
  class Agent
4
3
 
5
- attr_reader :queue, :active, :sleep_time
4
+ attr_reader :queue, :active, :sleep_time, :transmitter
5
+ ACTION = 'log_entries'
6
6
 
7
7
  def initialize
8
8
  @sleep_time = 5
@@ -16,37 +16,19 @@ module Justlogging
16
16
  sleep @sleep_time
17
17
  end
18
18
  end
19
+ @transmitter = Transmitter.new(
20
+ Justlogging.config[:endpoint],
21
+ ACTION,
22
+ Justlogging.config[:api_key]
23
+ )
19
24
  end
20
25
 
21
26
  def add_to_queue(transaction)
22
27
  @queue << transaction
23
28
  end
24
29
 
25
- def uri
26
- URI(Justlogging.config[:endpoint])
27
- end
28
-
29
- def http_client
30
- Net::HTTP.new(uri.host, uri.port).tap do |http|
31
- if uri.scheme == 'https'
32
- http.use_ssl = true
33
- http.verify_mode = OpenSSL::SSL::VERIFY_PEER
34
- end
35
- end
36
- end
37
-
38
30
  def send_queue
39
- json = ActiveSupport::JSON.encode @queue
40
- request = Net::HTTP::Post.new(uri.request_uri)
41
- request.set_form_data('api_key' => Justlogging.config[:api_key], 'log_entries' => json)
42
-
43
- begin
44
- result = http_client.request(request)
45
- code = result.code
46
- rescue => error
47
- code = nil
48
- end
49
- handle_result(code)
31
+ handle_result transmitter.transmit(:log_entries => queue)
50
32
  end
51
33
 
52
34
  # Empty queue is result is 200 ok.
@@ -64,5 +46,4 @@ module Justlogging
64
46
  end
65
47
 
66
48
  end
67
-
68
49
  end
@@ -1,5 +1,6 @@
1
1
  module Justlogging
2
2
  class MissingController
3
+
3
4
  def method_missing(*args, &block)
4
5
  end
5
6
  end
@@ -9,10 +10,7 @@ module Justlogging
9
10
  attr_reader :env, :exception, :kontroller, :request, :backtrace
10
11
 
11
12
  def initialize(env, exception)
12
- #@env = env
13
13
  @exception = exception
14
- #@kontroller = env['action_controller.instance'] || Justlogging::MissingController.new
15
- #@request = ActionDispatch::Request.new(env)
16
14
  @backtrace = Rails.respond_to?(:backtrace_cleaner) ?
17
15
  Rails.backtrace_cleaner.send(:filter, exception.backtrace) :
18
16
  exception.backtrace
@@ -11,7 +11,7 @@ module Justlogging
11
11
  Justlogging::Transaction.create(env['action_dispatch.request_id'], env)
12
12
  @app.call(env)
13
13
  rescue Exception => exception
14
- unless Array.wrap(Justlogging.config[:ignore_exceptions]).include?(exception.class.name)
14
+ unless includes_exception?(exception)
15
15
  Justlogging::Transaction.current.add_exception(
16
16
  Justlogging::ExceptionNotification.new(env, exception)
17
17
  )
@@ -21,5 +21,12 @@ module Justlogging
21
21
  Justlogging::Transaction.current.complete!
22
22
  end
23
23
 
24
+ private
25
+
26
+ def includes_exception?(exception)
27
+ Array.wrap(Justlogging.config[:ignore_exceptions]).
28
+ include?(exception.class.name)
29
+ end
30
+
24
31
  end
25
32
  end
@@ -4,7 +4,8 @@ module Justlogging
4
4
  class Railtie < Rails::Railtie
5
5
 
6
6
  initializer "justlogging.configure_rails_initialization" do |app|
7
- app.middleware.insert_after ActionDispatch::DebugExceptions, Justlogging::Middleware
7
+ app.middleware.insert_before ActionDispatch::RemoteIp,
8
+ Justlogging::Middleware
8
9
 
9
10
  Justlogging.subscriber = ActiveSupport::Notifications.subscribe do |*args|
10
11
  if Justlogging::Transaction.current
@@ -36,6 +36,10 @@ module Justlogging
36
36
  @exception = ex
37
37
  end
38
38
 
39
+ def exception?
40
+ !! @exception
41
+ end
42
+
39
43
  def formatted_exception
40
44
  return {} unless @exception
41
45
  {
@@ -58,15 +62,20 @@ module Justlogging
58
62
  end
59
63
 
60
64
  def formatted_log_entry
61
- @log_entry.payload.merge(
62
- :duration => @log_entry.duration,
63
- :time => @log_entry.time,
64
- :end => @log_entry.end,
65
+ {
65
66
  :name => request.fullpath,
66
67
  :environment => Rails.env,
67
68
  :server => @env['SERVER_NAME'],
68
69
  :kind => 'http_request'
69
- )
70
+ }.tap { |o| o.merge!(formatted_payload) unless exception? }
71
+ end
72
+
73
+ def formatted_payload
74
+ @log_entry.payload.merge(
75
+ :duration => @log_entry.duration,
76
+ :time => @log_entry.time,
77
+ :end => @log_entry.end
78
+ ).tap { |o| o[:action] = "#{o.delete(:controller)}##{o[:action]}" }
70
79
  end
71
80
 
72
81
  def to_hash
@@ -83,10 +92,9 @@ module Justlogging
83
92
  Thread.current[:justlogging_transaction_id] = nil
84
93
  current_transaction = Justlogging.transactions.delete(@id)
85
94
  if @events.any? || @exception.present?
86
- Justlogging.agent.add_to_queue(
87
- current_transaction.to_hash
88
- )
95
+ Justlogging.agent.add_to_queue(current_transaction.to_hash)
89
96
  end
90
97
  end
98
+
91
99
  end
92
100
  end
@@ -0,0 +1,51 @@
1
+ require 'net/http'
2
+ require 'net/https'
3
+ require 'uri'
4
+
5
+ module Justlogging
6
+ class Transmitter
7
+
8
+ attr_accessor :endpoint, :action, :api_key
9
+
10
+ def initialize(endpoint, action, api_key)
11
+ @endpoint = endpoint
12
+ @action = action
13
+ @api_key = api_key
14
+ end
15
+
16
+ def uri
17
+ URI("#{@endpoint}/#{@action}")
18
+ end
19
+
20
+ def transmit(payload)
21
+ begin
22
+ result = http_client.request(encoded_message(payload))
23
+ result.code
24
+ rescue
25
+ nil
26
+ end
27
+ end
28
+
29
+ def encoded_message(payload)
30
+ message(ActiveSupport::JSON.encode(payload))
31
+ end
32
+
33
+ def message(json)
34
+ Net::HTTP::Post.new(uri.request_uri).tap do |post|
35
+ post.set_form_data(json.reverse_merge('api_key' => api_key))
36
+ end
37
+ end
38
+
39
+ protected
40
+
41
+ def http_client
42
+ Net::HTTP.new(uri.host, uri.port).tap do |http|
43
+ if uri.scheme == 'https'
44
+ http.use_ssl = true
45
+ http.verify_mode = OpenSSL::SSL::VERIFY_PEER
46
+ end
47
+ end
48
+ end
49
+
50
+ end
51
+ end
@@ -1,3 +1,3 @@
1
1
  module Justlogging
2
- VERSION = '0.0.5'
2
+ VERSION = '0.0.6'
3
3
  end
@@ -1,79 +1,58 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Justlogging::Agent do
4
- before :each do
5
- Thread.stub(:new)
6
- end
7
-
8
- let(:agent) { Justlogging::Agent.new }
9
4
  let(:event) { stub(:name => 'event') }
5
+ before(:each) { Thread.stub(:new) }
10
6
 
11
7
  describe '#add_to_queue' do
12
8
  it 'should add the event to the queue' do
13
9
  expect {
14
- agent.add_to_queue(event)
15
- }.to change(agent, :queue).to([event])
10
+ subject.add_to_queue(event)
11
+ }.to change(subject, :queue).to([event])
16
12
  end
17
13
  end
18
14
 
19
- describe '#send_queue' do
20
- let(:http_client) { stub(:request => stub(:code => '200')) }
21
- before do
22
- agent.stub(:http_client).and_return(http_client)
23
- agent.add_to_queue(event)
24
- ActiveSupport::JSON.stub(:encode => '{"abc":"def"}')
25
- end
26
-
27
- it 'should call Net::HTTP.post_form with the correct params' do
28
- post = stub
29
- post.should_receive(:set_form_data).with(
30
- 'api_key' => 'abc',
31
- 'log_entries' => '{"abc":"def"}'
32
- )
33
-
34
- Net::HTTP::Post.should_receive(:new).with(
35
- '/api/1/log_entries'
36
- ).and_return(post)
15
+ describe "#send_queue" do
16
+ it "transmits" do
17
+ subject.stub(:queue => 'foo')
18
+ subject.transmitter.should_receive(:transmit).with(:log_entries => 'foo')
37
19
  end
38
20
 
39
- it "should call handle_result" do
40
- agent.should_receive(:handle_result).with('200')
21
+ it "handles the return code" do
22
+ subject.transmitter.stub(:transmit => '200')
23
+ subject.should_receive(:handle_result).with('200')
41
24
  end
42
25
 
43
- after { agent.send_queue }
26
+ after { subject.send_queue }
44
27
  end
45
28
 
46
29
  describe '#handle_result' do
47
- before do
48
- agent.add_to_queue(event)
49
- end
30
+ before { subject.add_to_queue(event) }
50
31
 
51
32
  it "should empty the queue for 200" do
52
33
  expect {
53
- agent.handle_result('200')
54
- }.to change(agent, :queue).to([])
34
+ subject.handle_result('200')
35
+ }.to change(subject, :queue).to([])
55
36
  end
56
37
 
57
38
  it "should raise the sleep_time time for 403" do
58
39
  expect {
59
- agent.handle_result('403')
60
- }.to change(agent, :sleep_time).to(7.5)
40
+ subject.handle_result('403')
41
+ }.to change(subject, :sleep_time).to(7.5)
61
42
  end
62
43
 
63
44
  context "any other response" do
64
45
 
65
46
  it "should deactivate for any other response code" do
66
47
  expect {
67
- agent.handle_result('500')
68
- }.to change(agent, :active).to(false)
48
+ subject.handle_result('500')
49
+ }.to change(subject, :active).to(false)
69
50
  end
70
51
 
71
52
  it "should unsubscribe from the justlogging subscriber" do
72
53
  ActiveSupport::Notifications.should_receive(:unsubscribe)
73
- agent.handle_result('500')
54
+ subject.handle_result('500')
74
55
  end
75
56
  end
76
-
77
57
  end
78
-
79
58
  end
@@ -1,10 +1,10 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Justlogging::ExceptionNotification do
4
- before { Rails.stub(:respond_to? => false) }
5
4
  let(:error) { StandardError.new('moo') }
6
5
  let(:notification) { Justlogging::ExceptionNotification.new({}, error) }
7
6
  subject { notification }
7
+ before { Rails.stub(:respond_to? => false) }
8
8
 
9
9
  its(:exception) { should == error }
10
10
  its(:name) { should == 'StandardError' }
@@ -1,8 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  module Justlogging
4
- class IgnoreMeError < StandardError
5
- end
4
+ IgnoreMeError = Class.new(StandardError)
6
5
  end
7
6
 
8
7
  class AppWithError
@@ -75,6 +74,5 @@ describe Justlogging::Middleware do
75
74
  after { middleware.call(env) rescue nil }
76
75
  end
77
76
  end
78
-
79
77
  end
80
78
  end
@@ -3,17 +3,15 @@ require 'action_controller/railtie'
3
3
  require 'justlogging/railtie'
4
4
 
5
5
  describe Justlogging::Railtie do
6
-
7
- before :all do
8
- MyApp::Application.initialize!
9
- end
6
+ before(:all) { MyApp::Application.initialize! }
10
7
 
11
8
  it "should have set the justlogging subscriber" do
12
- Justlogging.subscriber.should be_a ActiveSupport::Notifications::Fanout::Subscriber
9
+ Justlogging.subscriber.
10
+ should be_a ActiveSupport::Notifications::Fanout::Subscriber
13
11
  end
14
12
 
15
13
  it "should have added the middleware for exceptions" do
16
- MyApp::Application.middleware.middlewares.should include Justlogging::Middleware
14
+ MyApp::Application.middleware.to_a.should include Justlogging::Middleware
17
15
  end
18
16
 
19
17
  context "non action_controller event" do
@@ -21,13 +19,11 @@ describe Justlogging::Railtie do
21
19
  it "should call add_event for non action_controller event" do
22
20
  current = stub
23
21
  current.should_receive(:add_event)
24
- Justlogging::Transaction.should_receive(:current).twice.and_return(current)
25
- end
26
-
27
- after do
28
- ActiveSupport::Notifications.instrument 'query.mongoid'
22
+ Justlogging::Transaction.should_receive(:current).twice.
23
+ and_return(current)
29
24
  end
30
25
 
26
+ after { ActiveSupport::Notifications.instrument 'query.mongoid' }
31
27
  end
32
28
 
33
29
  context "action_controller event" do
@@ -35,13 +31,13 @@ describe Justlogging::Railtie do
35
31
  it "should call set_log_entry for action_controller event" do
36
32
  current = stub
37
33
  current.should_receive(:set_log_entry)
38
- Justlogging::Transaction.should_receive(:current).twice.and_return(current)
34
+ Justlogging::Transaction.should_receive(:current).twice.
35
+ and_return(current)
39
36
  end
40
37
 
41
38
  after do
42
- ActiveSupport::Notifications.instrument 'process_action.action_controller'
39
+ ActiveSupport::Notifications.
40
+ instrument 'process_action.action_controller'
43
41
  end
44
-
45
42
  end
46
-
47
43
  end
@@ -25,7 +25,9 @@ describe Justlogging::Transaction do
25
25
  end
26
26
 
27
27
  describe 'transaction instance' do
28
- let(:transaction) { Justlogging::Transaction.create('1', {'SERVER_NAME' => 'localhost'}) }
28
+ let(:transaction) do
29
+ Justlogging::Transaction.create('1', {'SERVER_NAME' => 'localhost'})
30
+ end
29
31
 
30
32
  describe '#request' do
31
33
  subject { transaction.request }
@@ -64,10 +66,14 @@ describe Justlogging::Transaction do
64
66
  end
65
67
 
66
68
  describe '#formatted_exception' do
67
- let(:exception) { stub(:backtrace => ['test'], :name => 'Justlogging::Error', :message => 'nooo') }
68
-
69
+ let(:exception) do
70
+ stub({
71
+ :backtrace => ['test'],
72
+ :name => 'Justlogging::Error',
73
+ :message => 'nooo'
74
+ })
75
+ end
69
76
  before { transaction.add_exception(exception) }
70
-
71
77
  subject { transaction.formatted_exception }
72
78
 
73
79
  it 'should return a formatted exception' do
@@ -82,43 +88,84 @@ describe Justlogging::Transaction do
82
88
  describe '#formatted_events' do
83
89
  let(:start_time) { Time.parse('01-01-2001 10:00:00') }
84
90
  let(:end_time) { Time.parse('01-01-2001 10:00:01') }
85
- let(:event) { stub(:name => 'name', :duration => 2, :time => start_time, :end => end_time, :payload => {}) }
91
+ let(:payload) do
92
+ {
93
+ :name => 'name',
94
+ :duration => 2,
95
+ :time => start_time,
96
+ :end => end_time,
97
+ :payload => {}
98
+ }
99
+ end
100
+ let(:event) { stub(payload) }
86
101
 
87
102
  before { transaction.add_event(event) }
88
103
 
89
104
  subject { transaction.formatted_events }
90
105
 
91
106
  it 'should return formatted events' do
92
- should == [{:name=>'name', :duration=>2, :time=>start_time, :end=>end_time, :payload=>{}}]
107
+ should == [payload]
93
108
  end
94
109
  end
95
110
 
96
111
  describe '#formatted_log_entry' do
97
- let(:start_time) { Time.parse('01-01-2001 10:00:00') }
98
- let(:end_time) { Time.parse('01-01-2001 10:00:01') }
99
- let(:log_entry) { stub(:name => 'name', :duration => 2, :time => start_time, :end => end_time, :payload => {:controller => 'JustSayinController'}) }
100
- let(:request) { stub(:fullpath => '/blog') }
112
+ subject { transaction.formatted_log_entry }
113
+ before { transaction.stub(:request => mock(:fullpath => '/blog')) }
114
+ before { Rails.stub(:env => 'care about it') }
115
+
116
+ context "successfully handled request" do
117
+ before { transaction.stub(:exception? => false) }
118
+ before { transaction.stub(:formatted_payload => {:foo => :bar}) }
119
+
120
+ it 'returns a formatted log_entry' do
121
+ should == {
122
+ :name => '/blog',
123
+ :environment => 'care about it',
124
+ :server => 'localhost',
125
+ :kind => 'http_request',
126
+ :foo => :bar
127
+ }
128
+ end
129
+ end
101
130
 
102
- before { transaction.stub(:request => request) }
103
- before { transaction.set_log_entry(log_entry) }
131
+ context "exception" do
132
+ before { transaction.stub(:exception? => true) }
104
133
 
105
- subject { transaction.formatted_log_entry }
134
+ it 'returns a formatted log_entry' do
135
+ should == {
136
+ :name => '/blog',
137
+ :environment => 'care about it',
138
+ :server => 'localhost',
139
+ :kind => 'http_request'
140
+ }
141
+ end
142
+ end
143
+ end
144
+
145
+ describe '#formatted_payload' do
146
+ let(:start_time) { Time.parse('01-01-2001 10:00:00') }
147
+ let(:end_time) { Time.parse('01-01-2001 10:00:01') }
148
+ subject { transaction.formatted_payload }
149
+ before do
150
+ transaction.set_log_entry(mock(
151
+ :name => 'name', :duration => 2, :time => start_time,
152
+ :end => end_time,
153
+ :payload => {:controller => 'controller', :action => 'action'}
154
+ ))
155
+ end
106
156
 
107
- it 'should return formatted log_entry' do
157
+ it 'returns the formatted payload of the log entry' do
108
158
  should == {
109
- :controller => 'JustSayinController',
159
+ :action => 'controller#action',
110
160
  :duration => 2,
111
161
  :time => start_time,
112
- :end => end_time,
113
- :name => '/blog',
114
- :environment => "development",
115
- :server => 'localhost',
116
- :kind => "http_request"
162
+ :end => end_time
117
163
  }
118
164
  end
119
165
  end
120
166
 
121
167
  describe '#to_hash' do
168
+ subject { transaction.to_hash }
122
169
  before { transaction.stub(
123
170
  :formatted_log_entry => {:name => 'log_entry'},
124
171
  :formatted_events => [{:name => 'event'}],
@@ -126,8 +173,6 @@ describe Justlogging::Transaction do
126
173
  :failed => false
127
174
  )}
128
175
 
129
- subject { transaction.to_hash }
130
-
131
176
  it 'should return a formatted hash of the transaction data' do
132
177
  should == {
133
178
  :request_id => '1',
@@ -184,8 +229,6 @@ describe Justlogging::Transaction do
184
229
  Thread.current[:justlogging_transaction_id].should be_nil
185
230
  end
186
231
  end
187
-
188
232
  end
189
233
  end
190
-
191
234
  end
@@ -0,0 +1,60 @@
1
+ require 'spec_helper'
2
+
3
+ describe Justlogging::Transmitter do
4
+ let(:_80beans_) { 'http://www.80beans.com' }
5
+ let(:action) { 'action' }
6
+ let(:klass) { Justlogging::Transmitter }
7
+ let(:instance) { klass.new(_80beans_, action, :the_api_key) }
8
+ subject { instance }
9
+
10
+ describe "#uri" do
11
+ it "returns uri" do
12
+ subject.uri.should == URI("http://www.80beans.com/action")
13
+ end
14
+ end
15
+
16
+ describe "#transmit" do
17
+ subject { instance.transmit(:shipit => :payload) }
18
+
19
+ context "without exception" do
20
+ let(:http_client) { stub(:request => stub(:code => '200')) }
21
+ before { instance.stub(:encoded_message => :the_message) }
22
+ before { instance.stub(:http_client => http_client) }
23
+
24
+ it { should == '200' }
25
+ end
26
+
27
+ context "with exception" do
28
+ let(:http_client) { stub(:request) }
29
+ before { instance.stub(:http_client).and_raise(Net::HTTPGatewayTimeOut) }
30
+
31
+ it { should == nil }
32
+ end
33
+ end
34
+
35
+ describe "#encoded_message" do
36
+ it "calls message" do
37
+ ActiveSupport::JSON.stub(:encode => :json)
38
+ subject.should_receive(:message).with(:json)
39
+ end
40
+
41
+ it "encodes the payload using json" do
42
+ subject.stub(:message)
43
+ ActiveSupport::JSON.should_receive(:encode).with(:payload)
44
+ end
45
+
46
+ after { subject.encoded_message(:payload) }
47
+ end
48
+
49
+ describe "#message" do
50
+ it "calls Net::HTTP.post_form with the correct params" do
51
+ post = stub
52
+ post.should_receive(:set_form_data).with(
53
+ 'api_key' => :the_api_key,
54
+ :the => :payload
55
+ )
56
+ Net::HTTP::Post.should_receive(:new).with('/action').and_return(post)
57
+ instance.message(:the => :payload)
58
+ end
59
+ end
60
+ end
@@ -20,7 +20,7 @@ describe Justlogging do
20
20
  subject { Justlogging.config }
21
21
 
22
22
  it 'should return the endpoint' do
23
- subject[:endpoint].should eq 'http://localhost:3000/api/1/log_entries'
23
+ subject[:endpoint].should eq 'http://localhost:3000/api/1'
24
24
  end
25
25
 
26
26
  it 'should return the api key' do
@@ -31,5 +31,4 @@ describe Justlogging do
31
31
  subject[:ignore_exceptions].should eq []
32
32
  end
33
33
  end
34
-
35
34
  end
data/spec/spec_helper.rb CHANGED
@@ -8,8 +8,8 @@ end
8
8
 
9
9
  module MyApp
10
10
  class Application < Rails::Application
11
- config.active_support.deprecation = proc { |message, stack| }
12
11
 
12
+ config.active_support.deprecation = proc { |message, stack| }
13
13
  end
14
14
  end
15
15
 
metadata CHANGED
@@ -1,15 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: justlogging-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Robert Beekman
9
+ - Steven Weller
9
10
  autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
- date: 2012-08-28 00:00:00.000000000 Z
13
+ date: 2012-09-07 00:00:00.000000000 Z
13
14
  dependencies:
14
15
  - !ruby/object:Gem::Dependency
15
16
  name: rails
@@ -43,22 +44,6 @@ dependencies:
43
44
  - - ! '>='
44
45
  - !ruby/object:Gem::Version
45
46
  version: '0'
46
- - !ruby/object:Gem::Dependency
47
- name: activesupport
48
- requirement: !ruby/object:Gem::Requirement
49
- none: false
50
- requirements:
51
- - - ! '>='
52
- - !ruby/object:Gem::Version
53
- version: '0'
54
- type: :runtime
55
- prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
- requirements:
59
- - - ! '>='
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
47
  - !ruby/object:Gem::Dependency
63
48
  name: rake
64
49
  requirement: !ruby/object:Gem::Requirement
@@ -78,6 +63,7 @@ dependencies:
78
63
  description: The official justlogging.com gem
79
64
  email:
80
65
  - robert@80beans.com
66
+ - steven@80beans.com
81
67
  executables: []
82
68
  extensions: []
83
69
  extra_rdoc_files: []
@@ -86,6 +72,8 @@ files:
86
72
  LmdpdGlnbm9yZQ==
87
73
  - !binary |-
88
74
  LnJ2bXJj
75
+ - !binary |-
76
+ LnRyYXZpcy55bWw=
89
77
  - !binary |-
90
78
  R2VtZmlsZQ==
91
79
  - !binary |-
@@ -96,6 +84,14 @@ files:
96
84
  Y29uZmlnL2p1c3Rsb2dnaW5nLnltbA==
97
85
  - !binary |-
98
86
  ZG9jL2p1c3Rsb2dnaW5nLW1vbmdvLm1hcmtkb3du
87
+ - !binary |-
88
+ Z2VtZmlsZXMvMy4wLmdlbWZpbGU=
89
+ - !binary |-
90
+ Z2VtZmlsZXMvMy4xLmdlbWZpbGU=
91
+ - !binary |-
92
+ Z2VtZmlsZXMvMy4yLmdlbWZpbGU=
93
+ - !binary |-
94
+ Z2VtZmlsZXMvZWRnZS5nZW1maWxl
99
95
  - !binary |-
100
96
  anVzdGxvZ2dpbmctcmFpbHMuZ2Vtc3BlYw==
101
97
  - !binary |-
@@ -110,6 +106,8 @@ files:
110
106
  bGliL2p1c3Rsb2dnaW5nL3JhaWx0aWUucmI=
111
107
  - !binary |-
112
108
  bGliL2p1c3Rsb2dnaW5nL3RyYW5zYWN0aW9uLnJi
109
+ - !binary |-
110
+ bGliL2p1c3Rsb2dnaW5nL3RyYW5zbWl0dGVyLnJi
113
111
  - !binary |-
114
112
  bGliL2p1c3Rsb2dnaW5nL3ZlcnNpb24ucmI=
115
113
  - !binary |-
@@ -123,6 +121,8 @@ files:
123
121
  c3BlYy9qdXN0bG9nZ2luZy9yYWlsdGllX3NwZWMucmI=
124
122
  - !binary |-
125
123
  c3BlYy9qdXN0bG9nZ2luZy90cmFuc2FjdGlvbl9zcGVjLnJi
124
+ - !binary |-
125
+ c3BlYy9qdXN0bG9nZ2luZy90cmFuc21pdHRlcl9zcGVjLnJi
126
126
  - !binary |-
127
127
  c3BlYy9qdXN0bG9nZ2luZ19zcGVjLnJi
128
128
  - !binary |-
@@ -163,6 +163,8 @@ test_files:
163
163
  c3BlYy9qdXN0bG9nZ2luZy9yYWlsdGllX3NwZWMucmI=
164
164
  - !binary |-
165
165
  c3BlYy9qdXN0bG9nZ2luZy90cmFuc2FjdGlvbl9zcGVjLnJi
166
+ - !binary |-
167
+ c3BlYy9qdXN0bG9nZ2luZy90cmFuc21pdHRlcl9zcGVjLnJi
166
168
  - !binary |-
167
169
  c3BlYy9qdXN0bG9nZ2luZ19zcGVjLnJi
168
170
  - !binary |-