From 93ab019d8c8cedc94e29bc9c7917809318b66fd2 Mon Sep 17 00:00:00 2001 From: Ari Timonen Date: Tue, 17 Mar 2020 03:03:02 +0200 Subject: [PATCH] Fix more scopes and fix gather --- Gemfile | 19 ++++++++++--------- Gemfile.lock | 12 ++++++------ app/controllers/gathers_controller.rb | 2 +- app/models/custom_url.rb | 2 +- app/models/gather.rb | 8 ++++---- app/models/gatherer.rb | 21 +++++++++------------ app/models/match_proposal.rb | 2 +- app/models/movie.rb | 4 ++-- app/models/poll.rb | 2 +- app/models/vote.rb | 8 ++++---- spec/factories/ban.rb | 12 ++++++------ spec/factories/category.rb | 2 +- spec/spec_helper.rb | 2 +- 13 files changed, 47 insertions(+), 49 deletions(-) diff --git a/Gemfile b/Gemfile index 5efa1ec..c38276e 100644 --- a/Gemfile +++ b/Gemfile @@ -1,13 +1,11 @@ # frozen_string_literal: true source 'http://rubygems.org' - ruby '2.4.9' # Rails core gem 'rails', '~> 5.2.4.1' gem 'rake', '< 11.0' -gem 'responders' # Dotenv gem 'dotenv-rails' @@ -32,12 +30,12 @@ gem 'active_link_to' gem 'bbcoder' gem 'bluecloth' gem 'carrierwave' -gem 'country_select', require: 'country_select_without_sort_alphabetical' -gem 'dynamic_form' -gem 'i18n_country_select' gem 'nokogiri' -gem 'public_suffix' gem 'rmagick' +gem 'country_select', require: 'country_select_without_sort_alphabetical' +gem 'i18n_country_select' +gem 'dynamic_form' +gem 'public_suffix' gem 'sanitize' gem 'will_paginate', '~> 3.0.5' @@ -46,14 +44,14 @@ gem 'google-api-client', '~> 0.10.3' gem 'steam-condenser', github: 'koraktor/steam-condenser-ruby' # FIXME: Legacy feature shims -# gem 'protected_attributes' gem 'rails_autolink' +gem 'responders' # Javascript gem 'coffee-rails' -gem 'i18n-js' gem 'jquery-rails' gem 'tinymce-rails' +gem 'i18n-js' # Please install nodejs locally. # gem 'therubyracer', '~> 0.12.1' if RUBY_PLATFORM == 'x86_64-linux' @@ -66,6 +64,8 @@ gem 'haml' # Upgrading will cause issues gem 'neat', '~> 1.6.0' + +# This it outdated by sassc gem 'sass-rails', '~> 5.0.3' gem 'uglifier', '~> 2.5.0' @@ -90,7 +90,8 @@ group :test do gem 'capybara' # gem 'codeclimate-test-reporter', require: nil gem 'database_cleaner' - gem 'factory_bot_rails' + # FIXME: Downgraded b/c of deprecations, fix static attributes + gem 'factory_bot_rails', '4.10.0' gem 'phantomjs', require: 'phantomjs/poltergeist' gem 'poltergeist' gem 'rspec' diff --git a/Gemfile.lock b/Gemfile.lock index cc042e3..48a10af 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -128,11 +128,11 @@ GEM dynamic_form (1.1.4) erubi (1.9.0) execjs (2.7.0) - factory_bot (5.1.1) - activesupport (>= 4.2.0) - factory_bot_rails (5.1.1) - factory_bot (~> 5.1.0) - railties (>= 4.2.0) + factory_bot (4.10.0) + activesupport (>= 3.0.0) + factory_bot_rails (4.10.0) + factory_bot (~> 4.10.0) + railties (>= 3.0.0) faraday (0.9.2) multipart-post (>= 1.2, < 3) ffi (1.12.2) @@ -405,7 +405,7 @@ DEPENDENCIES database_cleaner dotenv-rails dynamic_form - factory_bot_rails + factory_bot_rails (= 4.10.0) faraday (~> 0.9.0) font-awesome-sass (~> 4.1.0.0) google-api-client (~> 0.10.3) diff --git a/app/controllers/gathers_controller.rb b/app/controllers/gathers_controller.rb index 50ed5b7..45bd78d 100644 --- a/app/controllers/gathers_controller.rb +++ b/app/controllers/gathers_controller.rb @@ -67,7 +67,7 @@ class GathersController < ApplicationController def get_gather Gather.transaction do - @gather = Gather.basic.find(params[:id], :lock => true) + @gather = Gather.basic.where(id: params[:id]).lock(true).first @gather.refresh cuser end diff --git a/app/models/custom_url.rb b/app/models/custom_url.rb index 0c7bbaa..231ceee 100644 --- a/app/models/custom_url.rb +++ b/app/models/custom_url.rb @@ -1,6 +1,6 @@ class CustomUrl < ActiveRecord::Base belongs_to :article - attr_accessible :name + # FIXME: attr_accessible :name validates :name, length: {in: 2..10}, diff --git a/app/models/gather.rb b/app/models/gather.rb index 87c1818..bd165bc 100644 --- a/app/models/gather.rb +++ b/app/models/gather.rb @@ -43,12 +43,12 @@ class Gather < ActiveRecord::Base has_many :gatherers has_many :users, :through => :gatherers + has_many :gather_maps, :class_name => "GatherMap" has_many :gatherer_votes, :through => :gatherers, :source => :real_votes has_many :map_votes, :through => :gather_maps, :source => :real_votes - has_many :gather_maps, :class_name => "GatherMap" + has_many :gather_servers, :class_name => "GatherServer" has_many :maps, :through => :gather_maps has_many :server_votes, :through => :gather_servers, :source => :real_votes - has_many :gather_servers, :class_name => "GatherServer" has_many :servers, :through => :gather_servers has_many :shoutmsgs, :as => "shoutable" has_many :real_votes, :class_name => "Vote", :as => :votable, :dependent => :destroy @@ -93,11 +93,11 @@ class Gather < ActiveRecord::Base end def previous_gather - Gather.first.where("id < ? AND category_id = ?", self.id, category_id).order("id DESC") + Gather.where("id < ? AND category_id = ?", self.id, category_id).order("id DESC").first end def next_gather - Gather.first.where("id > ? AND category_id = ?", self.id, category_id).order("id ASC") + Gather.where("id > ? AND category_id = ?", self.id, category_id).order("id ASC").first end def last diff --git a/app/models/gatherer.rb b/app/models/gatherer.rb index 04dd4af..ed8e6dd 100644 --- a/app/models/gatherer.rb +++ b/app/models/gatherer.rb @@ -26,10 +26,8 @@ class Gatherer < ActiveRecord::Base attr_accessor :confirm, :username cattr_accessor :skip_callbacks - scope :team, - lambda { |team| {:conditions => {:team => team}} } - scope :of_user, - lambda { |user| {:conditions => {:user_id => user.id}} } + scope :team, -> (team) { where(team: team) } + scope :of_user, -> (user) { where(user_id: user.id) } scope :lobby, -> { where(team: nil) } scope :best, lambda { |gather| { @@ -47,11 +45,10 @@ class Gatherer < ActiveRecord::Base joins("LEFT JOIN rounders ON rounders.user_id = gatherers.user_id"). group("rounders.user_id"). order("kpd DESC") } - scope :lobby_team, -> (team) { conditions("gatherers.team IS NULL OR gatherers.team = ?", team). + scope :lobby_team, -> (team) { where("gatherers.team IS NULL OR gatherers.team = ?", team). order("gatherers.team") } scope :most_voted, -> { order("votes DESC, created_at DESC") } - scope :not_user, - lambda { |user| {:conditions => ["user_id != ?", user.id]} } + scope :not_user, -> (user) { where("user_id != ?", user.id) } scope :eject_order, -> { order("votes ASC") } scope :ordered, -> { joins("LEFT JOIN gathers ON captain1_id = gatherers.id OR captain2_id = gatherers.id"). @@ -80,7 +77,7 @@ class Gatherer < ActiveRecord::Base def validate_username if username - if u = User.first(:conditions => {:username => username}) + if u = User.where(username: username).exists? self.user = u else errors.add(:username, t(:gatherer_wrong_username)) @@ -93,7 +90,7 @@ class Gatherer < ActiveRecord::Base end def notify_gatherers - Profile.all(:include => :user, :conditions => "notify_gather = 1").each do |p| + Profile.where(notify_gather: 1).includes(:user).each do |p| Notifications.gather p.user, gather if p.user end end @@ -117,9 +114,9 @@ class Gatherer < ActiveRecord::Base end def cleanup_votes - gather.map_votes.all(:conditions => {:user_id => user_id}).each { |g| g.destroy } - gather.server_votes.all(:conditions => {:user_id => user_id}).each { |g| g.destroy } - gather.gatherer_votes.all(:conditions => {:user_id => user_id}).each { |g| g.destroy } + gather.map_votes.where(user_id: user_id).each { |g| g.destroy } + gather.server_votes.where(user_id: user_id).each { |g| g.destroy } + gather.gatherer_votes.where(user_id: user_id).each { |g| g.destroy } end def votes_needed? diff --git a/app/models/match_proposal.rb b/app/models/match_proposal.rb index 4d74e54..b04db86 100644 --- a/app/models/match_proposal.rb +++ b/app/models/match_proposal.rb @@ -12,7 +12,7 @@ class MatchProposal < ActiveRecord::Base belongs_to :match belongs_to :team #has_many :confirmed_by, class_name: 'Team', uniq: true - attr_accessible :proposed_time, :status + # FIXME: attr_accessible :proposed_time, :status validates_presence_of :match, :team, :proposed_time diff --git a/app/models/movie.rb b/app/models/movie.rb index 6361053..0702c98 100644 --- a/app/models/movie.rb +++ b/app/models/movie.rb @@ -35,7 +35,7 @@ class Movie < ActiveRecord::Base scope :recent, -> { limit(5) } scope :ordered, -> { include("file"). order("data_files.created_at DESC") } - scope :index, -> { + scope :with_ratings, -> { select("movies.*, users.username, AVG(rates.score) as total_ratings") .joins("LEFT JOIN data_files ON movies.file_id = data_files.id LEFT JOIN users ON movies.user_id = users.id @@ -146,7 +146,7 @@ def self.filter_or_all order, filter # end # return movies #else - return index.order(order) + return with_ratings.order(order) #end end diff --git a/app/models/poll.rb b/app/models/poll.rb index bee3f6b..b529702 100644 --- a/app/models/poll.rb +++ b/app/models/poll.rb @@ -28,7 +28,7 @@ class Poll < ActiveRecord::Base accepts_nested_attributes_for :options, :allow_destroy => true def voted? user - real_votes.count(:conditions => {:user_id => user.id}) > 0 + real_votes.where(user_id: user.id).count > 0 end def can_create? cuser diff --git a/app/models/vote.rb b/app/models/vote.rb index b199872..ec6bdd5 100644 --- a/app/models/vote.rb +++ b/app/models/vote.rb @@ -48,18 +48,18 @@ class Vote < ActiveRecord::Base return false end elsif votable_type == "Gatherer" or votable_type == "GatherMap" or votable_type == "GatherServer" - return false unless votable.gather.users.exists? cuser + return false unless votable.gather.users.exists? cuser.id case votable_type when "Gatherer" then return false if votable.gather.status != Gather::STATE_VOTING - return false if votable.gather.gatherer_votes.count(:conditions => {:user_id => user.id}) > 1 + return false if votable.gather.gatherer_votes.where(user_id: user.id).count > 1 when "GatherMap" then return false if votable.gather.status == Gather::STATE_FINISHED - return false if votable.gather.map_votes.count(:conditions => {:user_id => user.id}) > 1 + return false if votable.gather.map_votes.where(user_id: user.id).count > 1 when "GatherServer" then return false if votable.gather.status == Gather::STATE_FINISHED - return false if votable.gather.server_votes.first :conditions => {:user_id => user.id} + return false if votable.gather.server_votes.where(user_id: user.id).count > 0 end end diff --git a/spec/factories/ban.rb b/spec/factories/ban.rb index a4ae705..3d46d35 100755 --- a/spec/factories/ban.rb +++ b/spec/factories/ban.rb @@ -1,7 +1,7 @@ FactoryBot.define do factory :ban do - ban_type Ban::TYPE_SITE - expiry Time.now.utc.to_date + 1 + ban_type { Ban::TYPE_SITE } + expiry { Time.now.utc.to_date + 1 } # Hack because of the awkward way bans are created (requires user_name) before(:create) do |ban| if ban.user.nil? @@ -14,18 +14,18 @@ FactoryBot.define do end trait :mute do - ban_type Ban::TYPE_MUTE + ban_type { Ban::TYPE_MUTE } end trait :site do - ban_type Ban::TYPE_SITE + ban_type { Ban::TYPE_SITE } end trait :gather do - ban_type Ban::TYPE_GATHER + ban_type { Ban::TYPE_GATHERĀ } end trait :expired do - expiry Date.yesterday - 1 + expiry { Date.yesterday - 1 } end end diff --git a/spec/factories/category.rb b/spec/factories/category.rb index b14d7fb..c691b85 100755 --- a/spec/factories/category.rb +++ b/spec/factories/category.rb @@ -5,7 +5,7 @@ FactoryBot.define do end trait :news do - domain Category::DOMAIN_NEWS + domain { Category::DOMAIN_NEWS } end trait :game do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 218c971..911637b 100755 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -14,7 +14,7 @@ require "rspec/rails" require "capybara/rspec" require "capybara/poltergeist" -Capybara.default_wait_time = 5 +Capybara.default_max_wait_time = 5 Capybara.register_driver :poltergeist do |app| Capybara::Poltergeist::Driver.new( app,