Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More refactoring #9

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 9 additions & 13 deletions app/controllers/code_review_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

class CodeReviewController < ApplicationController
unloadable
before_filter :find_project, :authorize, :find_user, :find_setting, :find_repository

helper :sort
Expand Down Expand Up @@ -348,29 +347,26 @@ def forward_to_revision

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'
changeset_ids = params[:changeset_ids].to_s.split(',')
@changesets = changeset_ids.map do |id|
@repository.find_changeset_by_name(id) unless id.blank?
end
render partial: 'update_revisions'
end

private
def find_repository
if params[:repository_id].present? and @project.repositories
if params[:repository_id].present?
@repository = @project.repositories.find_by_identifier_param(params[:repository_id])
else
@repository = @project.repository
end
@repository_id = @repository.identifier_param if @repository.respond_to?("identifier_param")
@repository_id = @repository.identifier_param
end

def find_project
Expand Down
1 change: 0 additions & 1 deletion app/controllers/code_review_settings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

class CodeReviewSettingsController < ApplicationController
unloadable
layout 'base'
menu_item :code_review
include CodeReviewAutoAssignSettings
Expand Down
1 change: 0 additions & 1 deletion app/helpers/code_review_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
module CodeReviewHelper
unloadable
def show_assignments(assignments, project, options = {})
html = "#{l(:review_assignments)}:"
assignments.each do |assignment|
Expand Down
16 changes: 5 additions & 11 deletions app/models/code_review.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
class CodeReview < ActiveRecord::Base
include Redmine::SafeAttributes
unloadable
belongs_to :project
belongs_to :change
belongs_to :issue
Expand Down Expand Up @@ -158,18 +157,13 @@ def status_id
end

def open_assignment_issues(user_id)
issues = []
assignments = []
assignments = change.code_review_assignments if change
assignments = assignments + changeset.code_review_assignments if changeset
assignments = assignments + attachment.code_review_assignments if attachment
assignments += change.code_review_assignments if change
assignments += changeset.code_review_assignments if changeset
assignments += attachment.code_review_assignments if attachment

assignments.each {|assignment|
unless assignment.is_closed?
issues << assignment.issue if user_id == assignment.issue.assigned_to_id
end
assignments.reject(&:is_closed?).map(&:issue).select{ |issue|
user_id == issue.assigned_to_id
}

issues
end
end
3 changes: 1 addition & 2 deletions app/models/code_review_assignment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

class CodeReviewAssignment < ActiveRecord::Base
unloadable
belongs_to :issue
belongs_to :change
belongs_to :changeset
Expand Down Expand Up @@ -44,7 +43,7 @@ def repository

def repository_identifier
return nil unless repository
@repository_identifier ||= repository.identifier_param if repository.respond_to?("identifier_param")
@repository_identifier ||= repository.identifier_param
end

def self.create_with_changeset(changeset)
Expand Down
1 change: 0 additions & 1 deletion app/models/code_review_project_setting.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
class CodeReviewProjectSetting < ActiveRecord::Base
unloadable
include Redmine::SafeAttributes
include CodeReviewAutoAssignSettings

Expand Down
1 change: 0 additions & 1 deletion app/models/code_review_user_setting.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
class CodeReviewUserSetting < ActiveRecord::Base
unloadable
belongs_to :user

validates_presence_of :user_id
Expand Down
2 changes: 1 addition & 1 deletion app/views/code_review/_body_bottom.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ if project and controller and project.module_enabled?(:code_review)
path = parameters['path'].blank? ? '.' : parameters['path']


repository_id = @repository.identifier_param if @repository.respond_to?("identifier_param")
repository_id = @repository.identifier_param
url = url_for :controller => 'code_review', :action => 'update_diff_view', :id => project, :repository_id => repository_id
%>
<div id="code_review">
Expand Down
4 changes: 2 additions & 2 deletions app/views/code_review/_change_entry_norevision_view.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
parameters = request.parameters
path = parameters['path']
rev = parameters['rev']
repository_id = @repository.identifier_param if @repository.respond_to?("identifier_param")
repository_id = @repository.identifier_param
unless path.blank? or path.empty?
changesets = @repository.latest_changesets(path, rev, Setting.repository_log_display_limit.to_i)
change = changesets[0]
Expand All @@ -36,4 +36,4 @@ unless path.blank? or path.empty?
</script>
<% end %>

<% end %>
<% end %>
2 changes: 1 addition & 1 deletion app/views/code_review/_change_repository_view.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ if @changesets
changeset_ids << ','
}

repository_id = @repository.identifier_param if @repository.respond_to?("identifier_param")
repository_id = @repository.identifier_param
url = url_for :controller => 'code_review', :action => 'update_revisions_view', :id => project, :repository_id => repository_id
%>

Expand Down
2 changes: 1 addition & 1 deletion app/views/code_review/_change_revision_view.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-%>
<%
repository_id = @repository.identifier_param if @repository.respond_to?("identifier_param")
repository_id = @repository.identifier_param
if @changeset
urlprefix = url_for(:controller => 'repositories', :action => 'revisions', :id => project, :repository_id => repository_id) +
'/' + @changeset.identifier + '/entry'
Expand Down
3 changes: 0 additions & 3 deletions lib/code_review_attachment_patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,11 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

require_dependency 'attachment'

module CodeReviewAttachmentPatch
def self.included(base) # :nodoc:
base.send(:include, AttachmentInstanceMethodsCodeReview)

base.class_eval do
unloadable # Send unloadable so it will not be unloaded in development
has_many :code_reviews
has_many :code_review_assignments

Expand Down
3 changes: 0 additions & 3 deletions lib/code_review_change_patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,11 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

require_dependency 'change'

module CodeReviewChangePatch
def self.included(base) # :nodoc:
base.send(:include, ChangeInstanceMethodsCodeReview)

base.class_eval do
unloadable # Send unloadable so it will not be unloaded in development
has_many :code_reviews, :dependent => :destroy
has_many :code_review_assignments, :dependent => :destroy
after_save :review_auto_assign
Expand Down
3 changes: 0 additions & 3 deletions lib/code_review_issue_patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,11 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

require_dependency 'issue'

module CodeReviewIssuePatch
def self.included(base) # :nodoc:
base.send(:include, IssueInstanceMethodsCodeReview)

base.class_eval do
unloadable # Send unloadable so it will not be unloaded in development
has_one :code_review, :dependent => :destroy
has_one :code_review_assignment, :dependent => :destroy

Expand Down
4 changes: 1 addition & 3 deletions test/functional/repositories_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@


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, :projects_trackers

def setup
@controller = RepositoriesController.new
Expand Down Expand Up @@ -59,8 +59,6 @@ def test_revision
change = FactoryGirl.create(:change)
changeset = change.changeset
project = Project.find(1)
project.repository.destroy
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('/')
Expand Down