Fix more conditions and tests

This commit is contained in:
Ari Timonen 2020-03-23 04:22:12 +02:00
parent 89c1afb926
commit b15e1f888c
11 changed files with 38 additions and 41 deletions

View file

@ -8,9 +8,9 @@ class Api::V1::UsersController < Api::V1::BaseController
@user = User.find(params[:id])
elsif params[:format] == "steamid"
steamid_i = params[:id].to_i
@user = User.first(conditions: { steamid: format("0:%d:%d", steamid_i % 2, steamid_i >> 1) })
@user = User.where(steamid: format("0:%d:%d", steamid_i % 2, steamid_i >> 1)).first
elsif params[:format] == "steamidstr"
@user = User.first(conditions: { steamid: params[:id] })
@user = User.where(steamid: params[:id]).first
end
if @user.nil?

View file

@ -7,7 +7,7 @@ class CommentsController < ApplicationController
end
def show
@comments = Comment.recent5.all conditions: { commentable_id: params[:id2], commentable_type: params[:id] }
@comments = Comment.recent5.where(commentable_id: params[:id2], commentable_type: params[:id])
render partial: 'list', layout: false
end

View file

@ -5,7 +5,7 @@ module GathersHelper
render partial: 'running', layout: false
elsif @gather.status == Gather::STATE_VOTING
if @gatherer and @gather.gatherer_votes.first(conditions: { user_id: cuser.id })
if @gatherer and @gather.gatherer_votes.where(user_id: cuser.id)
headers['Gather'] = 'voted'
else
headers['Gather'] = 'voting'

View file

@ -73,7 +73,7 @@ class Contester < ActiveRecord::Base
end
def get_matches
contest.matches.all :conditions => ["contester1_id = ? OR contester2_id = ?", id, id]
contest.matches.where("contester1_id = ? OR contester2_id = ?", id, id)
end
def init_variables

View file

@ -22,8 +22,7 @@ class Forumer < ActiveRecord::Base
include Extra
scope :access,
lambda { |level| {:conditions => ["access >= ?", level]} }
scope :access, -> (level) { where("access >= ?", level) }
validates_uniqueness_of :group_id, :scope => [:forum_id, :access]
validates_presence_of [:group_id, :forum_id]

View file

@ -22,9 +22,7 @@ class Map < ActiveRecord::Base
scope :basic, -> { where(deleted: false).order("name") }
scope :with_name, -> (name) { where(name: name) }
scope :classic, -> { where("name LIKE 'ns_%'") }
scope :of_category,
lambda { |category| {
:conditions => {:category_id => category.id} }}
scope :of_category, ->(category) { where(category_id: category.id) }
validates_length_of :name, :maximum => 20
validates_length_of :download, :maximum => 100

View file

@ -131,7 +131,7 @@ class Server < ActiveRecord::Base
end
def self.move addr, newaddr, newpwd
self.hltvs.all(:conditions => {:reservation => addr}).each do |hltv|
self.hltvs.where(reservation => addr).each do |hltv|
hltv.reservation = newaddr
hltv.pwd = newpwd
hltv.save!
@ -139,7 +139,7 @@ class Server < ActiveRecord::Base
end
def self.stop addr
self.hltvs.all(:conditions => {:reservation => addr}).each do |hltv|
self.hltvs.where(:reservation => addr).each do |hltv|
hltv.reservation = nil
hltv.save!
end

View file

@ -108,7 +108,7 @@ class User < ActiveRecord::Base
.order("num DESC") }
scope :banned, -> {
joins("LEFT JOIN bans ON bans.user_id = users.id AND expiry > UTC_TIMESTAMP()")
.conditions("bans.id IS NOT NULL") }
.where("bans.id IS NOT NULL") }
scope :idle, -> {
where("lastvisit < ?", 30.minutes.ago.utc) }
scope :lately, -> {

View file

@ -11,7 +11,7 @@ describe Api::V1::ServersController do
it "returns a list of servers" do
get :index
expect(response).to be_success
expect(response).to have_http_status(:success)
expect(json["servers"].length).to eq(1)
json_server = json["servers"][0]
expect(json_server["id"]).to eq(server.id)

View file

@ -16,8 +16,8 @@ describe Api::V1::TeamsController do
end
it "returns team data" do
get :show, id: @team.id
expect(response).to be_success
get :show, params: { id: @team.id }
expect(response).to have_http_status(:success)
expect(json["id"]).to eq(@team.id)
expect(json["name"]).to eq(@team.name)
@ -28,7 +28,7 @@ describe Api::V1::TeamsController do
it "returns 404 if team not found" do
expect {
get :show, id: Team.last.id + 1
get :show, params: { id: Team.last.id + 1 }
}.to raise_error(ActionController::RoutingError)
end
end

View file

@ -31,16 +31,16 @@ describe Api::V1::UsersController do
end
it "returns user data" do
get :show, id: @user.id
get :show, params: { id: @user.id }
expect(response).to be_success
expect(response).to have_http_status(:success)
user_expectation(json, @user)
end
it "returns user data for query with id specified as format" do
get :show, id: @user.id, format: "id"
get :show, params: { id: @user.id, format: "id" }
expect(response).to be_success
expect(response).to have_http_status(:success)
user_expectation(json, @user)
end
@ -48,16 +48,16 @@ describe Api::V1::UsersController do
m = @user.steamid.match(/\A0:([01]):(\d{1,10})\Z/)
steamid = (m[2].to_i << 1) + m[1].to_i
get :show, id: steamid, format: "steamid"
get :show, params: { id: steamid, format: "steamid" }
expect(response).to be_success
expect(response).to have_http_status(:success)
user_expectation(json, @user)
end
it "returns user data for a string steamid query" do
get :show, id: @user.steamid, format: "steamidstr"
get :show, params: { id: @user.steamid, format: "steamidstr" }
expect(response).to be_success
expect(response).to have_http_status(:success)
user_expectation(json, @user)
end
@ -65,27 +65,27 @@ describe Api::V1::UsersController do
@user.steamid = nil
@user.save!
get :show, id: @user.id
get :show, params: { id: @user.id }
expect(response).to be_success
expect(response).to have_http_status(:success)
expect(json["steam"]).to be_nil
end
it "returns gather moderator status" do
group = create :group, :gather_moderator
create :grouper, user: @user, group: group
get :show, id: @user.id
get :show, params: { id: @user.id }
expect(json["moderator"]).to eq(true)
end
it "returns 404 if user does not exist" do
get :show, id: -1
get :show, params: { id: -1 }
expect(response.status).to eq(404)
expect(json["error"]).to eq("User not found")
end
it "returns 404 if user does not exist by steamid" do
get :show, id: -1, format: "steamid"
get :show, params: { id: -1, format: "steamid" }
expect(response.status).to eq(404)
expect(json["error"]).to eq("User not found")
end
@ -93,9 +93,9 @@ describe Api::V1::UsersController do
it "queries the steam condenser for an invalid steamid" do
@user.update_attribute(:steamid, "0:0:0")
get :show, id: @user.id
get :show, params: { id: @user.id }
expect(response).to be_success
expect(response).to have_http_status(:success)
expect(json["steam"]).to_not be_nil
expect(json["steam"]["id"]).to eq(@user.steamid)
expect(json["steam"]["url"]).to be_nil
@ -104,30 +104,30 @@ describe Api::V1::UsersController do
it "returns correct ban if user muted" do
create :ban, :mute, user: @user
get :show, id: @user.id
expect(response).to be_success
get :show, params: { id: @user.id }
expect(response).to have_http_status(:success)
expect(json["bans"]["mute"]).to eq(true)
end
it "returns correct ban if user gather banned" do
create :ban, :gather, user: @user
get :show, id: @user.id
expect(response).to be_success
get :show, params: { id: @user.id }
expect(response).to have_http_status(:success)
expect(json["bans"]["gather"]).to eq(true)
end
it "returns correct ban if user site banned" do
create :ban, :site, user: @user
get :show, id: @user.id
expect(response).to be_success
get :show, params: { id: @user.id }
expect(response).to have_http_status(:success)
expect(json["bans"]["site"]).to eq(true)
end
it "returns team information" do
@user.destroy
@user_with_team = create :user_with_team, :chris
get :show, id: @user_with_team.id
expect(response).to be_success
get :show, params: { id: @user_with_team.id }
expect(response).to have_http_status(:success)
expect(json["team"]["id"]).to eq(@user_with_team.team.id)
expect(json["team"]["name"]).to eq(@user_with_team.team.name)
end
@ -143,7 +143,7 @@ describe Api::V1::UsersController do
get :index
expect(response).to be_success
expect(response).to have_http_status(:success)
expect(json["users"].size).to eq(users.size)
end