Fix more tests related to time

This commit is contained in:
Ari Timonen 2020-03-25 03:13:38 +02:00
parent 62a49a0072
commit 0b033be5ca
8 changed files with 20 additions and 16 deletions

View file

@ -63,7 +63,7 @@ class ApplicationController < ActionController::Base
def update_user
if cuser
Time.zone = cuser.time_zone
cuser.update_attribute :lastvisit, DateTime.now if cuser.lastvisit and cuser.lastvisit < 2.minutes.ago
cuser.update_attribute :lastvisit, Time.now.utc if cuser&.lastvisit < 2.minutes.ago.utc
if cuser.banned? Ban::TYPE_SITE
session[:user] = nil

View file

@ -55,8 +55,6 @@ class UsersController < ApplicationController
def create
@user = User.new(User.params(params, cuser, "create"))
# FIXME: move to model
@user.lastvisit = Date.today
@user.lastip = request.env['REMOTE_ADDR']
raise AccessError unless @user.can_create? cuser
@ -135,7 +133,7 @@ class UsersController < ApplicationController
def save_session user
session[:user] = user.id
user.lastip = request.ip
user.lastvisit = DateTime.now
user.lastvisit = Time.now.utc
user.save
end
end

View file

@ -301,8 +301,8 @@ class Match < ActiveRecord::Base
end
def hltv_record(addr, pwd)
if (match_time - MATCH_LENGTH * 10) > DateTime.now.utc ||
(match_time + MATCH_LENGTH * 10) < DateTime.now.utc
if (match_time - MATCH_LENGTH * 10) > Time.now.utc ||
(match_time + MATCH_LENGTH * 10) < Time.now.utc
raise Error, I18n.t(:hltv_request_20)
end
if hltv && hltv.recording

View file

@ -46,7 +46,7 @@ class User < ActiveRecord::Base
#attr_protected :id, :created_at, :updated_at, :lastvisit, :lastip, :password, :version
attr_accessor :raw_password
#attribute :lastvisit, :string, default: DateTime.now
attribute :lastvisit, :datetime, default: Time.now.utc
belongs_to :team
has_one :profile, :dependent => :destroy
@ -192,13 +192,13 @@ class User < ActiveRecord::Base
def age
return 0 unless birthdate
a = Date.today.year - birthdate.year
a-= 1 if Date.today < birthdate + a.years
a = Time.zone.today.year - birthdate.year
a-= 1 if Time.zone.today < birthdate + a.years
a
end
def idle
"%d m" % [TimeDifference.between(DateTime.now, lastvisit).in_minutes.floor]
"%d m" % [TimeDifference.between(Time.now.utc, lastvisit).in_minutes.floor]
end
def current_layout
@ -214,7 +214,7 @@ class User < ActiveRecord::Base
end
def banned? type = Ban::TYPE_SITE
Ban.where("expiry > UTC_TIMESTAMP() AND user_id = ? AND ban_type = ?", self.id, type).exists?
bans.effective.where(ban_type: type).count > 0
end
def admin?

View file

@ -6,7 +6,7 @@ services:
tty: true
stdin_open: true
# Debug
command: /bin/bash
# command: /bin/bash
container_name: ensl_dev
build:
context: ./
@ -29,6 +29,7 @@ services:
# Debug
#stdin_open: true
command: ["/bin/bash", "-c", "--", "while true; do sleep 100; done;"]
container_name: ensl_test
build:
context: ./
dockerfile: Dockerfile.dev
@ -56,6 +57,7 @@ services:
redis:
image: 'redis:4.0-alpine'
container_name: ensl_dev_redis
selenium:
image: selenium/standalone-chrome-debug

View file

@ -5,7 +5,7 @@ RSpec.describe UsersController, type: :controller do
let!(:params) { FactoryBot.attributes_for(:user) }
let!(:invalid_params) { params.merge(:steamid => (50..150).map { (65 + rand(26)).chr }.join) }
let!(:admin) { create(:user, :admin) }
let!(:user) { create(:user) }
let!(:user) { create(:user).reload }
before :all do
create(:user)

View file

@ -1,7 +1,11 @@
FactoryBot.define do
factory :ban, class: Ban do
ban_type { Ban::TYPE_SITE }
expiry { Time.now.utc.to_date + 1 }
# NOTE: due to time zone difference this causes tests to fail
# When adding the time, its in previous day and the time is set to 00:00
# read: http://danilenko.org/2012/7/6/rails_timezones/
expiry { Time.now.utc + 1.day }
# Hack because of the awkward way bans are created (requires user_name)
before(:create) do |ban|
if ban.user.nil?
@ -25,7 +29,7 @@ FactoryBot.define do
end
trait :expired do
expiry { Date.yesterday - 1 }
expiry { Time.now.utc - 1.day }
end
end
end

View file

@ -42,7 +42,7 @@ describe Topic do
topic = create :topic, first_post: "Foo"
topics.push(topic)
end
recent_topics = Topic.recent_topicsbyebug
recent_topics = Topic.recent_topics
topics.last(5).each do |topic|
expect(recent_topics).to include(topic)
end