-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9c1e438
commit 69d2243
Showing
3 changed files
with
41 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
25 changes: 25 additions & 0 deletions
25
spec/migrations/20180626125654_make_maintenance_zone_record_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |