Add and apply Rails/DurationArithmetic rubocop rule

This rule was added in rubocop-rails 2.13.0. We were already applying it
most of the time.
This commit is contained in:
Javi Martín
2022-08-24 22:32:43 +02:00
parent 68899c80b6
commit c8270d58bd
18 changed files with 42 additions and 39 deletions

View File

@@ -236,6 +236,9 @@ Rails/CreateTableWithTimestamps:
Rails/Date:
Enabled: true
Rails/DurationArithmetic:
Enabled: true
Rails/DynamicFindBy:
Enabled: true
Whitelist:

View File

@@ -6,9 +6,9 @@ section "Creating banners" do
banner = Banner.new(title: title,
description: description,
target_url: target_url,
post_started_at: rand((Time.current - 1.week)..(Time.current - 1.day)),
post_ended_at: rand((Time.current - 1.day)..(Time.current + 1.week)),
created_at: rand((Time.current - 1.week)..Time.current))
post_started_at: rand((1.week.ago)..(1.day.ago)),
post_ended_at: rand((1.day.ago)..(1.week.from_now)),
created_at: rand((1.week.ago)..Time.current))
I18n.available_locales.map do |locale|
Globalize.with_locale(locale) do
banner.description = "Description for locale #{locale}"

View File

@@ -113,7 +113,7 @@ section "Creating Investments" do
heading: heading,
group: heading.group,
budget: heading.group.budget,
created_at: rand((Time.current - 1.week)..Time.current),
created_at: rand((1.week.ago)..Time.current),
feasibility: %w[undecided unfeasible feasible feasible feasible feasible].sample,
unfeasibility_explanation: Faker::Lorem.paragraph,
valuation_finished: [false, true].sample,
@@ -160,7 +160,7 @@ section "Winner Investments" do
budget: heading.group.budget,
title: Faker::Lorem.sentence(word_count: 3).truncate(60),
description: "<p>#{Faker::Lorem.paragraphs.join("</p><p>")}</p>",
created_at: rand((Time.current - 1.week)..Time.current),
created_at: rand((1.week.ago)..Time.current),
feasibility: "feasible",
valuation_finished: true,
selected: true,

View File

@@ -5,7 +5,7 @@ section "Creating Debates" do
description = "<p>#{Faker::Lorem.paragraphs.join("</p><p>")}</p>"
debate = Debate.create!(author: author,
title: Faker::Lorem.sentence(word_count: 3).truncate(60),
created_at: rand((Time.current - 1.week)..Time.current),
created_at: rand((1.week.ago)..Time.current),
description: description,
tag_list: tags.sample(3).join(","),
geozone: Geozone.all.sample,
@@ -26,7 +26,7 @@ section "Creating Debates" do
debate = Debate.create!(author: author,
title: Faker::Lorem.sentence(word_count: 3).truncate(60),
created_at: rand((Time.current - 1.week)..Time.current),
created_at: rand((1.week.ago)..Time.current),
description: description,
tag_list: tags.sample(3).join(","),
geozone: Geozone.all.sample,

View File

@@ -34,7 +34,7 @@ section "Creating Proposals" do
summary: summary,
responsible_name: Faker::Name.name,
description: description,
created_at: rand((Time.current - 1.week)..Time.current),
created_at: rand((1.week.ago)..Time.current),
tag_list: tags.sample(3).join(","),
geozone: Geozone.all.sample,
terms_of_service: "1",
@@ -89,7 +89,7 @@ section "Creating Successful Proposals" do
summary: Faker::Lorem.sentence(word_count: 3),
responsible_name: Faker::Name.name,
description: description,
created_at: rand((Time.current - 1.week)..Time.current),
created_at: rand((1.week.ago)..Time.current),
tag_list: tags.sample(3).join(","),
geozone: Geozone.all.sample,
terms_of_service: "1",
@@ -115,7 +115,7 @@ section "Creating Successful Proposals" do
summary: Faker::Lorem.sentence(word_count: 3),
responsible_name: Faker::Name.name,
description: description,
created_at: rand((Time.current - 1.week)..Time.current),
created_at: rand((1.week.ago)..Time.current),
tag_list: tags.sample(3).join(","),
geozone: Geozone.all.sample,
terms_of_service: "1",

View File

@@ -9,7 +9,7 @@ section "Creating Users" do
confirmed_at: Time.current,
terms_of_service: "1",
gender: %w[male female].sample,
date_of_birth: rand((Time.current - 80.years)..(Time.current - 16.years)),
date_of_birth: rand((80.years.ago)..(16.years.ago)),
public_activity: (rand(1..100) > 30)
)
end

View File

@@ -77,7 +77,7 @@ describe Dashboard::Action do
it "is active when published after day_offset" do
action = build(:dashboard_action, required_supports: 0, day_offset: 10)
proposal = build(:proposal, published_at: Time.current - 10.days)
proposal = build(:proposal, published_at: 10.days.ago)
expect(action).to be_active_for(proposal)
end
@@ -91,7 +91,7 @@ describe Dashboard::Action do
it "is not active when not enough time published" do
action = build(:dashboard_action, required_supports: 0, day_offset: 10)
proposal = build(:proposal, published_at: Time.current - 9.days)
proposal = build(:proposal, published_at: 9.days.ago)
expect(action).not_to be_active_for(proposal)
end

View File

@@ -352,7 +352,7 @@ describe Poll do
describe "#sort_for_list" do
it "returns polls sorted by name ASC" do
starts_at = Time.current + 1.day
starts_at = 1.day.from_now
poll1 = create(:poll, geozone_restricted: true, starts_at: starts_at, name: "Zzz...")
poll2 = create(:poll, geozone_restricted: true, starts_at: starts_at, name: "Mmmm...")
poll3 = create(:poll, geozone_restricted: true, starts_at: starts_at, name: "Aaaaah!")
@@ -361,7 +361,7 @@ describe Poll do
end
it "returns not geozone restricted polls first" do
starts_at = Time.current + 1.day
starts_at = 1.day.from_now
poll1 = create(:poll, geozone_restricted: false, starts_at: starts_at, name: "Zzz...")
poll2 = create(:poll, geozone_restricted: true, starts_at: starts_at, name: "Aaaaaah!")
@@ -382,7 +382,7 @@ describe Poll do
end
it "returns polls earlier to start first" do
starts_at = Time.current + 1.day
starts_at = 1.day.from_now
poll1 = create(:poll, geozone_restricted: false, starts_at: starts_at - 1.hour, name: "Zzz...")
poll2 = create(:poll, geozone_restricted: false, starts_at: starts_at, name: "Aaaaah!")
@@ -402,7 +402,7 @@ describe Poll do
end
it "orders by name considering fallback locales" do
starts_at = Time.current + 1.day
starts_at = 1.day.from_now
poll1 = create(:poll, starts_at: starts_at, name: "Charlie")
poll2 = create(:poll, starts_at: starts_at, name: "Delta")
poll3 = I18n.with_locale(:es) do

View File

@@ -1,7 +1,7 @@
require "rails_helper"
describe Dashboard::GroupSupports do
let(:created_at) { Time.current - 9.days }
let(:created_at) { 9.days.ago }
let(:proposal) { create(:proposal, created_at: created_at, published_at: created_at) }
before do

View File

@@ -211,11 +211,11 @@ describe "Machine learning" do
FileUtils.mkdir_p Rails.root.join("public", "machine_learning", "data")
allow_any_instance_of(MachineLearning).to receive(:run) do
MachineLearningJob.first.update!(finished_at: Time.current + 2.minutes)
MachineLearningJob.first.update!(finished_at: 2.minutes.from_now)
create(:machine_learning_info,
script: "proposals_summary_comments_textrank.py",
kind: "comments_summary",
updated_at: Time.current + 2.minutes)
updated_at: 2.minutes.from_now)
comments_file = MachineLearning::DATA_FOLDER.join(MachineLearning.comments_filename)
File.open(comments_file, "w") { |file| file.write([].to_json) }
proposals_comments_summary_file = MachineLearning::DATA_FOLDER.join(MachineLearning.proposals_comments_summary_filename)

View File

@@ -411,8 +411,8 @@ describe "Debates" do
scenario "Debates are ordered by newest" do
best_debate = create(:debate, title: "Best", created_at: Time.current)
medium_debate = create(:debate, title: "Medium", created_at: Time.current - 1.hour)
worst_debate = create(:debate, title: "Worst", created_at: Time.current - 1.day)
medium_debate = create(:debate, title: "Medium", created_at: 1.hour.ago)
worst_debate = create(:debate, title: "Worst", created_at: 1.day.ago)
visit debates_path
click_link "newest"

View File

@@ -200,14 +200,14 @@ describe "Moderate budget investments" do
flagged_investment = create(:budget_investment,
heading: heading,
title: "Flagged investment",
created_at: Time.current - 1.day,
created_at: 1.day.ago,
flags_count: 5
)
flagged_new_investment = create(:budget_investment,
heading: heading,
title: "Flagged new investment",
created_at: Time.current - 12.hours,
created_at: 12.hours.ago,
flags_count: 3
)

View File

@@ -211,8 +211,8 @@ describe "Moderate comments" do
end
scenario "sorting comments" do
flagged_comment = create(:comment, body: "Flagged comment", created_at: Time.current - 1.day, flags_count: 5)
flagged_new_comment = create(:comment, body: "Flagged new comment", created_at: Time.current - 12.hours, flags_count: 3)
flagged_comment = create(:comment, body: "Flagged comment", created_at: 1.day.ago, flags_count: 5)
flagged_new_comment = create(:comment, body: "Flagged new comment", created_at: 12.hours.ago, flags_count: 3)
newer_comment = create(:comment, body: "Newer comment", created_at: Time.current)
visit moderation_comments_path(order: "newest")

View File

@@ -180,8 +180,8 @@ describe "Moderate debates" do
end
scenario "sorting debates" do
flagged_debate = create(:debate, title: "Flagged debate", created_at: Time.current - 1.day, flags_count: 5)
flagged_new_debate = create(:debate, title: "Flagged new debate", created_at: Time.current - 12.hours, flags_count: 3)
flagged_debate = create(:debate, title: "Flagged debate", created_at: 1.day.ago, flags_count: 5)
flagged_new_debate = create(:debate, title: "Flagged new debate", created_at: 12.hours.ago, flags_count: 3)
newer_debate = create(:debate, title: "Newer debate", created_at: Time.current)
visit moderation_debates_path(order: "created_at")

View File

@@ -188,10 +188,10 @@ describe "Moderate proposal notifications" do
end
scenario "sorting proposal notifications" do
moderated_notification = create(:proposal_notification, :moderated, title: "Moderated notification", created_at: Time.current - 1.day)
moderated_new_notification = create(:proposal_notification, :moderated, title: "Moderated new notification", created_at: Time.current - 12.hours)
moderated_notification = create(:proposal_notification, :moderated, title: "Moderated notification", created_at: 1.day.ago)
moderated_new_notification = create(:proposal_notification, :moderated, title: "Moderated new notification", created_at: 12.hours.ago)
newer_notification = create(:proposal_notification, title: "Newer notification", created_at: Time.current)
old_moderated_notification = create(:proposal_notification, :moderated, title: "Older notification", created_at: Time.current - 2.days)
old_moderated_notification = create(:proposal_notification, :moderated, title: "Older notification", created_at: 2.days.ago)
visit moderation_proposal_notifications_path(filter: "all", order: "created_at")

View File

@@ -179,8 +179,8 @@ describe "Moderate proposals" do
end
scenario "sorting proposals" do
flagged_proposal = create(:proposal, title: "Flagged proposal", created_at: Time.current - 1.day, flags_count: 5)
flagged_new_proposal = create(:proposal, title: "Flagged new proposal", created_at: Time.current - 12.hours, flags_count: 3)
flagged_proposal = create(:proposal, title: "Flagged proposal", created_at: 1.day.ago, flags_count: 5)
flagged_new_proposal = create(:proposal, title: "Flagged new proposal", created_at: 12.hours.ago, flags_count: 3)
newer_proposal = create(:proposal, title: "Newer proposal", created_at: Time.current)
visit moderation_proposals_path(order: "created_at")

View File

@@ -794,8 +794,8 @@ describe "Proposals" do
scenario "Proposals are ordered by newest" do
best_proposal = create(:proposal, title: "Best proposal", created_at: Time.current)
medium_proposal = create(:proposal, title: "Medium proposal", created_at: Time.current - 1.hour)
worst_proposal = create(:proposal, title: "Worst proposal", created_at: Time.current - 1.day)
medium_proposal = create(:proposal, title: "Medium proposal", created_at: 1.hour.ago)
worst_proposal = create(:proposal, title: "Worst proposal", created_at: 1.day.ago)
visit proposals_path
click_link "newest"

View File

@@ -660,7 +660,7 @@ describe "Users" do
scenario "Sign in, admin with password expired" do
user = create(:administrator).user
user.update!(password_changed_at: Time.current - 1.year)
user.update!(password_changed_at: 1.year.ago)
visit new_user_session_path
fill_in "Email or username", with: user.email
@@ -679,7 +679,7 @@ describe "Users" do
end
scenario "Sign in, admin without password expired" do
user = create(:user, password_changed_at: Time.current - 360.days)
user = create(:user, password_changed_at: 360.days.ago)
admin = create(:administrator, user: user)
login_as(admin.user)
@@ -689,7 +689,7 @@ describe "Users" do
end
scenario "Sign in, user with password expired" do
user = create(:user, password_changed_at: Time.current - 1.year)
user = create(:user, password_changed_at: 1.year.ago)
login_as(user)
visit root_path
@@ -699,7 +699,7 @@ describe "Users" do
scenario "Admin with password expired trying to use same password" do
user = create(:administrator).user
user.update!(password_changed_at: Time.current - 1.year, password: "123456789")
user.update!(password_changed_at: 1.year.ago, password: "123456789")
visit new_user_session_path
fill_in "Email or username", with: user.email