diff --git a/README.md b/README.md index 666512a..a0735d3 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/lib/generators/audit_migration/USAGE b/lib/generators/audit_migration/USAGE index f62a798..c5a386e 100644 --- a/lib/generators/audit_migration/USAGE +++ b/lib/generators/audit_migration/USAGE @@ -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 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/sequel-bulk-audit.gemspec b/sequel-bulk-audit.gemspec index e1b50a9..91b0664 100644 --- a/sequel-bulk-audit.gemspec +++ b/sequel-bulk-audit.gemspec @@ -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" } 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",