From 16a542d5f74843088f5bcae9009e7b39cef7b74d Mon Sep 17 00:00:00 2001 From: Reegan Viljoen Date: Sun, 18 Aug 2024 12:01:04 +0200 Subject: [PATCH] add: working poc --- .gitignore | 49 +++++++++-- Appraisals | 14 +++ Gemfile.lock | 83 ++++++++++++++++++ Rakefile | 10 ++- gemfiles/rails_7.0.gemfile | 11 +++ gemfiles/rails_7.1.gemfile | 11 +++ gemfiles/rails_7.2.gemfile | 11 +++ lib/render_kit.rb | 10 ++- lib/render_kit/engine.rb | 18 ++++ lib/render_kit/renderable_registry.rb | 15 ++++ .../rendering_helper_monkey_patch.rb | 15 ++++ lib/render_kit/view_paths_monkey_patch.rb | 15 ++++ render_kit.gemspec | 22 ++--- .../implicit_render_component.html.erb | 1 + .../components/implicit_render_component.rb | 5 ++ .../app/controllers/application_controller.rb | 4 + test/sandbox/app/controllers/concerns/.keep | 0 .../app/controllers/test_controller.rb | 6 ++ .../sandbox/app/helpers/application_helper.rb | 2 + .../app/views/layouts/application.html.erb | 23 +++++ .../sandbox/app/views/layouts/mailer.html.erb | 13 +++ .../sandbox/app/views/layouts/mailer.text.erb | 1 + test/sandbox/app/views/pwa/manifest.json.erb | 22 +++++ test/sandbox/app/views/pwa/service-worker.js | 26 ++++++ .../test/component_implicit_render.html.erb | 3 + test/sandbox/config.ru | 6 ++ test/sandbox/config/application.rb | 15 ++++ test/sandbox/config/boot.rb | 5 ++ test/sandbox/config/environment.rb | 5 ++ test/sandbox/config/environments/test.rb | 51 +++++++++++ test/sandbox/config/puma.rb | 33 +++++++ test/sandbox/config/routes.rb | 14 +++ test/sandbox/lib/assets/.keep | 0 test/sandbox/lib/tasks/.keep | 0 test/sandbox/public/404.html | 67 ++++++++++++++ .../public/406-unsupported-browser.html | 66 ++++++++++++++ test/sandbox/public/422.html | 67 ++++++++++++++ test/sandbox/public/500.html | 66 ++++++++++++++ test/sandbox/public/icon.png | Bin 0 -> 5599 bytes test/sandbox/public/icon.svg | 3 + test/sandbox/public/robots.txt | 1 + .../test/view_component_compatability_test.rb | 33 +++++++ test/test_helper.rb | 11 ++- test/test_render_kit.rb | 13 --- 44 files changed, 808 insertions(+), 38 deletions(-) create mode 100644 Appraisals create mode 100644 Gemfile.lock create mode 100644 gemfiles/rails_7.0.gemfile create mode 100644 gemfiles/rails_7.1.gemfile create mode 100644 gemfiles/rails_7.2.gemfile create mode 100644 lib/render_kit/engine.rb create mode 100644 lib/render_kit/renderable_registry.rb create mode 100644 lib/render_kit/rendering_helper_monkey_patch.rb create mode 100644 lib/render_kit/view_paths_monkey_patch.rb create mode 100644 test/sandbox/app/components/implicit_render_component.html.erb create mode 100644 test/sandbox/app/components/implicit_render_component.rb create mode 100644 test/sandbox/app/controllers/application_controller.rb create mode 100644 test/sandbox/app/controllers/concerns/.keep create mode 100644 test/sandbox/app/controllers/test_controller.rb create mode 100644 test/sandbox/app/helpers/application_helper.rb create mode 100644 test/sandbox/app/views/layouts/application.html.erb create mode 100644 test/sandbox/app/views/layouts/mailer.html.erb create mode 100644 test/sandbox/app/views/layouts/mailer.text.erb create mode 100644 test/sandbox/app/views/pwa/manifest.json.erb create mode 100644 test/sandbox/app/views/pwa/service-worker.js create mode 100644 test/sandbox/app/views/test/component_implicit_render.html.erb create mode 100644 test/sandbox/config.ru create mode 100644 test/sandbox/config/application.rb create mode 100644 test/sandbox/config/boot.rb create mode 100644 test/sandbox/config/environment.rb create mode 100644 test/sandbox/config/environments/test.rb create mode 100644 test/sandbox/config/puma.rb create mode 100644 test/sandbox/config/routes.rb create mode 100644 test/sandbox/lib/assets/.keep create mode 100644 test/sandbox/lib/tasks/.keep create mode 100644 test/sandbox/public/404.html create mode 100644 test/sandbox/public/406-unsupported-browser.html create mode 100644 test/sandbox/public/422.html create mode 100644 test/sandbox/public/500.html create mode 100644 test/sandbox/public/icon.png create mode 100644 test/sandbox/public/icon.svg create mode 100644 test/sandbox/public/robots.txt create mode 100644 test/sandbox/test/view_component_compatability_test.rb delete mode 100644 test/test_render_kit.rb diff --git a/.gitignore b/.gitignore index 9106b2a..2594aa0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,47 @@ -/.bundle/ -/.yardoc -/_yardoc/ -/coverage/ -/doc/ +*.gem +*.rbc +.ruby-version +/.config +/coverage/assets +/coverage/index.html +/coverage/*.json +/coverage/*.json.lock +/InstalledFiles /pkg/ /spec/reports/ +/spec/examples.txt +/test/tmp/ +/test/version_tmp/ /tmp/ +/test/log/* +/test/sandbox/tmp/* +/test/sandbox/log/* +/test/tmp/* +/.yardoc + +## Specific to RubyMotion: +.dat* +.repl_history +build/ +*.bridgesupport +build-iPhoneOS/ +build-iPhoneSimulator/ + +## Documentation cache and generated files: +/doc/ +/rdoc/ + +## Environment normalization: +/.bundle/ +/vendor/bundle +/lib/bundler/man/ + +# unless supporting rvm < 1.11.0 or doing something fancy, ignore this: +.rvmrc + +# Sample bug replication repo +/replicate-bug + +# Appraisal +/gemfiles/*.gemfile.lock +/gemfiles/.bundle/ diff --git a/Appraisals b/Appraisals new file mode 100644 index 0000000..f5e8a68 --- /dev/null +++ b/Appraisals @@ -0,0 +1,14 @@ +appraise "rails-7.0" do + gem "rails", "~> 7.0" + gem "view_component", "~> 3.13.0" +end + +appraise "rails-7.1" do + gem "rails", "~> 7.1" + gem "view_component", "~> 3.13.0" +end + +appraise "rails-7.2" do + gem "rails", "~> 7.2" + gem "view_component", "~> 3.13.0" +end diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..83d5971 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,83 @@ +PATH + remote: . + specs: + render_kit (0.1.0) + +GEM + remote: https://rubygems.org/ + specs: + appraisal (2.5.0) + bundler + rake + thor (>= 0.14.0) + ast (2.4.2) + json (2.7.2) + language_server-protocol (3.17.0.3) + lint_roller (1.1.0) + minitest (5.25.0) + nio4r (2.7.3) + parallel (1.26.2) + parser (3.3.4.2) + ast (~> 2.4.1) + racc + puma (6.4.2) + nio4r (~> 2.0) + racc (1.8.1) + rainbow (3.1.1) + rake (13.2.1) + regexp_parser (2.9.2) + rexml (3.3.5) + strscan + rubocop (1.65.1) + json (~> 2.3) + language_server-protocol (>= 3.17.0) + parallel (~> 1.10) + parser (>= 3.3.0.2) + rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 2.4, < 3.0) + rexml (>= 3.2.5, < 4.0) + rubocop-ast (>= 1.31.1, < 2.0) + ruby-progressbar (~> 1.7) + unicode-display_width (>= 2.4.0, < 3.0) + rubocop-ast (1.32.0) + parser (>= 3.3.1.0) + rubocop-performance (1.21.1) + rubocop (>= 1.48.1, < 2.0) + rubocop-ast (>= 1.31.1, < 2.0) + ruby-progressbar (1.13.0) + standard (1.34.0) + language_server-protocol (~> 3.17.0.2) + lint_roller (~> 1.0) + rubocop (~> 1.60) + standard-custom (~> 1.0.0) + standard-performance (~> 1.3) + standard-custom (1.0.2) + lint_roller (~> 1.0) + rubocop (~> 1.50) + standard-performance (1.4.0) + lint_roller (~> 1.1) + rubocop-performance (~> 1.21.0) + strscan (3.1.0) + thor (1.3.1) + unicode-display_width (2.5.0) + +PLATFORMS + aarch64-linux + arm-linux + arm64-darwin + x86-linux + x86_64-darwin + x86_64-linux + +DEPENDENCIES + appraisal + bundler (~> 2) + minitest (~> 5.16) + puma (~> 6) + rake (~> 13.0) + render_kit! + rubocop (~> 1.21) + standard (~> 1) + +BUNDLED WITH + 2.5.13 diff --git a/Rakefile b/Rakefile index 2bf771f..284786d 100644 --- a/Rakefile +++ b/Rakefile @@ -1,12 +1,16 @@ # frozen_string_literal: true require "bundler/gem_tasks" -require "minitest/test_task" +require "rake/testtask" -Minitest::TestTask.create +Rake::TestTask.new(:test) do |t| + t.libs << "test" + t.libs << "lib" + t.test_files = FileList["test/**/*_test.rb"] +end require "rubocop/rake_task" RuboCop::RakeTask.new -task default: %i[test rubocop] +task default: %i[test] diff --git a/gemfiles/rails_7.0.gemfile b/gemfiles/rails_7.0.gemfile new file mode 100644 index 0000000..076f04b --- /dev/null +++ b/gemfiles/rails_7.0.gemfile @@ -0,0 +1,11 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "rake", "~> 13.0" +gem "minitest", "~> 5.16" +gem "rubocop", "~> 1.21" +gem "rails", "~> 7.0" +gem "view_component", "~> 3.13.0" + +gemspec path: "../" diff --git a/gemfiles/rails_7.1.gemfile b/gemfiles/rails_7.1.gemfile new file mode 100644 index 0000000..49a6f70 --- /dev/null +++ b/gemfiles/rails_7.1.gemfile @@ -0,0 +1,11 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "rake", "~> 13.0" +gem "minitest", "~> 5.16" +gem "rubocop", "~> 1.21" +gem "rails", "~> 7.1" +gem "view_component", "~> 3.13.0" + +gemspec path: "../" diff --git a/gemfiles/rails_7.2.gemfile b/gemfiles/rails_7.2.gemfile new file mode 100644 index 0000000..c3d779e --- /dev/null +++ b/gemfiles/rails_7.2.gemfile @@ -0,0 +1,11 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "rake", "~> 13.0" +gem "minitest", "~> 5.16" +gem "rubocop", "~> 1.21" +gem "rails", "~> 7.2" +gem "view_component", "~> 3.13.0" + +gemspec path: "../" diff --git a/lib/render_kit.rb b/lib/render_kit.rb index bcbc2d1..fc7d130 100644 --- a/lib/render_kit.rb +++ b/lib/render_kit.rb @@ -1,8 +1,10 @@ # frozen_string_literal: true -require_relative "render_kit/version" - +require "render_kit/version" +require "active_support/dependencies/autoload" +require "render_kit/engine" module RenderKit - class Error < StandardError; end - # Your code goes here... + extend ActiveSupport::Autoload + + autoload :RenderableRegistry end diff --git a/lib/render_kit/engine.rb b/lib/render_kit/engine.rb new file mode 100644 index 0000000..6925523 --- /dev/null +++ b/lib/render_kit/engine.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +require "rails" + +require "render_kit/view_paths_monkey_patch" +require "render_kit/rendering_helper_monkey_patch" + +module RenderKit + class Engine < ::Rails::Engine # :nodoc: + initializer "render_kit.action_view" do |app| + ActiveSupport.on_load(:action_view) do + ActionView::LookupContext.include RenderKit::ViewPathsMonkeyPatch + ActionView::Base.include RenderKit::ViewPathsMonkeyPatch + ActionView::Base.prepend RenderKit::RenderingHelperMonkeyPatch + end + end + end +end diff --git a/lib/render_kit/renderable_registry.rb b/lib/render_kit/renderable_registry.rb new file mode 100644 index 0000000..c6f5817 --- /dev/null +++ b/lib/render_kit/renderable_registry.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +module RenderKit + module RenderableRegistry # :nodoc: + @renderables = Hash.new {} + + def self.get_renderables(path) + @renderables[path] + end + + def self.set_renderable(path, renderable_klass) + @renderables[path] = renderable_klass + end + end +end diff --git a/lib/render_kit/rendering_helper_monkey_patch.rb b/lib/render_kit/rendering_helper_monkey_patch.rb new file mode 100644 index 0000000..9b718e5 --- /dev/null +++ b/lib/render_kit/rendering_helper_monkey_patch.rb @@ -0,0 +1,15 @@ +# frozen string literal: true + +require "active_support/concern" + +module RenderKit + module RenderingHelperMonkeyPatch + def render(options = {}, locals = {}, &) + if renderable = RenderKit::RenderableRegistry.get_renderables(options) + renderable.new(locals).render_in(self, &) + else + super + end + end + end +end diff --git a/lib/render_kit/view_paths_monkey_patch.rb b/lib/render_kit/view_paths_monkey_patch.rb new file mode 100644 index 0000000..fde83f7 --- /dev/null +++ b/lib/render_kit/view_paths_monkey_patch.rb @@ -0,0 +1,15 @@ +# frozen string literal: true + +require "active_support/concern" + +module RenderKit + module ViewPathsMonkeyPatch + extend ActiveSupport::Concern + + module ClassMethods + def register_renderable(path, renderable_klass) + RenderKit::RenderableRegistry.set_renderable(path, renderable_klass) + end + end + end +end diff --git a/render_kit.gemspec b/render_kit.gemspec index d34ac1d..73f239f 100644 --- a/render_kit.gemspec +++ b/render_kit.gemspec @@ -8,16 +8,16 @@ Gem::Specification.new do |spec| spec.authors = ["Reegan Viljoen"] spec.email = ["reeganviljoen@outlook.com"] - spec.summary = "TODO: Write a short summary, because RubyGems requires one." - spec.description = "TODO: Write a longer description or delete this line." - spec.homepage = "TODO: Put your gem's website or public repo URL here." + spec.summary = "A small library to allow claases to be rendered oike partials in Rails" + spec.description = "A small library to allow claases to be rendered oike partials in Rails" + # spec.homepage = "TODO: Put your gem's website or public repo URL here." spec.required_ruby_version = ">= 3.0.0" spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'" - spec.metadata["homepage_uri"] = spec.homepage - spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here." - spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here." + # spec.metadata["homepage_uri"] = spec.homepage + # spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here." + # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here." # Specify which files should be added to the gem when it is released. # The `git ls-files -z` loads the files in the RubyGem that have been added into git. @@ -32,9 +32,9 @@ Gem::Specification.new do |spec| spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) } spec.require_paths = ["lib"] - # Uncomment to register a new dependency of your gem - # spec.add_dependency "example-gem", "~> 1.0" - - # For more information and examples about making a new gem, check out our - # guide at: https://bundler.io/guides/creating_gem.html + spec.add_development_dependency "appraisal" + spec.add_development_dependency "bundler", "~> 2" + spec.add_development_dependency "minitest", "~> 5.18" + spec.add_development_dependency "puma", "~> 6" + spec.add_development_dependency "standard", "~> 1" end diff --git a/test/sandbox/app/components/implicit_render_component.html.erb b/test/sandbox/app/components/implicit_render_component.html.erb new file mode 100644 index 0000000..b0ac64d --- /dev/null +++ b/test/sandbox/app/components/implicit_render_component.html.erb @@ -0,0 +1 @@ +
I have been implicity rendered
diff --git a/test/sandbox/app/components/implicit_render_component.rb b/test/sandbox/app/components/implicit_render_component.rb new file mode 100644 index 0000000..1d929ee --- /dev/null +++ b/test/sandbox/app/components/implicit_render_component.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +class ImplicitRenderComponent < ViewComponent::Base + ActionView::Base.register_renderable("implicit_render_component", ImplicitRenderComponent) +end diff --git a/test/sandbox/app/controllers/application_controller.rb b/test/sandbox/app/controllers/application_controller.rb new file mode 100644 index 0000000..0d95db2 --- /dev/null +++ b/test/sandbox/app/controllers/application_controller.rb @@ -0,0 +1,4 @@ +class ApplicationController < ActionController::Base + # Only allow modern browsers supporting webp images, web push, badges, import maps, CSS nesting, and CSS :has. + allow_browser versions: :modern +end diff --git a/test/sandbox/app/controllers/concerns/.keep b/test/sandbox/app/controllers/concerns/.keep new file mode 100644 index 0000000..e69de29 diff --git a/test/sandbox/app/controllers/test_controller.rb b/test/sandbox/app/controllers/test_controller.rb new file mode 100644 index 0000000..bd70c9e --- /dev/null +++ b/test/sandbox/app/controllers/test_controller.rb @@ -0,0 +1,6 @@ +class TestController < ActionController::Base + protect_from_forgery + + def component_implicit_render + end +end diff --git a/test/sandbox/app/helpers/application_helper.rb b/test/sandbox/app/helpers/application_helper.rb new file mode 100644 index 0000000..de6be79 --- /dev/null +++ b/test/sandbox/app/helpers/application_helper.rb @@ -0,0 +1,2 @@ +module ApplicationHelper +end diff --git a/test/sandbox/app/views/layouts/application.html.erb b/test/sandbox/app/views/layouts/application.html.erb new file mode 100644 index 0000000..74c88bc --- /dev/null +++ b/test/sandbox/app/views/layouts/application.html.erb @@ -0,0 +1,23 @@ + + + + <%= content_for(:title) || "Sandbox" %> + + + <%= csrf_meta_tags %> + <%= csp_meta_tag %> + + <%= yield :head %> + + + + + + <%= stylesheet_link_tag "application", "data-turbo-track": "reload" %> + <%= javascript_importmap_tags %> + + + + <%= yield %> + + diff --git a/test/sandbox/app/views/layouts/mailer.html.erb b/test/sandbox/app/views/layouts/mailer.html.erb new file mode 100644 index 0000000..3aac900 --- /dev/null +++ b/test/sandbox/app/views/layouts/mailer.html.erb @@ -0,0 +1,13 @@ + + + + + + + + + <%= yield %> + + diff --git a/test/sandbox/app/views/layouts/mailer.text.erb b/test/sandbox/app/views/layouts/mailer.text.erb new file mode 100644 index 0000000..37f0bdd --- /dev/null +++ b/test/sandbox/app/views/layouts/mailer.text.erb @@ -0,0 +1 @@ +<%= yield %> diff --git a/test/sandbox/app/views/pwa/manifest.json.erb b/test/sandbox/app/views/pwa/manifest.json.erb new file mode 100644 index 0000000..cb5e326 --- /dev/null +++ b/test/sandbox/app/views/pwa/manifest.json.erb @@ -0,0 +1,22 @@ +{ + "name": "Sandbox", + "icons": [ + { + "src": "/icon.png", + "type": "image/png", + "sizes": "512x512" + }, + { + "src": "/icon.png", + "type": "image/png", + "sizes": "512x512", + "purpose": "maskable" + } + ], + "start_url": "/", + "display": "standalone", + "scope": "/", + "description": "Sandbox.", + "theme_color": "red", + "background_color": "red" +} diff --git a/test/sandbox/app/views/pwa/service-worker.js b/test/sandbox/app/views/pwa/service-worker.js new file mode 100644 index 0000000..68d5c2e --- /dev/null +++ b/test/sandbox/app/views/pwa/service-worker.js @@ -0,0 +1,26 @@ +// Add a service worker for processing Web Push notifications: +// +// self.addEventListener("push", async (event) => { +// const { title, options } = await event.data.json() +// event.waitUntil(self.registration.showNotification(title, options)) +// }) +// +// self.addEventListener("notificationclick", function(event) { +// event.notification.close() +// event.waitUntil( +// clients.matchAll({ type: "window" }).then((clientList) => { +// for (let i = 0; i < clientList.length; i++) { +// let client = clientList[i] +// let clientPath = (new URL(client.url)).pathname +// +// if (clientPath == event.notification.data.path && "focus" in client) { +// return client.focus() +// } +// } +// +// if (clients.openWindow) { +// return clients.openWindow(event.notification.data.path) +// } +// }) +// ) +// }) diff --git a/test/sandbox/app/views/test/component_implicit_render.html.erb b/test/sandbox/app/views/test/component_implicit_render.html.erb new file mode 100644 index 0000000..59e6770 --- /dev/null +++ b/test/sandbox/app/views/test/component_implicit_render.html.erb @@ -0,0 +1,3 @@ +
+ <%= render "implicit_render_component" %> +
diff --git a/test/sandbox/config.ru b/test/sandbox/config.ru new file mode 100644 index 0000000..78aa03a --- /dev/null +++ b/test/sandbox/config.ru @@ -0,0 +1,6 @@ +# frozen_string_literal: true + +# This file is used by Rack-based servers to start the application. + +require ::File.expand_path("../config/environment", __FILE__) +run Sandbox::Application diff --git a/test/sandbox/config/application.rb b/test/sandbox/config/application.rb new file mode 100644 index 0000000..d820ce1 --- /dev/null +++ b/test/sandbox/config/application.rb @@ -0,0 +1,15 @@ +# require "rails/all" + +require File.expand_path("boot", __dir__) + +require "active_model/railtie" +require "action_controller/railtie" +require "action_view/railtie" + +require "render_kit" +require "view_component" + +module Sandbox + class Application < Rails::Application + end +end diff --git a/test/sandbox/config/boot.rb b/test/sandbox/config/boot.rb new file mode 100644 index 0000000..b17aa74 --- /dev/null +++ b/test/sandbox/config/boot.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +require "rubygems" + +$:.unshift File.expand_path("../../../../../../lib", __FILE__) diff --git a/test/sandbox/config/environment.rb b/test/sandbox/config/environment.rb new file mode 100644 index 0000000..cac5315 --- /dev/null +++ b/test/sandbox/config/environment.rb @@ -0,0 +1,5 @@ +# Load the Rails application. +require_relative "application" + +# Initialize the Rails application. +Rails.application.initialize! diff --git a/test/sandbox/config/environments/test.rb b/test/sandbox/config/environments/test.rb new file mode 100644 index 0000000..36206e2 --- /dev/null +++ b/test/sandbox/config/environments/test.rb @@ -0,0 +1,51 @@ +require "active_support/core_ext/integer/time" + +# The test environment is used exclusively to run your application's +# test suite. You never need to work with it otherwise. Remember that +# your test database is "scratch space" for the test suite and is wiped +# and recreated between test runs. Don't rely on the data there! + +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # While tests run files are not watched, reloading is not necessary. + config.enable_reloading = false + + # Eager loading loads your entire application. When running a single test locally, + # this is usually not necessary, and can slow down your test suite. However, it's + # recommended that you enable it in continuous integration systems to ensure eager + # loading is working properly before deploying your code. + config.eager_load = true + + # Configure public file server for tests with Cache-Control for performance. + config.public_file_server.headers = {"Cache-Control" => "public, max-age=#{1.hour.to_i}"} + + # Show full error reports and disable caching. + config.consider_all_requests_local = true + config.action_controller.perform_caching = false + config.cache_store = :null_store + + # Render exception templates for rescuable exceptions and raise for other exceptions. + config.action_dispatch.show_exceptions = :rescuable + + # Disable request forgery protection in test environment. + config.action_controller.allow_forgery_protection = false + + # Print deprecation notices to the stderr. + config.active_support.deprecation = :stderr + + # 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 = [] + + # 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 +end diff --git a/test/sandbox/config/puma.rb b/test/sandbox/config/puma.rb new file mode 100644 index 0000000..60e1b9c --- /dev/null +++ b/test/sandbox/config/puma.rb @@ -0,0 +1,33 @@ +# 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 + +# Only use a pidfile when requested +pidfile ENV["PIDFILE"] if ENV["PIDFILE"] diff --git a/test/sandbox/config/routes.rb b/test/sandbox/config/routes.rb new file mode 100644 index 0000000..826592d --- /dev/null +++ b/test/sandbox/config/routes.rb @@ -0,0 +1,14 @@ +Rails.application.routes.draw do + # 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 + + # Render dynamic PWA files from app/views/pwa/* + get "service-worker" => "rails/pwa#service_worker", :as => :pwa_service_worker + get "manifest" => "rails/pwa#manifest", :as => :pwa_manifest + get "component_implicit_render", to: "test#component_implicit_render" + # Defines the root path route ("/") + # root "posts#index" +end diff --git a/test/sandbox/lib/assets/.keep b/test/sandbox/lib/assets/.keep new file mode 100644 index 0000000..e69de29 diff --git a/test/sandbox/lib/tasks/.keep b/test/sandbox/lib/tasks/.keep new file mode 100644 index 0000000..e69de29 diff --git a/test/sandbox/public/404.html b/test/sandbox/public/404.html new file mode 100644 index 0000000..2be3af2 --- /dev/null +++ b/test/sandbox/public/404.html @@ -0,0 +1,67 @@ + + + + The page you were looking for doesn't exist (404) + + + + + + +
+
+

The page you were looking for doesn't exist.

+

You may have mistyped the address or the page may have moved.

+
+

If you are the application owner check the logs for more information.

+
+ + diff --git a/test/sandbox/public/406-unsupported-browser.html b/test/sandbox/public/406-unsupported-browser.html new file mode 100644 index 0000000..7cf1e16 --- /dev/null +++ b/test/sandbox/public/406-unsupported-browser.html @@ -0,0 +1,66 @@ + + + + Your browser is not supported (406) + + + + + + +
+
+

Your browser is not supported.

+

Please upgrade your browser to continue.

+
+
+ + diff --git a/test/sandbox/public/422.html b/test/sandbox/public/422.html new file mode 100644 index 0000000..c08eac0 --- /dev/null +++ b/test/sandbox/public/422.html @@ -0,0 +1,67 @@ + + + + The change you wanted was rejected (422) + + + + + + +
+
+

The change you wanted was rejected.

+

Maybe you tried to change something you didn't have access to.

+
+

If you are the application owner check the logs for more information.

+
+ + diff --git a/test/sandbox/public/500.html b/test/sandbox/public/500.html new file mode 100644 index 0000000..78a030a --- /dev/null +++ b/test/sandbox/public/500.html @@ -0,0 +1,66 @@ + + + + We're sorry, but something went wrong (500) + + + + + + +
+
+

We're sorry, but something went wrong.

+
+

If you are the application owner check the logs for more information.

+
+ + diff --git a/test/sandbox/public/icon.png b/test/sandbox/public/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..f3b5abcbde91cf6d7a6a26e514eb7e30f476f950 GIT binary patch literal 5599 zcmeHL-D}fO6hCR_taXJlzs3}~RuB=Iujyo=i*=1|1FN%E=zNfMTjru|Q<6v{J{U!C zBEE}?j6I3sz>fzN!6}L_BKjcuASk~1;Dg|U_@d{g?V8mM`~#9U+>>*Ezw>c(PjYWA z4(;!cgge6k5E&d$G5`S-0}!Ik>CV(0Y#1}s-v_gAHhja2=W1?nBAte9D2HG<(+)uj z!5=W4u*{VKMw#{V@^NNs4TClr!FAA%ID-*gc{R%CFKEzG<6gm*9s_uy)oMGW*=nJf zw{(Mau|2FHfXIv6C0@Wk5k)F=3jo1srV-C{pl&k&)4_&JjYrnbJiul}d0^NCSh(#7h=F;3{|>EU>h z6U8_p;^wK6mAB(1b92>5-HxJ~V}@3?G`&Qq-TbJ2(&~-HsH6F#8mFaAG(45eT3VPO zM|(Jd<+;UZs;w>0Qw}0>D%{~r{uo_Fl5_Bo3ABWi zWo^j^_T3dxG6J6fH8X)$a^%TJ#PU!=LxF=#Fd9EvKx_x>q<(KY%+y-08?kN9dXjXK z**Q=yt-FTU*13ouhCdqq-0&;Ke{T3sQU9IdzhV9LhQIpq*P{N)+}|Mh+a-VV=x?R} c>%+pvTcMWshj-umO}|qP?%A)*_KlqT3uEqhU;qFB literal 0 HcmV?d00001 diff --git a/test/sandbox/public/icon.svg b/test/sandbox/public/icon.svg new file mode 100644 index 0000000..78307cc --- /dev/null +++ b/test/sandbox/public/icon.svg @@ -0,0 +1,3 @@ + + + diff --git a/test/sandbox/public/robots.txt b/test/sandbox/public/robots.txt new file mode 100644 index 0000000..c19f78a --- /dev/null +++ b/test/sandbox/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/test/sandbox/test/view_component_compatability_test.rb b/test/sandbox/test/view_component_compatability_test.rb new file mode 100644 index 0000000..4e16fdc --- /dev/null +++ b/test/sandbox/test/view_component_compatability_test.rb @@ -0,0 +1,33 @@ +# frozen_string_literal: true + +require "test_helper" + +class RenderKit::ViewComponentCompatibilityTest < ActionController::TestCase + tests TestController + + # def setup + # # enable a logger so that (e.g.) the benchmarking stuff runs, so we can get + # # a more accurate simulation of what happens in "real life". + # super + # @controller.logger = ActiveSupport::Logger.new(nil) + # ActionView::Base.logger = ActiveSupport::Logger.new(nil) + + # @request.host = "www.nextangle.com" + + # @old_view_paths = ActionController::Base.view_paths + # ActionController::Base.view_paths = File.join(FIXTURE_LOAD_PATH, "actionpack") + # end + + # def teardown + # ActionView::Base.logger = nil + + # ActionController::Base.view_paths = @old_view_paths + # end + + def test_rendering_view_component + get :component_implicit_render + assert_response 200 + assert_response :success + assert_match(/I have been implicity rendered/, @response.body) + end +end diff --git a/test/test_helper.rb b/test/test_helper.rb index d46db48..efe4ab6 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,6 +1,13 @@ # frozen_string_literal: true -$LOAD_PATH.unshift File.expand_path("../lib", __dir__) -require "render_kit" +require "rails/version" +require "bundler/setup" +require "pathname" require "minitest/autorun" + +# Configure Rails Environment +ENV["RAILS_ENV"] = "test" + +require File.expand_path("sandbox/config/environment.rb", __dir__) +require "rails/test_help" diff --git a/test/test_render_kit.rb b/test/test_render_kit.rb deleted file mode 100644 index d0e3f96..0000000 --- a/test/test_render_kit.rb +++ /dev/null @@ -1,13 +0,0 @@ -# frozen_string_literal: true - -require "test_helper" - -class TestRenderKit < Minitest::Test - def test_that_it_has_a_version_number - refute_nil ::RenderKit::VERSION - end - - def test_it_does_something_useful - assert false - end -end