diff options
| author | erdgeist <erdgeist@erdgeist.org> | 2026-06-24 04:13:16 +0200 |
|---|---|---|
| committer | erdgeist <erdgeist@erdgeist.org> | 2026-06-24 04:13:16 +0200 |
| commit | e0a7e0fec760ba12c8067a37e10c96f1f05876e2 (patch) | |
| tree | d0cf745592a46aee4d4913911fd34c7c24515220 /config/initializers | |
| parent | 6424e10be5a89f175a74c71c55660412a169b8b8 (diff) | |
Stage 1 complete: Rails 2.3.5 to Rails 3.2.22.5 upgrade
- Converted plugins to gems (Gemfile)
- Updated config structure (application.rb, boot.rb, environment.rb)
- Converted routes to Rails 3 DSL
- Converted named_scope to scope throughout models
- Converted find(:all, :conditions) to where() chains
- Fixed has_many :order to use ordering scope
- Updated session store and secret token configuration
- Fixed exception_notification middleware configuration
- Patched Ruby 2.4 / Rails 3.2 incompatibilities:
- Integer/Float duration arithmetic (ActiveSupport)
- Arel visit_Integer for PostgreSQL adapter
- create_database String/Integer coercion
- ActionController consider_all_requests_local
- Migrated taggings schema for acts-as-taggable-on
- Replaced dynamic_form gem with custom form_error_messages helper
- Fixed Rails 3 block helper syntax (form_for, form_tag, fields_for)
- Fixed admin layout yield
- Updated test suite for Rails 3 APIs
Diffstat (limited to 'config/initializers')
| -rw-r--r-- | config/initializers/activesupport_duration_patch.rb | 53 | ||||
| -rw-r--r-- | config/initializers/arel_patch.rb | 12 | ||||
| -rw-r--r-- | config/initializers/exception_notifier.rb | 6 | ||||
| -rw-r--r-- | config/initializers/postgresql_adapter_patch.rb | 30 | ||||
| -rw-r--r-- | config/initializers/ruby2.rb | 16 | ||||
| -rw-r--r-- | config/initializers/session_store.rb | 16 |
6 files changed, 118 insertions, 15 deletions
diff --git a/config/initializers/activesupport_duration_patch.rb b/config/initializers/activesupport_duration_patch.rb new file mode 100644 index 0000000..c2b431d --- /dev/null +++ b/config/initializers/activesupport_duration_patch.rb | |||
| @@ -0,0 +1,53 @@ | |||
| 1 | class Integer | ||
| 2 | def days | ||
| 3 | ActiveSupport::Duration.new(self * 86400, [[:days, self]]) | ||
| 4 | end | ||
| 5 | alias :day :days | ||
| 6 | |||
| 7 | def weeks | ||
| 8 | ActiveSupport::Duration.new(self * 7 * 86400, [[:days, self * 7]]) | ||
| 9 | end | ||
| 10 | alias :week :weeks | ||
| 11 | |||
| 12 | def hours | ||
| 13 | ActiveSupport::Duration.new(self * 3600, [[:seconds, self * 3600]]) | ||
| 14 | end | ||
| 15 | alias :hour :hours | ||
| 16 | |||
| 17 | def minutes | ||
| 18 | ActiveSupport::Duration.new(self * 60, [[:seconds, self * 60]]) | ||
| 19 | end | ||
| 20 | alias :minute :minutes | ||
| 21 | |||
| 22 | def seconds | ||
| 23 | ActiveSupport::Duration.new(self, [[:seconds, self]]) | ||
| 24 | end | ||
| 25 | alias :second :seconds | ||
| 26 | |||
| 27 | def months | ||
| 28 | ActiveSupport::Duration.new(self * 30 * 86400, [[:months, self]]) | ||
| 29 | end | ||
| 30 | alias :month :months | ||
| 31 | |||
| 32 | def years | ||
| 33 | ActiveSupport::Duration.new((self * 365.25 * 86400).to_i, [[:years, self]]) | ||
| 34 | end | ||
| 35 | alias :year :years | ||
| 36 | end | ||
| 37 | |||
| 38 | class Float | ||
| 39 | def days | ||
| 40 | ActiveSupport::Duration.new((self * 86400).to_i, [[:days, self]]) | ||
| 41 | end | ||
| 42 | alias :day :days | ||
| 43 | |||
| 44 | def hours | ||
| 45 | ActiveSupport::Duration.new((self * 3600).to_i, [[:seconds, (self * 3600).to_i]]) | ||
| 46 | end | ||
| 47 | alias :hour :hours | ||
| 48 | |||
| 49 | def minutes | ||
| 50 | ActiveSupport::Duration.new((self * 60).to_i, [[:seconds, (self * 60).to_i]]) | ||
| 51 | end | ||
| 52 | alias :minute :minutes | ||
| 53 | end | ||
diff --git a/config/initializers/arel_patch.rb b/config/initializers/arel_patch.rb new file mode 100644 index 0000000..753a72b --- /dev/null +++ b/config/initializers/arel_patch.rb | |||
| @@ -0,0 +1,12 @@ | |||
| 1 | require 'arel' | ||
| 2 | module Arel | ||
| 3 | module Visitors | ||
| 4 | [ToSql, DepthFirst].each do |visitor| | ||
| 5 | visitor.class_eval do | ||
| 6 | def visit_Integer(o, collector = nil) | ||
| 7 | collector ? collector << o.to_s : o.to_s | ||
| 8 | end | ||
| 9 | end | ||
| 10 | end | ||
| 11 | end | ||
| 12 | end | ||
diff --git a/config/initializers/exception_notifier.rb b/config/initializers/exception_notifier.rb new file mode 100644 index 0000000..bc7c385 --- /dev/null +++ b/config/initializers/exception_notifier.rb | |||
| @@ -0,0 +1,6 @@ | |||
| 1 | Cccms::Application.config.middleware.use ExceptionNotification::Rack, | ||
| 2 | :email => { | ||
| 3 | :email_prefix => "[CCCMS] ", | ||
| 4 | :sender_address => %("CCCMS Error" <error@www.ccc.de>), | ||
| 5 | :exception_recipients => %w(erdgeist@ccc.de) | ||
| 6 | } | ||
diff --git a/config/initializers/postgresql_adapter_patch.rb b/config/initializers/postgresql_adapter_patch.rb new file mode 100644 index 0000000..57df6a2 --- /dev/null +++ b/config/initializers/postgresql_adapter_patch.rb | |||
| @@ -0,0 +1,30 @@ | |||
| 1 | require 'active_record/connection_adapters/postgresql_adapter' | ||
| 2 | |||
| 3 | module ActiveRecord | ||
| 4 | module ConnectionAdapters | ||
| 5 | class PostgreSQLAdapter | ||
| 6 | def create_database(name, options = {}) | ||
| 7 | options = options.reverse_merge(:encoding => "utf8") | ||
| 8 | |||
| 9 | option_string = options.symbolize_keys.inject("") do |memo, (key, value)| | ||
| 10 | memo + case key | ||
| 11 | when :owner | ||
| 12 | " OWNER = \"#{value}\"" | ||
| 13 | when :template | ||
| 14 | " TEMPLATE = \"#{value}\"" | ||
| 15 | when :encoding | ||
| 16 | " ENCODING = '#{value}'" | ||
| 17 | when :tablespace | ||
| 18 | " TABLESPACE = \"#{value}\"" | ||
| 19 | when :connection_limit | ||
| 20 | " CONNECTION LIMIT = #{value}" | ||
| 21 | else | ||
| 22 | "" | ||
| 23 | end | ||
| 24 | end | ||
| 25 | |||
| 26 | execute "CREATE DATABASE #{quote_table_name(name)}#{option_string}" | ||
| 27 | end | ||
| 28 | end | ||
| 29 | end | ||
| 30 | end | ||
diff --git a/config/initializers/ruby2.rb b/config/initializers/ruby2.rb new file mode 100644 index 0000000..d2d62aa --- /dev/null +++ b/config/initializers/ruby2.rb | |||
| @@ -0,0 +1,16 @@ | |||
| 1 | if Rails::VERSION::MAJOR == 2 && RUBY_VERSION >= '2.0.0' | ||
| 2 | module ActiveRecord | ||
| 3 | module Associations | ||
| 4 | class AssociationProxy | ||
| 5 | def send(method, *args) | ||
| 6 | if proxy_respond_to?(method, true) | ||
| 7 | super | ||
| 8 | else | ||
| 9 | load_target | ||
| 10 | @target.send(method, *args) | ||
| 11 | end | ||
| 12 | end | ||
| 13 | end | ||
| 14 | end | ||
| 15 | end | ||
| 16 | end | ||
diff --git a/config/initializers/session_store.rb b/config/initializers/session_store.rb index b3e1098..507dc3c 100644 --- a/config/initializers/session_store.rb +++ b/config/initializers/session_store.rb | |||
| @@ -1,15 +1 @@ | |||
| 1 | # Be sure to restart your server when you modify this file. | Cccms::Application.config.session_store :cookie_store, :key => '_cccms_session' | |
| 2 | |||
| 3 | # Your secret key for verifying cookie session data integrity. | ||
| 4 | # If you change this key, all old sessions will become invalid! | ||
| 5 | # Make sure the secret is at least 30 characters and all random, | ||
| 6 | # no regular words or you'll be exposed to dictionary attacks. | ||
| 7 | ActionController::Base.session = { | ||
| 8 | :key => '_cccms_session', | ||
| 9 | :secret => 'b50f62033369e6039f2ece511f83f10f70301024709e189ab28d42379a26b7bfd0739fb83d89b6b76dba350569e5b9d83ee4abedbd9da468deea963512e4102b' | ||
| 10 | } | ||
| 11 | |||
| 12 | # Use the database for sessions instead of the cookie-based default, | ||
| 13 | # which shouldn't be used to store highly confidential information | ||
| 14 | # (create the session table with "rake db:sessions:create") | ||
| 15 | # ActionController::Base.session_store = :active_record_store | ||
