File tree Expand file tree Collapse file tree 4 files changed +21
-1
lines changed
Expand file tree Collapse file tree 4 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,12 @@ class InstallGenerator < Rails::Generators::Base
2323 def copy_migration
2424 migration_template "install.rb" , "db/migrate/install_audited.rb"
2525 end
26+
27+ def create_custom_audit
28+ return if options [ :audited_table_name ] == "audits"
29+
30+ template "custom_audit.rb" , "app/models/#{ options [ :audited_table_name ] . singularize . underscore } .rb"
31+ end
2632 end
2733 end
2834end
Original file line number Diff line number Diff line change 1+ # frozen_string_literal: true
2+
3+ <% table_name = options [ :audited_table_name ] . underscore . pluralize %>
4+ class <%= table_name.singularize.classify %> < Audited ::Audit
5+ self . table_name = "<%= table_name %>"
6+ end
Original file line number Diff line number Diff line change 11# frozen_string_literal: true
22
3- <% table_name = options [ :audited_table_name ] %>
3+ <% table_name = options [ :audited_table_name ] . underscore . pluralize %>
44class <%= migration_class_name %> < <%= migration_parent %>
55 def self.up
66 create_table :<%= table_name %> , :force => true do |t |
Original file line number Diff line number Diff line change @@ -59,4 +59,12 @@ class InstallGeneratorTest < Rails::Generators::TestCase
5959 assert_includes ( content , "class InstallAudited < ActiveRecord::Migration[#{ ActiveRecord ::Migration . current_version } ]\n " )
6060 end
6161 end
62+
63+ test "generate custom audit" do
64+ run_generator %w[ --audited-table-name custom_audits ]
65+
66+ assert_file "app/models/custom_audit.rb" do |content |
67+ assert_includes ( content , "class CustomAudit < Audited::Audit" )
68+ end
69+ end
6270end
You can’t perform that action at this time.
0 commit comments