1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-17 06:52:27 +01:00

uses DateTime#current instead of Time.now in tests

This commit is contained in:
Nicolas Florentin 2019-12-02 15:29:05 +01:00
parent b17bcfde86
commit db41e846dd
13 changed files with 30 additions and 36 deletions

View File

@ -52,12 +52,6 @@ class Slot < ActiveRecord::Base
attached_object: self
end
def can_be_modified?
return false if (start_at - DateTime.current) / 1.day < 1
true
end
def dates_were_modified?
start_at_changed? or end_at_changed?
end

View File

@ -30,7 +30,7 @@ class StatisticProfile < ActiveRecord::Base
def age
if birthday.present?
now = Time.now.utc.to_date
now = DateTime.current.utc.to_date
(now - birthday).to_f / AVG_DAYS_PER_YEAR
else
''

View File

@ -129,7 +129,7 @@ namespace :fablab do
desc '[release 3.1.2] fix users with invalid group_id'
task users_group_ids: :environment do
User.where.not(group_id: Group.all.map(&:id)).each do |u|
u.update_columns(group_id: Group.first.id, updated_at: DateTime.now)
u.update_columns(group_id: Group.first.id, updated_at: DateTime.current)
meta_data = { ex_group_name: 'invalid group' }

View File

@ -1,8 +1,8 @@
availability_1:
id: 1
start_at: <%= DateTime.now.utc.change({hour: 6}).strftime('%Y-%m-%d %H:%M:%S.%9N Z') %>
end_at: <%= DateTime.now.utc.change({hour: 10}).strftime('%Y-%m-%d %H:%M:%S.%9N Z') %>
start_at: <%= DateTime.current.utc.change({hour: 6}).strftime('%Y-%m-%d %H:%M:%S.%9N Z') %>
end_at: <%= DateTime.current.utc.change({hour: 10}).strftime('%Y-%m-%d %H:%M:%S.%9N Z') %>
available_type: training
created_at: 2016-04-04 15:24:01.517486000 Z
updated_at: 2016-04-04 15:24:01.517486000 Z
@ -11,8 +11,8 @@ availability_1:
availability_2:
id: 2
start_at: <%= (DateTime.now + 1.day).utc.change({hour: 6}).strftime('%Y-%m-%d %H:%M:%S.%9N Z') %>
end_at: <%= (DateTime.now + 1.day).utc.change({hour: 10}).strftime('%Y-%m-%d %H:%M:%S.%9N Z') %>
start_at: <%= (DateTime.current + 1.day).utc.change({hour: 6}).strftime('%Y-%m-%d %H:%M:%S.%9N Z') %>
end_at: <%= (DateTime.current + 1.day).utc.change({hour: 10}).strftime('%Y-%m-%d %H:%M:%S.%9N Z') %>
available_type: training
created_at: 2016-04-04 15:24:09.169364000 Z
updated_at: 2016-04-04 15:24:09.169364000 Z
@ -21,8 +21,8 @@ availability_2:
availability_3:
id: 3
start_at: <%= DateTime.now.utc.change({hour: 12}).strftime('%Y-%m-%d %H:%M:%S.%9N Z') %>
end_at: <%= DateTime.now.utc.change({hour: 18}).strftime('%Y-%m-%d %H:%M:%S.%9N Z') %>
start_at: <%= DateTime.current.utc.change({hour: 12}).strftime('%Y-%m-%d %H:%M:%S.%9N Z') %>
end_at: <%= DateTime.current.utc.change({hour: 18}).strftime('%Y-%m-%d %H:%M:%S.%9N Z') %>
available_type: machines
created_at: 2016-04-04 15:24:27.587583000 Z
updated_at: 2016-04-04 15:24:27.587583000 Z
@ -31,8 +31,8 @@ availability_3:
availability_4:
id: 4
start_at: <%= (DateTime.now + 1.day).utc.change({hour: 12}).strftime('%Y-%m-%d %H:%M:%S.%9N Z') %>
end_at: <%= (DateTime.now + 1.day).utc.change({hour: 18}).strftime('%Y-%m-%d %H:%M:%S.%9N Z') %>
start_at: <%= (DateTime.current + 1.day).utc.change({hour: 12}).strftime('%Y-%m-%d %H:%M:%S.%9N Z') %>
end_at: <%= (DateTime.current + 1.day).utc.change({hour: 18}).strftime('%Y-%m-%d %H:%M:%S.%9N Z') %>
available_type: machines
created_at: 2016-04-04 15:24:44.044908000 Z
updated_at: 2016-04-04 15:24:44.044908000 Z
@ -41,8 +41,8 @@ availability_4:
availability_5:
id: 5
start_at: <%= (DateTime.now + 2.day).utc.change({hour: 12}).strftime('%Y-%m-%d %H:%M:%S.%9N Z') %>
end_at: <%= (DateTime.now + 2.day).utc.change({hour: 18}).strftime('%Y-%m-%d %H:%M:%S.%9N Z') %>
start_at: <%= (DateTime.current + 2.day).utc.change({hour: 12}).strftime('%Y-%m-%d %H:%M:%S.%9N Z') %>
end_at: <%= (DateTime.current + 2.day).utc.change({hour: 18}).strftime('%Y-%m-%d %H:%M:%S.%9N Z') %>
available_type: machines
created_at: 2016-04-04 15:25:48.584444000 Z
updated_at: 2016-04-04 15:25:48.584444000 Z
@ -51,8 +51,8 @@ availability_5:
availability_6:
id: 6
start_at: <%= (DateTime.now + 3.day).utc.change({hour: 12}).strftime('%Y-%m-%d %H:%M:%S.%9N Z') %>
end_at: <%= (DateTime.now + 3.day).utc.change({hour: 18}).strftime('%Y-%m-%d %H:%M:%S.%9N Z') %>
start_at: <%= (DateTime.current + 3.day).utc.change({hour: 12}).strftime('%Y-%m-%d %H:%M:%S.%9N Z') %>
end_at: <%= (DateTime.current + 3.day).utc.change({hour: 18}).strftime('%Y-%m-%d %H:%M:%S.%9N Z') %>
available_type: machines
created_at: 2016-04-04 15:26:17.953216000 Z
updated_at: 2016-04-04 15:26:17.953216000 Z
@ -61,8 +61,8 @@ availability_6:
availability_7:
id: 7
start_at: <%= (DateTime.now + 3.day).utc.change({hour: 12}).strftime('%Y-%m-%d %H:%M:%S.%9N Z') %>
end_at: <%= (DateTime.now + 3.day).utc.change({hour: 18}).strftime('%Y-%m-%d %H:%M:%S.%9N Z') %>
start_at: <%= (DateTime.current + 3.day).utc.change({hour: 12}).strftime('%Y-%m-%d %H:%M:%S.%9N Z') %>
end_at: <%= (DateTime.current + 3.day).utc.change({hour: 18}).strftime('%Y-%m-%d %H:%M:%S.%9N Z') %>
available_type: machines
created_at: 2016-04-04 15:26:39.278627000 Z
updated_at: 2016-04-04 15:26:39.278627000 Z
@ -71,8 +71,8 @@ availability_7:
availability_8:
id: 8
start_at: <%= (DateTime.now + 2.day).utc.change({hour: 6}).strftime('%Y-%m-%d %H:%M:%S.%9N Z') %>
end_at: <%= (DateTime.now + 2.day).utc.change({hour: 10}).strftime('%Y-%m-%d %H:%M:%S.%9N Z') %>
start_at: <%= (DateTime.current + 2.day).utc.change({hour: 6}).strftime('%Y-%m-%d %H:%M:%S.%9N Z') %>
end_at: <%= (DateTime.current + 2.day).utc.change({hour: 10}).strftime('%Y-%m-%d %H:%M:%S.%9N Z') %>
available_type: training
created_at: 2016-04-04 15:26:49.572724000 Z
updated_at: 2016-04-04 15:26:49.572724000 Z

View File

@ -37,7 +37,7 @@ module Availabilities
# Check that we din't get availabilities from the past
availabilities.each do |a|
assert_not a[:start] < DateTime.now, 'retrieved a slot in the past'
assert_not a[:start] < DateTime.current, 'retrieved a slot in the past'
end
end
@ -46,7 +46,7 @@ module Availabilities
Rails.application.secrets.fablab_without_spaces = true
# this simulates a fullCalendar (v2) call
start_date = DateTime.now.utc.strftime('%Y-%m-%d')
start_date = DateTime.current.utc.strftime('%Y-%m-%d')
end_date = 7.days.from_now.utc.strftime('%Y-%m-%d')
tz = Time.zone.tzinfo.name
get "/api/availabilities?start=#{start_date}&end=#{end_date}&timezone=#{tz}&_=1487169767960"
@ -68,7 +68,7 @@ module Availabilities
test 'get calendar availabilities with spaces' do
# this simulates a fullCalendar (v2) call
start_date = DateTime.now.utc.strftime('%Y-%m-%d')
start_date = DateTime.current.utc.strftime('%Y-%m-%d')
end_date = 7.days.from_now.utc.strftime('%Y-%m-%d')
tz = Time.zone.tzinfo.name
get "/api/availabilities?start=#{start_date}&end=#{end_date}&timezone=#{tz}&_=1487169767960"

View File

@ -22,7 +22,7 @@ class Availabilities::AsUserTest < ActionDispatch::IntegrationTest
# Check that we din't get availabilities from the past
availabilities.each do |a|
assert_not a[:start] < DateTime.now, 'retrieved a slot in the past'
assert_not a[:start] < DateTime.current, 'retrieved a slot in the past'
end
# Check that we don't get availabilities in more than a month

View File

@ -57,7 +57,7 @@ module Credits
credit = json_response(response.body)
assert_equal 13, credit[:id]
c = Credit.find(credit[:id])
assert Time.now - c.updated_at < 1.minute
assert c.updated_at > 1.minute.ago
assert_equal 5, c.hours
end

View File

@ -19,7 +19,7 @@ class Exports::AccountingExportTest < ActionDispatch::IntegrationTest
encoding: 'ISO-8859-1',
date_format: '%d/%m/%Y',
start_date: '2012-03-12T00:00:00.000Z',
end_date: DateTime.now.utc.iso8601,
end_date: DateTime.current.utc.iso8601,
label_max_length: 50,
decimal_separator: ',',
export_invoices_at_zero: false

View File

@ -33,7 +33,7 @@ class InvoicesTest < ActionDispatch::IntegrationTest
end
test 'admin generates a refund' do
date = DateTime.now.iso8601
date = DateTime.current.iso8601
post '/api/invoices', { avoir: {
avoir_date: date,

View File

@ -37,14 +37,14 @@ class Subscriptions::RenewAsUserTest < ActionDispatch::IntegrationTest
assert_not_nil @user.subscription, "user's subscription was not found"
# Check the expiration date
assert @user.subscription.expired_at > DateTime.now,
assert @user.subscription.expired_at > DateTime.current,
"user's subscription expiration was not updated ... VCR cassettes may be outdated, please check the gitlab wiki"
assert_equal @user.subscription.expired_at.iso8601,
(@user.subscription.created_at + plan.duration).iso8601,
'subscription expiration date does not match'
assert_in_delta 5,
(DateTime.now.to_i - @user.subscription.updated_at.to_i),
(DateTime.current.to_i - @user.subscription.updated_at.to_i),
10,
"user's subscription was not updated recently"

View File

@ -83,7 +83,7 @@ class WalletsTest < ActionDispatch::IntegrationTest
login_as(admin, scope: :user)
w = @vlonchamp.wallet
amount = 10
avoir_date = Time.now.end_of_day
avoir_date = DateTime.current.end_of_day
expected_amount = w.amount + amount
put "/api/wallet/#{w.id}/credit",
amount: amount,

View File

@ -3,7 +3,7 @@ require 'test_helper'
class CouponTest < ActiveSupport::TestCase
test 'valid coupon with percentage' do
c = Coupon.new({name: 'Hot deals', code: 'HOT15', percent_off: 15, validity_per_user: 'once', valid_until: (Time.now + 2.weeks), max_usages: 100, active: true})
c = Coupon.new({name: 'Hot deals', code: 'HOT15', percent_off: 15, validity_per_user: 'once', valid_until: (DateTime.current + 2.weeks), max_usages: 100, active: true})
assert c.valid?
assert_equal 'active', c.status, 'Invalid coupon status'
assert_equal 'percent_off', c.type, 'Invalid coupon type'

View File

@ -39,7 +39,7 @@ class ActiveSupport::TestCase
def stripe_payment_method(error: nil)
number = '4242424242424242'
exp_month = 4
exp_year = DateTime.now.next_year.year
exp_year = DateTime.current.next_year.year
cvc = '314'
case error