File: after_commit_queue_test.rb

package info (click to toggle)
ruby-after-commit-queue 1.3.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster, forky, sid, trixie
  • size: 296 kB
  • sloc: ruby: 217; makefile: 2
file content (69 lines) | stat: -rw-r--r-- 1,371 bytes parent folder | download | duplicates (2)
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
require 'test_helper'

class AfterCommitQueueTest < ActiveSupport::TestCase
  def setup
    @server = Server.new
  end

  test "run methods after transaction is committed" do
    assert !@server.started

    @server.transaction do
      @server.start!
      assert !@server.started
    end

    assert @server.started
  end

  test "run blocks after transaction is committed" do
    @server.start!
    assert !@server.meditating

    @server.transaction do
      @server.crash!
      assert !@server.meditating
    end

    assert @server.meditating
  end

  test "external observer changes state" do
    @server.start!
    @server.stop!
    assert !@server.uninstalled

    @server.transaction do
      @server.uninstall!
      assert !@server.uninstalled
    end

    assert @server.uninstalled
  end
  
  test "clear queue after methods from are called" do
    @server.start!
    @server.started = false

    @server.stop!
    assert !@server.started
    assert @server.stopped
  end

  test "clears queue after rollback" do
    assert !@server.started

    Server.transaction do
      @server.start!
      assert !@server.started
      raise ActiveRecord::Rollback
    end

    assert @server.__send__(:_after_commit_queue).empty?
    assert !@server.started
  end

  test "clears queue even when no callback was enqueued" do
    @server.rolledback!(false)
  end
end