Skip to content

Commit dd9b660

Browse files
committed
rubocop fix
1 parent 72d1a17 commit dd9b660

File tree

9 files changed

+348
-1
lines changed

9 files changed

+348
-1
lines changed

.rubocop.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,6 @@ Rails/HttpPositionalArguments:
104104

105105
Rails/ActionControllerTestCase:
106106
Enabled: false
107+
108+
Naming/PredicateMethod:
109+
Enabled: false
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# frozen_string_literal: true
2+
3+
module EditsFinder
4+
extend ActiveSupport::Concern
5+
6+
private
7+
8+
def find_edits
9+
params[:sort] = params[:sort] || 'updated_at'
10+
edits = Edit.page(page_param).per_page(10).order("edits.#{params[:sort]} DESC, edits.id DESC")
11+
@edits = add_query_term(add_robotic_term(add_where_term(edits)))
12+
end
13+
14+
def add_where_term(edits)
15+
target_where = '(edits.target_id = ? AND edits.target_type = ?)'
16+
extra_where = add_where_extra_clause
17+
if params[:enlistment] == 'true'
18+
enlist_filter = 'edits.target_type = ? AND edits.project_id = ? AND key is NULL'
19+
edits.where([enlist_filter, 'Enlistment', @parent.id])
20+
elsif extra_where
21+
edits.where(["#{target_where}#{extra_where}", @parent.id, @parent.class.name.tableize, @parent.id])
22+
else
23+
edits.where([target_where, @parent.id, @parent.class.name])
24+
end
25+
end
26+
27+
def add_where_extra_clause
28+
return nil unless [Account, Project, Organization].include?(@parent.class)
29+
30+
" OR edits.#{@parent.class.name.downcase}_id = ?"
31+
end
32+
33+
def add_robotic_term(edits)
34+
non_human_ids = params[:human].to_bool? ? Account.non_human_ids : [0]
35+
edits.where.not(account_id: non_human_ids)
36+
end
37+
38+
def add_query_term(edits)
39+
query_term = params[:q] || params[:query]
40+
query_term ? edits.filter_by(query_term) : edits
41+
end
42+
end
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# frozen_string_literal: true
2+
3+
# This initializer adds nil protection to ActiveAdmin forms
4+
# to prevent "no implicit conversion of nil into String" errors after Rails 6.1 upgrade
5+
6+
module NilSafeAttributes
7+
extend ActiveSupport::Concern
8+
9+
# Convert nil to empty string for safe rendering in forms
10+
def nil_safe(attr_name)
11+
value = send(attr_name)
12+
value.nil? ? '' : value
13+
end
14+
15+
# Dynamically handle safe_* methods
16+
def method_missing(method_name, *args, &)
17+
method_str = method_name.to_s
18+
if method_str.start_with?('safe_')
19+
attr_name = method_str.sub('safe_', '')
20+
return nil_safe(attr_name) if respond_to?(attr_name)
21+
end
22+
super
23+
end
24+
25+
def respond_to_missing?(method_name, include_private = false)
26+
method_str = method_name.to_s
27+
return true if method_str.start_with?('safe_') && respond_to?(method_str.sub('safe_', ''))
28+
29+
super
30+
end
31+
end
32+
33+
# Add the module to ActiveRecord::Base so it's available to all models
34+
ActiveSupport.on_load(:active_record) { include NilSafeAttributes }
35+
36+
# Override ActiveAdmin form builder to handle nil values safely
37+
ActiveAdmin::FormBuilder.class_eval do
38+
# Helper method to get nil-safe value for form inputs
39+
def safe_value_for(method)
40+
object.respond_to?(:nil_safe) ? object.nil_safe(method) : (object.send(method) || '')
41+
end
42+
end
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# frozen_string_literal: true
2+
3+
# Add pagination capabilities to Array objects
4+
class Array
5+
# Simple paginate method for Array to make it compatible with will_paginate
6+
def paginate(options = {})
7+
page = options[:page] || 1
8+
per_page = options[:per_page] || WillPaginate.per_page
9+
total = options.fetch(:total_entries) { size }
10+
11+
WillPaginate::Collection.create(page, per_page, total) do |pager|
12+
pager.replace slice(pager.offset, pager.per_page)
13+
end
14+
end
15+
end
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# frozen_string_literal: true
2+
3+
# This initializer addresses the deprecation warning:
4+
# PG::Coder.new(hash) is deprecated. Please use keyword arguments instead!
5+
#
6+
# The warning comes from ActiveRecord's PostgreSQL adapter which instantiates
7+
# PG::Coder with a hash rather than keyword arguments. This monkey patch
8+
# allows both styles of initialization.
9+
10+
if defined?(PG::Coder)
11+
PG::Coder.singleton_class.class_eval do
12+
alias_method :original_new, :new
13+
14+
def new(*args, **kwargs)
15+
if args.length == 1 && args[0].is_a?(Hash) && kwargs.empty?
16+
# Convert hash argument to keyword arguments
17+
original_new(**args[0])
18+
else
19+
original_new(*args, **kwargs)
20+
end
21+
end
22+
end
23+
end
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# frozen_string_literal: true
2+
3+
# This monkey patch adds safe_concat to String to handle cases
4+
# where HAML templates are rendered without a proper ActionView::OutputBuffer
5+
unless String.instance_methods.include?(:safe_concat)
6+
class String
7+
def safe_concat(value)
8+
self << value
9+
self
10+
end
11+
end
12+
end

config/locales/managers.en.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
en:
2+
managers:
3+
manage:
4+
edit: 'edit'
5+
withdraw: 'withdraw'
6+
approve: 'approve'
7+
reject: 'reject'
8+
remove_manager: 'remove manager'
9+
message_label: 'Message:'
10+
confirm_withdraw: 'Withdraw your request to be a manager of %{target}?'
11+
withdraw_title: '%{name} is no longer a manager of %{target}, withdraw the application.'
12+
confirm_approve: 'Approve %{name} as a project manager for %{target}?'
13+
approve_title: '%{name} is now a manager of %{target}, approve the application.'
14+
confirm_reject: 'Reject %{name} as a project manager for %{target}?'
15+
reject_title: '%{name} is not a manager of %{target}, reject the application. %{name} may reapply later.'
16+
confirm_delete: 'Remove %{name} as a project manager for %{target}?'

fixtures/vcr_cassettes/code_location_find_by_url.yml

Lines changed: 163 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/helpers/assert_select_helper.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# frozen_string_literal: true
2+
3+
module AssertSelectHelper
4+
# A more flexible alternative to assert_select that uses regular expressions
5+
# instead of CSS selectors for more resilient tests.
6+
#
7+
# @param pattern [Regexp] A regular expression to match against the HTML
8+
# @param options [Hash] Optional settings
9+
# @option options [Integer] :count Expected number of matches (exact)
10+
# @option options [Integer] :minimum Minimum number of matches
11+
# @option options [Integer] :maximum Maximum number of matches
12+
# @option options [Boolean] :negative If true, expects pattern NOT to match
13+
def assert_select_flexible(pattern, options = {})
14+
if options[:negative]
15+
assert_no_match(pattern, response.body)
16+
elsif options[:count]
17+
matches = response.body.scan(pattern).count
18+
assert_equal options[:count], matches,
19+
"Expected #{options[:count]} occurrences of #{pattern}, but found #{matches}"
20+
elsif options[:minimum]
21+
matches = response.body.scan(pattern).count
22+
assert matches >= options[:minimum],
23+
"Expected at least #{options[:minimum]} occurrences of #{pattern}, but found #{matches}"
24+
elsif options[:maximum]
25+
matches = response.body.scan(pattern).count
26+
assert matches <= options[:maximum],
27+
"Expected at most #{options[:maximum]} occurrences of #{pattern}, but found #{matches}"
28+
else
29+
assert_match(pattern, response.body)
30+
end
31+
end
32+
end

0 commit comments

Comments
 (0)