+27
@@ -0,0 +1,27 @@
|
||||
---
|
||||
# === Checklist for Issue(1) ===
|
||||
one:
|
||||
id: 1
|
||||
is_done: false
|
||||
subject: First todo
|
||||
issue_id: 1
|
||||
|
||||
two:
|
||||
id: 2
|
||||
is_done: true
|
||||
subject: Second todo
|
||||
issue_id: 1
|
||||
|
||||
# === Checklist for Issue(2) ===
|
||||
section_one:
|
||||
id: 4
|
||||
is_done: false
|
||||
subject: New section
|
||||
is_section: true
|
||||
issue_id: 2
|
||||
|
||||
three:
|
||||
id: 3
|
||||
is_done: true
|
||||
subject: Third todo
|
||||
issue_id: 2
|
||||
@@ -0,0 +1,91 @@
|
||||
# encoding: utf-8
|
||||
#
|
||||
# This file is a part of Redmine Checklists (redmine_checklists) plugin,
|
||||
# issue checklists management plugin for Redmine
|
||||
#
|
||||
# Copyright (C) 2011-2024 RedmineUP
|
||||
# http://www.redmineup.com/
|
||||
#
|
||||
# redmine_checklists is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# redmine_checklists is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with redmine_checklists. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
require File.expand_path('../../test_helper', __FILE__)
|
||||
class ChecklistsControllerTest < ActionController::TestCase
|
||||
fixtures :projects,
|
||||
:users,
|
||||
:roles,
|
||||
:members,
|
||||
:member_roles,
|
||||
:issues,
|
||||
:issue_statuses,
|
||||
:versions,
|
||||
:trackers,
|
||||
:projects_trackers,
|
||||
:issue_categories,
|
||||
:enabled_modules,
|
||||
:enumerations,
|
||||
:attachments,
|
||||
:workflows,
|
||||
:custom_fields,
|
||||
:custom_values,
|
||||
:custom_fields_projects,
|
||||
:custom_fields_trackers,
|
||||
:time_entries,
|
||||
:journals,
|
||||
:journal_details,
|
||||
:queries
|
||||
RedmineChecklists::TestCase.create_fixtures(Redmine::Plugin.find(:redmine_checklists).directory + '/test/fixtures/', [:checklists])
|
||||
|
||||
def setup
|
||||
RedmineChecklists::TestCase.prepare
|
||||
Setting.default_language = 'en'
|
||||
Project.find(1).enable_module!(:checklists)
|
||||
User.current = nil
|
||||
@project_1 = Project.find(1)
|
||||
@issue_1 = Issue.find(1)
|
||||
@checklist_1 = Checklist.find(1)
|
||||
end
|
||||
|
||||
test "should post done" do
|
||||
# log_user('admin', 'admin')
|
||||
@request.session[:user_id] = 1
|
||||
|
||||
compatible_xhr_request :put, :done, :is_done => 'true', :id => '1'
|
||||
assert_response :success, 'Post done not working'
|
||||
assert_equal true, Checklist.find(1).is_done, 'Post done not working'
|
||||
end
|
||||
|
||||
test "should not post done by deny user" do
|
||||
# log_user('admin', 'admin')
|
||||
@request.session[:user_id] = 5
|
||||
|
||||
compatible_xhr_request :put, :done, :is_done => true, :id => "1"
|
||||
assert_response 403, "Post done accessible for all"
|
||||
end
|
||||
|
||||
test "should view issue with checklist" do
|
||||
# log_user('admin', 'admin')
|
||||
@request.session[:user_id] = 1
|
||||
@controller = IssuesController.new
|
||||
compatible_request :get, :show, :id => @issue_1.id
|
||||
assert_select 'ul#checklist_items li#checklist_item_1', @checklist_1.subject, "Issue won't view for admin"
|
||||
end
|
||||
|
||||
test "should not view issue with checklist if deny" do
|
||||
# log_user('anonymous', '')
|
||||
@request.session[:user_id] = 5
|
||||
@controller = IssuesController.new
|
||||
compatible_request :get, :show, :id => @issue_1.id
|
||||
assert_select 'ul#checklist_items', false, "Issue view for anonymous"
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,274 @@
|
||||
# encoding: utf-8
|
||||
#
|
||||
# This file is a part of Redmine Checklists (redmine_checklists) plugin,
|
||||
# issue checklists management plugin for Redmine
|
||||
#
|
||||
# Copyright (C) 2011-2024 RedmineUP
|
||||
# http://www.redmineup.com/
|
||||
#
|
||||
# redmine_checklists is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# redmine_checklists is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with redmine_checklists. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
require File.expand_path('../../test_helper', __FILE__)
|
||||
|
||||
# Re-raise errors caught by the controller.
|
||||
# class HelpdeskMailerController; def rescue_action(e) raise e end; end
|
||||
|
||||
class IssuesControllerTest < ActionController::TestCase
|
||||
fixtures :projects,
|
||||
:users,
|
||||
:roles,
|
||||
:members,
|
||||
:member_roles,
|
||||
:issues,
|
||||
:issue_statuses,
|
||||
:versions,
|
||||
:trackers,
|
||||
:projects_trackers,
|
||||
:issue_categories,
|
||||
:enabled_modules,
|
||||
:enumerations,
|
||||
:attachments,
|
||||
:workflows,
|
||||
:custom_fields,
|
||||
:custom_values,
|
||||
:custom_fields_projects,
|
||||
:custom_fields_trackers,
|
||||
:time_entries,
|
||||
:journals,
|
||||
:journal_details,
|
||||
:queries
|
||||
|
||||
RedmineChecklists::TestCase.create_fixtures(Redmine::Plugin.find(:redmine_checklists).directory + '/test/fixtures/', [:checklists])
|
||||
|
||||
def setup
|
||||
@request.session[:user_id] = 1
|
||||
RedmineChecklists::TestCase.prepare
|
||||
end
|
||||
|
||||
def test_new_issue_without_project
|
||||
compatible_request :get, :new
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
def test_get_show_issue
|
||||
issue = Issue.find(1)
|
||||
assert_not_nil issue.checklists.first
|
||||
compatible_request(:get, :show, :id => 1)
|
||||
assert_response :success
|
||||
assert_select "ul#checklist_items li#checklist_item_1", /First todo/
|
||||
assert_select "ul#checklist_items li#checklist_item_1 input[checked=?]", "checked", { :count => 0 }
|
||||
assert_select "ul#checklist_items li#checklist_item_2 input[checked=?]", "checked"
|
||||
end
|
||||
|
||||
def test_get_edit_issue
|
||||
compatible_request :get, :edit, :id => 1
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
def test_get_copy_issue
|
||||
compatible_request :get, :new, :project_id => 1, :copy_from => 1
|
||||
assert_response :success
|
||||
assert_select "span#checklist_form_items span.checklist-subject", { :count => 3 }
|
||||
assert_select "span#checklist_form_items span.checklist-edit input[value=?]", "First todo"
|
||||
end
|
||||
|
||||
def test_put_update_form
|
||||
parameters = {:tracker_id => 2,
|
||||
:checklists_attributes => {
|
||||
"0" => {"is_done"=>"0", "subject"=>"FirstChecklist"},
|
||||
"1" => {"is_done"=>"0", "subject"=>"Second"}}}
|
||||
|
||||
@request.session[:user_id] = 1
|
||||
issue = Issue.find(1)
|
||||
compatible_xhr_request :put, :new, :issue => parameters, :project_id => issue.project
|
||||
assert_response :success
|
||||
assert_match 'text/javascript', response.content_type
|
||||
assert_match 'FirstChecklist', response.body
|
||||
end
|
||||
|
||||
def test_added_attachment_shows_in_log_once
|
||||
Setting[:plugin_redmine_checklists] = { :save_log => 1, :issue_done_ratio => 0 }
|
||||
set_tmp_attachments_directory
|
||||
parameters = { :tracker_id => 2,
|
||||
:checklists_attributes => {
|
||||
'0' => { 'is_done' => '0', 'subject' => 'First' },
|
||||
'1' => { 'is_done' => '0', 'subject' => 'Second' } } }
|
||||
@request.session[:user_id] = 1
|
||||
issue = Issue.find(1)
|
||||
compatible_request :post, :update, :issue => parameters,
|
||||
:attachments => { '1' => { 'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file' } },
|
||||
:project_id => issue.project,
|
||||
:id => issue.to_param
|
||||
assert_response :redirect
|
||||
assert_equal 1, Journal.last.details.where(:property => 'attachment').count
|
||||
end
|
||||
|
||||
def test_history_dont_show_old_format_checklists
|
||||
Setting[:plugin_redmine_checklists] = { :save_log => 1, :issue_done_ratio => 0 }
|
||||
@request.session[:user_id] = 1
|
||||
issue = Issue.find(1)
|
||||
issue.journals.create!(:user_id => 1)
|
||||
issue.journals.last.details.create!(:property => 'attr',
|
||||
:prop_key => 'checklist',
|
||||
:old_value => '[ ] TEST',
|
||||
:value => '[x] TEST')
|
||||
|
||||
compatible_request :post, :show, :id => issue.id
|
||||
assert_response :success
|
||||
last_journal = issue.journals.last
|
||||
assert_equal last_journal.details.size, 1
|
||||
assert_equal last_journal.details.first.prop_key, 'checklist'
|
||||
assert_select "#change-#{last_journal.id} .details li", 'Checklist item changed from [ ] TEST to [x] TEST'
|
||||
end
|
||||
|
||||
def test_empty_update_dont_write_to_journal
|
||||
@request.session[:user_id] = 1
|
||||
issue = Issue.find(1)
|
||||
journals_before = issue.journals.count
|
||||
compatible_request :post, :update, :issue => {}, :id => issue.to_param, :project_id => issue.project
|
||||
assert_response :redirect
|
||||
assert_equal journals_before, issue.reload.journals.count
|
||||
end
|
||||
|
||||
def test_create_issue_without_checklists
|
||||
@request.session[:user_id] = 1
|
||||
assert_difference 'Issue.count' do
|
||||
compatible_request :post, :create, :project_id => 1, :issue => { :tracker_id => 3,
|
||||
:status_id => 2,
|
||||
:subject => 'NEW issue without checklists',
|
||||
:description => 'This is the description'
|
||||
}
|
||||
end
|
||||
assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
|
||||
|
||||
issue = Issue.find_by_subject('NEW issue without checklists')
|
||||
assert_not_nil issue
|
||||
end
|
||||
|
||||
def test_create_issue_with_checklists
|
||||
@request.session[:user_id] = 1
|
||||
assert_difference 'Issue.count' do
|
||||
compatible_request :post, :create, :project_id => 1, :issue => { :tracker_id => 3,
|
||||
:status_id => 2,
|
||||
:subject => 'NEW issue with checklists',
|
||||
:description => 'This is the description',
|
||||
:checklists_attributes => { '0' => { 'is_done' => '0', 'subject' => 'item 001', 'position' => '1' } }
|
||||
}
|
||||
end
|
||||
assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
|
||||
|
||||
issue = Issue.find_by_subject('NEW issue with checklists')
|
||||
assert_equal 1, issue.checklists.count
|
||||
assert_equal 'item 001', issue.checklists.last.subject
|
||||
assert_not_nil issue
|
||||
end
|
||||
|
||||
def test_delete_issue_with_checklists
|
||||
@request.session[:user_id] = 1
|
||||
other_checklist = Checklist.first
|
||||
other_checklist.update(position: 2)
|
||||
|
||||
assert_difference('Issue.count', -1) do
|
||||
assert_difference('Checklist.count', -2) do
|
||||
compatible_request :post, :destroy, id: '2'
|
||||
assert_response :redirect
|
||||
end
|
||||
end
|
||||
assert_equal other_checklist.position, other_checklist.reload.position
|
||||
end
|
||||
|
||||
def test_create_issue_using_json
|
||||
old_value = Setting.rest_api_enabled
|
||||
Setting.rest_api_enabled = '1'
|
||||
@request.session[:user_id] = 1
|
||||
assert_difference 'Issue.count' do
|
||||
compatible_request :post, :create, :format => :json, :project_id => 1, :issue => { :tracker_id => 3,
|
||||
:status_id => 2,
|
||||
:subject => 'NEW JSON issue',
|
||||
:description => 'This is the description',
|
||||
:checklists_attributes => [{ :is_done => 0, :subject => 'JSON checklist' }]
|
||||
},
|
||||
:key => User.find(1).api_key
|
||||
end
|
||||
assert_response :created
|
||||
|
||||
issue = Issue.find_by_subject('NEW JSON issue')
|
||||
assert_not_nil issue
|
||||
assert_equal 1, issue.checklists.count
|
||||
ensure
|
||||
Setting.rest_api_enabled = old_value
|
||||
end
|
||||
|
||||
def test_history_displaying_for_checklist
|
||||
@request.session[:user_id] = 1
|
||||
Setting[:plugin_redmine_checklists] = { save_log: 1, issue_done_ratio: 0 }
|
||||
|
||||
issue = Issue.find(1)
|
||||
journal = issue.journals.create!(user_id: 1)
|
||||
journal.details.create!(:property => 'attr',
|
||||
:prop_key => 'checklist',
|
||||
:old_value => '[ ] TEST',
|
||||
:value => '[x] TEST')
|
||||
|
||||
# With permissions
|
||||
@request.session[:user_id] = 1
|
||||
compatible_request :get, :show, id: issue.id
|
||||
assert_response :success
|
||||
assert_include 'changed from [ ] TEST to [x] TEST', response.body
|
||||
|
||||
# Without permissions
|
||||
@request.session[:user_id] = 5
|
||||
compatible_request :get, :show, id: issue.id
|
||||
assert_response :success
|
||||
assert_not_include 'changed from [ ] TEST to [x] TEST', response.body
|
||||
end
|
||||
|
||||
def test_bulk_copy_issues_with_checklists
|
||||
@target_project = Project.find(2)
|
||||
@target_project.issues.destroy_all
|
||||
issue1 = Issue.find(1) # issue with checklists
|
||||
issue3 = Issue.find(3) # issue without checklists
|
||||
|
||||
@request.session[:user_id] = 2
|
||||
|
||||
assert_difference 'Issue.count', 2 do
|
||||
assert_no_difference 'Project.find(1).issues.count' do
|
||||
post(
|
||||
:bulk_update,
|
||||
:params => {
|
||||
:ids => [issue1.id, issue3.id],
|
||||
:copy => '1',
|
||||
:issue => {
|
||||
:project_id => @target_project.id,
|
||||
:tracker_id => '',
|
||||
:assigned_to_id => '2',
|
||||
:status_id => '1'
|
||||
}
|
||||
}
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
copied_issues = Issue.where(project_id: @target_project.id)
|
||||
assert_equal 2, copied_issues.count
|
||||
copied_issues.each do |issue|
|
||||
assert_equal @target_project.id, issue.project_id, "Project is incorrect"
|
||||
assert_equal 2, issue.assigned_to_id, "Assigned to is incorrect"
|
||||
assert_equal 1, issue.status_id, "Status is incorrect"
|
||||
end
|
||||
|
||||
issue_with_checklists = copied_issues.select { |issue| issue.checklists.present? }.first
|
||||
assert_equal issue1.checklists.count, issue_with_checklists.checklists.count
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,166 @@
|
||||
# encoding: utf-8
|
||||
#
|
||||
# This file is a part of Redmine Checklists (redmine_checklists) plugin,
|
||||
# issue checklists management plugin for Redmine
|
||||
#
|
||||
# Copyright (C) 2011-2024 RedmineUP
|
||||
# http://www.redmineup.com/
|
||||
#
|
||||
# redmine_checklists is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# redmine_checklists is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with redmine_checklists. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
require File.expand_path('../../../test_helper', __FILE__)
|
||||
|
||||
class Redmine::ApiTest::ChecklistsTest < Redmine::ApiTest::Base
|
||||
fixtures :projects,
|
||||
:users,
|
||||
:roles,
|
||||
:members,
|
||||
:member_roles,
|
||||
:issues,
|
||||
:issue_statuses,
|
||||
:versions,
|
||||
:trackers,
|
||||
:projects_trackers,
|
||||
:issue_categories,
|
||||
:enabled_modules,
|
||||
:enumerations,
|
||||
:attachments,
|
||||
:workflows,
|
||||
:custom_fields,
|
||||
:custom_values,
|
||||
:custom_fields_projects,
|
||||
:custom_fields_trackers,
|
||||
:time_entries,
|
||||
:journals,
|
||||
:journal_details,
|
||||
:queries
|
||||
|
||||
RedmineChecklists::TestCase.create_fixtures(Redmine::Plugin.find(:redmine_checklists).directory + '/test/fixtures/', [:checklists])
|
||||
|
||||
def setup
|
||||
Setting.rest_api_enabled = '1'
|
||||
end
|
||||
|
||||
def test_get_checklists_xml
|
||||
compatible_api_request :get, '/issues/1/checklists.xml', {}, credentials('admin')
|
||||
|
||||
assert_select 'checklists[type=array]' do
|
||||
assert_select 'checklist' do
|
||||
assert_select 'id', :text => '1'
|
||||
assert_select 'subject', :text => 'First todo'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_get_checklists_with_section_xml
|
||||
compatible_api_request :get, '/issues/2/checklists.xml', {}, credentials('admin')
|
||||
|
||||
assert_select 'checklists[type=array]' do
|
||||
assert_select 'checklist' do
|
||||
assert_select 'id', :text => '4'
|
||||
assert_select 'subject', :text => 'New section'
|
||||
assert_select 'is_section', :text => 'true'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_get_checklists_1_xml
|
||||
compatible_api_request :get, '/checklists/1.xml', {}, credentials('admin')
|
||||
|
||||
assert_select 'checklist' do
|
||||
assert_select 'id', :text => '1'
|
||||
assert_select 'subject', :text => 'First todo'
|
||||
end
|
||||
end
|
||||
|
||||
def test_get_checklists_2_with_section_xml
|
||||
compatible_api_request :get, '/checklists/4.xml', {}, credentials('admin')
|
||||
|
||||
assert_select 'checklist' do
|
||||
assert_select 'id', :text => '4'
|
||||
assert_select 'subject', :text => 'New section'
|
||||
assert_select 'is_section', :text => 'true'
|
||||
end
|
||||
end
|
||||
|
||||
def test_checklists_2_should_not_section_xml
|
||||
compatible_api_request :get, '/checklists/3.xml', {}, credentials('admin')
|
||||
|
||||
assert_select 'checklist' do
|
||||
assert_select 'id', :text => '3'
|
||||
assert_select 'subject', :text => 'Third todo'
|
||||
assert_select 'is_section', :text => 'false'
|
||||
end
|
||||
end
|
||||
|
||||
def test_post_checklists_xml
|
||||
parameters = { :checklist => { :issue_id => 1,
|
||||
:subject => 'api_test_001',
|
||||
:is_done => true } }
|
||||
assert_difference('Checklist.count') do
|
||||
compatible_api_request :post, '/issues/1/checklists.xml', parameters, credentials('admin')
|
||||
end
|
||||
|
||||
checklist = Checklist.order('id DESC').first
|
||||
assert_equal parameters[:checklist][:subject], checklist.subject
|
||||
|
||||
assert_response :created
|
||||
assert_match 'application/xml', @response.content_type
|
||||
assert_select 'checklist id', :text => checklist.id.to_s
|
||||
end
|
||||
|
||||
def test_put_checklists_1_xml
|
||||
parameters = { :checklist => { subject: 'Item_UPDATED', is_done: '1' } }
|
||||
|
||||
assert_no_difference('Checklist.count') do
|
||||
compatible_api_request :put, '/checklists/1.xml', parameters, credentials('admin')
|
||||
end
|
||||
|
||||
checklist = Checklist.find(1)
|
||||
assert_equal parameters[:checklist][:subject], checklist.subject
|
||||
end
|
||||
|
||||
def test_recalculate_ratio_after_multirequests
|
||||
issue = Issue.find(1)
|
||||
with_checklists_settings('issue_done_ratio' => '1') do
|
||||
assert_equal 0, issue.reload.done_ratio
|
||||
|
||||
parameters_array = [
|
||||
[1, { :checklist => { subject: 'Item 1', is_done: '1' } }],
|
||||
[2, { :checklist => { subject: 'Item 2', is_done: '1' } }],
|
||||
[1, { :checklist => { subject: 'Item 1', is_done: '0' } }],
|
||||
[2, { :checklist => { subject: 'Item 2', is_done: '1' } }]
|
||||
]
|
||||
|
||||
assert_no_difference('Checklist.count') do
|
||||
parameters_array.each do |params|
|
||||
compatible_api_request :put, "/checklists/#{params[0]}.xml", params[1], credentials('admin')
|
||||
assert ['200', '204'].include?(response.code)
|
||||
end
|
||||
end
|
||||
|
||||
assert_equal 50, issue.reload.done_ratio
|
||||
end
|
||||
end
|
||||
|
||||
def test_delete_1_xml
|
||||
assert_difference 'Checklist.count', -1 do
|
||||
compatible_api_request :delete, '/checklists/1.xml', {}, credentials('admin')
|
||||
end
|
||||
|
||||
assert ['200', '204'].include?(response.code)
|
||||
assert_equal '', @response.body
|
||||
assert_nil Checklist.find_by_id(1)
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,62 @@
|
||||
# encoding: utf-8
|
||||
#
|
||||
# This file is a part of Redmine Checklists (redmine_checklists) plugin,
|
||||
# issue checklists management plugin for Redmine
|
||||
#
|
||||
# Copyright (C) 2011-2024 RedmineUP
|
||||
# http://www.redmineup.com/
|
||||
#
|
||||
# redmine_checklists is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# redmine_checklists is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with redmine_checklists. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
require File.expand_path('../../test_helper', __FILE__)
|
||||
class CommonIssueTest < RedmineChecklists::IntegrationTest
|
||||
fixtures :projects,
|
||||
:users,
|
||||
:roles,
|
||||
:members,
|
||||
:member_roles,
|
||||
:issues,
|
||||
:issue_statuses,
|
||||
:versions,
|
||||
:trackers,
|
||||
:projects_trackers,
|
||||
:issue_categories,
|
||||
:enabled_modules,
|
||||
:enumerations,
|
||||
:attachments,
|
||||
:workflows,
|
||||
:custom_fields,
|
||||
:custom_values,
|
||||
:custom_fields_projects,
|
||||
:custom_fields_trackers,
|
||||
:time_entries,
|
||||
:journals,
|
||||
:journal_details,
|
||||
:queries
|
||||
RedmineChecklists::TestCase.create_fixtures(Redmine::Plugin.find(:redmine_checklists).directory + '/test/fixtures/', [:checklists])
|
||||
|
||||
def setup
|
||||
RedmineChecklists::TestCase.prepare
|
||||
Setting.default_language = 'en'
|
||||
@project_1 = Project.find(1)
|
||||
@issue_1 = Issue.find(1)
|
||||
@checklist_1 = Checklist.find(1)
|
||||
end
|
||||
|
||||
def test_global_search_with_checklist
|
||||
log_user('admin', 'admin')
|
||||
compatible_request :get, '/search?q=First'
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,86 @@
|
||||
# encoding: utf-8
|
||||
#
|
||||
# This file is a part of Redmine Checklists (redmine_checklists) plugin,
|
||||
# issue checklists management plugin for Redmine
|
||||
#
|
||||
# Copyright (C) 2011-2024 RedmineUP
|
||||
# http://www.redmineup.com/
|
||||
#
|
||||
# redmine_checklists is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# redmine_checklists is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with redmine_checklists. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
require File.expand_path(File.dirname(__FILE__) + '/../../../test/test_helper')
|
||||
|
||||
module RedmineChecklists
|
||||
module TestHelper
|
||||
def compatible_request(type, action, parameters = {})
|
||||
return send(type, action, :params => parameters) if Rails.version >= '5.1'
|
||||
send(type, action, parameters)
|
||||
end
|
||||
|
||||
def compatible_xhr_request(type, action, parameters = {})
|
||||
return send(type, action, :params => parameters, :xhr => true) if Rails.version >= '5.1'
|
||||
xhr type, action, parameters
|
||||
end
|
||||
|
||||
def compatible_api_request(type, action, parameters = {}, headers = {})
|
||||
return send(type, action, :params => parameters, :headers => headers) if Redmine::VERSION.to_s >= '3.4'
|
||||
send(type, action, parameters, headers)
|
||||
end
|
||||
|
||||
def issues_in_list
|
||||
ids = css_select('tr.issue td.id a').map { |tag| tag.to_s.gsub(/<.*?>/, '') }.map(&:to_i)
|
||||
Issue.where(:id => ids).sort_by { |issue| ids.index(issue.id) }
|
||||
end
|
||||
|
||||
def with_checklists_settings(options, &block)
|
||||
original_settings = Setting.plugin_redmine_checklists
|
||||
Setting.plugin_redmine_checklists = original_settings.merge(Hash[options.map {|k,v| [k, v]}])
|
||||
yield
|
||||
ensure
|
||||
Setting.plugin_redmine_checklists = original_settings
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
include RedmineChecklists::TestHelper
|
||||
|
||||
class RedmineChecklists::IntegrationTest < Redmine::IntegrationTest; end
|
||||
|
||||
class RedmineChecklists::TestCase
|
||||
def self.create_fixtures(fixtures_directory, table_names, class_names = {})
|
||||
ActiveRecord::FixtureSet.create_fixtures(fixtures_directory, table_names, class_names = {})
|
||||
end
|
||||
|
||||
def self.prepare
|
||||
Role.find([1,2]).each do |r| # For anonymous
|
||||
r.permissions << :view_checklists
|
||||
r.save
|
||||
end
|
||||
|
||||
Role.find(1, 2, 3, 4).each do |r|
|
||||
r.permissions << :edit_checklists
|
||||
r.save
|
||||
end
|
||||
|
||||
Role.find(3, 4).each do |r|
|
||||
r.permissions << :done_checklists
|
||||
r.save
|
||||
end
|
||||
|
||||
Role.find([2]).each do |r|
|
||||
r.permissions << :manage_checklist_templates
|
||||
r.save
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,138 @@
|
||||
# encoding: utf-8
|
||||
#
|
||||
# This file is a part of Redmine Checklists (redmine_checklists) plugin,
|
||||
# issue checklists management plugin for Redmine
|
||||
#
|
||||
# Copyright (C) 2011-2024 RedmineUP
|
||||
# http://www.redmineup.com/
|
||||
#
|
||||
# redmine_checklists is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# redmine_checklists is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with redmine_checklists. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
require File.expand_path('../../test_helper', __FILE__)
|
||||
|
||||
class ChecklistTest < ActiveSupport::TestCase
|
||||
fixtures :projects,
|
||||
:users,
|
||||
:roles,
|
||||
:members,
|
||||
:member_roles,
|
||||
:issues,
|
||||
:issue_statuses,
|
||||
:versions,
|
||||
:trackers,
|
||||
:projects_trackers,
|
||||
:issue_categories,
|
||||
:enabled_modules,
|
||||
:enumerations,
|
||||
:attachments,
|
||||
:workflows,
|
||||
:custom_fields,
|
||||
:custom_values,
|
||||
:custom_fields_projects,
|
||||
:custom_fields_trackers,
|
||||
:time_entries,
|
||||
:journals,
|
||||
:journal_details,
|
||||
:queries
|
||||
|
||||
RedmineChecklists::TestCase.create_fixtures(Redmine::Plugin.find(:redmine_checklists).directory + '/test/fixtures/', [:checklists])
|
||||
def setup
|
||||
RedmineChecklists::TestCase.prepare
|
||||
Setting.default_language = 'en'
|
||||
@project_1 = Project.find(1)
|
||||
@issue_1 = Issue.create(:project_id => 1, :tracker_id => 1, :author_id => 1,
|
||||
:status_id => 1, :priority => IssuePriority.first,
|
||||
:subject => 'Invoice Issue 1')
|
||||
@checklist_1 = Checklist.create(:subject => 'TEST1', :position => 1, :issue => @issue_1)
|
||||
end
|
||||
|
||||
test "should save checklist" do
|
||||
assert @checklist_1.save, "Checklist save error"
|
||||
end
|
||||
|
||||
test "should not save checklist without subject" do
|
||||
@checklist_1.subject = nil
|
||||
assert !@checklist_1.save, "Checklist save with nil subject"
|
||||
end
|
||||
|
||||
test "should not save checklist without position" do
|
||||
@checklist_1.position = nil
|
||||
assert !@checklist_1.save, "Checklist save with nil position"
|
||||
end
|
||||
|
||||
test "should not save checklist with non integer position" do
|
||||
@checklist_1.position = "string"
|
||||
assert !@checklist_1.save, "Checklist save with non ingeger position"
|
||||
end
|
||||
|
||||
test "should return project info" do
|
||||
assert_equal @project_1, @checklist_1.project, "Helper project broken"
|
||||
end
|
||||
|
||||
test "should return info about checklist" do
|
||||
assert_equal "[ ] #{@checklist_1.subject}", @checklist_1.info, "Helper info broken"
|
||||
@checklist_1.is_done = 1
|
||||
assert_equal "[x] #{@checklist_1.subject}", @checklist_1.info, "Helper info broken"
|
||||
end
|
||||
|
||||
def test_should_correct_recalculate_rate
|
||||
issues = [
|
||||
[Issue.create(project_id: 1, tracker_id: 1, author_id: 1, status_id: 1, priority: IssuePriority.first, subject: "TI #1", done_ratio: 0,
|
||||
checklists_attributes: {
|
||||
'0' => { subject: 'item 1', is_done: false },
|
||||
'1' => { subject: 'item 2', is_done: false },
|
||||
'2' => { subject: 'item 3', is_done: true },
|
||||
}),
|
||||
30],
|
||||
[Issue.create(project_id: 1, tracker_id: 1, author_id: 1, status_id: 1, priority: IssuePriority.first, subject: "TI #2", done_ratio: 0,
|
||||
checklists_attributes: {
|
||||
'0' => { subject: 'item 1', is_done: false },
|
||||
'1' => { subject: 'item 2', is_done: true },
|
||||
'2' => { subject: 'item 3', is_done: true },
|
||||
}),
|
||||
60],
|
||||
[Issue.create(project_id: 1, tracker_id: 1, author_id: 1, status_id: 1, priority: IssuePriority.first, subject: "TI #3", done_ratio: 0,
|
||||
checklists_attributes: {
|
||||
'0' => { subject: 'item 1', is_done: true },
|
||||
'1' => { subject: 'item 2', is_done: true },
|
||||
'2' => { subject: 'item 3', is_done: true },
|
||||
}),
|
||||
100],
|
||||
[Issue.create(project_id: 1, tracker_id: 1, author_id: 1, status_id: 1, priority: IssuePriority.first, subject: "TI #4", done_ratio: 0,
|
||||
checklists_attributes: {
|
||||
'0' => { subject: 'item 1', is_done: false },
|
||||
'1' => { subject: 'item 2', is_done: false },
|
||||
'2' => { subject: 'section 1', is_done: true, is_section: true },
|
||||
'3' => { subject: 'item 3', is_done: true },
|
||||
}),
|
||||
30],
|
||||
[Issue.create(project_id: 1, tracker_id: 1, author_id: 1, status_id: 1, priority: IssuePriority.first, subject: "TI #5", done_ratio: 0,
|
||||
checklists_attributes: {
|
||||
'0' => { subject: 'section 1', is_done: true, is_section: true }
|
||||
}),
|
||||
0]
|
||||
]
|
||||
|
||||
with_checklists_settings('issue_done_ratio' => '1') do
|
||||
issues.each do |issue, after_ratio|
|
||||
assert_equal 0, issue.done_ratio
|
||||
Checklist.recalc_issue_done_ratio(issue.id)
|
||||
issue.reload
|
||||
assert_equal after_ratio, issue.done_ratio
|
||||
end
|
||||
end
|
||||
ensure
|
||||
issues.each { |issue, ratio| issue.destroy }
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,85 @@
|
||||
# encoding: utf-8
|
||||
#
|
||||
# This file is a part of Redmine Checklists (redmine_checklists) plugin,
|
||||
# issue checklists management plugin for Redmine
|
||||
#
|
||||
# Copyright (C) 2011-2024 RedmineUP
|
||||
# http://www.redmineup.com/
|
||||
#
|
||||
# redmine_checklists is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# redmine_checklists is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with redmine_checklists. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
require File.expand_path('../../test_helper', __FILE__)
|
||||
include RedmineChecklists::TestHelper
|
||||
|
||||
class IssueTest < ActiveSupport::TestCase
|
||||
fixtures :projects,
|
||||
:users,
|
||||
:roles,
|
||||
:members,
|
||||
:member_roles,
|
||||
:issues,
|
||||
:issue_statuses,
|
||||
:versions,
|
||||
:trackers,
|
||||
:projects_trackers,
|
||||
:issue_categories,
|
||||
:enabled_modules,
|
||||
:enumerations,
|
||||
:attachments,
|
||||
:workflows,
|
||||
:custom_fields,
|
||||
:custom_values,
|
||||
:custom_fields_projects,
|
||||
:custom_fields_trackers,
|
||||
:time_entries,
|
||||
:journals,
|
||||
:journal_details,
|
||||
:queries
|
||||
|
||||
RedmineChecklists::TestCase.create_fixtures(Redmine::Plugin.find(:redmine_checklists).directory + '/test/fixtures/', [:checklists])
|
||||
def setup
|
||||
RedmineChecklists::TestCase.prepare
|
||||
Setting.default_language = 'en'
|
||||
@project = Project.find(1)
|
||||
@issue = Issue.create(:project => @project, :tracker_id => 1, :author_id => 1,
|
||||
:status_id => 1, :priority => IssuePriority.first,
|
||||
:subject => 'TestIssue')
|
||||
@checklist_1 = Checklist.create(:subject => 'TEST1', :position => 1, :issue => @issue)
|
||||
@checklist_2 = Checklist.create(:subject => 'TEST2', :position => 2, :issue => @issue, :is_done => true)
|
||||
@issue.reload
|
||||
end
|
||||
|
||||
def test_issue_shouldnt_close_when_it_has_unfinished_checklists
|
||||
with_checklists_settings('block_issue_closing' => '1') do
|
||||
@issue.status_id = 5
|
||||
assert !@issue.valid?
|
||||
end
|
||||
end
|
||||
|
||||
def test_validation_should_be_ignored_if_setting_disabled
|
||||
with_checklists_settings('block_issue_closing' => '0') do
|
||||
@issue.status_id = 5
|
||||
assert @issue.valid?
|
||||
end
|
||||
end
|
||||
|
||||
def test_issue_should_close_when_all_checklists_finished
|
||||
with_checklists_settings('block_issue_closing' => '1') do
|
||||
@checklist_1.update(is_done: true)
|
||||
assert @issue.valid?
|
||||
end
|
||||
ensure
|
||||
@checklist_1.update(is_done: false)
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,73 @@
|
||||
# encoding: utf-8
|
||||
#
|
||||
# This file is a part of Redmine Checklists (redmine_checklists) plugin,
|
||||
# issue checklists management plugin for Redmine
|
||||
#
|
||||
# Copyright (C) 2011-2024 RedmineUP
|
||||
# http://www.redmineup.com/
|
||||
#
|
||||
# redmine_checklists is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# redmine_checklists is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with redmine_checklists. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
require File.expand_path('../../test_helper', __FILE__)
|
||||
|
||||
class ProjectTest < ActiveSupport::TestCase
|
||||
fixtures :projects,
|
||||
:users,
|
||||
:roles,
|
||||
:members,
|
||||
:member_roles,
|
||||
:issues,
|
||||
:issue_statuses,
|
||||
:versions,
|
||||
:trackers,
|
||||
:projects_trackers,
|
||||
:issue_categories,
|
||||
:enabled_modules,
|
||||
:enumerations,
|
||||
:attachments,
|
||||
:workflows,
|
||||
:custom_fields,
|
||||
:custom_values,
|
||||
:custom_fields_projects,
|
||||
:custom_fields_trackers,
|
||||
:time_entries,
|
||||
:journals,
|
||||
:journal_details,
|
||||
:queries
|
||||
|
||||
RedmineChecklists::TestCase.create_fixtures(Redmine::Plugin.find(:redmine_checklists).directory + '/test/fixtures/',
|
||||
[:checklists])
|
||||
def setup
|
||||
RedmineChecklists::TestCase.prepare
|
||||
Setting.default_language = 'en'
|
||||
@project_1 = Project.find(1)
|
||||
@issue_1 = Issue.create(:project => @project_1, :tracker_id => 1, :author_id => 1,
|
||||
:status_id => 1, :priority => IssuePriority.first,
|
||||
:subject => 'TestIssue')
|
||||
@checklist_1 = Checklist.create(:subject => 'TEST1', :position => 1, :issue => @issue_1)
|
||||
@checklist_1 = Checklist.create(:subject => 'TEST2', :position => 2, :issue => @issue_1, :is_done => true)
|
||||
end
|
||||
|
||||
test 'should copy checklists' do
|
||||
project_copy = Project.copy_from(Project.find(1))
|
||||
project_copy.name = 'Test name'
|
||||
project_copy.identifier = Project.next_identifier
|
||||
project_copy.copy(Project.find(1))
|
||||
|
||||
checklists_copies = project_copy.issues.where(:subject => 'TestIssue').first.checklists
|
||||
assert_equal(checklists_copies.count, 2)
|
||||
assert_equal(checklists_copies.where(:subject => 'TEST1').first.is_done, false)
|
||||
assert_equal(checklists_copies.where(:subject => 'TEST2').first.is_done, true)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user