2013-02-05 14:16:51 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
describe ErrorLog do
|
|
|
|
|
|
|
|
def boom
|
|
|
|
raise "boom"
|
|
|
|
end
|
|
|
|
|
2013-02-25 11:42:20 -05:00
|
|
|
def exception
|
|
|
|
begin
|
2013-02-05 14:16:51 -05:00
|
|
|
boom
|
|
|
|
rescue => e
|
|
|
|
return e
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def controller
|
|
|
|
DraftController.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def request
|
2013-03-23 11:02:59 -04:00
|
|
|
ActionController::TestRequest.new(host: 'test')
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "add_row!" do
|
|
|
|
it "creates a non empty file on first call" do
|
|
|
|
ErrorLog.clear_all!
|
|
|
|
ErrorLog.add_row!(hello: "world")
|
2014-09-25 11:44:48 -04:00
|
|
|
File.exists?(ErrorLog.filename).should == true
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-02-25 11:42:20 -05:00
|
|
|
describe "logging data" do
|
2013-02-05 14:16:51 -05:00
|
|
|
it "is able to read the data it writes" do
|
|
|
|
ErrorLog.clear_all!
|
|
|
|
ErrorLog.report!(exception, controller, request, nil)
|
|
|
|
ErrorLog.report!(exception, controller, request, nil)
|
|
|
|
i = 0
|
2013-02-25 11:42:20 -05:00
|
|
|
ErrorLog.each do |h|
|
2013-02-05 14:16:51 -05:00
|
|
|
i += 1
|
2013-02-25 11:42:20 -05:00
|
|
|
end
|
2013-02-05 14:16:51 -05:00
|
|
|
i.should == 2
|
|
|
|
end
|
|
|
|
|
2013-02-25 11:42:20 -05:00
|
|
|
it "is able to skip rows" do
|
2013-02-05 14:16:51 -05:00
|
|
|
ErrorLog.clear_all!
|
|
|
|
ErrorLog.report!(exception, controller, request, nil)
|
|
|
|
ErrorLog.report!(exception, controller, request, nil)
|
|
|
|
ErrorLog.report!(exception, controller, request, nil)
|
|
|
|
ErrorLog.report!(exception, controller, request, nil)
|
|
|
|
i = 0
|
2013-02-25 11:42:20 -05:00
|
|
|
ErrorLog.skip(3) do |h|
|
2013-02-05 14:16:51 -05:00
|
|
|
i += 1
|
|
|
|
end
|
|
|
|
i.should == 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-02-25 11:42:20 -05:00
|
|
|
end
|