From 50993942cd25a1da738801ae48235e903a52bf1f Mon Sep 17 00:00:00 2001 From: Martin Slemr Date: Wed, 27 Jun 2018 15:11:20 +0200 Subject: [PATCH] Splitting struct/data migrations https://bugzilla.redhat.com/show_bug.cgi?id=1455145 --- .../20180618083035_add_visible_to_zone.rb | 6 ----- ...0626125654_make_maintenance_zone_record.rb | 16 ++++++++++++ ...25654_make_maintenance_zone_record_spec.rb | 25 +++++++++++++++++++ 3 files changed, 41 insertions(+), 6 deletions(-) create mode 100644 db/migrate/20180626125654_make_maintenance_zone_record.rb create mode 100644 spec/migrations/20180626125654_make_maintenance_zone_record_spec.rb diff --git a/db/migrate/20180618083035_add_visible_to_zone.rb b/db/migrate/20180618083035_add_visible_to_zone.rb index d2277715c..a50a3d088 100644 --- a/db/migrate/20180618083035_add_visible_to_zone.rb +++ b/db/migrate/20180618083035_add_visible_to_zone.rb @@ -1,11 +1,5 @@ class AddVisibleToZone < ActiveRecord::Migration[5.0] def change add_column :zones, :visible, :boolean, :default => true - reversible do |dir| - dir.up do - ::Zone.reset_column_information - ::Zone.seed - end - end end end diff --git a/db/migrate/20180626125654_make_maintenance_zone_record.rb b/db/migrate/20180626125654_make_maintenance_zone_record.rb new file mode 100644 index 000000000..ee4d1fa25 --- /dev/null +++ b/db/migrate/20180626125654_make_maintenance_zone_record.rb @@ -0,0 +1,16 @@ +class MakeMaintenanceZoneRecord < ActiveRecord::Migration[5.0] + class Zone < ActiveRecord::Base + end + + def up + say_with_time("Creating Maintenance Zone") do + Zone.create_with(:description => "Maintenance Zone", :visible => false).find_or_create_by!(:name => 'maintenance') + end + end + + def down + say_with_time("Deleting Maintenance Zone") do + Zone.where(:name => 'maintenance').where(:visible => false).destroy_all + end + end +end diff --git a/spec/migrations/20180626125654_make_maintenance_zone_record_spec.rb b/spec/migrations/20180626125654_make_maintenance_zone_record_spec.rb new file mode 100644 index 000000000..d82546dc8 --- /dev/null +++ b/spec/migrations/20180626125654_make_maintenance_zone_record_spec.rb @@ -0,0 +1,25 @@ +require_migration + +describe MakeMaintenanceZoneRecord do + let(:zone_stub) { migration_stub(:Zone) } + + migration_context :up do + it "Adds MaintenanceZone" do + migrate + + expect(zone_stub.where(:name => 'maintenance').where(:visible => false).count).to eq(1) + end + end + + migration_context :down do + it "removes MaintenanceZone" do + zone_stub.create!(:name => 'maintenance', + :description => 'Maintenance Zone', + :visible => false) + + migrate + + expect(zone_stub.where(:name => 'maintenance').where(:visible => false).count).to eq(0) + end + end +end