File: empty_failure_backtraces_spec.rb

package info (click to toggle)
ruby-sequel 5.63.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 10,408 kB
  • sloc: ruby: 113,747; makefile: 3
file content (60 lines) | stat: -rw-r--r-- 1,559 bytes parent folder | download | duplicates (3)
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
require_relative "spec_helper"

describe "empty_failure_backtraces plugin" do
  before do
    @c = Class.new(Sequel::Model(:items)) do
      plugin :empty_failure_backtraces
      columns :x
      set_primary_key :x
      unrestrict_primary_key
      def before_create
        super
        cancel_action 'bc' if x == 2
      end
      def before_destroy
        super
        cancel_action 'bd' if x == 2
      end
      def validate
        super
        errors.add(:x, "3") if x == 3
      end
    end
    DB.reset
  end
  
  it "should work normally if no exceptions are thrown/raised" do
    o = @c.create(:x=>1)
    o.must_be_kind_of @c
    o.valid?.must_equal true
    o.destroy.must_equal o
  end

  it "should work normally when not rescuing exceptions internally when calling save" do
    @c.new.set(:x => 2).save(:raise_on_failure=>false).must_be_nil
    @c.raise_on_save_failure = false
    @c.create(:x => 2).must_be_nil
    @c.load(:x => 2).destroy(:raise_on_failure=>false).must_be_nil
  end
    
  it "should work normally when not rescuing exceptions internally when calling valid?" do
    @c.send(:define_method, :before_validation){cancel_action "bv"}
    @c.new(:x => 2).valid?.must_equal false
  end

  it "should raise exceptions with empty backtraces" do
    begin
      @c.create(:x => 2)
    rescue Sequel::HookFailed => e 
      e.backtrace.must_be_empty
      1
    end.must_equal 1

    begin
      @c.create(:x => 3)
    rescue Sequel::ValidationFailed => e 
      e.backtrace.must_be_empty
      1
    end.must_equal 1
  end
end