Skip to content

Commit

Permalink
Priority wasn't being set for new fields
Browse files Browse the repository at this point in the history
https://bugzilla.redhat.com/show_bug.cgi?id=1292791

The priority wasn't being set for the newly added fields, before
being saved the fields were sorted and the fields with nil priority
floated to the top. Set the fields to the highest priority if they
are new
  • Loading branch information
mkanoor committed Dec 21, 2015
1 parent 78080d0 commit 679a6eb
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
4 changes: 3 additions & 1 deletion app/controllers/miq_ae_class_controller.rb
Expand Up @@ -2247,12 +2247,14 @@ def ns_set_record_vars(miqaens)
# Set record variables to new values
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?
new_field = MiqAeField.new
highest_priority += 1
new_field.priority = highest_priority
if @ae_method
new_field.method_id = @ae_method.id
new_field.priority = i + 1
else
new_field.class_id = @ae_class.id
end
Expand Down
31 changes: 31 additions & 0 deletions spec/controllers/miq_ae_class_controller_spec.rb
Expand Up @@ -388,6 +388,9 @@
set_user_privileges
ns = FactoryGirl.create(:miq_ae_namespace)
@cls = FactoryGirl.create(:miq_ae_class, :namespace_id => ns.id)
@cls.ae_fields << FactoryGirl.create(:miq_ae_field, :name => 'fred',
:class_id => @cls.id, :priority => 1)
@cls.save
@method = FactoryGirl.create(:miq_ae_method, :name => "method01", :scope => "class",
:language => "ruby", :class_id => @cls.id, :data => "exit MIQ_OK", :location => "inline")
expect(controller).to receive(:render)
Expand Down Expand Up @@ -504,4 +507,32 @@
expect(flash_messages.first[:message]).to include("Automate Namespace \"foo_namespace\": Delete successful")
end
end

context "#set_field_vars" do
it "sets priority of new schema fields" do
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)
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"}
edit = {:fields_to_delete => [], :new => {:fields => [field2, field3, field1]}}
controller.instance_variable_set(:@edit, edit)
controller.instance_variable_set(:@ae_class, cls)
fields = controller.send(:set_field_vars, cls)
priorities = fields.collect(&:priority)
expect(priorities).to eq([1, 2, 3])
end
end
end

0 comments on commit 679a6eb

Please sign in to comment.