Skip to content

Commit

Permalink
Change to invalid state if the test case has been planned.
Browse files Browse the repository at this point in the history
  • Loading branch information
kawasima committed Jun 12, 2012
1 parent 6642507 commit ee5bc09
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 46 deletions.
67 changes: 37 additions & 30 deletions app/controllers/impasse/test_case_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ class TestCaseController < AbstractController
before_filter :find_project, :authorize

def index
@nodes = Node.find(:all, :conditions => ["name=? and node_type_id=?", @project.identifier, 1])
end

def list
Expand Down Expand Up @@ -44,15 +43,17 @@ def new
respond_to do |format|
format.json { render :json => [@test_case] }
end
rescue
rescue ActiveRecord::RecordInvalid => e
respond_to do |format|
errors = []
errors.concat(@node.errors.full_messages).concat(@test_case.errors.full_messages)
@test_steps.each {|test_step|
test_step.errors.each_full {|msg|
errors << "##{test_step.step_number} #{msg}"
if @test_steps
@test_steps.each {|test_step|
test_step.errors.each_full {|msg|
errors << "##{test_step.step_number} #{msg}"
}
}
}
end
format.json { render :json => { :errors => errors }}
end
end
Expand Down Expand Up @@ -92,7 +93,6 @@ def move
def edit
@node, @test_case = get_node(params[:node])
@test_case.attributes = params[:test_case]
@keywords = Keyword.find_all_by_project_id(@project)

if request.post?
begin
Expand All @@ -109,15 +109,17 @@ def edit
respond_to do |format|
format.json { render :json => [@test_case] }
end
rescue
rescue ActiveRecord::RecordInvalid => e
respond_to do |format|
errors = []
errors.concat(@node.errors.full_messages).concat(@test_case.errors.full_messages)
@test_steps.each {|test_step|
test_step.errors.each_full {|msg|
errors << "##{test_step.step_number} #{msg}"
if @test_steps
@test_steps.each {|test_step|
test_step.errors.each_full {|msg|
errors << "##{test_step.step_number} #{msg}"
}
}
}
end
format.json { render :json => { :errors => errors }}
end
end
Expand All @@ -130,27 +132,30 @@ def destroy
params[:node][:id].each do |id|
node = Node.find(id)
any_planned = false
node.all_decendant_cases_with_plan.each do |child|
if child.planned
TestCase.update_all("active=0", ["id=?", child.id])
any_planned = true
else
TestCase.delete(child.id)
child.destroy
end
end

unless any_planned
case node.node_type_id
when 2
TestSuite.delete(id)
node.destroy
when 3
if TestPlanCase.count_by_test_case_id(id) > 0
ActiveRecord::Base.transaction do
node.all_decendant_cases_with_plan.each do |child|
if child.planned?
TestCase.update_all("active=0", ["id=?", child.id])
any_planned = true
else
TestCase.delete(id)
TestCase.delete(child.id)
child.destroy
end
end

unless any_planned
case node.node_type_id
when 2
TestSuite.delete(id)
node.destroy
when 3
if TestPlanCase.count_by_test_case_id(id) > 0
TestCase.update_all("active=0", ["id=?", child.id])
else
TestCase.delete(id)
node.destroy
end
end
end
end
Expand All @@ -175,6 +180,7 @@ def new_node
case params[:node_type]
when 'test_case'
@test_case = TestCase.new(params[:test_case])
@test_case.active = true
@node.node_type_id = 3
else
@test_case = TestSuite.new(params[:test_case])
Expand Down Expand Up @@ -206,11 +212,12 @@ def save_node(node)
end

def save_keywords(node, keywords = "")
project_keywords = Keyword.find_all_by_project_id(@project)
node_keywords = node.node_keywords || []
words = keywords.split(/\s*,\s*/)
words.delete_if {|word| word =~ /^\s*$/}.uniq!
words.each{|word|
keyword = @keywords.detect {|k| k.keyword == word}
keyword = project_keywords.detect {|k| k.keyword == word}
if keyword
node_keyword = node_keywords.detect {|nk| nk.keyword_id == keyword.id}
if node_keyword
Expand Down
13 changes: 12 additions & 1 deletion app/models/impasse/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class Node < ActiveRecord::Base

belongs_to :parent, :class_name=>'Node', :foreign_key=> :parent_id
has_many :children, :class_name=> 'Node', :foreign_key=> :parent_id
has_many :node_keywords
has_many :node_keywords, :class_name => "Impasse::NodeKeyword", :dependent => :delete_all
has_many :keywords, :through => :node_keywords

validates_presence_of :name
Expand All @@ -22,6 +22,10 @@ def active?
!(attributes['active'] and attributes['active'].to_i == 0)
end

def planned?
attributes['planned'].to_i == 1
end

def self.find_children(node_id, test_plan_id=nil, filters=nil)
sql = <<-'END_OF_SQL'
SELECT node.*, tc.active
Expand Down Expand Up @@ -50,6 +54,9 @@ def self.find_children(node_id, test_plan_id=nil, filters=nil)
) AS node
LEFT OUTER JOIN impasse_test_cases AS tc
ON node.id = tc.id
<% unless conditions.include? :filters_inactive %>
WHERE tc.active = 1 OR tc.active IS NULL
<% end %>
END_OF_SQL

conditions = {}
Expand All @@ -67,6 +74,10 @@ def self.find_children(node_id, test_plan_id=nil, filters=nil)
conditions[:filters_query] = "%#{filters[:query]}%"
end

if filters and filters[:inactive]
conditions[:filters_inactive] = true
end

find_by_sql([ERB.new(sql).result(binding), conditions])
end

Expand Down
6 changes: 5 additions & 1 deletion app/views/impasse/test_case/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,13 @@
<div style="display:none;">
<table>
<tr class="filter">
<td><%= label_tag "filters_query", "Text" %></td>
<td><%= label_tag "filters_query", l(:label_filters_query) %></td>
<td><%= text_field_tag "filters[query]", "", :id => "filters_query" %></td>
</tr>
<tr class="filter">
<td><%= label_tag "filters_inactive", l(:label_filters_inactive) %></td>
<td><%= check_box_tag "filters[inactive]", true, false, :id => "filters_inactive" %></td>
</tr>
</table>
</div>
</fieldset>
Expand Down
1 change: 1 addition & 0 deletions assets/javascripts/test_case_assign.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ jQuery(document).ready(function ($) {
data : function (n) {
return {
prefix: "plan",
"filters[inactive]": true,
node_id : n.attr ? n.attr("id").replace("plan_","") : -1
};
}
Expand Down
17 changes: 13 additions & 4 deletions assets/javascripts/test_case_tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ jQuery(document).ready(function ($) {
remove: LEAF_MENU.contextmenu.remove
}
};
var ROOT_MENU = {
contextmenu: {
create: FOLDER_MENU.contextmenu.create,
paste: FOLDER_MENU.contextmenu.paste
}
};

var dialog = {
test_suite: $("#testsuite-dialog").dialog({
Expand Down Expand Up @@ -206,9 +212,10 @@ jQuery(document).ready(function ($) {
prefix: "node",
node_id: n.attr ? n.attr("id").replace("node_","") : -1
};
$("#filters :input[name]").each(function() {
$("#filters").find(":text[name],:checkbox:checked").each(function() {
var el = $(this);
data[el.attr("name")] = el.val();
if (el.val())
data[el.attr("name")] = el.val();
});
return data;
}
Expand Down Expand Up @@ -245,11 +252,13 @@ jQuery(document).ready(function ($) {
}
})
.bind("loaded.jstree", function (e, data) {
$(this).find("li[rel=test_project],li[rel=test_suite]").data("jstree", FOLDER_MENU);
$(this).find("li[rel=test_project]").data("jstree", ROOT_MENU);
$(this).find("li[rel=test_suite]").data("jstree", FOLDER_MENU);
$(this).find("li[rel=test_case]").data("jstree", LEAF_MENU);
})
.bind("refresh.jstree", function (e, data) {
$(this).find("li[rel=test_project],li[rel=test_suite]").data("jstree", FOLDER_MENU);
$(this).find("li[rel=test_project]").data("jstree", ROOT_MENU);
$(this).find("li[rel=test_suite]").data("jstree", FOLDER_MENU);
$(this).find("li[rel=test_case]").data("jstree", LEAF_MENU);
})
.bind("create.jstree", function (e, data) {
Expand Down
25 changes: 16 additions & 9 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,40 @@ en:
label_test_suite_new: "New test suite"
label_test_suite_edit: "Edit test suite"

label_assined_to_myself: "only assigned to me"
label_execution_status_0: "Not yet"
label_execution_status_1: "OK"
label_execution_status_2: "NG"
label_execution_status_3: "Block"

label_impasse_stat_total_cases: "total cases"
label_impasse_stat_total_executions: "executed cases"
label_impasse_stat_total_bugs: "bugs"
label_impasse_stat_open_bugs: "(open)"
label_impasse_stat_executions_rate: "progress rate"
label_impasse_stat_bugs_rate: "bugs rate"
label_impasse_stat_remain_cases: "Remain"
label_impasse_stat_expected_cases: "Estimate"
label_impasse_stat_overview: "Overview"
label_impasse_stat_members: "Each members"
label_impasse_stat_daily: "Daily summary"

label_assined_to_myself: "only assigned to me"
label_execution_status_0: "Not yet"
label_execution_status_1: "OK"
label_execution_status_2: "NG"
label_execution_status_3: "Block"

label_filters_query: "Includes words "
label_filters_inactive: "Includes invalid cases"

field_details: "Details"
field_preconditions: "Preconditions"
field_importance: "Importance"
field_test_steps: "Steps"
field_test_step_actions: "Actions"
field_test_step_expected_results: "Expected Results"
field_actions: "Actions"
field_expected_results: "Expected Results"
field_execution_status: "Execution status"
field_bug_tracker: "Tracker as bugs"

button_create_test_plan: "Create a test plan"

permission_view_testcases: "View test cases"
permission_manage_test_cases: "Manage test cases"
button_create_test_plan: "Create a test plan"

error_can_not_manage_test_cases: "You aren't permitted to manage test cases."

Expand Down
5 changes: 4 additions & 1 deletion config/locales/ja.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@ ja:
label_impasse_stat_members: "人別集計"
label_impasse_stat_daily: "日別集計"


label_assined_to_myself: "自分の担当のみ"
label_execution_status_0: "未実行"
label_execution_status_1: "合格"
label_execution_status_2: "不合格"
label_execution_status_3: "保留"

label_filters_query: "含まれる文字列"
label_filters_inactive: "無効なケースも対象にする"

field_details: "詳細"
field_preconditions: "前提条件"
Expand All @@ -54,3 +55,5 @@ ja:
error_can_not_manage_test_cases: "権限がないため、その操作は行えません。"
text_assign_cases: "ここにケースをドラッグ&ドロップするとテスト計画に追加できます"
text_assign_users: "日付やメンバをケースにドラッグ&ドロップすると、ケースの実行予定日やテスターの割当ができます"
field_test_step_actions: Actions
field_test_step_expected_results: Expected Results

0 comments on commit ee5bc09

Please sign in to comment.