-
Notifications
You must be signed in to change notification settings - Fork 898
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 MiqDialog to be seeded from plugins... #14653
Conversation
and add spec to test it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool! I'm excited to get this moving. I know @djberg96 has a PR open to move some dialogs, but it should depend on this PR.
app/models/miq_dialog.rb
Outdated
def self.sync_from_dir | ||
Dir.glob(File.join(DIALOG_DIR, "*.yaml")).each { |f| sync_from_file(f) } | ||
def self.sync_from_dir(root) | ||
root = root.join(DIALOG_DIR) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would avoid redefining root
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, in provider plugins, I would expect dialogs to live in content/dialogs
to match the pattern we started in the manageiq-content
repo.
app/models/miq_dialog.rb
Outdated
Dir.glob(File.join(DIALOG_DIR, "*.yaml")).each { |f| sync_from_file(f) } | ||
def self.sync_from_plugins | ||
Vmdb::Plugins.instance.registered_provider_plugins.each do |plugin| | ||
sync_from_dir(plugin.root.join('content', 'dialogs')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we really want to seed from content/dialogs
?
Or is it content/dialogs/miq_dialogs
?
TBH I have no idea what both are :/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, forgot there were two directories in there. I think content/miq_dialogs
and content/service_dialogs
would be a good layout.
@bdunne adressed feedback in last commit. See also my question about |
6cae6a8
to
f7a5f3d
Compare
@bdunne amended the last commit to use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code looks good, but I have a few comments about the specs
context '.seed' do | ||
it 'seeds from the core with correct metadata' do | ||
root = Rails.root.join('product', 'dialogs', 'miq_dialogs') | ||
allow(described_class).to receive(:find_by) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think expect(described_class).to receive(:find_by).once.with(...)
would be much simpler than allow
and expect().to have_received()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right, when I was trying that, rspec complained about the other calls - now it works 🤷♂️
thanks for letting me re-visit that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here it is still, I need to stub find_by
with allow(described_class).to receive(:find_by)
otherwise I get this:
same is true for :sync_from_dir
below.
Failures:
1) MiqDialog.seed seeds from the core with correct metadata
Failure/Error: rec = find_by(:name => item[:name], :filename => item[:filename])
#<MiqDialog(id: integer, name: string, description: string, dialog_type: string, content: text, default: boolean, filename: string, file_mtime: datetime, created_at: datetime, updated_at: datetime, href_slug: string, region_number: integer, region_description: string) (class)> received :find_by with unexpected arguments
expected: ({:name=>"miq_host_provision_dialogs", :filename=>"miq_host_provision_dialogs.yaml"})
got: ({:name=>"miq_provision_amazon_dialogs_template", :filename=>"miq_provision_amazon_dialogs_template.yaml"})
Diff:
@@ -1,3 +1,3 @@
-[{:name=>"miq_host_provision_dialogs",
- :filename=>"miq_host_provision_dialogs.yaml"}]
+[{:name=>"miq_provision_amazon_dialogs_template",
+ :filename=>"miq_provision_amazon_dialogs_template.yaml"}]
# ./app/models/miq_dialog.rb:36:in `sync_from_file'
# ./app/models/miq_dialog.rb:20:in `block in sync_from_dir'
# ./app/models/miq_dialog.rb:20:in `each'
# ./app/models/miq_dialog.rb:20:in `sync_from_dir'
# ./app/models/miq_dialog.rb:15:in `seed'
# ./spec/models/miq_dialog_spec.rb:11:in `block (3 levels) in <top (required)>'
# -e:1:in `<main>'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see 👍
spec/models/miq_dialog_spec.rb
Outdated
|
||
it 'seed from plugins' do | ||
mock_engine = double(:root => Pathname.new('/some/root')) | ||
allow(Vmdb::Plugins.instance).to receive(:registered_provider_plugins).and_return([mock_engine]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be expect
? I feel like this is an important part of the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok - why not :)
spec/models/miq_dialog_spec.rb
Outdated
it 'seed from plugins' do | ||
mock_engine = double(:root => Pathname.new('/some/root')) | ||
allow(Vmdb::Plugins.instance).to receive(:registered_provider_plugins).and_return([mock_engine]) | ||
allow(described_class).to receive(:sync_from_dir) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment about allow
with expect().to have_received()
3f8f31a
to
402bdd5
Compare
@bdunne addressed your comments in the last commit |
end | ||
|
||
def self.sync_from_dir(root) | ||
Dir.glob(root.join("*.{yaml,yml}")).each { |f| sync_from_file(f, root) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm refactoring seeding of dialog.rb
as well and noticed this loads .yaml and .yml files. So should we do here too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
added another commit to also load .yml files |
Checked commits durandom/manageiq@a2cf41b~...469689a with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0 |
end | ||
|
||
def self.sync_from_dir(root) | ||
Dir.glob(root.join("*.{yaml,yml}")).each { |f| sync_from_file(f, root) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
context '.seed' do | ||
it 'seeds from the core with correct metadata' do | ||
root = Rails.root.join('product', 'dialogs', 'miq_dialogs') | ||
allow(described_class).to receive(:find_by) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see 👍
...and add specs to test it actually does
required to merge ManageIQ/manageiq-providers-azure#16
@miq-bot assign @bdunne
@miq-bot add_labels enhancement
cc @djberg96 @gmcculloug