Skip to content

Commit

Permalink
Merge pull request #14147 from jntullo/enhancement/allow_for_simple_u…
Browse files Browse the repository at this point in the history
…pdate

Update catalog item without config_options
  • Loading branch information
gmcculloug committed Mar 10, 2017
2 parents 43f134a + 4aafba6 commit 30910fa
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 10 deletions.
8 changes: 7 additions & 1 deletion app/models/service_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ def self.class_from_request_data(data)

def update_catalog_item(options, auth_user = nil)
config_info = validate_update_config_info(options)
return update_attributes!(options) unless config_info
transaction do
update_from_options(options)

Expand Down Expand Up @@ -428,7 +429,12 @@ def build_resource_action(ae_endpoint, action)
end

def validate_update_config_info(options)
raise _('service_type and prov_type cannot be changed') if options[:service_type] || options[:prov_type]
if options[:service_type] && options[:service_type] != service_type
raise _('service_type cannot be changed')
end
if options[:prov_type] && options[:prov_type] != prov_type
raise _('prov_type cannot be changed')
end
options[:config_info]
end

Expand Down
1 change: 1 addition & 0 deletions app/models/service_template_ansible_tower.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def update_service_resources(config_info, _auth_user = nil)

def validate_update_config_info(options)
super
return unless options.key?(:config_info)
self.class.validate_config_info(options)
end

Expand Down
1 change: 1 addition & 0 deletions app/models/service_template_orchestration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def update_service_resources(config_info, _auth_user = nil)

def validate_update_config_info(options)
super
return unless options.key?(:config_info)
self.class.validate_config_info(options)
end

Expand Down
7 changes: 7 additions & 0 deletions spec/models/service_template_ansible_tower_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,13 @@

expect(updated.configuration_script).to eq(new_configuration_script)
end

it 'allows for update without the presence of config_info' do
expect do
@catalog_item.update_catalog_item(:name => 'new_name')
end.to change(@catalog_item, :name)
expect(@catalog_item.reload.name).to eq('new_name')
end
end

describe '#config_info' do
Expand Down
14 changes: 7 additions & 7 deletions spec/models/service_template_orchestration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -210,13 +210,6 @@
end.to raise_error(StandardError, 'Must provide both template_id and manager_id or manager and template')
end

it 'cannot change service_type or prov_type' do
updated_catalog_item_options[:prov_type] = 'new type'
expect do
@catalog_item.update_catalog_item(updated_catalog_item_options)
end.to raise_error(StandardError, 'service_type and prov_type cannot be changed')
end

it 'can accept manager and template objects on update' do
updated_catalog_item_options[:config_info].delete(:manager_id)
updated_catalog_item_options[:config_info].delete(:manager_id)
Expand All @@ -226,6 +219,13 @@
expect(updated.orchestration_template).to eq(new_template)
expect(updated.orchestration_manager).to eq(new_manager)
end

it 'allows for update without the presence of config_info' do
expect do
@catalog_item.update_catalog_item(:name => 'new_name')
end.to change(@catalog_item, :name)
expect(@catalog_item.reload.name).to eq('new_name')
end
end

describe '#config_info' do
Expand Down
26 changes: 24 additions & 2 deletions spec/models/service_template_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -615,10 +615,32 @@
expect(updated.config_info).to eq(updated_catalog_item_options[:config_info])
end

it 'does not allow service_type and prov_type to be changed' do
it 'does not allow service_type to be changed' do
expect do
@catalog_item.update_catalog_item({:service_type => 'new'}, user)
end.to raise_error(StandardError, /service_type and prov_type cannot be changed/)
end.to raise_error(StandardError, /service_type cannot be changed/)
end

it 'does not allow prov_type to be changed' do
expect do
@catalog_item.update_catalog_item({:prov_type => 'new'}, user)
end.to raise_error(StandardError, /prov_type cannot be changed/)
end

it 'accepts prov_type and service_type if they are not changed' do
expect do
@catalog_item.update_catalog_item({:name => 'new_name',
:service_type => @catalog_item.service_type,
:prov_type => @catalog_item.prov_type}, user)
end.to change(@catalog_item, :name)
expect(@catalog_item.reload.name).to eq('new_name')
end

it 'allows for update without the presence of config_info' do
expect do
@catalog_item.update_catalog_item(:name => 'new_name')
end.to change(@catalog_item, :name)
expect(@catalog_item.reload.name).to eq('new_name')
end
end

Expand Down

0 comments on commit 30910fa

Please sign in to comment.