@@ -787,8 +787,12 @@ def capture_exception
787
787
Mongoid ::Clients . with_name ( :default ) . database . collections . each ( &:drop )
788
788
TransactionsSpecPerson . collection . create
789
789
TransactionsSpecPersonWithOnCreate . collection . create
790
+ TransactionsSpecPersonWithAfterCreateCommit . collection . create
790
791
TransactionsSpecPersonWithOnUpdate . collection . create
792
+ TransactionsSpecPersonWithAfterUpdateCommit . collection . create
793
+ TransactionsSpecPersonWithAfterSaveCommit . collection . create
791
794
TransactionsSpecPersonWithOnDestroy . collection . create
795
+ TransactionsSpecPersonWithAfterDestroyCommit . collection . create
792
796
TransactionSpecRaisesBeforeSave . collection . create
793
797
TransactionSpecRaisesAfterSave . collection . create
794
798
end
@@ -818,6 +822,18 @@ def capture_exception
818
822
819
823
it_behaves_like 'commit callbacks are called'
820
824
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
821
837
end
822
838
823
839
context 'save' do
@@ -886,6 +902,94 @@ def capture_exception
886
902
it_behaves_like 'commit callbacks are called'
887
903
end
888
904
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
889
993
end
890
994
891
995
context 'update_attributes' do
@@ -919,6 +1023,34 @@ def capture_exception
919
1023
920
1024
it_behaves_like 'commit callbacks are called'
921
1025
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
922
1054
end
923
1055
924
1056
context 'destroy' do
@@ -971,6 +1103,31 @@ def capture_exception
971
1103
972
1104
it_behaves_like 'commit callbacks are called'
973
1105
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
974
1131
end
975
1132
end
976
1133
0 commit comments