From 9d4e3d2695fe3c79ca36b5556a9219a17059f2b6 Mon Sep 17 00:00:00 2001 From: Siddarth R Date: Tue, 9 Oct 2018 13:51:42 +0530 Subject: [PATCH 1/5] Upgrading Gemfile --- Gemfile | 3 +- Gemfile.lock | 158 +++++++++++++++++++++++++++------------------------ 2 files changed, 86 insertions(+), 75 deletions(-) diff --git a/Gemfile b/Gemfile index e495e944..e8e2bc69 100755 --- a/Gemfile +++ b/Gemfile @@ -15,7 +15,7 @@ gem 'omniauth-google-oauth2' gem 'paper_trail' gem 'paranoia' gem 'puma' -gem 'rails', '4.2.10' +gem 'rails', '5.0.2' gem 'redis' gem 'rotp' gem 'ruby-saml', '1.8.0' @@ -41,6 +41,7 @@ group :development, :test do gem 'faker' gem 'mock_redis' gem 'pry' + gem 'rails-controller-testing' gem 'rspec-rails' gem 'rubocop' gem 'rubocop-rspec' diff --git a/Gemfile.lock b/Gemfile.lock index afa5f2b1..b1686c49 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -11,54 +11,58 @@ GIT GEM remote: https://rubygems.org/ specs: - actionmailer (4.2.10) - actionpack (= 4.2.10) - actionview (= 4.2.10) - activejob (= 4.2.10) + actioncable (5.0.2) + actionpack (= 5.0.2) + nio4r (>= 1.2, < 3.0) + websocket-driver (~> 0.6.1) + actionmailer (5.0.2) + actionpack (= 5.0.2) + actionview (= 5.0.2) + activejob (= 5.0.2) mail (~> 2.5, >= 2.5.4) - rails-dom-testing (~> 1.0, >= 1.0.5) - actionpack (4.2.10) - actionview (= 4.2.10) - activesupport (= 4.2.10) - rack (~> 1.6) - rack-test (~> 0.6.2) - rails-dom-testing (~> 1.0, >= 1.0.5) + rails-dom-testing (~> 2.0) + actionpack (5.0.2) + actionview (= 5.0.2) + activesupport (= 5.0.2) + rack (~> 2.0) + rack-test (~> 0.6.3) + rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (4.2.10) - activesupport (= 4.2.10) + actionview (5.0.2) + activesupport (= 5.0.2) builder (~> 3.1) erubis (~> 2.7.0) - rails-dom-testing (~> 1.0, >= 1.0.5) + rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.3) - activejob (4.2.10) - activesupport (= 4.2.10) - globalid (>= 0.3.0) - activemodel (4.2.10) - activesupport (= 4.2.10) - builder (~> 3.1) - activerecord (4.2.10) - activemodel (= 4.2.10) - activesupport (= 4.2.10) - arel (~> 6.0) - activesupport (4.2.10) + activejob (5.0.2) + activesupport (= 5.0.2) + globalid (>= 0.3.6) + activemodel (5.0.2) + activesupport (= 5.0.2) + activerecord (5.0.2) + activemodel (= 5.0.2) + activesupport (= 5.0.2) + arel (~> 7.0) + activesupport (5.0.2) + concurrent-ruby (~> 1.0, >= 1.0.2) i18n (~> 0.7) minitest (~> 5.1) - thread_safe (~> 0.3, >= 0.3.4) tzinfo (~> 1.1) addressable (2.5.2) public_suffix (>= 2.0.2, < 4.0) ansi (1.5.0) - arel (6.0.4) + arel (7.1.4) ast (2.4.0) - autoprefixer-rails (9.1.3) + autoprefixer-rails (9.1.4) execjs bcrypt (3.1.12) + bindex (0.5.0) bootstrap (4.0.0) autoprefixer-rails (>= 6.0.3) popper_js (>= 1.12.9, < 2) sass (>= 3.5.2) builder (3.2.3) - capybara (3.6.0) + capybara (3.9.0) addressable mini_mime (>= 0.1.3) nokogiri (~> 1.8) @@ -90,7 +94,6 @@ GEM safe_yaml (~> 1.0.0) crass (1.0.4) database_cleaner (1.7.0) - debug_inspector (0.0.3) devise (4.5.0) bcrypt (~> 3.0) orm_adapter (~> 0.1) @@ -101,10 +104,10 @@ GEM docile (1.3.1) erubis (2.7.0) execjs (2.7.0) - factory_bot (4.11.0) + factory_bot (4.11.1) activesupport (>= 3.0.0) - factory_bot_rails (4.11.0) - factory_bot (~> 4.11.0) + factory_bot_rails (4.11.1) + factory_bot (~> 4.11.1) railties (>= 3.0.0) faker (1.9.1) i18n (>= 0.7) @@ -145,14 +148,15 @@ GEM mini_portile2 (2.3.0) minitest (5.11.3) mock_redis (0.19.0) - money (6.12.0) - i18n (>= 0.6.4, < 1.1) + money (6.13.0) + i18n (>= 0.6.4, <= 2) multi_json (1.13.1) multi_xml (0.6.0) multipart-post (2.0.0) mysql2 (0.4.10) - newrelic_rpm (5.3.0.346) - nokogiri (1.8.4) + newrelic_rpm (5.4.0.347) + nio4r (2.3.1) + nokogiri (1.8.5) mini_portile2 (~> 2.3.0) oauth2 (1.4.0) faraday (>= 0.8, < 0.13) @@ -171,11 +175,9 @@ GEM oauth2 (~> 1.1) omniauth (~> 1.2) orm_adapter (0.5.0) - paper_trail (9.2.0) + paper_trail (10.0.1) activerecord (>= 4.2, < 5.3) - paper_trail-association_tracking (< 2) request_store (~> 1.1) - paper_trail-association_tracking (1.0.0) parallel (1.12.1) paranoia (2.4.1) activerecord (>= 4.0, < 5.3) @@ -188,31 +190,34 @@ GEM method_source (~> 0.9.0) public_suffix (3.0.3) puma (3.12.0) - rack (1.6.10) + rack (2.0.5) rack-test (0.6.3) rack (>= 1.0) - rails (4.2.10) - actionmailer (= 4.2.10) - actionpack (= 4.2.10) - actionview (= 4.2.10) - activejob (= 4.2.10) - activemodel (= 4.2.10) - activerecord (= 4.2.10) - activesupport (= 4.2.10) + rails (5.0.2) + actioncable (= 5.0.2) + actionmailer (= 5.0.2) + actionpack (= 5.0.2) + actionview (= 5.0.2) + activejob (= 5.0.2) + activemodel (= 5.0.2) + activerecord (= 5.0.2) + activesupport (= 5.0.2) bundler (>= 1.3.0, < 2.0) - railties (= 4.2.10) - sprockets-rails - rails-deprecated_sanitizer (1.0.3) - activesupport (>= 4.2.0.alpha) - rails-dom-testing (1.0.9) - activesupport (>= 4.2.0, < 5.0) - nokogiri (~> 1.6) - rails-deprecated_sanitizer (>= 1.0.1) + railties (= 5.0.2) + 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.0.3) + activesupport (>= 4.2.0) + nokogiri (>= 1.6) rails-html-sanitizer (1.0.4) loofah (~> 2.2, >= 2.2.2) - railties (4.2.10) - actionpack (= 4.2.10) - activesupport (= 4.2.10) + railties (5.0.2) + actionpack (= 5.0.2) + activesupport (= 5.0.2) + method_source rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) rainbow (3.0.0) @@ -245,7 +250,7 @@ GEM rspec-mocks (~> 3.8.0) rspec-support (~> 3.8.0) rspec-support (3.8.0) - rubocop (0.58.2) + rubocop (0.59.2) jaro_winkler (~> 1.5.1) parallel (~> 1.10) parser (>= 2.5, != 2.5.1.1) @@ -253,13 +258,13 @@ GEM rainbow (>= 2.2.2, < 4.0) ruby-progressbar (~> 1.7) unicode-display_width (~> 1.0, >= 1.0.1) - rubocop-rspec (1.28.0) + rubocop-rspec (1.30.0) rubocop (>= 0.58.0) ruby-progressbar (1.10.0) ruby-saml (1.8.0) nokogiri (>= 1.5.10) safe_yaml (1.0.4) - sass (3.5.7) + sass (3.6.0) sass-listen (~> 4.0.0) sass-listen (4.0.0) rb-fsevent (~> 0.9, >= 0.9.4) @@ -284,13 +289,13 @@ GEM simplecov simplecov-html (0.10.2) sixarm_ruby_unaccent (1.2.0) - slim (3.0.9) + slim (4.0.1) temple (>= 0.7.6, < 0.9) - tilt (>= 1.3.3, < 2.1) - slim-rails (3.1.3) + tilt (>= 2.0.6, < 2.1) + slim-rails (3.2.0) actionpack (>= 3.1) railties (>= 3.1) - slim (~> 3.0) + slim (>= 3.0, < 5.0) sprockets (3.7.2) concurrent-ruby (~> 1.0) rack (> 1, < 3) @@ -312,7 +317,7 @@ GEM turbolinks-source (5.2.0) tzinfo (1.2.5) thread_safe (~> 0.1) - uglifier (4.1.18) + uglifier (4.1.19) execjs (>= 0.3.0, < 3) unicode-display_width (1.4.0) unicode_utils (1.4.0) @@ -320,14 +325,18 @@ GEM macaddr (~> 1.0) warden (1.2.7) rack (>= 1.0) - web-console (3.3.0) - activemodel (>= 4.2) - debug_inspector - railties (>= 4.2) + web-console (3.7.0) + actionview (>= 5.0) + activemodel (>= 5.0) + bindex (>= 0.4.0) + railties (>= 5.0) webmock (3.4.2) addressable (>= 2.3.6) crack (>= 0.3.2) hashdiff + websocket-driver (0.6.5) + websocket-extensions (>= 0.1.0) + websocket-extensions (0.1.3) whenever (0.10.0) chronic (>= 0.6.3) xpath (3.1.0) @@ -359,7 +368,8 @@ DEPENDENCIES paranoia pry puma - rails (= 4.2.10) + rails (= 5.0.2) + rails-controller-testing redis rotp rspec-rails @@ -381,4 +391,4 @@ DEPENDENCIES whenever BUNDLED WITH - 1.16.4 + 1.16.6 From 9037ffdee3a64f76d828c4f382091f9e849dbe5f Mon Sep 17 00:00:00 2001 From: Siddarth R Date: Tue, 9 Oct 2018 13:52:55 +0530 Subject: [PATCH 2/5] Replace before_filter with before_action --- app/controllers/api_controller.rb | 2 +- app/controllers/api_resources_controller.rb | 2 +- app/controllers/host_machines_controller.rb | 2 +- app/controllers/nss_controller.rb | 4 ++-- app/controllers/profile_controller.rb | 4 ++-- app/controllers/users_controller.rb | 2 +- app/controllers/vpns_controller.rb | 6 +++--- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/app/controllers/api_controller.rb b/app/controllers/api_controller.rb index 845e741e..1a38c7b0 100755 --- a/app/controllers/api_controller.rb +++ b/app/controllers/api_controller.rb @@ -1,6 +1,6 @@ class ApiController < ActionController::Base protect_from_forgery with: :null_session - before_filter :authenticate_user_from_token! + before_action :authenticate_user_from_token! def authenticate_user_from_token! unless AccessToken.valid_token(get_token) diff --git a/app/controllers/api_resources_controller.rb b/app/controllers/api_resources_controller.rb index 30f0a7f8..c6f5c27b 100755 --- a/app/controllers/api_resources_controller.rb +++ b/app/controllers/api_resources_controller.rb @@ -1,6 +1,6 @@ class ApiResourcesController < ApplicationController before_action :set_api_resource, only: [:show, :edit, :update, :destroy, :regenerate_access_key] - before_filter :authenticate_user!, :except => [:authenticate] + before_action :authenticate_user!, :except => [:authenticate] # GET /api_resources # GET /api_resources.json diff --git a/app/controllers/host_machines_controller.rb b/app/controllers/host_machines_controller.rb index f546a76d..3c0f28cf 100755 --- a/app/controllers/host_machines_controller.rb +++ b/app/controllers/host_machines_controller.rb @@ -2,7 +2,7 @@ class HostMachinesController < ApplicationController before_action :set_paper_trail_whodunnit before_action :set_host_machine, only: [:add_group, :show, :edit, :update, :destroy, :delete_group] prepend_before_filter :setup_user if Rails.env.development? - before_filter :authenticate_user! + before_action :authenticate_user! def index @title = "Host" @host_machines = HostMachine.all diff --git a/app/controllers/nss_controller.rb b/app/controllers/nss_controller.rb index f9825e27..c1a0efa3 100755 --- a/app/controllers/nss_controller.rb +++ b/app/controllers/nss_controller.rb @@ -1,6 +1,6 @@ class NssController < ApplicationController - skip_before_filter :verify_authenticity_token, only: [ :add_host, :add_user_to_group ] - before_filter :authenticate_access_token!, only: %i[add_host] + skip_before_action :verify_authenticity_token, only: [ :add_host, :add_user_to_group ] + before_action :authenticate_access_token!, only: %i[add_host] def host token = AccessToken.valid_token params[:token] diff --git a/app/controllers/profile_controller.rb b/app/controllers/profile_controller.rb index 42493561..e831c633 100755 --- a/app/controllers/profile_controller.rb +++ b/app/controllers/profile_controller.rb @@ -2,8 +2,8 @@ class ProfileController < ApplicationController require 'vpn/mobileconfig' before_action :set_paper_trail_whodunnit - skip_before_filter :verify_authenticity_token, :if => Proc.new { |c| c.request.format == 'application/json' } - before_filter :authenticate_user!, :except => [:user_id, :verify, :authenticate, :authenticate_cas, :authenticate_ms_chap, :authenticate_pam, :public_key] unless Rails.env.development? + skip_before_action :verify_authenticity_token, :if => Proc.new { |c| c.request.format == 'application/json' } + before_action :authenticate_user!, :except => [:user_id, :verify, :authenticate, :authenticate_cas, :authenticate_ms_chap, :authenticate_pam, :public_key] unless Rails.env.development? prepend_before_filter :setup_user if Rails.env.development? def regen_auth diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 6cac17b5..397cc2c3 100755 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,7 +1,7 @@ class UsersController < ApplicationController before_action :set_paper_trail_whodunnit - before_filter :authenticate_user!, :except => [:user_id, :verify, :authenticate, :authenticate_cas, :authenticate_ms_chap, :authenticate_pam, :public_key] + before_action :authenticate_user!, :except => [:user_id, :verify, :authenticate, :authenticate_cas, :authenticate_ms_chap, :authenticate_pam, :public_key] def index @user_search = params[:user_search] diff --git a/app/controllers/vpns_controller.rb b/app/controllers/vpns_controller.rb index 9d798f09..295f32ff 100755 --- a/app/controllers/vpns_controller.rb +++ b/app/controllers/vpns_controller.rb @@ -7,7 +7,7 @@ class VpnsController < ApplicationController :add_supplemental_match_domain, :remove_supplemental_match_domain, \ :migrate_to_new_group, :assign_group] - before_filter :authenticate_user! + before_action :authenticate_user! require 'securerandom' @@ -19,10 +19,10 @@ def update if current_user.admin? @vpn = Vpn.find(params[:id]) if @vpn.update(vpn_params) - redirect_to vpn_path(@vpn), notice: 'Vpn was successfully updated.' + redirect_to vpn_path(@vpn), notice: 'Vpn was successfully updated.' end else - redirect_to vpn_path(@vpn), notice: 'You can not update, not sufficient privileges.' + redirect_to vpn_path(@vpn), notice: 'You can not update, not sufficient privileges.' end end From 5ddac98d8fbb9b1a67e9ab312233c891e0e1480b Mon Sep 17 00:00:00 2001 From: Siddarth R Date: Tue, 9 Oct 2018 15:49:07 +0530 Subject: [PATCH 3/5] Changed Inheritance from ActiveRecord::Base to ApplicationRecord --- app/models/access_token.rb | 2 +- app/models/api_resource.rb | 2 +- app/models/application_record.rb | 3 +++ app/models/group.rb | 4 ++-- app/models/group_admin.rb | 2 +- app/models/group_association.rb | 2 +- app/models/host.rb | 2 +- app/models/host_access_group.rb | 2 +- app/models/host_machine.rb | 2 +- app/models/ip_address.rb | 2 +- app/models/organisation.rb | 2 +- app/models/user.rb | 18 +++++++++--------- app/models/vpn.rb | 2 +- app/models/vpn_domain_name_server.rb | 2 +- app/models/vpn_group_association.rb | 2 +- app/models/vpn_group_user_association.rb | 2 +- app/models/vpn_search_domain.rb | 2 +- app/models/vpn_supplemental_match_domain.rb | 2 +- 18 files changed, 29 insertions(+), 26 deletions(-) create mode 100644 app/models/application_record.rb diff --git a/app/models/access_token.rb b/app/models/access_token.rb index 6902e104..2e305b0e 100644 --- a/app/models/access_token.rb +++ b/app/models/access_token.rb @@ -1,4 +1,4 @@ -class AccessToken < ActiveRecord::Base +class AccessToken < ApplicationRecord attr_accessor :token has_paper_trail diff --git a/app/models/api_resource.rb b/app/models/api_resource.rb index 5a163424..20d9cdcd 100755 --- a/app/models/api_resource.rb +++ b/app/models/api_resource.rb @@ -1,4 +1,4 @@ -class ApiResource < ActiveRecord::Base +class ApiResource < ApplicationRecord attr_accessor :access_key validates :name, format: { with: /\A[a-zA-Z0-9_-]+\Z/ }, uniqueness: true, presence: true diff --git a/app/models/application_record.rb b/app/models/application_record.rb new file mode 100644 index 00000000..10a4cba8 --- /dev/null +++ b/app/models/application_record.rb @@ -0,0 +1,3 @@ +class ApplicationRecord < ActiveRecord::Base + self.abstract_class = true +end diff --git a/app/models/group.rb b/app/models/group.rb index 8fc0f39a..add70747 100755 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -1,4 +1,4 @@ -class Group < ActiveRecord::Base +class Group < ApplicationRecord has_paper_trail has_many :group_admins, dependent: :destroy @@ -162,7 +162,7 @@ def self.get_default_sysadmin_group_for_host sysadmins_login_ids, default_admins group_id = group.blank? ? 8999 : group.id sysadmin_group[:gr_gid] = group_id - sysadmin_group[:gr_mem] = sysadmins.uniq + sysadmin_group[:gr_mem] = sysadmins.uniq sysadmin_group[:gr_name] = "sysadmins" sysadmin_group[:gr_passwd] = "x" return sysadmin_group diff --git a/app/models/group_admin.rb b/app/models/group_admin.rb index a11673d4..751f7c58 100644 --- a/app/models/group_admin.rb +++ b/app/models/group_admin.rb @@ -1,4 +1,4 @@ -class GroupAdmin < ActiveRecord::Base +class GroupAdmin < ApplicationRecord has_paper_trail belongs_to :user belongs_to :group diff --git a/app/models/group_association.rb b/app/models/group_association.rb index 02d60fed..c1cfb9ca 100644 --- a/app/models/group_association.rb +++ b/app/models/group_association.rb @@ -1,4 +1,4 @@ -class GroupAssociation < ActiveRecord::Base +class GroupAssociation < ApplicationRecord has_paper_trail belongs_to :user belongs_to :group diff --git a/app/models/host.rb b/app/models/host.rb index 563e38b6..ec9b5cd3 100644 --- a/app/models/host.rb +++ b/app/models/host.rb @@ -1,4 +1,4 @@ -class Host < ActiveRecord::Base +class Host < ApplicationRecord has_paper_trail belongs_to :user acts_as_paranoid diff --git a/app/models/host_access_group.rb b/app/models/host_access_group.rb index e735e1d0..6a2f4033 100644 --- a/app/models/host_access_group.rb +++ b/app/models/host_access_group.rb @@ -1,4 +1,4 @@ -class HostAccessGroup < ActiveRecord::Base +class HostAccessGroup < ApplicationRecord belongs_to :host_machine belongs_to :group end diff --git a/app/models/host_machine.rb b/app/models/host_machine.rb index 69870a72..891f7277 100755 --- a/app/models/host_machine.rb +++ b/app/models/host_machine.rb @@ -1,4 +1,4 @@ -class HostMachine < ActiveRecord::Base +class HostMachine < ApplicationRecord has_paper_trail has_many :host_access_groups diff --git a/app/models/ip_address.rb b/app/models/ip_address.rb index f2c6b07f..49f3293c 100755 --- a/app/models/ip_address.rb +++ b/app/models/ip_address.rb @@ -1,2 +1,2 @@ -class IpAddress < ActiveRecord::Base +class IpAddress < ApplicationRecord end diff --git a/app/models/organisation.rb b/app/models/organisation.rb index 6d0a400e..0fe6720b 100644 --- a/app/models/organisation.rb +++ b/app/models/organisation.rb @@ -1,4 +1,4 @@ -class Organisation < ActiveRecord::Base +class Organisation < ApplicationRecord validates :name, :website, :domain, :country, :state, :address, :admin_email_address, :slug, presence: true validates :address, format: { diff --git a/app/models/user.rb b/app/models/user.rb index 65e468b4..2d11a2c3 100755 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,4 +1,4 @@ -class User < ActiveRecord::Base +class User < ApplicationRecord has_paper_trail include MsChapAuth @@ -97,15 +97,15 @@ def name_email def self.get_sysadmins user_ids users = User. select(%Q( - id, - name, - uid, - user_login_id, + id, + name, + uid, + user_login_id, ( - SELECT gid - FROM groups - INNER JOIN group_associations - ON groups.id = group_associations.group_id + SELECT gid + FROM groups + INNER JOIN group_associations + ON groups.id = group_associations.group_id WHERE group_associations.user_id = users.id AND groups.name = users.user_login_id LIMIT 1 diff --git a/app/models/vpn.rb b/app/models/vpn.rb index 80b569a5..1de7ed0e 100755 --- a/app/models/vpn.rb +++ b/app/models/vpn.rb @@ -1,4 +1,4 @@ -class Vpn < ActiveRecord::Base +class Vpn < ApplicationRecord has_paper_trail belongs_to :user belongs_to :group diff --git a/app/models/vpn_domain_name_server.rb b/app/models/vpn_domain_name_server.rb index dde6e579..8d59c5c0 100644 --- a/app/models/vpn_domain_name_server.rb +++ b/app/models/vpn_domain_name_server.rb @@ -1,3 +1,3 @@ -class VpnDomainNameServer < ActiveRecord::Base +class VpnDomainNameServer < ApplicationRecord belongs_to :vpn end diff --git a/app/models/vpn_group_association.rb b/app/models/vpn_group_association.rb index ae339683..fb3999a5 100644 --- a/app/models/vpn_group_association.rb +++ b/app/models/vpn_group_association.rb @@ -1,4 +1,4 @@ -class VpnGroupAssociation < ActiveRecord::Base +class VpnGroupAssociation < ApplicationRecord has_paper_trail belongs_to :vpn belongs_to :group diff --git a/app/models/vpn_group_user_association.rb b/app/models/vpn_group_user_association.rb index 8dd9ed15..9bb1a5a0 100644 --- a/app/models/vpn_group_user_association.rb +++ b/app/models/vpn_group_user_association.rb @@ -1,4 +1,4 @@ -class VpnGroupUserAssociation < ActiveRecord::Base +class VpnGroupUserAssociation < ApplicationRecord has_paper_trail belongs_to :vpn belongs_to :user diff --git a/app/models/vpn_search_domain.rb b/app/models/vpn_search_domain.rb index b6f766c0..25660abb 100644 --- a/app/models/vpn_search_domain.rb +++ b/app/models/vpn_search_domain.rb @@ -1,3 +1,3 @@ -class VpnSearchDomain < ActiveRecord::Base +class VpnSearchDomain < ApplicationRecord belongs_to :vpn end diff --git a/app/models/vpn_supplemental_match_domain.rb b/app/models/vpn_supplemental_match_domain.rb index 8834ce18..32e0564e 100644 --- a/app/models/vpn_supplemental_match_domain.rb +++ b/app/models/vpn_supplemental_match_domain.rb @@ -1,3 +1,3 @@ -class VpnSupplementalMatchDomain < ActiveRecord::Base +class VpnSupplementalMatchDomain < ApplicationRecord belongs_to :vpn end From dd1e7c4b752ead7afc84bd4a0852d376f8c39493 Mon Sep 17 00:00:00 2001 From: Siddarth R Date: Tue, 9 Oct 2018 15:49:51 +0530 Subject: [PATCH 4/5] Fixed failing specs due to migration --- .../api/v1/users_controller_spec.rb | 16 ++++----- spec/controllers/api_controller_spec.rb | 4 +-- .../api_resources_controller_spec.rb | 34 +++++++++---------- spec/controllers/groups_controller_spec.rb | 2 +- .../host_machines_controller_spec.rb | 2 +- spec/controllers/nss_controller_spec.rb | 34 +++++++++---------- spec/controllers/users_controller_spec.rb | 16 ++++----- spec/controllers/vpns_controller_spec.rb | 14 ++++---- spec/models/user_spec.rb | 9 +++-- 9 files changed, 65 insertions(+), 66 deletions(-) diff --git a/spec/controllers/api/v1/users_controller_spec.rb b/spec/controllers/api/v1/users_controller_spec.rb index 4ca2ee8e..21c545bf 100755 --- a/spec/controllers/api/v1/users_controller_spec.rb +++ b/spec/controllers/api/v1/users_controller_spec.rb @@ -14,7 +14,7 @@ describe 'Authentication' do context "with valid_attributes" do it "should create users" do - post :create, {user: valid_attributes, "access_token": @token} + post :create, params: {user: valid_attributes, "access_token": @token} expect(response.status).to eq(200) user = User.where(name: valid_attributes[:name]).first expect(user.blank?).to eq(false) @@ -25,7 +25,7 @@ describe 'UnAuthentication' do it 'gives 401 when access token is in valid' do - post :create, {user: valid_attributes, "access_token": "foo"} + post :create, params: {user: valid_attributes, "access_token": "foo"} expect(response.status).to eq(401) end end @@ -39,7 +39,7 @@ public_key = rsa_key.public_key.to_pem name = "test_name" product_name = "test_product" - post :update, { "access_token" => access_token.token, 'public_key' => public_key, 'product_name' => product_name, 'name' => name, 'email' => user.email } + post :update, params: { "access_token" => access_token.token, 'public_key' => public_key, 'product_name' => product_name, 'name' => name, 'email' => user.email } expect(response.status).to eq(200) end end @@ -49,14 +49,14 @@ it 'should return 200 http status code' do group = FactoryBot.create(:group) user = FactoryBot.create(:user, name: "foo", user_login_id: "foob", email: "foo@foobar.com", reset_password_token: "test1") - get :show, { email: user.email, "access_token": @token, :format => :json } + get :show, params: { email: user.email, "access_token": @token, :format => :json } expect(response.status).to eq(200) end it 'should return the user details' do group = FactoryBot.create(:group) user = FactoryBot.create(:user, name: "foo", user_login_id: "foob", email: "foo@foobar.com", reset_password_token: "test1", product_name: "fooproduct") - get :show, { email: user.email, "access_token": @token, :format => :json } + get :show, params: { email: user.email, "access_token": @token, :format => :json } reponse_json = JSON(response.body) expect(reponse_json["product_name"]).to eq(user.product_name) end @@ -64,7 +64,7 @@ it 'should not display user secrets' do group = FactoryBot.create(:group) user = FactoryBot.create(:user, name: "foo", user_login_id: "foob", email: "foo@foobar.com", reset_password_token: "test1", product_name: "fooproduct", created_at: "2018-01-11T21:30:41.000Z", updated_at: "2018-01-11T21:30:41.000Z") - get :show, { email: user.email, "access_token": @token, :format => :json } + get :show, params: { email: user.email, "access_token": @token, :format => :json } response_json = JSON(response.body) %w( email uid name active admin home_dir shell public_key user_login_id @@ -79,7 +79,7 @@ it 'should return http status code 404' do group = FactoryBot.create(:group) user = FactoryBot.create(:user, name: "foo", user_login_id: "foob", email: "foo@foobar.com", reset_password_token: "test1", product_name: "fooproduct") - get :show, { email: "test@test.com", "access_token": @token, :format => :json } + get :show, params: { email: "test@test.com", "access_token": @token, :format => :json } expect(response.status).to eq(404) end @@ -87,7 +87,7 @@ group = FactoryBot.create(:group) user = FactoryBot.create(:user, name: "foo", user_login_id: "foob", email: "foo@foobar.com", reset_password_token: "test1", product_name: "fooproduct") - get :show, { email: "test@test.com", "access_token": "invalid_access_token" } + get :show, params: { email: "test@test.com", "access_token": "invalid_access_token" } expect(response.status).to eq(401) end diff --git a/spec/controllers/api_controller_spec.rb b/spec/controllers/api_controller_spec.rb index fae29feb..894bd03b 100644 --- a/spec/controllers/api_controller_spec.rb +++ b/spec/controllers/api_controller_spec.rb @@ -16,12 +16,12 @@ def index @token = @user.access_token.token end it 'gives 200 when access token is valid' do - get :index, access_token: @token + get :index, params: { access_token: @token } expect(response.status).to eq(200) end it 'gives 401 when access token is in valid' do - get :index, access_token: "foo" + get :index, params: { access_token: "foo" } expect(response.status).to eq(401) end end diff --git a/spec/controllers/api_resources_controller_spec.rb b/spec/controllers/api_resources_controller_spec.rb index d7e35843..6dd3ca0f 100755 --- a/spec/controllers/api_resources_controller_spec.rb +++ b/spec/controllers/api_resources_controller_spec.rb @@ -33,7 +33,7 @@ describe "GET #index" do it "returns a success response" do api_resource = ApiResource.create! valid_attributes - get :index, {}, valid_session + get :index, params: {}, session: valid_session expect(response).to be_success end end @@ -41,14 +41,14 @@ describe "GET #show" do it "returns a success response" do api_resource = ApiResource.create! valid_attributes - get :show, {:id => api_resource.to_param}, valid_session + get :show, params: {:id => api_resource.to_param}, session: valid_session expect(response).to be_success end end describe "GET #new" do it "returns a success response" do - get :new, {}, valid_session + get :new, params: {}, session: valid_session expect(response).to be_success end end @@ -56,7 +56,7 @@ describe "GET #edit" do it "returns a success response" do api_resource = ApiResource.create! valid_attributes - get :edit, {:id => api_resource.to_param}, valid_session + get :edit, params: {:id => api_resource.to_param}, session: valid_session expect(response).to be_success end end @@ -67,19 +67,19 @@ sign_in user expect { - post :create, {:api_resource => valid_attributes}, valid_session + post :create, params: {:api_resource => valid_attributes}, session: valid_session }.to change(ApiResource, :count).by(1) end it "redirects to the created api_resource" do - post :create, {:api_resource => valid_attributes}, valid_session + post :create, params: {:api_resource => valid_attributes}, session: valid_session expect(response).to redirect_to(api_resource_path(assigns[:api_resource])) end end context "with invalid params" do it "returns a success response (i.e. to display the 'new' template)" do - post :create, {:api_resource => invalid_attributes}, valid_session + post :create, params: {:api_resource => invalid_attributes}, session: valid_session expect(response).to be_success end end @@ -93,14 +93,14 @@ it "updates the requested api_resource" do api_resource = ApiResource.create! valid_attributes - put :update, {:id => api_resource.to_param, :api_resource => new_attributes}, valid_session + put :update, params: {:id => api_resource.to_param, :api_resource => new_attributes}, session: valid_session api_resource.reload expect(api_resource.name).to eq("new_name") end it "redirects to the api_resource" do api_resource = ApiResource.create! valid_attributes - put :update, {:id => api_resource.to_param, :api_resource => valid_attributes}, valid_session + put :update, params: {:id => api_resource.to_param, :api_resource => valid_attributes}, session: valid_session expect(response).to redirect_to(api_resources_url) end end @@ -108,7 +108,7 @@ context "with invalid params" do it "returns a success response (i.e. to display the 'edit' template)" do api_resource = ApiResource.create! valid_attributes - put :update, {:id => api_resource.to_param, :api_resource => invalid_attributes}, valid_session + put :update, params: {:id => api_resource.to_param, :api_resource => invalid_attributes}, session: valid_session expect(response).to be_success end end @@ -118,13 +118,13 @@ it "destroys the requested api_resource" do api_resource = ApiResource.create! valid_attributes expect { - delete :destroy, {:id => api_resource.to_param}, valid_session + delete :destroy, params: {:id => api_resource.to_param}, session: valid_session }.to change(ApiResource, :count).by(-1) end it "redirects to the api_resources list" do api_resource = ApiResource.create! valid_attributes - delete :destroy, {:id => api_resource.to_param}, valid_session + delete :destroy, params: {:id => api_resource.to_param}, session: valid_session expect(response).to redirect_to(api_resources_url) end end @@ -132,7 +132,7 @@ describe 'Search for API Resources' do it "should return API Resources according to supplied search string" do api_resources = create_list(:api_resource, 3) - get :search, { q: "API" } + get :search, params: { q: "API" } expect(JSON.parse(response.body)).to eq(api_resources.map{|m| {"id" => m.id, "name" => m.name}}) end end @@ -141,14 +141,14 @@ it "regenerates access_key of the requested api_resource" do api_resource = ApiResource.create! valid_attributes old_hashed_access_key = api_resource.hashed_access_key - get :regenerate_access_key, {:id => api_resource.to_param}, valid_session + get :regenerate_access_key, params: {:id => api_resource.to_param}, session: valid_session api_resource.reload expect(api_resource.hashed_access_key).to_not eq old_hashed_access_key end it "redirects to the api_resource" do api_resource = ApiResource.create! valid_attributes - get :regenerate_access_key, {:id => api_resource.to_param} + get :regenerate_access_key, params: {:id => api_resource.to_param} expect(response).to redirect_to(api_resource_path(api_resource.id)) end end @@ -164,7 +164,7 @@ api_resource = ApiResource.create! valid_attributes api_resource.group = group api_resource.save! - get :authenticate, { access_key: valid_attributes[:access_key], access_token: access_token.token }, valid_session + get :authenticate, params: { access_key: valid_attributes[:access_key], access_token: access_token.token }, session: valid_session expect(response).not_to be_success body = JSON.parse(response.body) expect(body["result"]).to eq 1 @@ -181,7 +181,7 @@ api_resource.group = group group.users << user api_resource.save! - get :authenticate, { access_key: valid_attributes[:access_key], access_token: access_token.token }, valid_session + get :authenticate, params: { access_key: valid_attributes[:access_key], access_token: access_token.token }, session: valid_session expect(response).to be_success body = JSON.parse(response.body) expect(body["result"]).to eq 0 diff --git a/spec/controllers/groups_controller_spec.rb b/spec/controllers/groups_controller_spec.rb index 6b0755f1..c5c69453 100644 --- a/spec/controllers/groups_controller_spec.rb +++ b/spec/controllers/groups_controller_spec.rb @@ -7,7 +7,7 @@ it "should return groups according to supplied search string" do sign_in user groups = create_list(:group, 3) - get :search, { q: "People" } + get :search, params: { q: "People" } expect(JSON.parse(response.body)).to eq(groups.map{|m| {"id" => m.id, "name" => m.name}}) end end diff --git a/spec/controllers/host_machines_controller_spec.rb b/spec/controllers/host_machines_controller_spec.rb index 46610aba..d6f63f63 100644 --- a/spec/controllers/host_machines_controller_spec.rb +++ b/spec/controllers/host_machines_controller_spec.rb @@ -7,7 +7,7 @@ it "should return hosts according to supplied search string" do sign_in user host_machines = create_list(:host_machine, 3) - get :search, { q: "host" } + get :search, params: { q: "host" } expect(JSON.parse(response.body)).to eq(host_machines.map{|m| {"id" => m.id, "name" => m.name}}) end end diff --git a/spec/controllers/nss_controller_spec.rb b/spec/controllers/nss_controller_spec.rb index 15867139..432031c4 100755 --- a/spec/controllers/nss_controller_spec.rb +++ b/spec/controllers/nss_controller_spec.rb @@ -10,14 +10,14 @@ end it "should return false for invalid token" do - get :groups_list, token: access_token, email: email + get :groups_list, params: { token: access_token, email: email } data = JSON.parse(response.body) expect(data["success"]).to eq(false) end it "should return false for not registered email" do create(:access_token, token: access_token) - get :groups_list, token: access_token, email: email + get :groups_list, params: { token: access_token, email: email } data = JSON.parse(response.body) expect(data["success"]).to eq(false) end @@ -25,14 +25,14 @@ it "should return group list for registered email" do create(:access_token, token: access_token) user_test = create(:user, email: email) - get :groups_list, token: access_token, email: email + get :groups_list, params: { token: access_token, email: email } data = JSON.parse(response.body) expect(data["success"]).to eq(true) end it 'should not return sysadmins for invalid token' do json = { token: '', name: 'random_host', group_name: '', format: :json } - post 'add_host', json + post 'add_host', params: json body = response.body expect(JSON.parse(body)['success']).to eq(false) end @@ -41,13 +41,13 @@ create(:access_token, token: access_token) json = { token: access_token, name: 'random_host', group_name: 'duplicate_group', format: :json } - post 'add_host', json + post 'add_host', params: json body = response.body expect(JSON.parse(body)['success']).to eq(true) expect(JSON.parse(body)['groups'].count).to eq 2 json = { token: access_token, name: 'random_host', group_name: 'duplicate_group', format: :json } - post 'add_host', json + post 'add_host', params: json body = response.body expect(JSON.parse(body)['success']).to eq(true) expect(JSON.parse(body)['groups'].count).to eq 2 @@ -57,7 +57,7 @@ sign_in user access_token = create(:access_token) json = { token: access_token.token, name: "random_host_01" } - post "add_host", { token: access_token.token, name: "random_host_01", group_name: "random_group_01", format: :json} + post "add_host", params: { token: access_token.token, name: "random_host_01", group_name: "random_group_01", format: :json} body = response.body access_key = JSON.parse(body)["access_key"] @@ -80,14 +80,14 @@ group.reload expect(host.sysadmins.count).to eq 2 - get "host", { token: access_key, format: json } + get "host", params: { token: access_key, format: json } body = JSON.parse(response.body) expect(body.count).to eq 3 expect(body[2]["gr_mem"].count).to eq 2 - get "group", { token: access_key, format: json } + get "group", params: { token: access_key, format: json } body = JSON.parse(response.body) expect(body.count).to eq 3 @@ -107,13 +107,13 @@ user = create(:user) user.groups << group - post "add_host", { token: access_token.token, name: "random_host_01", group_name: "random_group_01", format: :json} + post "add_host", params: { token: access_token.token, name: "random_host_01", group_name: "random_group_01", format: :json} host = HostMachine.first expect(host.name).to eq "random_host_01" host.groups << group - get "group", { token: host.access_key, format: :json } + get "group", params: { token: host.access_key, format: :json } body = JSON.parse(response.body) expect(body.count).to eq 2 @@ -136,13 +136,13 @@ user_2 = create(:user) user_2.groups << group - post "add_host", { token: access_token.token, name: "random_host_01", group_name: "random_group_01", default_admins: false, format: :json} + post "add_host", params: { token: access_token.token, name: "random_host_01", group_name: "random_group_01", default_admins: false, format: :json} host = HostMachine.first expect(host.name).to eq "random_host_01" host.groups << group_2 - get "group", { token: host.access_key, format: :json } + get "group", params: { token: host.access_key, format: :json } body = JSON.parse(response.body) expect(body.count).to eq 2 @@ -162,7 +162,7 @@ user = create(:user) user.groups << group - post "add_host", { token: access_token.token, name: "random_host_01", group_name: "random_group_01", format: :json} + post "add_host", params: { token: access_token.token, name: "random_host_01", group_name: "random_group_01", format: :json} host = HostMachine.first expect(host.name).to eq "random_host_01" host.groups << group @@ -172,10 +172,10 @@ user.reload - get "passwd", { token: host.access_key, format: :json } + get "passwd", params: { token: host.access_key, format: :json } body = JSON.parse(response.body) expect(body.count).to eq 1 - get "passwd", { token: host.access_key, format: :json } + get "passwd", params: { token: host.access_key, format: :json } body = JSON.parse(response.body) expect(body.count).to eq 1 end @@ -194,7 +194,7 @@ cache_count_bfr = REDIS_CACHE.keys("UG*").count - get "group", { token: host_machine.access_key, format: :json } + get "group", params: { token: host_machine.access_key, format: :json } cache_count_aft = REDIS_CACHE.keys("UG*").count expect(cache_count_aft).to eq cache_count_bfr + 1 diff --git a/spec/controllers/users_controller_spec.rb b/spec/controllers/users_controller_spec.rb index 40a6427b..95ade399 100755 --- a/spec/controllers/users_controller_spec.rb +++ b/spec/controllers/users_controller_spec.rb @@ -9,7 +9,7 @@ it "should update profile with product name" do sign_in user - patch :update, id: user.id, product_name: product_name + patch :update, params: { id: user.id, product_name: product_name } user.reload expect(user.product_name).to eq(product_name) @@ -18,7 +18,7 @@ it "should return 302" do sign_in user - patch :update, id: user.id, product_name: product_name + patch :update, params: { id: user.id, product_name: product_name } expect(response).to have_http_status(302) end @@ -26,7 +26,7 @@ it "should redirect to same page once the profile is updated" do sign_in user - patch :update, id: user.id, product_name: product_name + patch :update, params: { id: user.id, product_name: product_name } expect(response).to redirect_to(user_path) end @@ -35,7 +35,7 @@ it "should return params missing message on flash" do sign_in user - patch :update, id: user.id + patch :update, params: { id: user.id } expect(flash[:notice]).to eq("Params are missing") end @@ -47,7 +47,7 @@ sign_in user users = create_list(:user, 3) users.last.update(active: false) - get :search, { q: users.first.name } + get :search, params: { q: users.first.name } returned_ids = JSON.parse(response.body).collect{|c| c['id']} expect(returned_ids).to eq([users.first.id]) end @@ -56,7 +56,7 @@ sign_in user users = create_list(:user, 3) users.last.update(active: false) - get :search, { q: users.last.name, include_inactive: 'true' } + get :search, params: { q: users.last.name, include_inactive: 'true' } returned_ids = JSON.parse(response.body).collect{|c| c['id']} expect(returned_ids).to eq([users.last.id]) end @@ -74,13 +74,13 @@ it "regenerates access token of the requested user" do old_hashed_token = user.access_token.hashed_token - get :regenerate_token, {:id => user.to_param} + get :regenerate_token, params: {:id => user.to_param} user.reload expect(user.access_token.hashed_token).to_not eq old_hashed_token end it "redirects to the user" do - get :regenerate_token, {:id => user.to_param} + get :regenerate_token, params: {:id => user.to_param} expect(response).to redirect_to(user_path(user.id)) end end diff --git a/spec/controllers/vpns_controller_spec.rb b/spec/controllers/vpns_controller_spec.rb index 603ec8ab..32146ee7 100755 --- a/spec/controllers/vpns_controller_spec.rb +++ b/spec/controllers/vpns_controller_spec.rb @@ -43,22 +43,22 @@ @vpn01 = Vpn.create(name: "z") - post :add_dns_server, { id: @vpn01.id, server_address: '1.1.1.1'} + post :add_dns_server, params: { id: @vpn01.id, server_address: '1.1.1.1'} expect(@vpn01.vpn_domain_name_servers.count).to eq(1) - post :remove_dns_server, { id: @vpn01.id, vpn_domain_name_server_id: @vpn01.vpn_domain_name_servers.first.id} + post :remove_dns_server, params: { id: @vpn01.id, vpn_domain_name_server_id: @vpn01.vpn_domain_name_servers.first.id} expect(@vpn01.vpn_domain_name_servers.count).to eq(0) - post :add_search_domain, { id: @vpn01.id, search_domain: 'xyz.com'} + post :add_search_domain, params: { id: @vpn01.id, search_domain: 'xyz.com'} expect(@vpn01.vpn_search_domains.count).to eq(1) - post :remove_search_domain, { id: @vpn01.id, vpn_search_domain_id: @vpn01.vpn_search_domains.first.id} + post :remove_search_domain, params: { id: @vpn01.id, vpn_search_domain_id: @vpn01.vpn_search_domains.first.id} expect(@vpn01.vpn_search_domains.count).to eq(0) - post :add_supplemental_match_domain, { id: @vpn01.id, supplemental_match_domain: 'abc.co.id'} + post :add_supplemental_match_domain, params: { id: @vpn01.id, supplemental_match_domain: 'abc.co.id'} expect(@vpn01.vpn_supplemental_match_domains.count).to eq(1) - post :remove_supplemental_match_domain, { id: @vpn01.id, vpn_supplemental_match_domain_id: @vpn01.vpn_supplemental_match_domains.first.id} + post :remove_supplemental_match_domain, params: { id: @vpn01.id, vpn_supplemental_match_domain_id: @vpn01.vpn_supplemental_match_domains.first.id} expect(@vpn01.vpn_supplemental_match_domains.count).to eq(0) end @@ -68,7 +68,7 @@ it "should return vpns according to supplied search string" do sign_in user vpns = create_list(:vpn, 3) - get :search, { q: "VPN" } + get :search, params: { q: "VPN" } expect(JSON.parse(response.body)).to eq(vpns.map{|m| {"id" => m.id, "name" => m.name}}) end end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 991fd102..089d0bce 100755 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -222,15 +222,14 @@ end it 'should update the deactivated_at date if user is made inactive' do - create(:user, admin: true) - Timecop.freeze - user.update_profile(active: false) - expect(user.deactivated_at).to eq(Time.current) + Timecop.freeze(Time.current) + inactive_user = create(:user, admin: true) + inactive_user.update_profile(active: false) + expect(inactive_user.deactivated_at.to_s).to eq(Time.current.to_s) end it 'shouldn\'t make the admin user a normal user if its only single admin user' do user.update_profile(active: false) - p user.errors.messages expect(user.errors.messages.key?(:admin)).to eq(true) expect(user.valid?).to eq(false) end From cdebe75081d8ae8a16e3f6dfdf4d87cf8334152b Mon Sep 17 00:00:00 2001 From: Siddarth R Date: Tue, 9 Oct 2018 15:50:33 +0530 Subject: [PATCH 5/5] Comitting configuration for Migration --- bin/rails | 2 +- bin/setup | 29 +++++++----- bin/update | 29 ++++++++++++ config/application.rb | 16 ++----- config/cable.yml | 9 ++++ config/environment.rb | 2 +- config/environments/development.rb | 47 ++++++++++++------- config/environments/production.rb | 37 +++++++-------- config/environments/test.rb | 12 ++--- .../application_controller_renderer.rb | 6 +++ config/initializers/assets.rb | 1 + config/initializers/cookies_serializer.rb | 2 + config/initializers/new_framework_defaults.rb | 23 +++++++++ config/initializers/paper_trail.rb | 1 - config/initializers/wrap_parameters.rb | 4 +- config/puma.rb | 47 +++++++++++++++++++ config/secrets.yml | 10 ++-- config/spring.rb | 6 +++ 18 files changed, 203 insertions(+), 80 deletions(-) create mode 100755 bin/update create mode 100644 config/cable.yml create mode 100644 config/initializers/application_controller_renderer.rb create mode 100644 config/initializers/new_framework_defaults.rb delete mode 100644 config/initializers/paper_trail.rb create mode 100644 config/puma.rb create mode 100644 config/spring.rb diff --git a/bin/rails b/bin/rails index 5191e692..07396602 100755 --- a/bin/rails +++ b/bin/rails @@ -1,4 +1,4 @@ #!/usr/bin/env ruby -APP_PATH = File.expand_path('../../config/application', __FILE__) +APP_PATH = File.expand_path('../config/application', __dir__) require_relative '../config/boot' require 'rails/commands' diff --git a/bin/setup b/bin/setup index acdb2c13..e620b4da 100755 --- a/bin/setup +++ b/bin/setup @@ -1,29 +1,34 @@ #!/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 = Pathname.new File.expand_path('../../', __FILE__) -Dir.chdir APP_ROOT do +def system!(*args) + system(*args) || abort("\n== Command #{args} failed ==") +end + +chdir APP_ROOT do # This script is a starting point to setup your application. - # Add necessary setup steps to this file: + # Add necessary setup steps to this file. - puts "== Installing dependencies ==" - system "gem install bundler --conservative" - system "bundle check || bundle install" + puts '== Installing dependencies ==' + system! 'gem install bundler --conservative' + system('bundle check') || system!('bundle install') # puts "\n== Copying sample files ==" - # unless File.exist?("config/database.yml") - # system "cp config/database.yml.sample config/database.yml" + # unless File.exist?('config/database.yml') + # cp 'config/database.yml.sample', 'config/database.yml' # end puts "\n== Preparing database ==" - system "bin/rake db:setup" + system! 'bin/rails db:setup' puts "\n== Removing old logs and tempfiles ==" - system "rm -f log/*" - system "rm -rf tmp/cache" + system! 'bin/rails log:clear tmp:clear' puts "\n== Restarting application server ==" - system "touch tmp/restart.txt" + system! 'bin/rails restart' end diff --git a/bin/update b/bin/update new file mode 100755 index 00000000..a8e4462f --- /dev/null +++ b/bin/update @@ -0,0 +1,29 @@ +#!/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/config/application.rb b/config/application.rb index 1ef50d8c..b93cf838 100644 --- a/config/application.rb +++ b/config/application.rb @@ -1,4 +1,4 @@ -require File.expand_path('../boot', __FILE__) +require_relative 'boot' require 'rails/all' @@ -11,18 +11,8 @@ class Application < Rails::Application # 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. - - # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. - # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. - # config.time_zone = 'Central Time (US & Canada)' - - # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. - # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] - # config.i18n.default_locale = :de - - # Do not swallow errors in after_commit/after_rollback callbacks. config.autoload_paths += %W["#{config.root}/app/validators/"] - config.active_record.raise_in_transactional_callbacks = true - Mime::Type.register "application/x-apple-aspen-config", :mobileconfig + # config.active_record.raise_in_transactional_callbacks = true + Mime::Type.register 'application/x-apple-aspen-config', :mobileconfig end end diff --git a/config/cable.yml b/config/cable.yml new file mode 100644 index 00000000..0bbde6f7 --- /dev/null +++ b/config/cable.yml @@ -0,0 +1,9 @@ +development: + adapter: async + +test: + adapter: async + +production: + adapter: redis + url: redis://localhost:6379/1 diff --git a/config/environment.rb b/config/environment.rb index ee8d90dc..426333bb 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -1,5 +1,5 @@ # Load the Rails application. -require File.expand_path('../application', __FILE__) +require_relative 'application' # Initialize the Rails application. Rails.application.initialize! diff --git a/config/environments/development.rb b/config/environments/development.rb index aaef5a6f..aeee1220 100755 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -1,10 +1,11 @@ -ActiveSupport::Dependencies.autoload_paths << File::join( Rails.root, 'lib') -ActiveSupport::Dependencies.explicitly_unloadable_constants << '' - Rails.application.configure do + OmniAuth.config.full_host = Figaro.env.GATE_SERVER_URL + config.consider_all_requests_local = true + config.action_controller.perform_caching = false + Slim::Engine.set_options pretty: true, sort_attrs: false + # Settings specified here will take precedence over those in config/application.rb. - OmniAuth.config.full_host = Figaro.env.GATE_SERVER_URL # In the development environment your application's code is reloaded on # 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. @@ -13,13 +14,28 @@ # Do not eager load code on boot. config.eager_load = false - # Show full error reports and disable caching. - config.consider_all_requests_local = true - config.action_controller.perform_caching = false + # Show full error reports. + config.consider_all_requests_local = true + + # Enable/disable caching. By default caching is disabled. + 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' + } + else + config.action_controller.perform_caching = false + + config.cache_store = :null_store + end # Don't care if the mailer can't send. config.action_mailer.raise_delivery_errors = false + config.action_mailer.perform_caching = false + # Print deprecation notices to the Rails logger. config.active_support.deprecation = :log @@ -31,18 +47,13 @@ # number of complex assets. config.assets.debug = true - # Asset digests allow you to set far-future HTTP expiration dates on all assets, - # yet still be able to expire them through the digest params. - config.assets.digest = true - - # Adds additional error checking when serving assets at runtime. - # Checks for improperly declared sprockets dependencies. - # Raises helpful error messages. - config.assets.raise_runtime_errors = true + # Suppress logger output for asset requests. + config.assets.quiet = true # Raises error for missing translations # config.action_view.raise_on_missing_translations = true - # - #Prettify HTML - Slim::Engine.set_options pretty: true, sort_attrs: false + + # 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 end diff --git a/config/environments/production.rb b/config/environments/production.rb index ab0bd621..0117f68f 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -14,15 +14,9 @@ config.consider_all_requests_local = false config.action_controller.perform_caching = true - # Enable Rack::Cache to put a simple HTTP cache in front of your application - # Add `rack-cache` to your Gemfile before enabling this. - # For large-scale production use, consider using a caching reverse proxy like - # NGINX, varnish or squid. - # config.action_dispatch.rack_cache = true - # Disable serving static files from the `/public` folder by default since # Apache or NGINX already handles this. - config.serve_static_files = Figaro.env.RAILS_SERVE_STATIC_FILES.present? + config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? # Compress JavaScripts and CSS. config.assets.js_compressor = :uglifier @@ -31,16 +25,20 @@ # Do not fallback to assets pipeline if a precompiled asset is missed. config.assets.compile = false - # Asset digests allow you to set far-future HTTP expiration dates on all assets, - # yet still be able to expire them through the digest params. - config.assets.digest = true - # `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 @@ -49,16 +47,15 @@ config.log_level = :error # Prepend all log lines with the following tags. - # config.log_tags = [ :subdomain, :uuid ] - - # Use a different logger for distributed setups. - # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new) + config.log_tags = [ :request_id ] # Use a different cache store in production. # config.cache_store = :mem_cache_store - # Enable serving of images, stylesheets, and JavaScripts from an asset server. - # config.action_controller.asset_host = 'http://assets.example.com' + # 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 = "gate_#{Rails.env}" + config.action_mailer.perform_caching = false # 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. @@ -74,9 +71,11 @@ # Use default logging formatter so that PID and timestamp are not suppressed. config.log_formatter = ::Logger::Formatter.new - # Enable option to log into STDOUT + # 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? - STDOUT.sync = true logger = ActiveSupport::Logger.new(STDOUT) logger.formatter = config.log_formatter config.logger = ActiveSupport::TaggedLogging.new(logger) diff --git a/config/environments/test.rb b/config/environments/test.rb index 1c19f08b..30587ef6 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -12,9 +12,11 @@ # preloads Rails for running tests, you may have to set it to true. config.eager_load = false - # Configure static file server for tests with Cache-Control for performance. - config.serve_static_files = true - config.static_cache_control = 'public, max-age=3600' + # 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' + } # Show full error reports and disable caching. config.consider_all_requests_local = true @@ -25,15 +27,13 @@ # Disable request forgery protection in test environment. config.action_controller.allow_forgery_protection = false + config.action_mailer.perform_caching = false # Tell Action Mailer not to deliver emails to the real world. # The :test delivery method accumulates sent emails in the # ActionMailer::Base.deliveries array. config.action_mailer.delivery_method = :test - # Randomize the order test cases are executed. - config.active_support.test_order = :random - # Print deprecation notices to the stderr. config.active_support.deprecation = :stderr diff --git a/config/initializers/application_controller_renderer.rb b/config/initializers/application_controller_renderer.rb new file mode 100644 index 00000000..51639b67 --- /dev/null +++ b/config/initializers/application_controller_renderer.rb @@ -0,0 +1,6 @@ +# Be sure to restart your server when you modify this file. + +# ApplicationController.renderer.defaults.merge!( +# http_host: 'example.org', +# https: false +# ) diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb index b723ab22..4f2f993b 100644 --- a/config/initializers/assets.rb +++ b/config/initializers/assets.rb @@ -9,3 +9,4 @@ # 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( profile.css general.css ) +# Rails.application.config.assets.precompile += %w( search.js ) diff --git a/config/initializers/cookies_serializer.rb b/config/initializers/cookies_serializer.rb index 7f70458d..5a6a32d3 100644 --- a/config/initializers/cookies_serializer.rb +++ b/config/initializers/cookies_serializer.rb @@ -1,3 +1,5 @@ # Be sure to restart your server when you modify this file. +# Specify a serializer for the signed and encrypted cookie jars. +# Valid options are :json, :marshal, and :hybrid. Rails.application.config.action_dispatch.cookies_serializer = :json diff --git a/config/initializers/new_framework_defaults.rb b/config/initializers/new_framework_defaults.rb new file mode 100644 index 00000000..f6e72335 --- /dev/null +++ b/config/initializers/new_framework_defaults.rb @@ -0,0 +1,23 @@ +# Be sure to restart your server when you modify this file. +# +# This file contains migration options to ease your Rails 5.0 upgrade. +# +# Once upgraded flip defaults one by one to migrate to the new default. +# +# Read the Rails 5.0 release notes for more info on each option. + +# Enable per-form CSRF tokens. Previous versions had false. +Rails.application.config.action_controller.per_form_csrf_tokens = false + +# Enable origin-checking CSRF mitigation. Previous versions had false. +Rails.application.config.action_controller.forgery_protection_origin_check = false + +# Make Ruby 2.4 preserve the timezone of the receiver when calling `to_time`. +# Previous versions had false. +ActiveSupport.to_time_preserves_timezone = false + +# Require `belongs_to` associations by default. Previous versions had false. +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 diff --git a/config/initializers/paper_trail.rb b/config/initializers/paper_trail.rb deleted file mode 100644 index 442b5f78..00000000 --- a/config/initializers/paper_trail.rb +++ /dev/null @@ -1 +0,0 @@ -PaperTrail.config.track_associations = false \ No newline at end of file diff --git a/config/initializers/wrap_parameters.rb b/config/initializers/wrap_parameters.rb index 33725e95..bbfc3961 100644 --- a/config/initializers/wrap_parameters.rb +++ b/config/initializers/wrap_parameters.rb @@ -5,10 +5,10 @@ # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. ActiveSupport.on_load(:action_controller) do - wrap_parameters format: [:json] if respond_to?(:wrap_parameters) + wrap_parameters format: [:json] end # To enable root element in JSON for ActiveRecord objects. # ActiveSupport.on_load(:active_record) do -# self.include_root_in_json = true +# self.include_root_in_json = true # end diff --git a/config/puma.rb b/config/puma.rb new file mode 100644 index 00000000..c7f311f8 --- /dev/null +++ b/config/puma.rb @@ -0,0 +1,47 @@ +# Puma can serve each request in a thread from an internal thread pool. +# 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. +# +threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }.to_i +threads threads_count, threads_count + +# Specifies the `port` that Puma will listen on to receive requests, default is 3000. +# +port ENV.fetch("PORT") { 3000 } + +# Specifies the `environment` that Puma will run in. +# +environment ENV.fetch("RAILS_ENV") { "development" } + +# 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 } + +# 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. +# +# 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/config/secrets.yml b/config/secrets.yml index 4730edfc..856c0be1 100644 --- a/config/secrets.yml +++ b/config/secrets.yml @@ -5,21 +5,17 @@ # Make sure the secret is at least 30 characters and all random, # no regular words or you'll be exposed to dictionary attacks. -# You can use `rake secret` to generate a secure secret key. +# You can use `rails secret` to generate a secure secret key. # Make sure the secrets in this file are kept private # if you're sharing your code publicly. development: - secret_key_base: 1d062c94f87003dd375df72bd54f29b451c07584217c15b7c029778f507d5511cb66f0de00c516925c3688b9a552888c09cf86b02551f58daf1181b37c8cfcb8 - secret_api_key: my_secret + secret_key_base: 6a4735f30c7ab8c09019b80cbfd60ba2ead1d1c6b2c60632522602f002460d4590741f9e6713b89e67fd298bd155ff4f5d2f010a09c19388b0a209bb4841a2f8 test: - secret_key_base: 8e83b8e5bcd4c4fc8b44e9bf49e5d30c5d98938a4e14866a0ca173ea501a703302e4d1bf09b9c52a6533e549cf8f2149f3153f2e6b4b5b615a9a721b83980c79 - secret_api_key: my_secret + secret_key_base: b575eb4f653d58f0b666df115bc91026211573c0224a516e0e20d8b2817d268df6183dd4a028a38780c7b5846e255af900de9319e395cc3e004a387fadb99555 -# Do not keep production secrets in the repository, -# instead read values from the environment. integration: secret_key_base: <%= Figaro.env.SECRET_KEY_BASE %> secret_api_key: <%= Figaro.env.SECRET_API_KEY %> diff --git a/config/spring.rb b/config/spring.rb new file mode 100644 index 00000000..c9119b40 --- /dev/null +++ b/config/spring.rb @@ -0,0 +1,6 @@ +%w( + .ruby-version + .rbenv-vars + tmp/restart.txt + tmp/caching-dev.txt +).each { |path| Spring.watch(path) }