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

Fix warnings in Ruby 2.7 and Ruby 3.0 #5070

Merged
merged 9 commits into from
Jan 31, 2023
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ Lint/BooleanSymbol:
Lint/ConstantDefinitionInBlock:
Enabled: true

Lint/DeprecatedClassMethods:
Enabled: true

Lint/DuplicateBranch:
Enabled: true

Expand Down
4 changes: 2 additions & 2 deletions app/components/admin/table_actions_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
<%= content %>

<% if actions.include?(:edit) %>
<%= action(:edit, edit_options.merge(text: edit_text, path: edit_path)) %>
<%= action(:edit, **edit_options.merge(text: edit_text, path: edit_path)) %>
<% end %>

<% if actions.include?(:destroy) %>
<%= action(:destroy, destroy_options.merge(text: destroy_text, path: destroy_path)) %>
<%= action(:destroy, **destroy_options.merge(text: destroy_text, path: destroy_path)) %>
<% end %>
</div>
2 changes: 1 addition & 1 deletion app/components/admin/widget/cards/row_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
<% end %>
</td>
<td>
<%= render Admin::TableActionsComponent.new(card, options) %>
<%= render Admin::TableActionsComponent.new(card, **options) %>
</td>
</tr>
2 changes: 1 addition & 1 deletion app/components/admin/widget/cards/table_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</thead>
<tbody>
<% cards.each do |card| %>
<%= render Admin::Widget::Cards::RowComponent.new(card, options) %>
<%= render Admin::Widget::Cards::RowComponent.new(card, **options) %>
<% end %>
</tbody>
</table>
Expand Down
10 changes: 9 additions & 1 deletion app/components/shared/link_list_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,15 @@ def present_links
end

def list_items
present_links.map do |text, url, current = false, **link_options|
present_links.map do |text, url, current_or_options = false, options = {}|
if current_or_options.is_a?(Hash)
current = false
link_options = current_or_options
else
current = current_or_options
link_options = options
end

tag.li("aria-current": (true if current)) do
if url
link_to text, url, link_options
Expand Down
20 changes: 10 additions & 10 deletions app/models/machine_learning.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,14 @@ def tenant_data_folder
def data_output_files
files = { tags: [], related_content: [], comments_summary: [] }

files[:tags] << proposals_tags_filename if File.exists?(data_folder.join(proposals_tags_filename))
files[:tags] << proposals_taggings_filename if File.exists?(data_folder.join(proposals_taggings_filename))
files[:tags] << investments_tags_filename if File.exists?(data_folder.join(investments_tags_filename))
files[:tags] << investments_taggings_filename if File.exists?(data_folder.join(investments_taggings_filename))
files[:related_content] << proposals_related_filename if File.exists?(data_folder.join(proposals_related_filename))
files[:related_content] << investments_related_filename if File.exists?(data_folder.join(investments_related_filename))
files[:comments_summary] << proposals_comments_summary_filename if File.exists?(data_folder.join(proposals_comments_summary_filename))
files[:comments_summary] << investments_comments_summary_filename if File.exists?(data_folder.join(investments_comments_summary_filename))
files[:tags] << proposals_tags_filename if File.exist?(data_folder.join(proposals_tags_filename))
files[:tags] << proposals_taggings_filename if File.exist?(data_folder.join(proposals_taggings_filename))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Layout/LineLength: Line is too long. [111/110] (https://rubystyle.guide#max-line-length)

files[:tags] << investments_tags_filename if File.exist?(data_folder.join(investments_tags_filename))
files[:tags] << investments_taggings_filename if File.exist?(data_folder.join(investments_taggings_filename))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Layout/LineLength: Line is too long. [115/110] (https://rubystyle.guide#max-line-length)

files[:related_content] << proposals_related_filename if File.exist?(data_folder.join(proposals_related_filename))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Layout/LineLength: Line is too long. [120/110] (https://rubystyle.guide#max-line-length)

files[:related_content] << investments_related_filename if File.exist?(data_folder.join(investments_related_filename))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Layout/LineLength: Line is too long. [124/110] (https://rubystyle.guide#max-line-length)

files[:comments_summary] << proposals_comments_summary_filename if File.exist?(data_folder.join(proposals_comments_summary_filename))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Layout/LineLength: Line is too long. [139/110] (https://rubystyle.guide#max-line-length)

files[:comments_summary] << investments_comments_summary_filename if File.exist?(data_folder.join(investments_comments_summary_filename))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Layout/LineLength: Line is too long. [143/110] (https://rubystyle.guide#max-line-length)


files
end
Expand Down Expand Up @@ -438,13 +438,13 @@ def set_previous_modified_date
end

def last_modified_date_for(filename)
return nil unless File.exists? data_folder.join(filename)
return nil unless File.exist? data_folder.join(filename)

File.mtime data_folder.join(filename)
end

def updated_file?(filename)
return false unless File.exists? data_folder.join(filename)
return false unless File.exist? data_folder.join(filename)
return true unless previous_modified_date[filename].present?

last_modified_date_for(filename) > previous_modified_date[filename]
Expand Down
2 changes: 2 additions & 0 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
Warning[:deprecated] = true

Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.

Expand Down
2 changes: 2 additions & 0 deletions config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# your test database is "scratch space" for the test suite and is wiped
# and recreated between test runs. Don't rely on the data there!

Warning[:deprecated] = true

Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.

Expand Down
2 changes: 1 addition & 1 deletion config/initializers/globalize.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Globalize
module ActiveRecord
module InstanceMethods
def save(*)
def save(...)
# Credit for this code belongs to Jack Tomaszewski:
# https://github.com/globalize/globalize/pull/578
Globalize.with_locale(Globalize.locale || I18n.default_locale) do
Expand Down
11 changes: 11 additions & 0 deletions db/dev_seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@ def random_locales_attributes(**attribute_names_with_values)
end
end

def add_image_to(imageable, sample_image_files)
# imageable should respond to #title & #author
imageable.image = Image.create!({
imageable: imageable,
title: imageable.title,
attachment: Rack::Test::UploadedFile.new(sample_image_files.sample),
user: imageable.author
})
imageable.save!
end

log "Creating dev seeds for tenant #{Tenant.current_schema}" unless Tenant.default?

load_dev_seeds "settings"
Expand Down
8 changes: 4 additions & 4 deletions db/dev_seeds/admin_notifications.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
section "Creating Admin Notifications & Templates" do
AdminNotification.create!(
random_locales_attributes(
%i[title body].index_with do |attribute|
**%i[title body].index_with do |attribute|
-> { I18n.t("seeds.admin_notifications.proposal.#{attribute}") }
end
).merge(
Expand All @@ -12,23 +12,23 @@

AdminNotification.create!(
random_locales_attributes(
%i[title body].index_with do |attribute|
**%i[title body].index_with do |attribute|
-> { I18n.t("seeds.admin_notifications.help.#{attribute}") }
end
).merge(link: "https://crwd.in/consul", segment_recipient: "administrators")
).deliver

AdminNotification.create!(
random_locales_attributes(
%i[title body].index_with do |attribute|
**%i[title body].index_with do |attribute|
-> { I18n.t("seeds.admin_notifications.map.#{attribute}") }
end
).merge(segment_recipient: "administrators")
).deliver

AdminNotification.create!(
random_locales_attributes(
%i[title body].index_with do |attribute|
**%i[title body].index_with do |attribute|
-> { I18n.t("seeds.admin_notifications.budget.#{attribute}") }
end
).merge(segment_recipient: "administrators", sent_at: nil)
Expand Down
43 changes: 18 additions & 25 deletions db/dev_seeds/budgets.rb
Original file line number Diff line number Diff line change
@@ -1,27 +1,20 @@
INVESTMENT_IMAGE_FILES = %w[
brennan-ehrhardt-25066-unsplash_713x513.jpg
carl-nenzen-loven-381554-unsplash_713x475.jpg
carlos-zurita-215387-unsplash_713x475.jpg
hector-arguello-canals-79584-unsplash_713x475.jpg
olesya-grichina-218176-unsplash_713x475.jpg
sole-d-alessandro-340443-unsplash_713x475.jpg
].map do |filename|
Rails.root.join("db",
"dev_seeds",
"images",
"budget",
"investments", filename)
end
def add_image_to_investment(investment)
image_files = %w[
brennan-ehrhardt-25066-unsplash_713x513.jpg
carl-nenzen-loven-381554-unsplash_713x475.jpg
carlos-zurita-215387-unsplash_713x475.jpg
hector-arguello-canals-79584-unsplash_713x475.jpg
olesya-grichina-218176-unsplash_713x475.jpg
sole-d-alessandro-340443-unsplash_713x475.jpg
].map do |filename|
Rails.root.join("db",
"dev_seeds",
"images",
"budget",
"investments", filename)
end

def add_image_to(imageable)
# imageable should respond to #title & #author
imageable.image = Image.create!({
imageable: imageable,
title: imageable.title,
attachment: Rack::Test::UploadedFile.new(INVESTMENT_IMAGE_FILES.sample),
user: imageable.author
})
imageable.save!
add_image_to(investment, image_files)
end

section "Creating Budgets" do
Expand Down Expand Up @@ -122,7 +115,7 @@ def add_image_to(imageable)
terms_of_service: "1"
}.merge(translation_attributes))

add_image_to(investment) if Random.rand > 0.5
add_image_to_investment(investment) if Random.rand > 0.5
end
end

Expand Down Expand Up @@ -167,7 +160,7 @@ def add_image_to(imageable)
price: rand(10000..heading.price),
terms_of_service: "1"
)
add_image_to(investment) if Random.rand > 0.3
add_image_to_investment(investment) if Random.rand > 0.3
end
budget.headings.each do |heading|
Budget::Result.new(budget, heading).calculate_winners
Expand Down
41 changes: 17 additions & 24 deletions db/dev_seeds/proposals.rb
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
IMAGE_FILES = %w[
firdouss-ross-414668-unsplash_846x475.jpg
nathan-dumlao-496190-unsplash_713x475.jpg
steve-harvey-597760-unsplash_713x475.jpg
tim-mossholder-302931-unsplash_713x475.jpg
].map do |filename|
Rails.root.join("db",
"dev_seeds",
"images",
"proposals", filename)
end
def add_image_to_proposal(proposal)
image_files = %w[
firdouss-ross-414668-unsplash_846x475.jpg
nathan-dumlao-496190-unsplash_713x475.jpg
steve-harvey-597760-unsplash_713x475.jpg
tim-mossholder-302931-unsplash_713x475.jpg
].map do |filename|
Rails.root.join("db",
"dev_seeds",
"images",
"proposals", filename)
end

def add_image_to(imageable)
# imageable should respond to #title & #author
imageable.image = Image.create!({
imageable: imageable,
title: imageable.title,
attachment: Rack::Test::UploadedFile.new(IMAGE_FILES.sample),
user: imageable.author
})
imageable.save!
add_image_to(proposal, image_files)
end

section "Creating Proposals" do
Expand Down Expand Up @@ -47,7 +40,7 @@ def add_image_to(imageable)
proposal.save!
end
end
add_image_to proposal
add_image_to_proposal proposal
end
end

Expand Down Expand Up @@ -75,7 +68,7 @@ def add_image_to(imageable)
proposal.save!
end
end
add_image_to proposal
add_image_to_proposal proposal
end
end

Expand Down Expand Up @@ -103,7 +96,7 @@ def add_image_to(imageable)
proposal.save!
end
end
add_image_to proposal
add_image_to_proposal proposal
end

tags = Tag.where(kind: "category")
Expand All @@ -128,7 +121,7 @@ def add_image_to(imageable)
proposal.save!
end
end
add_image_to proposal
add_image_to_proposal proposal
end
end

Expand Down
8 changes: 4 additions & 4 deletions db/dev_seeds/widgets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def create_image_attachment(type)

Widget::Card.create!(
random_locales_attributes(
%i[title description link_text label].index_with do |attribute|
**%i[title description link_text label].index_with do |attribute|
-> { I18n.t("seeds.cards.header.#{attribute}") }
end
).merge(
Expand All @@ -21,7 +21,7 @@ def create_image_attachment(type)

Widget::Card.create!(
random_locales_attributes(
%i[title description link_text label].index_with do |attribute|
**%i[title description link_text label].index_with do |attribute|
-> { I18n.t("seeds.cards.debate.#{attribute}") }
end
).merge(
Expand All @@ -33,7 +33,7 @@ def create_image_attachment(type)

Widget::Card.create!(
random_locales_attributes(
%i[title description link_text label].index_with do |attribute|
**%i[title description link_text label].index_with do |attribute|
-> { I18n.t("seeds.cards.proposal.#{attribute}") }
end
).merge(
Expand All @@ -45,7 +45,7 @@ def create_image_attachment(type)

Widget::Card.create!(
random_locales_attributes(
%i[title description link_text label].index_with do |attribute|
**%i[title description link_text label].index_with do |attribute|
-> { I18n.t("seeds.cards.budget.#{attribute}") }
end
).merge(
Expand Down
12 changes: 6 additions & 6 deletions spec/lib/tasks/files_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

travel_to(2.days.from_now) { run_rake_task }

expect(File.exists?(image.file_path)).to be false
expect(File.exists?(document.file_path)).to be false
expect(File.exist?(image.file_path)).to be false
expect(File.exist?(document.file_path)).to be false
end

it "does not delete recent cached attachments" do
Expand All @@ -33,8 +33,8 @@

travel_to(2.minutes.from_now) { run_rake_task }

expect(File.exists?(image.file_path)).to be true
expect(File.exists?(document.file_path)).to be true
expect(File.exist?(image.file_path)).to be true
expect(File.exist?(document.file_path)).to be true
end

it "does not delete old regular attachments" do
Expand All @@ -43,8 +43,8 @@

travel_to(2.days.from_now) { run_rake_task }

expect(File.exists?(image.file_path)).to be true
expect(File.exists?(document.file_path)).to be true
expect(File.exist?(image.file_path)).to be true
expect(File.exist?(document.file_path)).to be true
end
end
end
2 changes: 1 addition & 1 deletion spec/shared/system/mappable.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
shared_examples "mappable" do |mappable_factory_name, mappable_association_name, mappable_new_path, mappable_edit_path, mappable_show_path, mappable_path_arguments, management: false|
shared_examples "mappable" do |mappable_factory_name, mappable_association_name, mappable_new_path, mappable_edit_path, mappable_show_path, mappable_path_arguments: {}, management: false|

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Layout/LineLength: Line is too long. [187/110] (https://rubystyle.guide#max-line-length)

let!(:user) { create(:user, :level_two) }
let!(:arguments) { {} }
let!(:mappable) { create(mappable_factory_name.to_s.to_sym) }
Expand Down
Loading