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