mirror of
https://github.com/paper-trail-gem/paper_trail.git
synced 2022-11-09 11:33:19 -05:00
Change install generator to use new hash syntax
The install generator used literal Ruby hashes to build options for the item_type field. This change modifies the generator to use string literal output, which is consistent with the other option building method in the generator. Co-authored-by: Jared Beck <jared@jaredbeck.com>
This commit is contained in:
parent
1e56afdf84
commit
f7fe9cfd1e
2 changed files with 13 additions and 3 deletions
|
@ -40,9 +40,11 @@ module PaperTrail
|
|||
# MySQL 5.6 utf8mb4 limit is 191 chars for keys used in indexes.
|
||||
# See https://github.com/paper-trail-gem/paper_trail/issues/651
|
||||
def item_type_options
|
||||
opt = { null: false }
|
||||
opt[:limit] = 191 if mysql?
|
||||
", #{opt}"
|
||||
if mysql?
|
||||
", { null: false, limit: 191 }"
|
||||
else
|
||||
", { null: false }"
|
||||
end
|
||||
end
|
||||
|
||||
def mysql?
|
||||
|
|
|
@ -35,6 +35,13 @@ RSpec.describe PaperTrail::InstallGenerator, type: :generator do
|
|||
""
|
||||
end
|
||||
}.call
|
||||
expected_item_type_options = lambda {
|
||||
if described_class::MYSQL_ADAPTERS.include?(ActiveRecord::Base.connection.class.name)
|
||||
", { null: false, limit: 191 }"
|
||||
else
|
||||
", { null: false }"
|
||||
end
|
||||
}.call
|
||||
expect(destination_root).to(
|
||||
have_structure {
|
||||
directory("db") {
|
||||
|
@ -43,6 +50,7 @@ RSpec.describe PaperTrail::InstallGenerator, type: :generator do
|
|||
contains("class CreateVersions < " + expected_parent_class)
|
||||
contains "def change"
|
||||
contains "create_table :versions#{expected_create_table_options}"
|
||||
contains " t.string :item_type#{expected_item_type_options}"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue