Some preparations for rails 5.1

update some gems, replace before_filter / after_filter by before_action / after_action
and some more config changes (mostly commented out) and scripts generated by rails app:update task
This commit is contained in:
dgt 2018-08-25 18:48:12 +02:00 committed by Azul
parent dba6c2d9eb
commit 939fa3d1d1
76 changed files with 211 additions and 149 deletions

11
Gemfile
View File

@ -11,6 +11,7 @@ end
##
# Rails is the framework we use.
#gem 'rails', '~> 5.1.6'
gem 'rails', '~> 5.0.7'
# Security updates
@ -30,7 +31,7 @@ gem 'i18n', '~> 0.7'
# improved gem to access mysql database
# locking in to latest major to fix API
gem 'mysql2', '~> 0.3.18'
gem 'mysql2', '~> 0.5.2'
# parsing and generating JSON
# locking in to latest major to fix API
@ -38,8 +39,8 @@ gem 'json', '~> 1.8'
# Markup language that uses indent to indicate nesting
# locking in to latest major to fix API
gem 'haml', '~> 4.0'
gem 'haml-rails', '~> 0.9.0'
gem 'haml', '~> 5.0'
gem 'haml-rails', '~> 1.0'
# Extendet scriptable CSS language
# locking in to latest major to fix API
@ -56,6 +57,7 @@ gem 'sass'
# tests do not pass
#gem 'prototype-rails', github: 'rails/prototype-rails', branch: '4.2'
gem 'prototype-rails', path: 'vendor/gems/prototype-rails'
#gem 'prototype-rails', path: '/home/dora/Dev/crabgrass_project/2018/august/prototype-rails-5-1'
# Full text search for the database
gem 'thinking-sphinx', '~> 3.4.2'
@ -150,6 +152,9 @@ gem 'greencloth', require: 'greencloth',
# version is rather strict for now as api may still change.
gem 'crabgrass_media', '~> 0.3.0', require: 'media',
path: 'vendor/gems/crabgrass-media'
#gem 'crabgrass_media', '~> 0.4.0', require: 'media',
# path: '/home/dora/Dev/crabgrass_project/crabgrass-media'
##
## not required, but a really good idea

View File

@ -106,12 +106,13 @@ GEM
activesupport (>= 4.2.0)
gpgme (2.0.16)
mini_portile2 (~> 2.3)
haml (4.0.7)
haml (5.0.4)
temple (>= 0.8.0)
tilt
haml-rails (0.9.0)
haml-rails (1.0.0)
actionpack (>= 4.0.1)
activesupport (>= 4.0.1)
haml (>= 4.0.6, < 5.0)
haml (>= 4.0.6, < 6.0)
html2haml (>= 1.0.1)
railties (>= 4.0.1)
html2haml (2.1.0)
@ -143,7 +144,7 @@ GEM
mini_mime (1.0.1)
mini_portile2 (2.3.0)
minitest (5.10.3)
mysql2 (0.3.21)
mysql2 (0.5.2)
nio4r (2.3.1)
nokogiri (1.8.5)
mini_portile2 (~> 2.3.0)
@ -219,6 +220,7 @@ GEM
sqlite3 (1.3.13)
sys-uname (0.9.0)
ffi (>= 1.0.0)
temple (0.8.0)
therubyracer (0.12.3)
libv8 (~> 3.16.14.15)
ref
@ -274,8 +276,8 @@ DEPENDENCIES
factory_bot_rails
faker (~> 1.0.0)
greencloth!
haml (~> 4.0)
haml-rails (~> 0.9.0)
haml (~> 5.0)
haml-rails (~> 1.0)
http_accept_language (~> 2.0)
i18n (~> 0.7)
json (~> 1.8)
@ -283,7 +285,7 @@ DEPENDENCIES
mail-gpg (~> 0.3.3)
mime-types
minitest (~> 5.10.3)
mysql2 (~> 0.3.18)
mysql2 (~> 0.5.2)
nokogiri (~> 1.8.5)
phantomjs-binaries (~> 2.1.1)
poltergeist (~> 1.5)

View File

@ -1,8 +1,8 @@
class AssetsController < ApplicationController
before_filter :symlink_public_asset, only: :show
before_action :symlink_public_asset, only: :show
after_action :verify_authorized
prepend_before_filter :fetch_asset, only: %i[show destroy]
prepend_before_action :fetch_asset, only: %i[show destroy]
def show
authorize @asset

View File

@ -71,7 +71,7 @@ module Common::Application::Authentication
session[:return_to] = nil
end
# When called with before_filter :login_from_cookie will check for an :auth_token
# When called with before_action :login_from_cookie will check for an :auth_token
# cookie and log the user back in if apropriate
def login_from_cookie
return unless cookies[:auth_token] && !logged_in?
@ -85,7 +85,7 @@ module Common::Application::Authentication
end
# note: this method is not automatically called. if you want to enable HTTP
# authentication for some action(s), you must put a prepend_before_filter in
# authentication for some action(s), you must put a prepend_before_action in
# place.
# however, a user who successfully uses HTTP auth on an action for which it
# was enabled will stay logged in and can then go and see other things.

View File

@ -14,10 +14,10 @@ module Common::Application::BeforeFilters
included do
# the order of these filters matters. change with caution.
before_filter :set_session_locale
before_filter :set_session_timezone
before_filter :header_hack_for_ie6
before_filter :redirect_unverified_user
before_action :set_session_locale
before_action :set_session_timezone
before_action :header_hack_for_ie6
before_action :redirect_unverified_user
end
private
@ -48,11 +48,11 @@ module Common::Application::BeforeFilters
#
# To not require logins for specific actions, use this in your controllers:
#
# skip_before_filter :login_required, :only => [ :view, :index ]
# skip_before_action :login_required, :only => [ :view, :index ]
#
# To not require them for any action:
#
# skip_before_filter :login_required
# skip_before_action :login_required
#
def login_required
process_login

View File

@ -217,7 +217,7 @@ module Common::Application::RescueErrors
def render_error_js(exception = nil, options = {})
error exception if exception.present?
log_exception(exception)
return if performed? # error in after_filter
return if performed? # error in after_action
render template: 'error/alert', locals: { exception: exception },
status: options[:status]
end

View File

@ -1,5 +1,5 @@
#
# controllers including this must have a before_filter setup()
# controllers including this must have a before_action setup()
# which must set @entity and @success_url
#

View File

@ -12,10 +12,10 @@ module Common::Requests
helper_method :current_state
helper_method :request_path
helper_method :requests_path
before_filter :fetch_request, only: %i[update destroy show]
before_action :fetch_request, only: %i[update destroy show]
after_filter :create_notices, only: :create
after_filter :dismiss_notices, only: :update
after_action :create_notices, only: :create
after_action :dismiss_notices, only: :update
end
#

View File

@ -4,7 +4,7 @@
#
# This module makes creating the records from the controller easy.
#
# If you follow the conventions all you need to do is add a after_filter for
# If you follow the conventions all you need to do is add a after_action for
# the actions you want to track:
#
# class Groups::GroupsController < ...
@ -12,7 +12,7 @@
# ...
#
# This will have the same effect as an after filter for track_action:
# after_filter :track_action, only: [:create, :destroy]
# after_action :track_action, only: [:create, :destroy]
#
# track_action will call Action.track(:create_group, options). It will include
# the following default arguments if the corresponding variables are set:
@ -54,7 +54,7 @@ module Common::Tracking::Action
module ClassMethods
def track_actions(*actions)
options = actions.extract_options!
after_filter :track_action, options.merge(only: actions)
after_action :track_action, options.merge(only: actions)
end
end
end

View File

@ -9,7 +9,7 @@
#
class CronController < ActionController::Base
before_filter :allow_only_requests_from_localhost
before_action :allow_only_requests_from_localhost
def run
case params[:id]

View File

@ -1,6 +1,6 @@
if Rails.env.development?
class DebugController < ApplicationController
before_filter :authorization_required
before_action :authorization_required
# make the user assume the identity of another user
def become

View File

@ -13,7 +13,7 @@
#
class EntitiesController < ApplicationController
before_filter :login_required
before_action :login_required
LIMIT = 20

View File

@ -1,7 +1,7 @@
class Group::AvatarsController < Group::BaseController
include_controllers 'common/avatars'
include_controllers 'common/always_perform_caching'
before_filter :setup
before_action :setup
protected

View File

@ -1,8 +1,8 @@
class Group::BaseController < ApplicationController
before_filter :fetch_group
before_action :fetch_group
# default permission for all group controllers
before_filter :login_required
before_action :login_required
after_action :verify_authorized
helper 'group/links'

View File

@ -1,12 +1,12 @@
class Group::DirectoryController < ApplicationController
before_filter :login_required
# skip_before_filter :login_required
before_action :login_required
# skip_before_action :login_required
# ^^ for now, disable public directories. The old behavior was to require
# authentication to browse the directory, so we don't want to change this
# unexpectedly without either giving groups some warning or adding an
# additional level to the permissions.
before_filter :set_default_path
before_action :set_default_path
helper 'group/directory'

View File

@ -1,11 +1,11 @@
class Group::GroupsController < Group::BaseController
include Common::Tracking::Action
before_filter :initialize_group, only: %w[new create]
before_filter :fetch_group, only: :destroy
before_filter :fetch_associations, only: :destroy
before_action :initialize_group, only: %w[new create]
before_action :fetch_group, only: :destroy
before_action :fetch_associations, only: :destroy
after_filter :notify_former_users, only: :destroy
after_action :notify_former_users, only: :destroy
def new

View File

@ -1,8 +1,8 @@
class Group::HomeController < Group::BaseController
skip_before_filter :login_required
skip_before_action :login_required
before_filter :fetch_wikis
after_filter :track_visit, if: :logged_in?
before_action :fetch_wikis
after_action :track_visit, if: :logged_in?
layout 'sidecolumn'
helper 'wikis/base', 'wikis/sections'

View File

@ -1,5 +1,5 @@
class Group::PagesController < Group::BaseController
skip_before_filter :login_required
skip_before_action :login_required
include_controllers 'common/page_search'

View File

@ -1,5 +1,5 @@
class Group::ProfilesController < Group::BaseController
before_filter :fetch_profile
before_action :fetch_profile
helper :profile
def edit

View File

@ -1,7 +1,7 @@
class Me::AvatarsController < Me::BaseController
include_controllers 'common/avatars'
include_controllers 'common/always_perform_caching'
before_filter :setup
before_action :setup
def destroy
if avatar = @entity.avatar

View File

@ -2,7 +2,7 @@
# Abstract super class of all the Me controllers.
#
class Me::BaseController < ApplicationController
before_filter :login_required, :fetch_user
before_action :login_required, :fetch_user
protected

View File

@ -1,5 +1,5 @@
class Me::NoticesController < Me::BaseController
before_filter :fetch_notice, only: %i[destroy]
before_action :fetch_notice, only: %i[destroy]
def index
@notices = Notice.for_user(current_user)

View File

@ -5,7 +5,7 @@
class Me::PostsController < Me::BaseController
include_controllers 'common/posts'
prepend_before_filter :fetch_data
prepend_before_action :fetch_data
after_action :verify_authorized
# /me/discussions/green/posts

View File

@ -1,5 +1,5 @@
class Me::ProfileController < Me::BaseController
before_filter :fetch_profile
before_action :fetch_profile
helper :profile
def edit; end

View File

@ -5,7 +5,7 @@
#
class Page::AttributesController < Page::SidebarsController
before_filter :login_required
before_action :login_required
track_actions :update
def update

View File

@ -5,8 +5,8 @@
class Page::BaseController < ApplicationController
public
before_filter :login_required, except: :show
before_filter :bust_cache, only: :show
before_action :login_required, except: :show
before_action :bust_cache, only: :show
after_action :verify_authorized
layout 'page'
@ -18,16 +18,16 @@ class Page::BaseController < ApplicationController
## (the order matters!)
##
prepend_before_filter :default_fetch_data, except: :new
prepend_before_action :default_fetch_data, except: :new
append_before_filter :default_setup_options
append_before_filter :load_posts
append_before_action :default_setup_options
append_before_action :load_posts
# after_filters are processed the inside out.
# after_actions are processed the inside out.
# So whatever is defined first will be processed last
# ... after all the others
after_filter :save_if_needed, except: :create
after_filter :update_viewed, only: :show
after_action :save_if_needed, except: :create
after_action :update_viewed, only: :show
include Page::BeforeFilters

View File

@ -15,8 +15,8 @@
class Page::CreateController < ApplicationController
include Common::Tracking::Action
before_filter :login_required
before_filter :init_options, :set_owner, :catch_cancel
before_action :login_required
before_action :init_options, :set_owner, :catch_cancel
after_action :verify_authorized, only: :create
helper 'page/share', 'page/owner', 'page/creation'
track_actions :create

View File

@ -1,5 +1,5 @@
class Page::HistoryController < Page::SidebarsController
before_filter :login_required
before_action :login_required
def show
authorize @page, :update?

View File

@ -11,7 +11,7 @@
class Page::ParticipationsController < Page::SidebarsController
helper 'page/participation', 'page/share'
before_filter :fetch_data
before_action :fetch_data
track_actions :update
# this is used for ajax pagination

View File

@ -5,8 +5,8 @@ class Page::PostsController < ApplicationController
helper 'page/post'
prepend_before_filter :fetch_data
before_filter :login_required, except: :show
prepend_before_action :fetch_data
before_action :login_required, except: :show
after_action :verify_authorized
track_actions :create, :update, :destroy

View File

@ -25,8 +25,8 @@
class Page::SharesController < Page::SidebarsController
helper 'page/share', 'page/participation'
before_filter :close_popup, only: :update, if: :cancel_update?
before_filter :add_recipients, only: :update, if: :add_recipients?
before_action :close_popup, only: :update, if: :cancel_update?
before_action :add_recipients, only: :update, if: :add_recipients?
track_actions :update
# display the share or notify forms.
@ -44,9 +44,9 @@ class Page::SharesController < Page::SidebarsController
# there are four ways to submit the forms:
#
# (1) cancel button (params[:cancel]==true)
# -> before_filter :close_popup
# -> before_action :close_popup
# (2) add button or return in add field (params[:add]==true)
# -> before_filter :add_recipients
# -> before_action :add_recipients
# (3) share button (params[:share_button]==true)
# (3) notify button (params[:notify_button]==true)
#

View File

@ -5,9 +5,9 @@
class Page::SidebarsController < ApplicationController
include Common::Tracking::Action
before_filter :fetch_page
before_filter :login_required
after_filter :verify_authorized
before_action :fetch_page
before_action :login_required
after_action :verify_authorized
layout false
helper 'page/base', 'page/sidebar'

View File

@ -1,5 +1,5 @@
class Page::TagsController < Page::SidebarsController
before_filter :authorize_page
before_action :authorize_page
helper 'page/tags'
SUGGESTION_COUNT = 6

View File

@ -1,5 +1,5 @@
class Person::BaseController < ApplicationController
before_filter :fetch_person
before_action :fetch_person
after_action :verify_authorized
helper 'people/base'

View File

@ -1,11 +1,11 @@
class Person::DirectoryController < ApplicationController
before_filter :login_required
before_action :login_required
# ^^ for now, disable public directories. The old behavior was to require
# authentication to browse the directory, so we don't want to change this
# unexpectedly without either giving people some warning or adding an
# additional level to the permissions.
before_filter :prepare_path
before_action :prepare_path
def index
@query ||= finder.query_term

View File

@ -1,5 +1,5 @@
class Person::FriendRequestsController < Person::BaseController
before_filter :login_required
before_action :login_required
def new
@request = RequestToFriend.new recipient: @user, created_by: current_user

View File

@ -6,7 +6,7 @@
#
class PicturesController < ApplicationController
before_filter :fetch_picture
before_action :fetch_picture
#
# for now, all pictures are public.

View File

@ -4,7 +4,7 @@
class SessionController < ApplicationController
layout 'notice'
skip_before_filter :redirect_unverified_user
skip_before_action :redirect_unverified_user
def login
return unless request.post?

View File

@ -23,7 +23,7 @@
class StarsController < ApplicationController
include Common::Tracking::Action
before_filter :fetch_starred
before_action :fetch_starred
track_actions :create
def create
@ -43,7 +43,7 @@ class StarsController < ApplicationController
@starred = Post.find(params[:post_id])
@star = @starred.stars.where(user_id: current_user).first
# Prevent sending notifcation if the action will result in a noop.
# redirects in a before filter skip the action and after_filters.
# redirects in a before filter skip the action and after_actions.
redirect_to @starred if @star.blank? && action?(:destroy)
redirect_to @starred if @star.present? && action?(:create)
end

View File

@ -35,7 +35,7 @@ class ThemeController < ApplicationController
# don't cache css if '_refresh' is in the theme or stylesheet name.
# useful for debugging.
prepend_before_filter :get_theme
prepend_before_action :get_theme
def get_theme
self.cache_css = true
[params[:name], *params[:file]].each do |param|

View File

@ -1,5 +1,5 @@
class Wiki::AssetsController < Wiki::BaseController
before_filter :fetch_assets, only: :new
before_action :fetch_assets, only: :new
def new
# FIXME: Authorize needed because BaseController wants us to

View File

@ -1,6 +1,6 @@
class Wiki::BaseController < ApplicationController
before_filter :fetch_wiki
before_filter :login_required
before_action :fetch_wiki
before_action :login_required
after_action :verify_authorized
helper 'wikis/base'

View File

@ -8,7 +8,7 @@
class Wiki::WikisController < Wiki::BaseController
include Common::Tracking::Action
skip_before_filter :login_required, only: :show
skip_before_action :login_required, only: :show
track_actions :update
helper 'wikis/sections'

View File

@ -39,7 +39,7 @@
# The needed user_participation and group_partication objects will get saved
# unless page is modified, in which case they will not get saved.
# (assuming that page.save will get called eventually, which will then save
# the new participation objects. BasePageController has an after_filter that
# the new participation objects. BasePageController has an after_action that
# auto saves the @page if has been changed.)
#

View File

@ -136,7 +136,7 @@ module User::Pages
# should trigger a notification to page watchers. Also, if a page state changes
# from pending to resolved, we also update everyone's user participation.
# The page is not saved here, because it might still get more changes.
# An after_filter should finally save the page if it has not already been saved.
# An after_action should finally save the page if it has not already been saved.
#
# options:
# :resolved -- user's participation is resolved with this page

View File

@ -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'

View File

@ -1,29 +1,38 @@
#!/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') || system!('bundle install')
# Install JavaScript dependencies if using Yarn
# system('bin/yarn')
puts "== Installing dependencies =="
system "gem install bundler --conservative"
system "bundle check || 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

View File

@ -16,6 +16,8 @@ module Crabgrass
class Application < Rails::Application
info 'LOAD CONFIG BLOCK'
# config.load_defaults 5.1
config.autoload_paths << "#{Rails.root}/lib"
config.autoload_paths << "#{Rails.root}/app/models"

View File

@ -1,6 +1,3 @@
require 'rubygems'
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
# Set up gems listed in the Gemfile.
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
require 'bundler/setup' # Set up gems listed in the Gemfile.

View File

@ -1,5 +1,5 @@
# Load the rails application
require File.expand_path('../application', __FILE__)
require_relative 'application'
# Initialize the rails application
Crabgrass::Application.initialize!

View File

@ -36,4 +36,29 @@ Crabgrass::Application.configure do
##
require "#{Rails.root}/lib/crabgrass/debug.rb"
# FIXME: the following additional options were suggested by
# rails app:update for Rails 5.1
# Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log
# Raise an error on page load if there are pending migrations.
config.active_record.migration_error = :page_load
# Debug mode disables concatenation and preprocessing of assets.
# This option may cause significant delays in view rendering with a large
# Suppress logger output for asset requests.
config.assets.quiet = 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
end

View File

@ -45,4 +45,24 @@ Crabgrass::Application.configure do
##
require "crabgrass/debug.rb"
# additional config from rails app:update task to Rails 5.1
config.public_file_server.headers = {
'Cache-Control' => "public, max-age=#{1.hour.seconds.to_i}"
}
config.action_mailer.perform_caching = false
##
## DEBUGGING
## See doc/DEBUGGING for tips.
##
# Print deprecation notices to the stderr.
#config.active_support.deprecation = :stderr
# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true
end

View File

@ -1,5 +1,3 @@
# frozen_string_literal: true
# Be sure to restart your server when you modify this file.
# ActiveSupport::Reloader.to_prepare do

View File

@ -9,3 +9,11 @@ Rails.application.config.assets.precompile += ['icon_png.css']
# optional styles for ie6 and ie7 - poorly ported from 0.5
# Rails.application.config.assets.precompile += ['ie6.css', 'ie7.css']
#
## Stylesheets
# 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
# FIXME: Check if we have any!
Rails.application.config.assets.paths << Rails.root.join('node_modules')

View File

@ -1,5 +1,3 @@
# frozen_string_literal: true
# Be sure to restart your server when you modify this file.
# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
# 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 = :marshal
Rails.application.config.action_dispatch.cookies_serializer = :json

View File

@ -1,5 +1,3 @@
# frozen_string_literal: true
# Be sure to restart your server when you modify this file.
# Configure sensitive parameters which will be filtered from the log file.

View File

@ -1,15 +1,16 @@
# Be sure to restart your server when you modify this file.
# Add new inflection rules using the following format
# (all these examples are active by default):
# ActiveSupport::Inflector.inflections do |inflect|
# Add new inflection rules using the following format. Inflections
# are locale specific, and you may define rules for as many different
# locales as you wish. All of these examples are active by default:
# ActiveSupport::Inflector.inflections(:en) do |inflect|
# inflect.plural /^(ox)$/i, '\1en'
# inflect.singular /^(ox)en/i, '\1'
# inflect.irregular 'person', 'people'
# inflect.uncountable %w( fish sheep )
# end
#
# These inflection rules are supported but not enabled by default:
# ActiveSupport::Inflector.inflections do |inflect|
# ActiveSupport::Inflector.inflections(:en) do |inflect|
# inflect.acronym 'RESTful'
# end

View File

@ -2,4 +2,3 @@
# Add new mime types for use in respond_to blocks:
# Mime::Type.register "text/richtext", :rtf
# Mime::Type.register_alias "text/html", :iphone

View File

@ -1,7 +1,7 @@
```
class RobotsController < ApplicationController
before_filter :login_required # if you want to require logins
before_action :login_required # if you want to require logins
after_action :verify_authorized # ensures authorization happened
def create

View File

@ -2,7 +2,7 @@
class RobotsController < ApplicationController
before_filter :login_required # if you want to require logins
before_action :login_required # if you want to require logins
permissions :robots # will load app/permissions/robots_permissions.rb
permissions 'robots/cyborgs' # app/permissions/robots/cyborgs_permissions.rb
@ -221,7 +221,7 @@ the permission check happens.
Manual approach
--------------------
before_filter :fetch_robot, :login_required
before_action :fetch_robot, :login_required
permissions :robots
protected
@ -248,7 +248,7 @@ Automatic approach
in app/controllers/robots_controller.rb:
before_filter :fetch_robot, :login_required
before_action :fetch_robot, :login_required
permissions :robots
def show

View File

@ -1,5 +1,5 @@
class AssetPageController < Page::BaseController
# before_filter :fetch_asset
# before_action :fetch_asset
def show
redirect_to page_url(@page, action: 'new') if @asset.nil?

View File

@ -1,5 +1,5 @@
class CreateAssetPageController < Page::CreateController
before_filter :ensure_asset, only: :create
before_action :ensure_asset, only: :create
def new
@form_sections.unshift('file')

View File

@ -2,7 +2,7 @@ class GalleryImageController < Page::BaseController
helper 'gallery'
# default_fetch_data is disabled for new in Pages::BaseController
prepend_before_filter :fetch_page_for_new, only: :new
prepend_before_action :fetch_page_for_new, only: :new
def show
authorize @page

View File

@ -1,6 +1,6 @@
class RankedVotePageController < Page::BaseController
before_filter :fetch_poll
before_filter :find_possibles, only: %i[show edit]
before_action :fetch_poll
before_action :find_possibles, only: %i[show edit]
def show
authorize @page

View File

@ -1,6 +1,6 @@
class RankedVotePossiblesController < Page::BaseController
before_filter :fetch_poll
before_filter :fetch_possible, only: %i[edit update destroy]
before_action :fetch_poll
before_action :fetch_possible, only: %i[edit update destroy]
# returns nothing
# for this to work, there must be a <ul id='sort_list_xxx'> element

View File

@ -1,5 +1,5 @@
class RateManyPageController < Page::BaseController
before_filter :fetch_poll
before_action :fetch_poll
def show
@possibles = @poll ? @poll.possibles.sort_by { |p| p.position || 0 } : []

View File

@ -1,5 +1,5 @@
class RateManyPossiblesController < Page::BaseController
before_filter :fetch_poll
before_action :fetch_poll
# ajax only, returns nothing
# for this to work, there must be a <ul id='sort_list_xxx'> element

View File

@ -1,6 +1,6 @@
class TaskListPageController < Page::BaseController
before_filter :fetch_user_participation
before_filter :setup_second_nav
before_action :fetch_user_participation
before_action :setup_second_nav
def show
authorize @page

View File

@ -1,7 +1,7 @@
class TasksController < Page::BaseController
before_filter :fetch_task, only: %i[edit update destroy]
before_filter :setup_second_nav
after_filter :update_participations, only: %i[create update destroy]
before_action :fetch_task, only: %i[edit update destroy]
before_action :setup_second_nav
after_action :update_participations, only: %i[create update destroy]
def create
@task = @page.tasks.new task_params.merge created_by: current_user

View File

@ -1,6 +1,6 @@
class WikiPageController < Page::BaseController
helper 'wikis/base', 'wikis/sections'
before_filter :find_last_seen, only: :show
before_action :find_last_seen, only: :show
def show
if default_to_edit?

View File

@ -46,7 +46,7 @@ class IntegrationTest < ActionDispatch::IntegrationTest
# Page::Terms live in an MyIsam table
# so they do not get cleaned up by transactional fixtures.
def reload_page_terms
return unless self.class.use_transactional_fixtures
return unless self.class.use_transactional_tests
Page::Terms.delete_all
ActiveRecord::FixtureSet.cache_fixtures ActiveRecord::Base.connection,
'page/terms' => nil

View File

@ -11,8 +11,9 @@ class JavascriptIntegrationTest < IntegrationTest
include AjaxPending
include Autocomplete
# transactionaly fixtures make js tests fail non deterministicly
self.use_transactional_fixtures = false
# transactionaly fixtures made js tests fail non deterministicly
# since Rails 5.1 they have been replaced by transactional_tests
self.use_transactional_tests = false
# only use fixtures required explicitly in the tests
self.fixture_table_names = []

View File

@ -43,6 +43,7 @@ class JoinOurNetworkRequestTest < ActiveSupport::TestCase
req = RequestToJoinOurNetwork.create! created_by: inviter,
recipient: @group,
requestable: @network
byebug
assert !@network.groups(true).include?(@group)
assert_nothing_raised do
req.approve_by!(@user)

View File

@ -30,7 +30,7 @@ module Crabgrass
@@themes = HashWithIndifferentAccess.new
# for the theme to work, this controller must be set.
# crabgrass sets it in a before_filter common to call controllers.
# crabgrass sets it in a before_action common to call controllers.
# TODO: will this be a problem with multiple threads?
attr_accessor :controller

View File

@ -346,18 +346,18 @@ class GreenCloth < RedCloth::TextileDoc
arg.formatter = self
end
def to_html(*before_filters, &block)
def to_html(*before_actions, &block)
@block = block
@original_markup = clone
before_filters += %i[delete_leading_whitespace normalize_code_blocks
before_actions += %i[delete_leading_whitespace normalize_code_blocks
offtag_obvious_code_blocks dynamic_symbols bracket_links auto_links
normalize_heading_blocks quoted_block tables_with_tabs wrap_long_words]
formatter = clone # \ in case one of the before filters
formatter.extend(GreenClothFormatterHTML) # / needs the formatter.
apply_rules(before_filters)
apply_rules(before_actions)
html = to(GreenClothFormatterHTML)
extract_offtags(html)