Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 90 lines (69 sloc) 2.381 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
require 'dm-core'
require 'dm-migrations'
require 'slf4r/ruby_logger'
require 'ixtlan/errors/resource'

Error = Ixtlan::Errors::Error

require 'pony'
Pony.options = { :via => :test }

require 'ixtlan/errors/dumper'
require 'date'
require 'logger'

class Controller < Hash

  def request
    self
  end
  def env
    @env ||= {:one => 1, :two => 2, :three => 3}
  end

  def response
    self
  end

  def headers
    @headers ||= { 'ONE' => 1, "TWO" => 2 }
  end

  def session
    @session ||= { "user" => "me" }
  end

  def params
    @params ||= { :query => "all" }
  end
end

DataMapper.setup(:default, "sqlite3::memory:")
DataMapper.finalize
DataMapper.auto_migrate!

describe Ixtlan::Errors::Dumper do

  before :each do
    @dumper = Ixtlan::Errors::Dumper.new
    @dumper.send :instance_variable_set, '@keep_dumps'.to_sym, 1
    @dumper.model = Error
    @dumper.base_url = "http://localhost"
    @controller = Controller.new
  end

  it "should dump env and not send notification" do
    send = @dumper.dump(StandardError.new("dump it"), @controller.request, @controller.response, @controller.session, @controller.params)
    send.should be_false

    @dumper.from_email = "asd"
    send = @dumper.dump(StandardError.new("dump it"), @controller.request, @controller.response, @controller.session, @controller.params)
    send.should be_false

    @dumper.from_email = nil
    @dumper.to_emails = "dsa"
    send = @dumper.dump(StandardError.new("dump it"), @controller.request, @controller.response, @controller.session, @controller.params)
    send.should be_false
  end

  it "should clean up error dumps" do
    Error.create(:message => 'msg', :clazz => StandardError.to_s)
    Error.all.size.should > 0
    @dumper.keep_dumps = 0
    Error.all.size.should == 0

    @dumper.dump(StandardError.new("dump it"), @controller.request, @controller.response, @controller.session, @controller.params)
    Error.all.size.should == 1

    @dumper.dump(StandardError.new("dump it"), @controller.request, @controller.response, @controller.session, @controller.params)
    Error.all.size.should == 2
  end

  it "should send notifications" do
    @dumper.to_emails = "das"
    @dumper.from_email = "asd"
    
    send = @dumper.dump(StandardError.new("dump it"), @controller.request, @controller.response, @controller.session, @controller.params)
    send.should be_true
  end
end
Something went wrong with that request. Please try again.