Skip to content

Commit

Permalink
Splitting struct/data migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
slemrmartin committed Jun 27, 2018
1 parent 9c1e438 commit 69d2243
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 6 deletions.
6 changes: 0 additions & 6 deletions db/migrate/20180618083035_add_visible_to_zone.rb
Original file line number Diff line number Diff line change
@@ -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
16 changes: 16 additions & 0 deletions db/migrate/20180626125654_make_maintenance_zone_record.rb
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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').count).to eq(0)
end
end
end

0 comments on commit 69d2243

Please sign in to comment.