Skip to content

Commit

Permalink
Merge pull request #18705 from NickLaMuro/fix_service_template_pictur…
Browse files Browse the repository at this point in the history
…e_equals

Fix ServiceTemplate#picture= with models
  • Loading branch information
martinpovolny authored Apr 30, 2019
2 parents b7050c4 + 1cb062f commit f7fc0cb
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 f7fc0cb

Please sign in to comment.