discourse/spec/models/error_log_spec.rb

59 lines
1.2 KiB
Ruby
Raw Normal View History

2013-02-06 03:16:51 +08:00
require 'spec_helper'
describe ErrorLog do
def boom
raise "boom"
end
2013-02-26 00:42:20 +08:00
def exception
begin
2013-02-06 03:16:51 +08:00
boom
rescue => e
return e
end
end
def controller
DraftController.new
end
def request
ActionController::TestRequest.new(host: 'test')
2013-02-06 03:16:51 +08:00
end
describe "add_row!" do
it "creates a non empty file on first call" do
ErrorLog.clear_all!
ErrorLog.add_row!(hello: "world")
File.exists?(ErrorLog.filename).should == true
2013-02-06 03:16:51 +08:00
end
end
2013-02-26 00:42:20 +08:00
describe "logging data" do
2013-02-06 03:16:51 +08: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-26 00:42:20 +08:00
ErrorLog.each do |h|
2013-02-06 03:16:51 +08:00
i += 1
2013-02-26 00:42:20 +08:00
end
2013-02-06 03:16:51 +08:00
i.should == 2
end
2013-02-26 00:42:20 +08:00
it "is able to skip rows" do
2013-02-06 03:16:51 +08: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-26 00:42:20 +08:00
ErrorLog.skip(3) do |h|
2013-02-06 03:16:51 +08:00
i += 1
end
i.should == 1
end
end
2013-02-26 00:42:20 +08:00
end