ratchetio 0.4.3 → 0.4.4
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +3 -0
- data/lib/ratchetio/configuration.rb +2 -0
- data/lib/ratchetio/version.rb +1 -1
- data/lib/ratchetio.rb +8 -0
- data/spec/controllers/home_controller_spec.rb +104 -0
- data/spec/dummyapp/.gitignore +0 -1
- data/spec/dummyapp/config/database.yml +28 -0
- data/spec/ratchetio_spec.rb +26 -2
- metadata +4 -3
data/CHANGELOG.md
CHANGED
@@ -3,6 +3,7 @@ module Ratchetio
|
|
3
3
|
|
4
4
|
attr_accessor :access_token
|
5
5
|
attr_accessor :branch
|
6
|
+
attr_accessor :enabled
|
6
7
|
attr_accessor :endpoint
|
7
8
|
attr_accessor :exception_level_filters
|
8
9
|
attr_accessor :environment
|
@@ -17,6 +18,7 @@ module Ratchetio
|
|
17
18
|
DEFAULT_ENDPOINT = 'https://submit.ratchet.io/api/1/item/'
|
18
19
|
|
19
20
|
def initialize
|
21
|
+
@enabled = true
|
20
22
|
@endpoint = DEFAULT_ENDPOINT
|
21
23
|
@framework = 'Plain'
|
22
24
|
@exception_level_filters = {
|
data/lib/ratchetio/version.rb
CHANGED
data/lib/ratchetio.rb
CHANGED
@@ -46,6 +46,10 @@ module Ratchetio
|
|
46
46
|
# @param person_data [Hash] Data describing the affected person. Should be the result of calling
|
47
47
|
# `ratchetio_person_data`
|
48
48
|
def report_exception(exception, request_data = nil, person_data = nil)
|
49
|
+
unless configuration.enabled
|
50
|
+
return
|
51
|
+
end
|
52
|
+
|
49
53
|
filtered_level = configuration.exception_level_filters[exception.class.name]
|
50
54
|
if filtered_level == 'ignore'
|
51
55
|
# ignored - do nothing
|
@@ -74,6 +78,10 @@ module Ratchetio
|
|
74
78
|
# @param extra_data [Hash] Additional data to include alongside the body. Don't use 'body' as
|
75
79
|
# it is reserved.
|
76
80
|
def report_message(message, level = 'info', extra_data = {})
|
81
|
+
unless configuration.enabled
|
82
|
+
return
|
83
|
+
end
|
84
|
+
|
77
85
|
data = message_data(message, level, extra_data)
|
78
86
|
payload = build_payload(data)
|
79
87
|
send_payload(payload)
|
@@ -10,6 +10,110 @@ describe HomeController do
|
|
10
10
|
|
11
11
|
let(:logger_mock) { double("Rails.logger").as_null_object }
|
12
12
|
|
13
|
+
context "ratchetio controller methods" do
|
14
|
+
# TODO run these for a a more-real request
|
15
|
+
it "should build valid request data" do
|
16
|
+
data = @controller.ratchetio_request_data
|
17
|
+
data.should have_key(:params)
|
18
|
+
data.should have_key(:url)
|
19
|
+
data.should have_key(:user_ip)
|
20
|
+
data.should have_key(:headers)
|
21
|
+
data.should have_key(:GET)
|
22
|
+
data.should have_key(:session)
|
23
|
+
data.should have_key(:method)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should build empty person data when no one is logged-in" do
|
27
|
+
data = @controller.ratchetio_person_data
|
28
|
+
data.should == {}
|
29
|
+
end
|
30
|
+
|
31
|
+
context "ratchetio_filter_params" do
|
32
|
+
it "should filter files" do
|
33
|
+
name = "John Doe"
|
34
|
+
file_hash = {
|
35
|
+
:filename => "test.txt",
|
36
|
+
:type => "text/plain",
|
37
|
+
:head => {},
|
38
|
+
:tempfile => "dummy"
|
39
|
+
}
|
40
|
+
file = ActionDispatch::Http::UploadedFile.new(file_hash)
|
41
|
+
|
42
|
+
params = {
|
43
|
+
:name => name,
|
44
|
+
:a_file => file
|
45
|
+
}
|
46
|
+
|
47
|
+
filtered = controller.send(:ratchetio_filter_params, params)
|
48
|
+
|
49
|
+
filtered[:name].should == name
|
50
|
+
filtered[:a_file].should be_a_kind_of(Hash)
|
51
|
+
filtered[:a_file][:content_type].should == file_hash[:type]
|
52
|
+
filtered[:a_file][:original_filename].should == file_hash[:filename]
|
53
|
+
filtered[:a_file][:size].should == file_hash[:tempfile].size
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should filter files in nested params" do
|
57
|
+
name = "John Doe"
|
58
|
+
file_hash = {
|
59
|
+
:filename => "test.txt",
|
60
|
+
:type => "text/plain",
|
61
|
+
:head => {},
|
62
|
+
:tempfile => "dummy"
|
63
|
+
}
|
64
|
+
file = ActionDispatch::Http::UploadedFile.new(file_hash)
|
65
|
+
|
66
|
+
params = {
|
67
|
+
:name => name,
|
68
|
+
:wrapper => {
|
69
|
+
:wrapper2 => {
|
70
|
+
:a_file => file,
|
71
|
+
:foo => "bar"
|
72
|
+
}
|
73
|
+
}
|
74
|
+
}
|
75
|
+
|
76
|
+
filtered = controller.send(:ratchetio_filter_params, params)
|
77
|
+
|
78
|
+
filtered[:name].should == name
|
79
|
+
filtered[:wrapper][:wrapper2][:foo].should == "bar"
|
80
|
+
|
81
|
+
filtered_file = filtered[:wrapper][:wrapper2][:a_file]
|
82
|
+
filtered_file.should be_a_kind_of(Hash)
|
83
|
+
filtered_file[:content_type].should == file_hash[:type]
|
84
|
+
filtered_file[:original_filename].should == file_hash[:filename]
|
85
|
+
filtered_file[:size].should == file_hash[:tempfile].size
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
context "ratchetio_request_url" do
|
90
|
+
it "should build simple http urls" do
|
91
|
+
req = controller.request
|
92
|
+
req.host = 'ratchet.io'
|
93
|
+
|
94
|
+
controller.send(:ratchetio_request_url).should == 'http://ratchet.io'
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
context "ratchetio_user_ip" do
|
99
|
+
it "should use X-Real-Ip when set" do
|
100
|
+
controller.request.env["HTTP_X_REAL_IP"] = '1.1.1.1'
|
101
|
+
controller.request.env["HTTP_X_FORWARDED_FOR"] = '1.2.3.4'
|
102
|
+
controller.send(:ratchetio_user_ip).should == '1.1.1.1'
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should use X-Forwarded-For when set" do
|
106
|
+
controller.request.env["HTTP_X_FORWARDED_FOR"] = '1.2.3.4'
|
107
|
+
controller.send(:ratchetio_user_ip).should == '1.2.3.4'
|
108
|
+
end
|
109
|
+
|
110
|
+
it "should use the remote_addr when neither is set" do
|
111
|
+
controller.send(:ratchetio_user_ip).should == '0.0.0.0'
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
116
|
+
|
13
117
|
describe "GET 'index'" do
|
14
118
|
it "should be successful and report a message" do
|
15
119
|
logger_mock.should_receive(:info).with('[Ratchet.io] Sending payload')
|
data/spec/dummyapp/.gitignore
CHANGED
@@ -0,0 +1,28 @@
|
|
1
|
+
# SQLite version 3.x
|
2
|
+
# gem install sqlite3
|
3
|
+
#
|
4
|
+
# Ensure the SQLite 3 gem is defined in your Gemfile
|
5
|
+
# gem 'sqlite3'
|
6
|
+
development:
|
7
|
+
adapter: sqlite3
|
8
|
+
database: db/development.sqlite3
|
9
|
+
pool: 5
|
10
|
+
timeout: 5000
|
11
|
+
|
12
|
+
# Warning: The database defined as "test" will be erased and
|
13
|
+
# re-generated from your development database when you run "rake".
|
14
|
+
# Do not set this db to the same as development or production.
|
15
|
+
test: &test
|
16
|
+
adapter: sqlite3
|
17
|
+
database: db/test.sqlite3
|
18
|
+
pool: 5
|
19
|
+
timeout: 5000
|
20
|
+
|
21
|
+
production:
|
22
|
+
adapter: sqlite3
|
23
|
+
database: db/production.sqlite3
|
24
|
+
pool: 5
|
25
|
+
timeout: 5000
|
26
|
+
|
27
|
+
cucumber:
|
28
|
+
<<: *test
|
data/spec/ratchetio_spec.rb
CHANGED
@@ -3,8 +3,6 @@ require 'spec_helper'
|
|
3
3
|
|
4
4
|
describe Ratchetio do
|
5
5
|
|
6
|
-
it 'controller methods'
|
7
|
-
|
8
6
|
context 'report_exception' do
|
9
7
|
before(:each) do
|
10
8
|
configure
|
@@ -26,6 +24,19 @@ describe Ratchetio do
|
|
26
24
|
Ratchetio.report_exception(@exception)
|
27
25
|
end
|
28
26
|
|
27
|
+
it 'should not report anything when disabled' do
|
28
|
+
logger_mock.should_not_receive(:info).with('[Ratchet.io] Sending payload')
|
29
|
+
Ratchetio.configure do |config|
|
30
|
+
config.enabled = false
|
31
|
+
end
|
32
|
+
|
33
|
+
Ratchetio.report_exception(@exception)
|
34
|
+
|
35
|
+
Ratchetio.configure do |config|
|
36
|
+
config.enabled = true
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
29
40
|
it 'should report exceptions with request and person data' do
|
30
41
|
logger_mock.should_receive(:info).with('[Ratchet.io] Sending payload')
|
31
42
|
request_data = {
|
@@ -78,6 +89,19 @@ describe Ratchetio do
|
|
78
89
|
Ratchetio.report_message("Test message")
|
79
90
|
end
|
80
91
|
|
92
|
+
it 'should not report anything when disabled' do
|
93
|
+
logger_mock.should_not_receive(:info).with('[Ratchet.io] Sending payload')
|
94
|
+
Ratchetio.configure do |config|
|
95
|
+
config.enabled = false
|
96
|
+
end
|
97
|
+
|
98
|
+
Ratchetio.report_message("Test message that should be ignored")
|
99
|
+
|
100
|
+
Ratchetio.configure do |config|
|
101
|
+
config.enabled = true
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
81
105
|
it 'should report messages with extra data' do
|
82
106
|
logger_mock.should_receive(:info).with('[Ratchet.io] Sending payload')
|
83
107
|
Ratchetio.report_message("Test message with extra data", 'debug', :foo => "bar",
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ratchetio
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-11-
|
12
|
+
date: 2012-11-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec-rails
|
@@ -276,6 +276,7 @@ files:
|
|
276
276
|
- spec/dummyapp/config/application.rb
|
277
277
|
- spec/dummyapp/config/boot.rb
|
278
278
|
- spec/dummyapp/config/cucumber.yml
|
279
|
+
- spec/dummyapp/config/database.yml
|
279
280
|
- spec/dummyapp/config/environment.rb
|
280
281
|
- spec/dummyapp/config/environments/development.rb
|
281
282
|
- spec/dummyapp/config/environments/production.rb
|
@@ -371,6 +372,7 @@ test_files:
|
|
371
372
|
- spec/dummyapp/config/application.rb
|
372
373
|
- spec/dummyapp/config/boot.rb
|
373
374
|
- spec/dummyapp/config/cucumber.yml
|
375
|
+
- spec/dummyapp/config/database.yml
|
374
376
|
- spec/dummyapp/config/environment.rb
|
375
377
|
- spec/dummyapp/config/environments/development.rb
|
376
378
|
- spec/dummyapp/config/environments/production.rb
|
@@ -408,4 +410,3 @@ test_files:
|
|
408
410
|
- spec/ratchetio_spec.rb
|
409
411
|
- spec/spec_helper.rb
|
410
412
|
- spec/support/devise.rb
|
411
|
-
has_rdoc:
|