diff --git a/lib/sequel/plugins/bulk_audit.rb b/lib/sequel/plugins/bulk_audit.rb index 7f00f48..4e88bcf 100644 --- a/lib/sequel/plugins/bulk_audit.rb +++ b/lib/sequel/plugins/bulk_audit.rb @@ -29,8 +29,9 @@ def with_current_user(current_user, attributes = nil) Sequel.pg_jsonb(model_to_table_map).as(:model_map), Sequel.pg_jsonb(attributes || {}).as(:data)) self.db.create_table!(:__audit_info, temp: true, as: data) - yield if block_given? + result = yield if block_given? self.db.drop_table?(:__audit_info) + result end end end diff --git a/spec/sequel/plugins/bulk_audit_spec.rb b/spec/sequel/plugins/bulk_audit_spec.rb index b54d1cd..f31b446 100644 --- a/spec/sequel/plugins/bulk_audit_spec.rb +++ b/spec/sequel/plugins/bulk_audit_spec.rb @@ -112,10 +112,11 @@ class MyData < Sequel::Model(:data) one_to_many :audit_logs, as: :model end MyData.class_variable_set(:@@model_to_table_map, nil) - rec = nil - model.with_current_user(current_user) do - rec = MyData.create(value: 5) + rec = model.with_current_user(current_user) do + MyData.create(value: 5) end + expect(rec).to be_instance_of(MyData) + expect(DB[:audit_logs].all).to include( a_hash_including( event: "INSERT",