diff --git a/lib/generators/statesman/generator_helpers.rb b/lib/generators/statesman/generator_helpers.rb index ad2dd3de..d36d8590 100644 --- a/lib/generators/statesman/generator_helpers.rb +++ b/lib/generators/statesman/generator_helpers.rb @@ -44,9 +44,5 @@ def mysql? def database_supports_partial_indexes? Statesman::Adapters::ActiveRecord.database_supports_partial_indexes? end - - def metadata_default_value - Utils.rails_5_or_higher? ? "{}" : "{}".inspect - end end end diff --git a/lib/generators/statesman/templates/create_migration.rb.erb b/lib/generators/statesman/templates/create_migration.rb.erb index c538adaa..93fe5253 100644 --- a/lib/generators/statesman/templates/create_migration.rb.erb +++ b/lib/generators/statesman/templates/create_migration.rb.erb @@ -2,7 +2,7 @@ class Create<%= migration_class_name %> < ActiveRecord::Migration<%= "[#{ActiveR def change create_table :<%= table_name %> do |t| t.string :to_state, null: false - t.text :metadata<%= ", default: #{metadata_default_value}" unless mysql? %> + t.text :metadata<%= ", default: \"{}\"" unless mysql? %> t.integer :sort_key, null: false t.integer :<%= parent_id %>, null: false t.boolean :most_recent<%= ", null: false" if database_supports_partial_indexes? %> diff --git a/lib/generators/statesman/templates/update_migration.rb.erb b/lib/generators/statesman/templates/update_migration.rb.erb index 399b1762..9ce90327 100644 --- a/lib/generators/statesman/templates/update_migration.rb.erb +++ b/lib/generators/statesman/templates/update_migration.rb.erb @@ -1,7 +1,7 @@ class AddStatesmanTo<%= migration_class_name %> < ActiveRecord::Migration<%= "[#{ActiveRecord::Migration.current_version}]" if Statesman::Utils.rails_5_or_higher? %> def change add_column :<%= table_name %>, :to_state, :string, null: false - add_column :<%= table_name %>, :metadata, :text<%= ", default: #{metadata_default_value}" unless mysql? %> + add_column :<%= table_name %>, :metadata, :text<%= ", default: \"{}\"" unless mysql? %> add_column :<%= table_name %>, :sort_key, :integer, null: false add_column :<%= table_name %>, :<%= parent_id %>, :integer, null: false add_column :<%= table_name %>, :most_recent, null: false diff --git a/spec/generators/statesman/active_record_transition_generator_spec.rb b/spec/generators/statesman/active_record_transition_generator_spec.rb index ec5569c0..f843e51d 100644 --- a/spec/generators/statesman/active_record_transition_generator_spec.rb +++ b/spec/generators/statesman/active_record_transition_generator_spec.rb @@ -19,6 +19,8 @@ it "includes a foreign key" do expect(subject).to contain("add_foreign_key :bacon_transitions, :bacons") end + + it { is_expected.to contain(/default: "{}"/) } end describe "properly adds class names" do diff --git a/spec/generators/statesman/migration_generator_spec.rb b/spec/generators/statesman/migration_generator_spec.rb index b3f2c4ba..5689fdcf 100644 --- a/spec/generators/statesman/migration_generator_spec.rb +++ b/spec/generators/statesman/migration_generator_spec.rb @@ -28,6 +28,7 @@ it { is_expected.to contain(/:bacon_transition/) } it { is_expected.not_to contain(%r{:yummy/bacon}) } it { is_expected.to contain(/null: false/) } + it { is_expected.to contain(/default: "{}"/) } it "names the sorting index appropriately" do expect(subject).