Skip to content

Commit

Permalink
Update service description based on dialog options from provisioning.
Browse files Browse the repository at this point in the history
  • Loading branch information
gmcculloug committed Oct 31, 2017
1 parent 3142b7a commit 89c9982
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
6 changes: 5 additions & 1 deletion app/models/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -434,12 +434,16 @@ def remove_from_service(parenent_service)
def apply_dialog_settings
dialog_options = options[:dialog] || {}

%w(dialog_service_name).each do |field_name|
%w(dialog_service_name dialog_service_description).each do |field_name|
send(field_name, dialog_options[field_name]) if dialog_options.key?(field_name)
end
end

def dialog_service_name(value)
self.name = value if value.present?
end

def dialog_service_description(value)
self.description = value if value.present?
end
end
22 changes: 22 additions & 0 deletions spec/models/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,28 @@
end
end

context 'service description' do
it 'without empty options hash' do
expect(Service.create(:name => 'test').description).to be_blank
end

it 'with empty dialog options' do
expect(Service.create(:name => 'test',
:description => 'test description',
:options => {:dialog => {}}).description)
.to eq('test description')
end

it 'with dialog option dialog_service_description' do
expect(Service.create(:name => 'test',
:description => 'test description',
:options => {
:dialog => {'dialog_service_description' => 'test description from dialog'}
}).description)
.to eq('test description from dialog')
end
end

def create_deep_tree
@service = FactoryGirl.create(:service)
@service_c1 = FactoryGirl.create(:service, :service => @service)
Expand Down

0 comments on commit 89c9982

Please sign in to comment.