diff --git a/.gitignore b/.gitignore index 3904471..99f07ae 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,6 @@ coverage/ # Ignore cache file .DS_Store +.env +.env.* +node_modules diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml deleted file mode 100644 index b92e18a..0000000 --- a/.gitlab-ci.yml +++ /dev/null @@ -1,27 +0,0 @@ -image: ryudoawaru/ruby23a - -variables: - CAP_USER: "deployer" - BUNDLE_CACHE: "vendor/bundle/" - RAILS_ENV: "test" - CI: "true" - -cache: - untracked: true - key: "$CI_BUILD_NAME" - paths: - - vendor/bundle/ - -services: - - postgres:9.5 - -before_script: - - ./gitlabci/setup.sh - -stages: - - test - -rspec: - stage: test - script: - - ./bin/rake spec \ No newline at end of file diff --git a/Capfile b/Capfile deleted file mode 100644 index 38eba0f..0000000 --- a/Capfile +++ /dev/null @@ -1,30 +0,0 @@ -# Load DSL and set up stages -require "capistrano/setup" - -# Include default deployment tasks -require "capistrano/deploy" -require 'capistrano/upload-config' -require 'capistrano/sidekiq' -#require 'capistrano/sidekiq/monit' - -# Include tasks from other gems included in your Gemfile -# -# For documentation on these, see for example: -# -# https://github.com/capistrano/rvm -# https://github.com/capistrano/rbenv -# https://github.com/capistrano/chruby -# https://github.com/capistrano/bundler -# https://github.com/capistrano/rails -# https://github.com/capistrano/passenger -# -# require 'capistrano/rvm' -# require 'capistrano/rbenv' -# require 'capistrano/chruby' - require 'capistrano/bundler' - require 'capistrano/rails/assets' - require 'capistrano/rails/migrations' -# require 'capistrano/passenger' - -# Load custom tasks from `lib/capistrano/tasks` if you have any defined -Dir.glob("lib/capistrano/tasks/*.rake").each { |r| import r } diff --git a/Gemfile b/Gemfile index ebd8d8c..aaa6f57 100644 --- a/Gemfile +++ b/Gemfile @@ -2,48 +2,43 @@ source 'https://rubygems.org' gem 'bigdecimal', '~> 1.4' gem 'redis-namespace' -gem 'aasm', '~> 4' -gem 'default_value_for', '>= 3.0.2' -gem 'rails', '5.0.7.2' -gem 'pg', '~> 1.3' +gem 'aasm', '~> 5' +gem 'default_value_for', '~> 3.4.0' +gem 'rails', '5.2.8.1' +gem 'pg', '~> 1.0' gem 'bootstrap-sass', '~> 3.4.1' gem 'font-awesome-rails' gem 'pagedown-bootstrap-rails' gem 'sassc-rails' gem 'uglifier', '>= 1.3.0' -gem 'coffee-rails', '~> 4.1.0' +gem 'coffee-rails' gem 'jquery-rails' gem 'jbuilder', '~> 2.0' -gem 'sdoc', '~> 0.4.0', group: :doc -gem 'simple_form' +gem 'simple_form', '~> 4.1.0' gem 'mini_magick' gem 'jquery-ui-rails' -gem 'devise' +gem 'devise','~> 4.7.0' gem 'ratyrate' gem 'cancancan', '~> 1.10' gem 'carrierwave', '~> 1' gem 'omniauth' gem 'omniauth-github' -gem 'sidekiq', '~> 5' gem 'redcarpet' gem 'rouge', '~> 2.0.6' -gem 'acts-as-taggable-on' +gem 'acts-as-taggable-on', '6.5.0' gem 'unicode_utils' gem 'scenic' gem 'slack-notifier' gem 'puma' - +# gem 'json', '2.6.3' group :development, :test do gem 'byebug' gem 'rspec-rails' - gem 'shoulda' + gem 'shoulda-matchers', '~> 2.8.0' gem 'capybara' - #gem 'selenium-webdriver' - #gem 'capybara-webkit' gem 'fuubar' gem 'factory_bot_rails' - gem 'guard' gem 'guard-rspec' gem 'rails-controller-testing' @@ -56,13 +51,9 @@ group :test do end group :development do - gem 'capistrano-upload-config' + gem 'next_rails', '1.0.5' gem 'letter_opener' - gem 'capistrano', '~> 3.9.0' - gem 'capistrano-rails', '~> 1.1' - gem 'capistrano-sidekiq' - gem 'web-console', '~> 2.0' - gem 'pry-rails' + gem 'web-console', '~> 3.0' gem 'awesome_print' end @@ -73,8 +64,14 @@ end gem 'settingslogic' gem 'country_select' gem 'slim' -gem 'nokogiri', '~> 1.10.8' +gem 'nokogiri', '~> 1' gem "ffi", ">= 1.9.24" gem 'write_xlsx' gem "omniauth-twitter", "~> 1.4" + +gem "bootsnap", "~> 1.18" + +gem "postal-rails", "~> 1.0" + +gem "dotenv-rails", "~> 2.8" diff --git a/Gemfile.lock b/Gemfile.lock index 58e2114..cf1df0e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,81 +1,68 @@ GEM remote: https://rubygems.org/ specs: - aasm (4.12.3) + aasm (5.5.0) concurrent-ruby (~> 1.0) - actioncable (5.0.7.2) - actionpack (= 5.0.7.2) - nio4r (>= 1.2, < 3.0) - websocket-driver (~> 0.6.1) - actionmailer (5.0.7.2) - actionpack (= 5.0.7.2) - actionview (= 5.0.7.2) - activejob (= 5.0.7.2) + actioncable (5.2.8.1) + actionpack (= 5.2.8.1) + nio4r (~> 2.0) + websocket-driver (>= 0.6.1) + actionmailer (5.2.8.1) + actionpack (= 5.2.8.1) + actionview (= 5.2.8.1) + activejob (= 5.2.8.1) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 2.0) - actionpack (5.0.7.2) - actionview (= 5.0.7.2) - activesupport (= 5.0.7.2) - rack (~> 2.0) - rack-test (~> 0.6.3) + actionpack (5.2.8.1) + actionview (= 5.2.8.1) + activesupport (= 5.2.8.1) + rack (~> 2.0, >= 2.0.8) + rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (5.0.7.2) - activesupport (= 5.0.7.2) + actionview (5.2.8.1) + activesupport (= 5.2.8.1) builder (~> 3.1) - erubis (~> 2.7.0) + erubi (~> 1.4) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.3) - activejob (5.0.7.2) - activesupport (= 5.0.7.2) + activejob (5.2.8.1) + activesupport (= 5.2.8.1) globalid (>= 0.3.6) - activemodel (5.0.7.2) - activesupport (= 5.0.7.2) - activerecord (5.0.7.2) - activemodel (= 5.0.7.2) - activesupport (= 5.0.7.2) - arel (~> 7.0) - activesupport (5.0.7.2) + activemodel (5.2.8.1) + activesupport (= 5.2.8.1) + activerecord (5.2.8.1) + activemodel (= 5.2.8.1) + activesupport (= 5.2.8.1) + arel (>= 9.0) + activestorage (5.2.8.1) + actionpack (= 5.2.8.1) + activerecord (= 5.2.8.1) + marcel (~> 1.0.0) + activesupport (5.2.8.1) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 0.7, < 2) minitest (~> 5.1) tzinfo (~> 1.1) - acts-as-taggable-on (5.0.0) - activerecord (>= 4.2.8) + acts-as-taggable-on (6.5.0) + activerecord (>= 5.0, < 6.1) addressable (2.5.2) public_suffix (>= 2.0.2, < 4.0) - airbrussh (1.3.0) - sshkit (>= 1.6.1, != 1.7.0) - arel (7.1.4) + arel (9.0.0) autoprefixer-rails (9.4.9) execjs awesome_print (1.8.0) - bcrypt (3.1.12) + bcrypt (3.1.20) bigdecimal (1.4.4) - binding_of_caller (0.8.0) - debug_inspector (>= 0.0.1) + bindex (0.8.1) + bootsnap (1.18.3) + msgpack (~> 1.2) bootstrap-sass (3.4.1) autoprefixer-rails (>= 5.2.1) sassc (>= 2.0.0) builder (3.2.4) - byebug (9.1.0) + byebug (11.1.3) cancancan (1.17.0) - capistrano (3.9.1) - airbrussh (>= 1.0.0) - i18n - rake (>= 10.0.0) - sshkit (>= 1.9.0) - capistrano-bundler (1.3.0) - capistrano (~> 3.1) - sshkit (~> 1.2) - capistrano-rails (1.3.1) - capistrano (~> 3.1) - capistrano-bundler (~> 1.1) - capistrano-sidekiq (0.20.0) - capistrano (>= 3.9.0) - sidekiq (>= 3.4) - capistrano-upload-config (0.8.2) - capistrano (>= 3.0) capybara (2.17.0) addressable mini_mime (>= 0.1.3) @@ -88,15 +75,15 @@ GEM activesupport (>= 4.0.0) mime-types (>= 1.16) coderay (1.1.2) - coffee-rails (4.1.1) + coffee-rails (4.2.2) coffee-script (>= 2.2.0) - railties (>= 4.0.0, < 5.1.x) + railties (>= 4.0.0) coffee-script (2.4.1) coffee-script-source execjs coffee-script-source (1.12.2) - concurrent-ruby (1.2.2) - connection_pool (2.4.1) + colorize (1.1.0) + concurrent-ruby (1.2.3) countries (2.1.3) i18n_data (~> 0.8.0) money (~> 6.9) @@ -107,19 +94,23 @@ GEM sort_alphabetical (~> 1.0) crass (1.0.6) database_rewinder (0.8.2) - debug_inspector (0.0.3) - default_value_for (3.0.3) - activerecord (>= 3.2.0, < 5.2) - devise (4.6.2) + date (3.3.4) + default_value_for (3.4.0) + activerecord (>= 3.2.0, < 7.0) + devise (4.7.3) bcrypt (~> 3.0) orm_adapter (~> 0.1) - railties (>= 4.1.0, < 6.0) + railties (>= 4.1.0) responders warden (~> 1.2.3) diff-lcs (1.3) docile (1.1.5) - erubis (2.7.0) - execjs (2.7.0) + dotenv (2.8.1) + dotenv-rails (2.8.1) + dotenv (= 2.8.1) + railties (>= 3.2) + erubi (1.12.0) + execjs (2.9.1) factory_bot (5.0.2) activesupport (>= 4.2.0) factory_bot_rails (5.0.1) @@ -131,15 +122,15 @@ GEM faraday-net_http (>= 2.0, < 3.1) ruby2_keywords (>= 0.0.4) faraday-net_http (3.0.2) - ffi (1.9.25) - font-awesome-rails (4.7.0.2) - railties (>= 3.2, < 5.2) + ffi (1.16.3) + font-awesome-rails (4.7.0.8) + railties (>= 3.2, < 8.0) formatador (0.2.5) fuubar (2.3.1) rspec-core (~> 3.0) ruby-progressbar (~> 1.4) - globalid (0.4.2) - activesupport (>= 4.2.0) + globalid (1.1.0) + activesupport (>= 5.0) guard (2.14.2) formatador (>= 0.2.4) listen (>= 2.7, < 4.0) @@ -167,7 +158,7 @@ GEM thor (>= 0.14, < 2.0) jquery-ui-rails (6.0.1) railties (>= 3.2.16) - json (1.8.6) + json (2.7.1) jwt (2.7.1) launchy (2.4.3) addressable (~> 2.3) @@ -177,31 +168,47 @@ GEM rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) ruby_dep (~> 1.2) - loofah (2.21.1) + loofah (2.22.0) crass (~> 1.0.2) - nokogiri (>= 1.5.9) + nokogiri (>= 1.12.0) lumberjack (1.0.12) - mail (2.7.1) + mail (2.8.1) mini_mime (>= 0.1.1) + net-imap + net-pop + net-smtp + marcel (1.0.2) method_source (0.9.2) mime-types (3.4.1) mime-types-data (~> 3.2015) mime-types-data (3.2023.0218.1) mini_magick (4.9.4) - mini_mime (1.0.1) - mini_portile2 (2.4.0) - minitest (5.19.0) + mini_mime (1.1.5) + mini_portile2 (2.8.5) + minitest (5.22.2) money (6.10.1) i18n (>= 0.6.4, < 1.0) + moonrope-client (1.0.5) + json + msgpack (1.7.2) multi_json (1.15.0) multi_xml (0.6.0) nenv (0.3.0) - net-scp (1.2.1) - net-ssh (>= 2.6.5) - net-ssh (4.2.0) - nio4r (2.3.1) - nokogiri (1.10.10) - mini_portile2 (~> 2.4.0) + net-imap (0.4.10) + date + net-protocol + net-pop (0.1.2) + net-protocol + net-protocol (0.2.2) + timeout + net-smtp (0.4.0.1) + net-protocol + next_rails (1.0.5) + colorize (>= 0.8.1) + nio4r (2.7.0) + nokogiri (1.15.5) + mini_portile2 (~> 2.8.2) + racc (~> 1.4) notiffany (0.1.1) nenv (~> 0.1) shellany (~> 0.0) @@ -236,60 +243,62 @@ GEM orm_adapter (0.5.0) pagedown-bootstrap-rails (2.1.4) railties (> 3.1) - pg (1.5.3) + pg (1.5.4) + postal-rails (1.0.1) + postal-ruby (>= 0.0.2, < 2.0) + postal-ruby (1.0.1) + moonrope-client (>= 1.0.2, < 1.1) pry (0.11.3) coderay (~> 1.1.0) method_source (~> 0.9.0) - pry-rails (0.3.6) - pry (>= 0.10.4) public_suffix (3.0.1) puma (3.11.0) + racc (1.7.3) rack (2.2.8) - rack-protection (3.0.6) - rack - rack-test (0.6.3) - rack (>= 1.0) - rails (5.0.7.2) - actioncable (= 5.0.7.2) - actionmailer (= 5.0.7.2) - actionpack (= 5.0.7.2) - actionview (= 5.0.7.2) - activejob (= 5.0.7.2) - activemodel (= 5.0.7.2) - activerecord (= 5.0.7.2) - activesupport (= 5.0.7.2) + rack-test (2.1.0) + rack (>= 1.3) + rails (5.2.8.1) + actioncable (= 5.2.8.1) + actionmailer (= 5.2.8.1) + actionpack (= 5.2.8.1) + actionview (= 5.2.8.1) + activejob (= 5.2.8.1) + activemodel (= 5.2.8.1) + activerecord (= 5.2.8.1) + activestorage (= 5.2.8.1) + activesupport (= 5.2.8.1) bundler (>= 1.3.0) - railties (= 5.0.7.2) + railties (= 5.2.8.1) sprockets-rails (>= 2.0.0) rails-controller-testing (1.0.2) actionpack (~> 5.x, >= 5.0.1) actionview (~> 5.x, >= 5.0.1) activesupport (~> 5.x) - rails-dom-testing (2.1.1) + rails-dom-testing (2.2.0) activesupport (>= 5.0.0) minitest nokogiri (>= 1.6) - rails-html-sanitizer (1.5.0) - loofah (~> 2.19, >= 2.19.1) - railties (5.0.7.2) - actionpack (= 5.0.7.2) - activesupport (= 5.0.7.2) + rails-html-sanitizer (1.6.0) + loofah (~> 2.21) + nokogiri (~> 1.14) + railties (5.2.8.1) + actionpack (= 5.2.8.1) + activesupport (= 5.2.8.1) method_source rake (>= 0.8.7) - thor (>= 0.18.1, < 2.0) - rake (13.0.6) + thor (>= 0.19.0, < 2.0) + rake (13.1.0) ratyrate (1.2.2.alpha) rb-fsevent (0.10.3) rb-inotify (0.10.0) ffi (~> 1.0) - rdoc (4.3.0) redcarpet (3.4.0) redis (4.5.1) redis-namespace (1.6.0) redis (>= 3.0.4) - responders (2.4.1) - actionpack (>= 4.2.0, < 6.0) - railties (>= 4.2.0, < 6.0) + responders (3.1.1) + actionpack (>= 5.2) + railties (>= 5.2) rouge (2.0.7) rspec (3.7.0) rspec-core (~> 3.7.0) @@ -316,9 +325,8 @@ GEM ruby2_keywords (0.0.5) ruby_dep (1.5.0) rubyzip (1.2.2) - sassc (2.0.0) - ffi (~> 1.9.6) - rake + sassc (2.4.0) + ffi (~> 1.9) sassc-rails (2.1.0) railties (>= 4.0.0) sassc (>= 2.0) @@ -328,25 +336,13 @@ GEM scenic (1.4.1) activerecord (>= 4.0.0) railties (>= 4.0.0) - sdoc (0.4.2) - json (~> 1.7, >= 1.7.7) - rdoc (~> 4.0) settingslogic (2.0.9) shellany (0.0.1) - shoulda (3.5.0) - shoulda-context (~> 1.0, >= 1.0.1) - shoulda-matchers (>= 1.4.1, < 3.0) - shoulda-context (1.2.2) shoulda-matchers (2.8.0) activesupport (>= 3.0.0) - sidekiq (5.2.10) - connection_pool (~> 2.2, >= 2.2.2) - rack (~> 2.0) - rack-protection (>= 1.5.0) - redis (~> 4.5, < 4.6.0) - simple_form (3.5.0) - actionpack (> 4, < 5.2) - activemodel (> 4, < 5.2) + simple_form (4.1.0) + actionpack (>= 5.0) + activemodel (>= 5.0) simplecov (0.15.1) docile (~> 1.1.0) json (>= 1.8, < 3) @@ -364,36 +360,34 @@ GEM unicode_utils (>= 1.2.2) spring (2.0.2) activesupport (>= 4.2) - sprockets (3.7.2) + sprockets (4.2.1) concurrent-ruby (~> 1.0) - rack (> 1, < 3) - sprockets-rails (3.2.1) - actionpack (>= 4.0) - activesupport (>= 4.0) + rack (>= 2.2.4, < 4) + sprockets-rails (3.4.2) + actionpack (>= 5.2) + activesupport (>= 5.2) sprockets (>= 3.0.0) - sshkit (1.15.1) - net-scp (>= 1.1.2) - net-ssh (>= 2.8.0) temple (0.8.0) - thor (1.2.2) + thor (1.3.0) thread_safe (0.3.6) tilt (2.0.9) + timeout (0.4.1) tzinfo (1.2.11) thread_safe (~> 0.1) uglifier (4.1.3) execjs (>= 0.3.0, < 3) unicode_utils (1.4.0) version_gem (1.1.3) - warden (1.2.8) - rack (>= 2.0.6) - web-console (2.3.0) - activemodel (>= 4.0) - binding_of_caller (>= 0.7.2) - railties (>= 4.0) - sprockets-rails (>= 2.0, < 4.0) - websocket-driver (0.6.5) + warden (1.2.9) + rack (>= 2.0.9) + web-console (3.7.0) + actionview (>= 5.0) + activemodel (>= 5.0) + bindex (>= 0.4.0) + railties (>= 5.0) + websocket-driver (0.7.6) websocket-extensions (>= 0.1.0) - websocket-extensions (0.1.3) + websocket-extensions (0.1.5) write_xlsx (0.85.6) rubyzip (>= 1.0.0) zip-zip @@ -406,24 +400,22 @@ PLATFORMS ruby DEPENDENCIES - aasm (~> 4) - acts-as-taggable-on + aasm (~> 5) + acts-as-taggable-on (= 6.5.0) awesome_print bigdecimal (~> 1.4) + bootsnap (~> 1.18) bootstrap-sass (~> 3.4.1) byebug cancancan (~> 1.10) - capistrano (~> 3.9.0) - capistrano-rails (~> 1.1) - capistrano-sidekiq - capistrano-upload-config capybara carrierwave (~> 1) - coffee-rails (~> 4.1.0) + coffee-rails country_select database_rewinder - default_value_for (>= 3.0.2) - devise + default_value_for (~> 3.4.0) + devise (~> 4.7.0) + dotenv-rails (~> 2.8) factory_bot_rails faker ffi (>= 1.9.24) @@ -436,15 +428,16 @@ DEPENDENCIES jquery-ui-rails letter_opener mini_magick - nokogiri (~> 1.10.8) + next_rails (= 1.0.5) + nokogiri (~> 1) omniauth omniauth-github omniauth-twitter (~> 1.4) pagedown-bootstrap-rails - pg (~> 1.3) - pry-rails + pg (~> 1.0) + postal-rails (~> 1.0) puma - rails (= 5.0.7.2) + rails (= 5.2.8.1) rails-controller-testing ratyrate redcarpet @@ -453,18 +446,16 @@ DEPENDENCIES rspec-rails sassc-rails scenic - sdoc (~> 0.4.0) settingslogic - shoulda - sidekiq (~> 5) - simple_form + shoulda-matchers (~> 2.8.0) + simple_form (~> 4.1.0) simplecov slack-notifier slim spring uglifier (>= 1.3.0) unicode_utils - web-console (~> 2.0) + web-console (~> 3.0) write_xlsx BUNDLED WITH diff --git a/app/assets/config/manifest.js b/app/assets/config/manifest.js new file mode 100644 index 0000000..5cc2c08 --- /dev/null +++ b/app/assets/config/manifest.js @@ -0,0 +1,3 @@ +//= link_tree ../images +//= link_directory ../javascripts .js +//= link_directory ../stylesheets .css \ No newline at end of file diff --git a/app/models/paper.rb b/app/models/paper.rb index 23efe7a..8e10670 100644 --- a/app/models/paper.rb +++ b/app/models/paper.rb @@ -15,9 +15,14 @@ class Paper < ApplicationRecord mount_uploader :speaker_avatar, PictureUploader mount_uploader :attachement, AttachementUploader - validates :title, word: { in: Settings.paper.title.min..Settings.paper.title.max} if Settings.paper.title.limit_word - validates :abstract, word: { in: Settings.paper.abstract.min..Settings.paper.abstract.max } if Settings.paper.abstract.limit_word - validates :speaker_bio, word: { in: Settings.paper.bio.min..Settings.paper.bio.max } if Settings.paper.bio.limit_word + %i[abstract speaker_bio title].each do |attr| + define_method([attr, 'words'].join('_')) { send(attr).to_s.scan(/\w+/) } + end + + validates :title_words, length: { in: Settings.paper.title.min..Settings.paper.title.max } + validates :abstract_words, length: { in: Settings.paper.abstract.min..Settings.paper.abstract.max } + validates :speaker_bio_words, length: { in: Settings.paper.bio.min..Settings.paper.bio.max } + validates_presence_of :title validates_presence_of :abstract validates_presence_of :outline @@ -25,7 +30,7 @@ class Paper < ApplicationRecord validate :validate_proposal_expires, on: :create validates_presence_of :speaker_bio, :language - enum state: Hash[ALL_STATUS.map{|x| [x,x]}] + # enum state: Hash[ALL_STATUS.map{|x| [x,x]}] enum language: Hash[ALL_LANGUAGES.map{|x| [x,x]}] belongs_to :activity, counter_cache: true @@ -60,6 +65,10 @@ class Paper < ApplicationRecord end end + #def self.states + # aasm.states.map(&:name) + #end + after_create :notify_user default_value_for :speaker_name do |paper| @@ -123,8 +132,8 @@ def total_approve def total_disapprove reviews.where(reviewed: "disapprove").count end - private + private def notify_user PapersMailer.notification_after_create(self.id).deliver_now! diff --git a/app/validators/word_validator.rb b/app/validators/word_validator.rb deleted file mode 100644 index d81c3dc..0000000 --- a/app/validators/word_validator.rb +++ /dev/null @@ -1,26 +0,0 @@ -class WordValidator < ActiveModel::Validations::LengthValidator - def validate_each(record, attribute, value) - value = tokenize(record, value) - - words = value.nil? ? 0 : UnicodeUtils.each_word(value).count - spaces = value.nil? ? 0 : value.scan(/\p{Space}+/).size - - value_length = words - spaces - errors_options = options.except(*RESERVED_OPTIONS) - - CHECKS.each do |key, validity_check| - next unless check_value = options[key] - - if !value.nil? || skip_nil_check?(key) - next if value_length.send(validity_check, check_value) - end - - errors_options[:count] = check_value - - default_message = options[MESSAGES[key]] - errors_options[:message] ||= default_message if default_message - - record.errors.add(attribute, MESSAGES[key], errors_options) - end - end -end diff --git a/app/views/admin/activities/index.html.erb b/app/views/admin/activities/index.html.erb index 179dd66..40d4901 100644 --- a/app/views/admin/activities/index.html.erb +++ b/app/views/admin/activities/index.html.erb @@ -24,7 +24,7 @@ <%= activity.id %> <%= activity.name %> - <%= image_tag(activity.logo, height: 100, width: 100) %> + <%= image_tag(activity.logo.url, height: 100, width: 100) %> <%= activity.start_date %> ~ <%= activity.end_date %> <%= activity.papers_count %> diff --git a/app/views/admin/activities/show.html.erb b/app/views/admin/activities/show.html.erb index 46cfc5b..7c3a8ab 100644 --- a/app/views/admin/activities/show.html.erb +++ b/app/views/admin/activities/show.html.erb @@ -12,7 +12,7 @@ logo - <%= image_tag(@activity.logo, height: 100, width: 100) %> + <%= image_tag(@activity.logo_url, height: 100, width: 100) %> start date diff --git a/app/views/devise/registrations/edit.html.erb b/app/views/devise/registrations/edit.html.erb index 81a6750..88ec636 100644 --- a/app/views/devise/registrations/edit.html.erb +++ b/app/views/devise/registrations/edit.html.erb @@ -16,7 +16,7 @@ <%= f.input :country, as: :country %>
- <%= image_tag(resource.photo.small) if resource.photo.present? %> + <%= image_tag(resource.photo.small.url) if resource.photo.present? %> <%= f.input :photo, as: :file %>
diff --git a/bin/bundle b/bin/bundle index 66e9889..f19acf5 100755 --- a/bin/bundle +++ b/bin/bundle @@ -1,3 +1,3 @@ #!/usr/bin/env ruby -ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) load Gem.bin_path('bundler', 'bundle') diff --git a/bin/setup b/bin/setup index e620b4d..94fd4d7 100755 --- a/bin/setup +++ b/bin/setup @@ -1,10 +1,9 @@ #!/usr/bin/env ruby -require 'pathname' require 'fileutils' include FileUtils # path to your application root. -APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) +APP_ROOT = File.expand_path('..', __dir__) def system!(*args) system(*args) || abort("\n== Command #{args} failed ==") @@ -18,6 +17,9 @@ chdir APP_ROOT do system! 'gem install bundler --conservative' system('bundle check') || system!('bundle install') + # Install JavaScript dependencies if using Yarn + # system('bin/yarn') + # puts "\n== Copying sample files ==" # unless File.exist?('config/database.yml') # cp 'config/database.yml.sample', 'config/database.yml' diff --git a/bin/update b/bin/update deleted file mode 100755 index a8e4462..0000000 --- a/bin/update +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env ruby -require 'pathname' -require 'fileutils' -include FileUtils - -# path to your application root. -APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) - -def system!(*args) - system(*args) || abort("\n== Command #{args} failed ==") -end - -chdir APP_ROOT do - # This script is a way to update your development environment automatically. - # Add necessary update steps to this file. - - puts '== Installing dependencies ==' - system! 'gem install bundler --conservative' - system('bundle check') || system!('bundle install') - - puts "\n== Updating database ==" - system! 'bin/rails db:migrate' - - puts "\n== Removing old logs and tempfiles ==" - system! 'bin/rails log:clear tmp:clear' - - puts "\n== Restarting application server ==" - system! 'bin/rails restart' -end diff --git a/bin/yarn b/bin/yarn new file mode 100755 index 0000000..460dd56 --- /dev/null +++ b/bin/yarn @@ -0,0 +1,11 @@ +#!/usr/bin/env ruby +APP_ROOT = File.expand_path('..', __dir__) +Dir.chdir(APP_ROOT) do + begin + exec "yarnpkg", *ARGV + rescue Errno::ENOENT + $stderr.puts "Yarn executable was not detected in the system." + $stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install" + exit 1 + end +end diff --git a/config/application.rb b/config/application.rb index 2e2dc36..de9e2cb 100644 --- a/config/application.rb +++ b/config/application.rb @@ -8,12 +8,8 @@ module CfpSystem class Application < Rails::Application + config.load_defaults 5.2 config.assets.quiet = true - # Settings in config/environments/* take precedence over those specified here. - # Application configuration should go into files in config/initializers - # -- all .rb files in that directory are automatically loaded. - - config.time_zone = "Asia/Taipei" config.action_view.field_error_proc = Proc.new { |html_tag, instance| if instance.error_message.kind_of?(Array) @@ -24,8 +20,5 @@ class Application < Rails::Application html_tag << %(#{error_message}).html_safe %(
#{html_tag}
).html_safe } - - config.active_job.queue_adapter = :sidekiq - config.time_zone = 'Asia/Taipei' end end diff --git a/config/boot.rb b/config/boot.rb index 30f5120..b9e460c 100644 --- a/config/boot.rb +++ b/config/boot.rb @@ -1,3 +1,4 @@ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) require 'bundler/setup' # Set up gems listed in the Gemfile. +require 'bootsnap/setup' # Speed up boot time by caching expensive operations. diff --git a/config/cable.yml b/config/cable.yml index 0bbde6f..280e581 100644 --- a/config/cable.yml +++ b/config/cable.yml @@ -6,4 +6,5 @@ test: production: adapter: redis - url: redis://localhost:6379/1 + url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %> + channel_prefix: cfp_system_production diff --git a/config/deploy.rb b/config/deploy.rb deleted file mode 100644 index d3cb766..0000000 --- a/config/deploy.rb +++ /dev/null @@ -1,66 +0,0 @@ -# config valid only for current version of Capistrano -lock '~> 3.9.0' - -set :application, 'cfp' -set :repo_url, 'https://github.com/5xRuby/rubyconftw-cfp.git' - -# Default branch is :master -# -if ENV['USE_CURRENT_BRANCH'].to_i > 0 - set :branch, `git rev-parse --abbrev-ref HEAD`.chomp -elsif ENV.has_key?('USE_BRANCH') - set :branch, ENV['USE_BRANCH'] -else - ask :branch, `git rev-parse --abbrev-ref HEAD`.chomp -end - -# Default deploy_to directory is /var/www/my_app_name -# set :deploy_to, '/var/www/my_app_name' - -# Default value for :scm is :git -set :scm, :git - -# Default value for :format is :pretty -set :format, :pretty - -# Default value for :log_level is :debug -set :log_level, :debug - -# Default value for :pty is false -set :pty, false - -# Default value for :linked_files is [] -set :linked_files, %w{config/database.yml config/application.yml config/sidekiq.yml config/secrets.yml} -set :linked_dirs, %w{log tmp/pids tmp/cache tmp/sockets vendor/bundle public/uploads} - - -# Default value for linked_dirs is [] -# set :linked_dirs, fetch(:linked_dirs, []).push('log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle', 'public/system') - -# Default value for default_env is {} - - -# Default value for keep_releases is 5 -set :keep_releases, 3 - -set :bundle_bins, fetch(:bundle_bins, []).push('sidekiq', 'sidekiqctl') - -namespace :deploy do - desc 'Restart application' - task :restart do - on roles(:app), in: :sequence, wait: 5 do - execute :touch, release_path.join('tmp/restart.txt') - end - end - - after :restart, :clear_cache do - on roles(:web), in: :groups, limit: 3, wait: 10 do - # Here we can do anything such as: - within release_path do - execute :rake, 'tmp:clear' - end - end - end - -end -after :'deploy:publishing', :'deploy:restart' diff --git a/config/deploy/production.rb b/config/deploy/production.rb deleted file mode 100644 index 5ac2952..0000000 --- a/config/deploy/production.rb +++ /dev/null @@ -1,5 +0,0 @@ -set :default_env, { path: "/usr/local/ruby27/bin:$PATH:" } -set :deploy_to, '/home/deploy/rubyconf-cfp' -role :app, %w{deploy@do.5xruby.com} -role :web, %w{deploy@do.5xruby.com} -role :db, %w{deploy@do.5xruby.com} diff --git a/config/deploy/staging.rb b/config/deploy/staging.rb deleted file mode 100644 index c7b33ff..0000000 --- a/config/deploy/staging.rb +++ /dev/null @@ -1,5 +0,0 @@ -set :default_env, { path: "$PATH:/usr/local/ruby-2.4.1/bin:" } -set :deploy_to, '/home/deploy/rubyconf-cfp' -role :app, %w{deploy@10.128.128.153} -role :web, %w{deploy@10.128.128.153} -role :db, %w{deploy@10.128.128.153} \ No newline at end of file diff --git a/config/environment.rb b/config/environment.rb index 58c68fc..426333b 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -1,8 +1,5 @@ # Load the Rails application. require_relative 'application' -# Define new Mime type -Mime::Type.register "application/yml", :yml - # Initialize the Rails application. Rails.application.initialize! diff --git a/config/environments/development.rb b/config/environments/development.rb index 1413eb6..9538611 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -5,7 +5,6 @@ # every request. This slows down response time but is perfect for development # since you don't have to restart the web server when you make code changes. config.cache_classes = false - config.action_mailer.delivery_method = :letter_opener # Do not eager load code on boot. config.eager_load = false @@ -14,12 +13,13 @@ config.consider_all_requests_local = true # Enable/disable caching. By default caching is disabled. - if Rails.root.join('tmp/caching-dev.txt').exist? + # Run rails dev:cache to toggle caching. + if Rails.root.join('tmp', 'caching-dev.txt').exist? config.action_controller.perform_caching = true config.cache_store = :memory_store config.public_file_server.headers = { - 'Cache-Control' => 'public, max-age=172800' + 'Cache-Control' => "public, max-age=#{2.days.to_i}" } else config.action_controller.perform_caching = false @@ -27,6 +27,9 @@ config.cache_store = :null_store end + # Store uploaded files on the local file system (see config/storage.yml for options) + config.active_storage.service = :local + # Don't care if the mailer can't send. config.action_mailer.raise_delivery_errors = false @@ -38,6 +41,9 @@ # Raise an error on page load if there are pending migrations. config.active_record.migration_error = :page_load + # Highlight code that triggered database queries in logs. + config.active_record.verbose_query_logs = true + config.action_mailer.delivery_method = :letter_opener # Debug mode disables concatenation and preprocessing of assets. # This option may cause significant delays in view rendering with a large # number of complex assets. @@ -46,13 +52,10 @@ # Suppress logger output for asset requests. config.assets.quiet = true - # Source Map - config.sass.inline_source_maps = true - # Raises error for missing translations # config.action_view.raise_on_missing_translations = true # Use an evented file watcher to asynchronously detect changes in source code, # routes, locales, etc. This feature depends on the listen gem. - # config.file_watcher = ActiveSupport::EventedFileUpdateChecker + config.file_watcher = ActiveSupport::EventedFileUpdateChecker end diff --git a/config/environments/production.rb b/config/environments/production.rb index d404e18..39c5bfb 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -13,6 +13,10 @@ # Full error reports are disabled and caching is turned on. config.consider_all_requests_local = false config.action_controller.perform_caching = true + config.read_encrypted_secrets = false + # Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"] + # or in config/master.key. This key is used to decrypt credentials (and other encrypted files). + # config.require_master_key = true # Disable serving static files from the `/public` folder by default since # Apache or NGINX already handles this. @@ -34,6 +38,9 @@ # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX + # Store uploaded files on the local file system (see config/storage.yml for options) + config.active_storage.service = :local + # Mount Action Cable outside main process or domain # config.action_cable.mount_path = nil # config.action_cable.url = 'wss://example.com/cable' @@ -55,18 +62,10 @@ # Use a real queuing backend for Active Job (and separate queues per environment) # config.active_job.queue_adapter = :resque # config.active_job.queue_name_prefix = "cfp_system_#{Rails.env}" - config.action_mailer.perform_caching = false - config.action_mailer.delivery_method = :smtp - config.action_mailer.smtp_settings = { - authentication: :plain, - address: Settings.mailer.host, - :port => Settings.mailer.port, - :domain => Settings.mailer.domain, - :user_name => Settings.mailer.username, - :password => Settings.mailer.password - } + config.action_mailer.perform_caching = false + config.action_mailer.delivery_method = Settings.mailer.delivery_method.to_sym # Ignore bad email addresses and do not raise email delivery errors. # Set this to true and configure the email server for immediate delivery to raise delivery errors. # config.action_mailer.raise_delivery_errors = false @@ -88,7 +87,7 @@ if ENV["RAILS_LOG_TO_STDOUT"].present? logger = ActiveSupport::Logger.new(STDOUT) logger.formatter = config.log_formatter - config.logger = ActiveSupport::TaggedLogging.new(logger) + config.logger = ActiveSupport::TaggedLogging.new(logger) end # Do not dump schema after migrations. diff --git a/config/environments/staging.rb b/config/environments/staging.rb deleted file mode 100644 index d404e18..0000000 --- a/config/environments/staging.rb +++ /dev/null @@ -1,96 +0,0 @@ -Rails.application.configure do - # Settings specified here will take precedence over those in config/application.rb. - - # Code is not reloaded between requests. - config.cache_classes = true - - # Eager load code on boot. This eager loads most of Rails and - # your application in memory, allowing both threaded web servers - # and those relying on copy on write to perform better. - # Rake tasks automatically ignore this option for performance. - config.eager_load = true - - # Full error reports are disabled and caching is turned on. - config.consider_all_requests_local = false - config.action_controller.perform_caching = true - - # Disable serving static files from the `/public` folder by default since - # Apache or NGINX already handles this. - config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? - - # Compress JavaScripts and CSS. - config.assets.js_compressor = :uglifier - # config.assets.css_compressor = :sass - - # Do not fallback to assets pipeline if a precompiled asset is missed. - config.assets.compile = false - - # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb - - # Enable serving of images, stylesheets, and JavaScripts from an asset server. - # config.action_controller.asset_host = 'http://assets.example.com' - - # Specifies the header that your server uses for sending files. - # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache - # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX - - # Mount Action Cable outside main process or domain - # config.action_cable.mount_path = nil - # config.action_cable.url = 'wss://example.com/cable' - # config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ] - - # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. - # config.force_ssl = true - - # Use the lowest log level to ensure availability of diagnostic information - # when problems arise. - config.log_level = :debug - - # Prepend all log lines with the following tags. - config.log_tags = [ :request_id ] - - # Use a different cache store in production. - # config.cache_store = :mem_cache_store - - # Use a real queuing backend for Active Job (and separate queues per environment) - # config.active_job.queue_adapter = :resque - # config.active_job.queue_name_prefix = "cfp_system_#{Rails.env}" - config.action_mailer.perform_caching = false - - config.action_mailer.delivery_method = :smtp - config.action_mailer.smtp_settings = { - authentication: :plain, - address: Settings.mailer.host, - :port => Settings.mailer.port, - :domain => Settings.mailer.domain, - :user_name => Settings.mailer.username, - :password => Settings.mailer.password - } - - # Ignore bad email addresses and do not raise email delivery errors. - # Set this to true and configure the email server for immediate delivery to raise delivery errors. - # config.action_mailer.raise_delivery_errors = false - - # Enable locale fallbacks for I18n (makes lookups for any locale fall back to - # the I18n.default_locale when a translation cannot be found). - config.i18n.fallbacks = true - - # Send deprecation notices to registered listeners. - config.active_support.deprecation = :notify - - # Use default logging formatter so that PID and timestamp are not suppressed. - config.log_formatter = ::Logger::Formatter.new - - # Use a different logger for distributed setups. - # require 'syslog/logger' - # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') - - if ENV["RAILS_LOG_TO_STDOUT"].present? - logger = ActiveSupport::Logger.new(STDOUT) - logger.formatter = config.log_formatter - config.logger = ActiveSupport::TaggedLogging.new(logger) - end - - # Do not dump schema after migrations. - config.active_record.dump_schema_after_migration = false -end diff --git a/config/environments/test.rb b/config/environments/test.rb index 30587ef..0a38fd3 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -15,7 +15,7 @@ # Configure public file server for tests with Cache-Control for performance. config.public_file_server.enabled = true config.public_file_server.headers = { - 'Cache-Control' => 'public, max-age=3600' + 'Cache-Control' => "public, max-age=#{1.hour.to_i}" } # Show full error reports and disable caching. @@ -27,6 +27,10 @@ # Disable request forgery protection in test environment. config.action_controller.allow_forgery_protection = false + + # Store uploaded files on the local file system in a temporary directory + config.active_storage.service = :test + config.action_mailer.perform_caching = false # Tell Action Mailer not to deliver emails to the real world. diff --git a/config/initializers/application_controller_renderer.rb b/config/initializers/application_controller_renderer.rb index 51639b6..89d2efa 100644 --- a/config/initializers/application_controller_renderer.rb +++ b/config/initializers/application_controller_renderer.rb @@ -1,6 +1,8 @@ # Be sure to restart your server when you modify this file. -# ApplicationController.renderer.defaults.merge!( -# http_host: 'example.org', -# https: false -# ) +# ActiveSupport::Reloader.to_prepare do +# ApplicationController.renderer.defaults.merge!( +# http_host: 'example.org', +# https: false +# ) +# end diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb index 01ef3e6..4b828e8 100644 --- a/config/initializers/assets.rb +++ b/config/initializers/assets.rb @@ -3,9 +3,12 @@ # Version of your assets, change this if you want to expire all your assets. Rails.application.config.assets.version = '1.0' -# Add additional assets to the asset load path +# Add additional assets to the asset load path. # Rails.application.config.assets.paths << Emoji.images_path +# Add Yarn node_modules folder to the asset load path. +Rails.application.config.assets.paths << Rails.root.join('node_modules') # Precompile additional assets. -# application.js, application.css, and all non-JS/CSS in app/assets folder are already added. -# Rails.application.config.assets.precompile += %w( search.js ) +# application.js, application.css, and all non-JS/CSS in the app/assets +# folder are already added. +# Rails.application.config.assets.precompile += %w( admin.js admin.css ) diff --git a/config/initializers/content_security_policy.rb b/config/initializers/content_security_policy.rb new file mode 100644 index 0000000..d3bcaa5 --- /dev/null +++ b/config/initializers/content_security_policy.rb @@ -0,0 +1,25 @@ +# Be sure to restart your server when you modify this file. + +# Define an application-wide content security policy +# For further information see the following documentation +# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy + +# Rails.application.config.content_security_policy do |policy| +# policy.default_src :self, :https +# policy.font_src :self, :https, :data +# policy.img_src :self, :https, :data +# policy.object_src :none +# policy.script_src :self, :https +# policy.style_src :self, :https + +# # Specify URI for violation reports +# # policy.report_uri "/csp-violation-report-endpoint" +# end + +# If you are using UJS then enable automatic nonce generation +# Rails.application.config.content_security_policy_nonce_generator = -> request { SecureRandom.base64(16) } + +# Report CSP violations to a specified URI +# For further information see the following documentation: +# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy-Report-Only +# Rails.application.config.content_security_policy_report_only = true diff --git a/config/initializers/mime_types.rb b/config/initializers/mime_types.rb index edc1a71..daff587 100644 --- a/config/initializers/mime_types.rb +++ b/config/initializers/mime_types.rb @@ -2,4 +2,7 @@ # Add new mime types for use in respond_to blocks: # Mime::Type.register "text/richtext", :rtf -Mime::Type.register 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', :xlsx +Mime::Type.register 'application/yml', :yml +Mime::Type.register 'application/pdf', :pdf +Mime::Type.register "application/xls", :xls +Mime::Type.register "application/xlsx", :xlsx diff --git a/config/initializers/new_framework_defaults.rb b/config/initializers/new_framework_defaults.rb index f6e7233..dbf8263 100644 --- a/config/initializers/new_framework_defaults.rb +++ b/config/initializers/new_framework_defaults.rb @@ -20,4 +20,4 @@ Rails.application.config.active_record.belongs_to_required_by_default = false # Do not halt callback chains when a callback returns false. Previous versions had true. -ActiveSupport.halt_callback_chains_on_return_false = true +# ActiveSupport.halt_callback_chains_on_return_false = true diff --git a/config/initializers/new_framework_defaults_5_1.rb b/config/initializers/new_framework_defaults_5_1.rb new file mode 100644 index 0000000..9010abd --- /dev/null +++ b/config/initializers/new_framework_defaults_5_1.rb @@ -0,0 +1,14 @@ +# Be sure to restart your server when you modify this file. +# +# This file contains migration options to ease your Rails 5.1 upgrade. +# +# Once upgraded flip defaults one by one to migrate to the new default. +# +# Read the Guide for Upgrading Ruby on Rails for more info on each option. + +# Make `form_with` generate non-remote forms. +Rails.application.config.action_view.form_with_generates_remote_forms = false + +# Unknown asset fallback will return the path passed in when the given +# asset is not present in the asset pipeline. +# Rails.application.config.assets.unknown_asset_fallback = false diff --git a/config/initializers/new_framework_defaults_5_2.rb b/config/initializers/new_framework_defaults_5_2.rb new file mode 100644 index 0000000..c383d07 --- /dev/null +++ b/config/initializers/new_framework_defaults_5_2.rb @@ -0,0 +1,38 @@ +# Be sure to restart your server when you modify this file. +# +# This file contains migration options to ease your Rails 5.2 upgrade. +# +# Once upgraded flip defaults one by one to migrate to the new default. +# +# Read the Guide for Upgrading Ruby on Rails for more info on each option. + +# Make Active Record use stable #cache_key alongside new #cache_version method. +# This is needed for recyclable cache keys. +# Rails.application.config.active_record.cache_versioning = true + +# Use AES-256-GCM authenticated encryption for encrypted cookies. +# Also, embed cookie expiry in signed or encrypted cookies for increased security. +# +# This option is not backwards compatible with earlier Rails versions. +# It's best enabled when your entire app is migrated and stable on 5.2. +# +# Existing cookies will be converted on read then written with the new scheme. +# Rails.application.config.action_dispatch.use_authenticated_cookie_encryption = true + +# Use AES-256-GCM authenticated encryption as default cipher for encrypting messages +# instead of AES-256-CBC, when use_authenticated_message_encryption is set to true. +# Rails.application.config.active_support.use_authenticated_message_encryption = true + +# Add default protection from forgery to ActionController::Base instead of in +# ApplicationController. +# Rails.application.config.action_controller.default_protect_from_forgery = true + +# Store boolean values are in sqlite3 databases as 1 and 0 instead of 't' and +# 'f' after migrating old data. +# Rails.application.config.active_record.sqlite3.represent_boolean_as_integer = true + +# Use SHA-1 instead of MD5 to generate non-sensitive digests, such as the ETag header. +# Rails.application.config.active_support.use_sha1_digests = true + +# Make `form_with` generate id attributes for any generated HTML tags. +# Rails.application.config.action_view.form_with_generates_ids = true diff --git a/config/initializers/sidekiq.rb b/config/initializers/sidekiq.rb deleted file mode 100644 index d18babe..0000000 --- a/config/initializers/sidekiq.rb +++ /dev/null @@ -1,9 +0,0 @@ -if Settings.try(:sidekiq) - Sidekiq.configure_client do |config| - config.redis = Settings.sidekiq.symbolize_keys - end - Sidekiq.configure_server do |config| - config.redis = Settings.sidekiq.symbolize_keys - end -end - diff --git a/config/puma.rb b/config/puma.rb index c7f311f..c6dcc87 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -1,13 +1,13 @@ # Puma can serve each request in a thread from an internal thread pool. -# The `threads` method setting takes two numbers a minimum and maximum. +# The `threads` method setting takes two numbers: a minimum and maximum. # Any libraries that use thread pools should be configured to match # the maximum value specified for Puma. Default is set to 5 threads for minimum -# and maximum, this matches the default thread size of Active Record. +# and maximum; this matches the default thread size of Active Record. # -threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }.to_i +threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 } threads threads_count, threads_count -# Specifies the `port` that Puma will listen on to receive requests, default is 3000. +# Specifies the `port` that Puma will listen on to receive requests; default is 3000. # port ENV.fetch("PORT") { 3000 } @@ -15,33 +15,23 @@ # environment ENV.fetch("RAILS_ENV") { "development" } +# Specifies the `pidfile` that Puma will use. +pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" } + # Specifies the number of `workers` to boot in clustered mode. # Workers are forked webserver processes. If using threads and workers together # the concurrency of the application would be max `threads` * `workers`. # Workers do not work on JRuby or Windows (both of which do not support # processes). # -# workers ENV.fetch("WEB_CONCURRENCY") { 2 } +workers ENV.fetch("WEB_CONCURRENCY") { 2 } # Use the `preload_app!` method when specifying a `workers` number. # This directive tells Puma to first boot the application and load code # before forking the application. This takes advantage of Copy On Write -# process behavior so workers use less memory. If you use this option -# you need to make sure to reconnect any threads in the `on_worker_boot` -# block. +# process behavior so workers use less memory. # # preload_app! -# The code in the `on_worker_boot` will be called if you are using -# clustered mode by specifying a number of `workers`. After each worker -# process is booted this block will be run, if you are using `preload_app!` -# option you will want to use this block to reconnect to any threads -# or connections that may have been created at application boot, Ruby -# cannot share connections between processes. -# -# on_worker_boot do -# ActiveRecord::Base.establish_connection if defined?(ActiveRecord) -# end - # Allow puma to be restarted by `rails restart` command. plugin :tmp_restart diff --git a/db/migrate/20240212131356_add_missing_indexes_on_taggings.acts_as_taggable_on_engine.rb b/db/migrate/20240212131356_add_missing_indexes_on_taggings.acts_as_taggable_on_engine.rb new file mode 100644 index 0000000..7c39589 --- /dev/null +++ b/db/migrate/20240212131356_add_missing_indexes_on_taggings.acts_as_taggable_on_engine.rb @@ -0,0 +1,23 @@ +# This migration comes from acts_as_taggable_on_engine (originally 6) +if ActiveRecord.gem_version >= Gem::Version.new('5.0') + class AddMissingIndexesOnTaggings < ActiveRecord::Migration[4.2]; end +else + class AddMissingIndexesOnTaggings < ActiveRecord::Migration; end +end +AddMissingIndexesOnTaggings.class_eval do + def change + add_index ActsAsTaggableOn.taggings_table, :tag_id unless index_exists? ActsAsTaggableOn.taggings_table, :tag_id + add_index ActsAsTaggableOn.taggings_table, :taggable_id unless index_exists? ActsAsTaggableOn.taggings_table, :taggable_id + add_index ActsAsTaggableOn.taggings_table, :taggable_type unless index_exists? ActsAsTaggableOn.taggings_table, :taggable_type + add_index ActsAsTaggableOn.taggings_table, :tagger_id unless index_exists? ActsAsTaggableOn.taggings_table, :tagger_id + add_index ActsAsTaggableOn.taggings_table, :context unless index_exists? ActsAsTaggableOn.taggings_table, :context + + unless index_exists? ActsAsTaggableOn.taggings_table, [:tagger_id, :tagger_type] + add_index ActsAsTaggableOn.taggings_table, [:tagger_id, :tagger_type] + end + + unless index_exists? ActsAsTaggableOn.taggings_table, [:taggable_id, :taggable_type, :tagger_id, :context], name: 'taggings_idy' + add_index ActsAsTaggableOn.taggings_table, [:taggable_id, :taggable_type, :tagger_id, :context], name: 'taggings_idy' + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 9de051f..414772f 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,163 +10,163 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20170919082821) do +ActiveRecord::Schema.define(version: 2024_02_12_131356) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" - create_table "activities", force: :cascade do |t| - t.string "name" - t.text "description" - t.string "logo" - t.date "start_date" - t.date "end_date" - t.text "term" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.integer "papers_count", default: 0 + create_table "activities", id: :serial, force: :cascade do |t| + t.string "name" + t.text "description" + t.string "logo" + t.date "start_date" + t.date "end_date" + t.text "term" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.integer "papers_count", default: 0 t.datetime "open_at" t.datetime "close_at" - t.string "permalink" - t.boolean "accept_attachement" + t.string "permalink" + t.boolean "accept_attachement" end - create_table "categories", force: :cascade do |t| - t.string "name" - t.integer "activity_id" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + create_table "categories", id: :serial, force: :cascade do |t| + t.string "name" + t.integer "activity_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end - create_table "comments", force: :cascade do |t| - t.text "text" - t.integer "user_id" - t.integer "paper_id" + create_table "comments", id: :serial, force: :cascade do |t| + t.text "text" + t.integer "user_id" + t.integer "paper_id" t.datetime "created_at", null: false t.datetime "updated_at", null: false end - create_table "custom_fields", force: :cascade do |t| - t.integer "sort_order", default: 0 - t.string "name", limit: 64 - t.integer "activity_id" - t.string "field_type", limit: 48 - t.boolean "required", default: false - t.jsonb "options", default: {} - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.text "description" - t.string "collection", default: [], array: true + create_table "custom_fields", id: :serial, force: :cascade do |t| + t.integer "sort_order", default: 0 + t.string "name", limit: 64 + t.integer "activity_id" + t.string "field_type", limit: 48 + t.boolean "required", default: false + t.jsonb "options", default: {} + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.text "description" + t.string "collection", default: [], array: true end - create_table "notifiers", force: :cascade do |t| - t.integer "activity_id" - t.string "name" - t.boolean "enabled", default: true - t.boolean "on_new_comment", default: false - t.boolean "on_new_paper", default: false - t.boolean "on_paper_status_changed", default: false - t.string "service_name", default: "" - t.jsonb "service_info", default: {} - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + create_table "notifiers", id: :serial, force: :cascade do |t| + t.integer "activity_id" + t.string "name" + t.boolean "enabled", default: true + t.boolean "on_new_comment", default: false + t.boolean "on_new_paper", default: false + t.boolean "on_paper_status_changed", default: false + t.string "service_name", default: "" + t.jsonb "service_info", default: {} + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end - create_table "papers", force: :cascade do |t| - t.string "title" - t.text "abstract" - t.text "outline" - t.string "speaker_avatar" - t.string "state" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.integer "activity_id" - t.integer "user_id" - t.string "inviting_email" - t.jsonb "answer_of_custom_fields", default: {} - t.string "speaker_name" - t.string "speaker_company_or_org" - t.string "speaker_title" - t.string "speaker_country_code", limit: 8 - t.string "speaker_site" - t.text "pitch" - t.text "speaker_bio" - t.string "language", limit: 32 - t.string "uuid", limit: 8 - t.integer "reviews_count", default: 0 - t.string "attachement" - t.index ["activity_id"], name: "index_papers_on_activity_id", using: :btree - t.index ["uuid"], name: "index_papers_on_uuid", using: :btree + create_table "papers", id: :serial, force: :cascade do |t| + t.string "title" + t.text "abstract" + t.text "outline" + t.string "speaker_avatar" + t.string "state" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.integer "activity_id" + t.integer "user_id" + t.string "inviting_email" + t.jsonb "answer_of_custom_fields", default: {} + t.string "speaker_name" + t.string "speaker_company_or_org" + t.string "speaker_title" + t.string "speaker_country_code", limit: 8 + t.string "speaker_site" + t.text "pitch" + t.text "speaker_bio" + t.string "language", limit: 32 + t.string "uuid", limit: 8 + t.integer "reviews_count", default: 0 + t.string "attachement" + t.index ["activity_id"], name: "index_papers_on_activity_id" + t.index ["uuid"], name: "index_papers_on_uuid" end - create_table "reviews", force: :cascade do |t| - t.integer "user_id" - t.integer "paper_id" - t.string "reviewed", default: "pending" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.string "state" - t.index ["paper_id"], name: "index_reviews_on_paper_id", using: :btree - t.index ["user_id"], name: "index_reviews_on_user_id", using: :btree + create_table "reviews", id: :serial, force: :cascade do |t| + t.integer "user_id" + t.integer "paper_id" + t.string "reviewed", default: "pending" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "state" + t.index ["paper_id"], name: "index_reviews_on_paper_id" + t.index ["user_id"], name: "index_reviews_on_user_id" end - create_table "taggings", force: :cascade do |t| - t.integer "tag_id" - t.string "taggable_type" - t.integer "taggable_id" - t.string "tagger_type" - t.integer "tagger_id" - t.string "context", limit: 128 + create_table "taggings", id: :serial, force: :cascade do |t| + t.integer "tag_id" + t.string "taggable_type" + t.integer "taggable_id" + t.string "tagger_type" + t.integer "tagger_id" + t.string "context", limit: 128 t.datetime "created_at" - t.index ["context"], name: "index_taggings_on_context", using: :btree - t.index ["tag_id", "taggable_id", "taggable_type", "context", "tagger_id", "tagger_type"], name: "taggings_idx", unique: true, using: :btree - t.index ["tag_id"], name: "index_taggings_on_tag_id", using: :btree - t.index ["taggable_id", "taggable_type", "context"], name: "index_taggings_on_taggable_id_and_taggable_type_and_context", using: :btree - t.index ["taggable_id", "taggable_type", "tagger_id", "context"], name: "taggings_idy", using: :btree - t.index ["taggable_id"], name: "index_taggings_on_taggable_id", using: :btree - t.index ["taggable_type"], name: "index_taggings_on_taggable_type", using: :btree - t.index ["tagger_id", "tagger_type"], name: "index_taggings_on_tagger_id_and_tagger_type", using: :btree - t.index ["tagger_id"], name: "index_taggings_on_tagger_id", using: :btree + t.index ["context"], name: "index_taggings_on_context" + t.index ["tag_id", "taggable_id", "taggable_type", "context", "tagger_id", "tagger_type"], name: "taggings_idx", unique: true + t.index ["tag_id"], name: "index_taggings_on_tag_id" + t.index ["taggable_id", "taggable_type", "context"], name: "index_taggings_on_taggable_id_and_taggable_type_and_context" + t.index ["taggable_id", "taggable_type", "tagger_id", "context"], name: "taggings_idy" + t.index ["taggable_id"], name: "index_taggings_on_taggable_id" + t.index ["taggable_type"], name: "index_taggings_on_taggable_type" + t.index ["tagger_id", "tagger_type"], name: "index_taggings_on_tagger_id_and_tagger_type" + t.index ["tagger_id"], name: "index_taggings_on_tagger_id" end - create_table "tags", force: :cascade do |t| - t.string "name" + create_table "tags", id: :serial, force: :cascade do |t| + t.string "name" t.integer "taggings_count", default: 0 - t.index ["name"], name: "index_tags_on_name", unique: true, using: :btree + t.index ["name"], name: "index_tags_on_name", unique: true end - create_table "user_activity_relationships", force: :cascade do |t| - t.integer "user_id" - t.integer "activity_id" - t.boolean "is_reviewer" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + create_table "user_activity_relationships", id: :serial, force: :cascade do |t| + t.integer "user_id" + t.integer "activity_id" + t.boolean "is_reviewer" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end - create_table "users", force: :cascade do |t| - t.string "encrypted_password", default: "", null: false - t.string "email", default: "", null: false - t.string "name" - t.string "firstname" - t.string "lastname" - t.string "phone" - t.string "title" - t.string "company" - t.string "country" - t.string "photo" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.string "provider" - t.string "uid" - t.boolean "is_admin" - t.boolean "is_contributor", default: false - t.string "twitter" - t.string "github_username" - t.boolean "is_superadmin", default: false - t.index ["email"], name: "index_users_on_email", using: :btree - t.index ["is_contributor"], name: "index_users_on_is_contributor", using: :btree - t.index ["uid", "provider"], name: "index_users_on_uid_and_provider", using: :btree - t.index ["uid"], name: "index_users_on_uid", using: :btree + create_table "users", id: :serial, force: :cascade do |t| + t.string "encrypted_password", default: "", null: false + t.string "email", default: "", null: false + t.string "name" + t.string "firstname" + t.string "lastname" + t.string "phone" + t.string "title" + t.string "company" + t.string "country" + t.string "photo" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "provider" + t.string "uid" + t.boolean "is_admin" + t.boolean "is_contributor", default: false + t.string "twitter" + t.string "github_username" + t.boolean "is_superadmin", default: false + t.index ["email"], name: "index_users_on_email" + t.index ["is_contributor"], name: "index_users_on_is_contributor" + t.index ["uid", "provider"], name: "index_users_on_uid_and_provider" + t.index ["uid"], name: "index_users_on_uid" end add_foreign_key "papers", "activities" diff --git a/gitlabci/application.yml b/gitlabci/application.yml deleted file mode 100644 index f435f66..0000000 --- a/gitlabci/application.yml +++ /dev/null @@ -1,47 +0,0 @@ -defaults: &defaults - notifier: - email: - default_subject: "SUBJECTTT" - slack: - default_username: "BOT" - default_subject: "SUBJECTTTTT" - paper: - title: - limit_word: true - min: 1 - max: 100 - abstract: - limit_word: true - min: 10 - max: 601 - bio: - limit_word: true - min: 10 - max: 601 - sidekiq: - url: "redis://localhost:6379/0" - namespace: "rubyconftw-cfp-dev" - mailer: - default_from: "noreply@rubyconf.dev" - host: smtp.mailgun.org - domain: rubyconf.tw - username: postmaster@rubyconf.tw - password: 39f9d978429a3731ae1dde72bdf0e312 - port: 587 - bcc_email: - - "contact@rubyconf.dev" - github: - id: dfb842376669d5a12b19 - secret: 9ef8a60fec10a03ce46970e4c8e5cce4d973a043 - scope: 'user:email' - twitter: - id: mpss4WBNA6TPfsJSprO3IgUc7 - secret: jcKc0g7eki9HRSDUivVMAOu7Hyz48ysPPX1yESO96thgBXisBr -development: - <<: *defaults -test: - <<: *defaults -staging: - <<: *defaults -production: - <<: *defaults diff --git a/gitlabci/database.yml b/gitlabci/database.yml deleted file mode 100644 index 2a4ab4d..0000000 --- a/gitlabci/database.yml +++ /dev/null @@ -1,21 +0,0 @@ -default: &default - adapter: postgresql - -development: - <<: *default - database: cfp-dev - -test: - <<: *default - username: postgres - password: mysecretpassword - host: postgres - database: cfp-test - -staging: - <<: *default - database: cfp-staging - -production: - <<: *default - database: cfp-production \ No newline at end of file diff --git a/gitlabci/setup.sh b/gitlabci/setup.sh deleted file mode 100755 index 43f692c..0000000 --- a/gitlabci/setup.sh +++ /dev/null @@ -1,8 +0,0 @@ -apt-get install -y redis-server -service redis-server start -gem install rubygems-bundler -bundle check --path=${BUNDLE_CACHE} || bundle install --path=${BUNDLE_CACHE} --jobs=2 --retry=3 -cp gitlabci/application.yml config/application.yml -cp gitlabci/database.yml config/database.yml -bundle exec rake db:create -bundle exec rake db:migrate:reset \ No newline at end of file diff --git a/spec/controllers/admin/papers_controller_spec.rb b/spec/controllers/admin/papers_controller_spec.rb index 813281e..7bfd84d 100644 --- a/spec/controllers/admin/papers_controller_spec.rb +++ b/spec/controllers/admin/papers_controller_spec.rb @@ -9,9 +9,9 @@ expect(assigns(:papers)).to match_array papers end end - + describe "search ability in #index" do - + let(:admin) { FactoryBot.create(:user, :admin) } let(:activity) { FactoryBot.create(:activity_with_custom_field) } let(:params) { @@ -32,7 +32,7 @@ let!(:paper3) { FactoryBot.create(:paper, activity: activity) } before do - sign_in admin + sign_in admin, scope: :user end context "Commit is not 'Search'" do @@ -47,7 +47,7 @@ let(:search_field) { "__NOT_EXIST__" } it_behaves_like "do not search" end - + context "with 'equal'" do let(:search_type) { "equal" } context "when search on fixed fields" do @@ -58,7 +58,7 @@ let!(:paper3) { FactoryBot.create(:paper, activity: activity, speaker_bio: bio_2) } let(:search_field) { "speaker_bio" } let(:search_key) { bio_1 } - + it "returns matched results" do valid_papers = [paper1, paper2] get :index, params: params @@ -93,7 +93,7 @@ let!(:paper3) { FactoryBot.create(:paper, activity: activity, speaker_bio: bio_2) } let(:search_field) { "speaker_bio" } let(:search_key) { "UNIQUE_SEARCH_KEY" } - + it "returns matched results" do valid_papers = [paper1, paper2] get :index, params: params diff --git a/spec/factories/activities.rb b/spec/factories/activities.rb index e8f9854..4fb2193 100644 --- a/spec/factories/activities.rb +++ b/spec/factories/activities.rb @@ -1,5 +1,6 @@ FactoryBot.define do factory :activity do + logo { Rack::Test::UploadedFile.new(Rails.root.join('spec/fixtures/files/logo.jpg')) } sequence(:name, 2016) { |n| "RubyConfTW #{n}" } description { "RubyConfTW is a conference of ruby in Taiwan" } start_date { 1.day.ago } diff --git a/spec/fixtures/files/logo.jpg b/spec/fixtures/files/logo.jpg new file mode 100644 index 0000000..967ba6c Binary files /dev/null and b/spec/fixtures/files/logo.jpg differ diff --git a/spec/models/paper_spec.rb b/spec/models/paper_spec.rb index 7611eeb..466b97f 100644 --- a/spec/models/paper_spec.rb +++ b/spec/models/paper_spec.rb @@ -1,15 +1,6 @@ require 'rails_helper' -require 'support/matchers/should_have_validate_word_length_of' RSpec.describe Paper, type: :model do - it { should validate_word_length_of(:title).is_at_least(Settings.paper.title.min).is_at_most(Settings.paper.title.max) } - it { should validate_word_length_of(:abstract).is_at_least(Settings.paper.abstract.min).is_at_most(Settings.paper.abstract.max) } - it { should validate_word_length_of(:speaker_bio).is_at_least(Settings.paper.bio.min).is_at_most(Settings.paper.bio.max) } - - it { should validate_word_length_of(:title).include_unicode.is_at_least(Settings.paper.title.min).is_at_most(Settings.paper.title.max) } - it { should validate_word_length_of(:abstract).include_unicode.is_at_least(Settings.paper.abstract.min).is_at_most(Settings.paper.abstract.max) } - it { should validate_word_length_of(:speaker_bio).include_unicode.is_at_least(Settings.paper.bio.min).is_at_most(Settings.paper.bio.max) } - it { should validate_presence_of(:title) } it { should validate_presence_of(:abstract) } diff --git a/spec/requests/admin/admin_papers_spec.rb b/spec/requests/admin/admin_papers_spec.rb index e9c2040..7a7d5cb 100644 --- a/spec/requests/admin/admin_papers_spec.rb +++ b/spec/requests/admin/admin_papers_spec.rb @@ -168,7 +168,7 @@ it "put tab_list into values if tags already exist" do @paper.update(tag_list: %w(owo qwq)) visit admin_activity_paper_url(activity, @paper) - expect(page).to have_field('paper[tag_list]', with: "qwq, owo") + expect(page).to have_field('paper[tag_list]', with: "owo, qwq") end it "show tags on index page" do diff --git a/spec/support/matchers/should_have_validate_word_length_of.rb b/spec/support/matchers/should_have_validate_word_length_of.rb deleted file mode 100644 index 26bae21..0000000 --- a/spec/support/matchers/should_have_validate_word_length_of.rb +++ /dev/null @@ -1,23 +0,0 @@ -module Shoulda - module Matchers - module ActiveModel - - def validate_word_length_of(attr) - ValidateWordLengthOfMatcher.new(attr) - end - - class ValidateWordLengthOfMatcher < ValidateLengthOfMatcher - def include_unicode - @unicode = true - self - end - - def string_of_length(length) - return "δΈ­" * length if @unicode - (["word"] * length).join(" ") - end - end - - end - end -end