diff --git a/src/main/java/org/jruby/rack/DefaultRackConfig.java b/src/main/java/org/jruby/rack/DefaultRackConfig.java index 5e4604819..7705f556e 100644 --- a/src/main/java/org/jruby/rack/DefaultRackConfig.java +++ b/src/main/java/org/jruby/rack/DefaultRackConfig.java @@ -166,12 +166,6 @@ protected RackLogger createLogger(final String loggerClass) { throw new RackException("could not create logger: '" + loggerClass + "'", e.getTargetException()); } } - //catch (ClassNotFoundException e) { - // if ( ! isQuiet() ) { - // err.println("failed creating logger: '" + loggerClass + "'"); - // e.printStackTrace(err); - // } - //} catch (Exception e) { if ( ! isQuiet() ) { err.println("failed creating logger: '" + loggerClass + "'"); diff --git a/src/main/java/org/jruby/rack/RackContext.java b/src/main/java/org/jruby/rack/RackContext.java index 551050854..e3c0be879 100644 --- a/src/main/java/org/jruby/rack/RackContext.java +++ b/src/main/java/org/jruby/rack/RackContext.java @@ -13,6 +13,6 @@ * @author nicksieger */ public interface RackContext extends RackLogger { - RackConfig getConfig(); /// NOTE: deprecate ? + RackConfig getConfig(); String getServerInfo(); } diff --git a/src/main/java/org/jruby/rack/RackLogger.java b/src/main/java/org/jruby/rack/RackLogger.java index 91a22fde7..cc1b0abb1 100644 --- a/src/main/java/org/jruby/rack/RackLogger.java +++ b/src/main/java/org/jruby/rack/RackLogger.java @@ -47,4 +47,8 @@ public void setLevel(Level level) { /* noop */ } public boolean isFormatting() { return false; } public void setFormatting(boolean flag) { /* noop */ } } + + interface DelegatingLogger extends RackLogger { + RackLogger unwrapLogger(); + } } diff --git a/src/main/java/org/jruby/rack/RackServletContextListener.java b/src/main/java/org/jruby/rack/RackServletContextListener.java index ef6380e70..2fee50929 100644 --- a/src/main/java/org/jruby/rack/RackServletContextListener.java +++ b/src/main/java/org/jruby/rack/RackServletContextListener.java @@ -39,6 +39,7 @@ public RackServletContextListener() { this.factory = factory; } + @Override public void contextInitialized(final ServletContextEvent event) { final ServletContext context = event.getServletContext(); final ServletRackConfig config = new ServletRackConfig(context); @@ -54,6 +55,7 @@ public void contextInitialized(final ServletContextEvent event) { } } + @Override public void contextDestroyed(final ServletContextEvent event) { final ServletContext context = event.getServletContext(); final RackApplicationFactory factory = diff --git a/src/main/java/org/jruby/rack/ext/Logger.java b/src/main/java/org/jruby/rack/ext/Logger.java index b799503da..6d63e90cc 100644 --- a/src/main/java/org/jruby/rack/ext/Logger.java +++ b/src/main/java/org/jruby/rack/ext/Logger.java @@ -39,7 +39,6 @@ import org.jruby.rack.RackContext; import org.jruby.rack.RackLogger; import org.jruby.rack.logging.ServletContextLogger; -import org.jruby.rack.util.ExceptionUtils; import org.jruby.runtime.Block; import org.jruby.runtime.ObjectAllocator; import org.jruby.runtime.ThreadContext; @@ -123,6 +122,10 @@ public IRubyObject initialize_copy(final ThreadContext context, final IRubyObjec @JRubyMethod public IRubyObject real_logger(final ThreadContext context) { + RackLogger logger = this.logger; + if (logger instanceof RackLogger.DelegatingLogger) { + logger = ((RackLogger.DelegatingLogger) logger).unwrapLogger(); + } return JavaEmbedUtils.javaToRuby(context.runtime, logger); } @@ -357,8 +360,7 @@ public IRubyObject add(final ThreadContext context, final IRubyObject severity, return context.runtime.newBoolean( add(UNKNOWN, context, msg, block) ); } - private boolean add(final int severity, final ThreadContext context, - IRubyObject msg, final Block block) { + private boolean add(final int severity, final ThreadContext context, IRubyObject msg, final Block block) { // severity ||= UNKNOWN final RackLogger.Level loggerLevel = mapLevel(severity); @@ -379,10 +381,9 @@ private boolean add(final int severity, final ThreadContext context, final long datetime = System.currentTimeMillis(); msg = format_message(context, severity, datetime, progname, msg); } - else if ( msg instanceof RubyException ) { // print backtrace for error - final RubyException error = (RubyException) msg; - error.prepareIntegratedBacktrace(context, null); - doLog( loggerLevel, ExceptionUtils.formatError(error) ); + else if ( msg instanceof RubyException ) { + final RubyException ex = (RubyException) msg; + doLog( loggerLevel, ex.toThrowable() ); return true; } // @logdev.write(format_message(format_severity(severity), Time.now, progname, message)) @@ -455,16 +456,20 @@ private static int toInt(final IRubyObject level) { @SuppressWarnings("unchecked") @Override public T toJava(Class target) { - if ( RackLogger.class == target ) return (T) logger; + if ( RackLogger.class.isAssignableFrom(target) && target.isInstance(logger) ) return (T) logger; return super.toJava(target); } + private void doLog(RackLogger.Level level, Throwable ex) { + logger.log(level, "", ex); + } + private void doLog(RackLogger.Level level, CharSequence message) { - logger.log( level, message ); + logger.log(level, message); } private void doLog(RubyString message) { - logger.log( message ); + logger.log(message); } /** diff --git a/src/main/java/org/jruby/rack/logging/OutputStreamLogger.java b/src/main/java/org/jruby/rack/logging/OutputStreamLogger.java index c82ad2227..b0bd033f5 100644 --- a/src/main/java/org/jruby/rack/logging/OutputStreamLogger.java +++ b/src/main/java/org/jruby/rack/logging/OutputStreamLogger.java @@ -113,12 +113,7 @@ public static void printLevel(final RackLogger.Base logger, final Level level, f } public static void printMessage(final PrintStream out, final CharSequence message) { - if ( message.charAt(message.length() - 1) == '\n' ) { - out.print(message); - } - else { - out.println(message); - } + out.println(message); } } \ No newline at end of file diff --git a/src/main/java/org/jruby/rack/servlet/DefaultServletRackContext.java b/src/main/java/org/jruby/rack/servlet/DefaultServletRackContext.java index 6a4f1c182..33793c461 100644 --- a/src/main/java/org/jruby/rack/servlet/DefaultServletRackContext.java +++ b/src/main/java/org/jruby/rack/servlet/DefaultServletRackContext.java @@ -35,7 +35,7 @@ * * @author nicksieger */ -public class DefaultServletRackContext implements ServletRackContext { +public class DefaultServletRackContext implements ServletRackContext, RackLogger.DelegatingLogger { private final RackConfig config; private final ServletContext context; @@ -232,6 +232,11 @@ public void log(Level level, CharSequence message, Throwable e) { logger.log(level, message, e); } + @Override + public RackLogger unwrapLogger() { + return logger; + } + @Override public int getEffectiveMajorVersion() throws UnsupportedOperationException { return context.getEffectiveMajorVersion(); diff --git a/src/main/java/org/jruby/rack/util/ExceptionUtils.java b/src/main/java/org/jruby/rack/util/ExceptionUtils.java index 49a7231cc..ba921042a 100644 --- a/src/main/java/org/jruby/rack/util/ExceptionUtils.java +++ b/src/main/java/org/jruby/rack/util/ExceptionUtils.java @@ -26,13 +26,8 @@ import java.io.IOException; import org.jruby.Ruby; -import org.jruby.RubyArray; import org.jruby.RubyClass; -import org.jruby.RubyException; -import org.jruby.RubyString; import org.jruby.exceptions.RaiseException; -import org.jruby.runtime.ThreadContext; -import org.jruby.runtime.builtin.IRubyObject; /** * @@ -54,53 +49,10 @@ public static RaiseException newIOError(final Ruby runtime, final IOException ca return raise; } - private static RaiseException newRaiseException(final Ruby runtime, - final RubyClass errorClass, final Throwable cause) { + private static RaiseException newRaiseException(final Ruby runtime, final RubyClass errorClass, final Throwable cause) { final String message = cause.getMessage(); RaiseException raise = RaiseException.from(runtime, errorClass, message); raise.initCause(cause); return raise; } - - public static CharSequence formatError(final RubyException error) { - final StringBuilder out = new StringBuilder(128); - appendError(error, out); return out; - } - - private static void appendInspect(final RubyException error, final StringBuilder out) { - final RubyClass errorClass = error.getMetaClass().getRealClass(); - if ( error.getMessage() != null && ! error.getMessage().isNil() ) { - out.append("#<").append( errorClass.getName() ).append(": "); - out.append( error.getMessage().asString() ).append('>'); - } - else { - out.append( errorClass.getName() ); - } - } - - public static void appendError(final RubyException error, final StringBuilder out) { - appendInspect(error, out); - appendBacktrace(error, out.append('\n')); - } - - public static void appendBacktrace(final RubyException error, final StringBuilder out) { - appendBacktrace(error, 0, out); - } - - public static void appendBacktrace(final RubyException error, final int skip, - final StringBuilder out) { - final ThreadContext context = error.getRuntime().getCurrentContext(); - final IRubyObject backtrace = error.callMethod(context, "backtrace"); - if ( ! backtrace.isNil() ) { - final RubyArray trace = backtrace.convertToArray(); - out.ensureCapacity(out.length() + 24 * trace.getLength()); - for ( int i = skip; i < trace.getLength(); i++ ) { - IRubyObject stackTraceLine = trace.eltInternal(i); - if ( stackTraceLine instanceof RubyString ) { - out.append("\tfrom ").append(stackTraceLine).append('\n'); - } - } - } - } - } diff --git a/src/spec/ruby/jruby/rack/integration_spec.rb b/src/spec/ruby/jruby/rack/integration_spec.rb index 9a94037f8..eb686262a 100644 --- a/src/spec/ruby/jruby/rack/integration_spec.rb +++ b/src/spec/ruby/jruby/rack/integration_spec.rb @@ -85,7 +85,9 @@ shared_examples_for 'a rails app', :shared => true do - let(:servlet_context) { new_servlet_context(base_path) } + let(:servlet_context) do + new_servlet_context(base_path).tap { |servlet_context| prepare_servlet_context(servlet_context) } + end it "initializes pooling when min/max set" do servlet_context.addInitParameter('jruby.min.runtimes', '1') @@ -127,10 +129,66 @@ rack_factory.should be_a(RackApplicationFactory) rack_factory.should be_a(SharedRackApplicationFactory) rack_factory.realFactory.should be_a(RailsRackApplicationFactory) + end - rack_factory.getApplication.should be_a(DefaultRackApplication) + end + + describe 'rails 7.2', lib: :rails72 do + + before(:all) do name = :rails72 # copy_gemfile : + FileUtils.cp File.join(GEMFILES_DIR, "#{name}.gemfile"), File.join(STUB_DIR, "#{name}/Gemfile") + FileUtils.cp File.join(GEMFILES_DIR, "#{name}.gemfile.lock"), File.join(STUB_DIR, "#{name}/Gemfile.lock") + Dir.chdir File.join(STUB_DIR, name.to_s) end + def base_path; "#{STUB_DIR}/rails72" end + + it_should_behave_like 'a rails app' + + context "initialized" do + + before(:all) do + initialize_rails('production', "file://#{base_path}") do |servlet_context, _| + prepare_servlet_context(servlet_context) + end + end + after(:all) { restore_rails } + + it "loaded rack ~> 2.2" do + @runtime = @rack_factory.getApplication.getRuntime + should_eval_as_not_nil "defined?(Rack.release)" + should_eval_as_eql_to "Rack.release.to_s[0, 3]", '2.2' + end + + it "booted with a servlet logger" do + @runtime = @rack_factory.getApplication.getRuntime + should_eval_as_not_nil "defined?(Rails)" + should_eval_as_not_nil "Rails.logger" + + # Rails 7.x wraps the default in a ActiveSupport::BroadcastLogger + should_eval_as_eql_to "Rails.logger.is_a? ActiveSupport::BroadcastLogger", true + should_eval_as_eql_to "Rails.logger.broadcasts.size", 1 + should_eval_as_eql_to "Rails.logger.broadcasts.first.is_a? JRuby::Rack::Logger", true + # NOTE: TaggedLogging is a module that extends the logger instance: + should_eval_as_eql_to "Rails.logger.broadcasts.first.is_a? ActiveSupport::TaggedLogging", true + + # production.rb: config.log_level = 'info' + should_eval_as_eql_to "Rails.logger.level", Logger::INFO + should_eval_as_eql_to "Rails.logger.broadcasts.first.level", Logger::INFO + + unwrap_logger = "logger = Rails.logger.broadcasts.first;" + # sanity check logger-silence works: + should_eval_as_eql_to "#{unwrap_logger} logger.silence { logger.warn('from-integration-spec') }", true + + should_eval_as_eql_to "#{unwrap_logger} logger.real_logger.is_a?(org.jruby.rack.logging.ServletContextLogger)", true + end + + it "sets up public_path" do + @runtime = @rack_factory.getApplication.getRuntime + should_eval_as_eql_to "Rails.public_path.to_s", "#{base_path}/public" + end + + end end def expect_to_have_monkey_patched_chunked @@ -146,8 +204,6 @@ def expect_to_have_monkey_patched_chunked should_eval_as_eql_to script, "1\nsecond" end - ENV_COPY = ENV.to_h - def initialize_rails(env = nil, servlet_context = @servlet_context) if ! servlet_context || servlet_context.is_a?(String) base = servlet_context.is_a?(String) ? servlet_context : nil @@ -160,19 +216,23 @@ def initialize_rails(env = nil, servlet_context = @servlet_context) servlet_context.addInitParameter("jruby.runtime.env", the_env) yield(servlet_context, listener) if block_given? + listener.contextInitialized javax.servlet.ServletContextEvent.new(servlet_context) @rack_context = servlet_context.getAttribute("rack.context") @rack_factory = servlet_context.getAttribute("rack.factory") - @servlet_context ||= servlet_context + @servlet_context = servlet_context end def new_servlet_context(base_path = nil) servlet_context = org.jruby.rack.mock.RackLoggingMockServletContext.new base_path - servlet_context.logger = raise_logger + servlet_context.logger = raise_logger(:WARN).tap { |logger| logger.setEnabled(false) } servlet_context end - private + def prepare_servlet_context(servlet_context) + servlet_context.addInitParameter('rails.root', base_path) + servlet_context.addInitParameter('jruby.rack.layout_class', 'FileSystemLayout') + end GEMFILES_DIR = File.expand_path('../../../gemfiles', STUB_DIR) @@ -181,4 +241,11 @@ def copy_gemfile(name) # e.g. 'rails30' FileUtils.cp File.join(GEMFILES_DIR, "#{name}.gemfile.lock"), File.join(STUB_DIR, "#{name}/WEB-INF/Gemfile.lock") end + ENV_COPY = ENV.to_h + + def restore_rails + ENV['RACK_ENV'] = ENV_COPY['RACK_ENV'] if ENV.key?('RACK_ENV') + ENV['RAILS_ENV'] = ENV_COPY['RAILS_ENV'] if ENV.key?('RAILS_ENV') + end + end diff --git a/src/spec/ruby/jruby/rack/logger_spec.rb b/src/spec/ruby/jruby/rack/logger_spec.rb index a24313fcb..73e0cc477 100644 --- a/src/spec/ruby/jruby/rack/logger_spec.rb +++ b/src/spec/ruby/jruby/rack/logger_spec.rb @@ -54,7 +54,7 @@ logger = JRuby::Rack::Logger.new logger.debug? logger.debug 'hogy basza meg a zold tucsok!' - expect( logger.real_logger ).to be rack_context + expect( logger.to_java(org.jruby.rack.RackLogger) ).to be rack_context end it 'delegates level check (when level is not set)' do @@ -97,6 +97,15 @@ expect( real_logger.formatting? ).to be false end + it 'logs exception with trace when passed as argument' do + begin + raise IndexError.new('TEST') + rescue => e + logger.debug(e) + end + expect( real_logger.logged_content ).to match /^DEBUG.*?IndexError.*?TEST.*?at.*?logger_spec.rb.*/m + end + it 'handles constant resolution (for Rails compatibility)' do expect( logger.class::DEBUG ).to eql 0 expect( logger.class::FATAL ).to eql 4 diff --git a/src/spec/stub/rails72/Rakefile b/src/spec/stub/rails72/Rakefile new file mode 100644 index 000000000..9a5ea7383 --- /dev/null +++ b/src/spec/stub/rails72/Rakefile @@ -0,0 +1,6 @@ +# Add your own tasks in files placed in lib/tasks ending in .rake, +# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. + +require_relative "config/application" + +Rails.application.load_tasks diff --git a/src/spec/stub/rails72/app/controllers/application_controller.rb b/src/spec/stub/rails72/app/controllers/application_controller.rb new file mode 100644 index 000000000..4ac8823b0 --- /dev/null +++ b/src/spec/stub/rails72/app/controllers/application_controller.rb @@ -0,0 +1,2 @@ +class ApplicationController < ActionController::API +end diff --git a/src/spec/stub/rails72/app/controllers/concerns/.keep b/src/spec/stub/rails72/app/controllers/concerns/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/src/spec/stub/rails72/app/controllers/sample_controller.rb b/src/spec/stub/rails72/app/controllers/sample_controller.rb new file mode 100644 index 000000000..1b6e218b7 --- /dev/null +++ b/src/spec/stub/rails72/app/controllers/sample_controller.rb @@ -0,0 +1,4 @@ +class SampleController < ApplicationController + def index + end +end diff --git a/src/spec/stub/rails72/app/helpers/sample_helper.rb b/src/spec/stub/rails72/app/helpers/sample_helper.rb new file mode 100644 index 000000000..fef504b48 --- /dev/null +++ b/src/spec/stub/rails72/app/helpers/sample_helper.rb @@ -0,0 +1,2 @@ +module SampleHelper +end diff --git a/src/spec/stub/rails72/app/models/application_record.rb b/src/spec/stub/rails72/app/models/application_record.rb new file mode 100644 index 000000000..e7e0e1fc3 --- /dev/null +++ b/src/spec/stub/rails72/app/models/application_record.rb @@ -0,0 +1,6 @@ +# class ApplicationRecord < ActiveRecord::Base +# primary_abstract_class +# end + +class ApplicationRecord +end diff --git a/src/spec/stub/rails72/app/models/concerns/.keep b/src/spec/stub/rails72/app/models/concerns/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/src/spec/stub/rails72/app/views/sample/index.html.erb b/src/spec/stub/rails72/app/views/sample/index.html.erb new file mode 100644 index 000000000..1f18de4bc --- /dev/null +++ b/src/spec/stub/rails72/app/views/sample/index.html.erb @@ -0,0 +1,2 @@ +

Sample#index

+

Find me in app/views/sample/index.html.erb

diff --git a/src/spec/stub/rails72/config/application.rb b/src/spec/stub/rails72/config/application.rb new file mode 100644 index 000000000..9d099687a --- /dev/null +++ b/src/spec/stub/rails72/config/application.rb @@ -0,0 +1,44 @@ +require_relative "boot" + +require "rails" +# Pick the frameworks you want: +#require "active_model/railtie" +#require "active_job/railtie" +#require "active_record/railtie" +#require "active_storage/engine" +require "action_controller/railtie" +#require "action_mailer/railtie" +#require "action_mailbox/engine" +#require "action_text/engine" +require "action_view/railtie" +#require "action_cable/engine" +#require "rails/test_unit/railtie" + +# Require the gems listed in Gemfile, including any gems +# you've limited to :test, :development, or :production. +Bundler.require(*Rails.groups) + +module Rails72 + class Application < Rails::Application + # Initialize configuration defaults for originally generated Rails version. + config.load_defaults 7.2 + + # Please, add to the `ignore` list any other `lib` subdirectories that do + # not contain `.rb` files, or that should not be reloaded or eager loaded. + # Common ones are `templates`, `generators`, or `middleware`, for example. + config.autoload_lib(ignore: %w[assets tasks]) + + # Configuration for the application, engines, and railties goes here. + # + # These settings can be overridden in specific environments using the files + # in config/environments, which are processed later. + # + # config.time_zone = "Central Time (US & Canada)" + # config.eager_load_paths << Rails.root.join("extras") + + # Only loads a smaller set of middleware suitable for API only apps. + # Middleware like session, flash, cookies can be added back manually. + # Skip views, helpers and assets when generating a new resource. + #config.api_only = true + end +end diff --git a/src/spec/stub/rails72/config/boot.rb b/src/spec/stub/rails72/config/boot.rb new file mode 100644 index 000000000..282011619 --- /dev/null +++ b/src/spec/stub/rails72/config/boot.rb @@ -0,0 +1,3 @@ +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) + +require "bundler/setup" # Set up gems listed in the Gemfile. diff --git a/src/spec/stub/rails72/config/credentials.yml.enc b/src/spec/stub/rails72/config/credentials.yml.enc new file mode 100644 index 000000000..98b297e5e --- /dev/null +++ b/src/spec/stub/rails72/config/credentials.yml.enc @@ -0,0 +1 @@ +VcfM8jsFjbT1uz41VePTrE2/rI+fGrx6kyrFKJSoflAC2PlYpvBd6JdKeTMi3NFkCV2jsoNeM9ZkoPKffxdu5nBly27ax3A1nxhTRTuqIs2hOizrK2pIVPIAG2Q/rlG7vLuiTLzPQdm1+sapOPWyj7yNGyHckYJZv4jDkEfWZSQ8ERfmwdMSue3AeLWk/mHxq0aHNM26Lg5cCbGcea3No6doXCjk0xVFCY0qpOW1jbV6RrfgOjZ7yy72F37q/38ykPZ+/NyTAChxlkBuhFUf003qzuIirBDsE3zWcrIpKB5vWDPhj5vRS0F0uI1uVnWeeiah/RLc6FmrvCHr72lXeCBMorZBv4K32BI9IERZOCWjK/Yegf6Vfr33MEP9kPxOfu5+cH/apFjFD1+917LEOdHiDxd0--XKF4UI5O521M73io--qlQCj8KMYeYyis/202ipdw== \ No newline at end of file diff --git a/src/spec/stub/rails72/config/environment.rb b/src/spec/stub/rails72/config/environment.rb new file mode 100644 index 000000000..cac531577 --- /dev/null +++ b/src/spec/stub/rails72/config/environment.rb @@ -0,0 +1,5 @@ +# Load the Rails application. +require_relative "application" + +# Initialize the Rails application. +Rails.application.initialize! diff --git a/src/spec/stub/rails72/config/environments/development.rb b/src/spec/stub/rails72/config/environments/development.rb new file mode 100644 index 000000000..1409a9162 --- /dev/null +++ b/src/spec/stub/rails72/config/environments/development.rb @@ -0,0 +1,63 @@ +require "active_support/core_ext/integer/time" + +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # In the development environment your application's code is reloaded any time + # it changes. This slows down response time but is perfect for development + # since you don't have to restart the web server when you make code changes. + config.enable_reloading = true + + # Do not eager load code on boot. + config.eager_load = false + + # Show full error reports. + config.consider_all_requests_local = true + + # Enable server timing. + config.server_timing = true + + # Enable/disable caching. By default caching is disabled. + # Run rails dev:cache to toggle caching. + if Rails.root.join("tmp/caching-dev.txt").exist? + config.cache_store = :memory_store + config.public_file_server.headers = { "Cache-Control" => "public, max-age=#{2.days.to_i}" } + else + config.action_controller.perform_caching = false + + config.cache_store = :null_store + end + + # Store uploaded files on the local file system (see config/storage.yml for options). + #config.active_storage.service = :local + + # Print deprecation notices to the Rails logger. + config.active_support.deprecation = :log + + # Raise exceptions for disallowed deprecations. + config.active_support.disallowed_deprecation = :raise + + # Tell Active Support which deprecation messages to disallow. + config.active_support.disallowed_deprecation_warnings = [] + + # Raise an error on page load if there are pending migrations. + #config.active_record.migration_error = :page_load + + # Highlight code that triggered database queries in logs. + #config.active_record.verbose_query_logs = true + + # Highlight code that enqueued background job in logs. + #config.active_job.verbose_enqueue_logs = true + + # Raises error for missing translations. + # config.i18n.raise_on_missing_translations = true + + # Annotate rendered view with file names. + config.action_view.annotate_rendered_view_with_filenames = true + + # Raise error when a before_action's only/except options reference missing actions. + config.action_controller.raise_on_missing_callback_actions = true + + # Apply autocorrection by RuboCop to files generated by `bin/rails generate`. + # config.generators.apply_rubocop_autocorrect_after_generate! +end diff --git a/src/spec/stub/rails72/config/environments/production.rb b/src/spec/stub/rails72/config/environments/production.rb new file mode 100644 index 000000000..31d14ad7b --- /dev/null +++ b/src/spec/stub/rails72/config/environments/production.rb @@ -0,0 +1,87 @@ +require "active_support/core_ext/integer/time" + +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # Code is not reloaded between requests. + config.enable_reloading = false + + # Eager load code on boot. This eager loads most of Rails and + # your application in memory, allowing both threaded web servers + # and those relying on copy on write to perform better. + # Rake tasks automatically ignore this option for performance. + config.eager_load = true + + # Full error reports are disabled and caching is turned on. + config.consider_all_requests_local = false + + # Ensures that a master key has been made available in ENV["RAILS_MASTER_KEY"], config/master.key, or an environment + # key such as config/credentials/production.key. This key is used to decrypt credentials (and other encrypted files). + # config.require_master_key = true + + # Disable serving static files from `public/`, relying on NGINX/Apache to do so instead. + config.public_file_server.enabled = false + + # Enable serving of images, stylesheets, and JavaScripts from an asset server. + # config.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 + + # Store uploaded files on the local file system (see config/storage.yml for options). + #config.active_storage.service = :local + + # Assume all access to the app is happening through a SSL-terminating reverse proxy. + # Can be used together with config.force_ssl for Strict-Transport-Security and secure cookies. + # config.assume_ssl = true + + # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. + #config.force_ssl = true + + # Skip http-to-https redirect for the default health check endpoint. + # config.ssl_options = { redirect: { exclude: ->(request) { request.path == "/up" } } } + + # Log to STDOUT by default +# config.logger = ActiveSupport::Logger.new(STDOUT) +# .tap { |logger| logger.formatter = ::Logger::Formatter.new } +# .then { |logger| ActiveSupport::TaggedLogging.new(logger) } + + config.log_level = 'info' # added manually for the sake of a jruby-rack spec + + # Prepend all log lines with the following tags. + config.log_tags = [ :request_id ] + + # "info" includes generic and useful information about system operation, but avoids logging too much + # information to avoid inadvertent exposure of personally identifiable information (PII). If you + # want to log everything, set the level to "debug". + #config.log_level = ENV.fetch("RAILS_LOG_LEVEL", "info") + + # Use a different cache store in production. + # config.cache_store = :mem_cache_store + + # Use a real queuing backend for Active Job (and separate queues per environment). + # config.active_job.queue_adapter = :resque + # config.active_job.queue_name_prefix = "rails72_production" + + # Enable locale fallbacks for I18n (makes lookups for any locale fall back to + # the I18n.default_locale when a translation cannot be found). + config.i18n.fallbacks = true + + # Don't log any deprecations. + config.active_support.report_deprecations = false + + # Do not dump schema after migrations. + #config.active_record.dump_schema_after_migration = false + + # Only use :id for inspections in production. + #config.active_record.attributes_for_inspect = [ :id ] + + # Enable DNS rebinding protection and other `Host` header attacks. + # config.hosts = [ + # "example.com", # Allow requests from example.com + # /.*\.example\.com/ # Allow requests from subdomains like `www.example.com` + # ] + # Skip DNS rebinding protection for the default health check endpoint. + # config.host_authorization = { exclude: ->(request) { request.path == "/up" } } +end diff --git a/src/spec/stub/rails72/config/initializers/cors.rb b/src/spec/stub/rails72/config/initializers/cors.rb new file mode 100644 index 000000000..0c5dd99ac --- /dev/null +++ b/src/spec/stub/rails72/config/initializers/cors.rb @@ -0,0 +1,16 @@ +# Be sure to restart your server when you modify this file. + +# Avoid CORS issues when API is called from the frontend app. +# Handle Cross-Origin Resource Sharing (CORS) in order to accept cross-origin Ajax requests. + +# Read more: https://github.com/cyu/rack-cors + +# Rails.application.config.middleware.insert_before 0, Rack::Cors do +# allow do +# origins "example.com" +# +# resource "*", +# headers: :any, +# methods: [:get, :post, :put, :patch, :delete, :options, :head] +# end +# end diff --git a/src/spec/stub/rails72/config/initializers/filter_parameter_logging.rb b/src/spec/stub/rails72/config/initializers/filter_parameter_logging.rb new file mode 100644 index 000000000..c010b83dd --- /dev/null +++ b/src/spec/stub/rails72/config/initializers/filter_parameter_logging.rb @@ -0,0 +1,8 @@ +# Be sure to restart your server when you modify this file. + +# Configure parameters to be partially matched (e.g. passw matches password) and filtered from the log file. +# Use this to limit dissemination of sensitive information. +# See the ActiveSupport::ParameterFilter documentation for supported notations and behaviors. +Rails.application.config.filter_parameters += [ + :passw, :email, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn +] diff --git a/src/spec/stub/rails72/config/initializers/inflections.rb b/src/spec/stub/rails72/config/initializers/inflections.rb new file mode 100644 index 000000000..3860f659e --- /dev/null +++ b/src/spec/stub/rails72/config/initializers/inflections.rb @@ -0,0 +1,16 @@ +# Be sure to restart your server when you modify this file. + +# 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(:en) do |inflect| +# inflect.acronym "RESTful" +# end diff --git a/src/spec/stub/rails72/config/locales/en.yml b/src/spec/stub/rails72/config/locales/en.yml new file mode 100644 index 000000000..6c349ae5e --- /dev/null +++ b/src/spec/stub/rails72/config/locales/en.yml @@ -0,0 +1,31 @@ +# Files in the config/locales directory are used for internationalization and +# are automatically loaded by Rails. If you want to use locales other than +# English, add the necessary files in this directory. +# +# To use the locales, use `I18n.t`: +# +# I18n.t "hello" +# +# In views, this is aliased to just `t`: +# +# <%= t("hello") %> +# +# To use a different locale, set it with `I18n.locale`: +# +# I18n.locale = :es +# +# This would use the information in config/locales/es.yml. +# +# To learn more about the API, please read the Rails Internationalization guide +# at https://guides.rubyonrails.org/i18n.html. +# +# Be aware that YAML interprets the following case-insensitive strings as +# booleans: `true`, `false`, `on`, `off`, `yes`, `no`. Therefore, these strings +# must be quoted to be interpreted as strings. For example: +# +# en: +# "yes": yup +# enabled: "ON" + +en: + hello: "Hello world" diff --git a/src/spec/stub/rails72/config/master.key b/src/spec/stub/rails72/config/master.key new file mode 100644 index 000000000..ea0a8e79c --- /dev/null +++ b/src/spec/stub/rails72/config/master.key @@ -0,0 +1 @@ +3950bb2e89efce14a3bb718354edb208 \ No newline at end of file diff --git a/src/spec/stub/rails72/config/puma.rb b/src/spec/stub/rails72/config/puma.rb new file mode 100644 index 000000000..03c166f4c --- /dev/null +++ b/src/spec/stub/rails72/config/puma.rb @@ -0,0 +1,34 @@ +# This configuration file will be evaluated by Puma. The top-level methods that +# are invoked here are part of Puma's configuration DSL. For more information +# about methods provided by the DSL, see https://puma.io/puma/Puma/DSL.html. + +# Puma starts a configurable number of processes (workers) and each process +# serves each request in a thread from an internal thread pool. +# +# The ideal number of threads per worker depends both on how much time the +# application spends waiting for IO operations and on how much you wish to +# to prioritize throughput over latency. +# +# As a rule of thumb, increasing the number of threads will increase how much +# traffic a given process can handle (throughput), but due to CRuby's +# Global VM Lock (GVL) it has diminishing returns and will degrade the +# response time (latency) of the application. +# +# The default is set to 3 threads as it's deemed a decent compromise between +# throughput and latency for the average Rails application. +# +# Any libraries that use a connection pool or another resource pool should +# be configured to provide at least as many connections as the number of +# threads. This includes Active Record's `pool` parameter in `database.yml`. +threads_count = ENV.fetch("RAILS_MAX_THREADS", 3) +threads threads_count, threads_count + +# Specifies the `port` that Puma will listen on to receive requests; default is 3000. +port ENV.fetch("PORT", 3000) + +# Allow puma to be restarted by `bin/rails restart` command. +plugin :tmp_restart + +# Specify the PID file. Defaults to tmp/pids/server.pid in development. +# In other environments, only set the PID file if requested. +pidfile ENV["PIDFILE"] if ENV["PIDFILE"] diff --git a/src/spec/stub/rails72/config/routes.rb b/src/spec/stub/rails72/config/routes.rb new file mode 100644 index 000000000..cc34fc10f --- /dev/null +++ b/src/spec/stub/rails72/config/routes.rb @@ -0,0 +1,11 @@ +Rails.application.routes.draw do + get "sample/index" + # Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html + + # Reveal health status on /up that returns 200 if the app boots with no exceptions, otherwise 500. + # Can be used by load balancers and uptime monitors to verify that the app is live. + get "up" => "rails/health#show", as: :rails_health_check + + # Defines the root path route ("/") + # root "posts#index" +end diff --git a/src/spec/stub/rails72/lib/.keep b/src/spec/stub/rails72/lib/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/src/spec/stub/rails72/public/robots.txt b/src/spec/stub/rails72/public/robots.txt new file mode 100644 index 000000000..c19f78ab6 --- /dev/null +++ b/src/spec/stub/rails72/public/robots.txt @@ -0,0 +1 @@ +# See https://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file diff --git a/src/spec/stub/rails72/vendor/.keep b/src/spec/stub/rails72/vendor/.keep new file mode 100644 index 000000000..e69de29bb