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

Fixed code to expect keys as strings instead of symbols. #13087

Merged
merged 1 commit into from
Dec 9, 2016
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
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 @@ -2181,7 +2181,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 @@ -2191,12 +2191,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 @@ -2206,7 +2205,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 @@ -489,20 +489,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 @@ -518,10 +518,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 @@ -559,10 +559,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 @@ -583,9 +583,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 @@ -603,9 +603,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 @@ -706,20 +706,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