diff --git a/app/controllers/impasse_test_case_controller.rb b/app/controllers/impasse_test_case_controller.rb index 8bf2432..becad68 100644 --- a/app/controllers/impasse_test_case_controller.rb +++ b/app/controllers/impasse_test_case_controller.rb @@ -50,9 +50,23 @@ def new save_keywords(@node, params[:node_keywords]) @test_case.id = @node.id if @node.is_test_case? and params.include? :test_steps - @test_steps = params[:test_steps].collect{|i, ts| Impasse::TestStep.new(ts) } + #--------------------------------------------------------------------- + # BUGFIX: sort test steps list correctly + # params[:test_steps] --> tmp_params (hash with key corresponding to the step number) --> tmp (sorted array) + #--------------------------------------------------------------------- + tmp_params = Hash.new + params[:test_steps].each do |k,v| + k = "#{v['step_number']}" + tmp_params[("#{k}").to_i] = v + end + tmp = tmp_params.sort + tmp_params.clear + @test_steps = tmp.collect{|i, ts| Impasse::TestStep.new(ts) } @test_steps.each{|ts| raise ActiveRecord::RecordInvalid.new(ts) unless ts.valid? } @test_case.test_steps.replace(@test_steps) + tmp.clear + # + #--------------------------------------------------------------------- end @test_case.save! render :json => { :status => 'success', :message => l(:notice_successful_create), :ids => [@test_case.id] } @@ -115,9 +129,23 @@ def edit save_keywords(@node, params[:node_keywords]) if @node.is_test_case? and params.include? :test_steps - @test_steps = params[:test_steps].collect{|i, ts| Impasse::TestStep.new(ts) } + #--------------------------------------------------------------------- + # BUGFIX: sort test steps list correctly + # params[:test_steps] --> tmp_params (hash with key corresponding to the step number) --> tmp (sorted array) + #--------------------------------------------------------------------- + tmp_params = Hash.new + params[:test_steps].each do |k,v| + k = "#{v['step_number']}" + tmp_params[("#{k}").to_i] = v + end + tmp = tmp_params.sort + tmp_params.clear + @test_steps = tmp.collect{|i, ts| Impasse::TestStep.new(ts) } @test_steps.each{|ts| raise ActiveRecord::RecordInvalid.new(ts) unless ts.valid? } @test_case.test_steps.replace(@test_steps) + tmp.clear + # + #--------------------------------------------------------------------- end if params[:attachments]