Fix more scopes and fix gather

This commit is contained in:
Ari Timonen 2020-03-17 03:03:02 +02:00
parent 00c5c86eb4
commit 93ab019d8c
13 changed files with 47 additions and 49 deletions

19
Gemfile
View file

@ -1,13 +1,11 @@
# frozen_string_literal: true # frozen_string_literal: true
source 'http://rubygems.org' source 'http://rubygems.org'
ruby '2.4.9' ruby '2.4.9'
# Rails core # Rails core
gem 'rails', '~> 5.2.4.1' gem 'rails', '~> 5.2.4.1'
gem 'rake', '< 11.0' gem 'rake', '< 11.0'
gem 'responders'
# Dotenv # Dotenv
gem 'dotenv-rails' gem 'dotenv-rails'
@ -32,12 +30,12 @@ gem 'active_link_to'
gem 'bbcoder' gem 'bbcoder'
gem 'bluecloth' gem 'bluecloth'
gem 'carrierwave' gem 'carrierwave'
gem 'country_select', require: 'country_select_without_sort_alphabetical'
gem 'dynamic_form'
gem 'i18n_country_select'
gem 'nokogiri' gem 'nokogiri'
gem 'public_suffix'
gem 'rmagick' gem 'rmagick'
gem 'country_select', require: 'country_select_without_sort_alphabetical'
gem 'i18n_country_select'
gem 'dynamic_form'
gem 'public_suffix'
gem 'sanitize' gem 'sanitize'
gem 'will_paginate', '~> 3.0.5' 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' gem 'steam-condenser', github: 'koraktor/steam-condenser-ruby'
# FIXME: Legacy feature shims # FIXME: Legacy feature shims
# gem 'protected_attributes'
gem 'rails_autolink' gem 'rails_autolink'
gem 'responders'
# Javascript # Javascript
gem 'coffee-rails' gem 'coffee-rails'
gem 'i18n-js'
gem 'jquery-rails' gem 'jquery-rails'
gem 'tinymce-rails' gem 'tinymce-rails'
gem 'i18n-js'
# Please install nodejs locally. # Please install nodejs locally.
# gem 'therubyracer', '~> 0.12.1' if RUBY_PLATFORM == 'x86_64-linux' # gem 'therubyracer', '~> 0.12.1' if RUBY_PLATFORM == 'x86_64-linux'
@ -66,6 +64,8 @@ gem 'haml'
# Upgrading will cause issues # Upgrading will cause issues
gem 'neat', '~> 1.6.0' gem 'neat', '~> 1.6.0'
# This it outdated by sassc
gem 'sass-rails', '~> 5.0.3' gem 'sass-rails', '~> 5.0.3'
gem 'uglifier', '~> 2.5.0' gem 'uglifier', '~> 2.5.0'
@ -90,7 +90,8 @@ group :test do
gem 'capybara' gem 'capybara'
# gem 'codeclimate-test-reporter', require: nil # gem 'codeclimate-test-reporter', require: nil
gem 'database_cleaner' 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 'phantomjs', require: 'phantomjs/poltergeist'
gem 'poltergeist' gem 'poltergeist'
gem 'rspec' gem 'rspec'

View file

@ -128,11 +128,11 @@ GEM
dynamic_form (1.1.4) dynamic_form (1.1.4)
erubi (1.9.0) erubi (1.9.0)
execjs (2.7.0) execjs (2.7.0)
factory_bot (5.1.1) factory_bot (4.10.0)
activesupport (>= 4.2.0) activesupport (>= 3.0.0)
factory_bot_rails (5.1.1) factory_bot_rails (4.10.0)
factory_bot (~> 5.1.0) factory_bot (~> 4.10.0)
railties (>= 4.2.0) railties (>= 3.0.0)
faraday (0.9.2) faraday (0.9.2)
multipart-post (>= 1.2, < 3) multipart-post (>= 1.2, < 3)
ffi (1.12.2) ffi (1.12.2)
@ -405,7 +405,7 @@ DEPENDENCIES
database_cleaner database_cleaner
dotenv-rails dotenv-rails
dynamic_form dynamic_form
factory_bot_rails factory_bot_rails (= 4.10.0)
faraday (~> 0.9.0) faraday (~> 0.9.0)
font-awesome-sass (~> 4.1.0.0) font-awesome-sass (~> 4.1.0.0)
google-api-client (~> 0.10.3) google-api-client (~> 0.10.3)

View file

@ -67,7 +67,7 @@ class GathersController < ApplicationController
def get_gather def get_gather
Gather.transaction do Gather.transaction do
@gather = Gather.basic.find(params[:id], :lock => true) @gather = Gather.basic.where(id: params[:id]).lock(true).first
@gather.refresh cuser @gather.refresh cuser
end end

View file

@ -1,6 +1,6 @@
class CustomUrl < ActiveRecord::Base class CustomUrl < ActiveRecord::Base
belongs_to :article belongs_to :article
attr_accessible :name # FIXME: attr_accessible :name
validates :name, validates :name,
length: {in: 2..10}, length: {in: 2..10},

View file

@ -43,12 +43,12 @@ class Gather < ActiveRecord::Base
has_many :gatherers has_many :gatherers
has_many :users, :through => :gatherers has_many :users, :through => :gatherers
has_many :gather_maps, :class_name => "GatherMap"
has_many :gatherer_votes, :through => :gatherers, :source => :real_votes has_many :gatherer_votes, :through => :gatherers, :source => :real_votes
has_many :map_votes, :through => :gather_maps, :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 :maps, :through => :gather_maps
has_many :server_votes, :through => :gather_servers, :source => :real_votes 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 :servers, :through => :gather_servers
has_many :shoutmsgs, :as => "shoutable" has_many :shoutmsgs, :as => "shoutable"
has_many :real_votes, :class_name => "Vote", :as => :votable, :dependent => :destroy has_many :real_votes, :class_name => "Vote", :as => :votable, :dependent => :destroy
@ -93,11 +93,11 @@ class Gather < ActiveRecord::Base
end end
def previous_gather 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 end
def next_gather 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 end
def last def last

View file

@ -26,10 +26,8 @@ class Gatherer < ActiveRecord::Base
attr_accessor :confirm, :username attr_accessor :confirm, :username
cattr_accessor :skip_callbacks cattr_accessor :skip_callbacks
scope :team, scope :team, -> (team) { where(team: team) }
lambda { |team| {:conditions => {:team => team}} } scope :of_user, -> (user) { where(user_id: user.id) }
scope :of_user,
lambda { |user| {:conditions => {:user_id => user.id}} }
scope :lobby, -> { where(team: nil) } scope :lobby, -> { where(team: nil) }
scope :best, scope :best,
lambda { |gather| { lambda { |gather| {
@ -47,11 +45,10 @@ class Gatherer < ActiveRecord::Base
joins("LEFT JOIN rounders ON rounders.user_id = gatherers.user_id"). joins("LEFT JOIN rounders ON rounders.user_id = gatherers.user_id").
group("rounders.user_id"). group("rounders.user_id").
order("kpd DESC") } 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") } order("gatherers.team") }
scope :most_voted, -> { order("votes DESC, created_at DESC") } scope :most_voted, -> { order("votes DESC, created_at DESC") }
scope :not_user, scope :not_user, -> (user) { where("user_id != ?", user.id) }
lambda { |user| {:conditions => ["user_id != ?", user.id]} }
scope :eject_order, -> { order("votes ASC") } scope :eject_order, -> { order("votes ASC") }
scope :ordered, -> { scope :ordered, -> {
joins("LEFT JOIN gathers ON captain1_id = gatherers.id OR captain2_id = gatherers.id"). 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 def validate_username
if username if username
if u = User.first(:conditions => {:username => username}) if u = User.where(username: username).exists?
self.user = u self.user = u
else else
errors.add(:username, t(:gatherer_wrong_username)) errors.add(:username, t(:gatherer_wrong_username))
@ -93,7 +90,7 @@ class Gatherer < ActiveRecord::Base
end end
def notify_gatherers 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 Notifications.gather p.user, gather if p.user
end end
end end
@ -117,9 +114,9 @@ class Gatherer < ActiveRecord::Base
end end
def cleanup_votes def cleanup_votes
gather.map_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.all(:conditions => {:user_id => user_id}).each { |g| g.destroy } gather.server_votes.where(user_id: user_id).each { |g| g.destroy }
gather.gatherer_votes.all(:conditions => {:user_id => user_id}).each { |g| g.destroy } gather.gatherer_votes.where(user_id: user_id).each { |g| g.destroy }
end end
def votes_needed? def votes_needed?

View file

@ -12,7 +12,7 @@ class MatchProposal < ActiveRecord::Base
belongs_to :match belongs_to :match
belongs_to :team belongs_to :team
#has_many :confirmed_by, class_name: 'Team', uniq: true #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 validates_presence_of :match, :team, :proposed_time

View file

@ -35,7 +35,7 @@ class Movie < ActiveRecord::Base
scope :recent, -> { limit(5) } scope :recent, -> { limit(5) }
scope :ordered, -> { include("file"). scope :ordered, -> { include("file").
order("data_files.created_at DESC") } order("data_files.created_at DESC") }
scope :index, -> { scope :with_ratings, -> {
select("movies.*, users.username, AVG(rates.score) as total_ratings") select("movies.*, users.username, AVG(rates.score) as total_ratings")
.joins("LEFT JOIN data_files ON movies.file_id = data_files.id .joins("LEFT JOIN data_files ON movies.file_id = data_files.id
LEFT JOIN users ON movies.user_id = users.id LEFT JOIN users ON movies.user_id = users.id
@ -146,7 +146,7 @@ def self.filter_or_all order, filter
# end # end
# return movies # return movies
#else #else
return index.order(order) return with_ratings.order(order)
#end #end
end end

View file

@ -28,7 +28,7 @@ class Poll < ActiveRecord::Base
accepts_nested_attributes_for :options, :allow_destroy => true accepts_nested_attributes_for :options, :allow_destroy => true
def voted? user def voted? user
real_votes.count(:conditions => {:user_id => user.id}) > 0 real_votes.where(user_id: user.id).count > 0
end end
def can_create? cuser def can_create? cuser

View file

@ -48,18 +48,18 @@ class Vote < ActiveRecord::Base
return false return false
end end
elsif votable_type == "Gatherer" or votable_type == "GatherMap" or votable_type == "GatherServer" 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 case votable_type
when "Gatherer" then when "Gatherer" then
return false if votable.gather.status != Gather::STATE_VOTING 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 when "GatherMap" then
return false if votable.gather.status == Gather::STATE_FINISHED 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 when "GatherServer" then
return false if votable.gather.status == Gather::STATE_FINISHED 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
end end

View file

@ -1,7 +1,7 @@
FactoryBot.define do FactoryBot.define do
factory :ban do factory :ban do
ban_type Ban::TYPE_SITE ban_type { Ban::TYPE_SITE }
expiry Time.now.utc.to_date + 1 expiry { Time.now.utc.to_date + 1 }
# Hack because of the awkward way bans are created (requires user_name) # Hack because of the awkward way bans are created (requires user_name)
before(:create) do |ban| before(:create) do |ban|
if ban.user.nil? if ban.user.nil?
@ -14,18 +14,18 @@ FactoryBot.define do
end end
trait :mute do trait :mute do
ban_type Ban::TYPE_MUTE ban_type { Ban::TYPE_MUTE }
end end
trait :site do trait :site do
ban_type Ban::TYPE_SITE ban_type { Ban::TYPE_SITE }
end end
trait :gather do trait :gather do
ban_type Ban::TYPE_GATHER ban_type { Ban::TYPE_GATHER }
end end
trait :expired do trait :expired do
expiry Date.yesterday - 1 expiry { Date.yesterday - 1 }
end end
end end

View file

@ -5,7 +5,7 @@ FactoryBot.define do
end end
trait :news do trait :news do
domain Category::DOMAIN_NEWS domain { Category::DOMAIN_NEWS }
end end
trait :game do trait :game do

View file

@ -14,7 +14,7 @@ require "rspec/rails"
require "capybara/rspec" require "capybara/rspec"
require "capybara/poltergeist" require "capybara/poltergeist"
Capybara.default_wait_time = 5 Capybara.default_max_wait_time = 5
Capybara.register_driver :poltergeist do |app| Capybara.register_driver :poltergeist do |app|
Capybara::Poltergeist::Driver.new( Capybara::Poltergeist::Driver.new(
app, app,