Skip to content

Commit

Permalink
Merge pull request #14035 from mkanoor/add_initiator_to_service
Browse files Browse the repository at this point in the history
Adding initiator to the Service model
  • Loading branch information
Fryguy authored Mar 2, 2017
2 parents 92b5071 + 666ad98 commit c965151
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/models/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class Service < ApplicationRecord

default_value_for :display, false
default_value_for :retired, false
default_value_for :initiator, 'user'

validates :display, :inclusion => { :in => [true, false] }
validates :retired, :inclusion => { :in => [true, false] }
Expand Down
14 changes: 14 additions & 0 deletions db/migrate/20170222214902_add_initiator_to_service.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class AddInitiatorToService < ActiveRecord::Migration[5.0]
class Service < ActiveRecord::Base; end

def up
add_column :services, :initiator, :string, :comment => "Entity that initiated the service creation"
say_with_time("Updating existing services to 'user' initiator") do
Service.update_all(:initiator => 'user')
end
end

def down
remove_column :services, :initiator
end
end
1 change: 1 addition & 0 deletions db/schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6435,6 +6435,7 @@ services:
- retirement_requester
- tenant_id
- ancestry
- initiator
sessions:
- id
- session_id
Expand Down
19 changes: 19 additions & 0 deletions spec/migrations/20170222214902_add_initiator_to_service_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
require_migration

describe AddInitiatorToService do
let(:service_stub) { migration_stub(:Service) }
let(:default_initiator) { "user" }

migration_context :up do
it "adds initiator and sets it to user" do
service_stub.create!(:name => 'service1')
service_stub.create!(:name => 'service2')

migrate

expect(service_stub.count).to eq(2)
expect(service_stub.find_by(:name => 'service1').initiator).to eq(default_initiator)
expect(service_stub.find_by(:name => 'service2').initiator).to eq(default_initiator)
end
end
end

0 comments on commit c965151

Please sign in to comment.