Always use Time.current (aliases internally to Time.zone.now)
Some specs where breaking close to midnight because 30.years.ago uses zone.now and Time.now.utc.to_date doesn't. Also this will make all codebase consistent in the way time is deal with
This commit is contained in:
@@ -50,7 +50,7 @@ class Poll
|
|||||||
if dob.blank?
|
if dob.blank?
|
||||||
nil
|
nil
|
||||||
else
|
else
|
||||||
now = Time.now.utc.to_date
|
now = Time.current.to_date
|
||||||
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
|
||||||
|
|||||||
@@ -407,7 +407,7 @@ tags = Faker::Lorem.words(10)
|
|||||||
title: Faker::Lorem.sentence(3).truncate(60),
|
title: Faker::Lorem.sentence(3).truncate(60),
|
||||||
external_url: Faker::Internet.url,
|
external_url: Faker::Internet.url,
|
||||||
description: "<p>#{Faker::Lorem.paragraphs.join('</p><p>')}</p>",
|
description: "<p>#{Faker::Lorem.paragraphs.join('</p><p>')}</p>",
|
||||||
created_at: rand((Time.now - 1.week) .. Time.now),
|
created_at: rand((Time.current - 1.week) .. Time.current),
|
||||||
feasibility: %w{undecided unfeasible feasible feasible feasible feasible}.sample,
|
feasibility: %w{undecided unfeasible feasible feasible feasible feasible}.sample,
|
||||||
unfeasibility_explanation: Faker::Lorem.paragraph,
|
unfeasibility_explanation: Faker::Lorem.paragraph,
|
||||||
valuation_finished: [false, true].sample,
|
valuation_finished: [false, true].sample,
|
||||||
@@ -436,7 +436,7 @@ budget = Budget.where(phase: "finished").last
|
|||||||
title: Faker::Lorem.sentence(3).truncate(60),
|
title: Faker::Lorem.sentence(3).truncate(60),
|
||||||
external_url: Faker::Internet.url,
|
external_url: Faker::Internet.url,
|
||||||
description: "<p>#{Faker::Lorem.paragraphs.join('</p><p>')}</p>",
|
description: "<p>#{Faker::Lorem.paragraphs.join('</p><p>')}</p>",
|
||||||
created_at: rand((Time.now - 1.week) .. Time.now),
|
created_at: rand((Time.current - 1.week) .. Time.current),
|
||||||
feasibility: "feasible",
|
feasibility: "feasible",
|
||||||
valuation_finished: true,
|
valuation_finished: true,
|
||||||
selected: true,
|
selected: true,
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
module Age
|
module Age
|
||||||
def self.in_years(dob, now = Time.now.utc.to_date)
|
def self.in_years(dob, now = Time.current.to_date)
|
||||||
return nil unless dob.present?
|
return nil unless dob.present?
|
||||||
# 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)
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ require 'rails_helper'
|
|||||||
feature 'Votes' do
|
feature 'Votes' do
|
||||||
|
|
||||||
background do
|
background do
|
||||||
@manuela = create(:user, verified_at: Time.now)
|
@manuela = create(:user, verified_at: Time.current)
|
||||||
end
|
end
|
||||||
|
|
||||||
feature 'Investments' do
|
feature 'Investments' do
|
||||||
|
|||||||
@@ -65,9 +65,9 @@ describe DirectMessage do
|
|||||||
|
|
||||||
describe "today" do
|
describe "today" do
|
||||||
it "should return direct messages created today" do
|
it "should return direct messages created today" do
|
||||||
direct_message1 = create(:direct_message, created_at: Time.zone.now.beginning_of_day + 3.hours)
|
direct_message1 = create(:direct_message, created_at: Time.current.beginning_of_day + 3.hours)
|
||||||
direct_message2 = create(:direct_message, created_at: Time.zone.now)
|
direct_message2 = create(:direct_message, created_at: Time.current)
|
||||||
direct_message3 = create(:direct_message, created_at: Time.zone.now.end_of_day)
|
direct_message3 = create(:direct_message, created_at: Time.current.end_of_day)
|
||||||
|
|
||||||
expect(DirectMessage.today.count).to eq 3
|
expect(DirectMessage.today.count).to eq 3
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user