kawasima / redmine_impasse

The redmine plugin for test management.
http://kawasima.github.com/redmine_impasse/
91 stars 99 forks source link

Bugfix: Copy test cases to another project #226

Open vegetadevelop opened 10 years ago

vegetadevelop commented 10 years ago

"Copy" (to another project) button click have no effect.

My solution: in app/views/impasse_test_case/index.html.erb file added this html form (id edit_copy_tests) called in assets/javascripts/test_case_tree.js on "button-copy-exec" click event handler:

<!-- C.V. BUGFIX <copy to another project a test case> button don't sent copy request and its data. Solution: added this html form called in assets/javascripts/test_case_tree.js -->
<form id="edit_copy_tests" class="tabular" action="<%=url_for :controller => :impasse_test_case, :action => :copy_to_another_project, :project_id => @project %>" method="post" enctype="multipart/form-data">
  <% if @allowed_projects.present? %>
<p><%=l(:notice_copy_cases_to_another_project)%></p>
<% if Rails::VERSION::MAJOR < 3 %>
      <% labelled_tabular_form_for :copy_tests, @project, { :action => :copy_to_another_project } do |f| %>
    <p>
      <label for="dest_project_id"><%= l(:field_project) %></label>
      <%= select_tag('dest_project_id', project_tree_options_for_select(@allowed_projects, :selected => @target_project)) %>
    </p>
  <% end %>
<% else %>
      <% output = labelled_tabular_form_for @project, :as => :copy_tests, :url => { :action => :copy_to_another_project } do |f| %>
    <p>
      <label for="dest_project_id"><%= l(:field_project) %></label>
      <%= select_tag('dest_project_id', project_tree_options_for_select(@allowed_projects, :selected => @target_project)) %>
    </p>
  <% end %>
      <%= output %>
    <% end %>
<p>
  <button id="button-copy-exec" type="button"><%= l(:button_copy)%></button>
  <button id="button-copy-cancel" type="button"><%= l(:button_cancel)%></button>
</p>
  <% else %>
<p class="nodata"><%=l(:notice_no_projects_to_copy_cases)%></p>
  <% end %>
</div>
<div class="floating" style="width : 100%;">
  <div id="requirements-view" style="width: 100%;"></div>
  <div id="test-case-view" style="width: 100%;"></div>
</div>
<!-- C.V. BUGFIX </copy to another project a test case>: form closed here -->
</form>

Note: I added only form tag


Next sub-issue: only stepless test cases will copied. There is a problem with the copy of test case's steps.

My solution: in app/controllers/impasse_test_case_controller.rb file, in "copy_to_another_project" function definition there is a misprint: "attr[:test_case_id] = new_test_case._id" the correct field is "id" not "_id". This is the code:

       case new_node.node_type_id
        when 2
          test_suite = Impasse::TestSuite.find(node.id)
          new_test_suite = test_suite.dup
          new_test_suite.id = new_node.id
          new_test_suite.save!
        when 3
          test_case = Impasse::TestCase.find(:first, :conditions => { :id => node.id }, :include => :test_steps)
          new_test_case = test_case.dup
          new_test_case.id = new_node.id
          new_test_case.save!
          test_case.test_steps.each do |ts|
            attr = ts.attributes
            #---------------------------------------------------------------------      
            # C.V. BUGFIX: <copy to another project a test case> copy correctly its steps
            #   attr[:test_case_id] = new_test_case._id --> attr[:test_case_id] = new_test_case.id
            #   correct field is "id" not "_id"
            #---------------------------------------------------------------------      
            attr[:test_case_id] = new_test_case.id
            #attr[:test_case_id] = new_test_case._id
            #</copy to another project a test case>
            #---------------------------------------------------------------------
            Impasse::TestStep.create!(attr)
          end

My SW versions: Ruby 1.8.7 Rails 2.3.5 ( < 3 ) ---> WARNING: not tested with > 3 Redmine 1.4.7.stable.23 (MySQL) Impasse 1.2.2