@@ -787,8 +787,12 @@ def capture_exception
787787 Mongoid ::Clients . with_name ( :default ) . database . collections . each ( &:drop )
788788 TransactionsSpecPerson . collection . create
789789 TransactionsSpecPersonWithOnCreate . collection . create
790+ TransactionsSpecPersonWithAfterCreateCommit . collection . create
790791 TransactionsSpecPersonWithOnUpdate . collection . create
792+ TransactionsSpecPersonWithAfterUpdateCommit . collection . create
793+ TransactionsSpecPersonWithAfterSaveCommit . collection . create
791794 TransactionsSpecPersonWithOnDestroy . collection . create
795+ TransactionsSpecPersonWithAfterDestroyCommit . collection . create
792796 TransactionSpecRaisesBeforeSave . collection . create
793797 TransactionSpecRaisesAfterSave . collection . create
794798 end
@@ -818,6 +822,18 @@ def capture_exception
818822
819823 it_behaves_like 'commit callbacks are called'
820824 end
825+
826+ context 'when callback is after_create_commit' do
827+ let! ( :subject ) do
828+ person = nil
829+ TransactionsSpecPersonWithAfterCreateCommit . transaction do
830+ person = TransactionsSpecPersonWithAfterCreateCommit . create! ( name : 'James Bond' )
831+ end
832+ person
833+ end
834+
835+ it_behaves_like 'commit callbacks are called'
836+ end
821837 end
822838
823839 context 'save' do
@@ -886,6 +902,94 @@ def capture_exception
886902 it_behaves_like 'commit callbacks are called'
887903 end
888904 end
905+
906+ context 'with after_update_commit callback' do
907+ let ( :subject ) do
908+ TransactionsSpecPersonWithAfterUpdateCommit . create! ( name : 'James Bond' ) . tap do |subject |
909+ subject . after_commit_counter . reset
910+ subject . after_rollback_counter . reset
911+ end
912+ end
913+
914+ context 'when modified once' do
915+ before do
916+ subject . transaction do
917+ subject . name = 'Austin Powers'
918+ subject . save!
919+ end
920+ end
921+
922+ it_behaves_like 'commit callbacks are called'
923+ end
924+
925+ context 'when modified multiple times' do
926+ before do
927+ subject . transaction do
928+ subject . name = 'Austin Powers'
929+ subject . save!
930+ subject . name = 'Jason Bourne'
931+ subject . save!
932+ end
933+ end
934+
935+ it_behaves_like 'commit callbacks are called'
936+ end
937+ end
938+
939+ context 'with after_save_commit callback' do
940+ let ( :subject ) do
941+ TransactionsSpecPersonWithAfterSaveCommit . create! ( name : 'James Bond' ) . tap do |subject |
942+ subject . after_commit_counter . reset
943+ subject . after_rollback_counter . reset
944+ end
945+ end
946+
947+ context 'when modified once' do
948+ before do
949+ subject . transaction do
950+ subject . name = 'Austin Powers'
951+ subject . save!
952+ end
953+ end
954+
955+ it_behaves_like 'commit callbacks are called'
956+ end
957+
958+ context 'when created' do
959+ before do
960+ TransactionsSpecPersonWithAfterSaveCommit . transaction do
961+ subject
962+ end
963+ end
964+
965+ it_behaves_like 'commit callbacks are called'
966+ end
967+
968+ context 'when modified multiple times' do
969+ before do
970+ subject . transaction do
971+ subject . name = 'Austin Powers'
972+ subject . save!
973+ subject . name = 'Jason Bourne'
974+ subject . save!
975+ end
976+ end
977+
978+ it_behaves_like 'commit callbacks are called'
979+ end
980+
981+ context 'when created and modified' do
982+ before do
983+ TransactionsSpecPersonWithAfterSaveCommit . transaction do
984+ subject
985+ subject . name = 'Jason Bourne'
986+ subject . save!
987+ end
988+ end
989+
990+ it_behaves_like 'commit callbacks are called'
991+ end
992+ end
889993 end
890994
891995 context 'update_attributes' do
@@ -919,6 +1023,34 @@ def capture_exception
9191023
9201024 it_behaves_like 'commit callbacks are called'
9211025 end
1026+
1027+ context 'when callback is after_update_commit' do
1028+ let ( :subject ) do
1029+ TransactionsSpecPersonWithAfterUpdateCommit . create! ( name : 'Jason Bourne' )
1030+ end
1031+
1032+ before do
1033+ TransactionsSpecPersonWithAfterUpdateCommit . transaction do
1034+ subject . update_attributes! ( name : 'Foma Kiniaev' )
1035+ end
1036+ end
1037+
1038+ it_behaves_like 'commit callbacks are called'
1039+ end
1040+
1041+ context 'when callback is after_save_commit' do
1042+ let ( :subject ) do
1043+ TransactionsSpecPersonWithAfterSaveCommit . create! ( name : 'Jason Bourne' )
1044+ end
1045+
1046+ before do
1047+ TransactionsSpecPersonWithAfterSaveCommit . transaction do
1048+ subject . update_attributes! ( name : 'Foma Kiniaev' )
1049+ end
1050+ end
1051+
1052+ it_behaves_like 'commit callbacks are called'
1053+ end
9221054 end
9231055
9241056 context 'destroy' do
@@ -971,6 +1103,31 @@ def capture_exception
9711103
9721104 it_behaves_like 'commit callbacks are called'
9731105 end
1106+
1107+ context 'with after_destroy_commit' do
1108+ let ( :after_commit_counter ) do
1109+ TransactionsSpecCounter . new
1110+ end
1111+
1112+ let ( :after_rollback_counter ) do
1113+ TransactionsSpecCounter . new
1114+ end
1115+
1116+ let ( :subject ) do
1117+ TransactionsSpecPersonWithAfterDestroyCommit . create! ( name : 'James Bond' ) . tap do |p |
1118+ p . after_commit_counter = after_commit_counter
1119+ p . after_rollback_counter = after_rollback_counter
1120+ end
1121+ end
1122+
1123+ before do
1124+ subject . transaction do
1125+ subject . destroy
1126+ end
1127+ end
1128+
1129+ it_behaves_like 'commit callbacks are called'
1130+ end
9741131 end
9751132 end
9761133
0 commit comments