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 MiqDialog to be seeded from plugins... #14653

Merged
merged 4 commits into from
Apr 6, 2017

Conversation

durandom
Copy link
Member

@durandom durandom commented Apr 5, 2017

...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

Copy link
Member

@bdunne bdunne left a 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.

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)
Copy link
Member

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

Copy link
Member

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.

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'))
Copy link
Member Author

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

Copy link
Member

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.

@durandom
Copy link
Member Author

durandom commented Apr 5, 2017

@bdunne adressed feedback in last commit. See also my question about dialogs vs miq_dialogs

@durandom
Copy link
Member Author

durandom commented Apr 5, 2017

@bdunne amended the last commit to use content/miq_dialogs

Copy link
Member

@bdunne bdunne left a 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)
Copy link
Member

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().

Copy link
Member Author

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

Copy link
Member Author

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>'

Copy link
Member

Choose a reason for hiding this comment

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

I see 👍


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])
Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

ok - why not :)

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)
Copy link
Member

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()

@durandom
Copy link
Member Author

durandom commented Apr 6, 2017

@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) }
Copy link
Member Author

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

Copy link
Member

Choose a reason for hiding this comment

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

👍

@durandom
Copy link
Member Author

durandom commented Apr 6, 2017

added another commit to also load .yml files

@miq-bot
Copy link
Member

miq-bot commented Apr 6, 2017

Checked commits durandom/manageiq@a2cf41b~...469689a with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0
2 files checked, 0 offenses detected
Everything looks good. 🍰

end

def self.sync_from_dir(root)
Dir.glob(root.join("*.{yaml,yml}")).each { |f| sync_from_file(f, root) }
Copy link
Member

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)
Copy link
Member

Choose a reason for hiding this comment

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

I see 👍

@bdunne bdunne merged commit 6410786 into ManageIQ:master Apr 6, 2017
@durandom durandom deleted the miq_dialog_seed branch April 6, 2017 15:17
@bdunne bdunne added this to the Sprint 58 Ending Apr 10, 2017 milestone Apr 6, 2017
@durandom durandom mentioned this pull request Apr 21, 2017
38 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants