Skip to content

Commit

Permalink
seed plugins from content/dialogs
Browse files Browse the repository at this point in the history
  • Loading branch information
durandom committed Apr 5, 2017
1 parent a2cf41b commit f7a5f3d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
7 changes: 2 additions & 5 deletions app/models/miq_dialog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ class MiqDialog < ApplicationRecord
validates :name, :description, :presence => true
validates :name, :uniqueness => { :scope => :dialog_type, :case_sensitive => false }

DIALOG_DIR = "product/dialogs/miq_dialogs".freeze

DIALOG_TYPES = [
[_("VM Provision"), "MiqProvisionWorkflow"],
[_("Configured System Provision"), "MiqProvisionConfiguredSystemWorkflow"],
Expand All @@ -14,18 +12,17 @@ class MiqDialog < ApplicationRecord
serialize :content

def self.seed
sync_from_dir(Rails.root)
sync_from_dir(Rails.root.join('product', 'dialogs', 'miq_dialogs'))
sync_from_plugins
end

def self.sync_from_dir(root)
root = root.join(DIALOG_DIR)
Dir.glob(root.join("*.yaml")).each { |f| sync_from_file(f, root) }
end

def self.sync_from_plugins
Vmdb::Plugins.instance.registered_provider_plugins.each do |plugin|
sync_from_dir(plugin.root)
sync_from_dir(plugin.root.join('content', 'miq_dialogs'))
end
end

Expand Down
6 changes: 4 additions & 2 deletions spec/models/miq_dialog_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
describe MiqDialog do
context '.seed' do
it 'seeds from the core with correct metadata' do
root = Rails.root.join(described_class::DIALOG_DIR)
root = Rails.root.join('product', 'dialogs', 'miq_dialogs')
allow(described_class).to receive(:find_by)

expect(described_class).to receive(:sync_from_file).at_least(:once).with(/^#{root}/, root).and_call_original
Expand All @@ -20,7 +20,9 @@

described_class.seed

expect(described_class).to have_received(:sync_from_dir).at_least(:once).with(mock_engine.root)
expect(described_class).to have_received(:sync_from_dir).at_least(:once).with(
mock_engine.root.join('content', 'miq_dialogs')
)
end
end
end

0 comments on commit f7a5f3d

Please sign in to comment.