Skip to content

Commit

Permalink
Fix ServiceTemplate#picture= with models
Browse files Browse the repository at this point in the history
When creating a service template with a Picture that already exists
(done in some of specs in other repos), the previous form of this method
would break as `create_picture` was not relevant for updating pictures
that already exist.

This fix #should™ fix that, but more relevant eyes should probably take
a look just to make sure...
  • Loading branch information
NickLaMuro committed Apr 29, 2019
1 parent 5f37ae7 commit 1cb062f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
8 changes: 5 additions & 3 deletions app/models/service_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -401,9 +401,11 @@ def provision_request(user, options = nil, request_options = {})

def picture=(value)
if value
super unless value.kind_of?(Hash)

super(create_picture(value))
if value.kind_of?(Hash)
super(create_picture(value))
else
super
end
end
end

Expand Down
21 changes: 21 additions & 0 deletions spec/models/service_template_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1002,6 +1002,27 @@
expect(service_template.resource_actions.last.dialog).to eq(service_dialog)
expect(service_template.config_info).to eq(catalog_item_options[:config_info])
end

context "with an existing picture" do
let(:picture) { Picture.create(catalog_item_options.delete(:picture)) }

it "creates the picture without error" do
expect {
service_template = ServiceTemplate.create_catalog_item(catalog_item_options, user)
service_template.picture = picture
}.not_to raise_error
end

it "has the picture assigned properly" do
service_template = ServiceTemplate.create_catalog_item(catalog_item_options, user)
service_template.picture = picture
service_template.save

service_template.reload

expect(service_template.picture.id).to eq picture.id
end
end
end

describe '#update_catalog_item' do
Expand Down

0 comments on commit 1cb062f

Please sign in to comment.