Skip to content

Commit

Permalink
return block result in with_current_user method
Browse files Browse the repository at this point in the history
  • Loading branch information
loadkpi committed May 18, 2018
1 parent f0618d0 commit 22b70cc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
3 changes: 2 additions & 1 deletion lib/sequel/plugins/bulk_audit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions spec/sequel/plugins/bulk_audit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 22b70cc

Please sign in to comment.