Made rubocop happy by formatting and minor syntax tweaks.

This commit is contained in:
Matt Amos 2016-08-22 17:23:38 +01:00
parent 5cc0eba3f1
commit 757a1aaa85
18 changed files with 511 additions and 608 deletions

1
Vagrantfile vendored
View file

@ -1,7 +1,6 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.provider "virtualbox" do |vb|
vb.customize ["modifyvm", :id, "--memory", "8192"]

View file

@ -153,7 +153,7 @@ class DiaryEntryController < ApplicationController
if @entry
@title = t "diary_entry.view.title", :user => params[:display_name], :title => @entry.title
if params[:comment_id]
@reported_comment = DiaryComment.where(id: params[:comment_id])
@reported_comment = DiaryComment.where(:id => params[:comment_id])
end
else
@title = t "diary_entry.no_such_entry.title", :id => params[:id]

View file

@ -4,122 +4,112 @@ class IssuesController < ApplicationController
before_action :authorize_web
before_action :require_user
before_action :set_issues
before_action :check_permission, only: [:index, :show, :resolve,:open,:ignore,:comment]
before_action :find_issue, only: [:show, :resolve, :reopen, :ignore]
before_action :get_user_role, only: [:show, :index]
before_action :check_permission, :only => [:index, :show, :resolve, :open, :ignore, :comment]
before_action :find_issue, :only => [:show, :resolve, :reopen, :ignore]
before_action :setup_user_role, :only => [:show, :index]
helper_method :sort_column, :sort_direction
def index
if @user.moderator?
@issue_types = @moderator_issues
@users = User.joins(:roles).where(user_roles: {role: 'moderator'})
@users = User.joins(:roles).where(:user_roles => { :role => "moderator" })
else
@issue_types = @admin_issues
@users = User.joins(:roles).where(user_roles: {role: 'administrator'})
@users = User.joins(:roles).where(:user_roles => { :role => "administrator" })
end
@issues = Issue.where(issue_type: @user_role).order(sort_column + " " + sort_direction)
@issues = Issue.where(:issue_type => @user_role).order(sort_column + " " + sort_direction)
# If search
if params[:search_by_user] and !params[:search_by_user].blank?
if params[:search_by_user] && !params[:search_by_user].blank?
@find_user = User.find_by_display_name(params[:search_by_user])
if @find_user
@issues = @issues.where(reported_user_id: @find_user.id)
else
notice = t('issues.index.search.user_not_found')
@issues = @issues.where(:reported_user_id => @find_user.id)
else
notice = t("issues.index.search.user_not_found")
end
end
if params[:status] and !params[:status][0].blank?
@issues = @issues.where(status: params[:status][0].to_i)
if params[:status] && !params[:status][0].blank?
@issues = @issues.where(:status => params[:status][0].to_i)
end
if params[:issue_type] and !params[:issue_type][0].blank?
@issues = @issues.where(reportable_type: params[:issue_type][0])
if params[:issue_type] && !params[:issue_type][0].blank?
@issues = @issues.where(:reportable_type => params[:issue_type][0])
end
# If last_updated_by
if params[:last_updated_by] and !params[:last_updated_by][0].blank?
last_reported_by = params[:last_updated_by][0].to_s == "nil" ? nil : params[:last_updated_by][0].to_i
@issues = @issues.where(updated_by: last_updated_by)
if params[:last_updated_by] && !params[:last_updated_by][0].blank?
last_updated_by = params[:last_updated_by][0].to_s == "nil" ? nil : params[:last_updated_by][0].to_i
@issues = @issues.where(:updated_by => last_updated_by)
end
if @issues.first == nil
notice = t('issues.index.search.issues_not_found')
end
notice = t("issues.index.search.issues_not_found") if @issues.first.nil?
if params[:last_reported_by] and !params[:last_reported_by][0].blank?
if params[:last_reported_by] && !params[:last_reported_by][0].blank?
last_reported_by = params[:last_reported_by][0].to_s == "nil" ? nil : params[:last_reported_by][0].to_i
@issues = @issues.where(updated_by: last_reported_by)
@issues = @issues.where(:updated_by => last_reported_by)
end
if notice
redirect_to issues_path, notice: notice
end
redirect_to issues_path, :notice => notice if notice
end
def show
@read_reports = @issue.read_reports
@unread_reports = @issue.unread_reports
@comments = @issue.comments
@related_issues = @issue.user.issues.where(issue_type: @user_role)
if @issue.updated_by
@updated_by_admin = User.find(@issue.updated_by)
end
@related_issues = @issue.user.issues.where(:issue_type => @user_role)
@updated_by_admin = User.find(@issue.updated_by) if @issue.updated_by
end
def new
unless create_new_issue_params.blank?
@issue = Issue.find_or_initialize_by(create_new_issue_params)
path = 'issues.report_strings.' + @issue.reportable.class.name.to_s
path = "issues.report_strings." + @issue.reportable.class.name.to_s
@report_strings_yaml = t(path)
flash[:referer] = params[:referer]
end
end
def create
@issue = Issue.find_by_reportable_id_and_reportable_type(params[:reportable_id],params[:reportable_type])
@issue = Issue.find_by_reportable_id_and_reportable_type(params[:reportable_id], params[:reportable_type])
# Check if Issue already exists
if !@issue
unless @issue
@issue = Issue.find_or_initialize_by(issue_params)
@issue.updated_by = nil
# Reassign to moderators if it is a moderator issue
@issue.issue_type = "administrator"
if @moderator_issues.include? @issue.reportable.class.name
reassign_issue
end
reassign_issue if @moderator_issues.include? @issue.reportable.class.name
end
# Check if details provided are sufficient
if check_report_params
@report = @issue.reports.build(report_params)
details = get_report_details
details = report_details
@report.reporter_user_id = @user.id
@report.details = details
# Checking if instance has been updated since last report
@last_report = @issue.reports.order(updated_at: :desc).last
@last_report = @issue.reports.order(:updated_at => :desc).last
if check_if_updated
if @issue.reopen
@issue.save!
end
@issue.save! if @issue.reopen
end
if @issue.save!
@issue.report_count = @issue.reports.count
@issue.save!
@admins_or_mods = UserRole.where(role: @issue.issue_type)
@admins_or_mods = UserRole.where(:role => @issue.issue_type)
@admins_or_mods.each do |user|
Notifier.new_issue_notification(@issue.id, User.find(user.user_id)).deliver_now
end
redirect_to flash[:referer], notice: t('issues.create.successful_report')
redirect_to flash[:referer], :notice => t("issues.create.successful_report")
end
else
redirect_to new_issue_path(reportable_type: @issue.reportable_type,reportable_id: @issue.reportable_id, reported_user_id: @issue.reported_user_id), notice: t('issues.create.provide_details')
redirect_to new_issue_path(:reportable_type => @issue.reportable_type, :reportable_id => @issue.reportable_id, :reported_user_id => @issue.reported_user_id), :notice => t("issues.create.provide_details")
end
end
@ -127,43 +117,40 @@ class IssuesController < ApplicationController
@issue = Issue.find_by(issue_params)
# Check if details provided are sufficient
if check_report_params
@report = @issue.reports.where(reporter_user_id: @user.id).first
if @report == nil
@report = @issue.reports.where(:reporter_user_id => @user.id).first
if @report.nil?
@report = @issue.reports.build(report_params)
@report.reporter_user_id = @user.id
notice = t('issues.update.new_report')
notice = t("issues.update.new_report")
end
details = get_report_details
@report.details = details
details = report_details
@report.details = details
# Checking if instance has been updated since last report
@last_report = @issue.reports.order(updated_at: :desc).last
# Checking if instance has been updated since last report
@last_report = @issue.reports.order(:updated_at => :desc).last
if check_if_updated
@issue.reopen
@issue.save!
end
if notice == nil
notice = t('issues.update.successful_update')
end
notice = t("issues.update.successful_update") if notice.nil?
if @report.save!
@issue.report_count = @issue.reports.count
@issue.save!
redirect_to flash[:referer], notice: notice
redirect_to flash[:referer], :notice => notice
end
else
redirect_to new_issue_path(reportable_type: @issue.reportable_type,reportable_id: @issue.reportable_id, reported_user_id: @issue.reported_user_id), notice: t('issues.update.provide_details')
end
redirect_to new_issue_path(:reportable_type => @issue.reportable_type, :reportable_id => @issue.reportable_id, :reported_user_id => @issue.reported_user_id), :notice => t("issues.update.provide_details")
end
end
def comment
@issue = Issue.find(params[:id])
if issue_comment_params.blank?
notice = t('issues.comment.provide_details')
notice = t("issues.comment.provide_details")
else
@issue_comment = @issue.comments.build(issue_comment_params)
@issue_comment.commenter_user_id = @user.id
@ -174,16 +161,16 @@ class IssuesController < ApplicationController
@issue_comment.save!
@issue.updated_by = @user.id
@issue.save!
notice = t('issues.comment.comment_created')
notice = t("issues.comment.comment_created")
end
redirect_to @issue, notice: notice
redirect_to @issue, :notice => notice
end
# Status Transistions
def resolve
if @issue.resolve
@issue.save!
redirect_to @issue, notice: t('issues.resolved')
redirect_to @issue, :notice => t("issues.resolved")
else
render :show
end
@ -193,7 +180,7 @@ class IssuesController < ApplicationController
if @issue.ignore
@issue.updated_by = @user.id
@issue.save!
redirect_to @issue, notice: t('issues.ignored')
redirect_to @issue, :notice => t("issues.ignored")
else
render :show
end
@ -201,9 +188,9 @@ class IssuesController < ApplicationController
def reopen
if @issue.reopen
@issue.updated_by = @user.id
@issue.updated_by = @user.id
@issue.save!
redirect_to @issue, notice: t('issues.reopened')
redirect_to @issue, :notice => t("issues.reopened")
else
render :show
end
@ -211,83 +198,78 @@ class IssuesController < ApplicationController
# Reassign Issues between Administrators and Moderators
def reassign_issue
if @issue.issue_type == "moderator"
@issue.issue_type = "administrator"
else
@issue.issue_type = "moderator"
end
@issue.issue_type = upgrade_issue(@issue.issue_type)
@issue.save!
end
private
def set_issues
@admin_issues = [ 'DiaryEntry', 'DiaryComment', 'User']
@moderator_issues = [ 'Changeset', 'Note' ]
def upgrade_issue(type)
if type == "moderator"
"administrator"
else
"moderator"
end
end
def get_user_role
# Get user role
if @user.administrator?
@user_role = "administrator"
else
@user_role = "moderator"
end
end
def check_if_updated
if @issue.reportable and (@issue.ignored? or @issue.resolved?) and @issue.reportable.has_attribute?(:updated_by) and @issue.reportable.updated_at > @last_report.updated_at
return true
else
return false
end
end
def get_report_details
details = params[:report][:details] + "--||--"
details = details + params[:report_type].to_s + "--||--"
return details
end
def set_issues
@admin_issues = %w(DiaryEntry DiaryComment User)
@moderator_issues = %w(Changeset Note)
end
def check_report_params
if params[:report] and params[:report][:details] and params[:report_type]
return true
end
def setup_user_role
# Get user role
@user_role = @user.administrator? ? "administrator" : "moderator"
end
def check_if_updated
if @issue.reportable && (@issue.ignored? || @issue.resolved?) && @issue.reportable.has_attribute?(:updated_by) && @issue.reportable.updated_at > @last_report.updated_at
return true
else
return false
end
end
def find_issue
@issue = Issue.find(params[:id])
end
def report_details
params[:report][:details] + "--||--" + params[:report_type].to_s + "--||--"
end
def check_permission
unless @user.administrator? or @user.moderator?
flash[:error] = t('application.require_admin.not_an_admin')
redirect_to root_path
end
end
def check_report_params
params[:report] && params[:report][:details] && params[:report_type]
end
def create_new_issue_params
params.permit(:reportable_id, :reportable_type, :reported_user_id)
end
def find_issue
@issue = Issue.find(params[:id])
end
def issue_params
params[:issue].permit(:reportable_id, :reportable_type,:reported_user_id)
def check_permission
unless @user.administrator? || @user.moderator?
flash[:error] = t("application.require_admin.not_an_admin")
redirect_to root_path
end
end
def report_params
params[:report].permit(:details)
end
def create_new_issue_params
params.permit(:reportable_id, :reportable_type, :reported_user_id)
end
def issue_comment_params
params.require(:issue_comment).permit(:body)
end
def issue_params
params[:issue].permit(:reportable_id, :reportable_type, :reported_user_id)
end
def sort_column
Issue.column_names.include?(params[:sort]) ? params[:sort] : "status"
end
def report_params
params[:report].permit(:details)
end
def sort_direction
%w[asc desc].include?(params[:direction]) ? params[:direction] : "asc"
end
def issue_comment_params
params.require(:issue_comment).permit(:body)
end
def sort_column
Issue.column_names.include?(params[:sort]) ? params[:sort] : "status"
end
def sort_direction
%w(asc desc).include?(params[:direction]) ? params[:direction] : "asc"
end
end

View file

@ -1,109 +1,74 @@
module IssuesHelper
def reportable_url(reportable)
class_name = reportable.class.name
case class_name
when "DiaryEntry"
link_to reportable.title, :controller => reportable.class.name.underscore, :action => :view, :display_name => reportable.user.display_name, :id => reportable.id
when "User"
link_to reportable.display_name.to_s, :controller => reportable.class.name.underscore, :action => :view, :display_name => reportable.display_name
when "DiaryComment"
link_to "#{reportable.diary_entry.title}, Comment id ##{reportable.id}", :controller => reportable.diary_entry.class.name.underscore, :action => :view, :display_name => reportable.diary_entry.user.display_name, :id => reportable.diary_entry.id, :comment_id => reportable.id
when "Changeset"
link_to "Changeset ##{reportable.id}", :controller => :browse, :action => :changeset, :id => reportable.id
when "Note"
link_to "Note ##{reportable.id}", :controller => :browse, :action => :note, :id => reportable.id
end
end
def reportable_url(reportable)
class_name = reportable.class.name
case class_name
when "DiaryEntry"
link_to reportable.title, :controller => reportable.class.name.underscore,
:action => :view,
:display_name => reportable.user.display_name,
:id => reportable.id
when "User"
link_to reportable.display_name.to_s, :controller => reportable.class.name.underscore,
:action => :view,
:display_name => reportable.display_name
when "DiaryComment"
link_to "#{reportable.diary_entry.title}, Comment id ##{reportable.id}", :controller => reportable.diary_entry.class.name.underscore,
:action => :view,
:display_name => reportable.diary_entry.user.display_name,
:id => reportable.diary_entry.id,
:comment_id => reportable.id
when "Changeset"
link_to "Changeset ##{reportable.id}", :controller => :browse,
:action => :changeset,
:id => reportable.id
when "Note"
link_to "Note ##{reportable.id}", :controller => :browse,
:action => :note,
:id => reportable.id
else
nil
end
end
def reports_url(issue)
class_name = issue.reportable.class.name
case class_name
when "DiaryEntry"
link_to issue.reportable.title, issue
when "User"
link_to issue.reportable.display_name.to_s, issue
when "DiaryComment"
link_to "#{issue.reportable.diary_entry.title}, Comment id ##{issue.reportable.id}", issue
when "Changeset"
link_to "Changeset ##{issue.reportable.id}", issue
when "Note"
link_to "Note ##{issue.reportable.id}", issue
end
end
def reports_url(issue)
class_name = issue.reportable.class.name
case class_name
when "DiaryEntry"
link_to issue.reportable.title, issue
when "User"
link_to issue.reportable.display_name.to_s, issue
when "DiaryComment"
link_to "#{issue.reportable.diary_entry.title}, Comment id ##{issue.reportable.id}", issue
when "Changeset"
link_to "Changeset ##{issue.reportable.id}",issue
when "Note"
link_to "Note ##{issue.reportable.id}", issue
else
nil
end
end
def instance_url(reportable)
class_name = reportable.class.name
case class_name
when "DiaryEntry"
link_to "Show Instance", :controller => reportable.class.name.underscore, :action => :view, :display_name => reportable.user.display_name, :id => reportable.id
when "User"
link_to "Show Instance", :controller => reportable.class.name.underscore, :action => :view, :display_name => reportable.display_name
when "DiaryComment"
link_to "Show Instance", :controller => reportable.diary_entry.class.name.underscore, :action => :view, :display_name => reportable.diary_entry.user.display_name, :id => reportable.diary_entry.id, :comment_id => reportable.id
when "Changeset"
link_to "Show Instance", :controller => :browse, :action => :changeset, :id => reportable.id
when "Note"
link_to "Show Instance", :controller => :browse, :action => :note, :id => reportable.id
end
end
def instance_url(reportable)
class_name = reportable.class.name
case class_name
when "DiaryEntry"
link_to "Show Instance", :controller => reportable.class.name.underscore,
:action => :view,
:display_name => reportable.user.display_name,
:id => reportable.id
when "User"
link_to "Show Instance", :controller => reportable.class.name.underscore,
:action => :view,
:display_name => reportable.display_name
when "DiaryComment"
link_to "Show Instance", :controller => reportable.diary_entry.class.name.underscore,
:action => :view,
:display_name => reportable.diary_entry.user.display_name,
:id => reportable.diary_entry.id,
:comment_id => reportable.id
when "Changeset"
link_to "Show Instance", :controller => :browse,
:action => :changeset,
:id => reportable.id
when "Note"
link_to "Show Instance", :controller => :browse,
:action => :note,
:id => reportable.id
else
nil
end
end
def sortable(column, title = nil)
title ||= column.titleize
direction = column == sort_column && sort_direction == "asc" ? "desc" : "asc"
if column == sort_column
arrow = direction == "desc" ? ["25B2".hex].pack("U") : ["25BC".hex].pack("U")
title += arrow
end
link_to title, params.merge(:sort => column, :direction => direction)
end
def sortable(column,title=nil)
title ||= column.titleize
direction = column == sort_column && sort_direction == "asc" ? "desc" : "asc"
if column == sort_column
arrow = direction == "desc" ? ["25B2".hex].pack("U") : ["25BC".hex].pack("U")
title = title + arrow
end
link_to title, params.merge(:sort => column, :direction => direction)
end
def report_type(report_class)
case report_class
when "DiaryEntry"
t('activerecord.models.diary_entry')
when "User"
t('activerecord.models.user')
when "DiaryComment"
t('activerecord.models.diary_comment')
when "Changeset"
t('activerecord.models.changeset')
when "Note"
t('activerecord.models.note')
else
nil
end
end
def report_type(report_class)
case report_class
when "DiaryEntry"
t("activerecord.models.diary_entry")
when "User"
t("activerecord.models.user")
when "DiaryComment"
t("activerecord.models.diary_comment")
when "Changeset"
t("activerecord.models.changeset")
when "Note"
t("activerecord.models.note")
end
end
end

View file

@ -1,49 +1,48 @@
class Issue < ActiveRecord::Base
belongs_to :reportable, :polymorphic => true
belongs_to :user, :class_name => "User", :foreign_key => :reported_user_id
belongs_to :user_updated, :class_name => "User", :foreign_key => :updated_by
belongs_to :reportable, :polymorphic => true
belongs_to :user, :class_name => "User", :foreign_key => :reported_user_id
belongs_to :user_updated, :class_name => "User", :foreign_key => :updated_by
has_many :reports, dependent: :destroy
has_many :comments, :class_name => "IssueComment", dependent: :destroy
validates :reportable_id, :uniqueness => { :scope => [ :reportable_type ] }
validates :reported_user_id, :presence => true
has_many :reports, :dependent => :destroy
has_many :comments, :class_name => "IssueComment", :dependent => :destroy
# Check if more statuses are needed
enum status: %w( open ignored resolved )
enum type: %w( administrator moderator )
validates :reportable_id, :uniqueness => { :scope => [:reportable_type] }
validates :reported_user_id, :presence => true
scope :with_status, -> (issue_status) { where(:status => statuses[issue_status])}
# Check if more statuses are needed
enum :status => %w(open ignored resolved)
enum :type => %w(administrator moderator)
def read_reports
resolved_at.present? ? reports.where("updated_at < ?", resolved_at) : nil
end
scope :with_status, -> (issue_status) { where(:status => statuses[issue_status]) }
def unread_reports
def read_reports
resolved_at.present? ? reports.where("updated_at < ?", resolved_at) : nil
end
def unread_reports
resolved_at.present? ? reports.where("updated_at >= ?", resolved_at) : reports
end
end
include AASM
aasm :column => :status, :no_direct_assignment => true do
state :open, :initial => true
state :ignored
state :resolved
include AASM
aasm :column => :status, :no_direct_assignment => true do
state :open, :initial => true
state :ignored
state :resolved
event :ignore do
transitions :from => :open, :to => :ignored
end
event :ignore do
transitions :from => :open, :to => :ignored
end
event :resolve do
transitions :from => :open, :to => :resolved
after do
self.resolved_at = Time.now.getutc
end
end
event :resolve do
transitions :from => :open, :to => :resolved
after do
self.resolved_at = Time.now.getutc
end
end
event :reopen do
transitions :from => :resolved, :to => :open
transitions :from => :ignored, :to => :open
end
end
event :reopen do
transitions :from => :resolved, :to => :open
transitions :from => :ignored, :to => :open
end
end
end

View file

@ -1,6 +1,6 @@
class IssueComment < ActiveRecord::Base
belongs_to :issue
belongs_to :user, :class_name => "User", :foreign_key => :commenter_user_id
belongs_to :issue
belongs_to :user, :class_name => "User", :foreign_key => :commenter_user_id
validates :body, :presence => true
validates :body, :presence => true
end

View file

@ -172,7 +172,7 @@ class Notifier < ActionMailer::Base
end
end
def new_issue_notification(issue_id,recipient)
def new_issue_notification(issue_id, recipient)
with_recipient_locale recipient do
@url = url_for(:host => SERVER_URL,
:controller => "issues",
@ -198,5 +198,4 @@ class Notifier < ActionMailer::Base
EMAIL_FROM
end
end
end

View file

@ -1,5 +1,4 @@
class Report < ActiveRecord::Base
belongs_to :issue
belongs_to :user, :class_name => "User", :foreign_key => :reporter_user_id
belongs_to :issue
belongs_to :user, :class_name => "User", :foreign_key => :reporter_user_id
end

View file

@ -29,7 +29,7 @@ class User < ActiveRecord::Base
has_many :issues, :class_name => "Issue", :foreign_key => :reported_user_id
has_one :issue, :class_name => "Issue", :foreign_key => :updated_by
has_many :issue_comments
has_many :reports
scope :visible, -> { where(:status => %w(pending active confirmed)) }

View file

@ -297,8 +297,8 @@ OpenStreetMap::Application.routes.draw do
post "reopen"
end
end
post '/comment' => 'issues#comment'
post "/comment" => "issues#comment"
# redactions
resources :redactions

View file

@ -14,10 +14,10 @@ class CreateIssuesAndReports < ActiveRecord::Migration
t.datetime :updated_at
t.integer :updated_by
t.timestamps null: false
t.timestamps :null => false
end
add_foreign_key :issues, :users, :column => :reported_user_id,:name => "issues_reported_user_id_fkey", on_delete: :cascade
add_foreign_key :issues, :users, :column => :reported_user_id, :name => "issues_reported_user_id_fkey", :on_delete => :cascade
add_index :issues, :reported_user_id
add_index :issues, [:reportable_id, :reportable_type]
@ -29,14 +29,13 @@ class CreateIssuesAndReports < ActiveRecord::Migration
t.datetime :created_at
t.datetime :updated_at
t.timestamps null: false
t.timestamps :null => false
end
add_foreign_key :reports, :issues, :name => "reports_issue_id_fkey", on_delete: :cascade
add_foreign_key :reports, :users,:column => :reporter_user_id, :name => "reports_reporter_user_id_fkey", on_delete: :cascade
add_foreign_key :reports, :issues, :name => "reports_issue_id_fkey", :on_delete => :cascade
add_foreign_key :reports, :users, :column => :reporter_user_id, :name => "reports_reporter_user_id_fkey", :on_delete => :cascade
add_index :reports, :reporter_user_id
add_index :reports, :issue_id
end
end

View file

@ -6,14 +6,13 @@ class CreateIssueComments < ActiveRecord::Migration
t.text :body
t.datetime :created_at
t.boolean :reassign
t.timestamps null: false
t.timestamps :null => false
end
add_foreign_key :issue_comments, :issues, :name => "issue_comments_issue_id_fkey", on_delete: :cascade
add_foreign_key :issue_comments, :users,:column => :commenter_user_id, :name => "issue_comments_commenter_user_id", on_delete: :cascade
add_index :issue_comments, :commenter_user_id
add_index :issue_comments, :issue_id
add_foreign_key :issue_comments, :issues, :name => "issue_comments_issue_id_fkey", :on_delete => :cascade
add_foreign_key :issue_comments, :users, :column => :commenter_user_id, :name => "issue_comments_commenter_user_id", :on_delete => :cascade
add_index :issue_comments, :commenter_user_id
add_index :issue_comments, :issue_id
end
end

View file

@ -1,7 +1,7 @@
class AddReportCountToIssues < ActiveRecord::Migration
def change
add_column :issues, :report_count, :integer, :default => 0
add_foreign_key :issues, :users, :column => :updated_by, :name => "issues_updated_by_fkey", on_delete: :cascade
add_index :issues, :updated_by
add_foreign_key :issues, :users, :column => :updated_by, :name => "issues_updated_by_fkey", :on_delete => :cascade
add_index :issues, :updated_by
end
end

File diff suppressed because it is too large Load diff

View file

@ -1,7 +1,7 @@
require 'test_helper'
require "test_helper"
class IssuesControllerTest < ActionController::TestCase
fixtures :users,:user_roles
fixtures :users, :user_roles
def test_view_dashboard_without_auth
# Access issues_path without login
@ -21,16 +21,16 @@ class IssuesControllerTest < ActionController::TestCase
assert_response :success
# Access issues_path by moderator
session[:user]= users(:moderator_user).id
session[:user] = users(:moderator_user).id
get :index
assert_response :success
end
def test_new_issue_without_login
# Test creation of a new issue and a new report without logging in
get :new, {reportable_id: 1, reportable_type: "User", reported_user_id: 1}
get :new, :reportable_id => 1, :reportable_type => "User", :reported_user_id => 1
assert_response :redirect
assert_redirected_to login_path(:referer => new_issue_path(:reportable_id=>1, :reportable_type=>"User",:reported_user_id=> 1))
assert_redirected_to login_path(:referer => new_issue_path(:reportable_id => 1, :reportable_type => "User", :reported_user_id => 1))
end
def test_new_issue_after_login
@ -39,18 +39,19 @@ class IssuesControllerTest < ActionController::TestCase
# Login
session[:user] = users(:normal_user).id
assert_equal Issue.count,0
# Create an Issue and a report
get :new, {reportable_id: 1, reportable_type: "User", reported_user_id: 2}
assert_equal Issue.count, 0
# Create an Issue and a report
get :new, :reportable_id => 1, :reportable_type => "User", :reported_user_id => 2
assert_response :success
assert_difference "Issue.count",1 do
assert_difference "Issue.count", 1 do
details = "Details of a report"
post :create, { :report => { :details => details},
:report_type => "[OFFENSIVE]",
:issue => { reportable_id: 1, reportable_type: "User", reported_user_id: 2} }
post :create,
:report => { :details => details },
:report_type => "[OFFENSIVE]",
:issue => { :reportable_id => 1, :reportable_type => "User", :reported_user_id => 2 }
end
assert_equal Issue.count,1
assert_equal Issue.count, 1
assert_response :redirect
assert_redirected_to root_path
end
@ -61,40 +62,43 @@ class IssuesControllerTest < ActionController::TestCase
# Login
session[:user] = users(:normal_user).id
assert_equal Issue.count,0
assert_equal Issue.count, 0
# Create an Issue and a report
get :new, {reportable_id: 1, reportable_type: "User", reported_user_id: 2}
get :new, :reportable_id => 1, :reportable_type => "User", :reported_user_id => 2
assert_response :success
assert_difference "Issue.count",1 do
assert_difference "Issue.count", 1 do
details = "Details of a report"
post :create, { :report => { :details => details},
:report_type => "[OFFENSIVE]",
:issue => { reportable_id: 1, reportable_type: "User", reported_user_id: 2} }
end
assert_equal Issue.count,1
post :create,
:report => { :details => details },
:report_type => "[OFFENSIVE]",
:issue => { :reportable_id => 1, :reportable_type => "User", :reported_user_id => 2 }
end
assert_equal Issue.count, 1
assert_response :redirect
assert_redirected_to root_path
get :new, {reportable_id: 1, reportable_type: "User", reported_user_id: 2}
get :new, :reportable_id => 1, :reportable_type => "User", :reported_user_id => 2
assert_response :success
# Report without report_type
assert_no_difference "Issue.count" do
details = "Details of another report under the same issue"
post :create, { :report => { :details => details},
:issue => { reportable_id: 1, reportable_type: "User", reported_user_id: 2} }
post :create,
:report => { :details => details },
:issue => { :reportable_id => 1, :reportable_type => "User", :reported_user_id => 2 }
end
assert_response :redirect
assert_equal Issue.find_by_reportable_id_and_reportable_type(1,"User").reports.count,1
assert_equal Issue.find_by_reportable_id_and_reportable_type(1, "User").reports.count, 1
# Report without details
assert_no_difference "Issue.count" do
post :create, { :report_type => "[OFFENSIVE]",
:issue => { reportable_id: 1, reportable_type: "User", reported_user_id: 2} }
post :create,
:report_type => "[OFFENSIVE]",
:issue => { :reportable_id => 1, :reportable_type => "User", :reported_user_id => 2 }
end
assert_response :redirect
assert_equal Issue.find_by_reportable_id_and_reportable_type(1,"User").reports.count,1
assert_equal Issue.find_by_reportable_id_and_reportable_type(1, "User").reports.count, 1
end
def test_new_report_with_complete_details
@ -103,43 +107,46 @@ class IssuesControllerTest < ActionController::TestCase
# Login
session[:user] = users(:normal_user).id
assert_equal Issue.count,0
assert_equal Issue.count, 0
# Create an Issue and a report
get :new, {reportable_id: 1, reportable_type: "User", reported_user_id: 2}
get :new, :reportable_id => 1, :reportable_type => "User", :reported_user_id => 2
assert_response :success
assert_difference "Issue.count",1 do
assert_difference "Issue.count", 1 do
details = "Details of a report"
post :create, { :report => { :details => details},
:report_type => "[OFFENSIVE]",
:issue => { reportable_id: 1, reportable_type: "User", reported_user_id: 2} }
post :create,
:report => { :details => details },
:report_type => "[OFFENSIVE]",
:issue => { :reportable_id => 1, :reportable_type => "User", :reported_user_id => 2 }
end
assert_equal Issue.count,1
assert_equal Issue.count, 1
assert_response :redirect
assert_redirected_to root_path
# Create a report for an existing Issue
get :new, {reportable_id: 1, reportable_type: "User", reported_user_id: 2}
get :new, :reportable_id => 1, :reportable_type => "User", :reported_user_id => 2
assert_response :success
assert_no_difference "Issue.count" do
details = "Details of another report under the same issue"
post :create, { :report => { :details => details},
:report_type => "[OFFENSIVE]",
:issue => { reportable_id: 1, reportable_type: "User", reported_user_id: 2} }
post :create,
:report => { :details => details },
:report_type => "[OFFENSIVE]",
:issue => { :reportable_id => 1, :reportable_type => "User", :reported_user_id => 2 }
end
assert_response :redirect
assert_equal Issue.find_by_reportable_id_and_reportable_type(1,"User").reports.count,2
report_count = Issue.find_by_reportable_id_and_reportable_type(1, "User").reports.count
assert_equal report_count, 2
end
def test_change_status_by_normal_user
# Login as normal user
session[:user] = users(:normal_user).id
# Create Issue
test_new_issue_after_login
assert_equal Issue.count,1
get :resolve, id: Issue.find_by_reportable_id_and_reportable_type(1,"User").id
test_new_issue_after_login
assert_equal Issue.count, 1
get :resolve, :id => Issue.find_by_reportable_id_and_reportable_type(1, "User").id
assert_response :redirect
assert_redirected_to root_path
@ -151,25 +158,25 @@ class IssuesControllerTest < ActionController::TestCase
# Create Issue
test_new_issue_after_login
assert_equal Issue.count,1
assert_equal Issue.count, 1
assert_response :redirect
# Login as administrator
session[:user] = users(:administrator_user).id
# Test 'Resolved'
get :resolve, id: Issue.find_by_reportable_id_and_reportable_type(1,"User").id
assert_equal Issue.find_by_reportable_id_and_reportable_type(1,"User").resolved?, true
get :resolve, :id => Issue.find_by_reportable_id_and_reportable_type(1, "User").id
assert_equal Issue.find_by_reportable_id_and_reportable_type(1, "User").resolved?, true
assert_response :redirect
# Test 'Reopen'
get :reopen, id: Issue.find_by_reportable_id_and_reportable_type(1,"User").id
assert_equal Issue.find_by_reportable_id_and_reportable_type(1,"User").open?, true
get :reopen, :id => Issue.find_by_reportable_id_and_reportable_type(1, "User").id
assert_equal Issue.find_by_reportable_id_and_reportable_type(1, "User").open?, true
assert_response :redirect
# Test 'Ignored'
get :ignore, id: Issue.find_by_reportable_id_and_reportable_type(1,"User").id
assert_equal Issue.find_by_reportable_id_and_reportable_type(1,"User").ignored?, true
get :ignore, :id => Issue.find_by_reportable_id_and_reportable_type(1, "User").id
assert_equal Issue.find_by_reportable_id_and_reportable_type(1, "User").ignored?, true
assert_response :redirect
end
@ -178,33 +185,33 @@ class IssuesControllerTest < ActionController::TestCase
session[:user] = users(:administrator_user).id
# No issues against the user
get :index, search_by_user: "test1"
get :index, :search_by_user => "test1"
assert_response :redirect
assert_redirected_to issues_path
# User doesn't exist
get :index, search_by_user: "test1000"
get :index, :search_by_user => "test1000"
assert_response :redirect
assert_redirected_to issues_path
# Create Issue against user_id:2
test_new_issue_after_login
assert_equal Issue.count,1
assert_equal Issue.first.reported_user_id,2
assert_equal Issue.count, 1
assert_equal Issue.first.reported_user_id, 2
session[:user] = users(:administrator_user).id
# Find Issue against user_id:2
get :index, search_by_user: "test2"
get :index, :search_by_user => "test2"
assert_response :success
end
def test_comment_by_normal_user
# Create Issue
test_new_issue_after_login
assert_equal Issue.count,1
assert_equal Issue.count, 1
get :comment, id: 1
get :comment, :id => 1
assert_response :redirect
assert_redirected_to root_path
end
@ -212,13 +219,13 @@ class IssuesControllerTest < ActionController::TestCase
def test_comment
# Create Issue
test_new_issue_after_login
assert_equal Issue.count,1
assert_equal Issue.count, 1
@issue = Issue.all.first
# Login as administrator
session[:user] = users(:administrator_user).id
get :comment, id: @issue.id, :issue_comment => { body: "test comment" }
get :comment, :id => @issue.id, :issue_comment => { :body => "test comment" }
assert_response :redirect
assert_redirected_to @issue
end

View file

@ -1,4 +1,4 @@
require 'test_helper'
require "test_helper"
class IssueCommentTest < ActiveSupport::TestCase
# test "the truth" do

View file

@ -1,4 +1,4 @@
require 'test_helper'
require "test_helper"
class IssueTest < ActiveSupport::TestCase
# test "the truth" do

View file

@ -1,4 +1,4 @@
require 'test_helper'
require "test_helper"
class ReportTest < ActiveSupport::TestCase
# test "the truth" do