Skip to content

Commit

Permalink
Dialog seeding changes necessary for the service dialog yaml import.
Browse files Browse the repository at this point in the history
https://bugzilla.redhat.com/show_bug.cgi?id=1163875

Productization requires service dialog import files to be linked into
the manageiq dialog import folder.
Changed dialog seeding to accommodate sub-directories and added tests.
  • Loading branch information
tinaafitz committed Nov 20, 2014
1 parent e5e233a commit f5228d8
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 5 deletions.
5 changes: 4 additions & 1 deletion vmdb/app/models/dialog.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
class Dialog < ActiveRecord::Base
DIALOG_DIR = Rails.root.join("product/dialogs/service_dialogs")

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

has_many :dialog_tabs, :dependent => :destroy, :order => :position

include DialogMixin
Expand All @@ -18,7 +21,7 @@ def self.seed
dialog_import_service = DialogImportService.new

MiqRegion.my_region.lock do
Dir.glob(DIALOG_DIR.join("*.yaml")).each do |file|
Dir.glob(ALL_YAML_FILES).each do |file|
dialog_import_service.import_all_service_dialogs_from_yaml_file(file)
end
end
Expand Down
Empty file.
1 change: 1 addition & 0 deletions vmdb/spec/fixtures/files/dialogs/service_dialog_symlink
Empty file.
Empty file.
Empty file.
Empty file.
31 changes: 27 additions & 4 deletions vmdb/spec/models/dialog_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,40 @@
describe ".seed" do
let(:dialog_import_service) { instance_double("DialogImportService") }
let(:test_file_path) { Rails.root.join("spec/fixtures/files/dialogs") }
let(:all_yaml_files) { test_file_path.join("{,*/**/}*.{yaml,yml}") }

before do
MiqRegion.seed
DialogImportService.stub(:new).and_return(dialog_import_service)
dialog_import_service.stub(:import_all_service_dialogs_from_yaml_file)
end

it "delegates to the dialog import service" do
Dialog.with_constants(:DIALOG_DIR => test_file_path) do
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
dialog_import_service.should_receive(:import_all_service_dialogs_from_yaml_file).with(
test_file_path.join("seed_test.yaml").to_path
)
test_file_path.join("seed_test.yaml").to_path)
dialog_import_service.should_receive(:import_all_service_dialogs_from_yaml_file).with(
test_file_path.join("seed_test.yml").to_path)
Dialog.seed
end
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
dialog_import_service.should_receive(:import_all_service_dialogs_from_yaml_file).with(
test_file_path.join("service_dialogs/service_seed_test.yaml").to_path)
dialog_import_service.should_receive(:import_all_service_dialogs_from_yaml_file).with(
test_file_path.join("service_dialogs/service_seed_test.yml").to_path)
Dialog.seed
end
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
dialog_import_service.should_receive(:import_all_service_dialogs_from_yaml_file).with(
test_file_path.join("service_dialog_symlink/service_seed_test.yaml").to_path)
dialog_import_service.should_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
end
Expand Down

0 comments on commit f5228d8

Please sign in to comment.