File tree Expand file tree Collapse file tree 2 files changed +85
-0
lines changed
spec/integration/hati_command Expand file tree Collapse file tree 2 files changed +85
-0
lines changed Original file line number Diff line number Diff line change @@ -95,4 +95,34 @@ def execute(message)
9595 end
9696 end
9797 end
98+
99+ # TODO: load ActiveRecord !!!!!
100+ # describe 'ActiveRecord transaction wrapping' do
101+ # before do
102+ # stub_const(
103+ # 'MyDummyExecBefehl',
104+ # Class.new(befehl_klass) do
105+ # command do
106+ # ar_transaction :call
107+ # end
108+
109+ # def call(message)
110+ # HatiCommand::Success.new(message)
111+ # end
112+ # end
113+ # )
114+ # end
115+
116+ # describe '.execute' do
117+ # let(:rez_msg) { 'This is a result AR transaction message' }
118+ # let(:result) { MyDummyExecBefehl.call(rez_msg) }
119+
120+ # it 'returns success' do
121+ # aggregate_failures do
122+ # expect(result).to be_a(HatiCommand::Success)
123+ # expect(result.value).to eq(rez_msg)
124+ # end
125+ # end
126+ # end
127+ # end
98128end
Original file line number Diff line number Diff line change 1+ # frozen_string_literal: true
2+
3+ require 'spec_helper'
4+ require 'active_record'
5+ # require_relative 'support/active_record'
6+
7+ ActiveRecord ::Base . establish_connection (
8+ adapter : 'sqlite3' ,
9+ database : ':memory:'
10+ )
11+
12+ ActiveRecord ::Schema . define do
13+ create_table :widgets , force : true do |t |
14+ t . string :name
15+ t . timestamps
16+ end
17+ end
18+
19+ class Widget < ActiveRecord ::Base ; end
20+
21+ RSpec . describe HatiCommand ::Befehl do
22+ let ( :befehl_klass ) { support_dummy_befehl ( 'DummyBefehl' ) }
23+
24+ describe 'ActiveRecord transaction wrapping' do
25+ before do
26+ stub_const (
27+ 'MyDummyExecBefehl' ,
28+ Class . new ( befehl_klass ) do
29+ command do
30+ ar_transaction :call
31+ end
32+
33+ def call ( message )
34+ raise ActiveRecord ::Rollback if message == 'fail'
35+
36+ Widget . create! ( name : message )
37+ HatiCommand ::Success . new ( message )
38+ end
39+ end
40+ )
41+ end
42+
43+ it 'commits the transaction on success' do
44+ expect { MyDummyExecBefehl . call ( 'Widget1' ) } . to change { Widget . count } . by ( 1 )
45+ end
46+
47+ it 'rolls back the transaction on failure' do
48+ expect do
49+ MyDummyExecBefehl . call ( 'fail' )
50+ rescue StandardError
51+ nil
52+ end . not_to ( change { Widget . count } )
53+ end
54+ end
55+ end
You can’t perform that action at this time.
0 commit comments