From 960192c921b3db18c8e9dd20b0ba57d42d83c17b Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Mon, 6 May 2024 23:01:47 +0200 Subject: [PATCH] Use StandardRb as Ruby linter --- .github/workflows/lint.yml | 21 ++ .rubocop.yml | 308 +----------------- .standard.yml | 5 + Gemfile | 5 +- alchemy-json_api.gemspec | 1 + .../json_api/admin/layout_pages_controller.rb | 1 + .../json_api/admin/pages_controller.rb | 3 +- .../alchemy/json_api/base_controller.rb | 5 +- .../json_api/layout_pages_controller.rb | 1 + .../alchemy/json_api/nodes_controller.rb | 6 +- .../alchemy/json_api/pages_controller.rb | 30 +- .../alchemy/json_api/element_serializer.rb | 3 +- .../json_api/ingredient_audio_serializer.rb | 2 +- .../json_api/ingredient_picture_serializer.rb | 8 +- .../ingredient_richtext_serializer.rb | 2 +- .../json_api/ingredient_text_serializer.rb | 2 +- .../json_api/ingredient_video_serializer.rb | 2 +- .../alchemy/json_api/language_serializer.rb | 3 +- .../alchemy/json_api/node_serializer.rb | 3 +- .../alchemy/json_api/page_serializer.rb | 3 +- config/routes.rb | 9 +- lib/alchemy/json_api/engine.rb | 1 + lib/alchemy/json_api/essence_serializer.rb | 1 + .../essence_serializer_behaviour.rb | 5 +- .../ingredient_serializer_behaviour.rb | 2 +- lib/alchemy/json_api/version.rb | 1 + lib/tasks/alchemy/json_api_tasks.rake | 1 + .../json_api/admin/pages_controller_spec.rb | 2 +- spec/rails_helper.rb | 1 + .../json_api/admin/layout_pages_spec.rb | 19 +- .../alchemy/json_api/admin/pages_spec.rb | 13 +- .../alchemy/json_api/layout_pages_spec.rb | 9 +- spec/requests/alchemy/json_api/nodes_spec.rb | 15 +- spec/requests/alchemy/json_api/pages_spec.rb | 45 +-- spec/routing/layout_page_routing_spec.rb | 8 +- spec/routing/page_routing_spec.rb | 8 +- .../json_api/element_serializer_spec.rb | 15 +- .../ingredient_audio_serializer_spec.rb | 2 +- .../ingredient_file_serializer_spec.rb | 1 + .../ingredient_headline_serializer_spec.rb | 4 +- .../ingredient_html_serializer_spec.rb | 1 + .../ingredient_link_serializer_spec.rb | 2 +- .../ingredient_node_serializer_spec.rb | 2 +- .../ingredient_page_serializer_spec.rb | 2 +- .../ingredient_picture_serializer_spec.rb | 28 +- .../ingredient_richtext_serializer_spec.rb | 2 +- .../ingredient_text_serializer_spec.rb | 1 + .../ingredient_video_serializer_spec.rb | 2 +- .../json_api/language_serializer_spec.rb | 9 +- .../alchemy/json_api/node_serializer_spec.rb | 11 +- .../alchemy/json_api/page_serializer_spec.rb | 19 +- spec/spec_helper.rb | 1 + 52 files changed, 206 insertions(+), 450 deletions(-) create mode 100644 .github/workflows/lint.yml create mode 100644 .standard.yml diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..1a7dd9d --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,21 @@ +name: Lint + +on: [pull_request] + +concurrency: + group: lint-${{ github.ref_name }} + cancel-in-progress: ${{ github.ref_name != 'main' }} + +jobs: + Standard: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + - name: Install Ruby and gems + uses: ruby/setup-ruby@v1 + with: + ruby-version: "3.0" + bundler-cache: true + - name: Lint Ruby files + run: bundle exec standardrb diff --git a/.rubocop.yml b/.rubocop.yml index 68a2c8a..6faf5db 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,307 +1,7 @@ -# Relaxed.Ruby.Style +require: standard AllCops: - TargetRubyVersion: 2.4 - Exclude: - - 'bin/rspec' - - 'vendor/**/*' - - 'spec/dummy/db/**/*' - - 'spec/dummy/config/**/*' - - 'alchemy_cms.gemspec' - - 'Rakefile' - - 'node_modules/**/*' + TargetRubyVersion: 3.0 -# Really, rubocop? -Bundler/OrderedGems: - Enabled: false - -Style/EmptyLiteral: - Enabled: false - -# We use class vars and will have to continue doing so for compatability -Style/ClassVars: - Enabled: false - -Style/FloatDivision: - EnforcedStyle: left_coerce - -# This has been used for customization -Style/MutableConstant: - Enabled: false - -Style/ClassAndModuleChildren: - Enabled: false - -Style/GuardClause: - Enabled: false - -# We support older versions of Ruby (2.1) that do not have the %i syntax -Style/SymbolArray: - Enabled: false - -Style/SymbolProc: - Exclude: - - 'lib/alchemy/permissions.rb' - -Style/WordArray: - Enabled: false - -Style/ConditionalAssignment: - Enabled: false - -Style/MixinUsage: - Exclude: - - spec/**/* - -Layout/ArgumentAlignment: - Enabled: false - -Layout/HashAlignment: - Enabled: false - -Layout/ParameterAlignment: - Enabled: false - -Layout/ClosingParenthesisIndentation: - Enabled: false - -Layout/DotPosition: - Enabled: false - StyleGuide: http://relaxed.ruby.style/#styledotposition - -Layout/ElseAlignment: - Enabled: false - -Layout/EmptyLineAfterMagicComment: - Enabled: false - -Layout/FirstArrayElementIndentation: - Enabled: false - -Layout/FirstHashElementIndentation: - Enabled: false - -Layout/IndentationWidth: - Enabled: false - -Layout/LineLength: - Enabled: false - -Layout/MultilineHashBraceLayout: - Enabled: false - -Layout/MultilineMethodCallBraceLayout: - Enabled: false - -Layout/MultilineMethodCallIndentation: - Enabled: false - -Layout/MultilineOperationIndentation: - EnforcedStyle: indented - -Layout/SpaceBeforeBlockBraces: - Enabled: false - StyleGuide: http://relaxed.ruby.style/#stylespacebeforeblockbraces - -Layout/SpaceInsideHashLiteralBraces: - Enabled: false - -Layout/SpaceInsideParens: - Enabled: false - StyleGuide: http://relaxed.ruby.style/#stylespaceinsideparens - -Layout/EndAlignment: - Enabled: false - -Layout/RescueEnsureAlignment: - Enabled: false - -Lint/SuppressedException: - Exclude: - - 'config/initializers/mini_profiler.rb' - -Style/CollectionMethods: - Enabled: false - -Style/Alias: - Enabled: false - StyleGuide: http://relaxed.ruby.style/#stylealias - -Style/BeginBlock: - Enabled: false - StyleGuide: http://relaxed.ruby.style/#stylebeginblock - -Style/BlockDelimiters: - Enabled: false - StyleGuide: http://relaxed.ruby.style/#styleblockdelimiters - -Style/Documentation: - Enabled: false - StyleGuide: http://relaxed.ruby.style/#styledocumentation - -Style/DoubleNegation: - Enabled: false - StyleGuide: http://relaxed.ruby.style/#styledoublenegation - -Style/EmptyMethod: - Enabled: false - -Style/EndBlock: - Enabled: false - StyleGuide: http://relaxed.ruby.style/#styleendblock - -Style/FormatString: - Enabled: false - StyleGuide: http://relaxed.ruby.style/#styleformatstring - -Style/IfUnlessModifier: - Enabled: false - StyleGuide: http://relaxed.ruby.style/#styleifunlessmodifier - -Style/Lambda: - Enabled: false - StyleGuide: http://relaxed.ruby.style/#stylelambda - -Style/ModuleFunction: - Enabled: false - StyleGuide: http://relaxed.ruby.style/#stylemodulefunction - -Style/MultilineBlockChain: - Enabled: false - StyleGuide: http://relaxed.ruby.style/#stylemultilineblockchain - -Style/NegatedIf: - Enabled: false - StyleGuide: http://relaxed.ruby.style/#stylenegatedif - -Style/NegatedWhile: - Enabled: false - StyleGuide: http://relaxed.ruby.style/#stylenegatedwhile - -Style/NumericLiteralPrefix: - Enabled: false - -Style/ParallelAssignment: - Enabled: false - StyleGuide: http://relaxed.ruby.style/#styleparallelassignment - -Style/PercentLiteralDelimiters: - Enabled: false - StyleGuide: http://relaxed.ruby.style/#stylepercentliteraldelimiters - -Style/PerlBackrefs: - Enabled: false - StyleGuide: http://relaxed.ruby.style/#styleperlbackrefs - -Style/RegexpLiteral: - Enabled: false - -Style/Semicolon: - Enabled: false - StyleGuide: http://relaxed.ruby.style/#stylesemicolon - -Style/SignalException: - Enabled: false - StyleGuide: http://relaxed.ruby.style/#stylesignalexception - -Style/SingleLineBlockParams: - Enabled: false - StyleGuide: http://relaxed.ruby.style/#stylesinglelineblockparams - -Style/SingleLineMethods: - Enabled: false - StyleGuide: http://relaxed.ruby.style/#stylesinglelinemethods - -Style/SpecialGlobalVars: - Enabled: false - StyleGuide: http://relaxed.ruby.style/#stylespecialglobalvars - -Style/StringLiterals: - EnforcedStyle: double_quotes - -Style/StringLiteralsInInterpolation: - EnforcedStyle: double_quotes - -Style/TrailingCommaInArguments: - EnforcedStyleForMultiline: comma - -Style/TrailingCommaInArrayLiteral: - EnforcedStyleForMultiline: comma - -Style/TrailingCommaInHashLiteral: - EnforcedStyleForMultiline: consistent_comma - -Style/WhileUntilModifier: - Enabled: false - StyleGuide: http://relaxed.ruby.style/#stylewhileuntilmodifier - -# We use a lot of -# -# expect { -# something -# }.to { happen } -# -# syntax in the specs files. -Lint/AmbiguousBlockAssociation: - Exclude: - - 'spec/**/*' - -Lint/AmbiguousRegexpLiteral: - Enabled: false - StyleGuide: http://relaxed.ruby.style/#lintambiguousregexpliteral - -Lint/AssignmentInCondition: - Enabled: false - StyleGuide: http://relaxed.ruby.style/#lintassignmentincondition - -# We use eval to get the correct url proxy object of engines in: -# - app/helpers/alchemy/admin/navigation_helper.rb:139 -# - lib/alchemy/resources_helper.rb:24 -Security/Eval: - Exclude: - - app/helpers/alchemy/admin/navigation_helper.rb - - lib/alchemy/resources_helper.rb - -Metrics/AbcSize: - Enabled: false - -Metrics/BlockLength: - Enabled: false - -Metrics/BlockNesting: - Enabled: false - -Metrics/ClassLength: - Enabled: false - -Metrics/ModuleLength: - Enabled: false - -Metrics/CyclomaticComplexity: - Enabled: false - -Metrics/MethodLength: - Enabled: false - -Metrics/ParameterLists: - Enabled: false - -Metrics/PerceivedComplexity: - Enabled: false - -Naming/AccessorMethodName: - Enabled: false - -Naming/HeredocDelimiterNaming: - Enabled: false - -# This cop is great but has no config option to support the style `@_method_name` we are using. -Naming/MemoizedInstanceVariableName: - Enabled: false - -# We need these names for backwards compatability -Naming/PredicateName: - Enabled: false - -Naming/VariableNumber: - Enabled: false +inherit_gem: + standard: config/base.yml diff --git a/.standard.yml b/.standard.yml new file mode 100644 index 0000000..7e46ec6 --- /dev/null +++ b/.standard.yml @@ -0,0 +1,5 @@ +parallel: true +format: progress +ruby_version: 3.0 +ignore: + - "spec/dummy/**/*" diff --git a/Gemfile b/Gemfile index e4c9b27..a3dbb18 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,5 @@ # frozen_string_literal: true + source "https://rubygems.org" git_source(:github) { |repo| "https://github.com/#{repo}.git" } @@ -20,6 +21,6 @@ alchemy_branch = ENV.fetch("ALCHEMY_BRANCH", "main") gem "alchemy_cms", github: "AlchemyCMS/alchemy_cms", branch: alchemy_branch gem "alchemy-devise", github: "AlchemyCMS/alchemy-devise", branch: "main" -gem "rufo" -gem "rubocop" +gem "rubocop", require: false +gem "standard", "~> 1.25", require: false gem "pry-byebug" diff --git a/alchemy-json_api.gemspec b/alchemy-json_api.gemspec index ce1950a..d66b89e 100644 --- a/alchemy-json_api.gemspec +++ b/alchemy-json_api.gemspec @@ -1,4 +1,5 @@ # frozen_string_literal: true + $:.push File.expand_path("lib", __dir__) # Maintain your gem's version: diff --git a/app/controllers/alchemy/json_api/admin/layout_pages_controller.rb b/app/controllers/alchemy/json_api/admin/layout_pages_controller.rb index 18cc438..4dcf488 100644 --- a/app/controllers/alchemy/json_api/admin/layout_pages_controller.rb +++ b/app/controllers/alchemy/json_api/admin/layout_pages_controller.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module Alchemy module JsonApi module Admin diff --git a/app/controllers/alchemy/json_api/admin/pages_controller.rb b/app/controllers/alchemy/json_api/admin/pages_controller.rb index 92dc383..0bf5660 100644 --- a/app/controllers/alchemy/json_api/admin/pages_controller.rb +++ b/app/controllers/alchemy/json_api/admin/pages_controller.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module Alchemy module JsonApi module Admin @@ -13,7 +14,7 @@ def cache_duration end def caching_options - { public: false, must_revalidate: true } + {public: false, must_revalidate: true} end def set_current_preview diff --git a/app/controllers/alchemy/json_api/base_controller.rb b/app/controllers/alchemy/json_api/base_controller.rb index 6aa404a..10eb88d 100644 --- a/app/controllers/alchemy/json_api/base_controller.rb +++ b/app/controllers/alchemy/json_api/base_controller.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module Alchemy module JsonApi class BaseController < ::ApplicationController @@ -11,7 +12,7 @@ class BaseController < ::ApplicationController rescue_from( CanCan::AccessDenied, - with: :render_jsonapi_unauthorized, + with: :render_jsonapi_unauthorized ) private @@ -32,7 +33,7 @@ def log_error(exception) end def render_jsonapi_unauthorized(exception) - error = { status: "401", title: Rack::Utils::HTTP_STATUS_CODES[401] } + error = {status: "401", title: Rack::Utils::HTTP_STATUS_CODES[401]} render jsonapi_errors: [error], status: :unauthorized end end diff --git a/app/controllers/alchemy/json_api/layout_pages_controller.rb b/app/controllers/alchemy/json_api/layout_pages_controller.rb index 59e7b93..a4e361d 100644 --- a/app/controllers/alchemy/json_api/layout_pages_controller.rb +++ b/app/controllers/alchemy/json_api/layout_pages_controller.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module Alchemy module JsonApi class LayoutPagesController < JsonApi::PagesController diff --git a/app/controllers/alchemy/json_api/nodes_controller.rb b/app/controllers/alchemy/json_api/nodes_controller.rb index 5a417c3..0ce2e59 100644 --- a/app/controllers/alchemy/json_api/nodes_controller.rb +++ b/app/controllers/alchemy/json_api/nodes_controller.rb @@ -11,7 +11,7 @@ def index end end - expires_in cache_duration, { public: true, must_revalidate: true } + expires_in cache_duration, {public: true, must_revalidate: true} end private @@ -25,7 +25,7 @@ def jsonapi_meta(nodes) { pagination: pagination.presence, - total: node_scope.count, + total: node_scope.count }.compact end @@ -37,7 +37,7 @@ def node_scope_with_includes if params[:include].present? includes = params[:include].split(",").map do |association| association.split(".").reverse.inject({}) do |value, key| - { key.to_sym => value } + {key.to_sym => value} end end node_scope.includes(includes) diff --git a/app/controllers/alchemy/json_api/pages_controller.rb b/app/controllers/alchemy/json_api/pages_controller.rb index 2f219ff..850ee4c 100644 --- a/app/controllers/alchemy/json_api/pages_controller.rb +++ b/app/controllers/alchemy/json_api/pages_controller.rb @@ -17,7 +17,7 @@ def index end end - expires_in cache_duration, { public: @pages.none?(&:restricted?) }.merge(caching_options) + expires_in cache_duration, {public: @pages.none?(&:restricted?)}.merge(caching_options) end def show @@ -30,7 +30,7 @@ def show render jsonapi: api_page(load_page) end - expires_in cache_duration, { public: !@page.restricted? }.merge(caching_options) + expires_in cache_duration, {public: !@page.restricted?}.merge(caching_options) end private @@ -51,13 +51,13 @@ def cache_duration end def caching_options - { must_revalidate: true } + {must_revalidate: true} end # Get page w/o includes to get cache key def load_page_for_cache_key - @page = page_scope.where(id: params[:path]). - or(page_scope.where(urlname: params[:path])).first! + @page = page_scope.where(id: params[:path]) + .or(page_scope.where(urlname: params[:path])).first! end def last_modified_for(page) @@ -69,7 +69,7 @@ def jsonapi_meta(pages) { pagination: pagination.presence, - total: page_scope.count, + total: page_scope.count }.compact end @@ -78,7 +78,7 @@ def load_page end def load_page_by_id - return unless params[:path] =~ /\A\d+\z/ + return unless /\A\d+\z/.match?(params[:path]) page_scope_with_includes.find_by(id: params[:path]) end @@ -92,20 +92,20 @@ def page_scope end def page_scope_with_includes - page_scope. - includes( + page_scope + .includes( [ :legacy_urls, - { language: { nodes: [:parent, :children, { page: { language: { site: :languages } } }] } }, + {language: {nodes: [:parent, :children, {page: {language: {site: :languages}}}]}}, { page_version_type => { elements: [ :nested_elements, - { ingredients: :related_object }, - ], - }, - }, - ], + {ingredients: :related_object} + ] + } + } + ] ) end diff --git a/app/serializers/alchemy/json_api/element_serializer.rb b/app/serializers/alchemy/json_api/element_serializer.rb index 97a1a6d..9624f31 100644 --- a/app/serializers/alchemy/json_api/element_serializer.rb +++ b/app/serializers/alchemy/json_api/element_serializer.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module Alchemy module JsonApi class ElementSerializer < BaseSerializer @@ -7,7 +8,7 @@ class ElementSerializer < BaseSerializer :fixed, :position, :created_at, - :updated_at, + :updated_at ) cache_options store: Rails.cache, namespace: "alchemy-jsonapi" diff --git a/app/serializers/alchemy/json_api/ingredient_audio_serializer.rb b/app/serializers/alchemy/json_api/ingredient_audio_serializer.rb index 526863a..d5e3fb8 100644 --- a/app/serializers/alchemy/json_api/ingredient_audio_serializer.rb +++ b/app/serializers/alchemy/json_api/ingredient_audio_serializer.rb @@ -11,7 +11,7 @@ class IngredientAudioSerializer < BaseSerializer :autoplay, :controls, :muted, - :loop, + :loop ) attribute :value do |ingredient| diff --git a/app/serializers/alchemy/json_api/ingredient_picture_serializer.rb b/app/serializers/alchemy/json_api/ingredient_picture_serializer.rb index 88fea00..62ae44f 100644 --- a/app/serializers/alchemy/json_api/ingredient_picture_serializer.rb +++ b/app/serializers/alchemy/json_api/ingredient_picture_serializer.rb @@ -12,7 +12,7 @@ class IngredientPictureSerializer < BaseSerializer :caption, :link_class_name, :link_title, - :link_target, + :link_target ) attribute :value do |ingredient| @@ -26,7 +26,7 @@ class IngredientPictureSerializer < BaseSerializer attribute :image_dimensions do |ingredient| sizes = ingredient.settings[:size]&.split("x", 2)&.map(&:to_i) || [ ingredient.image_file_width, - ingredient.image_file_height, + ingredient.image_file_height ] ratio = ingredient.image_file_width.to_f / ingredient.image_file_height @@ -35,7 +35,7 @@ class IngredientPictureSerializer < BaseSerializer { width: width, - height: height, + height: height } end @@ -58,7 +58,7 @@ class IngredientPictureSerializer < BaseSerializer desc: "#{width}w", width: width, height: height, - type: type.to_s, + type: type.to_s } end end diff --git a/app/serializers/alchemy/json_api/ingredient_richtext_serializer.rb b/app/serializers/alchemy/json_api/ingredient_richtext_serializer.rb index 09de6ce..46f7923 100644 --- a/app/serializers/alchemy/json_api/ingredient_richtext_serializer.rb +++ b/app/serializers/alchemy/json_api/ingredient_richtext_serializer.rb @@ -9,7 +9,7 @@ class IngredientRichtextSerializer < BaseSerializer attributes( :sanitized_body, - :stripped_body, + :stripped_body ) attribute :body, &:value diff --git a/app/serializers/alchemy/json_api/ingredient_text_serializer.rb b/app/serializers/alchemy/json_api/ingredient_text_serializer.rb index 054c04d..44143af 100644 --- a/app/serializers/alchemy/json_api/ingredient_text_serializer.rb +++ b/app/serializers/alchemy/json_api/ingredient_text_serializer.rb @@ -11,7 +11,7 @@ class IngredientTextSerializer < BaseSerializer :link, :link_class_name, :link_target, - :link_title, + :link_title ) # maintain compatibility with EssenceText diff --git a/app/serializers/alchemy/json_api/ingredient_video_serializer.rb b/app/serializers/alchemy/json_api/ingredient_video_serializer.rb index a0ec68f..d056c8f 100644 --- a/app/serializers/alchemy/json_api/ingredient_video_serializer.rb +++ b/app/serializers/alchemy/json_api/ingredient_video_serializer.rb @@ -13,7 +13,7 @@ class IngredientVideoSerializer < BaseSerializer :allow_fullscreen, :autoplay, :controls, - :preload, + :preload ) attribute :value do |ingredient| diff --git a/app/serializers/alchemy/json_api/language_serializer.rb b/app/serializers/alchemy/json_api/language_serializer.rb index b6456cd..f071519 100644 --- a/app/serializers/alchemy/json_api/language_serializer.rb +++ b/app/serializers/alchemy/json_api/language_serializer.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module Alchemy module JsonApi class LanguageSerializer < BaseSerializer @@ -6,7 +7,7 @@ class LanguageSerializer < BaseSerializer :name, :language_code, :country_code, - :locale, + :locale ) has_many :menu_items, record_type: :node, serializer: ::Alchemy::JsonApi::NodeSerializer, object_method_name: :nodes, id_method_name: :node_ids diff --git a/app/serializers/alchemy/json_api/node_serializer.rb b/app/serializers/alchemy/json_api/node_serializer.rb index c6ed2b0..afbc1da 100644 --- a/app/serializers/alchemy/json_api/node_serializer.rb +++ b/app/serializers/alchemy/json_api/node_serializer.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module Alchemy module JsonApi class NodeSerializer < BaseSerializer @@ -13,7 +14,7 @@ class NodeSerializer < BaseSerializer :page, record_type: :page, if: ->(node) { node.page }, - serializer: ::Alchemy::JsonApi::PageSerializer, + serializer: ::Alchemy::JsonApi::PageSerializer ) do |node| ::Alchemy::JsonApi::Page.new(node.page) end diff --git a/app/serializers/alchemy/json_api/page_serializer.rb b/app/serializers/alchemy/json_api/page_serializer.rb index 824517e..8d6f962 100644 --- a/app/serializers/alchemy/json_api/page_serializer.rb +++ b/app/serializers/alchemy/json_api/page_serializer.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module Alchemy module JsonApi class PageSerializer < BaseSerializer @@ -14,7 +15,7 @@ class PageSerializer < BaseSerializer :meta_keywords, :meta_description, :created_at, - :updated_at, + :updated_at ) cache_options store: Rails.cache, namespace: "alchemy-jsonapi" diff --git a/config/routes.rb b/config/routes.rb index c7ed8e0..611cd58 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,14 +1,15 @@ # frozen_string_literal: true + Alchemy::JsonApi::Engine.routes.draw do resources :pages, only: [:index] - get "pages/*path" => "pages#show", as: :page + get "pages/*path" => "pages#show", :as => :page resources :layout_pages, only: [:index] - get "layout_pages/*path" => "layout_pages#show", as: :layout_page + get "layout_pages/*path" => "layout_pages#show", :as => :layout_page resources :nodes, only: [:index] namespace :admin do - get "pages/*path" => "pages#show", as: :page + get "pages/*path" => "pages#show", :as => :page resources :layout_pages, only: [:index] - get "layout_pages/*path" => "layout_pages#show", as: :layout_page + get "layout_pages/*path" => "layout_pages#show", :as => :layout_page end end diff --git a/lib/alchemy/json_api/engine.rb b/lib/alchemy/json_api/engine.rb index 7218a39..7b0bc1f 100644 --- a/lib/alchemy/json_api/engine.rb +++ b/lib/alchemy/json_api/engine.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "jsonapi" module Alchemy diff --git a/lib/alchemy/json_api/essence_serializer.rb b/lib/alchemy/json_api/essence_serializer.rb index ea3b72e..e3416b2 100644 --- a/lib/alchemy/json_api/essence_serializer.rb +++ b/lib/alchemy/json_api/essence_serializer.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module Alchemy module JsonApi module EssenceSerializer diff --git a/lib/alchemy/json_api/test_support/essence_serializer_behaviour.rb b/lib/alchemy/json_api/test_support/essence_serializer_behaviour.rb index c5d17d4..c446d8d 100644 --- a/lib/alchemy/json_api/test_support/essence_serializer_behaviour.rb +++ b/lib/alchemy/json_api/test_support/essence_serializer_behaviour.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + RSpec.shared_examples "an essence serializer" do describe "attributes" do subject { serializer.serializable_hash[:data][:attributes] } @@ -15,7 +16,7 @@ expect(content).to receive(:definition).at_least(:once) do { name: "intro", - deprecated: true, + deprecated: true } end end @@ -30,7 +31,7 @@ subject { serializer.serializable_hash[:data][:relationships] } it "has the right keys and values" do - expect(subject[:element]).to eq(data: { id: essence.element.id.to_s, type: :element }) + expect(subject[:element]).to eq(data: {id: essence.element.id.to_s, type: :element}) end end end diff --git a/lib/alchemy/json_api/test_support/ingredient_serializer_behaviour.rb b/lib/alchemy/json_api/test_support/ingredient_serializer_behaviour.rb index 547477c..5091016 100644 --- a/lib/alchemy/json_api/test_support/ingredient_serializer_behaviour.rb +++ b/lib/alchemy/json_api/test_support/ingredient_serializer_behaviour.rb @@ -31,7 +31,7 @@ subject { serializer.serializable_hash[:data][:relationships] } it "has one element" do - expect(subject[:element]).to eq(data: { id: ingredient.element_id.to_s, type: :element }) + expect(subject[:element]).to eq(data: {id: ingredient.element_id.to_s, type: :element}) end end end diff --git a/lib/alchemy/json_api/version.rb b/lib/alchemy/json_api/version.rb index d92f259..4e63f33 100644 --- a/lib/alchemy/json_api/version.rb +++ b/lib/alchemy/json_api/version.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module Alchemy module JsonApi VERSION = "2.0.1" diff --git a/lib/tasks/alchemy/json_api_tasks.rake b/lib/tasks/alchemy/json_api_tasks.rake index 39d42b2..d4af9e0 100644 --- a/lib/tasks/alchemy/json_api_tasks.rake +++ b/lib/tasks/alchemy/json_api_tasks.rake @@ -1,4 +1,5 @@ # frozen_string_literal: true + # desc "Explaining what the task does" # task :alchemy_json_api do # # Task goes here diff --git a/spec/controllers/alchemy/json_api/admin/pages_controller_spec.rb b/spec/controllers/alchemy/json_api/admin/pages_controller_spec.rb index dde698e..6c2b393 100644 --- a/spec/controllers/alchemy/json_api/admin/pages_controller_spec.rb +++ b/spec/controllers/alchemy/json_api/admin/pages_controller_spec.rb @@ -16,7 +16,7 @@ let(:page) { FactoryBot.create(:alchemy_page) } it "stores page as preview" do - get :show, params: { path: page.urlname } + get :show, params: {path: page.urlname} if Alchemy.const_defined?(:Current) expect(Alchemy::Current.preview_page).to eq(page) else diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index fb2f0e7..c934809 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # This file is copied to spec/ when you run 'rails generate rspec:install' require "spec_helper" ENV["RAILS_ENV"] ||= "test" diff --git a/spec/requests/alchemy/json_api/admin/layout_pages_spec.rb b/spec/requests/alchemy/json_api/admin/layout_pages_spec.rb index 7f7adc2..fa209e2 100644 --- a/spec/requests/alchemy/json_api/admin/layout_pages_spec.rb +++ b/spec/requests/alchemy/json_api/admin/layout_pages_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "rails_helper" require "alchemy/devise/test_support/factories" @@ -44,7 +45,7 @@ end it "returns paginated result" do - get alchemy_json_api.admin_layout_pages_path(page: { number: 2, size: 1 }) + get alchemy_json_api.admin_layout_pages_path(page: {number: 2, size: 1}) document = JSON.parse(response.body) expect(document["data"].length).to eq(1) expect(document["meta"]).to eq({ @@ -54,9 +55,9 @@ "last" => 3, "next" => 3, "prev" => 1, - "records" => 3, + "records" => 3 }, - "total" => 3, + "total" => 3 }) end end @@ -97,8 +98,8 @@ { "data" => [{ "id" => element.id.to_s, - "type" => "element", - }], + "type" => "element" + }] } ) end @@ -121,10 +122,10 @@ get alchemy_json_api.admin_layout_page_path(page) etag = response.headers["ETag"] get alchemy_json_api.admin_layout_page_path(page), - headers: { - "If-Modified-Since" => page.updated_at.utc.httpdate, - "If-None-Match" => etag, - } + headers: { + "If-Modified-Since" => page.updated_at.utc.httpdate, + "If-None-Match" => etag + } expect(response.status).to eq(304) end end diff --git a/spec/requests/alchemy/json_api/admin/pages_spec.rb b/spec/requests/alchemy/json_api/admin/pages_spec.rb index 97cabba..939b761 100644 --- a/spec/requests/alchemy/json_api/admin/pages_spec.rb +++ b/spec/requests/alchemy/json_api/admin/pages_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "rails_helper" require "alchemy/devise/test_support/factories" @@ -44,10 +45,10 @@ get alchemy_json_api.admin_page_path(page) etag = response.headers["ETag"] get alchemy_json_api.admin_page_path(page), - headers: { - "If-Modified-Since" => page.updated_at.utc.httpdate, - "If-None-Match" => etag, - } + headers: { + "If-Modified-Since" => page.updated_at.utc.httpdate, + "If-None-Match" => etag + } expect(response.status).to eq(304) end end @@ -68,8 +69,8 @@ { "data" => [{ "id" => element.id.to_s, - "type" => "element", - }], + "type" => "element" + }] } ) end diff --git a/spec/requests/alchemy/json_api/layout_pages_spec.rb b/spec/requests/alchemy/json_api/layout_pages_spec.rb index 341b835..4507014 100644 --- a/spec/requests/alchemy/json_api/layout_pages_spec.rb +++ b/spec/requests/alchemy/json_api/layout_pages_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "rails_helper" require "alchemy/devise/test_support/factories" @@ -9,7 +10,7 @@ :public, :layoutpage, urlname: nil, - title: "Footer", + title: "Footer" ) end @@ -117,7 +118,7 @@ end it "returns paginated result" do - get alchemy_json_api.layout_pages_path(page: { number: 2, size: 1 }) + get alchemy_json_api.layout_pages_path(page: {number: 2, size: 1}) document = JSON.parse(response.body) expect(document["data"].length).to eq(1) expect(document["meta"]).to eq({ @@ -127,9 +128,9 @@ "last" => 3, "next" => 3, "prev" => 1, - "records" => 3, + "records" => 3 }, - "total" => 3, + "total" => 3 }) end end diff --git a/spec/requests/alchemy/json_api/nodes_spec.rb b/spec/requests/alchemy/json_api/nodes_spec.rb index da747ac..27895cb 100644 --- a/spec/requests/alchemy/json_api/nodes_spec.rb +++ b/spec/requests/alchemy/json_api/nodes_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "rails_helper" require "alchemy/devise/test_support/factories" require "alchemy/version" @@ -33,10 +34,10 @@ get alchemy_json_api.nodes_path etag = response.headers["ETag"] get alchemy_json_api.nodes_path, - headers: { - "If-Modified-Since" => nodes.max_by(&:updated_at).updated_at.utc.httpdate, - "If-None-Match" => etag, - } + headers: { + "If-Modified-Since" => nodes.max_by(&:updated_at).updated_at.utc.httpdate, + "If-None-Match" => etag + } expect(response.status).to eq(304) end end @@ -86,7 +87,7 @@ end it "returns paginated result" do - get alchemy_json_api.nodes_path(page: { number: 2, size: 1 }) + get alchemy_json_api.nodes_path(page: {number: 2, size: 1}) document = JSON.parse(response.body) expect(document["data"].length).to eq(1) expect(document["meta"]).to eq({ @@ -96,9 +97,9 @@ "last" => 4, "next" => 3, "prev" => 1, - "records" => 4, + "records" => 4 }, - "total" => 4, + "total" => 4 }) end end diff --git a/spec/requests/alchemy/json_api/pages_spec.rb b/spec/requests/alchemy/json_api/pages_spec.rb index d81a63b..114112d 100644 --- a/spec/requests/alchemy/json_api/pages_spec.rb +++ b/spec/requests/alchemy/json_api/pages_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "rails_helper" require "alchemy/devise/test_support/factories" require "alchemy/version" @@ -12,7 +13,7 @@ title: "Page Title", meta_keywords: "Meta Keywords", meta_description: "Meta Description", - tag_list: "Tag1,Tag2", + tag_list: "Tag1,Tag2" ) end @@ -22,7 +23,7 @@ FactoryBot.create( :alchemy_page, :public, - published_at: DateTime.yesterday, + published_at: DateTime.yesterday ) end @@ -45,7 +46,7 @@ :alchemy_page, :public, :restricted, - published_at: DateTime.yesterday, + published_at: DateTime.yesterday ) end @@ -61,7 +62,7 @@ :alchemy_page, :public, page_layout: "contact", - published_at: DateTime.yesterday, + published_at: DateTime.yesterday ) end @@ -76,10 +77,10 @@ get alchemy_json_api.page_path(page) etag = response.headers["ETag"] get alchemy_json_api.page_path(page), - headers: { - "If-Modified-Since" => page.published_at.utc.httpdate, - "If-None-Match" => etag, - } + headers: { + "If-Modified-Since" => page.published_at.utc.httpdate, + "If-None-Match" => etag + } expect(response.status).to eq(304) end end @@ -121,7 +122,7 @@ FactoryBot.create( :alchemy_page, :public, - urlname: "a-nested/page", + urlname: "a-nested/page" ) end @@ -195,7 +196,7 @@ :alchemy_page, :public, :restricted, - published_at: DateTime.yesterday, + published_at: DateTime.yesterday ) end @@ -211,7 +212,7 @@ :alchemy_page, :public, page_layout: "contact", - published_at: DateTime.yesterday, + published_at: DateTime.yesterday ) end @@ -226,10 +227,10 @@ get alchemy_json_api.pages_path etag = response.headers["ETag"] get alchemy_json_api.pages_path, - headers: { - "If-Modified-Since" => pages.max_by(&:published_at).published_at.utc.httpdate, - "If-None-Match" => etag, - } + headers: { + "If-Modified-Since" => pages.max_by(&:published_at).published_at.utc.httpdate, + "If-None-Match" => etag + } expect(response.status).to eq(304) end end @@ -267,7 +268,7 @@ let!(:news_page2) { FactoryBot.create(:alchemy_page, :public, name: "News", page_layout: "news", published_at: Date.yesterday) } it "returns only matching pages by page_layout" do - get alchemy_json_api.pages_path(filter: { page_layout_eq: "news" }) + get alchemy_json_api.pages_path(filter: {page_layout_eq: "news"}) document = JSON.parse(response.body) expect(document["data"]).not_to include(have_id(standard_page.id.to_s)) expect(document["data"]).to include(have_id(news_page.id.to_s)) @@ -275,7 +276,7 @@ end it "returns only matching pages by name" do - get alchemy_json_api.pages_path(filter: { name_eq: "News" }) + get alchemy_json_api.pages_path(filter: {name_eq: "News"}) document = JSON.parse(response.body) expect(document["data"]).not_to include(have_id(standard_page.id.to_s)) expect(document["data"]).not_to include(have_id(news_page.id.to_s)) @@ -284,7 +285,7 @@ context "if no pages returned for filter params" do it "does not throw error" do - get alchemy_json_api.pages_path(filter: { page_layout_eq: "not-found" }) + get alchemy_json_api.pages_path(filter: {page_layout_eq: "not-found"}) expect(response).to be_successful end end @@ -296,7 +297,7 @@ end it "sets cache headers of latest matching page" do - get alchemy_json_api.pages_path(filter: { page_layout_eq: "news" }) + get alchemy_json_api.pages_path(filter: {page_layout_eq: "news"}) expect(response.headers["Last-Modified"]).to eq(news_page2.published_at.utc.httpdate) expect(response.headers["ETag"]).to match(/W\/".+"/) expect(response.headers["Cache-Control"]).to eq("max-age=10800, public, must-revalidate") @@ -310,7 +311,7 @@ end it "returns paginated result" do - get alchemy_json_api.pages_path(page: { number: 2, size: 1 }) + get alchemy_json_api.pages_path(page: {number: 2, size: 1}) document = JSON.parse(response.body) expect(document["data"].length).to eq(1) expect(document["meta"]).to eq({ @@ -320,9 +321,9 @@ "last" => 4, "next" => 3, "prev" => 1, - "records" => 4, + "records" => 4 }, - "total" => 4, + "total" => 4 }) end end diff --git a/spec/routing/layout_page_routing_spec.rb b/spec/routing/layout_page_routing_spec.rb index 08705e0..fbd0952 100644 --- a/spec/routing/layout_page_routing_spec.rb +++ b/spec/routing/layout_page_routing_spec.rb @@ -8,7 +8,7 @@ it "routes layout_pages/" do expect(get: "/layout_pages").to route_to( controller: "alchemy/json_api/layout_pages", - action: "index", + action: "index" ) end @@ -16,7 +16,7 @@ expect(get: "/layout_pages/1").to route_to( controller: "alchemy/json_api/layout_pages", action: "show", - path: "1", + path: "1" ) end @@ -24,7 +24,7 @@ expect(get: "/layout_pages/a-page").to route_to( controller: "alchemy/json_api/layout_pages", action: "show", - path: "a-page", + path: "a-page" ) end @@ -32,7 +32,7 @@ expect(get: "/layout_pages/a-nested/page").to route_to( controller: "alchemy/json_api/layout_pages", action: "show", - path: "a-nested/page", + path: "a-nested/page" ) end end diff --git a/spec/routing/page_routing_spec.rb b/spec/routing/page_routing_spec.rb index 2132129..a91865d 100644 --- a/spec/routing/page_routing_spec.rb +++ b/spec/routing/page_routing_spec.rb @@ -8,7 +8,7 @@ it "routes pages/" do expect(get: "/pages").to route_to( controller: "alchemy/json_api/pages", - action: "index", + action: "index" ) end @@ -16,7 +16,7 @@ expect(get: "/pages/1").to route_to( controller: "alchemy/json_api/pages", action: "show", - path: "1", + path: "1" ) end @@ -24,7 +24,7 @@ expect(get: "/pages/a-page").to route_to( controller: "alchemy/json_api/pages", action: "show", - path: "a-page", + path: "a-page" ) end @@ -32,7 +32,7 @@ expect(get: "/pages/a-nested/page").to route_to( controller: "alchemy/json_api/pages", action: "show", - path: "a-nested/page", + path: "a-nested/page" ) end end diff --git a/spec/serializers/alchemy/json_api/element_serializer_spec.rb b/spec/serializers/alchemy/json_api/element_serializer_spec.rb index f9c0e26..f72268b 100644 --- a/spec/serializers/alchemy/json_api/element_serializer_spec.rb +++ b/spec/serializers/alchemy/json_api/element_serializer_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "rails_helper" RSpec.describe Alchemy::JsonApi::ElementSerializer do @@ -8,7 +9,7 @@ autogenerate_ingredients: true, tag_list: "Tag1,Tag2", nested_elements: [nested_element], - parent_element: parent_element, + parent_element: parent_element ) end let(:nested_element) { FactoryBot.create(:alchemy_element) } @@ -45,7 +46,7 @@ subject { serializer.serializable_hash[:data][:relationships] } it "has nested_elements" do - expect(subject[:nested_elements]).to eq(data: [{ id: nested_element.id.to_s, type: :element }]) + expect(subject[:nested_elements]).to eq(data: [{id: nested_element.id.to_s, type: :element}]) end context "with ingredients" do @@ -54,7 +55,7 @@ [ FactoryBot.build_stubbed(:alchemy_ingredient_text, element: element), FactoryBot.build_stubbed(:alchemy_ingredient_richtext, element: element), - FactoryBot.build_stubbed(:alchemy_ingredient_picture, element: element), + FactoryBot.build_stubbed(:alchemy_ingredient_picture, element: element) ] end end @@ -62,10 +63,10 @@ it "has ingredients" do expect(subject[:ingredients]).to eq( data: [ - { id: "1001", type: :ingredient_text }, - { id: "1002", type: :ingredient_richtext }, - { id: "1003", type: :ingredient_picture }, - ], + {id: "1001", type: :ingredient_text}, + {id: "1002", type: :ingredient_richtext}, + {id: "1003", type: :ingredient_picture} + ] ) end end diff --git a/spec/serializers/alchemy/json_api/ingredient_audio_serializer_spec.rb b/spec/serializers/alchemy/json_api/ingredient_audio_serializer_spec.rb index 7fedc46..22f56cf 100644 --- a/spec/serializers/alchemy/json_api/ingredient_audio_serializer_spec.rb +++ b/spec/serializers/alchemy/json_api/ingredient_audio_serializer_spec.rb @@ -12,7 +12,7 @@ attachment: attachment, autoplay: false, controls: true, - muted: true, + muted: true ) end diff --git a/spec/serializers/alchemy/json_api/ingredient_file_serializer_spec.rb b/spec/serializers/alchemy/json_api/ingredient_file_serializer_spec.rb index 7eea312..fbbc29a 100644 --- a/spec/serializers/alchemy/json_api/ingredient_file_serializer_spec.rb +++ b/spec/serializers/alchemy/json_api/ingredient_file_serializer_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "rails_helper" RSpec.describe Alchemy::JsonApi::IngredientFileSerializer do diff --git a/spec/serializers/alchemy/json_api/ingredient_headline_serializer_spec.rb b/spec/serializers/alchemy/json_api/ingredient_headline_serializer_spec.rb index 189dc4f..360ece9 100644 --- a/spec/serializers/alchemy/json_api/ingredient_headline_serializer_spec.rb +++ b/spec/serializers/alchemy/json_api/ingredient_headline_serializer_spec.rb @@ -11,7 +11,7 @@ role: "headline", value: "Hello you world", size: 2, - level: 3, + level: 3 ) end @@ -26,7 +26,7 @@ hash_including( value: "Hello you world", level: 3, - size: 2, + size: 2 ) ) end diff --git a/spec/serializers/alchemy/json_api/ingredient_html_serializer_spec.rb b/spec/serializers/alchemy/json_api/ingredient_html_serializer_spec.rb index bd0cc78..cc1206d 100644 --- a/spec/serializers/alchemy/json_api/ingredient_html_serializer_spec.rb +++ b/spec/serializers/alchemy/json_api/ingredient_html_serializer_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "rails_helper" RSpec.describe Alchemy::JsonApi::IngredientHtmlSerializer do diff --git a/spec/serializers/alchemy/json_api/ingredient_link_serializer_spec.rb b/spec/serializers/alchemy/json_api/ingredient_link_serializer_spec.rb index 23a5eee..ec80a8c 100644 --- a/spec/serializers/alchemy/json_api/ingredient_link_serializer_spec.rb +++ b/spec/serializers/alchemy/json_api/ingredient_link_serializer_spec.rb @@ -9,7 +9,7 @@ value: "/hello", link_class_name: "external", link_target: "_blank", - link_title: "Greetings!", + link_title: "Greetings!" ) end diff --git a/spec/serializers/alchemy/json_api/ingredient_node_serializer_spec.rb b/spec/serializers/alchemy/json_api/ingredient_node_serializer_spec.rb index 70057d1..b891ae4 100644 --- a/spec/serializers/alchemy/json_api/ingredient_node_serializer_spec.rb +++ b/spec/serializers/alchemy/json_api/ingredient_node_serializer_spec.rb @@ -28,7 +28,7 @@ subject { serializer.serializable_hash[:data][:relationships] } it "has the right keys and values" do - expect(subject[:node]).to eq(data: { id: node.id.to_s, type: :node }) + expect(subject[:node]).to eq(data: {id: node.id.to_s, type: :node}) end end diff --git a/spec/serializers/alchemy/json_api/ingredient_page_serializer_spec.rb b/spec/serializers/alchemy/json_api/ingredient_page_serializer_spec.rb index 7883c20..505ce0b 100644 --- a/spec/serializers/alchemy/json_api/ingredient_page_serializer_spec.rb +++ b/spec/serializers/alchemy/json_api/ingredient_page_serializer_spec.rb @@ -30,7 +30,7 @@ subject { serializer.serializable_hash[:data][:relationships] } it "has page object" do - expect(subject[:page]).to eq(data: { id: page.id.to_s, type: :page }) + expect(subject[:page]).to eq(data: {id: page.id.to_s, type: :page}) end end diff --git a/spec/serializers/alchemy/json_api/ingredient_picture_serializer_spec.rb b/spec/serializers/alchemy/json_api/ingredient_picture_serializer_spec.rb index 70c8c23..56d610a 100644 --- a/spec/serializers/alchemy/json_api/ingredient_picture_serializer_spec.rb +++ b/spec/serializers/alchemy/json_api/ingredient_picture_serializer_spec.rb @@ -8,7 +8,7 @@ :alchemy_ingredient_picture, title: "Picture", link: "/hello", - picture: picture, + picture: picture ) end @@ -51,7 +51,7 @@ end let(:size) do - { size: "100x100" } + {size: "100x100"} end it do @@ -60,7 +60,7 @@ context "without y dimension" do let(:size) do - { size: "100x" } + {size: "100x"} end it "infers height from ratio" do @@ -70,7 +70,7 @@ context "without x dimension" do let(:size) do - { size: "x50" } + {size: "x50"} end it "infers width from ratio" do @@ -94,7 +94,7 @@ before do expect(ingredient).to receive(:settings).at_least(:once) do { - srcset: srcset_definition, + srcset: srcset_definition } end end @@ -112,15 +112,15 @@ desc: "100w", width: "100", height: "100", - type: "image/png", + type: "image/png" }, { url: instance_of(String), desc: "200w", width: "200", height: "100", - type: "image/png", - }, + type: "image/png" + } ] ) end @@ -131,12 +131,12 @@ [ { size: "100x100", - crop: true, + crop: true }, { size: "200x100", - format: "jpg", - }, + format: "jpg" + } ] end @@ -148,15 +148,15 @@ desc: "100w", width: "100", height: "100", - type: "image/png", + type: "image/png" }, { url: a_string_matching(%r{.jpg}), desc: "200w", width: "200", height: "100", - type: "image/jpeg", - }, + type: "image/jpeg" + } ] ) end diff --git a/spec/serializers/alchemy/json_api/ingredient_richtext_serializer_spec.rb b/spec/serializers/alchemy/json_api/ingredient_richtext_serializer_spec.rb index 450e4f7..3c42576 100644 --- a/spec/serializers/alchemy/json_api/ingredient_richtext_serializer_spec.rb +++ b/spec/serializers/alchemy/json_api/ingredient_richtext_serializer_spec.rb @@ -6,7 +6,7 @@ let(:ingredient) do FactoryBot.create( :alchemy_ingredient_richtext, - value: "

Hello

", + value: "

Hello

" ) end diff --git a/spec/serializers/alchemy/json_api/ingredient_text_serializer_spec.rb b/spec/serializers/alchemy/json_api/ingredient_text_serializer_spec.rb index 9233f22..aafb360 100644 --- a/spec/serializers/alchemy/json_api/ingredient_text_serializer_spec.rb +++ b/spec/serializers/alchemy/json_api/ingredient_text_serializer_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "rails_helper" RSpec.describe Alchemy::JsonApi::IngredientTextSerializer do diff --git a/spec/serializers/alchemy/json_api/ingredient_video_serializer_spec.rb b/spec/serializers/alchemy/json_api/ingredient_video_serializer_spec.rb index 2393f89..6a2b3ff 100644 --- a/spec/serializers/alchemy/json_api/ingredient_video_serializer_spec.rb +++ b/spec/serializers/alchemy/json_api/ingredient_video_serializer_spec.rb @@ -12,7 +12,7 @@ attachment: attachment, allow_fullscreen: true, autoplay: false, - controls: true, + controls: true ) end diff --git a/spec/serializers/alchemy/json_api/language_serializer_spec.rb b/spec/serializers/alchemy/json_api/language_serializer_spec.rb index 43e1fa8..c51f072 100644 --- a/spec/serializers/alchemy/json_api/language_serializer_spec.rb +++ b/spec/serializers/alchemy/json_api/language_serializer_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "rails_helper" RSpec.describe Alchemy::JsonApi::LanguageSerializer do @@ -29,10 +30,10 @@ subject { serializer.serializable_hash[:data][:relationships] } it "has the right keys and values" do - expect(subject[:root_page]).to eq(data: { id: root_page.id.to_s, type: :page }) - expect(subject[:pages]).to eq(data: [{ id: root_page.id.to_s, type: :page }]) - expect(subject[:menus]).to eq(data: [{ id: menu.id.to_s, type: :node }]) - expect(subject[:menu_items]).to eq(data: [{ id: menu.id.to_s, type: :node }, { id: menu_node.id.to_s, type: :node }]) + expect(subject[:root_page]).to eq(data: {id: root_page.id.to_s, type: :page}) + expect(subject[:pages]).to eq(data: [{id: root_page.id.to_s, type: :page}]) + expect(subject[:menus]).to eq(data: [{id: menu.id.to_s, type: :node}]) + expect(subject[:menu_items]).to eq(data: [{id: menu.id.to_s, type: :node}, {id: menu_node.id.to_s, type: :node}]) end end end diff --git a/spec/serializers/alchemy/json_api/node_serializer_spec.rb b/spec/serializers/alchemy/json_api/node_serializer_spec.rb index b7f1c79..6498ff1 100644 --- a/spec/serializers/alchemy/json_api/node_serializer_spec.rb +++ b/spec/serializers/alchemy/json_api/node_serializer_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "rails_helper" RSpec.describe Alchemy::JsonApi::NodeSerializer do @@ -8,7 +9,7 @@ name: "A Node", url: "/acdc", title: "Pop-up explanation", - nofollow: true, + nofollow: true ) end let(:options) { {} } @@ -38,7 +39,7 @@ url: "/acdc", title: "Pop-up explanation", nofollow: true, - children: [child_node], + children: [child_node] ) end @@ -46,7 +47,7 @@ let(:child_of_child_node) { FactoryBot.create(:alchemy_node) } it "has children" do - expect(subject[:children]).to eq(data: [{ id: child_node.id.to_s, type: :node }]) + expect(subject[:children]).to eq(data: [{id: child_node.id.to_s, type: :node}]) end end @@ -58,14 +59,14 @@ url: "/acdc", title: "Pop-up explanation", nofollow: true, - page: page, + page: page ) end let(:page) { FactoryBot.create(:alchemy_page) } it "has page" do - expect(subject[:page]).to eq(data: { id: page.id.to_s, type: :page }) + expect(subject[:page]).to eq(data: {id: page.id.to_s, type: :page}) end end end diff --git a/spec/serializers/alchemy/json_api/page_serializer_spec.rb b/spec/serializers/alchemy/json_api/page_serializer_spec.rb index 678f9dc..cbc3d45 100644 --- a/spec/serializers/alchemy/json_api/page_serializer_spec.rb +++ b/spec/serializers/alchemy/json_api/page_serializer_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "rails_helper" RSpec.describe Alchemy::JsonApi::PageSerializer do @@ -10,7 +11,7 @@ title: "Page Title", meta_keywords: "Meta Keywords", meta_description: "Meta Description", - tag_list: "Tag1,Tag2", + tag_list: "Tag1,Tag2" ) end let!(:legacy_url) { Alchemy::LegacyPageUrl.create(urlname: "/other", page: alchemy_page) } @@ -50,10 +51,10 @@ it "does not include trashed, fixed or hidden elements" do expect(subject[:elements]).to eq( data: [ - { id: element.id.to_s, type: :element }, - ], + {id: element.id.to_s, type: :element} + ] ) - expect(subject[:language]).to eq(data: { id: page.language_id.to_s, type: :language }) + expect(subject[:language]).to eq(data: {id: page.language_id.to_s, type: :language}) end end @@ -61,18 +62,18 @@ it "does not include trashed, non-fixed or hidden elements" do expect(subject[:fixed_elements]).to eq( data: [ - { id: fixed_element.id.to_s, type: :element }, - ], + {id: fixed_element.id.to_s, type: :element} + ] ) - expect(subject[:language]).to eq(data: { id: page.language_id.to_s, type: :language }) + expect(subject[:language]).to eq(data: {id: page.language_id.to_s, type: :language}) end end it "has ancestors relationship" do expect(subject[:ancestors]).to eq( data: [ - { id: page.parent_id.to_s, type: :page }, - ], + {id: page.parent_id.to_s, type: :page} + ] ) end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 5ec9648..75c51cc 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # This file was generated by the `rails generate rspec:install` command. Conventionally, all # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. # The generated `.rspec` file contains `--require spec_helper` which will cause