Sha256: 4b5778034610e2fa1b8d4cfec3601824e3432d4e69564d693747121ec7b0728b

Contents?: true

Size: 1.14 KB

Versions: 1

Compression:

Stored size: 1.14 KB

Contents

require File.expand_path(File.dirname(__FILE__) + '/spec_helper')

require 'models/tester'
require 'models/another_model'

describe "AfterCommitAction" do
  it "should correctly execute tasks after commit" do
    t = Tester.new
    expect(t.array).to be_empty
    t.save!
    expect(t.array.size).to eq(2)
    expect(t.array).to include('before_create')
    expect(t.array).to include('after_create')

    t = Tester.first
    expect(t.array).to be_empty
    t.save!
    expect(t.array.size).to eq(2)
    expect(t.array).to include('before_update')
    expect(t.array).to include('after_update')
  end

  context 'when block is executed in another model transaction' do
    let(:tester)        { Tester.create count: 0 }
    let(:another_model) { AnotherModel.new tester: tester }

    subject {}

    it "increments the counter" do
      expect { another_model.save! }.to change { tester.reload.count }.from(0).to 1
    end
  end

  context 'when there is no transaction' do
    let(:tester) { Tester.create count: 0 }

    it "increments the counter" do
      expect { tester.increment_counter }.to change { tester.reload.count }.from(0).to 1
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
after_commit_action-1.1.0 spec/after_commit_action_spec.rb