Skip to content

Commit

Permalink
Merge pull request #1 from loadkpi/feature-return-block-result
Browse files Browse the repository at this point in the history
Improvement of #with_current_user result
  • Loading branch information
fiscal-cliff authored May 18, 2018
2 parents f0618d0 + 88c3090 commit 18e10d0
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Or install it yourself as:

$ gem install sequel-bulk-audit

After Installation you should run ```rails g audit_install``` generator.
After Installation you should run ```rails g audit_migration``` generator.

You can exdend this migration by attaching the trigger to audited tables.

Expand Down
2 changes: 1 addition & 1 deletion lib/generators/audit_migration/USAGE
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Description:
You can attach the trigger to tables here.

Example:
rails generate audit_miogration
rails generate audit_migration

This will create:
what/will/it/create
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
2 changes: 1 addition & 1 deletion sequel-bulk-audit.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Gem::Specification.new do |spec|
spec.description = %q{Every update on audited table will be logged. You can update the table in bulk}
spec.homepage = "https://github.com/fiscal-cliff/sequel-bulk-audit/"
spec.post_install_message = %q{ Next steps:
1. Run rails g audit_install
1. Run rails g audit_migration
2. Edit generated migration
3. Apply the migration"
}
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 18e10d0

Please sign in to comment.