Merge pull request #1634 from consul/fix/date_time_current_usage

Fix Flaky test related with Time/Date in Search concern
This commit is contained in:
Raimond Garcia
2017-06-12 09:53:09 +02:00
committed by GitHub
9 changed files with 11 additions and 11 deletions

View File

@@ -41,11 +41,11 @@ module Search
end end
def search_finish_date def search_finish_date
(params[:advanced_search][:date_max].to_date rescue Date.today) || Date.today (params[:advanced_search][:date_max].to_date rescue Date.current) || Date.current
end end
def search_date_range def search_date_range
[100.years.ago, search_start_date].max.beginning_of_day..[search_finish_date, Date.today].min.end_of_day [100.years.ago, search_start_date].max.beginning_of_day..[search_finish_date, Date.current].min.end_of_day
end end
def set_search_order def set_search_order

View File

@@ -26,7 +26,7 @@ class Officing::ResidenceController < Officing::BaseController
@officer_assignments = current_user.poll_officer. @officer_assignments = current_user.poll_officer.
officer_assignments. officer_assignments.
voting_days. voting_days.
where(date: Time.current.to_date) where(date: Date.current)
end end
def validate_officer_assignment def validate_officer_assignment

View File

@@ -8,7 +8,7 @@ class DirectMessage < ActiveRecord::Base
validates :receiver, presence: true validates :receiver, presence: true
validate :max_per_day validate :max_per_day
scope :today, lambda { where('DATE(created_at) = ?', Date.today) } scope :today, lambda { where('DATE(created_at) = ?', Date.current) }
def max_per_day def max_per_day
return if errors.any? return if errors.any?

View File

@@ -50,7 +50,7 @@ class Poll
if dob.blank? if dob.blank?
nil nil
else else
now = Time.current.to_date now = Date.current
now.year - dob.year - (now.month > dob.month || (now.month == dob.month && now.day >= dob.day) ? 0 : 1) now.year - dob.year - (now.month > dob.month || (now.month == dob.month && now.day >= dob.day) ? 0 : 1)
end end
end end

View File

@@ -8,7 +8,7 @@
<%= image_tag "header_print_proposals.jpg", class: "for-print-only" %> <%= image_tag "header_print_proposals.jpg", class: "for-print-only" %>
<div class="filters"> <div class="filters">
<span class="for-print-only date-for-print"><%= l Date.today, format: :long %></span> <span class="for-print-only date-for-print"><%= l Date.current, format: :long %></span>
<h2 class="inline-block"> <h2 class="inline-block">
<span class="not-print"><%= t("proposals.index.select_order_long") %></span> <span class="not-print"><%= t("proposals.index.select_order_long") %></span>

View File

@@ -1,5 +1,5 @@
module Age module Age
def self.in_years(dob, now = Time.current.to_date) def self.in_years(dob, now = Date.current)
return nil if dob.blank? return nil if dob.blank?
# reference: http://stackoverflow.com/questions/819263/get-persons-age-in-ruby#comment21200772_819263 # reference: http://stackoverflow.com/questions/819263/get-persons-age-in-ruby#comment21200772_819263
now.year - dob.year - (now.month > dob.month || (now.month == dob.month && now.day >= dob.day) ? 0 : 1) now.year - dob.year - (now.month > dob.month || (now.month == dob.month && now.day >= dob.day) ? 0 : 1)

View File

@@ -1,7 +1,7 @@
class MigrateSpendingProposalsToInvestments class MigrateSpendingProposalsToInvestments
def import(sp) def import(sp)
budget = Budget.last || Budget.create!(name: Date.today.year.to_s, currency_symbol: "") budget = Budget.last || Budget.create!(name: Date.current.year.to_s, currency_symbol: "")
group = nil group = nil
heading = nil heading = nil

View File

@@ -429,7 +429,7 @@ FactoryGirl.define do
factory :poll_officer_assignment, class: 'Poll::OfficerAssignment' do factory :poll_officer_assignment, class: 'Poll::OfficerAssignment' do
association :officer, factory: :poll_officer association :officer, factory: :poll_officer
association :booth_assignment, factory: :poll_booth_assignment association :booth_assignment, factory: :poll_booth_assignment
date Time.current.to_date date Date.current
trait :final do trait :final do
final true final true

View File

@@ -144,7 +144,7 @@ feature 'Admin booths assignments' do
poll = create(:poll) poll = create(:poll)
booth = create(:poll_booth) booth = create(:poll_booth)
booth_assignment = create(:poll_booth_assignment, poll: poll, booth: booth) booth_assignment = create(:poll_booth_assignment, poll: poll, booth: booth)
today = Time.current.to_date today = Date.current
officer_assignment = create(:poll_officer_assignment, booth_assignment: booth_assignment, date: today) officer_assignment = create(:poll_officer_assignment, booth_assignment: booth_assignment, date: today)
recount = create(:poll_recount, recount = create(:poll_recount,