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

Fix ServiceTemplate#picture= with models #18705

Merged
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: 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