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 seeding of dialogs from plugins #14668

Merged
merged 4 commits into from
Apr 11, 2017
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
13 changes: 10 additions & 3 deletions app/models/dialog.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
class Dialog < ApplicationRecord
DIALOG_DIR = Rails.root.join("product/dialogs/service_dialogs")
DIALOG_DIR_CORE = 'product/dialogs/service_dialogs'.freeze
DIALOG_DIR_PLUGIN = 'content/service_dialogs'.freeze
Copy link
Member

Choose a reason for hiding this comment

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

I feel like we should just create a content/service_dialogs directory in manageiq proper, so the directories are consistent.

Copy link
Member

@bdunne bdunne Apr 11, 2017

Choose a reason for hiding this comment

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

We can drop the DIALOG_DIR_CORE logic once all dialogs have been moved to provider pugins or manageiq-content

Copy link
Member Author

Choose a reason for hiding this comment

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

you mean move all from product/dialogs/service_dialogs to content/service_dialogs?


# The following gets around a glob symbolic link issue
ALL_YAML_FILES = DIALOG_DIR.join("{,*/**/}*.{yaml,yml}")
YAML_FILES_PATTERN = "{,*/**/}*.{yaml,yml}".freeze

has_many :dialog_tabs, -> { order :position }, :dependent => :destroy
validate :validate_children
Expand All @@ -25,9 +26,15 @@ class Dialog < ApplicationRecord
def self.seed
dialog_import_service = DialogImportService.new

Dir.glob(ALL_YAML_FILES).each do |file|
Dir.glob(Rails.root.join(DIALOG_DIR_CORE, YAML_FILES_PATTERN)).each do |file|
dialog_import_service.import_all_service_dialogs_from_yaml_file(file)
end

Vmdb::Plugins.instance.registered_provider_plugins.each do |plugin|
Dir.glob(plugin.root.join(DIALOG_DIR_PLUGIN, YAML_FILES_PATTERN)).each do |file|
dialog_import_service.import_all_service_dialogs_from_yaml_file(file)
end
end
end

def each_dialog_field(&block)
Expand Down
61 changes: 38 additions & 23 deletions spec/models/dialog_spec.rb
Original file line number Diff line number Diff line change
@@ -1,42 +1,57 @@
describe Dialog do
describe ".seed" do
let(:dialog_import_service) { double("DialogImportService") }
let(:test_file_path) { Rails.root.join("spec/fixtures/files/dialogs") }
let(:all_yaml_files) { test_file_path.join("{,*/**/}*.{yaml,yml}") }
let(:test_file_path) { "spec/fixtures/files/dialogs" }

before do
allow(DialogImportService).to receive(:new).and_return(dialog_import_service)
allow(dialog_import_service).to receive(:import_all_service_dialogs_from_yaml_file)
end

it "delegates to the dialog import service with a file in the default directory" do
Dialog.with_constants(:DIALOG_DIR => test_file_path, :ALL_YAML_FILES => all_yaml_files) do
expect(dialog_import_service).to receive(:import_all_service_dialogs_from_yaml_file).with(
test_file_path.join("seed_test.yaml").to_path)
expect(dialog_import_service).to receive(:import_all_service_dialogs_from_yaml_file).with(
test_file_path.join("seed_test.yml").to_path)
Dialog.seed
end
stub_const('Dialog::DIALOG_DIR_CORE', test_file_path)
expect(dialog_import_service).to receive(:import_all_service_dialogs_from_yaml_file).with(
Rails.root.join(test_file_path, "seed_test.yaml").to_path
)
expect(dialog_import_service).to receive(:import_all_service_dialogs_from_yaml_file).with(
Rails.root.join(test_file_path, "seed_test.yml").to_path
)
described_class.seed
end

it "delegates to the dialog import service with a file in a sub directory" do
Dialog.with_constants(:DIALOG_DIR => test_file_path, :ALL_YAML_FILES => all_yaml_files) do
expect(dialog_import_service).to receive(:import_all_service_dialogs_from_yaml_file).with(
test_file_path.join("service_dialogs/service_seed_test.yaml").to_path)
expect(dialog_import_service).to receive(:import_all_service_dialogs_from_yaml_file).with(
test_file_path.join("service_dialogs/service_seed_test.yml").to_path)
Dialog.seed
end
stub_const('Dialog::DIALOG_DIR_CORE', test_file_path)
expect(dialog_import_service).to receive(:import_all_service_dialogs_from_yaml_file).with(
Rails.root.join(test_file_path, "service_dialogs", "service_seed_test.yaml").to_path
)
expect(dialog_import_service).to receive(:import_all_service_dialogs_from_yaml_file).with(
Rails.root.join(test_file_path, "service_dialogs", "service_seed_test.yml").to_path
)
described_class.seed
end

it "delegates to the dialog import service with a symlinked file" do
Dialog.with_constants(:DIALOG_DIR => test_file_path, :ALL_YAML_FILES => all_yaml_files) do
expect(dialog_import_service).to receive(:import_all_service_dialogs_from_yaml_file).with(
test_file_path.join("service_dialog_symlink/service_seed_test.yaml").to_path)
expect(dialog_import_service).to receive(:import_all_service_dialogs_from_yaml_file).with(
test_file_path.join("service_dialog_symlink/service_seed_test.yml").to_path)
Dialog.seed
end
stub_const('Dialog::DIALOG_DIR_CORE', test_file_path)
expect(dialog_import_service).to receive(:import_all_service_dialogs_from_yaml_file).with(
Rails.root.join(test_file_path, "service_dialog_symlink", "service_seed_test.yaml").to_path
)
expect(dialog_import_service).to receive(:import_all_service_dialogs_from_yaml_file).with(
Rails.root.join(test_file_path, "service_dialog_symlink", "service_seed_test.yml").to_path
)
described_class.seed
end

it "seed files from plugins" do
mock_engine = double(:root => Rails.root)
expect(Vmdb::Plugins.instance).to receive(:registered_provider_plugins).and_return([mock_engine])

stub_const('Dialog::DIALOG_DIR_PLUGIN', test_file_path)
stub_const('Dialog::DIALOG_DIR_CORE', 'non-existent-dir')
expect(dialog_import_service).to receive(:import_all_service_dialogs_from_yaml_file).with(
Rails.root.join(test_file_path, "seed_test.yaml").to_path
)
expect(mock_engine).to receive(:root)
described_class.seed
end
end

Expand Down