Skip to content

Commit

Permalink
Merge pull request #17126 from miha-plesko/subclass-can-override-calc…
Browse files Browse the repository at this point in the history
…-md5

Allow OrchestrationTemplate subclass to customize md5 calculation
  • Loading branch information
agrare authored Mar 14, 2018
2 parents c76b358 + 4df94a0 commit fbdd937
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app/models/orchestration_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ def self.find_or_create_by_contents(hashes)
create!(hash.except(:md5)) # always create a new template if it is a draft
true
else
md5s << calc_md5(with_universal_newline(hash[:content]))
klass = hash[:type].present? ? hash[:type].constantize : self
md5s << klass.calc_md5(with_universal_newline(hash[:content]))
false
end
end
Expand Down
17 changes: 17 additions & 0 deletions spec/models/orchestration_template_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,23 @@
expect(@existing_record).not_to eq(OrchestrationTemplate.find_or_create_by_contents(@query_hash)[0])
expect(OrchestrationTemplate.count).to eq(2)
end

it "uses subclass if type is present" do
expect(ManageIQ::Providers::Vmware::CloudManager::OrchestrationTemplate).to receive(:calc_md5).at_least(:once)
expect(described_class).not_to receive(:calc_md5)

@query_hash[:draft] = false
@query_hash[:type] = ManageIQ::Providers::Vmware::CloudManager::OrchestrationTemplate.name
OrchestrationTemplate.find_or_create_by_contents(@query_hash)
end

it "uses parent if type is not present" do
expect(described_class).to receive(:calc_md5).at_least(:once)

@query_hash[:draft] = false
@query_hash[:type] = nil
OrchestrationTemplate.find_or_create_by_contents(@query_hash)
end
end
end

Expand Down

0 comments on commit fbdd937

Please sign in to comment.