From fca024ec28f3356cc1752e2ae01d1756cb971bd2 Mon Sep 17 00:00:00 2001 From: Haruyuki Iida Date: Tue, 25 Jul 2017 23:32:58 +0900 Subject: [PATCH 01/33] refs #1478 For Rails 5.1 --- app/models/code_review.rb | 4 +--- db/migrate/0001_create_code_reviews.rb | 4 ++-- db/migrate/0002_add_updated_by.rb | 4 ++-- db/migrate/0003_add_lock_version.rb | 4 ++-- db/migrate/0004_add_status_changed.rb | 4 ++-- db/migrate/0005_create_code_review_user_settings.rb | 4 ++-- db/migrate/0006_link_to_issue.rb | 4 ++-- db/migrate/0007_rename_user.rb | 4 ++-- db/migrate/0008_create_code_review_project_settings.rb | 4 ++-- db/migrate/0009_add_hide_tab.rb | 4 ++-- db/migrate/0010_add_action_type.rb | 4 ++-- db/migrate/0011_add_auto_relation.rb | 4 ++-- db/migrate/0012_add_attachment_id.rb | 4 ++-- db/migrate/0013_add_file_count.rb | 4 ++-- db/migrate/0014_create_code_review_assignments.rb | 4 ++-- db/migrate/0015_add_assignment_tracker.rb | 4 ++-- db/migrate/0016_add_changeset_id.rb | 4 ++-- db/migrate/0017_add_auto_assign.rb | 4 ++-- db/migrate/0018_add_lock_version_to_project_settings.rb | 4 ++-- db/migrate/0019_delete_old_fields.rb | 4 ++-- db/migrate/0020_add_tracker_to_review_dialog.rb | 4 ++-- db/migrate/0021_add_diff_all.rb | 4 ++-- 22 files changed, 43 insertions(+), 45 deletions(-) diff --git a/app/models/code_review.rb b/app/models/code_review.rb index e2cb549..4cc4dbf 100644 --- a/app/models/code_review.rb +++ b/app/models/code_review.rb @@ -1,5 +1,5 @@ # Code Review plugin for Redmine -# Copyright (C) 2009-2015 Haruyuki Iida +# Copyright (C) 2009-2017 Haruyuki Iida # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -29,8 +29,6 @@ class CodeReview < ActiveRecord::Base STATUS_OPEN = 0 STATUS_CLOSED = 1 - attr_accessible :change_id, :subject, :line, :parent_id, :comment, :status_id, :issue - def before_create issue = Issue.new unless issue end diff --git a/db/migrate/0001_create_code_reviews.rb b/db/migrate/0001_create_code_reviews.rb index 9410360..5bbf794 100644 --- a/db/migrate/0001_create_code_reviews.rb +++ b/db/migrate/0001_create_code_reviews.rb @@ -1,5 +1,5 @@ # Code Review plugin for Redmine -# Copyright (C) 2009 Haruyuki Iida +# Copyright (C) 2009-2017 Haruyuki Iida # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -15,7 +15,7 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -class CreateCodeReviews < ActiveRecord::Migration +class CreateCodeReviews < ActiveRecord::Migration[4.2] def self.up create_table :code_reviews do |t| diff --git a/db/migrate/0002_add_updated_by.rb b/db/migrate/0002_add_updated_by.rb index 21d8959..34630e3 100644 --- a/db/migrate/0002_add_updated_by.rb +++ b/db/migrate/0002_add_updated_by.rb @@ -1,5 +1,5 @@ # Code Review plugin for Redmine -# Copyright (C) 2009 Haruyuki Iida +# Copyright (C) 2009-2017 Haruyuki Iida # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -15,7 +15,7 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -class AddUpdatedBy < ActiveRecord::Migration +class AddUpdatedBy < ActiveRecord::Migration[4.2] def self.up add_column(:code_reviews, "updated_by_id", :integer) diff --git a/db/migrate/0003_add_lock_version.rb b/db/migrate/0003_add_lock_version.rb index 0ddb0ec..3ec794d 100644 --- a/db/migrate/0003_add_lock_version.rb +++ b/db/migrate/0003_add_lock_version.rb @@ -1,5 +1,5 @@ # Code Review plugin for Redmine -# Copyright (C) 2009 Haruyuki Iida +# Copyright (C) 2009-2017 Haruyuki Iida # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -15,7 +15,7 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -class AddLockVersion < ActiveRecord::Migration +class AddLockVersion < ActiveRecord::Migration[4.2] def self.up add_column(:code_reviews, "lock_version", :integer, :default=>0, :null => false) diff --git a/db/migrate/0004_add_status_changed.rb b/db/migrate/0004_add_status_changed.rb index ab110e1..793c7ee 100644 --- a/db/migrate/0004_add_status_changed.rb +++ b/db/migrate/0004_add_status_changed.rb @@ -1,5 +1,5 @@ # Code Review plugin for Redmine -# Copyright (C) 2009 Haruyuki Iida +# Copyright (C) 2009-2017 Haruyuki Iida # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -15,7 +15,7 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -class AddStatusChanged < ActiveRecord::Migration +class AddStatusChanged < ActiveRecord::Migration[4.2] def self.up add_column(:code_reviews, "status_changed_from", :integer) diff --git a/db/migrate/0005_create_code_review_user_settings.rb b/db/migrate/0005_create_code_review_user_settings.rb index e61a2a3..645573d 100644 --- a/db/migrate/0005_create_code_review_user_settings.rb +++ b/db/migrate/0005_create_code_review_user_settings.rb @@ -1,5 +1,5 @@ # Code Review plugin for Redmine -# Copyright (C) 2009 Haruyuki Iida +# Copyright (C) 2009-2017 Haruyuki Iida # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -14,7 +14,7 @@ # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -class CreateCodeReviewUserSettings < ActiveRecord::Migration +class CreateCodeReviewUserSettings < ActiveRecord::Migration[4.2] def self.up create_table :code_review_user_settings do |t| diff --git a/db/migrate/0006_link_to_issue.rb b/db/migrate/0006_link_to_issue.rb index 9d3ecb7..8ac80ec 100644 --- a/db/migrate/0006_link_to_issue.rb +++ b/db/migrate/0006_link_to_issue.rb @@ -1,5 +1,5 @@ # Code Review plugin for Redmine -# Copyright (C) 2009 Haruyuki Iida +# Copyright (C) 2009-2017 Haruyuki Iida # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -15,7 +15,7 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -class LinkToIssue < ActiveRecord::Migration +class LinkToIssue < ActiveRecord::Migration[4.2] def self.up add_column(:code_reviews, "issue_id", :integer) diff --git a/db/migrate/0007_rename_user.rb b/db/migrate/0007_rename_user.rb index 6a66866..debbc98 100644 --- a/db/migrate/0007_rename_user.rb +++ b/db/migrate/0007_rename_user.rb @@ -1,5 +1,5 @@ # Code Review plugin for Redmine -# Copyright (C) 2009 Haruyuki Iida +# Copyright (C) 2009-2017 Haruyuki Iida # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -15,7 +15,7 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -class RenameUser < ActiveRecord::Migration +class RenameUser < ActiveRecord::Migration[4.2] def self.up rename_column(:code_reviews, "user_id", "old_user_id") diff --git a/db/migrate/0008_create_code_review_project_settings.rb b/db/migrate/0008_create_code_review_project_settings.rb index 5bfdc8a..a4aa134 100644 --- a/db/migrate/0008_create_code_review_project_settings.rb +++ b/db/migrate/0008_create_code_review_project_settings.rb @@ -1,5 +1,5 @@ # Code Review plugin for Redmine -# Copyright (C) 2009 Haruyuki Iida +# Copyright (C) 2009-2017 Haruyuki Iida # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -14,7 +14,7 @@ # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -class CreateCodeReviewProjectSettings < ActiveRecord::Migration +class CreateCodeReviewProjectSettings < ActiveRecord::Migration[4.2] def self.up create_table :code_review_project_settings do |t| diff --git a/db/migrate/0009_add_hide_tab.rb b/db/migrate/0009_add_hide_tab.rb index ca09e29..832ad97 100644 --- a/db/migrate/0009_add_hide_tab.rb +++ b/db/migrate/0009_add_hide_tab.rb @@ -1,5 +1,5 @@ # Code Review plugin for Redmine -# Copyright (C) 2009 Haruyuki Iida +# Copyright (C) 2009-2017 Haruyuki Iida # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -15,7 +15,7 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -class AddHideTab < ActiveRecord::Migration +class AddHideTab < ActiveRecord::Migration[4.2] def self.up add_column(:code_review_project_settings, "hide_code_review_tab", :boolean, :default => false) diff --git a/db/migrate/0010_add_action_type.rb b/db/migrate/0010_add_action_type.rb index a64e306..2debb31 100644 --- a/db/migrate/0010_add_action_type.rb +++ b/db/migrate/0010_add_action_type.rb @@ -1,5 +1,5 @@ # Code Review plugin for Redmine -# Copyright (C) 2009 Haruyuki Iida +# Copyright (C) 2009-2017 Haruyuki Iida # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -15,7 +15,7 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -class AddActionType < ActiveRecord::Migration +class AddActionType < ActiveRecord::Migration[4.2] def self.up add_column(:code_reviews, "action_type", :string) diff --git a/db/migrate/0011_add_auto_relation.rb b/db/migrate/0011_add_auto_relation.rb index ee8fe73..d36e33e 100644 --- a/db/migrate/0011_add_auto_relation.rb +++ b/db/migrate/0011_add_auto_relation.rb @@ -1,5 +1,5 @@ # Code Review plugin for Redmine -# Copyright (C) 2009 Haruyuki Iida +# Copyright (C) 2009-2017 Haruyuki Iida # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -15,7 +15,7 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -class AddAutoRelation < ActiveRecord::Migration +class AddAutoRelation < ActiveRecord::Migration[4.2] def self.up add_column(:code_review_project_settings, "auto_relation", :integer, :default => 1) diff --git a/db/migrate/0012_add_attachment_id.rb b/db/migrate/0012_add_attachment_id.rb index ec2e7a0..c9c2b18 100644 --- a/db/migrate/0012_add_attachment_id.rb +++ b/db/migrate/0012_add_attachment_id.rb @@ -1,5 +1,5 @@ # Code Review plugin for Redmine -# Copyright (C) 2009 Haruyuki Iida +# Copyright (C) 2009-2017 Haruyuki Iida # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -15,7 +15,7 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -class AddAttachmentId < ActiveRecord::Migration +class AddAttachmentId < ActiveRecord::Migration[4.2] def self.up add_column(:code_reviews, "attachment_id", :integer) diff --git a/db/migrate/0013_add_file_count.rb b/db/migrate/0013_add_file_count.rb index 464d046..86a685b 100644 --- a/db/migrate/0013_add_file_count.rb +++ b/db/migrate/0013_add_file_count.rb @@ -1,5 +1,5 @@ # Code Review plugin for Redmine -# Copyright (C) 2009 Haruyuki Iida +# Copyright (C) 2009-2017 Haruyuki Iida # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -15,7 +15,7 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -class AddFileCount < ActiveRecord::Migration +class AddFileCount < ActiveRecord::Migration[4.2] def self.up add_column(:code_reviews, "file_count", :integer, :default => 0, :null => false) diff --git a/db/migrate/0014_create_code_review_assignments.rb b/db/migrate/0014_create_code_review_assignments.rb index a582d31..491294a 100644 --- a/db/migrate/0014_create_code_review_assignments.rb +++ b/db/migrate/0014_create_code_review_assignments.rb @@ -1,5 +1,5 @@ # Code Review plugin for Redmine -# Copyright (C) 2010 Haruyuki Iida +# Copyright (C) 2010-2017 Haruyuki Iida # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -15,7 +15,7 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -class CreateCodeReviewAssignments < ActiveRecord::Migration +class CreateCodeReviewAssignments < ActiveRecord::Migration[4.2] def self.up create_table :code_review_assignments do |t| diff --git a/db/migrate/0015_add_assignment_tracker.rb b/db/migrate/0015_add_assignment_tracker.rb index 08567e2..bf6cacf 100644 --- a/db/migrate/0015_add_assignment_tracker.rb +++ b/db/migrate/0015_add_assignment_tracker.rb @@ -1,5 +1,5 @@ # Code Review plugin for Redmine -# Copyright (C) 2009 Haruyuki Iida +# Copyright (C) 2009-2017 Haruyuki Iida # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -15,7 +15,7 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -class AddAssignmentTracker < ActiveRecord::Migration +class AddAssignmentTracker < ActiveRecord::Migration[4.2] def self.up add_column(:code_review_project_settings, "assignment_tracker_id", :integer) diff --git a/db/migrate/0016_add_changeset_id.rb b/db/migrate/0016_add_changeset_id.rb index 96536e8..29a6160 100644 --- a/db/migrate/0016_add_changeset_id.rb +++ b/db/migrate/0016_add_changeset_id.rb @@ -1,5 +1,5 @@ # Code Review plugin for Redmine -# Copyright (C) 2009 Haruyuki Iida +# Copyright (C) 2009-2017 Haruyuki Iida # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -15,7 +15,7 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -class AddChangesetId < ActiveRecord::Migration +class AddChangesetId < ActiveRecord::Migration[4.2] def self.up add_column(:code_review_assignments, "changeset_id", :integer) diff --git a/db/migrate/0017_add_auto_assign.rb b/db/migrate/0017_add_auto_assign.rb index 6e9c6fe..9a17953 100644 --- a/db/migrate/0017_add_auto_assign.rb +++ b/db/migrate/0017_add_auto_assign.rb @@ -1,5 +1,5 @@ # Code Review plugin for Redmine -# Copyright (C) 2009-2010 Haruyuki Iida +# Copyright (C) 2009-2017 Haruyuki Iida # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -15,7 +15,7 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -class AddAutoAssign < ActiveRecord::Migration +class AddAutoAssign < ActiveRecord::Migration[4.2] def self.up add_column(:code_review_project_settings, "auto_assign", :text) diff --git a/db/migrate/0018_add_lock_version_to_project_settings.rb b/db/migrate/0018_add_lock_version_to_project_settings.rb index c6ba8cf..9f766c2 100644 --- a/db/migrate/0018_add_lock_version_to_project_settings.rb +++ b/db/migrate/0018_add_lock_version_to_project_settings.rb @@ -1,5 +1,5 @@ # Code Review plugin for Redmine -# Copyright (C) 2009-2010 Haruyuki Iida +# Copyright (C) 2009-2017 Haruyuki Iida # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -15,7 +15,7 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -class AddLockVersionToProjectSettings < ActiveRecord::Migration +class AddLockVersionToProjectSettings < ActiveRecord::Migration[4.2] def self.up add_column(:code_review_project_settings, "lock_version", :integer, :null => false, :default => 0) diff --git a/db/migrate/0019_delete_old_fields.rb b/db/migrate/0019_delete_old_fields.rb index ab9744b..d67c01a 100644 --- a/db/migrate/0019_delete_old_fields.rb +++ b/db/migrate/0019_delete_old_fields.rb @@ -1,5 +1,5 @@ # Code Review plugin for Redmine -# Copyright (C) 2012 Haruyuki Iida +# Copyright (C) 2012-2017 Haruyuki Iida # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -15,7 +15,7 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -class DeleteOldFields < ActiveRecord::Migration +class DeleteOldFields < ActiveRecord::Migration[4.2] OLD_FIELDS=["old_parent_id", "old_user_id", "old_comment", "old_status"] def self.up remove_column(:code_reviews, "old_parent_id") diff --git a/db/migrate/0020_add_tracker_to_review_dialog.rb b/db/migrate/0020_add_tracker_to_review_dialog.rb index 8b9daa4..6db6d63 100644 --- a/db/migrate/0020_add_tracker_to_review_dialog.rb +++ b/db/migrate/0020_add_tracker_to_review_dialog.rb @@ -1,5 +1,5 @@ # Code Review plugin for Redmine -# Copyright (C) 2009-2012 Haruyuki Iida +# Copyright (C) 2009-2017 Haruyuki Iida # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -16,7 +16,7 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -class AddTrackerToReviewDialog < ActiveRecord::Migration +class AddTrackerToReviewDialog < ActiveRecord::Migration[4.2] def self.up add_column(:code_review_project_settings, "tracker_in_review_dialog", :boolean, :default => false) diff --git a/db/migrate/0021_add_diff_all.rb b/db/migrate/0021_add_diff_all.rb index 44ee539..56c5506 100644 --- a/db/migrate/0021_add_diff_all.rb +++ b/db/migrate/0021_add_diff_all.rb @@ -1,5 +1,5 @@ # Code Review plugin for Redmine -# Copyright (C) 2013 Haruyuki Iida +# Copyright (C) 2013-2017 Haruyuki Iida # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -15,7 +15,7 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -class AddDiffAll < ActiveRecord::Migration +class AddDiffAll < ActiveRecord::Migration[4.2] def self.up add_column(:code_reviews, "diff_all", :boolean) end From 219314f0c13307a5a8cf6e096cbfab3d365b35a2 Mon Sep 17 00:00:00 2001 From: Haruyuki Iida Date: Tue, 25 Jul 2017 23:33:17 +0900 Subject: [PATCH 02/33] refs #1478 For Rails 5.1 --- .gitignore | 2 ++ init.rb | 4 ---- lib/code_review_changeset_patch.rb | 7 +++---- lib/code_review_projects_helper_patch.rb | 19 ++++--------------- 4 files changed, 9 insertions(+), 23 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ee92314 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +Gemfile +coverage/* diff --git a/init.rb b/init.rb index 23dd20e..3bcc01e 100644 --- a/init.rb +++ b/init.rb @@ -41,10 +41,6 @@ Issue.send(:include, CodeReviewIssuePatch) end - unless ProjectsHelper.included_modules.include? CodeReviewProjectsHelperPatch - ProjectsHelper.send(:include, CodeReviewProjectsHelperPatch) - end - unless Attachment.included_modules.include? CodeReviewAttachmentPatch Attachment.send(:include, CodeReviewAttachmentPatch) end diff --git a/lib/code_review_changeset_patch.rb b/lib/code_review_changeset_patch.rb index a5dfba7..9c40670 100644 --- a/lib/code_review_changeset_patch.rb +++ b/lib/code_review_changeset_patch.rb @@ -19,12 +19,10 @@ module CodeReviewChangesetPatch def self.included(base) # :nodoc: - base.send(:include, ChangesetInstanceMethodsCodeReview) base.class_eval do unloadable # Send unloadable so it will not be unloaded in development has_many :code_review_assignments, :dependent => :destroy - alias_method_chain :scan_comment_for_issue_ids, :code_review end end @@ -163,8 +161,8 @@ def completed_assignment_pourcent # # changeset作成時にレビューの自動アサインを行う # - def scan_comment_for_issue_ids_with_code_review - ret = scan_comment_for_issue_ids_without_code_review + def scan_comment_for_issue_ids + ret = super project = repository.project if repository return ret unless project return ret unless project.module_enabled?('code_review') @@ -177,4 +175,5 @@ def scan_comment_for_issue_ids_with_code_review end end +Changeset.prepend(ChangesetInstanceMethodsCodeReview) diff --git a/lib/code_review_projects_helper_patch.rb b/lib/code_review_projects_helper_patch.rb index f167693..c8f6f33 100644 --- a/lib/code_review_projects_helper_patch.rb +++ b/lib/code_review_projects_helper_patch.rb @@ -17,22 +17,9 @@ require_dependency 'projects_helper' -module CodeReviewProjectsHelperPatch - def self.included(base) # :nodoc: - base.send(:include, ProjectsHelperMethodsCodeReview) - - base.class_eval do - #unloadable - - alias_method_chain :project_settings_tabs, :code_review - end - - end -end - module ProjectsHelperMethodsCodeReview - def project_settings_tabs_with_code_review - tabs = project_settings_tabs_without_code_review + def project_settings_tabs + tabs = super action = {:name => 'code_review', :controller => 'code_review_settings', :action => :show, :partial => 'code_review_settings/show', :label => :code_review} tabs << action if User.current.allowed_to?(action, @project) @@ -41,4 +28,6 @@ def project_settings_tabs_with_code_review end end +ProjectsHelper.prepend(ProjectsHelperMethodsCodeReview) + From c02a317b97270378ea11f118ed0d388ecb5a0676 Mon Sep 17 00:00:00 2001 From: Haruyuki Iida Date: Sat, 29 Jul 2017 22:06:19 +0900 Subject: [PATCH 03/33] refs #1478 For Rails 5.1 --- app/controllers/code_review_controller.rb | 6 +++--- app/controllers/code_review_settings_controller.rb | 4 ++-- app/models/code_review_project_setting.rb | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/controllers/code_review_controller.rb b/app/controllers/code_review_controller.rb index 47de18b..bbe1a05 100644 --- a/app/controllers/code_review_controller.rb +++ b/app/controllers/code_review_controller.rb @@ -17,7 +17,7 @@ class CodeReviewController < ApplicationController unloadable - before_filter :find_project, :authorize, :find_user, :find_setting, :find_repository + before_action :find_project, :authorize, :find_user, :find_setting, :find_repository helper :sort include SortHelper @@ -68,7 +68,7 @@ def new else @review.issue.tracker_id = @setting.tracker_id end - @review.assign_attributes(params[:review]) + @review.attributes = params.require(:review).permit(:change_id, :subject, :line, :parent_id, :comment, :status_id, :issue) if params[:review] @review.project_id = @project.id @review.issue.project_id = @project.id @@ -284,7 +284,7 @@ def reply @issue.lock_version = params[:issue][:lock_version] comment = params[:reply][:comment] journal = @issue.init_journal(User.current, comment) - @review.assign_attributes(params[:review]) + @review.attributes = params.require(:review).permit(:change_id, :subject, :line, :parent_id, :comment, :status_id, :issue) if params[:review] @allowed_statuses = @issue.new_statuses_allowed_to(User.current) @issue.save! diff --git a/app/controllers/code_review_settings_controller.rb b/app/controllers/code_review_settings_controller.rb index 2b367da..b72f6cb 100644 --- a/app/controllers/code_review_settings_controller.rb +++ b/app/controllers/code_review_settings_controller.rb @@ -21,13 +21,13 @@ class CodeReviewSettingsController < ApplicationController menu_item :code_review include CodeReviewAutoAssignSettings - before_filter :find_project, :authorize, :find_user + before_action :find_project, :authorize, :find_user def update begin @setting = CodeReviewProjectSetting.find_or_create(@project) - @setting.assign_attributes params[:setting] + @setting.attributes = params.require(:setting).permit(:tracker_id, :assignment_tracker_id, :hide_code_review_tab, :auto_relation, :tracker_in_review_dialog, :auto_assign) @setting.updated_by = @user.id params[:auto_assign][:filters] = params[:auto_assign][:filters].values unless params[:auto_assign][:filters].blank? @setting.auto_assign_settings = params[:auto_assign].to_yaml diff --git a/app/models/code_review_project_setting.rb b/app/models/code_review_project_setting.rb index f1a8d28..ffa6b81 100644 --- a/app/models/code_review_project_setting.rb +++ b/app/models/code_review_project_setting.rb @@ -29,7 +29,7 @@ class CodeReviewProjectSetting < ActiveRecord::Base before_save :set_assignment_settings - attr_accessible :tracker_id, :assignment_tracker_id, :hide_code_review_tab, :auto_relation, :tracker_in_review_dialog, :auto_assign + #attr_accessible :tracker_id, :assignment_tracker_id, :hide_code_review_tab, :auto_relation, :tracker_in_review_dialog, :auto_assign AUTORELATION_TYPE_NONE = 0 AUTORELATION_TYPE_RELATES = 1 From b63c6f23df5472e32355572bd317e8b0b1213944 Mon Sep 17 00:00:00 2001 From: Haruyuki Iida Date: Sat, 29 Jul 2017 23:23:41 +0900 Subject: [PATCH 04/33] refs #1478 For Rails 5.1 --- test/functional/attachments_controller_test.rb | 16 ++++++++-------- test/functional/code_review_controller_test.rb | 3 +-- .../code_review_settings_controller_test.rb | 3 +-- test/functional/issues_controller_test.rb | 3 +-- test/functional/projects_controller_test.rb | 3 +-- test/functional/repositories_controller_test.rb | 3 +-- 6 files changed, 13 insertions(+), 18 deletions(-) diff --git a/test/functional/attachments_controller_test.rb b/test/functional/attachments_controller_test.rb index d1279f1..c3ec500 100644 --- a/test/functional/attachments_controller_test.rb +++ b/test/functional/attachments_controller_test.rb @@ -25,19 +25,19 @@ class AttachmentsController; def rescue_action(e) raise e end; end class AttachmentsControllerTest < ActionController::TestCase fixtures :users, :projects, :roles, :members, :member_roles, :enabled_modules, :issues, :trackers, :attachments, :versions, :wiki_pages, :wikis, :documents - + def setup @controller = AttachmentsController.new - @request = ActionController::TestRequest.new + @request = ActionController::TestRequest.create(self.class.controller_class) @response = ActionController::TestResponse.new Attachment.storage_path = "#{Rails.root}/test/fixtures/files" - + [1, 2].each { |num| project = Project.find(num) project.enable_module!('code_review') project.save! } - + roles = Role.all roles.each {|role| @@ -46,8 +46,8 @@ def setup } User.current = nil end - - + + def test_show_diff @request.session[:user_id] = 1 attachment = FactoryGirl.create(:attachment, filename: "test.diff") @@ -56,7 +56,7 @@ def test_show_diff assert_template 'diff' assert_equal 'text/html', @response.content_type end - + def test_show_text_file @request.session[:user_id] = 1 attachment = FactoryGirl.create(:attachment, filename: "test.rb") @@ -65,5 +65,5 @@ def test_show_text_file assert_template 'file' assert_equal 'text/html', @response.content_type end - + end diff --git a/test/functional/code_review_controller_test.rb b/test/functional/code_review_controller_test.rb index 1e6cd1b..164fc9a 100644 --- a/test/functional/code_review_controller_test.rb +++ b/test/functional/code_review_controller_test.rb @@ -23,8 +23,7 @@ class CodeReviewControllerTest < ActionController::TestCase :code_review_project_settings, :attachments def setup @controller = CodeReviewController.new - @request = ActionController::TestRequest.new - @response = ActionController::TestResponse.new + @request = ActionController::TestRequest.create(self.class.controller_class) @request.env["HTTP_REFERER"] = '/' enabled_module = EnabledModule.new enabled_module.project_id = 1 diff --git a/test/functional/code_review_settings_controller_test.rb b/test/functional/code_review_settings_controller_test.rb index a1f8fe5..4436786 100644 --- a/test/functional/code_review_settings_controller_test.rb +++ b/test/functional/code_review_settings_controller_test.rb @@ -23,8 +23,7 @@ class CodeReviewSettingsControllerTest < ActionController::TestCase include CodeReviewAutoAssignSettings def setup @controller = CodeReviewSettingsController.new - @request = ActionController::TestRequest.new - @response = ActionController::TestResponse.new + @request = ActionController::TestRequest.create(self.class.controller_class) @request.env["HTTP_REFERER"] = '/' enabled_module = EnabledModule.new enabled_module.project_id = 1 diff --git a/test/functional/issues_controller_test.rb b/test/functional/issues_controller_test.rb index eca63ea..eaa5a89 100644 --- a/test/functional/issues_controller_test.rb +++ b/test/functional/issues_controller_test.rb @@ -46,8 +46,7 @@ class IssuesControllerTest < ActionController::TestCase def setup @controller = IssuesController.new - @request = ActionController::TestRequest.new - @response = ActionController::TestResponse.new + @request = ActionController::TestRequest.create(self.class.controller_class) User.current = nil enabled_module = EnabledModule.new enabled_module.project_id = 1 diff --git a/test/functional/projects_controller_test.rb b/test/functional/projects_controller_test.rb index 99b1701..d5b8c39 100644 --- a/test/functional/projects_controller_test.rb +++ b/test/functional/projects_controller_test.rb @@ -24,8 +24,7 @@ class ProjectsControllerTest < ActionController::TestCase def setup @controller = ProjectsController.new - @request = ActionController::TestRequest.new - @response = ActionController::TestResponse.new + @request = ActionController::TestRequest.create(self.class.controller_class) end context "#settings" do diff --git a/test/functional/repositories_controller_test.rb b/test/functional/repositories_controller_test.rb index 45385d8..327098d 100644 --- a/test/functional/repositories_controller_test.rb +++ b/test/functional/repositories_controller_test.rb @@ -24,8 +24,7 @@ class RepositoriesControllerTest < ActionController::TestCase def setup @controller = RepositoriesController.new - @request = ActionController::TestRequest.new - @response = ActionController::TestResponse.new + @request = ActionController::TestRequest.create(self.class.controller_class) User.current = nil enabled_module = EnabledModule.new enabled_module.project_id = 1 From e0565054f36797dd88a36c97f57b6fbd6135083d Mon Sep 17 00:00:00 2001 From: Haruyuki Iida Date: Sun, 30 Jul 2017 00:24:04 +0900 Subject: [PATCH 05/33] refs #1478 For Rails 5.1 --- .../functional/code_review_controller_test.rb | 78 +++++++++---------- .../code_review_settings_controller_test.rb | 30 +++---- test/functional/issues_controller_test.rb | 22 +++--- test/functional/projects_controller_test.rb | 48 ++++++------ .../repositories_controller_test.rb | 12 +-- test/test_helper.rb | 21 +++-- 6 files changed, 105 insertions(+), 106 deletions(-) diff --git a/test/functional/code_review_controller_test.rb b/test/functional/code_review_controller_test.rb index 164fc9a..077359e 100644 --- a/test/functional/code_review_controller_test.rb +++ b/test/functional/code_review_controller_test.rb @@ -45,19 +45,19 @@ def setup context "index" do should "show review list" do @request.session[:user_id] = 1 - get :index, :id => 1 + get :index, :params => {:id => 1} assert_response :success end should "not show review list if module was not enabled." do @request.session[:user_id] = 1 - get :index, :id => 3 + get :index, :params => {:id => 3} assert_response 403 end should "show all review list if show_closed is true" do @request.session[:user_id] = 1 - get :index, :id => 1, :show_closed => true + get :index, :params => {:id => 1, :show_closed => true} assert_response :success end @@ -66,7 +66,7 @@ def setup context "new" do should "create form when get mthod" do @request.session[:user_id] = 1 - get :new, :id => 1, :action_type => 'diff', :rev => 5 + get :new, :params => {:id => 1, :action_type => 'diff', :rev => 5} assert_response :success assert_template '_new_form' end @@ -74,13 +74,13 @@ def setup should "create new review" do @request.session[:user_id] = 1 count = CodeReview.all.length - post :new, :id => 1, :review => {:line => 1, :change_id => 1, - :comment => 'aaa', :subject => 'bbb'}, :action_type => 'diff' + post :new, :params => {:id => 1, :review => {:line => 1, :change_id => 1, + :comment => 'aaa', :subject => 'bbb'}, :action_type => 'diff'} assert_response :success assert_template '_add_success' assert_equal(count + 1, CodeReview.all.length) - get :new, :id => 1, :action_type => 'diff', :rev => 5 + get :new, :params => {:id => 1, :action_type => 'diff', :rev => 5} assert_response :success assert_template '_new_form' end @@ -94,8 +94,8 @@ def setup changeset.issues << issue changeset.save count = CodeReview.all.length - post :new, :id => 1, :review => {:line => 1, :change_id => 3, - :comment => 'aaa', :subject => 'bbb'}, :action_type => 'diff' + post :new, :params => {:id => 1, :review => {:line => 1, :change_id => 3, + :comment => 'aaa', :subject => 'bbb'}, :action_type => 'diff'} assert_response :success assert_template '_add_success' assert_equal(count + 1, CodeReview.all.length) @@ -104,11 +104,11 @@ def setup settings.each{|setting| setting.destroy } - post :new, :id => 1, :review => {:line => 1, :change_id => 1, - :comment => 'aaa', :subject => 'bbb'}, :action_type => 'diff' + post :new, :params => {:id => 1, :review => {:line => 1, :change_id => 1, + :comment => 'aaa', :subject => 'bbb'}, :action_type => 'diff'} assert_response 200 end - + should "save safe_attributes" do @request.session[:user_id] = 1 project = Project.find(1) @@ -118,11 +118,11 @@ def setup changeset.issues << issue changeset.save count = CodeReview.all.length - post :new, :id => 1, :review => {:line => 10, :change_id => 3, - :comment => 'aaa', :subject => 'bbb', :parent_id => 1, :status_id => 1}, :action_type => 'diff' + post :new, :params => {:id => 1, :review => {:line => 10, :change_id => 3, + :comment => 'aaa', :subject => 'bbb', :parent_id => 1, :status_id => 1}, :action_type => 'diff'} assert_response :success assert_template '_add_success' - + review = assigns :review assert_equal(1, review.project_id) assert_equal(3, review.change_id) @@ -138,8 +138,8 @@ def setup issue = Issue.generate!(:project => project) attachment = FactoryGirl.create(:attachment, container: issue) count = CodeReview.all.length - post :new, :id => 1, :review => {:line => 1, :comment => 'aaa', - :subject => 'bbb', :attachment_id => attachment.id}, :action_type => 'diff' + post :new, :params => {:id => 1, :review => {:line => 1, :comment => 'aaa', + :subject => 'bbb', :attachment_id => attachment.id}, :action_type => 'diff'} assert_response :success assert_template '_add_success' assert_equal(count + 1, CodeReview.all.length) @@ -148,7 +148,7 @@ def setup def test_show @request.session[:user_id] = 1 - get :show, :id => 1, :review_id => 9 + get :show, :params => {:id => 1, :review_id => 9} assert_response 302 #assert_template '_show' end @@ -156,13 +156,13 @@ def test_show context "show" do should "be success with review_id" do @request.session[:user_id] = 1 - get :show, :id => 1, :review_id => 9 + get :show, :params => {:id => 1, :review_id => 9} assert_response 302 #assert_template '_show' end should "be success with assignment_id" do @request.session[:user_id] = 1 - get :show, :id => 1, :assignment_id => 1 + get :show, :params => {:id => 1, :assignment_id => 1} assert_response 302 #assert_template '_show' end @@ -174,10 +174,10 @@ def test_destroy review = FactoryGirl.create(:code_review, project: project) count = CodeReview.all.length @request.session[:user_id] = 1 - get :destroy, :id => 1, :review_id => review.id + get :destroy, :params => {:id => 1, :review_id => review.id} assert_response :success assert_equal(count - 1, CodeReview.all.length) - + end context "reply" do @@ -185,8 +185,8 @@ def test_destroy @request.session[:user_id] = 1 review = CodeReview.find(9) - get :reply, :id => 1, :review_id => 9, - :reply => {:comment => 'aaa'}, :issue=> {:lock_version => review.issue.lock_version} + get :reply, :params => {:id => 1, :review_id => 9, + :reply => {:comment => 'aaa'}, :issue=> {:lock_version => review.issue.lock_version}} assert_response :success assert_template '_show' assert_equal(nil, assigns(:error)) @@ -196,8 +196,8 @@ def test_destroy @request.session[:user_id] = 1 review = CodeReview.find(9) - get :reply, :id => 1, :review_id => 9, - :reply => {:comment => 'aaa'}, :issue=> {:lock_version => review.issue.lock_version + 1} + get :reply, :params => {:id => 1, :review_id => 9, + :reply => {:comment => 'aaa'}, :issue=> {:lock_version => review.issue.lock_version + 1}} assert_response :success assert_template '_show' assert_not_nil assigns(:error) @@ -206,8 +206,8 @@ def test_destroy def test_reply_lock_error @request.session[:user_id] = 1 - get :reply, :id => 1, :review_id => 9, - :reply => {:comment => 'aaa'}, :issue=> {:lock_version => 1} + get :reply, :params => {:id => 1, :review_id => 9, + :reply => {:comment => 'aaa'}, :issue=> {:lock_version => 1}} assert_response :success assert_template '_show' assert assigns(:error) @@ -245,9 +245,9 @@ def test_update review_id = 9 review = CodeReview.find(review_id) assert_equal('Unable to print recipes', review.comment) - post :update, :id => 1, :review_id => review_id, + post :update, :params => {:id => 1, :review_id => review_id, :review => {:comment => 'bbb', :lock_version => review.lock_version}, - :issue => {:lock_version => review.issue.lock_version} + :issue => {:lock_version => review.issue.lock_version}} assert_response :success review = CodeReview.find(review_id) assert_equal('bbb', review.comment) @@ -258,9 +258,9 @@ def test_update_lock_error review_id = 9 review = CodeReview.find(review_id) assert_equal('Unable to print recipes', review.comment) - post :update, :id => 1, :review_id => review_id, + post :update, :params => {:id => 1, :review_id => review_id, :review => {:comment => 'bbb', :lock_version => review.lock_version}, - :issue => {:lock_version => 1} + :issue => {:lock_version => 1}} assert_response :success review = CodeReview.find(review_id) assert_equal('Unable to print recipes', review.comment) @@ -272,14 +272,14 @@ def test_update_diff_view review_id = 9 review = CodeReview.find(review_id) assert_equal('Unable to print recipes', review.comment) - post :update_diff_view, :id => 1, :review_id => review_id, :rev => 1, :path => '/test/some/path/in/the/repo' + post :update_diff_view, :params => {:id => 1, :review_id => review_id, :rev => 1, :path => '/test/some/path/in/the/repo'} assert_response :success review = CodeReview.find(review_id) end def test_forward_to_revision @request.session[:user_id] = 1 - post :forward_to_revision, :id => 1, :path => '/test/some/path/in/the/repo' + post :forward_to_revision, :params => {:id => 1, :path => '/test/some/path/in/the/repo'} end def test_update_attachment_view @@ -287,7 +287,7 @@ def test_update_attachment_view review_id = 9 review = CodeReview.find(review_id) assert_equal('Unable to print recipes', review.comment) - post :update_attachment_view, :id => 1, :attachment_id => 1 + post :update_attachment_view, :params => {:id => 1, :attachment_id => 1} assert_response :success review = CodeReview.find(review_id) end @@ -296,13 +296,13 @@ def test_preview @request.session[:user_id] = 1 review = {} review[:comment] = 'aaa' - post :preview, :id => 1, :review => review + post :preview, :params => {:id => 1, :review => review} assert_response :success end def test_assign @request.session[:user_id] = 1 - post :assign, :id => 1 + post :assign, :params => {:id => 1} assert_response :redirect end @@ -312,13 +312,13 @@ def test_assign end should "succeed if changeset_ids is nil" do - get :update_revisions_view, :id => 1 + get :update_revisions_view, :params => {:id => 1} assert_response :success assert_equal(0, assigns(:changesets).length) end should "succeed if changeset_ids is not nil" do - get :update_revisions_view, :id => 1, :changeset_ids => '1,2,3' + get :update_revisions_view, :params => {:id => 1, :changeset_ids => '1,2,3'} assert_response :success assert_equal(3, assigns(:changesets).length) end diff --git a/test/functional/code_review_settings_controller_test.rb b/test/functional/code_review_settings_controller_test.rb index 4436786..c4a9003 100644 --- a/test/functional/code_review_settings_controller_test.rb +++ b/test/functional/code_review_settings_controller_test.rb @@ -51,7 +51,7 @@ def setup should "return 302 if user is anonymous" do @request.session[:user_id] = User.anonymous.id - get :update, :id => 1 + get :update, :params => {:id => 1} assert_response 302 end @@ -60,9 +60,9 @@ def setup @request.session[:user_id] = 1 setting = CodeReviewProjectSetting.find(1) - post :update, :id => 1, :setting => {:tracker_id => 2, :assignment_tracker_id => 3, + post :update, :params => {:id => 1, :setting => {:tracker_id => 2, :assignment_tracker_id => 3, :hide_code_review_tab => true, :auto_relation => CodeReviewProjectSetting::AUTORELATION_TYPE_BLOCKS}, - :auto_assign => {:filters => {:a => 1}} + :auto_assign => {:filters => {:a => 1}}} assert_response :redirect project = Project.find(1) assert_redirected_to :controller => 'projects', :action => 'settings', :id => project, :tab => 'code_review' @@ -102,7 +102,7 @@ def setup filter.expression = 'aaa' filter.order = 10 filter.accept = true - post :add_filter, :id => @project.id, :auto_assign => @setting.auto_assign_settings.attributes.merge({:add_filter => filter.attributes}) + post :add_filter, :params => {:id => @project.id, :auto_assign => @setting.auto_assign_settings.attributes.merge({:add_filter => filter.attributes})} @auto_assign = assigns(:auto_assign) assert_not_nil @auto_assign assert_equal(count + 1, @auto_assign.filters.length) @@ -124,14 +124,14 @@ def setup filter.expression = 'aaa' filter.order = 10 filter.accept = true - + filter2 = AssignmentFilter.new filter2.expression = 'bbb' filter2.order = 10 filter2.accept = false - post :edit_filter, :id => @project.id, :auto_assign => @setting.auto_assign_settings.attributes.merge(:filters => {'0' => filter.attributes}), :num => 0, - :auto_assign_edit_filter => {'0' => filter2.attributes} + post :edit_filter, :params => {:id => @project.id, :auto_assign => @setting.auto_assign_settings.attributes.merge(:filters => {'0' => filter.attributes}), :num => 0, + :auto_assign_edit_filter => {'0' => filter2.attributes}} @auto_assign = assigns(:auto_assign) assert_not_nil @auto_assign assert_equal(1, @auto_assign.filters.length) @@ -169,26 +169,26 @@ def setup end should "sort filters" do - post :sort, :id => @project.id, :auto_assign => @setting.auto_assign_settings.attributes.merge(:filters => @filters), :num => 0, - :auto_assign_filter => {:num => 2, :move_to => 'highest'} + post :sort, :params => {:id => @project.id, :auto_assign => @setting.auto_assign_settings.attributes.merge(:filters => @filters), :num => 0, + :auto_assign_filter => {:num => 2, :move_to => 'highest'}} @auto_assign = assigns(:auto_assign) assert_not_nil @auto_assign assert_response :success - post :sort, :id => @project.id, :auto_assign => @setting.auto_assign_settings.attributes.merge(:filters => @filters), :num => 0, - :auto_assign_filter => {:num => 2, :move_to => 'higher'} + post :sort, :params => {:id => @project.id, :auto_assign => @setting.auto_assign_settings.attributes.merge(:filters => @filters), :num => 0, + :auto_assign_filter => {:num => 2, :move_to => 'higher'}} @auto_assign = assigns(:auto_assign) assert_not_nil @auto_assign assert_response :success - post :sort, :id => @project.id, :auto_assign => @setting.auto_assign_settings.attributes.merge(:filters => @filters), :num => 0, - :auto_assign_filter => {:num => 2, :move_to => 'lowest'} + post :sort, :params => {:id => @project.id, :auto_assign => @setting.auto_assign_settings.attributes.merge(:filters => @filters), :num => 0, + :auto_assign_filter => {:num => 2, :move_to => 'lowest'}} @auto_assign = assigns(:auto_assign) assert_not_nil @auto_assign assert_response :success - post :sort, :id => @project.id, :auto_assign => @setting.auto_assign_settings.attributes.merge(:filters => @filters), :num => 0, - :auto_assign_filter => {:num => 2, :move_to => 'lower'} + post :sort, :params => {:id => @project.id, :auto_assign => @setting.auto_assign_settings.attributes.merge(:filters => @filters), :num => 0, + :auto_assign_filter => {:num => 2, :move_to => 'lower'}} @auto_assign = assigns(:auto_assign) assert_not_nil @auto_assign assert_response :success diff --git a/test/functional/issues_controller_test.rb b/test/functional/issues_controller_test.rb index eaa5a89..f65e3f4 100644 --- a/test/functional/issues_controller_test.rb +++ b/test/functional/issues_controller_test.rb @@ -67,40 +67,40 @@ def test_show @request.session[:user_id] = 1 project = Project.find(1) issue = Issue.generate!(:project => project) - get :show, :id => issue.id + get :show, params: {id: issue.id} issue = Issue.generate!(:project => project) assignment = FactoryGirl.create(:code_review_assignment, issue: issue, rev: 'aaa', file_path: nil) - get :show, :id => assignment.issue.id + get :show, :params => {:id => assignment.issue.id} issue = Issue.generate!(:project => Project.find(1)) assignment = FactoryGirl.create(:code_review_assignment, issue: issue, rev: 'aaa', file_path: '/aaa/bbb') - get :show, :id => assignment.issue.id - + get :show, :params => {:id => assignment.issue.id} + review = FactoryGirl.create(:code_review, project: project) - get :show, :id => review.issue.id + get :show, :params => {:id => review.issue.id} end def test_new @request.session[:user_id] = 1 - get :new, :project_id => 1 + get :new, params: { project_id: 1 } assert_response :success - get :new, :project_id => 1, :code =>{:rev => 1, :rev_to => 2, :path => '/aaa/bbb', :action_type => 'diff'} + get :new, :params => {:project_id => 1, :code =>{:rev => 1, :rev_to => 2, :path => '/aaa/bbb', :action_type => 'diff'}} assert_response :success - post :new, :project_id => 1, + post :new, :params => {:project_id => 1, :issue => {:tracker_id => 1, :status_id => 1, :subject => 'hoge'}, - :code =>{:rev => 1, :rev_to => 2, :path => '/aaa/bbb', :action_type => 'diff'} + :code =>{:rev => 1, :rev_to => 2, :path => '/aaa/bbb', :action_type => 'diff'}} # TODO: 0.9.xのサポート終了時に以下を有効にする。 #assert_response :SUCESS end - + context "create" do should "create code_review_assignment." do @request.session[:user_id] = 1 project = Project.find(1) - post :create, :project_id => 1, :issue => {:subject => 'test'}, :code => {:change_id => 1, :changeset_id => 1} + post :create, :params => {:project_id => 1, :issue => {:subject => 'test'}, :code => {:change_id => 1, :changeset_id => 1}} assert_response :redirect end end diff --git a/test/functional/projects_controller_test.rb b/test/functional/projects_controller_test.rb index d5b8c39..cdab47a 100644 --- a/test/functional/projects_controller_test.rb +++ b/test/functional/projects_controller_test.rb @@ -34,12 +34,12 @@ def setup end should "302 get" do - get :settings, :id => 1 + get :settings, :params => {:id => 1} assert_response 302 end should "302 post" do - get :settings, :id => 1 + get :settings, :params => {:id => 1} assert_response 302 end @@ -49,7 +49,7 @@ def setup end should "not exist tag id get" do - get :settings, :id => 1 + get :settings, :params => {:id => 1} assert_response :success assert_template 'settings' assert_no_tag :div, :attributes => {:class => 'tabs'}, @@ -59,7 +59,7 @@ def setup end should "not exist tag id post" do - post :settings, :id => 1 + post :settings, :params => {:id => 1} assert_response :success assert_template 'settings' assert_no_tag :div, :attributes => {:class => 'tabs'}, @@ -74,7 +74,7 @@ def setup end should "not exist tag id get" do - get :settings, :id => 1 + get :settings, :params => {:id => 1} assert_response :success assert_template 'settings' assert_no_tag :div, :attributes => {:class => 'tabs'}, @@ -84,7 +84,7 @@ def setup end should "not exist tag id post" do - post :settings, :id => 1 + post :settings, :params => {:id => 1} assert_response :success assert_template 'settings' assert_no_tag :div, :attributes => {:class => 'tabs'}, @@ -102,12 +102,12 @@ def setup end should "403 get" do - get :settings, :id => 1 + get :settings, :params => {:id => 1} assert_response 403 end should "403 post" do - get :settings, :id => 1 + get :settings, :params => {:id => 1} assert_response 403 end @@ -117,7 +117,7 @@ def setup end should "not exist tag id get" do - get :settings, :id => 1 + get :settings, :params => {:id => 1} assert_response :success assert_template 'settings' assert_no_tag :div, :attributes => {:class => 'tabs'}, @@ -127,7 +127,7 @@ def setup end should "not exist tag id post" do - post :settings, :id => 1 + post :settings, :params => {:id => 1} assert_response :success assert_template 'settings' assert_no_tag :div, :attributes => {:class => 'tabs'}, @@ -142,7 +142,7 @@ def setup end should "not exist tag id get" do - get :settings, :id => 1 + get :settings, :params => {:id => 1} assert_response :success assert_template 'settings' assert_no_tag :div, :attributes => {:class => 'tabs'}, @@ -152,7 +152,7 @@ def setup end should "not exist tag id post" do - post :settings, :id => 1 + post :settings, :params => {:id => 1} assert_response :success assert_template 'settings' assert_no_tag :div, :attributes => {:class => 'tabs'}, @@ -171,7 +171,7 @@ def setup end should "not exist tag id get" do - get :settings, :id => 1 + get :settings, :params => {:id => 1} assert_response :success assert_template 'settings' assert_no_tag :div, :attributes => {:class => 'tabs'}, @@ -181,7 +181,7 @@ def setup end should "not exist tag id post" do - get :settings, :id => 1 + get :settings, :params => {:id => 1} assert_response :success assert_template 'settings' assert_no_tag :div, :attributes => {:class => 'tabs'}, @@ -196,7 +196,7 @@ def setup end should "not exist tag id get" do - get :settings, :id => 1 + get :settings, :params => {:id => 1} assert_response :success assert_template 'settings' assert_no_tag :div, :attributes => {:class => 'tabs'}, @@ -206,7 +206,7 @@ def setup end should "not exist tag id post" do - post :settings, :id => 1 + post :settings, :params => {:id => 1} assert_response :success assert_template 'settings' assert_no_tag :div, :attributes => {:class => 'tabs'}, @@ -221,7 +221,7 @@ def setup end should "not exist tag id get" do - get :settings, :id => 1 + get :settings, :params => {:id => 1} assert_response :success assert_template 'settings' assert_no_tag :div, :attributes => {:class => 'tabs'}, @@ -231,7 +231,7 @@ def setup end should "not exist tag id post" do - post :settings, :id => 1 + post :settings, :params => {:id => 1} assert_response :success assert_template 'settings' assert_no_tag :div, :attributes => {:class => 'tabs'}, @@ -250,7 +250,7 @@ def setup end should "not exist tag id get" do - get :settings, :id => 1 + get :settings, :params => {:id => 1} assert_response :success assert_template 'settings' assert_no_tag :div, :attributes => {:class => 'tabs'}, @@ -260,7 +260,7 @@ def setup end should "not exist tag id post" do - get :settings, :id => 1 + get :settings, :params => {:id => 1} assert_response :success assert_template 'settings' assert_no_tag :div, :attributes => {:class => 'tabs'}, @@ -275,7 +275,7 @@ def setup end should "not exist tag id get" do - get :settings, :id => 1 + get :settings, :params => {:id => 1} assert_response :success assert_template 'settings' assert_no_tag :div, :attributes => {:class => 'tabs'}, @@ -285,7 +285,7 @@ def setup end should "not exist tag id post" do - post :settings, :id => 1 + post :settings, :params => {:id => 1} assert_response :success assert_template 'settings' assert_no_tag :div, :attributes => {:class => 'tabs'}, @@ -300,7 +300,7 @@ def setup end should "exist tag id get" do - get :settings, :id => 1 + get :settings, :params => {:id => 1} assert_response :success assert_template 'settings' assert_tag :div, :attributes => {:class => 'tabs'}, @@ -310,7 +310,7 @@ def setup end should "exist tag id post" do - post :settings, :id => 1 + post :settings, :params => {:id => 1} assert_response :success assert_template 'settings' assert_tag :div, :attributes => {:class => 'tabs'}, diff --git a/test/functional/repositories_controller_test.rb b/test/functional/repositories_controller_test.rb index 327098d..513375a 100644 --- a/test/functional/repositories_controller_test.rb +++ b/test/functional/repositories_controller_test.rb @@ -62,31 +62,31 @@ def test_revision project.repository = changeset.repository issue = Issue.generate!({:project => project, :description => 'test'}) review = FactoryGirl.create(:code_review, change: change, project: project, issue: issue) - get :revision, :id => project.id, :rev => changeset.revision, :path => change.path.split('/') + get :revision, :params => {:id => project.id, :rev => changeset.revision, :path => change.path.split('/')} #assert_response :success end def test_revisions @request.session[:user_id] = 1 - get :revisions, :id => 1 + get :revisions, :params => {:id => 1} assert_response :success end def test_show @request.session[:user_id] = 1 - get :show, :id => 1 + get :show, :params => {:id => 1} assert_response :success end - + def test_diff @request.session[:user_id] = 1 - get :diff, :id => 1, :path => '/subversion_test/helloworld.c'.split('/'), :rev => 8 + get :diff, :params => {:id => 1, :path => '/subversion_test/helloworld.c'.split('/'), :rev => 8} #assert_response :success end def test_entry @request.session[:user_id] = 1 - get :entry, :id => 1, :path => '/subversion_test/helloworld.c'.split('/'), :rev => 8 + get :entry, :params => {:id => 1, :path => '/subversion_test/helloworld.c'.split('/'), :rev => 8} assert_response :success end end diff --git a/test/test_helper.rb b/test/test_helper.rb index 809ef8a..3ab9fd6 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -43,18 +43,18 @@ def mock_file FactoryGirl.define do factory :attachment do - + container{ Project.find(1) } file { - ActiveSupport::TestCase.mock_file + AttachmentTest.MockFile.new(:original_filename => "path/to/the/file") } author { User.find(1) } end - + factory :repository do project_id 1 url "file:///#{Rails.root}/tmp/test/subversion_repository" @@ -70,7 +70,7 @@ def mock_file } is_default true end - + factory :changeset do sequence(:revision, 1000) committed_on{ @@ -85,7 +85,7 @@ def mock_file Repository.find(10) } end - + factory :change do action { "A" @@ -97,33 +97,32 @@ def mock_file FactoryGirl.create(:changeset) } end - + factory :code_review_assignment do issue_id 1 end - + factory :issue do subject 'hoge' author{ User.find(1) } end - + factory :code_review do issue_id 1 updated_by_id 1 line 10 action_type 'diff' end - + factory :code_review_project_setting do project_id 1 tracker_id 1 assignment_tracker_id 1 end - + factory :enabled_module do - end end \ No newline at end of file From 03bfaff9ba040d1f8fecf4298d12d45bfac4f0f9 Mon Sep 17 00:00:00 2001 From: Haruyuki Iida Date: Sat, 5 Aug 2017 20:17:19 +0900 Subject: [PATCH 06/33] refs #1478 For Rails 5.1 --- Gemfile_for_test | 3 +- .../functional/attachments_controller_test.rb | 6 +- test/functional/projects_controller_test.rb | 80 ++++--------------- test/test_helper.rb | 8 +- 4 files changed, 27 insertions(+), 70 deletions(-) diff --git a/Gemfile_for_test b/Gemfile_for_test index e1731cc..decef01 100644 --- a/Gemfile_for_test +++ b/Gemfile_for_test @@ -1,7 +1,8 @@ -source 'http://rubygems.org' + group :test do gem "simplecov-rcov" gem 'factory_girl_rails' gem 'shoulda' + gem 'rails-controller-testing' end \ No newline at end of file diff --git a/test/functional/attachments_controller_test.rb b/test/functional/attachments_controller_test.rb index c3ec500..f8e1342 100644 --- a/test/functional/attachments_controller_test.rb +++ b/test/functional/attachments_controller_test.rb @@ -29,7 +29,7 @@ class AttachmentsControllerTest < ActionController::TestCase def setup @controller = AttachmentsController.new @request = ActionController::TestRequest.create(self.class.controller_class) - @response = ActionController::TestResponse.new + #@response = ActionController::TestResponse.new Attachment.storage_path = "#{Rails.root}/test/fixtures/files" [1, 2].each { |num| @@ -54,7 +54,7 @@ def test_show_diff get :show, :id => attachment.id, :type => 'inline' assert_response :success assert_template 'diff' - assert_equal 'text/html', @response.content_type + #assert_equal 'text/html', @response.content_type end def test_show_text_file @@ -63,7 +63,7 @@ def test_show_text_file get :show, :id => attachment.id, :type => 'inline' assert_response :success assert_template 'file' - assert_equal 'text/html', @response.content_type + #assert_equal 'text/html', @response.content_type end end diff --git a/test/functional/projects_controller_test.rb b/test/functional/projects_controller_test.rb index cdab47a..15cd9c2 100644 --- a/test/functional/projects_controller_test.rb +++ b/test/functional/projects_controller_test.rb @@ -52,20 +52,14 @@ def setup get :settings, :params => {:id => 1} assert_response :success assert_template 'settings' - assert_no_tag :div, :attributes => {:class => 'tabs'}, - :descendant => {:tag => 'ul', - :descendant => {:tag => 'li', - :descendant => {:tag => 'a', :attributes => {:id => 'tab-code_review'}}}} + assert_select 'div.tabs ul li a#id', 'tab-code_review' end should "not exist tag id post" do post :settings, :params => {:id => 1} assert_response :success assert_template 'settings' - assert_no_tag :div, :attributes => {:class => 'tabs'}, - :descendant => {:tag => 'ul', - :descendant => {:tag => 'li', - :descendant => {:tag => 'a', :attributes => {:id => 'tab-code_review'}}}} + assert_select 'div.tabs ul li a#id', 'tab-code_review' end context "and module" do @@ -77,20 +71,14 @@ def setup get :settings, :params => {:id => 1} assert_response :success assert_template 'settings' - assert_no_tag :div, :attributes => {:class => 'tabs'}, - :descendant => {:tag => 'ul', - :descendant => {:tag => 'li', - :descendant => {:tag => 'a', :attributes => {:id => 'tab-code_review'}}}} + assert_select 'div.tabs ul li a#id', 'tab-code_review' end should "not exist tag id post" do post :settings, :params => {:id => 1} assert_response :success assert_template 'settings' - assert_no_tag :div, :attributes => {:class => 'tabs'}, - :descendant => {:tag => 'ul', - :descendant => {:tag => 'li', - :descendant => {:tag => 'a', :attributes => {:id => 'tab-code_review'}}}} + assert_select 'div.tabs ul li a#id', 'tab-code_review' end end end @@ -120,20 +108,14 @@ def setup get :settings, :params => {:id => 1} assert_response :success assert_template 'settings' - assert_no_tag :div, :attributes => {:class => 'tabs'}, - :descendant => {:tag => 'ul', - :descendant => {:tag => 'li', - :descendant => {:tag => 'a', :attributes => {:id => 'tab-code_review'}}}} + assert_select 'div.tabs ul li a#id', 'tab-code_review' end should "not exist tag id post" do post :settings, :params => {:id => 1} assert_response :success assert_template 'settings' - assert_no_tag :div, :attributes => {:class => 'tabs'}, - :descendant => {:tag => 'ul', - :descendant => {:tag => 'li', - :descendant => {:tag => 'a', :attributes => {:id => 'tab-code_review'}}}} + assert_select 'div.tabs ul li a#id', 'tab-code_review' end context "and module" do @@ -145,20 +127,14 @@ def setup get :settings, :params => {:id => 1} assert_response :success assert_template 'settings' - assert_no_tag :div, :attributes => {:class => 'tabs'}, - :descendant => {:tag => 'ul', - :descendant => {:tag => 'li', - :descendant => {:tag => 'a', :attributes => {:id => 'tab-code_review'}}}} + assert_select 'div.tabs ul li a#id', 'tab-code_review' end should "not exist tag id post" do post :settings, :params => {:id => 1} assert_response :success assert_template 'settings' - assert_no_tag :div, :attributes => {:class => 'tabs'}, - :descendant => {:tag => 'ul', - :descendant => {:tag => 'li', - :descendant => {:tag => 'a', :attributes => {:id => 'tab-code_review'}}}} + assert_select 'div.tabs ul li a#id', 'tab-code_review' end end end @@ -224,20 +200,14 @@ def setup get :settings, :params => {:id => 1} assert_response :success assert_template 'settings' - assert_no_tag :div, :attributes => {:class => 'tabs'}, - :descendant => {:tag => 'ul', - :descendant => {:tag => 'li', - :descendant => {:tag => 'a', :attributes => {:id => 'tab-code_review'}}}} + assert_select 'div.tabs ul li a#id', 'tab-code_review' end should "not exist tag id post" do post :settings, :params => {:id => 1} assert_response :success assert_template 'settings' - assert_no_tag :div, :attributes => {:class => 'tabs'}, - :descendant => {:tag => 'ul', - :descendant => {:tag => 'li', - :descendant => {:tag => 'a', :attributes => {:id => 'tab-code_review'}}}} + assert_select 'div.tabs ul li a#id', 'tab-code_review' end end end @@ -253,20 +223,14 @@ def setup get :settings, :params => {:id => 1} assert_response :success assert_template 'settings' - assert_no_tag :div, :attributes => {:class => 'tabs'}, - :descendant => {:tag => 'ul', - :descendant => {:tag => 'li', - :descendant => {:tag => 'a', :attributes => {:id => 'tab-code_review'}}}} + assert_select 'div.tabs ul li a#id', 'tab-code_review' end should "not exist tag id post" do get :settings, :params => {:id => 1} assert_response :success assert_template 'settings' - assert_no_tag :div, :attributes => {:class => 'tabs'}, - :descendant => {:tag => 'ul', - :descendant => {:tag => 'li', - :descendant => {:tag => 'a', :attributes => {:id => 'tab-code_review'}}}} + assert_select 'div.tabs ul li a#id', 'tab-code_review' end context "with permission" do @@ -278,20 +242,14 @@ def setup get :settings, :params => {:id => 1} assert_response :success assert_template 'settings' - assert_no_tag :div, :attributes => {:class => 'tabs'}, - :descendant => {:tag => 'ul', - :descendant => {:tag => 'li', - :descendant => {:tag => 'a', :attributes => {:id => 'tab-code_review'}}}} + assert_select 'div.tabs ul li a#id', 'tab-code_review' end should "not exist tag id post" do post :settings, :params => {:id => 1} assert_response :success assert_template 'settings' - assert_no_tag :div, :attributes => {:class => 'tabs'}, - :descendant => {:tag => 'ul', - :descendant => {:tag => 'li', - :descendant => {:tag => 'a', :attributes => {:id => 'tab-code_review'}}}} + assert_select 'div.tabs ul li a#id', 'tab-code_review' end context "and module" do @@ -303,20 +261,14 @@ def setup get :settings, :params => {:id => 1} assert_response :success assert_template 'settings' - assert_tag :div, :attributes => {:class => 'tabs'}, - :descendant => {:tag => 'ul', - :descendant => {:tag => 'li', - :descendant => {:tag => 'a', :attributes => {:id => 'tab-code_review'}}}} + assert_select 'div.tabs ul li a#id', 'tab-code_review' end should "exist tag id post" do post :settings, :params => {:id => 1} assert_response :success assert_template 'settings' - assert_tag :div, :attributes => {:class => 'tabs'}, - :descendant => {:tag => 'ul', - :descendant => {:tag => 'li', - :descendant => {:tag => 'a', :attributes => {:id => 'tab-code_review'}}}} + assert_select 'div.tabs ul li a#id', 'tab-code_review' end end end diff --git a/test/test_helper.rb b/test/test_helper.rb index 3ab9fd6..08eeb9a 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -45,16 +45,20 @@ def mock_file factory :attachment do container{ - Project.find(1) + Issue.find(1) } file { - AttachmentTest.MockFile.new(:original_filename => "path/to/the/file") + uploaded_test_file("hg-export.diff", "text/plain") } author { User.find(1) } end + def uploaded_test_file(name, mime) + fixture_file_upload("files/#{name}", mime, true) + end + factory :repository do project_id 1 url "file:///#{Rails.root}/tmp/test/subversion_repository" From a74479475f22a6f6d8ead10e5a89210f38513167 Mon Sep 17 00:00:00 2001 From: Haruyuki Iida Date: Sun, 6 Aug 2017 00:19:22 +0900 Subject: [PATCH 07/33] refs #1478 For Rails 5.1 --- .../functional/attachments_controller_test.rb | 4 +- .../functional/code_review_controller_test.rb | 2 +- .../code_review_settings_controller_test.rb | 6 +-- test/functional/projects_controller_test.rb | 52 +++++++------------ test/test_helper.rb | 9 ++-- .../code_review_auto_assign_settings_test.rb | 4 +- 6 files changed, 34 insertions(+), 43 deletions(-) diff --git a/test/functional/attachments_controller_test.rb b/test/functional/attachments_controller_test.rb index f8e1342..b62ace5 100644 --- a/test/functional/attachments_controller_test.rb +++ b/test/functional/attachments_controller_test.rb @@ -51,7 +51,7 @@ def setup def test_show_diff @request.session[:user_id] = 1 attachment = FactoryGirl.create(:attachment, filename: "test.diff") - get :show, :id => attachment.id, :type => 'inline' + get :show, :params => {:id => attachment.id, :type => 'inline'} assert_response :success assert_template 'diff' #assert_equal 'text/html', @response.content_type @@ -60,7 +60,7 @@ def test_show_diff def test_show_text_file @request.session[:user_id] = 1 attachment = FactoryGirl.create(:attachment, filename: "test.rb") - get :show, :id => attachment.id, :type => 'inline' + get :show, :params => {:id => attachment.id, :type => 'inline'} assert_response :success assert_template 'file' #assert_equal 'text/html', @response.content_type diff --git a/test/functional/code_review_controller_test.rb b/test/functional/code_review_controller_test.rb index 077359e..8598d00 100644 --- a/test/functional/code_review_controller_test.rb +++ b/test/functional/code_review_controller_test.rb @@ -189,7 +189,7 @@ def test_destroy :reply => {:comment => 'aaa'}, :issue=> {:lock_version => review.issue.lock_version}} assert_response :success assert_template '_show' - assert_equal(nil, assigns(:error)) + assert_nil assigns(:error) end should "not create reply if anyone replied sametime" do diff --git a/test/functional/code_review_settings_controller_test.rb b/test/functional/code_review_settings_controller_test.rb index c4a9003..32248ff 100644 --- a/test/functional/code_review_settings_controller_test.rb +++ b/test/functional/code_review_settings_controller_test.rb @@ -75,13 +75,13 @@ def setup assert_equal(true, setting.hide_code_review_tab) assert_equal(CodeReviewProjectSetting::AUTORELATION_TYPE_BLOCKS, setting.auto_relation) - get :update, :id => 1, :setting => {:tracker_id => 1, :id => setting.id}, :convert => 'true', - :auto_assign => {} + get :update, :params => {:id => 1, :setting => {:tracker_id => 1, :id => setting.id}, :convert => 'true', + :auto_assign => {}} assert_response :redirect project = Project.find(1) assert_redirected_to :controller => 'projects', :action => 'settings', :id => project, :tab => 'code_review' - post :update, :id => 2, :setting => {:tracker_id => 1, :assignment_tracker_id => 1}, :auto_assign => {} + post :update, :params => {:id => 2, :setting => {:tracker_id => 1, :assignment_tracker_id => 1}, :auto_assign => {}} assert_response :redirect project = Project.find(2) assert_redirected_to :controller => 'projects', :action => 'settings', :id => project, :tab => 'code_review' diff --git a/test/functional/projects_controller_test.rb b/test/functional/projects_controller_test.rb index 15cd9c2..48b1acd 100644 --- a/test/functional/projects_controller_test.rb +++ b/test/functional/projects_controller_test.rb @@ -52,14 +52,14 @@ def setup get :settings, :params => {:id => 1} assert_response :success assert_template 'settings' - assert_select 'div.tabs ul li a#id', 'tab-code_review' + assert_select 'div.tabs ul li a#tab-code_review', false end should "not exist tag id post" do post :settings, :params => {:id => 1} assert_response :success assert_template 'settings' - assert_select 'div.tabs ul li a#id', 'tab-code_review' + assert_select 'div.tabs ul li a#tab-code_review', false end context "and module" do @@ -71,14 +71,14 @@ def setup get :settings, :params => {:id => 1} assert_response :success assert_template 'settings' - assert_select 'div.tabs ul li a#id', 'tab-code_review' + assert_select 'div.tabs ul li a#tab-code_review' end should "not exist tag id post" do post :settings, :params => {:id => 1} assert_response :success assert_template 'settings' - assert_select 'div.tabs ul li a#id', 'tab-code_review' + assert_select 'div.tabs ul li a#tab-code_review' end end end @@ -108,14 +108,14 @@ def setup get :settings, :params => {:id => 1} assert_response :success assert_template 'settings' - assert_select 'div.tabs ul li a#id', 'tab-code_review' + assert_select 'div.tabs ul li a#tab-code_review' end should "not exist tag id post" do post :settings, :params => {:id => 1} assert_response :success assert_template 'settings' - assert_select 'div.tabs ul li a#id', 'tab-code_review' + assert_select 'div.tabs ul li a#tab-code_review' end context "and module" do @@ -127,14 +127,14 @@ def setup get :settings, :params => {:id => 1} assert_response :success assert_template 'settings' - assert_select 'div.tabs ul li a#id', 'tab-code_review' + assert_select 'div.tabs ul li a#tab-code_review' end should "not exist tag id post" do post :settings, :params => {:id => 1} assert_response :success assert_template 'settings' - assert_select 'div.tabs ul li a#id', 'tab-code_review' + assert_select 'div.tabs ul li a#tab-code_review' end end end @@ -150,20 +150,14 @@ def setup get :settings, :params => {:id => 1} assert_response :success assert_template 'settings' - assert_no_tag :div, :attributes => {:class => 'tabs'}, - :descendant => {:tag => 'ul', - :descendant => {:tag => 'li', - :descendant => {:tag => 'a', :attributes => {:id => 'tab-code_review'}}}} + assert_select 'div.tabs ul li a#tab-code_review' end should "not exist tag id post" do get :settings, :params => {:id => 1} assert_response :success assert_template 'settings' - assert_no_tag :div, :attributes => {:class => 'tabs'}, - :descendant => {:tag => 'ul', - :descendant => {:tag => 'li', - :descendant => {:tag => 'a', :attributes => {:id => 'tab-code_review'}}}} + assert_select 'div.tabs ul li a#tab-code_review' end context "with permission" do @@ -175,20 +169,14 @@ def setup get :settings, :params => {:id => 1} assert_response :success assert_template 'settings' - assert_no_tag :div, :attributes => {:class => 'tabs'}, - :descendant => {:tag => 'ul', - :descendant => {:tag => 'li', - :descendant => {:tag => 'a', :attributes => {:id => 'tab-code_review'}}}} + assert_select 'div.tabs ul li a#tab-code_review', false end should "not exist tag id post" do post :settings, :params => {:id => 1} assert_response :success assert_template 'settings' - assert_no_tag :div, :attributes => {:class => 'tabs'}, - :descendant => {:tag => 'ul', - :descendant => {:tag => 'li', - :descendant => {:tag => 'a', :attributes => {:id => 'tab-code_review'}}}} + assert_select 'div.tabs ul li a#tab-code_review', false end context "and module" do @@ -200,14 +188,14 @@ def setup get :settings, :params => {:id => 1} assert_response :success assert_template 'settings' - assert_select 'div.tabs ul li a#id', 'tab-code_review' + assert_select 'div.tabs ul li a#tab-code_review' end should "not exist tag id post" do post :settings, :params => {:id => 1} assert_response :success assert_template 'settings' - assert_select 'div.tabs ul li a#id', 'tab-code_review' + assert_select 'div.tabs ul li a#tab-code_review' end end end @@ -223,14 +211,14 @@ def setup get :settings, :params => {:id => 1} assert_response :success assert_template 'settings' - assert_select 'div.tabs ul li a#id', 'tab-code_review' + assert_select 'div.tabs ul li a#tab-code_review' end should "not exist tag id post" do get :settings, :params => {:id => 1} assert_response :success assert_template 'settings' - assert_select 'div.tabs ul li a#id', 'tab-code_review' + assert_select 'div.tabs ul li a#tab-code_review' end context "with permission" do @@ -242,14 +230,14 @@ def setup get :settings, :params => {:id => 1} assert_response :success assert_template 'settings' - assert_select 'div.tabs ul li a#id', 'tab-code_review' + assert_select 'div.tabs ul li a#tab-code_review' end should "not exist tag id post" do post :settings, :params => {:id => 1} assert_response :success assert_template 'settings' - assert_select 'div.tabs ul li a#id', 'tab-code_review' + assert_select 'div.tabs ul li a#tab-code_review' end context "and module" do @@ -261,14 +249,14 @@ def setup get :settings, :params => {:id => 1} assert_response :success assert_template 'settings' - assert_select 'div.tabs ul li a#id', 'tab-code_review' + assert_select 'div.tabs ul li a#tab-code_review' end should "exist tag id post" do post :settings, :params => {:id => 1} assert_response :success assert_template 'settings' - assert_select 'div.tabs ul li a#id', 'tab-code_review' + assert_select 'div.tabs ul li a#tab-code_review' end end end diff --git a/test/test_helper.rb b/test/test_helper.rb index 08eeb9a..c6d3f7e 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -26,6 +26,7 @@ end require File.expand_path(File.dirname(__FILE__) + '/../../../test/test_helper') +include ActionDispatch::TestProcess # Ensure that we are using the temporary fixture path #ngines::Testing.set_fixture_path @@ -40,10 +41,14 @@ def mock_file file end +def uploaded_test_file(name, mime) + fixture_file_upload(Rails.root.to_s + "/test/fixtures/files/#{name}", mime, true) +end FactoryGirl.define do factory :attachment do + container{ Issue.find(1) } @@ -55,9 +60,7 @@ def mock_file } end - def uploaded_test_file(name, mime) - fixture_file_upload("files/#{name}", mime, true) - end + factory :repository do project_id 1 diff --git a/test/unit/code_review_auto_assign_settings_test.rb b/test/unit/code_review_auto_assign_settings_test.rb index 8723ff2..bf14966 100644 --- a/test/unit/code_review_auto_assign_settings_test.rb +++ b/test/unit/code_review_auto_assign_settings_test.rb @@ -93,12 +93,12 @@ class CodeReviewAtuoAssignSettingsTest < ActiveSupport::TestCase should "return nil if author_id is nil" do @settings.author_id = nil - assert_equal(nil, @settings.author_id) + assert_nil @settings.author_id end should "return nil if author_id is empty string" do @settings.author_id = '' - assert_equal(nil, @settings.author_id) + assert_nil @settings.author_id end end From 8f806f2e802d67bd2e7a233493e27fb8f8f2ea90 Mon Sep 17 00:00:00 2001 From: Haruyuki Iida Date: Sun, 6 Aug 2017 09:38:03 +0900 Subject: [PATCH 08/33] refs #1478 For Rails 5.1 --- app/controllers/code_review_controller.rb | 2 +- test/functional/issues_controller_test.rb | 1 - test/functional/projects_controller_test.rb | 16 ++++++++-------- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/app/controllers/code_review_controller.rb b/app/controllers/code_review_controller.rb index bbe1a05..4628d36 100644 --- a/app/controllers/code_review_controller.rb +++ b/app/controllers/code_review_controller.rb @@ -332,7 +332,7 @@ def update def destroy @review = CodeReview.find(params[:review_id].to_i) @review.issue.destroy if @review - render :text => 'delete success.' + render :plain => 'delete success.' end def forward_to_revision diff --git a/test/functional/issues_controller_test.rb b/test/functional/issues_controller_test.rb index f65e3f4..fb509e4 100644 --- a/test/functional/issues_controller_test.rb +++ b/test/functional/issues_controller_test.rb @@ -69,7 +69,6 @@ def test_show issue = Issue.generate!(:project => project) get :show, params: {id: issue.id} - issue = Issue.generate!(:project => project) assignment = FactoryGirl.create(:code_review_assignment, issue: issue, rev: 'aaa', file_path: nil) get :show, :params => {:id => assignment.issue.id} diff --git a/test/functional/projects_controller_test.rb b/test/functional/projects_controller_test.rb index 48b1acd..15fee69 100644 --- a/test/functional/projects_controller_test.rb +++ b/test/functional/projects_controller_test.rb @@ -108,14 +108,14 @@ def setup get :settings, :params => {:id => 1} assert_response :success assert_template 'settings' - assert_select 'div.tabs ul li a#tab-code_review' + assert_select 'div.tabs ul li a#tab-code_review', false end should "not exist tag id post" do post :settings, :params => {:id => 1} assert_response :success assert_template 'settings' - assert_select 'div.tabs ul li a#tab-code_review' + assert_select 'div.tabs ul li a#tab-code_review', false end context "and module" do @@ -188,14 +188,14 @@ def setup get :settings, :params => {:id => 1} assert_response :success assert_template 'settings' - assert_select 'div.tabs ul li a#tab-code_review' + assert_select 'div.tabs ul li a#tab-code_review', false end should "not exist tag id post" do post :settings, :params => {:id => 1} assert_response :success assert_template 'settings' - assert_select 'div.tabs ul li a#tab-code_review' + assert_select 'div.tabs ul li a#tab-code_review', false end end end @@ -211,14 +211,14 @@ def setup get :settings, :params => {:id => 1} assert_response :success assert_template 'settings' - assert_select 'div.tabs ul li a#tab-code_review' + assert_select 'div.tabs ul li a#tab-code_review', false end should "not exist tag id post" do get :settings, :params => {:id => 1} assert_response :success assert_template 'settings' - assert_select 'div.tabs ul li a#tab-code_review' + assert_select 'div.tabs ul li a#tab-code_review', false end context "with permission" do @@ -230,14 +230,14 @@ def setup get :settings, :params => {:id => 1} assert_response :success assert_template 'settings' - assert_select 'div.tabs ul li a#tab-code_review' + assert_select 'div.tabs ul li a#tab-code_review', false end should "not exist tag id post" do post :settings, :params => {:id => 1} assert_response :success assert_template 'settings' - assert_select 'div.tabs ul li a#tab-code_review' + assert_select 'div.tabs ul li a#tab-code_review', false end context "and module" do From b721c4b2bd4d23539abc5cff553b4c609ef87a19 Mon Sep 17 00:00:00 2001 From: Haruyuki Iida Date: Sun, 6 Aug 2017 09:57:26 +0900 Subject: [PATCH 09/33] refs #1478 For Rails 5.1 --- test/functional/projects_controller_test.rb | 12 ++++++------ test/unit/code_review_auto_assign_settings_test.rb | 2 ++ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/test/functional/projects_controller_test.rb b/test/functional/projects_controller_test.rb index 15fee69..c164f83 100644 --- a/test/functional/projects_controller_test.rb +++ b/test/functional/projects_controller_test.rb @@ -71,14 +71,14 @@ def setup get :settings, :params => {:id => 1} assert_response :success assert_template 'settings' - assert_select 'div.tabs ul li a#tab-code_review' + assert_select 'div.tabs ul li a#tab-code_review', false end should "not exist tag id post" do post :settings, :params => {:id => 1} assert_response :success assert_template 'settings' - assert_select 'div.tabs ul li a#tab-code_review' + assert_select 'div.tabs ul li a#tab-code_review', false end end end @@ -127,14 +127,14 @@ def setup get :settings, :params => {:id => 1} assert_response :success assert_template 'settings' - assert_select 'div.tabs ul li a#tab-code_review' + assert_select 'div.tabs ul li a#tab-code_review', false end should "not exist tag id post" do post :settings, :params => {:id => 1} assert_response :success assert_template 'settings' - assert_select 'div.tabs ul li a#tab-code_review' + assert_select 'div.tabs ul li a#tab-code_review', false end end end @@ -150,14 +150,14 @@ def setup get :settings, :params => {:id => 1} assert_response :success assert_template 'settings' - assert_select 'div.tabs ul li a#tab-code_review' + assert_select 'div.tabs ul li a#tab-code_review', false end should "not exist tag id post" do get :settings, :params => {:id => 1} assert_response :success assert_template 'settings' - assert_select 'div.tabs ul li a#tab-code_review' + assert_select 'div.tabs ul li a#tab-code_review', false end context "with permission" do diff --git a/test/unit/code_review_auto_assign_settings_test.rb b/test/unit/code_review_auto_assign_settings_test.rb index bf14966..688114e 100644 --- a/test/unit/code_review_auto_assign_settings_test.rb +++ b/test/unit/code_review_auto_assign_settings_test.rb @@ -137,6 +137,8 @@ class CodeReviewAtuoAssignSettingsTest < ActiveSupport::TestCase setup do @settings = AutoAssignSettings.new @project = Project.find(1) + member = Member.new(:project => @project, :user_id => 2) + @project.members << member end should "return nil if assignable_list is nil" do From 2b65b79270cdcc591960c5996c280f59dc9f6bbb Mon Sep 17 00:00:00 2001 From: Haruyuki Iida Date: Sun, 6 Aug 2017 10:40:59 +0900 Subject: [PATCH 10/33] refs #1478 For Rails 5.1 --- lib/code_review_changeset_patch.rb | 4 +++- test/unit/code_review_changeset_patch_test.rb | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/code_review_changeset_patch.rb b/lib/code_review_changeset_patch.rb index 9c40670..e2ccf88 100644 --- a/lib/code_review_changeset_patch.rb +++ b/lib/code_review_changeset_patch.rb @@ -153,7 +153,9 @@ def completed_assignment_pourcent elsif open_assignment_count == 0 100 else - @completed_assignment_pourcent ||= (closed_assignment_count * 100 + open_assignments.collect{|o|o.issue.done_ratio}.inject(:+))/assignment_count + @completed_assignment_pourcent ||= (closed_assignment_count * 100 + open_assignments.collect{|o| + o.issue.done_ratio + }.sum)/assignment_count end end diff --git a/test/unit/code_review_changeset_patch_test.rb b/test/unit/code_review_changeset_patch_test.rb index a7ce94f..23c35b8 100644 --- a/test/unit/code_review_changeset_patch_test.rb +++ b/test/unit/code_review_changeset_patch_test.rb @@ -77,6 +77,7 @@ def test_completed_assignment_pourcent issues[i - 1].save! } changeset.save! + changeset = Changeset.find(changeset.id) assert_equal(0, changeset.completed_assignment_pourcent) issues[0].status_id = 5 issues[0].save! @@ -90,7 +91,7 @@ def test_completed_assignment_pourcent end context "closed_assignment_pourcent" do - + should "returns 0 if changeset has no assignments." do change = FactoryGirl.create(:change) changeset = change.changeset From 1bbb2eeb5663d0197f95767949aa3387c69172cb Mon Sep 17 00:00:00 2001 From: Haruyuki Iida Date: Sun, 6 Aug 2017 22:45:01 +0900 Subject: [PATCH 11/33] refs #1478 For Rails 5.1 --- app/controllers/code_review_controller.rb | 7 ++++--- app/controllers/code_review_settings_controller.rb | 2 +- test/functional/code_review_controller_test.rb | 3 ++- test/unit/code_review_auto_assign_settings_test.rb | 7 +++++-- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/app/controllers/code_review_controller.rb b/app/controllers/code_review_controller.rb index 4628d36..e81fadb 100644 --- a/app/controllers/code_review_controller.rb +++ b/app/controllers/code_review_controller.rb @@ -309,7 +309,7 @@ def update @allowed_statuses = @review.issue.new_statuses_allowed_to(User.current) @issue = @review.issue @issue.lock_version = params[:issue][:lock_version] - @review.assign_attributes(params[:review]) + @review.attributes = params.require(:review).permit(:change_id, :subject, :lock_version, :parent_id, :comment, :status_id, :issue) @review.updated_by_id = @user.id @review.save! @review.issue.save! @@ -323,8 +323,9 @@ def update # Optimistic locking exception @error = l(:notice_locking_conflict) render :partial => 'show' - rescue - render :partial => 'show' + #rescue => e + #throw e + #render :partial => 'show' end end diff --git a/app/controllers/code_review_settings_controller.rb b/app/controllers/code_review_settings_controller.rb index b72f6cb..52b41e6 100644 --- a/app/controllers/code_review_settings_controller.rb +++ b/app/controllers/code_review_settings_controller.rb @@ -29,7 +29,7 @@ def update @setting.attributes = params.require(:setting).permit(:tracker_id, :assignment_tracker_id, :hide_code_review_tab, :auto_relation, :tracker_in_review_dialog, :auto_assign) @setting.updated_by = @user.id - params[:auto_assign][:filters] = params[:auto_assign][:filters].values unless params[:auto_assign][:filters].blank? + params[:auto_assign][:filters] = params[:auto_assign][:filters].values if !params[:auto_assign].blank? && !params[:auto_assign][:filters].blank? @setting.auto_assign_settings = params[:auto_assign].to_yaml @setting.save! diff --git a/test/functional/code_review_controller_test.rb b/test/functional/code_review_controller_test.rb index 8598d00..7c79032 100644 --- a/test/functional/code_review_controller_test.rb +++ b/test/functional/code_review_controller_test.rb @@ -257,14 +257,15 @@ def test_update_lock_error @request.session[:user_id] = 1 review_id = 9 review = CodeReview.find(review_id) + review.save! assert_equal('Unable to print recipes', review.comment) post :update, :params => {:id => 1, :review_id => review_id, :review => {:comment => 'bbb', :lock_version => review.lock_version}, :issue => {:lock_version => 1}} + assert_not_nil assigns(:error) assert_response :success review = CodeReview.find(review_id) assert_equal('Unable to print recipes', review.comment) - assert assigns(:error) end def test_update_diff_view diff --git a/test/unit/code_review_auto_assign_settings_test.rb b/test/unit/code_review_auto_assign_settings_test.rb index 688114e..7436e96 100644 --- a/test/unit/code_review_auto_assign_settings_test.rb +++ b/test/unit/code_review_auto_assign_settings_test.rb @@ -137,8 +137,11 @@ class CodeReviewAtuoAssignSettingsTest < ActiveSupport::TestCase setup do @settings = AutoAssignSettings.new @project = Project.find(1) - member = Member.new(:project => @project, :user_id => 2) - @project.members << member + members = [] + 2.upto(5) {|i| + members << Member.new(:project => @project, :user_id => i) + } + @project.members << members end should "return nil if assignable_list is nil" do From d13fd2d46376347f4439d7b9b49fc2dacc2ac8aa Mon Sep 17 00:00:00 2001 From: Haruyuki Iida Date: Mon, 7 Aug 2017 00:03:13 +0900 Subject: [PATCH 12/33] refs #1478 For Rails 5.1 --- lib/code_review_changeset_patch.rb | 2 ++ test/functional/code_review_controller_test.rb | 7 ++++--- test/functional/repositories_controller_test.rb | 7 ++++--- test/unit/code_review_changeset_patch_test.rb | 4 ++++ 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/code_review_changeset_patch.rb b/lib/code_review_changeset_patch.rb index e2ccf88..4d82f31 100644 --- a/lib/code_review_changeset_patch.rb +++ b/lib/code_review_changeset_patch.rb @@ -153,7 +153,9 @@ def completed_assignment_pourcent elsif open_assignment_count == 0 100 else + opens = open_assignments @completed_assignment_pourcent ||= (closed_assignment_count * 100 + open_assignments.collect{|o| + puts o.issue.done_ratio o.issue.done_ratio }.sum)/assignment_count diff --git a/test/functional/code_review_controller_test.rb b/test/functional/code_review_controller_test.rb index 7c79032..1b55360 100644 --- a/test/functional/code_review_controller_test.rb +++ b/test/functional/code_review_controller_test.rb @@ -19,8 +19,9 @@ class CodeReviewControllerTest < ActionController::TestCase fixtures :code_reviews, :projects, :users, :repositories, :changesets, :changes, :members, :roles, :issues, :issue_statuses, - :enumerations, :issue_categories, :trackers, :trackers, :projects, :projects_trackers, - :code_review_project_settings, :attachments + :enumerations, :issue_categories, :trackers, :projects, :projects_trackers, + :code_review_project_settings, :attachments, :code_review_assignments, + :code_review_user_settings def setup @controller = CodeReviewController.new @request = ActionController::TestRequest.create(self.class.controller_class) @@ -280,7 +281,7 @@ def test_update_diff_view def test_forward_to_revision @request.session[:user_id] = 1 - post :forward_to_revision, :params => {:id => 1, :path => '/test/some/path/in/the/repo'} + post :forward_to_revision, :params => {:id => 1, :path => '/subversion_test/folder/helloworld.rb'} end def test_update_attachment_view diff --git a/test/functional/repositories_controller_test.rb b/test/functional/repositories_controller_test.rb index 513375a..0d4802c 100644 --- a/test/functional/repositories_controller_test.rb +++ b/test/functional/repositories_controller_test.rb @@ -20,8 +20,9 @@ class RepositoriesControllerTest < ActionController::TestCase - fixtures :projects, :users, :roles, :members, :repositories, :issues, :issue_statuses, :changesets, :changes, :issue_categories, :enumerations, :custom_fields, :custom_values, :trackers - + fixtures :projects, :users, :roles, :members, :repositories, :issues, :issue_statuses, :changesets, + :changes, :issue_categories, :enumerations, :custom_fields, :custom_values, :trackers + def setup @controller = RepositoriesController.new @request = ActionController::TestRequest.create(self.class.controller_class) @@ -60,7 +61,7 @@ def test_revision project = Project.find(1) project.repository.destroy project.repository = changeset.repository - issue = Issue.generate!({:project => project, :description => 'test'}) + issue = Issue.generate!({:project_id => project.id, :description => 'test', :tracker_id =>1, :status_id => 1}) review = FactoryGirl.create(:code_review, change: change, project: project, issue: issue) get :revision, :params => {:id => project.id, :rev => changeset.revision, :path => change.path.split('/')} #assert_response :success diff --git a/test/unit/code_review_changeset_patch_test.rb b/test/unit/code_review_changeset_patch_test.rb index 23c35b8..96cb7c5 100644 --- a/test/unit/code_review_changeset_patch_test.rb +++ b/test/unit/code_review_changeset_patch_test.rb @@ -115,11 +115,15 @@ def test_completed_assignment_pourcent changeset = change.changeset @project = Project.find(1) issue1 = Issue.generate!({:project => @project, :status => IssueStatus.find(5)}) + issue1.status = IssueStatus.find(5); issue2 = Issue.generate!({:project => @project, :status => IssueStatus.find(5)}) + issue2.status = IssueStatus.find(5); change.code_review_assignments << FactoryGirl.create(:code_review_assignment, issue: issue1) change.code_review_assignments << FactoryGirl.create(:code_review_assignment, issue: issue2) change.save! changeset =Changeset.find(changeset.id) + assert issue1.closed? + assert issue2.closed? assert_equal(2, changeset.assignment_count) assert_equal(100, changeset.closed_assignment_pourcent) end From 05917871625f6847442f10fce69dd9d9c1f3da39 Mon Sep 17 00:00:00 2001 From: Haruyuki Iida Date: Wed, 9 Aug 2017 00:05:17 +0900 Subject: [PATCH 13/33] refs #1478 For Rails 5.1 --- test/functional/issues_controller_test.rb | 6 ++++-- test/unit/code_review_changeset_patch_test.rb | 12 +++++++----- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/test/functional/issues_controller_test.rb b/test/functional/issues_controller_test.rb index fb509e4..65b5c0a 100644 --- a/test/functional/issues_controller_test.rb +++ b/test/functional/issues_controller_test.rb @@ -1,5 +1,5 @@ # Code Review plugin for Redmine -# Copyright (C) 2009-2014 Haruyuki Iida +# Copyright (C) 2009-2017 Haruyuki Iida # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -42,7 +42,9 @@ class IssuesControllerTest < ActionController::TestCase :time_entries, :journals, :journal_details, - :code_reviews + :code_reviews, + :code_review_assignments, + :code_review_user_settings def setup @controller = IssuesController.new diff --git a/test/unit/code_review_changeset_patch_test.rb b/test/unit/code_review_changeset_patch_test.rb index 96cb7c5..de769c6 100644 --- a/test/unit/code_review_changeset_patch_test.rb +++ b/test/unit/code_review_changeset_patch_test.rb @@ -1,5 +1,5 @@ # Code Review plugin for Redmine -# Copyright (C) 2009-2014 Haruyuki Iida +# Copyright (C) 2009-2017 Haruyuki Iida # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -17,12 +17,14 @@ require File.expand_path(File.dirname(__FILE__) + '/../test_helper') class CodeReviewChangesetPatchTest < ActiveSupport::TestCase - fixtures :code_reviews, :projects, :users, :repositories, :changesets, - :changes, :issues, :issue_statuses, :enumerations, :issue_categories, :trackers, - :projects_trackers + fixtures :code_reviews, :projects, :users, :repositories, + :changesets, :changes, :members, :roles, :issues, :issue_statuses, + :enumerations, :issue_categories, :trackers, :projects, :projects_trackers, + :code_review_project_settings, :attachments, :code_review_assignments, + :code_review_user_settings include CodeReviewAutoAssignSettings - + def test_review_count changeset = Changeset.find(100) assert_equal(2, changeset.review_count) From 19f98f5ab887c7594a5b2b96be9ccf1d66bd30b7 Mon Sep 17 00:00:00 2001 From: Haruyuki Iida Date: Thu, 10 Aug 2017 00:57:43 +0900 Subject: [PATCH 14/33] change branch to master --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 1bf7e34..4ed131c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,7 @@ rvm: #branches: env: - - REDMINE_VER=3.4-stable + - REDMINE_VER=master #install: "echo skip bundle install" From 663ce2140abf757bd7f36734ca54200628671210 Mon Sep 17 00:00:00 2001 From: Haruyuki Iida Date: Thu, 10 Aug 2017 21:41:56 +0900 Subject: [PATCH 15/33] fix open_assignments does not search recursively. --- lib/code_review_changeset_patch.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/code_review_changeset_patch.rb b/lib/code_review_changeset_patch.rb index 4d82f31..e372f7e 100644 --- a/lib/code_review_changeset_patch.rb +++ b/lib/code_review_changeset_patch.rb @@ -130,9 +130,15 @@ def assignment_issues end def open_assignments - @open_assignments ||= code_review_assignments.select {|assignment| + return @open_assignments if @open_assignments + @open_assignments = code_review_assignments.select {|assignment| !assignment.is_closed? } + filechanges.each{|change| + @open_assignments = @open_assignments + change.code_review_assignments.select {|assignment| + !assignment.is_closed? + } + } end def closed_assignment_count @@ -155,7 +161,6 @@ def completed_assignment_pourcent else opens = open_assignments @completed_assignment_pourcent ||= (closed_assignment_count * 100 + open_assignments.collect{|o| - puts o.issue.done_ratio o.issue.done_ratio }.sum)/assignment_count From ebcd33e41e8d0c3a8db600e0c1a548ae53d1855a Mon Sep 17 00:00:00 2001 From: Haruyuki Iida Date: Thu, 10 Aug 2017 21:42:23 +0900 Subject: [PATCH 16/33] test code maintenance. --- test/functional/repositories_controller_test.rb | 2 +- test/unit/code_review_auto_assign_settings_test.rb | 14 +++++++++++++- test/unit/code_review_changeset_patch_test.rb | 8 +++++++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/test/functional/repositories_controller_test.rb b/test/functional/repositories_controller_test.rb index 0d4802c..ac571b6 100644 --- a/test/functional/repositories_controller_test.rb +++ b/test/functional/repositories_controller_test.rb @@ -61,7 +61,7 @@ def test_revision project = Project.find(1) project.repository.destroy project.repository = changeset.repository - issue = Issue.generate!({:project_id => project.id, :description => 'test', :tracker_id =>1, :status_id => 1}) + issue = Issue.generate!({:project_id => project.id, :description => 'test', :tracker => Tracker.find(1), :status_id => 1}) review = FactoryGirl.create(:code_review, change: change, project: project, issue: issue) get :revision, :params => {:id => project.id, :rev => changeset.revision, :path => change.path.split('/')} #assert_response :success diff --git a/test/unit/code_review_auto_assign_settings_test.rb b/test/unit/code_review_auto_assign_settings_test.rb index 7436e96..260375f 100644 --- a/test/unit/code_review_auto_assign_settings_test.rb +++ b/test/unit/code_review_auto_assign_settings_test.rb @@ -18,9 +18,21 @@ require File.expand_path(File.dirname(__FILE__) + '/../test_helper') class CodeReviewAtuoAssignSettingsTest < ActiveSupport::TestCase - fixtures :code_review_project_settings, :projects, :users, :trackers, :repositories, :projects_trackers + fixtures :code_reviews, :projects, :users, :repositories, + :changesets, :changes, :members, :roles, :issues, :issue_statuses, + :enumerations, :issue_categories, :trackers, :projects, :projects_trackers, + :code_review_project_settings, :attachments, :code_review_assignments, + :code_review_user_settings include CodeReviewAutoAssignSettings + + def startup + #DatabaseRewinder.clean_all + end + + def teardown + #DatabaseRewinder.clean + end context "AutoAssignSettings" do context "to_s" do diff --git a/test/unit/code_review_changeset_patch_test.rb b/test/unit/code_review_changeset_patch_test.rb index de769c6..a1d9a4a 100644 --- a/test/unit/code_review_changeset_patch_test.rb +++ b/test/unit/code_review_changeset_patch_test.rb @@ -89,7 +89,9 @@ def test_completed_assignment_pourcent issues[1].done_ratio = 50 issues[1].save! changeset = Changeset.find(changeset.id) - assert_equal(37.5, changeset.completed_assignment_pourcent) + assert_equal(4, changeset.assignment_count) + assert_equal(3, changeset.open_assignment_count) + assert_equal(37.5.to_i, changeset.completed_assignment_pourcent) end context "closed_assignment_pourcent" do @@ -127,6 +129,9 @@ def test_completed_assignment_pourcent assert issue1.closed? assert issue2.closed? assert_equal(2, changeset.assignment_count) + assert_equal(1, changeset.filechanges.length) + assert_equal(0, changeset.open_assignment_count) + assert_equal(2, changeset.closed_assignment_count) assert_equal(100, changeset.closed_assignment_pourcent) end @@ -145,6 +150,7 @@ def test_completed_assignment_pourcent change.code_review_assignments << FactoryGirl.create(:code_review_assignment, issue: issue3) change.code_review_assignments << FactoryGirl.create(:code_review_assignment, issue: issue4) change.save! + changeset = Changeset.find(changeset.id) assert_equal(50, changeset.closed_assignment_pourcent) end end From fb27471d3f79f9ad60bb6935469bf3cc276e7f9c Mon Sep 17 00:00:00 2001 From: Haruyuki Iida Date: Thu, 10 Aug 2017 21:48:50 +0900 Subject: [PATCH 17/33] change redmine version for travis ci --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 67a25ac..7ead66a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,9 @@ language: ruby rvm: -- 2.2 - 2.3 +- 2.4 env: -- REDMINE_VER=3.4-stable +- REDMINE_VER=master script: - export TESTSPACE=`pwd`/testspace - export NAME_OF_PLUGIN=redmine_code_review From c3e24512a3c6c219b494153d86457003d61a912c Mon Sep 17 00:00:00 2001 From: Haruyuki Iida Date: Fri, 11 Aug 2017 13:05:01 +0900 Subject: [PATCH 18/33] test code maintenance. --- test/functional/code_review_controller_test.rb | 2 +- test/functional/issues_controller_test.rb | 1 + test/functional/repositories_controller_test.rb | 4 ++-- test/unit/code_review_auto_assign_settings_test.rb | 2 +- test/unit/code_review_changeset_patch_test.rb | 2 +- 5 files changed, 6 insertions(+), 5 deletions(-) diff --git a/test/functional/code_review_controller_test.rb b/test/functional/code_review_controller_test.rb index 1b55360..d0c7306 100644 --- a/test/functional/code_review_controller_test.rb +++ b/test/functional/code_review_controller_test.rb @@ -18,7 +18,7 @@ class CodeReviewControllerTest < ActionController::TestCase fixtures :code_reviews, :projects, :users, :repositories, - :changesets, :changes, :members, :roles, :issues, :issue_statuses, + :changesets, :changes, :members, :member_roles, :roles, :issues, :issue_statuses, :enumerations, :issue_categories, :trackers, :projects, :projects_trackers, :code_review_project_settings, :attachments, :code_review_assignments, :code_review_user_settings diff --git a/test/functional/issues_controller_test.rb b/test/functional/issues_controller_test.rb index 65b5c0a..2b2fd98 100644 --- a/test/functional/issues_controller_test.rb +++ b/test/functional/issues_controller_test.rb @@ -26,6 +26,7 @@ class IssuesControllerTest < ActionController::TestCase :users, :roles, :members, + :member_roles, :issues, :issue_statuses, :versions, diff --git a/test/functional/repositories_controller_test.rb b/test/functional/repositories_controller_test.rb index ac571b6..c8cc641 100644 --- a/test/functional/repositories_controller_test.rb +++ b/test/functional/repositories_controller_test.rb @@ -20,8 +20,8 @@ class RepositoriesControllerTest < ActionController::TestCase - fixtures :projects, :users, :roles, :members, :repositories, :issues, :issue_statuses, :changesets, - :changes, :issue_categories, :enumerations, :custom_fields, :custom_values, :trackers + fixtures :projects, :users, :roles, :members, :member_roles, :repositories, :issues, :issue_statuses, :changesets, + :changes, :issue_categories, :enumerations, :custom_fields, :custom_values, :trackers, :projects_trackers def setup @controller = RepositoriesController.new diff --git a/test/unit/code_review_auto_assign_settings_test.rb b/test/unit/code_review_auto_assign_settings_test.rb index 260375f..354a092 100644 --- a/test/unit/code_review_auto_assign_settings_test.rb +++ b/test/unit/code_review_auto_assign_settings_test.rb @@ -19,7 +19,7 @@ class CodeReviewAtuoAssignSettingsTest < ActiveSupport::TestCase fixtures :code_reviews, :projects, :users, :repositories, - :changesets, :changes, :members, :roles, :issues, :issue_statuses, + :changesets, :changes, :members, :member_roles, :roles, :issues, :issue_statuses, :enumerations, :issue_categories, :trackers, :projects, :projects_trackers, :code_review_project_settings, :attachments, :code_review_assignments, :code_review_user_settings diff --git a/test/unit/code_review_changeset_patch_test.rb b/test/unit/code_review_changeset_patch_test.rb index a1d9a4a..b3d53cb 100644 --- a/test/unit/code_review_changeset_patch_test.rb +++ b/test/unit/code_review_changeset_patch_test.rb @@ -18,7 +18,7 @@ class CodeReviewChangesetPatchTest < ActiveSupport::TestCase fixtures :code_reviews, :projects, :users, :repositories, - :changesets, :changes, :members, :roles, :issues, :issue_statuses, + :changesets, :changes, :members, :member_roles, :roles, :issues, :issue_statuses, :enumerations, :issue_categories, :trackers, :projects, :projects_trackers, :code_review_project_settings, :attachments, :code_review_assignments, :code_review_user_settings From 6f44b0706d6553ff54866b2439def07501e1c4db Mon Sep 17 00:00:00 2001 From: Haruyuki Iida Date: Sun, 29 Oct 2017 15:59:22 +0900 Subject: [PATCH 19/33] update test scripts --- .travis.yml | 9 ++---- test/test_helper.rb | 6 ++++ travis/env.sh | 5 ++++ travis/travis.sh | 24 ++++++++++++++++ travis.sh => travis/travis_install.sh | 40 ++++++++++++--------------- 5 files changed, 56 insertions(+), 28 deletions(-) create mode 100644 travis/env.sh create mode 100644 travis/travis.sh rename travis.sh => travis/travis_install.sh (63%) diff --git a/.travis.yml b/.travis.yml index 7ead66a..77ace18 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,13 +4,10 @@ rvm: - 2.4 env: - REDMINE_VER=master +install: +- bash -x ./travis/travis_install.sh script: -- export TESTSPACE=`pwd`/testspace -- export NAME_OF_PLUGIN=redmine_code_review -- export PATH_TO_PLUGIN=`pwd` -- export PATH_TO_REDMINE=$TESTSPACE/redmine -- mkdir $TESTSPACE -- bash -x ./travis.sh +- bash -x ./travis/travis.sh notifications: slack: secure: XhtN5XeJKyYhGYRFGfxGpGaVcUnUsZoxX3ZL3RgHikcBhD0hY6Ogn09BSiygP381lbIlV7+2nlRvNoSUKYmx2uX5w8AUYCE4yo9yJGlY+70rD2kjWsuG9OK4L/QPCXIUf8NFX24PdY9CRITK5CfR1/hEZCx9ygT6GLAqpjqNDtfMpSRx7S3olVjX58ucB9azDcvaT75vPY1nEnnn/IuOwGF27KBk9lLZtMaG1ohI6+9jW9xCxz8cLfUUPIu+PH4/AvJ8GMNJtlc3Yvgbg57lCtulvHyrXqXHMvMDL2aTdIj2XsjVSvXV4jRrNuhJga6gDAtl/3Lzm+UZZAeHpR4qHDZN06za25HypX/GbX5pZtpr30t+HHs3cd+ecHb4uP/Tnxko0KzNywg6Ayn/8TC548eu0JRITzPS5C9/NKzA+XnAjVgKMzqy0zU1VVk83hBXshgpfqplfZzdIrn75kcV/3qsiaD4qEFM2MqNYD15Epq8a7W/9IKdhd95LsQjp1Fb0g7XiQcM3ahIgMLIjP5tZfQ8b7tVlmDx1GCP4uRFOBeDeoz9i++UaT/FdPHOFGirWfDZMJoVq3MXixaTudEPFomO2HktErAMIEjQQyVe4FylglGnE52RCqEJ0qiD/kh1HV1VnVqyTJ9o3DXgLTIMdFiw+jHtTuorYPG0Qn1Dqbg= diff --git a/test/test_helper.rb b/test/test_helper.rb index 12d9ed6..b3f0494 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -33,6 +33,12 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../test/test_helper') include ActionDispatch::TestProcess +fixtures = [] +Dir.chdir(File.dirname(__FILE__) + '/fixtures/') do + fixtures = Dir.glob('*.yml').map{|s| s.gsub(/.yml$/, '')} +end +ActiveRecord::FixtureSet.create_fixtures(File.dirname(__FILE__) + '/fixtures/', fixtures) + # Ensure that we are using the temporary fixture path #ngines::Testing.set_fixture_path diff --git a/travis/env.sh b/travis/env.sh new file mode 100644 index 0000000..3ba4f48 --- /dev/null +++ b/travis/env.sh @@ -0,0 +1,5 @@ +export TRAVISDIR=`pwd` +export PATH_TO_PLUGIN=`dirname ${TRAVISDIR}` +export TESTSPACE=$PATH_TO_PLUGIN/testspace +export PATH_TO_REDMINE=$TESTSPACE/redmine +export RAILS_ENV=test \ No newline at end of file diff --git a/travis/travis.sh b/travis/travis.sh new file mode 100644 index 0000000..6d901d9 --- /dev/null +++ b/travis/travis.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +set -e + +cd `dirname $0` +. env.sh +cd .. + +if [ "$NAME_OF_PLUGIN" == "" ] +then + export NAME_OF_PLUGIN=`basename $PATH_TO_PLUGIN` +fi + +cd $PATH_TO_REDMINE + +bundle exec rake db:structure:dump + +# create scms for test +bundle exec rake test:scm:setup:all + +# run tests +# bundle exec rake TEST=test/unit/role_test.rb +bundle exec rake redmine:plugins:test NAME=$NAME_OF_PLUGIN + diff --git a/travis.sh b/travis/travis_install.sh similarity index 63% rename from travis.sh rename to travis/travis_install.sh index 16d5341..8bd0755 100644 --- a/travis.sh +++ b/travis/travis_install.sh @@ -1,29 +1,37 @@ #!/bin/bash -#/bin/bash - set -e +cd `dirname $0` +. env.sh +cd .. + if [[ ! "$TESTSPACE" = /* ]] || [[ ! "$PATH_TO_REDMINE" = /* ]] || - [[ ! "$REDMINE_VER" = * ]] || - [[ ! "$NAME_OF_PLUGIN" = * ]] || [[ ! "$PATH_TO_PLUGIN" = /* ]]; then echo "You should set"\ - " TESTSPACE, PATH_TO_REDMINE, REDMINE_VER"\ - " NAME_OF_PLUGIN, PATH_TO_PLUGIN"\ + " TESTSPACE, PATH_TO_REDMINE,"\ + " PATH_TO_PLUGIN"\ " environment variables" echo "You set:"\ "$TESTSPACE"\ "$PATH_TO_REDMINE"\ - "$REDMINE_VER"\ - "$NAME_OF_PLUGIN"\ "$PATH_TO_PLUGIN" exit 1; fi -export RAILS_ENV=test +if [ "$REDMINE_VER" = "" ] +then + export REDMINE_VER=master +fi + +if [ "$NAME_OF_PLUGIN" == "" ] +then + export NAME_OF_PLUGIN=`basename $PATH_TO_PLUGIN` +fi + +mkdir -p $TESTSPACE export REDMINE_GIT_REPO=git://github.com/redmine/redmine.git export REDMINE_GIT_TAG=$REDMINE_VER @@ -36,7 +44,7 @@ fi # checkout redmine git clone $REDMINE_GIT_REPO $PATH_TO_REDMINE -cp test/fixtures/* ${PATH_TO_REDMINE}/test/fixtures/ + cd $PATH_TO_REDMINE if [ ! "$REDMINE_GIT_TAG" = "master" ]; then @@ -63,16 +71,4 @@ bundle exec rake db:migrate # run plugin database migrations bundle exec rake redmine:plugins:migrate -# install redmine database -#bundle exec rake redmine:load_default_data REDMINE_LANG=en - -bundle exec rake db:structure:dump - -# create scms for test - -bundle exec rake test:scm:setup:all - -# run tests -# bundle exec rake TEST=test/unit/role_test.rb -bundle exec rake redmine:plugins:test NAME=$NAME_OF_PLUGIN From 89cf862c9b4dee924345a9ad31581cc13ad98e93 Mon Sep 17 00:00:00 2001 From: Haruyuki Iida Date: Fri, 8 Dec 2017 14:14:58 +0900 Subject: [PATCH 20/33] code re-format by rufo --- app/controllers/code_review_controller.rb | 44 ++++------ .../code_review_settings_controller.rb | 13 ++- app/helpers/code_review_helper.rb | 11 +-- app/models/code_review.rb | 15 ++-- app/models/code_review_assignment.rb | 15 ++-- app/models/code_review_project_setting.rb | 5 +- app/models/review_mailer.rb | 30 +++---- config/routes.rb | 2 +- db/migrate/0001_create_code_reviews.rb | 2 - db/migrate/0002_add_updated_by.rb | 1 - db/migrate/0003_add_lock_version.rb | 3 +- db/migrate/0004_add_status_changed.rb | 1 - .../0005_create_code_review_user_settings.rb | 6 +- db/migrate/0006_link_to_issue.rb | 1 - db/migrate/0007_rename_user.rb | 3 +- ...008_create_code_review_project_settings.rb | 2 - db/migrate/0009_add_hide_tab.rb | 1 - db/migrate/0010_add_action_type.rb | 1 - db/migrate/0011_add_auto_relation.rb | 3 +- db/migrate/0012_add_attachment_id.rb | 1 - db/migrate/0013_add_file_count.rb | 1 - .../0014_create_code_review_assignments.rb | 2 - db/migrate/0015_add_assignment_tracker.rb | 1 - db/migrate/0016_add_changeset_id.rb | 1 - db/migrate/0017_add_auto_assign.rb | 1 - ...18_add_lock_version_to_project_settings.rb | 1 - db/migrate/0019_delete_old_fields.rb | 2 +- .../0020_add_tracker_to_review_dialog.rb | 4 +- db/migrate/0021_add_diff_all.rb | 2 +- init.rb | 15 ++-- lib/code_review_application_hooks.rb | 1 + lib/code_review_attachment_patch.rb | 5 -- lib/code_review_auto_assign_settings.rb | 19 ++-- lib/code_review_change_patch.rb | 7 +- lib/code_review_changeset_patch.rb | 41 ++++----- lib/code_review_issue_hooks.rb | 15 ++-- lib/code_review_issue_patch.rb | 5 -- lib/code_review_projects_helper_patch.rb | 2 - test/code_review_object_daddy_helpers.rb | 14 +-- test/exemplars/code_review_exemplar.rb | 2 - .../functional/attachments_controller_test.rb | 8 +- .../functional/code_review_controller_test.rb | 87 +++++++++---------- .../code_review_settings_controller_test.rb | 29 +++---- test/functional/issues_controller_test.rb | 15 ++-- test/functional/projects_controller_test.rb | 2 +- .../repositories_controller_test.rb | 7 +- test/test_helper.rb | 20 ++--- test/test_runner.rb | 7 +- test/unit/code_review_assignment_test.rb | 3 +- .../unit/code_review_attachment_patch_test.rb | 2 +- .../code_review_auto_assign_settings_test.rb | 28 +++--- test/unit/code_review_change_patch_test.rb | 6 +- test/unit/code_review_changeset_patch_test.rb | 14 ++- .../unit/code_review_project_settings_test.rb | 26 +++--- test/unit/code_review_test.rb | 23 +++-- 55 files changed, 246 insertions(+), 332 deletions(-) diff --git a/app/controllers/code_review_controller.rb b/app/controllers/code_review_controller.rb index e81fadb..4cac153 100644 --- a/app/controllers/code_review_controller.rb +++ b/app/controllers/code_review_controller.rb @@ -33,7 +33,7 @@ class CodeReviewController < ApplicationController def index sort_init "#{Issue.table_name}.id", 'desc' - sort_update ["#{Issue.table_name}.id", "#{Issue.table_name}.status_id", "#{Issue.table_name}.subject", "path", "updated_at", "user_id", "#{Changeset.table_name}.committer", "#{Changeset.table_name}.revision"] + sort_update ["#{Issue.table_name}.id", "#{Issue.table_name}.status_id", "#{Issue.table_name}.subject", "path", "updated_at", "user_id", "#{Changeset.table_name}.committer", "#{Changeset.table_name}.revision"] limit = per_page_option @review_count = CodeReview.where(["project_id = ? and issue_id is NOT NULL", @project.id]).count @@ -52,7 +52,8 @@ def index @reviews = CodeReview.order(sort_clause).limit(limit).where(conditions).joins( "left join #{Change.table_name} on change_id = #{Change.table_name}.id left join #{Changeset.table_name} on #{Change.table_name}.changeset_id = #{Changeset.table_name}.id " + "left join #{Issue.table_name} on issue_id = #{Issue.table_name}.id " + - "left join #{IssueStatus.table_name} on #{Issue.table_name}.status_id = #{IssueStatus.table_name}.id").offset(@review_pages.offset) + "left join #{IssueStatus.table_name} on #{Issue.table_name}.status_id = #{IssueStatus.table_name}.id" + ).offset(@review_pages.offset) @i_am_member = @user.member_of?(@project) render :template => 'code_review/index', :layout => !request.xhr? end @@ -85,12 +86,12 @@ def new @review.issue.safe_attributes = params[:issue] unless params[:issue].blank? @review.diff_all = (params[:diff_all] == 'true') - @parent_candidate = get_parent_candidate(@review.rev) if @review.rev + @parent_candidate = get_parent_candidate(@review.rev) if @review.rev if request.post? @review.issue.save! if @review.changeset - @review.changeset.issues.each {|issue| + @review.changeset.issues.each { |issue| create_relation @review, issue, @setting.issue_relation_type } if @setting.auto_relation? elsif @review.attachment and @review.attachment.container_type == 'Issue' @@ -98,7 +99,7 @@ def new create_relation @review, issue, @setting.issue_relation_type if @setting.auto_relation? end watched_users = [] - @review.open_assignment_issues(@user.id).each {|issue| + @review.open_assignment_issues(@user.id).each { |issue| unless @review.issue.parent_id == issue.id create_relation @review, issue, IssueRelation::TYPE_RELATES end @@ -124,21 +125,19 @@ def new end @default_version_id = @review.issue.fixed_version.id if @review.issue.fixed_version if @review.changeset and @default_version_id.blank? - @review.changeset.issues.each {|issue| + @review.changeset.issues.each { |issue| if issue.fixed_version @default_version_id = issue.fixed_version.id - break; + break end } end - @review.open_assignment_issues(@user.id).each {|issue| + @review.open_assignment_issues(@user.id).each { |issue| if issue.fixed_version @default_version_id = issue.fixed_version.id - break; + break end } unless @default_version_id - - end render :partial => 'new_form', :status => 200 } @@ -174,7 +173,7 @@ def assign end issue[:tracker_id] = @setting.assignment_tracker_id if @setting.assignment_tracker_id - redirect_to :controller => 'issues', :action => "new" , :project_id => @project, + redirect_to :controller => 'issues', :action => "new", :project_id => @project, :issue => issue, :code => code end @@ -191,8 +190,7 @@ def update_diff_view @action_type = params[:action_type] changeset = @repository.find_changeset_by_name(@rev) if @paths.empty? - changeset.filechanges.each{|chg| - } + changeset.filechanges.each { |chg| } end url = @repository.url @@ -208,9 +206,9 @@ def update_diff_view end end @change = nil - changeset.filechanges.each{|chg| + changeset.filechanges.each { |chg| @change = chg if ((chg.path == fullpath) or ("/#{chg.path}" == fullpath)) or (chg.path == "/#{@path}") - } unless @path.blank? + } unless @path.blank? @changeset = changeset if @path @@ -223,8 +221,6 @@ def update_diff_view #render :partial => 'show_error' #return - - render :partial => 'update_diff_view' end @@ -268,7 +264,7 @@ def show else path = nil if target.diff_all url = url_for(:controller => 'repositories', :action => action_name, :id => @project, - :repository_id => @repository_id, :rev => target.revision, :path => path) + :repository_id => @repository_id, :rev => target.revision, :path => path) #url = url_for(:controller => 'repositories', :action => action_name, :id => @project, :repository_id => @repository_id) + path + '?rev=' + target.revision url << '?review_id=' + @review.id.to_s + rev_to if @review url << '?r=' + rev_to unless @review @@ -323,13 +319,12 @@ def update # Optimistic locking exception @error = l(:notice_locking_conflict) render :partial => 'show' - #rescue => e + #rescue => e #throw e #render :partial => 'show' end end - def destroy @review = CodeReview.find(params[:review_id].to_i) @review.issue.destroy if @review @@ -344,7 +339,6 @@ def forward_to_revision identifier = change.identifier redirect_to url_for(:controller => 'repositories', :action => 'entry', :id => @project, :repository_id => @repository_id) + '/' + path + '?rev=' + identifier.to_s - end def preview @@ -358,13 +352,14 @@ def update_revisions_view #changeset_ids = CGI.unescape(params[:changeset_ids]).split(',') unless params[:changeset_ids].blank? changeset_ids = params[:changeset_ids].split(',') unless params[:changeset_ids].blank? @changesets = [] - changeset_ids.each {|id| + changeset_ids.each { |id| @changesets << @repository.find_changeset_by_name(id) unless id.blank? } render :partial => 'update_revisions' end private + def find_repository if params[:repository_id].present? and @project.repositories @repository = @project.repositories.find_by_identifier_param(params[:repository_id]) @@ -383,14 +378,13 @@ def find_user @user = User.current end - def find_setting @setting = CodeReviewProjectSetting.find_or_create(@project) end def get_parent_candidate(revision) changeset = @repository.find_changeset_by_name(revision) - changeset.issues.each {|issue| + changeset.issues.each { |issue| return Issue.find(issue.parent_issue_id) if issue.parent_issue_id } nil diff --git a/app/controllers/code_review_settings_controller.rb b/app/controllers/code_review_settings_controller.rb index 52b41e6..93aae06 100644 --- a/app/controllers/code_review_settings_controller.rb +++ b/app/controllers/code_review_settings_controller.rb @@ -33,14 +33,13 @@ def update @setting.auto_assign_settings = params[:auto_assign].to_yaml @setting.save! - + flash[:notice] = l(:notice_successful_update) rescue ActiveRecord::StaleObjectError # Optimistic locking exception flash[:error] = l(:notice_locking_conflict) end redirect_to :controller => 'projects', :action => "settings", :id => @project, :tab => 'code_review' - end def add_filter @@ -50,7 +49,7 @@ def add_filter filters = [] unless filters filters << params[:auto_assign_add_filter] - @auto_assign.filters = filters.collect{|f| + @auto_assign.filters = filters.collect { |f| filter = AssignmentFilter.new filter.attributes = f filter @@ -66,7 +65,7 @@ def edit_filter filters = params[:auto_assign][:filters].values unless params[:auto_assign][:filters].blank? filters = [] unless filters i = 0 - @auto_assign.filters = filters.collect{|f| + @auto_assign.filters = filters.collect { |f| filter = AssignmentFilter.new if i == num filter.attributes = params[:auto_assign_edit_filter][num.to_s] @@ -97,16 +96,17 @@ def sort filters[num][:order] = 999999999 end - @auto_assign.filters = filters.collect{|f| + @auto_assign.filters = filters.collect { |f| filter = AssignmentFilter.new filter.attributes = f filter } - render :partial => "code_review_settings/filters" end + private + def find_project # @project variable must be set before calling the authorize filter @project = Project.find(params[:id]) @@ -115,5 +115,4 @@ def find_project def find_user @user = User.current end - end diff --git a/app/helpers/code_review_helper.rb b/app/helpers/code_review_helper.rb index 2086c33..5b64c14 100644 --- a/app/helpers/code_review_helper.rb +++ b/app/helpers/code_review_helper.rb @@ -16,19 +16,20 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. module CodeReviewHelper unloadable + def show_assignments(assignments, project, options = {}) html = "#{l(:review_assignments)}:" assignments.each do |assignment| issue = assignment.issue html << link_to("##{issue.id} ", {:controller => 'issues', :action => 'show', :id => issue.id}, - :class => issue.css_classes, :title => "#{issue}(#{issue.status})") + :class => issue.css_classes, :title => "#{issue}(#{issue.status})") end if assignments link = link_to(l(:button_add), {:controller => 'code_review', - :action => 'assign', :id=>project, :action_type => options[:action_type], - :rev => options[:rev], :rev_to => options[:rev_to], :path => options[:path], - :change_id => options[:change_id], :attachment_id => options[:attachment_id], - :changeset_id => options[:changeset_id]}, :class => 'icon icon-add') + :action => 'assign', :id => project, :action_type => options[:action_type], + :rev => options[:rev], :rev_to => options[:rev_to], :path => options[:path], + :change_id => options[:change_id], :attachment_id => options[:attachment_id], + :changeset_id => options[:changeset_id]}, :class => 'icon icon-add') html << link if link diff --git a/app/models/code_review.rb b/app/models/code_review.rb index 4cc4dbf..bf81b44 100644 --- a/app/models/code_review.rb +++ b/app/models/code_review.rb @@ -23,7 +23,7 @@ class CodeReview < ActiveRecord::Base belongs_to :updated_by, :class_name => 'User', :foreign_key => 'updated_by_id' belongs_to :attachment - validates_presence_of :project_id, :user_id, :updated_by_id, :issue, + validates_presence_of :project_id, :user_id, :updated_by_id, :issue, :subject, :action_type, :line STATUS_OPEN = 0 @@ -47,7 +47,7 @@ def reopen issue.status = IssueStatus.find(1) #self.root.status = STATUS_OPEN end - + def committer return changeset.author if changeset end @@ -72,7 +72,7 @@ def path @path = change.path else @path = change.path[rootpath.length, change.path.length - rootpath.length] - end + end rescue => ex return ex.to_s end @@ -90,13 +90,13 @@ def changeset def repository @repository ||= changeset.repository if changeset end - + def repository_identifier return nil unless repository @repository_identifier ||= repository.identifier_param end - def comment=(str) + def comment=(str) issue.description = str if issue end @@ -111,7 +111,6 @@ def before_save def validate unless issue.validate false - end end @@ -139,7 +138,7 @@ def subject issue.subject end - def parent_id= (p) + def parent_id=(p) issue.parent_issue_id = p end @@ -162,7 +161,7 @@ def open_assignment_issues(user_id) assignments = assignments + changeset.code_review_assignments if changeset assignments = assignments + attachment.code_review_assignments if attachment - assignments.each {|assignment| + assignments.each { |assignment| unless assignment.is_closed? issues << assignment.issue if user_id == assignment.issue.assigned_to_id end diff --git a/app/models/code_review_assignment.rb b/app/models/code_review_assignment.rb index 75c45e1..768030b 100644 --- a/app/models/code_review_assignment.rb +++ b/app/models/code_review_assignment.rb @@ -35,13 +35,13 @@ def revision return rev if rev changeset.revision if changeset end - + def repository @repository ||= change.changeset.repository if change @repository ||= changeset.repository if changeset @repository end - + def repository_identifier return nil unless repository @repository_identifier ||= repository.identifier_param if repository.respond_to?("identifier_param") @@ -55,25 +55,24 @@ def self.create_with_changeset(changeset) issue = Issue.new issue.subject = auto_assign.subject issue.subject = l(:code_review_requrest) if issue.subject.blank? - issue.subject = issue.subject.sub("$REV" , changeset.revision) - issue.subject = issue.subject.sub("$COMMENTS" , changeset.comments.split(//u)[0..60].join) unless changeset.comments.blank? + issue.subject = issue.subject.sub("$REV", changeset.revision) + issue.subject = issue.subject.sub("$COMMENTS", changeset.comments.split(//u)[0..60].join) unless changeset.comments.blank? issue.tracker_id = setting.assignment_tracker_id issue.project = project issue.author = User.find(auto_assign.author_id) issue.assigned_to_id = auto_assign.select_assign_to(project, changeset.user) issue.description = auto_assign.description - issue.description = issue.description.sub("$REV" , changeset.revision) unless issue.description.blank? - issue.description = issue.description.sub("$COMMENTS" , changeset.comments) unless changeset.comments.blank? + issue.description = issue.description.sub("$REV", changeset.revision) unless issue.description.blank? + issue.description = issue.description.sub("$COMMENTS", changeset.comments) unless changeset.comments.blank? issue.save! - + assignment.issue_id = issue.id assignment.changeset_id = changeset.id assignment.save! assignment end - def diff_all path.blank? end diff --git a/app/models/code_review_project_setting.rb b/app/models/code_review_project_setting.rb index ffa6b81..c418965 100644 --- a/app/models/code_review_project_setting.rb +++ b/app/models/code_review_project_setting.rb @@ -55,18 +55,19 @@ def auto_assign_settings def auto_assign_settings=(settings) @auto_assign_settings = settings end - + def issue_relation_type return IssueRelation::TYPE_RELATES if auto_relation == CodeReviewProjectSetting::AUTORELATION_TYPE_RELATES return IssueRelation::TYPE_BLOCKS if auto_relation == CodeReviewProjectSetting::AUTORELATION_TYPE_BLOCKS return nil end - + def auto_relation? issue_relation_type != nil end private + def set_assignment_settings if auto_assign_settings self.auto_assign = auto_assign_settings.to_s diff --git a/app/models/review_mailer.rb b/app/models/review_mailer.rb index 3975f9b..6c0851a 100644 --- a/app/models/review_mailer.rb +++ b/app/models/review_mailer.rb @@ -16,12 +16,11 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. class ReviewMailer < Mailer - def review_add(project, review) redmine_headers 'Project' => review.project.identifier, 'Review-Id' => review.id, 'Review-Author' => review.user.login - + recipients get_mail_addresses(review) subject "[#{review.project.name} - #{l(:label_review_new)} - #{l(:label_review)}##{review.id}] " @@ -31,18 +30,18 @@ def review_add(project, review) return if (l(:this_is_checking_for_before_rails_2_2_2) == 'this_is_checking_for_before_rails_2_2_2') # 何故かrails 2.2 以後は以下の処理が必要 - + content_type "multipart/alternative" part "text/plain" do |p| - p.body = render_message("review_add.text.plain.erb", :body => body, :review=>review, :review_url => review_url) + p.body = render_message("review_add.text.plain.erb", :body => body, :review => review, :review_url => review_url) end part "text/html" do |p| - p.body = render_message("review_add.text.html.erb", :body => body, :review=>review, :review_url => review_url) + p.body = render_message("review_add.text.html.erb", :body => body, :review => review, :review_url => review_url) end end - + def review_reply(project, review) redmine_headers 'Project' => review.project.identifier, 'Review-Id' => review.id, @@ -56,17 +55,16 @@ def review_reply(project, review) return if (l(:this_is_checking_for_before_rails_2_2_2) == 'this_is_checking_for_before_rails_2_2_2') # 何故かrails 2.2 以後は以下の処理が必要 - + content_type "multipart/alternative" part "text/plain" do |p| - p.body = render_message("review_reply.text.plain.erb", :body => body, :review=>review, :review_url => review_url) + p.body = render_message("review_reply.text.plain.erb", :body => body, :review => review, :review_url => review_url) end part "text/html" do |p| - p.body = render_message("review_reply.text.html.erb", :body => body, :review=>review, :review_url => review_url) + p.body = render_message("review_reply.text.html.erb", :body => body, :review => review, :review_url => review_url) end - end def review_status_changed(project, review) @@ -86,21 +84,21 @@ def review_status_changed(project, review) return if (l(:this_is_checking_for_before_rails_2_2_2) == 'this_is_checking_for_before_rails_2_2_2') # 何故かrails 2.2 以後は以下の処理が必要 - + content_type "multipart/alternative" part "text/plain" do |p| - p.body = render_message("review_status_changed.text.plain.erb", :body => body, :review=>review, :review_url => review_url) + p.body = render_message("review_status_changed.text.plain.erb", :body => body, :review => review, :review_url => review_url) end part "text/html" do |p| - p.body = render_message("review_status_changed.text.html.erb", :body => body, :review=>review, :review_url => review_url) + p.body = render_message("review_status_changed.text.html.erb", :body => body, :review => review, :review_url => review_url) end end def get_mail_addresses(review) mail_addresses = [] - review.root.users_for_notification.each{|u| + review.root.users_for_notification.each { |u| mail_addresses << u.mail } committer = review.change.changeset.user @@ -109,14 +107,12 @@ def get_mail_addresses(review) mail_addresses << committer.mail if setting and !setting.mail_notification_none? end - review.project.members.each{|member| + review.project.members.each { |member| user = member.user setting = CodeReviewUserSetting.find_or_create(user.id) next unless setting mail_addresses << user.mail if setting.mail_notification_all? } mail_addresses.compact.uniq - end - end diff --git a/config/routes.rb b/config/routes.rb index af39e4e..f4bb5be 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -19,4 +19,4 @@ #map.connect 'projects/:id/code_review/:action', :controller => 'code_review' match 'projects/:id/code_review/:action', :controller => 'code_review', :via => [:get, :post] match 'projects/:id/code_review_settings/:action', :controller => 'code_review_settings', :via => [:get, :post, :put, :patch] -end \ No newline at end of file +end diff --git a/db/migrate/0001_create_code_reviews.rb b/db/migrate/0001_create_code_reviews.rb index 5bbf794..a01f11c 100644 --- a/db/migrate/0001_create_code_reviews.rb +++ b/db/migrate/0001_create_code_reviews.rb @@ -18,7 +18,6 @@ class CreateCodeReviews < ActiveRecord::Migration[4.2] def self.up create_table :code_reviews do |t| - t.column :project_id, :integer t.column :parent_id, :integer @@ -36,7 +35,6 @@ def self.up t.column :status, :integer t.column :line, :integer - end end diff --git a/db/migrate/0002_add_updated_by.rb b/db/migrate/0002_add_updated_by.rb index 34630e3..fec07e5 100644 --- a/db/migrate/0002_add_updated_by.rb +++ b/db/migrate/0002_add_updated_by.rb @@ -16,7 +16,6 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. class AddUpdatedBy < ActiveRecord::Migration[4.2] - def self.up add_column(:code_reviews, "updated_by_id", :integer) end diff --git a/db/migrate/0003_add_lock_version.rb b/db/migrate/0003_add_lock_version.rb index 3ec794d..51a777d 100644 --- a/db/migrate/0003_add_lock_version.rb +++ b/db/migrate/0003_add_lock_version.rb @@ -16,9 +16,8 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. class AddLockVersion < ActiveRecord::Migration[4.2] - def self.up - add_column(:code_reviews, "lock_version", :integer, :default=>0, :null => false) + add_column(:code_reviews, "lock_version", :integer, :default => 0, :null => false) end def self.down diff --git a/db/migrate/0004_add_status_changed.rb b/db/migrate/0004_add_status_changed.rb index 793c7ee..de0d9df 100644 --- a/db/migrate/0004_add_status_changed.rb +++ b/db/migrate/0004_add_status_changed.rb @@ -16,7 +16,6 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. class AddStatusChanged < ActiveRecord::Migration[4.2] - def self.up add_column(:code_reviews, "status_changed_from", :integer) add_column(:code_reviews, "status_changed_to", :integer) diff --git a/db/migrate/0005_create_code_review_user_settings.rb b/db/migrate/0005_create_code_review_user_settings.rb index 645573d..43fd11f 100644 --- a/db/migrate/0005_create_code_review_user_settings.rb +++ b/db/migrate/0005_create_code_review_user_settings.rb @@ -17,15 +17,13 @@ class CreateCodeReviewUserSettings < ActiveRecord::Migration[4.2] def self.up create_table :code_review_user_settings do |t| + t.column :user_id, :integer, :default => 0, :null => false - t.column :user_id, :integer, :default=>0, :null => false - - t.column :mail_notification, :integer, :default=>0, :null => false + t.column :mail_notification, :integer, :default => 0, :null => false t.column :created_at, :timestamp t.column :updated_at, :timestamp - end end diff --git a/db/migrate/0006_link_to_issue.rb b/db/migrate/0006_link_to_issue.rb index 8ac80ec..4193136 100644 --- a/db/migrate/0006_link_to_issue.rb +++ b/db/migrate/0006_link_to_issue.rb @@ -16,7 +16,6 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. class LinkToIssue < ActiveRecord::Migration[4.2] - def self.up add_column(:code_reviews, "issue_id", :integer) rename_column(:code_reviews, "status", "old_status") diff --git a/db/migrate/0007_rename_user.rb b/db/migrate/0007_rename_user.rb index debbc98..19439b9 100644 --- a/db/migrate/0007_rename_user.rb +++ b/db/migrate/0007_rename_user.rb @@ -16,12 +16,11 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. class RenameUser < ActiveRecord::Migration[4.2] - def self.up rename_column(:code_reviews, "user_id", "old_user_id") end def self.down - rename_column(:code_reviews, "old_user_id", "user_id") + rename_column(:code_reviews, "old_user_id", "user_id") end end diff --git a/db/migrate/0008_create_code_review_project_settings.rb b/db/migrate/0008_create_code_review_project_settings.rb index a4aa134..e0bcc9d 100644 --- a/db/migrate/0008_create_code_review_project_settings.rb +++ b/db/migrate/0008_create_code_review_project_settings.rb @@ -17,7 +17,6 @@ class CreateCodeReviewProjectSettings < ActiveRecord::Migration[4.2] def self.up create_table :code_review_project_settings do |t| - t.column :project_id, :integer t.column :tracker_id, :integer @@ -27,7 +26,6 @@ def self.up t.column :updated_at, :timestamp t.column :updated_by, :integer - end end diff --git a/db/migrate/0009_add_hide_tab.rb b/db/migrate/0009_add_hide_tab.rb index 832ad97..319862e 100644 --- a/db/migrate/0009_add_hide_tab.rb +++ b/db/migrate/0009_add_hide_tab.rb @@ -16,7 +16,6 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. class AddHideTab < ActiveRecord::Migration[4.2] - def self.up add_column(:code_review_project_settings, "hide_code_review_tab", :boolean, :default => false) end diff --git a/db/migrate/0010_add_action_type.rb b/db/migrate/0010_add_action_type.rb index 2debb31..49eaa51 100644 --- a/db/migrate/0010_add_action_type.rb +++ b/db/migrate/0010_add_action_type.rb @@ -16,7 +16,6 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. class AddActionType < ActiveRecord::Migration[4.2] - def self.up add_column(:code_reviews, "action_type", :string) add_column(:code_reviews, "file_path", :string) diff --git a/db/migrate/0011_add_auto_relation.rb b/db/migrate/0011_add_auto_relation.rb index d36e33e..8a4e2cd 100644 --- a/db/migrate/0011_add_auto_relation.rb +++ b/db/migrate/0011_add_auto_relation.rb @@ -16,12 +16,11 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. class AddAutoRelation < ActiveRecord::Migration[4.2] - def self.up add_column(:code_review_project_settings, "auto_relation", :integer, :default => 1) end def self.down - remove_column(:code_review_project_settings, "auto_relation") + remove_column(:code_review_project_settings, "auto_relation") end end diff --git a/db/migrate/0012_add_attachment_id.rb b/db/migrate/0012_add_attachment_id.rb index c9c2b18..7acfbdf 100644 --- a/db/migrate/0012_add_attachment_id.rb +++ b/db/migrate/0012_add_attachment_id.rb @@ -16,7 +16,6 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. class AddAttachmentId < ActiveRecord::Migration[4.2] - def self.up add_column(:code_reviews, "attachment_id", :integer) end diff --git a/db/migrate/0013_add_file_count.rb b/db/migrate/0013_add_file_count.rb index 86a685b..2cfee35 100644 --- a/db/migrate/0013_add_file_count.rb +++ b/db/migrate/0013_add_file_count.rb @@ -16,7 +16,6 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. class AddFileCount < ActiveRecord::Migration[4.2] - def self.up add_column(:code_reviews, "file_count", :integer, :default => 0, :null => false) end diff --git a/db/migrate/0014_create_code_review_assignments.rb b/db/migrate/0014_create_code_review_assignments.rb index 491294a..b2f483f 100644 --- a/db/migrate/0014_create_code_review_assignments.rb +++ b/db/migrate/0014_create_code_review_assignments.rb @@ -18,7 +18,6 @@ class CreateCodeReviewAssignments < ActiveRecord::Migration[4.2] def self.up create_table :code_review_assignments do |t| - t.column :issue_id, :int t.column :change_id, :int @@ -32,7 +31,6 @@ def self.up t.column :rev_to, :string t.column :action_type, :string - end end diff --git a/db/migrate/0015_add_assignment_tracker.rb b/db/migrate/0015_add_assignment_tracker.rb index bf6cacf..7c8d34b 100644 --- a/db/migrate/0015_add_assignment_tracker.rb +++ b/db/migrate/0015_add_assignment_tracker.rb @@ -16,7 +16,6 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. class AddAssignmentTracker < ActiveRecord::Migration[4.2] - def self.up add_column(:code_review_project_settings, "assignment_tracker_id", :integer) end diff --git a/db/migrate/0016_add_changeset_id.rb b/db/migrate/0016_add_changeset_id.rb index 29a6160..d916905 100644 --- a/db/migrate/0016_add_changeset_id.rb +++ b/db/migrate/0016_add_changeset_id.rb @@ -16,7 +16,6 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. class AddChangesetId < ActiveRecord::Migration[4.2] - def self.up add_column(:code_review_assignments, "changeset_id", :integer) end diff --git a/db/migrate/0017_add_auto_assign.rb b/db/migrate/0017_add_auto_assign.rb index 9a17953..0135a3b 100644 --- a/db/migrate/0017_add_auto_assign.rb +++ b/db/migrate/0017_add_auto_assign.rb @@ -16,7 +16,6 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. class AddAutoAssign < ActiveRecord::Migration[4.2] - def self.up add_column(:code_review_project_settings, "auto_assign", :text) end diff --git a/db/migrate/0018_add_lock_version_to_project_settings.rb b/db/migrate/0018_add_lock_version_to_project_settings.rb index 9f766c2..47d88b8 100644 --- a/db/migrate/0018_add_lock_version_to_project_settings.rb +++ b/db/migrate/0018_add_lock_version_to_project_settings.rb @@ -16,7 +16,6 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. class AddLockVersionToProjectSettings < ActiveRecord::Migration[4.2] - def self.up add_column(:code_review_project_settings, "lock_version", :integer, :null => false, :default => 0) end diff --git a/db/migrate/0019_delete_old_fields.rb b/db/migrate/0019_delete_old_fields.rb index d67c01a..c5cca80 100644 --- a/db/migrate/0019_delete_old_fields.rb +++ b/db/migrate/0019_delete_old_fields.rb @@ -16,7 +16,7 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. class DeleteOldFields < ActiveRecord::Migration[4.2] - OLD_FIELDS=["old_parent_id", "old_user_id", "old_comment", "old_status"] + OLD_FIELDS = ["old_parent_id", "old_user_id", "old_comment", "old_status"] def self.up remove_column(:code_reviews, "old_parent_id") remove_column(:code_reviews, "old_user_id") diff --git a/db/migrate/0020_add_tracker_to_review_dialog.rb b/db/migrate/0020_add_tracker_to_review_dialog.rb index 6db6d63..05d358c 100644 --- a/db/migrate/0020_add_tracker_to_review_dialog.rb +++ b/db/migrate/0020_add_tracker_to_review_dialog.rb @@ -15,9 +15,7 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - class AddTrackerToReviewDialog < ActiveRecord::Migration[4.2] - def self.up add_column(:code_review_project_settings, "tracker_in_review_dialog", :boolean, :default => false) end @@ -25,4 +23,4 @@ def self.up def self.down remove_column(:code_review_project_settings, "tracker_in_review_dialog") end -end \ No newline at end of file +end diff --git a/db/migrate/0021_add_diff_all.rb b/db/migrate/0021_add_diff_all.rb index 56c5506..fd8ddda 100644 --- a/db/migrate/0021_add_diff_all.rb +++ b/db/migrate/0021_add_diff_all.rb @@ -23,4 +23,4 @@ def self.up def self.down remove_column(:code_reviews, "diff_all") end -end \ No newline at end of file +end diff --git a/init.rb b/init.rb index a94282c..60752d9 100644 --- a/init.rb +++ b/init.rb @@ -44,7 +44,6 @@ unless Attachment.included_modules.include? CodeReviewAttachmentPatch Attachment.send(:include, CodeReviewAttachmentPatch) end - end Redmine::Plugin.register :redmine_code_review do @@ -63,15 +62,13 @@ permission :delete_code_review, {:code_review => [:destroy]}, :require => :member permission :assign_code_review, {:code_review => [:assign]}, :require => :member permission :code_review_setting, {:code_review_settings => [:show, :update, :add_filter, :edit_filter, :sort]}, :require => :member - end - menu :project_menu, :code_review, { :controller => 'code_review', :action => 'index' }, :caption => :code_reviews, - :if => Proc.new{|project| - setting = CodeReviewProjectSetting.find_or_create(project) - project.repository != nil and setting and !setting.hide_code_review_tab - }, :after => :repository - + menu :project_menu, :code_review, {:controller => 'code_review', :action => 'index'}, :caption => :code_reviews, + :if => Proc.new { |project| + setting = CodeReviewProjectSetting.find_or_create(project) + project.repository != nil and setting and !setting.hide_code_review_tab + }, :after => :repository Redmine::WikiFormatting::Macros.register do desc "This is my macro link to code review" @@ -82,8 +79,6 @@ review = CodeReview.find(review_id) return nil unless review link_to(l(:label_review) + '#' + review.id.to_s, :controller => 'code_review', :action => 'show', :id => review.project, :review_id => review.id) - end end - end diff --git a/lib/code_review_application_hooks.rb b/lib/code_review_application_hooks.rb index 5e7b0a4..af9c87f 100644 --- a/lib/code_review_application_hooks.rb +++ b/lib/code_review_application_hooks.rb @@ -16,6 +16,7 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. require 'redmine/utils' + class CodeReviewApplicationHooks < Redmine::Hook::ViewListener render_on :view_layouts_base_html_head, :partial => 'code_review/html_header' render_on :view_layouts_base_body_bottom, :partial => 'code_review/body_bottom' diff --git a/lib/code_review_attachment_patch.rb b/lib/code_review_attachment_patch.rb index 1b1ccb1..41c2047 100644 --- a/lib/code_review_attachment_patch.rb +++ b/lib/code_review_attachment_patch.rb @@ -25,14 +25,9 @@ def self.included(base) # :nodoc: unloadable # Send unloadable so it will not be unloaded in development has_many :code_reviews has_many :code_review_assignments - end - end end module AttachmentInstanceMethodsCodeReview - end - - diff --git a/lib/code_review_auto_assign_settings.rb b/lib/code_review_auto_assign_settings.rb index 5dd5b97..2c58c2a 100644 --- a/lib/code_review_auto_assign_settings.rb +++ b/lib/code_review_auto_assign_settings.rb @@ -21,7 +21,7 @@ def initialize(yml_string = nil) yml_string = {:enabled => false}.to_yaml if yml_string.blank? load_yml(yml_string) end - + def self.load(yml_string) AutoAssignSettings.new(yml_string) end @@ -49,7 +49,7 @@ def assignable_list=(list) def assignable_list return nil unless yml[:assignable_list] - yml[:assignable_list].collect { |id| id.to_i } + yml[:assignable_list].collect { |id| id.to_i } end def assignable?(user) @@ -86,7 +86,6 @@ def filter_enabled? yml[:filter_enabled] == true or yml[:filter_enabled] == 'true' end - def to_s return YAML.dump(yml) nil @@ -94,7 +93,7 @@ def to_s def filters=(list) unless list - return yml[:filters] = nil + return yml[:filters] = nil end yml[:filters] = list.collect do |filter| filter.attributes @@ -105,10 +104,10 @@ def filters return [] unless yml[:filters] list = yml[:filters].collect do |hash| filter = AssignmentFilter.new - filter.attributes=(hash) + filter.attributes = (hash) filter end - list.sort {|a, b| a.order <=> b.order} + list.sort { |a, b| a.order <=> b.order } end def add_filter(filter) @@ -126,8 +125,8 @@ def accept_for_default def match_with_changeset?(changeset) return true unless filter_enabled? - changeset.filechanges.each{|change| - return if match_with_change?(change) + changeset.filechanges.each { |change| + return if match_with_change?(change) } return false end @@ -143,7 +142,7 @@ def match_with_change?(change) def attributes yml end - + private def yml @@ -161,7 +160,7 @@ def load_yml(yml_string) def select_assign_to_with_list(project, list, commiter_id = nil) return nil unless list return nil if list.empty? - list.collect!{|item| item.to_i} + list.collect! { |item| item.to_i } list.delete(commiter_id) return nil if list.empty? assign_to = list.at(rand(list.size)) diff --git a/lib/code_review_change_patch.rb b/lib/code_review_change_patch.rb index 95f9f9e..0e2ad96 100644 --- a/lib/code_review_change_patch.rb +++ b/lib/code_review_change_patch.rb @@ -26,9 +26,7 @@ def self.included(base) # :nodoc: has_many :code_reviews, :dependent => :destroy has_many :code_review_assignments, :dependent => :destroy after_save :review_auto_assign - end - end end @@ -37,7 +35,7 @@ module ChangeInstanceMethodsCodeReview # for review_issues # def review_count - code_reviews.select{|o| + code_reviews.select { |o| o.issue_id != nil }.length end @@ -55,7 +53,7 @@ def open_review_count def closed_review_count closed_reviews.length end - + def closed_reviews @closed_reviews ||= code_reviews.select do |o| o.issue_id != nil and o.is_closed? @@ -94,4 +92,3 @@ def review_auto_assign CodeReviewAssignment.create_with_changeset(changeset) end end - diff --git a/lib/code_review_changeset_patch.rb b/lib/code_review_changeset_patch.rb index e372f7e..7300ece 100644 --- a/lib/code_review_changeset_patch.rb +++ b/lib/code_review_changeset_patch.rb @@ -19,12 +19,10 @@ module CodeReviewChangesetPatch def self.included(base) # :nodoc: - base.class_eval do unloadable # Send unloadable so it will not be unloaded in development has_many :code_review_assignments, :dependent => :destroy end - end end @@ -35,7 +33,7 @@ module ChangesetInstanceMethodsCodeReview def review_count return @review_count if @review_count @review_count = 0 - filechanges.each{|change| + filechanges.each { |change| @review_count += change.review_count } return @review_count @@ -44,7 +42,7 @@ def review_count def open_review_count return @open_review_count if @open_review_count @open_review_count = 0 - filechanges.each{|change| + filechanges.each { |change| @open_review_count += change.open_review_count } return @open_review_count @@ -61,11 +59,11 @@ def open_reviews def review_issues return @review_issues if @review_issues - filechanges.each{|change| + filechanges.each { |change| unless @review_issues - @review_issues = change.code_reviews.collect{|issue| issue} + @review_issues = change.code_reviews.collect { |issue| issue } else - @review_issues = @review_issues + change.code_reviews.collect{|issue| issue} + @review_issues = @review_issues + change.code_reviews.collect { |issue| issue } end @review_issues } @@ -89,20 +87,20 @@ def completed_review_pourcent elsif open_review_count == 0 100 else - @completed_review_pourcent ||= (closed_review_count * 100 + open_reviews.collect{|o| + @completed_review_pourcent ||= (closed_review_count * 100 + open_reviews.collect { |o| o.issue.done_ratio - }.inject(:+))/review_count + }.inject(:+)) / review_count end end # # for assignment issues # - + def assignment_count #return @assignment_count if @assignment_count @assignment_count = code_review_assignments.length - filechanges.each{|change| + filechanges.each { |change| @assignment_count += change.assignment_count } return @assignment_count @@ -110,10 +108,10 @@ def assignment_count def open_assignment_count return @open_assignment_count if @open_assignment_count - @open_assignment_count = code_review_assignments.select {|assignment| + @open_assignment_count = code_review_assignments.select { |assignment| !assignment.is_closed? }.length - filechanges.each{|change| + filechanges.each { |change| @open_assignment_count += change.open_assignment_count } return @open_assignment_count @@ -122,20 +120,19 @@ def open_assignment_count def assignment_issues return @assignment_issues if @assignment_issues @assignment_issues = code_review_assignments - filechanges.each{|change| - @assignment_issues = @assignment_issues + change.code_review_assignments.collect{|issue| issue} + filechanges.each { |change| + @assignment_issues = @assignment_issues + change.code_review_assignments.collect { |issue| issue } } @assignment_issues - end def open_assignments return @open_assignments if @open_assignments - @open_assignments = code_review_assignments.select {|assignment| + @open_assignments = code_review_assignments.select { |assignment| !assignment.is_closed? } - filechanges.each{|change| - @open_assignments = @open_assignments + change.code_review_assignments.select {|assignment| + filechanges.each { |change| + @open_assignments = @open_assignments + change.code_review_assignments.select { |assignment| !assignment.is_closed? } } @@ -160,10 +157,9 @@ def completed_assignment_pourcent 100 else opens = open_assignments - @completed_assignment_pourcent ||= (closed_assignment_count * 100 + open_assignments.collect{|o| + @completed_assignment_pourcent ||= (closed_assignment_count * 100 + open_assignments.collect { |o| o.issue.done_ratio - }.sum)/assignment_count - + }.sum) / assignment_count end end @@ -185,4 +181,3 @@ def scan_comment_for_issue_ids end Changeset.prepend(ChangesetInstanceMethodsCodeReview) - diff --git a/lib/code_review_issue_hooks.rb b/lib/code_review_issue_hooks.rb index f1326dd..aefd423 100644 --- a/lib/code_review_issue_hooks.rb +++ b/lib/code_review_issue_hooks.rb @@ -18,7 +18,8 @@ class CodeReviewIssueHooks < Redmine::Hook::ViewListener include RepositoriesHelper render_on :view_issues_show_details_bottom, :partial => 'code_review/issues_show_details_bottom' - def view_issues_show_details_bottom_org(context = { }) + + def view_issues_show_details_bottom_org(context = {}) project = context[:project] return '' unless project unless User.current.allowed_to?({:controller => 'code_review', :action => 'show'}, project) @@ -36,7 +37,7 @@ def view_issues_show_details_bottom_org(context = { }) return o end - def view_issues_form_details_bottom(context = { }) + def view_issues_form_details_bottom(context = {}) project = context[:project] request = context[:request] parameters = request.parameters @@ -58,11 +59,10 @@ def view_issues_form_details_bottom(context = { }) o << "\n" o << hidden_field_tag("code[attachment_id]", code[:attachment_id].to_i) unless code[:attachment_id].blank? - return o end - - def controller_issues_new_after_save(context = { }) + + def controller_issues_new_after_save(context = {}) if context[:request] && context[:project] && context[:issue] project = context[:project] request = context[:request] @@ -86,12 +86,13 @@ def controller_issues_new_after_save(context = { }) end private + def create_review_info(project, review) o = '' o << "#{l(:code_review)}:" o << '' o << link_to("#{review.repository_identifier + ':' if review.repository_identifier}#{review.path}#{'@' + review.revision if review.revision}:line #{review.line}", - :controller => 'code_review', :action => 'show', :id => project, :review_id => review.id, :repository_id => review.repository_identifier) + :controller => 'code_review', :action => 'show', :id => project, :review_id => review.id, :repository_id => review.repository_identifier) o << '' o << '' return o @@ -104,7 +105,7 @@ def create_assignment_info(project, assignment) o << '' if assignment.path o << link_to("#{repository_id + ':' if repository_id}#{assignment.path}#{'@' + assignment.revision if assignment.revision}", - :controller => 'code_review', :action => 'show', :id => project, :assignment_id => assignment.id, :repository_id => repository_id) + :controller => 'code_review', :action => 'show', :id => project, :assignment_id => assignment.id, :repository_id => repository_id) elsif assignment.revision repo = project unless repository_id repo ||= assignment.repository diff --git a/lib/code_review_issue_patch.rb b/lib/code_review_issue_patch.rb index e05ae8b..3a88259 100644 --- a/lib/code_review_issue_patch.rb +++ b/lib/code_review_issue_patch.rb @@ -25,14 +25,9 @@ def self.included(base) # :nodoc: unloadable # Send unloadable so it will not be unloaded in development has_one :code_review, :dependent => :destroy has_one :code_review_assignment, :dependent => :destroy - end - end end module IssueInstanceMethodsCodeReview - end - - diff --git a/lib/code_review_projects_helper_patch.rb b/lib/code_review_projects_helper_patch.rb index c8f6f33..06fa67c 100644 --- a/lib/code_review_projects_helper_patch.rb +++ b/lib/code_review_projects_helper_patch.rb @@ -29,5 +29,3 @@ def project_settings_tabs end ProjectsHelper.prepend(ProjectsHelperMethodsCodeReview) - - diff --git a/test/code_review_object_daddy_helpers.rb b/test/code_review_object_daddy_helpers.rb index 13c7ed0..9d17551 100644 --- a/test/code_review_object_daddy_helpers.rb +++ b/test/code_review_object_daddy_helpers.rb @@ -16,11 +16,11 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. module CodeReviewObjectDaddyHelpers - def CodeReview.generate_for_project!(project, attributes={}) - attributes[:comment] = 'test comment' unless attributes[:comment] - attributes[:issue] = Issue.generate_for_project!({:project => project, :description => attributes[:comment], :subject => 'test'}) unless attributes[:issue] - attributes[:project] = project - review = CodeReview.generate!(attributes) - review - end + def CodeReview.generate_for_project!(project, attributes = {}) + attributes[:comment] = 'test comment' unless attributes[:comment] + attributes[:issue] = Issue.generate_for_project!({:project => project, :description => attributes[:comment], :subject => 'test'}) unless attributes[:issue] + attributes[:project] = project + review = CodeReview.generate!(attributes) + review + end end diff --git a/test/exemplars/code_review_exemplar.rb b/test/exemplars/code_review_exemplar.rb index 565422f..0543491 100644 --- a/test/exemplars/code_review_exemplar.rb +++ b/test/exemplars/code_review_exemplar.rb @@ -23,11 +23,9 @@ class CodeReview < ActiveRecord::Base generator_for :action_type => 'diff' generator_for :line => 30 - def self.next_subject @last_subject ||= 'Code Review 0' @last_subject.succ! @last_subject end - end diff --git a/test/functional/attachments_controller_test.rb b/test/functional/attachments_controller_test.rb index b62ace5..36e9eac 100644 --- a/test/functional/attachments_controller_test.rb +++ b/test/functional/attachments_controller_test.rb @@ -21,14 +21,13 @@ # Re-raise errors caught by the controller. class AttachmentsController; def rescue_action(e) raise e end; end - class AttachmentsControllerTest < ActionController::TestCase fixtures :users, :projects, :roles, :members, :member_roles, :enabled_modules, :issues, :trackers, :attachments, :versions, :wiki_pages, :wikis, :documents def setup @controller = AttachmentsController.new - @request = ActionController::TestRequest.create(self.class.controller_class) + @request = ActionController::TestRequest.create(self.class.controller_class) #@response = ActionController::TestResponse.new Attachment.storage_path = "#{Rails.root}/test/fixtures/files" @@ -38,16 +37,14 @@ def setup project.save! } - roles = Role.all - roles.each {|role| + roles.each { |role| role.permissions << :view_code_review role.save } User.current = nil end - def test_show_diff @request.session[:user_id] = 1 attachment = FactoryGirl.create(:attachment, filename: "test.diff") @@ -65,5 +62,4 @@ def test_show_text_file assert_template 'file' #assert_equal 'text/html', @response.content_type end - end diff --git a/test/functional/code_review_controller_test.rb b/test/functional/code_review_controller_test.rb index d0c7306..6239dfd 100644 --- a/test/functional/code_review_controller_test.rb +++ b/test/functional/code_review_controller_test.rb @@ -22,9 +22,10 @@ class CodeReviewControllerTest < ActionController::TestCase :enumerations, :issue_categories, :trackers, :projects, :projects_trackers, :code_review_project_settings, :attachments, :code_review_assignments, :code_review_user_settings + def setup @controller = CodeReviewController.new - @request = ActionController::TestRequest.create(self.class.controller_class) + @request = ActionController::TestRequest.create(self.class.controller_class) @request.env["HTTP_REFERER"] = '/' enabled_module = EnabledModule.new enabled_module.project_id = 1 @@ -37,7 +38,7 @@ def setup User.current = nil roles = Role.all - roles.each {|role| + roles.each { |role| role.permissions << :view_code_review role.save } @@ -61,7 +62,6 @@ def setup get :index, :params => {:id => 1, :show_closed => true} assert_response :success end - end context "new" do @@ -76,7 +76,7 @@ def setup @request.session[:user_id] = 1 count = CodeReview.all.length post :new, :params => {:id => 1, :review => {:line => 1, :change_id => 1, - :comment => 'aaa', :subject => 'bbb'}, :action_type => 'diff'} + :comment => 'aaa', :subject => 'bbb'}, :action_type => 'diff'} assert_response :success assert_template '_add_success' assert_equal(count + 1, CodeReview.all.length) @@ -96,22 +96,22 @@ def setup changeset.save count = CodeReview.all.length post :new, :params => {:id => 1, :review => {:line => 1, :change_id => 3, - :comment => 'aaa', :subject => 'bbb'}, :action_type => 'diff'} + :comment => 'aaa', :subject => 'bbb'}, :action_type => 'diff'} assert_response :success assert_template '_add_success' assert_equal(count + 1, CodeReview.all.length) settings = CodeReviewProjectSetting.all - settings.each{|setting| + settings.each { |setting| setting.destroy } post :new, :params => {:id => 1, :review => {:line => 1, :change_id => 1, - :comment => 'aaa', :subject => 'bbb'}, :action_type => 'diff'} + :comment => 'aaa', :subject => 'bbb'}, :action_type => 'diff'} assert_response 200 end should "save safe_attributes" do - @request.session[:user_id] = 1 + @request.session[:user_id] = 1 project = Project.find(1) change = Change.find(3) changeset = change.changeset @@ -120,7 +120,7 @@ def setup changeset.save count = CodeReview.all.length post :new, :params => {:id => 1, :review => {:line => 10, :change_id => 3, - :comment => 'aaa', :subject => 'bbb', :parent_id => 1, :status_id => 1}, :action_type => 'diff'} + :comment => 'aaa', :subject => 'bbb', :parent_id => 1, :status_id => 1}, :action_type => 'diff'} assert_response :success assert_template '_add_success' @@ -140,7 +140,7 @@ def setup attachment = FactoryGirl.create(:attachment, container: issue) count = CodeReview.all.length post :new, :params => {:id => 1, :review => {:line => 1, :comment => 'aaa', - :subject => 'bbb', :attachment_id => attachment.id}, :action_type => 'diff'} + :subject => 'bbb', :attachment_id => attachment.id}, :action_type => 'diff'} assert_response :success assert_template '_add_success' assert_equal(count + 1, CodeReview.all.length) @@ -178,7 +178,6 @@ def test_destroy get :destroy, :params => {:id => 1, :review_id => review.id} assert_response :success assert_equal(count - 1, CodeReview.all.length) - end context "reply" do @@ -187,7 +186,7 @@ def test_destroy review = CodeReview.find(9) get :reply, :params => {:id => 1, :review_id => 9, - :reply => {:comment => 'aaa'}, :issue=> {:lock_version => review.issue.lock_version}} + :reply => {:comment => 'aaa'}, :issue => {:lock_version => review.issue.lock_version}} assert_response :success assert_template '_show' assert_nil assigns(:error) @@ -198,7 +197,7 @@ def test_destroy review = CodeReview.find(9) get :reply, :params => {:id => 1, :review_id => 9, - :reply => {:comment => 'aaa'}, :issue=> {:lock_version => review.issue.lock_version + 1}} + :reply => {:comment => 'aaa'}, :issue => {:lock_version => review.issue.lock_version + 1}} assert_response :success assert_template '_show' assert_not_nil assigns(:error) @@ -208,38 +207,38 @@ def test_destroy def test_reply_lock_error @request.session[:user_id] = 1 get :reply, :params => {:id => 1, :review_id => 9, - :reply => {:comment => 'aaa'}, :issue=> {:lock_version => 1}} + :reply => {:comment => 'aaa'}, :issue => {:lock_version => 1}} assert_response :success assert_template '_show' assert assigns(:error) end -# def test_close -# @request.session[:user_id] = 1 -# review_id = 9 -# review = CodeReview.find(review_id) -# review.reopen -# review.save -# assert !review.is_closed? -# get :close, :id => 1, :review_id => review_id -# assert_response :success -# assert_template '_show' -# review = CodeReview.find(review_id) -# assert review.is_closed? -# end -# -# def test_reopen -# @request.session[:user_id] = 1 -# review = CodeReview.find(1) -# review.close -# review.save -# assert review.is_closed? -# get :reopen, :id => 1, :review_id => 1 -# assert_response :success -# assert_template '_show' -# review = CodeReview.find(1) -# assert !review.is_closed? -# end + # def test_close + # @request.session[:user_id] = 1 + # review_id = 9 + # review = CodeReview.find(review_id) + # review.reopen + # review.save + # assert !review.is_closed? + # get :close, :id => 1, :review_id => review_id + # assert_response :success + # assert_template '_show' + # review = CodeReview.find(review_id) + # assert review.is_closed? + # end + # + # def test_reopen + # @request.session[:user_id] = 1 + # review = CodeReview.find(1) + # review.close + # review.save + # assert review.is_closed? + # get :reopen, :id => 1, :review_id => 1 + # assert_response :success + # assert_template '_show' + # review = CodeReview.find(1) + # assert !review.is_closed? + # end def test_update @request.session[:user_id] = 1 @@ -247,8 +246,8 @@ def test_update review = CodeReview.find(review_id) assert_equal('Unable to print recipes', review.comment) post :update, :params => {:id => 1, :review_id => review_id, - :review => {:comment => 'bbb', :lock_version => review.lock_version}, - :issue => {:lock_version => review.issue.lock_version}} + :review => {:comment => 'bbb', :lock_version => review.lock_version}, + :issue => {:lock_version => review.issue.lock_version}} assert_response :success review = CodeReview.find(review_id) assert_equal('bbb', review.comment) @@ -261,8 +260,8 @@ def test_update_lock_error review.save! assert_equal('Unable to print recipes', review.comment) post :update, :params => {:id => 1, :review_id => review_id, - :review => {:comment => 'bbb', :lock_version => review.lock_version}, - :issue => {:lock_version => 1}} + :review => {:comment => 'bbb', :lock_version => review.lock_version}, + :issue => {:lock_version => 1}} assert_not_nil assigns(:error) assert_response :success review = CodeReview.find(review_id) diff --git a/test/functional/code_review_settings_controller_test.rb b/test/functional/code_review_settings_controller_test.rb index 32248ff..678a77b 100644 --- a/test/functional/code_review_settings_controller_test.rb +++ b/test/functional/code_review_settings_controller_test.rb @@ -21,9 +21,10 @@ class CodeReviewSettingsControllerTest < ActionController::TestCase :code_review_project_settings, :issues, :issue_statuses, :enumerations include CodeReviewAutoAssignSettings + def setup @controller = CodeReviewSettingsController.new - @request = ActionController::TestRequest.create(self.class.controller_class) + @request = ActionController::TestRequest.create(self.class.controller_class) @request.env["HTTP_REFERER"] = '/' enabled_module = EnabledModule.new enabled_module.project_id = 1 @@ -37,13 +38,12 @@ def setup User.current = nil roles = Role.all - roles.each {|role| + roles.each { |role| role.permissions << :view_code_review role.save } end - context "update" do setup do @request.session[:user_id] = 1 @@ -56,13 +56,12 @@ def setup end should "save settings" do - @request.session[:user_id] = 1 setting = CodeReviewProjectSetting.find(1) - post :update, :params => {:id => 1, :setting => {:tracker_id => 2, :assignment_tracker_id => 3, - :hide_code_review_tab => true, :auto_relation => CodeReviewProjectSetting::AUTORELATION_TYPE_BLOCKS}, - :auto_assign => {:filters => {:a => 1}}} + post :update, :params => {:id => 1, :setting => {:tracker_id => 2, :assignment_tracker_id => 3, + :hide_code_review_tab => true, :auto_relation => CodeReviewProjectSetting::AUTORELATION_TYPE_BLOCKS}, + :auto_assign => {:filters => {:a => 1}}} assert_response :redirect project = Project.find(1) assert_redirected_to :controller => 'projects', :action => 'settings', :id => project, :tab => 'code_review' @@ -76,7 +75,7 @@ def setup assert_equal(CodeReviewProjectSetting::AUTORELATION_TYPE_BLOCKS, setting.auto_relation) get :update, :params => {:id => 1, :setting => {:tracker_id => 1, :id => setting.id}, :convert => 'true', - :auto_assign => {}} + :auto_assign => {}} assert_response :redirect project = Project.find(1) assert_redirected_to :controller => 'projects', :action => 'settings', :id => project, :tab => 'code_review' @@ -119,7 +118,6 @@ def setup end should "update filter" do - filter = AssignmentFilter.new filter.expression = 'aaa' filter.order = 10 @@ -131,7 +129,7 @@ def setup filter2.accept = false post :edit_filter, :params => {:id => @project.id, :auto_assign => @setting.auto_assign_settings.attributes.merge(:filters => {'0' => filter.attributes}), :num => 0, - :auto_assign_edit_filter => {'0' => filter2.attributes}} + :auto_assign_edit_filter => {'0' => filter2.attributes}} @auto_assign = assigns(:auto_assign) assert_not_nil @auto_assign assert_equal(1, @auto_assign.filters.length) @@ -165,30 +163,29 @@ def setup @filters['1'] = filter.attributes @filters['2'] = filter2.attributes @filters['3'] = filter2.attributes - end - should "sort filters" do + should "sort filters" do post :sort, :params => {:id => @project.id, :auto_assign => @setting.auto_assign_settings.attributes.merge(:filters => @filters), :num => 0, - :auto_assign_filter => {:num => 2, :move_to => 'highest'}} + :auto_assign_filter => {:num => 2, :move_to => 'highest'}} @auto_assign = assigns(:auto_assign) assert_not_nil @auto_assign assert_response :success post :sort, :params => {:id => @project.id, :auto_assign => @setting.auto_assign_settings.attributes.merge(:filters => @filters), :num => 0, - :auto_assign_filter => {:num => 2, :move_to => 'higher'}} + :auto_assign_filter => {:num => 2, :move_to => 'higher'}} @auto_assign = assigns(:auto_assign) assert_not_nil @auto_assign assert_response :success post :sort, :params => {:id => @project.id, :auto_assign => @setting.auto_assign_settings.attributes.merge(:filters => @filters), :num => 0, - :auto_assign_filter => {:num => 2, :move_to => 'lowest'}} + :auto_assign_filter => {:num => 2, :move_to => 'lowest'}} @auto_assign = assigns(:auto_assign) assert_not_nil @auto_assign assert_response :success post :sort, :params => {:id => @project.id, :auto_assign => @setting.auto_assign_settings.attributes.merge(:filters => @filters), :num => 0, - :auto_assign_filter => {:num => 2, :move_to => 'lower'}} + :auto_assign_filter => {:num => 2, :move_to => 'lower'}} @auto_assign = assigns(:auto_assign) assert_not_nil @auto_assign assert_response :success diff --git a/test/functional/issues_controller_test.rb b/test/functional/issues_controller_test.rb index 2b2fd98..bc7b1a2 100644 --- a/test/functional/issues_controller_test.rb +++ b/test/functional/issues_controller_test.rb @@ -46,10 +46,10 @@ class IssuesControllerTest < ActionController::TestCase :code_reviews, :code_review_assignments, :code_review_user_settings - + def setup @controller = IssuesController.new - @request = ActionController::TestRequest.create(self.class.controller_class) + @request = ActionController::TestRequest.create(self.class.controller_class) User.current = nil enabled_module = EnabledModule.new enabled_module.project_id = 1 @@ -60,7 +60,7 @@ def setup enabled_module.name = 'code_review' enabled_module.save roles = Role.all - roles.each {|role| + roles.each { |role| role.permissions << :view_code_review role.save } @@ -81,18 +81,17 @@ def test_show review = FactoryGirl.create(:code_review, project: project) get :show, :params => {:id => review.issue.id} - end def test_new @request.session[:user_id] = 1 - get :new, params: { project_id: 1 } + get :new, params: {project_id: 1} assert_response :success - get :new, :params => {:project_id => 1, :code =>{:rev => 1, :rev_to => 2, :path => '/aaa/bbb', :action_type => 'diff'}} + get :new, :params => {:project_id => 1, :code => {:rev => 1, :rev_to => 2, :path => '/aaa/bbb', :action_type => 'diff'}} assert_response :success post :new, :params => {:project_id => 1, - :issue => {:tracker_id => 1, :status_id => 1, :subject => 'hoge'}, - :code =>{:rev => 1, :rev_to => 2, :path => '/aaa/bbb', :action_type => 'diff'}} + :issue => {:tracker_id => 1, :status_id => 1, :subject => 'hoge'}, + :code => {:rev => 1, :rev_to => 2, :path => '/aaa/bbb', :action_type => 'diff'}} # TODO: 0.9.xのサポート終了時に以下を有効にする。 #assert_response :SUCESS diff --git a/test/functional/projects_controller_test.rb b/test/functional/projects_controller_test.rb index c164f83..7edb700 100644 --- a/test/functional/projects_controller_test.rb +++ b/test/functional/projects_controller_test.rb @@ -24,7 +24,7 @@ class ProjectsControllerTest < ActionController::TestCase def setup @controller = ProjectsController.new - @request = ActionController::TestRequest.create(self.class.controller_class) + @request = ActionController::TestRequest.create(self.class.controller_class) end context "#settings" do diff --git a/test/functional/repositories_controller_test.rb b/test/functional/repositories_controller_test.rb index c8cc641..25edd6c 100644 --- a/test/functional/repositories_controller_test.rb +++ b/test/functional/repositories_controller_test.rb @@ -18,14 +18,13 @@ require File.expand_path(File.dirname(__FILE__) + '/../test_helper') require 'repositories_controller' - class RepositoriesControllerTest < ActionController::TestCase fixtures :projects, :users, :roles, :members, :member_roles, :repositories, :issues, :issue_statuses, :changesets, - :changes, :issue_categories, :enumerations, :custom_fields, :custom_values, :trackers, :projects_trackers + :changes, :issue_categories, :enumerations, :custom_fields, :custom_values, :trackers, :projects_trackers def setup @controller = RepositoriesController.new - @request = ActionController::TestRequest.create(self.class.controller_class) + @request = ActionController::TestRequest.create(self.class.controller_class) User.current = nil enabled_module = EnabledModule.new enabled_module.project_id = 1 @@ -46,7 +45,7 @@ def setup User.current = nil roles = Role.all - roles.each {|role| + roles.each { |role| role.permissions << :view_code_review role.permissions << :add_code_review role.permissions << :browse_repository diff --git a/test/test_helper.rb b/test/test_helper.rb index b3f0494..43c2938 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -15,7 +15,6 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - require 'simplecov' require 'simplecov-rcov' require 'coveralls' @@ -35,7 +34,7 @@ fixtures = [] Dir.chdir(File.dirname(__FILE__) + '/fixtures/') do - fixtures = Dir.glob('*.yml').map{|s| s.gsub(/.yml$/, '')} + fixtures = Dir.glob('*.yml').map { |s| s.gsub(/.yml$/, '') } end ActiveRecord::FixtureSet.create_fixtures(File.dirname(__FILE__) + '/fixtures/', fixtures) @@ -55,12 +54,10 @@ def mock_file def uploaded_test_file(name, mime) fixture_file_upload(Rails.root.to_s + "/test/fixtures/files/#{name}", mime, true) end -FactoryGirl.define do +FactoryGirl.define do factory :attachment do - - - container{ + container { Issue.find(1) } file { @@ -71,8 +68,6 @@ def uploaded_test_file(name, mime) } end - - factory :repository do project_id 1 url "file:///#{Rails.root}/tmp/test/subversion_repository" @@ -91,7 +86,7 @@ def uploaded_test_file(name, mime) factory :changeset do sequence(:revision, 1000) - committed_on{ + committed_on { Date.today } #association :repository @@ -108,7 +103,7 @@ def uploaded_test_file(name, mime) action { "A" } - sequence(:path){ |n| + sequence(:path) { |n| "test/dir/aaa#{n}" } changeset { @@ -122,7 +117,7 @@ def uploaded_test_file(name, mime) factory :issue do subject 'hoge' - author{ + author { User.find(1) } end @@ -142,5 +137,4 @@ def uploaded_test_file(name, mime) factory :enabled_module do end - -end \ No newline at end of file +end diff --git a/test/test_runner.rb b/test/test_runner.rb index eaec046..f74ef8b 100644 --- a/test/test_runner.rb +++ b/test/test_runner.rb @@ -15,7 +15,6 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - require 'simplecov' require 'simplecov-rcov' SimpleCov.formatter = SimpleCov::Formatter::RcovFormatter @@ -28,10 +27,10 @@ require "#{testdir}/test_helper" -Dir::glob("#{testdir}/fixtures/*.yml").each {|f| +Dir::glob("#{testdir}/fixtures/*.yml").each { |f| FileUtils.copy(f, "#{testdir}/../../../test/fixtures/") } -Dir::glob("#{testdir}/**/*test.rb").each {|f| +Dir::glob("#{testdir}/**/*test.rb").each { |f| require f -} \ No newline at end of file +} diff --git a/test/unit/code_review_assignment_test.rb b/test/unit/code_review_assignment_test.rb index 976196a..03774da 100644 --- a/test/unit/code_review_assignment_test.rb +++ b/test/unit/code_review_assignment_test.rb @@ -25,7 +25,7 @@ class CodeReviewAssignmentTest < ActiveSupport::TestCase def setup @assignment = CodeReviewAssignment.new end - + context "is_closed?" do should "return false if assignment issue is not closed." do @assignment.issue = Issue.new @@ -100,5 +100,4 @@ def setup assert_equal('123 5001 foo 456', assignment.issue.subject) end end - end diff --git a/test/unit/code_review_attachment_patch_test.rb b/test/unit/code_review_attachment_patch_test.rb index 2eba3a7..faa39c9 100644 --- a/test/unit/code_review_attachment_patch_test.rb +++ b/test/unit/code_review_attachment_patch_test.rb @@ -26,7 +26,7 @@ def setup @issue = Issue.where(:project_id => 1).first @attachment = FactoryGirl.create(:attachment, container: @issue) end - + context "code_review_assginments" do should "returns empty array if attachment has no assignments" do assert_not_nil(@attachment.code_review_assignments) diff --git a/test/unit/code_review_auto_assign_settings_test.rb b/test/unit/code_review_auto_assign_settings_test.rb index 354a092..fc4e178 100644 --- a/test/unit/code_review_auto_assign_settings_test.rb +++ b/test/unit/code_review_auto_assign_settings_test.rb @@ -33,12 +33,11 @@ def startup def teardown #DatabaseRewinder.clean end - + context "AutoAssignSettings" do context "to_s" do should "return string if @yml is not nil." do - - str =< @project, :user_id => i) } @project.members << members end - + should "return nil if assignable_list is nil" do @settings.assignable_list = nil assert_nil @settings.select_assign_to @project @@ -167,12 +166,12 @@ def teardown end should "return user_id" do - @settings.assignable_list = [1,2,3,4,5] + @settings.assignable_list = [1, 2, 3, 4, 5] assert_not_nil @settings.select_assign_to(@project) end should "not return id that equals user.id" do - @settings.assignable_list = [1,2] + @settings.assignable_list = [1, 2] user = User.find(1) assert_equal(2, @settings.select_assign_to(@project, user)) @settings.assignable_list = [1] @@ -221,7 +220,7 @@ def teardown setup do @settings = AutoAssignSettings.new end - + should "return empty array if :filters is nil" do @settings.filters = nil assert_equal(0, @settings.filters.length) @@ -394,5 +393,4 @@ def teardown assert @settings.filter_enabled? end end - end diff --git a/test/unit/code_review_change_patch_test.rb b/test/unit/code_review_change_patch_test.rb index 63c5b8b..3d87344 100644 --- a/test/unit/code_review_change_patch_test.rb +++ b/test/unit/code_review_change_patch_test.rb @@ -19,7 +19,6 @@ class CodeReviewChangePatchTest < ActiveSupport::TestCase fixtures :code_reviews, :projects, :users, :repositories, :changesets, :changes, :issues, :issue_statuses, :enumerations, :issue_categories, :trackers - def test_review_count change = Change.find(2) assert_equal(2, change.review_count) @@ -33,7 +32,6 @@ def test_open_review_count issue.save change = Change.find(2) assert_equal(1, change.open_review_count) - end def test_closed_review_count @@ -46,7 +44,7 @@ def test_closed_review_count assert_equal(1, change.closed_review_count) end - def test_assignment_count + def test_assignment_count change = FactoryGirl.create(:change) assert_equal(0, change.assignment_count) change.code_review_assignments << FactoryGirl.create(:code_review_assignment) @@ -94,7 +92,7 @@ def test_closed_assignment_count change.code_review_assignments << FactoryGirl.create(:code_review_assignment) change.code_review_assignments << FactoryGirl.create(:code_review_assignment) close_status = IssueStatus.find(5) - change.code_review_assignments.each{|assignments| + change.code_review_assignments.each { |assignments| assignments.issue.status = close_status } assert_equal(0, change.open_assignments.length) diff --git a/test/unit/code_review_changeset_patch_test.rb b/test/unit/code_review_changeset_patch_test.rb index b3d53cb..d97cf83 100644 --- a/test/unit/code_review_changeset_patch_test.rb +++ b/test/unit/code_review_changeset_patch_test.rb @@ -62,7 +62,7 @@ def test_completed_assignment_pourcent changeset = FactoryGirl.create(:changeset) FactoryGirl.create(:change, changeset: changeset) FactoryGirl.create(:change, changeset: changeset) - + changeset = Changeset.find(changeset.id) change = changeset.filechanges[0] change.code_review_assignments << FactoryGirl.create(:code_review_assignment, issue_id: 1) @@ -71,7 +71,7 @@ def test_completed_assignment_pourcent change.code_review_assignments << FactoryGirl.create(:code_review_assignment, issue_id: 3) change.code_review_assignments << FactoryGirl.create(:code_review_assignment, issue_id: 4) issues = [] - 1.upto(4) {|i| + 1.upto(4) { |i| issues[i - 1] = Issue.find(i) issues[i - 1].status_id = 1 issues[i - 1].due_date = nil @@ -95,7 +95,6 @@ def test_completed_assignment_pourcent end context "closed_assignment_pourcent" do - should "returns 0 if changeset has no assignments." do change = FactoryGirl.create(:change) changeset = change.changeset @@ -119,13 +118,13 @@ def test_completed_assignment_pourcent changeset = change.changeset @project = Project.find(1) issue1 = Issue.generate!({:project => @project, :status => IssueStatus.find(5)}) - issue1.status = IssueStatus.find(5); + issue1.status = IssueStatus.find(5) issue2 = Issue.generate!({:project => @project, :status => IssueStatus.find(5)}) - issue2.status = IssueStatus.find(5); + issue2.status = IssueStatus.find(5) change.code_review_assignments << FactoryGirl.create(:code_review_assignment, issue: issue1) change.code_review_assignments << FactoryGirl.create(:code_review_assignment, issue: issue2) change.save! - changeset =Changeset.find(changeset.id) + changeset = Changeset.find(changeset.id) assert issue1.closed? assert issue2.closed? assert_equal(2, changeset.assignment_count) @@ -185,7 +184,6 @@ def test_completed_assignment_pourcent assert_not_nil(changeset.assignment_issues) assert_equal(3, changeset.assignment_issues.length) end - end context "after_save" do @@ -196,7 +194,7 @@ def test_completed_assignment_pourcent repository = project.repository @changeset = FactoryGirl.create(:changeset, repository: repository) - + auto_assign = AutoAssignSettings.new auto_assign.enabled = true filters = [] diff --git a/test/unit/code_review_project_settings_test.rb b/test/unit/code_review_project_settings_test.rb index 971fde8..a6ab7ae 100644 --- a/test/unit/code_review_project_settings_test.rb +++ b/test/unit/code_review_project_settings_test.rb @@ -25,7 +25,7 @@ class CodeReviewProjectSettingsTest < ActiveSupport::TestCase @setting = CodeReviewProjectSetting.new end - should "return false if project_id is nil." do + should "return false if project_id is nil." do assert !@setting.save end @@ -53,55 +53,55 @@ class CodeReviewProjectSettingsTest < ActiveSupport::TestCase assert setting.auto_assign_settings.enabled? end end - + context "issue_relation_type" do setup do @setting = CodeReviewProjectSetting.new end - + should "return IssueRelation::TYPE_RELATES if auto_relation is CodeReviewProjectSetting::AUTORELATION_TYPE_RELATES" do @setting.auto_relation = CodeReviewProjectSetting::AUTORELATION_TYPE_RELATES assert_equal(IssueRelation::TYPE_RELATES, @setting.issue_relation_type) end - + should "return IssueRelation::TYPE_BLOCKS if auto_relation is CodeReviewProjectSetting::AUTORELATION_TYPE_BLOCKS" do @setting.auto_relation = CodeReviewProjectSetting::AUTORELATION_TYPE_BLOCKS assert_equal(IssueRelation::TYPE_BLOCKS, @setting.issue_relation_type) end - + should "return nil if auto_relation is CodeReviewProjectSetting::AUTORELATION_TYPE_NONE" do @setting.auto_relation = CodeReviewProjectSetting::AUTORELATION_TYPE_NONE assert_nil(@setting.issue_relation_type) end - + should "return nil if auto_relation is nil" do - @setting.auto_relation =nil + @setting.auto_relation = nil assert_nil(@setting.issue_relation_type) end end - + context "auto_relation?" do setup do @setting = CodeReviewProjectSetting.new end - + should "return true if auto_relation is CodeReviewProjectSetting::AUTORELATION_TYPE_RELATES" do @setting.auto_relation = CodeReviewProjectSetting::AUTORELATION_TYPE_RELATES assert(@setting.issue_relation_type) end - + should "return true if auto_relation is CodeReviewProjectSetting::AUTORELATION_TYPE_BLOCKS" do @setting.auto_relation = CodeReviewProjectSetting::AUTORELATION_TYPE_BLOCKS assert(@setting.issue_relation_type) end - + should "return false if auto_relation is CodeReviewProjectSetting::AUTORELATION_TYPE_NONE" do @setting.auto_relation = CodeReviewProjectSetting::AUTORELATION_TYPE_NONE assert !(@setting.issue_relation_type) end - + should "return false if auto_relation is nil" do - @setting.auto_relation =nil + @setting.auto_relation = nil assert !(@setting.issue_relation_type) end end diff --git a/test/unit/code_review_test.rb b/test/unit/code_review_test.rb index c667836..7a0a492 100644 --- a/test/unit/code_review_test.rb +++ b/test/unit/code_review_test.rb @@ -18,7 +18,7 @@ class CodeReviewTest < ActiveSupport::TestCase fixtures :code_reviews, :projects, :users, :repositories, :changesets, - :changes, :issues, :issue_statuses , :enumerations, :issue_categories, + :changes, :issues, :issue_statuses, :enumerations, :issue_categories, :trackers, :projects_trackers, :attachments # Create new object. @@ -29,15 +29,15 @@ def test_create code_review.project_id = 1 code_review.issue.project_id = 1 code_review.comment = "aaa" - code_review.user_id = 1; - code_review.change_id = 1; - code_review.updated_by_id = 1; + code_review.user_id = 1 + code_review.change_id = 1 + code_review.updated_by_id = 1 code_review.subject = "aaa" code_review.action_type = 'diff' code_review.line = 20 assert code_review.save - + code_review.destroy end @@ -81,8 +81,6 @@ def test_repository assert_equal(10, code_review.repository.id) end - - def test_is_closed? review = CodeReview.find(9) assert !review.is_closed? @@ -105,7 +103,6 @@ def test_status_id assert_equal(review.status_id, review.issue.status_id) review.status_id = 5 assert_equal(5, review.issue.status_id) - end def test_user @@ -115,15 +112,17 @@ def test_user issue = review.issue assert_equal(issue.author_id, 2) end + private + def newreview code_review = CodeReview.new code_review.issue = Issue.new - code_review.project_id = 1; + code_review.project_id = 1 code_review.comment = "aaa" - code_review.user_id = 1; - code_review.change_id = 1; - code_review.updated_by_id = 1; + code_review.user_id = 1 + code_review.change_id = 1 + code_review.updated_by_id = 1 return code_review end end From 4e6feb62b5e801f6b00f9c58c779dd6e7eb1fbf4 Mon Sep 17 00:00:00 2001 From: Haruyuki Iida Date: Fri, 8 Dec 2017 14:15:44 +0900 Subject: [PATCH 21/33] code re-format by rufo --- app/controllers/code_review_controller.rb | 42 +++--- .../code_review_settings_controller.rb | 13 +- app/helpers/code_review_helper.rb | 11 +- app/models/code_review.rb | 15 +-- app/models/code_review_assignment.rb | 15 +-- app/models/code_review_project_setting.rb | 5 +- app/models/review_mailer.rb | 30 ++--- config/routes.rb | 2 +- db/migrate/0001_create_code_reviews.rb | 2 - db/migrate/0002_add_updated_by.rb | 1 - db/migrate/0003_add_lock_version.rb | 3 +- db/migrate/0004_add_status_changed.rb | 1 - .../0005_create_code_review_user_settings.rb | 6 +- db/migrate/0006_link_to_issue.rb | 1 - db/migrate/0007_rename_user.rb | 3 +- ...008_create_code_review_project_settings.rb | 2 - db/migrate/0009_add_hide_tab.rb | 1 - db/migrate/0010_add_action_type.rb | 1 - db/migrate/0011_add_auto_relation.rb | 3 +- db/migrate/0012_add_attachment_id.rb | 1 - db/migrate/0013_add_file_count.rb | 1 - .../0014_create_code_review_assignments.rb | 2 - db/migrate/0015_add_assignment_tracker.rb | 1 - db/migrate/0016_add_changeset_id.rb | 1 - db/migrate/0017_add_auto_assign.rb | 1 - ...18_add_lock_version_to_project_settings.rb | 1 - db/migrate/0019_delete_old_fields.rb | 2 +- .../0020_add_tracker_to_review_dialog.rb | 4 +- db/migrate/0021_add_diff_all.rb | 2 +- init.rb | 15 +-- lib/code_review_application_hooks.rb | 1 + lib/code_review_attachment_patch.rb | 5 - lib/code_review_auto_assign_settings.rb | 19 ++- lib/code_review_change_patch.rb | 7 +- lib/code_review_changeset_patch.rb | 39 +++--- lib/code_review_issue_hooks.rb | 15 ++- lib/code_review_issue_patch.rb | 5 - lib/code_review_projects_helper_patch.rb | 3 - test/code_review_object_daddy_helpers.rb | 14 +- test/exemplars/code_review_exemplar.rb | 2 - .../functional/attachments_controller_test.rb | 18 +-- .../functional/code_review_controller_test.rb | 97 +++++++------- .../code_review_settings_controller_test.rb | 33 +++-- test/functional/issues_controller_test.rb | 19 ++- test/functional/projects_controller_test.rb | 124 +++++++++--------- .../repositories_controller_test.rb | 11 +- test/test_helper.rb | 15 +-- test/test_runner.rb | 7 +- test/unit/code_review_assignment_test.rb | 3 +- .../unit/code_review_attachment_patch_test.rb | 2 +- .../code_review_auto_assign_settings_test.rb | 22 ++-- test/unit/code_review_change_patch_test.rb | 6 +- test/unit/code_review_changeset_patch_test.rb | 14 +- .../unit/code_review_project_settings_test.rb | 26 ++-- test/unit/code_review_test.rb | 23 ++-- 55 files changed, 316 insertions(+), 402 deletions(-) diff --git a/app/controllers/code_review_controller.rb b/app/controllers/code_review_controller.rb index 47de18b..53d2e42 100644 --- a/app/controllers/code_review_controller.rb +++ b/app/controllers/code_review_controller.rb @@ -33,7 +33,7 @@ class CodeReviewController < ApplicationController def index sort_init "#{Issue.table_name}.id", 'desc' - sort_update ["#{Issue.table_name}.id", "#{Issue.table_name}.status_id", "#{Issue.table_name}.subject", "path", "updated_at", "user_id", "#{Changeset.table_name}.committer", "#{Changeset.table_name}.revision"] + sort_update ["#{Issue.table_name}.id", "#{Issue.table_name}.status_id", "#{Issue.table_name}.subject", "path", "updated_at", "user_id", "#{Changeset.table_name}.committer", "#{Changeset.table_name}.revision"] limit = per_page_option @review_count = CodeReview.where(["project_id = ? and issue_id is NOT NULL", @project.id]).count @@ -52,7 +52,8 @@ def index @reviews = CodeReview.order(sort_clause).limit(limit).where(conditions).joins( "left join #{Change.table_name} on change_id = #{Change.table_name}.id left join #{Changeset.table_name} on #{Change.table_name}.changeset_id = #{Changeset.table_name}.id " + "left join #{Issue.table_name} on issue_id = #{Issue.table_name}.id " + - "left join #{IssueStatus.table_name} on #{Issue.table_name}.status_id = #{IssueStatus.table_name}.id").offset(@review_pages.offset) + "left join #{IssueStatus.table_name} on #{Issue.table_name}.status_id = #{IssueStatus.table_name}.id" + ).offset(@review_pages.offset) @i_am_member = @user.member_of?(@project) render :template => 'code_review/index', :layout => !request.xhr? end @@ -85,12 +86,12 @@ def new @review.issue.safe_attributes = params[:issue] unless params[:issue].blank? @review.diff_all = (params[:diff_all] == 'true') - @parent_candidate = get_parent_candidate(@review.rev) if @review.rev + @parent_candidate = get_parent_candidate(@review.rev) if @review.rev if request.post? @review.issue.save! if @review.changeset - @review.changeset.issues.each {|issue| + @review.changeset.issues.each { |issue| create_relation @review, issue, @setting.issue_relation_type } if @setting.auto_relation? elsif @review.attachment and @review.attachment.container_type == 'Issue' @@ -98,7 +99,7 @@ def new create_relation @review, issue, @setting.issue_relation_type if @setting.auto_relation? end watched_users = [] - @review.open_assignment_issues(@user.id).each {|issue| + @review.open_assignment_issues(@user.id).each { |issue| unless @review.issue.parent_id == issue.id create_relation @review, issue, IssueRelation::TYPE_RELATES end @@ -124,21 +125,19 @@ def new end @default_version_id = @review.issue.fixed_version.id if @review.issue.fixed_version if @review.changeset and @default_version_id.blank? - @review.changeset.issues.each {|issue| + @review.changeset.issues.each { |issue| if issue.fixed_version @default_version_id = issue.fixed_version.id - break; + break end } end - @review.open_assignment_issues(@user.id).each {|issue| + @review.open_assignment_issues(@user.id).each { |issue| if issue.fixed_version @default_version_id = issue.fixed_version.id - break; + break end } unless @default_version_id - - end render :partial => 'new_form', :status => 200 } @@ -174,7 +173,7 @@ def assign end issue[:tracker_id] = @setting.assignment_tracker_id if @setting.assignment_tracker_id - redirect_to :controller => 'issues', :action => "new" , :project_id => @project, + redirect_to :controller => 'issues', :action => "new", :project_id => @project, :issue => issue, :code => code end @@ -191,8 +190,7 @@ def update_diff_view @action_type = params[:action_type] changeset = @repository.find_changeset_by_name(@rev) if @paths.empty? - changeset.filechanges.each{|chg| - } + changeset.filechanges.each { |chg| } end url = @repository.url @@ -208,9 +206,9 @@ def update_diff_view end end @change = nil - changeset.filechanges.each{|chg| + changeset.filechanges.each { |chg| @change = chg if ((chg.path == fullpath) or ("/#{chg.path}" == fullpath)) or (chg.path == "/#{@path}") - } unless @path.blank? + } unless @path.blank? @changeset = changeset if @path @@ -223,8 +221,6 @@ def update_diff_view #render :partial => 'show_error' #return - - render :partial => 'update_diff_view' end @@ -268,7 +264,7 @@ def show else path = nil if target.diff_all url = url_for(:controller => 'repositories', :action => action_name, :id => @project, - :repository_id => @repository_id, :rev => target.revision, :path => path) + :repository_id => @repository_id, :rev => target.revision, :path => path) #url = url_for(:controller => 'repositories', :action => action_name, :id => @project, :repository_id => @repository_id) + path + '?rev=' + target.revision url << '?review_id=' + @review.id.to_s + rev_to if @review url << '?r=' + rev_to unless @review @@ -328,7 +324,6 @@ def update end end - def destroy @review = CodeReview.find(params[:review_id].to_i) @review.issue.destroy if @review @@ -343,7 +338,6 @@ def forward_to_revision identifier = change.identifier redirect_to url_for(:controller => 'repositories', :action => 'entry', :id => @project, :repository_id => @repository_id) + '/' + path + '?rev=' + identifier.to_s - end def preview @@ -357,13 +351,14 @@ def update_revisions_view #changeset_ids = CGI.unescape(params[:changeset_ids]).split(',') unless params[:changeset_ids].blank? changeset_ids = params[:changeset_ids].split(',') unless params[:changeset_ids].blank? @changesets = [] - changeset_ids.each {|id| + changeset_ids.each { |id| @changesets << @repository.find_changeset_by_name(id) unless id.blank? } render :partial => 'update_revisions' end private + def find_repository if params[:repository_id].present? and @project.repositories @repository = @project.repositories.find_by_identifier_param(params[:repository_id]) @@ -382,14 +377,13 @@ def find_user @user = User.current end - def find_setting @setting = CodeReviewProjectSetting.find_or_create(@project) end def get_parent_candidate(revision) changeset = @repository.find_changeset_by_name(revision) - changeset.issues.each {|issue| + changeset.issues.each { |issue| return Issue.find(issue.parent_issue_id) if issue.parent_issue_id } nil diff --git a/app/controllers/code_review_settings_controller.rb b/app/controllers/code_review_settings_controller.rb index 2b367da..5d806f0 100644 --- a/app/controllers/code_review_settings_controller.rb +++ b/app/controllers/code_review_settings_controller.rb @@ -33,14 +33,13 @@ def update @setting.auto_assign_settings = params[:auto_assign].to_yaml @setting.save! - + flash[:notice] = l(:notice_successful_update) rescue ActiveRecord::StaleObjectError # Optimistic locking exception flash[:error] = l(:notice_locking_conflict) end redirect_to :controller => 'projects', :action => "settings", :id => @project, :tab => 'code_review' - end def add_filter @@ -50,7 +49,7 @@ def add_filter filters = [] unless filters filters << params[:auto_assign_add_filter] - @auto_assign.filters = filters.collect{|f| + @auto_assign.filters = filters.collect { |f| filter = AssignmentFilter.new filter.attributes = f filter @@ -66,7 +65,7 @@ def edit_filter filters = params[:auto_assign][:filters].values unless params[:auto_assign][:filters].blank? filters = [] unless filters i = 0 - @auto_assign.filters = filters.collect{|f| + @auto_assign.filters = filters.collect { |f| filter = AssignmentFilter.new if i == num filter.attributes = params[:auto_assign_edit_filter][num.to_s] @@ -97,16 +96,17 @@ def sort filters[num][:order] = 999999999 end - @auto_assign.filters = filters.collect{|f| + @auto_assign.filters = filters.collect { |f| filter = AssignmentFilter.new filter.attributes = f filter } - render :partial => "code_review_settings/filters" end + private + def find_project # @project variable must be set before calling the authorize filter @project = Project.find(params[:id]) @@ -115,5 +115,4 @@ def find_project def find_user @user = User.current end - end diff --git a/app/helpers/code_review_helper.rb b/app/helpers/code_review_helper.rb index 2086c33..5b64c14 100644 --- a/app/helpers/code_review_helper.rb +++ b/app/helpers/code_review_helper.rb @@ -16,19 +16,20 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. module CodeReviewHelper unloadable + def show_assignments(assignments, project, options = {}) html = "#{l(:review_assignments)}:" assignments.each do |assignment| issue = assignment.issue html << link_to("##{issue.id} ", {:controller => 'issues', :action => 'show', :id => issue.id}, - :class => issue.css_classes, :title => "#{issue}(#{issue.status})") + :class => issue.css_classes, :title => "#{issue}(#{issue.status})") end if assignments link = link_to(l(:button_add), {:controller => 'code_review', - :action => 'assign', :id=>project, :action_type => options[:action_type], - :rev => options[:rev], :rev_to => options[:rev_to], :path => options[:path], - :change_id => options[:change_id], :attachment_id => options[:attachment_id], - :changeset_id => options[:changeset_id]}, :class => 'icon icon-add') + :action => 'assign', :id => project, :action_type => options[:action_type], + :rev => options[:rev], :rev_to => options[:rev_to], :path => options[:path], + :change_id => options[:change_id], :attachment_id => options[:attachment_id], + :changeset_id => options[:changeset_id]}, :class => 'icon icon-add') html << link if link diff --git a/app/models/code_review.rb b/app/models/code_review.rb index e2cb549..bccb227 100644 --- a/app/models/code_review.rb +++ b/app/models/code_review.rb @@ -23,7 +23,7 @@ class CodeReview < ActiveRecord::Base belongs_to :updated_by, :class_name => 'User', :foreign_key => 'updated_by_id' belongs_to :attachment - validates_presence_of :project_id, :user_id, :updated_by_id, :issue, + validates_presence_of :project_id, :user_id, :updated_by_id, :issue, :subject, :action_type, :line STATUS_OPEN = 0 @@ -49,7 +49,7 @@ def reopen issue.status = IssueStatus.find(1) #self.root.status = STATUS_OPEN end - + def committer return changeset.author if changeset end @@ -74,7 +74,7 @@ def path @path = change.path else @path = change.path[rootpath.length, change.path.length - rootpath.length] - end + end rescue => ex return ex.to_s end @@ -92,13 +92,13 @@ def changeset def repository @repository ||= changeset.repository if changeset end - + def repository_identifier return nil unless repository @repository_identifier ||= repository.identifier_param end - def comment=(str) + def comment=(str) issue.description = str if issue end @@ -113,7 +113,6 @@ def before_save def validate unless issue.validate false - end end @@ -141,7 +140,7 @@ def subject issue.subject end - def parent_id= (p) + def parent_id=(p) issue.parent_issue_id = p end @@ -164,7 +163,7 @@ def open_assignment_issues(user_id) assignments = assignments + changeset.code_review_assignments if changeset assignments = assignments + attachment.code_review_assignments if attachment - assignments.each {|assignment| + assignments.each { |assignment| unless assignment.is_closed? issues << assignment.issue if user_id == assignment.issue.assigned_to_id end diff --git a/app/models/code_review_assignment.rb b/app/models/code_review_assignment.rb index 75c45e1..768030b 100644 --- a/app/models/code_review_assignment.rb +++ b/app/models/code_review_assignment.rb @@ -35,13 +35,13 @@ def revision return rev if rev changeset.revision if changeset end - + def repository @repository ||= change.changeset.repository if change @repository ||= changeset.repository if changeset @repository end - + def repository_identifier return nil unless repository @repository_identifier ||= repository.identifier_param if repository.respond_to?("identifier_param") @@ -55,25 +55,24 @@ def self.create_with_changeset(changeset) issue = Issue.new issue.subject = auto_assign.subject issue.subject = l(:code_review_requrest) if issue.subject.blank? - issue.subject = issue.subject.sub("$REV" , changeset.revision) - issue.subject = issue.subject.sub("$COMMENTS" , changeset.comments.split(//u)[0..60].join) unless changeset.comments.blank? + issue.subject = issue.subject.sub("$REV", changeset.revision) + issue.subject = issue.subject.sub("$COMMENTS", changeset.comments.split(//u)[0..60].join) unless changeset.comments.blank? issue.tracker_id = setting.assignment_tracker_id issue.project = project issue.author = User.find(auto_assign.author_id) issue.assigned_to_id = auto_assign.select_assign_to(project, changeset.user) issue.description = auto_assign.description - issue.description = issue.description.sub("$REV" , changeset.revision) unless issue.description.blank? - issue.description = issue.description.sub("$COMMENTS" , changeset.comments) unless changeset.comments.blank? + issue.description = issue.description.sub("$REV", changeset.revision) unless issue.description.blank? + issue.description = issue.description.sub("$COMMENTS", changeset.comments) unless changeset.comments.blank? issue.save! - + assignment.issue_id = issue.id assignment.changeset_id = changeset.id assignment.save! assignment end - def diff_all path.blank? end diff --git a/app/models/code_review_project_setting.rb b/app/models/code_review_project_setting.rb index f1a8d28..eedd47b 100644 --- a/app/models/code_review_project_setting.rb +++ b/app/models/code_review_project_setting.rb @@ -55,18 +55,19 @@ def auto_assign_settings def auto_assign_settings=(settings) @auto_assign_settings = settings end - + def issue_relation_type return IssueRelation::TYPE_RELATES if auto_relation == CodeReviewProjectSetting::AUTORELATION_TYPE_RELATES return IssueRelation::TYPE_BLOCKS if auto_relation == CodeReviewProjectSetting::AUTORELATION_TYPE_BLOCKS return nil end - + def auto_relation? issue_relation_type != nil end private + def set_assignment_settings if auto_assign_settings self.auto_assign = auto_assign_settings.to_s diff --git a/app/models/review_mailer.rb b/app/models/review_mailer.rb index 3975f9b..6c0851a 100644 --- a/app/models/review_mailer.rb +++ b/app/models/review_mailer.rb @@ -16,12 +16,11 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. class ReviewMailer < Mailer - def review_add(project, review) redmine_headers 'Project' => review.project.identifier, 'Review-Id' => review.id, 'Review-Author' => review.user.login - + recipients get_mail_addresses(review) subject "[#{review.project.name} - #{l(:label_review_new)} - #{l(:label_review)}##{review.id}] " @@ -31,18 +30,18 @@ def review_add(project, review) return if (l(:this_is_checking_for_before_rails_2_2_2) == 'this_is_checking_for_before_rails_2_2_2') # 何故かrails 2.2 以後は以下の処理が必要 - + content_type "multipart/alternative" part "text/plain" do |p| - p.body = render_message("review_add.text.plain.erb", :body => body, :review=>review, :review_url => review_url) + p.body = render_message("review_add.text.plain.erb", :body => body, :review => review, :review_url => review_url) end part "text/html" do |p| - p.body = render_message("review_add.text.html.erb", :body => body, :review=>review, :review_url => review_url) + p.body = render_message("review_add.text.html.erb", :body => body, :review => review, :review_url => review_url) end end - + def review_reply(project, review) redmine_headers 'Project' => review.project.identifier, 'Review-Id' => review.id, @@ -56,17 +55,16 @@ def review_reply(project, review) return if (l(:this_is_checking_for_before_rails_2_2_2) == 'this_is_checking_for_before_rails_2_2_2') # 何故かrails 2.2 以後は以下の処理が必要 - + content_type "multipart/alternative" part "text/plain" do |p| - p.body = render_message("review_reply.text.plain.erb", :body => body, :review=>review, :review_url => review_url) + p.body = render_message("review_reply.text.plain.erb", :body => body, :review => review, :review_url => review_url) end part "text/html" do |p| - p.body = render_message("review_reply.text.html.erb", :body => body, :review=>review, :review_url => review_url) + p.body = render_message("review_reply.text.html.erb", :body => body, :review => review, :review_url => review_url) end - end def review_status_changed(project, review) @@ -86,21 +84,21 @@ def review_status_changed(project, review) return if (l(:this_is_checking_for_before_rails_2_2_2) == 'this_is_checking_for_before_rails_2_2_2') # 何故かrails 2.2 以後は以下の処理が必要 - + content_type "multipart/alternative" part "text/plain" do |p| - p.body = render_message("review_status_changed.text.plain.erb", :body => body, :review=>review, :review_url => review_url) + p.body = render_message("review_status_changed.text.plain.erb", :body => body, :review => review, :review_url => review_url) end part "text/html" do |p| - p.body = render_message("review_status_changed.text.html.erb", :body => body, :review=>review, :review_url => review_url) + p.body = render_message("review_status_changed.text.html.erb", :body => body, :review => review, :review_url => review_url) end end def get_mail_addresses(review) mail_addresses = [] - review.root.users_for_notification.each{|u| + review.root.users_for_notification.each { |u| mail_addresses << u.mail } committer = review.change.changeset.user @@ -109,14 +107,12 @@ def get_mail_addresses(review) mail_addresses << committer.mail if setting and !setting.mail_notification_none? end - review.project.members.each{|member| + review.project.members.each { |member| user = member.user setting = CodeReviewUserSetting.find_or_create(user.id) next unless setting mail_addresses << user.mail if setting.mail_notification_all? } mail_addresses.compact.uniq - end - end diff --git a/config/routes.rb b/config/routes.rb index af39e4e..f4bb5be 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -19,4 +19,4 @@ #map.connect 'projects/:id/code_review/:action', :controller => 'code_review' match 'projects/:id/code_review/:action', :controller => 'code_review', :via => [:get, :post] match 'projects/:id/code_review_settings/:action', :controller => 'code_review_settings', :via => [:get, :post, :put, :patch] -end \ No newline at end of file +end diff --git a/db/migrate/0001_create_code_reviews.rb b/db/migrate/0001_create_code_reviews.rb index 9410360..6ca820c 100644 --- a/db/migrate/0001_create_code_reviews.rb +++ b/db/migrate/0001_create_code_reviews.rb @@ -18,7 +18,6 @@ class CreateCodeReviews < ActiveRecord::Migration def self.up create_table :code_reviews do |t| - t.column :project_id, :integer t.column :parent_id, :integer @@ -36,7 +35,6 @@ def self.up t.column :status, :integer t.column :line, :integer - end end diff --git a/db/migrate/0002_add_updated_by.rb b/db/migrate/0002_add_updated_by.rb index 21d8959..5e0d9ce 100644 --- a/db/migrate/0002_add_updated_by.rb +++ b/db/migrate/0002_add_updated_by.rb @@ -16,7 +16,6 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. class AddUpdatedBy < ActiveRecord::Migration - def self.up add_column(:code_reviews, "updated_by_id", :integer) end diff --git a/db/migrate/0003_add_lock_version.rb b/db/migrate/0003_add_lock_version.rb index 0ddb0ec..7b33c4e 100644 --- a/db/migrate/0003_add_lock_version.rb +++ b/db/migrate/0003_add_lock_version.rb @@ -16,9 +16,8 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. class AddLockVersion < ActiveRecord::Migration - def self.up - add_column(:code_reviews, "lock_version", :integer, :default=>0, :null => false) + add_column(:code_reviews, "lock_version", :integer, :default => 0, :null => false) end def self.down diff --git a/db/migrate/0004_add_status_changed.rb b/db/migrate/0004_add_status_changed.rb index ab110e1..d7b76bb 100644 --- a/db/migrate/0004_add_status_changed.rb +++ b/db/migrate/0004_add_status_changed.rb @@ -16,7 +16,6 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. class AddStatusChanged < ActiveRecord::Migration - def self.up add_column(:code_reviews, "status_changed_from", :integer) add_column(:code_reviews, "status_changed_to", :integer) diff --git a/db/migrate/0005_create_code_review_user_settings.rb b/db/migrate/0005_create_code_review_user_settings.rb index e61a2a3..7e2a9c7 100644 --- a/db/migrate/0005_create_code_review_user_settings.rb +++ b/db/migrate/0005_create_code_review_user_settings.rb @@ -17,15 +17,13 @@ class CreateCodeReviewUserSettings < ActiveRecord::Migration def self.up create_table :code_review_user_settings do |t| + t.column :user_id, :integer, :default => 0, :null => false - t.column :user_id, :integer, :default=>0, :null => false - - t.column :mail_notification, :integer, :default=>0, :null => false + t.column :mail_notification, :integer, :default => 0, :null => false t.column :created_at, :timestamp t.column :updated_at, :timestamp - end end diff --git a/db/migrate/0006_link_to_issue.rb b/db/migrate/0006_link_to_issue.rb index 9d3ecb7..2ddd72e 100644 --- a/db/migrate/0006_link_to_issue.rb +++ b/db/migrate/0006_link_to_issue.rb @@ -16,7 +16,6 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. class LinkToIssue < ActiveRecord::Migration - def self.up add_column(:code_reviews, "issue_id", :integer) rename_column(:code_reviews, "status", "old_status") diff --git a/db/migrate/0007_rename_user.rb b/db/migrate/0007_rename_user.rb index 6a66866..dee4ed7 100644 --- a/db/migrate/0007_rename_user.rb +++ b/db/migrate/0007_rename_user.rb @@ -16,12 +16,11 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. class RenameUser < ActiveRecord::Migration - def self.up rename_column(:code_reviews, "user_id", "old_user_id") end def self.down - rename_column(:code_reviews, "old_user_id", "user_id") + rename_column(:code_reviews, "old_user_id", "user_id") end end diff --git a/db/migrate/0008_create_code_review_project_settings.rb b/db/migrate/0008_create_code_review_project_settings.rb index 5bfdc8a..05b678f 100644 --- a/db/migrate/0008_create_code_review_project_settings.rb +++ b/db/migrate/0008_create_code_review_project_settings.rb @@ -17,7 +17,6 @@ class CreateCodeReviewProjectSettings < ActiveRecord::Migration def self.up create_table :code_review_project_settings do |t| - t.column :project_id, :integer t.column :tracker_id, :integer @@ -27,7 +26,6 @@ def self.up t.column :updated_at, :timestamp t.column :updated_by, :integer - end end diff --git a/db/migrate/0009_add_hide_tab.rb b/db/migrate/0009_add_hide_tab.rb index ca09e29..8ba0c2b 100644 --- a/db/migrate/0009_add_hide_tab.rb +++ b/db/migrate/0009_add_hide_tab.rb @@ -16,7 +16,6 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. class AddHideTab < ActiveRecord::Migration - def self.up add_column(:code_review_project_settings, "hide_code_review_tab", :boolean, :default => false) end diff --git a/db/migrate/0010_add_action_type.rb b/db/migrate/0010_add_action_type.rb index a64e306..17e8f61 100644 --- a/db/migrate/0010_add_action_type.rb +++ b/db/migrate/0010_add_action_type.rb @@ -16,7 +16,6 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. class AddActionType < ActiveRecord::Migration - def self.up add_column(:code_reviews, "action_type", :string) add_column(:code_reviews, "file_path", :string) diff --git a/db/migrate/0011_add_auto_relation.rb b/db/migrate/0011_add_auto_relation.rb index ee8fe73..3afaf15 100644 --- a/db/migrate/0011_add_auto_relation.rb +++ b/db/migrate/0011_add_auto_relation.rb @@ -16,12 +16,11 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. class AddAutoRelation < ActiveRecord::Migration - def self.up add_column(:code_review_project_settings, "auto_relation", :integer, :default => 1) end def self.down - remove_column(:code_review_project_settings, "auto_relation") + remove_column(:code_review_project_settings, "auto_relation") end end diff --git a/db/migrate/0012_add_attachment_id.rb b/db/migrate/0012_add_attachment_id.rb index ec2e7a0..0fa7050 100644 --- a/db/migrate/0012_add_attachment_id.rb +++ b/db/migrate/0012_add_attachment_id.rb @@ -16,7 +16,6 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. class AddAttachmentId < ActiveRecord::Migration - def self.up add_column(:code_reviews, "attachment_id", :integer) end diff --git a/db/migrate/0013_add_file_count.rb b/db/migrate/0013_add_file_count.rb index 464d046..968d396 100644 --- a/db/migrate/0013_add_file_count.rb +++ b/db/migrate/0013_add_file_count.rb @@ -16,7 +16,6 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. class AddFileCount < ActiveRecord::Migration - def self.up add_column(:code_reviews, "file_count", :integer, :default => 0, :null => false) end diff --git a/db/migrate/0014_create_code_review_assignments.rb b/db/migrate/0014_create_code_review_assignments.rb index a582d31..ceb68e8 100644 --- a/db/migrate/0014_create_code_review_assignments.rb +++ b/db/migrate/0014_create_code_review_assignments.rb @@ -18,7 +18,6 @@ class CreateCodeReviewAssignments < ActiveRecord::Migration def self.up create_table :code_review_assignments do |t| - t.column :issue_id, :int t.column :change_id, :int @@ -32,7 +31,6 @@ def self.up t.column :rev_to, :string t.column :action_type, :string - end end diff --git a/db/migrate/0015_add_assignment_tracker.rb b/db/migrate/0015_add_assignment_tracker.rb index 08567e2..f79609d 100644 --- a/db/migrate/0015_add_assignment_tracker.rb +++ b/db/migrate/0015_add_assignment_tracker.rb @@ -16,7 +16,6 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. class AddAssignmentTracker < ActiveRecord::Migration - def self.up add_column(:code_review_project_settings, "assignment_tracker_id", :integer) end diff --git a/db/migrate/0016_add_changeset_id.rb b/db/migrate/0016_add_changeset_id.rb index 96536e8..1473115 100644 --- a/db/migrate/0016_add_changeset_id.rb +++ b/db/migrate/0016_add_changeset_id.rb @@ -16,7 +16,6 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. class AddChangesetId < ActiveRecord::Migration - def self.up add_column(:code_review_assignments, "changeset_id", :integer) end diff --git a/db/migrate/0017_add_auto_assign.rb b/db/migrate/0017_add_auto_assign.rb index 6e9c6fe..80dec4d 100644 --- a/db/migrate/0017_add_auto_assign.rb +++ b/db/migrate/0017_add_auto_assign.rb @@ -16,7 +16,6 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. class AddAutoAssign < ActiveRecord::Migration - def self.up add_column(:code_review_project_settings, "auto_assign", :text) end diff --git a/db/migrate/0018_add_lock_version_to_project_settings.rb b/db/migrate/0018_add_lock_version_to_project_settings.rb index c6ba8cf..6a2d56f 100644 --- a/db/migrate/0018_add_lock_version_to_project_settings.rb +++ b/db/migrate/0018_add_lock_version_to_project_settings.rb @@ -16,7 +16,6 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. class AddLockVersionToProjectSettings < ActiveRecord::Migration - def self.up add_column(:code_review_project_settings, "lock_version", :integer, :null => false, :default => 0) end diff --git a/db/migrate/0019_delete_old_fields.rb b/db/migrate/0019_delete_old_fields.rb index ab9744b..7e25ff1 100644 --- a/db/migrate/0019_delete_old_fields.rb +++ b/db/migrate/0019_delete_old_fields.rb @@ -16,7 +16,7 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. class DeleteOldFields < ActiveRecord::Migration - OLD_FIELDS=["old_parent_id", "old_user_id", "old_comment", "old_status"] + OLD_FIELDS = ["old_parent_id", "old_user_id", "old_comment", "old_status"] def self.up remove_column(:code_reviews, "old_parent_id") remove_column(:code_reviews, "old_user_id") diff --git a/db/migrate/0020_add_tracker_to_review_dialog.rb b/db/migrate/0020_add_tracker_to_review_dialog.rb index 8b9daa4..d29d258 100644 --- a/db/migrate/0020_add_tracker_to_review_dialog.rb +++ b/db/migrate/0020_add_tracker_to_review_dialog.rb @@ -15,9 +15,7 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - class AddTrackerToReviewDialog < ActiveRecord::Migration - def self.up add_column(:code_review_project_settings, "tracker_in_review_dialog", :boolean, :default => false) end @@ -25,4 +23,4 @@ def self.up def self.down remove_column(:code_review_project_settings, "tracker_in_review_dialog") end -end \ No newline at end of file +end diff --git a/db/migrate/0021_add_diff_all.rb b/db/migrate/0021_add_diff_all.rb index 44ee539..d89e68c 100644 --- a/db/migrate/0021_add_diff_all.rb +++ b/db/migrate/0021_add_diff_all.rb @@ -23,4 +23,4 @@ def self.up def self.down remove_column(:code_reviews, "diff_all") end -end \ No newline at end of file +end diff --git a/init.rb b/init.rb index 1d35765..9472cc0 100644 --- a/init.rb +++ b/init.rb @@ -48,7 +48,6 @@ unless Attachment.included_modules.include? CodeReviewAttachmentPatch Attachment.send(:include, CodeReviewAttachmentPatch) end - end Redmine::Plugin.register :redmine_code_review do @@ -67,15 +66,13 @@ permission :delete_code_review, {:code_review => [:destroy]}, :require => :member permission :assign_code_review, {:code_review => [:assign]}, :require => :member permission :code_review_setting, {:code_review_settings => [:show, :update, :add_filter, :edit_filter, :sort]}, :require => :member - end - menu :project_menu, :code_review, { :controller => 'code_review', :action => 'index' }, :caption => :code_reviews, - :if => Proc.new{|project| - setting = CodeReviewProjectSetting.find_or_create(project) - project.repository != nil and setting and !setting.hide_code_review_tab - }, :after => :repository - + menu :project_menu, :code_review, {:controller => 'code_review', :action => 'index'}, :caption => :code_reviews, + :if => Proc.new { |project| + setting = CodeReviewProjectSetting.find_or_create(project) + project.repository != nil and setting and !setting.hide_code_review_tab + }, :after => :repository Redmine::WikiFormatting::Macros.register do desc "This is my macro link to code review" @@ -86,8 +83,6 @@ review = CodeReview.find(review_id) return nil unless review link_to(l(:label_review) + '#' + review.id.to_s, :controller => 'code_review', :action => 'show', :id => review.project, :review_id => review.id) - end end - end diff --git a/lib/code_review_application_hooks.rb b/lib/code_review_application_hooks.rb index 5e7b0a4..af9c87f 100644 --- a/lib/code_review_application_hooks.rb +++ b/lib/code_review_application_hooks.rb @@ -16,6 +16,7 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. require 'redmine/utils' + class CodeReviewApplicationHooks < Redmine::Hook::ViewListener render_on :view_layouts_base_html_head, :partial => 'code_review/html_header' render_on :view_layouts_base_body_bottom, :partial => 'code_review/body_bottom' diff --git a/lib/code_review_attachment_patch.rb b/lib/code_review_attachment_patch.rb index 1b1ccb1..41c2047 100644 --- a/lib/code_review_attachment_patch.rb +++ b/lib/code_review_attachment_patch.rb @@ -25,14 +25,9 @@ def self.included(base) # :nodoc: unloadable # Send unloadable so it will not be unloaded in development has_many :code_reviews has_many :code_review_assignments - end - end end module AttachmentInstanceMethodsCodeReview - end - - diff --git a/lib/code_review_auto_assign_settings.rb b/lib/code_review_auto_assign_settings.rb index 5dd5b97..2c58c2a 100644 --- a/lib/code_review_auto_assign_settings.rb +++ b/lib/code_review_auto_assign_settings.rb @@ -21,7 +21,7 @@ def initialize(yml_string = nil) yml_string = {:enabled => false}.to_yaml if yml_string.blank? load_yml(yml_string) end - + def self.load(yml_string) AutoAssignSettings.new(yml_string) end @@ -49,7 +49,7 @@ def assignable_list=(list) def assignable_list return nil unless yml[:assignable_list] - yml[:assignable_list].collect { |id| id.to_i } + yml[:assignable_list].collect { |id| id.to_i } end def assignable?(user) @@ -86,7 +86,6 @@ def filter_enabled? yml[:filter_enabled] == true or yml[:filter_enabled] == 'true' end - def to_s return YAML.dump(yml) nil @@ -94,7 +93,7 @@ def to_s def filters=(list) unless list - return yml[:filters] = nil + return yml[:filters] = nil end yml[:filters] = list.collect do |filter| filter.attributes @@ -105,10 +104,10 @@ def filters return [] unless yml[:filters] list = yml[:filters].collect do |hash| filter = AssignmentFilter.new - filter.attributes=(hash) + filter.attributes = (hash) filter end - list.sort {|a, b| a.order <=> b.order} + list.sort { |a, b| a.order <=> b.order } end def add_filter(filter) @@ -126,8 +125,8 @@ def accept_for_default def match_with_changeset?(changeset) return true unless filter_enabled? - changeset.filechanges.each{|change| - return if match_with_change?(change) + changeset.filechanges.each { |change| + return if match_with_change?(change) } return false end @@ -143,7 +142,7 @@ def match_with_change?(change) def attributes yml end - + private def yml @@ -161,7 +160,7 @@ def load_yml(yml_string) def select_assign_to_with_list(project, list, commiter_id = nil) return nil unless list return nil if list.empty? - list.collect!{|item| item.to_i} + list.collect! { |item| item.to_i } list.delete(commiter_id) return nil if list.empty? assign_to = list.at(rand(list.size)) diff --git a/lib/code_review_change_patch.rb b/lib/code_review_change_patch.rb index 95f9f9e..0e2ad96 100644 --- a/lib/code_review_change_patch.rb +++ b/lib/code_review_change_patch.rb @@ -26,9 +26,7 @@ def self.included(base) # :nodoc: has_many :code_reviews, :dependent => :destroy has_many :code_review_assignments, :dependent => :destroy after_save :review_auto_assign - end - end end @@ -37,7 +35,7 @@ module ChangeInstanceMethodsCodeReview # for review_issues # def review_count - code_reviews.select{|o| + code_reviews.select { |o| o.issue_id != nil }.length end @@ -55,7 +53,7 @@ def open_review_count def closed_review_count closed_reviews.length end - + def closed_reviews @closed_reviews ||= code_reviews.select do |o| o.issue_id != nil and o.is_closed? @@ -94,4 +92,3 @@ def review_auto_assign CodeReviewAssignment.create_with_changeset(changeset) end end - diff --git a/lib/code_review_changeset_patch.rb b/lib/code_review_changeset_patch.rb index c68d7a4..23ea08a 100644 --- a/lib/code_review_changeset_patch.rb +++ b/lib/code_review_changeset_patch.rb @@ -26,7 +26,6 @@ def self.included(base) # :nodoc: has_many :code_review_assignments, :dependent => :destroy alias_method_chain :scan_comment_for_issue_ids, :code_review end - end end @@ -37,7 +36,7 @@ module ChangesetInstanceMethodsCodeReview def review_count return @review_count if @review_count @review_count = 0 - filechanges.each{|change| + filechanges.each { |change| @review_count += change.review_count } return @review_count @@ -46,7 +45,7 @@ def review_count def open_review_count return @open_review_count if @open_review_count @open_review_count = 0 - filechanges.each{|change| + filechanges.each { |change| @open_review_count += change.open_review_count } return @open_review_count @@ -63,11 +62,11 @@ def open_reviews def review_issues return @review_issues if @review_issues - filechanges.each{|change| + filechanges.each { |change| unless @review_issues - @review_issues = change.code_reviews.collect{|issue| issue} + @review_issues = change.code_reviews.collect { |issue| issue } else - @review_issues = @review_issues + change.code_reviews.collect{|issue| issue} + @review_issues = @review_issues + change.code_reviews.collect { |issue| issue } end @review_issues } @@ -91,9 +90,9 @@ def completed_review_pourcent elsif open_review_count == 0 100 else - @completed_review_pourcent ||= (closed_review_count * 100 + open_reviews.collect{|o| + @completed_review_pourcent ||= (closed_review_count * 100 + open_reviews.collect { |o| o.issue.done_ratio - }.inject(:+))/review_count + }.inject(:+)) / review_count end end @@ -104,7 +103,7 @@ def completed_review_pourcent def assignment_count #return @assignment_count if @assignment_count @assignment_count = code_review_assignments.length - filechanges.each{|change| + filechanges.each { |change| @assignment_count += change.assignment_count } return @assignment_count @@ -112,10 +111,10 @@ def assignment_count def open_assignment_count return @open_assignment_count if @open_assignment_count - @open_assignment_count = code_review_assignments.select {|assignment| + @open_assignment_count = code_review_assignments.select { |assignment| !assignment.is_closed? }.length - filechanges.each{|change| + filechanges.each { |change| @open_assignment_count += change.open_assignment_count } return @open_assignment_count @@ -124,20 +123,19 @@ def open_assignment_count def assignment_issues return @assignment_issues if @assignment_issues @assignment_issues = code_review_assignments - filechanges.each{|change| - @assignment_issues = @assignment_issues + change.code_review_assignments.collect{|issue| issue} + filechanges.each { |change| + @assignment_issues = @assignment_issues + change.code_review_assignments.collect { |issue| issue } } @assignment_issues - end def open_assignments return @open_assignments if @open_assignments - @open_assignments = code_review_assignments.select {|assignment| + @open_assignments = code_review_assignments.select { |assignment| !assignment.is_closed? } - filechanges.each{|change| - @open_assignments = @open_assignments + change.code_review_assignments.select {|assignment| + filechanges.each { |change| + @open_assignments = @open_assignments + change.code_review_assignments.select { |assignment| !assignment.is_closed? } } @@ -162,10 +160,9 @@ def completed_assignment_pourcent 100 else opens = open_assignments - @completed_assignment_pourcent ||= (closed_assignment_count * 100 + open_assignments.collect{|o| + @completed_assignment_pourcent ||= (closed_assignment_count * 100 + open_assignments.collect { |o| o.issue.done_ratio - }.sum)/assignment_count - + }.sum) / assignment_count end end @@ -185,5 +182,3 @@ def scan_comment_for_issue_ids_with_code_review ret end end - - diff --git a/lib/code_review_issue_hooks.rb b/lib/code_review_issue_hooks.rb index f1326dd..aefd423 100644 --- a/lib/code_review_issue_hooks.rb +++ b/lib/code_review_issue_hooks.rb @@ -18,7 +18,8 @@ class CodeReviewIssueHooks < Redmine::Hook::ViewListener include RepositoriesHelper render_on :view_issues_show_details_bottom, :partial => 'code_review/issues_show_details_bottom' - def view_issues_show_details_bottom_org(context = { }) + + def view_issues_show_details_bottom_org(context = {}) project = context[:project] return '' unless project unless User.current.allowed_to?({:controller => 'code_review', :action => 'show'}, project) @@ -36,7 +37,7 @@ def view_issues_show_details_bottom_org(context = { }) return o end - def view_issues_form_details_bottom(context = { }) + def view_issues_form_details_bottom(context = {}) project = context[:project] request = context[:request] parameters = request.parameters @@ -58,11 +59,10 @@ def view_issues_form_details_bottom(context = { }) o << "\n" o << hidden_field_tag("code[attachment_id]", code[:attachment_id].to_i) unless code[:attachment_id].blank? - return o end - - def controller_issues_new_after_save(context = { }) + + def controller_issues_new_after_save(context = {}) if context[:request] && context[:project] && context[:issue] project = context[:project] request = context[:request] @@ -86,12 +86,13 @@ def controller_issues_new_after_save(context = { }) end private + def create_review_info(project, review) o = '' o << "#{l(:code_review)}:" o << '' o << link_to("#{review.repository_identifier + ':' if review.repository_identifier}#{review.path}#{'@' + review.revision if review.revision}:line #{review.line}", - :controller => 'code_review', :action => 'show', :id => project, :review_id => review.id, :repository_id => review.repository_identifier) + :controller => 'code_review', :action => 'show', :id => project, :review_id => review.id, :repository_id => review.repository_identifier) o << '' o << '' return o @@ -104,7 +105,7 @@ def create_assignment_info(project, assignment) o << '' if assignment.path o << link_to("#{repository_id + ':' if repository_id}#{assignment.path}#{'@' + assignment.revision if assignment.revision}", - :controller => 'code_review', :action => 'show', :id => project, :assignment_id => assignment.id, :repository_id => repository_id) + :controller => 'code_review', :action => 'show', :id => project, :assignment_id => assignment.id, :repository_id => repository_id) elsif assignment.revision repo = project unless repository_id repo ||= assignment.repository diff --git a/lib/code_review_issue_patch.rb b/lib/code_review_issue_patch.rb index e05ae8b..3a88259 100644 --- a/lib/code_review_issue_patch.rb +++ b/lib/code_review_issue_patch.rb @@ -25,14 +25,9 @@ def self.included(base) # :nodoc: unloadable # Send unloadable so it will not be unloaded in development has_one :code_review, :dependent => :destroy has_one :code_review_assignment, :dependent => :destroy - end - end end module IssueInstanceMethodsCodeReview - end - - diff --git a/lib/code_review_projects_helper_patch.rb b/lib/code_review_projects_helper_patch.rb index f167693..4fa33e8 100644 --- a/lib/code_review_projects_helper_patch.rb +++ b/lib/code_review_projects_helper_patch.rb @@ -26,7 +26,6 @@ def self.included(base) # :nodoc: alias_method_chain :project_settings_tabs, :code_review end - end end @@ -40,5 +39,3 @@ def project_settings_tabs_with_code_review tabs end end - - diff --git a/test/code_review_object_daddy_helpers.rb b/test/code_review_object_daddy_helpers.rb index 13c7ed0..9d17551 100644 --- a/test/code_review_object_daddy_helpers.rb +++ b/test/code_review_object_daddy_helpers.rb @@ -16,11 +16,11 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. module CodeReviewObjectDaddyHelpers - def CodeReview.generate_for_project!(project, attributes={}) - attributes[:comment] = 'test comment' unless attributes[:comment] - attributes[:issue] = Issue.generate_for_project!({:project => project, :description => attributes[:comment], :subject => 'test'}) unless attributes[:issue] - attributes[:project] = project - review = CodeReview.generate!(attributes) - review - end + def CodeReview.generate_for_project!(project, attributes = {}) + attributes[:comment] = 'test comment' unless attributes[:comment] + attributes[:issue] = Issue.generate_for_project!({:project => project, :description => attributes[:comment], :subject => 'test'}) unless attributes[:issue] + attributes[:project] = project + review = CodeReview.generate!(attributes) + review + end end diff --git a/test/exemplars/code_review_exemplar.rb b/test/exemplars/code_review_exemplar.rb index 565422f..0543491 100644 --- a/test/exemplars/code_review_exemplar.rb +++ b/test/exemplars/code_review_exemplar.rb @@ -23,11 +23,9 @@ class CodeReview < ActiveRecord::Base generator_for :action_type => 'diff' generator_for :line => 30 - def self.next_subject @last_subject ||= 'Code Review 0' @last_subject.succ! @last_subject end - end diff --git a/test/functional/attachments_controller_test.rb b/test/functional/attachments_controller_test.rb index d1279f1..e95cf34 100644 --- a/test/functional/attachments_controller_test.rb +++ b/test/functional/attachments_controller_test.rb @@ -21,33 +21,30 @@ # Re-raise errors caught by the controller. class AttachmentsController; def rescue_action(e) raise e end; end - class AttachmentsControllerTest < ActionController::TestCase fixtures :users, :projects, :roles, :members, :member_roles, :enabled_modules, :issues, :trackers, :attachments, :versions, :wiki_pages, :wikis, :documents - + def setup @controller = AttachmentsController.new - @request = ActionController::TestRequest.new - @response = ActionController::TestResponse.new + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new Attachment.storage_path = "#{Rails.root}/test/fixtures/files" - + [1, 2].each { |num| project = Project.find(num) project.enable_module!('code_review') project.save! } - roles = Role.all - roles.each {|role| + roles.each { |role| role.permissions << :view_code_review role.save } User.current = nil end - - + def test_show_diff @request.session[:user_id] = 1 attachment = FactoryGirl.create(:attachment, filename: "test.diff") @@ -56,7 +53,7 @@ def test_show_diff assert_template 'diff' assert_equal 'text/html', @response.content_type end - + def test_show_text_file @request.session[:user_id] = 1 attachment = FactoryGirl.create(:attachment, filename: "test.rb") @@ -65,5 +62,4 @@ def test_show_text_file assert_template 'file' assert_equal 'text/html', @response.content_type end - end diff --git a/test/functional/code_review_controller_test.rb b/test/functional/code_review_controller_test.rb index fdebc67..05c6716 100644 --- a/test/functional/code_review_controller_test.rb +++ b/test/functional/code_review_controller_test.rb @@ -18,14 +18,15 @@ class CodeReviewControllerTest < ActionController::TestCase fixtures :code_reviews, :projects, :users, :repositories, - :changesets, :changes, :members, :member_roles, :roles, :issues, :issue_statuses, - :enumerations, :issue_categories, :trackers, :projects, :projects_trackers, - :code_review_project_settings, :attachments, :code_review_assignments, - :code_review_user_settings + :changesets, :changes, :members, :member_roles, :roles, :issues, :issue_statuses, + :enumerations, :issue_categories, :trackers, :projects, :projects_trackers, + :code_review_project_settings, :attachments, :code_review_assignments, + :code_review_user_settings + def setup @controller = CodeReviewController.new - @request = ActionController::TestRequest.new - @response = ActionController::TestResponse.new + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new @request.env["HTTP_REFERER"] = '/' enabled_module = EnabledModule.new enabled_module.project_id = 1 @@ -38,7 +39,7 @@ def setup User.current = nil roles = Role.all - roles.each {|role| + roles.each { |role| role.permissions << :view_code_review role.save } @@ -62,7 +63,6 @@ def setup get :index, :id => 1, :show_closed => true assert_response :success end - end context "new" do @@ -77,7 +77,7 @@ def setup @request.session[:user_id] = 1 count = CodeReview.all.length post :new, :id => 1, :review => {:line => 1, :change_id => 1, - :comment => 'aaa', :subject => 'bbb'}, :action_type => 'diff' + :comment => 'aaa', :subject => 'bbb'}, :action_type => 'diff' assert_response :success assert_template '_add_success' assert_equal(count + 1, CodeReview.all.length) @@ -97,22 +97,22 @@ def setup changeset.save count = CodeReview.all.length post :new, :id => 1, :review => {:line => 1, :change_id => 3, - :comment => 'aaa', :subject => 'bbb'}, :action_type => 'diff' + :comment => 'aaa', :subject => 'bbb'}, :action_type => 'diff' assert_response :success assert_template '_add_success' assert_equal(count + 1, CodeReview.all.length) settings = CodeReviewProjectSetting.all - settings.each{|setting| + settings.each { |setting| setting.destroy } post :new, :id => 1, :review => {:line => 1, :change_id => 1, - :comment => 'aaa', :subject => 'bbb'}, :action_type => 'diff' + :comment => 'aaa', :subject => 'bbb'}, :action_type => 'diff' assert_response 200 end should "save safe_attributes" do - @request.session[:user_id] = 1 + @request.session[:user_id] = 1 project = Project.find(1) change = Change.find(3) changeset = change.changeset @@ -121,7 +121,7 @@ def setup changeset.save count = CodeReview.all.length post :new, :id => 1, :review => {:line => 10, :change_id => 3, - :comment => 'aaa', :subject => 'bbb', :parent_id => 1, :status_id => 1}, :action_type => 'diff' + :comment => 'aaa', :subject => 'bbb', :parent_id => 1, :status_id => 1}, :action_type => 'diff' assert_response :success assert_template '_add_success' @@ -141,7 +141,7 @@ def setup attachment = FactoryGirl.create(:attachment, container: issue) count = CodeReview.all.length post :new, :id => 1, :review => {:line => 1, :comment => 'aaa', - :subject => 'bbb', :attachment_id => attachment.id}, :action_type => 'diff' + :subject => 'bbb', :attachment_id => attachment.id}, :action_type => 'diff' assert_response :success assert_template '_add_success' assert_equal(count + 1, CodeReview.all.length) @@ -179,7 +179,6 @@ def test_destroy get :destroy, :id => 1, :review_id => review.id assert_response :success assert_equal(count - 1, CodeReview.all.length) - end context "reply" do @@ -188,7 +187,7 @@ def test_destroy review = CodeReview.find(9) get :reply, :id => 1, :review_id => 9, - :reply => {:comment => 'aaa'}, :issue=> {:lock_version => review.issue.lock_version} + :reply => {:comment => 'aaa'}, :issue => {:lock_version => review.issue.lock_version} assert_response :success assert_template '_show' assert_equal(nil, assigns(:error)) @@ -199,7 +198,7 @@ def test_destroy review = CodeReview.find(9) get :reply, :id => 1, :review_id => 9, - :reply => {:comment => 'aaa'}, :issue=> {:lock_version => review.issue.lock_version + 1} + :reply => {:comment => 'aaa'}, :issue => {:lock_version => review.issue.lock_version + 1} assert_response :success assert_template '_show' assert_not_nil assigns(:error) @@ -209,38 +208,38 @@ def test_destroy def test_reply_lock_error @request.session[:user_id] = 1 get :reply, :id => 1, :review_id => 9, - :reply => {:comment => 'aaa'}, :issue=> {:lock_version => 1} + :reply => {:comment => 'aaa'}, :issue => {:lock_version => 1} assert_response :success assert_template '_show' assert assigns(:error) end -# def test_close -# @request.session[:user_id] = 1 -# review_id = 9 -# review = CodeReview.find(review_id) -# review.reopen -# review.save -# assert !review.is_closed? -# get :close, :id => 1, :review_id => review_id -# assert_response :success -# assert_template '_show' -# review = CodeReview.find(review_id) -# assert review.is_closed? -# end -# -# def test_reopen -# @request.session[:user_id] = 1 -# review = CodeReview.find(1) -# review.close -# review.save -# assert review.is_closed? -# get :reopen, :id => 1, :review_id => 1 -# assert_response :success -# assert_template '_show' -# review = CodeReview.find(1) -# assert !review.is_closed? -# end + # def test_close + # @request.session[:user_id] = 1 + # review_id = 9 + # review = CodeReview.find(review_id) + # review.reopen + # review.save + # assert !review.is_closed? + # get :close, :id => 1, :review_id => review_id + # assert_response :success + # assert_template '_show' + # review = CodeReview.find(review_id) + # assert review.is_closed? + # end + # + # def test_reopen + # @request.session[:user_id] = 1 + # review = CodeReview.find(1) + # review.close + # review.save + # assert review.is_closed? + # get :reopen, :id => 1, :review_id => 1 + # assert_response :success + # assert_template '_show' + # review = CodeReview.find(1) + # assert !review.is_closed? + # end def test_update @request.session[:user_id] = 1 @@ -248,8 +247,8 @@ def test_update review = CodeReview.find(review_id) assert_equal('Unable to print recipes', review.comment) post :update, :id => 1, :review_id => review_id, - :review => {:comment => 'bbb', :lock_version => review.lock_version}, - :issue => {:lock_version => review.issue.lock_version} + :review => {:comment => 'bbb', :lock_version => review.lock_version}, + :issue => {:lock_version => review.issue.lock_version} assert_response :success review = CodeReview.find(review_id) assert_equal('bbb', review.comment) @@ -261,8 +260,8 @@ def test_update_lock_error review = CodeReview.find(review_id) assert_equal('Unable to print recipes', review.comment) post :update, :id => 1, :review_id => review_id, - :review => {:comment => 'bbb', :lock_version => review.lock_version}, - :issue => {:lock_version => 1} + :review => {:comment => 'bbb', :lock_version => review.lock_version}, + :issue => {:lock_version => 1} assert_response :success review = CodeReview.find(review_id) assert_equal('Unable to print recipes', review.comment) diff --git a/test/functional/code_review_settings_controller_test.rb b/test/functional/code_review_settings_controller_test.rb index a1f8fe5..faacc83 100644 --- a/test/functional/code_review_settings_controller_test.rb +++ b/test/functional/code_review_settings_controller_test.rb @@ -21,10 +21,11 @@ class CodeReviewSettingsControllerTest < ActionController::TestCase :code_review_project_settings, :issues, :issue_statuses, :enumerations include CodeReviewAutoAssignSettings + def setup @controller = CodeReviewSettingsController.new - @request = ActionController::TestRequest.new - @response = ActionController::TestResponse.new + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new @request.env["HTTP_REFERER"] = '/' enabled_module = EnabledModule.new enabled_module.project_id = 1 @@ -38,13 +39,12 @@ def setup User.current = nil roles = Role.all - roles.each {|role| + roles.each { |role| role.permissions << :view_code_review role.save } end - context "update" do setup do @request.session[:user_id] = 1 @@ -57,13 +57,12 @@ def setup end should "save settings" do - @request.session[:user_id] = 1 setting = CodeReviewProjectSetting.find(1) - post :update, :id => 1, :setting => {:tracker_id => 2, :assignment_tracker_id => 3, - :hide_code_review_tab => true, :auto_relation => CodeReviewProjectSetting::AUTORELATION_TYPE_BLOCKS}, - :auto_assign => {:filters => {:a => 1}} + post :update, :id => 1, :setting => {:tracker_id => 2, :assignment_tracker_id => 3, + :hide_code_review_tab => true, :auto_relation => CodeReviewProjectSetting::AUTORELATION_TYPE_BLOCKS}, + :auto_assign => {:filters => {:a => 1}} assert_response :redirect project = Project.find(1) assert_redirected_to :controller => 'projects', :action => 'settings', :id => project, :tab => 'code_review' @@ -77,7 +76,7 @@ def setup assert_equal(CodeReviewProjectSetting::AUTORELATION_TYPE_BLOCKS, setting.auto_relation) get :update, :id => 1, :setting => {:tracker_id => 1, :id => setting.id}, :convert => 'true', - :auto_assign => {} + :auto_assign => {} assert_response :redirect project = Project.find(1) assert_redirected_to :controller => 'projects', :action => 'settings', :id => project, :tab => 'code_review' @@ -120,19 +119,18 @@ def setup end should "update filter" do - filter = AssignmentFilter.new filter.expression = 'aaa' filter.order = 10 filter.accept = true - + filter2 = AssignmentFilter.new filter2.expression = 'bbb' filter2.order = 10 filter2.accept = false post :edit_filter, :id => @project.id, :auto_assign => @setting.auto_assign_settings.attributes.merge(:filters => {'0' => filter.attributes}), :num => 0, - :auto_assign_edit_filter => {'0' => filter2.attributes} + :auto_assign_edit_filter => {'0' => filter2.attributes} @auto_assign = assigns(:auto_assign) assert_not_nil @auto_assign assert_equal(1, @auto_assign.filters.length) @@ -166,30 +164,29 @@ def setup @filters['1'] = filter.attributes @filters['2'] = filter2.attributes @filters['3'] = filter2.attributes - end - should "sort filters" do + should "sort filters" do post :sort, :id => @project.id, :auto_assign => @setting.auto_assign_settings.attributes.merge(:filters => @filters), :num => 0, - :auto_assign_filter => {:num => 2, :move_to => 'highest'} + :auto_assign_filter => {:num => 2, :move_to => 'highest'} @auto_assign = assigns(:auto_assign) assert_not_nil @auto_assign assert_response :success post :sort, :id => @project.id, :auto_assign => @setting.auto_assign_settings.attributes.merge(:filters => @filters), :num => 0, - :auto_assign_filter => {:num => 2, :move_to => 'higher'} + :auto_assign_filter => {:num => 2, :move_to => 'higher'} @auto_assign = assigns(:auto_assign) assert_not_nil @auto_assign assert_response :success post :sort, :id => @project.id, :auto_assign => @setting.auto_assign_settings.attributes.merge(:filters => @filters), :num => 0, - :auto_assign_filter => {:num => 2, :move_to => 'lowest'} + :auto_assign_filter => {:num => 2, :move_to => 'lowest'} @auto_assign = assigns(:auto_assign) assert_not_nil @auto_assign assert_response :success post :sort, :id => @project.id, :auto_assign => @setting.auto_assign_settings.attributes.merge(:filters => @filters), :num => 0, - :auto_assign_filter => {:num => 2, :move_to => 'lower'} + :auto_assign_filter => {:num => 2, :move_to => 'lower'} @auto_assign = assigns(:auto_assign) assert_not_nil @auto_assign assert_response :success diff --git a/test/functional/issues_controller_test.rb b/test/functional/issues_controller_test.rb index eca63ea..85e7477 100644 --- a/test/functional/issues_controller_test.rb +++ b/test/functional/issues_controller_test.rb @@ -43,11 +43,11 @@ class IssuesControllerTest < ActionController::TestCase :journals, :journal_details, :code_reviews - + def setup @controller = IssuesController.new - @request = ActionController::TestRequest.new - @response = ActionController::TestResponse.new + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new User.current = nil enabled_module = EnabledModule.new enabled_module.project_id = 1 @@ -58,7 +58,7 @@ def setup enabled_module.name = 'code_review' enabled_module.save roles = Role.all - roles.each {|role| + roles.each { |role| role.permissions << :view_code_review role.save } @@ -77,26 +77,25 @@ def test_show issue = Issue.generate!(:project => Project.find(1)) assignment = FactoryGirl.create(:code_review_assignment, issue: issue, rev: 'aaa', file_path: '/aaa/bbb') get :show, :id => assignment.issue.id - + review = FactoryGirl.create(:code_review, project: project) get :show, :id => review.issue.id - end def test_new @request.session[:user_id] = 1 get :new, :project_id => 1 assert_response :success - get :new, :project_id => 1, :code =>{:rev => 1, :rev_to => 2, :path => '/aaa/bbb', :action_type => 'diff'} + get :new, :project_id => 1, :code => {:rev => 1, :rev_to => 2, :path => '/aaa/bbb', :action_type => 'diff'} assert_response :success post :new, :project_id => 1, - :issue => {:tracker_id => 1, :status_id => 1, :subject => 'hoge'}, - :code =>{:rev => 1, :rev_to => 2, :path => '/aaa/bbb', :action_type => 'diff'} + :issue => {:tracker_id => 1, :status_id => 1, :subject => 'hoge'}, + :code => {:rev => 1, :rev_to => 2, :path => '/aaa/bbb', :action_type => 'diff'} # TODO: 0.9.xのサポート終了時に以下を有効にする。 #assert_response :SUCESS end - + context "create" do should "create code_review_assignment." do @request.session[:user_id] = 1 diff --git a/test/functional/projects_controller_test.rb b/test/functional/projects_controller_test.rb index 99b1701..37a622d 100644 --- a/test/functional/projects_controller_test.rb +++ b/test/functional/projects_controller_test.rb @@ -24,8 +24,8 @@ class ProjectsControllerTest < ActionController::TestCase def setup @controller = ProjectsController.new - @request = ActionController::TestRequest.new - @response = ActionController::TestResponse.new + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new end context "#settings" do @@ -54,9 +54,9 @@ def setup assert_response :success assert_template 'settings' assert_no_tag :div, :attributes => {:class => 'tabs'}, - :descendant => {:tag => 'ul', - :descendant => {:tag => 'li', - :descendant => {:tag => 'a', :attributes => {:id => 'tab-code_review'}}}} + :descendant => {:tag => 'ul', + :descendant => {:tag => 'li', + :descendant => {:tag => 'a', :attributes => {:id => 'tab-code_review'}}}} end should "not exist tag id post" do @@ -64,9 +64,9 @@ def setup assert_response :success assert_template 'settings' assert_no_tag :div, :attributes => {:class => 'tabs'}, - :descendant => {:tag => 'ul', - :descendant => {:tag => 'li', - :descendant => {:tag => 'a', :attributes => {:id => 'tab-code_review'}}}} + :descendant => {:tag => 'ul', + :descendant => {:tag => 'li', + :descendant => {:tag => 'a', :attributes => {:id => 'tab-code_review'}}}} end context "and module" do @@ -79,9 +79,9 @@ def setup assert_response :success assert_template 'settings' assert_no_tag :div, :attributes => {:class => 'tabs'}, - :descendant => {:tag => 'ul', - :descendant => {:tag => 'li', - :descendant => {:tag => 'a', :attributes => {:id => 'tab-code_review'}}}} + :descendant => {:tag => 'ul', + :descendant => {:tag => 'li', + :descendant => {:tag => 'a', :attributes => {:id => 'tab-code_review'}}}} end should "not exist tag id post" do @@ -89,9 +89,9 @@ def setup assert_response :success assert_template 'settings' assert_no_tag :div, :attributes => {:class => 'tabs'}, - :descendant => {:tag => 'ul', - :descendant => {:tag => 'li', - :descendant => {:tag => 'a', :attributes => {:id => 'tab-code_review'}}}} + :descendant => {:tag => 'ul', + :descendant => {:tag => 'li', + :descendant => {:tag => 'a', :attributes => {:id => 'tab-code_review'}}}} end end end @@ -122,9 +122,9 @@ def setup assert_response :success assert_template 'settings' assert_no_tag :div, :attributes => {:class => 'tabs'}, - :descendant => {:tag => 'ul', - :descendant => {:tag => 'li', - :descendant => {:tag => 'a', :attributes => {:id => 'tab-code_review'}}}} + :descendant => {:tag => 'ul', + :descendant => {:tag => 'li', + :descendant => {:tag => 'a', :attributes => {:id => 'tab-code_review'}}}} end should "not exist tag id post" do @@ -132,9 +132,9 @@ def setup assert_response :success assert_template 'settings' assert_no_tag :div, :attributes => {:class => 'tabs'}, - :descendant => {:tag => 'ul', - :descendant => {:tag => 'li', - :descendant => {:tag => 'a', :attributes => {:id => 'tab-code_review'}}}} + :descendant => {:tag => 'ul', + :descendant => {:tag => 'li', + :descendant => {:tag => 'a', :attributes => {:id => 'tab-code_review'}}}} end context "and module" do @@ -147,9 +147,9 @@ def setup assert_response :success assert_template 'settings' assert_no_tag :div, :attributes => {:class => 'tabs'}, - :descendant => {:tag => 'ul', - :descendant => {:tag => 'li', - :descendant => {:tag => 'a', :attributes => {:id => 'tab-code_review'}}}} + :descendant => {:tag => 'ul', + :descendant => {:tag => 'li', + :descendant => {:tag => 'a', :attributes => {:id => 'tab-code_review'}}}} end should "not exist tag id post" do @@ -157,9 +157,9 @@ def setup assert_response :success assert_template 'settings' assert_no_tag :div, :attributes => {:class => 'tabs'}, - :descendant => {:tag => 'ul', - :descendant => {:tag => 'li', - :descendant => {:tag => 'a', :attributes => {:id => 'tab-code_review'}}}} + :descendant => {:tag => 'ul', + :descendant => {:tag => 'li', + :descendant => {:tag => 'a', :attributes => {:id => 'tab-code_review'}}}} end end end @@ -176,9 +176,9 @@ def setup assert_response :success assert_template 'settings' assert_no_tag :div, :attributes => {:class => 'tabs'}, - :descendant => {:tag => 'ul', - :descendant => {:tag => 'li', - :descendant => {:tag => 'a', :attributes => {:id => 'tab-code_review'}}}} + :descendant => {:tag => 'ul', + :descendant => {:tag => 'li', + :descendant => {:tag => 'a', :attributes => {:id => 'tab-code_review'}}}} end should "not exist tag id post" do @@ -186,9 +186,9 @@ def setup assert_response :success assert_template 'settings' assert_no_tag :div, :attributes => {:class => 'tabs'}, - :descendant => {:tag => 'ul', - :descendant => {:tag => 'li', - :descendant => {:tag => 'a', :attributes => {:id => 'tab-code_review'}}}} + :descendant => {:tag => 'ul', + :descendant => {:tag => 'li', + :descendant => {:tag => 'a', :attributes => {:id => 'tab-code_review'}}}} end context "with permission" do @@ -201,9 +201,9 @@ def setup assert_response :success assert_template 'settings' assert_no_tag :div, :attributes => {:class => 'tabs'}, - :descendant => {:tag => 'ul', - :descendant => {:tag => 'li', - :descendant => {:tag => 'a', :attributes => {:id => 'tab-code_review'}}}} + :descendant => {:tag => 'ul', + :descendant => {:tag => 'li', + :descendant => {:tag => 'a', :attributes => {:id => 'tab-code_review'}}}} end should "not exist tag id post" do @@ -211,9 +211,9 @@ def setup assert_response :success assert_template 'settings' assert_no_tag :div, :attributes => {:class => 'tabs'}, - :descendant => {:tag => 'ul', - :descendant => {:tag => 'li', - :descendant => {:tag => 'a', :attributes => {:id => 'tab-code_review'}}}} + :descendant => {:tag => 'ul', + :descendant => {:tag => 'li', + :descendant => {:tag => 'a', :attributes => {:id => 'tab-code_review'}}}} end context "and module" do @@ -226,9 +226,9 @@ def setup assert_response :success assert_template 'settings' assert_no_tag :div, :attributes => {:class => 'tabs'}, - :descendant => {:tag => 'ul', - :descendant => {:tag => 'li', - :descendant => {:tag => 'a', :attributes => {:id => 'tab-code_review'}}}} + :descendant => {:tag => 'ul', + :descendant => {:tag => 'li', + :descendant => {:tag => 'a', :attributes => {:id => 'tab-code_review'}}}} end should "not exist tag id post" do @@ -236,9 +236,9 @@ def setup assert_response :success assert_template 'settings' assert_no_tag :div, :attributes => {:class => 'tabs'}, - :descendant => {:tag => 'ul', - :descendant => {:tag => 'li', - :descendant => {:tag => 'a', :attributes => {:id => 'tab-code_review'}}}} + :descendant => {:tag => 'ul', + :descendant => {:tag => 'li', + :descendant => {:tag => 'a', :attributes => {:id => 'tab-code_review'}}}} end end end @@ -255,9 +255,9 @@ def setup assert_response :success assert_template 'settings' assert_no_tag :div, :attributes => {:class => 'tabs'}, - :descendant => {:tag => 'ul', - :descendant => {:tag => 'li', - :descendant => {:tag => 'a', :attributes => {:id => 'tab-code_review'}}}} + :descendant => {:tag => 'ul', + :descendant => {:tag => 'li', + :descendant => {:tag => 'a', :attributes => {:id => 'tab-code_review'}}}} end should "not exist tag id post" do @@ -265,9 +265,9 @@ def setup assert_response :success assert_template 'settings' assert_no_tag :div, :attributes => {:class => 'tabs'}, - :descendant => {:tag => 'ul', - :descendant => {:tag => 'li', - :descendant => {:tag => 'a', :attributes => {:id => 'tab-code_review'}}}} + :descendant => {:tag => 'ul', + :descendant => {:tag => 'li', + :descendant => {:tag => 'a', :attributes => {:id => 'tab-code_review'}}}} end context "with permission" do @@ -280,9 +280,9 @@ def setup assert_response :success assert_template 'settings' assert_no_tag :div, :attributes => {:class => 'tabs'}, - :descendant => {:tag => 'ul', - :descendant => {:tag => 'li', - :descendant => {:tag => 'a', :attributes => {:id => 'tab-code_review'}}}} + :descendant => {:tag => 'ul', + :descendant => {:tag => 'li', + :descendant => {:tag => 'a', :attributes => {:id => 'tab-code_review'}}}} end should "not exist tag id post" do @@ -290,9 +290,9 @@ def setup assert_response :success assert_template 'settings' assert_no_tag :div, :attributes => {:class => 'tabs'}, - :descendant => {:tag => 'ul', - :descendant => {:tag => 'li', - :descendant => {:tag => 'a', :attributes => {:id => 'tab-code_review'}}}} + :descendant => {:tag => 'ul', + :descendant => {:tag => 'li', + :descendant => {:tag => 'a', :attributes => {:id => 'tab-code_review'}}}} end context "and module" do @@ -305,9 +305,9 @@ def setup assert_response :success assert_template 'settings' assert_tag :div, :attributes => {:class => 'tabs'}, - :descendant => {:tag => 'ul', - :descendant => {:tag => 'li', - :descendant => {:tag => 'a', :attributes => {:id => 'tab-code_review'}}}} + :descendant => {:tag => 'ul', + :descendant => {:tag => 'li', + :descendant => {:tag => 'a', :attributes => {:id => 'tab-code_review'}}}} end should "exist tag id post" do @@ -315,9 +315,9 @@ def setup assert_response :success assert_template 'settings' assert_tag :div, :attributes => {:class => 'tabs'}, - :descendant => {:tag => 'ul', - :descendant => {:tag => 'li', - :descendant => {:tag => 'a', :attributes => {:id => 'tab-code_review'}}}} + :descendant => {:tag => 'ul', + :descendant => {:tag => 'li', + :descendant => {:tag => 'a', :attributes => {:id => 'tab-code_review'}}}} end end end diff --git a/test/functional/repositories_controller_test.rb b/test/functional/repositories_controller_test.rb index 45385d8..02ec5f5 100644 --- a/test/functional/repositories_controller_test.rb +++ b/test/functional/repositories_controller_test.rb @@ -18,14 +18,13 @@ require File.expand_path(File.dirname(__FILE__) + '/../test_helper') require 'repositories_controller' - class RepositoriesControllerTest < ActionController::TestCase fixtures :projects, :users, :roles, :members, :repositories, :issues, :issue_statuses, :changesets, :changes, :issue_categories, :enumerations, :custom_fields, :custom_values, :trackers - + def setup @controller = RepositoriesController.new - @request = ActionController::TestRequest.new - @response = ActionController::TestResponse.new + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new User.current = nil enabled_module = EnabledModule.new enabled_module.project_id = 1 @@ -46,7 +45,7 @@ def setup User.current = nil roles = Role.all - roles.each {|role| + roles.each { |role| role.permissions << :view_code_review role.permissions << :add_code_review role.permissions << :browse_repository @@ -78,7 +77,7 @@ def test_show get :show, :id => 1 assert_response :success end - + def test_diff @request.session[:user_id] = 1 get :diff, :id => 1, :path => '/subversion_test/helloworld.c'.split('/'), :rev => 8 diff --git a/test/test_helper.rb b/test/test_helper.rb index e0fbbe3..287814a 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -15,7 +15,6 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - require 'simplecov' require 'simplecov-rcov' require 'coveralls' @@ -46,10 +45,8 @@ def mock_file end FactoryGirl.define do - factory :attachment do - - container{ + container { Project.find(1) } file { @@ -78,7 +75,7 @@ def mock_file factory :changeset do sequence(:revision, 1000) - committed_on{ + committed_on { Date.today } #association :repository @@ -95,7 +92,7 @@ def mock_file action { "A" } - sequence(:path){ |n| + sequence(:path) { |n| "test/dir/aaa#{n}" } changeset { @@ -109,7 +106,7 @@ def mock_file factory :issue do subject 'hoge' - author{ + author { User.find(1) } end @@ -128,7 +125,5 @@ def mock_file end factory :enabled_module do - end - -end \ No newline at end of file +end diff --git a/test/test_runner.rb b/test/test_runner.rb index eaec046..f74ef8b 100644 --- a/test/test_runner.rb +++ b/test/test_runner.rb @@ -15,7 +15,6 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - require 'simplecov' require 'simplecov-rcov' SimpleCov.formatter = SimpleCov::Formatter::RcovFormatter @@ -28,10 +27,10 @@ require "#{testdir}/test_helper" -Dir::glob("#{testdir}/fixtures/*.yml").each {|f| +Dir::glob("#{testdir}/fixtures/*.yml").each { |f| FileUtils.copy(f, "#{testdir}/../../../test/fixtures/") } -Dir::glob("#{testdir}/**/*test.rb").each {|f| +Dir::glob("#{testdir}/**/*test.rb").each { |f| require f -} \ No newline at end of file +} diff --git a/test/unit/code_review_assignment_test.rb b/test/unit/code_review_assignment_test.rb index 976196a..03774da 100644 --- a/test/unit/code_review_assignment_test.rb +++ b/test/unit/code_review_assignment_test.rb @@ -25,7 +25,7 @@ class CodeReviewAssignmentTest < ActiveSupport::TestCase def setup @assignment = CodeReviewAssignment.new end - + context "is_closed?" do should "return false if assignment issue is not closed." do @assignment.issue = Issue.new @@ -100,5 +100,4 @@ def setup assert_equal('123 5001 foo 456', assignment.issue.subject) end end - end diff --git a/test/unit/code_review_attachment_patch_test.rb b/test/unit/code_review_attachment_patch_test.rb index 2eba3a7..faa39c9 100644 --- a/test/unit/code_review_attachment_patch_test.rb +++ b/test/unit/code_review_attachment_patch_test.rb @@ -26,7 +26,7 @@ def setup @issue = Issue.where(:project_id => 1).first @attachment = FactoryGirl.create(:attachment, container: @issue) end - + context "code_review_assginments" do should "returns empty array if attachment has no assignments" do assert_not_nil(@attachment.code_review_assignments) diff --git a/test/unit/code_review_auto_assign_settings_test.rb b/test/unit/code_review_auto_assign_settings_test.rb index b2b4cff..9a26251 100644 --- a/test/unit/code_review_auto_assign_settings_test.rb +++ b/test/unit/code_review_auto_assign_settings_test.rb @@ -19,18 +19,17 @@ class CodeReviewAtuoAssignSettingsTest < ActiveSupport::TestCase fixtures :code_reviews, :projects, :users, :repositories, - :changesets, :changes, :members, :member_roles, :roles, :issues, :issue_statuses, - :enumerations, :issue_categories, :trackers, :projects, :projects_trackers, - :code_review_project_settings, :attachments, :code_review_assignments, - :code_review_user_settings + :changesets, :changes, :members, :member_roles, :roles, :issues, :issue_statuses, + :enumerations, :issue_categories, :trackers, :projects, :projects_trackers, + :code_review_project_settings, :attachments, :code_review_assignments, + :code_review_user_settings include CodeReviewAutoAssignSettings context "AutoAssignSettings" do context "to_s" do should "return string if @yml is not nil." do - - str =< Date: Fri, 8 Dec 2017 15:49:15 +0900 Subject: [PATCH 22/33] refoctoring --- app/controllers/code_review_controller.rb | 155 ++++++++++------------ 1 file changed, 72 insertions(+), 83 deletions(-) diff --git a/app/controllers/code_review_controller.rb b/app/controllers/code_review_controller.rb index 53d2e42..7ef1363 100644 --- a/app/controllers/code_review_controller.rb +++ b/app/controllers/code_review_controller.rb @@ -41,13 +41,12 @@ def index @review_pages = Paginator.new @review_count, limit, params['page'] @show_closed = (params['show_closed'] == 'true') show_closed_option = " and #{IssueStatus.table_name}.is_closed = ? " - if (@show_closed) - show_closed_option = '' - end + + show_closed_option = '' if (@show_closed) + conditions = ["#{CodeReview.table_name}.project_id = ? and issue_id is NOT NULL" + show_closed_option, @project.id] - unless (@show_closed) - conditions << false - end + + conditions << false unless (@show_closed) @reviews = CodeReview.order(sort_clause).limit(limit).where(conditions).joins( "left join #{Change.table_name} on change_id = #{Change.table_name}.id left join #{Changeset.table_name} on #{Change.table_name}.changeset_id = #{Changeset.table_name}.id " + @@ -120,7 +119,7 @@ def new change_id = params[:change_id].to_i unless params[:change_id].blank? @review.change = Change.find(change_id) if change_id @review.line = params[:line].to_i unless params[:line].blank? - if (@review.changeset and @review.changeset.user_id) + if @review.changeset and @review.changeset.user_id @review.issue.assigned_to_id = @review.changeset.user_id end @default_version_id = @review.issue.fixed_version.id if @review.issue.fixed_version @@ -139,11 +138,11 @@ def new end } unless @default_version_id end - render :partial => 'new_form', :status => 200 + render partial: 'new_form', status: 200 } rescue ActiveRecord::RecordInvalid => e logger.error e - render :partial => 'new_form', :status => 200 + render partial: 'new_form', status: 200 end end @@ -159,7 +158,7 @@ def assign code[:repository_id] = @repository_id if @repository_id changeset = Changeset.find(code[:changeset_id]) if code[:changeset_id] - if (changeset == nil and code[:change_id] != nil) + if changeset == nil and code[:change_id] != nil change = Change.find(code[:change_id]) changeset = change.changeset if change end @@ -173,8 +172,8 @@ def assign end issue[:tracker_id] = @setting.assignment_tracker_id if @setting.assignment_tracker_id - redirect_to :controller => 'issues', :action => "new", :project_id => @project, - :issue => issue, :code => code + redirect_to controller: 'issues', action: "new", project_id: @project, + issue: issue, code: code end def update_diff_view @@ -189,13 +188,12 @@ def update_diff_view @action_type = params[:action_type] changeset = @repository.find_changeset_by_name(@rev) - if @paths.empty? - changeset.filechanges.each { |chg| } - end + + changeset.filechanges.each { |chg| } if @paths.empty? url = @repository.url root_url = @repository.root_url - if (url == nil || root_url == nil) + if url.nil? || root_url.nil? fullpath = @path else rootpath = url[root_url.length, url.length - root_url.length] @@ -207,7 +205,7 @@ def update_diff_view end @change = nil changeset.filechanges.each { |chg| - @change = chg if ((chg.path == fullpath) or ("/#{chg.path}" == fullpath)) or (chg.path == "/#{@path}") + @change = chg if ((chg.path == fullpath) || ("/#{chg.path}" == fullpath)) || (chg.path == "/#{@path}") } unless @path.blank? @changeset = changeset @@ -218,10 +216,7 @@ def update_diff_view end @review.change_id = @change.id if @change - #render :partial => 'show_error' - #return - - render :partial => 'update_diff_view' + render partial: 'update_diff_view' end def update_attachment_view @@ -234,7 +229,7 @@ def update_attachment_view @reviews = CodeReview.where(['attachment_id = (?) and issue_id is NOT NULL', @attachment_id]).all - render :partial => 'update_diff_view' + render partial: 'update_diff_view' end def show @@ -247,87 +242,81 @@ def show target = @review if @review target = @assignment if @assignment @repository_id = target.repository_identifier - if request.xhr? or !params[:update].blank? - render :partial => 'show' + if request.xhr? || !params[:update].blank? + render partial: 'show' elsif target.path - #@review = @review.root - path = URI.decode(target.path) - #path = '/' + path unless path.match(/^\//) + path = URI.decode_www_form(target.path) action_name = target.action_type rev_to = '' rev_to = '&rev_to=' + target.rev_to if target.rev_to if action_name == 'attachment' attachment = target.attachment - url = url_for(:controller => 'attachments', :action => 'show', :id => attachment.id) + '/' + URI.escape(attachment.filename) + url = url_for(controller: 'attachments', action: 'show', + id: attachment.id) + '/' + URI.escape_www_form(attachment.filename) url << '?review_id=' + @review.id.to_s if @review - redirect_to(url) else path = nil if target.diff_all - url = url_for(:controller => 'repositories', :action => action_name, :id => @project, - :repository_id => @repository_id, :rev => target.revision, :path => path) - #url = url_for(:controller => 'repositories', :action => action_name, :id => @project, :repository_id => @repository_id) + path + '?rev=' + target.revision + url = url_for(controller: 'repositories', action: action_name, + id: @project, repository_id: @repository_id, + rev: target.revision, path: path) url << '?review_id=' + @review.id.to_s + rev_to if @review url << '?r=' + rev_to unless @review - redirect_to url end + redirect_to url end end def reply - begin - @review = CodeReview.find(params[:review_id].to_i) - @issue = @review.issue - @issue.lock_version = params[:issue][:lock_version] - comment = params[:reply][:comment] - journal = @issue.init_journal(User.current, comment) - @review.assign_attributes(params[:review]) - @allowed_statuses = @issue.new_statuses_allowed_to(User.current) - - @issue.save! - if !journal.new_record? - # Only send notification if something was actually changed - flash[:notice] = l(:notice_successful_update) - end - - render :partial => 'show' - rescue ActiveRecord::StaleObjectError - # Optimistic locking exception - @error = l(:notice_locking_conflict) - render :partial => 'show' + @review = CodeReview.find(params[:review_id].to_i) + @issue = @review.issue + @issue.lock_version = params[:issue][:lock_version] + comment = params[:reply][:comment] + journal = @issue.init_journal(User.current, comment) + @review.assign_attributes(params[:review]) + @allowed_statuses = @issue.new_statuses_allowed_to(User.current) + + @issue.save! + unless journal.new_record? + # Only send notification if something was actually changed + flash[:notice] = l(:notice_successful_update) end + + render partial: 'show' + rescue ActiveRecord::StaleObjectError + # Optimistic locking exception + @error = l(:notice_locking_conflict) + render partial: 'show' end def update - begin - CodeReview.transaction { - @review = CodeReview.find(params[:review_id].to_i) - journal = @review.issue.init_journal(User.current, nil) - @allowed_statuses = @review.issue.new_statuses_allowed_to(User.current) - @issue = @review.issue - @issue.lock_version = params[:issue][:lock_version] - @review.assign_attributes(params[:review]) - @review.updated_by_id = @user.id - @review.save! - @review.issue.save! - @notice = l(:notice_review_updated) - lang = current_language - Mailer.deliver_issue_edit(journal) if Setting.notified_events.include?('issue_updated') - set_language lang if respond_to? 'set_language' - render :partial => 'show' - } - rescue ActiveRecord::StaleObjectError - # Optimistic locking exception - @error = l(:notice_locking_conflict) - render :partial => 'show' - rescue - render :partial => 'show' - end + CodeReview.transaction { + @review = CodeReview.find(params[:review_id].to_i) + journal = @review.issue.init_journal(User.current, nil) + @allowed_statuses = @review.issue.new_statuses_allowed_to(User.current) + @issue = @review.issue + @issue.lock_version = params[:issue][:lock_version] + @review.assign_attributes(params[:review]) + @review.updated_by_id = @user.id + @review.save! + @review.issue.save! + @notice = l(:notice_review_updated) + lang = current_language + Mailer.deliver_issue_edit(journal) if Setting.notified_events.include?('issue_updated') + set_language lang if respond_to? 'set_language' + render partial: 'show' + } + rescue ActiveRecord::StaleObjectError + # Optimistic locking exception + @error = l(:notice_locking_conflict) + render partial: 'show' + rescue + render partial: 'show' end def destroy @review = CodeReview.find(params[:review_id].to_i) @review.issue.destroy if @review - render :text => 'delete success.' + render text: 'delete success.' end def forward_to_revision @@ -337,24 +326,24 @@ def forward_to_revision change = changesets[0] identifier = change.identifier - redirect_to url_for(:controller => 'repositories', :action => 'entry', :id => @project, :repository_id => @repository_id) + '/' + path + '?rev=' + identifier.to_s + redirect_to url_for(controller: 'repositories', action: 'entry', + id: @project, repository_id: @repository_id) + '/' + path + '?rev=' + identifier.to_s end def preview @text = params[:review][:comment] - @text = params[:reply][:comment] unless @text - render :partial => 'common/preview' + @text ||= params[:reply][:comment] + render partial: 'common/preview' end def update_revisions_view changeset_ids = [] - #changeset_ids = CGI.unescape(params[:changeset_ids]).split(',') unless params[:changeset_ids].blank? changeset_ids = params[:changeset_ids].split(',') unless params[:changeset_ids].blank? @changesets = [] changeset_ids.each { |id| @changesets << @repository.find_changeset_by_name(id) unless id.blank? } - render :partial => 'update_revisions' + render partial: 'update_revisions' end private From 5f53c516fbd126336660e711d319194b0130555f Mon Sep 17 00:00:00 2001 From: Haruyuki Iida Date: Sun, 11 Nov 2018 21:23:58 +0900 Subject: [PATCH 23/33] fix broken dialogs --- app/views/code_review/_new_form.html.erb | 8 +- app/views/code_review/_show.html.erb | 4 - assets/javascripts/code_review.js | 533 ++++++++++++----------- 3 files changed, 279 insertions(+), 266 deletions(-) diff --git a/app/views/code_review/_new_form.html.erb b/app/views/code_review/_new_form.html.erb index a560d17..df6748b 100644 --- a/app/views/code_review/_new_form.html.erb +++ b/app/views/code_review/_new_form.html.erb @@ -71,11 +71,14 @@

<%= custom_field_tag_with_label :issue, value %>

<% end %>

+ <%= f.text_area :comment, :cols => 30, :rows => 12, :accesskey => accesskey(:edit), :class => 'wiki-edit' %> + <%= wikitoolbar_for 'review_comment' %> +

@@ -110,10 +113,9 @@ <%= button_tag l(:button_apply), type: 'button', onclick: "$('#review-form').load('#{submit_url}', $('#review_form').serialize2json())" %> - <%= preview_link({ :controller => 'code_review', :action => 'preview', :id => @project}, 'review_form') %> +

-
- <%= wikitoolbar_for 'review_comment' %> + <% end %> diff --git a/app/views/code_review/_show.html.erb b/app/views/code_review/_show.html.erb index 24a1edd..e381cf5 100644 --- a/app/views/code_review/_show.html.erb +++ b/app/views/code_review/_show.html.erb @@ -117,9 +117,7 @@ -%> <%= button_tag l(:button_apply), type: 'button', onclick: "$('#show_review_#{@review.id}').load('#{submit_url}', $('##{review_form_id}').serialize())" %> - <%= link_to_function l(:label_preview), "$('#preview_#{@review.id}').load('#{url_for(:controller => 'code_review', :action => 'preview', :id => @project)}', $('##{review_form_id}').serialize())" %>

-
<%= wikitoolbar_for 'review_comment_' + @review.id.to_s %> <% end %> @@ -179,9 +177,7 @@ <% reply_preview_id = "reply_preview_#{@review.id}" -%> - <%= link_to_function l(:label_preview), "$('##{reply_preview_id}').load('#{url_for(:controller => 'code_review', :action => 'preview', :id => @project)}', $('##{message_form_id}').serialize())" %>

-
<%= wikitoolbar_for 'reply_comment_' + @review.id.to_s %> <% end %> diff --git a/assets/javascripts/code_review.js b/assets/javascripts/code_review.js index f2eef97..a2ea33d 100644 --- a/assets/javascripts/code_review.js +++ b/assets/javascripts/code_review.js @@ -29,19 +29,19 @@ var review_dialog_title = null; var repository_id = null; var filenames = []; -var ReviewCount = function(total, open, progress){ - this.total = total; - this.open = open; - this.closed = total - open; - this.progress = progress +var ReviewCount = function (total, open, progress) { + this.total = total; + this.open = open; + this.closed = total - open; + this.progress = progress }; -var CodeReview = function(id) { - this.id = id; - this.path = ''; - this.line = 0; - this.url = ''; - this.is_closed = false; +var CodeReview = function (id) { + this.id = id; + this.path = ''; + this.line = 0; + this.url = ''; + this.is_closed = false; }; var review_counts = new Array(); @@ -49,135 +49,134 @@ var code_reviews_map = new Array(); var code_reviews_dialog_map = new Array(); function UpdateRepositoryView(title) { - var header = $("table.changesets thead tr:first"); - var th = $(''); - th.html(title); - header.append(th); - $('tr.changeset td.id a:first-child').each(function(i){ - var revision = this.getAttribute("href"); - revision = revision.substr(revision.lastIndexOf("/") + 1); - var review = review_counts['revision_' + revision]; - var td = $('',{ - 'class':'progress' - }); - td.html(review.progress); - $(this.parentNode.parentNode).append(td); + var header = $("table.changesets thead tr:first"); + var th = $(''); + th.html(title); + header.append(th); + $('tr.changeset td.id a:first-child').each(function (i) { + var revision = this.getAttribute("href"); + revision = revision.substr(revision.lastIndexOf("/") + 1); + var review = review_counts['revision_' + revision]; + var td = $('', { + 'class': 'progress' }); - } + td.html(review.progress); + $(this.parentNode.parentNode).append(td); + }); +} //add function $.down -if(! $.fn.down) -(function($) { - $.fn.down = function() { - var el = this[0] && this[0].firstChild; - while (el && el.nodeType != 1) - el = el.nextSibling; - return $(el); +if (!$.fn.down) + (function ($) { + $.fn.down = function () { + var el = this[0] && this[0].firstChild; + while (el && el.nodeType != 1) + el = el.nextSibling; + return $(el); }; -})(jQuery); + })(jQuery); function UpdateRevisionView() { - $('li.change').each(function(){ - var li = $(this); - if (li.hasClass('folder')) return; - - var a = li.down('a'); - if (a.size() == 0) return; - var path = a.attr('href').replace(urlprefix, '').replace(/\?.*$/, ''); - - var reviewlist = code_reviews_map[path]; - if (reviewlist == null) return; - - var ul = $('
    '); - for (var j = 0; j < reviewlist.length; j++) { - var review = reviewlist[j]; - var icon = review.is_closed? 'icon-closed-review': 'icon-review'; - var item = $('
  • ', { - 'class': 'icon ' + icon + ' code_review_summary' - }); - item.html(review.url); - ul.append(item); - } - li.append(ul); - }); + $('li.change').each(function () { + var li = $(this); + if (li.hasClass('folder')) return; + + var a = li.down('a'); + if (a.size() == 0) return; + var path = a.attr('href').replace(urlprefix, '').replace(/\?.*$/, ''); + + var reviewlist = code_reviews_map[path]; + if (reviewlist == null) return; + + var ul = $('
      '); + for (var j = 0; j < reviewlist.length; j++) { + var review = reviewlist[j]; + var icon = review.is_closed ? 'icon-closed-review' : 'icon-review'; + var item = $('
    • ', { + 'class': 'icon ' + icon + ' code_review_summary' + }); + item.html(review.url); + ul.append(item); + } + li.append(ul); + }); } -function setAddReviewButton(url, change_id, image_tag, is_readonly, is_diff, attachment_id){ - var filetables = []; - var j = 0; - $('table').each(function(){ - if($(this).hasClass('filecontent')){ - filetables[j++] = this; - } - }); - j = 0; - $('table.filecontent th.filename').each(function(){ - filenames[j] = $.trim($(this).text()); - j++; - }); - addReviewUrl = url + '?change_id=' + change_id + '&action_type=' + action_type + - '&rev=' + rev + '&rev_to=' + rev_to + - '&attachment_id=' + attachment_id + '&repository_id=' + encodeURIComponent(repository_id); - if (path != null && path.length > 0) { - addReviewUrl = addReviewUrl + '&path=' + encodeURIComponent(path); - } - var num = 0; - if (is_diff) { - num = 1; +function setAddReviewButton(url, change_id, image_tag, is_readonly, is_diff, attachment_id) { + var filetables = []; + var j = 0; + $('table').each(function () { + if ($(this).hasClass('filecontent')) { + filetables[j++] = this; } - var i, l, tl; - for (i = 0, tl = filetables.length; i < tl; i++) { - var table = filetables[i]; - var trs = table.getElementsByTagName('tr'); - - for (j = 0,l = trs.length; j < l; j++) { - var tr = trs[j]; - var ths = tr.getElementsByTagName('th'); - - var th = ths[num]; - if (th == null) { - continue; - } - - var th_html = th.innerHTML; - - var line = th_html.match(/[0-9]+/); - if (line == null) { - continue; - } - - var span_html = ''; - - if (!is_readonly) { - span_html += image_tag; - } - span_html += ''; - th.innerHTML = th_html + span_html; - - var img = th.getElementsByTagName('img')[0]; - if (img != null ) { - img.id = 'add_revew_img_' + line + '_' + i; - $(img).click(clickPencil); - } - } + }); + j = 0; + $('table.filecontent th.filename').each(function () { + filenames[j] = $.trim($(this).text()); + j++; + }); + addReviewUrl = url + '?change_id=' + change_id + '&action_type=' + action_type + + '&rev=' + rev + '&rev_to=' + rev_to + + '&attachment_id=' + attachment_id + '&repository_id=' + encodeURIComponent(repository_id); + if (path != null && path.length > 0) { + addReviewUrl = addReviewUrl + '&path=' + encodeURIComponent(path); + } + var num = 0; + if (is_diff) { + num = 1; + } + var i, l, tl; + for (i = 0, tl = filetables.length; i < tl; i++) { + var table = filetables[i]; + var trs = table.getElementsByTagName('tr'); + + for (j = 0, l = trs.length; j < l; j++) { + var tr = trs[j]; + var ths = tr.getElementsByTagName('th'); + + var th = ths[num]; + if (th == null) { + continue; + } + + var th_html = th.innerHTML; + + var line = th_html.match(/[0-9]+/); + if (line == null) { + continue; + } + + var span_html = ''; + + if (!is_readonly) { + span_html += image_tag; + } + span_html += ''; + th.innerHTML = th_html + span_html; + + var img = th.getElementsByTagName('img')[0]; + if (img != null) { + img.id = 'add_revew_img_' + line + '_' + i; + $(img).click(clickPencil); + } } + } } -function clickPencil(e) -{ -// alert('$(e.target).attr("id") = ' + $(e.target).attr("id")); - var result = $(e.target).attr("id").match(/([0-9]+)_([0-9]+)/); - var line = result[1]; - var file_count = eval(result[2]); - var url = addReviewUrl + '&line=' + line + '&file_count=' + file_count; - - if (path == null || path.length == 0) { - url = url + '&path=' + encodeURIComponent(filenames[file_count]) + '&diff_all=true'; - } - addReview(url); - formPopup(e.pageX, e.pageY); - e.preventDefault(); +function clickPencil(e) { + // alert('$(e.target).attr("id") = ' + $(e.target).attr("id")); + var result = $(e.target).attr("id").match(/([0-9]+)_([0-9]+)/); + var line = result[1]; + var file_count = eval(result[2]); + var url = addReviewUrl + '&line=' + line + '&file_count=' + file_count; + + if (path == null || path.length == 0) { + url = url + '&path=' + encodeURIComponent(filenames[file_count]) + '&diff_all=true'; + } + addReview(url); + formPopup(e.pageX, e.pageY); + e.preventDefault(); } var addReviewUrl = null; var showReviewUrl = null; @@ -185,170 +184,186 @@ var showReviewImageTag = null; var showClosedReviewImageTag = null; function setShowReviewButton(line, review_id, is_closed, file_count) { - //alert('file_count = ' + file_count); - var span = $('#review_span_' + line + '_' + file_count); - if (span.size() == 0) { - return; - } - var innerSpan = $('',{id: 'review_' + review_id}); - span.append(innerSpan); - innerSpan.html(is_closed? showClosedReviewImageTag : showReviewImageTag); - var div = $('
      ', { - 'class':'draggable', - id: 'show_review_' + review_id - }); - $('#code_review').append(div); - innerSpan.down('img').click(function(e) { - var review_id = $(e.target).parent().attr('id').match(/[0-9]+/)[0]; - var span = $('#review_' + review_id); // span element of view review button + //alert('file_count = ' + file_count); + var span = $('#review_span_' + line + '_' + file_count); + if (span.size() == 0) { + return; + } + var innerSpan = $('', { + id: 'review_' + review_id + }); + span.append(innerSpan); + innerSpan.html(is_closed ? showClosedReviewImageTag : showReviewImageTag); + var div = $('
      ', { + 'class': 'draggable', + id: 'show_review_' + review_id + }); + $('#code_review').append(div); + innerSpan.down('img').click(function (e) { + var review_id = $(e.target).parent().attr('id').match(/[0-9]+/)[0]; + var span = $('#review_' + review_id); // span element of view review button var pos = span.offset(); - showReview(showReviewUrl, review_id, pos.left + 10 + 5, pos.top + 25); - }); + showReview(showReviewUrl, review_id, pos.left + 10 + 5, pos.top + 25); + }); } function popupReview(review_id) { - var span = $('#review_' + review_id); // span element of view review button - var pos = span.offset(); - $('html,body').animate({ scrollTop: pos.top }, - {duration: 'fast', - complete: function(){showReview(showReviewUrl, review_id, pos.left + 10 + 5, pos.top)}}); - // position and show popup dialog - // create popup dialog - //var win = showReview(showReviewUrl, review_id, pos.left + 10 + 5, pos.top); -// win.toFront(); + var span = $('#review_' + review_id); // span element of view review button + var pos = span.offset(); + $('html,body').animate({ + scrollTop: pos.top + }, { + duration: 'fast', + complete: function () { + showReview(showReviewUrl, review_id, pos.left + 10 + 5, pos.top) + } + }); + // position and show popup dialog + // create popup dialog + //var win = showReview(showReviewUrl, review_id, pos.left + 10 + 5, pos.top); + // win.toFront(); } function showReview(url, review_id, x, y) { - if (code_reviews_dialog_map[review_id] != null) { - var cur_win = code_reviews_dialog_map[review_id]; - cur_win.hide(); - code_reviews_dialog_map[review_id] = null; - } - $('#show_review_' + review_id).load(url, {review_id: review_id}); - var review = getReviewObjById(review_id); - - var win = $('#show_review_' + review_id).dialog({ - show: {effect:'scale'},// ? 'top-left' - //position: [x, y + 5], - width:640, - zIndex: topZindex, - title: review_dialog_title - }); -// win.getContent().style.color = "#484848"; -// win.getContent().style.background = "#ffffff"; - topZindex++; - code_reviews_dialog_map[review_id] = win; - return win + if (code_reviews_dialog_map[review_id] != null) { + var cur_win = code_reviews_dialog_map[review_id]; + cur_win.hide(); + code_reviews_dialog_map[review_id] = null; + } + $('#show_review_' + review_id).load(url, { + review_id: review_id + }); + var review = getReviewObjById(review_id); + + var win = $('#show_review_' + review_id).dialog({ + show: { + effect: 'scale' + }, // ? 'top-left' + //position: [x, y + 5], + width: 640, + zIndex: topZindex, + title: review_dialog_title + }); + // win.getContent().style.color = "#484848"; + // win.getContent().style.background = "#ffffff"; + topZindex++; + code_reviews_dialog_map[review_id] = win; + $('.ui-dialog').appendTo('#content'); + $('.ui-effects-wrapper').zIndex(0); + return win } function getReviewObjById(review_id) { - for (var reviewlist in code_reviews_map) { - for (var i = 0; i < reviewlist.length; i++) { - var review = reviewlist[i]; - if (review.id == review_id) { - return review; - } - } + for (var reviewlist in code_reviews_map) { + for (var i = 0; i < reviewlist.length; i++) { + var review = reviewlist[i]; + if (review.id == review_id) { + return review; + } } - return null; + } + return null; } -function formPopup(x, y){ - //@see http://docs.jquery.com/UI/Effects/Scale - var win = $('#review-form-frame').dialog({ - show: {effect:'scale', direction: 'both'},// ? 'top-left' -// position: [x, y + 5], - width:640, - zIndex: topZindex, - title: add_form_title - }); -// win.getContent().style.background = "#ffffff"; - if (review_form_dialog != null) { - review_form_dialog.destroy(); - review_form_dialog = null; - } - review_form_dialog = win; - topZindex += 10; - return false; +function formPopup(x, y) { + //@see http://docs.jquery.com/UI/Effects/Scale + var win = $('#review-form-frame').dialog({ + show: { + effect: 'scale', + direction: 'both' + }, // ? 'top-left' + // position: [x, y + 5], + width: 640, + zIndex: topZindex, + title: add_form_title + }); + // win.getContent().style.background = "#ffffff"; + if (review_form_dialog != null) { + review_form_dialog.destroy(); + review_form_dialog = null; + } + review_form_dialog = win; + topZindex += 10; + $('.ui-dialog').appendTo('#content'); + $('.ui-effects-wrapper').zIndex(0); + return false; } function hideForm() { - if (review_form_dialog == null) { - return; - } - review_form_dialog.dialog('close'); - review_form_dialog = null; - $('#review-form').html(''); + if (review_form_dialog == null) { + return; + } + review_form_dialog.dialog('close'); + review_form_dialog = null; + $('#review-form').html(''); } + function addReview(url) { - $('#review-form').load(url); + $('#review-form').load(url); } function deleteReview(review_id) { - $('show_review_' + review_id).remove(); - $('review_' + review_id).remove(); - + $('show_review_' + review_id).remove(); + $('review_' + review_id).remove(); + } function changeImage(review_id, is_closed) { - var span = $('review_' + review_id); - var new_image = null; - var dummy = new Element('span'); - if (is_closed) { - dummy.insert(showClosedReviewImageTag); - } - else { - dummy.insert(showReviewImageTag); - } - new_image = dummy.down().getAttribute('src'); - //alert(new_image); - span.down('img').setAttribute('src', new_image); + var span = $('review_' + review_id); + var new_image = null; + var dummy = new Element('span'); + if (is_closed) { + dummy.insert(showClosedReviewImageTag); + } else { + dummy.insert(showReviewImageTag); + } + new_image = dummy.down().getAttribute('src'); + //alert(new_image); + span.down('img').setAttribute('src', new_image); } function make_addreview_link(project, link) { - var alist = $('div.tabs ul li a#tab-entry'); - if (alist == null) { - return; - } - var a = alist[0]; - var p = a.parentNode.parentNode; - p.innerHTML = p.innerHTML + link; + var alist = $('div.tabs ul li a#tab-entry'); + if (alist == null) { + return; + } + var a = alist[0]; + var p = a.parentNode.parentNode; + p.innerHTML = p.innerHTML + link; } function call_update_revisions(url) { - var changeset_ids = ''; - var links = $$('table.changesets tbody tr.changeset td.id a'); - for (var i = 0; i < links.length; i++) { - var link = links[i]; - var href = link.getAttribute('href'); - var id = href.replace(/^.*\/revisions\//, ''); - if (i > 0) { - changeset_ids += ','; - } - changeset_ids += id; + var changeset_ids = ''; + var links = $$('table.changesets tbody tr.changeset td.id a'); + for (var i = 0; i < links.length; i++) { + var link = links[i]; + var href = link.getAttribute('href'); + var id = href.replace(/^.*\/revisions\//, ''); + if (i > 0) { + changeset_ids += ','; } - new Ajax.Updater('code_review_revisions', url, - { - evalScripts:true, - method:'get', - parameters: 'changeset_ids=' + encodeURI(changeset_ids) - }); + changeset_ids += id; + } + new Ajax.Updater('code_review_revisions', url, { + evalScripts: true, + method: 'get', + parameters: 'changeset_ids=' + encodeURI(changeset_ids) + }); } -$.fn.serialize2json = function() -{ - var o = {}; - var a = this.serializeArray(); - $.each(a, function() { - if (o[this.name]) { - if (!o[this.name].push) { - o[this.name] = [o[this.name]]; - } - o[this.name].push(this.value || ''); - } else { - o[this.name] = this.value || ''; - } - }); - return o; +$.fn.serialize2json = function () { + var o = {}; + var a = this.serializeArray(); + $.each(a, function () { + if (o[this.name]) { + if (!o[this.name].push) { + o[this.name] = [o[this.name]]; + } + o[this.name].push(this.value || ''); + } else { + o[this.name] = this.value || ''; + } + }); + return o; }; \ No newline at end of file From 81c2fe6fdf4538957519efaa877d7da186973447 Mon Sep 17 00:00:00 2001 From: Haruyuki Iida Date: Sun, 11 Nov 2018 22:32:20 +0900 Subject: [PATCH 24/33] Change FactoryGirl to FactoryBot. --- Gemfile_for_test | 2 +- .../functional/attachments_controller_test.rb | 4 +- .../functional/code_review_controller_test.rb | 4 +- test/functional/issues_controller_test.rb | 6 +- test/functional/projects_controller_test.rb | 8 +-- .../repositories_controller_test.rb | 4 +- test/test_helper.rb | 8 ++- .../code_review_auto_assign_settings_test.rb | 16 ++--- test/unit/code_review_change_patch_test.rb | 52 +++++++-------- test/unit/code_review_changeset_patch_test.rb | 64 +++++++++---------- .../unit/code_review_project_settings_test.rb | 2 +- 11 files changed, 86 insertions(+), 84 deletions(-) diff --git a/Gemfile_for_test b/Gemfile_for_test index 5475687..2d8d66d 100644 --- a/Gemfile_for_test +++ b/Gemfile_for_test @@ -2,7 +2,7 @@ group :test do gem "simplecov-rcov" - gem 'factory_girl_rails' + gem 'factory_bot_rails' gem 'shoulda' gem 'rails-controller-testing' gem 'coveralls', :require => false diff --git a/test/functional/attachments_controller_test.rb b/test/functional/attachments_controller_test.rb index 36e9eac..83714a4 100644 --- a/test/functional/attachments_controller_test.rb +++ b/test/functional/attachments_controller_test.rb @@ -47,7 +47,7 @@ def setup def test_show_diff @request.session[:user_id] = 1 - attachment = FactoryGirl.create(:attachment, filename: "test.diff") + attachment = FactoryBot.create(:attachment, filename: "test.diff") get :show, :params => {:id => attachment.id, :type => 'inline'} assert_response :success assert_template 'diff' @@ -56,7 +56,7 @@ def test_show_diff def test_show_text_file @request.session[:user_id] = 1 - attachment = FactoryGirl.create(:attachment, filename: "test.rb") + attachment = FactoryBot.create(:attachment, filename: "test.rb") get :show, :params => {:id => attachment.id, :type => 'inline'} assert_response :success assert_template 'file' diff --git a/test/functional/code_review_controller_test.rb b/test/functional/code_review_controller_test.rb index 6239dfd..8b4bd94 100644 --- a/test/functional/code_review_controller_test.rb +++ b/test/functional/code_review_controller_test.rb @@ -137,7 +137,7 @@ def setup @request.session[:user_id] = 1 project = Project.find(1) issue = Issue.generate!(:project => project) - attachment = FactoryGirl.create(:attachment, container: issue) + attachment = FactoryBot.create(:attachment, container: issue) count = CodeReview.all.length post :new, :params => {:id => 1, :review => {:line => 1, :comment => 'aaa', :subject => 'bbb', :attachment_id => attachment.id}, :action_type => 'diff'} @@ -172,7 +172,7 @@ def test_show def test_destroy project = Project.find(1) issue = Issue.generate!(:project => project) - review = FactoryGirl.create(:code_review, project: project) + review = FactoryBot.create(:code_review, project: project) count = CodeReview.all.length @request.session[:user_id] = 1 get :destroy, :params => {:id => 1, :review_id => review.id} diff --git a/test/functional/issues_controller_test.rb b/test/functional/issues_controller_test.rb index bc7b1a2..5bcbfbf 100644 --- a/test/functional/issues_controller_test.rb +++ b/test/functional/issues_controller_test.rb @@ -72,14 +72,14 @@ def test_show issue = Issue.generate!(:project => project) get :show, params: {id: issue.id} - assignment = FactoryGirl.create(:code_review_assignment, issue: issue, rev: 'aaa', file_path: nil) + assignment = FactoryBot.create(:code_review_assignment, issue: issue, rev: 'aaa', file_path: nil) get :show, :params => {:id => assignment.issue.id} issue = Issue.generate!(:project => Project.find(1)) - assignment = FactoryGirl.create(:code_review_assignment, issue: issue, rev: 'aaa', file_path: '/aaa/bbb') + assignment = FactoryBot.create(:code_review_assignment, issue: issue, rev: 'aaa', file_path: '/aaa/bbb') get :show, :params => {:id => assignment.issue.id} - review = FactoryGirl.create(:code_review, project: project) + review = FactoryBot.create(:code_review, project: project) get :show, :params => {:id => review.issue.id} end diff --git a/test/functional/projects_controller_test.rb b/test/functional/projects_controller_test.rb index 7edb700..8133437 100644 --- a/test/functional/projects_controller_test.rb +++ b/test/functional/projects_controller_test.rb @@ -64,7 +64,7 @@ def setup context "and module" do setup do - FactoryGirl.create(:enabled_module, project_id: 1, name: 'code_review') + FactoryBot.create(:enabled_module, project_id: 1, name: 'code_review') end should "not exist tag id get" do @@ -120,7 +120,7 @@ def setup context "and module" do setup do - FactoryGirl.create(:enabled_module, project_id: 1, name: 'code_review') + FactoryBot.create(:enabled_module, project_id: 1, name: 'code_review') end should "not exist tag id get" do @@ -181,7 +181,7 @@ def setup context "and module" do setup do - FactoryGirl.create(:enabled_module, project_id: 1, name: 'code_review') + FactoryBot.create(:enabled_module, project_id: 1, name: 'code_review') end should "not exist tag id get" do @@ -242,7 +242,7 @@ def setup context "and module" do setup do - FactoryGirl.create(:enabled_module, project_id: 1, name: 'code_review') + FactoryBot.create(:enabled_module, project_id: 1, name: 'code_review') end should "exist tag id get" do diff --git a/test/functional/repositories_controller_test.rb b/test/functional/repositories_controller_test.rb index 25edd6c..c32d246 100644 --- a/test/functional/repositories_controller_test.rb +++ b/test/functional/repositories_controller_test.rb @@ -55,13 +55,13 @@ def setup def test_revision @request.session[:user_id] = 1 - change = FactoryGirl.create(:change) + change = FactoryBot.create(:change) changeset = change.changeset project = Project.find(1) project.repository.destroy project.repository = changeset.repository issue = Issue.generate!({:project_id => project.id, :description => 'test', :tracker => Tracker.find(1), :status_id => 1}) - review = FactoryGirl.create(:code_review, change: change, project: project, issue: issue) + review = FactoryBot.create(:code_review, change: change, project: project, issue: issue) get :revision, :params => {:id => project.id, :rev => changeset.revision, :path => change.path.split('/')} #assert_response :success end diff --git a/test/test_helper.rb b/test/test_helper.rb index 43c2938..bde5bcd 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,5 +1,5 @@ # Code Review plugin for Redmine -# Copyright (C) 2010-2017 Haruyuki Iida +# Copyright (C) 2010-2018 Haruyuki Iida # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -18,6 +18,8 @@ require 'simplecov' require 'simplecov-rcov' require 'coveralls' +require 'factory_bot' +require 'shoulda' SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[ SimpleCov::Formatter::RcovFormatter, @@ -55,7 +57,7 @@ def uploaded_test_file(name, mime) fixture_file_upload(Rails.root.to_s + "/test/fixtures/files/#{name}", mime, true) end -FactoryGirl.define do +FactoryBot.define do factory :attachment do container { Issue.find(1) @@ -107,7 +109,7 @@ def uploaded_test_file(name, mime) "test/dir/aaa#{n}" } changeset { - FactoryGirl.create(:changeset) + FactoryBot.create(:changeset) } end diff --git a/test/unit/code_review_auto_assign_settings_test.rb b/test/unit/code_review_auto_assign_settings_test.rb index fc4e178..6af7546 100644 --- a/test/unit/code_review_auto_assign_settings_test.rb +++ b/test/unit/code_review_auto_assign_settings_test.rb @@ -259,37 +259,37 @@ def teardown #project.repository.destroy if project.repository #repository = Repository.new #repository.project = project - @changeset = FactoryGirl.create(:changeset, repository: project.repository) + @changeset = FactoryBot.create(:changeset, repository: project.repository) #@changeset.repository = repository end should "return true if filters.length is 0 and accept_for_default is true." do @settings.filters = [] - change = FactoryGirl.create(:change, changeset: @changeset) + change = FactoryBot.create(:change, changeset: @changeset) assert @settings.match_with_change?(change) end should "return true if filter matches and accept? is true" do @settings.accept_for_default = false - change = FactoryGirl.create(:change, path: '/aaa/bbb/ccc.rb', changeset: @changeset) + change = FactoryBot.create(:change, path: '/aaa/bbb/ccc.rb', changeset: @changeset) assert @settings.match_with_change?(change) - change = FactoryGirl.create(:change, path: '/trunk/plugins/redmine_code_review/lib/ccc.rb', changeset: @changeset) + change = FactoryBot.create(:change, path: '/trunk/plugins/redmine_code_review/lib/ccc.rb', changeset: @changeset) assert @settings.match_with_change?(change) end should "return false if filter matches and accept? is false" do - change = FactoryGirl.create(:change, path: '/aaa/bbb/ccctest.rb', changeset: @changeset) + change = FactoryBot.create(:change, path: '/aaa/bbb/ccctest.rb', changeset: @changeset) assert !@settings.match_with_change?(change) end should "return false if filter doesn't matches and accept_for_default is false" do - change = FactoryGirl.create(:change, path: '/aaa/bbb/ccctest.html', changeset: @changeset) + change = FactoryBot.create(:change, path: '/aaa/bbb/ccctest.html', changeset: @changeset) @settings.accept_for_default = false assert !@settings.match_with_change?(change) end should "return true if filter doesn't matches and accept_for_default is true" do - change = FactoryGirl.create(:change, path: '/aaa/bbb/ccctest.html', changeset: @changeset) + change = FactoryBot.create(:change, path: '/aaa/bbb/ccctest.html', changeset: @changeset) @settings.accept_for_default = true assert @settings.match_with_change?(change) end @@ -297,7 +297,7 @@ def teardown should "return false if filters.length is 0 and accept_for_default is false." do @settings.filters = [] @settings.accept_for_default = false - change = FactoryGirl.create(:change, changeset: @changeset) + change = FactoryBot.create(:change, changeset: @changeset) assert !@settings.match_with_change?(change) end end diff --git a/test/unit/code_review_change_patch_test.rb b/test/unit/code_review_change_patch_test.rb index 3d87344..10df2e3 100644 --- a/test/unit/code_review_change_patch_test.rb +++ b/test/unit/code_review_change_patch_test.rb @@ -45,20 +45,20 @@ def test_closed_review_count end def test_assignment_count - change = FactoryGirl.create(:change) + change = FactoryBot.create(:change) assert_equal(0, change.assignment_count) - change.code_review_assignments << FactoryGirl.create(:code_review_assignment) + change.code_review_assignments << FactoryBot.create(:code_review_assignment) assert_equal(1, change.assignment_count) - change.code_review_assignments << FactoryGirl.create(:code_review_assignment) + change.code_review_assignments << FactoryBot.create(:code_review_assignment) assert_equal(2, change.assignment_count) end def test_open_assignment_count - change = FactoryGirl.create(:change) - change.code_review_assignments << FactoryGirl.create(:code_review_assignment) - change.code_review_assignments << FactoryGirl.create(:code_review_assignment) - change.code_review_assignments << FactoryGirl.create(:code_review_assignment) - change.code_review_assignments << FactoryGirl.create(:code_review_assignment) + change = FactoryBot.create(:change) + change.code_review_assignments << FactoryBot.create(:code_review_assignment) + change.code_review_assignments << FactoryBot.create(:code_review_assignment) + change.code_review_assignments << FactoryBot.create(:code_review_assignment) + change.code_review_assignments << FactoryBot.create(:code_review_assignment) assert_equal(4, change.open_assignment_count) close_status = IssueStatus.find(5) change.code_review_assignments[0].issue.status = close_status @@ -68,11 +68,11 @@ def test_open_assignment_count end def test_closed_assignment_count - change = FactoryGirl.create(:change) - change.code_review_assignments << FactoryGirl.create(:code_review_assignment) - change.code_review_assignments << FactoryGirl.create(:code_review_assignment) - change.code_review_assignments << FactoryGirl.create(:code_review_assignment) - change.code_review_assignments << FactoryGirl.create(:code_review_assignment) + change = FactoryBot.create(:change) + change.code_review_assignments << FactoryBot.create(:code_review_assignment) + change.code_review_assignments << FactoryBot.create(:code_review_assignment) + change.code_review_assignments << FactoryBot.create(:code_review_assignment) + change.code_review_assignments << FactoryBot.create(:code_review_assignment) assert_equal(0, change.closed_assignment_count) close_status = IssueStatus.find(5) change.code_review_assignments[0].issue.status = close_status @@ -83,14 +83,14 @@ def test_closed_assignment_count context "open_assignments" do should "return empty array if change has no assignments." do - change = FactoryGirl.create(:change) + change = FactoryBot.create(:change) assert_equal(0, change.open_assignments.length) end should "return empty array if change has no open assignments" do - change = FactoryGirl.create(:change) - change.code_review_assignments << FactoryGirl.create(:code_review_assignment) - change.code_review_assignments << FactoryGirl.create(:code_review_assignment) + change = FactoryBot.create(:change) + change.code_review_assignments << FactoryBot.create(:code_review_assignment) + change.code_review_assignments << FactoryBot.create(:code_review_assignment) close_status = IssueStatus.find(5) change.code_review_assignments.each { |assignments| assignments.issue.status = close_status @@ -99,10 +99,10 @@ def test_closed_assignment_count end should "return 2 assignments if change has 2 open assignments" do - change = FactoryGirl.create(:change) - change.code_review_assignments << FactoryGirl.create(:code_review_assignment) - change.code_review_assignments << FactoryGirl.create(:code_review_assignment) - change.code_review_assignments << FactoryGirl.create(:code_review_assignment) + change = FactoryBot.create(:change) + change.code_review_assignments << FactoryBot.create(:code_review_assignment) + change.code_review_assignments << FactoryBot.create(:code_review_assignment) + change.code_review_assignments << FactoryBot.create(:code_review_assignment) close_status = IssueStatus.find(5) change.code_review_assignments[0].issue.status = close_status @@ -110,11 +110,11 @@ def test_closed_assignment_count end should "return 2 assignments if change has 2 open assignments which are assigned to user_id 1" do - change = FactoryGirl.create(:change) - change.code_review_assignments << FactoryGirl.create(:code_review_assignment) - change.code_review_assignments << FactoryGirl.create(:code_review_assignment) - change.code_review_assignments << FactoryGirl.create(:code_review_assignment) - change.code_review_assignments << FactoryGirl.create(:code_review_assignment) + change = FactoryBot.create(:change) + change.code_review_assignments << FactoryBot.create(:code_review_assignment) + change.code_review_assignments << FactoryBot.create(:code_review_assignment) + change.code_review_assignments << FactoryBot.create(:code_review_assignment) + change.code_review_assignments << FactoryBot.create(:code_review_assignment) close_status = IssueStatus.find(5) change.code_review_assignments[0].issue.status = close_status change.code_review_assignments[0].issue.assigned_to_id = 1 diff --git a/test/unit/code_review_changeset_patch_test.rb b/test/unit/code_review_changeset_patch_test.rb index d97cf83..fe75b5c 100644 --- a/test/unit/code_review_changeset_patch_test.rb +++ b/test/unit/code_review_changeset_patch_test.rb @@ -50,26 +50,26 @@ def test_assignment_count changeset = Changeset.find(100) assert_equal(0, changeset.assignment_count) change = changeset.filechanges[0] - change.code_review_assignments << FactoryGirl.create(:code_review_assignment, issue_id: 1) - change.code_review_assignments << FactoryGirl.create(:code_review_assignment, issue_id: 2) + change.code_review_assignments << FactoryBot.create(:code_review_assignment, issue_id: 1) + change.code_review_assignments << FactoryBot.create(:code_review_assignment, issue_id: 2) change = changeset.filechanges[1] - change.code_review_assignments << FactoryGirl.create(:code_review_assignment, issue_id: 3) + change.code_review_assignments << FactoryBot.create(:code_review_assignment, issue_id: 3) assert_equal(3, changeset.assignment_count) end def test_completed_assignment_pourcent - changeset = FactoryGirl.create(:changeset) - FactoryGirl.create(:change, changeset: changeset) - FactoryGirl.create(:change, changeset: changeset) + changeset = FactoryBot.create(:changeset) + FactoryBot.create(:change, changeset: changeset) + FactoryBot.create(:change, changeset: changeset) changeset = Changeset.find(changeset.id) change = changeset.filechanges[0] - change.code_review_assignments << FactoryGirl.create(:code_review_assignment, issue_id: 1) - change.code_review_assignments << FactoryGirl.create(:code_review_assignment, issue_id: 2) + change.code_review_assignments << FactoryBot.create(:code_review_assignment, issue_id: 1) + change.code_review_assignments << FactoryBot.create(:code_review_assignment, issue_id: 2) change = changeset.filechanges[1] - change.code_review_assignments << FactoryGirl.create(:code_review_assignment, issue_id: 3) - change.code_review_assignments << FactoryGirl.create(:code_review_assignment, issue_id: 4) + change.code_review_assignments << FactoryBot.create(:code_review_assignment, issue_id: 3) + change.code_review_assignments << FactoryBot.create(:code_review_assignment, issue_id: 4) issues = [] 1.upto(4) { |i| issues[i - 1] = Issue.find(i) @@ -96,33 +96,33 @@ def test_completed_assignment_pourcent context "closed_assignment_pourcent" do should "returns 0 if changeset has no assignments." do - change = FactoryGirl.create(:change) + change = FactoryBot.create(:change) changeset = change.changeset assert_equal(0, changeset.closed_assignment_pourcent) end should "returns 0 if changeset has no closed assignments." do - change = FactoryGirl.create(:change) + change = FactoryBot.create(:change) changeset = change.changeset @project = Project.generate! issue1 = Issue.generate!({:project => @project, :status_id => 1}) issue2 = Issue.generate!({:project => @project, :status_id => 1}) - change.code_review_assignments << FactoryGirl.create(:code_review_assignment, issue: issue1) - change.code_review_assignments << FactoryGirl.create(:code_review_assignment, issue: issue2) + change.code_review_assignments << FactoryBot.create(:code_review_assignment, issue: issue1) + change.code_review_assignments << FactoryBot.create(:code_review_assignment, issue: issue2) change.save! assert_equal(0, changeset.closed_assignment_pourcent) end should "returns 100 if changeset has no closed assignments." do - change = FactoryGirl.create(:change) + change = FactoryBot.create(:change) changeset = change.changeset @project = Project.find(1) issue1 = Issue.generate!({:project => @project, :status => IssueStatus.find(5)}) issue1.status = IssueStatus.find(5) issue2 = Issue.generate!({:project => @project, :status => IssueStatus.find(5)}) issue2.status = IssueStatus.find(5) - change.code_review_assignments << FactoryGirl.create(:code_review_assignment, issue: issue1) - change.code_review_assignments << FactoryGirl.create(:code_review_assignment, issue: issue2) + change.code_review_assignments << FactoryBot.create(:code_review_assignment, issue: issue1) + change.code_review_assignments << FactoryBot.create(:code_review_assignment, issue: issue2) change.save! changeset = Changeset.find(changeset.id) assert issue1.closed? @@ -135,19 +135,19 @@ def test_completed_assignment_pourcent end should "returns 50 if half of assignments were closed." do - change = FactoryGirl.create(:change) + change = FactoryBot.create(:change) changeset = change.changeset @project = Project.generate! issue1 = Issue.generate!({:project => @project, :status => IssueStatus.find(5)}) issue2 = Issue.generate!({:project => @project, :status => IssueStatus.find(1)}) issue3 = Issue.generate!({:project => @project, :status => IssueStatus.find(5)}) issue4 = Issue.generate!({:project => @project, :status => IssueStatus.find(1)}) - change.code_review_assignments << FactoryGirl.create(:code_review_assignment, issue: issue1) - change.code_review_assignments << FactoryGirl.create(:code_review_assignment, issue: issue2) + change.code_review_assignments << FactoryBot.create(:code_review_assignment, issue: issue1) + change.code_review_assignments << FactoryBot.create(:code_review_assignment, issue: issue2) change.save! - change = FactoryGirl.create(:change, changeset: changeset) - change.code_review_assignments << FactoryGirl.create(:code_review_assignment, issue: issue3) - change.code_review_assignments << FactoryGirl.create(:code_review_assignment, issue: issue4) + change = FactoryBot.create(:change, changeset: changeset) + change.code_review_assignments << FactoryBot.create(:code_review_assignment, issue: issue3) + change.code_review_assignments << FactoryBot.create(:code_review_assignment, issue: issue4) change.save! changeset = Changeset.find(changeset.id) assert_equal(50, changeset.closed_assignment_pourcent) @@ -156,27 +156,27 @@ def test_completed_assignment_pourcent context "assignment_issues" do should "returns empty array if changeset has no assignments." do - change = FactoryGirl.create(:change) + change = FactoryBot.create(:change) changeset = change.changeset assert_not_nil(changeset.assignment_issues) end should "returns assignments if changeset has assignments." do - change = FactoryGirl.create(:change) + change = FactoryBot.create(:change) changeset = change.changeset assert_not_nil change - change.code_review_assignments << FactoryGirl.create(:code_review_assignment, issue_id: 1) - change.code_review_assignments << FactoryGirl.create(:code_review_assignment, issue_id: 2) + change.code_review_assignments << FactoryBot.create(:code_review_assignment, issue_id: 1) + change.code_review_assignments << FactoryBot.create(:code_review_assignment, issue_id: 2) change.save! changeset = Changeset.find(changeset.id) assert_not_nil(changeset.assignment_issues) assert_equal(2, changeset.assignment_issues.length) - change = FactoryGirl.create(:change, changeset: changeset) + change = FactoryBot.create(:change, changeset: changeset) - change.code_review_assignments << FactoryGirl.create(:code_review_assignment, issue_id: 3) + change.code_review_assignments << FactoryBot.create(:code_review_assignment, issue_id: 3) change.save! changeset = Changeset.find(changeset.id) @@ -193,7 +193,7 @@ def test_completed_assignment_pourcent repository = project.repository - @changeset = FactoryGirl.create(:changeset, repository: repository) + @changeset = FactoryBot.create(:changeset, repository: repository) auto_assign = AutoAssignSettings.new auto_assign.enabled = true @@ -221,9 +221,9 @@ def test_completed_assignment_pourcent should "create assignments" do count = CodeReviewAssignment.all.length - change1 = FactoryGirl.create(:change, path: '/aaa/bbb/ccc.rb', changeset: @changeset) + change1 = FactoryBot.create(:change, path: '/aaa/bbb/ccc.rb', changeset: @changeset) assert_equal(count + 1, CodeReviewAssignment.all.length) - change2 = FactoryGirl.create(:change, path: '/aaa/bbb/ccc2.rb', changeset: @changeset) + change2 = FactoryBot.create(:change, path: '/aaa/bbb/ccc2.rb', changeset: @changeset) assert_equal(count + 1, CodeReviewAssignment.all.length) end end diff --git a/test/unit/code_review_project_settings_test.rb b/test/unit/code_review_project_settings_test.rb index a6ab7ae..6046b04 100644 --- a/test/unit/code_review_project_settings_test.rb +++ b/test/unit/code_review_project_settings_test.rb @@ -44,7 +44,7 @@ class CodeReviewProjectSettingsTest < ActiveSupport::TestCase should "be saved if auto_assign is setted." do project = Project.find(1) - setting = FactoryGirl.create(:code_review_project_setting, project: project) + setting = FactoryBot.create(:code_review_project_setting, project: project) id = setting.id assert !setting.auto_assign_settings.enabled? setting.auto_assign_settings.enabled = true From a4fa7ba8b730ecc76cfe86357805c6ae6eb60d0d Mon Sep 17 00:00:00 2001 From: Haruyuki Iida Date: Sat, 29 Dec 2018 14:18:26 +0900 Subject: [PATCH 25/33] change required redmine version to 4.0.0 --- init.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/init.rb b/init.rb index 60752d9..c2e5ede 100644 --- a/init.rb +++ b/init.rb @@ -1,5 +1,5 @@ # Code Review plugin for Redmine -# Copyright (C) 2009-2017 Haruyuki Iida +# Copyright (C) 2009-2018 Haruyuki Iida # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -52,8 +52,8 @@ author_url 'http://twitter.com/haru_iida' url "http://www.r-labs.org/projects/show/codereview" if respond_to?(:url) description 'This is a Code Review plugin for Redmine' - version '0.9.0' - requires_redmine :version_or_higher => '3.4.0' + version '1.0.0' + requires_redmine :version_or_higher => '4.0.0' project_module :code_review do permission :view_code_review, {:code_review => [:update_diff_view, :update_attachment_view, :update_revisions_view, :index, :show]}, {:read => true} From d4ca9b72b034cb1583e2bf091067fad58e6e8388 Mon Sep 17 00:00:00 2001 From: Haruyuki Iida Date: Sat, 29 Dec 2018 21:21:14 +0900 Subject: [PATCH 26/33] fixes broken tests --- test/fixtures/code_review_assignments.yml | 22 +++++++++---------- .../repositories_controller_test.rb | 12 +++++----- .../unit/code_review_attachment_patch_test.rb | 2 +- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/test/fixtures/code_review_assignments.yml b/test/fixtures/code_review_assignments.yml index c23a486..d4f09a0 100644 --- a/test/fixtures/code_review_assignments.yml +++ b/test/fixtures/code_review_assignments.yml @@ -2,13 +2,13 @@ one: id: 1 - issue_id: + issue_id: 1 - change_id: + change_id: 1 - attachment_id: + attachment_id: - file_path: MyString + file_path: /aaa/bbb rev: 1 @@ -19,17 +19,17 @@ one: two: id: 2 - issue_id: + issue_id: 1 - change_id: + change_id: 2 - attachment_id: + attachment_id: 1 - file_path: MyString + file_path: /aaa/bbb - rev: MyString + rev: 2 - rev_to: MyString + rev_to: 3 - action_type: MyString + action_type: diff diff --git a/test/functional/repositories_controller_test.rb b/test/functional/repositories_controller_test.rb index c32d246..0edb2bd 100644 --- a/test/functional/repositories_controller_test.rb +++ b/test/functional/repositories_controller_test.rb @@ -62,13 +62,13 @@ def test_revision project.repository = changeset.repository issue = Issue.generate!({:project_id => project.id, :description => 'test', :tracker => Tracker.find(1), :status_id => 1}) review = FactoryBot.create(:code_review, change: change, project: project, issue: issue) - get :revision, :params => {:id => project.id, :rev => changeset.revision, :path => change.path.split('/')} + get :revision, :params => {:id => project.id, :rev => changeset.revision, :path => change.path.split('/'), repository_id: 1} #assert_response :success end def test_revisions @request.session[:user_id] = 1 - get :revisions, :params => {:id => 1} + get :revisions, :params => {:id => 1, repository_id: 10} assert_response :success end @@ -79,14 +79,14 @@ def test_show end def test_diff - @request.session[:user_id] = 1 - get :diff, :params => {:id => 1, :path => '/subversion_test/helloworld.c'.split('/'), :rev => 8} + @request.session[:user_id] = 10 + get :diff, :params => {:id => 1, :path => '/subversion_test/helloworld.c'.split('/'), :rev => 8, repository_id: 10} #assert_response :success end def test_entry - @request.session[:user_id] = 1 - get :entry, :params => {:id => 1, :path => '/subversion_test/helloworld.c'.split('/'), :rev => 8} + @request.session[:user_id] = 10 + get :entry, :params => {:id => 1, :path => '/subversion_test/helloworld.c'.split('/'), :rev => 8, repository_id: 10} assert_response :success end end diff --git a/test/unit/code_review_attachment_patch_test.rb b/test/unit/code_review_attachment_patch_test.rb index faa39c9..9484ff2 100644 --- a/test/unit/code_review_attachment_patch_test.rb +++ b/test/unit/code_review_attachment_patch_test.rb @@ -24,7 +24,7 @@ class CodeReviewAttachmentPatchTest < ActiveSupport::TestCase def setup @project = Project.find(1) @issue = Issue.where(:project_id => 1).first - @attachment = FactoryGirl.create(:attachment, container: @issue) + @attachment = FactoryBot.create(:attachment, container: @issue) end context "code_review_assginments" do From d83424e6f60f420ef2abff0159d5dde42b042a1d Mon Sep 17 00:00:00 2001 From: Haruyuki Iida Date: Sat, 29 Dec 2018 21:31:31 +0900 Subject: [PATCH 27/33] fixes broken tests --- test/unit/code_review_changeset_patch_test.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/unit/code_review_changeset_patch_test.rb b/test/unit/code_review_changeset_patch_test.rb index fe75b5c..89cd5f0 100644 --- a/test/unit/code_review_changeset_patch_test.rb +++ b/test/unit/code_review_changeset_patch_test.rb @@ -47,6 +47,7 @@ def test_review_issues end def test_assignment_count + CodeReviewAssignment.destroy_all changeset = Changeset.find(100) assert_equal(0, changeset.assignment_count) change = changeset.filechanges[0] @@ -114,6 +115,7 @@ def test_completed_assignment_pourcent end should "returns 100 if changeset has no closed assignments." do + CodeReviewAssignment.destroy_all change = FactoryBot.create(:change) changeset = change.changeset @project = Project.find(1) From 76e0b41ef197c36b79694a55cedac22097e6b3f7 Mon Sep 17 00:00:00 2001 From: Haruyuki Iida Date: Sun, 30 Dec 2018 09:41:54 +0900 Subject: [PATCH 28/33] fix broken tests --- test/unit/code_review_changeset_patch_test.rb | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/test/unit/code_review_changeset_patch_test.rb b/test/unit/code_review_changeset_patch_test.rb index 89cd5f0..a569230 100644 --- a/test/unit/code_review_changeset_patch_test.rb +++ b/test/unit/code_review_changeset_patch_test.rb @@ -116,13 +116,18 @@ def test_completed_assignment_pourcent should "returns 100 if changeset has no closed assignments." do CodeReviewAssignment.destroy_all + Issue.destroy_all change = FactoryBot.create(:change) changeset = change.changeset @project = Project.find(1) issue1 = Issue.generate!({:project => @project, :status => IssueStatus.find(5)}) issue1.status = IssueStatus.find(5) + issue1.save! + issue1 = Issue.find(issue1.id) issue2 = Issue.generate!({:project => @project, :status => IssueStatus.find(5)}) issue2.status = IssueStatus.find(5) + issue2.save! + issue2 = Issue.find(issue2.id) change.code_review_assignments << FactoryBot.create(:code_review_assignment, issue: issue1) change.code_review_assignments << FactoryBot.create(:code_review_assignment, issue: issue2) change.save! @@ -137,21 +142,32 @@ def test_completed_assignment_pourcent end should "returns 50 if half of assignments were closed." do + CodeReviewAssignment.destroy_all + Issue.destroy_all + Change.destroy_all + Changeset.destroy_all change = FactoryBot.create(:change) changeset = change.changeset @project = Project.generate! issue1 = Issue.generate!({:project => @project, :status => IssueStatus.find(5)}) + issue1.save! issue2 = Issue.generate!({:project => @project, :status => IssueStatus.find(1)}) + issue2.save! issue3 = Issue.generate!({:project => @project, :status => IssueStatus.find(5)}) + issue3.save! issue4 = Issue.generate!({:project => @project, :status => IssueStatus.find(1)}) - change.code_review_assignments << FactoryBot.create(:code_review_assignment, issue: issue1) - change.code_review_assignments << FactoryBot.create(:code_review_assignment, issue: issue2) + issue4.save! + change.code_review_assignments << FactoryBot.create(:code_review_assignment, issue: Issue.find(issue1.id)) + change.code_review_assignments << FactoryBot.create(:code_review_assignment, issue: Issue.find(issue2.id)) change.save! + assert_equal(1, change.open_assignment_count) change = FactoryBot.create(:change, changeset: changeset) - change.code_review_assignments << FactoryBot.create(:code_review_assignment, issue: issue3) - change.code_review_assignments << FactoryBot.create(:code_review_assignment, issue: issue4) + change.code_review_assignments << FactoryBot.create(:code_review_assignment, issue: Issue.find(issue3.id)) + change.code_review_assignments << FactoryBot.create(:code_review_assignment, issue: Issue.find(issue4.id)) change.save! + changeset.save! changeset = Changeset.find(changeset.id) + assert_equal(2, changeset.open_assignment_count) assert_equal(50, changeset.closed_assignment_pourcent) end end From c025c61c234104867c47e5a0a36d8a6d7ad8556f Mon Sep 17 00:00:00 2001 From: Haruyuki Iida Date: Sun, 30 Dec 2018 12:26:39 +0900 Subject: [PATCH 29/33] fix broken tests --- test/unit/code_review_changeset_patch_test.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/unit/code_review_changeset_patch_test.rb b/test/unit/code_review_changeset_patch_test.rb index a569230..8b5e1af 100644 --- a/test/unit/code_review_changeset_patch_test.rb +++ b/test/unit/code_review_changeset_patch_test.rb @@ -1,5 +1,5 @@ # Code Review plugin for Redmine -# Copyright (C) 2009-2017 Haruyuki Iida +# Copyright (C) 2009-2018 Haruyuki Iida # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -150,12 +150,16 @@ def test_completed_assignment_pourcent changeset = change.changeset @project = Project.generate! issue1 = Issue.generate!({:project => @project, :status => IssueStatus.find(5)}) + issue1.status = IssueStatus.find(5) issue1.save! issue2 = Issue.generate!({:project => @project, :status => IssueStatus.find(1)}) + issue2.status = IssueStatus.find(1) issue2.save! issue3 = Issue.generate!({:project => @project, :status => IssueStatus.find(5)}) + issue3.status = IssueStatus.find(5) issue3.save! issue4 = Issue.generate!({:project => @project, :status => IssueStatus.find(1)}) + issue4.status = IssueStatus.find(1) issue4.save! change.code_review_assignments << FactoryBot.create(:code_review_assignment, issue: Issue.find(issue1.id)) change.code_review_assignments << FactoryBot.create(:code_review_assignment, issue: Issue.find(issue2.id)) From d9fc6ff4187933eb24d4d4692a7d66b30cd0f5f4 Mon Sep 17 00:00:00 2001 From: Haruyuki Iida Date: Sun, 30 Dec 2018 12:45:53 +0900 Subject: [PATCH 30/33] fix broken tests --- test/functional/issues_controller_test.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/test/functional/issues_controller_test.rb b/test/functional/issues_controller_test.rb index 5bcbfbf..1c24d6f 100644 --- a/test/functional/issues_controller_test.rb +++ b/test/functional/issues_controller_test.rb @@ -1,5 +1,5 @@ # Code Review plugin for Redmine -# Copyright (C) 2009-2017 Haruyuki Iida +# Copyright (C) 2009-2018 Haruyuki Iida # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -45,7 +45,10 @@ class IssuesControllerTest < ActionController::TestCase :journal_details, :code_reviews, :code_review_assignments, - :code_review_user_settings + :code_review_user_settings, + :changes, + :changesets, + :repositories def setup @controller = IssuesController.new @@ -72,7 +75,7 @@ def test_show issue = Issue.generate!(:project => project) get :show, params: {id: issue.id} - assignment = FactoryBot.create(:code_review_assignment, issue: issue, rev: 'aaa', file_path: nil) + assignment = FactoryBot.create(:code_review_assignment, issue: issue, rev: 'aaa', file_path: nil, change_id: 1) get :show, :params => {:id => assignment.issue.id} issue = Issue.generate!(:project => Project.find(1)) From 4a43c9269af7f9394464eb29fc872c555ce2eea8 Mon Sep 17 00:00:00 2001 From: Haruyuki Iida Date: Sun, 30 Dec 2018 12:52:13 +0900 Subject: [PATCH 31/33] add ruby 2.5 and 4.0-stable branch to travis environment. --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 77ace18..29c721d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,8 +2,10 @@ language: ruby rvm: - 2.3 - 2.4 +- 2.5 env: - REDMINE_VER=master +- REDMINE_VER=4.0-stable install: - bash -x ./travis/travis_install.sh script: From 6d1e4aeb667131f2d81f0a667fc1b062f328e305 Mon Sep 17 00:00:00 2001 From: Haruyuki Iida Date: Sun, 30 Dec 2018 20:29:34 +0900 Subject: [PATCH 32/33] #13 can't show review of attachment file. --- app/controllers/code_review_controller.rb | 2 +- .../code_review/_issues_show_details_bottom.html.erb | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/controllers/code_review_controller.rb b/app/controllers/code_review_controller.rb index ea15807..d64143b 100644 --- a/app/controllers/code_review_controller.rb +++ b/app/controllers/code_review_controller.rb @@ -252,7 +252,7 @@ def show if action_name == 'attachment' attachment = target.attachment url = url_for(controller: 'attachments', action: 'show', - id: attachment.id) + '/' + URI.escape_www_form(attachment.filename) + id: attachment.id) + '/' + URI.encode(attachment.filename) url << '?review_id=' + @review.id.to_s if @review else path = nil if target.diff_all diff --git a/app/views/code_review/_issues_show_details_bottom.html.erb b/app/views/code_review/_issues_show_details_bottom.html.erb index 620f2a2..62463e9 100644 --- a/app/views/code_review/_issues_show_details_bottom.html.erb +++ b/app/views/code_review/_issues_show_details_bottom.html.erb @@ -5,7 +5,7 @@ <% unless User.current.allowed_to?({:controller => 'code_review', :action => 'show'}, project) - return + return end %> @@ -18,7 +18,11 @@ review = issue.code_review <%= l(:code_review) %>: <% - label = URI.decode("#{review.repository_identifier + ':' if review.repository_identifier}#{review.path}#{'@' + review.revision if review.revision}:line #{review.line}") + if review.attachment + label = URI.decode("#{review.attachment.filename}#{'@' + review.revision if review.revision}:line #{review.line}") + else + label = URI.decode("#{review.repository_identifier + ':' if review.repository_identifier}#{review.path}#{'@' + review.revision if review.revision}:line #{review.line}") + end -%> <%= link_to(label, :controller => 'code_review', :action => 'show', :id => project, :review_id => review.id, :repository_id => review.repository_identifier) %> @@ -26,7 +30,7 @@ review = issue.code_review <% end %> <% if issue.code_review_assignment %> - <% + <% assignment = issue.code_review_assignment repository_id = assignment.repository_identifier %> From 3a920e8c87f0eadf2064c5b7d7605f47302b4da9 Mon Sep 17 00:00:00 2001 From: Haruyuki Iida Date: Mon, 31 Dec 2018 15:55:41 +0900 Subject: [PATCH 33/33] Change plugin's url. --- init.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/init.rb b/init.rb index c2e5ede..d0f8bf4 100644 --- a/init.rb +++ b/init.rb @@ -50,7 +50,7 @@ name 'Redmine Code Review plugin' author 'Haruyuki Iida' author_url 'http://twitter.com/haru_iida' - url "http://www.r-labs.org/projects/show/codereview" if respond_to?(:url) + url "http://www.redmine.org/plugins/redmine_code_review" if respond_to?(:url) description 'This is a Code Review plugin for Redmine' version '1.0.0' requires_redmine :version_or_higher => '4.0.0'