Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update catalog item without config_options #14147

Merged
merged 2 commits into from
Mar 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -426,7 +427,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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be two independent if...end blocks

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 @@ -593,10 +593,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