Use Date.current and Time.current
Using Date.today and Time.now might lead to inconsistencies if the time zone the application uses is not the same as the system time zone.
This commit is contained in:
@@ -15,7 +15,7 @@ class Admin::Dashboard::AdministratorTasksController < Admin::Dashboard::BaseCon
|
||||
def update
|
||||
authorize! :update, administrator_task
|
||||
|
||||
administrator_task.update(user: current_user, executed_at: Time.now)
|
||||
administrator_task.update(user: current_user, executed_at: Time.current)
|
||||
redirect_to admin_dashboard_administrator_tasks_path,
|
||||
{ flash: { notice: t("admin.dashboard.administrator_tasks.update.success") } }
|
||||
end
|
||||
|
||||
@@ -10,6 +10,6 @@ module Dashboard::ExpectsDateRange
|
||||
|
||||
def end_date
|
||||
return Date.parse(params[:end_date]) unless params[:end_date].blank?
|
||||
Date.today
|
||||
Date.current
|
||||
end
|
||||
end
|
||||
|
||||
@@ -12,7 +12,7 @@ class Dashboard::ActionsController < Dashboard::BaseController
|
||||
source_params = {
|
||||
proposal: proposal,
|
||||
action: dashboard_action,
|
||||
executed_at: Time.now
|
||||
executed_at: Time.current
|
||||
}
|
||||
|
||||
@dashboard_executed_action = Dashboard::ExecutedAction.new(source_params)
|
||||
@@ -31,7 +31,7 @@ class Dashboard::ActionsController < Dashboard::BaseController
|
||||
authorize! :dashboard, proposal
|
||||
|
||||
Dashboard::ExecutedAction.create(proposal: proposal, action: dashboard_action,
|
||||
executed_at: Time.now)
|
||||
executed_at: Time.current)
|
||||
redirect_to request.referer
|
||||
end
|
||||
|
||||
|
||||
@@ -112,7 +112,7 @@ class Legislation::ProcessesController < Legislation::BaseController
|
||||
@phase = :resume
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.xlsx {render xlsx: "resume_to_xlsx", filename: ("resume-" + Date.today.to_s + ".xlsx")}
|
||||
format.xlsx {render xlsx: "resume_to_xlsx", filename: ("resume-" + Date.current.to_s + ".xlsx")}
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ class Management::ProposalsController < Management::BaseController
|
||||
|
||||
def create
|
||||
@resource = resource_model.new(strong_params.merge(author: current_user,
|
||||
published_at: Time.now))
|
||||
published_at: Time.current))
|
||||
|
||||
if @resource.save
|
||||
track_event
|
||||
|
||||
@@ -44,10 +44,10 @@ class Dashboard::Action < ApplicationRecord
|
||||
}
|
||||
|
||||
def self.active_for(proposal)
|
||||
published_at = proposal.published_at&.to_date || Date.today
|
||||
published_at = proposal.published_at&.to_date || Date.current
|
||||
|
||||
active.where("required_supports <= ?", proposal.cached_votes_up)
|
||||
.where("day_offset <= ?", (Date.today - published_at).to_i)
|
||||
.where("day_offset <= ?", (Date.current - published_at).to_i)
|
||||
.by_proposal(proposal)
|
||||
end
|
||||
|
||||
@@ -59,9 +59,9 @@ class Dashboard::Action < ApplicationRecord
|
||||
end
|
||||
|
||||
def active_for?(proposal)
|
||||
published_at = proposal.published_at&.to_date || Date.today
|
||||
published_at = proposal.published_at&.to_date || Date.current
|
||||
|
||||
required_supports <= proposal.cached_votes_up && day_offset <= (Date.today - published_at).to_i
|
||||
required_supports <= proposal.cached_votes_up && day_offset <= (Date.current - published_at).to_i
|
||||
end
|
||||
|
||||
def requested_for?(proposal)
|
||||
@@ -95,7 +95,7 @@ class Dashboard::Action < ApplicationRecord
|
||||
private
|
||||
def self.get_actions_for_today(proposal)
|
||||
proposal_votes = proposal.cached_votes_up
|
||||
day_offset = calculate_day_offset(proposal, Date.today)
|
||||
day_offset = calculate_day_offset(proposal, Date.current)
|
||||
|
||||
calculate_actions(proposal_votes, day_offset, proposal)
|
||||
end
|
||||
|
||||
@@ -96,7 +96,7 @@ class Proposal < ApplicationRecord
|
||||
end
|
||||
|
||||
def publish
|
||||
update(published_at: Time.now)
|
||||
update(published_at: Time.current)
|
||||
send_new_actions_notification_on_published
|
||||
end
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
Setting["months_to_archive_proposals"].to_i.months %>
|
||||
<p>
|
||||
<%= t("mailers.new_actions_notification_rake_published.text_3",
|
||||
days_count: (limit_to_archive_proposal - Date.today).to_i,
|
||||
days_count: (limit_to_archive_proposal - Date.current).to_i,
|
||||
max_votes_count: Setting["votes_for_proposal_success"]) %>
|
||||
</p>
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@
|
||||
</li>
|
||||
<% end %>
|
||||
|
||||
<% if process.result_publication.enabled? && process.end_date <= Date.today %>
|
||||
<% if process.result_publication.enabled? && process.end_date <= Date.current %>
|
||||
<li <%= "class=is-active" if phase == :resume %>>
|
||||
<%= link_to resume_legislation_process_path(process) do %>
|
||||
<h4><%= t("legislation.summary.title") %></h4>
|
||||
|
||||
@@ -17,7 +17,7 @@ section "Creating Newsletters" do
|
||||
segment_recipient: UserSegments::SEGMENTS.sample,
|
||||
from: "no-reply@consul.dev",
|
||||
body: newsletter_body.sample,
|
||||
sent_at: [Time.now, nil].sample
|
||||
sent_at: [Time.current, nil].sample
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -39,7 +39,7 @@ section "Creating Proposals" do
|
||||
geozone: Geozone.all.sample,
|
||||
skip_map: "1",
|
||||
terms_of_service: "1",
|
||||
published_at: Time.now)
|
||||
published_at: Time.current)
|
||||
random_locales.map do |locale|
|
||||
Globalize.with_locale(locale) do
|
||||
proposal.title = "Title for locale #{locale}"
|
||||
@@ -97,7 +97,7 @@ section "Creating Successful Proposals" do
|
||||
skip_map: "1",
|
||||
terms_of_service: "1",
|
||||
cached_votes_up: Setting["votes_for_proposal_success"],
|
||||
published_at: Time.now)
|
||||
published_at: Time.current)
|
||||
random_locales.map do |locale|
|
||||
Globalize.with_locale(locale) do
|
||||
proposal.title = "Successful proposal title for locale #{locale}"
|
||||
@@ -123,7 +123,7 @@ section "Creating Successful Proposals" do
|
||||
geozone: Geozone.all.sample,
|
||||
skip_map: "1",
|
||||
terms_of_service: "1",
|
||||
published_at: Time.now)
|
||||
published_at: Time.current)
|
||||
random_locales.map do |locale|
|
||||
Globalize.with_locale(locale) do
|
||||
proposal.title = "Tagged proposal title for locale #{locale}"
|
||||
|
||||
@@ -418,12 +418,12 @@ namespace :proposal_actions do
|
||||
summary: Faker::Lorem.sentence(3),
|
||||
responsible_name: Faker::Name.name,
|
||||
description: description,
|
||||
created_at: Time.now - expected_supports.length.days,
|
||||
created_at: Time.current - expected_supports.length.days,
|
||||
tag_list: "Example",
|
||||
geozone: Geozone.all.sample,
|
||||
skip_map: "1",
|
||||
terms_of_service: "1",
|
||||
published_at: Time.now - expected_supports.length.days)
|
||||
published_at: Time.current - expected_supports.length.days)
|
||||
|
||||
expected_supports.each_with_index do |supports, day_offset|
|
||||
supports = (supports * goal_votes / votes_count).ceil
|
||||
|
||||
@@ -51,7 +51,7 @@ describe "Admin collaborative legislation" do
|
||||
|
||||
scenario "Processes are sorted by descending start date" do
|
||||
process_1 = create(:legislation_process, title: "Process 1", start_date: Date.yesterday)
|
||||
process_2 = create(:legislation_process, title: "Process 2", start_date: Date.today)
|
||||
process_2 = create(:legislation_process, title: "Process 2", start_date: Date.current)
|
||||
process_3 = create(:legislation_process, title: "Process 3", start_date: Date.tomorrow)
|
||||
|
||||
visit admin_legislation_processes_path(filter: "all")
|
||||
|
||||
@@ -195,7 +195,7 @@ describe "Proposal's dashboard" do
|
||||
end
|
||||
|
||||
scenario "Dashboard progress show available resources for published proposal" do
|
||||
proposal.update(published_at: Date.today)
|
||||
proposal.update(published_at: Date.current)
|
||||
available = create(:dashboard_action, :resource, :active)
|
||||
|
||||
requested = create(:dashboard_action, :resource, :admin_request, :active)
|
||||
@@ -481,7 +481,7 @@ describe "Proposal's dashboard" do
|
||||
scenario "Not display tag 'new' on resouce when there is not new resources since last login" do
|
||||
resource = create(:dashboard_action, :resource, :active, day_offset: 0,
|
||||
published_proposal: false)
|
||||
proposal.author.update(last_sign_in_at: Date.today)
|
||||
proposal.author.update(last_sign_in_at: Date.current)
|
||||
|
||||
visit progress_proposal_dashboard_path(proposal)
|
||||
|
||||
@@ -504,7 +504,7 @@ describe "Proposal's dashboard" do
|
||||
scenario "Not display tag 'new' on proposed_action when there is not new since last login" do
|
||||
proposed_action = create(:dashboard_action, :proposed_action, :active, day_offset: 0,
|
||||
published_proposal: false)
|
||||
proposal.author.update(last_sign_in_at: Date.today)
|
||||
proposal.author.update(last_sign_in_at: Date.current)
|
||||
|
||||
visit progress_proposal_dashboard_path(proposal)
|
||||
|
||||
@@ -525,7 +525,7 @@ describe "Proposal's dashboard" do
|
||||
|
||||
scenario "Not display tag 'new' on sidebar when there is not a new resouce since last login" do
|
||||
create(:dashboard_action, :resource, :active, day_offset: 0, published_proposal: false)
|
||||
proposal.author.update(last_sign_in_at: Date.today)
|
||||
proposal.author.update(last_sign_in_at: Date.current)
|
||||
|
||||
visit progress_proposal_dashboard_path(proposal)
|
||||
|
||||
|
||||
@@ -200,7 +200,7 @@ describe "Valuation budget investments" do
|
||||
|
||||
expect(page).to have_content("Create milestone")
|
||||
fill_in("Description", with: "Test Description")
|
||||
page.find("#milestone_publication_date").set(Date.today)
|
||||
page.find("#milestone_publication_date").set(Date.current)
|
||||
|
||||
click_button "Create milestone"
|
||||
|
||||
|
||||
@@ -136,7 +136,7 @@ describe Dashboard::Mailer do
|
||||
|
||||
months_to_archive_proposals = Setting["months_to_archive_proposals"].to_i.months
|
||||
limit_to_archive_proposal = proposal.created_at.to_date + months_to_archive_proposals
|
||||
days_count = (limit_to_archive_proposal - Date.today).to_i
|
||||
days_count = (limit_to_archive_proposal - Date.current).to_i
|
||||
|
||||
expect(email).to have_body_text("You are missing #{days_count} days before your proposal "\
|
||||
"gets the #{Setting["votes_for_proposal_success"]} "\
|
||||
|
||||
@@ -30,19 +30,19 @@ describe Budget::Phase do
|
||||
|
||||
describe "#dates_range_valid?" do
|
||||
it "is valid when start & end dates are different & consecutive" do
|
||||
first_phase.update_attributes(starts_at: Date.today, ends_at: Date.tomorrow)
|
||||
first_phase.update_attributes(starts_at: Date.current, ends_at: Date.tomorrow)
|
||||
|
||||
expect(first_phase).to be_valid
|
||||
end
|
||||
|
||||
it "is not valid when dates are equal" do
|
||||
first_phase.update_attributes(starts_at: Date.today, ends_at: Date.today)
|
||||
first_phase.update_attributes(starts_at: Date.current, ends_at: Date.current)
|
||||
|
||||
expect(first_phase).not_to be_valid
|
||||
end
|
||||
|
||||
it "is not valid when start date is later than end date" do
|
||||
first_phase.update_attributes(starts_at: Date.tomorrow, ends_at: Date.today)
|
||||
first_phase.update_attributes(starts_at: Date.tomorrow, ends_at: Date.current)
|
||||
|
||||
expect(first_phase).not_to be_valid
|
||||
end
|
||||
|
||||
@@ -9,7 +9,7 @@ describe Tag do
|
||||
|
||||
expect(tag.taggings_count).to eq(1)
|
||||
|
||||
debate.update(hidden_at: Time.now)
|
||||
debate.update(hidden_at: Time.current)
|
||||
|
||||
tag.reload
|
||||
expect(tag.taggings_count).to eq(0)
|
||||
@@ -22,7 +22,7 @@ describe Tag do
|
||||
|
||||
expect(tag.taggings_count).to eq(1)
|
||||
|
||||
proposal.update(hidden_at: Time.now)
|
||||
proposal.update(hidden_at: Time.current)
|
||||
|
||||
tag.reload
|
||||
expect(tag.taggings_count).to eq(0)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
require "rails_helper"
|
||||
|
||||
describe "Retrieves number of supports for the successful proposal" do
|
||||
let(:created_at) { Time.now.beginning_of_day - 9.days }
|
||||
let(:created_at) { Date.current.beginning_of_day - 9.days }
|
||||
let(:proposal) { create(:proposal, created_at: created_at, published_at: created_at) }
|
||||
|
||||
before do
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
require "rails_helper"
|
||||
|
||||
describe Dashboard::GroupSupports do
|
||||
let(:created_at) { Time.now - 9.days }
|
||||
let(:created_at) { Time.current - 9.days }
|
||||
let(:proposal) { create(:proposal, created_at: created_at, published_at: created_at) }
|
||||
|
||||
before do
|
||||
|
||||
Reference in New Issue
Block a user