-
Notifications
You must be signed in to change notification settings - Fork 900
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14035 from mkanoor/add_initiator_to_service
Adding initiator to the Service model
- Loading branch information
Showing
4 changed files
with
35 additions
and
0 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
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,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 |
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 |
---|---|---|
|
@@ -6435,6 +6435,7 @@ services: | |
- retirement_requester | ||
- tenant_id | ||
- ancestry | ||
- initiator | ||
sessions: | ||
- id | ||
- session_id | ||
|
19 changes: 19 additions & 0 deletions
19
spec/migrations/20170222214902_add_initiator_to_service_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,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 |