Skip to content

Commit

Permalink
Merge pull request #13087 from h-kataria/ae_method_editor_fix
Browse files Browse the repository at this point in the history
Fixed code to expect keys as strings instead of symbols.
(cherry picked from commit c3171b8)

https://bugzilla.redhat.com/show_bug.cgi?id=1403351
  • Loading branch information
mkanoor authored and chessbyte committed Dec 14, 2016
1 parent 83a52db commit fd7155d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 39 deletions.
8 changes: 3 additions & 5 deletions app/controllers/miq_ae_class_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2263,7 +2263,7 @@ def set_field_vars(parent = nil)
fields = parent_fields(parent)
highest_priority = fields.count
@edit[:new][:fields].each_with_index do |fld, i|
if fld[:id].nil?
if fld["id"].nil?
new_field = MiqAeField.new
highest_priority += 1
new_field.priority = highest_priority
Expand All @@ -2273,12 +2273,11 @@ def set_field_vars(parent = nil)
new_field.class_id = @ae_class.id
end
else
new_field = parent.nil? ? MiqAeField.find_by_id(fld[:id]) : fields.detect { |f| f.id == fld[:id] }
new_field = parent.nil? ? MiqAeField.find_by_id(fld["id"]) : fields.detect { |f| f.id == fld["id"] }
end

field_attributes.each do |attr|
attr = attr.to_sym
if attr == :substitute
if attr == "substitute"
new_field.send("#{attr}=", @edit[:new][:fields][i][attr])
else
new_field.send("#{attr}=", @edit[:new][:fields][i][attr]) if @edit[:new][:fields][i][attr]
Expand All @@ -2288,7 +2287,6 @@ def set_field_vars(parent = nil)
raise StandardError, new_field.errors.full_messages[0] unless fields.push(new_field)
end
end

reset_field_priority(fields)
end
alias_method :set_input_vars, :set_field_vars
Expand Down
68 changes: 34 additions & 34 deletions spec/controllers/miq_ae_class_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -479,20 +479,20 @@
end

it "Should not allow to create two schema fields with identical name" do
field = {:aetype => "attribute",
:datatype => "string",
:name => "name01"}
field = {"aetype" => "attribute",
"datatype" => "string",
"name" => "name01"}
session[:edit][:new][:fields] = [field, field]
controller.instance_variable_set(:@_params, :button => "save", :id => @cls.id)
controller.send(:update_fields)
expect(assigns(:flash_array).first[:message]).to include("Name has already been taken")
end

it "Should not allow to add two parameters with identical name to a method" do
field = {:default_value => nil,
:datatype => nil,
:name => "name01",
:method_id => @method.id}
field = {"default_value" => nil,
"datatype" => nil,
"name" => "name01",
"method_id" => @method.id}
session[:edit] = {
:key => "aemethod_edit__#{@method.id}",
:ae_class_id => @cls.id,
Expand All @@ -508,10 +508,10 @@
end

it "Should not allow to add two parameters with identical name to a newly created method" do
field = {:default_value => nil,
:datatype => nil,
:name => "name01",
:method_id => nil}
field = {"default_value" => nil,
"datatype" => nil,
"name" => "name01",
"method_id" => nil}
session[:edit] = {
:key => "aemethod_edit__new",
:ae_class_id => @cls.id,
Expand Down Expand Up @@ -549,10 +549,10 @@
end

it "update a method with inputs" do
field = {:default_value => nil,
:datatype => nil,
:name => "name01",
:method_id => @method.id}
field = {"default_value" => nil,
"datatype" => nil,
"name" => "name01",
"method_id" => @method.id}
session[:edit] = {
:key => "aemethod_edit__#{@method.id}",
:fields_to_delete => [],
Expand All @@ -573,9 +573,9 @@
end

it "update a class with fields" do
field = {:aetype => "attribute",
:datatype => "string",
:name => "name01"}
field = {"aetype" => "attribute",
"datatype" => "string",
"name" => "name01"}
session[:edit] = {
:key => "aefields_edit__#{@cls.id}",
:ae_class_id => @cls.id,
Expand All @@ -593,9 +593,9 @@
end

it "update a default value of existing class field" do
field = {:aetype => "attribute",
:default_value => "Wilma",
:name => "name01"}
field = {"aetype" => "attribute",
"default_value" => "Wilma",
"name" => "name01"}
session[:field_data] = field
session[:edit] = {
:key => "aefields_edit__#{@cls.id}",
Expand Down Expand Up @@ -670,20 +670,20 @@
ns = FactoryGirl.create(:miq_ae_namespace)
cls = FactoryGirl.create(:miq_ae_class, :namespace_id => ns.id)
field1 = FactoryGirl.create(:miq_ae_field,
:aetype => "attribute",
:datatype => "string",
:name => "name01",
:class_id => cls.id,
:priority => 1)
"aetype" => "attribute",
"datatype" => "string",
"name" => "name01",
"class_id" => cls.id,
"priority" => 1)
field2 = FactoryGirl.create(:miq_ae_field,
:aetype => "attribute",
:datatype => "string",
:name => "name02",
:class_id => cls.id,
:priority => 2)
field3 = {:aetype => "attribute",
:datatype => "string",
:name => "name03"}
"aetype" => "attribute",
"datatype" => "string",
"name" => "name02",
"class_id" => cls.id,
"priority" => 2)
field3 = {"aetype" => "attribute",
"datatype" => "string",
"name" => "name03"}
edit = {:fields_to_delete => [], :new => {:fields => [field2, field3, field1]}}
controller.instance_variable_set(:@edit, edit)
controller.instance_variable_set(:@ae_class, cls)
Expand Down

0 comments on commit fd7155d

Please sign in to comment.