diff --git a/.rubocop.yml b/.rubocop.yml index 5422099f..b5fa9062 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,5 +1,3 @@ -inherit_from: .rubocop_todo.yml - AllCops: TargetRubyVersion: 3.0 NewCops: enable diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml deleted file mode 100644 index d0182929..00000000 --- a/.rubocop_todo.yml +++ /dev/null @@ -1,473 +0,0 @@ -# This configuration was generated by -# `rubocop --auto-gen-config --exclude-limit 10000` -# on 2025-08-27 13:50:45 UTC using RuboCop version 1.80.1. -# The point is for the user to remove these configuration records -# one by one as the offenses are removed from the code base. -# Note that changes in the inspected code, or installation of new -# versions of RuboCop, may require this file to be generated again. - -# Offense count: 2 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle, IndentationWidth. -# SupportedStyles: with_first_argument, with_fixed_indentation -Layout/ArgumentAlignment: - Exclude: - - 'bin/console' - - 'spec/inertia/response_spec.rb' - -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -Layout/EmptyLineAfterGuardClause: - Exclude: - - 'lib/inertia_rails/controller.rb' - -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -Layout/EmptyLineAfterMagicComment: - Exclude: - - 'lib/inertia_rails/action_filter.rb' - -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle. -# SupportedStyles: empty_lines, no_empty_lines -Layout/EmptyLinesAroundBlockBody: - Exclude: - - 'spec/inertia/rails_mimic_spec.rb' - -# Offense count: 3 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: AllowForAlignment, AllowBeforeTrailingComments, ForceEqualSignAlignment. -Layout/ExtraSpacing: - Exclude: - - 'lib/inertia_rails/controller.rb' - - 'spec/inertia/request_spec.rb' - - 'spec/inertia/response_spec.rb' - -# Offense count: 16 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: IndentationWidth. -# SupportedStyles: special_inside_parentheses, consistent, align_braces -Layout/FirstHashElementIndentation: - EnforcedStyle: consistent - -# Offense count: 5 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces. -# SupportedStyles: space, no_space -# SupportedStylesForEmptyBraces: space, no_space -Layout/SpaceBeforeBlockBraces: - Exclude: - - 'spec/inertia/error_sharing_spec.rb' - - 'spec/inertia/request_spec.rb' - -# Offense count: 4 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBrackets. -# SupportedStyles: space, no_space, compact -# SupportedStylesForEmptyBrackets: space, no_space -Layout/SpaceInsideArrayLiteralBrackets: - Exclude: - - 'spec/dummy/app/controllers/inertia_test_controller.rb' - - 'spec/dummy/config/environments/production.rb' - -# Offense count: 5 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters. -# SupportedStyles: space, no_space -# SupportedStylesForEmptyBraces: space, no_space -Layout/SpaceInsideBlockBraces: - Exclude: - - 'spec/inertia/error_sharing_spec.rb' - - 'spec/inertia/request_spec.rb' - -# Offense count: 54 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces. -# SupportedStyles: space, no_space, compact -# SupportedStylesForEmptyBraces: space, no_space -Layout/SpaceInsideHashLiteralBraces: - Exclude: - - 'spec/dummy/app/controllers/inertia_conditional_sharing_controller.rb' - - 'spec/dummy/app/controllers/inertia_share_test_controller.rb' - - 'spec/inertia/conditional_sharing_spec.rb' - - 'spec/inertia/rails_mimic_spec.rb' - - 'spec/inertia/request_spec.rb' - - 'spec/inertia/rspec_helper_spec.rb' - -# Offense count: 2 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle. -# SupportedStyles: final_newline, final_blank_line -Layout/TrailingEmptyLines: - Exclude: - - 'lib/tasks/inertia_rails.rake' - - 'spec/inertia/rails_mimic_spec.rb' - -# Offense count: 9 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: AllowInHeredoc. -Layout/TrailingWhitespace: - Exclude: - - 'lib/inertia_rails/rspec.rb' - - 'spec/dummy/config/environments/test.rb' - -# Offense count: 1 -# Configuration parameters: AllowComments. -Lint/EmptyClass: - Exclude: - - 'spec/dummy/app/controllers/inertia_responders_test_controller.rb' - -# Offense count: 1 -# Configuration parameters: AllowedParentClasses. -Lint/MissingSuper: - Exclude: - - 'lib/inertia_rails/lazy_prop.rb' - -# Offense count: 1 -# This cop supports unsafe autocorrection (--autocorrect-all). -# Configuration parameters: AllowedImplicitNamespaces. -# AllowedImplicitNamespaces: Gem -Lint/RaiseException: - Exclude: - - 'spec/dummy/app/controllers/inertia_multithreaded_share_controller.rb' - -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle. -# SupportedStyles: strict, consistent -Lint/SymbolConversion: - Exclude: - - 'spec/inertia/rails_mimic_spec.rb' - -# Offense count: 1 -Naming/AccessorMethodName: - Exclude: - - 'lib/inertia_rails/rspec.rb' - -# Offense count: 2 -# Configuration parameters: ExpectMatchingDefinition, CheckDefinitionPathHierarchy, CheckDefinitionPathHierarchyRoots, Regex, IgnoreExecutableScripts, AllowedAcronyms. -# CheckDefinitionPathHierarchyRoots: lib, spec, test, src -# AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS -Naming/FileName: - Exclude: - - 'Rakefile.rb' - - 'lib/patches/debug_exceptions/patch-5-0.rb' - - 'lib/patches/debug_exceptions/patch-5-1.rb' - -# Offense count: 2 -# Configuration parameters: EnforcedStyle, CheckMethodNames, CheckSymbols, AllowedIdentifiers, AllowedPatterns. -# SupportedStyles: snake_case, normalcase, non_integer -# AllowedIdentifiers: TLS1_1, TLS1_2, capture3, iso8601, rfc1123_date, rfc822, rfc2822, rfc3339, x86_64 -Naming/VariableNumber: - Exclude: - - 'spec/dummy/app/controllers/inertia_test_controller.rb' - -# Offense count: 7 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle, ProceduralMethods, FunctionalMethods, AllowedMethods, AllowedPatterns, AllowBracesOnProceduralOneLiners, BracesRequiredMethods. -# SupportedStyles: line_count_based, semantic, braces_for_chaining, always_braces -# ProceduralMethods: benchmark, bm, bmbm, create, each_with_object, measure, new, realtime, tap, with_object -# FunctionalMethods: let, let!, subject, watch -# AllowedMethods: lambda, proc, it -Style/BlockDelimiters: - Exclude: - - 'lib/inertia_rails/controller.rb' - - 'spec/inertia/action_filter_spec.rb' - - 'spec/inertia/conditional_sharing_spec.rb' - - 'spec/inertia/rails_mimic_spec.rb' - - 'spec/inertia/request_spec.rb' - - 'spec/inertia/rspec_helper_spec.rb' - -# Offense count: 1 -# This cop supports unsafe autocorrection (--autocorrect-all). -# Configuration parameters: EnforcedStyle, EnforcedStyleForClasses, EnforcedStyleForModules. -# SupportedStyles: nested, compact -# SupportedStylesForClasses: ~, nested, compact -# SupportedStylesForModules: ~, nested, compact -Style/ClassAndModuleChildren: - Exclude: - - 'lib/inertia_rails/helper.rb' - -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -Style/ColonMethodCall: - Exclude: - - 'spec/inertia/error_sharing_spec.rb' - -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle, AllowComments. -# SupportedStyles: empty, nil, both -Style/EmptyElse: - Exclude: - - 'lib/patches/debug_exceptions.rb' - -# Offense count: 3 -# This cop supports safe autocorrection (--autocorrect). -Style/EmptyLiteral: - Exclude: - - 'spec/inertia/request_spec.rb' - -# Offense count: 2 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle. -# SupportedStyles: compact, expanded -Style/EmptyMethod: - Exclude: - - 'spec/dummy/app/controllers/transformed_inertia_rails_mimic_controller.rb' - - 'spec/inertia/rspec_helper_spec.rb' - -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -Style/ExpandPathArguments: - Exclude: - - 'spec/rails_helper.rb' - -# Offense count: 63 -# This cop supports unsafe autocorrection (--autocorrect-all). -# Configuration parameters: EnforcedStyle. -# SupportedStyles: always, always_true, never -Style/FrozenStringLiteralComment: - Exclude: - - '**/*.arb' - - 'app/controllers/inertia_rails/static_controller.rb' - - 'bin/console' - - 'lib/inertia_rails/controller.rb' - - 'lib/inertia_rails/engine.rb' - - 'lib/inertia_rails/helper.rb' - - 'lib/inertia_rails/rspec.rb' - - 'lib/inertia_rails/version.rb' - - 'lib/patches/better_errors.rb' - - 'lib/patches/debug_exceptions.rb' - - 'lib/patches/debug_exceptions/patch-5-0.rb' - - 'lib/patches/debug_exceptions/patch-5-1.rb' - - 'lib/patches/mapper.rb' - - 'lib/patches/request.rb' - - 'lib/tasks/inertia_rails.rake' - - 'spec/dummy/Rakefile' - - 'spec/dummy/app/controllers/application_controller.rb' - - 'spec/dummy/app/controllers/inertia_child_share_test_controller.rb' - - 'spec/dummy/app/controllers/inertia_conditional_sharing_controller.rb' - - 'spec/dummy/app/controllers/inertia_config_test_controller.rb' - - 'spec/dummy/app/controllers/inertia_lambda_shared_props_controller.rb' - - 'spec/dummy/app/controllers/inertia_merge_instance_props_controller.rb' - - 'spec/dummy/app/controllers/inertia_merge_shared_controller.rb' - - 'spec/dummy/app/controllers/inertia_multithreaded_share_controller.rb' - - 'spec/dummy/app/controllers/inertia_rails_mimic_controller.rb' - - 'spec/dummy/app/controllers/inertia_responders_test_controller.rb' - - 'spec/dummy/app/controllers/inertia_session_continuity_test_controller.rb' - - 'spec/dummy/app/controllers/inertia_share_test_controller.rb' - - 'spec/dummy/app/controllers/inertia_test_controller.rb' - - 'spec/dummy/app/controllers/transformed_inertia_rails_mimic_controller.rb' - - 'spec/dummy/app/helpers/application_helper.rb' - - 'spec/dummy/bin/rails' - - 'spec/dummy/bin/rake' - - 'spec/dummy/bin/setup' - - 'spec/dummy/config.ru' - - 'spec/dummy/config/application.rb' - - 'spec/dummy/config/boot.rb' - - 'spec/dummy/config/environment.rb' - - 'spec/dummy/config/environments/development.rb' - - 'spec/dummy/config/environments/production.rb' - - 'spec/dummy/config/environments/test.rb' - - 'spec/dummy/config/initializers/application_controller_renderer.rb' - - 'spec/dummy/config/initializers/backtrace_silencers.rb' - - 'spec/dummy/config/initializers/content_security_policy.rb' - - 'spec/dummy/config/initializers/cookies_serializer.rb' - - 'spec/dummy/config/initializers/filter_parameter_logging.rb' - - 'spec/dummy/config/initializers/inflections.rb' - - 'spec/dummy/config/initializers/mime_types.rb' - - 'spec/dummy/config/initializers/wrap_parameters.rb' - - 'spec/dummy/config/puma.rb' - - 'spec/dummy/config/routes.rb' - - 'spec/dummy/config/spring.rb' - - 'spec/inertia/action_filter_spec.rb' - - 'spec/inertia/always_prop_spec.rb' - - 'spec/inertia/base_prop_spec.rb' - - 'spec/inertia/conditional_sharing_spec.rb' - - 'spec/inertia/error_sharing_spec.rb' - - 'spec/inertia/lazy_prop_spec.rb' - - 'spec/inertia/rails_mimic_spec.rb' - - 'spec/inertia/request_spec.rb' - - 'spec/inertia/response_spec.rb' - - 'spec/inertia/rspec_helper_spec.rb' - - 'spec/rails_helper.rb' - - 'spec/support/shared_examples.rb' - -# Offense count: 1 -# This cop supports unsafe autocorrection (--autocorrect-all). -Style/GlobalStdStream: - Exclude: - - 'spec/dummy/config/environments/production.rb' - -# Offense count: 2 -# Configuration parameters: AllowedVariables. -Style/GlobalVars: - Exclude: - - 'spec/inertia/rspec_helper_spec.rb' - -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle, EnforcedShorthandSyntax, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols. -# SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys -# SupportedShorthandSyntax: always, never, either, consistent, either_consistent -Style/HashSyntax: - Exclude: - - 'lib/tasks/inertia_rails.rake' - -# Offense count: 5 -# This cop supports safe autocorrection (--autocorrect). -Style/IfUnlessModifier: - Exclude: - - 'lib/inertia_rails/controller.rb' - - 'lib/patches/better_errors.rb' - - 'lib/patches/debug_exceptions/patch-5-0.rb' - - 'lib/patches/debug_exceptions/patch-5-1.rb' - - 'spec/dummy/config/environments/test.rb' - -# Offense count: 2 -# This cop supports safe autocorrection (--autocorrect). -Style/IfUnlessModifierOfIfUnless: - Exclude: - - 'lib/inertia_rails/controller.rb' - -# Offense count: 2 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle. -# SupportedStyles: line_count_dependent, lambda, literal -Style/Lambda: - Exclude: - - 'spec/dummy/app/controllers/inertia_lambda_shared_props_controller.rb' - - 'spec/dummy/app/controllers/transformed_inertia_rails_mimic_controller.rb' - -# Offense count: 1 -# This cop supports unsafe autocorrection (--autocorrect-all). -Style/MapToSet: - Exclude: - - 'lib/inertia_rails/action_filter.rb' - -# Offense count: 1 -# This cop supports unsafe autocorrection (--autocorrect-all). -# Configuration parameters: EnforcedStyle. -# SupportedStyles: literals, strict -Style/MutableConstant: - Exclude: - - 'lib/inertia_rails/version.rb' - -# Offense count: 2 -# This cop supports safe autocorrection (--autocorrect). -Style/NestedModifier: - Exclude: - - 'lib/inertia_rails/controller.rb' - -# Offense count: 2 -# This cop supports safe autocorrection (--autocorrect). -Style/RedundantBegin: - Exclude: - - 'spec/inertia/rspec_helper_spec.rb' - -# Offense count: 5 -# This cop supports safe autocorrection (--autocorrect). -Style/RedundantConstantBase: - Exclude: - - 'lib/inertia_rails/rspec.rb' - - 'spec/dummy/config/environments/production.rb' - - 'spec/inertia/rspec_helper_spec.rb' - -# Offense count: 2 -# This cop supports unsafe autocorrection (--autocorrect-all). -# Configuration parameters: SafeForConstants. -Style/RedundantFetchBlock: - Exclude: - - 'spec/dummy/config/puma.rb' - -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: AllowMultipleReturnValues. -Style/RedundantReturn: - Exclude: - - 'spec/dummy/app/controllers/inertia_session_continuity_test_controller.rb' - -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: AllowIfMethodIsEmpty. -Style/SingleLineMethods: - Exclude: - - 'spec/dummy/app/controllers/inertia_test_controller.rb' - -# Offense count: 2 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: AllowModifier. -Style/SoleNestedConditional: - Exclude: - - 'lib/inertia_rails/controller.rb' - -# Offense count: 85 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline. -# SupportedStyles: single_quotes, double_quotes -Style/StringLiterals: - Exclude: - - 'bin/console' - - 'lib/inertia_rails/controller.rb' - - 'lib/inertia_rails/engine.rb' - - 'lib/inertia_rails/helper.rb' - - 'lib/inertia_rails/rspec.rb' - - 'lib/inertia_rails/version.rb' - - 'lib/patches/better_errors.rb' - - 'lib/patches/debug_exceptions/patch-5-0.rb' - - 'lib/patches/debug_exceptions/patch-5-1.rb' - - 'lib/tasks/inertia_rails.rake' - - 'spec/dummy/app/controllers/inertia_conditional_sharing_controller.rb' - - 'spec/dummy/app/controllers/inertia_config_test_controller.rb' - - 'spec/dummy/app/controllers/inertia_lambda_shared_props_controller.rb' - - 'spec/dummy/app/controllers/inertia_rails_mimic_controller.rb' - - 'spec/dummy/config/application.rb' - - 'spec/dummy/config/environments/production.rb' - - 'spec/dummy/config/puma.rb' - - 'spec/dummy/config/routes.rb' - - 'spec/dummy/config/spring.rb' - - 'spec/inertia/conditional_sharing_spec.rb' - - 'spec/inertia/response_spec.rb' - - 'spec/inertia/rspec_helper_spec.rb' - - 'spec/rails_helper.rb' - -# Offense count: 3 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: . -# SupportedStyles: percent, brackets -Style/SymbolArray: - EnforcedStyle: percent - MinSize: 3 - -# Offense count: 3 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyleForMultiline. -# SupportedStylesForMultiline: comma, consistent_comma, no_comma -Style/TrailingCommaInArguments: - Exclude: - - 'spec/dummy/app/controllers/inertia_config_test_controller.rb' - - 'spec/dummy/app/controllers/inertia_rails_mimic_controller.rb' - -# Offense count: 12 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyleForMultiline. -# SupportedStylesForMultiline: comma, consistent_comma, diff_comma, no_comma -Style/TrailingCommaInHashLiteral: - Exclude: - - 'lib/inertia_rails/rspec.rb' - - 'spec/dummy/app/controllers/inertia_lambda_shared_props_controller.rb' - - 'spec/dummy/app/controllers/inertia_merge_instance_props_controller.rb' - - 'spec/dummy/app/controllers/inertia_merge_shared_controller.rb' - - 'spec/dummy/config/environments/development.rb' - - 'spec/dummy/config/environments/test.rb' - - 'spec/inertia/response_spec.rb' - - 'spec/inertia/rspec_helper_spec.rb' - -# Offense count: 36 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: AllowHeredoc, AllowURI, AllowQualifiedName, URISchemes, IgnoreCopDirectives, AllowedPatterns, SplitStrings. -# URISchemes: http, https -Layout/LineLength: - Max: 276 diff --git a/app/controllers/inertia_rails/static_controller.rb b/app/controllers/inertia_rails/static_controller.rb index 933a2725..7a44d554 100644 --- a/app/controllers/inertia_rails/static_controller.rb +++ b/app/controllers/inertia_rails/static_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module InertiaRails class StaticController < InertiaRails.configuration.parent_controller.constantize def static diff --git a/bin/console b/bin/console index a9310808..55c0418b 100755 --- a/bin/console +++ b/bin/console @@ -1,13 +1,14 @@ #!/usr/bin/env ruby +# frozen_string_literal: true -require "pathname" -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", - Pathname.new(__FILE__).realpath) +require 'pathname' +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', + Pathname.new(__FILE__).realpath) -require "rubygems" -require "bundler/setup" -require "rails/all" -require "inertia_rails" +require 'rubygems' +require 'bundler/setup' +require 'rails/all' +require 'inertia_rails' -require "irb" +require 'irb' IRB.start(__FILE__) diff --git a/bin/generate_scaffold_example b/bin/generate_scaffold_example index b1ad3524..65b9fb02 100755 --- a/bin/generate_scaffold_example +++ b/bin/generate_scaffold_example @@ -76,7 +76,8 @@ Dir.chdir(app_dir) do system("bin/rails g inertia:install --no-interactive --force --vite #{generator_args} --verbose", exception: true) # Generate a scaffold - system('bin/rails g inertia:scaffold user name email admin:boolean password:digest avatar:attachment', exception: true) + system('bin/rails g inertia:scaffold user name email admin:boolean password:digest avatar:attachment', + exception: true) system('bin/rails g inertia:scaffold post content:text published_at:date gallery:attachments', exception: true) system('bin/rails db:migrate', exception: true) diff --git a/lib/generators/inertia/install/install_generator.rb b/lib/generators/inertia/install/install_generator.rb index 8d617e67..6ef0d507 100644 --- a/lib/generators/inertia/install/install_generator.rb +++ b/lib/generators/inertia/install/install_generator.rb @@ -128,8 +128,12 @@ def install_typescript add_dependencies(*FRAMEWORKS[framework]['packages_ts']) say 'Copying adding scripts to package.json' - run 'npm pkg set scripts.check="svelte-check --tsconfig ./tsconfig.json && tsc -p tsconfig.node.json"' if svelte? - run 'npm pkg set scripts.check="vue-tsc -p tsconfig.app.json && tsc -p tsconfig.node.json"' if framework == 'vue' + if svelte? + run 'npm pkg set scripts.check="svelte-check --tsconfig ./tsconfig.json && tsc -p tsconfig.node.json"' + end + if framework == 'vue' + run 'npm pkg set scripts.check="vue-tsc -p tsconfig.app.json && tsc -p tsconfig.node.json"' + end run 'npm pkg set scripts.check="tsc -p tsconfig.app.json && tsc -p tsconfig.node.json"' if framework == 'react' end @@ -262,8 +266,9 @@ def vite_tag end def inertia_resolved_version + package = "@inertiajs/core@#{options[:inertia_version]}" @inertia_resolved_version ||= Gem::Version.new( - `npm show @inertiajs/core@#{options[:inertia_version]} version --json | tail -n2 | head -n1 | tr -d '", '`.strip + `npm show #{package} version --json | tail -n2 | head -n1 | tr -d '", '`.strip ) end diff --git a/lib/inertia_rails/action_filter.rb b/lib/inertia_rails/action_filter.rb index 8ef958e0..6b3c2076 100644 --- a/lib/inertia_rails/action_filter.rb +++ b/lib/inertia_rails/action_filter.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # # Based on AbstractController::Callbacks::ActionFilter # https://github.com/rails/rails/blob/v7.2.0/actionpack/lib/abstract_controller/callbacks.rb#L39 @@ -6,7 +7,7 @@ module InertiaRails class ActionFilter def initialize(conditional_key, actions) @conditional_key = conditional_key - @actions = Array(actions).map(&:to_s).to_set + @actions = Array(actions).to_set(&:to_s) end def match?(controller) diff --git a/lib/inertia_rails/controller.rb b/lib/inertia_rails/controller.rb index 21129fc5..d394df8d 100644 --- a/lib/inertia_rails/controller.rb +++ b/lib/inertia_rails/controller.rb @@ -1,7 +1,9 @@ -require_relative "inertia_rails" -require_relative "helper" -require_relative "action_filter" -require_relative "meta_tag_builder" +# frozen_string_literal: true + +require_relative 'inertia_rails' +require_relative 'helper' +require_relative 'action_filter' +require_relative 'meta_tag_builder' module InertiaRails module Controller @@ -21,8 +23,8 @@ def inertia_share(hash = nil, **props, &block) return push_to_inertia_share(**(hash || props), &block) if options.empty? push_to_inertia_share do - next unless options[:if].all? { |filter| instance_exec(&filter) } if options[:if] - next unless options[:unless].none? { |filter| instance_exec(&filter) } if options[:unless] + next if options[:if] && !options[:if].all? { |filter| instance_exec(&filter) } + next if options[:unless]&.any? { |filter| instance_exec(&filter) } next hash unless block @@ -81,7 +83,9 @@ def extract_inertia_share_options(props) return options if options.empty? if props.except(:if, :unless, :only, :except).any? - raise ArgumentError, "You must not mix shared data and [:if, :unless, :only, :except] options, pass data as a hash or a block." + raise ArgumentError, + 'You must not mix shared data and [:if, :unless, :only, :except] options, ' \ + 'pass data as a hash or a block.' end transform_inertia_share_option(options, :only, :if) @@ -110,7 +114,7 @@ def filter_to_proc(filter) when InertiaRails::ActionFilter -> { filter.match?(self) } else - raise ArgumentError, "You must pass a symbol or a proc as a filter." + raise ArgumentError, 'You must pass a symbol or a proc as a filter.' end end end @@ -136,6 +140,7 @@ def inertia_meta def inertia_view_assigns return {} unless @_inertia_instance_props + view_assigns.except(*@_inertia_skip_props) end @@ -152,22 +157,22 @@ def inertia_shared_data else if inertia_configuration.always_include_errors_hash.nil? InertiaRails.deprecator.warn( - "To comply with the Inertia protocol, an empty errors hash `{errors: {}}` " \ - "will be included to all responses by default starting with InertiaRails 4.0. " \ - "To opt-in now, set `config.always_include_errors_hash = true`. " \ - "To disable this warning, set it to `false`." + 'To comply with the Inertia protocol, an empty errors hash `{errors: {}}` ' \ + 'will be included to all responses by default starting with InertiaRails 4.0. ' \ + 'To opt-in now, set `config.always_include_errors_hash = true`. ' \ + 'To disable this warning, set it to `false`.' ) end {} end - self.class._inertia_shared_data.filter_map { |shared_data| + self.class._inertia_shared_data.filter_map do |shared_data| if shared_data.respond_to?(:call) instance_exec(&shared_data) else shared_data end - }.reduce(initial_data, &:merge) + end.reduce(initial_data, &:merge) end def inertia_location(url) @@ -183,7 +188,7 @@ def capture_inertia_session_options(options) session[:inertia_errors] = inertia_errors.to_hash else InertiaRails.deprecator.warn( - "Object passed to `inertia: { errors: ... }` must respond to `to_hash`. Pass a hash-like object instead." + 'Object passed to `inertia: { errors: ... }` must respond to `to_hash`. Pass a hash-like object instead.' ) session[:inertia_errors] = inertia_errors end diff --git a/lib/inertia_rails/engine.rb b/lib/inertia_rails/engine.rb index 0e39d545..4f28ff7a 100644 --- a/lib/inertia_rails/engine.rb +++ b/lib/inertia_rails/engine.rb @@ -1,13 +1,15 @@ -require_relative "middleware" -require_relative "controller" +# frozen_string_literal: true + +require_relative 'middleware' +require_relative 'controller' module InertiaRails class Engine < ::Rails::Engine - initializer "inertia_rails.configure_rails_initialization" do |app| + initializer 'inertia_rails.configure_rails_initialization' do |app| app.middleware.use ::InertiaRails::Middleware end - initializer "inertia_rails.action_controller" do + initializer 'inertia_rails.action_controller' do ActiveSupport.on_load(:action_controller_base) do include ::InertiaRails::Controller end diff --git a/lib/inertia_rails/helper.rb b/lib/inertia_rails/helper.rb index eb25339d..6701835b 100644 --- a/lib/inertia_rails/helper.rb +++ b/lib/inertia_rails/helper.rb @@ -1,32 +1,36 @@ +# frozen_string_literal: true + require_relative 'inertia_rails' -module InertiaRails::Helper - def inertia_ssr_head - controller.instance_variable_get("@_inertia_ssr_head") - end +module InertiaRails + module Helper + def inertia_ssr_head + controller.instance_variable_get('@_inertia_ssr_head') + end - def inertia_headers - InertiaRails.deprecator.warn( - "`inertia_headers` is deprecated and will be removed in InertiaRails 4.0, use `inertia_ssr_head` instead." - ) - inertia_ssr_head - end + def inertia_headers + InertiaRails.deprecator.warn( + '`inertia_headers` is deprecated and will be removed in InertiaRails 4.0, use `inertia_ssr_head` instead.' + ) + inertia_ssr_head + end - def inertia_rendering? - controller.instance_variable_get("@_inertia_rendering") - end + def inertia_rendering? + controller.instance_variable_get('@_inertia_rendering') + end - def inertia_page - controller.instance_variable_get("@_inertia_page") - end + def inertia_page + controller.instance_variable_get('@_inertia_page') + end - def inertia_meta_tags - meta_tag_data = (inertia_page || {}).dig(:props, :_inertia_meta) || [] + def inertia_meta_tags + meta_tag_data = (inertia_page || {}).dig(:props, :_inertia_meta) || [] - meta_tags = meta_tag_data.map do |inertia_meta_tag| - inertia_meta_tag.to_tag(tag) - end + meta_tags = meta_tag_data.map do |inertia_meta_tag| + inertia_meta_tag.to_tag(tag) + end - safe_join(meta_tags, "\n") + safe_join(meta_tags, "\n") + end end end diff --git a/lib/inertia_rails/lazy_prop.rb b/lib/inertia_rails/lazy_prop.rb index cdb35865..1ea03e21 100644 --- a/lib/inertia_rails/lazy_prop.rb +++ b/lib/inertia_rails/lazy_prop.rb @@ -10,7 +10,7 @@ def initialize(value = nil, &block) ) @value = value - @block = block + super(&block) end def call(controller) diff --git a/lib/inertia_rails/renderer.rb b/lib/inertia_rails/renderer.rb index 36356fbb..3d2359bf 100644 --- a/lib/inertia_rails/renderer.rb +++ b/lib/inertia_rails/renderer.rb @@ -101,7 +101,9 @@ def computed_props end .then { |props| deep_transform_props(props) } # Internal hydration/filtering .then { |props| configuration.prop_transformer(props: props) } # Apply user-defined prop transformer - .tap { |props| props[:_inertia_meta] = meta_tags if meta_tags.present? } # Add meta tags last (never transformed) + .tap do |props| # Add meta tags last (never transformed) + props[:_inertia_meta] = meta_tags if meta_tags.present? + end # rubocop:enable Style/MultilineBlockChain end diff --git a/lib/inertia_rails/rspec.rb b/lib/inertia_rails/rspec.rb index 033e3b1e..9be5d81f 100644 --- a/lib/inertia_rails/rspec.rb +++ b/lib/inertia_rails/rspec.rb @@ -1,30 +1,32 @@ -require "rspec/core" -require "rspec/matchers" +# frozen_string_literal: true + +require 'rspec/core' +require 'rspec/matchers' module InertiaRails module RSpec class InertiaRenderWrapper attr_reader :view_data, :props, :component - + def initialize @view_data = nil @props = nil @component = nil end - + def call(params) - set_values(params) + assign_locals(params) @render_method&.call(params) end - + def wrap_render(render_method) @render_method = render_method self end - + protected - - def set_values(params) + + def assign_locals(params) if params[:locals].present? @view_data = params[:locals].except(:page) @props = params[:locals][:page][:props] @@ -33,18 +35,24 @@ def set_values(params) # Sequential Inertia request @view_data = {} json = JSON.parse(params[:json]) - @props = json["props"] - @component = json["component"] + @props = json['props'] + @component = json['component'] end end end module Helpers def inertia - raise 'Inertia test helpers aren\'t set up! Make sure you add inertia: true to describe blocks using inertia tests.' unless inertia_tests_setup? + unless inertia_tests_setup? + raise "Inertia test helpers aren't set up! " \ + 'Make sure you add `inertia: true` to describe blocks using inertia tests.' + end if @_inertia_render_wrapper.nil? && !::RSpec.configuration.inertia[:skip_missing_renderer_warnings] - warn 'WARNING: the test never created an Inertia renderer. Maybe the code wasn\'t able to reach a `render inertia:` call? If this was intended, or you don\'t want to see this message, set ::RSpec.configuration.inertia[:skip_missing_renderer_warnings] = true' + warn 'WARNING: the test never created an Inertia renderer. ' \ + "Maybe the code wasn't able to reach a `render inertia:` call? If this was intended, " \ + "or you don't want to see this message, " \ + 'set ::RSpec.configuration.inertia[:skip_missing_renderer_warnings] = true' end @_inertia_render_wrapper end @@ -57,8 +65,8 @@ def inertia_wrap_render(render) @_inertia_render_wrapper = InertiaRenderWrapper.new.wrap_render(render) end - protected - + protected + def inertia_tests_setup? ::RSpec.current_example.metadata.fetch(:inertia, false) end @@ -67,9 +75,9 @@ def inertia_tests_setup? end RSpec.configure do |config| - config.include ::InertiaRails::RSpec::Helpers + config.include InertiaRails::RSpec::Helpers config.add_setting :inertia, default: { - skip_missing_renderer_warnings: false + skip_missing_renderer_warnings: false, } config.before(:each, inertia: true) do @@ -106,13 +114,14 @@ def inertia_tests_setup? end failure_message do |inertia| - "expected rendered inertia component to be #{expected_component}, instead received #{inertia.component || 'nothing'}" + "expected rendered inertia component to be #{expected_component}, " \ + "instead received #{inertia.component || 'nothing'}" end end RSpec::Matchers.define :have_exact_view_data do |expected_view_data| match do |inertia| - expect(inertia.view_data).to eq expected_view_data + expect(inertia.view_data).to eq expected_view_data end failure_message do |inertia| diff --git a/lib/inertia_rails/version.rb b/lib/inertia_rails/version.rb index 1649f8c0..909074a0 100644 --- a/lib/inertia_rails/version.rb +++ b/lib/inertia_rails/version.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module InertiaRails - VERSION = "3.11.0" + VERSION = '3.11.0' end diff --git a/lib/patches/better_errors.rb b/lib/patches/better_errors.rb index cf133ae2..2e487710 100644 --- a/lib/patches/better_errors.rb +++ b/lib/patches/better_errors.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Patch BetterErrors::Middleware to render HTML for Inertia requests # # Original source: @@ -7,13 +9,11 @@ module InertiaRails module InertiaBetterErrors def text?(env) - return false if env["HTTP_X_INERTIA"] + return false if env['HTTP_X_INERTIA'] super end end end -if defined?(BetterErrors) - BetterErrors::Middleware.include InertiaRails::InertiaBetterErrors -end +BetterErrors::Middleware.include InertiaRails::InertiaBetterErrors if defined?(BetterErrors) diff --git a/lib/patches/debug_exceptions.rb b/lib/patches/debug_exceptions.rb index 052d45e2..f94078b6 100644 --- a/lib/patches/debug_exceptions.rb +++ b/lib/patches/debug_exceptions.rb @@ -1,17 +1,34 @@ +# frozen_string_literal: true + # Patch ActionDispatch::DebugExceptions to render HTML for Inertia requests # -# Rails has introduced text rendering for XHR requests with Rails 4.1 and -# changed the implementation in 4.2, 5.0 and 5.1 (unchanged since then). -# # The original source needs to be patched, so that Inertia requests are # NOT responded with plain text, but with HTML. +# +# Original source (unchanged since Rails 5.1): +# https://github.com/rails/rails/blob/5-1-stable/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb +# https://github.com/rails/rails/blob/8-0-stable/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb +# -if defined?(ActionDispatch::DebugExceptions) - if ActionPack.version.to_s >= '5.1' - require 'patches/debug_exceptions/patch-5-1' - elsif ActionPack.version.to_s >= '5.0' - require 'patches/debug_exceptions/patch-5-0' - else - # This gem supports Rails 5 or later +module InertiaRails + module InertiaDebugExceptions + def render_for_browser_request(request, wrapper) + template = create_template(request, wrapper) + file = "rescues/#{wrapper.rescue_template}" + + if request.xhr? && !request.headers['X-Inertia'] # <<<< this line is changed only + body = template.render(template: file, layout: false, formats: [:text]) + format = 'text/plain' + else + body = template.render(template: file, layout: 'rescues/layout') + format = 'text/html' + end + + render(wrapper.status_code, body, format) + end end end + +if defined?(ActionDispatch::DebugExceptions) + ActionDispatch::DebugExceptions.prepend InertiaRails::InertiaDebugExceptions +end diff --git a/lib/patches/debug_exceptions/patch-5-0.rb b/lib/patches/debug_exceptions/patch-5-0.rb deleted file mode 100644 index 741f052a..00000000 --- a/lib/patches/debug_exceptions/patch-5-0.rb +++ /dev/null @@ -1,27 +0,0 @@ -# Patch ActionDispatch::DebugExceptions to render HTML for Inertia requests -# -# Original source: -# https://github.com/rails/rails/blob/5-0-stable/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb -# - -module InertiaRails - module InertiaDebugExceptions - def render_for_default_application(request, wrapper) - template = create_template(request, wrapper) - file = "rescues/#{wrapper.rescue_template}" - - if request.xhr? && !request.headers['X-Inertia'] # <<<< this line is changed only - body = template.render(template: file, layout: false, formats: [:text]) - format = "text/plain" - else - body = template.render(template: file, layout: 'rescues/layout') - format = "text/html" - end - render(wrapper.status_code, body, format) - end - end -end - -if defined?(ActionDispatch::DebugExceptions) - ActionDispatch::DebugExceptions.prepend InertiaRails::InertiaDebugExceptions -end diff --git a/lib/patches/debug_exceptions/patch-5-1.rb b/lib/patches/debug_exceptions/patch-5-1.rb deleted file mode 100644 index c22d779c..00000000 --- a/lib/patches/debug_exceptions/patch-5-1.rb +++ /dev/null @@ -1,30 +0,0 @@ -# Patch ActionDispatch::DebugExceptions to render HTML for Inertia requests -# -# Original source (unchanged since Rails 5.1): -# https://github.com/rails/rails/blob/5-1-stable/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb -# https://github.com/rails/rails/blob/5-2-stable/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb -# https://github.com/rails/rails/blob/6-0-stable/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb -# - -module InertiaRails - module InertiaDebugExceptions - def render_for_browser_request(request, wrapper) - template = create_template(request, wrapper) - file = "rescues/#{wrapper.rescue_template}" - - if request.xhr? && !request.headers['X-Inertia'] # <<<< this line is changed only - body = template.render(template: file, layout: false, formats: [:text]) - format = "text/plain" - else - body = template.render(template: file, layout: "rescues/layout") - format = "text/html" - end - - render(wrapper.status_code, body, format) - end - end -end - -if defined?(ActionDispatch::DebugExceptions) - ActionDispatch::DebugExceptions.prepend InertiaRails::InertiaDebugExceptions -end diff --git a/lib/patches/mapper.rb b/lib/patches/mapper.rb index f309903f..dc1dd9b3 100644 --- a/lib/patches/mapper.rb +++ b/lib/patches/mapper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module InertiaRails module InertiaMapper def inertia(*args, **options) @@ -12,7 +14,10 @@ def extract_route_and_component(path) if path.is_a?(Hash) path.first elsif resource_scope? - [path, InertiaRails.configuration.component_path_resolver(path: [@scope[:module], @scope[:controller]].compact.join('/'), action: path)] + [path, + InertiaRails.configuration.component_path_resolver( + path: [@scope[:module], @scope[:controller]].compact.join('/'), action: path + )] elsif @scope[:module].blank? [path, path] else diff --git a/lib/patches/request.rb b/lib/patches/request.rb index e796ae3f..8122a618 100644 --- a/lib/patches/request.rb +++ b/lib/patches/request.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module InertiaRails module InertiaRequest def inertia? diff --git a/lib/tasks/inertia_rails.rake b/lib/tasks/inertia_rails.rake index c626ee4e..b3f1342e 100644 --- a/lib/tasks/inertia_rails.rake +++ b/lib/tasks/inertia_rails.rake @@ -1,16 +1,18 @@ +# frozen_string_literal: true + namespace :inertia_rails do namespace :install do - desc "Installs inertia_rails packages and configurations for a React based app" - task :react => :environment do + desc 'Installs inertia_rails packages and configurations for a React based app' + task react: :environment do system 'rails g inertia_rails:install --front_end react' end - desc "Installs inertia_rails packages and configurations for a Vue based app" + desc 'Installs inertia_rails packages and configurations for a Vue based app' task vue: :environment do system 'rails g inertia_rails:install --front_end vue' end - desc "Installs inertia_rails packages and configurations for a Svelte based app" + desc 'Installs inertia_rails packages and configurations for a Svelte based app' task svelte: :environment do system 'rails g inertia_rails:install --front_end svelte' end end -end \ No newline at end of file +end diff --git a/spec/dummy/Rakefile b/spec/dummy/Rakefile index e85f9139..488c551f 100644 --- a/spec/dummy/Rakefile +++ b/spec/dummy/Rakefile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # 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. diff --git a/spec/dummy/app/controllers/application_controller.rb b/spec/dummy/app/controllers/application_controller.rb index ebd72426..eb7882de 100644 --- a/spec/dummy/app/controllers/application_controller.rb +++ b/spec/dummy/app/controllers/application_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class ApplicationController < ActionController::Base def controller_method 'controller_method value' diff --git a/spec/dummy/app/controllers/concerns/meta_taggable.rb b/spec/dummy/app/controllers/concerns/meta_taggable.rb index 6a9c13c2..96d49435 100644 --- a/spec/dummy/app/controllers/concerns/meta_taggable.rb +++ b/spec/dummy/app/controllers/concerns/meta_taggable.rb @@ -10,18 +10,18 @@ module MetaTaggable def set_meta_tags inertia_meta .add({ - name: 'meta_tag_from_concern', - content: 'This should be overriden by the controller', - head_key: 'meta_tag_from_concern', - }) + name: 'meta_tag_from_concern', + content: 'This should be overriden by the controller', + head_key: 'meta_tag_from_concern', + }) .add({ - name: 'unnecessary_tag', - content: 'This tag will be removed', - head_key: 'unnecessary_tag', - }) + name: 'unnecessary_tag', + content: 'This tag will be removed', + head_key: 'unnecessary_tag', + }) .add({ - name: 'please_remove_me', - content: 'no head_key to target!', - }) + name: 'please_remove_me', + content: 'no head_key to target!', + }) end end diff --git a/spec/dummy/app/controllers/inertia_child_share_test_controller.rb b/spec/dummy/app/controllers/inertia_child_share_test_controller.rb index 13659894..2daa5fa5 100644 --- a/spec/dummy/app/controllers/inertia_child_share_test_controller.rb +++ b/spec/dummy/app/controllers/inertia_child_share_test_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class InertiaChildShareTestController < InertiaShareTestController inertia_share name: 'No Longer Brandon' diff --git a/spec/dummy/app/controllers/inertia_conditional_sharing_controller.rb b/spec/dummy/app/controllers/inertia_conditional_sharing_controller.rb index e4704b78..7e6c1444 100644 --- a/spec/dummy/app/controllers/inertia_conditional_sharing_controller.rb +++ b/spec/dummy/app/controllers/inertia_conditional_sharing_controller.rb @@ -1,37 +1,39 @@ +# frozen_string_literal: true + class InertiaConditionalSharingController < ApplicationController before_action :conditionally_share_a_prop, only: :show_with_a_problem inertia_share normal_shared_prop: 1 inertia_share do - {conditionally_shared_show_prop: 1} if action_name == "show" + { conditionally_shared_show_prop: 1 } if action_name == 'show' end inertia_share only: :edit do - {edit_only_only_block_prop: 1} + { edit_only_only_block_prop: 1 } end - inertia_share except: [:show, :index] do - {edit_only_except_block_prop: 1} + inertia_share except: %i[show index] do + { edit_only_except_block_prop: 1 } end inertia_share if: -> { is_edit? } do - {edit_only_if_proc_prop: 1} + { edit_only_if_proc_prop: 1 } end inertia_share unless: -> { !is_edit? } do - {edit_only_unless_proc_prop: 1} + { edit_only_unless_proc_prop: 1 } end - inertia_share({edit_only_only_prop: 1}, only: :edit) + inertia_share({ edit_only_only_prop: 1 }, only: :edit) - inertia_share({edit_only_if_prop: 1}, if: [:is_edit?, -> { true }]) + inertia_share({ edit_only_if_prop: 1 }, if: [:is_edit?, -> { true }]) - inertia_share({edit_only_unless_prop: 1}, unless: :not_edit?) + inertia_share({ edit_only_unless_prop: 1 }, unless: :not_edit?) - inertia_share({edit_only_only_if_prop: 1}, only: :edit, if: -> { true }) + inertia_share({ edit_only_only_if_prop: 1 }, only: :edit, if: -> { true }) - inertia_share({edit_only_except_if_prop: 1}, except: [:index, :show], if: -> { true }) + inertia_share({ edit_only_except_if_prop: 1 }, except: %i[index show], if: -> { true }) def index render inertia: 'EmptyTestComponent', props: { @@ -68,6 +70,6 @@ def not_edit? end def is_edit? - action_name == "edit" + action_name == 'edit' end end diff --git a/spec/dummy/app/controllers/inertia_config_test_controller.rb b/spec/dummy/app/controllers/inertia_config_test_controller.rb index 6744926d..18950b50 100644 --- a/spec/dummy/app/controllers/inertia_config_test_controller.rb +++ b/spec/dummy/app/controllers/inertia_config_test_controller.rb @@ -1,16 +1,18 @@ +# frozen_string_literal: true + class InertiaConfigTestController < ApplicationController inertia_config( deep_merge_shared_data: true, ssr_enabled: true, - ssr_url: "http://localhost:7777", - layout: "test", - version: "1.0", - encrypt_history: false, + ssr_url: 'http://localhost:7777', + layout: 'test', + version: '1.0', + encrypt_history: false ) # Test that modules included in the same class can also call it. inertia_config( - version: "2.0", + version: '2.0' ) def configuration diff --git a/spec/dummy/app/controllers/inertia_lambda_shared_props_controller.rb b/spec/dummy/app/controllers/inertia_lambda_shared_props_controller.rb index 956749fe..3c26e535 100644 --- a/spec/dummy/app/controllers/inertia_lambda_shared_props_controller.rb +++ b/spec/dummy/app/controllers/inertia_lambda_shared_props_controller.rb @@ -1,12 +1,14 @@ +# frozen_string_literal: true + class InertiaLambdaSharedPropsController < ApplicationController - inertia_share someProperty: -> { + inertia_share someProperty: lambda { { - property_a: "some value", - property_b: "this value" + property_a: 'some value', + property_b: 'this value', } } def lamda_shared_props - render inertia: 'ShareTestComponent', props: { property_c: "some other value" } + render inertia: 'ShareTestComponent', props: { property_c: 'some other value' } end end diff --git a/spec/dummy/app/controllers/inertia_merge_instance_props_controller.rb b/spec/dummy/app/controllers/inertia_merge_instance_props_controller.rb index 854d1d37..d5e03134 100644 --- a/spec/dummy/app/controllers/inertia_merge_instance_props_controller.rb +++ b/spec/dummy/app/controllers/inertia_merge_instance_props_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class InertiaMergeInstancePropsController < ApplicationController use_inertia_instance_props inertia_share do @@ -5,7 +7,7 @@ class InertiaMergeInstancePropsController < ApplicationController nested: { points: 55, rebounds: 10, - } + }, } end diff --git a/spec/dummy/app/controllers/inertia_merge_shared_controller.rb b/spec/dummy/app/controllers/inertia_merge_shared_controller.rb index 5e8a9920..54c1217f 100644 --- a/spec/dummy/app/controllers/inertia_merge_shared_controller.rb +++ b/spec/dummy/app/controllers/inertia_merge_shared_controller.rb @@ -1,10 +1,12 @@ +# frozen_string_literal: true + class InertiaMergeSharedController < ApplicationController inertia_share do { nested: { goals: 100, assists: 100, - } + }, } end @@ -12,7 +14,7 @@ def merge_shared render inertia: 'ShareTestComponent', props: { nested: { assists: 200, - } + }, } end @@ -20,7 +22,7 @@ def deep_merge_shared render inertia: 'ShareTestComponent', props: { nested: { assists: 300, - } + }, }, deep_merge: true end @@ -28,7 +30,7 @@ def shallow_merge_shared render inertia: 'ShareTestComponent', props: { nested: { assists: 200, - } + }, }, deep_merge: false end end diff --git a/spec/dummy/app/controllers/inertia_meta_controller.rb b/spec/dummy/app/controllers/inertia_meta_controller.rb index 10e3a808..f475196c 100644 --- a/spec/dummy/app/controllers/inertia_meta_controller.rb +++ b/spec/dummy/app/controllers/inertia_meta_controller.rb @@ -3,7 +3,7 @@ class InertiaMetaController < ApplicationController include MetaTaggable - before_action :set_description_meta_tag, only: [:from_before_filter, :cleared_meta] + before_action :set_description_meta_tag, only: %i[from_before_filter cleared_meta] before_action :set_deduplicatable_tags, only: :auto_dedup inertia_config( @@ -38,10 +38,10 @@ def with_duplicate_head_keys def override_tags_from_module inertia_meta.add({ - name: 'meta_tag_from_concern', - content: 'This is overriden by the controller', - head_key: 'meta_tag_from_concern', - }) + name: 'meta_tag_from_concern', + content: 'This is overriden by the controller', + head_key: 'meta_tag_from_concern', + }) inertia_meta.remove('unnecessary_tag') @@ -94,10 +94,10 @@ def meta_with_default_render def set_description_meta_tag inertia_meta.add({ - name: 'description', - content: 'This is a description set from a before filter', - head_key: 'before_filter_tag', - }) + name: 'description', + content: 'This is a description set from a before filter', + head_key: 'before_filter_tag', + }) end def set_deduplicatable_tags diff --git a/spec/dummy/app/controllers/inertia_multithreaded_share_controller.rb b/spec/dummy/app/controllers/inertia_multithreaded_share_controller.rb index e2a3978a..f7e5ebde 100644 --- a/spec/dummy/app/controllers/inertia_multithreaded_share_controller.rb +++ b/spec/dummy/app/controllers/inertia_multithreaded_share_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class InertiaMultithreadedShareController < ApplicationController inertia_share name: 'Michael' inertia_share has_goat_status: true @@ -8,6 +10,6 @@ def share_multithreaded end def share_multithreaded_error - raise Exception + raise StandardError end end diff --git a/spec/dummy/app/controllers/inertia_rails_mimic_controller.rb b/spec/dummy/app/controllers/inertia_rails_mimic_controller.rb index e3d05c21..27b5de10 100644 --- a/spec/dummy/app/controllers/inertia_rails_mimic_controller.rb +++ b/spec/dummy/app/controllers/inertia_rails_mimic_controller.rb @@ -1,6 +1,8 @@ +# frozen_string_literal: true + class InertiaRailsMimicController < ApplicationController inertia_config( - default_render: -> { action_name == "default_render_test" }, + default_render: -> { action_name == 'default_render_test' } ) use_inertia_instance_props diff --git a/spec/dummy/app/controllers/inertia_responders_test_controller.rb b/spec/dummy/app/controllers/inertia_responders_test_controller.rb index d286834e..a1fc3e9c 100644 --- a/spec/dummy/app/controllers/inertia_responders_test_controller.rb +++ b/spec/dummy/app/controllers/inertia_responders_test_controller.rb @@ -1,7 +1,8 @@ +# frozen_string_literal: true + require 'responders' -class Thing -end +Thing = Class.new class InertiaRespondersTestController < ApplicationController self.responder = ActionController::Responder diff --git a/spec/dummy/app/controllers/inertia_session_continuity_test_controller.rb b/spec/dummy/app/controllers/inertia_session_continuity_test_controller.rb index 43d4ffc3..baabd5d9 100644 --- a/spec/dummy/app/controllers/inertia_session_continuity_test_controller.rb +++ b/spec/dummy/app/controllers/inertia_session_continuity_test_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class InertiaSessionContinuityTestController < ApplicationController def initialize_session render inertia: 'TestNewSessionComponent' @@ -10,6 +12,6 @@ def submit_form_to_test_csrf def clear_session session.clear - return redirect_to initialize_session_path + redirect_to initialize_session_path end end diff --git a/spec/dummy/app/controllers/inertia_share_test_controller.rb b/spec/dummy/app/controllers/inertia_share_test_controller.rb index 1569952d..67fc030a 100644 --- a/spec/dummy/app/controllers/inertia_share_test_controller.rb +++ b/spec/dummy/app/controllers/inertia_share_test_controller.rb @@ -1,7 +1,9 @@ +# frozen_string_literal: true + class InertiaShareTestController < ApplicationController inertia_share name: 'Brandon' inertia_share sport: -> { 'hockey' } - inertia_share({a_hash: 'also works'}) + inertia_share({ a_hash: 'also works' }) inertia_share do { position: 'center', diff --git a/spec/dummy/app/controllers/inertia_test_controller.rb b/spec/dummy/app/controllers/inertia_test_controller.rb index e8f7bc2b..4ad554e7 100644 --- a/spec/dummy/app/controllers/inertia_test_controller.rb +++ b/spec/dummy/app/controllers/inertia_test_controller.rb @@ -1,5 +1,7 @@ +# frozen_string_literal: true + class MyError - def to_hash() { uh: 'oh' } end + def to_hash = { uh: 'oh' } end class InertiaTestController < ApplicationController @@ -69,18 +71,18 @@ def redirect_back_or_to_with_inertia_errors ) end - def error_404 + def error_404 # rubocop:disable Naming/VariableNumber render inertia: 'ErrorComponent', status: 404 end - def error_500 + def error_500 # rubocop:disable Naming/VariableNumber render inertia: 'ErrorComponent', status: 500 end def content_type_test respond_to do |format| format.html { render inertia: 'EmptyTestComponent' } - format.xml { render xml: [ 1, 2, 3 ] } + format.xml { render xml: [1, 2, 3] } end end diff --git a/spec/dummy/app/controllers/transformed_inertia_rails_mimic_controller.rb b/spec/dummy/app/controllers/transformed_inertia_rails_mimic_controller.rb index 4861bcf0..3f8ecf7b 100644 --- a/spec/dummy/app/controllers/transformed_inertia_rails_mimic_controller.rb +++ b/spec/dummy/app/controllers/transformed_inertia_rails_mimic_controller.rb @@ -1,11 +1,12 @@ +# frozen_string_literal: true + class TransformedInertiaRailsMimicController < ApplicationController inertia_config( default_render: true, - component_path_resolver: ->(path:, action:) do + component_path_resolver: lambda do |path:, action:| "#{path.camelize}/#{action.camelize}" end ) - def render_test - end + def render_test; end end diff --git a/spec/dummy/app/helpers/application_helper.rb b/spec/dummy/app/helpers/application_helper.rb index de6be794..15b06f0f 100644 --- a/spec/dummy/app/helpers/application_helper.rb +++ b/spec/dummy/app/helpers/application_helper.rb @@ -1,2 +1,4 @@ +# frozen_string_literal: true + module ApplicationHelper end diff --git a/spec/dummy/bin/rails b/spec/dummy/bin/rails index 07396602..a31728ab 100755 --- a/spec/dummy/bin/rails +++ b/spec/dummy/bin/rails @@ -1,4 +1,6 @@ #!/usr/bin/env ruby +# frozen_string_literal: true + APP_PATH = File.expand_path('../config/application', __dir__) require_relative '../config/boot' require 'rails/commands' diff --git a/spec/dummy/bin/rake b/spec/dummy/bin/rake index 17240489..c1999550 100755 --- a/spec/dummy/bin/rake +++ b/spec/dummy/bin/rake @@ -1,4 +1,6 @@ #!/usr/bin/env ruby +# frozen_string_literal: true + require_relative '../config/boot' require 'rake' Rake.application.run diff --git a/spec/dummy/bin/setup b/spec/dummy/bin/setup index 0e39e8cb..65a6ca72 100755 --- a/spec/dummy/bin/setup +++ b/spec/dummy/bin/setup @@ -1,4 +1,6 @@ #!/usr/bin/env ruby +# frozen_string_literal: true + require 'fileutils' # path to your application root. diff --git a/spec/dummy/config.ru b/spec/dummy/config.ru index f7ba0b52..842bccc3 100644 --- a/spec/dummy/config.ru +++ b/spec/dummy/config.ru @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # This file is used by Rack-based servers to start the application. require_relative 'config/environment' diff --git a/spec/dummy/config/application.rb b/spec/dummy/config/application.rb index 1ea383c3..8078371b 100644 --- a/spec/dummy/config/application.rb +++ b/spec/dummy/config/application.rb @@ -1,12 +1,14 @@ +# frozen_string_literal: true + require_relative 'boot' -require "rails" +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_controller/railtie' # require "action_mailer/railtie" # require "action_mailbox/engine" # require "action_text/engine" @@ -16,7 +18,7 @@ # require "rails/test_unit/railtie" Bundler.require(*Rails.groups) -require "inertia_rails" +require 'inertia_rails' module Dummy class Application < Rails::Application diff --git a/spec/dummy/config/boot.rb b/spec/dummy/config/boot.rb index c9aef85d..6d2cba07 100644 --- a/spec/dummy/config/boot.rb +++ b/spec/dummy/config/boot.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Set up gems listed in the Gemfile. ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../Gemfile', __dir__) diff --git a/spec/dummy/config/environment.rb b/spec/dummy/config/environment.rb index 426333bb..d5abe558 100644 --- a/spec/dummy/config/environment.rb +++ b/spec/dummy/config/environment.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Load the Rails application. require_relative 'application' diff --git a/spec/dummy/config/environments/development.rb b/spec/dummy/config/environments/development.rb index dad857f7..90a2fdd1 100644 --- a/spec/dummy/config/environments/development.rb +++ b/spec/dummy/config/environments/development.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. @@ -20,7 +22,7 @@ config.cache_store = :memory_store config.public_file_server.headers = { - 'Cache-Control' => "public, max-age=#{2.days.to_i}" + 'Cache-Control' => "public, max-age=#{2.days.to_i}", } else config.action_controller.perform_caching = false diff --git a/spec/dummy/config/environments/production.rb b/spec/dummy/config/environments/production.rb index f4222484..a657ec3a 100644 --- a/spec/dummy/config/environments/production.rb +++ b/spec/dummy/config/environments/production.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. @@ -48,7 +50,7 @@ config.log_level = :debug # Prepend all log lines with the following tags. - config.log_tags = [ :request_id ] + config.log_tags = [:request_id] # Use a different cache store in production. # config.cache_store = :mem_cache_store @@ -65,14 +67,14 @@ config.active_support.deprecation = :notify # Use default logging formatter so that PID and timestamp are not suppressed. - config.log_formatter = ::Logger::Formatter.new + config.log_formatter = Logger::Formatter.new # Use a different logger for distributed setups. # require 'syslog/logger' # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') - if ENV["RAILS_LOG_TO_STDOUT"].present? - logger = ActiveSupport::Logger.new(STDOUT) + if ENV['RAILS_LOG_TO_STDOUT'].present? + logger = ActiveSupport::Logger.new($stdout) logger.formatter = config.log_formatter config.logger = ActiveSupport::TaggedLogging.new(logger) end diff --git a/spec/dummy/config/environments/test.rb b/spec/dummy/config/environments/test.rb index 0e16e721..2670d3a7 100644 --- a/spec/dummy/config/environments/test.rb +++ b/spec/dummy/config/environments/test.rb @@ -1,6 +1,6 @@ -if Gem::Version.new(Rails::VERSION::STRING) >= Gem::Version.new('6.1.0') - require 'active_support/core_ext/integer/time' -end +# frozen_string_literal: true + +require 'active_support/core_ext/integer/time' if Gem::Version.new(Rails::VERSION::STRING) >= Gem::Version.new('6.1.0') # The test environment is used exclusively to run your application's # test suite. You never need to work with it otherwise. Remember that @@ -9,7 +9,7 @@ Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. - + config.cache_classes = false # Do not eager load code on boot. This avoids loading your whole application @@ -20,7 +20,7 @@ # Configure public file server for tests with Cache-Control for performance. config.public_file_server.enabled = true config.public_file_server.headers = { - 'Cache-Control' => "public, max-age=#{1.hour.to_i}" + 'Cache-Control' => "public, max-age=#{1.hour.to_i}", } # Show full error reports and disable caching. diff --git a/spec/dummy/config/initializers/application_controller_renderer.rb b/spec/dummy/config/initializers/application_controller_renderer.rb index 89d2efab..6d56e439 100644 --- a/spec/dummy/config/initializers/application_controller_renderer.rb +++ b/spec/dummy/config/initializers/application_controller_renderer.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Be sure to restart your server when you modify this file. # ActiveSupport::Reloader.to_prepare do diff --git a/spec/dummy/config/initializers/backtrace_silencers.rb b/spec/dummy/config/initializers/backtrace_silencers.rb index 59385cdf..4b63f289 100644 --- a/spec/dummy/config/initializers/backtrace_silencers.rb +++ b/spec/dummy/config/initializers/backtrace_silencers.rb @@ -1,3 +1,5 @@ +# 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. diff --git a/spec/dummy/config/initializers/content_security_policy.rb b/spec/dummy/config/initializers/content_security_policy.rb index 41c43016..87fd451f 100644 --- a/spec/dummy/config/initializers/content_security_policy.rb +++ b/spec/dummy/config/initializers/content_security_policy.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Be sure to restart your server when you modify this file. # Define an application-wide content security policy diff --git a/spec/dummy/config/initializers/cookies_serializer.rb b/spec/dummy/config/initializers/cookies_serializer.rb index 5a6a32d3..ee8dff9c 100644 --- a/spec/dummy/config/initializers/cookies_serializer.rb +++ b/spec/dummy/config/initializers/cookies_serializer.rb @@ -1,3 +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. diff --git a/spec/dummy/config/initializers/filter_parameter_logging.rb b/spec/dummy/config/initializers/filter_parameter_logging.rb index 4a994e1e..7a4f47b4 100644 --- a/spec/dummy/config/initializers/filter_parameter_logging.rb +++ b/spec/dummy/config/initializers/filter_parameter_logging.rb @@ -1,3 +1,5 @@ +# 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. diff --git a/spec/dummy/config/initializers/inflections.rb b/spec/dummy/config/initializers/inflections.rb index ac033bf9..dc847422 100644 --- a/spec/dummy/config/initializers/inflections.rb +++ b/spec/dummy/config/initializers/inflections.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Be sure to restart your server when you modify this file. # Add new inflection rules using the following format. Inflections diff --git a/spec/dummy/config/initializers/mime_types.rb b/spec/dummy/config/initializers/mime_types.rb index dc189968..be6fedc5 100644 --- a/spec/dummy/config/initializers/mime_types.rb +++ b/spec/dummy/config/initializers/mime_types.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Be sure to restart your server when you modify this file. # Add new mime types for use in respond_to blocks: diff --git a/spec/dummy/config/initializers/wrap_parameters.rb b/spec/dummy/config/initializers/wrap_parameters.rb index bbfc3961..2f3c0db4 100644 --- a/spec/dummy/config/initializers/wrap_parameters.rb +++ b/spec/dummy/config/initializers/wrap_parameters.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Be sure to restart your server when you modify this file. # This file contains settings for ActionController::ParamsWrapper which diff --git a/spec/dummy/config/puma.rb b/spec/dummy/config/puma.rb index 5ed44377..69e2645f 100644 --- a/spec/dummy/config/puma.rb +++ b/spec/dummy/config/puma.rb @@ -1,23 +1,25 @@ +# frozen_string_literal: true + # Puma can serve each request in a thread from an internal thread pool. # The `threads` method setting takes two numbers: a minimum and maximum. # Any libraries that use thread pools should be configured to match # the maximum value specified for Puma. Default is set to 5 threads for minimum # and maximum; this matches the default thread size of Active Record. # -max_threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 } -min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count } +max_threads_count = ENV.fetch('RAILS_MAX_THREADS', 5) +min_threads_count = ENV.fetch('RAILS_MIN_THREADS') { max_threads_count } threads min_threads_count, max_threads_count # Specifies the `port` that Puma will listen on to receive requests; default is 3000. # -port ENV.fetch("PORT") { 3000 } +port ENV.fetch('PORT', 3000) # Specifies the `environment` that Puma will run in. # -environment ENV.fetch("RAILS_ENV") { "development" } +environment ENV.fetch('RAILS_ENV', 'development') # Specifies the `pidfile` that Puma will use. -pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" } +pidfile ENV.fetch('PIDFILE', 'tmp/pids/server.pid') # Specifies the number of `workers` to boot in clustered mode. # Workers are forked web server processes. If using threads and workers together diff --git a/spec/dummy/config/routes.rb b/spec/dummy/config/routes.rb index 8dae460e..131a1de3 100644 --- a/spec/dummy/config/routes.rb +++ b/spec/dummy/config/routes.rb @@ -1,5 +1,7 @@ +# frozen_string_literal: true + Rails.application.routes.draw do - mount InertiaRails::Engine => "/inertia-rails" + mount InertiaRails::Engine => '/inertia-rails' get 'configuration' => 'inertia_config_test#configuration' get 'props' => 'inertia_render_test#props' @@ -47,14 +49,15 @@ get 'prop_transformer_no_props_test' => 'inertia_prop_transformer#no_props' get 'default_component_test' => 'inertia_rails_mimic#default_component_test' get 'default_component_with_props_test' => 'inertia_rails_mimic#default_component_with_props_test' - get 'default_component_with_duplicated_props_test' => 'inertia_rails_mimic#default_component_with_duplicated_props_test' + get 'default_component_with_duplicated_props_test' => + 'inertia_rails_mimic#default_component_with_duplicated_props_test' get 'provided_props_test' => 'inertia_rails_mimic#provided_props_test' post 'redirect_to_share_test' => 'inertia_test#redirect_to_share_test' inertia 'inertia_route' => 'TestComponent' inertia :inertia_route_with_default_component - scope :scoped, as: "scoped" do + scope :scoped, as: 'scoped' do inertia 'inertia_route' => 'TestComponent' end namespace :namespaced do @@ -65,7 +68,7 @@ inertia :inertia_route_with_default_component inertia :inertia_route_with_default_component_on_member, on: :member inertia :inertia_route_with_default_component_on_collection, on: :collection - scope :scoped, as: "scoped" do + scope :scoped, as: 'scoped' do inertia :inertia_route_with_default_component end end diff --git a/spec/dummy/config/spring.rb b/spec/dummy/config/spring.rb index db5bf130..93cd0ff8 100644 --- a/spec/dummy/config/spring.rb +++ b/spec/dummy/config/spring.rb @@ -1,6 +1,8 @@ +# frozen_string_literal: true + Spring.watch( - ".ruby-version", - ".rbenv-vars", - "tmp/restart.txt", - "tmp/caching-dev.txt" + '.ruby-version', + '.rbenv-vars', + 'tmp/restart.txt', + 'tmp/caching-dev.txt' ) diff --git a/spec/generators/generators_helper_spec.rb b/spec/generators/generators_helper_spec.rb index 4d244ad0..da3e6a13 100644 --- a/spec/generators/generators_helper_spec.rb +++ b/spec/generators/generators_helper_spec.rb @@ -5,7 +5,9 @@ RSpec.describe InertiaRails::Generators::Helper, type: :helper do describe '#guess_the_default_framework' do - let(:package_json_path) { Pathname.new(File.expand_path("spec/fixtures/package_json_files/#{fixture_file_name}", Dir.pwd)) } + let(:package_json_path) do + Pathname.new(File.expand_path("spec/fixtures/package_json_files/#{fixture_file_name}", Dir.pwd)) + end shared_examples 'framework detection' do |file_name, expected_framework| let(:fixture_file_name) { file_name } @@ -36,7 +38,9 @@ end describe '#guess_inertia_template' do - let(:package_json_path) { Pathname.new(File.expand_path("spec/fixtures/package_json_files/#{fixture_file_name}", Dir.pwd)) } + let(:package_json_path) do + Pathname.new(File.expand_path("spec/fixtures/package_json_files/#{fixture_file_name}", Dir.pwd)) + end shared_examples 'template detection' do |file_name, expected_template| let(:fixture_file_name) { file_name } diff --git a/spec/inertia/action_filter_spec.rb b/spec/inertia/action_filter_spec.rb index 6a351872..47eeca4b 100644 --- a/spec/inertia/action_filter_spec.rb +++ b/spec/inertia/action_filter_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # spec/lib/inertia_rails/action_filter_spec.rb require 'rails_helper' @@ -46,9 +48,9 @@ :only option. MSG - expect { + expect do filter.match?(controller) - }.to raise_error(AbstractController::ActionNotFound, expected_message) + end.to raise_error(AbstractController::ActionNotFound, expected_message) end end end diff --git a/spec/inertia/always_prop_spec.rb b/spec/inertia/always_prop_spec.rb index 62b820bb..846ad4c1 100644 --- a/spec/inertia/always_prop_spec.rb +++ b/spec/inertia/always_prop_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + RSpec.describe InertiaRails::AlwaysProp do it_behaves_like 'base prop' end diff --git a/spec/inertia/base_prop_spec.rb b/spec/inertia/base_prop_spec.rb index 079f5524..6c5ae9a7 100644 --- a/spec/inertia/base_prop_spec.rb +++ b/spec/inertia/base_prop_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + RSpec.describe InertiaRails::BaseProp do it_behaves_like 'base prop' end diff --git a/spec/inertia/conditional_sharing_spec.rb b/spec/inertia/conditional_sharing_spec.rb index 62dc8410..a5c104d5 100644 --- a/spec/inertia/conditional_sharing_spec.rb +++ b/spec/inertia/conditional_sharing_spec.rb @@ -1,7 +1,9 @@ +# frozen_string_literal: true + # Specs as documentation. Per-action shared data isn't explicity supported, # but it can be done by referencing the action name in an inertia_share block. -RSpec.describe "conditionally shared data in a controller", type: :request do - context "when there is data inside inertia_share only applicable to a single action" do +RSpec.describe 'conditionally shared data in a controller', type: :request do + context 'when there is data inside inertia_share only applicable to a single action' do let(:edit_only_props) do { edit_only_only_block_prop: 1, @@ -30,26 +32,26 @@ } end - it "does not leak the data between requests" do - get conditional_share_show_path, headers: {'X-Inertia' => true} - expect(JSON.parse(response.body)['props'].deep_symbolize_keys).to eq(show_only_props.merge(normal_shared_prop: 1)) + it 'does not leak the data between requests' do + get conditional_share_show_path, headers: { 'X-Inertia' => true } + expect(JSON.parse(response.body)['props'].symbolize_keys).to eq(show_only_props.merge(normal_shared_prop: 1)) - get conditional_share_index_path, headers: {'X-Inertia' => true} - expect(JSON.parse(response.body)['props'].deep_symbolize_keys).to eq(index_only_props.merge(normal_shared_prop: 1)) + get conditional_share_index_path, headers: { 'X-Inertia' => true } + expect(JSON.parse(response.body)['props'].symbolize_keys).to eq(index_only_props.merge(normal_shared_prop: 1)) get conditional_share_edit_path, headers: { 'X-Inertia' => true } - expect(JSON.parse(response.body)['props'].deep_symbolize_keys).to eq(edit_only_props.merge(normal_shared_prop: 1)) + expect(JSON.parse(response.body)['props'].symbolize_keys).to eq(edit_only_props.merge(normal_shared_prop: 1)) end end - context "when there is conditional data shared via before_action" do - it "raises an error because it is frozen" do + context 'when there is conditional data shared via before_action' do + it 'raises an error because it is frozen' do # InertiaSharedData isn't frozen until after the first time it's accessed. InertiaConditionalSharingController.send(:_inertia_shared_data) - expect { - get conditional_share_show_with_a_problem_path, headers: {'X-Inertia' => true} - }.to raise_error(FrozenError) + expect do + get conditional_share_show_with_a_problem_path, headers: { 'X-Inertia' => true } + end.to raise_error(FrozenError) end end end diff --git a/spec/inertia/error_sharing_spec.rb b/spec/inertia/error_sharing_spec.rb index a8c95fe2..1862b942 100644 --- a/spec/inertia/error_sharing_spec.rb +++ b/spec/inertia/error_sharing_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + RSpec.describe 'errors shared automatically', type: :request do context 'always_include_errors_hash configuration' do let(:server_version) { 1.0 } @@ -53,11 +55,11 @@ end context 'rendering errors across redirects' do - let(:server_version){ 1.0 } - let(:headers){ { 'X-Inertia' => true, 'X-Inertia-Version' => server_version } } + let(:server_version) { 1.0 } + let(:headers) { { 'X-Inertia' => true, 'X-Inertia-Version' => server_version } } - before { InertiaRails.configure{|c| c.version = server_version} } - after { InertiaRails.configure{|c| c.version = nil } } + before { InertiaRails.configure { |c| c.version = server_version } } + after { InertiaRails.configure { |c| c.version = nil } } it 'automatically renders errors in inertia' do post redirect_with_inertia_errors_path, headers: headers @@ -95,7 +97,7 @@ # Simulate the page refresh that Inertia triggers in response to a 409 get empty_test_path - expect(response.body).to include(CGI::escape_html({ errors: { uh: 'oh' } }.to_json)) + expect(response.body).to include(CGI.escape_html({ errors: { uh: 'oh' } }.to_json)) expect(session[:inertia_errors]).not_to be end diff --git a/spec/inertia/helper_spec.rb b/spec/inertia/helper_spec.rb index 5450c19d..452bd6c8 100644 --- a/spec/inertia/helper_spec.rb +++ b/spec/inertia/helper_spec.rb @@ -22,13 +22,17 @@ describe '#inertia_meta_tags' do context 'basic rendering' do before do - controller.instance_variable_set(:@_inertia_page, { - props: { - _inertia_meta: [ - InertiaRails::MetaTag.new(name: 'description', content: 'Inertia rules', head_key: 'my_key') - ], - }, - }) + controller.instance_variable_set( + :@_inertia_page, + { + props: { + _inertia_meta: [ + InertiaRails::MetaTag.new(name: 'description', content: 'Inertia rules', + head_key: 'my_key') + ], + }, + } + ) end it 'generates a meta tag' do @@ -38,21 +42,33 @@ context 'with multiple meta tags' do before do - controller.instance_variable_set(:@_inertia_page, { - props: { - _inertia_meta: [ - InertiaRails::MetaTag.new(tag_name: 'title', inner_content: 'Inertia Page Title', head_key: 'meta-12345678'), - InertiaRails::MetaTag.new(name: 'description', content: 'Inertia rules', head_key: 'meta-23456789'), - InertiaRails::MetaTag.new(tag_name: 'script', type: 'application/ld+json', inner_content: { '@context': 'https://schema.org' }, head_key: 'meta-34567890') - ], - }, - }) + controller.instance_variable_set( + :@_inertia_page, + { + props: { + _inertia_meta: [ + InertiaRails::MetaTag.new( + tag_name: 'title', inner_content: 'Inertia Page Title', head_key: 'meta-12345678' + ), + InertiaRails::MetaTag.new( + name: 'description', content: 'Inertia rules', head_key: 'meta-23456789' + ), + InertiaRails::MetaTag.new( + tag_name: 'script', type: 'application/ld+json', + inner_content: { '@context': 'https://schema.org' }, head_key: 'meta-34567890' + ) + ], + }, + } + ) end it 'generates multiple meta tags' do - expect(helper.inertia_meta_tags).to include("Inertia Page Title\n") - expect(helper.inertia_meta_tags).to include("\n") - expect(helper.inertia_meta_tags).to include('') + expect(helper.inertia_meta_tags).to include( + "Inertia Page Title\n", + "\n", + '' + ) end end end diff --git a/spec/inertia/lazy_prop_spec.rb b/spec/inertia/lazy_prop_spec.rb index 0828d7cb..f182febf 100644 --- a/spec/inertia/lazy_prop_spec.rb +++ b/spec/inertia/lazy_prop_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + RSpec.describe InertiaRails::LazyProp do it_behaves_like 'base prop' @@ -8,7 +10,8 @@ end it 'is deprecated' do - expect(deprecator).to receive(:warn).with('`lazy` is deprecated and will be removed in InertiaRails 4.0, use `optional` instead.') + expect(deprecator).to receive(:warn) + .with('`lazy` is deprecated and will be removed in InertiaRails 4.0, use `optional` instead.') described_class.new('value') end diff --git a/spec/inertia/meta_tag_rendering_spec.rb b/spec/inertia/meta_tag_rendering_spec.rb index af03cbfc..b7a7f2d0 100644 --- a/spec/inertia/meta_tag_rendering_spec.rb +++ b/spec/inertia/meta_tag_rendering_spec.rb @@ -88,14 +88,16 @@ it 'overrides the meta tag set from the module' do get override_tags_from_module_meta_path, headers: headers - expect(response.parsed_body['props']['_inertia_meta']).to eq([ - { - 'tagName' => 'meta', - 'name' => 'meta_tag_from_concern', - 'content' => 'This is overriden by the controller', - 'headKey' => 'meta_tag_from_concern', - } - ]) + expect(response.parsed_body['props']['_inertia_meta']).to eq( + [ + { + 'tagName' => 'meta', + 'name' => 'meta_tag_from_concern', + 'content' => 'This is overriden by the controller', + 'headKey' => 'meta_tag_from_concern', + } + ] + ) end end diff --git a/spec/inertia/meta_tag_spec.rb b/spec/inertia/meta_tag_spec.rb index 96b97eda..2c6fcfc1 100644 --- a/spec/inertia/meta_tag_spec.rb +++ b/spec/inertia/meta_tag_spec.rb @@ -18,7 +18,8 @@ end it 'transforms snake_case keys to camelCase' do - meta_tag = described_class.new(head_key: dummy_head_key, http_equiv: 'content-security-policy', content: "default-src 'self'") + meta_tag = described_class.new(head_key: dummy_head_key, http_equiv: 'content-security-policy', + content: "default-src 'self'") expected_json = { tagName: :meta, @@ -31,7 +32,8 @@ end it 'handles JSON LD content' do - meta_tag = described_class.new(tag_name: 'script', head_key: dummy_head_key, type: 'application/ld+json', inner_content: { '@context': 'https://schema.org' }) + meta_tag = described_class.new(tag_name: 'script', head_key: dummy_head_key, type: 'application/ld+json', + inner_content: { '@context': 'https://schema.org' }) expected_json = { tagName: :script, @@ -44,7 +46,8 @@ end it 'marks executable script tags with text/plain' do - meta_tag = described_class.new(tag_name: 'script', head_key: dummy_head_key, inner_content: '', type: 'application/javascript') + meta_tag = described_class.new(tag_name: 'script', head_key: dummy_head_key, + inner_content: '', type: 'application/javascript') expected_json = { tagName: :script, @@ -113,8 +116,9 @@ context 'with allow_duplicates set to true' do it 'generates a head key with a unique suffix' do meta_tag = described_class.new(name: 'description', content: 'Inertia rules', allow_duplicates: true) + expected_hash = Digest::MD5.hexdigest('content=Inertia rules&name=description')[0, 8] - expect(meta_tag.as_json[:headKey]).to eq("meta-name-description-#{Digest::MD5.hexdigest('content=Inertia rules&name=description')[0, 8]}") + expect(meta_tag.as_json[:headKey]).to eq("meta-name-description-#{expected_hash}") end end end @@ -127,7 +131,8 @@ end it 'renders kebab case' do - meta_tag = described_class.new(tag_name: :meta, head_key: dummy_head_key, http_equiv: 'X-UA-Compatible', content: 'IE=edge') + meta_tag = described_class.new(tag_name: :meta, head_key: dummy_head_key, http_equiv: 'X-UA-Compatible', + content: 'IE=edge') tag = meta_tag.to_tag(tag_helper) @@ -136,7 +141,8 @@ describe 'script tag rendering' do it 'renders JSON LD content correctly' do - meta_tag = described_class.new(tag_name: :script, head_key: dummy_head_key, type: 'application/ld+json', inner_content: { '@context': 'https://schema.org' }) + meta_tag = described_class.new(tag_name: :script, head_key: dummy_head_key, type: 'application/ld+json', + inner_content: { '@context': 'https://schema.org' }) tag = meta_tag.to_tag(tag_helper) @@ -144,7 +150,8 @@ end it 'adds text/plain and escapes all other script tags' do - meta_tag = described_class.new(tag_name: :script, head_key: dummy_head_key, type: 'application/javascript', inner_content: 'alert("XSS")') + meta_tag = described_class.new(tag_name: :script, head_key: dummy_head_key, type: 'application/javascript', + inner_content: 'alert("XSS")') tag = meta_tag.to_tag(tag_helper) @@ -165,7 +172,8 @@ end it 'escapes inner content for non-script tags' do - meta_tag = described_class.new(tag_name: :div, head_key: dummy_head_key, inner_content: '') + meta_tag = described_class.new(tag_name: :div, head_key: dummy_head_key, + inner_content: '') tag = meta_tag.to_tag(tag_helper) diff --git a/spec/inertia/prop_transformer_spec.rb b/spec/inertia/prop_transformer_spec.rb index 5ccb1fac..c0dad3ae 100644 --- a/spec/inertia/prop_transformer_spec.rb +++ b/spec/inertia/prop_transformer_spec.rb @@ -15,11 +15,11 @@ expect_inertia.to render_component('TestComponent') .and have_exact_props({ - 'LOWER_PROP' => 'lower_value', - 'PARENT_HASH' => { - 'LOWER_CHILD_PROP' => 'lower_child_value', - }, - }) + 'LOWER_PROP' => 'lower_value', + 'PARENT_HASH' => { + 'LOWER_CHILD_PROP' => 'lower_child_value', + }, + }) end end @@ -29,8 +29,8 @@ expect_inertia.to render_component('TestComponent') .and include_props({ - 'LOWER_PROP' => 'lower_value', - }) + 'LOWER_PROP' => 'lower_value', + }) end it 'does not transform the meta' do diff --git a/spec/inertia/rails_mimic_spec.rb b/spec/inertia/rails_mimic_spec.rb index 773d3794..9d83ad41 100644 --- a/spec/inertia/rails_mimic_spec.rb +++ b/spec/inertia/rails_mimic_spec.rb @@ -1,12 +1,13 @@ +# frozen_string_literal: true + require_relative '../../lib/inertia_rails/rspec' RSpec.describe 'rendering when mimicking rails behavior', type: :request, inertia: true do - context 'the props are provided by instance variables' do it 'has the props' do get instance_props_test_path - expect_inertia.to have_exact_props({name: 'Brandon', sport: 'hockey'}) + expect_inertia.to have_exact_props({ name: 'Brandon', sport: 'hockey' }) end end @@ -14,7 +15,7 @@ it 'only includes the provided props' do get provided_props_test_path - expect_inertia.to have_exact_props({'sport': 'basketball'}) + expect_inertia.to have_exact_props({ sport: 'basketball' }) end end @@ -29,13 +30,13 @@ get default_component_with_props_test_path expect_inertia.to render_component('inertia_rails_mimic/default_component_with_props_test') - .and have_exact_props({my: 'props'}) + .and have_exact_props({ my: 'props' }) end it 'raises an error when props as properties are provided' do - expect { + expect do get default_component_with_duplicated_props_test_path - }.to raise_error(ArgumentError, 'Parameter `props` is not allowed when passing a Hash as the first argument') + end.to raise_error(ArgumentError, 'Parameter `props` is not allowed when passing a Hash as the first argument') end end @@ -44,7 +45,7 @@ get default_render_test_path expect_inertia.to render_component('inertia_rails_mimic/default_render_test') - expect_inertia.to include_props({name: 'Brian'}) + expect_inertia.to include_props({ name: 'Brian' }) end context 'a rendering transformation is provided' do @@ -56,4 +57,3 @@ end end end - diff --git a/spec/inertia/rendering_spec.rb b/spec/inertia/rendering_spec.rb index d4c9f791..c75a929b 100644 --- a/spec/inertia/rendering_spec.rb +++ b/spec/inertia/rendering_spec.rb @@ -541,10 +541,21 @@ 'deep_merge' => { 'deep' => 'merge prop' }, 'deep_match_on' => { 'deep' => [{ 'id' => 1 }] }, 'regular' => 'regular prop' ) - expect(response.parsed_body['mergeProps']).to match_array(%w[merge match_on deferred_merge deferred_match_on]) - expect(response.parsed_body['deepMergeProps']).to match_array(%w[deep_merge deep_match_on deferred_deep_merge deferred_deep_match_on]) - expect(response.parsed_body['deferredProps']).to eq('default' => %w[deferred_merge deferred_match_on deferred_deep_merge deferred_deep_match_on deferred]) - expect(response.parsed_body['matchPropsOn']).to match_array(%w[deep_match_on.deep.id deferred_deep_match_on.deep.id deferred_match_on.id match_on.id]) + expect(response.parsed_body['mergeProps']).to match_array( + %w[merge match_on deferred_merge deferred_match_on] + ) + expect(response.parsed_body['deepMergeProps']).to match_array( + %w[deep_merge deep_match_on deferred_deep_merge + deferred_deep_match_on] + ) + expect(response.parsed_body['deferredProps']).to eq( + 'default' => %w[deferred_merge deferred_match_on + deferred_deep_merge deferred_deep_match_on deferred] + ) + expect(response.parsed_body['matchPropsOn']).to match_array( + %w[deep_match_on.deep.id deferred_deep_match_on.deep.id + deferred_match_on.id match_on.id] + ) end context 'with a partial reload' do @@ -566,7 +577,8 @@ expect(response.parsed_body['mergeProps']).to match_array(%w[deferred_merge deferred_match_on]) expect(response.parsed_body['deepMergeProps']).to match_array(%w[deferred_deep_merge deferred_deep_match_on]) expect(response.parsed_body['deferredProps']).to be_nil - expect(response.parsed_body['matchPropsOn']).to match_array(%w[deferred_deep_match_on.deep.id deferred_match_on.id]) + expect(response.parsed_body['matchPropsOn']).to match_array(%w[deferred_deep_match_on.deep.id + deferred_match_on.id]) end end diff --git a/spec/inertia/request_spec.rb b/spec/inertia/request_spec.rb index 36036797..c0b24ae1 100644 --- a/spec/inertia/request_spec.rb +++ b/spec/inertia/request_spec.rb @@ -1,16 +1,18 @@ +# frozen_string_literal: true + RSpec.describe 'Inertia::Request', type: :request do describe 'it tests whether a call is an inertia call' do subject { response.status } before { get inertia_request_test_path, headers: headers } context 'it is an inertia call' do - let(:headers) { {'X-Inertia' => true} } + let(:headers) { { 'X-Inertia' => true } } it { is_expected.to eq 202 } end context 'it is not an inertia call' do - let(:headers) { Hash.new } + let(:headers) { {} } it { is_expected.to eq 200 } end @@ -21,7 +23,9 @@ before { get inertia_partial_request_test_path, headers: headers } context 'it is a partial inertia call' do - let(:headers) { { 'X-Inertia' => true, 'X-Inertia-Partial-Component' => 'Component', 'X-Inertia-Partial-Data' => 'foo,bar,baz' } } + let(:headers) do + { 'X-Inertia' => true, 'X-Inertia-Partial-Component' => 'Component', 'X-Inertia-Partial-Data' => 'foo,bar,baz' } + end it { is_expected.to eq 202 } end @@ -72,13 +76,13 @@ before { get content_type_test_path, headers: headers } context 'it is an inertia call' do - let(:headers) { {'X-Inertia' => true} } + let(:headers) { { 'X-Inertia' => true } } it { is_expected.to eq 'application/json' } end context 'it is not an inertia call' do - let(:headers) { Hash.new } + let(:headers) { {} } it { is_expected.to eq 'text/html' } end @@ -107,22 +111,22 @@ end context 'it is not an inertia call' do - let(:headers) { Hash.new } + let(:headers) { {} } it { is_expected.to include('XSRF-TOKEN') } end context 'it is an inertia call' do - let(:headers){ { 'X-Inertia' => true } } + let(:headers) { { 'X-Inertia' => true } } it { is_expected.to include('XSRF-TOKEN') } end end - describe 'copying an X-XSRF-Token header (like Axios sends by default) into the X-CSRF-Token header (that Rails looks for by default)' do + describe 'copying an X-XSRF-Token header (Axios default) into the X-CSRF-Token header (Rails default)' do subject { request.headers['X-CSRF-Token'] } before { get inertia_request_test_path, headers: headers } context 'it is an inertia call' do - let(:headers) {{ 'X-Inertia' => true, 'X-XSRF-Token' => 'foo' }} + let(:headers) { { 'X-Inertia' => true, 'X-XSRF-Token' => 'foo' } } it { is_expected.to eq 'foo' } end @@ -138,7 +142,8 @@ expect(response).to have_http_status(:ok) initial_xsrf_token_cookie = response.cookies['XSRF-TOKEN'] - post submit_form_to_test_csrf_path, headers: { 'X-Inertia' => true, 'X-XSRF-Token' => initial_xsrf_token_cookie } + post submit_form_to_test_csrf_path, + headers: { 'X-Inertia' => true, 'X-XSRF-Token' => initial_xsrf_token_cookie } expect(response).to have_http_status(:ok) delete clear_session_path, headers: { 'X-Inertia' => true, 'X-XSRF-Token' => initial_xsrf_token_cookie } @@ -149,7 +154,8 @@ expect(post_logout_xsrf_token_cookie).not_to be_nil expect(post_logout_xsrf_token_cookie).not_to eq(initial_xsrf_token_cookie) - post submit_form_to_test_csrf_path, headers: { 'X-Inertia' => true, 'X-XSRF-Token' => post_logout_xsrf_token_cookie } + post submit_form_to_test_csrf_path, + headers: { 'X-Inertia' => true, 'X-XSRF-Token' => post_logout_xsrf_token_cookie } expect(response).to have_http_status(:ok) end end @@ -157,9 +163,9 @@ describe 'a non existent route' do it 'raises a 404 exception' do - expect { + expect do get '/non_existent_route', headers: { 'X-Inertia' => true } - }.to raise_error(ActionController::RoutingError, /No route matches/) + end.to raise_error(ActionController::RoutingError, /No route matches/) end end end diff --git a/spec/inertia/response_spec.rb b/spec/inertia/response_spec.rb index 2a37f5e5..395f2b74 100644 --- a/spec/inertia/response_spec.rb +++ b/spec/inertia/response_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + RSpec.describe 'InertiaRails::Response', type: :request do describe 'inertia location response' do it 'returns an inertia location response' do @@ -12,7 +14,7 @@ context 'with an [:inertia][:errors] option' do # In practice, a GET -> redirect + errors probably shouldn't happen context 'with a get request' do - it 'adds :inertia_errors to the session' do + it 'adds :inertia_errors to the session' do get redirect_with_inertia_errors_path expect(response.status).to eq 302 expect(response.headers['Location']).to eq(empty_test_url) @@ -30,7 +32,7 @@ it 'serializes :inertia_errors to the session' do post redirect_with_inertia_error_object_path, - headers: { 'X-Inertia' => true } + headers: { 'X-Inertia' => true } expect(response.status).to eq 302 expect(response.headers['Location']).to eq(empty_test_url) @@ -48,7 +50,7 @@ redirect_back_with_inertia_errors_path, headers: { 'X-Inertia' => true, - 'HTTP_REFERER' => "http://www.example.com/current-path" + 'HTTP_REFERER' => 'http://www.example.com/current-path', } ) expect(response.status).to eq 302 @@ -63,13 +65,13 @@ context 'with an [:inertia][:errors] option' do context 'with a post request' do it 'adds :inertia_errors to the session' do - skip("Requires Rails 7.0 or higher") if Rails.version < '7' + skip('Requires Rails 7.0 or higher') if Rails.version < '7' post( redirect_back_or_to_with_inertia_errors_path, headers: { 'X-Inertia' => true, - 'HTTP_REFERER' => "http://www.example.com/current-path" + 'HTTP_REFERER' => 'http://www.example.com/current-path', } ) expect(response.status).to eq 302 diff --git a/spec/inertia/rspec_helper_spec.rb b/spec/inertia/rspec_helper_spec.rb index e05cd635..c371a74f 100644 --- a/spec/inertia/rspec_helper_spec.rb +++ b/spec/inertia/rspec_helper_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative '../../lib/inertia_rails/rspec' class FakeStdErr @@ -12,8 +14,7 @@ def write(msg) end # Rails 5.0 + Ruby 2.6 require puts to be a public method - def puts(thing) - end + def puts(thing); end end RSpec.describe InertiaRails::RSpec, type: :request do @@ -22,11 +23,11 @@ def puts(thing) before { get props_path } it 'has props' do - expect_inertia.to have_exact_props({name: 'Brandon', sport: 'hockey'}) + expect_inertia.to have_exact_props({ name: 'Brandon', sport: 'hockey' }) end it 'includes props' do - expect_inertia.to include_props({sport: 'hockey'}) + expect_inertia.to include_props({ sport: 'hockey' }) end it 'can retrieve props' do @@ -35,18 +36,18 @@ def puts(thing) end context 'with props during sequential request' do - before { get props_path, headers: {'X-Inertia': true} } + before { get props_path, headers: { 'X-Inertia': true } } it 'has props' do - expect_inertia.to have_exact_props({"name" => 'Brandon', "sport" => 'hockey'}) + expect_inertia.to have_exact_props({ 'name' => 'Brandon', 'sport' => 'hockey' }) end it 'includes props' do - expect_inertia.to include_props({"sport" => 'hockey'}) + expect_inertia.to include_props({ 'sport' => 'hockey' }) end it 'can retrieve props' do - expect(inertia.props["name"]).to eq 'Brandon' + expect(inertia.props['name']).to eq 'Brandon' end end @@ -54,11 +55,11 @@ def puts(thing) before { get view_data_path } it 'has view data' do - expect_inertia.to have_exact_view_data({name: 'Brian', sport: 'basketball'}) + expect_inertia.to have_exact_view_data({ name: 'Brian', sport: 'basketball' }) end it 'includes view data' do - expect_inertia.to include_view_data({sport: 'basketball'}) + expect_inertia.to include_view_data({ sport: 'basketball' }) end it 'can retrieve view data' do @@ -97,36 +98,36 @@ def puts(thing) # h/t for this technique: # https://blog.arkency.com/testing-deprecations-warnings-with-rspec/ it 'warns that the renderer was never created' do - begin + original_stderr = $stderr + fake_std_err = FakeStdErr.new + $stderr = fake_std_err + expect_inertia + warn_message = + 'WARNING: the test never created an Inertia renderer. ' \ + "Maybe the code wasn't able to reach a `render inertia:` call? If this was intended, " \ + "or you don't want to see this message, set " \ + '::RSpec.configuration.inertia[:skip_missing_renderer_warnings] = true' + expect(fake_std_err.messages[0].chomp).to(eq(warn_message)) + ensure + $stderr = original_stderr + end + + context 'with the :skip_missing_renderer_warnings setting set to true' do + before do + @original = RSpec.configuration.inertia[:skip_missing_renderer_warnings] + RSpec.configuration.inertia[:skip_missing_renderer_warnings] = true + end + after do + RSpec.configuration.inertia[:skip_missing_renderer_warnings] = @original + end + it 'skips the warning' do original_stderr = $stderr fake_std_err = FakeStdErr.new $stderr = fake_std_err expect_inertia - warn_message = 'WARNING: the test never created an Inertia renderer. Maybe the code wasn\'t able to reach a `render inertia:` call? If this was intended, or you don\'t want to see this message, set ::RSpec.configuration.inertia[:skip_missing_renderer_warnings] = true' - expect(fake_std_err.messages[0].chomp).to(eq(warn_message)) + expect(fake_std_err.messages).to be_empty ensure - $std_err = original_stderr - end - end - - context 'with the :skip_missing_renderer_warnings setting set to true' do - before { - @original = ::RSpec.configuration.inertia[:skip_missing_renderer_warnings] - ::RSpec.configuration.inertia[:skip_missing_renderer_warnings] = true - } - after { - ::RSpec.configuration.inertia[:skip_missing_renderer_warnings] = @original - } - it 'skips the warning' do - begin - original_stderr = $stderr - fake_std_err = FakeStdErr.new - $stderr = fake_std_err - expect_inertia - expect(fake_std_err.messages).to be_empty - ensure - $std_err = original_stderr - end + $stderr = original_stderr end end end @@ -136,13 +137,13 @@ def puts(thing) it 'compares props with either string or symbol keys' do get lamda_shared_props_path - expect_inertia.to have_exact_props({ + expect_inertia.to have_exact_props( someProperty: { - property_a: "some value", - property_b: "this value", + property_a: 'some value', + property_b: 'this value', }, - property_c: "some other value" - }) + property_c: 'some other value' + ) end end end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 03e1f42e..568635ec 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -1,16 +1,18 @@ +# frozen_string_literal: true + require 'spec_helper' # Requiring logger fixes an issue between concurrent-ruby and activesupport in Rails < 7.1 # https://github.com/rails/rails/issues/54260 require 'logger' ENV['RAILS_ENV'] ||= 'test' -require File.expand_path('../dummy/config/environment', __FILE__) +require File.expand_path('dummy/config/environment', __dir__) # Allow using `debugger` to debug failing tests. require 'debug' # Prevent database truncation if the environment is production -abort("The Rails environment is running in production mode!") if Rails.env.production? +abort('The Rails environment is running in production mode!') if Rails.env.production? require 'rspec/rails' # Require the spec/support directory and its subdirectories. Dir[Pathname.new(__dir__).join('support', '**', '*.rb')].each { |f| require f } diff --git a/spec/support/shared_examples.rb b/spec/support/shared_examples.rb index ac3fe284..10921fda 100644 --- a/spec/support/shared_examples.rb +++ b/spec/support/shared_examples.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + RSpec.shared_examples 'base prop' do describe '#call' do subject(:call) { prop.call(controller) }