Skip to content

Commit

Permalink
Added spec to validate the expression data
Browse files Browse the repository at this point in the history
  • Loading branch information
mkanoor committed Jul 11, 2017
1 parent 0947e36 commit 6012299
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/models/miq_ae_yaml_import.rb
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def process_method(class_obj, ruby_method_file_name, method_yaml)
data = if method_attributes['location'] == 'inline'
load_method_ruby(ruby_method_file_name)
elsif method_attributes['location'] == 'expression'
load_file(ruby_method_file_name.gsub('.yaml', '.expr'))
read_file(ruby_method_file_name.gsub('.yaml', '.expr'))
end
method_yaml.store_path('object', 'attributes', 'data', data) if data
method_obj = MiqAeMethod.find_by(:name => method_attributes['name'], :class_id => class_obj.id) unless class_obj.nil?
Expand Down
4 changes: 4 additions & 0 deletions app/models/miq_ae_yaml_import_consolidated.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ def load_method_ruby(method_file_name)
load_file(method_file_name.gsub('.yaml', '.rb'))
end

def read_file(file_name)
@yaml_model.fetch_path(*file_name.split('/'))
end

def load_class_schema(class_folder)
class_file = "#{class_folder}/#{CLASS_YAML_FILENAME}"
@yaml_model.fetch_path(*class_file.split('/'))
Expand Down
4 changes: 4 additions & 0 deletions app/models/miq_ae_yaml_import_fs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,8 @@ def load_method_ruby(method_file_name)
ruby_method_filename = method_file_name.gsub('.yaml', '.rb')
File.read(ruby_method_filename) if File.exist?(ruby_method_filename)
end

def read_file(filename)
File.read(filename)
end
end
4 changes: 4 additions & 0 deletions app/models/miq_ae_yaml_import_gitfs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,8 @@ def load_file(file)
def load_method_ruby(method_file_name)
@gwt.read_file(method_file_name.gsub('.yaml', '.rb'))
end

def read_file(filename)
@gwt.read_file(filename)
end
end
4 changes: 4 additions & 0 deletions app/models/miq_ae_yaml_import_zipfs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,8 @@ def load_file(file)
def load_method_ruby(method_file_name)
@zip.file.read(method_file_name.gsub('.yaml', '.rb'))
end

def read_file(filename)
@zip.file.read(filename)
end
end
28 changes: 24 additions & 4 deletions spec/models/miq_ae_yaml_import_export_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -589,15 +589,35 @@ def assert_class_with_methods_export(export_options, import_options)
assert_class_with_builtin_methods_export(export_options, import_options)
end

def assert_class_with_builtin_methods_export(export_options, import_options)
it "class, with expression methods, as zip" do
export_options = {'namespace' => @aen1.name, 'class' => @aen1_aec1.name}
export_options['zip_file'] = @zip_file
import_options = {'zip_file' => @zip_file}
assert_class_with_expression_methods_export(export_options, import_options)
end

def assert_methods_export(export_options, import_options)
export_model(@manageiq_domain.name, export_options)
reset_and_import(@export_dir, @manageiq_domain.name, import_options)
check_counts('dom' => 1, 'ns' => 1, 'class' => 1, 'inst' => 2,
'meth' => 3, 'field' => 6, 'value' => 4)
end

def assert_class_with_builtin_methods_export(export_options, import_options)
assert_methods_export(export_options, import_options)
assert_method_data('test2', 'builtin', nil)
end

def assert_class_with_expression_methods_export(export_options, import_options)
assert_methods_export(export_options, import_options)
assert_method_data('test3', 'expression', @expression_data)
end

def assert_method_data(name, location, data)
aen1_aec1 = MiqAeClass.find_by_name('manageiq_test_class_1')
builtin_method = MiqAeMethod.find_by_class_id_and_name(aen1_aec1.id, 'test2')
expect(builtin_method.location).to eql 'builtin'
expect(builtin_method.data).to be_nil
method = MiqAeMethod.find_by_class_id_and_name(aen1_aec1.id, name)
expect(method.location).to eql location
expect(method.data).to eq(data)
end

it "class, without methods, to directory" do
Expand Down

0 comments on commit 6012299

Please sign in to comment.