Skip to content
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
27 changes: 27 additions & 0 deletions .github/workflows/analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Analysis

on:
push:
branches:
- master
pull_request:

jobs:
test:
strategy:
fail-fast: false
max-parallel: 20
runs-on: ubuntu-latest

env:
CI: true
RAILS_ENV: test

name: leftovers
steps:
- uses: actions/checkout@v2
- uses: ruby/setup-ruby@v1
with:
bundler-cache: true

- run: bin/leftovers
45 changes: 45 additions & 0 deletions .leftovers.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# for instructions on how to address these
# see https://github.com/robotdana/leftovers/tree/v0.12.2/README.md#how-to-resolve

exclude_paths:
- 'vendor/**/*'

keep:
# Policies are used by Pundit to determine what a user can and cannot do.
# Ideally we'd keep track of which policies are actually used, but we
# haven't figured out a way to do that yet.
- path: 'app/policies/*_policy.rb'
privacy: public
type: Method
names:
- create?
- destroy?
- edit?
- index?
- permitted_attributes
- resolve
- show?
- update?
- path: 'app/policies/*_policy.rb'
type: Constant
name:
- has_suffix: Policy

# Mailer previews are used to display emails in the browser.
# They're not used in production, but they're useful for development.
- path: 'spec/mailers/previews/*_preview.rb'
privacy: public
type: Constant
name:
- has_suffix: Preview

dynamic:
# Nested associations are usually assigned in our controllers,
# but the process is often too indirect for leftovers to spot.
- path: 'app/models/*.rb'
name: accepts_nested_attributes_for
calls:
argument: '*'
transforms:
- add_suffix: '_attributes'
- add_suffix: '_attributes='
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ group :development, :test do
gem "factory_bot_rails", "~> 6.0"
gem "faker"
gem "i18n-tasks", "~> 0.9.6"
gem "leftovers", require: false
gem "rspec-rails"
end

Expand Down
6 changes: 6 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ GEM
faraday-net_http (>= 2.0, < 3.2)
faraday-net_http (3.1.0)
net-http
fast_ignore (0.17.4)
ffi (1.16.3)
fog-aws (3.21.0)
fog-core (~> 2.1)
Expand Down Expand Up @@ -202,6 +203,10 @@ GEM
language_server-protocol (3.17.0.3)
launchy (2.5.2)
addressable (~> 2.8)
leftovers (0.12.2)
fast_ignore (>= 0.17.0)
parallel
parser
letter_opener (1.8.1)
launchy (>= 2.2, < 3)
letter_opener_web (2.0.0)
Expand Down Expand Up @@ -479,6 +484,7 @@ DEPENDENCIES
jsonapi-serializer
kaminari
launchy
leftovers
letter_opener_web
listen
net-imap
Expand Down
2 changes: 1 addition & 1 deletion app/channels/application_cable/channel.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

module ApplicationCable
module ApplicationCable # leftovers:keep
class Channel < ActionCable::Channel::Base
end
end
2 changes: 1 addition & 1 deletion app/channels/application_cable/connection.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

module ApplicationCable
module ApplicationCable # leftovers:keep
class Connection < ActionCable::Connection::Base
end
end
2 changes: 1 addition & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ApplicationController < ActionController::Base
before_action :set_paper_trail_whodunnit

# Allow pundit to authorize a non-logged in user
def pundit_user
def pundit_user # leftovers:keep
current_user || User.new
end

Expand Down
4 changes: 2 additions & 2 deletions app/controllers/impact_omniauth_callbacks_controller.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# frozen_string_literal: true

class ImpactOmniauthCallbacksController < DeviseTokenAuth::OmniauthCallbacksController
class ImpactOmniauthCallbacksController < DeviseTokenAuth::OmniauthCallbacksController # leftovers:keep
def auth_hash
@_auth_hash ||= request.env["omniauth.auth"] ||= session.delete("dta.omniauth.auth")
end

def get_resource_from_auth_hash
def get_resource_from_auth_hash # leftovers:keep
super

if @resource
Expand Down
4 changes: 3 additions & 1 deletion app/jobs/send_category_due_emails_job.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class SendCategoryDueEmailsJob < ApplicationJob
# This is currently uncalled because it lacks an entry in Scheduler.rb
# Maybe we can delete it?
class SendCategoryDueEmailsJob < ApplicationJob # leftovers:keep
queue_as :default

def perform
Expand Down
2 changes: 1 addition & 1 deletion app/models/category.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Category < VersionedRecord
has_many :measure_categories, inverse_of: :category, dependent: :destroy
has_many :sdgtarget_categories, inverse_of: :category, dependent: :destroy
has_many :recommendations, through: :recommendation_categories
has_many :users, through: :user_categories
has_many :users, through: :user_categories # leftovers:keep
has_many :measures, through: :measure_categories
has_many :indicators, through: :recommendations
has_many :indicators_via_measures, through: :recommendations
Expand Down
2 changes: 1 addition & 1 deletion app/models/framework.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class Framework < ApplicationRecord
has_many :frameworks, through: :framework_frameworks, source: :other_framework

has_many :framework_taxonomies, inverse_of: :framework, dependent: :destroy
has_many :taxonomies, through: :framework_taxonomies
has_many :taxonomies, through: :framework_taxonomies # leftovers:keep

has_many :recommendations

Expand Down
2 changes: 1 addition & 1 deletion app/models/role.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Role < ApplicationRecord
has_many :user_roles
has_many :users, through: :user_roles
has_many :users, through: :user_roles # leftovers:keep
end
6 changes: 1 addition & 5 deletions app/models/taxonomy.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class Taxonomy < VersionedRecord
has_many :categories
belongs_to :taxonomy, class_name: "Taxonomy", foreign_key: :parent_id, optional: true
has_many :taxonomies, class_name: "Taxonomy", foreign_key: :parent_id
has_many :taxonomies, class_name: "Taxonomy", foreign_key: :parent_id # leftovers:keep

has_many :framework_taxonomies, inverse_of: :taxonomy, dependent: :destroy
has_many :frameworks, through: :framework_taxonomies
Expand All @@ -24,10 +24,6 @@ def sub_relation
end
end

def self.current_reporting_cycle
find(current_reporting_cycle_id)
end

def self.current_reporting_cycle_id
Rails.application.config.x.reporting_cycle_taxonomy_id
end
Expand Down
4 changes: 2 additions & 2 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ class User < VersionedRecord

has_many :user_roles, dependent: :destroy
has_many :roles, through: :user_roles
has_many :managed_categories, foreign_key: :manager_id, class_name: "Category"
has_many :managed_indicators, foreign_key: :manager_id, class_name: "Indicator"
has_many :managed_categories, foreign_key: :manager_id, class_name: "Category" # leftovers:keep
has_many :managed_indicators, foreign_key: :manager_id, class_name: "Indicator" # leftovers:keep
has_many :user_categories
has_many :categories, through: :user_categories
has_many :bookmarks
Expand Down
7 changes: 4 additions & 3 deletions app/serializers/fast_versioned_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ module FastVersionedSerializer
def self.included(base)
base.include FastApplicationSerializer

base.attribute :created_by_id
base.attribute :updated_by_id
base.attribute :created_by_id # leftovers:keep
base.attribute :updated_by_id # leftovers:keep
end

def current_user_has_permission?
# This appears to be uncalled but I'm not 100% sure. Maybe we can delete it?
def current_user_has_permission? # leftovers:keep
current_user&.role?("admin") || current_user&.role?("manager")
end
end
16 changes: 16 additions & 0 deletions bin/leftovers
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

# The application 'leftovers' is installed as part of a gem, and
# this file is here to facilitate running it.

require "pathname"
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
Pathname.new(__FILE__).realpath)

bundle_binstub = File.expand_path("../bundle", __FILE__)

require "rubygems"
require "bundler/setup"

load Gem.bin_path("leftovers", "leftovers")
2 changes: 1 addition & 1 deletion config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)

module HumanRightsNationalReporting
module HumanRightsNationalReporting # leftovers:keep
class Application < Rails::Application
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
Expand Down
2 changes: 1 addition & 1 deletion db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1349,7 +1349,7 @@ def base_seeds!
)
end

def development_seeds!
def development_seeds! # leftovers:keep
nil unless User.count.zero?
end

Expand Down
4 changes: 3 additions & 1 deletion scheduler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
require File.expand_path("../config/environment", __FILE__)
require "clockwork"

module Clockwork
module Clockwork # leftovers:keep
every(1.day, "Send Due Emails", at: "10:30", tz: Rails.application.config.time_zone) do
SendDueEmailsJob.perform_now
end
Expand All @@ -11,6 +11,8 @@ module Clockwork
SendOverdueEmailsJob.perform_now
end

# Should this also have a call to send Category Due Emails?

every(1.day, "Send Category Overdue Emails", at: "9:15", tz: Rails.application.config.time_zone) do
SendCategoryOverdueEmailsJob.perform_now
end
Expand Down
5 changes: 0 additions & 5 deletions spec/support/controller_macros.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,4 @@ def sign_in(user = double("user"))
end
user
end

def sign_in_admin
user = sign_in
allow(user).to receive(:role?).with("admin").and_return(true)
end
end
5 changes: 0 additions & 5 deletions spec/support/feature_spec_helpers.rb

This file was deleted.