mirror of
https://github.com/neocities/neocities.git
synced 2025-04-24 17:22:35 +02:00
patch a few missing tests, deprecate server model, fix a few bugs
This commit is contained in:
parent
86990f3535
commit
50c1f67bdf
14 changed files with 90 additions and 49 deletions
|
@ -13,6 +13,7 @@ Bundler.require :development if ENV['RACK_ENV'] == 'development'
|
||||||
|
|
||||||
Dir['./ext/**/*.rb'].each {|f| require f}
|
Dir['./ext/**/*.rb'].each {|f| require f}
|
||||||
|
|
||||||
|
# :nocov:
|
||||||
if ENV['TRAVIS']
|
if ENV['TRAVIS']
|
||||||
$config = YAML.load_file File.join(DIR_ROOT, 'config.yml.travis')
|
$config = YAML.load_file File.join(DIR_ROOT, 'config.yml.travis')
|
||||||
else
|
else
|
||||||
|
@ -23,31 +24,37 @@ else
|
||||||
exit
|
exit
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
# :nocov:
|
||||||
|
|
||||||
DB = Sequel.connect $config['database'], sslmode: 'disable', max_connections: $config['database_pool']
|
DB = Sequel.connect $config['database'], sslmode: 'disable', max_connections: $config['database_pool']
|
||||||
DB.extension :pagination
|
DB.extension :pagination
|
||||||
|
|
||||||
|
# :nocov:
|
||||||
if defined?(Pry)
|
if defined?(Pry)
|
||||||
Pry.commands.alias_command 'c', 'continue'
|
Pry.commands.alias_command 'c', 'continue'
|
||||||
Pry.commands.alias_command 's', 'step'
|
Pry.commands.alias_command 's', 'step'
|
||||||
Pry.commands.alias_command 'n', 'next'
|
Pry.commands.alias_command 'n', 'next'
|
||||||
Pry.commands.alias_command 'f', 'finish'
|
Pry.commands.alias_command 'f', 'finish'
|
||||||
end
|
end
|
||||||
|
# :nocov:
|
||||||
|
|
||||||
Sidekiq::Logging.logger = nil unless ENV['RACK_ENV'] == 'production'
|
Sidekiq::Logging.logger = nil unless ENV['RACK_ENV'] == 'production'
|
||||||
|
|
||||||
sidekiq_redis_config = {namespace: 'neocitiesworker'}
|
sidekiq_redis_config = {namespace: 'neocitiesworker'}
|
||||||
sidekiq_redis_config[:url] = $config['sidekiq_url'] if $config['sidekiq_url']
|
sidekiq_redis_config[:url] = $config['sidekiq_url'] if $config['sidekiq_url']
|
||||||
|
|
||||||
|
# :nocov:
|
||||||
Sidekiq.configure_server do |config|
|
Sidekiq.configure_server do |config|
|
||||||
config.redis = sidekiq_redis_config
|
config.redis = sidekiq_redis_config
|
||||||
end
|
end
|
||||||
|
# :nocov:
|
||||||
|
|
||||||
Sidekiq.configure_client do |config|
|
Sidekiq.configure_client do |config|
|
||||||
config.logger = nil
|
config.logger = nil
|
||||||
config.redis = sidekiq_redis_config
|
config.redis = sidekiq_redis_config
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# :nocov:
|
||||||
if $config['pubsub_url']
|
if $config['pubsub_url']
|
||||||
$pubsub_pool = ConnectionPool.new(size: 10, timeout: 5) {
|
$pubsub_pool = ConnectionPool.new(size: 10, timeout: 5) {
|
||||||
Redis.new url: $config['pubsub_url']
|
Redis.new url: $config['pubsub_url']
|
||||||
|
@ -57,10 +64,7 @@ end
|
||||||
if $config['pubsub_url'].nil? && ENV['RACK_ENV'] == 'production'
|
if $config['pubsub_url'].nil? && ENV['RACK_ENV'] == 'production'
|
||||||
raise 'pubsub_url is missing from config'
|
raise 'pubsub_url is missing from config'
|
||||||
end
|
end
|
||||||
|
# :nocov:
|
||||||
#require File.join(DIR_ROOT, 'workers', 'thumbnail_worker.rb')
|
|
||||||
#require File.join(DIR_ROOT, 'workers', 'screenshot_worker.rb')
|
|
||||||
#require File.join(DIR_ROOT, 'workers', 'email_worker.rb')
|
|
||||||
|
|
||||||
Sequel.datetime_class = Time
|
Sequel.datetime_class = Time
|
||||||
Sequel.extension :core_extensions
|
Sequel.extension :core_extensions
|
||||||
|
@ -79,13 +83,6 @@ Dir.glob('workers/*.rb').each {|w| require File.join(DIR_ROOT, "/#{w}") }
|
||||||
|
|
||||||
DB.loggers << Logger.new(STDOUT) if ENV['RACK_ENV'] == 'development'
|
DB.loggers << Logger.new(STDOUT) if ENV['RACK_ENV'] == 'development'
|
||||||
|
|
||||||
if ENV['RACK_ENV'] == 'development'
|
|
||||||
# If new, throw up a random Server for development.
|
|
||||||
if Server.count == 0
|
|
||||||
Server.create ip: '127.0.0.1', slots_available: 999999
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
Mail.defaults do
|
Mail.defaults do
|
||||||
#options = { :address => "smtp.gmail.com",
|
#options = { :address => "smtp.gmail.com",
|
||||||
# :port => 587,
|
# :port => 587,
|
||||||
|
@ -108,7 +105,7 @@ Sass::Plugin.options[:template_location] = 'sass'
|
||||||
Sass::Plugin.options[:css_location] = './public/css'
|
Sass::Plugin.options[:css_location] = './public/css'
|
||||||
Sass::Plugin.options[:style] = :nested
|
Sass::Plugin.options[:style] = :nested
|
||||||
|
|
||||||
if ENV['RACK_ENV'] == 'production'
|
if ENV['RACK_ENV'] != 'development'
|
||||||
Sass::Plugin.options[:style] = :compressed
|
Sass::Plugin.options[:style] = :compressed
|
||||||
Sass::Plugin.options[:never_update] = true
|
Sass::Plugin.options[:never_update] = true
|
||||||
Sass::Plugin.options[:full_exception] = false
|
Sass::Plugin.options[:full_exception] = false
|
||||||
|
|
|
@ -2,8 +2,4 @@ class Numeric
|
||||||
def roundup(nearest=10)
|
def roundup(nearest=10)
|
||||||
self % nearest == 0 ? self : self + nearest - (self % nearest)
|
self % nearest == 0 ? self : self + nearest - (self % nearest)
|
||||||
end
|
end
|
||||||
|
|
||||||
def rounddown(nearest=10)
|
|
||||||
self % nearest == 0 ? self : self - (self % nearest)
|
|
||||||
end
|
|
||||||
end
|
end
|
15
migrations/045_remove_servers.rb
Normal file
15
migrations/045_remove_servers.rb
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
Sequel.migration do
|
||||||
|
up {
|
||||||
|
DB.drop_table :servers
|
||||||
|
}
|
||||||
|
|
||||||
|
down {
|
||||||
|
DB.create_table! :servers do
|
||||||
|
primary_key :id
|
||||||
|
String :ip
|
||||||
|
Integer :slots_available
|
||||||
|
DateTime :created_at
|
||||||
|
DateTime :updated_at
|
||||||
|
end
|
||||||
|
}
|
||||||
|
end
|
|
@ -1,7 +0,0 @@
|
||||||
class Server < Sequel::Model
|
|
||||||
one_to_many :sites
|
|
||||||
|
|
||||||
def self.with_slots_available
|
|
||||||
where{slots_available > 0}.first
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -118,8 +118,6 @@ class Site < Sequel::Model
|
||||||
site_mounting: false
|
site_mounting: false
|
||||||
)
|
)
|
||||||
|
|
||||||
many_to_one :server
|
|
||||||
|
|
||||||
many_to_many :tags
|
many_to_many :tags
|
||||||
|
|
||||||
one_to_many :profile_comments
|
one_to_many :profile_comments
|
||||||
|
@ -216,11 +214,6 @@ class Site < Sequel::Model
|
||||||
@new_tags_string = tags_string
|
@new_tags_string = tags_string
|
||||||
end
|
end
|
||||||
|
|
||||||
def before_validation
|
|
||||||
self.server ||= Server.with_slots_available
|
|
||||||
super
|
|
||||||
end
|
|
||||||
|
|
||||||
def save(validate={})
|
def save(validate={})
|
||||||
DB.transaction do
|
DB.transaction do
|
||||||
is_new = new?
|
is_new = new?
|
||||||
|
@ -547,11 +540,6 @@ class Site < Sequel::Model
|
||||||
add_tag Tag[name: name] || Tag.create(name: name)
|
add_tag Tag[name: name] || Tag.create(name: name)
|
||||||
end
|
end
|
||||||
|
|
||||||
def after_create
|
|
||||||
DB['update servers set slots_available=slots_available-1 where id=?', self.server.id].first
|
|
||||||
super
|
|
||||||
end
|
|
||||||
|
|
||||||
def before_create
|
def before_create
|
||||||
self.email_confirmation_token = SecureRandom.hex 3
|
self.email_confirmation_token = SecureRandom.hex 3
|
||||||
super
|
super
|
||||||
|
@ -570,10 +558,6 @@ class Site < Sequel::Model
|
||||||
def validate
|
def validate
|
||||||
super
|
super
|
||||||
|
|
||||||
if server.nil?
|
|
||||||
errors.add :over_capacity, 'We are currently at capacity, and cannot create your home page. We will fix this shortly. Please come back later and try again, our apologies.'
|
|
||||||
end
|
|
||||||
|
|
||||||
if !self.class.valid_username?(values[:username])
|
if !self.class.valid_username?(values[:username])
|
||||||
errors.add :username, 'A valid user/site name is required.'
|
errors.add :username, 'A valid user/site name is required.'
|
||||||
end
|
end
|
||||||
|
|
|
@ -9,7 +9,7 @@ class Tag < Sequel::Model
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.create_unless_exists(name)
|
def self.create_unless_exists(name)
|
||||||
dataset.filter(name: name).first || create(name: name)
|
dataset.filter(name: name.downcase).first || create(name: name)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.suggestions(name, limit=3)
|
def self.suggestions(name, limit=3)
|
||||||
|
|
|
@ -79,7 +79,7 @@ def generate_ssl_certs(opts={})
|
||||||
combined_cert_tmpfile.close
|
combined_cert_tmpfile.close
|
||||||
res[:combined_cert_path] = combined_cert_tmpfile.path
|
res[:combined_cert_path] = combined_cert_tmpfile.path
|
||||||
|
|
||||||
bad_combined_cert_tmpfile = Tempfile.new 'combined_cert'
|
bad_combined_cert_tmpfile = Tempfile.new 'bad_combined_cert'
|
||||||
bad_combined_cert_tmpfile.write "#{File.read(res[:cert_intermediate_path])}\n#{File.read(res[:cert_path])}"
|
bad_combined_cert_tmpfile.write "#{File.read(res[:cert_intermediate_path])}\n#{File.read(res[:cert_path])}"
|
||||||
bad_combined_cert_tmpfile.close
|
bad_combined_cert_tmpfile.close
|
||||||
res[:bad_combined_cert_path] = bad_combined_cert_tmpfile.path
|
res[:bad_combined_cert_path] = bad_combined_cert_tmpfile.path
|
||||||
|
|
|
@ -38,7 +38,6 @@ Sequel.extension :migration
|
||||||
|
|
||||||
Sequel::Migrator.apply DB, './migrations', 0
|
Sequel::Migrator.apply DB, './migrations', 0
|
||||||
Sequel::Migrator.apply DB, './migrations'
|
Sequel::Migrator.apply DB, './migrations'
|
||||||
Server.create ip: '127.0.0.1', slots_available: 999999
|
|
||||||
|
|
||||||
Fabrication.configure do |config|
|
Fabrication.configure do |config|
|
||||||
config.fabricator_path = 'tests/fabricators'
|
config.fabricator_path = 'tests/fabricators'
|
||||||
|
@ -46,3 +45,7 @@ Fabrication.configure do |config|
|
||||||
end
|
end
|
||||||
|
|
||||||
I18n.enforce_available_locales = true
|
I18n.enforce_available_locales = true
|
||||||
|
|
||||||
|
Mail.defaults do
|
||||||
|
delivery_method :test
|
||||||
|
end
|
9
tests/ext_tests.rb
Normal file
9
tests/ext_tests.rb
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
require_relative './environment.rb'
|
||||||
|
|
||||||
|
describe Time do
|
||||||
|
describe 'ago' do
|
||||||
|
it 'should return the modified value' do
|
||||||
|
Time.now.ago.must_equal 'just now'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
13
tests/tag_tests.rb
Normal file
13
tests/tag_tests.rb
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
require_relative './environment.rb'
|
||||||
|
|
||||||
|
describe Tag do
|
||||||
|
describe 'creation' do
|
||||||
|
it 'should force downcase' do
|
||||||
|
tag_name = SecureRandom.hex(10).downcase
|
||||||
|
Tag.create_unless_exists tag_name
|
||||||
|
Tag[name: tag_name].wont_be_nil
|
||||||
|
Tag.create_unless_exists tag_name.upcase
|
||||||
|
Tag.filter(name: tag_name).count.must_equal 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
23
tests/workers/email_worker_tests.rb
Normal file
23
tests/workers/email_worker_tests.rb
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
require_relative '../environment.rb'
|
||||||
|
|
||||||
|
describe EmailWorker do
|
||||||
|
before do
|
||||||
|
Mail::TestMailer.deliveries.clear
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'sends an email' do
|
||||||
|
worker = EmailWorker.new
|
||||||
|
worker.perform({
|
||||||
|
'from' => 'from@example.com',
|
||||||
|
'to' => 'to@example.com',
|
||||||
|
'subject' => 'Hello World',
|
||||||
|
'body' => 'testing'
|
||||||
|
})
|
||||||
|
|
||||||
|
mail = Mail::TestMailer.deliveries.first
|
||||||
|
mail.from.first.must_equal 'from@example.com'
|
||||||
|
mail.to.first.must_equal 'to@example.com'
|
||||||
|
mail.subject.must_equal 'Hello World'
|
||||||
|
mail.body.to_s.must_equal 'testing'
|
||||||
|
end
|
||||||
|
end
|
|
@ -4,11 +4,12 @@ class EmailWorker
|
||||||
|
|
||||||
def perform(args={})
|
def perform(args={})
|
||||||
Mail.deliver do
|
Mail.deliver do
|
||||||
from args['from']
|
# TODO this is not doing UTF-8 properly.
|
||||||
reply_to args['reply_to']
|
from args['from']
|
||||||
to args['to']
|
reply_to args['reply_to']
|
||||||
subject args['subject']
|
to args['to']
|
||||||
body args['body']
|
subject args['subject']
|
||||||
|
body args['body']
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,7 +2,9 @@ class PurgeCacheWorker
|
||||||
include Sidekiq::Worker
|
include Sidekiq::Worker
|
||||||
sidekiq_options queue: :purgecache, retry: 10, backtrace: true
|
sidekiq_options queue: :purgecache, retry: 10, backtrace: true
|
||||||
|
|
||||||
|
|
||||||
def perform(payload)
|
def perform(payload)
|
||||||
|
# :nocov:
|
||||||
attempt = 0
|
attempt = 0
|
||||||
begin
|
begin
|
||||||
attempt += 1
|
attempt += 1
|
||||||
|
@ -15,5 +17,6 @@ class PurgeCacheWorker
|
||||||
sleep 1
|
sleep 1
|
||||||
retry
|
retry
|
||||||
end
|
end
|
||||||
|
# :nocov:
|
||||||
end
|
end
|
||||||
end
|
end
|
|
@ -16,6 +16,7 @@ module Phantomjs
|
||||||
wait_thr.join
|
wait_thr.join
|
||||||
return stdout.read
|
return stdout.read
|
||||||
end
|
end
|
||||||
|
# :nocov:
|
||||||
rescue Timeout::Error
|
rescue Timeout::Error
|
||||||
stdin.close
|
stdin.close
|
||||||
stdout.close
|
stdout.close
|
||||||
|
@ -23,6 +24,7 @@ module Phantomjs
|
||||||
Process.kill 'QUIT', pid
|
Process.kill 'QUIT', pid
|
||||||
raise Timeout::Error
|
raise Timeout::Error
|
||||||
end
|
end
|
||||||
|
# :nocov:
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -45,6 +47,7 @@ class ScreenshotWorker
|
||||||
height: 720
|
height: 720
|
||||||
)
|
)
|
||||||
rescue Timeout::Error
|
rescue Timeout::Error
|
||||||
|
# :nocov:
|
||||||
puts "#{username}/#{path} is timing out, discontinuing"
|
puts "#{username}/#{path} is timing out, discontinuing"
|
||||||
site = Site[username: username]
|
site = Site[username: username]
|
||||||
site.update is_crashing: true
|
site.update is_crashing: true
|
||||||
|
@ -68,6 +71,7 @@ class ScreenshotWorker
|
||||||
end
|
end
|
||||||
=end
|
=end
|
||||||
return
|
return
|
||||||
|
# :nocov:
|
||||||
end
|
end
|
||||||
|
|
||||||
img_list = Magick::ImageList.new
|
img_list = Magick::ImageList.new
|
||||||
|
|
Loading…
Add table
Reference in a new issue