ratchetio 0.4.2 → 0.4.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/CHANGELOG.md +6 -0
- data/README.md +2 -0
- data/Rakefile +7 -1
- data/lib/generators/ratchetio/ratchetio_generator.rb +1 -1
- data/lib/ratchetio/configuration.rb +9 -10
- data/lib/ratchetio/rails/controller_methods.rb +3 -3
- data/lib/ratchetio/rails/middleware/exception_catcher.rb +2 -4
- data/lib/ratchetio/version.rb +1 -1
- data/lib/ratchetio.rb +87 -60
- data/ratchetio.gemspec +16 -1
- data/spec/controllers/home_controller_spec.rb +41 -0
- data/spec/dummyapp/.gitignore +74 -0
- data/spec/dummyapp/Gemfile +19 -0
- data/spec/dummyapp/README +19 -0
- data/spec/dummyapp/README.textile +80 -0
- data/spec/dummyapp/Rakefile +7 -0
- data/spec/dummyapp/app/assets/javascripts/application.js +15 -0
- data/spec/dummyapp/app/assets/javascripts/home.js.coffee +3 -0
- data/spec/dummyapp/app/assets/stylesheets/application.css.scss +37 -0
- data/spec/dummyapp/app/assets/stylesheets/home.css.scss +3 -0
- data/spec/dummyapp/app/controllers/application_controller.rb +3 -0
- data/spec/dummyapp/app/controllers/home_controller.rb +21 -0
- data/spec/dummyapp/app/controllers/users_controller.rb +12 -0
- data/spec/dummyapp/app/helpers/application_helper.rb +2 -0
- data/spec/dummyapp/app/helpers/home_helper.rb +2 -0
- data/spec/dummyapp/app/mailers/.gitkeep +0 -0
- data/spec/dummyapp/app/models/.gitkeep +0 -0
- data/spec/dummyapp/app/models/user.rb +11 -0
- data/spec/dummyapp/app/views/devise/registrations/edit.html.erb +27 -0
- data/spec/dummyapp/app/views/devise/registrations/new.html.erb +20 -0
- data/spec/dummyapp/app/views/devise/shared/_links.html.erb +25 -0
- data/spec/dummyapp/app/views/home/cause_exception.html.erb +1 -0
- data/spec/dummyapp/app/views/home/index.html.erb +4 -0
- data/spec/dummyapp/app/views/home/report_exception.html.erb +1 -0
- data/spec/dummyapp/app/views/layouts/_messages.html.erb +5 -0
- data/spec/dummyapp/app/views/layouts/_navigation.html.erb +21 -0
- data/spec/dummyapp/app/views/layouts/application.html.erb +25 -0
- data/spec/dummyapp/app/views/users/index.html.erb +8 -0
- data/spec/dummyapp/app/views/users/show.html.erb +3 -0
- data/spec/dummyapp/config/application.rb +76 -0
- data/spec/dummyapp/config/boot.rb +6 -0
- data/spec/dummyapp/config/cucumber.yml +8 -0
- data/spec/dummyapp/config/environment.rb +5 -0
- data/spec/dummyapp/config/environments/development.rb +54 -0
- data/spec/dummyapp/config/environments/production.rb +87 -0
- data/spec/dummyapp/config/environments/test.rb +41 -0
- data/spec/dummyapp/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummyapp/config/initializers/devise.rb +233 -0
- data/spec/dummyapp/config/initializers/generators.rb +2 -0
- data/spec/dummyapp/config/initializers/inflections.rb +15 -0
- data/spec/dummyapp/config/initializers/mime_types.rb +5 -0
- data/spec/dummyapp/config/initializers/ratchetio.rb +20 -0
- data/spec/dummyapp/config/initializers/secret_token.rb +7 -0
- data/spec/dummyapp/config/initializers/session_store.rb +8 -0
- data/spec/dummyapp/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummyapp/config/locales/devise.en.yml +58 -0
- data/spec/dummyapp/config/locales/en.yml +5 -0
- data/spec/dummyapp/config/routes.rb +11 -0
- data/spec/dummyapp/config.ru +4 -0
- data/spec/dummyapp/db/migrate/20121121184652_devise_create_users.rb +46 -0
- data/spec/dummyapp/db/migrate/20121121184654_add_name_to_users.rb +5 -0
- data/spec/dummyapp/db/schema.rb +35 -0
- data/spec/dummyapp/db/seeds.rb +12 -0
- data/spec/dummyapp/lib/assets/.gitkeep +0 -0
- data/spec/dummyapp/lib/tasks/.gitkeep +0 -0
- data/spec/dummyapp/lib/tasks/cucumber.rake +65 -0
- data/spec/dummyapp/public/404.html +26 -0
- data/spec/dummyapp/public/422.html +26 -0
- data/spec/dummyapp/public/500.html +25 -0
- data/spec/dummyapp/public/favicon.ico +0 -0
- data/spec/dummyapp/public/humans.txt +20 -0
- data/spec/dummyapp/public/robots.txt +5 -0
- data/spec/dummyapp/script/cucumber +10 -0
- data/spec/dummyapp/script/rails +6 -0
- data/spec/dummyapp/vendor/assets/javascripts/.gitkeep +0 -0
- data/spec/dummyapp/vendor/assets/stylesheets/.gitkeep +0 -0
- data/spec/dummyapp/vendor/plugins/.gitkeep +0 -0
- data/spec/ratchetio_spec.rb +233 -1
- data/spec/spec_helper.rb +36 -0
- data/spec/support/devise.rb +3 -0
- metadata +350 -3
@@ -0,0 +1,20 @@
|
|
1
|
+
/* the humans responsible & colophon */
|
2
|
+
/* humanstxt.org */
|
3
|
+
|
4
|
+
|
5
|
+
/* TEAM */
|
6
|
+
<your title>: <your name>
|
7
|
+
Site:
|
8
|
+
Twitter:
|
9
|
+
Location:
|
10
|
+
|
11
|
+
/* THANKS */
|
12
|
+
Daniel Kehoe (@rails_apps) for the RailsApps project
|
13
|
+
|
14
|
+
/* SITE */
|
15
|
+
Standards: HTML5, CSS3
|
16
|
+
Components: jQuery
|
17
|
+
Software: Ruby on Rails
|
18
|
+
|
19
|
+
/* GENERATED BY */
|
20
|
+
RailsApps application template: http://railsapps.github.com/
|
@@ -0,0 +1,10 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
vendored_cucumber_bin = Dir["#{File.dirname(__FILE__)}/../vendor/{gems,plugins}/cucumber*/bin/cucumber"].first
|
4
|
+
if vendored_cucumber_bin
|
5
|
+
load File.expand_path(vendored_cucumber_bin)
|
6
|
+
else
|
7
|
+
require 'rubygems' unless ENV['NO_RUBYGEMS']
|
8
|
+
require 'cucumber'
|
9
|
+
load Cucumber::BINARY
|
10
|
+
end
|
@@ -0,0 +1,6 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
|
3
|
+
|
4
|
+
APP_PATH = File.expand_path('../../config/application', __FILE__)
|
5
|
+
require File.expand_path('../../config/boot', __FILE__)
|
6
|
+
require 'rails/commands'
|
File without changes
|
File without changes
|
File without changes
|
data/spec/ratchetio_spec.rb
CHANGED
@@ -1,3 +1,235 @@
|
|
1
|
-
|
1
|
+
require 'socket'
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Ratchetio do
|
5
|
+
|
6
|
+
it 'controller methods'
|
7
|
+
|
8
|
+
context 'report_exception' do
|
9
|
+
before(:each) do
|
10
|
+
configure
|
11
|
+
Ratchetio.configure do |config|
|
12
|
+
config.logger = logger_mock
|
13
|
+
end
|
14
|
+
|
15
|
+
begin
|
16
|
+
foo = bar
|
17
|
+
rescue => e
|
18
|
+
@exception = e
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
let(:logger_mock) { double("Rails.logger").as_null_object }
|
23
|
+
|
24
|
+
it 'should report exceptions without person or request data' do
|
25
|
+
logger_mock.should_receive(:info).with('[Ratchet.io] Sending payload')
|
26
|
+
Ratchetio.report_exception(@exception)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should report exceptions with request and person data' do
|
30
|
+
logger_mock.should_receive(:info).with('[Ratchet.io] Sending payload')
|
31
|
+
request_data = {
|
32
|
+
:params => { :foo => "bar" },
|
33
|
+
:url => 'http://localhost/',
|
34
|
+
:user_ip => '127.0.0.1',
|
35
|
+
:headers => {},
|
36
|
+
:GET => { "baz" => "boz" },
|
37
|
+
:session => { :user_id => 123 },
|
38
|
+
:method => "GET",
|
39
|
+
}
|
40
|
+
person_data = {
|
41
|
+
:id => 1,
|
42
|
+
:username => "test",
|
43
|
+
:email => "test@example.com"
|
44
|
+
}
|
45
|
+
Ratchetio.report_exception(@exception, request_data, person_data)
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'should ignore ignored exception classes' do
|
49
|
+
saved_filters = Ratchetio.configuration.exception_level_filters
|
50
|
+
Ratchetio.configure do |config|
|
51
|
+
config.exception_level_filters = { 'NameError' => 'ignore' }
|
52
|
+
end
|
53
|
+
|
54
|
+
logger_mock.should_not_receive(:info)
|
55
|
+
logger_mock.should_not_receive(:warn)
|
56
|
+
logger_mock.should_not_receive(:error)
|
57
|
+
|
58
|
+
Ratchetio.report_exception(@exception)
|
59
|
+
|
60
|
+
Ratchetio.configure do |config|
|
61
|
+
config.exception_level_filters = saved_filters
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
context 'report_message' do
|
67
|
+
before(:each) do
|
68
|
+
configure
|
69
|
+
Ratchetio.configure do |config|
|
70
|
+
config.logger = logger_mock
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
let(:logger_mock) { double("Rails.logger").as_null_object }
|
75
|
+
|
76
|
+
it 'should report simple messages' do
|
77
|
+
logger_mock.should_receive(:info).with('[Ratchet.io] Sending payload')
|
78
|
+
Ratchetio.report_message("Test message")
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'should report messages with extra data' do
|
82
|
+
logger_mock.should_receive(:info).with('[Ratchet.io] Sending payload')
|
83
|
+
Ratchetio.report_message("Test message with extra data", 'debug', :foo => "bar",
|
84
|
+
:hash => { :a => 123, :b => "xyz" })
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'should not crash with circular extra_data' do
|
88
|
+
a = { :foo => "bar" }
|
89
|
+
b = { :a => a }
|
90
|
+
c = { :b => b }
|
91
|
+
a[:c] = c
|
92
|
+
|
93
|
+
logger_mock.should_receive(:error).with('[Ratchet.io] Error reporting message to Ratchet.io: object references itself')
|
94
|
+
Ratchetio.report_message("Test message with extra data", 'debug', a)
|
95
|
+
end
|
96
|
+
|
97
|
+
after(:each) do
|
98
|
+
Ratchetio.configure do |config|
|
99
|
+
config.logger = ::Rails.logger
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
context 'message_data' do
|
105
|
+
before(:each) do
|
106
|
+
configure
|
107
|
+
@message_body = "This is a test"
|
108
|
+
@level = 'debug'
|
109
|
+
end
|
110
|
+
|
111
|
+
it 'should build a message' do
|
112
|
+
data = Ratchetio.send(:message_data, @message_body, @level, {})
|
113
|
+
data[:body][:message][:body].should == @message_body
|
114
|
+
data[:level].should == @level
|
115
|
+
end
|
116
|
+
|
117
|
+
it 'should accept extra_data' do
|
118
|
+
user_id = 123
|
119
|
+
name = "Tester"
|
120
|
+
|
121
|
+
data = Ratchetio.send(:message_data, @message_body, 'info',
|
122
|
+
:user_id => user_id, :name => name)
|
123
|
+
|
124
|
+
message = data[:body][:message]
|
125
|
+
message[:body].should == @message_body
|
126
|
+
message[:user_id].should == user_id
|
127
|
+
message[:name].should == name
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
context 'exception_data' do
|
132
|
+
before(:each) do
|
133
|
+
configure
|
134
|
+
begin
|
135
|
+
foo = bar
|
136
|
+
rescue => e
|
137
|
+
@exception = e
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
it 'should accept force_level' do
|
142
|
+
level = 'critical'
|
143
|
+
data = Ratchetio.send(:exception_data, @exception, level)
|
144
|
+
data[:level].should == level
|
145
|
+
end
|
146
|
+
|
147
|
+
it 'should build valid exception data' do
|
148
|
+
data = Ratchetio.send(:exception_data, @exception)
|
149
|
+
|
150
|
+
data[:level].should_not be_nil
|
151
|
+
|
152
|
+
trace = data[:body][:trace]
|
153
|
+
|
154
|
+
frames = trace[:frames]
|
155
|
+
frames.should be_a_kind_of(Array)
|
156
|
+
frames.each do |frame|
|
157
|
+
frame[:filename].should be_a_kind_of(String)
|
158
|
+
frame[:method].should be_a_kind_of(String)
|
159
|
+
frame[:lineno].should be_a_kind_of(Fixnum)
|
160
|
+
end
|
161
|
+
|
162
|
+
trace[:exception][:class].should == 'NameError'
|
163
|
+
trace[:exception][:message].should match(/^undefined local variable or method `bar' for/)
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
context 'logger' do
|
168
|
+
it 'should have its logger configured' do
|
169
|
+
configure
|
170
|
+
Ratchetio.send(:logger).should == ::Rails.logger
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
context 'build_payload' do
|
175
|
+
it 'should build valid json' do
|
176
|
+
json = Ratchetio.send(:build_payload, {:foo => {:bar => "baz"}})
|
177
|
+
hash = ActiveSupport::JSON.decode(json)
|
178
|
+
hash["data"]["foo"]["bar"].should == "baz"
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
context 'base_data' do
|
183
|
+
before(:each) do
|
184
|
+
configure
|
185
|
+
end
|
186
|
+
|
187
|
+
it 'should have the correct notifier name' do
|
188
|
+
Ratchetio.send(:base_data)[:notifier][:name].should == 'ratchetio-gem'
|
189
|
+
end
|
190
|
+
|
191
|
+
it 'should have the correct notifier version' do
|
192
|
+
Ratchetio.send(:base_data)[:notifier][:version].should == Ratchetio::VERSION
|
193
|
+
end
|
194
|
+
|
195
|
+
it 'should have all the required keys' do
|
196
|
+
data = Ratchetio.send(:base_data)
|
197
|
+
data[:timestamp].should_not be_nil
|
198
|
+
data[:environment].should_not be_nil
|
199
|
+
data[:level].should_not be_nil
|
200
|
+
data[:language].should == 'ruby'
|
201
|
+
data[:framework].should match(/^Rails/)
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
context 'server_data' do
|
206
|
+
it 'should have the right hostname' do
|
207
|
+
Ratchetio.send(:server_data)[:host] == Socket.gethostname
|
208
|
+
end
|
209
|
+
|
210
|
+
it 'should have root and branch set when configured' do
|
211
|
+
configure
|
212
|
+
Ratchetio.configure do |config|
|
213
|
+
config.root = '/path/to/root'
|
214
|
+
config.branch = 'master'
|
215
|
+
end
|
216
|
+
|
217
|
+
data = Ratchetio.send(:server_data)
|
218
|
+
data[:root].should == '/path/to/root'
|
219
|
+
data[:branch].should == 'master'
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
# configure with some basic params
|
224
|
+
def configure
|
225
|
+
Ratchetio.configure do |config|
|
226
|
+
# special test access token
|
227
|
+
config.access_token = 'aaaabbbbccccddddeeeeffff00001111'
|
228
|
+
config.logger = ::Rails.logger
|
229
|
+
config.environment = ::Rails.env
|
230
|
+
config.root = ::Rails.root
|
231
|
+
config.framework = "Rails: #{::Rails::VERSION::STRING}"
|
232
|
+
end
|
233
|
+
end
|
2
234
|
|
3
235
|
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
#require 'rspec'
|
2
|
+
#require 'ratchetio'
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
|
6
|
+
ENV['RAILS_ENV'] ||= 'test'
|
7
|
+
require File.expand_path('../dummyapp/config/environment', __FILE__)
|
8
|
+
require 'rspec/rails'
|
9
|
+
require 'factory_girl_rails'
|
10
|
+
require 'database_cleaner'
|
11
|
+
|
12
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| puts f; require f }
|
13
|
+
FactoryGirl.definition_file_paths = [ File.join(Rails.root, '../factories') ]
|
14
|
+
|
15
|
+
RSpec.configure do |config|
|
16
|
+
config.color_enabled = true
|
17
|
+
config.formatter = 'documentation'
|
18
|
+
|
19
|
+
config.use_transactional_fixtures = true
|
20
|
+
config.order = "random"
|
21
|
+
|
22
|
+
config.before(:suite) do
|
23
|
+
FactoryGirl.reload
|
24
|
+
DatabaseCleaner.strategy = :truncation
|
25
|
+
end
|
26
|
+
|
27
|
+
config.before(:each) do
|
28
|
+
DatabaseCleaner.start
|
29
|
+
DatabaseCleaner.clean
|
30
|
+
end
|
31
|
+
|
32
|
+
config.after(:each) do
|
33
|
+
DatabaseCleaner.clean
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|