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

Allow OrchestrationTemplate subclass to customize md5 calculation #17126

Merged
merged 1 commit into from
Mar 14, 2018
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
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)
Copy link
Contributor

Choose a reason for hiding this comment

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

why at_lease(:once)? can it be called more than once?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In fact it gets called twice:

Theoretically I could test for :twice but would prefer to keep it more general, should you agree.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, yes, it is called twice. Then I think at_least(:once) is ok.

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