From 9f8f8f85b543bff3809b15a3b390872db576914f Mon Sep 17 00:00:00 2001 From: Thomas von Deyen <thomas@vondeyen.com> Date: Wed, 29 Apr 2020 08:47:00 +0200 Subject: [PATCH 1/5] Rubocop -a --- app/controllers/alchemy/base_controller.rb | 1 + bin/webpack | 1 + bin/webpack-dev-server | 1 + lib/alchemy/configuration_methods.rb | 1 + lib/alchemy/page_layout.rb | 1 + lib/tasks/alchemy/db.rake | 1 - .../alchemy/admin/languages_controller_spec.rb | 18 +++++++++--------- spec/libraries/controller_actions_spec.rb | 2 +- .../alchemy/api/nodes_controller_spec.rb | 1 - 9 files changed, 15 insertions(+), 12 deletions(-) diff --git a/app/controllers/alchemy/base_controller.rb b/app/controllers/alchemy/base_controller.rb index dad72d6c72..968f9d9dad 100644 --- a/app/controllers/alchemy/base_controller.rb +++ b/app/controllers/alchemy/base_controller.rb @@ -27,6 +27,7 @@ class BaseController < ApplicationController # def set_locale return unless Language.current + ::I18n.locale = Language.current&.locale end diff --git a/bin/webpack b/bin/webpack index 008ecb22f7..334c800545 100755 --- a/bin/webpack +++ b/bin/webpack @@ -1,4 +1,5 @@ #!/usr/bin/env ruby +# frozen_string_literal: true ENV["RAILS_ENV"] ||= ENV["RACK_ENV"] || "development" ENV["NODE_ENV"] ||= "development" diff --git a/bin/webpack-dev-server b/bin/webpack-dev-server index a931a9b7fc..91025bb661 100755 --- a/bin/webpack-dev-server +++ b/bin/webpack-dev-server @@ -1,4 +1,5 @@ #!/usr/bin/env ruby +# frozen_string_literal: true ENV["RAILS_ENV"] ||= ENV["RACK_ENV"] || "development" ENV["NODE_ENV"] ||= "development" diff --git a/lib/alchemy/configuration_methods.rb b/lib/alchemy/configuration_methods.rb index 973f323fcd..a80fab9478 100644 --- a/lib/alchemy/configuration_methods.rb +++ b/lib/alchemy/configuration_methods.rb @@ -30,6 +30,7 @@ def multi_language? # def prefix_locale?(locale = Language.current&.code) return false unless locale + multi_language? && locale != ::I18n.default_locale.to_s end diff --git a/lib/alchemy/page_layout.rb b/lib/alchemy/page_layout.rb index fec48f918c..f3c759f9f6 100644 --- a/lib/alchemy/page_layout.rb +++ b/lib/alchemy/page_layout.rb @@ -154,6 +154,7 @@ def page_with_layout_existing?(layout) # def available_on_site?(layout) return false unless Alchemy::Site.current + Alchemy::Site.current.definition.blank? || Alchemy::Site.current.definition.fetch('page_layouts', []).include?(layout['name']) end diff --git a/lib/tasks/alchemy/db.rake b/lib/tasks/alchemy/db.rake index 3dab98e15a..298d4f3f47 100644 --- a/lib/tasks/alchemy/db.rake +++ b/lib/tasks/alchemy/db.rake @@ -4,7 +4,6 @@ require 'alchemy/seeder' namespace :alchemy do namespace :db do - desc "Seeds the database with Alchemy defaults" task seed: [:environment] do Alchemy::Seeder.seed! diff --git a/spec/controllers/alchemy/admin/languages_controller_spec.rb b/spec/controllers/alchemy/admin/languages_controller_spec.rb index 0944a97b63..8e9ae39aa1 100644 --- a/spec/controllers/alchemy/admin/languages_controller_spec.rb +++ b/spec/controllers/alchemy/admin/languages_controller_spec.rb @@ -57,17 +57,17 @@ get :new expect(response).to redirect_to(admin_sites_path) end - end + end - context 'with a site' do - let!(:site) { create(:alchemy_site) } + context 'with a site' do + let!(:site) { create(:alchemy_site) } - it "has default language's page_layout set" do - get :new - expect(assigns(:language).page_layout). - to eq(Alchemy::Config.get(:default_language)['page_layout']) - end - end + it "has default language's page_layout set" do + get :new + expect(assigns(:language).page_layout). + to eq(Alchemy::Config.get(:default_language)['page_layout']) + end + end end describe "#create" do diff --git a/spec/libraries/controller_actions_spec.rb b/spec/libraries/controller_actions_spec.rb index db5d435638..b43fc4fc23 100644 --- a/spec/libraries/controller_actions_spec.rb +++ b/spec/libraries/controller_actions_spec.rb @@ -55,7 +55,7 @@ describe "#set_alchemy_language" do let!(:default_language) { create(:alchemy_language, code: :en) } - let(:klingon) { create(:alchemy_language, :klingon) } + let(:klingon) { create(:alchemy_language, :klingon) } after do # We must never change the app's locale diff --git a/spec/requests/alchemy/api/nodes_controller_spec.rb b/spec/requests/alchemy/api/nodes_controller_spec.rb index 2f2b6d19fd..152f64bcab 100644 --- a/spec/requests/alchemy/api/nodes_controller_spec.rb +++ b/spec/requests/alchemy/api/nodes_controller_spec.rb @@ -46,7 +46,6 @@ module Alchemy end end - describe '#toggle_folded' do context 'with expanded node' do let(:node) { create(:alchemy_node, folded: false) } From 68b1ff5ab5880f568b2a1c24d1499c9fb2e25b75 Mon Sep 17 00:00:00 2001 From: Thomas von Deyen <thomas@vondeyen.com> Date: Wed, 29 Apr 2020 08:47:19 +0200 Subject: [PATCH 2/5] Fix rubocop config --- .rubocop.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.rubocop.yml b/.rubocop.yml index 076dc5c8a0..24190ba851 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,7 +1,7 @@ # Relaxed.Ruby.Style AllCops: - TargetRubyVersion: 2.3 + TargetRubyVersion: 2.4 Exclude: - 'bin/rspec' - 'vendor/**/*' @@ -9,6 +9,7 @@ AllCops: - 'spec/dummy/config/**/*' - 'alchemy_cms.gemspec' - 'Rakefile' + - 'node_modules/**/*' # Really, rubocop? Bundler/OrderedGems: From bd74753a7ba9bf9909442512bd11e196476eb515 Mon Sep 17 00:00:00 2001 From: Thomas von Deyen <thomas@vondeyen.com> Date: Wed, 29 Apr 2020 09:05:08 +0200 Subject: [PATCH 3/5] [Rufo] Add trailing commas --- .rubocop.yml | 9 + .../alchemy/admin/attachments_controller.rb | 8 +- .../alchemy/admin/clipboard_controller.rb | 2 +- .../alchemy/admin/elements_controller.rb | 40 ++--- .../alchemy/admin/languages_controller.rb | 2 +- .../alchemy/admin/nodes_controller.rb | 4 +- .../alchemy/admin/pages_controller.rb | 6 +- .../alchemy/admin/pictures_controller.rb | 12 +- .../alchemy/admin/resources_controller.rb | 8 +- .../alchemy/admin/trash_controller.rb | 12 +- .../alchemy/api/contents_controller.rb | 6 +- .../alchemy/api/elements_controller.rb | 14 +- .../alchemy/api/pages_controller.rb | 22 +-- .../alchemy/attachments_controller.rb | 6 +- .../alchemy/messages_controller.rb | 4 +- app/controllers/alchemy/pages_controller.rb | 4 +- .../alchemy/admin/uploader_responses.rb | 10 +- .../concerns/alchemy/legacy_page_redirects.rb | 6 +- .../concerns/alchemy/page_redirects.rb | 2 +- app/decorators/alchemy/content_editor.rb | 4 +- app/decorators/alchemy/element_editor.rb | 2 +- app/helpers/alchemy/admin/base_helper.rb | 26 +-- app/helpers/alchemy/admin/contents_helper.rb | 2 +- app/helpers/alchemy/admin/elements_helper.rb | 2 +- app/helpers/alchemy/admin/essences_helper.rb | 2 +- app/helpers/alchemy/admin/form_helper.rb | 2 +- .../alchemy/admin/navigation_helper.rb | 12 +- app/helpers/alchemy/admin/pages_helper.rb | 4 +- app/helpers/alchemy/admin/tags_helper.rb | 6 +- app/helpers/alchemy/base_helper.rb | 2 +- app/helpers/alchemy/elements_block_helper.rb | 4 +- app/helpers/alchemy/elements_helper.rb | 6 +- app/helpers/alchemy/pages_helper.rb | 12 +- app/mailers/alchemy/messages_mailer.rb | 2 +- app/models/alchemy/attachment.rb | 2 +- app/models/alchemy/content.rb | 4 +- app/models/alchemy/content/factory.rb | 6 +- app/models/alchemy/element.rb | 70 ++++---- .../alchemy/element/element_essences.rb | 4 +- app/models/alchemy/essence_file.rb | 2 +- app/models/alchemy/essence_node.rb | 4 +- app/models/alchemy/essence_page.rb | 4 +- app/models/alchemy/essence_picture.rb | 8 +- app/models/alchemy/essence_picture_view.rb | 6 +- app/models/alchemy/language/code.rb | 2 +- app/models/alchemy/page.rb | 51 +++--- app/models/alchemy/page/page_elements.rb | 4 +- app/models/alchemy/page/page_natures.rb | 2 +- app/models/alchemy/page/page_scopes.rb | 2 +- app/models/alchemy/picture.rb | 2 +- app/models/alchemy/picture/transformations.rb | 14 +- app/models/alchemy/picture/url.rb | 4 +- .../alchemy/essence_picture_serializer.rb | 2 +- .../alchemy/essence_text_serializer.rb | 2 +- .../alchemy/page_tree_serializer.rb | 8 +- lib/alchemy/elements_finder.rb | 2 +- lib/alchemy/engine.rb | 4 +- lib/alchemy/essence.rb | 4 +- lib/alchemy/filetypes.rb | 10 +- lib/alchemy/forms/builder.rb | 4 +- lib/alchemy/permissions.rb | 8 +- lib/alchemy/resource.rb | 4 +- lib/alchemy/resources_helper.rb | 6 +- lib/alchemy/seeder.rb | 6 +- lib/alchemy/shell.rb | 2 +- lib/alchemy/test_support/shared_contexts.rb | 2 +- lib/alchemy/tinymce.rb | 4 +- lib/alchemy/webpacker.rb | 2 +- lib/tasks/alchemy/upgrade.rake | 8 +- lib/tasks/alchemy/webpacker.rake | 2 +- .../admin/attachments_controller_spec.rb | 106 +++++------ .../admin/dashboard_controller_spec.rb | 8 +- .../alchemy/admin/elements_controller_spec.rb | 6 +- .../admin/essence_files_controller_spec.rb | 4 +- .../admin/essence_pictures_controller_spec.rb | 8 +- .../admin/languages_controller_spec.rb | 4 +- .../alchemy/admin/pictures_controller_spec.rb | 4 +- .../alchemy/messages_controller_spec.rb | 10 +- .../alchemy/pages_controller_spec.rb | 2 +- spec/dummy/app/models/event.rb | 2 +- spec/features/admin/tinymce_feature_spec.rb | 4 +- spec/features/page_redirects_spec.rb | 10 +- .../helpers/alchemy/admin/base_helper_spec.rb | 14 +- .../alchemy/admin/elements_helper_spec.rb | 4 +- .../alchemy/admin/essences_helper_spec.rb | 8 +- .../alchemy/admin/navigation_helper_spec.rb | 168 +++++++++--------- .../helpers/alchemy/admin/tags_helper_spec.rb | 2 +- .../alchemy/elements_block_helper_spec.rb | 4 +- spec/libraries/config_spec.rb | 2 +- spec/libraries/elements_finder_spec.rb | 12 +- spec/libraries/i18n_spec.rb | 4 +- spec/libraries/modules_spec.rb | 14 +- spec/libraries/resource_spec.rb | 20 +-- spec/libraries/resources_helper_spec.rb | 8 +- spec/libraries/tinymce_spec.rb | 24 +-- spec/models/alchemy/content_spec.rb | 14 +- spec/models/alchemy/element_spec.rb | 36 ++-- spec/models/alchemy/essence_picture_spec.rb | 12 +- .../alchemy/essence_picture_view_spec.rb | 2 +- spec/models/alchemy/language_spec.rb | 2 +- .../alchemy/page/fixed_attributes_spec.rb | 6 +- spec/models/alchemy/page_spec.rb | 30 ++-- spec/models/alchemy/picture_spec.rb | 4 +- spec/models/alchemy/picture_url_spec.rb | 16 +- spec/models/alchemy/tag_spec.rb | 2 +- .../alchemy/admin/pages_controller_spec.rb | 14 +- .../alchemy/api/nodes_controller_spec.rb | 4 +- .../alchemy/legacy_page_redirecting_spec.rb | 2 +- spec/routing/api_routing_spec.rb | 30 ++-- spec/routing/routing_spec.rb | 72 ++++---- .../alchemy/element_serializer_spec.rb | 2 +- .../alchemy/node_serializer_spec.rb | 2 +- spec/views/admin/pictures/show_spec.rb | 4 +- .../admin/elements/element_view_spec.rb | 8 +- .../_main_navigation_entry.html.erb_spec.rb | 8 +- .../essences/essence_boolean_editor_spec.rb | 6 +- .../essences/essence_file_editor_spec.rb | 2 +- spec/views/essences/essence_file_view_spec.rb | 2 +- .../essences/essence_link_editor_spec.rb | 2 +- .../essences/essence_picture_editor_spec.rb | 6 +- .../essences/essence_select_editor_spec.rb | 2 +- .../essences/essence_text_editor_spec.rb | 6 +- 122 files changed, 648 insertions(+), 636 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 24190ba851..cfe32487d6 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -224,6 +224,15 @@ Style/StringLiterals: Enabled: false StyleGuide: http://relaxed.ruby.style/#stylestringliterals +Style/TrailingCommaInArguments: + EnforcedStyleForMultiline: comma + +Style/TrailingCommaInArrayLiteral: + EnforcedStyleForMultiline: comma + +Style/TrailingCommaInHashLiteral: + EnforcedStyleForMultiline: consistent_comma + Style/WhileUntilModifier: Enabled: false StyleGuide: http://relaxed.ruby.style/#stylewhileuntilmodifier diff --git a/app/controllers/alchemy/admin/attachments_controller.rb b/app/controllers/alchemy/admin/attachments_controller.rb index 54eecdc262..03630f8c7e 100644 --- a/app/controllers/alchemy/admin/attachments_controller.rb +++ b/app/controllers/alchemy/admin/attachments_controller.rb @@ -48,7 +48,7 @@ def update render_errors_or_redirect( @attachment, admin_attachments_path(search_filter_params), - Alchemy.t("File successfully updated") + Alchemy.t("File successfully updated"), ) end end @@ -64,7 +64,7 @@ def download @attachment = Attachment.find(params[:id]) send_file @attachment.file.path, { filename: @attachment.file_name, - type: @attachment.file_mime_type + type: @attachment.file_mime_type, } end @@ -74,8 +74,8 @@ def search_filter_params @_search_filter_params ||= params.except(*COMMON_SEARCH_FILTER_EXCLUDES + [:attachment]).permit( *common_search_filter_includes + [ :file_type, - :content_id - ] + :content_id, + ], ) end diff --git a/app/controllers/alchemy/admin/clipboard_controller.rb b/app/controllers/alchemy/admin/clipboard_controller.rb index 3977e72ede..0b980cc956 100644 --- a/app/controllers/alchemy/admin/clipboard_controller.rb +++ b/app/controllers/alchemy/admin/clipboard_controller.rb @@ -20,7 +20,7 @@ def insert unless @clipboard.detect { |item| item['id'] == remarkable_params[:remarkable_id] } @clipboard << { 'id' => remarkable_params[:remarkable_id], - 'action' => params[:remove] ? 'cut' : 'copy' + 'action' => params[:remove] ? 'cut' : 'copy', } end respond_to do |format| diff --git a/app/controllers/alchemy/admin/elements_controller.rb b/app/controllers/alchemy/admin/elements_controller.rb index 11520da98a..54ad29933c 100644 --- a/app/controllers/alchemy/admin/elements_controller.rb +++ b/app/controllers/alchemy/admin/elements_controller.rb @@ -17,7 +17,7 @@ def new @parent_element = Element.find_by(id: params[:parent_element_id]) @elements = @page.available_elements_within_current_scope(@parent_element) @element = @page.elements.build - @clipboard = get_clipboard('elements') + @clipboard = get_clipboard("elements") @clipboard_items = Element.all_from_clipboard_for_page(@clipboard, @page) end @@ -30,7 +30,7 @@ def create else @element = Element.create(create_element_params) end - if @page.definition['insert_elements_at'] == 'top' + if @page.definition["insert_elements_at"] == "top" @insert_at_top = true @element.move_to_top end @@ -40,7 +40,7 @@ def create else @element.page = @page @elements = @page.available_element_definitions - @clipboard = get_clipboard('elements') + @clipboard = get_clipboard("elements") @clipboard_items = Element.all_from_clipboard_for_page(@clipboard, @page) render :new end @@ -56,7 +56,7 @@ def update @element_validated = @element.update(element_params) else @element_validated = false - @notice = Alchemy.t('Validation failed') + @notice = Alchemy.t("Validation failed") @error_message = "<h2>#{@notice}</h2><p>#{Alchemy.t(:content_validations_headline)}</p>".html_safe end end @@ -81,7 +81,7 @@ def order Element.where(id: element_id).update_all( page_id: params[:page_id], parent_element_id: params[:parent_element_id], - position: idx + 1 + position: idx + 1, ) end @parent_element.try!(:touch) @@ -100,20 +100,20 @@ def element_includes [ { contents: { - essence: :ingredient_association - } + essence: :ingredient_association, + }, }, :tags, { all_nested_elements: [ { contents: { - essence: :ingredient_association - } + essence: :ingredient_association, + }, }, - :tags - ] - } + :tags, + ], + }, ] end @@ -123,20 +123,20 @@ def load_element def element_from_clipboard @element_from_clipboard ||= begin - @clipboard = get_clipboard('elements') - @clipboard.detect { |item| item['id'].to_i == params[:paste_from_clipboard].to_i } - end + @clipboard = get_clipboard("elements") + @clipboard.detect { |item| item["id"].to_i == params[:paste_from_clipboard].to_i } + end end def paste_element_from_clipboard - @source_element = Element.find(element_from_clipboard['id']) + @source_element = Element.find(element_from_clipboard["id"]) element = Element.copy(@source_element, { parent_element_id: create_element_params[:parent_element_id], - page_id: @page.id} - ) - if element_from_clipboard['action'] == 'cut' + page_id: @page.id, + }) + if element_from_clipboard["action"] == "cut" @cut_element_id = @source_element.id - @clipboard.delete_if { |item| item['id'] == @source_element.id.to_s } + @clipboard.delete_if { |item| item["id"] == @source_element.id.to_s } @source_element.destroy end element diff --git a/app/controllers/alchemy/admin/languages_controller.rb b/app/controllers/alchemy/admin/languages_controller.rb index b3f97d30b9..c734bbfb38 100644 --- a/app/controllers/alchemy/admin/languages_controller.rb +++ b/app/controllers/alchemy/admin/languages_controller.rb @@ -14,7 +14,7 @@ def index def new @language = Language.new( site: @current_site, - page_layout: Config.get(:default_language)['page_layout'] + page_layout: Config.get(:default_language)['page_layout'], ) end diff --git a/app/controllers/alchemy/admin/nodes_controller.rb b/app/controllers/alchemy/admin/nodes_controller.rb index 98ca0bb1f4..452a7eae06 100644 --- a/app/controllers/alchemy/admin/nodes_controller.rb +++ b/app/controllers/alchemy/admin/nodes_controller.rb @@ -13,7 +13,7 @@ def new @node = Node.new( site: Alchemy::Site.current, parent_id: params[:parent_id], - language: @current_language + language: @current_language, ) end @@ -29,7 +29,7 @@ def resource_params :url, :title, :nofollow, - :external + :external, ) end end diff --git a/app/controllers/alchemy/admin/pages_controller.rb b/app/controllers/alchemy/admin/pages_controller.rb index 36716c5f8d..92d0da5abd 100644 --- a/app/controllers/alchemy/admin/pages_controller.rb +++ b/app/controllers/alchemy/admin/pages_controller.rb @@ -169,7 +169,7 @@ def visit redirect_to show_page_url( urlname: @page.urlname, locale: prefix_locale? ? @page.language_code : nil, - host: @page.site.host == "*" ? request.host : @page.site.host + host: @page.site.host == "*" ? request.host : @page.site.host, ) end @@ -224,7 +224,7 @@ def copy_of_language_root page_copy = Page.copy( language_root_to_copy_from, language_id: params[:languages][:new_lang_id], - language_code: @current_language.code + language_code: @current_language.code, ) page_copy.move_to_child_of Page.root page_copy @@ -321,7 +321,7 @@ def pages_from_raw_request request.raw_post.split('&').map do |i| parts = i.split('=') { - parts[0].gsub(/[^0-9]/, '') => parts[1] + parts[0].gsub(/[^0-9]/, '') => parts[1], } end end diff --git a/app/controllers/alchemy/admin/pictures_controller.rb b/app/controllers/alchemy/admin/pictures_controller.rb index 75354555ed..0c00d54ada 100644 --- a/app/controllers/alchemy/admin/pictures_controller.rb +++ b/app/controllers/alchemy/admin/pictures_controller.rb @@ -19,7 +19,7 @@ def index @pictures = Picture.search_by( search_filter_params, @query, - items_per_page + items_per_page, ) if in_overlay? @@ -53,12 +53,12 @@ def update if @picture.update(picture_params) @message = { body: Alchemy.t(:picture_updated_successfully, name: @picture.name), - type: 'notice' + type: 'notice', } else @message = { body: Alchemy.t(:picture_update_failed), - type: 'error' + type: 'error', } end render :update @@ -89,7 +89,7 @@ def delete_multiple if not_deletable.any? flash[:warn] = Alchemy.t( "These pictures could not be deleted, because they were in use", - names: not_deletable.to_sentence + names: not_deletable.to_sentence, ) else flash[:notice] = Alchemy.t("Pictures deleted successfully", names: names.to_sentence) @@ -154,8 +154,8 @@ def search_filter_params :size, :element_id, :swap, - :content_id - ] + :content_id, + ], ) end diff --git a/app/controllers/alchemy/admin/resources_controller.rb b/app/controllers/alchemy/admin/resources_controller.rb index e6079942c8..b55273451e 100644 --- a/app/controllers/alchemy/admin/resources_controller.rb +++ b/app/controllers/alchemy/admin/resources_controller.rb @@ -64,7 +64,7 @@ def create render_errors_or_redirect( resource_instance_variable, resources_path(resource_instance_variable.class, search_filter_params), - flash_notice_for_resource_action + flash_notice_for_resource_action, ) end @@ -73,7 +73,7 @@ def update render_errors_or_redirect( resource_instance_variable, resources_path(resource_instance_variable.class, search_filter_params), - flash_notice_for_resource_action + flash_notice_for_resource_action, ) end @@ -147,12 +147,12 @@ def common_search_filter_includes [ {q: [ resource_handler.search_field_name, - :s + :s, ]}, :tagged_with, :filter, :page, - :per_page + :per_page, ].freeze end diff --git a/app/controllers/alchemy/admin/trash_controller.rb b/app/controllers/alchemy/admin/trash_controller.rb index 8956f70b79..98c3dce514 100644 --- a/app/controllers/alchemy/admin/trash_controller.rb +++ b/app/controllers/alchemy/admin/trash_controller.rb @@ -25,16 +25,16 @@ def element_includes [ { contents: { - essence: :ingredient_association + essence: :ingredient_association, }, all_nested_elements: [ { contents: { - essence: :ingredient_association - } - } - ] - } + essence: :ingredient_association, + }, + }, + ], + }, ] end end diff --git a/app/controllers/alchemy/api/contents_controller.rb b/app/controllers/alchemy/api/contents_controller.rb index 13162e08ca..3999c34e71 100644 --- a/app/controllers/alchemy/api/contents_controller.rb +++ b/app/controllers/alchemy/api/contents_controller.rb @@ -36,7 +36,7 @@ def show elsif params[:element_id] && params[:name] @content = Content.where( element_id: params[:element_id], - name: params[:name] + name: params[:name], ).includes(*content_includes).first || raise(ActiveRecord::RecordNotFound) end authorize! :show, @content @@ -48,8 +48,8 @@ def show def content_includes [ { - essence: :ingredient_association - } + essence: :ingredient_association, + }, ] end end diff --git a/app/controllers/alchemy/api/elements_controller.rb b/app/controllers/alchemy/api/elements_controller.rb index 45367a8104..3d83612f8b 100644 --- a/app/controllers/alchemy/api/elements_controller.rb +++ b/app/controllers/alchemy/api/elements_controller.rb @@ -41,18 +41,18 @@ def element_includes nested_elements: [ { contents: { - essence: :ingredient_association - } + essence: :ingredient_association, + }, }, - :tags - ] + :tags, + ], }, { contents: { - essence: :ingredient_association - } + essence: :ingredient_association, + }, }, - :tags + :tags, ] end end diff --git a/app/controllers/alchemy/api/pages_controller.rb b/app/controllers/alchemy/api/pages_controller.rb index 0946d6a39e..30123399cb 100644 --- a/app/controllers/alchemy/api/pages_controller.rb +++ b/app/controllers/alchemy/api/pages_controller.rb @@ -64,7 +64,7 @@ def load_page_by_urlname Language.current.pages.where( urlname: params[:urlname], - language_code: params[:locale] || Language.current.code + language_code: params[:locale] || Language.current.code, ).includes(page_includes).first end @@ -72,7 +72,7 @@ def meta_data { total_count: total_count_value, per_page: per_page_value, - page: page_value + page: page_value, } end @@ -101,20 +101,20 @@ def page_includes nested_elements: [ { contents: { - essence: :ingredient_association - } + essence: :ingredient_association, + }, }, - :tags - ] + :tags, + ], }, { contents: { - essence: :ingredient_association - } + essence: :ingredient_association, + }, }, - :tags - ] - } + :tags, + ], + }, ] end end diff --git a/app/controllers/alchemy/attachments_controller.rb b/app/controllers/alchemy/attachments_controller.rb index 3327d67849..8c00baa2a1 100644 --- a/app/controllers/alchemy/attachments_controller.rb +++ b/app/controllers/alchemy/attachments_controller.rb @@ -13,8 +13,8 @@ def show { filename: @attachment.file_name, type: @attachment.file_mime_type, - disposition: 'inline' - } + disposition: 'inline', + }, ) end @@ -24,7 +24,7 @@ def download send_file( @attachment.file.path, { filename: @attachment.file_name, - type: @attachment.file_mime_type + type: @attachment.file_mime_type, } ) end diff --git a/app/controllers/alchemy/messages_controller.rb b/app/controllers/alchemy/messages_controller.rb index 1503f71b6e..e29d48e7f3 100644 --- a/app/controllers/alchemy/messages_controller.rb +++ b/app/controllers/alchemy/messages_controller.rb @@ -44,7 +44,7 @@ class MessagesController < Alchemy::BaseController def index #:nodoc: redirect_to show_page_path( urlname: @page.urlname, - locale: prefix_locale? ? @page.language_code : nil + locale: prefix_locale? ? @page.language_code : nil, ) end @@ -100,7 +100,7 @@ def redirect_to_success_page end redirect_to show_page_path( urlname: urlname, - locale: prefix_locale? ? Language.current.code : nil + locale: prefix_locale? ? Language.current.code : nil, ) end diff --git a/app/controllers/alchemy/pages_controller.rb b/app/controllers/alchemy/pages_controller.rb index 87c153d2e7..fde0a2cecc 100644 --- a/app/controllers/alchemy/pages_controller.rb +++ b/app/controllers/alchemy/pages_controller.rb @@ -6,7 +6,7 @@ class PagesController < Alchemy::BaseController 'action', 'controller', 'urlname', - 'locale' + 'locale', ] include OnPageLayout::CallbacksRunner @@ -112,7 +112,7 @@ def load_page @page ||= Language.current.pages.contentpages.find_by( urlname: params[:urlname], - language_code: params[:locale] || Language.current.code + language_code: params[:locale] || Language.current.code, ) end diff --git a/app/controllers/concerns/alchemy/admin/uploader_responses.rb b/app/controllers/concerns/alchemy/admin/uploader_responses.rb index 4662ea384a..6a2f21f2e6 100644 --- a/app/controllers/concerns/alchemy/admin/uploader_responses.rb +++ b/app/controllers/concerns/alchemy/admin/uploader_responses.rb @@ -8,12 +8,12 @@ module UploaderResponses def successful_uploader_response(file:, status: :created) message = Alchemy.t(:upload_success, scope: [:uploader, file.class.model_name.i18n_key], - name: file.name + name: file.name, ) { json: uploader_response(file: file, message: message), - status: status + status: status, } end @@ -21,12 +21,12 @@ def failed_uploader_response(file:) message = Alchemy.t(:upload_failure, scope: [:uploader, file.class.model_name.i18n_key], error: file.errors[:file].join, - name: file.name + name: file.name, ) { json: uploader_response(file: file, message: message), - status: :unprocessable_entity + status: :unprocessable_entity, } end @@ -35,7 +35,7 @@ def failed_uploader_response(file:) def uploader_response(file:, message:) { files: [file.to_jq_upload], - growl_message: message + growl_message: message, } end end diff --git a/app/controllers/concerns/alchemy/legacy_page_redirects.rb b/app/controllers/concerns/alchemy/legacy_page_redirects.rb index e00780d26d..7f312a33a6 100644 --- a/app/controllers/concerns/alchemy/legacy_page_redirects.rb +++ b/app/controllers/concerns/alchemy/legacy_page_redirects.rb @@ -36,7 +36,7 @@ def legacy_page_redirect_url alchemy.show_page_path( locale: prefix_locale? ? page.language_code : nil, - urlname: page.urlname + urlname: page.urlname, ) end @@ -46,8 +46,8 @@ def legacy_urls LegacyPageUrl.joins(:page).where( urlname: urlname, Page.table_name => { - language_id: Language.current.id - } + language_id: Language.current.id, + }, ) end diff --git a/app/controllers/concerns/alchemy/page_redirects.rb b/app/controllers/concerns/alchemy/page_redirects.rb index 751f42c3e9..b39d766670 100644 --- a/app/controllers/concerns/alchemy/page_redirects.rb +++ b/app/controllers/concerns/alchemy/page_redirects.rb @@ -51,7 +51,7 @@ def public_child_redirect_url def page_redirect_url(options = {}) options = { locale: prefix_locale? ? @page.language_code : nil, - urlname: @page.urlname + urlname: @page.urlname, }.merge(options) alchemy.show_page_path additional_params.merge(options) diff --git a/app/decorators/alchemy/content_editor.rb b/app/decorators/alchemy/content_editor.rb index 2e5055aee5..ffb95d52e3 100644 --- a/app/decorators/alchemy/content_editor.rb +++ b/app/decorators/alchemy/content_editor.rb @@ -11,14 +11,14 @@ def to_partial_path def css_classes [ 'content_editor', - essence_partial_name + essence_partial_name, ].compact end def data_attributes { content_id: id, - content_name: name + content_name: name, } end diff --git a/app/decorators/alchemy/element_editor.rb b/app/decorators/alchemy/element_editor.rb index ba2b1ce838..a15bbac3b2 100644 --- a/app/decorators/alchemy/element_editor.rb +++ b/app/decorators/alchemy/element_editor.rb @@ -17,7 +17,7 @@ def css_classes taggable? ? 'taggable' : 'not-taggable', folded ? 'folded' : 'expanded', compact? ? 'compact' : nil, - fixed? ? 'is-fixed' : 'not-fixed' + fixed? ? 'is-fixed' : 'not-fixed', ].join(' ') end diff --git a/app/helpers/alchemy/admin/base_helper.rb b/app/helpers/alchemy/admin/base_helper.rb index af2ded90cf..ced2410879 100644 --- a/app/helpers/alchemy/admin/base_helper.rb +++ b/app/helpers/alchemy/admin/base_helper.rb @@ -111,7 +111,7 @@ def sites_for_select def js_filter_field(items, options = {}) options = { class: 'js_filter_field', - data: {'alchemy-list-filter' => items} + data: {'alchemy-list-filter' => items}, }.merge(options) content_tag(:div, class: 'js_filter_field_box') do concat text_field_tag(nil, nil, options) @@ -151,8 +151,8 @@ def link_to_confirm_dialog(link_string = "", message = "", url = "", html_option title: Alchemy.t(:please_confirm), message: message, ok_label: Alchemy.t("Yes"), - cancel_label: Alchemy.t("No") - }.to_json + cancel_label: Alchemy.t("No"), + }.to_json, ) ) end @@ -181,7 +181,7 @@ def button_with_confirm(value = "", url = "", options = {}, html_options = {}) message: Alchemy.t(:confirm_to_proceed), ok_label: Alchemy.t("Yes"), title: Alchemy.t(:please_confirm), - cancel_label: Alchemy.t("No") + cancel_label: Alchemy.t("No"), }.merge(options) form_tag url, {method: html_options.delete(:method), class: 'button-with-confirm'} do button_tag value, html_options.merge('data-alchemy-confirm' => options.to_json) @@ -201,16 +201,16 @@ def delete_button(url, options = {}, html_options = {}) options = { title: Alchemy.t('Delete'), message: Alchemy.t('Are you sure?'), - icon: :minus + icon: :minus, }.merge(options) button_with_confirm( render_icon(options[:icon]), url, { - message: options[:message] + message: options[:message], }, { method: 'delete', title: options[:title], - class: "icon_button #{html_options.delete(:class)}".strip + class: "icon_button #{html_options.delete(:class)}".strip, }.merge(html_options) ) end @@ -270,11 +270,11 @@ def toolbar_button(options = {}) active: false, link_options: {}, dialog_options: {}, - loading_indicator: false + loading_indicator: false, }.merge(options.symbolize_keys) button = render( 'alchemy/admin/partials/toolbar_button', - options: options + options: options, ) if options[:skip_permission_check] || can?(*permission_from_options(options)) button @@ -313,7 +313,7 @@ def toolbar_button(options = {}) def toolbar(options = {}) defaults = { buttons: [], - search: true + search: true, } options = defaults.merge(options) content_for(:toolbar) do @@ -397,7 +397,7 @@ def alchemy_body_class controller_name, action_name, content_for(:main_menu_style), - content_for(:alchemy_body_class) + content_for(:alchemy_body_class), ].compact end @@ -439,7 +439,7 @@ def hint_with_tooltip(text, icon: 'exclamation-triangle') # that explains the user that the page layout is missing def page_layout_missing_warning hint_with_tooltip( - Alchemy.t(:page_definition_missing) + Alchemy.t(:page_definition_missing), ) end @@ -457,7 +457,7 @@ def permission_array_from_url(options) action_controller = options[:url].gsub(/\A\//, '').split('/') [ action_controller.last.to_sym, - action_controller[0..action_controller.length - 2].join('_').to_sym + action_controller[0..action_controller.length - 2].join('_').to_sym, ] end end diff --git a/app/helpers/alchemy/admin/contents_helper.rb b/app/helpers/alchemy/admin/contents_helper.rb index 609d6980a7..f6c1f58950 100644 --- a/app/helpers/alchemy/admin/contents_helper.rb +++ b/app/helpers/alchemy/admin/contents_helper.rb @@ -23,7 +23,7 @@ def render_content_name(content) warning("Content #{content.name} is missing its definition") icon = hint_with_tooltip( - Alchemy.t(:content_definition_missing) + Alchemy.t(:content_definition_missing), ) content_name = "#{icon} #{content_name}".html_safe diff --git a/app/helpers/alchemy/admin/elements_helper.rb b/app/helpers/alchemy/admin/elements_helper.rb index 07b01eb8ca..16a8b9b3d7 100644 --- a/app/helpers/alchemy/admin/elements_helper.rb +++ b/app/helpers/alchemy/admin/elements_helper.rb @@ -17,7 +17,7 @@ def elements_for_select(elements) elements.collect do |e| [ Element.display_name_for(e['name']), - e['name'] + e['name'], ] end end diff --git a/app/helpers/alchemy/admin/essences_helper.rb b/app/helpers/alchemy/admin/essences_helper.rb index 9f67587dca..78a3915f5e 100644 --- a/app/helpers/alchemy/admin/essences_helper.rb +++ b/app/helpers/alchemy/admin/essences_helper.rb @@ -14,7 +14,7 @@ def essence_picture_thumbnail(content) essence.thumbnail_url, alt: picture.name, class: 'img_paddingtop', - title: Alchemy.t(:image_name) + ": #{picture.name}" + title: Alchemy.t(:image_name) + ": #{picture.name}", ) end diff --git a/app/helpers/alchemy/admin/form_helper.rb b/app/helpers/alchemy/admin/form_helper.rb index 2e0dc0a9cd..34daba6aca 100644 --- a/app/helpers/alchemy/admin/form_helper.rb +++ b/app/helpers/alchemy/admin/form_helper.rb @@ -19,7 +19,7 @@ def alchemy_form_for(object, *args, &block) options[:remote] = request.xhr? options[:html] = { id: options.delete(:id), - class: ["alchemy", options.delete(:class)].compact.join(' ') + class: ["alchemy", options.delete(:class)].compact.join(' '), } simple_form_for(object, *(args << options), &block) end diff --git a/app/helpers/alchemy/admin/navigation_helper.rb b/app/helpers/alchemy/admin/navigation_helper.rb index 846e08a628..c742f0c8e2 100644 --- a/app/helpers/alchemy/admin/navigation_helper.rb +++ b/app/helpers/alchemy/admin/navigation_helper.rb @@ -14,7 +14,7 @@ def alchemy_main_navigation_entry(alchemy_module) render( 'alchemy/admin/partials/main_navigation_entry', alchemy_module: alchemy_module, - navigation: alchemy_module['navigation'] + navigation: alchemy_module['navigation'], ) end @@ -37,7 +37,7 @@ def alchemy_main_navigation_entry(alchemy_module) def navigate_module(navigation) [ navigation['action'].to_sym, - navigation['controller'].to_s.gsub(/\A\//, '').gsub(/\//, '_').to_sym + navigation['controller'].to_s.gsub(/\A\//, '').gsub(/\//, '_').to_sym, ] end @@ -47,7 +47,7 @@ def main_navigation_css_classes(navigation) [ 'main_navi_entry', admin_mainnavi_active?(navigation) ? 'active' : nil, - navigation.key?('sub_navigation') ? 'has_sub_navigation' : nil + navigation.key?('sub_navigation') ? 'has_sub_navigation' : nil, ].compact end @@ -75,7 +75,7 @@ def entry_active?(entry) def url_for_module(alchemy_module) route_from_engine_or_main_app( alchemy_module['engine_name'], - url_options_for_module(alchemy_module) + url_options_for_module(alchemy_module), ) end @@ -94,7 +94,7 @@ def url_for_module_sub_navigation(navigation) route_from_engine_or_main_app( alchemy_module['engine_name'], - url_options_for_navigation_entry(navigation) + url_options_for_navigation_entry(navigation), ) end @@ -151,7 +151,7 @@ def url_options_for_navigation_entry(entry) controller: entry['controller'], action: entry['action'], only_path: true, - params: entry['params'] + params: entry['params'], }.delete_if { |_k, v| v.nil? } end diff --git a/app/helpers/alchemy/admin/pages_helper.rb b/app/helpers/alchemy/admin/pages_helper.rb index f46664bff3..53555cea55 100644 --- a/app/helpers/alchemy/admin/pages_helper.rb +++ b/app/helpers/alchemy/admin/pages_helper.rb @@ -15,7 +15,7 @@ def preview_sizes_for_select [Alchemy.t('480', scope: 'preview_sizes'), 480], [Alchemy.t('768', scope: 'preview_sizes'), 768], [Alchemy.t('1024', scope: 'preview_sizes'), 1024], - [Alchemy.t('1280', scope: 'preview_sizes'), 1280] + [Alchemy.t('1280', scope: 'preview_sizes'), 1280], ]) end @@ -27,7 +27,7 @@ def page_layout_label(page) if page.persisted? && page.definition.blank? [ page_layout_missing_warning, - Alchemy.t(:page_type) + Alchemy.t(:page_type), ].join(' ').html_safe else Alchemy.t(:page_type) diff --git a/app/helpers/alchemy/admin/tags_helper.rb b/app/helpers/alchemy/admin/tags_helper.rb index c9e7a9709a..95d6628ae9 100644 --- a/app/helpers/alchemy/admin/tags_helper.rb +++ b/app/helpers/alchemy/admin/tags_helper.rb @@ -20,10 +20,10 @@ def render_tag_list(class_name) "#{tag.name} (#{tag.taggings_count})", url_for( search_filter_params.except(:page, :tagged_with).merge( - tagged_with: tags_for_filter(current: tag).presence - ) + tagged_with: tags_for_filter(current: tag).presence, + ), ), - remote: request.xhr? + remote: request.xhr?, ) end end.join.html_safe diff --git a/app/helpers/alchemy/base_helper.rb b/app/helpers/alchemy/base_helper.rb index 55c60f98c3..a944096cc4 100644 --- a/app/helpers/alchemy/base_helper.rb +++ b/app/helpers/alchemy/base_helper.rb @@ -34,7 +34,7 @@ def render_icon(icon_class, options = {}) "fa#{options[:style].first}", options[:size] ? "fa-#{options[:size]}" : nil, options[:transform] ? "fa-#{options[:transform]}" : nil, - options[:class] + options[:class], ].compact content_tag('i', nil, class: classes) end diff --git a/app/helpers/alchemy/elements_block_helper.rb b/app/helpers/alchemy/elements_block_helper.rb index 91aafeed07..6d5e0459c8 100644 --- a/app/helpers/alchemy/elements_block_helper.rb +++ b/app/helpers/alchemy/elements_block_helper.rb @@ -33,7 +33,7 @@ def render(name, options = {}, html_options = {}) helpers.render(content, { content: content, options: options, - html_options: html_options + html_options: html_options, }) end @@ -107,7 +107,7 @@ def element_view_for(element, options = {}) tag: :div, id: element_dom_id(element), class: element.name, - tags_formatter: ->(tags) { tags.join(" ") } + tags_formatter: ->(tags) { tags.join(" ") }, }.merge(options) # capture inner template block diff --git a/app/helpers/alchemy/elements_helper.rb b/app/helpers/alchemy/elements_helper.rb index 981ee81503..ed66342772 100644 --- a/app/helpers/alchemy/elements_helper.rb +++ b/app/helpers/alchemy/elements_helper.rb @@ -91,7 +91,7 @@ module ElementsHelper def render_elements(options = {}) options = { from_page: @page, - render_format: 'html' + render_format: 'html', }.update(options) finder = options[:finder] || Alchemy::ElementsFinder.new(options) @@ -160,7 +160,7 @@ def render_element(element, options = {}, counter = 1) render element, { element: element, counter: counter, - options: options + options: options, }.merge(options.delete(:locals) || {}) rescue ActionView::MissingTemplate => e warning(%( @@ -224,7 +224,7 @@ def element_tags(element, options = {}) # def element_tags_attributes(element, options = {}) options = { - formatter: lambda { |tags| tags.join(' ') } + formatter: lambda { |tags| tags.join(' ') }, }.merge(options) return {} if !element.taggable? || element.tag_list.blank? diff --git a/app/helpers/alchemy/pages_helper.rb b/app/helpers/alchemy/pages_helper.rb index b9af4d9c5c..c2646da0f5 100644 --- a/app/helpers/alchemy/pages_helper.rb +++ b/app/helpers/alchemy/pages_helper.rb @@ -28,7 +28,7 @@ def language_links(options = {}) linkname: 'name', show_title: true, spacer: '', - reverse: false + reverse: false, }.merge(options) languages = Language.on_current_site.published.with_root_page.order("name #{options[:reverse] ? 'DESC' : 'ASC'}") return nil if languages.count < 2 @@ -37,7 +37,7 @@ def language_links(options = {}) partial: "alchemy/language_links/language", collection: languages, spacer_template: "alchemy/language_links/spacer", - locals: {languages: languages, options: options} + locals: {languages: languages, options: options}, ) end @@ -83,7 +83,7 @@ def render_site_layout def render_menu(name, options = {}) root_node = Alchemy::Node.roots.find_by( name: name, - language: Alchemy::Language.current + language: Alchemy::Language.current, ) if root_node.nil? warning("Menu with name #{name} not found!") @@ -91,7 +91,7 @@ def render_menu(name, options = {}) end options = { - node_partial_name: "#{root_node.view_folder_name}/node" + node_partial_name: "#{root_node.view_folder_name}/node", }.merge(options) render(root_node.to_partial_path, menu: root_node, node: root_node, options: options) @@ -124,7 +124,7 @@ def render_breadcrumb(options = {}) page: @page, restricted_only: false, reverse: false, - link_active_page: false + link_active_page: false, }.merge(options) pages = Page. @@ -160,7 +160,7 @@ def page_title(options = {}) options = { prefix: "", suffix: "", - separator: "" + separator: "", }.update(options) title_parts = [options[:prefix]] if response.status == 200 diff --git a/app/mailers/alchemy/messages_mailer.rb b/app/mailers/alchemy/messages_mailer.rb index 61640737e3..b5d2e77080 100644 --- a/app/mailers/alchemy/messages_mailer.rb +++ b/app/mailers/alchemy/messages_mailer.rb @@ -8,7 +8,7 @@ def contact_form_mail(message, mail_to, mail_from, subject) from: mail_from, to: mail_to, reply_to: message.try(:email), - subject: subject + subject: subject, ) end end diff --git a/app/models/alchemy/attachment.rb b/app/models/alchemy/attachment.rb index a3b9a451eb..b16e8d91ae 100644 --- a/app/models/alchemy/attachment.rb +++ b/app/models/alchemy/attachment.rb @@ -71,7 +71,7 @@ def to_jq_upload { "name" => read_attribute(:file_name), "size" => read_attribute(:file_size), - 'error' => errors[:file].join + 'error' => errors[:file].join, } end diff --git a/app/models/alchemy/content.rb b/app/models/alchemy/content.rb index 25621726c7..296e07c912 100644 --- a/app/models/alchemy/content.rb +++ b/app/models/alchemy/content.rb @@ -72,7 +72,7 @@ def translated_label_for(content_name, element_name = nil) Alchemy.t( content_name, scope: "content_names.#{element_name}", - default: Alchemy.t("content_names.#{content_name}", default: content_name.humanize) + default: Alchemy.t("content_names.#{content_name}", default: content_name.humanize), ) end end @@ -132,7 +132,7 @@ def serialize { name: name, value: serialized_ingredient, - link: essence.try(:link) + link: essence.try(:link), }.delete_if { |_k, v| v.blank? } end diff --git a/app/models/alchemy/content/factory.rb b/app/models/alchemy/content/factory.rb index c01ba3505b..0369df0dae 100644 --- a/app/models/alchemy/content/factory.rb +++ b/app/models/alchemy/content/factory.rb @@ -56,11 +56,11 @@ def copy(source, differences = {}) new_content = Content.new( source.attributes. except(*SKIPPED_ATTRIBUTES_ON_COPY). - merge(differences.with_indifferent_access) + merge(differences.with_indifferent_access), ) new_essence = source.essence.class.create!( source.essence.attributes. - except(*SKIPPED_ATTRIBUTES_ON_COPY) + except(*SKIPPED_ATTRIBUTES_ON_COPY), ) new_content.tap do |content| content.essence = new_essence @@ -119,7 +119,7 @@ def definition # def build_essence(type = essence_type) self.essence = essence_class(type).new({ - ingredient: default_value + ingredient: default_value, }) end diff --git a/app/models/alchemy/element.rb b/app/models/alchemy/element.rb index 2385a3269c..ebcfb0fffb 100644 --- a/app/models/alchemy/element.rb +++ b/app/models/alchemy/element.rb @@ -34,7 +34,7 @@ class Element < BaseRecord "hint", "taggable", "compact", - "message" + "message", ].freeze SKIPPED_ATTRIBUTES_ON_COPY = [ @@ -45,7 +45,7 @@ class Element < BaseRecord "folded", "position", "updated_at", - "updater_id" + "updater_id", ].freeze # All Elements that share the same page id and parent element id and are fixed or not are considered a list. @@ -64,13 +64,13 @@ class Element < BaseRecord has_many :all_nested_elements, -> { order(:position).not_trashed }, - class_name: 'Alchemy::Element', + class_name: "Alchemy::Element", foreign_key: :parent_element_id, dependent: :destroy has_many :nested_elements, -> { order(:position).available }, - class_name: 'Alchemy::Element', + class_name: "Alchemy::Element", foreign_key: :parent_element_id, dependent: :destroy, inverse_of: :parent_element @@ -79,13 +79,13 @@ class Element < BaseRecord # A nested element belongs to a parent element. belongs_to :parent_element, - class_name: 'Alchemy::Element', + class_name: "Alchemy::Element", optional: true, touch: true, inverse_of: :nested_elements has_and_belongs_to_many :touchable_pages, -> { distinct }, - class_name: 'Alchemy::Page', + class_name: "Alchemy::Page", join_table: ElementToPage.table_name validates_presence_of :name, on: :create @@ -98,19 +98,19 @@ class Element < BaseRecord after_update :touch_touchable_pages - scope :trashed, -> { where(position: nil).order('updated_at DESC') } - scope :not_trashed, -> { where.not(position: nil) } - scope :published, -> { where(public: true) } - scope :not_restricted, -> { joins(:page).merge(Page.not_restricted) } - scope :available, -> { published.not_trashed } - scope :named, ->(names) { where(name: names) } - scope :excluded, ->(names) { where.not(name: names) } - scope :fixed, -> { where(fixed: true) } - scope :unfixed, -> { where(fixed: false) } - scope :from_current_site, -> { where(Language.table_name => {site_id: Site.current || Site.default}).joins(page: 'language') } - scope :folded, -> { where(folded: true) } - scope :expanded, -> { where(folded: false) } - scope :not_nested, -> { where(parent_element_id: nil) } + scope :trashed, -> { where(position: nil).order("updated_at DESC") } + scope :not_trashed, -> { where.not(position: nil) } + scope :published, -> { where(public: true) } + scope :not_restricted, -> { joins(:page).merge(Page.not_restricted) } + scope :available, -> { published.not_trashed } + scope :named, ->(names) { where(name: names) } + scope :excluded, ->(names) { where.not(name: names) } + scope :fixed, -> { where(fixed: true) } + scope :unfixed, -> { where(fixed: false) } + scope :from_current_site, -> { where(Language.table_name => { site_id: Site.current || Site.default }).joins(page: "language") } + scope :folded, -> { where(folded: true) } + scope :expanded, -> { where(folded: false) } + scope :not_nested, -> { where(parent_element_id: nil) } delegate :restricted?, to: :page, allow_nil: true @@ -132,7 +132,7 @@ class << self def new(attributes = {}) return super if attributes[:name].blank? - element_attributes = attributes.to_h.merge(name: attributes[:name].split('#').first) + element_attributes = attributes.to_h.merge(name: attributes[:name].split("#").first) element_definition = Element.definition_by_name(element_attributes[:name]) if element_definition.nil? raise(ElementDefinitionError, attributes) @@ -154,13 +154,13 @@ def new(attributes = {}) # def copy(source_element, differences = {}) attributes = source_element.attributes.with_indifferent_access - .except(*SKIPPED_ATTRIBUTES_ON_COPY) - .merge(differences) - .merge({ - autogenerate_contents: false, - autogenerate_nested_elements: false, - tag_list: source_element.tag_list - }) + .except(*SKIPPED_ATTRIBUTES_ON_COPY) + .merge(differences) + .merge({ + autogenerate_contents: false, + autogenerate_nested_elements: false, + tag_list: source_element.tag_list, + }) new_element = create!(attributes) @@ -178,7 +178,7 @@ def copy(source_element, differences = {}) def all_from_clipboard(clipboard) return [] if clipboard.nil? - where(id: clipboard.collect { |e| e['id'] }) + where(id: clipboard.collect { |e| e["id"] }) end # All elements in clipboard that could be placed on page @@ -197,7 +197,7 @@ def all_from_clipboard_for_page(clipboard, page) # Pass an element name to get next of this kind. # def next(name = nil) - elements = page.elements.published.where('position > ?', position) + elements = page.elements.published.where("position > ?", position) select_element(elements, name, :asc) end @@ -206,7 +206,7 @@ def next(name = nil) # Pass an element name to get previous of this kind. # def prev(name = nil) - elements = page.elements.published.where('position < ?', position) + elements = page.elements.published.where("position < ?", position) select_element(elements, name, :desc) end @@ -232,7 +232,7 @@ def trashed? # Returns true if the definition of this element has a taggable true value. def taggable? - definition['taggable'] == true + definition["taggable"] == true end # The opposite of folded? @@ -242,7 +242,7 @@ def expanded? # Defined as compact element? def compact? - definition['compact'] == true + definition["compact"] == true end # The element's view partial is dependent from its name @@ -279,7 +279,7 @@ def cache_key # A collection of element names that can be nested inside this element. def nestable_elements - definition.fetch('nestable_elements', []) + definition.fetch("nestable_elements", []) end # Copy all nested elements from current element to given target element. @@ -287,7 +287,7 @@ def copy_nested_elements_to(target_element) nested_elements.map do |nested_element| Element.copy(nested_element, { parent_element_id: target_element.id, - page_id: target_element.page_id + page_id: target_element.page_id, }) end end @@ -295,7 +295,7 @@ def copy_nested_elements_to(target_element) private def generate_nested_elements - definition.fetch('autogenerate', []).each do |nestable_element| + definition.fetch("autogenerate", []).each do |nestable_element| if nestable_elements.include?(nestable_element) Element.create(page: page, parent_element_id: id, name: nestable_element) else diff --git a/app/models/alchemy/element/element_essences.rb b/app/models/alchemy/element/element_essences.rb index 706cde4fb2..86dd423531 100644 --- a/app/models/alchemy/element/element_essences.rb +++ b/app/models/alchemy/element/element_essences.rb @@ -100,9 +100,9 @@ def essence_error_messages scope: 'content_validations', default: [ "fields.#{content_name}.#{error}".to_sym, - "errors.#{error}".to_sym + "errors.#{error}".to_sym, ], - field: Content.translated_label_for(content_name, name) + field: Content.translated_label_for(content_name, name), ) end end diff --git a/app/models/alchemy/essence_file.rb b/app/models/alchemy/essence_file.rb index c732875553..54205556dd 100644 --- a/app/models/alchemy/essence_file.rb +++ b/app/models/alchemy/essence_file.rb @@ -26,7 +26,7 @@ def attachment_url routes.download_attachment_path( id: attachment.id, name: attachment.urlname, - format: attachment.suffix + format: attachment.suffix, ) end diff --git a/app/models/alchemy/essence_node.rb b/app/models/alchemy/essence_node.rb index b39a8e6ec4..031f9ff1ef 100644 --- a/app/models/alchemy/essence_node.rb +++ b/app/models/alchemy/essence_node.rb @@ -11,8 +11,8 @@ class EssenceNode < BaseRecord class_name: "Alchemy::Node", foreign_key: :node_id, inverse_of: :essence_nodes, - optional: true - } + optional: true, + }, ) delegate :name, to: :node, prefix: true diff --git a/app/models/alchemy/essence_page.rb b/app/models/alchemy/essence_page.rb index ad369cd975..eecb7e4944 100644 --- a/app/models/alchemy/essence_page.rb +++ b/app/models/alchemy/essence_page.rb @@ -11,8 +11,8 @@ class EssencePage < BaseRecord class_name: 'Alchemy::Page', foreign_key: :page_id, inverse_of: :essence_pages, - optional: true - } + optional: true, + }, ) def ingredient=(page) diff --git a/app/models/alchemy/essence_picture.rb b/app/models/alchemy/essence_picture.rb index 4acb98e755..5212c25cf1 100644 --- a/app/models/alchemy/essence_picture.rb +++ b/app/models/alchemy/essence_picture.rb @@ -29,7 +29,7 @@ class EssencePicture < BaseRecord class_name: 'Alchemy::Picture', foreign_key: :picture_id, inverse_of: :essence_pictures, - optional: true + optional: true, } delegate :image_file_width, :image_file_height, :image_file, to: :picture @@ -80,7 +80,7 @@ def picture_url_options format: picture.default_render_format, crop_from: crop_from.presence, crop_size: crop_size.presence, - size: content.settings[:size] + size: content.settings[:size], }.with_indifferent_access end @@ -102,7 +102,7 @@ def thumbnail_url crop_from: crop_from.presence, crop_size: crop_size.presence, flatten: true, - format: picture.image_file_format + format: picture.image_file_format, } picture.url(options) @@ -144,7 +144,7 @@ def allow_image_cropping? content && content.settings[:crop] && picture && picture.can_be_cropped_to( content.settings[:size], - content.settings[:upsample] + content.settings[:upsample], ) end diff --git a/app/models/alchemy/essence_picture_view.rb b/app/models/alchemy/essence_picture_view.rb index 30c1f6e3d0..2a67b3edeb 100644 --- a/app/models/alchemy/essence_picture_view.rb +++ b/app/models/alchemy/essence_picture_view.rb @@ -13,7 +13,7 @@ class EssencePictureView show_caption: true, disable_link: false, srcset: [], - sizes: [] + sizes: [], }.with_indifferent_access def initialize(content, options = {}, html_options = {}) @@ -33,7 +33,7 @@ def render output = link_to(output, url_for(essence.link), { title: essence.link_title.presence, target: essence.link_target == "blank" ? "_blank" : nil, - data: {link_target: essence.link_target.presence} + data: {link_target: essence.link_target.presence}, }) end @@ -59,7 +59,7 @@ def img_tag title: essence.title.presence, class: caption ? nil : essence.css_class.presence, srcset: srcset.join(', ').presence, - sizes: options[:sizes].join(', ').presence + sizes: options[:sizes].join(', ').presence, }.merge(caption ? {} : html_options) ) end diff --git a/app/models/alchemy/language/code.rb b/app/models/alchemy/language/code.rb index 3b90d98b75..aafbee1cc4 100644 --- a/app/models/alchemy/language/code.rb +++ b/app/models/alchemy/language/code.rb @@ -17,7 +17,7 @@ def find_by_code(code) codes << '' if codes.length == 1 on_current_site.find_by( language_code: codes[0], - country_code: codes[1] + country_code: codes[1], ) end end diff --git a/app/models/alchemy/page.rb b/app/models/alchemy/page.rb index f4d6b051d9..cf8bf98413 100644 --- a/app/models/alchemy/page.rb +++ b/app/models/alchemy/page.rb @@ -48,7 +48,7 @@ class Page < BaseRecord public_on: nil, public_until: nil, locked_at: nil, - locked_by: nil + locked_by: nil, } SKIPPED_ATTRIBUTES_ON_COPY = %w( @@ -80,7 +80,7 @@ class Page < BaseRecord :urlname, :visible, :layoutpage, - :menu_id + :menu_id, ] acts_as_nested_set(dependent: :destroy) @@ -110,8 +110,8 @@ class Page < BaseRecord has_one :site, through: :language has_many :site_languages, through: :site, source: :languages has_many :folded_pages - has_many :legacy_urls, class_name: 'Alchemy::LegacyPageUrl' - has_many :nodes, class_name: 'Alchemy::Node', inverse_of: :page + has_many :legacy_urls, class_name: "Alchemy::LegacyPageUrl" + has_many :nodes, class_name: "Alchemy::Node", inverse_of: :page validates_presence_of :language, on: :create, unless: :root validates_presence_of :page_layout, unless: :systempage? @@ -170,8 +170,9 @@ class << self # Automatically created when accessed the first time. # def root - super || create!(name: 'Root') + super || create!(name: "Root") end + alias_method :rootpage, :root # Used to store the current page previewed in the edit page template. @@ -218,7 +219,7 @@ def copy(source, differences = {}) end def layout_root_for(language_id) - where({parent_id: Page.root.id, layoutpage: true, language_id: language_id}).limit(1).first + where({ parent_id: Page.root.id, layoutpage: true, language_id: language_id }).limit(1).first end def find_or_create_layout_root_for(language_id) @@ -231,7 +232,7 @@ def find_or_create_layout_root_for(language_id) layoutpage: true, language: language, autogenerate_elements: false, - parent_id: Page.root.id + parent_id: Page.root.id, ) end @@ -240,7 +241,7 @@ def copy_and_paste(source, new_parent, new_name) parent_id: new_parent.id, language: new_parent.language, name: new_name, - title: new_name + title: new_name, }) if source.children.any? source.copy_children_to(page) @@ -251,7 +252,7 @@ def copy_and_paste(source, new_parent, new_name) def all_from_clipboard(clipboard) return [] if clipboard.blank? - where(id: clipboard.collect { |p| p['id'] }) + where(id: clipboard.collect { |p| p["id"] }) end def all_from_clipboard_for_select(clipboard, language_id, layoutpage = false) @@ -259,16 +260,16 @@ def all_from_clipboard_for_select(clipboard, language_id, layoutpage = false) clipboard_pages = all_from_clipboard(clipboard) allowed_page_layouts = Alchemy::PageLayout.selectable_layouts(language_id, layoutpage) - allowed_page_layout_names = allowed_page_layouts.collect { |p| p['name'] } + allowed_page_layout_names = allowed_page_layouts.collect { |p| p["name"] } clipboard_pages.select { |cp| allowed_page_layout_names.include?(cp.page_layout) } end def link_target_options - options = [[Alchemy.t(:default, scope: 'link_target_options'), '']] + options = [[Alchemy.t(:default, scope: "link_target_options"), ""]] link_target_options = Config.get(:link_target_options) link_target_options.each do |option| - options << [Alchemy.t(option, scope: 'link_target_options', - default: option.to_s.humanize), option] + options << [Alchemy.t(option, scope: "link_target_options", + default: option.to_s.humanize), option] end options end @@ -295,7 +296,7 @@ def attributes_from_source_for_copy(source, differences = {}) differences.stringify_keys! attributes = source.attributes.merge(differences) attributes.merge!(DEFAULT_ATTRIBUTES_FOR_COPY) - attributes['name'] = new_name_for_copy(differences['name'], source.name) + attributes["name"] = new_name_for_copy(differences["name"], source.name) attributes.except(*SKIPPED_ATTRIBUTES_ON_COPY) end @@ -312,7 +313,7 @@ def attributes_from_source_for_copy(source, differences = {}) def new_name_for_copy(custom_name, source_name) return custom_name if custom_name.present? - "#{source_name} (#{Alchemy.t('Copy')})" + "#{source_name} (#{Alchemy.t("Copy")})" end end @@ -371,9 +372,10 @@ def to_partial_path # only public pages (true), skip public pages (false) # def previous(options = {}) - pages = self_and_siblings.where('lft < ?', lft) + pages = self_and_siblings.where("lft < ?", lft) select_page(pages, options.merge(order: :desc)) end + alias_method :previous_page, :previous # Returns the next page on the same level or nil. @@ -384,9 +386,10 @@ def previous(options = {}) # only public pages (true), skip public pages (false) # def next(options = {}) - pages = self_and_siblings.where('lft > ?', lft) + pages = self_and_siblings.where("lft > ?", lft) select_page(pages, options.merge(order: :asc)) end + alias_method :next_page, :next # Locks the page to given user @@ -435,7 +438,7 @@ def copy_children_to(new_parent) new_child = Page.copy(child, { language_id: new_parent.language_id, - language_code: new_parent.language_code + language_code: new_parent.language_code, }) new_child.move_to_child_of(new_parent) child.copy_children_to(new_child) unless child.children.blank? @@ -454,7 +457,7 @@ def publish! update_columns( published_at: current_time, public_on: already_public_for?(current_time) ? public_on : current_time, - public_until: still_public_for?(current_time) ? public_until : nil + public_until: still_public_for?(current_time) ? public_until : nil, ) end @@ -467,7 +470,7 @@ def publish! # A tree node with new lft, rgt, depth, url, parent_id and restricted indexes to be updated # def update_node!(node) - hash = {lft: node.left, rgt: node.right, parent_id: node.parent, depth: node.depth, restricted: node.restricted} + hash = { lft: node.left, rgt: node.right, parent_id: node.parent, depth: node.depth, restricted: node.restricted } if Config.get(:url_nesting) && urlname != node.url LegacyPageUrl.create(page_id: id, urlname: urlname) @@ -520,7 +523,7 @@ def public_until # does not respond to +#name+ it returns +'unknown'+ # def creator_name - creator.try(:name) || Alchemy.t('unknown') + creator.try(:name) || Alchemy.t("unknown") end # Returns the name of the last updater of this page. @@ -529,7 +532,7 @@ def creator_name # does not respond to +#name+ it returns +'unknown'+ # def updater_name - updater.try(:name) || Alchemy.t('unknown') + updater.try(:name) || Alchemy.t("unknown") end # Returns the name of the user currently editing this page. @@ -538,7 +541,7 @@ def updater_name # does not respond to +#name+ it returns +'unknown'+ # def locker_name - locker.try(:name) || Alchemy.t('unknown') + locker.try(:name) || Alchemy.t("unknown") end # Menus (aka. root nodes) this page is attached to @@ -600,7 +603,7 @@ def attach_to_menu! site_id: current_site_id, language_id: language_id, page_id: id, - name: name + name: name, ) end diff --git a/app/models/alchemy/page/page_elements.rb b/app/models/alchemy/page/page_elements.rb index 7caa06ce01..848d0f2679 100644 --- a/app/models/alchemy/page/page_elements.rb +++ b/app/models/alchemy/page/page_elements.rb @@ -53,7 +53,7 @@ def copy_elements(source, target) source_elements = source.all_elements.not_nested.not_trashed source_elements.order(:position).map do |source_element| Element.copy(source_element, { - page_id: target.id + page_id: target.id, }).tap(&:move_to_bottom) end end @@ -206,7 +206,7 @@ def generate_elements def trash_not_allowed_elements! not_allowed_elements = elements.where([ "#{Element.table_name}.name NOT IN (?)", - element_definition_names + element_definition_names, ]) not_allowed_elements.to_a.map(&:trash!) end diff --git a/app/models/alchemy/page/page_natures.rb b/app/models/alchemy/page/page_natures.rb index 63be5afe2b..19fcebd730 100644 --- a/app/models/alchemy/page/page_natures.rb +++ b/app/models/alchemy/page/page_natures.rb @@ -69,7 +69,7 @@ def status public: public?, visible: visible?, locked: locked?, - restricted: restricted? + restricted: restricted?, } end diff --git a/app/models/alchemy/page/page_scopes.rb b/app/models/alchemy/page/page_scopes.rb index acfbafd2a1..ae11093ab4 100644 --- a/app/models/alchemy/page/page_scopes.rb +++ b/app/models/alchemy/page/page_scopes.rb @@ -47,7 +47,7 @@ module Page::PageScopes # scope :public_language_roots, -> { published.language_roots.where( - language_code: Language.published.pluck(:language_code) + language_code: Language.published.pluck(:language_code), ) } diff --git a/app/models/alchemy/picture.rb b/app/models/alchemy/picture.rb index 9deb1fd11e..ff8b5c6d4d 100644 --- a/app/models/alchemy/picture.rb +++ b/app/models/alchemy/picture.rb @@ -167,7 +167,7 @@ def to_jq_upload { name: image_file_name, size: image_file_size, - error: errors[:image_file].join + error: errors[:image_file].join, } end diff --git a/app/models/alchemy/picture/transformations.rb b/app/models/alchemy/picture/transformations.rb index 1475a8c845..e3c59cf40e 100644 --- a/app/models/alchemy/picture/transformations.rb +++ b/app/models/alchemy/picture/transformations.rb @@ -80,7 +80,7 @@ def sizes_from_string(string = "0x0") height = 0 if height.nil? { width: width, - height: height + height: height, } end @@ -110,7 +110,7 @@ def square_format? def image_size { width: image_file_width, - height: image_file_height + height: image_file_height, } end @@ -149,7 +149,7 @@ def point_from_string(string = "0x0") y = 0 if y.nil? { x: x, - y: y + y: y, } end @@ -160,7 +160,7 @@ def point_from_string(string = "0x0") def get_top_left_crop_corner(dimensions) { x: (image_file_width - dimensions[:width]) / 2, - y: (image_file_height - dimensions[:height]) / 2 + y: (image_file_height - dimensions[:height]) / 2, } end @@ -184,7 +184,7 @@ def get_base_dimensions def size_when_fitting(target, dimensions = get_base_dimensions) zoom = [ dimensions[:width].to_f / target[:width], - dimensions[:height].to_f / target[:height] + dimensions[:height].to_f / target[:height], ].max if zoom == 0.0 @@ -207,7 +207,7 @@ def point_and_mask_to_points(point, mask) x1: point[:x], y1: point[:y], x2: point[:x] + mask[:width], - y2: point[:y] + mask[:height] + y2: point[:y] + mask[:height], } end @@ -254,7 +254,7 @@ def xy_crop_resize(dimensions, top_left, crop_dimensions, upsample) def reduce_to_image(dimensions) { width: [dimensions[:width], image_file_width].min, - height: [dimensions[:height], image_file_height].min + height: [dimensions[:height], image_file_height].min, } end end diff --git a/app/models/alchemy/picture/url.rb b/app/models/alchemy/picture/url.rb index 02f58da0fa..82300cd828 100644 --- a/app/models/alchemy/picture/url.rb +++ b/app/models/alchemy/picture/url.rb @@ -12,7 +12,7 @@ module Picture::Url :format, :quality, :size, - :upsample + :upsample, ] # Returns a path to picture for use inside a image_tag helper. @@ -66,7 +66,7 @@ def encoded_image(image, options = {}) end options = { - flatten: target_format != 'gif' && image_file_format == 'gif' + flatten: target_format != 'gif' && image_file_format == 'gif', }.merge(options) encoding_options = [] diff --git a/app/serializers/alchemy/essence_picture_serializer.rb b/app/serializers/alchemy/essence_picture_serializer.rb index 3082b78b39..a00a5e7c9f 100644 --- a/app/serializers/alchemy/essence_picture_serializer.rb +++ b/app/serializers/alchemy/essence_picture_serializer.rb @@ -21,7 +21,7 @@ def link url: object.link, css_class: object.link_class_name, title: object.link_title, - target: object.link_target + target: object.link_target, } end end diff --git a/app/serializers/alchemy/essence_text_serializer.rb b/app/serializers/alchemy/essence_text_serializer.rb index 3f1d9c6ec6..b8596cca78 100644 --- a/app/serializers/alchemy/essence_text_serializer.rb +++ b/app/serializers/alchemy/essence_text_serializer.rb @@ -15,7 +15,7 @@ def link url: object.link, title: object.link_title, css_class: object.link_class_name, - target: object.link_target + target: object.link_target, } end end diff --git a/app/serializers/alchemy/page_tree_serializer.rb b/app/serializers/alchemy/page_tree_serializer.rb index f6a36b6d29..aead2f6185 100644 --- a/app/serializers/alchemy/page_tree_serializer.rb +++ b/app/serializers/alchemy/page_tree_serializer.rb @@ -61,7 +61,7 @@ def page_hash(page, has_children, level, folded) level: level, root: level == 1, root_or_leaf: level == 1 || !has_children, - children: [] + children: [], } if opts[:elements] @@ -75,7 +75,7 @@ def page_hash(page, has_children, level, folded) locked: page.locked?, locked_notice: page.locked? ? Alchemy.t('This page is locked', name: page.locker_name) : nil, permissions: page_permissions(page, opts[:ability]), - status_titles: page_status_titles(page) + status_titles: page_status_titles(page), }) else p_hash @@ -97,7 +97,7 @@ def page_permissions(page, ability) copy: ability.can?(:copy, page), destroy: ability.can?(:destroy, page), create: ability.can?(:create, Alchemy::Page), - edit_content: ability.can?(:edit_content, page) + edit_content: ability.can?(:edit_content, page), } end @@ -105,7 +105,7 @@ def page_status_titles(page) { public: page.status_title(:public), visible: page.status_title(:visible), - restricted: page.status_title(:restricted) + restricted: page.status_title(:restricted), } end end diff --git a/lib/alchemy/elements_finder.rb b/lib/alchemy/elements_finder.rb index 0befac9a8b..50c4540f45 100644 --- a/lib/alchemy/elements_finder.rb +++ b/lib/alchemy/elements_finder.rb @@ -86,7 +86,7 @@ def get_page(page_or_layout) Alchemy::Page.find_by( language: Alchemy::Language.current, page_layout: page_or_layout, - restricted: false + restricted: false, ) end end diff --git a/lib/alchemy/engine.rb b/lib/alchemy/engine.rb index 60453a41e1..c1ea56042b 100644 --- a/lib/alchemy/engine.rb +++ b/lib/alchemy/engine.rb @@ -31,7 +31,7 @@ class Engine < Rails::Engine Ransack.configure do |config| config.custom_arrows = { up_arrow: '<i class="fa fas fa-xs fa-arrow-up"></i>', - down_arrow: '<i class="fa fas fa-xs fa-arrow-down"></i>' + down_arrow: '<i class="fa fas fa-xs fa-arrow-down"></i>', } end end @@ -52,7 +52,7 @@ class Engine < Rails::Engine app.middleware.use( Rack::Static, urls: ['/alchemy-packs', '/alchemy-packs-test'], - root: Alchemy::ROOT_PATH.join('public') + root: Alchemy::ROOT_PATH.join('public'), ) end end diff --git a/lib/alchemy/essence.rb b/lib/alchemy/essence.rb index 81baa58d20..81780ac62d 100644 --- a/lib/alchemy/essence.rb +++ b/lib/alchemy/essence.rb @@ -40,7 +40,7 @@ def acts_as_essence(options = {}) register_as_essence_association! configuration = { - ingredient_column: 'body' + ingredient_column: 'body', }.update(options) @_classes_with_ingredient_association ||= [] @@ -109,7 +109,7 @@ def _reflect_on_association(name) def register_as_essence_association! klass_name = model_name.to_s arguments = [:has_many, klass_name.demodulize.tableize.to_sym, through: :contents, - source: :essence, source_type: klass_name] + source: :essence, source_type: klass_name] %w(Page Element).each { |k| "Alchemy::#{k}".constantize.send(*arguments) } end end diff --git a/lib/alchemy/filetypes.rb b/lib/alchemy/filetypes.rb index 947b55de4c..d5461342bb 100644 --- a/lib/alchemy/filetypes.rb +++ b/lib/alchemy/filetypes.rb @@ -8,7 +8,7 @@ module Filetypes "audio/mpeg", "audio/mp4", "audio/wav", - "audio/x-wav" + "audio/x-wav", ] IMAGE_FILE_TYPES = [ @@ -17,7 +17,7 @@ module Filetypes "image/png", "image/svg+xml", "image/tiff", - "image/x-psd" + "image/x-psd", ] VCARD_FILE_TYPES = ["text/x-vcard", "application/vcard"] @@ -29,18 +29,18 @@ module Filetypes "video/mpeg", "video/quicktime", "video/x-msvideo", - "video/x-ms-wmv" + "video/x-ms-wmv", ] TEXT_FILE_TYPES = [ "application/rtf", - "text/plain" + "text/plain", ] EXCEL_FILE_TYPES = [ "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "application/vnd.ms-excel", - "text/csv" + "text/csv", ] end end diff --git a/lib/alchemy/forms/builder.rb b/lib/alchemy/forms/builder.rb index 159957ad87..616a87fd5d 100644 --- a/lib/alchemy/forms/builder.rb +++ b/lib/alchemy/forms/builder.rb @@ -11,7 +11,7 @@ def input(attribute_name, options = {}, &block) if object.respond_to?(:attribute_fixed?) && object.attribute_fixed?(attribute_name) options[:disabled] = true options[:input_html] = options.fetch(:input_html, {}).merge( - 'data-alchemy-tooltip' => Alchemy.t(:attribute_fixed, attribute_name) + 'data-alchemy-tooltip' => Alchemy.t(:attribute_fixed, attribute_name), ) end @@ -22,7 +22,7 @@ def input(attribute_name, options = {}, &block) # def submit(label, options = {}) options = { - wrapper_html: {class: 'submit'} + wrapper_html: {class: 'submit'}, }.update(options) template.content_tag('div', options.delete(:wrapper_html)) do template.content_tag('button', label, options.delete(:input_html)) diff --git a/lib/alchemy/permissions.rb b/lib/alchemy/permissions.rb index 81bb3b606b..38e29d8b71 100644 --- a/lib/alchemy/permissions.rb +++ b/lib/alchemy/permissions.rb @@ -99,7 +99,7 @@ def alchemy_author_rules :alchemy_admin_pages, :alchemy_admin_pictures, :alchemy_admin_tags, - :alchemy_admin_users + :alchemy_admin_users, ] # Controller actions @@ -137,7 +137,7 @@ def alchemy_editor_rules # Navigation can :index, [ :alchemy_admin_languages, - :alchemy_admin_users + :alchemy_admin_users, ] # Controller actions @@ -150,7 +150,7 @@ def alchemy_editor_rules :flush, :order, :sort, - :switch_language + :switch_language, ], Alchemy::Page # Resources which may be locked via template permissions @@ -164,7 +164,7 @@ def alchemy_editor_rules can([ :create, :destroy, - :publish + :publish, ], Alchemy::Page) { |p| p.editable_by?(@user) } can :manage, Alchemy::Picture diff --git a/lib/alchemy/resource.rb b/lib/alchemy/resource.rb index 7bd647217f..85159433dd 100644 --- a/lib/alchemy/resource.rb +++ b/lib/alchemy/resource.rb @@ -166,7 +166,7 @@ def attributes { name: col.name, type: resource_column_type(col), - relation: resource_relation(col.name) + relation: resource_relation(col.name), }.delete_if { |_k, v| v.nil? } end.compact end @@ -264,7 +264,7 @@ def searchable_relation_attributes(attrs) def searchable_relation_attribute(attribute) { name: "#{attribute[:relation][:model_association].name}_#{attribute[:relation][:attr_method]}", - type: attribute[:relation][:attr_type] + type: attribute[:relation][:attr_type], } end diff --git a/lib/alchemy/resources_helper.rb b/lib/alchemy/resources_helper.rb index de75ad51ea..19a0f421d5 100644 --- a/lib/alchemy/resources_helper.rb +++ b/lib/alchemy/resources_helper.rb @@ -112,8 +112,8 @@ def resource_attribute_field_options(attribute) as: 'string', input_html: { 'data-datepicker-type' => input_type, - value: date ? date.iso8601 : nil - } + value: date ? date.iso8601 : nil, + }, ) when 'text' options.merge(as: 'text', input_html: {rows: 4}) @@ -180,7 +180,7 @@ def resource_filter_select resource_model.alchemy_resource_filters.map do |filter_scope| [ Alchemy.t(filter_scope.to_sym, scope: ['resources', resource_name, 'filters']), - filter_scope + filter_scope, ] end end diff --git a/lib/alchemy/seeder.rb b/lib/alchemy/seeder.rb index 6cb2e35fab..efc341f070 100644 --- a/lib/alchemy/seeder.rb +++ b/lib/alchemy/seeder.rb @@ -47,7 +47,7 @@ def seed_pages create_page(page, { parent: Alchemy::Page.root, language: Alchemy::Language.default, - language_root: true + language_root: true, }) end end @@ -59,7 +59,7 @@ def seed_layoutpages layoutpages.each do |page| create_page(page, { parent: layout_root, - language: language + language: language, }) end end @@ -124,7 +124,7 @@ def create_default_language! page_layout: default_language['page_layout'], public: true, default: true, - site: Alchemy::Site.default + site: Alchemy::Site.default, ) else raise DefaultLanguageNotFoundError diff --git a/lib/alchemy/shell.rb b/lib/alchemy/shell.rb index b15b2ebbd4..d4aa730271 100644 --- a/lib/alchemy/shell.rb +++ b/lib/alchemy/shell.rb @@ -10,7 +10,7 @@ module Shell clear: Thor::Shell::Color::CLEAR, green: Thor::Shell::Color::GREEN, red: Thor::Shell::Color::RED, - yellow: Thor::Shell::Color::YELLOW + yellow: Thor::Shell::Color::YELLOW, }.freeze def self.silence! diff --git a/lib/alchemy/test_support/shared_contexts.rb b/lib/alchemy/test_support/shared_contexts.rb index c14a28b53e..c9bafc7d7d 100644 --- a/lib/alchemy/test_support/shared_contexts.rb +++ b/lib/alchemy/test_support/shared_contexts.rb @@ -3,7 +3,7 @@ let(:invalid_file) do fixture_file_upload( File.expand_path('../../../spec/fixtures/users.yml', __dir__), - 'text/x-yaml' + 'text/x-yaml', ) end diff --git a/lib/alchemy/tinymce.rb b/lib/alchemy/tinymce.rb index 2d52de9040..f8c647f401 100644 --- a/lib/alchemy/tinymce.rb +++ b/lib/alchemy/tinymce.rb @@ -15,14 +15,14 @@ module Tinymce statusbar: true, toolbar: [ 'bold italic underline | strikethrough subscript superscript | numlist bullist indent outdent | removeformat | fullscreen', - 'pastetext charmap hr | undo redo | alchemy_link unlink anchor | code' + 'pastetext charmap hr | undo redo | alchemy_link unlink anchor | code', ], fix_list_elements: true, convert_urls: false, entity_encoding: 'raw', paste_as_text: true, element_format: 'html', - branding: false + branding: false, } class << self diff --git a/lib/alchemy/webpacker.rb b/lib/alchemy/webpacker.rb index 680fa180af..b7ac15027d 100644 --- a/lib/alchemy/webpacker.rb +++ b/lib/alchemy/webpacker.rb @@ -7,7 +7,7 @@ module Alchemy def self.webpacker @webpacker ||= ::Webpacker::Instance.new( root_path: ROOT_PATH, - config_path: ROOT_PATH.join("config/webpacker.yml") + config_path: ROOT_PATH.join("config/webpacker.yml"), ) end end diff --git a/lib/tasks/alchemy/upgrade.rake b/lib/tasks/alchemy/upgrade.rake index ccf58bed5e..ab1049b97c 100644 --- a/lib/tasks/alchemy/upgrade.rake +++ b/lib/tasks/alchemy/upgrade.rake @@ -5,7 +5,7 @@ require 'alchemy/version' namespace :alchemy do desc "Upgrades your app to AlchemyCMS v#{Alchemy::VERSION}." task upgrade: [ - 'alchemy:upgrade:prepare' + 'alchemy:upgrade:prepare', ] do Alchemy::Upgrader.display_todos end @@ -14,7 +14,7 @@ namespace :alchemy do desc 'Alchemy Upgrader: Prepares the database and updates Alchemys configuration file.' task prepare: [ 'alchemy:upgrade:database', - 'alchemy:upgrade:config' + 'alchemy:upgrade:config', ] desc "Alchemy Upgrader: Prepares the database." @@ -22,7 +22,7 @@ namespace :alchemy do 'alchemy:upgrade:5.0:install_gutentag_migrations', 'alchemy:install:migrations', 'db:migrate', - 'alchemy:db:seed' + 'alchemy:db:seed', ] desc "Alchemy Upgrader: Copy configuration file." @@ -32,7 +32,7 @@ namespace :alchemy do desc 'Upgrade Alchemy to v5.0' task '5.0' => [ - 'alchemy:upgrade:prepare' + 'alchemy:upgrade:prepare', ] do Alchemy::Upgrader.display_todos end diff --git a/lib/tasks/alchemy/webpacker.rake b/lib/tasks/alchemy/webpacker.rake index 1bb1ed071b..69b0f459e9 100644 --- a/lib/tasks/alchemy/webpacker.rake +++ b/lib/tasks/alchemy/webpacker.rake @@ -21,7 +21,7 @@ namespace :alchemy do if Alchemy.webpacker.commands.compile FileUtils.cp_r( Alchemy::Engine.root.join("public", "alchemy-packs"), - Rails.root.join("public") + Rails.root.join("public"), ) else # Failed compilation diff --git a/spec/controllers/alchemy/admin/attachments_controller_spec.rb b/spec/controllers/alchemy/admin/attachments_controller_spec.rb index 8ec06a7697..3a6a697cd1 100644 --- a/spec/controllers/alchemy/admin/attachments_controller_spec.rb +++ b/spec/controllers/alchemy/admin/attachments_controller_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" module Alchemy describe Admin::AttachmentsController do @@ -10,8 +10,8 @@ module Alchemy let(:file) do fixture_file_upload( - File.expand_path('../../../fixtures/500x500.png', __dir__), - 'image/png' + File.expand_path("../../../fixtures/500x500.png", __dir__), + "image/png", ) end @@ -28,7 +28,7 @@ module Alchemy context "when params[:tagged_with] is set" do it "should filter the records by tags" do expect(Attachment).to receive(:tagged_with).and_return(Attachment.all) - get :index, params: {tagged_with: "pdf"} + get :index, params: { tagged_with: "pdf" } end end @@ -38,8 +38,8 @@ module Alchemy context "is set" do it "it renders the archive_overlay partial" do expect(Content).to receive(:find_by).and_return(content) - get :index, params: {content_id: content.id} - expect(response).to render_template(partial: '_archive_overlay') + get :index, params: { content_id: content.id } + expect(response).to render_template(partial: "_archive_overlay") expect(assigns(:content)).to eq(content) end end @@ -52,17 +52,17 @@ module Alchemy end end - describe 'file_type filter' do + describe "file_type filter" do let!(:png) { create(:alchemy_attachment) } let!(:jpg) do create :alchemy_attachment, - file: File.new(File.expand_path('../../../fixtures/image3.jpeg', __dir__)) + file: File.new(File.expand_path("../../../fixtures/image3.jpeg", __dir__)) end - context 'with params[:file_type]' do - it 'loads only attachments with matching content type' do - get :index, params: {file_type: 'image/jpeg'} + context "with params[:file_type]" do + it "loads only attachments with matching content type" do + get :index, params: { file_type: "image/jpeg" } expect(assigns(:attachments).to_a).to eq([jpg]) expect(assigns(:attachments).to_a).to_not eq([png]) end @@ -70,46 +70,46 @@ module Alchemy end end - describe '#show' do + describe "#show" do before do expect(Attachment).to receive(:find).and_return(attachment) end it "renders the show template" do - get :show, params: {id: attachment.id} + get :show, params: { id: attachment.id } expect(response).to render_template(:show) end end - describe '#create' do + describe "#create" do subject { post :create, params: params } - context 'with passing validations' do - let(:params) { {attachment: {file: file}} } + context "with passing validations" do + let(:params) { { attachment: { file: file } } } it "renders json response with success message" do subject - expect(response.media_type).to eq('application/json') + expect(response.media_type).to eq("application/json") expect(response.status).to eq(201) json = JSON.parse(response.body) - expect(json).to have_key('growl_message') - expect(json).to have_key('files') + expect(json).to have_key("growl_message") + expect(json).to have_key("files") end end - context 'with failing validations' do - include_context 'with invalid file' + context "with failing validations" do + include_context "with invalid file" - let(:params) { {attachment: {file: invalid_file}} } + let(:params) { { attachment: { file: invalid_file } } } - it_behaves_like 'having a json uploader error message' + it_behaves_like "having a json uploader error message" end end - describe '#update' do + describe "#update" do let(:params) do { - id: attachment.id, attachment: {name: ''} + id: attachment.id, attachment: { name: "" }, } end @@ -122,25 +122,25 @@ module Alchemy context "when file is passed" do let(:file) do fixture_file_upload( - File.expand_path('../../../fixtures/image2.PNG', __dir__), - 'image/png' + File.expand_path("../../../fixtures/image2.PNG", __dir__), + "image/png", ) end - context 'with passing validations' do + context "with passing validations" do let(:params) do { - id: attachment.id, attachment: {file: file} + id: attachment.id, attachment: { file: file }, } end it "renders json response with success message" do subject - expect(response.media_type).to eq('application/json') + expect(response.media_type).to eq("application/json") expect(response.status).to eq(202) json = JSON.parse(response.body) - expect(json).to have_key('growl_message') - expect(json).to have_key('files') + expect(json).to have_key("growl_message") + expect(json).to have_key("files") end it "replaces the file" do @@ -149,25 +149,25 @@ module Alchemy end end - context 'with passing validations' do + context "with passing validations" do it "redirects to index path" do is_expected.to redirect_to admin_attachments_path end - context 'with search params' do + context "with search params" do let(:search_filter_params) do { - q: {name_or_file_name_cont: 'kitten'}, - tagged_with: 'cute', - file_type: 'pdf', - page: 2 + q: { name_or_file_name_cont: "kitten" }, + tagged_with: "cute", + file_type: "pdf", + page: 2, } end subject do put :update, params: { - id: attachment.id, attachment: {name: ''} - }.merge(search_filter_params) + id: attachment.id, attachment: { name: "" }, + }.merge(search_filter_params) end it "passes them along" do @@ -176,8 +176,8 @@ module Alchemy end end - context 'with failing validations' do - include_context 'with invalid file' + context "with failing validations" do + include_context "with invalid file" it "renders edit form" do is_expected.to render_template(:edit) @@ -185,33 +185,33 @@ module Alchemy end end - describe '#destroy' do + describe "#destroy" do before do expect(Attachment).to receive(:find).and_return(attachment) end it "destroys the attachment and sets a success message" do expect(attachment).to receive(:destroy) - delete :destroy, params: {id: 1}, xhr: true + delete :destroy, params: { id: 1 }, xhr: true expect(assigns(:attachment)).to eq(attachment) expect(assigns(:url)).not_to be_blank expect(flash[:notice]).not_to be_blank end - context 'with search params' do + context "with search params" do let(:search_filter_params) do { - q: {name_or_file_name_cont: 'kitten'}, - tagged_with: 'cute', - file_type: 'pdf', - page: 2 + q: { name_or_file_name_cont: "kitten" }, + tagged_with: "cute", + file_type: "pdf", + page: 2, } end it "passes them along" do expect(attachment).to receive(:destroy) { true } - delete :destroy, params: {id: 1}.merge(search_filter_params), xhr: true - expect(assigns(:url)).to eq admin_attachments_url(search_filter_params.merge(host: 'test.host')) + delete :destroy, params: { id: 1 }.merge(search_filter_params), xhr: true + expect(assigns(:url)).to eq admin_attachments_url(search_filter_params.merge(host: "test.host")) end end end @@ -222,8 +222,8 @@ module Alchemy end it "sends the file as download" do - get :download, params: {id: attachment.id} - expect(response.headers['Content-Disposition']).to match(/attachment/) + get :download, params: { id: attachment.id } + expect(response.headers["Content-Disposition"]).to match(/attachment/) end end end diff --git a/spec/controllers/alchemy/admin/dashboard_controller_spec.rb b/spec/controllers/alchemy/admin/dashboard_controller_spec.rb index 2b4ca871f6..6219396a0f 100644 --- a/spec/controllers/alchemy/admin/dashboard_controller_spec.rb +++ b/spec/controllers/alchemy/admin/dashboard_controller_spec.rb @@ -16,8 +16,8 @@ module Alchemy double( all_last_edited_from: [], locked_by: [], - locked: [] - ) + locked: [], + ), ) end @@ -86,7 +86,7 @@ module Alchemy context "requesting rubygems.org" do before do stub_request(:get, 'https://rubygems.org/api/v1/versions/alchemy_cms.json').to_return( - status: 200, body: '[{"number": "3.0.0.alpha"}, {"number": "2.6.0"}, {"number": "2.5.1"}]' + status: 200, body: '[{"number": "3.0.0.alpha"}, {"number": "2.6.0"}, {"number": "2.5.1"}]', ) end @@ -119,7 +119,7 @@ module Alchemy before do stub_request(:get, 'https://rubygems.org/api/v1/versions/alchemy_cms.json').to_return(status: 503) stub_request(:get, 'https://api.github.com/repos/AlchemyCMS/alchemy_cms/tags').to_return( - status: 200, body: '[{"name": "v2.6.0"}, {"name": "v2.5.0"}]' + status: 200, body: '[{"name": "v2.6.0"}, {"name": "v2.5.0"}]', ) allow(Alchemy).to receive(:version).and_return("2.6.2") end diff --git a/spec/controllers/alchemy/admin/elements_controller_spec.rb b/spec/controllers/alchemy/admin/elements_controller_spec.rb index 9ffc9e32a5..b017cc78e4 100644 --- a/spec/controllers/alchemy/admin/elements_controller_spec.rb +++ b/spec/controllers/alchemy/admin/elements_controller_spec.rb @@ -79,7 +79,7 @@ module Alchemy post :order, params: { page_id: page.id, element_ids: element_ids, - parent_element_id: parent.id + parent_element_id: parent.id, }, xhr: true end @@ -87,7 +87,7 @@ module Alchemy post :order, params: { page_id: page.id, element_ids: element_ids, - parent_element_id: parent.id + parent_element_id: parent.id, }, xhr: true [element_1, element_2, element_3].each do |element| expect(element.reload.parent_element_id).to eq parent.id @@ -162,7 +162,7 @@ module Alchemy expect(PageLayout).to receive(:get).at_least(:once).and_return({ 'name' => 'news', 'elements' => ['news'], - 'insert_elements_at' => 'top' + 'insert_elements_at' => 'top', }) end diff --git a/spec/controllers/alchemy/admin/essence_files_controller_spec.rb b/spec/controllers/alchemy/admin/essence_files_controller_spec.rb index ffae4c8678..c99b8e49c8 100644 --- a/spec/controllers/alchemy/admin/essence_files_controller_spec.rb +++ b/spec/controllers/alchemy/admin/essence_files_controller_spec.rb @@ -45,8 +45,8 @@ module Alchemy essence_file: { title: 'new title', css_class: 'left', - link_text: 'Download this file' - } + link_text: 'Download this file', + }, }, xhr: true expect(essence_file.title).to eq 'new title' expect(essence_file.css_class).to eq 'left' diff --git a/spec/controllers/alchemy/admin/essence_pictures_controller_spec.rb b/spec/controllers/alchemy/admin/essence_pictures_controller_spec.rb index d6724f41d9..a2b667f2a6 100644 --- a/spec/controllers/alchemy/admin/essence_pictures_controller_spec.rb +++ b/spec/controllers/alchemy/admin/essence_pictures_controller_spec.rb @@ -47,7 +47,7 @@ module Alchemy x1: 0, y1: 0, x2: 300, - y2: 250 + y2: 250, } end @@ -213,7 +213,7 @@ module Alchemy alt_tag: 'Alt Tag', caption: 'Caption', css_class: 'CSS Class', - title: 'Title' + title: 'Title', } end @@ -229,8 +229,8 @@ module Alchemy essence_picture: { render_size: '1x1', crop_from: '0x0', - crop_size: '100x100' - } + crop_size: '100x100', + }, }, xhr: true end end diff --git a/spec/controllers/alchemy/admin/languages_controller_spec.rb b/spec/controllers/alchemy/admin/languages_controller_spec.rb index 8e9ae39aa1..4096e87e01 100644 --- a/spec/controllers/alchemy/admin/languages_controller_spec.rb +++ b/spec/controllers/alchemy/admin/languages_controller_spec.rb @@ -81,8 +81,8 @@ page_layout: "index", public: true, default: true, - site_id: create(:alchemy_site) - } + site_id: create(:alchemy_site), + }, } language = Alchemy::Language.last expect(response).to redirect_to admin_pages_path(language_id: language) diff --git a/spec/controllers/alchemy/admin/pictures_controller_spec.rb b/spec/controllers/alchemy/admin/pictures_controller_spec.rb index e14220b07a..911735d9e1 100644 --- a/spec/controllers/alchemy/admin/pictures_controller_spec.rb +++ b/spec/controllers/alchemy/admin/pictures_controller_spec.rb @@ -9,7 +9,7 @@ page: 2, q: {name_or_image_file_name_cont: 'kitten'}, size: 'small', - tagged_with: 'cat' + tagged_with: 'cat', } end @@ -252,7 +252,7 @@ module Alchemy it_behaves_like :redirecting_to_picture_library do let(:subject) do delete :delete_multiple, params: { - picture_ids: %w(1 2) + picture_ids: %w(1 2), }.merge(params) end end diff --git a/spec/controllers/alchemy/messages_controller_spec.rb b/spec/controllers/alchemy/messages_controller_spec.rb index 43c5a4579d..5a8f40b1fe 100644 --- a/spec/controllers/alchemy/messages_controller_spec.rb +++ b/spec/controllers/alchemy/messages_controller_spec.rb @@ -162,7 +162,7 @@ module Alchemy it "should redirect to the given urlname" do expect( - subject + subject, ).to redirect_to(show_page_path(urlname: 'success-page')) end end @@ -176,7 +176,7 @@ module Alchemy it "should redirect to the given urlname" do expect( - subject + subject, ).to redirect_to(show_page_path(urlname: 'success-page')) end end @@ -193,7 +193,7 @@ module Alchemy { 'fields' => %w(email), 'forward_to_page' => true, - 'mail_success_page' => 'mailer-config-success-page' + 'mail_success_page' => 'mailer-config-success-page', } end allow(Page).to receive(:find_by).and_return double(urlname: 'mailer-config-success-page') @@ -201,7 +201,7 @@ module Alchemy it "redirect to the given success page" do expect( - subject + subject, ).to redirect_to(show_page_path(urlname: 'mailer-config-success-page')) end end @@ -217,7 +217,7 @@ module Alchemy it "should redirect to the language root page" do allow(Language).to receive(:current).and_return(language) expect( - subject + subject, ).to redirect_to(show_page_path(urlname: 'lang-root')) end end diff --git a/spec/controllers/alchemy/pages_controller_spec.rb b/spec/controllers/alchemy/pages_controller_spec.rb index 20c07e6ca1..4fc9a605c6 100644 --- a/spec/controllers/alchemy/pages_controller_spec.rb +++ b/spec/controllers/alchemy/pages_controller_spec.rb @@ -32,7 +32,7 @@ module Alchemy it 'returns a 404' do expect { get(:index) }.to raise_exception( ActionController::RoutingError, - 'Alchemy::Page not found "/"' + 'Alchemy::Page not found "/"', ) end end diff --git a/spec/dummy/app/models/event.rb b/spec/dummy/app/models/event.rb index b63fbc7ffd..4b634bc69e 100644 --- a/spec/dummy/app/models/event.rb +++ b/spec/dummy/app/models/event.rb @@ -11,7 +11,7 @@ class Event < ActiveRecord::Base def self.alchemy_resource_relations { - location: {attr_method: 'name', attr_type: 'string'} + location: {attr_method: 'name', attr_type: 'string'}, } end diff --git a/spec/features/admin/tinymce_feature_spec.rb b/spec/features/admin/tinymce_feature_spec.rb index a079e853e8..5577596940 100644 --- a/spec/features/admin/tinymce_feature_spec.rb +++ b/spec/features/admin/tinymce_feature_spec.rb @@ -10,7 +10,7 @@ it 'base path should be set to tinymce asset folder' do visit admin_dashboard_path expect(page).to have_content( - "var tinyMCEPreInit = { base: '/assets/tinymce', suffix: '.min' };" + "var tinyMCEPreInit = { base: '/assets/tinymce', suffix: '.min' };", ) end @@ -22,7 +22,7 @@ it 'base path should be set to tinymce asset folder' do visit admin_dashboard_path expect(page).to have_content( - "var tinyMCEPreInit = { base: 'http://127.0.0.1/assets/tinymce', suffix: '.min' };" + "var tinyMCEPreInit = { base: 'http://127.0.0.1/assets/tinymce', suffix: '.min' };", ) end end diff --git a/spec/features/page_redirects_spec.rb b/spec/features/page_redirects_spec.rb index e76dab2e90..e060a8daa6 100644 --- a/spec/features/page_redirects_spec.rb +++ b/spec/features/page_redirects_spec.rb @@ -23,7 +23,7 @@ let(:legacy_url) do Alchemy::LegacyPageUrl.create( urlname: 'index.php?option=com_content&view=article&id=48&Itemid=69', - page: second_page + page: second_page, ) end @@ -91,7 +91,7 @@ public_on: nil, visible: false, name: 'Not Public', - urlname: '' + urlname: '', ) public_child end @@ -140,7 +140,7 @@ public_on: nil, visible: false, name: 'Not Public', - urlname: '' + urlname: '', ) end @@ -222,7 +222,7 @@ let(:legacy_url) do Alchemy::LegacyPageUrl.create( urlname: 'index.php?option=com_content&view=article&id=48&Itemid=69', - page: second_page + page: second_page, ) end @@ -248,7 +248,7 @@ visible: false, public_on: nil, name: 'Not Public', - urlname: '' + urlname: '', ) public_child end diff --git a/spec/helpers/alchemy/admin/base_helper_spec.rb b/spec/helpers/alchemy/admin/base_helper_spec.rb index 2b04920f64..49d9a8ef5a 100644 --- a/spec/helpers/alchemy/admin/base_helper_spec.rb +++ b/spec/helpers/alchemy/admin/base_helper_spec.rb @@ -10,7 +10,7 @@ module Alchemy it "renders a toolbar button" do expect(helper.toolbar_button( - url: admin_dashboard_path + url: admin_dashboard_path, )).to match /<div.+class="button_with_label/ end end @@ -20,7 +20,7 @@ module Alchemy it "returns empty string" do expect( - helper.toolbar_button(url: admin_dashboard_path) + helper.toolbar_button(url: admin_dashboard_path), ).to be_empty end end @@ -32,8 +32,8 @@ module Alchemy expect( helper.toolbar_button( url: admin_dashboard_path, - skip_permission_check: true - ) + skip_permission_check: true, + ), ).to match /<div.+class="button_with_label/ end end @@ -46,8 +46,8 @@ module Alchemy expect( helper.toolbar_button( url: admin_dashboard_path, - if_permitted_to: '' - ) + if_permitted_to: '', + ), ).not_to be_empty end end @@ -61,7 +61,7 @@ module Alchemy it "renders a normal link" do button = helper.toolbar_button( url: admin_dashboard_path, - overlay: false + overlay: false, ) expect(button).to match /<a.+href="#{admin_dashboard_path}"/ expect(button).not_to match /data-alchemy-overlay/ diff --git a/spec/helpers/alchemy/admin/elements_helper_spec.rb b/spec/helpers/alchemy/admin/elements_helper_spec.rb index 0e91b270f9..cddd13ae09 100644 --- a/spec/helpers/alchemy/admin/elements_helper_spec.rb +++ b/spec/helpers/alchemy/admin/elements_helper_spec.rb @@ -9,7 +9,7 @@ module Alchemy let(:element_objects) do [ mock_model('Element', name: 'element_1', display_name: 'Element 1'), - mock_model('Element', name: 'element_2', display_name: 'Element 2') + mock_model('Element', name: 'element_2', display_name: 'Element 2'), ] end @@ -23,7 +23,7 @@ module Alchemy let(:element_definitions) do [{ 'name' => 'headline', - 'contents' => [] + 'contents' => [], }] end diff --git a/spec/helpers/alchemy/admin/essences_helper_spec.rb b/spec/helpers/alchemy/admin/essences_helper_spec.rb index 235b0bcf59..0b4e661689 100644 --- a/spec/helpers/alchemy/admin/essences_helper_spec.rb +++ b/spec/helpers/alchemy/admin/essences_helper_spec.rb @@ -47,7 +47,7 @@ allow(content).to receive(:settings) do { caption_as_textarea: true, - sizes: ['100x100', '200x200'] + sizes: ['100x100', '200x200'], } end @@ -59,7 +59,7 @@ before do allow(content).to receive(:settings) do { - caption_as_textarea: true + caption_as_textarea: true, } end @@ -72,7 +72,7 @@ allow(content).to receive(:settings) do { caption_as_textarea: false, - sizes: ['100x100', '200x200'] + sizes: ['100x100', '200x200'], } end @@ -84,7 +84,7 @@ before do allow(content).to receive(:settings) do { - caption_as_textarea: false + caption_as_textarea: false, } end diff --git a/spec/helpers/alchemy/admin/navigation_helper_spec.rb b/spec/helpers/alchemy/admin/navigation_helper_spec.rb index 68d6f58001..4d2255c58a 100644 --- a/spec/helpers/alchemy/admin/navigation_helper_spec.rb +++ b/spec/helpers/alchemy/admin/navigation_helper_spec.rb @@ -1,81 +1,81 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" describe Alchemy::Admin::NavigationHelper do let(:alchemy_module) do { - 'name' => 'dashboard', - 'engine_name' => 'alchemy', - 'navigation' => { - 'name' => 'modules.dashboard', - 'controller' => 'alchemy/admin/dashboard', - 'action' => 'index', - 'icon' => 'dashboard' - } + "name" => "dashboard", + "engine_name" => "alchemy", + "navigation" => { + "name" => "modules.dashboard", + "controller" => "alchemy/admin/dashboard", + "action" => "index", + "icon" => "dashboard", + }, } end let(:module_with_subnavigation) do { - 'name' => 'library', - 'engine_name' => 'alchemy', - 'navigation' => { - 'name' => 'modules.library', - 'controller' => 'alchemy/admin/pictures', - 'action' => 'index', - 'sub_navigation' => [{ - 'name' => 'modules.pictures', - 'controller' => 'alchemy/admin/pictures', - 'action' => 'index' + "name" => "library", + "engine_name" => "alchemy", + "navigation" => { + "name" => "modules.library", + "controller" => "alchemy/admin/pictures", + "action" => "index", + "sub_navigation" => [{ + "name" => "modules.pictures", + "controller" => "alchemy/admin/pictures", + "action" => "index", }, { - 'name' => 'modules.files', - 'controller' => 'alchemy/admin/attachments', - 'action' => 'index' - }] - } + "name" => "modules.files", + "controller" => "alchemy/admin/attachments", + "action" => "index", + }], + }, } end let(:event_module) do { - 'navigation' => { - 'controller' => '/admin/events', - 'action' => 'index', - 'sub_navigation' => [{ - 'controller' => '/admin/events', - 'action' => 'index' - }] - } + "navigation" => { + "controller" => "/admin/events", + "action" => "index", + "sub_navigation" => [{ + "controller" => "/admin/events", + "action" => "index", + }], + }, } end let(:event_module_with_params) do { - 'navigation' => { - 'controller' => '/admin/events', - 'action' => 'index', - 'params' => { - 'key' => 'value' + "navigation" => { + "controller" => "/admin/events", + "action" => "index", + "params" => { + "key" => "value", }, - 'sub_navigation' => [{ - 'controller' => '/admin/events', - 'action' => 'index', - 'params' => { - 'key' => 'value', - 'key2' => 'value2' - } - }] - } + "sub_navigation" => [{ + "controller" => "/admin/events", + "action" => "index", + "params" => { + "key" => "value", + "key2" => "value2", + }, + }], + }, } end - let(:navigation) { alchemy_module['navigation'] } + let(:navigation) { alchemy_module["navigation"] } - describe '#alchemy_main_navigation_entry' do + describe "#alchemy_main_navigation_entry" do before do - allow(helper).to receive(:url_for_module).and_return('') - allow(Alchemy).to receive(:t).and_return(alchemy_module['name']) + allow(helper).to receive(:url_for_module).and_return("") + allow(Alchemy).to receive(:t).and_return(alchemy_module["name"]) end context "with permission" do @@ -85,7 +85,7 @@ it "renders the main navigation entry partial" do expect(helper.alchemy_main_navigation_entry(alchemy_module)). - to have_selector '.main_navi_entry' + to have_selector ".main_navi_entry" end context "when module has sub navigation" do @@ -99,9 +99,9 @@ end end - it 'includes the sub navigation' do + it "includes the sub navigation" do expect(helper.alchemy_main_navigation_entry(alchemy_module)). - to have_selector '.main_navi_entry .sub_navigation' + to have_selector ".main_navi_entry .sub_navigation" end end end @@ -117,7 +117,7 @@ end end - describe '#navigate_module' do + describe "#navigate_module" do it "returns array with symbolized action and controller name" do expect(helper.navigate_module(navigation)).to eq([:index, :alchemy_admin_dashboard]) end @@ -125,8 +125,8 @@ context "when controller name has a leading slash" do let(:navigation) do { - 'action' => 'index', - 'controller' => '/admin/pictures' + "action" => "index", + "controller" => "/admin/pictures", } end @@ -136,7 +136,7 @@ end end - describe '#main_navigation_css_classes' do + describe "#main_navigation_css_classes" do it "returns string with css classes for main navigation entry" do expect(helper.main_navigation_css_classes(navigation)).to eq(%w(main_navi_entry)) end @@ -144,8 +144,8 @@ context "with active entry" do before do allow(helper).to receive(:params).and_return({ - controller: 'alchemy/admin/dashboard', - action: 'index' + controller: "alchemy/admin/dashboard", + action: "index", }) end @@ -155,17 +155,17 @@ end end - describe '#entry_active?' do + describe "#entry_active?" do let(:entry) do - {'controller' => 'alchemy/admin/dashboard', 'action' => 'index'} + { "controller" => "alchemy/admin/dashboard", "action" => "index" } end context "with active entry" do before do allow(helper).to receive(:params) do { - controller: 'alchemy/admin/dashboard', - action: 'index' + controller: "alchemy/admin/dashboard", + action: "index", } end end @@ -175,7 +175,7 @@ end context "and with leading slash in controller name" do - before { entry['controller'] = '/alchemy/admin/dashboard' } + before { entry["controller"] = "/alchemy/admin/dashboard" } it "returns true" do expect(helper.entry_active?(entry)).to be_truthy @@ -184,8 +184,8 @@ context "but with action listed in nested_actions key" do before do - entry['action'] = nil - entry['nested_actions'] = %w(index) + entry["action"] = nil + entry["nested_actions"] = %w(index) end it "returns true" do @@ -198,8 +198,8 @@ before do expect(helper).to receive(:params) do { - controller: 'alchemy/admin/users', - action: 'index' + controller: "alchemy/admin/users", + action: "index", } end end @@ -210,43 +210,43 @@ end end - describe '#url_for_module' do + describe "#url_for_module" do context "with module within an engine" do it "returns correct url string" do - expect(helper.url_for_module(alchemy_module)).to eq('/admin/dashboard') + expect(helper.url_for_module(alchemy_module)).to eq("/admin/dashboard") end end context "with module within host app" do it "returns correct url string" do - expect(helper.url_for_module(event_module)).to eq('/admin/events') + expect(helper.url_for_module(event_module)).to eq("/admin/events") end it "returns correct url string with params" do - expect(helper.url_for_module(event_module_with_params)).to eq('/admin/events?key=value') + expect(helper.url_for_module(event_module_with_params)).to eq("/admin/events?key=value") end end end - describe '#url_for_module_sub_navigation' do + describe "#url_for_module_sub_navigation" do let(:current_module) do module_with_subnavigation end let(:navigation) do - current_module['navigation']['sub_navigation'].first + current_module["navigation"]["sub_navigation"].first end subject { helper.url_for_module_sub_navigation(navigation) } - context 'with module found' do + context "with module found" do before do expect(helper).to receive(:module_definition_for).and_return current_module end context "with module within an engine" do it "returns correct url string" do - is_expected.to eq('/admin/pictures') + is_expected.to eq("/admin/pictures") end end @@ -254,7 +254,7 @@ let(:current_module) { event_module } it "returns correct url string" do - is_expected.to eq('/admin/events') + is_expected.to eq("/admin/events") end end @@ -262,12 +262,12 @@ let(:current_module) { event_module_with_params } it "returns correct url string with params" do - is_expected.to eq('/admin/events?key2=value2&key=value') + is_expected.to eq("/admin/events?key2=value2&key=value") end end end - context 'without module found' do + context "without module found" do before do expect(helper).to receive(:module_definition_for).and_return nil end @@ -279,10 +279,10 @@ describe "#sorted_alchemy_modules" do subject { helper.sorted_alchemy_modules } - context 'with position attribute on modules' do + context "with position attribute on modules" do before do - alchemy_module['position'] = 1 - event_module['position'] = 2 + alchemy_module["position"] = 1 + event_module["position"] = 2 expect(helper).to receive(:alchemy_modules).and_return [event_module, alchemy_module] end @@ -291,9 +291,9 @@ end end - context 'with no position attribute on one module' do + context "with no position attribute on one module" do before do - event_module['position'] = 2 + event_module["position"] = 2 expect(helper).to receive(:alchemy_modules).and_return [alchemy_module, event_module] end diff --git a/spec/helpers/alchemy/admin/tags_helper_spec.rb b/spec/helpers/alchemy/admin/tags_helper_spec.rb index 0697aa675c..bbc87600f9 100644 --- a/spec/helpers/alchemy/admin/tags_helper_spec.rb +++ b/spec/helpers/alchemy/admin/tags_helper_spec.rb @@ -55,7 +55,7 @@ module Alchemy let(:params) do ActionController::Parameters.new( filter: 'foo', - q: {name_eq: 'foo'} + q: {name_eq: 'foo'}, ) end diff --git a/spec/helpers/alchemy/elements_block_helper_spec.rb b/spec/helpers/alchemy/elements_block_helper_spec.rb index 76298a5509..4b9a5c9d84 100644 --- a/spec/helpers/alchemy/elements_block_helper_spec.rb +++ b/spec/helpers/alchemy/elements_block_helper_spec.rb @@ -75,9 +75,9 @@ module Alchemy expect(scope).to receive(:render).with(content, { content: content, options: { - foo: 'bar' + foo: 'bar', }, - html_options: {} + html_options: {}, }) subject.render(:headline, foo: 'bar') end diff --git a/spec/libraries/config_spec.rb b/spec/libraries/config_spec.rb index dc08e57fea..d0b5c91d2f 100644 --- a/spec/libraries/config_spec.rb +++ b/spec/libraries/config_spec.rb @@ -97,7 +97,7 @@ module Alchemy context 'when configs containing same keys' do it "should merge them together" do expect(Config.send(:merge_configs!, config_1, config_2)).to eq( - {'setting_1' => 'same', 'other_setting' => 'something', 'setting_2' => 'anything'} + {'setting_1' => 'same', 'other_setting' => 'something', 'setting_2' => 'anything'}, ) end end diff --git a/spec/libraries/elements_finder_spec.rb b/spec/libraries/elements_finder_spec.rb index 9d4583c396..60f81deb08 100644 --- a/spec/libraries/elements_finder_spec.rb +++ b/spec/libraries/elements_finder_spec.rb @@ -177,8 +177,8 @@ { fallback: { for: 'download', - from: page_2 - } + from: page_2, + }, } end @@ -200,8 +200,8 @@ fallback: { for: 'download', with: 'header', - from: page_2 - } + from: page_2, + }, } end @@ -219,8 +219,8 @@ fallback: { for: 'download', with: 'text', - from: 'everything' - } + from: 'everything', + }, } end diff --git a/spec/libraries/i18n_spec.rb b/spec/libraries/i18n_spec.rb index 27afeb989a..6c48404eff 100644 --- a/spec/libraries/i18n_spec.rb +++ b/spec/libraries/i18n_spec.rb @@ -39,7 +39,7 @@ module Alchemy expect(::I18n).to receive(:load_path) do [ '/Users/tvd/gems/alchemy-devise/config/locales/alchemy.de.yml', - '/Users/tvd/gems/alchemy_i18n/config/locales/alchemy.de.yml' + '/Users/tvd/gems/alchemy_i18n/config/locales/alchemy.de.yml', ] end end @@ -66,7 +66,7 @@ module Alchemy expect(::I18n).to receive(:load_path) do [ '/Users/tvd/gems/alchemy_i18n/config/locales/alchemy.zh-CN.yml', - '/Users/tvd/gems/alchemy_i18n/config/locales/alchemy.de.yml' + '/Users/tvd/gems/alchemy_i18n/config/locales/alchemy.de.yml', ] end end diff --git a/spec/libraries/modules_spec.rb b/spec/libraries/modules_spec.rb index 368b1eb0b5..269993c2a0 100644 --- a/spec/libraries/modules_spec.rb +++ b/spec/libraries/modules_spec.rb @@ -58,8 +58,8 @@ class ModulesTestController < ApplicationController 'name' => 'module', 'navigation' => { 'controller' => 'register_module_dummy', - 'action' => 'index' - } + 'action' => 'index', + }, } end @@ -68,8 +68,8 @@ class ModulesTestController < ApplicationController 'name' => 'bad_module_a', 'navigation' => { 'controller' => 'bad_module', - 'action' => 'index' - } + 'action' => 'index', + }, } end @@ -81,9 +81,9 @@ class ModulesTestController < ApplicationController 'action' => 'index', 'sub_navigation' => [{ 'controller' => 'bad_module', - 'action' => 'index' - }] - } + 'action' => 'index', + }], + }, } end diff --git a/spec/libraries/resource_spec.rb b/spec/libraries/resource_spec.rb index 6f040eb3b6..147cc0198e 100644 --- a/spec/libraries/resource_spec.rb +++ b/spec/libraries/resource_spec.rb @@ -36,8 +36,8 @@ module Alchemy "name" => "modules.party_list", "controller" => "/admin/parties", "action" => "index", - "image" => "/assets/party_list_module.png" - } + "image" => "/assets/party_list_module.png", + }, } end @@ -49,7 +49,7 @@ module Alchemy double(:column, {name: 'id', type: :integer, array: false}), double(:column, {name: 'starts_at', type: :datetime, array: false}), double(:column, {name: 'location_id', type: :integer, array: false}), - double(:column, {name: 'organizer_id', type: :integer, array: false}) + double(:column, {name: 'organizer_id', type: :integer, array: false}), ] end @@ -182,7 +182,7 @@ module Alchemy {name: "description", type: :text}, {name: "starts_at", type: :datetime}, {name: "location_id", type: :integer}, - {name: "organizer_id", type: :integer} + {name: "organizer_id", type: :integer}, ]) end @@ -255,7 +255,7 @@ module Alchemy before do allow(Party).to receive(:alchemy_resource_relations) do { - location: {attr_method: "name", attr_type: :string} + location: {attr_method: "name", attr_type: :string}, } end end @@ -269,7 +269,7 @@ module Alchemy let(:columns) do [ double(:column, {name: 'name', type: :string, array: false}), - double(:column, {name: 'languages', type: :string, array: true}) + double(:column, {name: 'languages', type: :string, array: true}), ] end @@ -295,7 +295,7 @@ module Alchemy double(:column, {name: 'name', type: :string}), double(:column, {name: 'title', type: :string}), double(:column, {name: 'synced_at', type: :datetime}), - double(:column, {name: 'remote_record_id', type: :string}) + double(:column, {name: 'remote_record_id', type: :string}), ] end @@ -318,7 +318,7 @@ module Alchemy double(:column, {name: 'title', type: :string}), double(:column, {name: 'name', type: :string}), double(:column, {name: 'updated_at', type: :datetime}), - double(:column, {name: 'public', type: :boolean}) + double(:column, {name: 'public', type: :boolean}), ] end @@ -327,7 +327,7 @@ module Alchemy {name: "name", type: :string}, {name: "title", type: :string}, {name: "public", type: :boolean}, - {name: "updated_at", type: :datetime} + {name: "updated_at", type: :datetime}, ]) end end @@ -338,7 +338,7 @@ module Alchemy before do allow(Event).to receive(:alchemy_resource_relations) do { - location: {attr_method: "name", attr_type: :string} + location: {attr_method: "name", attr_type: :string}, } end end diff --git a/spec/libraries/resources_helper_spec.rb b/spec/libraries/resources_helper_spec.rb index f9e3ab22d5..ad8d91d14b 100644 --- a/spec/libraries/resources_helper_spec.rb +++ b/spec/libraries/resources_helper_spec.rb @@ -131,13 +131,13 @@ def resource_handler let(:relation) do { attr_method: 'title', - name: 'location' + name: 'location', } end let(:attributes) do { name: 'name', - relation: relation + relation: relation, } end @@ -187,7 +187,7 @@ def resource_handler let(:attributes) do { name: :created_at, - type: :datetime + type: :datetime, } end @@ -216,7 +216,7 @@ def resource_handler let(:attributes) do { name: :created_at, - type: :time + type: :time, } end diff --git a/spec/libraries/tinymce_spec.rb b/spec/libraries/tinymce_spec.rb index 599e84eb3f..07f7533035 100644 --- a/spec/libraries/tinymce_spec.rb +++ b/spec/libraries/tinymce_spec.rb @@ -27,16 +27,16 @@ module Alchemy 'name' => 'text', 'settings' => { 'tinymce' => { - 'foo' => 'bar' - } - } + 'foo' => 'bar', + }, + }, } end let(:element_definition) do { 'name' => 'article', - 'contents' => [content_definition] + 'contents' => [content_definition], } end @@ -57,7 +57,7 @@ module Alchemy and element name" do is_expected.to be_an(Array) is_expected.to include({ - 'element' => element_definition['name'] + 'element' => element_definition['name'], }.merge(content_definition)) end @@ -73,7 +73,7 @@ module Alchemy let(:element_definition) do { 'name' => 'element', - 'contents' => nil + 'contents' => nil, } end @@ -89,9 +89,9 @@ module Alchemy 'contents' => [ 'name' => 'headline', 'settings' => { - 'tinymce' => true - } - ] + 'tinymce' => true, + }, + ], } end @@ -106,14 +106,14 @@ module Alchemy element_definition, { 'name' => 'nested_element', - 'contents' => [content_definition] - } + 'contents' => [content_definition], + }, ] end it 'includes these configs' do is_expected.to include({ - 'element' => element_definition['name'] + 'element' => element_definition['name'], }.merge(content_definition)) end end diff --git a/spec/models/alchemy/content_spec.rb b/spec/models/alchemy/content_spec.rb index 92c7afb9e4..373e3b3981 100644 --- a/spec/models/alchemy/content_spec.rb +++ b/spec/models/alchemy/content_spec.rb @@ -137,18 +137,18 @@ module Alchemy [ { 'name' => 'foo', - 'contents' => [{'name' => 'title'}] + 'contents' => [{'name' => 'title'}], }, { - 'name' => 'bar' - } + 'name' => 'bar', + }, ] end end it "returns only content definitions" do expect(Content.definitions).to match_array( - [{'name' => 'title'}] + [{'name' => 'title'}], ) end end @@ -191,7 +191,7 @@ module Alchemy { 'name' => 'headline', 'type' => 'EssenceText', - 'default' => 'Welcome' + 'default' => 'Welcome', }.with_indifferent_access end expect(content.ingredient).to eq("Welcome") @@ -203,7 +203,7 @@ module Alchemy { 'name' => 'headline', 'type' => 'EssenceText', - 'default' => :welcome + 'default' => :welcome, }.with_indifferent_access end expect(content.ingredient).to eq("Welcome to my site") @@ -280,7 +280,7 @@ module Alchemy context 'defined as preview content' do before do expect(content).to receive(:definition).at_least(:once).and_return({ - 'as_element_title' => true + 'as_element_title' => true, }) end diff --git a/spec/models/alchemy/element_spec.rb b/spec/models/alchemy/element_spec.rb index 861a9629bb..b3723ee9ae 100644 --- a/spec/models/alchemy/element_spec.rb +++ b/spec/models/alchemy/element_spec.rb @@ -43,7 +43,7 @@ module Alchemy an_instance_of(Alchemy::Content), an_instance_of(Alchemy::Content), an_instance_of(Alchemy::Content), - an_instance_of(Alchemy::Content) + an_instance_of(Alchemy::Content), ]) end @@ -52,7 +52,7 @@ module Alchemy described_class.create( page: page, name: 'article', - autogenerate_contents: false + autogenerate_contents: false, ) end @@ -68,7 +68,7 @@ module Alchemy it 'creates nested elements' do expect(element.nested_elements).to match_array([ - an_instance_of(Alchemy::Element) + an_instance_of(Alchemy::Element), ]) end @@ -76,14 +76,14 @@ module Alchemy subject(:element) do described_class.create( page: page, - name: 'slider' + name: 'slider', ) end before do expect(Alchemy::Element).to receive(:definitions).at_least(:once) do [ - {'name' => 'slider', 'nestable_elements' => ['foo'], 'autogenerate' => ['bar']} + {'name' => 'slider', 'nestable_elements' => ['foo'], 'autogenerate' => ['bar']}, ] end end @@ -104,7 +104,7 @@ module Alchemy described_class.create( page: page, name: 'slider', - autogenerate_nested_elements: false + autogenerate_nested_elements: false, ) end @@ -148,7 +148,7 @@ module Alchemy let(:element) do create(:alchemy_element, :with_contents, :with_nestable_elements, { tag_list: 'red, yellow', - page: create(:alchemy_page) + page: create(:alchemy_page), }) end @@ -273,7 +273,7 @@ module Alchemy it "should return all elements that are fixed" do expect(Element.fixed).to match_array([ - fixed_element + fixed_element, ]) end end @@ -284,7 +284,7 @@ module Alchemy it "should return all elements that are not fixed" do expect(Element.unfixed).to match_array([ - element + element, ]) end end @@ -474,7 +474,7 @@ module Alchemy .with('article.content.invalid', { scope: "content_validations", default: [:"fields.content.invalid", :"errors.invalid"], - field: "Contenido"}) + field: "Contenido", }) expect(element).to receive(:essence_errors) .and_return({'content' => [:invalid]}) @@ -736,7 +736,7 @@ module Alchemy it "should return true" do expect(element).to receive(:definition).and_return({ 'name' => 'article', - 'taggable' => true + 'taggable' => true, }) expect(element.taggable?).to be_truthy end @@ -746,7 +746,7 @@ module Alchemy it "should return false" do expect(element).to receive(:definition).and_return({ 'name' => 'article', - 'taggable' => 'foo' + 'taggable' => 'foo', }) expect(element.taggable?).to be_falsey end @@ -755,7 +755,7 @@ module Alchemy context "definition has no 'taggable' key" do it "should return false" do expect(element).to receive(:definition).and_return({ - 'name' => 'article' + 'name' => 'article', }) expect(element.taggable?).to be_falsey end @@ -866,7 +866,7 @@ module Alchemy before do allow(element).to receive(:definition) do { - 'nestable_elements' => %w(news article) + 'nestable_elements' => %w(news article), } end end @@ -971,7 +971,7 @@ module Alchemy create(:alchemy_element, :with_contents, { name: 'text', parent_element: element, - folded: false + folded: false, }) end @@ -979,7 +979,7 @@ module Alchemy create(:alchemy_element, :with_contents, { name: 'text', parent_element: nested_element_1, - folded: false + folded: false, }) end @@ -987,7 +987,7 @@ module Alchemy create(:alchemy_element, :with_contents, { name: 'text', parent_element: nested_element_1, - folded: true + folded: true, }) end @@ -995,7 +995,7 @@ module Alchemy is_expected.to eq( element.content_ids + nested_element_1.content_ids + - nested_element_2.content_ids + nested_element_2.content_ids, ) end end diff --git a/spec/models/alchemy/essence_picture_spec.rb b/spec/models/alchemy/essence_picture_spec.rb index 3694c544a0..3fc0c04fdd 100644 --- a/spec/models/alchemy/essence_picture_spec.rb +++ b/spec/models/alchemy/essence_picture_spec.rb @@ -78,7 +78,7 @@ module Alchemy it "passes these crop sizes to the picture's url method." do expect(picture).to receive(:url).with( - hash_including(crop_from: '10x10', crop_size: '200x200') + hash_including(crop_from: '10x10', crop_size: '200x200'), ) picture_url end @@ -90,7 +90,7 @@ module Alchemy it "passes these crop sizes instead." do expect(picture).to receive(:url).with( - hash_including(crop_from: '30x30', crop_size: '75x75') + hash_including(crop_from: '30x30', crop_size: '75x75'), ) picture_url end @@ -208,7 +208,7 @@ module Alchemy it "passes these crop sizes to the picture's url method." do expect(picture).to receive(:url).with( - hash_including(crop_from: '10x10', crop_size: '200x200', crop: true) + hash_including(crop_from: '10x10', crop_size: '200x200', crop: true), ) thumbnail_url end @@ -217,7 +217,7 @@ module Alchemy context 'when no crop sizes are present' do it "it does not pass crop sizes to the picture's url method and disables cropping." do expect(picture).to receive(:url).with( - hash_including(crop_from: nil, crop_size: nil, crop: false) + hash_including(crop_from: nil, crop_size: nil, crop: false), ) thumbnail_url end @@ -229,7 +229,7 @@ module Alchemy it "it enables cropping." do expect(picture).to receive(:url).with( - hash_including(crop: true) + hash_including(crop: true), ) thumbnail_url end @@ -303,7 +303,7 @@ module Alchemy let(:settings) do { size: '150x150', - format: 'png' + format: 'png', } end diff --git a/spec/models/alchemy/essence_picture_view_spec.rb b/spec/models/alchemy/essence_picture_view_spec.rb index 4cd33d8b5a..caadcc0b7c 100644 --- a/spec/models/alchemy/essence_picture_view_spec.rb +++ b/spec/models/alchemy/essence_picture_view_spec.rb @@ -255,7 +255,7 @@ let(:sizes) do [ '(max-width: 1023px) 100vh', - '(min-width: 1024px) 33.333vh' + '(min-width: 1024px) 33.333vh', ] end diff --git a/spec/models/alchemy/language_spec.rb b/spec/models/alchemy/language_spec.rb index 04c9dc4490..bf7aa54f7d 100644 --- a/spec/models/alchemy/language_spec.rb +++ b/spec/models/alchemy/language_spec.rb @@ -15,7 +15,7 @@ module Alchemy name: 'Österreich', frontpage_name: 'Start', page_layout: 'index', - site: build(:alchemy_site) + site: build(:alchemy_site), ) expect(language).to be_valid end diff --git a/spec/models/alchemy/page/fixed_attributes_spec.rb b/spec/models/alchemy/page/fixed_attributes_spec.rb index 6f4d4bb29f..a4b91d7b91 100644 --- a/spec/models/alchemy/page/fixed_attributes_spec.rb +++ b/spec/models/alchemy/page/fixed_attributes_spec.rb @@ -9,14 +9,14 @@ { 'name' => 'foo', 'fixed_attributes' => { - name: 'Home' - } + name: 'Home', + }, } end let(:definition_without_fixed_attributes) do { - 'name' => 'foo' + 'name' => 'foo', } end diff --git a/spec/models/alchemy/page_spec.rb b/spec/models/alchemy/page_spec.rb index 49c9b0d8e1..b3d7c06f40 100644 --- a/spec/models/alchemy/page_spec.rb +++ b/spec/models/alchemy/page_spec.rb @@ -311,7 +311,7 @@ module Alchemy page_2 = create(:alchemy_page, language: language, name: 'Another page') clipboard = [ {'id' => page_1.id.to_s, 'action' => 'copy'}, - {'id' => page_2.id.to_s, 'action' => 'copy'} + {'id' => page_2.id.to_s, 'action' => 'copy'}, ] expect(Page.all_from_clipboard_for_select(clipboard, language.id)).to include(page_1, page_2) end @@ -321,7 +321,7 @@ module Alchemy it "should not return any pages" do page_1 = create(:alchemy_page, language: language, page_layout: 'contact') clipboard = [ - {'id' => page_1.id.to_s, 'action' => 'copy'} + {'id' => page_1.id.to_s, 'action' => 'copy'}, ] expect(Page.all_from_clipboard_for_select(clipboard, language.id)).to eq([]) end @@ -333,7 +333,7 @@ module Alchemy page_2 = create(:alchemy_page, name: 'Another page', language: language, page_layout: 'contact') clipboard = [ {'id' => page_1.id.to_s, 'action' => 'copy'}, - {'id' => page_2.id.to_s, 'action' => 'copy'} + {'id' => page_2.id.to_s, 'action' => 'copy'}, ] expect(Page.all_from_clipboard_for_select(clipboard, language.id)).to eq([page_1]) end @@ -408,7 +408,7 @@ module Alchemy name: 'layoutpage', layoutpage: true, parent_id: layoutroot.id, - language: klingon + language: klingon, } end @@ -416,7 +416,7 @@ module Alchemy create :alchemy_page, :language_root, { name: 'klingon_lang_root', layoutpage: nil, - language: klingon + language: klingon, } end @@ -424,7 +424,7 @@ module Alchemy create :alchemy_page, :public, { name: 'contentpage', parent_id: language_root.id, - language: language + language: language, } end @@ -432,7 +432,7 @@ module Alchemy expect(Page.contentpages.to_a).to include( language_root, klingon_lang_root, - contentpage + contentpage, ) end @@ -531,7 +531,7 @@ module Alchemy allow(page).to receive(:definition).and_return({ 'name' => 'standard', 'elements' => ['headline'], - 'autogenerate' => ['headline'] + 'autogenerate' => ['headline'], }) end @@ -772,19 +772,19 @@ module Alchemy { 'name' => 'column_headline', 'amount' => 3, - 'contents' => [{'name' => 'headline', 'type' => 'EssenceText'}] + 'contents' => [{'name' => 'headline', 'type' => 'EssenceText'}], }, { 'name' => 'unique_headline', 'unique' => true, 'amount' => 3, - 'contents' => [{'name' => 'headline', 'type' => 'EssenceText'}] - } + 'contents' => [{'name' => 'headline', 'type' => 'EssenceText'}], + }, ]) allow(PageLayout).to receive(:get).and_return({ 'name' => 'columns', 'elements' => ['column_headline', 'unique_headline'], - 'autogenerate' => ['unique_headline', 'column_headline', 'column_headline', 'column_headline'] + 'autogenerate' => ['unique_headline', 'column_headline', 'column_headline', 'column_headline'], }) end @@ -1025,7 +1025,7 @@ module Alchemy [ {'name' => 'slider', 'nestable_elements' => %w(slide)}, {'name' => 'gallery', 'nestable_elements' => %w(slide)}, - {'name' => 'slide'} + {'name' => 'slide'}, ] end end @@ -1266,7 +1266,7 @@ module Alchemy parent_id: new_parent.id, language: new_parent.language, name: page_name, - title: page_name + title: page_name, }) subject end @@ -1519,7 +1519,7 @@ module Alchemy create(:alchemy_page, public_on: public_on, public_until: public_until, - published_at: published_at + published_at: published_at, ) end let(:published_at) { nil } diff --git a/spec/models/alchemy/picture_spec.rb b/spec/models/alchemy/picture_spec.rb index 1d3988a248..4d252c49b2 100644 --- a/spec/models/alchemy/picture_spec.rb +++ b/spec/models/alchemy/picture_spec.rb @@ -335,7 +335,7 @@ module Alchemy before do expect(picture).to receive(:pages).at_least(:once).and_return double( not_restricted: double(blank?: true), - any?: true + any?: true, ) end @@ -346,7 +346,7 @@ module Alchemy before do expect(picture).to receive(:pages).at_least(:once).and_return double( not_restricted: double(blank?: false), - any?: true + any?: true, ) end diff --git a/spec/models/alchemy/picture_url_spec.rb b/spec/models/alchemy/picture_url_spec.rb index a5419b6fc6..0d4ae9a9fe 100644 --- a/spec/models/alchemy/picture_url_spec.rb +++ b/spec/models/alchemy/picture_url_spec.rb @@ -15,7 +15,7 @@ def decode_dragon_fly_job(url) let(:image) do fixture_file_upload( File.expand_path('../../fixtures/500x500.png', __dir__), - 'image/png' + 'image/png', ) end @@ -61,7 +61,7 @@ def decode_dragon_fly_job(url) let(:options) do { size: '1600x1200', - upsample: true + upsample: true, } end @@ -75,7 +75,7 @@ def decode_dragon_fly_job(url) let(:options) do { size: '160x120', - crop: true + crop: true, } end @@ -90,7 +90,7 @@ def decode_dragon_fly_job(url) crop_size: '123x44', crop_from: '0x0', size: '160x120', - crop: true + crop: true, } end @@ -105,7 +105,7 @@ def decode_dragon_fly_job(url) let(:options) do { size: '160x120', - crop: false + crop: false, } end @@ -120,7 +120,7 @@ def decode_dragon_fly_job(url) crop_size: '123x44', crop_from: '0x0', size: '160x120', - crop: false + crop: false, } end @@ -175,7 +175,7 @@ def decode_dragon_fly_job(url) let(:image) do fixture_file_upload( File.expand_path('../../fixtures/icon.svg', __dir__), - 'image/svg+xml' + 'image/svg+xml', ) end @@ -193,7 +193,7 @@ def decode_dragon_fly_job(url) let(:image) do fixture_file_upload( File.expand_path('../../fixtures/animated.gif', __dir__), - 'image/gif' + 'image/gif', ) end diff --git a/spec/models/alchemy/tag_spec.rb b/spec/models/alchemy/tag_spec.rb index 8660b91a70..b063e1256c 100644 --- a/spec/models/alchemy/tag_spec.rb +++ b/spec/models/alchemy/tag_spec.rb @@ -17,7 +17,7 @@ module Alchemy allow(element).to receive(:save).and_return(true) allow(tag).to receive(:taggings).and_return([ mock_model(Gutentag::Tagging, taggable: picture), - mock_model(Gutentag::Tagging, taggable: element) + mock_model(Gutentag::Tagging, taggable: element), ]) end diff --git a/spec/requests/alchemy/admin/pages_controller_spec.rb b/spec/requests/alchemy/admin/pages_controller_spec.rb index 4bd7321562..db0b86fadc 100644 --- a/spec/requests/alchemy/admin/pages_controller_spec.rb +++ b/spec/requests/alchemy/admin/pages_controller_spec.rb @@ -338,7 +338,7 @@ module Alchemy id: page_2.id, slug: page_2.slug, children: [page_item_3], - visible: false + visible: false, } end @@ -358,7 +358,7 @@ module Alchemy id: page_2.id, slug: page_2.slug, children: [page_item_3], - restricted: true + restricted: true, } end @@ -374,7 +374,7 @@ module Alchemy { id: page_2.id, slug: 42, - children: [page_item_3] + children: [page_item_3], } end @@ -420,7 +420,7 @@ module Alchemy { parent_id: parent.id, name: 'new Page', - page_layout: 'standard' + page_layout: 'standard', } end @@ -438,7 +438,7 @@ module Alchemy let(:page_params) do { parent_id: parent.id, - name: 'new Page' + name: 'new Page', } end @@ -460,7 +460,7 @@ module Alchemy let(:page_params) do { parent_id: parent.id, - name: 'new Page' + name: 'new Page', } end @@ -492,7 +492,7 @@ module Alchemy with(page_in_clipboard, parent, page_params[:name]) post admin_pages_path( page: page_params, - paste_from_clipboard: page_in_clipboard.id + paste_from_clipboard: page_in_clipboard.id, ), xhr: true end end diff --git a/spec/requests/alchemy/api/nodes_controller_spec.rb b/spec/requests/alchemy/api/nodes_controller_spec.rb index 152f64bcab..5c27ef0278 100644 --- a/spec/requests/alchemy/api/nodes_controller_spec.rb +++ b/spec/requests/alchemy/api/nodes_controller_spec.rb @@ -20,7 +20,7 @@ module Alchemy expect(url_node.lft).to eq(6) patch alchemy.move_api_node_path(url_node, format: :json), params: { target_parent_id: page_node.id, - new_position: 0 + new_position: 0, } expect(response.status).to eq(200) response_json = JSON.parse(response.body) @@ -37,7 +37,7 @@ module Alchemy it 'returns an unauthorized error' do patch alchemy.move_api_node_path(url_node, format: :json), params: { target_parent_id: page_node.id, - new_position: 0 + new_position: 0, } expect(response).to be_forbidden response_json = JSON.parse(response.body) diff --git a/spec/requests/alchemy/legacy_page_redirecting_spec.rb b/spec/requests/alchemy/legacy_page_redirecting_spec.rb index cfd0f264c3..a4ca2709f3 100644 --- a/spec/requests/alchemy/legacy_page_redirecting_spec.rb +++ b/spec/requests/alchemy/legacy_page_redirecting_spec.rb @@ -26,7 +26,7 @@ let(:legacy_url4) do Alchemy::LegacyPageUrl.create( urlname: 'index.php?option=com_content&view=article&id=48&Itemid=69', - page: second_page + page: second_page, ) end diff --git a/spec/routing/api_routing_spec.rb b/spec/routing/api_routing_spec.rb index 3052e57b41..607cbab205 100644 --- a/spec/routing/api_routing_spec.rb +++ b/spec/routing/api_routing_spec.rb @@ -10,7 +10,7 @@ expect({get: "/api/pages.json"}).to route_to( controller: "alchemy/api/pages", action: "index", - format: "json" + format: "json", ) end @@ -19,7 +19,7 @@ expect({get: "/api/pages"}).to route_to( controller: "alchemy/api/pages", action: "index", - format: "json" + format: "json", ) end end @@ -29,7 +29,7 @@ controller: "alchemy/api/pages", action: "show", urlname: "a-page", - format: "json" + format: "json", ) end @@ -38,7 +38,7 @@ controller: "alchemy/api/pages", action: "show", urlname: "nested/a-page", - format: "json" + format: "json", ) end @@ -48,7 +48,7 @@ controller: "alchemy/api/pages", action: "show", id: "8", - format: "json" + format: "json", ) end end @@ -59,7 +59,7 @@ expect({get: "/api/elements.json"}).to route_to( controller: "alchemy/api/elements", action: "index", - format: "json" + format: "json", ) end @@ -68,7 +68,7 @@ expect({get: "/api/elements"}).to route_to( controller: "alchemy/api/elements", action: "index", - format: "json" + format: "json", ) end end @@ -78,7 +78,7 @@ controller: "alchemy/api/elements", action: "index", page_id: "1", - format: "json" + format: "json", ) end @@ -88,7 +88,7 @@ action: "index", page_id: "1", named: "article", - format: "json" + format: "json", ) end @@ -97,7 +97,7 @@ controller: "alchemy/api/elements", action: "show", id: "1", - format: "json" + format: "json", ) end end @@ -107,7 +107,7 @@ expect({get: "/api/contents.json"}).to route_to( controller: "alchemy/api/contents", action: "index", - format: "json" + format: "json", ) end @@ -116,7 +116,7 @@ expect({get: "/api/contents"}).to route_to( controller: "alchemy/api/contents", action: "index", - format: "json" + format: "json", ) end end @@ -126,7 +126,7 @@ controller: "alchemy/api/contents", action: "index", element_id: "1", - format: "json" + format: "json", ) end @@ -136,7 +136,7 @@ action: "show", element_id: "1", name: "headline", - format: "json" + format: "json", ) end @@ -145,7 +145,7 @@ controller: "alchemy/api/contents", action: "show", id: "1", - format: "json" + format: "json", ) end end diff --git a/spec/routing/routing_spec.rb b/spec/routing/routing_spec.rb index 42e59163b8..e711f6fca7 100644 --- a/spec/routing/routing_spec.rb +++ b/spec/routing/routing_spec.rb @@ -8,32 +8,32 @@ describe "root url" do it "routes to pages_controller#index" do expect({ - get: "/" + get: "/", }).to route_to( controller: "alchemy/pages", - action: "index" + action: "index", ) end context 'with locale parameter' do it 'routes to pages_controller#index' do expect({ - get: '/en' + get: '/en', }).to route_to( controller: 'alchemy/pages', action: 'index', - locale: 'en' + locale: 'en', ) end context 'that contains uppercase country code' do it 'routes to pages_controller#index' do expect({ - get: '/en-UK' + get: '/en-UK', }).to route_to( controller: 'alchemy/pages', action: 'index', - locale: 'en-UK' + locale: 'en-UK', ) end end @@ -43,13 +43,13 @@ context "for downloads" do it "should have a named route" do expect({ - get: "/attachment/32/download/Presseveranstaltung.pdf" + get: "/attachment/32/download/Presseveranstaltung.pdf", }).to route_to( controller: "alchemy/attachments", action: "download", id: "32", name: "Presseveranstaltung", - format: "pdf" + format: "pdf", ) end end @@ -58,23 +58,23 @@ context "one level deep nested" do it "should route to pages show" do expect({ - get: "/products/my-product" + get: "/products/my-product", }).to route_to( controller: "alchemy/pages", action: "show", - urlname: "products/my-product" + urlname: "products/my-product", ) end context "and language" do it "should route to pages show" do expect({ - get: "/de/products/my-product" + get: "/de/products/my-product", }).to route_to( controller: "alchemy/pages", action: "show", urlname: "products/my-product", - locale: "de" + locale: "de", ) end end @@ -83,23 +83,23 @@ context "two levels deep nested" do it "should route to pages show" do expect({ - get: "/catalog/products/my-product" + get: "/catalog/products/my-product", }).to route_to( controller: "alchemy/pages", action: "show", - urlname: "catalog/products/my-product" + urlname: "catalog/products/my-product", ) end context "and language" do it "should route to pages show" do expect({ - get: "/de/catalog/products/my-product" + get: "/de/catalog/products/my-product", }).to route_to( controller: "alchemy/pages", action: "show", urlname: "catalog/products/my-product", - locale: "de" + locale: "de", ) end end @@ -108,23 +108,23 @@ context "with a blog date url" do it "should route to pages show" do expect({ - get: "/2011/12/08/my-post" + get: "/2011/12/08/my-post", }).to route_to( controller: "alchemy/pages", action: "show", - urlname: "2011/12/08/my-post" + urlname: "2011/12/08/my-post", ) end context "and language" do it "should route to pages show" do expect({ - get: "/de/2011/12/08/my-post" + get: "/de/2011/12/08/my-post", }).to route_to( controller: "alchemy/pages", action: "show", urlname: "2011/12/08/my-post", - locale: "de" + locale: "de", ) end end @@ -134,7 +134,7 @@ describe "image format requests" do it "should not be handled by alchemy/pages controller" do expect({ - get: "/products/my-product.jpg" + get: "/products/my-product.jpg", }).not_to be_routable end end @@ -142,12 +142,12 @@ describe "rss feed requests" do it "should be handled by alchemy/pages controller" do expect({ - get: "/news.rss" + get: "/news.rss", }).to route_to( controller: "alchemy/pages", action: "show", urlname: "news", - format: "rss" + format: "rss", ) end end @@ -155,22 +155,22 @@ describe "unknown formats" do it "should be handled by alchemy/pages controller" do expect({ - get: "/index.php?id=234" + get: "/index.php?id=234", }).to route_to( controller: "alchemy/pages", action: "show", urlname: "index", format: "php", - id: "234" + id: "234", ) expect({ - get: "/action.do" + get: "/action.do", }).to route_to( controller: "alchemy/pages", action: "show", urlname: "action", - format: "do" + format: "do", ) end end @@ -178,7 +178,7 @@ describe "Rails info requests" do it "should not be handled by alchemy/pages controller" do expect({ - get: "/rails/info/routes" + get: "/rails/info/routes", }).not_to be_routable end end @@ -187,20 +187,20 @@ context "default" do it "should route to admin dashboard" do expect({ - get: "/admin/dashboard" + get: "/admin/dashboard", }).to route_to( controller: "alchemy/admin/dashboard", - action: "index" + action: "index", ) end it "should route to page preview" do expect({ - get: "/admin/pages/3/preview" + get: "/admin/pages/3/preview", }).to route_to( controller: "alchemy/admin/pages", action: "preview", - id: "3" + id: "3", ) end end @@ -214,22 +214,22 @@ it "should route to admin dashboard" do expect({ - get: "http://hidden.example.org/backend/dashboard" + get: "http://hidden.example.org/backend/dashboard", }).to route_to( controller: "alchemy/admin/dashboard", action: "index", - subdomain: "hidden" + subdomain: "hidden", ) end it "should route to page preview" do expect({ - get: "http://hidden.example.org/backend/pages/3/preview" + get: "http://hidden.example.org/backend/pages/3/preview", }).to route_to( controller: "alchemy/admin/pages", action: "preview", id: "3", - subdomain: "hidden" + subdomain: "hidden", ) end diff --git a/spec/serializers/alchemy/element_serializer_spec.rb b/spec/serializers/alchemy/element_serializer_spec.rb index ac7964a76e..7c220dcfdd 100644 --- a/spec/serializers/alchemy/element_serializer_spec.rb +++ b/spec/serializers/alchemy/element_serializer_spec.rb @@ -21,7 +21,7 @@ 'page_id' => element.page_id, 'position' => nil, 'tag_list' => [], - 'updated_at' => element.updated_at.strftime('%FT%T.%LZ') + 'updated_at' => element.updated_at.strftime('%FT%T.%LZ'), ) end end diff --git a/spec/serializers/alchemy/node_serializer_spec.rb b/spec/serializers/alchemy/node_serializer_spec.rb index 5c6365056d..20b3b4aa85 100644 --- a/spec/serializers/alchemy/node_serializer_spec.rb +++ b/spec/serializers/alchemy/node_serializer_spec.rb @@ -15,7 +15,7 @@ 'rgt' => node.rgt, 'parent_id' => node.parent_id, 'name' => node.name, - 'url' => node.url + 'url' => node.url, ) end end diff --git a/spec/views/admin/pictures/show_spec.rb b/spec/views/admin/pictures/show_spec.rb index 8fa8ba4eb5..8b2c619eb9 100644 --- a/spec/views/admin/pictures/show_spec.rb +++ b/spec/views/admin/pictures/show_spec.rb @@ -6,7 +6,7 @@ let(:image) do fixture_file_upload( File.expand_path('../../../fixtures/animated.gif', __dir__), - 'image/gif' + 'image/gif', ) end @@ -14,7 +14,7 @@ create(:alchemy_picture, { image_file: image, name: 'animated', - image_file_name: 'animated.gif' + image_file_name: 'animated.gif', }) end diff --git a/spec/views/alchemy/admin/elements/element_view_spec.rb b/spec/views/alchemy/admin/elements/element_view_spec.rb index 6b439f25ee..556cb604af 100644 --- a/spec/views/alchemy/admin/elements/element_view_spec.rb +++ b/spec/views/alchemy/admin/elements/element_view_spec.rb @@ -10,7 +10,7 @@ let(:definition) do { name: 'with_message', - message: 'One nice message' + message: 'One nice message', }.with_indifferent_access end @@ -30,7 +30,7 @@ let(:definition) do { name: 'with_message', - message: '<h1>One nice message</h1>' + message: '<h1>One nice message</h1>', }.with_indifferent_access end @@ -46,7 +46,7 @@ let(:definition) do { name: 'with_warning', - warning: 'One nice warning' + warning: 'One nice warning', }.with_indifferent_access end @@ -58,7 +58,7 @@ let(:definition) do { name: 'with_warning', - warning: '<h1>One nice warning</h1>' + warning: '<h1>One nice warning</h1>', }.with_indifferent_access end diff --git a/spec/views/alchemy/admin/partials/_main_navigation_entry.html.erb_spec.rb b/spec/views/alchemy/admin/partials/_main_navigation_entry.html.erb_spec.rb index 0e428b85d5..0b2f0fd126 100644 --- a/spec/views/alchemy/admin/partials/_main_navigation_entry.html.erb_spec.rb +++ b/spec/views/alchemy/admin/partials/_main_navigation_entry.html.erb_spec.rb @@ -13,8 +13,8 @@ name: 'Pages', image: 'alchemy/alchemy-logo.svg', data: { turbolinks: false }, - sub_navigation: [] - } + sub_navigation: [], + }, }.with_indifferent_access end @@ -43,8 +43,8 @@ action: 'index', name: 'Pages', image: 'alchemy/alchemy-logo.svg', - sub_navigation: [] - } + sub_navigation: [], + }, }.with_indifferent_access end diff --git a/spec/views/essences/essence_boolean_editor_spec.rb b/spec/views/essences/essence_boolean_editor_spec.rb index a8eb7f3a5e..63a914c21c 100644 --- a/spec/views/essences/essence_boolean_editor_spec.rb +++ b/spec/views/essences/essence_boolean_editor_spec.rb @@ -9,7 +9,7 @@ let(:content_definition) do { name: 'essence_boolean', - type: 'EssenceBoolean' + type: 'EssenceBoolean', }.with_indifferent_access end @@ -22,7 +22,7 @@ subject do render partial: "alchemy/essences/essence_boolean_editor", locals: { - essence_boolean_editor: Alchemy::ContentEditor.new(content) + essence_boolean_editor: Alchemy::ContentEditor.new(content), } rendered end @@ -36,7 +36,7 @@ { name: 'essence_boolean', type: 'EssenceBoolean', - default: true + default: true, }.with_indifferent_access end diff --git a/spec/views/essences/essence_file_editor_spec.rb b/spec/views/essences/essence_file_editor_spec.rb index 03b3604bf3..8bbc69c281 100644 --- a/spec/views/essences/essence_file_editor_spec.rb +++ b/spec/views/essences/essence_file_editor_spec.rb @@ -9,7 +9,7 @@ subject do render partial: "alchemy/essences/essence_file_editor", locals: { - essence_file_editor: Alchemy::ContentEditor.new(content) + essence_file_editor: Alchemy::ContentEditor.new(content), } rendered end diff --git a/spec/views/essences/essence_file_view_spec.rb b/spec/views/essences/essence_file_view_spec.rb index 138c9e54db..8a8338999e 100644 --- a/spec/views/essences/essence_file_view_spec.rb +++ b/spec/views/essences/essence_file_view_spec.rb @@ -27,7 +27,7 @@ it "renders a link to download the attachment" do render content, content: content expect(rendered).to have_selector( - "a[href='/attachment/#{attachment.id}/download/#{attachment.urlname}.#{attachment.suffix}']" + "a[href='/attachment/#{attachment.id}/download/#{attachment.urlname}.#{attachment.suffix}']", ) end diff --git a/spec/views/essences/essence_link_editor_spec.rb b/spec/views/essences/essence_link_editor_spec.rb index 840ca929ab..87e474b084 100644 --- a/spec/views/essences/essence_link_editor_spec.rb +++ b/spec/views/essences/essence_link_editor_spec.rb @@ -11,7 +11,7 @@ view.class.send :include, Alchemy::Admin::BaseHelper allow(view).to receive(:content_label).and_return("1e Zahl") render partial: "alchemy/essences/essence_link_editor", locals: { - essence_link_editor: Alchemy::ContentEditor.new(content) + essence_link_editor: Alchemy::ContentEditor.new(content), } end diff --git a/spec/views/essences/essence_picture_editor_spec.rb b/spec/views/essences/essence_picture_editor_spec.rb index 23d3b9dcc7..722e0c3651 100644 --- a/spec/views/essences/essence_picture_editor_spec.rb +++ b/spec/views/essences/essence_picture_editor_spec.rb @@ -9,7 +9,7 @@ stub_model( Alchemy::EssencePicture, picture: picture, - caption: 'This is a cute cat' + caption: 'This is a cute cat', ) end @@ -18,7 +18,7 @@ Alchemy::Content, name: 'image', essence_type: 'EssencePicture', - essence: essence_picture + essence: essence_picture, ) end @@ -48,7 +48,7 @@ context "with settings[:deletable] being false" do let(:settings) do { - linkable: false + linkable: false, } end diff --git a/spec/views/essences/essence_select_editor_spec.rb b/spec/views/essences/essence_select_editor_spec.rb index 5ecff83b15..1c015662c0 100644 --- a/spec/views/essences/essence_select_editor_spec.rb +++ b/spec/views/essences/essence_select_editor_spec.rb @@ -26,7 +26,7 @@ before do expect(content).to receive(:settings).at_least(:once) do { - select_values: %w(red blue yellow) + select_values: %w(red blue yellow), } end end diff --git a/spec/views/essences/essence_text_editor_spec.rb b/spec/views/essences/essence_text_editor_spec.rb index 6365dfa281..3280b5600b 100644 --- a/spec/views/essences/essence_text_editor_spec.rb +++ b/spec/views/essences/essence_text_editor_spec.rb @@ -12,7 +12,7 @@ allow(view).to receive(:content_label).and_return("1e Zahl") allow(content).to receive(:settings) { settings } render partial: "alchemy/essences/essence_text_editor", locals: { - essence_text_editor: Alchemy::ContentEditor.new(content) + essence_text_editor: Alchemy::ContentEditor.new(content), } end @@ -25,7 +25,7 @@ context 'with a different input type set' do let(:settings) do { - input_type: "number" + input_type: "number", } end @@ -37,7 +37,7 @@ context 'with settings linkable set to true' do let(:settings) do { - linkable: true + linkable: true, } end From e06cf88f9a83f6d55801fd26cbd2c3a2b3e53df1 Mon Sep 17 00:00:00 2001 From: Thomas von Deyen <thomas@vondeyen.com> Date: Wed, 29 Apr 2020 09:15:38 +0200 Subject: [PATCH 4/5] [Rufo] Use double quotes for strings --- .rubocop.yml | 6 +- Gemfile | 44 +- .../alchemy/admin/attachments_controller.rb | 8 +- .../alchemy/admin/base_controller.rb | 10 +- .../alchemy/admin/clipboard_controller.rb | 8 +- .../alchemy/admin/contents_controller.rb | 2 +- .../alchemy/admin/dashboard_controller.rb | 18 +- .../admin/essence_pictures_controller.rb | 6 +- .../alchemy/admin/languages_controller.rb | 8 +- .../alchemy/admin/pages_controller.rb | 46 +- .../alchemy/admin/pictures_controller.rb | 20 +- .../alchemy/admin/resources_controller.rb | 18 +- .../alchemy/admin/sites_controller.rb | 4 +- .../alchemy/admin/tags_controller.rb | 6 +- .../alchemy/api/base_controller.rb | 4 +- .../alchemy/api/contents_controller.rb | 2 +- .../alchemy/api/elements_controller.rb | 2 +- .../alchemy/api/pages_controller.rb | 2 +- .../alchemy/attachments_controller.rb | 6 +- app/controllers/alchemy/base_controller.rb | 14 +- .../alchemy/messages_controller.rb | 24 +- app/controllers/alchemy/pages_controller.rb | 20 +- .../concerns/alchemy/admin/archive_overlay.rb | 4 +- .../alchemy/admin/current_language.rb | 2 +- .../concerns/alchemy/legacy_page_redirects.rb | 2 +- .../concerns/alchemy/site_redirects.rb | 2 +- app/decorators/alchemy/content_editor.rb | 6 +- app/decorators/alchemy/element_editor.rb | 16 +- .../alchemy/admin/attachments_helper.rb | 12 +- app/helpers/alchemy/admin/base_helper.rb | 50 +- app/helpers/alchemy/admin/contents_helper.rb | 4 +- app/helpers/alchemy/admin/elements_helper.rb | 4 +- app/helpers/alchemy/admin/essences_helper.rb | 6 +- app/helpers/alchemy/admin/form_helper.rb | 2 +- .../alchemy/admin/navigation_helper.rb | 42 +- app/helpers/alchemy/admin/pages_helper.rb | 22 +- app/helpers/alchemy/admin/pictures_helper.rb | 6 +- app/helpers/alchemy/admin/tags_helper.rb | 8 +- app/helpers/alchemy/base_helper.rb | 12 +- app/helpers/alchemy/elements_helper.rb | 12 +- app/helpers/alchemy/pages_helper.rb | 14 +- app/helpers/alchemy/url_helper.rb | 2 +- app/mailers/alchemy/base_mailer.rb | 2 +- app/models/alchemy/attachment.rb | 14 +- app/models/alchemy/base_record.rb | 4 +- app/models/alchemy/content.rb | 8 +- app/models/alchemy/content/factory.rb | 4 +- app/models/alchemy/element/definitions.rb | 6 +- .../alchemy/element/element_contents.rb | 12 +- .../alchemy/element/element_essences.rb | 2 +- app/models/alchemy/element/presenters.rb | 4 +- app/models/alchemy/element_to_page.rb | 2 +- app/models/alchemy/essence_boolean.rb | 2 +- app/models/alchemy/essence_date.rb | 2 +- app/models/alchemy/essence_file.rb | 2 +- app/models/alchemy/essence_html.rb | 2 +- app/models/alchemy/essence_link.rb | 2 +- app/models/alchemy/essence_page.rb | 2 +- app/models/alchemy/essence_picture.rb | 4 +- app/models/alchemy/essence_picture_view.rb | 10 +- app/models/alchemy/essence_richtext.rb | 2 +- app/models/alchemy/essence_select.rb | 2 +- app/models/alchemy/language.rb | 4 +- app/models/alchemy/language/code.rb | 6 +- app/models/alchemy/legacy_page_url.rb | 2 +- app/models/alchemy/message.rb | 6 +- app/models/alchemy/node.rb | 12 +- app/models/alchemy/page/fixed_attributes.rb | 2 +- app/models/alchemy/page/page_elements.rb | 38 +- app/models/alchemy/page/page_naming.rb | 6 +- app/models/alchemy/page/page_natures.rb | 6 +- app/models/alchemy/page/page_scopes.rb | 2 +- app/models/alchemy/picture.rb | 20 +- app/models/alchemy/picture/url.rb | 6 +- app/models/alchemy/site/layout.rb | 4 +- .../alchemy/page_tree_serializer.rb | 8 +- app/views/alchemy/pages/show.rss.builder | 4 +- bin/rails | 8 +- config/initializers/assets.rb | 2 +- config/initializers/dragonfly.rb | 2 +- config/initializers/mini_profiler.rb | 4 +- config/initializers/simple_form.rb | 12 +- config/routes.rb | 46 +- config/spring.rb | 4 +- lib/alchemy/admin/locale.rb | 2 +- lib/alchemy/auth_accessors.rb | 14 +- lib/alchemy/cache_digests/template_tracker.rb | 8 +- lib/alchemy/config.rb | 4 +- lib/alchemy/controller_actions.rb | 2 +- lib/alchemy/deprecation.rb | 2 +- lib/alchemy/elements_finder.rb | 8 +- lib/alchemy/engine.rb | 24 +- lib/alchemy/essence.rb | 16 +- lib/alchemy/forms/builder.rb | 8 +- lib/alchemy/hints.rb | 2 +- lib/alchemy/i18n.rb | 2 +- lib/alchemy/modules.rb | 24 +- lib/alchemy/name_conversions.rb | 10 +- lib/alchemy/page_layout.rb | 22 +- lib/alchemy/paths.rb | 2 +- lib/alchemy/resource.rb | 22 +- lib/alchemy/resources_helper.rb | 18 +- lib/alchemy/routing_constraints.rb | 2 +- lib/alchemy/seeder.rb | 22 +- lib/alchemy/shell.rb | 8 +- lib/alchemy/ssl_protection.rb | 2 +- lib/alchemy/tasks/tidy.rb | 6 +- .../test_support/essence_shared_examples.rb | 130 ++-- .../factories/attachment_factory.rb | 10 +- .../test_support/factories/content_factory.rb | 12 +- .../factories/dummy_user_factory.rb | 14 +- .../test_support/factories/element_factory.rb | 18 +- .../factories/essence_file_factory.rb | 6 +- .../factories/essence_page_factory.rb | 6 +- .../factories/essence_picture_factory.rb | 8 +- .../factories/essence_text_factory.rb | 6 +- .../factories/language_factory.rb | 26 +- .../test_support/factories/node_factory.rb | 12 +- .../test_support/factories/page_factory.rb | 10 +- .../test_support/factories/picture_factory.rb | 10 +- .../test_support/factories/site_factory.rb | 12 +- lib/alchemy/test_support/shared_contexts.rb | 8 +- .../test_support/shared_uploader_examples.rb | 6 +- lib/alchemy/tinymce.rb | 24 +- lib/alchemy/upgrader.rb | 12 +- lib/alchemy/upgrader/five_point_zero.rb | 4 +- lib/alchemy/upgrader/four_point_four.rb | 6 +- .../upgrader/tasks/element_views_updater.rb | 8 +- .../tasks/harden_gutentag_migrations.rb | 6 +- lib/alchemy/webpacker.rb | 4 +- lib/alchemy_cms.rb | 100 +-- lib/rails/generators/alchemy/base.rb | 8 +- .../alchemy/elements/elements_generator.rb | 8 +- .../alchemy/essence/essence_generator.rb | 6 +- .../alchemy/install/install_generator.rb | 8 +- .../alchemy/menus/menus_generator.rb | 4 +- .../alchemy/module/module_generator.rb | 4 +- .../page_layouts/page_layouts_generator.rb | 6 +- .../site_layouts/site_layouts_generator.rb | 4 +- .../alchemy/views/views_generator.rb | 12 +- lib/tasks/alchemy/db.rake | 2 +- lib/tasks/alchemy/install.rake | 2 +- lib/tasks/alchemy/tidy.rake | 16 +- lib/tasks/alchemy/upgrade.rake | 30 +- .../alchemy/admin/base_controller_spec.rb | 38 +- .../admin/clipboard_controller_spec.rb | 48 +- .../admin/dashboard_controller_spec.rb | 38 +- .../alchemy/admin/elements_controller_spec.rb | 70 +- .../admin/essence_files_controller_spec.rb | 26 +- .../admin/essence_pictures_controller_spec.rb | 88 +-- .../admin/languages_controller_spec.rb | 40 +- .../admin/layoutpages_controller_spec.rb | 18 +- .../alchemy/admin/nodes_controller_spec.rb | 40 +- .../alchemy/admin/pictures_controller_spec.rb | 182 ++--- .../admin/resources_controller_spec.rb | 64 +- .../alchemy/admin/sites_controller_spec.rb | 28 +- .../alchemy/admin/tags_controller_spec.rb | 30 +- .../alchemy/admin/translations_spec.rb | 24 +- .../alchemy/admin/trash_controller_spec.rb | 2 +- .../alchemy/api/contents_controller_spec.rb | 62 +- .../alchemy/api/elements_controller_spec.rb | 78 +- .../alchemy/api/pages_controller_spec.rb | 198 ++--- .../alchemy/attachments_controller_spec.rb | 16 +- .../alchemy/base_controller_spec.rb | 20 +- .../alchemy/elements_controller_spec.rb | 8 +- .../alchemy/messages_controller_spec.rb | 72 +- .../alchemy/on_page_layout_mixin_spec.rb | 88 +-- .../alchemy/pages_controller_spec.rb | 116 +-- .../decorators/alchemy/content_editor_spec.rb | 32 +- .../decorators/alchemy/element_editor_spec.rb | 50 +- spec/dummy/Rakefile | 2 +- .../dummy/app/controllers/login_controller.rb | 2 +- spec/dummy/app/models/dummy_model.rb | 2 +- spec/dummy/app/models/dummy_user.rb | 2 +- spec/dummy/app/models/event.rb | 2 +- spec/dummy/bin/bundle | 4 +- spec/dummy/bin/rails | 6 +- spec/dummy/bin/rake | 4 +- spec/dummy/bin/setup | 16 +- spec/dummy/bin/update | 16 +- spec/dummy/config.ru | 2 +- spec/factories.rb | 8 +- spec/features/admin/admin_layout_spec.rb | 8 +- .../attachment_assignment_overlay_spec.rb | 2 +- spec/features/admin/dashboard_spec.rb | 32 +- .../admin/edit_elements_feature_spec.rb | 18 +- .../admin/language_tree_feature_spec.rb | 32 +- .../features/admin/languages_features_spec.rb | 48 +- .../admin/legacy_page_url_management_spec.rb | 50 +- spec/features/admin/link_overlay_spec.rb | 28 +- .../admin/locale_select_feature_spec.rb | 26 +- .../admin/locked_page_feature_spec.rb | 18 +- spec/features/admin/menus_features_spec.rb | 26 +- .../admin/modules_integration_spec.rb | 12 +- .../features/admin/navigation_feature_spec.rb | 18 +- .../admin/page_creation_feature_spec.rb | 20 +- .../admin/page_destroy_feature_spec.rb | 14 +- .../admin/page_editing_feature_spec.rb | 100 +-- .../admin/page_sorting_feature_spec.rb | 12 +- .../admin/picture_assignment_overlay_spec.rb | 6 +- .../admin/picture_library_integration_spec.rb | 36 +- .../admin/resources_integration_spec.rb | 54 +- .../admin/site_select_feature_spec.rb | 22 +- spec/features/admin/tinymce_feature_spec.rb | 10 +- spec/features/navigation_spec.rb | 2 +- spec/features/page_feature_spec.rb | 68 +- spec/features/page_redirects_spec.rb | 62 +- spec/features/page_seeder_spec.rb | 38 +- spec/features/security_spec.rb | 8 +- spec/features/user_seeder_spec.rb | 20 +- .../alchemy/admin/attachments_helper_spec.rb | 10 +- .../helpers/alchemy/admin/base_helper_spec.rb | 74 +- .../alchemy/admin/contents_helper_spec.rb | 32 +- .../alchemy/admin/elements_helper_spec.rb | 18 +- .../alchemy/admin/essences_helper_spec.rb | 12 +- .../alchemy/admin/pages_helper_spec.rb | 24 +- .../alchemy/admin/pictures_helper_spec.rb | 12 +- .../helpers/alchemy/admin/tags_helper_spec.rb | 34 +- spec/helpers/alchemy/base_helper_spec.rb | 70 +- .../alchemy/elements_block_helper_spec.rb | 38 +- spec/helpers/alchemy/elements_helper_spec.rb | 64 +- spec/helpers/alchemy/pages_helper_spec.rb | 72 +- spec/helpers/alchemy/url_helper_spec.rb | 44 +- spec/libraries/auth_accessors_spec.rb | 30 +- spec/libraries/config_spec.rb | 52 +- spec/libraries/configuration_methods_spec.rb | 24 +- spec/libraries/controller_actions_spec.rb | 16 +- spec/libraries/elements_finder_spec.rb | 106 +-- spec/libraries/i18n_spec.rb | 40 +- .../scoped_pagination_url_helper_spec.rb | 6 +- spec/libraries/logger_spec.rb | 10 +- spec/libraries/modules_spec.rb | 56 +- spec/libraries/page_layout_spec.rb | 64 +- spec/libraries/paths_spec.rb | 12 +- spec/libraries/permissions_spec.rb | 4 +- spec/libraries/resource_spec.rb | 64 +- spec/libraries/resources_helper_spec.rb | 82 +- spec/libraries/shell_spec.rb | 42 +- spec/libraries/template_tracker_spec.rb | 54 +- spec/libraries/tinymce_spec.rb | 60 +- spec/libraries/userstamp_spec.rb | 6 +- spec/mailers/alchemy/messages_mailer_spec.rb | 10 +- spec/models/alchemy/attachment_spec.rb | 110 +-- spec/models/alchemy/content_spec.rb | 192 ++--- spec/models/alchemy/element_spec.rb | 347 ++++----- spec/models/alchemy/element_to_page_spec.rb | 6 +- spec/models/alchemy/essence_boolean_spec.rb | 2 +- spec/models/alchemy/essence_date_spec.rb | 4 +- spec/models/alchemy/essence_file_spec.rb | 10 +- spec/models/alchemy/essence_html_spec.rb | 10 +- spec/models/alchemy/essence_link_spec.rb | 4 +- spec/models/alchemy/essence_node_spec.rb | 8 +- spec/models/alchemy/essence_page_spec.rb | 22 +- spec/models/alchemy/essence_picture_spec.rb | 118 +-- .../alchemy/essence_picture_view_spec.rb | 90 +-- spec/models/alchemy/essence_richtext_spec.rb | 8 +- spec/models/alchemy/essence_select_spec.rb | 4 +- spec/models/alchemy/essence_text_spec.rb | 52 +- spec/models/alchemy/folded_page_spec.rb | 2 +- spec/models/alchemy/language_spec.rb | 114 +-- spec/models/alchemy/legacy_page_url_spec.rb | 10 +- spec/models/alchemy/message_spec.rb | 18 +- spec/models/alchemy/node_spec.rb | 74 +- .../alchemy/page/fixed_attributes_spec.rb | 56 +- spec/models/alchemy/page_spec.rb | 728 +++++++++--------- spec/models/alchemy/picture_spec.rb | 162 ++-- spec/models/alchemy/picture_url_spec.rb | 70 +- spec/models/alchemy/site_spec.rb | 86 +-- spec/models/alchemy/tag_spec.rb | 16 +- spec/models/dummy_model_spec.rb | 4 +- spec/rails_helper.rb | 50 +- .../alchemy/admin/contents_controller_spec.rb | 10 +- .../alchemy/admin/pages_controller_spec.rb | 236 +++--- .../alchemy/admin/resources_requests_spec.rb | 28 +- .../alchemy/admin/site_requests_spec.rb | 12 +- .../alchemy/api/nodes_controller_spec.rb | 34 +- .../alchemy/legacy_page_redirecting_spec.rb | 26 +- .../alchemy/page_request_caching_spec.rb | 38 +- spec/requests/alchemy/site_requests_spec.rb | 10 +- spec/requests/alchemy/sitemap_spec.rb | 48 +- spec/routing/api_routing_spec.rb | 16 +- spec/routing/routing_spec.rb | 26 +- .../alchemy/element_serializer_spec.rb | 28 +- .../alchemy/node_serializer_spec.rb | 16 +- spec/spec_helper.rb | 12 +- spec/support/capybara_helpers.rb | 18 +- spec/support/custom_news_elements_finder.rb | 2 +- spec/support/hint_examples.rb | 18 +- spec/support/transformation_examples.rb | 30 +- spec/views/admin/pictures/show_spec.rb | 12 +- .../admin/elements/element_view_spec.rb | 32 +- .../_main_navigation_entry.html.erb_spec.rb | 28 +- .../essences/essence_boolean_editor_spec.rb | 20 +- .../essences/essence_boolean_view_spec.rb | 16 +- .../essences/essence_date_editor_spec.rb | 6 +- spec/views/essences/essence_date_view_spec.rb | 20 +- .../essences/essence_file_editor_spec.rb | 26 +- spec/views/essences/essence_file_view_spec.rb | 34 +- spec/views/essences/essence_html_view_spec.rb | 10 +- .../essences/essence_link_editor_spec.rb | 6 +- spec/views/essences/essence_link_view_spec.rb | 18 +- .../essences/essence_page_editor_spec.rb | 10 +- spec/views/essences/essence_page_view_spec.rb | 12 +- .../essences/essence_picture_editor_spec.rb | 28 +- .../essences/essence_richtext_view_spec.rb | 22 +- .../essences/essence_select_editor_spec.rb | 16 +- .../essences/essence_select_view_spec.rb | 8 +- .../essences/essence_text_editor_spec.rb | 12 +- spec/views/essences/essence_text_view_spec.rb | 34 +- spec/views/pages/meta_data_spec.rb | 10 +- 310 files changed, 4269 insertions(+), 4266 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index cfe32487d6..f1ea14e8cc 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -221,8 +221,10 @@ Style/SpecialGlobalVars: StyleGuide: http://relaxed.ruby.style/#stylespecialglobalvars Style/StringLiterals: - Enabled: false - StyleGuide: http://relaxed.ruby.style/#stylestringliterals + EnforcedStyle: double_quotes + +Style/StringLiteralsInInterpolation: + EnforcedStyle: double_quotes Style/TrailingCommaInArguments: EnforcedStyleForMultiline: comma diff --git a/Gemfile b/Gemfile index 88d0e21d8a..d87714e381 100644 --- a/Gemfile +++ b/Gemfile @@ -1,33 +1,33 @@ # frozen_string_literal: true -source 'https://rubygems.org' +source "https://rubygems.org" gemspec -rails_version = ENV.fetch('RAILS_VERSION', 6.0).to_f -gem 'rails', "~> #{rails_version}.0" +rails_version = ENV.fetch("RAILS_VERSION", 6.0).to_f +gem "rails", "~> #{rails_version}.0" -if ENV['DB'].nil? || ENV['DB'] == 'sqlite' - gem 'sqlite3', rails_version > 5.0 ? '~> 1.4.1' : '~> 1.3.6' +if ENV["DB"].nil? || ENV["DB"] == "sqlite" + gem "sqlite3", rails_version > 5.0 ? "~> 1.4.1" : "~> 1.3.6" end -gem 'mysql2', '~> 0.5.1' if ENV['DB'] == 'mysql' -gem 'pg', '~> 1.0' if ENV['DB'] == 'postgresql' +gem "mysql2", "~> 0.5.1" if ENV["DB"] == "mysql" +gem "pg", "~> 1.0" if ENV["DB"] == "postgresql" group :development, :test do - if ENV['GITHUB_ACTIONS'] - gem 'sassc', '~> 2.3.0' # https://github.com/sass/sassc-ruby/issues/146 + if ENV["GITHUB_ACTIONS"] + gem "sassc", "~> 2.3.0" # https://github.com/sass/sassc-ruby/issues/146 else - gem 'launchy' - gem 'annotate' - gem 'bumpy' - gem 'yard' - gem 'redcarpet' - gem 'pry-byebug' - gem 'rubocop', '~> 0.82.0', require: false - gem 'listen' - gem 'localeapp', '~> 3.0', require: false - gem 'dotenv', '~> 2.2' - gem 'github_fast_changelog', require: false - gem 'active_record_query_trace', require: false - gem 'rack-mini-profiler', require: false + gem "launchy" + gem "annotate" + gem "bumpy" + gem "yard" + gem "redcarpet" + gem "pry-byebug" + gem "rubocop", "~> 0.82.0", require: false + gem "listen" + gem "localeapp", "~> 3.0", require: false + gem "dotenv", "~> 2.2" + gem "github_fast_changelog", require: false + gem "active_record_query_trace", require: false + gem "rack-mini-profiler", require: false end end diff --git a/app/controllers/alchemy/admin/attachments_controller.rb b/app/controllers/alchemy/admin/attachments_controller.rb index 03630f8c7e..47bc3ca362 100644 --- a/app/controllers/alchemy/admin/attachments_controller.rb +++ b/app/controllers/alchemy/admin/attachments_controller.rb @@ -6,11 +6,11 @@ class AttachmentsController < ResourcesController include UploaderResponses include ArchiveOverlay - helper 'alchemy/admin/tags' + helper "alchemy/admin/tags" def index @query = Attachment.ransack(search_filter_params[:q]) - @query.sorts = 'name asc' if @query.sorts.empty? + @query.sorts = "name asc" if @query.sorts.empty? @attachments = @query.result if search_filter_params[:tagged_with].present? @@ -42,7 +42,7 @@ def create def update @attachment.update(attachment_attributes) - if attachment_attributes['file'].present? + if attachment_attributes["file"].present? handle_uploader_response(status: :accepted) else render_errors_or_redirect( @@ -57,7 +57,7 @@ def destroy name = @attachment.name @attachment.destroy @url = admin_attachments_url(search_filter_params) - flash[:notice] = Alchemy.t('File deleted successfully', name: name) + flash[:notice] = Alchemy.t("File deleted successfully", name: name) end def download diff --git a/app/controllers/alchemy/admin/base_controller.rb b/app/controllers/alchemy/admin/base_controller.rb index 4e3e16c3cb..11a98ead5f 100644 --- a/app/controllers/alchemy/admin/base_controller.rb +++ b/app/controllers/alchemy/admin/base_controller.rb @@ -27,14 +27,14 @@ class BaseController < Alchemy::BaseController def leave authorize! :leave, :alchemy_admin - render template: '/alchemy/admin/leave', layout: !request.xhr? + render template: "/alchemy/admin/leave", layout: !request.xhr? end private # Disable layout rendering for xhr requests. def set_layout - request.xhr? ? false : 'alchemy/admin' + request.xhr? ? false : "alchemy/admin" end # Handles exceptions @@ -55,7 +55,7 @@ def show_error_notice(error) if request.xhr? render action: "error_notice" else - render '500', status: 500 + render "500", status: 500 end end @@ -105,7 +105,7 @@ def render_errors_or_redirect(object, redirect_url, flash_notice) flash[:notice] = Alchemy.t(flash_notice) do_redirect_to redirect_url else - render action: (params[:action] == 'update' ? 'edit' : 'new') + render action: (params[:action] == "update" ? "edit" : "new") end end @@ -131,7 +131,7 @@ def raise_exception? # Are we currently in the page edit mode page preview. def is_page_preview? - controller_path == 'alchemy/admin/pages' && action_name == 'show' + controller_path == "alchemy/admin/pages" && action_name == "show" end def load_locked_pages diff --git a/app/controllers/alchemy/admin/clipboard_controller.rb b/app/controllers/alchemy/admin/clipboard_controller.rb index 0b980cc956..06c6733f4a 100644 --- a/app/controllers/alchemy/admin/clipboard_controller.rb +++ b/app/controllers/alchemy/admin/clipboard_controller.rb @@ -17,10 +17,10 @@ def index def insert @item = model_class.find(remarkable_params[:remarkable_id]) - unless @clipboard.detect { |item| item['id'] == remarkable_params[:remarkable_id] } + unless @clipboard.detect { |item| item["id"] == remarkable_params[:remarkable_id] } @clipboard << { - 'id' => remarkable_params[:remarkable_id], - 'action' => params[:remove] ? 'cut' : 'copy', + "id" => remarkable_params[:remarkable_id], + "action" => params[:remove] ? "cut" : "copy", } end respond_to do |format| @@ -30,7 +30,7 @@ def insert def remove @item = model_class.find(remarkable_params[:remarkable_id]) - @clipboard.delete_if { |item| item['id'] == remarkable_params[:remarkable_id] } + @clipboard.delete_if { |item| item["id"] == remarkable_params[:remarkable_id] } respond_to do |format| format.js end diff --git a/app/controllers/alchemy/admin/contents_controller.rb b/app/controllers/alchemy/admin/contents_controller.rb index d4685c266e..13b460dc69 100644 --- a/app/controllers/alchemy/admin/contents_controller.rb +++ b/app/controllers/alchemy/admin/contents_controller.rb @@ -3,7 +3,7 @@ module Alchemy module Admin class ContentsController < Alchemy::Admin::BaseController - helper 'alchemy/admin/essences' + helper "alchemy/admin/essences" authorize_resource class: Alchemy::Content diff --git a/app/controllers/alchemy/admin/dashboard_controller.rb b/app/controllers/alchemy/admin/dashboard_controller.rb index 0ec91fcedc..cde544c502 100644 --- a/app/controllers/alchemy/admin/dashboard_controller.rb +++ b/app/controllers/alchemy/admin/dashboard_controller.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require 'net/http' -require 'alchemy/version' +require "net/http" +require "alchemy/version" module Alchemy module Admin @@ -28,9 +28,9 @@ def info def update_check @alchemy_version = Alchemy.version if @alchemy_version < latest_alchemy_version - render plain: 'true' + render plain: "true" else - render plain: 'false' + render plain: "false" end rescue UpdateServiceUnavailable => e render plain: e, status: 503 @@ -41,7 +41,7 @@ def update_check # Returns latest alchemy version. def latest_alchemy_version versions = get_alchemy_versions - return '' if versions.blank? + return "" if versions.blank? # reject any non release version versions.reject! { |v| v =~ /[a-z]/ } @@ -54,14 +54,14 @@ def get_alchemy_versions response = query_rubygems if response.code == "200" alchemy_versions = JSON.parse(response.body) - alchemy_versions.collect { |h| h['number'] }.sort + alchemy_versions.collect { |h| h["number"] }.sort else # rubygems.org not available? # then we try github response = query_github if response.code == "200" alchemy_tags = JSON.parse(response.body) - alchemy_tags.collect { |h| h['name'].tr('v', '') }.sort + alchemy_tags.collect { |h| h["name"].tr("v", "") }.sort else # no luck at all? raise UpdateServiceUnavailable @@ -71,12 +71,12 @@ def get_alchemy_versions # Query the RubyGems API for Alchemy versions. def query_rubygems - make_api_request('https://rubygems.org/api/v1/versions/alchemy_cms.json') + make_api_request("https://rubygems.org/api/v1/versions/alchemy_cms.json") end # Query the GitHub API for Alchemy tags. def query_github - make_api_request('https://api.github.com/repos/AlchemyCMS/alchemy_cms/tags') + make_api_request("https://api.github.com/repos/AlchemyCMS/alchemy_cms/tags") end # Make a HTTP API request for given request url. diff --git a/app/controllers/alchemy/admin/essence_pictures_controller.rb b/app/controllers/alchemy/admin/essence_pictures_controller.rb index 3f736c17ea..f1f56279a2 100644 --- a/app/controllers/alchemy/admin/essence_pictures_controller.rb +++ b/app/controllers/alchemy/admin/essence_pictures_controller.rb @@ -9,9 +9,9 @@ class EssencePicturesController < Alchemy::Admin::BaseController before_action :load_essence_picture, only: [:edit, :crop, :update] before_action :load_content, only: [:edit, :update, :assign] - helper 'alchemy/admin/contents' - helper 'alchemy/admin/essences' - helper 'alchemy/url' + helper "alchemy/admin/contents" + helper "alchemy/admin/essences" + helper "alchemy/url" def edit end diff --git a/app/controllers/alchemy/admin/languages_controller.rb b/app/controllers/alchemy/admin/languages_controller.rb index c734bbfb38..402ee0e395 100644 --- a/app/controllers/alchemy/admin/languages_controller.rb +++ b/app/controllers/alchemy/admin/languages_controller.rb @@ -14,14 +14,14 @@ def index def new @language = Language.new( site: @current_site, - page_layout: Config.get(:default_language)['page_layout'], + page_layout: Config.get(:default_language)["page_layout"], ) end def create @language = Alchemy::Language.new(resource_params) if @language.save - flash[:notice] = Alchemy.t('Language successfully created') + flash[:notice] = Alchemy.t("Language successfully created") redirect_to alchemy.admin_pages_path(language_id: @language) else render :new @@ -30,7 +30,7 @@ def create def destroy if @language.destroy - flash[:notice] = Alchemy.t('Language successfully removed') + flash[:notice] = Alchemy.t("Language successfully removed") else flash[:warning] = @language.errors.full_messages.to_sentence end @@ -47,7 +47,7 @@ def switch def load_current_site @current_site = Alchemy::Site.current if @current_site.nil? - flash[:warning] = Alchemy.t('Please create a site first.') + flash[:warning] = Alchemy.t("Please create a site first.") redirect_to admin_sites_path end end diff --git a/app/controllers/alchemy/admin/pages_controller.rb b/app/controllers/alchemy/admin/pages_controller.rb index 92d0da5abd..4e90bdb622 100644 --- a/app/controllers/alchemy/admin/pages_controller.rb +++ b/app/controllers/alchemy/admin/pages_controller.rb @@ -5,7 +5,7 @@ module Admin class PagesController < Alchemy::Admin::BaseController include OnPageLayout::CallbacksRunner - helper 'alchemy/pages' + helper "alchemy/pages" before_action :load_page, except: [:index, :flush, :new, :order, :create, :copy_language_tree, :link, :sort] @@ -48,7 +48,7 @@ def show Page.current_preview = @page # Setting the locale to pages language, so the page content has it's correct translations. ::I18n.locale = @page.language.locale - render(layout: Alchemy::Config.get(:admin_page_preview_layout) || 'application') + render(layout: Alchemy::Config.get(:admin_page_preview_layout) || "application") end def info @@ -56,9 +56,9 @@ def info end def new - @page ||= Page.new(layoutpage: params[:layoutpage] == 'true', parent_id: params[:parent_id]) + @page ||= Page.new(layoutpage: params[:layoutpage] == "true", parent_id: params[:parent_id]) @page_layouts = PageLayout.layouts_for_select(@current_language.id, @page.layoutpage?) - @clipboard = get_clipboard('pages') + @clipboard = get_clipboard("pages") @clipboard_items = Page.all_from_clipboard_for_select(@clipboard, @current_language.id, @page.layoutpage?) end @@ -80,7 +80,7 @@ def create def edit # fetching page via before filter if page_is_locked? - flash[:warning] = Alchemy.t('This page is locked', name: @page.locker_name) + flash[:warning] = Alchemy.t("This page is locked", name: @page.locker_name) redirect_to admin_pages_path elsif page_needs_lock? @page.lock_to!(current_alchemy_user) @@ -102,7 +102,7 @@ def update @old_page_layout = @page.page_layout if @page.update(page_params) @notice = Alchemy.t("Page saved", name: @page.name) - @while_page_edit = request.referer.include?('edit') + @while_page_edit = request.referer.include?("edit") unless @while_page_edit @tree = serialized_page_tree @@ -118,17 +118,17 @@ def destroy flash[:notice] = Alchemy.t("Page deleted", name: @page.name) # Remove page from clipboard - clipboard = get_clipboard('pages') - clipboard.delete_if { |item| item['id'] == @page.id.to_s } + clipboard = get_clipboard("pages") + clipboard.delete_if { |item| item["id"] == @page.id.to_s } end respond_to do |format| format.js do @redirect_url = if @page.layoutpage? - alchemy.admin_layoutpages_path - else - alchemy.admin_pages_path - end + alchemy.admin_layoutpages_path + else + alchemy.admin_pages_path + end render :redirect end @@ -257,14 +257,14 @@ def language_root_to_copy_from def visit_nodes(nodes, my_left, parent, depth, tree, url, restricted) nodes.each do |item| my_right = my_left + 1 - my_restricted = item['restricted'] || restricted + my_restricted = item["restricted"] || restricted urls = process_url(url, item) - if item['children'] - my_right, tree = visit_nodes(item['children'], my_left + 1, item['id'], depth + 1, tree, urls[:children_path], my_restricted) + if item["children"] + my_right, tree = visit_nodes(item["children"], my_left + 1, item["id"], depth + 1, tree, urls[:children_path], my_restricted) end - tree[item['id']] = TreeNode.new(my_left, my_right, parent, depth, urls[:my_urlname], my_restricted) + tree[item["id"]] = TreeNode.new(my_left, my_right, parent, depth, urls[:my_urlname], my_restricted) my_left = my_right + 1 end @@ -301,11 +301,11 @@ def create_tree(items, rootpage) # A children node # def process_url(ancestors_path, item) - default_urlname = (ancestors_path.blank? ? "" : "#{ancestors_path}/") + item['slug'].to_s + default_urlname = (ancestors_path.blank? ? "" : "#{ancestors_path}/") + item["slug"].to_s - pair = {my_urlname: default_urlname, children_path: default_urlname} + pair = { my_urlname: default_urlname, children_path: default_urlname } - if item['visible'] == false + if item["visible"] == false # children ignore an ancestor in their path if invisible pair[:children_path] = ancestors_path end @@ -318,10 +318,10 @@ def load_page end def pages_from_raw_request - request.raw_post.split('&').map do |i| - parts = i.split('=') + request.raw_post.split("&").map do |i| + parts = i.split("=") { - parts[0].gsub(/[^0-9]/, '') => parts[1], + parts[0].gsub(/[^0-9]/, "") => parts[1], } end end @@ -374,7 +374,7 @@ def set_root_page def serialized_page_tree PageTreeSerializer.new(@page, ability: current_ability, user: current_alchemy_user, - full: params[:full] == 'true') + full: params[:full] == "true") end end end diff --git a/app/controllers/alchemy/admin/pictures_controller.rb b/app/controllers/alchemy/admin/pictures_controller.rb index 0c00d54ada..7869a3ee42 100644 --- a/app/controllers/alchemy/admin/pictures_controller.rb +++ b/app/controllers/alchemy/admin/pictures_controller.rb @@ -6,7 +6,7 @@ class PicturesController < Alchemy::Admin::ResourcesController include UploaderResponses include ArchiveOverlay - helper 'alchemy/admin/tags' + helper "alchemy/admin/tags" before_action :load_resource, only: [:show, :edit, :update, :destroy, :info] @@ -14,7 +14,7 @@ class PicturesController < Alchemy::Admin::ResourcesController authorize_resource class: Alchemy::Picture def index - @size = params[:size].present? ? params[:size] : 'medium' + @size = params[:size].present? ? params[:size] : "medium" @query = Picture.ransack(search_filter_params[:q]) @pictures = Picture.search_by( search_filter_params, @@ -31,7 +31,7 @@ def show @previous = @picture.previous(params) @next = @picture.next(params) @assignments = @picture.essence_pictures.joins(content: {element: :page}) - render action: 'show' + render action: "show" end def create @@ -46,19 +46,19 @@ def create def edit_multiple @pictures = Picture.where(id: params[:picture_ids]) - @tags = @pictures.collect(&:tag_list).flatten.uniq.join(', ') + @tags = @pictures.collect(&:tag_list).flatten.uniq.join(", ") end def update if @picture.update(picture_params) @message = { body: Alchemy.t(:picture_updated_successfully, name: @picture.name), - type: 'notice', + type: "notice", } else @message = { body: Alchemy.t(:picture_update_failed), - type: 'error', + type: "error", } end render :update @@ -116,8 +116,8 @@ def destroy def items_per_page if in_overlay? case params[:size] - when 'small' then 25 - when 'large' then 4 + when "small" then 25 + when "large" then 4 else 9 end @@ -137,8 +137,8 @@ def items_per_page_options def pictures_per_page_for_size(size) case size - when 'small' then 60 - when 'large' then 12 + when "small" then 60 + when "large" then 12 else 20 end diff --git a/app/controllers/alchemy/admin/resources_controller.rb b/app/controllers/alchemy/admin/resources_controller.rb index b55273451e..bff8b29a8c 100644 --- a/app/controllers/alchemy/admin/resources_controller.rb +++ b/app/controllers/alchemy/admin/resources_controller.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true -require 'csv' -require 'alchemy/resource' -require 'alchemy/resources_helper' +require "csv" +require "alchemy/resource" +require "alchemy/resources_helper" module Alchemy module Admin @@ -53,7 +53,7 @@ def new end def show - render action: 'edit' + render action: "edit" end def edit; end @@ -80,7 +80,7 @@ def update def destroy resource_instance_variable.destroy flash_notice_for_resource_action - do_redirect_to resource_url_proxy.url_for(search_filter_params.merge(action: 'index')) + do_redirect_to resource_url_proxy.url_for(search_filter_params.merge(action: "index")) end def resource_handler @@ -106,11 +106,11 @@ def flash_notice_for_resource_action(action = params[:action]) end def is_alchemy_module? - !alchemy_module.nil? && !alchemy_module['engine_name'].nil? + !alchemy_module.nil? && !alchemy_module["engine_name"].nil? end def alchemy_module - @alchemy_module ||= module_definition_for(controller: params[:controller], action: 'index') + @alchemy_module ||= module_definition_for(controller: params[:controller], action: "index") end def load_resource @@ -166,8 +166,8 @@ def items_per_page_options end def default_sort_order - name = resource_handler.attributes.detect { |attr| attr[:name] == 'name' } - name ? 'name asc' : "#{resource_handler.attributes.first[:name]} asc" + name = resource_handler.attributes.detect { |attr| attr[:name] == "name" } + name ? "name asc" : "#{resource_handler.attributes.first[:name]} asc" end end end diff --git a/app/controllers/alchemy/admin/sites_controller.rb b/app/controllers/alchemy/admin/sites_controller.rb index 3fd772b664..be79b0dd29 100644 --- a/app/controllers/alchemy/admin/sites_controller.rb +++ b/app/controllers/alchemy/admin/sites_controller.rb @@ -6,7 +6,7 @@ class SitesController < ResourcesController def create @site = Alchemy::Site.new(resource_params) if @site.save - flash[:notice] = Alchemy.t('Please create a default language for this site.') + flash[:notice] = Alchemy.t("Please create a default language for this site.") redirect_to alchemy.admin_languages_path(site_id: @site) else render :new @@ -15,7 +15,7 @@ def create def destroy if @site.destroy - flash[:notice] = Alchemy.t('Site successfully removed') + flash[:notice] = Alchemy.t("Site successfully removed") else flash[:warning] = @site.errors.full_messages.to_sentence end diff --git a/app/controllers/alchemy/admin/tags_controller.rb b/app/controllers/alchemy/admin/tags_controller.rb index d418b7aca9..857e4f4778 100644 --- a/app/controllers/alchemy/admin/tags_controller.rb +++ b/app/controllers/alchemy/admin/tags_controller.rb @@ -21,7 +21,7 @@ def new def create @tag = Gutentag::Tag.create(tag_params) - render_errors_or_redirect @tag, admin_tags_path, Alchemy.t('New Tag Created') + render_errors_or_redirect @tag, admin_tags_path, Alchemy.t("New Tag Created") end def edit @@ -32,7 +32,7 @@ def update if tag_params[:merge_to] @new_tag = Gutentag::Tag.find(tag_params[:merge_to]) Tag.replace(@tag, @new_tag) - operation_text = Alchemy.t('Replaced Tag') % {old_tag: @tag.name, new_tag: @new_tag.name} + operation_text = Alchemy.t("Replaced Tag") % {old_tag: @tag.name, new_tag: @new_tag.name} @tag.destroy else @tag.update(tag_params) @@ -67,7 +67,7 @@ def tag_params def tags_from_term(term) return [] if term.blank? - Gutentag::Tag.where(['LOWER(name) LIKE ?', "#{term.downcase}%"]) + Gutentag::Tag.where(["LOWER(name) LIKE ?", "#{term.downcase}%"]) end def json_for_autocomplete(items, attribute) diff --git a/app/controllers/alchemy/api/base_controller.rb b/app/controllers/alchemy/api/base_controller.rb index b3e21c42f5..c79f5badcd 100644 --- a/app/controllers/alchemy/api/base_controller.rb +++ b/app/controllers/alchemy/api/base_controller.rb @@ -11,11 +11,11 @@ class Api::BaseController < Alchemy::BaseController private def render_not_authorized - render json: {error: 'Not authorized'}, status: 403 + render json: {error: "Not authorized"}, status: 403 end def render_not_found - render json: {error: 'Record not found'}, status: 404 + render json: {error: "Record not found"}, status: 404 end end end diff --git a/app/controllers/alchemy/api/contents_controller.rb b/app/controllers/alchemy/api/contents_controller.rb index 3999c34e71..c864de5fe2 100644 --- a/app/controllers/alchemy/api/contents_controller.rb +++ b/app/controllers/alchemy/api/contents_controller.rb @@ -18,7 +18,7 @@ def index end @contents = @contents.includes(*content_includes) - render json: @contents, adapter: :json, root: 'contents' + render json: @contents, adapter: :json, root: "contents" end # Returns a json object for content diff --git a/app/controllers/alchemy/api/elements_controller.rb b/app/controllers/alchemy/api/elements_controller.rb index 3d83612f8b..1ad9583065 100644 --- a/app/controllers/alchemy/api/elements_controller.rb +++ b/app/controllers/alchemy/api/elements_controller.rb @@ -22,7 +22,7 @@ def index end @elements = @elements.includes(*element_includes) - render json: @elements, adapter: :json, root: 'elements' + render json: @elements, adapter: :json, root: "elements" end # Returns a json object for element diff --git a/app/controllers/alchemy/api/pages_controller.rb b/app/controllers/alchemy/api/pages_controller.rb index 30123399cb..2b72e26d60 100644 --- a/app/controllers/alchemy/api/pages_controller.rb +++ b/app/controllers/alchemy/api/pages_controller.rb @@ -20,7 +20,7 @@ def index @pages = @pages.page(params[:page]).per(params[:per_page]) end - render json: @pages, adapter: :json, root: 'pages', meta: meta_data + render json: @pages, adapter: :json, root: "pages", meta: meta_data end # Returns all pages as nested json object for tree views diff --git a/app/controllers/alchemy/attachments_controller.rb b/app/controllers/alchemy/attachments_controller.rb index 8c00baa2a1..8841ad8a35 100644 --- a/app/controllers/alchemy/attachments_controller.rb +++ b/app/controllers/alchemy/attachments_controller.rb @@ -7,20 +7,20 @@ class AttachmentsController < BaseController # sends file inline. i.e. for viewing pdfs/movies in browser def show - response.headers['Content-Length'] = @attachment.file.size.to_s + response.headers["Content-Length"] = @attachment.file.size.to_s send_file( @attachment.file.path, { filename: @attachment.file_name, type: @attachment.file_mime_type, - disposition: 'inline', + disposition: "inline", }, ) end # sends file as attachment. aka download def download - response.headers['Content-Length'] = @attachment.file.size.to_s + response.headers["Content-Length"] = @attachment.file.size.to_s send_file( @attachment.file.path, { filename: @attachment.file_name, diff --git a/app/controllers/alchemy/base_controller.rb b/app/controllers/alchemy/base_controller.rb index 968f9d9dad..60b1eb6fd6 100644 --- a/app/controllers/alchemy/base_controller.rb +++ b/app/controllers/alchemy/base_controller.rb @@ -15,7 +15,7 @@ class BaseController < ApplicationController before_action :mailer_set_url_options before_action :set_locale - helper 'alchemy/admin/form' + helper "alchemy/admin/form" rescue_from CanCan::AccessDenied do |exception| permission_denied(exception) @@ -62,11 +62,11 @@ def permission_denied(exception = nil) end def handle_redirect_for_user - flash[:warning] = Alchemy.t('You are not authorized') + flash[:warning] = Alchemy.t("You are not authorized") if can?(:index, :alchemy_admin_dashboard) redirect_or_render_notice else - redirect_to('/') + redirect_to("/") end end @@ -77,8 +77,8 @@ def redirect_or_render_notice render plain: flash.discard(:warning), status: 403 end format.html do - render partial: 'alchemy/admin/partials/flash', - locals: {message: flash[:warning], flash_type: 'warning'} + render partial: "alchemy/admin/partials/flash", + locals: {message: flash[:warning], flash_type: "warning"} end end else @@ -87,7 +87,7 @@ def redirect_or_render_notice end def handle_redirect_for_guest - flash[:info] = Alchemy.t('Please log in') + flash[:info] = Alchemy.t("Please log in") if request.xhr? render :permission_denied else @@ -100,7 +100,7 @@ def handle_redirect_for_guest def exception_logger(error) Rails.logger.error("\n#{error.class} #{error.message} in #{error.backtrace.first}") Rails.logger.error(error.backtrace[1..50].each { |line| - line.gsub(/#{Rails.root}/, '') + line.gsub(/#{Rails.root}/, "") }.join("\n")) end end diff --git a/app/controllers/alchemy/messages_controller.rb b/app/controllers/alchemy/messages_controller.rb index e29d48e7f3..0148f29d1c 100644 --- a/app/controllers/alchemy/messages_controller.rb +++ b/app/controllers/alchemy/messages_controller.rb @@ -39,7 +39,7 @@ module Alchemy class MessagesController < Alchemy::BaseController before_action :get_page, except: :create - helper 'alchemy/pages' + helper "alchemy/pages" def index #:nodoc: redirect_to show_page_path( @@ -50,7 +50,7 @@ def index #:nodoc: def new #:nodoc: @message = Message.new - render template: 'alchemy/pages/show' + render template: "alchemy/pages/show" end def create #:nodoc: @@ -67,7 +67,7 @@ def create #:nodoc: MessagesMailer.contact_form_mail(@message, mail_to, mail_from, subject).deliver redirect_to_success_page else - render template: 'alchemy/pages/show' + render template: "alchemy/pages/show" end end @@ -78,23 +78,23 @@ def mailer_config end def mail_to - @element.ingredient(:mail_to) || mailer_config['mail_to'] + @element.ingredient(:mail_to) || mailer_config["mail_to"] end def mail_from - @element.ingredient(:mail_from) || mailer_config['mail_from'] + @element.ingredient(:mail_from) || mailer_config["mail_from"] end def subject - @element.ingredient(:subject) || mailer_config['subject'] + @element.ingredient(:subject) || mailer_config["subject"] end def redirect_to_success_page - flash[:notice] = Alchemy.t(:success, scope: 'contactform.messages') + flash[:notice] = Alchemy.t(:success, scope: "contactform.messages") if success_page urlname = success_page_urlname - elsif mailer_config['forward_to_page'] && mailer_config['mail_success_page'] - urlname = Page.find_by(urlname: mailer_config['mail_success_page']).urlname + elsif mailer_config["forward_to_page"] && mailer_config["mail_success_page"] + urlname = Page.find_by(urlname: mailer_config["mail_success_page"]).urlname else urlname = Language.current_root_page.urlname end @@ -118,16 +118,16 @@ def success_page_urlname end def get_page - @page = Language.current.pages.find_by(page_layout: mailer_config['page_layout_name']) + @page = Language.current.pages.find_by(page_layout: mailer_config["page_layout_name"]) if @page.blank? - raise "Page for page_layout #{mailer_config['page_layout_name']} not found" + raise "Page for page_layout #{mailer_config["page_layout_name"]} not found" end @root_page = @page.get_language_root end def message_params - params.require(:message).permit(*mailer_config['fields']) + params.require(:message).permit(*mailer_config["fields"]) end end end diff --git a/app/controllers/alchemy/pages_controller.rb b/app/controllers/alchemy/pages_controller.rb index fde0a2cecc..674ff91ed9 100644 --- a/app/controllers/alchemy/pages_controller.rb +++ b/app/controllers/alchemy/pages_controller.rb @@ -3,10 +3,10 @@ module Alchemy class PagesController < Alchemy::BaseController SHOW_PAGE_PARAMS_KEYS = [ - 'action', - 'controller', - 'urlname', - 'locale', + "action", + "controller", + "urlname", + "locale", ] include OnPageLayout::CallbacksRunner @@ -78,7 +78,7 @@ def show def sitemap @pages = Page.sitemap respond_to do |format| - format.xml { render layout: 'alchemy/sitemap' } + format.xml { render layout: "alchemy/sitemap" } end end @@ -95,7 +95,7 @@ def sitemap # def load_index_page @page ||= Language.current_root_page - render template: 'alchemy/welcome', layout: false if signup_required? + render template: "alchemy/welcome", layout: false if signup_required? end # == Loads page by urlname @@ -150,7 +150,7 @@ def render_page if @page.contains_feed? render action: :show, layout: false, handlers: [:builder] else - render xml: {error: 'Not found'}, status: 404 + render xml: { error: "Not found" }, status: 404 end end end @@ -193,9 +193,9 @@ def page_etag # def render_fresh_page? must_not_cache? || stale?(etag: page_etag, - last_modified: @page.published_at, - public: !@page.restricted, - template: 'pages/show') + last_modified: @page.published_at, + public: !@page.restricted, + template: "pages/show") end # don't cache pages if we have flash message to display or the page has caching disabled diff --git a/app/controllers/concerns/alchemy/admin/archive_overlay.rb b/app/controllers/concerns/alchemy/admin/archive_overlay.rb index 782228a730..6346d646d6 100644 --- a/app/controllers/concerns/alchemy/admin/archive_overlay.rb +++ b/app/controllers/concerns/alchemy/admin/archive_overlay.rb @@ -12,8 +12,8 @@ def archive_overlay @content = Content.find_by(id: params[:content_id]) respond_to do |format| - format.html { render partial: 'archive_overlay' } - format.js { render action: 'archive_overlay' } + format.html { render partial: "archive_overlay" } + format.js { render action: "archive_overlay" } end end end diff --git a/app/controllers/concerns/alchemy/admin/current_language.rb b/app/controllers/concerns/alchemy/admin/current_language.rb index 6a6a864e1a..d2bf50a6e7 100644 --- a/app/controllers/concerns/alchemy/admin/current_language.rb +++ b/app/controllers/concerns/alchemy/admin/current_language.rb @@ -14,7 +14,7 @@ module CurrentLanguage def load_current_language @current_language = Alchemy::Language.current if @current_language.nil? - flash[:warning] = Alchemy.t('Please create a language first.') + flash[:warning] = Alchemy.t("Please create a language first.") redirect_to admin_languages_path end end diff --git a/app/controllers/concerns/alchemy/legacy_page_redirects.rb b/app/controllers/concerns/alchemy/legacy_page_redirects.rb index 7f312a33a6..aa18739edf 100644 --- a/app/controllers/concerns/alchemy/legacy_page_redirects.rb +++ b/app/controllers/concerns/alchemy/legacy_page_redirects.rb @@ -42,7 +42,7 @@ def legacy_page_redirect_url def legacy_urls # /slug/tree => slug/tree - urlname = (request.fullpath[1..-1] if request.fullpath[0] == '/') || request.fullpath + urlname = (request.fullpath[1..-1] if request.fullpath[0] == "/") || request.fullpath LegacyPageUrl.joins(:page).where( urlname: urlname, Page.table_name => { diff --git a/app/controllers/concerns/alchemy/site_redirects.rb b/app/controllers/concerns/alchemy/site_redirects.rb index e0696dd7fb..059bd7a5d3 100644 --- a/app/controllers/concerns/alchemy/site_redirects.rb +++ b/app/controllers/concerns/alchemy/site_redirects.rb @@ -17,7 +17,7 @@ def enforce_primary_host_for_site def needs_redirect_to_primary_host? current_alchemy_site&.redirect_to_primary_host? && - current_alchemy_site.host != '*' && + current_alchemy_site.host != "*" && current_alchemy_site.host != request.host end end diff --git a/app/decorators/alchemy/content_editor.rb b/app/decorators/alchemy/content_editor.rb index ffb95d52e3..4d7bcf6317 100644 --- a/app/decorators/alchemy/content_editor.rb +++ b/app/decorators/alchemy/content_editor.rb @@ -10,7 +10,7 @@ def to_partial_path def css_classes [ - 'content_editor', + "content_editor", essence_partial_name, ].compact end @@ -36,11 +36,11 @@ def data_attributes # # <%= text_field_tag content_editor.form_field_name(:link), content_editor.ingredient %> # - def form_field_name(essence_column = 'ingredient') + def form_field_name(essence_column = "ingredient") "contents[#{id}][#{essence_column}]" end - def form_field_id(essence_column = 'ingredient') + def form_field_id(essence_column = "ingredient") "contents_#{id}_#{essence_column}" end diff --git a/app/decorators/alchemy/element_editor.rb b/app/decorators/alchemy/element_editor.rb index a15bbac3b2..29c9478079 100644 --- a/app/decorators/alchemy/element_editor.rb +++ b/app/decorators/alchemy/element_editor.rb @@ -11,14 +11,14 @@ def to_partial_path # CSS classes for the element editor partial. def css_classes [ - 'element-editor', - content_definitions.present? ? 'with-contents' : 'without-contents', - nestable_elements.any? ? 'nestable' : 'not-nestable', - taggable? ? 'taggable' : 'not-taggable', - folded ? 'folded' : 'expanded', - compact? ? 'compact' : nil, - fixed? ? 'is-fixed' : 'not-fixed', - ].join(' ') + "element-editor", + content_definitions.present? ? "with-contents" : "without-contents", + nestable_elements.any? ? "nestable" : "not-nestable", + taggable? ? "taggable" : "not-taggable", + folded ? "folded" : "expanded", + compact? ? "compact" : nil, + fixed? ? "is-fixed" : "not-fixed", + ].join(" ") end # Tells us, if we should show the element footer and form inputs. diff --git a/app/helpers/alchemy/admin/attachments_helper.rb b/app/helpers/alchemy/admin/attachments_helper.rb index 22bb255b39..8bc876a275 100644 --- a/app/helpers/alchemy/admin/attachments_helper.rb +++ b/app/helpers/alchemy/admin/attachments_helper.rb @@ -6,17 +6,17 @@ module AttachmentsHelper include Alchemy::Admin::BaseHelper def mime_to_human(mime) - Alchemy.t(mime, scope: 'mime_types', default: Alchemy.t(:document)) + Alchemy.t(mime, scope: "mime_types", default: Alchemy.t(:document)) end def attachment_preview_size(attachment) case attachment.icon_css_class - when 'image' then '600x475' - when 'audio' then '600x190' - when 'video' then '600x485' - when 'pdf' then '600x500' + when "image" then "600x475" + when "audio" then "600x190" + when "video" then "600x485" + when "pdf" then "600x500" else - '600x145' + "600x145" end end end diff --git a/app/helpers/alchemy/admin/base_helper.rb b/app/helpers/alchemy/admin/base_helper.rb index ced2410879..70fc19ce28 100644 --- a/app/helpers/alchemy/admin/base_helper.rb +++ b/app/helpers/alchemy/admin/base_helper.rb @@ -19,7 +19,7 @@ module BaseHelper include ::Webpacker::Helper def current_webpacker_instance - if controller_name == 'pages' && action_name == 'show' + if controller_name == "pages" && action_name == "show" super else Alchemy.webpacker @@ -34,7 +34,7 @@ def current_webpacker_instance def current_alchemy_user_name name = current_alchemy_user.try(:alchemy_display_name) if name.present? - content_tag :span, "#{Alchemy.t('Logged in as')} #{name}", class: 'current-user-name' + content_tag :span, "#{Alchemy.t("Logged in as")} #{name}", class: "current-user-name" end end @@ -66,7 +66,7 @@ def link_to_dialog(content, url, options = {}, html_options = {}) default_options = {modal: true} options = default_options.merge(options) link_to content, url, - html_options.merge('data-alchemy-dialog' => options.to_json) + html_options.merge("data-alchemy-dialog" => options.to_json) end # Used for translations selector in Alchemy cockpit user settings. @@ -110,13 +110,13 @@ def sites_for_select # def js_filter_field(items, options = {}) options = { - class: 'js_filter_field', - data: {'alchemy-list-filter' => items}, + class: "js_filter_field", + data: {"alchemy-list-filter" => items}, }.merge(options) - content_tag(:div, class: 'js_filter_field_box') do + content_tag(:div, class: "js_filter_field_box") do concat text_field_tag(nil, nil, options) concat render_icon(:search) - concat link_to(render_icon(:times, size: 'xs'), '', class: 'js_filter_field_clear', title: Alchemy.t(:click_to_show_all)) + concat link_to(render_icon(:times, size: "xs"), "", class: "js_filter_field_clear", title: Alchemy.t(:click_to_show_all)) end end @@ -147,7 +147,7 @@ def js_filter_field(items, options = {}) def link_to_confirm_dialog(link_string = "", message = "", url = "", html_options = {}) link_to(link_string, url, html_options.merge( - 'data-alchemy-confirm-delete' => { + "data-alchemy-confirm-delete" => { title: Alchemy.t(:please_confirm), message: message, ok_label: Alchemy.t("Yes"), @@ -183,8 +183,8 @@ def button_with_confirm(value = "", url = "", options = {}, html_options = {}) title: Alchemy.t(:please_confirm), cancel_label: Alchemy.t("No"), }.merge(options) - form_tag url, {method: html_options.delete(:method), class: 'button-with-confirm'} do - button_tag value, html_options.merge('data-alchemy-confirm' => options.to_json) + form_tag url, {method: html_options.delete(:method), class: "button-with-confirm"} do + button_tag value, html_options.merge("data-alchemy-confirm" => options.to_json) end end @@ -199,8 +199,8 @@ def button_with_confirm(value = "", url = "", options = {}, html_options = {}) # def delete_button(url, options = {}, html_options = {}) options = { - title: Alchemy.t('Delete'), - message: Alchemy.t('Are you sure?'), + title: Alchemy.t("Delete"), + message: Alchemy.t("Are you sure?"), icon: :minus, }.merge(options) button_with_confirm( @@ -208,7 +208,7 @@ def delete_button(url, options = {}, html_options = {}) url, { message: options[:message], }, { - method: 'delete', + method: "delete", title: options[:title], class: "icon_button #{html_options.delete(:class)}".strip, }.merge(html_options) @@ -273,7 +273,7 @@ def toolbar_button(options = {}) loading_indicator: false, }.merge(options.symbolize_keys) button = render( - 'alchemy/admin/partials/toolbar_button', + "alchemy/admin/partials/toolbar_button", options: options, ) if options[:skip_permission_check] || can?(*permission_from_options(options)) @@ -319,7 +319,7 @@ def toolbar(options = {}) content_for(:toolbar) do content = <<-CONTENT.strip_heredoc #{options[:buttons].map { |button_options| toolbar_button(button_options) }.join} - #{render('alchemy/admin/partials/search_form', url: options[:search_url]) if options[:search]} + #{render("alchemy/admin/partials/search_form", url: options[:search_url]) if options[:search]} CONTENT content.html_safe end @@ -371,7 +371,7 @@ def new_asset_path_with_session_information(asset_type) # The value the input displays. If you pass a String its parsed with +Time.parse+ # def alchemy_datepicker(object, method, html_options = {}) - type = html_options.delete(:type) || 'date' + type = html_options.delete(:type) || "date" date = html_options.delete(:value) || object.send(method.to_sym).presence date = Time.zone.parse(date) if date.is_a?(String) value = date ? date.iso8601 : nil @@ -385,9 +385,9 @@ def alchemy_datepicker(object, method, html_options = {}) def render_hint_for(element) return unless element.has_hint? - content_tag :span, class: 'hint-with-icon' do - render_icon('question-circle') + - content_tag(:span, element.hint.html_safe, class: 'hint-bubble') + content_tag :span, class: "hint-with-icon" do + render_icon("question-circle") + + content_tag(:span, element.hint.html_safe, class: "hint-bubble") end end @@ -416,7 +416,7 @@ def clipboard_select_tag_options(items) # Returns the regular expression used for external url validation in link dialog. def link_url_regexp - Alchemy::Config.get(:format_matchers)['link_url'] || /^(mailto:|\/|[a-z]+:\/\/)/ + Alchemy::Config.get(:format_matchers)["link_url"] || /^(mailto:|\/|[a-z]+:\/\/)/ end # Renders a hint with tooltip @@ -429,9 +429,9 @@ def link_url_regexp # @param icon: 'exclamation-triangle' [String] - Icon name # # @return [String] - def hint_with_tooltip(text, icon: 'exclamation-triangle') - content_tag :span, class: 'hint-with-icon' do - render_icon(icon) + content_tag(:span, text, class: 'hint-bubble') + def hint_with_tooltip(text, icon: "exclamation-triangle") + content_tag :span, class: "hint-with-icon" do + render_icon(icon) + content_tag(:span, text, class: "hint-bubble") end end @@ -454,10 +454,10 @@ def permission_from_options(options) end def permission_array_from_url(options) - action_controller = options[:url].gsub(/\A\//, '').split('/') + action_controller = options[:url].gsub(/\A\//, "").split("/") [ action_controller.last.to_sym, - action_controller[0..action_controller.length - 2].join('_').to_sym, + action_controller[0..action_controller.length - 2].join("_").to_sym, ] end end diff --git a/app/helpers/alchemy/admin/contents_helper.rb b/app/helpers/alchemy/admin/contents_helper.rb index f6c1f58950..18b4fcf214 100644 --- a/app/helpers/alchemy/admin/contents_helper.rb +++ b/app/helpers/alchemy/admin/contents_helper.rb @@ -13,7 +13,7 @@ module ContentsHelper # def render_content_name(content) if content.blank? - warning('Content is nil') + warning("Content is nil") return end @@ -39,7 +39,7 @@ def render_content_name(content) # Renders the label and a remove link for a content. def content_label(content) content_tag :label, for: content.form_field_id do - [render_hint_for(content), render_content_name(content)].compact.join(' ').html_safe + [render_hint_for(content), render_content_name(content)].compact.join(" ").html_safe end end end diff --git a/app/helpers/alchemy/admin/elements_helper.rb b/app/helpers/alchemy/admin/elements_helper.rb index 16a8b9b3d7..56d0aeec66 100644 --- a/app/helpers/alchemy/admin/elements_helper.rb +++ b/app/helpers/alchemy/admin/elements_helper.rb @@ -16,8 +16,8 @@ def elements_for_select(elements) elements.collect do |e| [ - Element.display_name_for(e['name']), - e['name'], + Element.display_name_for(e["name"]), + e["name"], ] end end diff --git a/app/helpers/alchemy/admin/essences_helper.rb b/app/helpers/alchemy/admin/essences_helper.rb index 78a3915f5e..00fefb240a 100644 --- a/app/helpers/alchemy/admin/essences_helper.rb +++ b/app/helpers/alchemy/admin/essences_helper.rb @@ -13,7 +13,7 @@ def essence_picture_thumbnail(content) image_tag( essence.thumbnail_url, alt: picture.name, - class: 'img_paddingtop', + class: "img_paddingtop", title: Alchemy.t(:image_name) + ": #{picture.name}", ) end @@ -21,9 +21,9 @@ def essence_picture_thumbnail(content) # Size value for edit picture dialog def edit_picture_dialog_size(content) if content.settings[:caption_as_textarea] - content.settings[:sizes] ? '380x320' : '380x300' + content.settings[:sizes] ? "380x320" : "380x300" else - content.settings[:sizes] ? '380x290' : '380x255' + content.settings[:sizes] ? "380x290" : "380x255" end end end diff --git a/app/helpers/alchemy/admin/form_helper.rb b/app/helpers/alchemy/admin/form_helper.rb index 34daba6aca..1a132029a2 100644 --- a/app/helpers/alchemy/admin/form_helper.rb +++ b/app/helpers/alchemy/admin/form_helper.rb @@ -19,7 +19,7 @@ def alchemy_form_for(object, *args, &block) options[:remote] = request.xhr? options[:html] = { id: options.delete(:id), - class: ["alchemy", options.delete(:class)].compact.join(' '), + class: ["alchemy", options.delete(:class)].compact.join(" "), } simple_form_for(object, *(args << options), &block) end diff --git a/app/helpers/alchemy/admin/navigation_helper.rb b/app/helpers/alchemy/admin/navigation_helper.rb index c742f0c8e2..63654d9cc3 100644 --- a/app/helpers/alchemy/admin/navigation_helper.rb +++ b/app/helpers/alchemy/admin/navigation_helper.rb @@ -12,9 +12,9 @@ module NavigationHelper # def alchemy_main_navigation_entry(alchemy_module) render( - 'alchemy/admin/partials/main_navigation_entry', + "alchemy/admin/partials/main_navigation_entry", alchemy_module: alchemy_module, - navigation: alchemy_module['navigation'], + navigation: alchemy_module["navigation"], ) end @@ -36,8 +36,8 @@ def alchemy_main_navigation_entry(alchemy_module) # def navigate_module(navigation) [ - navigation['action'].to_sym, - navigation['controller'].to_s.gsub(/\A\//, '').gsub(/\//, '_').to_sym, + navigation["action"].to_sym, + navigation["controller"].to_s.gsub(/\A\//, "").gsub(/\//, "_").to_sym, ] end @@ -45,9 +45,9 @@ def navigate_module(navigation) # def main_navigation_css_classes(navigation) [ - 'main_navi_entry', - admin_mainnavi_active?(navigation) ? 'active' : nil, - navigation.key?('sub_navigation') ? 'has_sub_navigation' : nil, + "main_navi_entry", + admin_mainnavi_active?(navigation) ? "active" : nil, + navigation.key?("sub_navigation") ? "has_sub_navigation" : nil, ].compact end @@ -74,7 +74,7 @@ def entry_active?(entry) # def url_for_module(alchemy_module) route_from_engine_or_main_app( - alchemy_module['engine_name'], + alchemy_module["engine_name"], url_options_for_module(alchemy_module), ) end @@ -93,7 +93,7 @@ def url_for_module_sub_navigation(navigation) return if alchemy_module.nil? route_from_engine_or_main_app( - alchemy_module['engine_name'], + alchemy_module["engine_name"], url_options_for_navigation_entry(navigation), ) end @@ -106,13 +106,13 @@ def sorted_alchemy_modules sorted = [] not_sorted = [] alchemy_modules.map do |m| - if m['position'].blank? + if m["position"].blank? not_sorted << m else sorted << m end end - sorted.sort_by { |m| m['position'] } + not_sorted + sorted.sort_by { |m| m["position"] } + not_sorted end private @@ -138,7 +138,7 @@ def route_from_engine_or_main_app(engine_name, url_options) # A Alchemy module definition # def url_options_for_module(alchemy_module) - url_options_for_navigation_entry(alchemy_module['navigation'] || {}) + url_options_for_navigation_entry(alchemy_module["navigation"] || {}) end # Returns a url options hash for given navigation entry. @@ -148,26 +148,26 @@ def url_options_for_module(alchemy_module) # def url_options_for_navigation_entry(entry) { - controller: entry['controller'], - action: entry['action'], + controller: entry["controller"], + action: entry["action"], only_path: true, - params: entry['params'], + params: entry["params"], }.delete_if { |_k, v| v.nil? } end # Retrieves the current Alchemy module from controller and index action. # def current_alchemy_module - module_definition_for(controller: params[:controller], action: 'index') + module_definition_for(controller: params[:controller], action: "index") end # Returns true if the current controller and action is in a modules navigation definition. # def admin_mainnavi_active?(navigation) # Has the given navigation entry a active sub navigation? - has_active_entry?(navigation['sub_navigation'] || []) || + has_active_entry?(navigation["sub_navigation"] || []) || # Has the given navigation entry a active nested navigation? - has_active_entry?(navigation['nested'] || []) || + has_active_entry?(navigation["nested"] || []) || # Is the navigation entry active? entry_active?(navigation || {}) end @@ -175,7 +175,7 @@ def admin_mainnavi_active?(navigation) # Returns true if the given entry's controller is current controller # def is_entry_controller_active?(entry) - entry['controller'].gsub(/\A\//, '') == params[:controller] + entry["controller"].gsub(/\A\//, "") == params[:controller] end # Returns true if the given entry's action is current controllers action @@ -183,8 +183,8 @@ def is_entry_controller_active?(entry) # Also checks if given entry has a +nested_actions+ key, if so it checks if one of them is current controller's action # def is_entry_action_active?(entry) - entry['action'] == params[:action] || - entry.fetch('nested_actions', []).include?(params[:action]) + entry["action"] == params[:action] || + entry.fetch("nested_actions", []).include?(params[:action]) end # Returns true if an entry of given entries is active. diff --git a/app/helpers/alchemy/admin/pages_helper.rb b/app/helpers/alchemy/admin/pages_helper.rb index 53555cea55..af2037bf3e 100644 --- a/app/helpers/alchemy/admin/pages_helper.rb +++ b/app/helpers/alchemy/admin/pages_helper.rb @@ -9,13 +9,13 @@ module PagesHelper # def preview_sizes_for_select options_for_select([ - 'auto', - [Alchemy.t('240', scope: 'preview_sizes'), 240], - [Alchemy.t('320', scope: 'preview_sizes'), 320], - [Alchemy.t('480', scope: 'preview_sizes'), 480], - [Alchemy.t('768', scope: 'preview_sizes'), 768], - [Alchemy.t('1024', scope: 'preview_sizes'), 1024], - [Alchemy.t('1280', scope: 'preview_sizes'), 1280], + "auto", + [Alchemy.t("240", scope: "preview_sizes"), 240], + [Alchemy.t("320", scope: "preview_sizes"), 320], + [Alchemy.t("480", scope: "preview_sizes"), 480], + [Alchemy.t("768", scope: "preview_sizes"), 768], + [Alchemy.t("1024", scope: "preview_sizes"), 1024], + [Alchemy.t("1280", scope: "preview_sizes"), 1280], ]) end @@ -28,7 +28,7 @@ def page_layout_label(page) [ page_layout_missing_warning, Alchemy.t(:page_type), - ].join(' ').html_safe + ].join(" ").html_safe else Alchemy.t(:page_type) end @@ -39,10 +39,10 @@ def page_status_checkbox(page, attribute) if page.attribute_fixed?(attribute) checkbox = check_box(:page, attribute, disabled: true) - hint = content_tag(:span, class: 'hint-bubble') do + hint = content_tag(:span, class: "hint-bubble") do Alchemy.t(:attribute_fixed, attribute: attribute) end - content = content_tag(:span, class: 'with-hint') do + content = content_tag(:span, class: "with-hint") do "#{checkbox}\n#{label}\n#{hint}".html_safe end else @@ -50,7 +50,7 @@ def page_status_checkbox(page, attribute) content = "#{checkbox}\n#{label}".html_safe end - content_tag(:label, class: 'checkbox') { content } + content_tag(:label, class: "checkbox") { content } end end end diff --git a/app/helpers/alchemy/admin/pictures_helper.rb b/app/helpers/alchemy/admin/pictures_helper.rb index 0cf9ab0ec4..a920f17ecc 100644 --- a/app/helpers/alchemy/admin/pictures_helper.rb +++ b/app/helpers/alchemy/admin/pictures_helper.rb @@ -5,10 +5,10 @@ module Admin module PicturesHelper def preview_size(size) case size - when 'small' then '80x60' - when 'large' then '240x180' + when "small" then "80x60" + when "large" then "240x180" else - '160x120' + "160x120" end end end diff --git a/app/helpers/alchemy/admin/tags_helper.rb b/app/helpers/alchemy/admin/tags_helper.rb index 95d6628ae9..05212f15f0 100644 --- a/app/helpers/alchemy/admin/tags_helper.rb +++ b/app/helpers/alchemy/admin/tags_helper.rb @@ -12,10 +12,10 @@ module TagsHelper # A HTML string containing <tt><li></tt> tags # def render_tag_list(class_name) - raise ArgumentError, 'Please provide a String as class_name' if class_name.nil? + raise ArgumentError, "Please provide a String as class_name" if class_name.nil? sorted_tags_from(class_name: class_name).map do |tag| - content_tag('li', name: tag.name, class: filtered_by_tag?(tag) ? 'active' : nil) do + content_tag("li", name: tag.name, class: filtered_by_tag?(tag) ? "active" : nil) do link_to( "#{tag.name} (#{tag.taggings_count})", url_for( @@ -44,13 +44,13 @@ def tags_for_filter(current:) tags_from_params - Array(current.name) else tags_from_params.push(current.name) - end.uniq.join(',') + end.uniq.join(",") end # Returns tags from params # @returns [Array] def tags_from_params - search_filter_params[:tagged_with].to_s.split(',') + search_filter_params[:tagged_with].to_s.split(",") end def sorted_tags_from(class_name:) diff --git a/app/helpers/alchemy/base_helper.rb b/app/helpers/alchemy/base_helper.rb index a944096cc4..76b9826326 100644 --- a/app/helpers/alchemy/base_helper.rb +++ b/app/helpers/alchemy/base_helper.rb @@ -27,7 +27,7 @@ def warning(message, text = nil) # # @return [String] def render_icon(icon_class, options = {}) - options = {style: 'solid'}.merge(options) + options = {style: "solid"}.merge(options) classes = [ "icon fa-fw", "fa-#{icon_class}", @@ -36,7 +36,7 @@ def render_icon(icon_class, options = {}) options[:transform] ? "fa-#{options[:transform]}" : nil, options[:class], ].compact - content_tag('i', nil, class: classes) + content_tag("i", nil, class: classes) end # Returns a div with an icon and the passed content @@ -64,7 +64,7 @@ def render_message(type = :info, msg = nil, &blk) # @param [Symbol] style The style of this flash. Valid values are +:notice+ (default), +:warn+ and +:error+ # def render_flash_notice(notice, style = :notice) - render('alchemy/admin/partials/flash', flash_type: style, message: notice) + render("alchemy/admin/partials/flash", flash_type: style, message: notice) end # Checks if the given argument is a String or a Page object. @@ -93,9 +93,9 @@ def page_or_find(page) # @return [String] The FontAwesome icon name def message_icon_class(message_type) case message_type.to_s - when 'warning', 'warn', 'alert' then 'exclamation' - when 'notice' then 'check' - when 'error' then 'bug' + when "warning", "warn", "alert" then "exclamation" + when "notice" then "check" + when "error" then "bug" else message_type end diff --git a/app/helpers/alchemy/elements_helper.rb b/app/helpers/alchemy/elements_helper.rb index ed66342772..c6088c0e4a 100644 --- a/app/helpers/alchemy/elements_helper.rb +++ b/app/helpers/alchemy/elements_helper.rb @@ -91,7 +91,7 @@ module ElementsHelper def render_elements(options = {}) options = { from_page: @page, - render_format: 'html', + render_format: "html", }.update(options) finder = options[:finder] || Alchemy::ElementsFinder.new(options) @@ -150,8 +150,8 @@ def render_elements(options = {}) # def render_element(element, options = {}, counter = 1) if element.nil? - warning('Element is nil') - render "alchemy/elements/view_not_found", {name: 'nil'} + warning("Element is nil") + render "alchemy/elements/view_not_found", {name: "nil"} return end @@ -191,7 +191,7 @@ def element_preview_code(element) def element_preview_code_attributes(element) return {} unless element.present? && @preview_mode && element.page == @page - { 'data-alchemy-element' => element.id } + { "data-alchemy-element" => element.id } end # Returns the element's tags information as a string. Parameters and options @@ -224,12 +224,12 @@ def element_tags(element, options = {}) # def element_tags_attributes(element, options = {}) options = { - formatter: lambda { |tags| tags.join(' ') }, + formatter: lambda { |tags| tags.join(" ") }, }.merge(options) return {} if !element.taggable? || element.tag_list.blank? - { 'data-element-tags' => options[:formatter].call(element.tag_list) } + { "data-element-tags" => options[:formatter].call(element.tag_list) } end end end diff --git a/app/helpers/alchemy/pages_helper.rb b/app/helpers/alchemy/pages_helper.rb index c2646da0f5..eaea9bf733 100644 --- a/app/helpers/alchemy/pages_helper.rb +++ b/app/helpers/alchemy/pages_helper.rb @@ -25,12 +25,12 @@ def picture_essence_caption(content) # def language_links(options = {}) options = { - linkname: 'name', + linkname: "name", show_title: true, - spacer: '', + spacer: "", reverse: false, }.merge(options) - languages = Language.on_current_site.published.with_root_page.order("name #{options[:reverse] ? 'DESC' : 'ASC'}") + languages = Language.on_current_site.published.with_root_page.order("name #{options[:reverse] ? "DESC" : "ASC"}") return nil if languages.count < 2 render( @@ -51,7 +51,7 @@ def render_page_layout render @page, page: @page rescue ActionView::MissingTemplate warning("PageLayout: '#{@page.page_layout}' not found. Rendering standard page_layout.") - render 'alchemy/page_layouts/standard', page: @page + render "alchemy/page_layouts/standard", page: @page end # Renders a partial for current site @@ -136,7 +136,7 @@ def render_breadcrumb(options = {}) end if options.delete(:reverse) - pages = pages.reorder('lft DESC') + pages = pages.reorder("lft DESC") end if options[:without].present? @@ -144,7 +144,7 @@ def render_breadcrumb(options = {}) pages = pages.where.not(id: without.try(:collect, &:id) || without.id) end - render 'alchemy/breadcrumb/wrapper', pages: pages, options: options + render "alchemy/breadcrumb/wrapper", pages: pages, options: options end # Returns current page title @@ -181,7 +181,7 @@ def meta_keywords end def meta_robots - "#{@page.robot_index? ? '' : 'no'}index, #{@page.robot_follow? ? '' : 'no'}follow" + "#{@page.robot_index? ? "" : "no"}index, #{@page.robot_follow? ? "" : "no"}follow" end end end diff --git a/app/helpers/alchemy/url_helper.rb b/app/helpers/alchemy/url_helper.rb index 0ce6846d80..a628ac6ecd 100644 --- a/app/helpers/alchemy/url_helper.rb +++ b/app/helpers/alchemy/url_helper.rb @@ -18,7 +18,7 @@ def show_alchemy_page_url(page, optional_params = {}) # Returns the correct params-hash for passing to show_page_path def show_page_path_params(page, optional_params = {}) - raise ArgumentError, 'Page is nil' if page.nil? + raise ArgumentError, "Page is nil" if page.nil? url_params = {urlname: page.urlname}.update(optional_params) prefix_locale? ? url_params.update(locale: page.language_code) : url_params diff --git a/app/mailers/alchemy/base_mailer.rb b/app/mailers/alchemy/base_mailer.rb index 7a72340240..ff69598fdc 100644 --- a/app/mailers/alchemy/base_mailer.rb +++ b/app/mailers/alchemy/base_mailer.rb @@ -2,7 +2,7 @@ module Alchemy begin - base_class = Object.const_get('::ApplicationMailer') + base_class = Object.const_get("::ApplicationMailer") rescue NameError base_class = ActionMailer::Base end diff --git a/app/models/alchemy/attachment.rb b/app/models/alchemy/attachment.rb index b16e8d91ae..46baca41f5 100644 --- a/app/models/alchemy/attachment.rb +++ b/app/models/alchemy/attachment.rb @@ -30,7 +30,7 @@ class Attachment < BaseRecord stampable stamper_class_name: Alchemy.user_class_name - has_many :essence_files, class_name: 'Alchemy::EssenceFile', foreign_key: 'attachment_id' + has_many :essence_files, class_name: "Alchemy::EssenceFile", foreign_key: "attachment_id" has_many :contents, through: :essence_files has_many :elements, through: :contents has_many :pages, through: :elements @@ -42,24 +42,24 @@ def searchable_alchemy_resource_attributes end def allowed_filetypes - Config.get(:uploader).fetch('allowed_filetypes', {}).fetch('alchemy/attachments', []) + Config.get(:uploader).fetch("allowed_filetypes", {}).fetch("alchemy/attachments", []) end def file_types_for_select file_types = Alchemy::Attachment.pluck(:file_mime_type).uniq.map do |type| - [Alchemy.t(type, scope: 'mime_types'), type] + [Alchemy.t(type, scope: "mime_types"), type] end file_types.sort_by(&:first) end end validates_presence_of :file - validates_size_of :file, maximum: Config.get(:uploader)['file_size_limit'].megabytes + validates_size_of :file, maximum: Config.get(:uploader)["file_size_limit"].megabytes validates_property :ext, of: :file, in: allowed_filetypes, case_sensitive: false, message: Alchemy.t("not a valid file"), - unless: -> { self.class.allowed_filetypes.include?('*') } + unless: -> { self.class.allowed_filetypes.include?("*") } before_save :set_name, if: :file_name_changed? @@ -71,13 +71,13 @@ def to_jq_upload { "name" => read_attribute(:file_name), "size" => read_attribute(:file_size), - 'error' => errors[:file].join, + "error" => errors[:file].join, } end # An url save filename without format suffix def urlname - CGI.escape(file_name.gsub(/\.#{extension}$/, '').tr('.', ' ')) + CGI.escape(file_name.gsub(/\.#{extension}$/, "").tr(".", " ")) end # Checks if the attachment is restricted, because it is attached on restricted pages only diff --git a/app/models/alchemy/base_record.rb b/app/models/alchemy/base_record.rb index 3a023c6460..5ad801a1fc 100644 --- a/app/models/alchemy/base_record.rb +++ b/app/models/alchemy/base_record.rb @@ -1,14 +1,14 @@ # frozen_string_literal: true module Alchemy def self.table_name_prefix - 'alchemy_' + "alchemy_" end class BaseRecord < ActiveRecord::Base self.abstract_class = true def active_record_5_1? - ActiveRecord.gem_version >= Gem::Version.new('5.1.0') + ActiveRecord.gem_version >= Gem::Version.new("5.1.0") end end end diff --git a/app/models/alchemy/content.rb b/app/models/alchemy/content.rb index 296e07c912..4b973aec48 100644 --- a/app/models/alchemy/content.rb +++ b/app/models/alchemy/content.rb @@ -174,12 +174,12 @@ def essence_validation_failed? end def has_validations? - definition['validate'].present? + definition["validate"].present? end # Returns a string used as dom id on html elements. def dom_id - return '' if essence.nil? + return "" if essence.nil? "#{essence_partial_name}_#{id}" end @@ -195,7 +195,7 @@ def linked? # Returns true if this content should be taken for element preview. def preview_content? - !!definition['as_element_title'] + !!definition["as_element_title"] end # Proxy method that returns the preview text from essence. @@ -205,7 +205,7 @@ def preview_text(maxlength = 30) end def essence_partial_name - return '' if essence.nil? + return "" if essence.nil? essence.partial_name end diff --git a/app/models/alchemy/content/factory.rb b/app/models/alchemy/content/factory.rb index 0369df0dae..44c197125a 100644 --- a/app/models/alchemy/content/factory.rb +++ b/app/models/alchemy/content/factory.rb @@ -71,7 +71,7 @@ def copy(source, differences = {}) # Returns all content definitions from elements.yml # def definitions - definitions = Element.definitions.flat_map { |e| e['contents'] } + definitions = Element.definitions.flat_map { |e| e["contents"] } definitions.compact! definitions end @@ -139,7 +139,7 @@ def create_essence!(type = nil) # If an optional type is passed, this type of essence gets constantized. # def essence_class(type = nil) - Content.normalize_essence_type(type || definition['type']).constantize + Content.normalize_essence_type(type || definition["type"]).constantize end end end diff --git a/app/models/alchemy/element/definitions.rb b/app/models/alchemy/element/definitions.rb index ed42ab42a2..6bea4c26a0 100644 --- a/app/models/alchemy/element/definitions.rb +++ b/app/models/alchemy/element/definitions.rb @@ -19,7 +19,7 @@ def definitions # Returns one element definition by given name. # def definition_by_name(name) - definitions.detect { |d| d['name'] == name } + definitions.detect { |d| d["name"] == name } end private @@ -37,14 +37,14 @@ def read_definitions_file # Returns the +elements.yml+ file path # def definitions_file_path - Rails.root.join 'config/alchemy/elements.yml' + Rails.root.join "config/alchemy/elements.yml" end end # The definition of this element. # def definition - if definition = self.class.definitions.detect { |d| d['name'] == name } + if definition = self.class.definitions.detect { |d| d["name"] == name } definition else log_warning "Could not find element definition for #{name}. Please check your elements.yml file!" diff --git a/app/models/alchemy/element/element_contents.rb b/app/models/alchemy/element/element_contents.rb index 254b941740..6175097b5a 100644 --- a/app/models/alchemy/element/element_contents.rb +++ b/app/models/alchemy/element/element_contents.rb @@ -73,7 +73,7 @@ def copy_contents_to(element) # rss_title: true # def content_for_rss_title - content_for_rss_meta('title') + content_for_rss_meta("title") end # Returns the content that is marked as rss description. @@ -87,14 +87,14 @@ def content_for_rss_title # rss_description: true # def content_for_rss_description - content_for_rss_meta('description') + content_for_rss_meta("description") end # Returns the array with the hashes for all element contents in the elements.yml file def content_definitions return nil if definition.blank? - definition['contents'] + definition["contents"] end # Returns the definition for given content_name @@ -103,7 +103,7 @@ def content_definition_for(content_name) log_warning "Element #{name} is missing the content definition for #{content_name}" nil else - content_definitions.detect { |d| d['name'] == content_name.to_s } + content_definitions.detect { |d| d["name"] == content_name.to_s } end end @@ -139,12 +139,12 @@ def content_for_rss_meta(type) definition = content_definitions.detect { |c| c["rss_#{type}"] } return if definition.blank? - contents.detect { |content| content.name == definition['name'] } + contents.detect { |content| content.name == definition["name"] } end # creates the contents for this element as described in the elements.yml def create_contents - definition.fetch('contents', []).each do |attributes| + definition.fetch("contents", []).each do |attributes| Content.create(attributes.merge(element: self)) end end diff --git a/app/models/alchemy/element/element_essences.rb b/app/models/alchemy/element/element_essences.rb index 86dd423531..e94237a8dc 100644 --- a/app/models/alchemy/element/element_essences.rb +++ b/app/models/alchemy/element/element_essences.rb @@ -97,7 +97,7 @@ def essence_error_messages errors.each do |error| messages << Alchemy.t( "#{name}.#{content_name}.#{error}", - scope: 'content_validations', + scope: "content_validations", default: [ "fields.#{content_name}.#{error}".to_sym, "errors.#{error}".to_sym, diff --git a/app/models/alchemy/element/presenters.rb b/app/models/alchemy/element/presenters.rb index 2f08573ef1..2feb754185 100644 --- a/app/models/alchemy/element/presenters.rb +++ b/app/models/alchemy/element/presenters.rb @@ -23,7 +23,7 @@ module ClassMethods # If no translation is found a humanized name is used. # def display_name_for(name) - Alchemy.t(name, scope: 'element_names', default: name.to_s.humanize) + Alchemy.t(name, scope: "element_names", default: name.to_s.humanize) end end @@ -32,7 +32,7 @@ def display_name_for(name) # @see Alchemy::Element::Presenters#display_name_for # def display_name - self.class.display_name_for(definition['name'] || name) + self.class.display_name_for(definition["name"] || name) end # Returns a preview text for element. diff --git a/app/models/alchemy/element_to_page.rb b/app/models/alchemy/element_to_page.rb index f48f6d79ef..4fe35ffb56 100644 --- a/app/models/alchemy/element_to_page.rb +++ b/app/models/alchemy/element_to_page.rb @@ -3,7 +3,7 @@ module Alchemy class ElementToPage def self.table_name - [Alchemy::Element.table_name, Alchemy::Page.table_name].join('_') + [Alchemy::Element.table_name, Alchemy::Page.table_name].join("_") end end end diff --git a/app/models/alchemy/essence_boolean.rb b/app/models/alchemy/essence_boolean.rb index b943e4f67a..fbbdc97fd2 100644 --- a/app/models/alchemy/essence_boolean.rb +++ b/app/models/alchemy/essence_boolean.rb @@ -16,6 +16,6 @@ # Provides a checkbox in the editor views. module Alchemy class EssenceBoolean < BaseRecord - acts_as_essence ingredient_column: 'value' + acts_as_essence ingredient_column: "value" end end diff --git a/app/models/alchemy/essence_date.rb b/app/models/alchemy/essence_date.rb index 8b4bfa8534..a79da66fd9 100644 --- a/app/models/alchemy/essence_date.rb +++ b/app/models/alchemy/essence_date.rb @@ -14,7 +14,7 @@ module Alchemy class EssenceDate < BaseRecord - acts_as_essence ingredient_column: 'date' + acts_as_essence ingredient_column: "date" # Returns self.date for the Element#preview_text method. def preview_text(_maxlength = nil) diff --git a/app/models/alchemy/essence_file.rb b/app/models/alchemy/essence_file.rb index 54205556dd..0f45190d38 100644 --- a/app/models/alchemy/essence_file.rb +++ b/app/models/alchemy/essence_file.rb @@ -18,7 +18,7 @@ module Alchemy class EssenceFile < BaseRecord belongs_to :attachment, optional: true - acts_as_essence ingredient_column: 'attachment' + acts_as_essence ingredient_column: "attachment" def attachment_url return if attachment.nil? diff --git a/app/models/alchemy/essence_html.rb b/app/models/alchemy/essence_html.rb index bb8b5bc7bc..b4a3c823da 100644 --- a/app/models/alchemy/essence_html.rb +++ b/app/models/alchemy/essence_html.rb @@ -14,7 +14,7 @@ module Alchemy class EssenceHtml < BaseRecord - acts_as_essence ingredient_column: 'source' + acts_as_essence ingredient_column: "source" # Returns the first x (default = 30) (HTML escaped) characters from self.source for the Element#preview_text method. def preview_text(maxlength = 30) diff --git a/app/models/alchemy/essence_link.rb b/app/models/alchemy/essence_link.rb index 6b0f0a5491..8959cd7c22 100644 --- a/app/models/alchemy/essence_link.rb +++ b/app/models/alchemy/essence_link.rb @@ -17,6 +17,6 @@ module Alchemy class EssenceLink < BaseRecord - acts_as_essence ingredient_column: 'link' + acts_as_essence ingredient_column: "link" end end diff --git a/app/models/alchemy/essence_page.rb b/app/models/alchemy/essence_page.rb index eecb7e4944..301364165b 100644 --- a/app/models/alchemy/essence_page.rb +++ b/app/models/alchemy/essence_page.rb @@ -8,7 +8,7 @@ class EssencePage < BaseRecord ingredient_column: :page, preview_text_method: :name, belongs_to: { - class_name: 'Alchemy::Page', + class_name: "Alchemy::Page", foreign_key: :page_id, inverse_of: :essence_pages, optional: true, diff --git a/app/models/alchemy/essence_picture.rb b/app/models/alchemy/essence_picture.rb index 5212c25cf1..736d22441a 100644 --- a/app/models/alchemy/essence_picture.rb +++ b/app/models/alchemy/essence_picture.rb @@ -26,7 +26,7 @@ module Alchemy class EssencePicture < BaseRecord acts_as_essence ingredient_column: :picture, belongs_to: { - class_name: 'Alchemy::Picture', + class_name: "Alchemy::Picture", foreign_key: :picture_id, inverse_of: :essence_pictures, optional: true, @@ -163,7 +163,7 @@ def fix_crop_values end def normalize_crop_value(crop_value) - self[crop_value].split('x').map { |n| normalize_number(n) }.join('x') + self[crop_value].split("x").map { |n| normalize_number(n) }.join("x") end def normalize_number(number) diff --git a/app/models/alchemy/essence_picture_view.rb b/app/models/alchemy/essence_picture_view.rb index 2a67b3edeb..6465f4ebb0 100644 --- a/app/models/alchemy/essence_picture_view.rb +++ b/app/models/alchemy/essence_picture_view.rb @@ -33,12 +33,12 @@ def render output = link_to(output, url_for(essence.link), { title: essence.link_title.presence, target: essence.link_target == "blank" ? "_blank" : nil, - data: {link_target: essence.link_target.presence}, + data: { link_target: essence.link_target.presence }, }) end if caption - content_tag(:figure, output, {class: essence.css_class.presence}.merge(html_options)) + content_tag(:figure, output, { class: essence.css_class.presence }.merge(html_options)) else output end @@ -58,8 +58,8 @@ def img_tag alt: essence.alt_tag.presence, title: essence.title.presence, class: caption ? nil : essence.css_class.presence, - srcset: srcset.join(', ').presence, - sizes: options[:sizes].join(', ').presence, + srcset: srcset.join(", ").presence, + sizes: options[:sizes].join(", ").presence, }.merge(caption ? {} : html_options) ) end @@ -75,7 +75,7 @@ def is_linked? def srcset options[:srcset].map do |size| url = essence.picture_url(size: size) - width, height = size.split('x') + width, height = size.split("x") width.present? ? "#{url} #{width}w" : "#{url} #{height}h" end end diff --git a/app/models/alchemy/essence_richtext.rb b/app/models/alchemy/essence_richtext.rb index 8c545d76c8..44093acc35 100644 --- a/app/models/alchemy/essence_richtext.rb +++ b/app/models/alchemy/essence_richtext.rb @@ -16,7 +16,7 @@ module Alchemy class EssenceRichtext < BaseRecord - acts_as_essence preview_text_column: 'stripped_body' + acts_as_essence preview_text_column: "stripped_body" before_save :strip_content diff --git a/app/models/alchemy/essence_select.rb b/app/models/alchemy/essence_select.rb index b9e2865fbe..ced0384e95 100644 --- a/app/models/alchemy/essence_select.rb +++ b/app/models/alchemy/essence_select.rb @@ -15,6 +15,6 @@ # Provides a select box that stores string values. module Alchemy class EssenceSelect < BaseRecord - acts_as_essence ingredient_column: 'value' + acts_as_essence ingredient_column: "value" end end diff --git a/app/models/alchemy/language.rb b/app/models/alchemy/language.rb index 3770f1c2c0..eb6235c0ac 100644 --- a/app/models/alchemy/language.rb +++ b/app/models/alchemy/language.rb @@ -20,7 +20,7 @@ # locale :string # -require_dependency 'alchemy/site' +require_dependency "alchemy/site" module Alchemy class Language < BaseRecord @@ -122,7 +122,7 @@ def layout_root_page # def matching_locales @_matching_locales ||= ::I18n.available_locales.select do |locale| - locale.to_s.split('-')[0] == language_code + locale.to_s.split("-")[0] == language_code end end diff --git a/app/models/alchemy/language/code.rb b/app/models/alchemy/language/code.rb index aafbee1cc4..78d257315e 100644 --- a/app/models/alchemy/language/code.rb +++ b/app/models/alchemy/language/code.rb @@ -4,7 +4,7 @@ module Alchemy::Language::Code extend ActiveSupport::Concern def code - [language_code, country_code].select(&:present?).join('-') + [language_code, country_code].select(&:present?).join("-") end def code=(code) @@ -13,8 +13,8 @@ def code=(code) module ClassMethods def find_by_code(code) - codes = code.split('-') - codes << '' if codes.length == 1 + codes = code.split("-") + codes << "" if codes.length == 1 on_current_site.find_by( language_code: codes[0], country_code: codes[1], diff --git a/app/models/alchemy/legacy_page_url.rb b/app/models/alchemy/legacy_page_url.rb index 5e24960d0b..f733105e28 100644 --- a/app/models/alchemy/legacy_page_url.rb +++ b/app/models/alchemy/legacy_page_url.rb @@ -13,7 +13,7 @@ class Alchemy::LegacyPageUrl < ActiveRecord::Base belongs_to :page, - class_name: 'Alchemy::Page', + class_name: "Alchemy::Page", required: true validates :urlname, diff --git a/app/models/alchemy/message.rb b/app/models/alchemy/message.rb index e1c5fea234..64326e07c5 100644 --- a/app/models/alchemy/message.rb +++ b/app/models/alchemy/message.rb @@ -22,17 +22,17 @@ def self.config attr_accessor :contact_form_id, :ip - config['fields'].each do |field| + config["fields"].each do |field| attr_accessor field.to_sym end - config['validate_fields'].each do |field| + config["validate_fields"].each do |field| validates_presence_of field case field.to_sym when /email/ validates_format_of field, - with: Alchemy::Config.get('format_matchers')['email'], + with: Alchemy::Config.get("format_matchers")["email"], if: -> { send(field).present? } when :email_confirmation validates_confirmation_of :email diff --git a/app/models/alchemy/node.rb b/app/models/alchemy/node.rb index 8ef38f8ed2..c4a120b9a2 100644 --- a/app/models/alchemy/node.rb +++ b/app/models/alchemy/node.rb @@ -4,12 +4,12 @@ module Alchemy class Node < BaseRecord VALID_URL_REGEX = /\A(\/|\D[a-z\+\d\.\-]+:)/ - acts_as_nested_set scope: 'language_id', touch: true + acts_as_nested_set scope: "language_id", touch: true stampable stamper_class_name: Alchemy.user_class_name - belongs_to :site, class_name: 'Alchemy::Site' - belongs_to :language, class_name: 'Alchemy::Language' - belongs_to :page, class_name: 'Alchemy::Page', optional: true, inverse_of: :nodes + belongs_to :site, class_name: "Alchemy::Site" + belongs_to :language, class_name: "Alchemy::Language" + belongs_to :page, class_name: "Alchemy::Page", optional: true, inverse_of: :nodes has_many :essence_nodes, class_name: "Alchemy::Node", inverse_of: :node @@ -27,7 +27,7 @@ def name class << self # Returns all root nodes for current language def language_root_nodes - raise 'No language found' if Language.current.nil? + raise "No language found" if Language.current.nil? roots.where(language_id: Language.current.id) end @@ -51,7 +51,7 @@ def read_definitions_file # Returns the +menus.yml+ file path # def definitions_file_path - Rails.root.join 'config/alchemy/menus.yml' + Rails.root.join "config/alchemy/menus.yml" end end diff --git a/app/models/alchemy/page/fixed_attributes.rb b/app/models/alchemy/page/fixed_attributes.rb index 9a91116d92..4ee8409e89 100644 --- a/app/models/alchemy/page/fixed_attributes.rb +++ b/app/models/alchemy/page/fixed_attributes.rb @@ -31,7 +31,7 @@ def initialize(page) # @return Hash # def attributes - @_attributes ||= page.definition.fetch('fixed_attributes', {}).symbolize_keys + @_attributes ||= page.definition.fetch("fixed_attributes", {}).symbolize_keys end alias_method :all, :attributes diff --git a/app/models/alchemy/page/page_elements.rb b/app/models/alchemy/page/page_elements.rb index 848d0f2679..310878f6c1 100644 --- a/app/models/alchemy/page/page_elements.rb +++ b/app/models/alchemy/page/page_elements.rb @@ -9,27 +9,27 @@ module Page::PageElements has_many :all_elements, -> { order(:position) }, - class_name: 'Alchemy::Element', + class_name: "Alchemy::Element", inverse_of: :page has_many :elements, -> { order(:position).not_nested.unfixed.available }, - class_name: 'Alchemy::Element', + class_name: "Alchemy::Element", inverse_of: :page has_many :trashed_elements, -> { Element.trashed.order(:position) }, - class_name: 'Alchemy::Element', + class_name: "Alchemy::Element", inverse_of: :page has_many :fixed_elements, -> { order(:position).fixed.available }, - class_name: 'Alchemy::Element', + class_name: "Alchemy::Element", inverse_of: :page has_many :dependent_destroyable_elements, -> { not_nested }, - class_name: 'Alchemy::Element', + class_name: "Alchemy::Element", dependent: :destroy has_many :contents, through: :elements has_and_belongs_to_many :to_be_swept_elements, -> { distinct }, - class_name: 'Alchemy::Element', + class_name: "Alchemy::Element", join_table: ElementToPage.table_name after_create :generate_elements, @@ -82,7 +82,7 @@ def copy_elements(source, target) def available_element_definitions(only_element_named = nil) @_element_definitions ||= if only_element_named definition = Element.definition_by_name(only_element_named) - element_definitions_by_name(definition['nestable_elements']) + element_definitions_by_name(definition["nestable_elements"]) else element_definitions end @@ -100,7 +100,7 @@ def available_element_definitions(only_element_named = nil) # All names of elements that can actually be placed on current page. # def available_element_names - @_available_element_names ||= available_element_definitions.map { |e| e['name'] } + @_available_element_names ||= available_element_definitions.map { |e| e["name"] } end # Available element definitions excluding nested unique elements. @@ -109,7 +109,7 @@ def available_elements_within_current_scope(parent) @_available_elements = if parent parents_unique_nested_elements = parent.nested_elements.where(unique: true).pluck(:name) available_element_definitions(parent.name).reject do |e| - parents_unique_nested_elements.include? e['name'] + parents_unique_nested_elements.include? e["name"] end else available_element_definitions @@ -129,10 +129,10 @@ def element_definitions # def descendent_element_definitions definitions = element_definitions_by_name(element_definition_names) - definitions.select { |d| d.key?('nestable_elements') }.each do |d| - definitions += element_definitions_by_name(d['nestable_elements']) + definitions.select { |d| d.key?("nestable_elements") }.each do |d| + definitions += element_definitions_by_name(d["nestable_elements"]) end - definitions.uniq { |d| d['name'] } + definitions.uniq { |d| d["name"] } end # All names of elements that are defined in the page definition. @@ -145,7 +145,7 @@ def descendent_element_definitions # elements: [headline, contactform] # def element_definition_names - definition['elements'] || [] + definition["elements"] || [] end # Element definitions with given name(s) @@ -161,7 +161,7 @@ def element_definitions_by_name(names) if names.to_s == "all" Element.definitions else - Element.definitions.select { |e| names.include? e['name'] } + Element.definitions.select { |e| names.include? e["name"] } end end @@ -174,7 +174,7 @@ def element_definitions_by_name(names) # feed_elements: [element_name, element_2_name] # def feed_elements - elements.named(definition['feed_elements']) + elements.named(definition["feed_elements"]) end # Returns an array of all EssenceRichtext contents ids from not folded elements @@ -195,7 +195,7 @@ def richtext_contents_ids def generate_elements existing_elements = all_elements.not_nested.not_trashed existing_element_names = existing_elements.pluck(:name).uniq - definition.fetch('autogenerate', []).each do |element_name| + definition.fetch("autogenerate", []).each do |element_name| next if existing_element_names.include?(element_name) Element.create(page: self, name: element_name) @@ -223,7 +223,7 @@ def has_page_layout_changed? # def delete_unique_element_definitions! @_element_definitions.delete_if do |element| - element['unique'] && @_existing_element_names.include?(element['name']) + element["unique"] && @_existing_element_names.include?(element["name"]) end end @@ -231,8 +231,8 @@ def delete_unique_element_definitions! # def delete_outnumbered_element_definitions! @_element_definitions.delete_if do |element| - outnumbered = @_existing_element_names.select { |name| name == element['name'] } - element['amount'] && outnumbered.count >= element['amount'].to_i + outnumbered = @_existing_element_names.select { |name| name == element["name"] } + element["amount"] && outnumbered.count >= element["amount"].to_i end end end diff --git a/app/models/alchemy/page/page_naming.rb b/app/models/alchemy/page/page_naming.rb index dd55a5668f..729ad4ee77 100644 --- a/app/models/alchemy/page/page_naming.rb +++ b/app/models/alchemy/page/page_naming.rb @@ -46,7 +46,7 @@ def update_urlname! # Returns always the last part of a urlname path def slug - urlname.to_s.split('/').last + urlname.to_s.split("/").last end # Returns an array of visible/non-language_root ancestors. @@ -103,14 +103,14 @@ def set_title def convert_url_name(value) url_name = convert_to_urlname(value.blank? ? name : value) if url_name.length < 3 - ('-' * (3 - url_name.length)) + url_name + ("-" * (3 - url_name.length)) + url_name else url_name end end def nested_url_name(value) - (ancestor_slugs << convert_url_name(value)).join('/') + (ancestor_slugs << convert_url_name(value)).join("/") end # Slugs of all visible/non-language_root ancestors. diff --git a/app/models/alchemy/page/page_natures.rb b/app/models/alchemy/page/page_natures.rb index 19fcebd730..60f6390515 100644 --- a/app/models/alchemy/page/page_natures.rb +++ b/app/models/alchemy/page/page_natures.rb @@ -14,7 +14,7 @@ def expiration_time end def taggable? - definition['taggable'] == true + definition["taggable"] == true end def rootpage? @@ -95,7 +95,7 @@ def definition # Page layout names are defined inside the config/alchemy/page_layouts.yml file. # Translate the name in your config/locales language yml file. def layout_display_name - Alchemy.t(page_layout, scope: 'page_layout_names') + Alchemy.t(page_layout, scope: "page_layout_names") end # Returns the name for the layout partial @@ -155,7 +155,7 @@ def cache_page? return false unless caching_enabled? page_layout = PageLayout.get(self.page_layout) - page_layout['cache'] != false && page_layout['searchresults'] != true + page_layout["cache"] != false && page_layout["searchresults"] != true end private diff --git a/app/models/alchemy/page/page_scopes.rb b/app/models/alchemy/page/page_scopes.rb index ae11093ab4..d4ffe48e2e 100644 --- a/app/models/alchemy/page/page_scopes.rb +++ b/app/models/alchemy/page/page_scopes.rb @@ -54,7 +54,7 @@ module Page::PageScopes # Last 5 pages that where recently edited by given user # scope :all_last_edited_from, ->(user) { - where(updater_id: user.id).order('updated_at DESC').limit(5) + where(updater_id: user.id).order("updated_at DESC").limit(5) } # Returns all pages that have the given +language_id+ diff --git a/app/models/alchemy/picture.rb b/app/models/alchemy/picture.rb index ff8b5c6d4d..ce3bedf6ad 100644 --- a/app/models/alchemy/picture.rb +++ b/app/models/alchemy/picture.rb @@ -31,8 +31,8 @@ class Picture < BaseRecord include Alchemy::Picture::Url has_many :essence_pictures, - class_name: 'Alchemy::EssencePicture', - foreign_key: 'picture_id', + class_name: "Alchemy::EssencePicture", + foreign_key: "picture_id", inverse_of: :ingredient_association has_many :contents, through: :essence_pictures @@ -62,12 +62,12 @@ class Picture < BaseRecord # We need to define this method here to have it available in the validations below. class << self def allowed_filetypes - Config.get(:uploader).fetch('allowed_filetypes', {}).fetch('alchemy/pictures', []) + Config.get(:uploader).fetch("allowed_filetypes", {}).fetch("alchemy/pictures", []) end end validates_presence_of :image_file - validates_size_of :image_file, maximum: Config.get(:uploader)['file_size_limit'].megabytes + validates_size_of :image_file, maximum: Config.get(:uploader)["file_size_limit"].megabytes validates_property :format, of: :image_file, in: allowed_filetypes, @@ -124,11 +124,11 @@ def search_by(params, query, per_page = nil) pictures.order(:name) end - def filtered_by(filter = '') + def filtered_by(filter = "") case filter - when 'recent' then recent - when 'last_upload' then last_upload - when 'without_tag' then without_tag + when "recent" then recent + when "last_upload" then last_upload + when "without_tag" then without_tag else all end @@ -177,7 +177,7 @@ def urlname if name.blank? "image_#{id}" else - ::CGI.escape(name.gsub(/\.(gif|png|jpe?g|tiff?)/i, '').tr('.', ' ')) + ::CGI.escape(name.gsub(/\.(gif|png|jpe?g|tiff?)/i, "").tr(".", " ")) end end @@ -215,7 +215,7 @@ def default_render_format # def convertible? Config.get(:image_output_format) && - Config.get(:image_output_format) != 'original' && + Config.get(:image_output_format) != "original" && has_convertible_format? end diff --git a/app/models/alchemy/picture/url.rb b/app/models/alchemy/picture/url.rb index 82300cd828..9df002b1ca 100644 --- a/app/models/alchemy/picture/url.rb +++ b/app/models/alchemy/picture/url.rb @@ -66,7 +66,7 @@ def encoded_image(image, options = {}) end options = { - flatten: target_format != 'gif' && image_file_format == 'gif', + flatten: target_format != "gif" && image_file_format == "gif", }.merge(options) encoding_options = [] @@ -77,13 +77,13 @@ def encoded_image(image, options = {}) end if options[:flatten] - encoding_options << '-flatten' + encoding_options << "-flatten" end convertion_needed = target_format != image_file_format || encoding_options.present? if has_convertible_format? && convertion_needed - image = image.encode(target_format, encoding_options.join(' ')) + image = image.encode(target_format, encoding_options.join(" ")) end image diff --git a/app/models/alchemy/site/layout.rb b/app/models/alchemy/site/layout.rb index a863e834f5..12088dfb8b 100644 --- a/app/models/alchemy/site/layout.rb +++ b/app/models/alchemy/site/layout.rb @@ -3,7 +3,7 @@ module Alchemy module Site::Layout extend ActiveSupport::Concern - SITE_DEFINITIONS_FILE = Rails.root.join('config/alchemy/site_layouts.yml') + SITE_DEFINITIONS_FILE = Rails.root.join("config/alchemy/site_layouts.yml") module ClassMethods # Returns the site layouts definition defined in +site_layouts.yml+ file @@ -28,7 +28,7 @@ def read_site_definitions # Returns site's layout definition # def definition - self.class.definitions.detect { |l| l['name'] == partial_name } + self.class.definitions.detect { |l| l["name"] == partial_name } end # Returns the name for the layout partial diff --git a/app/serializers/alchemy/page_tree_serializer.rb b/app/serializers/alchemy/page_tree_serializer.rb index aead2f6185..0f882a7edd 100644 --- a/app/serializers/alchemy/page_tree_serializer.rb +++ b/app/serializers/alchemy/page_tree_serializer.rb @@ -3,7 +3,7 @@ module Alchemy class PageTreeSerializer < BaseSerializer def attributes - {'pages' => nil} + {"pages" => nil} end def pages @@ -73,7 +73,7 @@ def page_hash(page, has_children, level, folded) definition_missing: page.definition.blank?, folded: folded, locked: page.locked?, - locked_notice: page.locked? ? Alchemy.t('This page is locked', name: page.locker_name) : nil, + locked_notice: page.locked? ? Alchemy.t("This page is locked", name: page.locker_name) : nil, permissions: page_permissions(page, opts[:ability]), status_titles: page_status_titles(page), }) @@ -83,10 +83,10 @@ def page_hash(page, has_children, level, folded) end def page_elements(page) - if opts[:elements] == 'true' + if opts[:elements] == "true" page.elements else - page.elements.named(opts[:elements].split(',') || []) + page.elements.named(opts[:elements].split(",") || []) end end diff --git a/app/views/alchemy/pages/show.rss.builder b/app/views/alchemy/pages/show.rss.builder index 19377b16b8..608239ed2e 100644 --- a/app/views/alchemy/pages/show.rss.builder +++ b/app/views/alchemy/pages/show.rss.builder @@ -10,8 +10,8 @@ xml.rss version: "2.0" do xml.item do xml.title element.content_for_rss_title.try(:ingredient) xml.description element.content_for_rss_description.try(:ingredient) - if element.has_ingredient?('date') - xml.pubDate element.ingredient('date').to_s(:rfc822) + if element.has_ingredient?("date") + xml.pubDate element.ingredient("date").to_s(:rfc822) end xml.link show_alchemy_page_url(@page, anchor: element_dom_id(element)) xml.guid show_alchemy_page_url(@page, anchor: element_dom_id(element)) diff --git a/bin/rails b/bin/rails index 5d8a41f30e..7ad4e14e01 100755 --- a/bin/rails +++ b/bin/rails @@ -2,8 +2,8 @@ # frozen_string_literal: true # This command will automatically be run when you run "rails" with Rails 4 gems installed from the root of your application. -ENGINE_ROOT = File.expand_path('..', __dir__) -ENGINE_PATH = File.expand_path('../lib/alchemy/engine', __dir__) +ENGINE_ROOT = File.expand_path("..", __dir__) +ENGINE_PATH = File.expand_path("../lib/alchemy/engine", __dir__) -require 'rails/all' -require 'rails/engine/commands' +require "rails/all" +require "rails/engine/commands" diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb index 150ad0fdc4..4a75c7e252 100644 --- a/config/initializers/assets.rb +++ b/config/initializers/assets.rb @@ -1,3 +1,3 @@ # frozen_string_literal: true # Add Alchemy assets for precompiling -Rails.application.config.assets.precompile << 'alchemy_manifest.js' +Rails.application.config.assets.precompile << "alchemy_manifest.js" diff --git a/config/initializers/dragonfly.rb b/config/initializers/dragonfly.rb index 8ed78220d8..786b23a6b5 100644 --- a/config/initializers/dragonfly.rb +++ b/config/initializers/dragonfly.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true -require 'dragonfly_svg' +require "dragonfly_svg" # Logger Dragonfly.logger = Rails.logger diff --git a/config/initializers/mini_profiler.rb b/config/initializers/mini_profiler.rb index af008dc7c7..562b940e05 100644 --- a/config/initializers/mini_profiler.rb +++ b/config/initializers/mini_profiler.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true begin - require 'rack-mini-profiler' - Rack::MiniProfiler.config.position = 'right' + require "rack-mini-profiler" + Rack::MiniProfiler.config.position = "right" Rack::MiniProfiler.config.start_hidden = true rescue LoadError end diff --git a/config/initializers/simple_form.rb b/config/initializers/simple_form.rb index 9e632b7e09..1da4f1892c 100644 --- a/config/initializers/simple_form.rb +++ b/config/initializers/simple_form.rb @@ -77,7 +77,7 @@ config.boolean_style = :inline # Default class for buttons - config.button_class = 'button' + config.button_class = "button" # Method used to tidy up errors. Specify any Rails Array method. # :first lists the first message for each field. @@ -88,7 +88,7 @@ config.error_notification_tag = :div # CSS class to add for error notification helper. - config.error_notification_class = 'field_with_errors' + config.error_notification_class = "field_with_errors" # ID to add for error notification helper. # config.error_notification_id = nil @@ -103,7 +103,7 @@ config.collection_wrapper_tag = :div # You can define the class to use on all collection wrappers. Defaulting to none. - config.collection_wrapper_class = 'control_group' + config.collection_wrapper_class = "control_group" # You can wrap each item in a collection of radio/check boxes with a tag, # defaulting to :span. @@ -116,7 +116,7 @@ config.label_text = proc { |label, required| "#{label}#{required}" } # You can define the class to use on all labels. Default is nil. - config.label_class = 'control-label' + config.label_class = "control-label" # You can define the default class to be used on forms. Can be overriden # with `html: { :class }`. Defaulting to none. @@ -170,12 +170,12 @@ # config.input_class = nil # Define the default class of the input wrapper of the boolean input. - config.boolean_label_class = 'checkbox' + config.boolean_label_class = "checkbox" # Defines if the default input wrapper class should be included in radio # collection wrappers. # config.include_default_input_wrapper_class = true # Defines which i18n scope will be used in Simple Form. - config.i18n_scope = 'alchemy.forms' + config.i18n_scope = "alchemy.forms" end diff --git a/config/routes.rb b/config/routes.rb index 1cf0de3483..b3c5abe012 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,18 +1,18 @@ # frozen_string_literal: true -require 'alchemy/routing_constraints' +require "alchemy/routing_constraints" Alchemy::Engine.routes.draw do - root to: 'pages#index' + root to: "pages#index" - get '/sitemap.xml' => 'pages#sitemap', format: 'xml' + get "/sitemap.xml" => "pages#sitemap", format: "xml" scope Alchemy.admin_path, {constraints: Alchemy.admin_constraints} do - get '/' => redirect("#{Alchemy.admin_path}/dashboard"), as: :admin - get '/dashboard' => 'admin/dashboard#index', as: :admin_dashboard - get '/dashboard/info' => 'admin/dashboard#info', as: :dashboard_info - get '/help' => 'admin/dashboard#help', as: :help - get '/dashboard/update_check' => 'admin/dashboard#update_check', as: :update_check - get '/leave' => 'admin/base#leave', as: :leave_admin + get "/" => redirect("#{Alchemy.admin_path}/dashboard"), as: :admin + get "/dashboard" => "admin/dashboard#index", as: :admin_dashboard + get "/dashboard/info" => "admin/dashboard#info", as: :dashboard_info + get "/help" => "admin/dashboard#help", as: :help + get "/dashboard/update_check" => "admin/dashboard#update_check", as: :update_check + get "/leave" => "admin/base#leave", as: :leave_admin end namespace :admin, {path: Alchemy.admin_path, constraints: Alchemy.admin_constraints} do @@ -95,7 +95,7 @@ end end - resource :clipboard, only: :index, controller: 'clipboard' do + resource :clipboard, only: :index, controller: "clipboard" do collection do get :index delete :clear @@ -104,7 +104,7 @@ end end - resource :trash, only: :index, controller: 'trash' do + resource :trash, only: :index, controller: "trash" do collection do get :index delete :clear @@ -119,36 +119,36 @@ resources :sites - get '/styleguide' => 'styleguide#index' + get "/styleguide" => "styleguide#index" end - get '/attachment/:id/download(/:name)' => 'attachments#download', + get "/attachment/:id/download(/:name)" => "attachments#download", as: :download_attachment - get '/attachment/:id/show' => 'attachments#show', + get "/attachment/:id/show" => "attachments#show", as: :show_attachment resources :messages, only: [:index, :new, :create] resources :elements, only: :show resources :contents, only: :show - namespace :api, defaults: {format: 'json'} do + namespace :api, defaults: {format: "json"} do resources :contents, only: [:index, :show] resources :elements, only: [:index, :show] do - get '/contents' => 'contents#index', as: 'contents' - get '/contents/:name' => 'contents#show', as: 'content' + get "/contents" => "contents#index", as: "contents" + get "/contents/:name" => "contents#show", as: "content" end resources :pages, only: [:index] do - get 'elements' => 'elements#index', as: 'elements' - get 'elements/:named' => 'elements#index', as: 'named_elements' + get "elements" => "elements#index", as: "elements" + get "elements/:named" => "elements#index", as: "named_elements" collection do get :nested end end - get '/pages/*urlname(.:format)' => 'pages#show', as: 'page' - get '/admin/pages/:id(.:format)' => 'pages#show', as: 'preview_page' + get "/pages/*urlname(.:format)" => "pages#show", as: "page" + get "/admin/pages/:id(.:format)" => "pages#show", as: "preview_page" resources :nodes, only: [] do member do @@ -158,13 +158,13 @@ end end - get '/:locale' => 'pages#index', + get "/:locale" => "pages#index", constraints: {locale: Alchemy::RoutingConstraints::LOCALE_REGEXP}, as: :show_language_root # The page show action has to be last route constraints(locale: Alchemy::RoutingConstraints::LOCALE_REGEXP) do - get '(/:locale)/*urlname(.:format)' => 'pages#show', + get "(/:locale)/*urlname(.:format)" => "pages#show", constraints: Alchemy::RoutingConstraints.new, as: :show_page end diff --git a/config/spring.rb b/config/spring.rb index 9ee5253fd9..a28a83bf50 100755 --- a/config/spring.rb +++ b/config/spring.rb @@ -1,3 +1,3 @@ # frozen_string_literal: true -Spring.application_root = './spec/dummy' -Spring.watch 'lib/**/*' +Spring.application_root = "./spec/dummy" +Spring.watch "lib/**/*" diff --git a/lib/alchemy/admin/locale.rb b/lib/alchemy/admin/locale.rb index 7300e4b5e1..d5627afa77 100644 --- a/lib/alchemy/admin/locale.rb +++ b/lib/alchemy/admin/locale.rb @@ -64,7 +64,7 @@ def user_has_preferred_language? # Try to get the locale from browser headers. def locale_from_browser - request.env['HTTP_ACCEPT_LANGUAGE'].try(:scan, /\A[a-z]{2}/).try(:first) + request.env["HTTP_ACCEPT_LANGUAGE"].try(:scan, /\A[a-z]{2}/).try(:first) end end end diff --git a/lib/alchemy/auth_accessors.rb b/lib/alchemy/auth_accessors.rb index d35fa6afe3..0114eff556 100644 --- a/lib/alchemy/auth_accessors.rb +++ b/lib/alchemy/auth_accessors.rb @@ -53,13 +53,13 @@ module Alchemy # Defaults # - @@user_class_name = 'User' + @@user_class_name = "User" @@user_class_primary_key = :id - @@current_user_method = 'current_user' - @@signup_path = '/signup' - @@login_path = '/login' - @@logout_path = '/logout' - @@logout_method = 'delete' + @@current_user_method = "current_user" + @@signup_path = "/signup" + @@login_path = "/login" + @@logout_path = "/logout" + @@logout_method = "delete" # Returns the user class # @@ -76,7 +76,7 @@ module Alchemy # Prefix with :: when getting to avoid constant name conflicts def self.user_class_name if !@@user_class_name.is_a?(String) - raise TypeError, 'Alchemy.user_class_name must be a String, not a Class.' + raise TypeError, "Alchemy.user_class_name must be a String, not a Class." end "::#{@@user_class_name}" diff --git a/lib/alchemy/cache_digests/template_tracker.rb b/lib/alchemy/cache_digests/template_tracker.rb index ef1e646759..d6f6aa7a88 100644 --- a/lib/alchemy/cache_digests/template_tracker.rb +++ b/lib/alchemy/cache_digests/template_tracker.rb @@ -14,10 +14,10 @@ def initialize(name, template) def dependencies case @name.to_s when /^alchemy\/pages\/show/ - PageLayout.all.map { |p| "alchemy/page_layouts/_#{p['name']}" } + PageLayout.all.map { |p| "alchemy/page_layouts/_#{p["name"]}" } when /^alchemy\/page_layouts\/_(\w+)/ page_layout = PageLayout.get($1) - layout_elements = page_layout.fetch('elements', []) + layout_elements = page_layout.fetch("elements", []) layout_elements.map { |name| "alchemy/elements/_#{name}_view" } + layout_elements.map { |name| "alchemy/elements/_#{name}" } when /^alchemy\/elements\/_(\w+)_view/, /^alchemy\/elements\/_(\w+)/ @@ -32,10 +32,10 @@ def dependencies private def essence_types(name) - element = Element.definitions.detect { |e| e['name'] == name } + element = Element.definitions.detect { |e| e["name"] == name } return [] unless element - element.fetch('contents', []).collect { |c| c['type'] } + element.fetch("contents", []).collect { |c| c["type"] } end end end diff --git a/lib/alchemy/config.rb b/lib/alchemy/config.rb index 7b60a8919d..3daaa40e42 100644 --- a/lib/alchemy/config.rb +++ b/lib/alchemy/config.rb @@ -29,7 +29,7 @@ def show # Alchemy default configuration def alchemy_config - read_file(File.join(File.dirname(__FILE__), '..', '..', 'config/alchemy/config.yml')) + read_file(File.join(File.dirname(__FILE__), "..", "..", "config/alchemy/config.yml")) end # Application specific configuration @@ -54,7 +54,7 @@ def read_file(file) # Merges all given configs together # def merge_configs!(*config_files) - raise LoadError, 'No Alchemy config file found!' if config_files.map(&:blank?).all? + raise LoadError, "No Alchemy config file found!" if config_files.map(&:blank?).all? config = {} config_files.each { |h| config.merge!(h.stringify_keys!) } diff --git a/lib/alchemy/controller_actions.rb b/lib/alchemy/controller_actions.rb index 6ac7db7fc7..177323055e 100644 --- a/lib/alchemy/controller_actions.rb +++ b/lib/alchemy/controller_actions.rb @@ -8,7 +8,7 @@ module ControllerActions before_action :set_current_alchemy_site before_action :set_alchemy_language - helper 'alchemy/pages' + helper "alchemy/pages" helper_method :current_alchemy_user, :alchemy_user_signed_in?, diff --git a/lib/alchemy/deprecation.rb b/lib/alchemy/deprecation.rb index c2ccd9c987..37c738abc0 100644 --- a/lib/alchemy/deprecation.rb +++ b/lib/alchemy/deprecation.rb @@ -1,4 +1,4 @@ # frozen_string_literal: true module Alchemy - Deprecation = ActiveSupport::Deprecation.new('5.0', 'Alchemy') + Deprecation = ActiveSupport::Deprecation.new("5.0", "Alchemy") end diff --git a/lib/alchemy/elements_finder.rb b/lib/alchemy/elements_finder.rb index 50c4540f45..66c06416a2 100644 --- a/lib/alchemy/elements_finder.rb +++ b/lib/alchemy/elements_finder.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'alchemy/logger' +require "alchemy/logger" module Alchemy # Loads elements from given page @@ -104,10 +104,10 @@ def fallback_elements def random_function case ActiveRecord::Base.connection_config[:adapter] - when 'postgresql', 'sqlite3' - 'RANDOM()' + when "postgresql", "sqlite3" + "RANDOM()" else - 'RAND()' + "RAND()" end end end diff --git a/lib/alchemy/engine.rb b/lib/alchemy/engine.rb index c1ea56042b..4e488f59cb 100644 --- a/lib/alchemy/engine.rb +++ b/lib/alchemy/engine.rb @@ -2,32 +2,32 @@ module Alchemy class Engine < Rails::Engine isolate_namespace Alchemy - engine_name 'alchemy' - config.mount_at = '/' + engine_name "alchemy" + config.mount_at = "/" - initializer 'alchemy.lookup_context' do - Alchemy::LOOKUP_CONTEXT = ActionView::LookupContext.new(Rails.root.join('app', 'views', 'alchemy')) + initializer "alchemy.lookup_context" do + Alchemy::LOOKUP_CONTEXT = ActionView::LookupContext.new(Rails.root.join("app", "views", "alchemy")) end - initializer 'alchemy.dependency_tracker' do + initializer "alchemy.dependency_tracker" do [:erb, :slim, :haml].each do |handler| ActionView::DependencyTracker.register_tracker(handler, CacheDigests::TemplateTracker) end end - initializer 'alchemy.non_digest_assets' do + initializer "alchemy.non_digest_assets" do NonStupidDigestAssets.whitelist += [/^tinymce\//] end # Gutentag downcases all tgas before save. # We support having tags with uppercase characters. # The Gutentag search is case insensitive. - initializer 'alchemy.gutentag_normalizer' do + initializer "alchemy.gutentag_normalizer" do Gutentag.normaliser = ->(value) { value.to_s } end # Custom Ransack sort arrows - initializer 'alchemy.ransack' do + initializer "alchemy.ransack" do Ransack.configure do |config| config.custom_arrows = { up_arrow: '<i class="fa fas fa-xs fa-arrow-up"></i>', @@ -47,18 +47,18 @@ class Engine < Rails::Engine end # Serve webpacks if public file server enabled - initializer 'alchemy.webpacker.middleware' do |app| + initializer "alchemy.webpacker.middleware" do |app| if app.config.public_file_server.enabled app.middleware.use( Rack::Static, - urls: ['/alchemy-packs', '/alchemy-packs-test'], - root: Alchemy::ROOT_PATH.join('public'), + urls: ["/alchemy-packs", "/alchemy-packs-test"], + root: Alchemy::ROOT_PATH.join("public"), ) end end config.after_initialize do - require_relative './userstamp' + require_relative "./userstamp" end end end diff --git a/lib/alchemy/essence.rb b/lib/alchemy/essence.rb index 81780ac62d..2b14019554 100644 --- a/lib/alchemy/essence.rb +++ b/lib/alchemy/essence.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'active_record' +require "active_record" module Alchemy #:nodoc: # A bogus association that skips eager loading for essences not having an ingredient association @@ -40,7 +40,7 @@ def acts_as_essence(options = {}) register_as_essence_association! configuration = { - ingredient_column: 'body', + ingredient_column: "body", }.update(options) @_classes_with_ingredient_association ||= [] @@ -171,7 +171,7 @@ def validate_ingredient end def validations - @validations ||= definition.present? ? definition['validate'] || [] : [] + @validations ||= definition.present? ? definition["validate"] || [] : [] end def validation_errors @@ -195,7 +195,7 @@ def validate_uniqueness(validate = true) end def validate_format(format) - matcher = Config.get('format_matchers')[format] || format + matcher = Config.get("format_matchers")[format] || format if ingredient.to_s.match(Regexp.new(matcher)).nil? errors.add(ingredient_column, :invalid) validation_errors << :invalid @@ -226,14 +226,14 @@ def ingredient=(value) # Returns the setter method for ingredient column def ingredient_setter_method - ingredient_column.to_s + '=' + ingredient_column.to_s + "=" end # Essence definition from config/elements.yml def definition return {} if element.nil? || element.content_definitions.nil? - element.content_definitions.detect { |c| c['name'] == content.name } || {} + element.content_definitions.detect { |c| c["name"] == content.name } || {} end # Touch content. Called after update. @@ -250,11 +250,11 @@ def preview_text(maxlength = 30) end def open_link_in_new_window? - respond_to?(:link_target) && link_target == 'blank' + respond_to?(:link_target) && link_target == "blank" end def partial_name - self.class.name.split('::').last.underscore + self.class.name.split("::").last.underscore end def acts_as_essence? diff --git a/lib/alchemy/forms/builder.rb b/lib/alchemy/forms/builder.rb index 616a87fd5d..53fd36da68 100644 --- a/lib/alchemy/forms/builder.rb +++ b/lib/alchemy/forms/builder.rb @@ -11,7 +11,7 @@ def input(attribute_name, options = {}, &block) if object.respond_to?(:attribute_fixed?) && object.attribute_fixed?(attribute_name) options[:disabled] = true options[:input_html] = options.fetch(:input_html, {}).merge( - 'data-alchemy-tooltip' => Alchemy.t(:attribute_fixed, attribute_name), + "data-alchemy-tooltip" => Alchemy.t(:attribute_fixed, attribute_name), ) end @@ -22,10 +22,10 @@ def input(attribute_name, options = {}, &block) # def submit(label, options = {}) options = { - wrapper_html: {class: 'submit'}, + wrapper_html: {class: "submit"}, }.update(options) - template.content_tag('div', options.delete(:wrapper_html)) do - template.content_tag('button', label, options.delete(:input_html)) + template.content_tag("div", options.delete(:wrapper_html)) do + template.content_tag("button", label, options.delete(:input_html)) end end end diff --git a/lib/alchemy/hints.rb b/lib/alchemy/hints.rb index a7ed3128fa..e767626bc2 100644 --- a/lib/alchemy/hints.rb +++ b/lib/alchemy/hints.rb @@ -35,7 +35,7 @@ module Hints # @return String # def hint - hint = definition['hint'] + hint = definition["hint"] if hint == true Alchemy.t(name, scope: hint_translation_scope) else diff --git a/lib/alchemy/i18n.rb b/lib/alchemy/i18n.rb index 4f139709fd..fdfe934d47 100644 --- a/lib/alchemy/i18n.rb +++ b/lib/alchemy/i18n.rb @@ -79,7 +79,7 @@ def humanize_default_string!(msg, options) end def alchemy_scoped_scope(options) - default_scope = ['alchemy'] + default_scope = ["alchemy"] case options[:scope] when Array default_scope + options[:scope] diff --git a/lib/alchemy/modules.rb b/lib/alchemy/modules.rb index 898f9ce4d0..907fa00225 100644 --- a/lib/alchemy/modules.rb +++ b/lib/alchemy/modules.rb @@ -4,7 +4,7 @@ module Alchemy module Modules mattr_accessor :alchemy_modules - @@alchemy_modules = YAML.load_file(File.expand_path('../../config/alchemy/modules.yml', __dir__)) + @@alchemy_modules = YAML.load_file(File.expand_path("../../config/alchemy/modules.yml", __dir__)) class << self def included(base) @@ -28,11 +28,11 @@ def register_module(module_definition) definition_hash = module_definition.deep_stringify_keys ### Validate controller(s) existence - if definition_hash['navigation'].is_a?(Hash) - defined_controllers = [definition_hash['navigation']['controller']] + if definition_hash["navigation"].is_a?(Hash) + defined_controllers = [definition_hash["navigation"]["controller"]] - if definition_hash['navigation']['sub_navigation'].is_a?(Array) - defined_controllers.concat(definition_hash['navigation']['sub_navigation'].map{ |x| x['controller'] }) + if definition_hash["navigation"]["sub_navigation"].is_a?(Array) + defined_controllers.concat(definition_hash["navigation"]["sub_navigation"].map{ |x| x["controller"] }) end validate_controllers_existence(defined_controllers) @@ -52,7 +52,7 @@ def validate_controllers_existence(controllers) begin controller_name.constantize rescue NameError - raise "Error in AlchemyCMS module definition: '#{definition_hash['name']}'. Could not find the matching controller class #{controller_name.sub(/^::/, '')} for the specified controller: '#{controller_val}'" + raise "Error in AlchemyCMS module definition: '#{definition_hash["name"]}'. Could not find the matching controller class #{controller_name.sub(/^::/, "")} for the specified controller: '#{controller_val}'" end end end @@ -66,11 +66,11 @@ def validate_controllers_existence(controllers) def module_definition_for(name_or_params) case name_or_params when String - alchemy_modules.detect { |m| m['name'] == name_or_params } + alchemy_modules.detect { |m| m["name"] == name_or_params } when Hash name_or_params.stringify_keys! alchemy_modules.detect do |alchemy_module| - module_navi = alchemy_module.fetch('navigation', {}) + module_navi = alchemy_module.fetch("navigation", {}) definition_from_mainnavi(module_navi, name_or_params) || definition_from_subnavi(module_navi, name_or_params) end @@ -86,7 +86,7 @@ def definition_from_mainnavi(module_navi, params) end def definition_from_subnavi(module_navi, params) - subnavi = module_navi['sub_navigation'] + subnavi = module_navi["sub_navigation"] return if subnavi.nil? subnavi.any? do |navi| @@ -95,15 +95,15 @@ def definition_from_subnavi(module_navi, params) end def controller_matches?(navi, params) - remove_slash(navi['controller']) == remove_slash(params['controller']) + remove_slash(navi["controller"]) == remove_slash(params["controller"]) end def action_matches?(navi, params) - navi['action'] == params['action'] + navi["action"] == params["action"] end def remove_slash(str) - str.gsub(/^\//, '') + str.gsub(/^\//, "") end end end diff --git a/lib/alchemy/name_conversions.rb b/lib/alchemy/name_conversions.rb index 9d3b84db03..6962366b2a 100644 --- a/lib/alchemy/name_conversions.rb +++ b/lib/alchemy/name_conversions.rb @@ -10,17 +10,17 @@ module NameConversions # @returns String def convert_to_urlname(name) name - .gsub(/[äÄ]/, 'ae') - .gsub(/[üÜ]/, 'ue') - .gsub(/[öÖ]/, 'oe') - .gsub(/[ß]/, 'ss') + .gsub(/[äÄ]/, "ae") + .gsub(/[üÜ]/, "ue") + .gsub(/[öÖ]/, "oe") + .gsub(/[ß]/, "ss") .parameterize end # Converts a filename and suffix into a human readable name. # def convert_to_humanized_name(name, suffix) - name.gsub(/\.#{::Regexp.quote(suffix)}$/i, '').tr('_', ' ').strip + name.gsub(/\.#{::Regexp.quote(suffix)}$/i, "").tr("_", " ").strip end end end diff --git a/lib/alchemy/page_layout.rb b/lib/alchemy/page_layout.rb index f3c759f9f6..6827b6eafa 100644 --- a/lib/alchemy/page_layout.rb +++ b/lib/alchemy/page_layout.rb @@ -38,7 +38,7 @@ def add(page_layout) def get(name) return {} if name.blank? - all.detect { |a| a['name'].casecmp(name).zero? } + all.detect { |a| a["name"].casecmp(name).zero? } end def get_all_by_attributes(attributes) @@ -67,7 +67,7 @@ def layouts_for_select(language_id, only_layoutpages = false) # def layouts_with_own_for_select(page_layout_name, language_id, only_layoutpages = false) layouts = selectable_layouts(language_id, only_layoutpages) - if layouts.detect { |l| l['name'] == page_layout_name }.nil? + if layouts.detect { |l| l["name"] == page_layout_name }.nil? @map_array = [[human_layout_name(page_layout_name), page_layout_name]] else @map_array = [] @@ -88,9 +88,9 @@ def selectable_layouts(language_id, only_layoutpages = false) @language_id = language_id all.select do |layout| if only_layoutpages - layout['layoutpage'] && layout_available?(layout) + layout["layoutpage"] && layout_available?(layout) else - !layout['layoutpage'] && layout_available?(layout) + !layout["layoutpage"] && layout_available?(layout) end end end @@ -99,7 +99,7 @@ def selectable_layouts(language_id, only_layoutpages = false) # def element_names_for(page_layout) if definition = get(page_layout) - definition.fetch('elements', []) + definition.fetch("elements", []) else Rails.logger.warn "\n+++ Warning: No layout definition for #{page_layout} found! in page_layouts.yml\n" [] @@ -119,7 +119,7 @@ def element_names_for(page_layout) # The layout name # def human_layout_name(layout) - Alchemy.t(layout, scope: 'page_layout_names', default: layout.to_s.humanize) + Alchemy.t(layout, scope: "page_layout_names", default: layout.to_s.humanize) end private @@ -127,13 +127,13 @@ def human_layout_name(layout) # Returns true if the given layout is unique and not already taken or it should be hidden. # def layout_available?(layout) - !layout['hide'] && !already_taken?(layout) && available_on_site?(layout) + !layout["hide"] && !already_taken?(layout) && available_on_site?(layout) end # Returns true if this layout is unique and already taken by another page. # def already_taken?(layout) - layout['unique'] && page_with_layout_existing?(layout['name']) + layout["unique"] && page_with_layout_existing?(layout["name"]) end # Returns true if one page already has the given layout @@ -156,7 +156,7 @@ def available_on_site?(layout) return false unless Alchemy::Site.current Alchemy::Site.current.definition.blank? || - Alchemy::Site.current.definition.fetch('page_layouts', []).include?(layout['name']) + Alchemy::Site.current.definition.fetch("page_layouts", []).include?(layout["name"]) end # Reads the layout definitions from +config/alchemy/page_layouts.yml+. @@ -172,14 +172,14 @@ def read_definitions_file # Returns the page_layouts.yml file path # def layouts_file_path - Rails.root.join 'config/alchemy/page_layouts.yml' + Rails.root.join "config/alchemy/page_layouts.yml" end # Maps given layouts for Rails select form helper. # def mapped_layouts_for_select(layouts) layouts.each do |layout| - @map_array << [human_layout_name(layout['name']), layout["name"]] + @map_array << [human_layout_name(layout["name"]), layout["name"]] end @map_array end diff --git a/lib/alchemy/paths.rb b/lib/alchemy/paths.rb index 241eeca1c5..a3e263d795 100644 --- a/lib/alchemy/paths.rb +++ b/lib/alchemy/paths.rb @@ -29,6 +29,6 @@ module Alchemy # Defaults # - @@admin_path = 'admin' + @@admin_path = "admin" @@admin_constraints = {} end diff --git a/lib/alchemy/resource.rb b/lib/alchemy/resource.rb index 85159433dd..c7326b54d0 100644 --- a/lib/alchemy/resource.rb +++ b/lib/alchemy/resource.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true -require 'active_support' -require 'active_support/core_ext' -require 'active_support/inflector' +require "active_support" +require "active_support/core_ext" +require "active_support/inflector" module Alchemy # = Alchemy::Resource @@ -120,7 +120,7 @@ def initialize(controller_path, module_definition = nil, custom_model = nil) end def resource_array - @_resource_array ||= controller_path_array.reject { |el| el == 'admin' } + @_resource_array ||= controller_path_array.reject { |el| el == "admin" } end def resources_name @@ -139,7 +139,7 @@ def namespaced_resources_name @_namespaced_resources_name ||= begin resource_name_array = resource_array.dup resource_name_array.delete(engine_name) if in_engine? - resource_name_array.join('_') + resource_name_array.join("_") end end @@ -173,9 +173,9 @@ def attributes def sorted_attributes @_sorted_attributes ||= attributes. - sort_by { |attr| attr[:name] == 'name' ? 0 : 1 }. + sort_by { |attr| attr[:name] == "name" ? 0 : 1 }. sort_by! { |attr| attr[:type] == :boolean ? 1 : 0 }. - sort_by! { |attr| attr[:name] == 'updated_at' ? 1 : 0 } + sort_by! { |attr| attr[:name] == "updated_at" ? 1 : 0 } end def editable_attributes @@ -207,7 +207,7 @@ def in_engine? end def engine_name - @module_definition && @module_definition['engine_name'] + @module_definition && @module_definition["engine_name"] end # Returns a help text for resource's form @@ -269,11 +269,11 @@ def searchable_relation_attribute(attribute) end def guess_model_from_controller_path - resource_array.join('/').classify.constantize + resource_array.join("/").classify.constantize end def controller_path_array - @controller_path.split('/') + @controller_path.split("/") end def namespace_diff @@ -296,7 +296,7 @@ def resource_relation(column_name) def map_relations self.resource_relations = {} model.alchemy_resource_relations.each do |name, options| - name = name.to_s.gsub(/_id$/, '') # ensure that we don't have an id + name = name.to_s.gsub(/_id$/, "") # ensure that we don't have an id association = association_from_relation_name(name) foreign_key = association.options[:foreign_key] || "#{association.name}_id".to_sym resource_relations[foreign_key] = options.merge(model_association: association, name: name) diff --git a/lib/alchemy/resources_helper.rb b/lib/alchemy/resources_helper.rb index 19a0f421d5..c8a7241576 100644 --- a/lib/alchemy/resources_helper.rb +++ b/lib/alchemy/resources_helper.rb @@ -104,21 +104,21 @@ def resource_attribute_field_options(attribute) options = {hint: resource_handler.help_text_for(attribute)} input_type = attribute[:type].to_s case input_type - when 'boolean' + when "boolean" options - when 'date', 'time', 'datetime' + when "date", "time", "datetime" date = resource_instance_variable.send(attribute[:name]) || Time.current options.merge( - as: 'string', + as: "string", input_html: { - 'data-datepicker-type' => input_type, + "data-datepicker-type" => input_type, value: date ? date.iso8601 : nil, }, ) - when 'text' - options.merge(as: 'text', input_html: {rows: 4}) + when "text" + options.merge(as: "text", input_html: {rows: 4}) else - options.merge(as: 'string') + options.merge(as: "string") end end @@ -165,7 +165,7 @@ def sortable_resource_header_column(attribute) def render_resources render partial: resource_name, collection: resources_instance_variable rescue ActionView::MissingTemplate - render partial: 'resource', collection: resources_instance_variable + render partial: "resource", collection: resources_instance_variable end def resource_has_tags @@ -179,7 +179,7 @@ def resource_has_filters def resource_filter_select resource_model.alchemy_resource_filters.map do |filter_scope| [ - Alchemy.t(filter_scope.to_sym, scope: ['resources', resource_name, 'filters']), + Alchemy.t(filter_scope.to_sym, scope: ["resources", resource_name, "filters"]), filter_scope, ] end diff --git a/lib/alchemy/routing_constraints.rb b/lib/alchemy/routing_constraints.rb index 54844b2bcc..16390a46ed 100644 --- a/lib/alchemy/routing_constraints.rb +++ b/lib/alchemy/routing_constraints.rb @@ -34,7 +34,7 @@ def handable_format? def no_rails_route? return true if !%w(development test).include?(Rails.env) - (@params['urlname'] =~ /\Arails\//).nil? + (@params["urlname"] =~ /\Arails\//).nil? end end end diff --git a/lib/alchemy/seeder.rb b/lib/alchemy/seeder.rb index efc341f070..dfcfe9fafd 100644 --- a/lib/alchemy/seeder.rb +++ b/lib/alchemy/seeder.rb @@ -83,7 +83,7 @@ def seed_users private def page_seeds_file - @_page_seeds_file ||= Rails.root.join('db', 'seeds', 'alchemy', 'pages.yml') + @_page_seeds_file ||= Rails.root.join("db", "seeds", "alchemy", "pages.yml") end def page_yml @@ -91,19 +91,19 @@ def page_yml end def contentpages - page_yml.reject { |p| p['layoutpage'] } + page_yml.reject { |p| p["layoutpage"] } end def layoutpages - page_yml.select { |p| p['layoutpage'] } + page_yml.select { |p| p["layoutpage"] } end def user_seeds_file - @_user_seeds_file ||= Rails.root.join('db', 'seeds', 'alchemy', 'users.yml') + @_user_seeds_file ||= Rails.root.join("db", "seeds", "alchemy", "users.yml") end def create_page(draft, attributes = {}) - children = draft.delete('children') || [] + children = draft.delete("children") || [] page = Alchemy::Page.create!(draft.merge(attributes)) log "Created page: #{page.name}" children.each do |child| @@ -117,11 +117,11 @@ def create_default_language! default_language = Alchemy::Config.get(:default_language) if default_language Alchemy::Language.create!( - name: default_language['name'], - language_code: default_language['code'], - locale: default_language['code'], - frontpage_name: default_language['frontpage_name'], - page_layout: default_language['page_layout'], + name: default_language["name"], + language_code: default_language["code"], + locale: default_language["code"], + frontpage_name: default_language["frontpage_name"], + page_layout: default_language["page_layout"], public: true, default: true, site: Alchemy::Site.default, @@ -134,7 +134,7 @@ def create_default_language! def create_default_site! default_site = Alchemy::Config.get(:default_site) if default_site - Alchemy::Site.create!(name: default_site['name'], host: default_site['host']) + Alchemy::Site.create!(name: default_site["name"], host: default_site["host"]) else raise DefaultSiteNotFoundError end diff --git a/lib/alchemy/shell.rb b/lib/alchemy/shell.rb index d4aa730271..d3b71e2f52 100644 --- a/lib/alchemy/shell.rb +++ b/lib/alchemy/shell.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true -require 'thor/shell/color' +require "thor/shell/color" module Alchemy # Provides methods for collecting sentences and displaying them @@ -28,11 +28,11 @@ def self.silenced? def desc(message) unless Alchemy::Shell.silenced? puts "\n#{message}" - puts "#{'-' * message.length}\n" + puts "#{"-" * message.length}\n" end end - def todo(todo, title = '') + def todo(todo, title = "") add_todo [title, todo] end @@ -64,7 +64,7 @@ def display_todos todos.each_with_index do |todo, i| title = "\n#{i + 1}. #{todo[0]}" log title, :message - puts '=' * title.length + puts "=" * title.length puts "" log todo[1], :message end diff --git a/lib/alchemy/ssl_protection.rb b/lib/alchemy/ssl_protection.rb index aa134e848e..6fb5eeee94 100644 --- a/lib/alchemy/ssl_protection.rb +++ b/lib/alchemy/ssl_protection.rb @@ -26,7 +26,7 @@ def ssl_required? # Redirects current request to https. def enforce_ssl - redirect_to url_for(request.params.merge(protocol: 'https')) + redirect_to url_for(request.params.merge(protocol: "https")) end end end diff --git a/lib/alchemy/tasks/tidy.rb b/lib/alchemy/tasks/tidy.rb index ef2c662cad..e60c37547f 100644 --- a/lib/alchemy/tasks/tidy.rb +++ b/lib/alchemy/tasks/tidy.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true -require 'alchemy/shell' +require "alchemy/shell" module Alchemy class Tidy @@ -53,7 +53,7 @@ def remove_orphaned_elements end if orphaned_elements.any? log "Found #{orphaned_elements.size} orphaned elements" - destroy_orphaned_records(orphaned_elements, 'element') + destroy_orphaned_records(orphaned_elements, "element") else log "No orphaned elements found", :skip end @@ -72,7 +72,7 @@ def remove_orphaned_contents end if orphaned_contents.any? log "Found #{orphaned_contents.size} orphaned contents" - destroy_orphaned_records(orphaned_contents, 'content') + destroy_orphaned_records(orphaned_contents, "content") else log "No orphaned contents found", :skip end diff --git a/lib/alchemy/test_support/essence_shared_examples.rb b/lib/alchemy/test_support/essence_shared_examples.rb index e1a2af7c30..0f4a9fd0f9 100644 --- a/lib/alchemy/test_support/essence_shared_examples.rb +++ b/lib/alchemy/test_support/essence_shared_examples.rb @@ -1,21 +1,21 @@ # frozen_string_literal: true -require 'shoulda-matchers' -require 'alchemy/test_support/factories/page_factory' -require 'alchemy/test_support/factories/element_factory' -require 'alchemy/test_support/factories/content_factory' +require "shoulda-matchers" +require "alchemy/test_support/factories/page_factory" +require "alchemy/test_support/factories/element_factory" +require "alchemy/test_support/factories/content_factory" RSpec.shared_examples_for "an essence" do let(:element) { Alchemy::Element.new } - let(:content) { Alchemy::Content.new(name: 'foo') } - let(:content_definition) { {'name' => 'foo'} } + let(:content) { Alchemy::Content.new(name: "foo") } + let(:content_definition) { {"name" => "foo"} } - describe 'eager loading' do + describe "eager loading" do before do 2.times { described_class.create! } end - it 'does not throw error if eager loaded' do + it "does not throw error if eager loaded" do expect { described_class.all.includes(:ingredient_association).to_a }.to_not raise_error @@ -38,28 +38,28 @@ expect(essence.to_partial_path).to eq("alchemy/essences/#{underscored_essence}_view") end - describe '#definition' do + describe "#definition" do subject { essence.definition } - context 'without element' do + context "without element" do it { is_expected.to eq({}) } end - context 'with element' do + context "with element" do before do expect(essence).to receive(:element).at_least(:once).and_return(element) end - context 'but without content definitions' do + context "but without content definitions" do it { is_expected.to eq({}) } end - context 'and content definitions' do + context "and content definitions" do before do allow(essence).to receive(:content).and_return(content) end - context 'containing the content name' do + context "containing the content name" do before do expect(element).to receive(:content_definitions).at_least(:once).and_return([content_definition]) end @@ -69,7 +69,7 @@ end end - context 'not containing the content name' do + context "not containing the content name" do before do expect(element).to receive(:content_definitions).at_least(:once).and_return([]) end @@ -80,199 +80,199 @@ end end - describe '#ingredient=' do - it 'should set the value to ingredient column' do + describe "#ingredient=" do + it "should set the value to ingredient column" do essence.ingredient = ingredient_value expect(essence.ingredient).to eq ingredient_value end end - describe 'validations' do - context 'without essence definition in elements.yml' do - it 'should return an empty array' do + describe "validations" do + context "without essence definition in elements.yml" do + it "should return an empty array" do allow(essence).to receive(:definition).and_return nil expect(essence.validations).to eq([]) end end - context 'without validations defined in essence definition in elements.yml' do - it 'should return an empty array' do - allow(essence).to receive(:definition).and_return({name: 'test', type: 'EssenceText'}) + context "without validations defined in essence definition in elements.yml" do + it "should return an empty array" do + allow(essence).to receive(:definition).and_return({name: "test", type: "EssenceText"}) expect(essence.validations).to eq([]) end end - describe 'presence' do - context 'with string given as validation type' do + describe "presence" do + context "with string given as validation type" do before do - allow(essence).to receive(:definition).and_return({'validate' => ['presence']}) + allow(essence).to receive(:definition).and_return({"validate" => ["presence"]}) end - context 'when the ingredient column is empty' do + context "when the ingredient column is empty" do before do essence.update(essence.ingredient_column.to_sym => nil) end - it 'should not be valid' do + it "should not be valid" do expect(essence).to_not be_valid end end - context 'when the ingredient column is not nil' do + context "when the ingredient column is not nil" do before do essence.update(essence.ingredient_column.to_sym => ingredient_value) end - it 'should be valid' do + it "should be valid" do expect(essence).to be_valid end end end - context 'with hash given as validation type' do - context 'where the value is true' do + context "with hash given as validation type" do + context "where the value is true" do before do - allow(essence).to receive(:definition).and_return({'validate' => [{'presence' => true}]}) + allow(essence).to receive(:definition).and_return({"validate" => [{"presence" => true}]}) end - context 'when the ingredient column is empty' do + context "when the ingredient column is empty" do before do essence.update(essence.ingredient_column.to_sym => nil) end - it 'should not be valid' do + it "should not be valid" do expect(essence).to_not be_valid end end - context 'when the ingredient column is not nil' do + context "when the ingredient column is not nil" do before do essence.update(essence.ingredient_column.to_sym => ingredient_value) end - it 'should be valid' do + it "should be valid" do expect(essence).to be_valid end end end - context 'where the value is false' do + context "where the value is false" do before do - allow(essence).to receive(:definition).and_return({'validate' => [{'presence' => false}]}) + allow(essence).to receive(:definition).and_return({"validate" => [{"presence" => false}]}) end - it 'should be valid' do + it "should be valid" do expect(essence).to be_valid end end end end - describe 'uniqueness' do + describe "uniqueness" do before do allow(essence).to receive(:element).and_return(FactoryBot.build_stubbed(:alchemy_element)) essence.update(essence.ingredient_column.to_sym => ingredient_value) end - context 'with string given as validation type' do + context "with string given as validation type" do before do - expect(essence).to receive(:definition).at_least(:once).and_return({'validate' => ['uniqueness']}) + expect(essence).to receive(:definition).at_least(:once).and_return({"validate" => ["uniqueness"]}) end - context 'when a duplicate exists' do + context "when a duplicate exists" do before do allow(essence).to receive(:duplicates).and_return([essence.dup]) end - it 'should not be valid' do + it "should not be valid" do expect(essence).to_not be_valid end - context 'when validated essence is not public' do + context "when validated essence is not public" do before do expect(essence).to receive(:public?).and_return(false) end - it 'should be valid' do + it "should be valid" do expect(essence).to be_valid end end end - context 'when no duplicate exists' do + context "when no duplicate exists" do before do expect(essence).to receive(:duplicates).and_return([]) end - it 'should be valid' do + it "should be valid" do expect(essence).to be_valid end end end - context 'with hash given as validation type' do - context 'where the value is true' do + context "with hash given as validation type" do + context "where the value is true" do before do - expect(essence).to receive(:definition).at_least(:once).and_return({'validate' => [{'uniqueness' => true}]}) + expect(essence).to receive(:definition).at_least(:once).and_return({"validate" => [{"uniqueness" => true}]}) end - context 'when a duplicate exists' do + context "when a duplicate exists" do before do allow(essence).to receive(:duplicates).and_return([essence.dup]) end - it 'should not be valid' do + it "should not be valid" do expect(essence).to_not be_valid end - context 'when validated essence is not public' do + context "when validated essence is not public" do before do expect(essence).to receive(:public?).and_return(false) end - it 'should be valid' do + it "should be valid" do expect(essence).to be_valid end end end - context 'when no duplicate exists' do + context "when no duplicate exists" do before do expect(essence).to receive(:duplicates).and_return([]) end - it 'should be valid' do + it "should be valid" do expect(essence).to be_valid end end end - context 'where the value is false' do + context "where the value is false" do before do - allow(essence).to receive(:definition).and_return({'validate' => [{'uniqueness' => false}]}) + allow(essence).to receive(:definition).and_return({"validate" => [{"uniqueness" => false}]}) end - it 'should be valid' do + it "should be valid" do expect(essence).to be_valid end end end end - describe '#acts_as_essence?' do - it 'should return true' do + describe "#acts_as_essence?" do + it "should return true" do expect(essence.acts_as_essence?).to be_truthy end end end - context 'delegations' do + context "delegations" do it { should delegate_method(:restricted?).to(:page) } it { should delegate_method(:trashed?).to(:element) } it { should delegate_method(:public?).to(:element) } end - describe 'essence relations' do + describe "essence relations" do let(:page) { FactoryBot.create(:alchemy_page, :restricted) } let(:element) { FactoryBot.create(:alchemy_element) } diff --git a/lib/alchemy/test_support/factories/attachment_factory.rb b/lib/alchemy/test_support/factories/attachment_factory.rb index 515712ef07..085cf90938 100644 --- a/lib/alchemy/test_support/factories/attachment_factory.rb +++ b/lib/alchemy/test_support/factories/attachment_factory.rb @@ -1,13 +1,13 @@ # frozen_string_literal: true -require 'factory_bot' +require "factory_bot" FactoryBot.define do - factory :alchemy_attachment, class: 'Alchemy::Attachment' do + factory :alchemy_attachment, class: "Alchemy::Attachment" do file do - File.new(Alchemy::Engine.root.join('lib', 'alchemy', 'test_support', 'fixtures', 'image.png')) + File.new(Alchemy::Engine.root.join("lib", "alchemy", "test_support", "fixtures", "image.png")) end - name { 'image' } - file_name { 'image.png' } + name { "image" } + file_name { "image.png" } end end diff --git a/lib/alchemy/test_support/factories/content_factory.rb b/lib/alchemy/test_support/factories/content_factory.rb index 3c5ac27700..44ab890c67 100644 --- a/lib/alchemy/test_support/factories/content_factory.rb +++ b/lib/alchemy/test_support/factories/content_factory.rb @@ -1,13 +1,13 @@ # frozen_string_literal: true -require 'factory_bot' -require 'alchemy/test_support/factories/element_factory' -require 'alchemy/test_support/factories/essence_file_factory' -require 'alchemy/test_support/factories/essence_picture_factory' -require 'alchemy/test_support/factories/essence_text_factory' +require "factory_bot" +require "alchemy/test_support/factories/element_factory" +require "alchemy/test_support/factories/essence_file_factory" +require "alchemy/test_support/factories/essence_picture_factory" +require "alchemy/test_support/factories/essence_text_factory" FactoryBot.define do - factory :alchemy_content, class: 'Alchemy::Content' do + factory :alchemy_content, class: "Alchemy::Content" do name { "text" } essence_type { "Alchemy::EssenceText" } association :essence, factory: :alchemy_essence_text diff --git a/lib/alchemy/test_support/factories/dummy_user_factory.rb b/lib/alchemy/test_support/factories/dummy_user_factory.rb index a06ecbfc0f..0b40c47df4 100644 --- a/lib/alchemy/test_support/factories/dummy_user_factory.rb +++ b/lib/alchemy/test_support/factories/dummy_user_factory.rb @@ -1,23 +1,23 @@ # frozen_string_literal: true -require 'factory_bot' +require "factory_bot" FactoryBot.define do - factory :alchemy_dummy_user, class: 'DummyUser' do + factory :alchemy_dummy_user, class: "DummyUser" do sequence(:email) { |n| "john.#{n}@doe.com" } - password { 's3cr3t' } - alchemy_roles { ['member'] } + password { "s3cr3t" } + alchemy_roles { ["member"] } trait :as_admin do - alchemy_roles { ['admin'] } + alchemy_roles { ["admin"] } end trait :as_author do - alchemy_roles { ['author'] } + alchemy_roles { ["author"] } end trait :as_editor do - alchemy_roles { ['editor'] } + alchemy_roles { ["editor"] } end end end diff --git a/lib/alchemy/test_support/factories/element_factory.rb b/lib/alchemy/test_support/factories/element_factory.rb index 1ef960c0af..8140b6d3e8 100644 --- a/lib/alchemy/test_support/factories/element_factory.rb +++ b/lib/alchemy/test_support/factories/element_factory.rb @@ -1,22 +1,22 @@ # frozen_string_literal: true -require 'factory_bot' -require 'alchemy/test_support/factories/page_factory' +require "factory_bot" +require "alchemy/test_support/factories/page_factory" FactoryBot.define do - factory :alchemy_element, class: 'Alchemy::Element' do - name { 'article' } + factory :alchemy_element, class: "Alchemy::Element" do + name { "article" } autogenerate_contents { false } association :page, factory: :alchemy_page trait :fixed do fixed { true } - name { 'right_column' } + name { "right_column" } end trait :unique do unique { true } - name { 'header' } + name { "header" } end trait :trashed do @@ -26,12 +26,12 @@ end trait :with_nestable_elements do - name { 'slider' } + name { "slider" } end trait :nested do - association :parent_element, factory: :alchemy_element, name: 'slider' - name { 'slide' } + association :parent_element, factory: :alchemy_element, name: "slider" + name { "slide" } end trait :with_contents do diff --git a/lib/alchemy/test_support/factories/essence_file_factory.rb b/lib/alchemy/test_support/factories/essence_file_factory.rb index aaf38558f6..aaf1b425f5 100644 --- a/lib/alchemy/test_support/factories/essence_file_factory.rb +++ b/lib/alchemy/test_support/factories/essence_file_factory.rb @@ -1,10 +1,10 @@ # frozen_string_literal: true -require 'factory_bot' -require 'alchemy/test_support/factories/attachment_factory' +require "factory_bot" +require "alchemy/test_support/factories/attachment_factory" FactoryBot.define do - factory :alchemy_essence_file, class: 'Alchemy::EssenceFile' do + factory :alchemy_essence_file, class: "Alchemy::EssenceFile" do attachment factory: :alchemy_attachment end end diff --git a/lib/alchemy/test_support/factories/essence_page_factory.rb b/lib/alchemy/test_support/factories/essence_page_factory.rb index ce346ad9e0..ad4b7a2494 100644 --- a/lib/alchemy/test_support/factories/essence_page_factory.rb +++ b/lib/alchemy/test_support/factories/essence_page_factory.rb @@ -1,10 +1,10 @@ # frozen_string_literal: true -require 'factory_bot' -require 'alchemy/test_support/factories/page_factory' +require "factory_bot" +require "alchemy/test_support/factories/page_factory" FactoryBot.define do - factory :alchemy_essence_page, class: 'Alchemy::EssencePage' do + factory :alchemy_essence_page, class: "Alchemy::EssencePage" do page factory: :alchemy_page end end diff --git a/lib/alchemy/test_support/factories/essence_picture_factory.rb b/lib/alchemy/test_support/factories/essence_picture_factory.rb index 2337815a8b..267f2bac45 100644 --- a/lib/alchemy/test_support/factories/essence_picture_factory.rb +++ b/lib/alchemy/test_support/factories/essence_picture_factory.rb @@ -1,11 +1,11 @@ # frozen_string_literal: true -require 'factory_bot' -require 'alchemy/test_support/factories/content_factory' -require 'alchemy/test_support/factories/picture_factory' +require "factory_bot" +require "alchemy/test_support/factories/content_factory" +require "alchemy/test_support/factories/picture_factory" FactoryBot.define do - factory :alchemy_essence_picture, class: 'Alchemy::EssencePicture' do + factory :alchemy_essence_picture, class: "Alchemy::EssencePicture" do picture factory: :alchemy_picture trait :with_content do diff --git a/lib/alchemy/test_support/factories/essence_text_factory.rb b/lib/alchemy/test_support/factories/essence_text_factory.rb index 6472895cc7..4982cccebb 100644 --- a/lib/alchemy/test_support/factories/essence_text_factory.rb +++ b/lib/alchemy/test_support/factories/essence_text_factory.rb @@ -1,9 +1,9 @@ # frozen_string_literal: true -require 'factory_bot' +require "factory_bot" FactoryBot.define do - factory :alchemy_essence_text, class: 'Alchemy::EssenceText' do - body { 'This is a headline' } + factory :alchemy_essence_text, class: "Alchemy::EssenceText" do + body { "This is a headline" } end end diff --git a/lib/alchemy/test_support/factories/language_factory.rb b/lib/alchemy/test_support/factories/language_factory.rb index 3668e42851..8255b2c665 100644 --- a/lib/alchemy/test_support/factories/language_factory.rb +++ b/lib/alchemy/test_support/factories/language_factory.rb @@ -1,31 +1,31 @@ # frozen_string_literal: true -require 'factory_bot' -require 'alchemy/test_support/factories/site_factory' +require "factory_bot" +require "alchemy/test_support/factories/site_factory" FactoryBot.define do - factory :alchemy_language, class: 'Alchemy::Language' do - name { 'Deutsch' } - code { 'de' } + factory :alchemy_language, class: "Alchemy::Language" do + name { "Deutsch" } + code { "de" } default { true } - frontpage_name { 'Intro' } - page_layout { Alchemy::Config.get(:default_language)['page_layout'] } + frontpage_name { "Intro" } + page_layout { Alchemy::Config.get(:default_language)["page_layout"] } public { true } site { Alchemy::Site.default || create(:alchemy_site, :default) } trait :klingon do - name { 'Klingon' } - code { 'kl' } - frontpage_name { 'Tuq' } + name { "Klingon" } + code { "kl" } + frontpage_name { "Tuq" } default { false } end trait :english do - name { 'English' } - code { 'en' } - frontpage_name { 'Intro' } + name { "English" } + code { "en" } + frontpage_name { "Intro" } default { false } end end diff --git a/lib/alchemy/test_support/factories/node_factory.rb b/lib/alchemy/test_support/factories/node_factory.rb index bedc16e046..13cc1292ea 100644 --- a/lib/alchemy/test_support/factories/node_factory.rb +++ b/lib/alchemy/test_support/factories/node_factory.rb @@ -1,14 +1,14 @@ # frozen_string_literal: true -require 'factory_bot' -require 'alchemy/test_support/factories/language_factory' -require 'alchemy/test_support/factories/page_factory' +require "factory_bot" +require "alchemy/test_support/factories/language_factory" +require "alchemy/test_support/factories/page_factory" FactoryBot.define do - factory :alchemy_node, class: 'Alchemy::Node' do + factory :alchemy_node, class: "Alchemy::Node" do site { Alchemy::Site.default || create(:alchemy_site) } language { Alchemy::Language.default || create(:alchemy_language) } - name { 'A Node' } + name { "A Node" } trait :with_page do association :page, factory: :alchemy_page @@ -16,7 +16,7 @@ end trait :with_url do - url { 'https://example.com' } + url { "https://example.com" } end end end diff --git a/lib/alchemy/test_support/factories/page_factory.rb b/lib/alchemy/test_support/factories/page_factory.rb index 03c6f0aa08..5c16324bd6 100644 --- a/lib/alchemy/test_support/factories/page_factory.rb +++ b/lib/alchemy/test_support/factories/page_factory.rb @@ -1,10 +1,10 @@ # frozen_string_literal: true -require 'factory_bot' -require 'alchemy/test_support/factories/language_factory' +require "factory_bot" +require "alchemy/test_support/factories/language_factory" FactoryBot.define do - factory :alchemy_page, class: 'Alchemy::Page' do + factory :alchemy_page, class: "Alchemy::Page" do language { Alchemy::Language.default || FactoryBot.create(:alchemy_language) } sequence(:name) { |n| "A Page #{n}" } page_layout { "standard" } @@ -19,14 +19,14 @@ autogenerate_elements { false } trait :root do - name { 'Root' } + name { "Root" } language { nil } parent_id { nil } page_layout { nil } end trait :language_root do - name { 'Startseite' } + name { "Startseite" } page_layout { language.page_layout } language_root { true } public_on { Time.current } diff --git a/lib/alchemy/test_support/factories/picture_factory.rb b/lib/alchemy/test_support/factories/picture_factory.rb index bdcf6c323b..881cf83c21 100644 --- a/lib/alchemy/test_support/factories/picture_factory.rb +++ b/lib/alchemy/test_support/factories/picture_factory.rb @@ -1,14 +1,14 @@ # frozen_string_literal: true -require 'factory_bot' +require "factory_bot" FactoryBot.define do - factory :alchemy_picture, class: 'Alchemy::Picture' do + factory :alchemy_picture, class: "Alchemy::Picture" do image_file do - File.new(Alchemy::Engine.root.join('lib', 'alchemy', 'test_support', 'fixtures', 'image.png')) + File.new(Alchemy::Engine.root.join("lib", "alchemy", "test_support", "fixtures", "image.png")) end - name { 'image' } - image_file_name { 'image.png' } + name { "image" } + image_file_name { "image.png" } upload_hash { Time.current.hash } end end diff --git a/lib/alchemy/test_support/factories/site_factory.rb b/lib/alchemy/test_support/factories/site_factory.rb index 834318090d..5d848fd010 100644 --- a/lib/alchemy/test_support/factories/site_factory.rb +++ b/lib/alchemy/test_support/factories/site_factory.rb @@ -1,17 +1,17 @@ # frozen_string_literal: true -require 'factory_bot' +require "factory_bot" FactoryBot.define do - factory :alchemy_site, class: 'Alchemy::Site' do - name { 'A Site' } - host { 'domain.com' } + factory :alchemy_site, class: "Alchemy::Site" do + name { "A Site" } + host { "domain.com" } trait :default do public { true } - name { Alchemy::Config.get(:default_site)['name'] } - host { Alchemy::Config.get(:default_site)['host'] } + name { Alchemy::Config.get(:default_site)["name"] } + host { Alchemy::Config.get(:default_site)["host"] } end trait :public do diff --git a/lib/alchemy/test_support/shared_contexts.rb b/lib/alchemy/test_support/shared_contexts.rb index c9bafc7d7d..6946f87a50 100644 --- a/lib/alchemy/test_support/shared_contexts.rb +++ b/lib/alchemy/test_support/shared_contexts.rb @@ -1,15 +1,15 @@ # frozen_string_literal: true -RSpec.shared_context 'with invalid file' do +RSpec.shared_context "with invalid file" do let(:invalid_file) do fixture_file_upload( - File.expand_path('../../../spec/fixtures/users.yml', __dir__), - 'text/x-yaml', + File.expand_path("../../../spec/fixtures/users.yml", __dir__), + "text/x-yaml", ) end before do allow(Alchemy::Attachment).to receive(:allowed_filetypes) do - ['png'] + ["png"] end end end diff --git a/lib/alchemy/test_support/shared_uploader_examples.rb b/lib/alchemy/test_support/shared_uploader_examples.rb index f35d5249c7..563d269727 100644 --- a/lib/alchemy/test_support/shared_uploader_examples.rb +++ b/lib/alchemy/test_support/shared_uploader_examples.rb @@ -2,10 +2,10 @@ RSpec.shared_examples_for "having a json uploader error message" do it "renders json response with error message" do subject - expect(response.media_type).to eq('application/json') + expect(response.media_type).to eq("application/json") expect(response.status).to eq(422) json = JSON.parse(response.body) - expect(json).to have_key('growl_message') - expect(json).to have_key('files') + expect(json).to have_key("growl_message") + expect(json).to have_key("files") end end diff --git a/lib/alchemy/tinymce.rb b/lib/alchemy/tinymce.rb index f8c647f401..27f3862187 100644 --- a/lib/alchemy/tinymce.rb +++ b/lib/alchemy/tinymce.rb @@ -6,22 +6,22 @@ module Tinymce @@plugins = %w(alchemy_link anchor autoresize charmap code directionality fullscreen hr link lists paste tabfocus table) @@init = { - skin: 'alchemy', - width: 'auto', + skin: "alchemy", + width: "auto", resize: true, - autoresize_min_height: '105', - autoresize_max_height: '480', + autoresize_min_height: "105", + autoresize_max_height: "480", menubar: false, statusbar: true, toolbar: [ - 'bold italic underline | strikethrough subscript superscript | numlist bullist indent outdent | removeformat | fullscreen', - 'pastetext charmap hr | undo redo | alchemy_link unlink anchor | code', + "bold italic underline | strikethrough subscript superscript | numlist bullist indent outdent | removeformat | fullscreen", + "pastetext charmap hr | undo redo | alchemy_link unlink anchor | code", ], fix_list_elements: true, convert_urls: false, - entity_encoding: 'raw', + entity_encoding: "raw", paste_as_text: true, - element_format: 'html', + element_format: "html", branding: false, } @@ -42,14 +42,14 @@ def custom_config_contents(page) def content_definitions_from_elements(definitions) definitions.collect do |el| - next if el['contents'].blank? + next if el["contents"].blank? - contents = el['contents'].select do |c| - c['settings'] && c['settings']['tinymce'].is_a?(Hash) + contents = el["contents"].select do |c| + c["settings"] && c["settings"]["tinymce"].is_a?(Hash) end next if contents.blank? - contents.map { |c| c.merge('element' => el['name']) } + contents.map { |c| c.merge("element" => el["name"]) } end.flatten.compact end end diff --git a/lib/alchemy/upgrader.rb b/lib/alchemy/upgrader.rb index 7d628ad41e..fa32620c51 100644 --- a/lib/alchemy/upgrader.rb +++ b/lib/alchemy/upgrader.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true -require 'alchemy/shell' +require "alchemy/shell" module Alchemy class Upgrader @@ -10,18 +10,18 @@ class Upgrader class << self def copy_new_config_file desc "Copy configuration file." - config_file = Rails.root.join('config/alchemy/config.yml') - default_config = File.join(File.dirname(__FILE__), '../../config/alchemy/config.yml') + config_file = Rails.root.join("config/alchemy/config.yml") + default_config = File.join(File.dirname(__FILE__), "../../config/alchemy/config.yml") if !File.exist? config_file log "No configuration file found. Creating it." - FileUtils.cp default_config, Rails.root.join('config/alchemy/config.yml') + FileUtils.cp default_config, Rails.root.join("config/alchemy/config.yml") elsif FileUtils.identical? default_config, config_file log "Configuration file already present.", :skip else log "Custom configuration file found." - FileUtils.cp default_config, Rails.root.join('config/alchemy/config.yml.defaults') + FileUtils.cp default_config, Rails.root.join("config/alchemy/config.yml.defaults") log "Copied new default configuration file." - todo "Check the default configuration file (./config/alchemy/config.yml.defaults) for new configuration options and insert them into your config file.", 'Configuration has changed' + todo "Check the default configuration file (./config/alchemy/config.yml.defaults) for new configuration options and insert them into your config file.", "Configuration has changed" end end end diff --git a/lib/alchemy/upgrader/five_point_zero.rb b/lib/alchemy/upgrader/five_point_zero.rb index 9cbaff7c13..6ddcc6d2b6 100644 --- a/lib/alchemy/upgrader/five_point_zero.rb +++ b/lib/alchemy/upgrader/five_point_zero.rb @@ -1,12 +1,12 @@ # frozen_string_literal: true -require_relative 'tasks/harden_gutentag_migrations' +require_relative "tasks/harden_gutentag_migrations" module Alchemy class Upgrader::FivePointZero < Upgrader class << self def install_gutentag_migrations - desc 'Install Gutentag migrations' + desc "Install Gutentag migrations" `bundle exec rake gutentag:install:migrations` Alchemy::Upgrader::Tasks::HardenGutentagMigrations.new.patch_migrations `bundle exec rake db:migrate` diff --git a/lib/alchemy/upgrader/four_point_four.rb b/lib/alchemy/upgrader/four_point_four.rb index 85525df828..b7aca620ca 100644 --- a/lib/alchemy/upgrader/four_point_four.rb +++ b/lib/alchemy/upgrader/four_point_four.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require_relative 'tasks/element_views_updater' +require_relative "tasks/element_views_updater" module Alchemy class Upgrader::FourPointFour < Upgrader @@ -11,7 +11,7 @@ def rename_element_views end def update_local_variable - desc 'Update element views local variable to element name.' + desc "Update element views local variable to element name." Alchemy::Upgrader::Tasks::ElementViewsUpdater.new.update_local_variable end @@ -45,7 +45,7 @@ def alchemy_4_4_todos The former `element` variable is still present, though. NOTE - todo notice, 'Alchemy v4.4 TODO' + todo notice, "Alchemy v4.4 TODO" end end end diff --git a/lib/alchemy/upgrader/tasks/element_views_updater.rb b/lib/alchemy/upgrader/tasks/element_views_updater.rb index dbb0c6ab13..8ca26465f6 100644 --- a/lib/alchemy/upgrader/tasks/element_views_updater.rb +++ b/lib/alchemy/upgrader/tasks/element_views_updater.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'alchemy/upgrader' +require "alchemy/upgrader" module Alchemy::Upgrader::Tasks class ElementViewsUpdater < Thor @@ -11,14 +11,14 @@ def rename_element_views puts "-- Removing '_view' suffix from element views" Dir.glob("#{elements_view_folder}/*_view.*").each do |file| - FileUtils.mv(file, file.to_s.sub(/_view/, '')) + FileUtils.mv(file, file.to_s.sub(/_view/, "")) end end def update_local_variable puts "-- Updating element views local variable to element name" - Alchemy::Element.definitions.map { |e| e['name'] }.each do |name| + Alchemy::Element.definitions.map { |e| e["name"] }.each do |name| view = Dir.glob("#{elements_view_folder}/_#{name}.*").last gsub_file(view, /\b#{name}_view\b/, name) end @@ -28,7 +28,7 @@ def update_local_variable private def elements_view_folder - Rails.root.join('app', 'views', 'alchemy', 'elements') + Rails.root.join("app", "views", "alchemy", "elements") end end end diff --git a/lib/alchemy/upgrader/tasks/harden_gutentag_migrations.rb b/lib/alchemy/upgrader/tasks/harden_gutentag_migrations.rb index 53e8b9abd8..b8533a05d4 100644 --- a/lib/alchemy/upgrader/tasks/harden_gutentag_migrations.rb +++ b/lib/alchemy/upgrader/tasks/harden_gutentag_migrations.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'thor' +require "thor" module Alchemy::Upgrader::Tasks class HardenGutentagMigrations < Thor @@ -10,14 +10,14 @@ class HardenGutentagMigrations < Thor def patch_migrations sentinel = /def up/ - migration_file = Dir.glob('db/migrate/*_gutentag_tables.gutentag.rb').first + migration_file = Dir.glob("db/migrate/*_gutentag_tables.gutentag.rb").first if migration_file inject_into_file migration_file, "\n # inserted by Alchemy CMS upgrader\n return if table_exists?(:gutentag_taggings)\n", { after: sentinel, verbose: true } end - migration_file = Dir.glob('db/migrate/*_gutentag_cache_counter.gutentag.rb').first + migration_file = Dir.glob("db/migrate/*_gutentag_cache_counter.gutentag.rb").first if migration_file inject_into_file migration_file, "\n # inserted by Alchemy CMS upgrader\n return if column_exists?(:gutentag_tags, :taggings_count)\n", diff --git a/lib/alchemy/webpacker.rb b/lib/alchemy/webpacker.rb index b7ac15027d..1194e75112 100644 --- a/lib/alchemy/webpacker.rb +++ b/lib/alchemy/webpacker.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require 'webpacker' -require 'webpacker/instance' +require "webpacker" +require "webpacker/instance" module Alchemy def self.webpacker diff --git a/lib/alchemy_cms.rb b/lib/alchemy_cms.rb index 6259ff6d92..2d34ab5c6b 100644 --- a/lib/alchemy_cms.rb +++ b/lib/alchemy_cms.rb @@ -6,59 +6,59 @@ module Alchemy end # Require globally used external libraries -require 'acts_as_list' -require 'action_view/dependency_tracker' -require 'active_model_serializers' -require 'awesome_nested_set' -require 'cancan' -require 'dragonfly' -require 'gutentag' -require 'handlebars_assets' -require 'jquery-rails' -require 'jquery-ui-rails' -require 'kaminari' -require 'non-stupid-digest-assets' -require 'ransack' -require 'request_store' -require 'responders' -require 'sassc-rails' -require 'simple_form' -require 'select2-rails' -require 'turbolinks' -require 'userstamp' +require "acts_as_list" +require "action_view/dependency_tracker" +require "active_model_serializers" +require "awesome_nested_set" +require "cancan" +require "dragonfly" +require "gutentag" +require "handlebars_assets" +require "jquery-rails" +require "jquery-ui-rails" +require "kaminari" +require "non-stupid-digest-assets" +require "ransack" +require "request_store" +require "responders" +require "sassc-rails" +require "simple_form" +require "select2-rails" +require "turbolinks" +require "userstamp" # Require globally used Alchemy mixins -require_relative 'alchemy/ability_helper' -require_relative 'alchemy/admin/locale' -require_relative 'alchemy/auth_accessors' -require_relative 'alchemy/cache_digests/template_tracker' -require_relative 'alchemy/config' -require_relative 'alchemy/configuration_methods' -require_relative 'alchemy/controller_actions' -require_relative 'alchemy/deprecation' -require_relative 'alchemy/elements_finder' -require_relative 'alchemy/errors' -require_relative 'alchemy/essence' -require_relative 'alchemy/filetypes' -require_relative 'alchemy/forms/builder' -require_relative 'alchemy/hints' -require_relative 'alchemy/i18n' -require_relative 'alchemy/logger' -require_relative 'alchemy/modules' -require_relative 'alchemy/name_conversions' -require_relative 'alchemy/on_page_layout' -require_relative 'alchemy/on_page_layout/callbacks_runner' -require_relative 'alchemy/page_layout' -require_relative 'alchemy/paths' -require_relative 'alchemy/permissions' -require_relative 'alchemy/ssl_protection' -require_relative 'alchemy/resource' -require_relative 'alchemy/tinymce' -require_relative 'alchemy/taggable' -require_relative 'alchemy/webpacker' +require_relative "alchemy/ability_helper" +require_relative "alchemy/admin/locale" +require_relative "alchemy/auth_accessors" +require_relative "alchemy/cache_digests/template_tracker" +require_relative "alchemy/config" +require_relative "alchemy/configuration_methods" +require_relative "alchemy/controller_actions" +require_relative "alchemy/deprecation" +require_relative "alchemy/elements_finder" +require_relative "alchemy/errors" +require_relative "alchemy/essence" +require_relative "alchemy/filetypes" +require_relative "alchemy/forms/builder" +require_relative "alchemy/hints" +require_relative "alchemy/i18n" +require_relative "alchemy/logger" +require_relative "alchemy/modules" +require_relative "alchemy/name_conversions" +require_relative "alchemy/on_page_layout" +require_relative "alchemy/on_page_layout/callbacks_runner" +require_relative "alchemy/page_layout" +require_relative "alchemy/paths" +require_relative "alchemy/permissions" +require_relative "alchemy/ssl_protection" +require_relative "alchemy/resource" +require_relative "alchemy/tinymce" +require_relative "alchemy/taggable" +require_relative "alchemy/webpacker" # Require hacks -require_relative 'kaminari/scoped_pagination_url_helper' +require_relative "kaminari/scoped_pagination_url_helper" # Finally require Alchemy itself -require_relative 'alchemy/engine' +require_relative "alchemy/engine" diff --git a/lib/rails/generators/alchemy/base.rb b/lib/rails/generators/alchemy/base.rb index 43c3c1811a..0074ac243e 100644 --- a/lib/rails/generators/alchemy/base.rb +++ b/lib/rails/generators/alchemy/base.rb @@ -1,15 +1,15 @@ # frozen_string_literal: true -require 'rails' +require "rails" module Alchemy module Generators class Base < ::Rails::Generators::Base - class_option :template_engine, type: :string, aliases: '-e', desc: 'Template engine for the views. Available options are "erb", "haml", and "slim".' + class_option :template_engine, type: :string, aliases: "-e", desc: 'Template engine for the views. Available options are "erb", "haml", and "slim".' private def conditional_template(source, destination) - files = Dir.glob(destination.gsub(/\.([a-z]+)$/, '*')) + files = Dir.glob(destination.gsub(/\.([a-z]+)$/, "*")) if files.any? ext = File.extname(files.first)[1..-1] @@ -29,7 +29,7 @@ def template_engine # Rails is clever enough to default this to whatever template # engine is configured through its generator configuration, # but we'll default it to erb anyway, just in case. - options[:template_engine] || 'erb' + options[:template_engine] || "erb" end def load_alchemy_yaml(name) diff --git a/lib/rails/generators/alchemy/elements/elements_generator.rb b/lib/rails/generators/alchemy/elements/elements_generator.rb index e3c182dfda..94af08026a 100644 --- a/lib/rails/generators/alchemy/elements/elements_generator.rb +++ b/lib/rails/generators/alchemy/elements/elements_generator.rb @@ -1,14 +1,14 @@ # frozen_string_literal: true -require_relative '../base' +require_relative "../base" module Alchemy module Generators class ElementsGenerator < Base desc "This generator generates your elements view partials." - source_root File.expand_path('templates', __dir__) + source_root File.expand_path("templates", __dir__) def create_partials - @elements = load_alchemy_yaml('elements.yml') + @elements = load_alchemy_yaml("elements.yml") return unless @elements @elements.each do |element| @@ -17,7 +17,7 @@ def create_partials if element["name"] =~ /\A[a-z0-9_-]+\z/ @element_name = element["name"].underscore else - raise "Element name '#{element['name']}' has wrong format. Only lowercase and non whitespace characters allowed." + raise "Element name '#{element["name"]}' has wrong format. Only lowercase and non whitespace characters allowed." end conditional_template "view.html.#{template_engine}", "#{elements_dir}/_#{@element_name}.html.#{template_engine}" diff --git a/lib/rails/generators/alchemy/essence/essence_generator.rb b/lib/rails/generators/alchemy/essence/essence_generator.rb index 72688d8a4d..8946856ba8 100644 --- a/lib/rails/generators/alchemy/essence/essence_generator.rb +++ b/lib/rails/generators/alchemy/essence/essence_generator.rb @@ -1,16 +1,16 @@ # frozen_string_literal: true -require 'rails' +require "rails" module Alchemy module Generators class EssenceGenerator < ::Rails::Generators::Base desc "This generator generates an Alchemy essence for you." argument :essence_name, banner: "YourEssenceName" - source_root File.expand_path('templates', __dir__) + source_root File.expand_path("templates", __dir__) def init @essence_name = essence_name.underscore - @essence_view_path = 'app/views/alchemy/essences' + @essence_view_path = "app/views/alchemy/essences" end def create_model diff --git a/lib/rails/generators/alchemy/install/install_generator.rb b/lib/rails/generators/alchemy/install/install_generator.rb index 17598238ca..465f3a16e7 100644 --- a/lib/rails/generators/alchemy/install/install_generator.rb +++ b/lib/rails/generators/alchemy/install/install_generator.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true -require 'rails' +require "rails" module Alchemy module Generators @@ -11,7 +11,7 @@ class InstallGenerator < ::Rails::Generators::Base default: false, desc: "Skip creation of demo element, page and application layout." - source_root File.expand_path('files', __dir__) + source_root File.expand_path("files", __dir__) def copy_config copy_file "#{config_path}/config.yml", "config/alchemy/config.yml" @@ -52,13 +52,13 @@ def copy_dragonfly_config end def install_gutentag_migrations - rake 'gutentag:install:migrations' + rake "gutentag:install:migrations" end private def config_path - @_config_path ||= File.expand_path('../../../../../config/alchemy', __dir__) + @_config_path ||= File.expand_path("../../../../../config/alchemy", __dir__) end end end diff --git a/lib/rails/generators/alchemy/menus/menus_generator.rb b/lib/rails/generators/alchemy/menus/menus_generator.rb index 9545a1c138..3e0bfca40d 100644 --- a/lib/rails/generators/alchemy/menus/menus_generator.rb +++ b/lib/rails/generators/alchemy/menus/menus_generator.rb @@ -1,12 +1,12 @@ # frozen_string_literal: true -require_relative '../base' +require_relative "../base" module Alchemy module Generators class MenusGenerator < Base desc "This generator generates Alchemy menu partials." - source_root File.expand_path('templates', __dir__) + source_root File.expand_path("templates", __dir__) def create_partials menus = Alchemy::Node.available_menu_names diff --git a/lib/rails/generators/alchemy/module/module_generator.rb b/lib/rails/generators/alchemy/module/module_generator.rb index 7d6651b1c6..a2a08bcb16 100644 --- a/lib/rails/generators/alchemy/module/module_generator.rb +++ b/lib/rails/generators/alchemy/module/module_generator.rb @@ -1,12 +1,12 @@ # frozen_string_literal: true -require 'rails' +require "rails" module Alchemy module Generators class ModuleGenerator < ::Rails::Generators::Base desc "This generator generates an Alchemy module for you." argument :module_name, banner: "your_module_name" - source_root File.expand_path('templates', __dir__) + source_root File.expand_path("templates", __dir__) def init @module_name = module_name.downcase diff --git a/lib/rails/generators/alchemy/page_layouts/page_layouts_generator.rb b/lib/rails/generators/alchemy/page_layouts/page_layouts_generator.rb index 1ceb9ce2b1..d747a96c57 100644 --- a/lib/rails/generators/alchemy/page_layouts/page_layouts_generator.rb +++ b/lib/rails/generators/alchemy/page_layouts/page_layouts_generator.rb @@ -1,14 +1,14 @@ # frozen_string_literal: true -require_relative '../base' +require_relative "../base" module Alchemy module Generators class PageLayoutsGenerator < Base desc "This generator generates your page_layouts view partials." - source_root File.expand_path('templates', __dir__) + source_root File.expand_path("templates", __dir__) def create_partials - @page_layouts = load_alchemy_yaml('page_layouts.yml') + @page_layouts = load_alchemy_yaml("page_layouts.yml") return unless @page_layouts @page_layouts.each do |page_layout| diff --git a/lib/rails/generators/alchemy/site_layouts/site_layouts_generator.rb b/lib/rails/generators/alchemy/site_layouts/site_layouts_generator.rb index aba495be9d..0cf8f8d2a4 100644 --- a/lib/rails/generators/alchemy/site_layouts/site_layouts_generator.rb +++ b/lib/rails/generators/alchemy/site_layouts/site_layouts_generator.rb @@ -1,11 +1,11 @@ # frozen_string_literal: true -require_relative '../base' +require_relative "../base" module Alchemy module Generators class SiteLayoutsGenerator < Base desc "This generator generates your site layouts view partials." - source_root File.expand_path('templates', __dir__) + source_root File.expand_path("templates", __dir__) def create_partials @sites = Alchemy::Site.all diff --git a/lib/rails/generators/alchemy/views/views_generator.rb b/lib/rails/generators/alchemy/views/views_generator.rb index a9750a87ef..edb7952008 100644 --- a/lib/rails/generators/alchemy/views/views_generator.rb +++ b/lib/rails/generators/alchemy/views/views_generator.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true -require 'rails' +require "rails" module Alchemy module Generators @@ -22,17 +22,17 @@ class ViewsGenerator < ::Rails::Generators::Base def copy_alchemy_views views_to_copy.each do |dir| - directory dir, Rails.root.join('app/views/alchemy', dir) + directory dir, Rails.root.join("app/views/alchemy", dir) end end private def views_to_copy - if @options['except'] - ALCHEMY_VIEWS - @options['except'] - elsif @options['only'] - ALCHEMY_VIEWS.select { |v| @options['only'].include?(v) } + if @options["except"] + ALCHEMY_VIEWS - @options["except"] + elsif @options["only"] + ALCHEMY_VIEWS.select { |v| @options["only"].include?(v) } else ALCHEMY_VIEWS end diff --git a/lib/tasks/alchemy/db.rake b/lib/tasks/alchemy/db.rake index 298d4f3f47..d5c2b07af7 100644 --- a/lib/tasks/alchemy/db.rake +++ b/lib/tasks/alchemy/db.rake @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'alchemy/seeder' +require "alchemy/seeder" namespace :alchemy do namespace :db do diff --git a/lib/tasks/alchemy/install.rake b/lib/tasks/alchemy/install.rake index 06dcf7a8da..c84a2433cd 100644 --- a/lib/tasks/alchemy/install.rake +++ b/lib/tasks/alchemy/install.rake @@ -1,5 +1,5 @@ # frozen_string_literal: true -require 'thor' +require "thor" class Alchemy::InstallTask < Thor include Thor::Actions diff --git a/lib/tasks/alchemy/tidy.rake b/lib/tasks/alchemy/tidy.rake index 856ab588f4..29b390d026 100644 --- a/lib/tasks/alchemy/tidy.rake +++ b/lib/tasks/alchemy/tidy.rake @@ -1,13 +1,13 @@ # frozen_string_literal: true -require 'alchemy/tasks/tidy' +require "alchemy/tasks/tidy" namespace :alchemy do namespace :tidy do desc "Tidy up Alchemy database." task :up do - Rake::Task['alchemy:tidy:element_positions'].invoke - Rake::Task['alchemy:tidy:content_positions'].invoke - Rake::Task['alchemy:tidy:remove_orphaned_records'].invoke + Rake::Task["alchemy:tidy:element_positions"].invoke + Rake::Task["alchemy:tidy:content_positions"].invoke + Rake::Task["alchemy:tidy:remove_orphaned_records"].invoke end desc "Fixes element positions." @@ -22,8 +22,8 @@ namespace :alchemy do desc "Remove orphaned records (elements & contents)." task remove_orphaned_records: [:environment] do - Rake::Task['alchemy:tidy:remove_orphaned_elements'].invoke - Rake::Task['alchemy:tidy:remove_orphaned_contents'].invoke + Rake::Task["alchemy:tidy:remove_orphaned_elements"].invoke + Rake::Task["alchemy:tidy:remove_orphaned_contents"].invoke end desc "Remove orphaned elements." @@ -40,7 +40,7 @@ namespace :alchemy do task elements_usage: :environment do puts "\n" removable_elements = [] - names = Alchemy::Element.definitions.map { |e| e['name'] } + names = Alchemy::Element.definitions.map { |e| e["name"] } longest_name = names.max_by { |name| name.to_s.length }.length + 1 names.sort.each do |name| names = Alchemy::Element.where(name: name) @@ -49,7 +49,7 @@ namespace :alchemy do if count.zero? removable_elements.push(name) else - spacer = ' ' * (longest_name - name.length) + spacer = " " * (longest_name - name.length) puts "#{name}#{spacer}is used\t#{count}\ttime(s) on\t#{page_count}\tpublic page(s)" end end diff --git a/lib/tasks/alchemy/upgrade.rake b/lib/tasks/alchemy/upgrade.rake index ab1049b97c..5a499fbbcb 100644 --- a/lib/tasks/alchemy/upgrade.rake +++ b/lib/tasks/alchemy/upgrade.rake @@ -1,28 +1,28 @@ # frozen_string_literal: true -require 'alchemy/upgrader' -require 'alchemy/version' +require "alchemy/upgrader" +require "alchemy/version" namespace :alchemy do desc "Upgrades your app to AlchemyCMS v#{Alchemy::VERSION}." task upgrade: [ - 'alchemy:upgrade:prepare', + "alchemy:upgrade:prepare", ] do Alchemy::Upgrader.display_todos end namespace :upgrade do - desc 'Alchemy Upgrader: Prepares the database and updates Alchemys configuration file.' + desc "Alchemy Upgrader: Prepares the database and updates Alchemys configuration file." task prepare: [ - 'alchemy:upgrade:database', - 'alchemy:upgrade:config', + "alchemy:upgrade:database", + "alchemy:upgrade:config", ] desc "Alchemy Upgrader: Prepares the database." task database: [ - 'alchemy:upgrade:5.0:install_gutentag_migrations', - 'alchemy:install:migrations', - 'db:migrate', - 'alchemy:db:seed', + "alchemy:upgrade:5.0:install_gutentag_migrations", + "alchemy:install:migrations", + "db:migrate", + "alchemy:db:seed", ] desc "Alchemy Upgrader: Copy configuration file." @@ -30,15 +30,15 @@ namespace :alchemy do Alchemy::Upgrader.copy_new_config_file end - desc 'Upgrade Alchemy to v5.0' - task '5.0' => [ - 'alchemy:upgrade:prepare', + desc "Upgrade Alchemy to v5.0" + task "5.0" => [ + "alchemy:upgrade:prepare", ] do Alchemy::Upgrader.display_todos end - namespace '5.0' do - desc 'Install Gutentag migrations' + namespace "5.0" do + desc "Install Gutentag migrations" task install_gutentag_migrations: [:environment] do Alchemy::Upgrader::FivePointZero.install_gutentag_migrations end diff --git a/spec/controllers/alchemy/admin/base_controller_spec.rb b/spec/controllers/alchemy/admin/base_controller_spec.rb index 861319d2e9..cce76cd11a 100644 --- a/spec/controllers/alchemy/admin/base_controller_spec.rb +++ b/spec/controllers/alchemy/admin/base_controller_spec.rb @@ -1,38 +1,38 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" describe Alchemy::Admin::BaseController do - describe '#raise_exception?' do + describe "#raise_exception?" do subject { controller.send(:raise_exception?) } - context 'in test mode' do + context "in test mode" do before { expect(Rails.env).to receive(:test?).and_return true } it { is_expected.to be_truthy } end - context 'not in test mode' do + context "not in test mode" do before { expect(Rails.env).to receive(:test?).and_return false } it { is_expected.to be_falsey } - context 'and in page preview' do + context "and in page preview" do before { expect(controller).to receive(:is_page_preview?).and_return true } it { is_expected.to be_truthy } end - context 'and not in page preview' do + context "and not in page preview" do before { expect(controller).to receive(:is_page_preview?).and_return false } it { is_expected.to be_falsey } end end end - describe '#set_translation' do - context 'with unavailable locale in the session' do + describe "#set_translation" do + context "with unavailable locale in the session" do before do allow(I18n).to receive(:default_locale) { :es } allow(I18n).to receive(:available_locales) { [:es] } - allow(controller).to receive(:session) { { alchemy_locale: 'kl'} } + allow(controller).to receive(:session) { { alchemy_locale: "kl"} } end it "sets I18n.locale to the default locale" do @@ -42,27 +42,27 @@ end end - describe '#is_page_preview?' do + describe "#is_page_preview?" do subject { controller.send(:is_page_preview?) } it { is_expected.to be_falsey } - context 'is pages controller and show action' do + context "is pages controller and show action" do before do - expect(controller).to receive(:controller_path).and_return('alchemy/admin/pages') - expect(controller).to receive(:action_name).and_return('show') + expect(controller).to receive(:controller_path).and_return("alchemy/admin/pages") + expect(controller).to receive(:action_name).and_return("show") end it { is_expected.to be_truthy } end end - context 'when current_alchemy_user is present' do - let!(:page_1) { create(:alchemy_page, name: 'Page 1') } - let!(:page_2) { create(:alchemy_page, name: 'Page 2') } + context "when current_alchemy_user is present" do + let!(:page_1) { create(:alchemy_page, name: "Page 1") } + let!(:page_2) { create(:alchemy_page, name: "Page 2") } let(:user) { create(:alchemy_dummy_user, :as_admin) } - context 'and she has locked pages' do + context "and she has locked pages" do before do allow(controller).to receive(:current_alchemy_user) { user } [page_1, page_2].each_with_index do |p, i| @@ -70,9 +70,9 @@ end end - it 'loads locked pages ordered by locked_at date' do + it "loads locked pages ordered by locked_at date" do controller.send(:load_locked_pages) - expect(assigns(:locked_pages).pluck(:name)).to eq(['Page 2', 'Page 1']) + expect(assigns(:locked_pages).pluck(:name)).to eq(["Page 2", "Page 1"]) end end end diff --git a/spec/controllers/alchemy/admin/clipboard_controller_spec.rb b/spec/controllers/alchemy/admin/clipboard_controller_spec.rb index 09b90b81d5..c9f57d8dc7 100644 --- a/spec/controllers/alchemy/admin/clipboard_controller_spec.rb +++ b/spec/controllers/alchemy/admin/clipboard_controller_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" module Alchemy describe Admin::ClipboardController do @@ -15,47 +15,47 @@ module Alchemy session[:alchemy_clipboard] = {} end - describe '#index' do - context 'with `remarkable_type` being an allowed type' do - it 'is successful' do - get :index, params: {remarkable_type: 'elements'} + describe "#index" do + context "with `remarkable_type` being an allowed type" do + it "is successful" do + get :index, params: {remarkable_type: "elements"} expect(response).to be_successful end end - context 'with `remarkable_type` not an allowed type' do - it 'raises 400 Bad Request' do + context "with `remarkable_type` not an allowed type" do + it "raises 400 Bad Request" do expect { - get :index, params: {remarkable_type: 'evil'} + get :index, params: {remarkable_type: "evil"} }.to raise_error(ActionController::BadRequest) end end end - context 'for elements' do + context "for elements" do before do expect(Element).to receive(:find).and_return(element) end describe "#insert" do it "should hold element ids" do - post :insert, params: {remarkable_type: 'elements', remarkable_id: element.id}, xhr: true - expect(session[:alchemy_clipboard]['elements']).to eq([{'id' => element.id.to_s, 'action' => 'copy'}]) + post :insert, params: {remarkable_type: "elements", remarkable_id: element.id}, xhr: true + expect(session[:alchemy_clipboard]["elements"]).to eq([{"id" => element.id.to_s, "action" => "copy"}]) end it "should not have the same element twice" do - session[:alchemy_clipboard]['elements'] = [{'id' => element.id.to_s, 'action' => 'copy'}] - post :insert, params: {remarkable_type: 'elements', remarkable_id: element.id}, xhr: true - expect(session[:alchemy_clipboard]['elements'].collect { |e| e['id'] }).not_to eq([element.id, element.id]) + session[:alchemy_clipboard]["elements"] = [{"id" => element.id.to_s, "action" => "copy"}] + post :insert, params: {remarkable_type: "elements", remarkable_id: element.id}, xhr: true + expect(session[:alchemy_clipboard]["elements"].collect { |e| e["id"] }).not_to eq([element.id, element.id]) end end describe "#delete" do it "should remove element ids from clipboard" do - session[:alchemy_clipboard]['elements'] = [{'id' => element.id.to_s, 'action' => 'copy'}] - session[:alchemy_clipboard]['elements'] << {'id' => another_element.id.to_s, 'action' => 'copy'} - delete :remove, params: {remarkable_type: 'elements', remarkable_id: another_element.id}, xhr: true - expect(session[:alchemy_clipboard]['elements']).to eq([{'id' => element.id.to_s, 'action' => 'copy'}]) + session[:alchemy_clipboard]["elements"] = [{"id" => element.id.to_s, "action" => "copy"}] + session[:alchemy_clipboard]["elements"] << {"id" => another_element.id.to_s, "action" => "copy"} + delete :remove, params: {remarkable_type: "elements", remarkable_id: another_element.id}, xhr: true + expect(session[:alchemy_clipboard]["elements"]).to eq([{"id" => element.id.to_s, "action" => "copy"}]) end end end @@ -63,17 +63,17 @@ module Alchemy describe "#clear" do context "with elements as remarkable_type" do it "should clear the elements clipboard" do - session[:alchemy_clipboard]['elements'] = [{'id' => element.id.to_s}] - delete :clear, params: {remarkable_type: 'elements'}, xhr: true - expect(session[:alchemy_clipboard]['elements']).to be_empty + session[:alchemy_clipboard]["elements"] = [{"id" => element.id.to_s}] + delete :clear, params: {remarkable_type: "elements"}, xhr: true + expect(session[:alchemy_clipboard]["elements"]).to be_empty end end context "with pages as remarkable_type" do it "should clear the pages clipboard" do - session[:alchemy_clipboard]['pages'] = [{'id' => public_page.id.to_s}] - delete :clear, params: {remarkable_type: 'pages'}, xhr: true - expect(session[:alchemy_clipboard]['pages']).to be_empty + session[:alchemy_clipboard]["pages"] = [{"id" => public_page.id.to_s}] + delete :clear, params: {remarkable_type: "pages"}, xhr: true + expect(session[:alchemy_clipboard]["pages"]).to be_empty end end end diff --git a/spec/controllers/alchemy/admin/dashboard_controller_spec.rb b/spec/controllers/alchemy/admin/dashboard_controller_spec.rb index 6219396a0f..fb2861566c 100644 --- a/spec/controllers/alchemy/admin/dashboard_controller_spec.rb +++ b/spec/controllers/alchemy/admin/dashboard_controller_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" module Alchemy describe Admin::DashboardController do @@ -10,7 +10,7 @@ module Alchemy before { authorize_user(user) } - describe '#index' do + describe "#index" do before do allow(Page).to receive(:from_current_site).and_return( double( @@ -31,9 +31,9 @@ module Alchemy expect(assigns(:all_locked_pages)).to eq([]) end - context 'with user class having logged_in scope' do - context 'with other users online' do - let(:another_user) { mock_model('DummyUser') } + context "with user class having logged_in scope" do + context "with other users online" do + let(:another_user) { mock_model("DummyUser") } before do expect(Alchemy.user_class).to receive(:logged_in).and_return([another_user]) @@ -45,7 +45,7 @@ module Alchemy end end - context 'without other users online' do + context "without other users online" do it "does not assign @online_users" do get :index expect(assigns(:online_users)).to eq([]) @@ -53,7 +53,7 @@ module Alchemy end end - context 'user having signed in before' do + context "user having signed in before" do before do expect(user).to receive(:sign_in_count).and_return(5) expect(user).to receive(:last_sign_in_at).and_return(Time.current) @@ -71,21 +71,21 @@ module Alchemy end end - describe '#info' do + describe "#info" do it "assigns @alchemy_version with the current Alchemy version" do get :info expect(assigns(:alchemy_version)).to eq(Alchemy.version) end end - describe '#update_check' do + describe "#update_check" do before do WebMock.enable! end context "requesting rubygems.org" do before do - stub_request(:get, 'https://rubygems.org/api/v1/versions/alchemy_cms.json').to_return( + stub_request(:get, "https://rubygems.org/api/v1/versions/alchemy_cms.json").to_return( status: 200, body: '[{"number": "3.0.0.alpha"}, {"number": "2.6.0"}, {"number": "2.5.1"}]', ) end @@ -97,8 +97,8 @@ module Alchemy it "should render 'false'" do get :update_check - expect(response.code).to eq('200') - expect(response.body).to eq('false') + expect(response.code).to eq("200") + expect(response.body).to eq("false") end end @@ -109,16 +109,16 @@ module Alchemy it "should render 'true'" do get :update_check - expect(response.code).to eq('200') - expect(response.body).to eq('true') + expect(response.code).to eq("200") + expect(response.body).to eq("true") end end end context "if rubygems.org is unavailable" do before do - stub_request(:get, 'https://rubygems.org/api/v1/versions/alchemy_cms.json').to_return(status: 503) - stub_request(:get, 'https://api.github.com/repos/AlchemyCMS/alchemy_cms/tags').to_return( + stub_request(:get, "https://rubygems.org/api/v1/versions/alchemy_cms.json").to_return(status: 503) + stub_request(:get, "https://api.github.com/repos/AlchemyCMS/alchemy_cms/tags").to_return( status: 200, body: '[{"name": "v2.6.0"}, {"name": "v2.5.0"}]', ) allow(Alchemy).to receive(:version).and_return("2.6.2") @@ -126,8 +126,8 @@ module Alchemy it "should request github.com" do get :update_check - expect(response.code).to eq('200') - expect(response.body).to eq('false') + expect(response.code).to eq("200") + expect(response.body).to eq("false") end end @@ -138,7 +138,7 @@ module Alchemy it "should have status code 503" do get :update_check - expect(response.code).to eq('503') + expect(response.code).to eq("503") end end diff --git a/spec/controllers/alchemy/admin/elements_controller_spec.rb b/spec/controllers/alchemy/admin/elements_controller_spec.rb index b017cc78e4..b87b39b2e7 100644 --- a/spec/controllers/alchemy/admin/elements_controller_spec.rb +++ b/spec/controllers/alchemy/admin/elements_controller_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" module Alchemy describe Admin::ElementsController do @@ -13,14 +13,14 @@ module Alchemy before { authorize_user(:as_author) } - describe '#index' do + describe "#index" do let!(:alchemy_page) { create(:alchemy_page) } let!(:element) { create(:alchemy_element, page: alchemy_page) } let!(:trashed_element) { create(:alchemy_element, page: alchemy_page).tap(&:trash!) } let!(:nested_element) { create(:alchemy_element, :nested, page: alchemy_page) } let!(:hidden_element) { create(:alchemy_element, page: alchemy_page, public: false) } - context 'with fixed elements' do + context "with fixed elements" do let!(:fixed_element) do create(:alchemy_element, :fixed, page: alchemy_page) @@ -50,7 +50,7 @@ module Alchemy end end - describe '#order' do + describe "#order" do let(:element_1) { create(:alchemy_element) } let(:element_2) { create(:alchemy_element, page: page) } let(:element_3) { create(:alchemy_element, page: page) } @@ -62,8 +62,8 @@ module Alchemy expect(Element.all.pluck(:id)).to eq(element_ids) end - context 'with missing [:element_ids] param' do - it 'does not raise any error and silently rejects to order' do + context "with missing [:element_ids] param" do + it "does not raise any error and silently rejects to order" do expect { post :order, params: {page_id: page.id}, xhr: true }.to_not raise_error @@ -73,7 +73,7 @@ module Alchemy context "when nested inside parent element" do let(:parent) { create(:alchemy_element) } - it 'touches the cache key of parent element' do + it "touches the cache key of parent element" do expect(Element).to receive(:find_by) { parent } expect(parent).to receive(:touch) { true } post :order, params: { @@ -83,7 +83,7 @@ module Alchemy }, xhr: true end - it 'assigns parent element id to each element' do + it "assigns parent element id to each element" do post :order, params: { page_id: page.id, element_ids: element_ids, @@ -121,7 +121,7 @@ module Alchemy end end - describe '#new' do + describe "#new" do let(:alchemy_page) { build_stubbed(:alchemy_page) } before do @@ -135,9 +135,9 @@ module Alchemy context "with elements in clipboard" do let(:element) { build_stubbed(:alchemy_element) } - let(:clipboard_items) { [{'id' => element.id.to_s, 'action' => 'copy'}] } + let(:clipboard_items) { [{"id" => element.id.to_s, "action" => "copy"}] } - before { clipboard['elements'] = clipboard_items } + before { clipboard["elements"] = clipboard_items } it "should load all elements from clipboard" do expect(Element).to receive(:all_from_clipboard_for_page).and_return(clipboard_items) @@ -147,29 +147,29 @@ module Alchemy end end - describe '#create' do - describe 'insertion position' do + describe "#create" do + describe "insertion position" do before { element } it "should insert the element at bottom of list" do - post :create, params: {element: {name: 'news', page_id: alchemy_page.id}}, xhr: true + post :create, params: {element: {name: "news", page_id: alchemy_page.id}}, xhr: true expect(alchemy_page.elements.count).to eq(2) - expect(alchemy_page.elements.last.name).to eq('news') + expect(alchemy_page.elements.last.name).to eq("news") end context "on a page with a setting for insert_elements_at of top" do before do expect(PageLayout).to receive(:get).at_least(:once).and_return({ - 'name' => 'news', - 'elements' => ['news'], - 'insert_elements_at' => 'top', + "name" => "news", + "elements" => ["news"], + "insert_elements_at" => "top", }) end it "should insert the element at top of list" do - post :create, params: {element: {name: 'news', page_id: alchemy_page.id}}, xhr: true + post :create, params: {element: {name: "news", page_id: alchemy_page.id}}, xhr: true expect(alchemy_page.elements.count).to eq(2) - expect(alchemy_page.elements.first.name).to eq('news') + expect(alchemy_page.elements.first.name).to eq("news") end end end @@ -178,7 +178,7 @@ module Alchemy let(:parent_element) { create(:alchemy_element, :with_nestable_elements, page: alchemy_page) } it "creates the element in the parent element" do - post :create, params: {element: {name: 'slide', page_id: alchemy_page.id, parent_element_id: parent_element.id}}, xhr: true + post :create, params: {element: {name: "slide", page_id: alchemy_page.id, parent_element_id: parent_element.id}}, xhr: true expect(Alchemy::Element.last.parent_element_id).to eq(parent_element.id) end end @@ -187,7 +187,7 @@ module Alchemy render_views before do - clipboard['elements'] = [{'id' => element_in_clipboard.id.to_s, 'action' => 'cut'}] + clipboard["elements"] = [{"id" => element_in_clipboard.id.to_s, "action" => "cut"}] end it "should create an element from clipboard" do @@ -199,7 +199,7 @@ module Alchemy context "and with cut as action parameter" do it "should also remove the element id from clipboard" do post :create, params: {paste_from_clipboard: element_in_clipboard.id, element: {page_id: alchemy_page.id}}, xhr: true - expect(session[:alchemy_clipboard]['elements'].detect { |item| item['id'] == element_in_clipboard.id.to_s }).to be_nil + expect(session[:alchemy_clipboard]["elements"].detect { |item| item["id"] == element_in_clipboard.id.to_s }).to be_nil end end @@ -214,7 +214,7 @@ module Alchemy end end - context 'if element could not be saved' do + context "if element could not be saved" do subject { post :create, params: {element: {page_id: alchemy_page.id}} } before do @@ -227,11 +227,11 @@ module Alchemy end end - describe '#update' do + describe "#update" do let(:page) { build_stubbed(:alchemy_page) } let(:element) { build_stubbed(:alchemy_element, page: page) } - let(:contents_parameters) { ActionController::Parameters.new(1 => {ingredient: 'Title'}) } - let(:element_parameters) { ActionController::Parameters.new(tag_list: 'Tag 1', public: false) } + let(:contents_parameters) { ActionController::Parameters.new(1 => {ingredient: "Title"}) } + let(:element_parameters) { ActionController::Parameters.new(tag_list: "Tag 1", public: false) } before do expect(Element).to receive(:find).and_return element @@ -259,9 +259,9 @@ module Alchemy end end - describe 'params security' do + describe "params security" do context "contents params" do - let(:parameters) { ActionController::Parameters.new(contents: {1 => {ingredient: 'Title'}}) } + let(:parameters) { ActionController::Parameters.new(contents: {1 => {ingredient: "Title"}}) } specify ":contents is required" do expect(controller.params).to receive(:fetch).and_return(parameters) @@ -284,7 +284,7 @@ module Alchemy expect(parameters).to receive(:fetch).with(:element, {}).and_return(parameters) end - context 'with taggable element' do + context "with taggable element" do before do controller.instance_variable_set(:'@element', mock_model(Element, taggable?: true)) end @@ -295,7 +295,7 @@ module Alchemy end end - context 'with not taggable element' do + context "with not taggable element" do before do controller.instance_variable_set(:'@element', mock_model(Element, taggable?: false)) end @@ -308,7 +308,7 @@ module Alchemy end end - describe '#trash' do + describe "#trash" do subject { delete :trash, params: {id: element.id}, xhr: true } let(:element) { build_stubbed(:alchemy_element) } @@ -321,7 +321,7 @@ module Alchemy end end - describe '#fold' do + describe "#fold" do subject { post :fold, params: {id: element.id}, xhr: true } let(:element) { build_stubbed(:alchemy_element) } @@ -331,7 +331,7 @@ module Alchemy expect(Element).to receive(:find).and_return element end - context 'if element is folded' do + context "if element is folded" do before { expect(element).to receive(:folded).and_return true } it "sets folded to false." do @@ -340,7 +340,7 @@ module Alchemy end end - context 'if element is not folded' do + context "if element is not folded" do before { expect(element).to receive(:folded).and_return false } it "sets folded to true." do diff --git a/spec/controllers/alchemy/admin/essence_files_controller_spec.rb b/spec/controllers/alchemy/admin/essence_files_controller_spec.rb index c99b8e49c8..14a097a51b 100644 --- a/spec/controllers/alchemy/admin/essence_files_controller_spec.rb +++ b/spec/controllers/alchemy/admin/essence_files_controller_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" module Alchemy describe Admin::EssenceFilesController do @@ -10,11 +10,11 @@ module Alchemy authorize_user(:as_admin) end - let(:essence_file) { mock_model('EssenceFile', :attachment= => nil, content: content) } - let(:content) { mock_model('Content') } - let(:attachment) { mock_model('Attachment') } + let(:essence_file) { mock_model("EssenceFile", :attachment= => nil, content: content) } + let(:content) { mock_model("Content") } + let(:attachment) { mock_model("Attachment") } - describe '#edit' do + describe "#edit" do before do expect(EssenceFile).to receive(:find) .with(essence_file.id.to_s) @@ -32,7 +32,7 @@ module Alchemy end end - describe '#update' do + describe "#update" do let(:essence_file) { create(:alchemy_essence_file) } before do @@ -43,18 +43,18 @@ module Alchemy put :update, params: { id: essence_file.id, essence_file: { - title: 'new title', - css_class: 'left', - link_text: 'Download this file', + title: "new title", + css_class: "left", + link_text: "Download this file", }, }, xhr: true - expect(essence_file.title).to eq 'new title' - expect(essence_file.css_class).to eq 'left' - expect(essence_file.link_text).to eq 'Download this file' + expect(essence_file.title).to eq "new title" + expect(essence_file.css_class).to eq "left" + expect(essence_file.link_text).to eq "Download this file" end end - describe '#assign' do + describe "#assign" do let(:content) { create(:alchemy_content) } before do diff --git a/spec/controllers/alchemy/admin/essence_pictures_controller_spec.rb b/spec/controllers/alchemy/admin/essence_pictures_controller_spec.rb index a2b667f2a6..e2f5b8eb27 100644 --- a/spec/controllers/alchemy/admin/essence_pictures_controller_spec.rb +++ b/spec/controllers/alchemy/admin/essence_pictures_controller_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" module Alchemy describe Admin::EssencePicturesController do @@ -12,25 +12,25 @@ module Alchemy let(:content) { Content.new } let(:picture) { Picture.new } - describe '#edit' do + describe "#edit" do before do expect(EssencePicture).to receive(:find).and_return(essence) expect(Content).to receive(:find).and_return(content) end - it 'should assign @essence_picture and @content instance variables' do + it "should assign @essence_picture and @content instance variables" do post :edit, params: {id: 1, content_id: 1} expect(assigns(:essence_picture)).to be_a(EssencePicture) expect(assigns(:content)).to be_a(Content) end end - describe '#crop' do + describe "#crop" do before do expect(EssencePicture).to receive(:find).and_return(essence) end - context 'with no picture assigned' do + context "with no picture assigned" do before do expect(essence).to receive(:picture).at_least(:once).and_return(nil) end @@ -41,7 +41,7 @@ module Alchemy end end - context 'with picture assigned' do + context "with picture assigned" do let(:default_mask) do { x1: 0, @@ -60,14 +60,14 @@ module Alchemy allow(content).to receive(:settings) { settings } end - context 'with no render_size present in essence' do + context "with no render_size present in essence" do before do expect(essence).to receive(:render_size).at_least(:once).and_return(nil) end - context 'with sizes in content settings' do + context "with sizes in content settings" do let(:settings) do - { size: '300x250' } + { size: "300x250" } end it "sets sizes to given values" do @@ -76,7 +76,7 @@ module Alchemy end end - context 'with no sizes in content settngs' do + context "with no sizes in content settngs" do it "sets sizes to zero" do get :crop, params: {id: 1} expect(assigns(:min_size)).to eq({ width: 0, height: 0 }) @@ -84,17 +84,17 @@ module Alchemy end end - context 'with render_size present in essence' do + context "with render_size present in essence" do it "sets sizes from these values" do - expect(essence).to receive(:render_size).at_least(:once).and_return('30x25') + expect(essence).to receive(:render_size).at_least(:once).and_return("30x25") get :crop, params: {id: 1} expect(assigns(:min_size)).to eq({ width: 30, height: 25 }) end - context 'when width or height is not fixed' do - it 'infers the height from the image file preserving the aspect ratio' do - expect(essence).to receive(:render_size).at_least(:once).and_return('30x') + context "when width or height is not fixed" do + it "infers the height from the image file preserving the aspect ratio" do + expect(essence).to receive(:render_size).at_least(:once).and_return("30x") get :crop, params: {id: 1} expect(assigns(:min_size)).to eq({ width: 30, height: 0}) @@ -105,8 +105,8 @@ module Alchemy { fixed_ratio: "2" } end - it 'does not infer the height from the image file preserving the aspect ratio' do - expect(essence).to receive(:render_size).at_least(:once).and_return('x25') + it "does not infer the height from the image file preserving the aspect ratio" do + expect(essence).to receive(:render_size).at_least(:once).and_return("x25") get :crop, params: {id: 1} expect(assigns(:min_size)).to eq({ width: 50, height: 25 }) @@ -114,22 +114,22 @@ module Alchemy end end - context 'when width or height is not fixed and an aspect ratio is given' do + context "when width or height is not fixed and an aspect ratio is given" do context "and aspect ratio set on the contents setting" do let(:settings) do { fixed_ratio: "0.5" } end - it 'width is given, it infers the height from width and ratio' do - expect(essence).to receive(:render_size).at_least(:once).and_return('30x') + it "width is given, it infers the height from width and ratio" do + expect(essence).to receive(:render_size).at_least(:once).and_return("30x") get :crop, params: {id: 1} expect(assigns(:min_size)).to eq({ width: 30, height: 60 }) end end - it 'infers the height from the image file preserving the aspect ratio' do - expect(essence).to receive(:render_size).at_least(:once).and_return('x25') + it "infers the height from the image file preserving the aspect ratio" do + expect(essence).to receive(:render_size).at_least(:once).and_return("x25") get :crop, params: {id: 1} expect(assigns(:min_size)).to eq({ width: 0, height: 25}) @@ -137,7 +137,7 @@ module Alchemy end end - context 'no crop sizes present in essence' do + context "no crop sizes present in essence" do before do expect(essence).to receive(:crop_from).and_return(nil) allow(essence).to receive(:crop_size).and_return(nil) @@ -150,12 +150,12 @@ module Alchemy end end - context 'crop sizes present in essence' do - let(:mask) { {'x1' => '0', 'y1' => '0', 'x2' => '120', 'y2' => '160'} } + context "crop sizes present in essence" do + let(:mask) { {"x1" => "0", "y1" => "0", "x2" => "120", "y2" => "160"} } before do - allow(essence).to receive(:crop_from).and_return('0x0') - allow(essence).to receive(:crop_size).and_return('120x160') + allow(essence).to receive(:crop_from).and_return("0x0") + allow(essence).to receive(:crop_size).and_return("120x160") end it "assigns cropping boxes" do @@ -166,7 +166,7 @@ module Alchemy end end - context 'with fixed_ratio set to false' do + context "with fixed_ratio set to false" do let(:settings) do { fixed_ratio: false } end @@ -177,9 +177,9 @@ module Alchemy end end - context 'with fixed_ratio set to a non float string' do + context "with fixed_ratio set to a non float string" do let(:settings) do - { fixed_ratio: '123,45' } + { fixed_ratio: "123,45" } end it "doesn't set a fixed ratio" do @@ -188,9 +188,9 @@ module Alchemy end end - context 'with no fixed_ratio set' do + context "with no fixed_ratio set" do let(:settings) do - { size: '80x60' } + { size: "80x60" } end it "sets a fixed ratio from sizes" do @@ -201,7 +201,7 @@ module Alchemy end end - describe '#update' do + describe "#update" do before do expect(EssencePicture).to receive(:find).and_return(essence) expect(Content).to receive(:find).and_return(content) @@ -209,11 +209,11 @@ module Alchemy let(:attributes) do { - render_size: '1x1', - alt_tag: 'Alt Tag', - caption: 'Caption', - css_class: 'CSS Class', - title: 'Title', + render_size: "1x1", + alt_tag: "Alt Tag", + caption: "Caption", + css_class: "CSS Class", + title: "Title", } end @@ -227,15 +227,15 @@ module Alchemy put :update, params: { id: 1, essence_picture: { - render_size: '1x1', - crop_from: '0x0', - crop_size: '100x100', + render_size: "1x1", + crop_from: "0x0", + crop_size: "100x100", }, }, xhr: true end end - describe '#assign' do + describe "#assign" do let(:content) { create(:alchemy_content) } before do @@ -245,14 +245,14 @@ module Alchemy end it "should assign a Picture" do - put :assign, params: {content_id: '1', picture_id: '1'}, xhr: true + put :assign, params: {content_id: "1", picture_id: "1"}, xhr: true expect(assigns(:content).essence.picture).to eq(picture) end it "updates the content timestamp" do content.update_column(:updated_at, 3.days.ago) expect { - put :assign, params: {content_id: '1', picture_id: '1'}, xhr: true + put :assign, params: {content_id: "1", picture_id: "1"}, xhr: true }.to change(content, :updated_at) end end diff --git a/spec/controllers/alchemy/admin/languages_controller_spec.rb b/spec/controllers/alchemy/admin/languages_controller_spec.rb index 4096e87e01..f109154fc5 100644 --- a/spec/controllers/alchemy/admin/languages_controller_spec.rb +++ b/spec/controllers/alchemy/admin/languages_controller_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" describe Alchemy::Admin::LanguagesController do routes { Alchemy::Engine.routes } @@ -10,7 +10,7 @@ end describe "#index" do - context 'without a site' do + context "without a site" do it "redirects to the sites admin" do get :index expect(response).to redirect_to(admin_sites_path) @@ -23,14 +23,14 @@ end let!(:site_2) do - create(:alchemy_site, host: 'another-site.com') + create(:alchemy_site, host: "another-site.com") end let!(:site_2_language) do site_2.default_language end - it 'only shows languages from current site' do + it "only shows languages from current site" do get :index expect(assigns(:languages)).to include(default_site_language) expect(assigns(:languages)).to_not include(site_2_language) @@ -52,27 +52,27 @@ end describe "#new" do - context 'without a site' do + context "without a site" do it "redirects to the sites admin" do get :new expect(response).to redirect_to(admin_sites_path) end end - context 'with a site' do + context "with a site" do let!(:site) { create(:alchemy_site) } it "has default language's page_layout set" do get :new expect(assigns(:language).page_layout). - to eq(Alchemy::Config.get(:default_language)['page_layout']) + to eq(Alchemy::Config.get(:default_language)["page_layout"]) end end end describe "#create" do - context 'with valid params' do - it 'redirects to the pages admin' do + context "with valid params" do + it "redirects to the pages admin" do post :create, params: { language: { name: "English", @@ -86,13 +86,13 @@ } language = Alchemy::Language.last expect(response).to redirect_to admin_pages_path(language_id: language) - expect(flash[:notice]).to eq('Language successfully created.') + expect(flash[:notice]).to eq("Language successfully created.") end end - context 'with invalid params' do - it 'shows the form again' do - post :create, params: { language: { name: '' } } + context "with invalid params" do + it "shows the form again" do + post :create, params: { language: { name: "" } } expect(response).to render_template(:new) end end @@ -101,22 +101,22 @@ describe "#destroy" do let(:language) { create(:alchemy_language) } - context 'with pages attached' do + context "with pages attached" do let!(:page) { create(:alchemy_page, language: language) } - it 'returns with error message' do + it "returns with error message" do delete :destroy, params: { id: language.id } expect(response).to redirect_to admin_languages_path expect(flash[:warning]).to \ - eq('Pages are still attached to this language. Please remove them first.') + eq("Pages are still attached to this language. Please remove them first.") end end - context 'without pages' do - it 'removes the language' do + context "without pages" do + it "removes the language" do delete :destroy, params: { id: language.id } expect(response).to redirect_to admin_languages_path - expect(flash[:notice]).to eq('Language successfully removed.') + expect(flash[:notice]).to eq("Language successfully removed.") end end end @@ -136,7 +136,7 @@ context "having a referer" do before do expect_any_instance_of(ActionDispatch::Request).to receive(:referer) do - '/admin/pages' + "/admin/pages" end end diff --git a/spec/controllers/alchemy/admin/layoutpages_controller_spec.rb b/spec/controllers/alchemy/admin/layoutpages_controller_spec.rb index 32aaddc044..5e7403f232 100644 --- a/spec/controllers/alchemy/admin/layoutpages_controller_spec.rb +++ b/spec/controllers/alchemy/admin/layoutpages_controller_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" module Alchemy describe Admin::LayoutpagesController do @@ -11,14 +11,14 @@ module Alchemy end describe "#index" do - context 'with no language present' do - it 'redirects to the languages admin' do + context "with no language present" do + it "redirects to the languages admin" do get :index expect(response).to redirect_to(admin_languages_path) end end - context 'with a language present' do + context "with a language present" do let!(:language) { create(:alchemy_language) } it "should assign @layout_root" do @@ -33,23 +33,23 @@ module Alchemy context "with multiple sites" do let!(:site_2) do - create(:alchemy_site, host: 'another-site.com') + create(:alchemy_site, host: "another-site.com") end - context 'if no language exists for the current site' do - it 'redirects to the languages admin' do + context "if no language exists for the current site" do + it "redirects to the languages admin" do get :index, session: { alchemy_site_id: site_2.id } expect(response).to redirect_to(admin_languages_path) end end - context 'if an language exists for the current site' do + context "if an language exists for the current site" do let!(:language) { create(:alchemy_language) } let!(:language_2) do create(:alchemy_language, site: site_2) end - it 'only shows languages from current site' do + it "only shows languages from current site" do get :index, session: { alchemy_site_id: site_2.id } expect(assigns(:languages)).to_not include(language) expect(assigns(:languages)).to include(language_2) diff --git a/spec/controllers/alchemy/admin/nodes_controller_spec.rb b/spec/controllers/alchemy/admin/nodes_controller_spec.rb index 9039223b69..b20f12ec21 100644 --- a/spec/controllers/alchemy/admin/nodes_controller_spec.rb +++ b/spec/controllers/alchemy/admin/nodes_controller_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" module Alchemy describe Admin::NodesController do @@ -10,70 +10,70 @@ module Alchemy authorize_user(:as_admin) end - describe '#index' do - context 'if no language is present' do - it 'redirects to the language admin' do + describe "#index" do + context "if no language is present" do + it "redirects to the language admin" do get :index expect(response).to redirect_to(admin_languages_path) end end - context 'if root nodes present' do + context "if root nodes present" do let!(:root_node) { create(:alchemy_node) } let!(:child_node) { create(:alchemy_node, parent_id: root_node.id) } it "loads only root nodes from current language" do get :index - expect(assigns('root_nodes').to_a).to eq([root_node]) - expect(assigns('root_nodes').to_a).to_not eq([child_node]) + expect(assigns("root_nodes").to_a).to eq([root_node]) + expect(assigns("root_nodes").to_a).to_not eq([child_node]) end end end - describe '#new' do - context 'if no language is present' do - it 'redirects to the language admin' do + describe "#new" do + context "if no language is present" do + it "redirects to the language admin" do get :new expect(response).to redirect_to(admin_languages_path) end end - context 'if language is present' do + context "if language is present" do let!(:default_language) { create(:alchemy_language) } it "sets the current language on new node" do get :new - expect(assigns('node').language).to eq(default_language) + expect(assigns("node").language).to eq(default_language) end - context 'with parent id in params' do + context "with parent id in params" do it "sets it to new node" do get :new, params: { parent_id: 1 } - expect(assigns('node').parent_id).to eq(1) + expect(assigns("node").parent_id).to eq(1) end end end end - describe '#create' do - context 'with valid params' do + describe "#create" do + context "with valid params" do let(:language) { create(:alchemy_language) } it "creates node and redirects to index" do expect { - post :create, params: { node: { name: 'Node', language_id: language.id, site_id: language.site_id } } + post :create, params: { node: { name: "Node", language_id: language.id, site_id: language.site_id } } }.to change { Alchemy::Node.count }.by(1) expect(response).to redirect_to(admin_nodes_path) end end end - describe '#update' do + describe "#update" do let(:node) { create(:alchemy_node) } - context 'with valid params' do + context "with valid params" do it "redirects to nodes path" do - put :update, params: { id: node.id, node: { name: 'Node'} } + put :update, params: { id: node.id, node: { name: "Node"} } expect(response).to redirect_to(admin_nodes_path) end end diff --git a/spec/controllers/alchemy/admin/pictures_controller_spec.rb b/spec/controllers/alchemy/admin/pictures_controller_spec.rb index 911735d9e1..b94e43c3c8 100644 --- a/spec/controllers/alchemy/admin/pictures_controller_spec.rb +++ b/spec/controllers/alchemy/admin/pictures_controller_spec.rb @@ -1,19 +1,19 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" RSpec.shared_examples :redirecting_to_picture_library do let(:params) do { - filter: 'latest', + filter: "latest", page: 2, - q: {name_or_image_file_name_cont: 'kitten'}, - size: 'small', - tagged_with: 'cat', + q: {name_or_image_file_name_cont: "kitten"}, + size: "small", + tagged_with: "cat", } end - it 'redirects to index keeping all query, filter and page params' do + it "redirects to index keeping all query, filter and page params" do is_expected.to redirect_to admin_pictures_path(params) end end @@ -26,62 +26,62 @@ module Alchemy authorize_user(:as_admin) end - describe '#index' do - context 'with search params' do - let!(:picture_1) { create(:alchemy_picture, name: 'cute kitten') } - let!(:picture_2) { create(:alchemy_picture, name: 'nice beach') } + describe "#index" do + context "with search params" do + let!(:picture_1) { create(:alchemy_picture, name: "cute kitten") } + let!(:picture_2) { create(:alchemy_picture, name: "nice beach") } - it 'assigns @pictures with filtered pictures' do - get :index, params: {q: {name_or_image_file_name_cont: 'kitten'}} + it "assigns @pictures with filtered pictures" do + get :index, params: {q: {name_or_image_file_name_cont: "kitten"}} expect(assigns(:pictures)).to include(picture_1) expect(assigns(:pictures)).to_not include(picture_2) end end - context 'with filter params' do + context "with filter params" do let!(:picture_1) { create(:alchemy_picture) } let!(:picture_2) { create(:alchemy_picture, tag_list: %w(kitten)) } - it 'assigns @pictures with filtered pictures' do - get :index, params: {filter: 'without_tag'} + it "assigns @pictures with filtered pictures" do + get :index, params: {filter: "without_tag"} expect(assigns(:pictures)).to include(picture_1) expect(assigns(:pictures)).to_not include(picture_2) end end - context 'with tag params' do + context "with tag params" do let!(:picture_1) { create(:alchemy_picture, tag_list: %w(water)) } let!(:picture_2) { create(:alchemy_picture, tag_list: %w(kitten)) } let!(:picture_3) { create(:alchemy_picture, tag_list: %w(water nature)) } - it 'assigns @pictures with filtered pictures' do - get :index, params: {tagged_with: 'water'} + it "assigns @pictures with filtered pictures" do + get :index, params: {tagged_with: "water"} expect(assigns(:pictures)).to include(picture_1) expect(assigns(:pictures)).to_not include(picture_2) expect(assigns(:pictures)).to include(picture_3) end end - context 'with multiple tag params' do + context "with multiple tag params" do let!(:picture_1) { create(:alchemy_picture, tag_list: %w(water)) } let!(:picture_2) { create(:alchemy_picture, tag_list: %w(water nature)) } - it 'assigns @pictures with filtered pictures' do - get :index, params: {tagged_with: 'water,nature'} + it "assigns @pictures with filtered pictures" do + get :index, params: {tagged_with: "water,nature"} expect(assigns(:pictures)).to_not include(picture_1) expect(assigns(:pictures)).to include(picture_2) end end - it 'assigns @size to default value' do + it "assigns @size to default value" do get :index - expect(assigns(:size)).to eq('medium') + expect(assigns(:size)).to eq("medium") end context "with params[:size] set to 'large'" do - it 'assigns @size to large' do - get :index, params: {size: 'large'} - expect(assigns(:size)).to eq('large') + it "assigns @size to large" do + get :index, params: {size: "large"} + expect(assigns(:size)).to eq("large") end end @@ -89,7 +89,7 @@ module Alchemy context "is set" do it "for html requests it renders the archive_overlay partial" do get :index, params: {content_id: 1} - expect(response).to render_template(partial: '_archive_overlay') + expect(response).to render_template(partial: "_archive_overlay") end it "for ajax requests it renders the archive_overlay template" do @@ -107,101 +107,101 @@ module Alchemy end end - describe '#create' do + describe "#create" do subject { post :create, params: params } - let(:params) { {picture: {name: ''}} } - let(:picture) { mock_model('Picture', humanized_name: 'Cute kittens', to_jq_upload: {}) } + let(:params) { {picture: {name: ""}} } + let(:picture) { mock_model("Picture", humanized_name: "Cute kittens", to_jq_upload: {}) } - context 'with passing validations' do + context "with passing validations" do before do expect(Picture).to receive(:new).and_return(picture) - expect(picture).to receive(:name=).and_return('Cute kittens') - expect(picture).to receive(:name).and_return('Cute kittens') + expect(picture).to receive(:name=).and_return("Cute kittens") + expect(picture).to receive(:name).and_return("Cute kittens") expect(picture).to receive(:save).and_return(true) end it "renders json response with success message" do subject - expect(response.media_type).to eq('application/json') + expect(response.media_type).to eq("application/json") expect(response.status).to eq(201) json = JSON.parse(response.body) - expect(json).to have_key('growl_message') - expect(json).to have_key('files') + expect(json).to have_key("growl_message") + expect(json).to have_key("files") end end - context 'with failing validations' do - it_behaves_like 'having a json uploader error message' + context "with failing validations" do + it_behaves_like "having a json uploader error message" end end - describe '#show' do - let(:picture) { create(:alchemy_picture, name: 'kitten') } + describe "#show" do + let(:picture) { create(:alchemy_picture, name: "kitten") } - it 'assigns @picture' do + it "assigns @picture" do get :show, params: {id: picture.id} expect(assigns(:picture).id).to eq(picture.id) end - context 'with assignments' do + context "with assignments" do let!(:page) { create(:alchemy_page) } let!(:element) { create(:alchemy_element, page: page) } let!(:content) { create(:alchemy_content, element: element) } let!(:essence) { create(:alchemy_essence_picture, content: content, picture: picture) } - it 'assigns all essence pictures having an assignment to @assignments' do + it "assigns all essence pictures having an assignment to @assignments" do get :show, params: {id: picture.id} expect(assigns(:assignments)).to eq([essence]) end end - context 'with previous picture existing' do - let!(:previous) { create(:alchemy_picture, name: 'abraham') } + context "with previous picture existing" do + let!(:previous) { create(:alchemy_picture, name: "abraham") } - it 'assigns @previous to previous picture' do + it "assigns @previous to previous picture" do get :show, params: {id: picture.id} expect(assigns(:previous).id).to eq(previous.id) end end - context 'with next picture existing' do - let!(:next_picture) { create(:alchemy_picture, name: 'zebra') } + context "with next picture existing" do + let!(:next_picture) { create(:alchemy_picture, name: "zebra") } - it 'assigns @next to next picture' do + it "assigns @next to next picture" do get :show, params: {id: picture.id} expect(assigns(:next).id).to eq(next_picture.id) end end end - describe '#edit_multiple' do - let(:pictures) { [mock_model('Picture', tag_list: 'kitten')] } + describe "#edit_multiple" do + let(:pictures) { [mock_model("Picture", tag_list: "kitten")] } before { expect(Picture).to receive(:where).and_return(pictures) } - it 'assigns pictures instance variable' do + it "assigns pictures instance variable" do get :edit_multiple expect(assigns(:pictures)).to eq(pictures) end - it 'assigns tags instance variable' do + it "assigns tags instance variable" do get :edit_multiple - expect(assigns(:tags)).to include('kitten') + expect(assigns(:tags)).to include("kitten") end end - describe '#update' do + describe "#update" do subject do - put :update, params: {id: 1, picture: {name: ''}}, xhr: true + put :update, params: {id: 1, picture: {name: ""}}, xhr: true end - let(:picture) { build_stubbed(:alchemy_picture, name: 'Cute kitten') } + let(:picture) { build_stubbed(:alchemy_picture, name: "Cute kitten") } before do expect(Picture).to receive(:find).and_return(picture) end - context 'with passing validations' do + context "with passing validations" do before do expect(picture).to receive(:update).and_return(true) end @@ -210,11 +210,11 @@ module Alchemy subject expect(assigns(:message)[:body]).to \ eq(Alchemy.t(:picture_updated_successfully, name: picture.name)) - expect(assigns(:message)[:type]).to eq('notice') + expect(assigns(:message)[:type]).to eq("notice") end end - context 'with failing validations' do + context "with failing validations" do before do expect(picture).to receive(:update).and_return(false) end @@ -222,12 +222,12 @@ module Alchemy it "sets error notice" do subject expect(assigns(:message)[:body]).to eq(Alchemy.t(:picture_update_failed)) - expect(assigns(:message)[:type]).to eq('error') + expect(assigns(:message)[:type]).to eq("error") end end end - describe '#update_multiple' do + describe "#update_multiple" do let(:picture) { build_stubbed(:alchemy_picture) } let(:pictures) { [picture] } @@ -258,19 +258,19 @@ module Alchemy end let(:deletable_picture) do - mock_model('Picture', name: 'pic of the pig', deletable?: true) + mock_model("Picture", name: "pic of the pig", deletable?: true) end let(:not_deletable_picture) do - mock_model('Picture', name: 'pic of the chick', deletable?: false) + mock_model("Picture", name: "pic of the chick", deletable?: false) end context "no picture_ids given" do - let(:picture_ids) { '' } + let(:picture_ids) { "" } it "should give a warning about not deleting any pictures" do subject - expect(flash[:warn]).to match('Could not delete Pictures') + expect(flash[:warn]).to match("Could not delete Pictures") end end @@ -284,7 +284,7 @@ module Alchemy it "should delete the pictures give a notice about deleting them" do subject - expect(flash[:notice]).to match('successfully') + expect(flash[:notice]).to match("successfully") end end @@ -298,15 +298,15 @@ module Alchemy it "should give a warning for the non deletable pictures and delete the others" do expect(deletable_picture).to receive(:destroy) subject - expect(flash[:warn]).to match('could not be deleted') + expect(flash[:warn]).to match("could not be deleted") end end - context 'with error happening' do + context "with error happening" do let(:picture_ids) { deletable_picture.id.to_s } before do - expect(Picture).to receive(:find).and_raise('yada') + expect(Picture).to receive(:find).and_raise("yada") end it "sets error message" do @@ -322,8 +322,8 @@ module Alchemy end end - describe '#destroy' do - let(:picture) { build_stubbed(:alchemy_picture, name: 'Cute kitten') } + describe "#destroy" do + let(:picture) { build_stubbed(:alchemy_picture, name: "Cute kitten") } before do expect(Picture).to receive(:find).and_return(picture) @@ -336,9 +336,9 @@ module Alchemy expect(flash[:notice]).not_to be_blank end - context 'if an error happens' do + context "if an error happens" do before do - expect(picture).to receive(:destroy).and_raise('yada') + expect(picture).to receive(:destroy).and_raise("yada") end it "shows error notice" do @@ -357,51 +357,51 @@ module Alchemy end end - describe '#items_per_page' do + describe "#items_per_page" do subject { controller.send(:items_per_page) } before do expect(controller).to receive(:params).at_least(:once) { params } end - context 'in overlay' do + context "in overlay" do let(:params) { {content_id: :id, size: size} } - context 'with params[:size] set to medium' do - let(:size) { 'medium' } + context "with params[:size] set to medium" do + let(:size) { "medium" } it { is_expected.to eq(9) } end - context 'with params[:size] set to small' do - let(:size) { 'small' } + context "with params[:size] set to small" do + let(:size) { "small" } it { is_expected.to eq(25) } end - context 'with params[:size] set to large' do - let(:size) { 'large' } + context "with params[:size] set to large" do + let(:size) { "large" } it { is_expected.to eq(4) } end end - context 'in archive' do + context "in archive" do let(:params) { {size: size} } - context 'with params[:size] set to medium' do - let(:size) { 'medium' } + context "with params[:size] set to medium" do + let(:size) { "medium" } it { is_expected.to eq(20) } - context 'with cookie set' do + context "with cookie set" do before do @request.cookies[:alchemy_pictures_per_page] = 2 end it { is_expected.to eq(2) } - context 'with params[:per_page] given' do + context "with params[:per_page] given" do let(:params) { {per_page: 8, size: size} } it { is_expected.to eq(8) } @@ -409,14 +409,14 @@ module Alchemy end end - context 'with params[:size] set to small' do - let(:size) { 'small' } + context "with params[:size] set to small" do + let(:size) { "small" } it { is_expected.to eq(60) } end - context 'with params[:size] set to large' do - let(:size) { 'large' } + context "with params[:size] set to large" do + let(:size) { "large" } it { is_expected.to eq(12) } end diff --git a/spec/controllers/alchemy/admin/resources_controller_spec.rb b/spec/controllers/alchemy/admin/resources_controller_spec.rb index ac3cccc6a1..535f84aa75 100644 --- a/spec/controllers/alchemy/admin/resources_controller_spec.rb +++ b/spec/controllers/alchemy/admin/resources_controller_spec.rb @@ -1,16 +1,16 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" describe Admin::EventsController do it "should include ResourcesHelper" do expect(controller.respond_to?(:resource_window_size)).to be_truthy end - describe '#index' do + describe "#index" do let(:params) { Hash.new } - let!(:peter) { create(:event, name: 'Peter') } - let!(:lustig) { create(:event, name: 'Lustig') } + let!(:peter) { create(:event, name: "Peter") } + let!(:lustig) { create(:event, name: "Lustig") } before do authorize_user(:as_admin) @@ -22,7 +22,7 @@ expect(assigns(:events)).to include(lustig) end - context 'with search query given' do + context "with search query given" do let(:params) { {q: {name_or_hidden_name_or_description_or_location_name_cont: "PeTer"}} } it "returns only matching records" do @@ -32,7 +32,7 @@ end context "but searching for record with certain association" do - let(:bauwagen) { create(:location, name: 'Bauwagen') } + let(:bauwagen) { create(:location, name: "Bauwagen") } let(:params) { {q: {name_or_hidden_name_or_description_or_location_name_cont: "Bauwagen"}} } before do @@ -47,7 +47,7 @@ end end - context 'with sort parameter given' do + context "with sort parameter given" do let(:params) { {q: {s: "name desc"}} } it "returns records in the defined order" do @@ -56,15 +56,15 @@ end end - context 'without sort parameter given' do - context 'if resource has name attribute' do + context "without sort parameter given" do + context "if resource has name attribute" do it "returns records sorted by name" do get :index expect(assigns(:events)).to eq([lustig, peter]) end end - context 'if resource has no name attribute' do + context "if resource has no name attribute" do let!(:booking1) { Booking.create!(from: 2.week.from_now) } let!(:booking2) { Booking.create!(from: 1.weeks.from_now) } @@ -83,57 +83,57 @@ def resource_handler end end - describe '#update' do - let(:params) { {q: {name_or_hidden_name_or_description_or_location_name_cont: 'some_query'}, page: 6} } + describe "#update" do + let(:params) { {q: {name_or_hidden_name_or_description_or_location_name_cont: "some_query"}, page: 6} } - context 'with regular noun model name' do - let(:peter) { create(:event, name: 'Peter') } + context "with regular noun model name" do + let(:peter) { create(:event, name: "Peter") } - it 'redirects to index, keeping the current location parameters' do + it "redirects to index, keeping the current location parameters" do post :update, params: {id: peter.id, event: {name: "Hans"}}.merge(params) expect(response.redirect_url).to eq("http://test.host/admin/events?page=6&q%5Bname_or_hidden_name_or_description_or_location_name_cont%5D=some_query") end end - context 'with zero plural noun model name' do - let!(:peter) { create(:series, name: 'Peter') } - let(:params) { {q: { name_cont: 'some_query'}, page: 6} } + context "with zero plural noun model name" do + let!(:peter) { create(:series, name: "Peter") } + let(:params) { {q: { name_cont: "some_query"}, page: 6} } - it 'redirects to index, keeping the current location parameters' do - expect(controller).to receive(:controller_path) { 'admin/series' } + it "redirects to index, keeping the current location parameters" do + expect(controller).to receive(:controller_path) { "admin/series" } post :update, params: {id: peter.id, series: {name: "Hans"}}.merge(params) expect(response.redirect_url).to eq("http://test.host/admin/series?page=6&q%5Bname_cont%5D=some_query") end end end - describe '#create' do - let(:params) { {q: {name_or_hidden_name_or_description_or_location_name_cont: 'some_query'}, page: 6} } + describe "#create" do + let(:params) { {q: {name_or_hidden_name_or_description_or_location_name_cont: "some_query"}, page: 6} } let!(:location) { create(:location) } - context 'with regular noun model name' do - it 'redirects to index, keeping the current location parameters' do + context "with regular noun model name" do + it "redirects to index, keeping the current location parameters" do post :create, params: {event: {name: "Hans", location_id: location.id}}.merge(params) expect(response.redirect_url).to eq("http://test.host/admin/events?page=6&q%5Bname_or_hidden_name_or_description_or_location_name_cont%5D=some_query") end end - context 'with zero plural noun model name' do - let(:params) { {q: {name_cont: 'some_query'}, page: 6} } + context "with zero plural noun model name" do + let(:params) { {q: {name_cont: "some_query"}, page: 6} } - it 'redirects to index, keeping the current location parameters' do - expect(controller).to receive(:controller_path) { 'admin/series' } + it "redirects to index, keeping the current location parameters" do + expect(controller).to receive(:controller_path) { "admin/series" } post :create, params: {series: {name: "Hans"}}.merge(params) expect(response.redirect_url).to eq("http://test.host/admin/series?page=6&q%5Bname_cont%5D=some_query") end end end - describe '#destroy' do - let(:params) { {q: {name_or_hidden_name_or_description_or_location_name_cont: 'some_query'}, page: 6} } - let!(:peter) { create(:event, name: 'Peter') } + describe "#destroy" do + let(:params) { {q: {name_or_hidden_name_or_description_or_location_name_cont: "some_query"}, page: 6} } + let!(:peter) { create(:event, name: "Peter") } - it 'redirects to index, keeping the current location parameters' do + it "redirects to index, keeping the current location parameters" do delete :destroy, params: {id: peter.id}.merge(params) expect(response.redirect_url).to eq("http://test.host/admin/events?page=6&q%5Bname_or_hidden_name_or_description_or_location_name_cont%5D=some_query") end diff --git a/spec/controllers/alchemy/admin/sites_controller_spec.rb b/spec/controllers/alchemy/admin/sites_controller_spec.rb index d23aa3eeeb..af19397f17 100644 --- a/spec/controllers/alchemy/admin/sites_controller_spec.rb +++ b/spec/controllers/alchemy/admin/sites_controller_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" describe Alchemy::Admin::SitesController do routes { Alchemy::Engine.routes } @@ -10,18 +10,18 @@ end describe "#create" do - context 'with valid params' do - it 'redirects to the languages admin' do - post :create, params: { site: { host: '*' } } + context "with valid params" do + it "redirects to the languages admin" do + post :create, params: { site: { host: "*" } } site = Alchemy::Site.last expect(response).to redirect_to admin_languages_path(site_id: site) - expect(flash[:notice]).to eq('Please create a default language for this site.') + expect(flash[:notice]).to eq("Please create a default language for this site.") end end - context 'with invalid params' do - it 'shows the form again' do - post :create, params: { site: { host: '' } } + context "with invalid params" do + it "shows the form again" do + post :create, params: { site: { host: "" } } expect(response).to render_template(:new) end end @@ -30,22 +30,22 @@ describe "#destroy" do let(:site) { create(:alchemy_site) } - context 'with languages attached' do + context "with languages attached" do let!(:language) { create(:alchemy_language, site: site) } - it 'returns with error message' do + it "returns with error message" do delete :destroy, params: { id: site.id } expect(response).to redirect_to admin_sites_path expect(flash[:warning]).to \ - eq('Languages are still attached to this site. Please remove them first.') + eq("Languages are still attached to this site. Please remove them first.") end end - context 'without languages' do - it 'removes the site' do + context "without languages" do + it "removes the site" do delete :destroy, params: { id: site.id } expect(response).to redirect_to admin_sites_path - expect(flash[:notice]).to eq('Website successfully removed.') + expect(flash[:notice]).to eq("Website successfully removed.") end end end diff --git a/spec/controllers/alchemy/admin/tags_controller_spec.rb b/spec/controllers/alchemy/admin/tags_controller_spec.rb index b1d0f31c8c..8ed53cb767 100644 --- a/spec/controllers/alchemy/admin/tags_controller_spec.rb +++ b/spec/controllers/alchemy/admin/tags_controller_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" module Alchemy module Admin @@ -9,29 +9,29 @@ module Admin before { authorize_user(:as_admin) } - describe '#create' do - context 'without required params' do + describe "#create" do + context "without required params" do render_views it "does not create tag" do - post :create, params: {tag: {name: ''}} + post :create, params: {tag: {name: ""}} expect(response.body).to have_content("can't be blank") end end - context 'with required params' do + context "with required params" do it "creates tag and redirects to tags view" do expect { - post :create, params: {tag: {name: 'Foo'}} + post :create, params: {tag: {name: "Foo"}} }.to change { Gutentag::Tag.count }.by(1) expect(response).to redirect_to admin_tags_path end end end - describe '#edit' do - let(:tag) { Gutentag::Tag.create(name: 'Sputz') } - let(:another_tag) { Gutentag::Tag.create(name: 'Hutzl') } + describe "#edit" do + let(:tag) { Gutentag::Tag.create(name: "Sputz") } + let(:another_tag) { Gutentag::Tag.create(name: "Hutzl") } before { another_tag; tag } @@ -42,17 +42,17 @@ module Admin end end - describe '#update' do - let(:tag) { Gutentag::Tag.create(name: 'Sputz') } + describe "#update" do + let(:tag) { Gutentag::Tag.create(name: "Sputz") } it "changes tags name" do - put :update, params: {id: tag.id, tag: {name: 'Foo'}} + put :update, params: {id: tag.id, tag: {name: "Foo"}} expect(response).to redirect_to(admin_tags_path) - expect(tag.reload.name).to eq('Foo') + expect(tag.reload.name).to eq("Foo") end - context 'with merg_to param given' do - let(:another_tag) { Gutentag::Tag.create(name: 'Hutzl') } + context "with merg_to param given" do + let(:another_tag) { Gutentag::Tag.create(name: "Hutzl") } it "replaces tag with other tag" do expect(Alchemy::Tag).to receive(:replace) diff --git a/spec/controllers/alchemy/admin/translations_spec.rb b/spec/controllers/alchemy/admin/translations_spec.rb index 0661f29583..6271d887b1 100644 --- a/spec/controllers/alchemy/admin/translations_spec.rb +++ b/spec/controllers/alchemy/admin/translations_spec.rb @@ -1,16 +1,16 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" describe Alchemy::Admin::DashboardController do routes { Alchemy::Engine.routes } context "in admin backend" do - let(:dummy_user) { mock_model(Alchemy.user_class, alchemy_roles: %w(admin), language: 'de') } + let(:dummy_user) { mock_model(Alchemy.user_class, alchemy_roles: %w(admin), language: "de") } before { authorize_user(dummy_user) } - context 'if locale is available' do + context "if locale is available" do before do expect(Alchemy::I18n).to receive(:available_locales).at_least(:once) do [:de, :nl, :en] @@ -18,26 +18,26 @@ end it "should be possible to set the locale of the admin backend via params" do - get :index, params: {admin_locale: 'nl'} + get :index, params: {admin_locale: "nl"} expect(::I18n.locale).to eq(:nl) end it "should store the current locale in the session" do - get :index, params: {admin_locale: 'nl'} + get :index, params: {admin_locale: "nl"} expect(session[:alchemy_locale]).to eq(:nl) end it "should be possible to change the current locale in the session" do - get :index, params: {admin_locale: 'de'} + get :index, params: {admin_locale: "de"} expect(session[:alchemy_locale]).to eq(:de) - get :index, params: {admin_locale: 'en'} + get :index, params: {admin_locale: "en"} expect(session[:alchemy_locale]).to eq(:en) end end - context 'with unknown locale' do + context "with unknown locale" do it "it uses the users default language" do - get :index, params: {admin_locale: 'ko'} + get :index, params: {admin_locale: "ko"} expect(::I18n.locale).to eq(:de) end end @@ -51,7 +51,7 @@ context "if user has no preferred locale" do let(:dummy_user) { mock_model(Alchemy.user_class, alchemy_roles: %w(admin), language: nil) } - context 'if locale is available' do + context "if locale is available" do before do expect(Alchemy::I18n).to receive(:available_locales).at_least(:once) do [:es, :nl] @@ -59,7 +59,7 @@ end it "should use the browsers language setting" do - request.headers['ACCEPT-LANGUAGE'] = 'es-ES' + request.headers["ACCEPT-LANGUAGE"] = "es-ES" get :index expect(::I18n.locale).to eq(:es) end @@ -70,7 +70,7 @@ context "if language doesn't return a valid locale symbol" do it "should use the browsers language setting" do - request.headers['ACCEPT-LANGUAGE'] = 'es-ES' + request.headers["ACCEPT-LANGUAGE"] = "es-ES" get :index expect(::I18n.locale).to eq(:es) end diff --git a/spec/controllers/alchemy/admin/trash_controller_spec.rb b/spec/controllers/alchemy/admin/trash_controller_spec.rb index acba8ceb16..708ee66b4f 100644 --- a/spec/controllers/alchemy/admin/trash_controller_spec.rb +++ b/spec/controllers/alchemy/admin/trash_controller_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" module Alchemy module Admin diff --git a/spec/controllers/alchemy/api/contents_controller_spec.rb b/spec/controllers/alchemy/api/contents_controller_spec.rb index 3d0d56a4cc..d4fba343aa 100644 --- a/spec/controllers/alchemy/api/contents_controller_spec.rb +++ b/spec/controllers/alchemy/api/contents_controller_spec.rb @@ -1,12 +1,12 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" module Alchemy describe Api::ContentsController do routes { Alchemy::Engine.routes } - describe '#index' do + describe "#index" do let!(:page) { create(:alchemy_page) } let!(:element) { create(:alchemy_element, page: page) } let!(:content) { create(:alchemy_content, element: element) } @@ -15,15 +15,15 @@ module Alchemy get :index, params: {format: :json} expect(response.status).to eq(200) - expect(response.media_type).to eq('application/json') + expect(response.media_type).to eq("application/json") result = JSON.parse(response.body) expect(result).to have_key("contents") - expect(result['contents'].size).to eq(Alchemy::Content.count) + expect(result["contents"].size).to eq(Alchemy::Content.count) end - context 'with element_id' do + context "with element_id" do let!(:other_element) { create(:alchemy_element, page: page) } let!(:other_content) { create(:alchemy_content, element: other_element) } @@ -31,31 +31,31 @@ module Alchemy get :index, params: {element_id: other_element.id, format: :json} expect(response.status).to eq(200) - expect(response.media_type).to eq('application/json') + expect(response.media_type).to eq("application/json") result = JSON.parse(response.body) expect(result).to have_key("contents") - expect(result['contents'].size).to eq(1) - expect(result['contents'][0]['element_id']).to eq(other_element.id) + expect(result["contents"].size).to eq(1) + expect(result["contents"][0]["element_id"]).to eq(other_element.id) end end - context 'with empty element_id' do + context "with empty element_id" do it "returns all contents" do get :index, params: {element_id: element.id, format: :json} expect(response.status).to eq(200) - expect(response.media_type).to eq('application/json') + expect(response.media_type).to eq("application/json") result = JSON.parse(response.body) expect(result).to have_key("contents") - expect(result['contents'].size).to eq(Alchemy::Content.count) + expect(result["contents"].size).to eq(Alchemy::Content.count) end end - context 'as author' do + context "as author" do before do authorize_user(build(:alchemy_dummy_user, :as_author)) end @@ -64,18 +64,18 @@ module Alchemy get :index, params: {format: :json} expect(response.status).to eq(200) - expect(response.media_type).to eq('application/json') + expect(response.media_type).to eq("application/json") result = JSON.parse(response.body) - expect(result).to have_key('contents') - expect(result['contents'].size).to eq(Alchemy::Content.count) + expect(result).to have_key("contents") + expect(result["contents"].size).to eq(Alchemy::Content.count) end end end - describe '#show' do - context 'with no other params given' do + describe "#show" do + context "with no other params given" do let(:page) { create(:alchemy_page) } let(:element) { create(:alchemy_element, page: page) } let(:content) { create(:alchemy_content, element: element) } @@ -84,58 +84,58 @@ module Alchemy get :show, params: {id: content.id, format: :json} expect(response.status).to eq(200) - expect(response.media_type).to eq('application/json') + expect(response.media_type).to eq("application/json") result = JSON.parse(response.body) - expect(result['id']).to eq(content.id) + expect(result["id"]).to eq(content.id) end - context 'requesting an restricted content' do + context "requesting an restricted content" do let(:page) { create(:alchemy_page, restricted: true) } it "responds with 403" do get :show, params: {id: content.id, format: :json} - expect(response.media_type).to eq('application/json') + expect(response.media_type).to eq("application/json") expect(response.status).to eq(403) result = JSON.parse(response.body) expect(result).to have_key("error") - expect(result['error']).to eq("Not authorized") + expect(result["error"]).to eq("Not authorized") end end end - context 'with element_id and name params given' do + context "with element_id and name params given" do let!(:page) { create(:alchemy_page) } let!(:element) { create(:alchemy_element, page: page) } let!(:content) { create(:alchemy_content, element: element) } - it 'returns the named content from element with given id.' do + it "returns the named content from element with given id." do get :show, params: {element_id: element.id, name: content.name, format: :json} expect(response.status).to eq(200) - expect(response.media_type).to eq('application/json') + expect(response.media_type).to eq("application/json") result = JSON.parse(response.body) - expect(result['id']).to eq(content.id) + expect(result["id"]).to eq(content.id) end end - context 'with empty element_id or name param' do - it 'returns 404 error.' do - get :show, params: {element_id: '', name: '', format: :json} + context "with empty element_id or name param" do + it "returns 404 error." do + get :show, params: {element_id: "", name: "", format: :json} expect(response.status).to eq(404) - expect(response.media_type).to eq('application/json') + expect(response.media_type).to eq("application/json") result = JSON.parse(response.body) expect(result).to have_key("error") - expect(result['error']).to eq("Record not found") + expect(result["error"]).to eq("Record not found") end end end diff --git a/spec/controllers/alchemy/api/elements_controller_spec.rb b/spec/controllers/alchemy/api/elements_controller_spec.rb index ddd3118252..0173aeda63 100644 --- a/spec/controllers/alchemy/api/elements_controller_spec.rb +++ b/spec/controllers/alchemy/api/elements_controller_spec.rb @@ -1,12 +1,12 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" module Alchemy describe Api::ElementsController do routes { Alchemy::Engine.routes } - describe '#index' do + describe "#index" do let(:page) { create(:alchemy_page, :public) } before do @@ -18,15 +18,15 @@ module Alchemy get :index, params: {format: :json} expect(response.status).to eq(200) - expect(response.media_type).to eq('application/json') + expect(response.media_type).to eq("application/json") result = JSON.parse(response.body) - expect(result).to have_key('elements') - expect(result['elements'].last['nested_elements']).to_not be_empty - expect(result['elements'].size).to eq(Alchemy::Element.not_nested.count) + expect(result).to have_key("elements") + expect(result["elements"].last["nested_elements"]).to_not be_empty + expect(result["elements"].size).to eq(Alchemy::Element.not_nested.count) end - context 'with page_id param' do + context "with page_id param" do let!(:other_page) { create(:alchemy_page, :public) } let!(:other_element) { create(:alchemy_element, page: other_page) } @@ -34,62 +34,62 @@ module Alchemy get :index, params: {page_id: other_page.id, format: :json} expect(response.status).to eq(200) - expect(response.media_type).to eq('application/json') + expect(response.media_type).to eq("application/json") result = JSON.parse(response.body) - expect(result).to have_key('elements') - expect(result['elements'].size).to eq(1) - expect(result['elements'][0]['page_id']).to eq(other_page.id) + expect(result).to have_key("elements") + expect(result["elements"].size).to eq(1) + expect(result["elements"][0]["page_id"]).to eq(other_page.id) end end - context 'with empty page_id param' do + context "with empty page_id param" do it "returns all not nested elements" do - get :index, params: {page_id: '', format: :json} + get :index, params: {page_id: "", format: :json} expect(response.status).to eq(200) - expect(response.media_type).to eq('application/json') + expect(response.media_type).to eq("application/json") result = JSON.parse(response.body) - expect(result).to have_key('elements') - expect(result['elements'].size).to eq(Alchemy::Element.not_nested.count) + expect(result).to have_key("elements") + expect(result["elements"].size).to eq(Alchemy::Element.not_nested.count) end end - context 'with named param' do - let!(:other_element) { create(:alchemy_element, page: page, name: 'news') } + context "with named param" do + let!(:other_element) { create(:alchemy_element, page: page, name: "news") } it "returns only elements named like this." do - get :index, params: {named: 'news', format: :json} + get :index, params: {named: "news", format: :json} expect(response.status).to eq(200) - expect(response.media_type).to eq('application/json') + expect(response.media_type).to eq("application/json") result = JSON.parse(response.body) - expect(result).to have_key('elements') - expect(result['elements'].size).to eq(1) - expect(result['elements'][0]['name']).to eq('news') + expect(result).to have_key("elements") + expect(result["elements"].size).to eq(1) + expect(result["elements"][0]["name"]).to eq("news") end end - context 'with empty named param' do + context "with empty named param" do it "returns all not nested elements" do - get :index, params: {named: '', format: :json} + get :index, params: {named: "", format: :json} expect(response.status).to eq(200) - expect(response.media_type).to eq('application/json') + expect(response.media_type).to eq("application/json") result = JSON.parse(response.body) - expect(result).to have_key('elements') - expect(result['elements'].size).to eq(Alchemy::Element.not_nested.count) + expect(result).to have_key("elements") + expect(result["elements"].size).to eq(Alchemy::Element.not_nested.count) end end - context 'as author' do + context "as author" do before do authorize_user(build(:alchemy_dummy_user, :as_author)) end @@ -98,17 +98,17 @@ module Alchemy get :index, params: {format: :json} expect(response.status).to eq(200) - expect(response.media_type).to eq('application/json') + expect(response.media_type).to eq("application/json") result = JSON.parse(response.body) - expect(result).to have_key('elements') - expect(result['elements'].size).to eq(Alchemy::Element.not_nested.count) + expect(result).to have_key("elements") + expect(result["elements"].size).to eq(Alchemy::Element.not_nested.count) end end end - describe '#show' do + describe "#show" do let(:page) { create(:alchemy_page) } let(:element) { create(:alchemy_element, page: page, position: 1) } @@ -116,26 +116,26 @@ module Alchemy get :show, params: {id: element.id, format: :json} expect(response.status).to eq(200) - expect(response.media_type).to eq('application/json') + expect(response.media_type).to eq("application/json") result = JSON.parse(response.body) - expect(result['id']).to eq(element.id) + expect(result["id"]).to eq(element.id) end - context 'requesting an restricted element' do + context "requesting an restricted element" do let(:page) { create(:alchemy_page, restricted: true) } it "responds with 403" do get :show, params: {id: element.id, format: :json} expect(response.status).to eq(403) - expect(response.media_type).to eq('application/json') + expect(response.media_type).to eq("application/json") result = JSON.parse(response.body) - expect(result).to have_key('error') - expect(result['error']).to eq("Not authorized") + expect(result).to have_key("error") + expect(result["error"]).to eq("Not authorized") end end end diff --git a/spec/controllers/alchemy/api/pages_controller_spec.rb b/spec/controllers/alchemy/api/pages_controller_spec.rb index 67f08cee50..6eec37639f 100644 --- a/spec/controllers/alchemy/api/pages_controller_spec.rb +++ b/spec/controllers/alchemy/api/pages_controller_spec.rb @@ -1,40 +1,40 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" module Alchemy describe Api::PagesController do routes { Alchemy::Engine.routes } - describe '#index' do - context 'without a Language present' do + describe "#index" do + context "without a Language present" do let(:result) { JSON.parse(response.body) } - it 'returns JSON' do + it "returns JSON" do get :index, params: {format: :json} - expect(result['pages']).to eq([]) + expect(result["pages"]).to eq([]) end end - context 'with a language and a page present' do + context "with a language and a page present" do let!(:page) { create(:alchemy_page, :public) } let(:result) { JSON.parse(response.body) } - it 'returns JSON' do + it "returns JSON" do get :index, params: {format: :json} expect(response.status).to eq(200) - expect(response.media_type).to eq('application/json') - expect(result).to have_key('pages') + expect(response.media_type).to eq("application/json") + expect(result).to have_key("pages") end it "returns all public pages" do get :index, params: {format: :json} - expect(result['pages'].size).to eq(2) + expect(result["pages"].size).to eq(2) end - context 'as author' do + context "as author" do before do authorize_user(build(:alchemy_dummy_user, :as_author)) end @@ -42,20 +42,20 @@ module Alchemy it "returns all pages" do get :index, params: {format: :json} - expect(result['pages'].size).to eq(Alchemy::Page.count) + expect(result["pages"].size).to eq(Alchemy::Page.count) end end - it 'includes meta data' do + it "includes meta data" do get :index, params: { format: :json } - expect(result['pages'].size).to eq(2) - expect(result['meta']['page']).to be_nil - expect(result['meta']['per_page']).to eq(2) - expect(result['meta']['total_count']).to eq(2) + expect(result["pages"].size).to eq(2) + expect(result["meta"]["page"]).to be_nil + expect(result["meta"]["per_page"]).to eq(2) + expect(result["meta"]["total_count"]).to eq(2) end - context 'with page param given' do + context "with page param given" do let!(:page1) { create(:alchemy_page) } let!(:page2) { create(:alchemy_page) } @@ -63,49 +63,49 @@ module Alchemy expect(Kaminari.config).to receive(:default_per_page).at_least(:once) { 1 } end - it 'returns paginated result' do + it "returns paginated result" do get :index, params: { page: 2, format: :json } - expect(result['pages'].size).to eq(1) - expect(result['meta']['page']).to eq(2) - expect(result['meta']['per_page']).to eq(1) - expect(result['meta']['total_count']).to eq(2) + expect(result["pages"].size).to eq(1) + expect(result["meta"]["page"]).to eq(2) + expect(result["meta"]["per_page"]).to eq(1) + expect(result["meta"]["total_count"]).to eq(2) end end - context 'with ransack query param given' do - it 'returns filtered result' do + context "with ransack query param given" do + it "returns filtered result" do get :index, params: { q: { name_eq: page.name }, format: :json } - expect(result['pages'].size).to eq(1) + expect(result["pages"].size).to eq(1) end end end - describe '#nested' do - let!(:page) { create(:alchemy_page, :public, page_layout: 'contact') } + describe "#nested" do + let!(:page) { create(:alchemy_page, :public, page_layout: "contact") } it "returns all pages as nested json tree without admin related infos", :aggregate_failures do get :nested, params: {format: :json} expect(response.status).to eq(200) - expect(response.media_type).to eq('application/json') + expect(response.media_type).to eq("application/json") result = JSON.parse(response.body) - expect(result).to have_key('pages') - expect(result['pages'].size).to eq(1) - expect(result['pages'][0]).to have_key('children') - expect(result['pages'][0]['children'].size).to eq(1) + expect(result).to have_key("pages") + expect(result["pages"].size).to eq(1) + expect(result["pages"][0]).to have_key("children") + expect(result["pages"][0]["children"].size).to eq(1) - child = result['pages'][0]['children'][0] + child = result["pages"][0]["children"][0] - expect(child['name']).to eq(page.name) - expect(child).to_not have_key('definition_missing') - expect(child).to_not have_key('folded') - expect(child).to_not have_key('locked') - expect(child).to_not have_key('permissions') - expect(child).to_not have_key('status_titles') + expect(child["name"]).to eq(page.name) + expect(child).to_not have_key("definition_missing") + expect(child).to_not have_key("folded") + expect(child).to_not have_key("locked") + expect(child).to_not have_key("permissions") + expect(child).to_not have_key("status_titles") end context "as author" do @@ -117,51 +117,51 @@ module Alchemy get :nested, params: {format: :json} expect(response.status).to eq(200) - expect(response.media_type).to eq('application/json') + expect(response.media_type).to eq("application/json") result = JSON.parse(response.body) - expect(result).to have_key('pages') - expect(result['pages'].size).to eq(1) - expect(result['pages'][0]).to have_key('children') - expect(result['pages'][0]['children'].size).to eq(1) + expect(result).to have_key("pages") + expect(result["pages"].size).to eq(1) + expect(result["pages"][0]).to have_key("children") + expect(result["pages"][0]["children"].size).to eq(1) - child = result['pages'][0]['children'][0] + child = result["pages"][0]["children"][0] - expect(child['name']).to eq(page.name) - expect(child).to have_key('definition_missing') - expect(child).to have_key('folded') - expect(child).to have_key('locked') - expect(child).to have_key('permissions') - expect(child).to have_key('status_titles') + expect(child["name"]).to eq(page.name) + expect(child).to have_key("definition_missing") + expect(child).to have_key("folded") + expect(child).to have_key("locked") + expect(child).to have_key("permissions") + expect(child).to have_key("status_titles") end end context "when a page_id is passed" do - it 'returns all pages as nested json from this page only' do + it "returns all pages as nested json from this page only" do get :nested, params: {page_id: page.id, format: :json} expect(response.status).to eq(200) - expect(response.media_type).to eq('application/json') + expect(response.media_type).to eq("application/json") result = JSON.parse(response.body) - expect(result).to have_key('pages') - expect(result['pages'][0]['name']).to eq(page.name) + expect(result).to have_key("pages") + expect(result["pages"][0]["name"]).to eq(page.name) end end context "when `elements=true` is passed" do - it 'returns all pages as nested json tree with elements included' do - get :nested, params: {elements: 'true', format: :json} + it "returns all pages as nested json tree with elements included" do + get :nested, params: {elements: "true", format: :json} expect(response.status).to eq(200) - expect(response.media_type).to eq('application/json') + expect(response.media_type).to eq("application/json") result = JSON.parse(response.body) - expect(result).to have_key('pages') - expect(result['pages'][0]).to have_key('elements') + expect(result).to have_key("pages") + expect(result["pages"][0]).to have_key("elements") end context "and elements is a comma separated list of element names" do @@ -169,128 +169,128 @@ module Alchemy page.send(:generate_elements) end - it 'returns all pages as nested json tree with only these elements included' do - get :nested, params: {elements: 'headline,text', format: :json} + it "returns all pages as nested json tree with only these elements included" do + get :nested, params: {elements: "headline,text", format: :json} result = JSON.parse(response.body) - elements = result['pages'][0]['children'][0]['elements'] - element_names = elements.collect { |element| element['name'] } - expect(element_names).to include('headline', 'text') - expect(element_names).to_not include('contactform') + elements = result["pages"][0]["children"][0]["elements"] + element_names = elements.collect { |element| element["name"] } + expect(element_names).to include("headline", "text") + expect(element_names).to_not include("contactform") end end end end end - describe '#show' do - context 'for existing page' do - let(:page) { create(:alchemy_page, :public, urlname: 'a-page') } + describe "#show" do + context "for existing page" do + let(:page) { create(:alchemy_page, :public, urlname: "a-page") } it "returns page as json" do get :show, params: {urlname: page.urlname, format: :json} expect(response.status).to eq(200) - expect(response.media_type).to eq('application/json') + expect(response.media_type).to eq("application/json") result = JSON.parse(response.body) - expect(result['id']).to eq(page.id) + expect(result["id"]).to eq(page.id) end - context 'requesting an restricted page' do - let(:page) { create(:alchemy_page, restricted: true, urlname: 'a-page') } + context "requesting an restricted page" do + let(:page) { create(:alchemy_page, restricted: true, urlname: "a-page") } it "responds with 403" do get :show, params: {urlname: page.urlname, format: :json} expect(response.status).to eq(403) - expect(response.media_type).to eq('application/json') + expect(response.media_type).to eq("application/json") result = JSON.parse(response.body) - expect(result).to have_key('error') - expect(result['error']).to eq("Not authorized") + expect(result).to have_key("error") + expect(result["error"]).to eq("Not authorized") end end - context 'requesting a not public page' do - let(:page) { create(:alchemy_page, urlname: 'a-page') } + context "requesting a not public page" do + let(:page) { create(:alchemy_page, urlname: "a-page") } it "responds with 403" do get :show, params: {urlname: page.urlname, format: :json} expect(response.status).to eq(403) - expect(response.media_type).to eq('application/json') + expect(response.media_type).to eq("application/json") result = JSON.parse(response.body) - expect(result).to have_key('error') - expect(result['error']).to eq("Not authorized") + expect(result).to have_key("error") + expect(result["error"]).to eq("Not authorized") end end end - context 'requesting an unknown page' do + context "requesting an unknown page" do it "responds with 404" do - get :show, params: {urlname: 'not-existing', format: :json} + get :show, params: {urlname: "not-existing", format: :json} expect(response.status).to eq(404) - expect(response.media_type).to eq('application/json') + expect(response.media_type).to eq("application/json") result = JSON.parse(response.body) - expect(result).to have_key('error') - expect(result['error']).to eq("Record not found") + expect(result).to have_key("error") + expect(result["error"]).to eq("Record not found") end context "because of requesting not existing language" do let(:page) { create(:alchemy_page, :public) } it "responds with 404" do - get :show, params: {urlname: page.urlname, locale: 'na', format: :json} + get :show, params: {urlname: page.urlname, locale: "na", format: :json} expect(response.status).to eq(404) end end end - context 'requesting a page with id' do + context "requesting a page with id" do let(:page) { create(:alchemy_page, :public) } it "responds with json" do get :show, params: {urlname: page.id, format: :json} expect(response.status).to eq(200) - expect(response.media_type).to eq('application/json') + expect(response.media_type).to eq("application/json") result = JSON.parse(response.body) - expect(result['id']).to eq(page.id) + expect(result["id"]).to eq(page.id) end end - context 'in an environment with multiple languages' do + context "in an environment with multiple languages" do let!(:default_language) { create(:alchemy_language, :english, default: true) } let(:klingon) { create(:alchemy_language, :klingon) } - context 'having two pages with the same url names in different languages' do + context "having two pages with the same url names in different languages" do let!(:english_page) { create(:alchemy_page, :public, language: default_language, name: "same-name") } let!(:klingon_page) { create(:alchemy_page, :public, language: klingon, name: "same-name") } - context 'when a locale is given' do - it 'renders the page related to its language' do + context "when a locale is given" do + it "renders the page related to its language" do get :show, params: {urlname: "same-name", locale: klingon_page.language_code, format: :json} result = JSON.parse(response.body) - expect(result['id']).to eq(klingon_page.id) + expect(result["id"]).to eq(klingon_page.id) end end - context 'when no locale is given' do - it 'renders the page of the default language' do + context "when no locale is given" do + it "renders the page of the default language" do get :show, params: {urlname: "same-name", format: :json} result = JSON.parse(response.body) - expect(result['id']).to eq(english_page.id) + expect(result["id"]).to eq(english_page.id) end end end diff --git a/spec/controllers/alchemy/attachments_controller_spec.rb b/spec/controllers/alchemy/attachments_controller_spec.rb index f25a409004..86b8b6ef2e 100644 --- a/spec/controllers/alchemy/attachments_controller_spec.rb +++ b/spec/controllers/alchemy/attachments_controller_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" module Alchemy describe AttachmentsController do @@ -12,7 +12,7 @@ module Alchemy expect { get :download, params: {id: 0} }.to raise_error(ActiveRecord::RecordNotFound) end - context 'with public attachment' do + context "with public attachment" do before do allow(Attachment).to receive(:find).and_return(attachment) end @@ -20,35 +20,35 @@ module Alchemy it "sends download as attachment." do get :download, params: {id: attachment.id} expect(response.status).to eq(200) - expect(response.headers['Content-Disposition']).to match(/attachment/) + expect(response.headers["Content-Disposition"]).to match(/attachment/) end it "sends download inline." do get :show, params: {id: attachment.id} expect(response.status).to eq(200) - expect(response.headers['Content-Disposition']).to match(/inline/) + expect(response.headers["Content-Disposition"]).to match(/inline/) end context "adds Content-Length to header" do it "when downloading attachment" do get :download, params: {id: attachment.id} - expect(response.headers['Content-Length']).to eq(attachment.file_size.to_s) + expect(response.headers["Content-Length"]).to eq(attachment.file_size.to_s) end it "when showing attachment" do get :show, params: {id: attachment.id} - expect(response.headers['Content-Length']).to eq(attachment.file_size.to_s) + expect(response.headers["Content-Length"]).to eq(attachment.file_size.to_s) end end end - context 'with restricted attachment' do + context "with restricted attachment" do before do allow(attachment).to receive(:restricted?).and_return(true) allow(Attachment).to receive(:find).and_return(attachment) end - context 'as anonymous user' do + context "as anonymous user" do it "should not be possible to download attachments from restricted pages" do get :download, params: {id: attachment.id} expect(response.status).to eq(302) diff --git a/spec/controllers/alchemy/base_controller_spec.rb b/spec/controllers/alchemy/base_controller_spec.rb index 1ad49a6ba8..8287779e22 100644 --- a/spec/controllers/alchemy/base_controller_spec.rb +++ b/spec/controllers/alchemy/base_controller_spec.rb @@ -1,11 +1,11 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" module Alchemy describe BaseController do - describe '#set_locale' do - context 'with Language.current set' do + describe "#set_locale" do + context "with Language.current set" do let(:language) { create(:alchemy_language, :klingon) } before { Alchemy::Language.current = language } @@ -16,7 +16,7 @@ module Alchemy end end - context 'without Language.current set' do + context "without Language.current set" do before { Alchemy::Language.current = nil } it "does not set the ::I18n.locale" do @@ -59,14 +59,14 @@ module Alchemy let!(:default_site) { create(:alchemy_site, :default) } let!(:site_2) do - create(:alchemy_site, host: 'another-host.com') + create(:alchemy_site, host: "another-host.com") end let!(:site_2_language_2) do create(:alchemy_language, :klingon, site: site_2) end - it 'only is true for current site' do + it "only is true for current site" do is_expected.to be(false) end end @@ -83,7 +83,7 @@ module Alchemy context "and current language is not the default locale" do before do - allow(Alchemy::Language).to receive(:current) { double(code: 'kl') } + allow(Alchemy::Language).to receive(:current) { double(code: "kl") } allow(::I18n).to receive(:default_locale) { :de } end @@ -92,7 +92,7 @@ module Alchemy context "and current language is the default locale" do before do - allow(Alchemy::Language).to receive(:current) { double(code: 'de') } + allow(Alchemy::Language).to receive(:current) { double(code: "de") } allow(::I18n).to receive(:default_locale) { :de } end @@ -100,7 +100,7 @@ module Alchemy end context "and passed in locale is not the default locale" do - subject(:prefix_locale?) { controller.prefix_locale?('en') } + subject(:prefix_locale?) { controller.prefix_locale?("en") } before do allow(::I18n).to receive(:default_locale) { :de } @@ -110,7 +110,7 @@ module Alchemy end context "and passed in locale is the default locale" do - subject(:prefix_locale?) { controller.prefix_locale?('de') } + subject(:prefix_locale?) { controller.prefix_locale?("de") } before do allow(::I18n).to receive(:default_locale) { :de } diff --git a/spec/controllers/alchemy/elements_controller_spec.rb b/spec/controllers/alchemy/elements_controller_spec.rb index 2ddfc9869f..bcbe46c07a 100644 --- a/spec/controllers/alchemy/elements_controller_spec.rb +++ b/spec/controllers/alchemy/elements_controller_spec.rb @@ -1,17 +1,17 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" module Alchemy describe ElementsController do routes { Alchemy::Engine.routes } let(:public_page) { create(:alchemy_page, :public) } - let(:element) { create(:alchemy_element, page: public_page, name: 'download') } + let(:element) { create(:alchemy_element, page: public_page, name: "download") } let(:restricted_page) { create(:alchemy_page, :public, restricted: true) } - let(:restricted_element) { create(:alchemy_element, page: restricted_page, name: 'download') } + let(:restricted_element) { create(:alchemy_element, page: restricted_page, name: "download") } - describe '#show' do + describe "#show" do it "should render available elements" do get :show, params: {id: element.id} expect(response.status).to eq(200) diff --git a/spec/controllers/alchemy/messages_controller_spec.rb b/spec/controllers/alchemy/messages_controller_spec.rb index 5a8f40b1fe..504544b568 100644 --- a/spec/controllers/alchemy/messages_controller_spec.rb +++ b/spec/controllers/alchemy/messages_controller_spec.rb @@ -1,12 +1,12 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" module Alchemy describe MessagesController do routes { Alchemy::Engine.routes } - let(:page) { mock_model('Page') } + let(:page) { mock_model("Page") } before do controller.instance_variable_set(:@page, page) @@ -14,7 +14,7 @@ module Alchemy end describe "#index" do - let(:page) { mock_model('Page', {urlname: 'contact', page_layout: 'contact'}) } + let(:page) { mock_model("Page", {urlname: "contact", page_layout: "contact"}) } it "should redirect to @page" do expect(get(:index)).to redirect_to(show_page_path(urlname: page.urlname)) @@ -24,17 +24,17 @@ module Alchemy describe "#new" do it "should render the alchemy/pages/show template" do get :new - expect(get(:new)).to render_template('alchemy/pages/show') + expect(get(:new)).to render_template("alchemy/pages/show") end end describe "#create" do subject do - post :create, params: {message: {email: ''}} + post :create, params: {message: {email: ""}} end - let(:page) { mock_model('Page', get_language_root: mock_model('Page')) } - let(:element) { mock_model('Element', page: page, ingredient: '') } + let(:page) { mock_model("Page", get_language_root: mock_model("Page")) } + let(:element) { mock_model("Element", page: page, ingredient: "") } let(:message) { Message.new } it "should raise ActiveRecord::RecordNotFound if element of contactform could not be found" do @@ -44,7 +44,7 @@ module Alchemy context "if validation of message" do before do allow(Element).to receive(:find_by).and_return(element) - allow(element).to receive(:ingredient).with(:success_page).and_return('thank-you') + allow(element).to receive(:ingredient).with(:success_page).and_return("thank-you") allow_any_instance_of(Message).to receive(:contact_form_id).and_return(1) end @@ -54,7 +54,7 @@ module Alchemy end it "should render 'alchemy/pages/show' template" do - expect(subject).to render_template('alchemy/pages/show') + expect(subject).to render_template("alchemy/pages/show") end end @@ -69,16 +69,16 @@ module Alchemy subject end - describe '#mail_to' do + describe "#mail_to" do context "with element having mail_to ingredient" do before do - allow(element).to receive(:ingredient).with(:mail_to).and_return('peter@schroeder.de') + allow(element).to receive(:ingredient).with(:mail_to).and_return("peter@schroeder.de") message allow(Message).to receive(:new).and_return(message) end it "returns the ingredient" do - expect(MessagesMailer).to receive(:contact_form_mail).with(message, 'peter@schroeder.de', '', '') + expect(MessagesMailer).to receive(:contact_form_mail).with(message, "peter@schroeder.de", "", "") subject end end @@ -91,22 +91,22 @@ module Alchemy end it "returns the config value" do - expect(MessagesMailer).to receive(:contact_form_mail).with(message, 'your.mail@your-domain.com', '', '') + expect(MessagesMailer).to receive(:contact_form_mail).with(message, "your.mail@your-domain.com", "", "") subject end end end - describe '#mail_from' do + describe "#mail_from" do context "with element having mail_from ingredient" do before do - allow(element).to receive(:ingredient).with(:mail_from).and_return('peter@schroeder.de') + allow(element).to receive(:ingredient).with(:mail_from).and_return("peter@schroeder.de") message allow(Message).to receive(:new).and_return(message) end it "returns the ingredient" do - expect(MessagesMailer).to receive(:contact_form_mail).with(message, '', 'peter@schroeder.de', '') + expect(MessagesMailer).to receive(:contact_form_mail).with(message, "", "peter@schroeder.de", "") subject end end @@ -119,22 +119,22 @@ module Alchemy end it "returns the config value" do - expect(MessagesMailer).to receive(:contact_form_mail).with(message, '', 'your.mail@your-domain.com', '') + expect(MessagesMailer).to receive(:contact_form_mail).with(message, "", "your.mail@your-domain.com", "") subject end end end - describe '#subject' do + describe "#subject" do context "with element having subject ingredient" do before do - allow(element).to receive(:ingredient).with(:subject).and_return('A new message') + allow(element).to receive(:ingredient).with(:subject).and_return("A new message") message allow(Message).to receive(:new).and_return(message) end it "returns the ingredient" do - expect(MessagesMailer).to receive(:contact_form_mail).with(message, '', '', 'A new message') + expect(MessagesMailer).to receive(:contact_form_mail).with(message, "", "", "A new message") subject end end @@ -147,7 +147,7 @@ module Alchemy end it "returns the config value" do - expect(MessagesMailer).to receive(:contact_form_mail).with(message, '', '', 'A new contact form message') + expect(MessagesMailer).to receive(:contact_form_mail).with(message, "", "", "A new contact form message") subject end end @@ -155,20 +155,20 @@ module Alchemy describe "#redirect_to_success_page" do context "if 'success_page' ingredient of element" do - context 'is set with urlname string' do + context "is set with urlname string" do before do - allow(element).to receive(:ingredient).with(:success_page).and_return('success-page') + allow(element).to receive(:ingredient).with(:success_page).and_return("success-page") end it "should redirect to the given urlname" do expect( subject, - ).to redirect_to(show_page_path(urlname: 'success-page')) + ).to redirect_to(show_page_path(urlname: "success-page")) end end - context 'is set with page instance' do - let(:page) { build(:alchemy_page, name: 'Success', urlname: 'success-page') } + context "is set with page instance" do + let(:page) { build(:alchemy_page, name: "Success", urlname: "success-page") } before do allow(element).to receive(:ingredient).with(:success_page).and_return(page) @@ -177,7 +177,7 @@ module Alchemy it "should redirect to the given urlname" do expect( subject, - ).to redirect_to(show_page_path(urlname: 'success-page')) + ).to redirect_to(show_page_path(urlname: "success-page")) end end end @@ -191,34 +191,34 @@ module Alchemy before do allow(controller).to receive(:mailer_config) do { - 'fields' => %w(email), - 'forward_to_page' => true, - 'mail_success_page' => 'mailer-config-success-page', + "fields" => %w(email), + "forward_to_page" => true, + "mail_success_page" => "mailer-config-success-page", } end - allow(Page).to receive(:find_by).and_return double(urlname: 'mailer-config-success-page') + allow(Page).to receive(:find_by).and_return double(urlname: "mailer-config-success-page") end it "redirect to the given success page" do expect( subject, - ).to redirect_to(show_page_path(urlname: 'mailer-config-success-page')) + ).to redirect_to(show_page_path(urlname: "mailer-config-success-page")) end end context "and mailer_config has no instructions for success_page" do - let(:language) { mock_model('Language', code: 'en', locale: 'en', pages: double(find_by: build_stubbed(:alchemy_page))) } + let(:language) { mock_model("Language", code: "en", locale: "en", pages: double(find_by: build_stubbed(:alchemy_page))) } before do - allow(controller).to receive(:mailer_config).and_return({'fields' => %w(email)}) - allow(Language).to receive(:current_root_page).and_return double(urlname: 'lang-root') + allow(controller).to receive(:mailer_config).and_return({"fields" => %w(email)}) + allow(Language).to receive(:current_root_page).and_return double(urlname: "lang-root") end it "should redirect to the language root page" do allow(Language).to receive(:current).and_return(language) expect( subject, - ).to redirect_to(show_page_path(urlname: 'lang-root')) + ).to redirect_to(show_page_path(urlname: "lang-root")) end end end diff --git a/spec/controllers/alchemy/on_page_layout_mixin_spec.rb b/spec/controllers/alchemy/on_page_layout_mixin_spec.rb index 2c07c94a9d..2c3fc3fc8b 100644 --- a/spec/controllers/alchemy/on_page_layout_mixin_spec.rb +++ b/spec/controllers/alchemy/on_page_layout_mixin_spec.rb @@ -1,18 +1,18 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" -RSpec.describe Alchemy::PagesController, 'OnPageLayout mixin', type: :controller do +RSpec.describe Alchemy::PagesController, "OnPageLayout mixin", type: :controller do routes { Alchemy::Engine.routes } before(:all) do ApplicationController.extend Alchemy::OnPageLayout end - let(:page) { create(:alchemy_page, :public, page_layout: 'standard') } + let(:page) { create(:alchemy_page, :public, page_layout: "standard") } - describe '.on_page_layout' do - context 'with :all as argument for page_layout' do + describe ".on_page_layout" do + context "with :all as argument for page_layout" do before do ApplicationController.class_eval do on_page_layout(:all) do @@ -43,7 +43,7 @@ end end - context 'with :standard as argument for page_layout' do + context "with :standard as argument for page_layout" do before do ApplicationController.class_eval do on_page_layout(:standard) do @@ -52,28 +52,28 @@ end end - context 'and page having standard layout' do + context "and page having standard layout" do context "for show action" do - let(:page) { create(:alchemy_page, :public, page_layout: 'standard') } + let(:page) { create(:alchemy_page, :public, page_layout: "standard") } - it 'runs the callback' do + it "runs the callback" do get :show, params: {urlname: page.urlname} expect(assigns(:successful_for_standard)).to eq(true) end end context "for index action" do - let!(:page) { create(:alchemy_page, :language_root, page_layout: 'standard') } + let!(:page) { create(:alchemy_page, :language_root, page_layout: "standard") } - it 'runs the callback' do + it "runs the callback" do get :index expect(assigns(:successful_for_standard)).to eq(true) end end end - context 'and page not having standard layout' do - let(:page) { create(:alchemy_page, :public, page_layout: 'news') } + context "and page not having standard layout" do + let(:page) { create(:alchemy_page, :public, page_layout: "news") } context "for show action" do it "doesn't run the callback" do @@ -83,7 +83,7 @@ end context "for index action" do - let!(:page) { create(:alchemy_page, :language_root, page_layout: 'news') } + let!(:page) { create(:alchemy_page, :language_root, page_layout: "news") } it "doesn't run the callback" do get :index @@ -93,7 +93,7 @@ end end - context 'when defining two callbacks for different page layouts' do + context "when defining two callbacks for different page layouts" do context "for show action" do before do ApplicationController.class_eval do @@ -141,7 +141,7 @@ end end - context 'when defining two callbacks for the same page_layout' do + context "when defining two callbacks for the same page_layout" do before do ApplicationController.class_eval do on_page_layout(:standard) do @@ -155,7 +155,7 @@ end context "for show action" do - it 'runs both callbacks' do + it "runs both callbacks" do get :show, params: {urlname: page.urlname} expect(assigns(:successful_for_standard_first)).to eq(true) expect(assigns(:successful_for_standard_second)).to eq(true) @@ -163,9 +163,9 @@ end context "for index action" do - let!(:page) { create(:alchemy_page, :language_root, page_layout: 'standard') } + let!(:page) { create(:alchemy_page, :language_root, page_layout: "standard") } - it 'runs both callbacks' do + it "runs both callbacks" do get :index expect(assigns(:successful_for_standard_first)).to eq(true) expect(assigns(:successful_for_standard_second)).to eq(true) @@ -173,7 +173,7 @@ end end - context 'when block is given' do + context "when block is given" do before do ApplicationController.class_eval do on_page_layout :standard do @@ -182,24 +182,24 @@ end end - context 'for show action' do - it 'evaluates the given block' do + context "for show action" do + it "evaluates the given block" do get :show, params: {urlname: page.urlname} expect(assigns(:successful_for_callback_method)).to eq(true) end end - context 'for index action' do - let!(:page) { create(:alchemy_page, :language_root, page_layout: 'standard') } + context "for index action" do + let!(:page) { create(:alchemy_page, :language_root, page_layout: "standard") } - it 'evaluates the given block' do + it "evaluates the given block" do get :index expect(assigns(:successful_for_callback_method)).to eq(true) end end end - context 'when callback method name is given' do + context "when callback method name is given" do before do ApplicationController.class_eval do on_page_layout :standard, :run_method @@ -210,25 +210,25 @@ def run_method end end - context 'for show action' do - it 'runs the given callback method' do + context "for show action" do + it "runs the given callback method" do get :show, params: {urlname: page.urlname} expect(assigns(:successful_for_callback_method)).to eq(true) end end - context 'for index action' do - let!(:page) { create(:alchemy_page, :language_root, page_layout: 'standard') } + context "for index action" do + let!(:page) { create(:alchemy_page, :language_root, page_layout: "standard") } - it 'runs the given callback method' do + it "runs the given callback method" do get :index expect(assigns(:successful_for_callback_method)).to eq(true) end end end - context 'when neither callback method name nor block given' do - it 'raises an ArgumentError' do + context "when neither callback method name nor block given" do + it "raises an ArgumentError" do expect do ApplicationController.class_eval do on_page_layout :standard @@ -237,7 +237,7 @@ def run_method end end - context 'when passing two page_layouts for a callback' do + context "when passing two page_layouts for a callback" do before do ApplicationController.class_eval do on_page_layout([:standard, :news]) do @@ -247,7 +247,7 @@ def run_method end %w(standard news).each do |page_layout| - it 'evaluates the given callback on both page_layouts for show action' do + it "evaluates the given callback on both page_layouts for show action" do page = create(:alchemy_page, :public, page_layout: page_layout) get :show, params: {urlname: page.urlname} @@ -256,7 +256,7 @@ def run_method end %w(standard news).each do |page_layout| - it 'evaluates the given callback on both page_layouts for index action' do + it "evaluates the given callback on both page_layouts for index action" do create(:alchemy_page, :language_root, page_layout: page_layout) get :index @@ -267,7 +267,7 @@ def run_method end end -RSpec.describe ApplicationController, 'OnPageLayout mixin', type: :controller do +RSpec.describe ApplicationController, "OnPageLayout mixin", type: :controller do before(:all) do ApplicationController.extend Alchemy::OnPageLayout end @@ -279,7 +279,7 @@ def index end end - context 'in another controller' do + context "in another controller" do before do ApplicationController.class_eval do on_page_layout(:standard) do @@ -288,7 +288,7 @@ def index end end - it 'callback does not run' do + it "callback does not run" do get :index expect(assigns(:another_controller)).to eq(true) expect(assigns(:successful_for_another_controller)).to eq(nil) @@ -296,14 +296,14 @@ def index end end -RSpec.describe Alchemy::Admin::PagesController, 'OnPageLayout mixin', type: :controller do +RSpec.describe Alchemy::Admin::PagesController, "OnPageLayout mixin", type: :controller do routes { Alchemy::Engine.routes } before(:all) do ApplicationController.extend Alchemy::OnPageLayout end - context 'in admin/pages_controller' do + context "in admin/pages_controller" do before do ApplicationController.class_eval do on_page_layout(:standard) do @@ -314,16 +314,16 @@ def index end context "for show action" do - let(:page) { create(:alchemy_page, page_layout: 'standard') } + let(:page) { create(:alchemy_page, page_layout: "standard") } - it 'callback also runs' do + it "callback also runs" do get :show, params: {id: page.id} expect(assigns(:successful_for_alchemy_admin_pages_controller)).to be(true) end end context "for index action" do - it 'does not run callback' do + it "does not run callback" do get :index expect(assigns(:successful_for_alchemy_admin_pages_controller)).to be(nil) end diff --git a/spec/controllers/alchemy/pages_controller_spec.rb b/spec/controllers/alchemy/pages_controller_spec.rb index 4fc9a605c6..c3dab217be 100644 --- a/spec/controllers/alchemy/pages_controller_spec.rb +++ b/spec/controllers/alchemy/pages_controller_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require 'ostruct' -require 'rails_helper' +require "ostruct" +require "rails_helper" module Alchemy describe PagesController do @@ -10,15 +10,15 @@ module Alchemy let(:default_language) { create(:alchemy_language) } let(:default_language_root) do - create(:alchemy_page, :language_root, language: default_language, name: 'Home') + create(:alchemy_page, :language_root, language: default_language, name: "Home") end let(:page) do create :alchemy_page, :public, parent_id: default_language_root.id, - page_layout: 'news', - name: 'News', - urlname: 'news', + page_layout: "news", + name: "News", + urlname: "news", language: default_language, autogenerate_elements: true end @@ -28,8 +28,8 @@ module Alchemy end describe "#index" do - context 'without a site or language present' do - it 'returns a 404' do + context "without a site or language present" do + it "returns a 404" do expect { get(:index) }.to raise_exception( ActionController::RoutingError, 'Alchemy::Page not found "/"', @@ -37,37 +37,37 @@ module Alchemy end end - context 'with site and language root present' do + context "with site and language root present" do before do default_language_root end - it 'renders :show template' do + it "renders :show template" do expect(get(:index)).to render_template(:show) end - context 'requesting nothing' do - it 'loads default language root page' do + context "requesting nothing" do + it "loads default language root page" do get :index expect(assigns(:page)).to eq(default_language_root) end - it 'sets @root_page to default language root' do + it "sets @root_page to default language root" do get :index expect(assigns(:root_page)).to eq(default_language_root) end - context 'and the root page is not public' do + context "and the root page is not public" do before do default_language_root.update!(public_on: nil) end - context 'and redirect_to_public_child is set to false' do + context "and redirect_to_public_child is set to false" do before do stub_alchemy_config(:redirect_to_public_child, false) end - it 'raises routing error (404)' do + it "raises routing error (404)" do expect { get :index }.to raise_error(ActionController::RoutingError) @@ -77,7 +77,7 @@ module Alchemy before do ApplicationController.extend Alchemy::OnPageLayout ApplicationController.class_eval do - on_page_layout('index') { "do something" } + on_page_layout("index") { "do something" } end end @@ -89,44 +89,44 @@ module Alchemy end end - context 'and redirect_to_public_child is set to true' do + context "and redirect_to_public_child is set to true" do before do stub_alchemy_config(:redirect_to_public_child, true) end - context 'that has a public child' do + context "that has a public child" do let!(:public_child) do create(:alchemy_page, :public, parent: default_language_root) end - it 'loads this page' do + it "loads this page" do get :index expect(assigns(:page)).to eq(public_child) end end - context 'that has a non public child' do + context "that has a non public child" do let!(:non_public_child) do create(:alchemy_page, parent: default_language_root) end - context 'that has a public child' do + context "that has a public child" do let!(:public_child) do create(:alchemy_page, :public, parent: non_public_child) end - it 'loads this page' do + it "loads this page" do get :index expect(assigns(:page)).to eq(public_child) end end - context 'that has a non public child' do + context "that has a non public child" do before do create(:alchemy_page, parent: non_public_child) end - it 'raises routing error (404)' do + it "raises routing error (404)" do expect { get :index }.to raise_error(ActionController::RoutingError) @@ -137,7 +137,7 @@ module Alchemy end end - context 'requesting non default locale' do + context "requesting non default locale" do let!(:english) do create(:alchemy_language, :english, default: false) end @@ -145,26 +145,26 @@ module Alchemy let!(:start_page) do create :alchemy_page, :language_root, language: english, - name: 'Start Page' + name: "Start Page" end before do - allow(::I18n).to receive(:default_locale) { 'de' } + allow(::I18n).to receive(:default_locale) { "de" } end - it 'loads the root page of that language' do - get :index, params: {locale: 'en'} + it "loads the root page of that language" do + get :index, params: {locale: "en"} expect(assigns(:page)).to eq(start_page) end - it 'sets @root_page to root page of that language' do - get :index, params: {locale: 'en'} + it "sets @root_page to root page of that language" do + get :index, params: {locale: "en"} expect(assigns(:root_page)).to eq(start_page) end end end - describe 'requesting a not yet public page' do + describe "requesting a not yet public page" do let(:not_yet_public) do create :alchemy_page, parent: default_language_root, @@ -178,7 +178,7 @@ module Alchemy end end - describe 'requesting a no longer public page' do + describe "requesting a no longer public page" do let(:no_longer_public) do create :alchemy_page, parent: default_language_root, @@ -193,7 +193,7 @@ module Alchemy end end - describe 'requesting a still public page' do + describe "requesting a still public page" do let(:still_public_page) do create :alchemy_page, parent: default_language_root, @@ -207,7 +207,7 @@ module Alchemy end end - describe 'requesting a page without time limit' do + describe "requesting a page without time limit" do let(:still_public_page) do create :alchemy_page, parent: default_language_root, @@ -226,12 +226,12 @@ module Alchemy it "should render a rss feed" do get :show, params: {urlname: page.urlname, format: :rss} - expect(response.media_type).to eq('application/rss+xml') + expect(response.media_type).to eq("application/rss+xml") end it "should include content" do - page.elements.first.content_by_name('news_headline').essence.update_columns(body: 'Peters Petshop') - get :show, params: {urlname: 'news', format: :rss} + page.elements.first.content_by_name("news_headline").essence.update_columns(body: "Peters Petshop") + get :show, params: {urlname: "news", format: :rss} expect(response.body).to match /Peters Petshop/ end end @@ -248,7 +248,7 @@ module Alchemy it "should not render a layout" do get :show, params: {urlname: page.urlname}, xhr: true expect(response).to render_template(:show) - expect(response).not_to render_template(layout: 'application') + expect(response).not_to render_template(layout: "application") end end end @@ -256,19 +256,19 @@ module Alchemy describe "url nesting" do render_views - let(:catalog) { create(:alchemy_page, :public, name: "Catalog", urlname: 'catalog', parent: default_language_root, language: default_language, visible: true) } - let(:products) { create(:alchemy_page, :public, name: "Products", urlname: 'products', parent: catalog, language: default_language, visible: true) } - let(:product) { create(:alchemy_page, :public, name: "Screwdriver", urlname: 'screwdriver', parent: products, language: default_language, autogenerate_elements: true, visible: true) } + let(:catalog) { create(:alchemy_page, :public, name: "Catalog", urlname: "catalog", parent: default_language_root, language: default_language, visible: true) } + let(:products) { create(:alchemy_page, :public, name: "Products", urlname: "products", parent: catalog, language: default_language, visible: true) } + let(:product) { create(:alchemy_page, :public, name: "Screwdriver", urlname: "screwdriver", parent: products, language: default_language, autogenerate_elements: true, visible: true) } before do allow(Alchemy.user_class).to receive(:admins).and_return(OpenStruct.new(count: 1)) stub_alchemy_config(:url_nesting, true) - product.elements.find_by_name('article').contents.essence_texts.first.essence.update_column(:body, 'screwdriver') + product.elements.find_by_name("article").contents.essence_texts.first.essence.update_column(:body, "screwdriver") end context "with correct levelnames in params" do it "should show the requested page" do - get :show, params: {urlname: 'catalog/products/screwdriver'} + get :show, params: {urlname: "catalog/products/screwdriver"} expect(response.status).to eq(200) expect(response.body).to have_content("screwdriver") end @@ -277,7 +277,7 @@ module Alchemy context "with incorrect levelnames in params" do it "should render a 404 page" do expect { - get :show, params: {urlname: 'catalog/faqs/screwdriver'} + get :show, params: {urlname: "catalog/faqs/screwdriver"} }.to raise_error(ActionController::RoutingError) end end @@ -286,7 +286,7 @@ module Alchemy context "when a non-existent page is requested" do it "should rescue a RoutingError with rendering a 404 page." do expect { - get :show, params: {urlname: 'doesntexist'} + get :show, params: {urlname: "doesntexist"} }.to raise_error(ActionController::RoutingError) end end @@ -311,10 +311,10 @@ module Alchemy end end - context 'in an environment with multiple languages' do + context "in an environment with multiple languages" do let(:klingon) { create(:alchemy_language, :klingon) } - context 'having two pages with the same url names in different languages' do + context "having two pages with the same url names in different languages" do render_views let!(:klingon_page) { create(:alchemy_page, :public, language: klingon, name: "same-name", autogenerate_elements: true) } @@ -322,35 +322,35 @@ module Alchemy before do # Set a text in an essence rendered on the page so we can match against that - klingon_page.essence_texts.first.update_column(:body, 'klingon page') + klingon_page.essence_texts.first.update_column(:body, "klingon page") end - it 'renders the page related to its language' do + it "renders the page related to its language" do get :show, params: {urlname: "same-name", locale: klingon_page.language_code} expect(response.body).to have_content("klingon page") end end end - describe '#page_etag' do + describe "#page_etag" do subject { controller.send(:page_etag) } before do - expect(page).to receive(:cache_key).and_return('aaa') - controller.instance_variable_set('@page', page) + expect(page).to receive(:cache_key).and_return("aaa") + controller.instance_variable_set("@page", page) end it "returns the etag for response headers" do - expect(subject).to eq('aaa') + expect(subject).to eq("aaa") end - context 'with user logged in' do + context "with user logged in" do before do - authorize_user(mock_model(Alchemy.user_class, cache_key: 'bbb')) + authorize_user(mock_model(Alchemy.user_class, cache_key: "bbb")) end it "returns another etag for response headers" do - expect(subject).to eq('aaabbb') + expect(subject).to eq("aaabbb") end end end diff --git a/spec/decorators/alchemy/content_editor_spec.rb b/spec/decorators/alchemy/content_editor_spec.rb index 8d7572e145..69cf742917 100644 --- a/spec/decorators/alchemy/content_editor_spec.rb +++ b/spec/decorators/alchemy/content_editor_spec.rb @@ -1,21 +1,21 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" RSpec.describe Alchemy::ContentEditor do let(:essence) { Alchemy::EssenceText.new } let(:content) { Alchemy::Content.new(id: 1, essence: essence) } let(:content_editor) { described_class.new(content) } - describe '#content' do - it 'returns content object' do + describe "#content" do + it "returns content object" do expect(content_editor.content).to eq(content) end end describe "#css_classes" do it "includes content_editor class" do - expect(content_editor.css_classes).to include('content_editor') + expect(content_editor.css_classes).to include("content_editor") end it "includes essence partial class" do @@ -33,39 +33,39 @@ end end - describe '#to_partial_path' do + describe "#to_partial_path" do subject { content_editor.to_partial_path } - it 'returns the editor partial path' do - is_expected.to eq('alchemy/essences/essence_text_editor') + it "returns the editor partial path" do + is_expected.to eq("alchemy/essences/essence_text_editor") end end - describe '#form_field_name' do + describe "#form_field_name" do it "returns a name value for form fields with ingredient as default" do - expect(content_editor.form_field_name).to eq('contents[1][ingredient]') + expect(content_editor.form_field_name).to eq("contents[1][ingredient]") end - context 'with a essence column given' do + context "with a essence column given" do it "returns a name value for form fields for that column" do - expect(content_editor.form_field_name(:link_title)).to eq('contents[1][link_title]') + expect(content_editor.form_field_name(:link_title)).to eq("contents[1][link_title]") end end end - describe '#form_field_id' do + describe "#form_field_id" do it "returns a id value for form fields with ingredient as default" do - expect(content_editor.form_field_id).to eq('contents_1_ingredient') + expect(content_editor.form_field_id).to eq("contents_1_ingredient") end - context 'with a essence column given' do + context "with a essence column given" do it "returns a id value for form fields for that column" do - expect(content_editor.form_field_id(:link_title)).to eq('contents_1_link_title') + expect(content_editor.form_field_id(:link_title)).to eq("contents_1_link_title") end end end - describe '#respond_to?(:to_model)' do + describe "#respond_to?(:to_model)" do subject { content_editor.respond_to?(:to_model) } it { is_expected.to be(false) } diff --git a/spec/decorators/alchemy/element_editor_spec.rb b/spec/decorators/alchemy/element_editor_spec.rb index 5d2f71f828..469a3b4220 100644 --- a/spec/decorators/alchemy/element_editor_spec.rb +++ b/spec/decorators/alchemy/element_editor_spec.rb @@ -1,90 +1,90 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" RSpec.describe Alchemy::ElementEditor do let(:element) { Alchemy::Element.new } let(:element_editor) { described_class.new(element) } - describe '#element' do - it 'returns element object' do + describe "#element" do + it "returns element object" do expect(element_editor.element).to eq(element) end end - describe '#to_partial_path' do + describe "#to_partial_path" do subject { element_editor.to_partial_path } - it 'returns the editor partial path' do - is_expected.to eq('alchemy/admin/elements/element') + it "returns the editor partial path" do + is_expected.to eq("alchemy/admin/elements/element") end end - describe '#css_classes' do + describe "#css_classes" do subject { element_editor.css_classes } it "returns css classes for element editor partial" do - is_expected.to include('element-editor') + is_expected.to include("element-editor") end - context 'with element is folded' do + context "with element is folded" do let(:element) { build_stubbed(:alchemy_element, folded: true) } - it { is_expected.to include('folded') } + it { is_expected.to include("folded") } end - context 'with element is expanded' do + context "with element is expanded" do let(:element) { build_stubbed(:alchemy_element, folded: false) } - it { is_expected.to include('expanded') } + it { is_expected.to include("expanded") } end - context 'with element is taggable' do + context "with element is taggable" do before do allow(element).to receive(:taggable?) { true } end - it { is_expected.to include('taggable') } + it { is_expected.to include("taggable") } end - context 'with element is not taggable' do + context "with element is not taggable" do before do allow(element).to receive(:taggable?) { false } end - it { is_expected.to include('not-taggable') } + it { is_expected.to include("not-taggable") } end - context 'with element having content_definitions' do + context "with element having content_definitions" do before do allow(element).to receive(:content_definitions) { [1] } end - it { is_expected.to include('with-contents') } + it { is_expected.to include("with-contents") } end - context 'with element not having content_definitions' do + context "with element not having content_definitions" do before do allow(element).to receive(:content_definitions) { [] } end - it { is_expected.to include('without-contents') } + it { is_expected.to include("without-contents") } end - context 'with element having nestable_elements' do + context "with element having nestable_elements" do before do allow(element).to receive(:nestable_elements) { [1] } end - it { is_expected.to include('nestable') } + it { is_expected.to include("nestable") } end - context 'with element not having nestable_elements' do + context "with element not having nestable_elements" do before do allow(element).to receive(:nestable_elements) { [] } end - it { is_expected.to include('not-nestable') } + it { is_expected.to include("not-nestable") } end end @@ -124,7 +124,7 @@ end end - describe '#respond_to?(:to_model)' do + describe "#respond_to?(:to_model)" do subject { element_editor.respond_to?(:to_model) } it { is_expected.to be(false) } diff --git a/spec/dummy/Rakefile b/spec/dummy/Rakefile index 488c551fee..d2a78aa258 100644 --- a/spec/dummy/Rakefile +++ b/spec/dummy/Rakefile @@ -3,6 +3,6 @@ # Add your own tasks in files placed in lib/tasks ending in .rake, # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. -require_relative 'config/application' +require_relative "config/application" Rails.application.load_tasks diff --git a/spec/dummy/app/controllers/login_controller.rb b/spec/dummy/app/controllers/login_controller.rb index a64f2242d5..9ab5b154e4 100644 --- a/spec/dummy/app/controllers/login_controller.rb +++ b/spec/dummy/app/controllers/login_controller.rb @@ -2,6 +2,6 @@ class LoginController < ApplicationController def new - render plain: 'Please login' + render plain: "Please login" end end diff --git a/spec/dummy/app/models/dummy_model.rb b/spec/dummy/app/models/dummy_model.rb index 1a021d5283..7a369c9ff7 100644 --- a/spec/dummy/app/models/dummy_model.rb +++ b/spec/dummy/app/models/dummy_model.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true class DummyModel < ActiveRecord::Base - acts_as_essence ingredient_column: 'data' + acts_as_essence ingredient_column: "data" end diff --git a/spec/dummy/app/models/dummy_user.rb b/spec/dummy/app/models/dummy_user.rb index ab60542797..1f8f9f9811 100644 --- a/spec/dummy/app/models/dummy_user.rb +++ b/spec/dummy/app/models/dummy_user.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class DummyUser < ActiveRecord::Base - has_many :folded_pages, class_name: 'Alchemy::FoldedPage' + has_many :folded_pages, class_name: "Alchemy::FoldedPage" attr_writer :alchemy_roles, :name def self.logged_in diff --git a/spec/dummy/app/models/event.rb b/spec/dummy/app/models/event.rb index 4b634bc69e..2b76472b76 100644 --- a/spec/dummy/app/models/event.rb +++ b/spec/dummy/app/models/event.rb @@ -11,7 +11,7 @@ class Event < ActiveRecord::Base def self.alchemy_resource_relations { - location: {attr_method: 'name', attr_type: 'string'}, + location: {attr_method: "name", attr_type: "string"}, } end diff --git a/spec/dummy/bin/bundle b/spec/dummy/bin/bundle index 7b9c7cdc8a..db7742b94a 100755 --- a/spec/dummy/bin/bundle +++ b/spec/dummy/bin/bundle @@ -1,4 +1,4 @@ #!/usr/bin/env ruby # frozen_string_literal: true -ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../Gemfile', __dir__) -load Gem.bin_path('bundler', 'bundle') +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../../Gemfile", __dir__) +load Gem.bin_path("bundler", "bundle") diff --git a/spec/dummy/bin/rails b/spec/dummy/bin/rails index dd027b406c..cbfe38b1c3 100755 --- a/spec/dummy/bin/rails +++ b/spec/dummy/bin/rails @@ -1,5 +1,5 @@ #!/usr/bin/env ruby # frozen_string_literal: true -APP_PATH = File.expand_path('../config/application', __dir__) -require_relative '../config/boot' -require 'rails/commands' +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 609af74703..d648cf02d5 100755 --- a/spec/dummy/bin/rake +++ b/spec/dummy/bin/rake @@ -1,5 +1,5 @@ #!/usr/bin/env ruby # frozen_string_literal: true -require_relative '../config/boot' -require 'rake' +require_relative "../config/boot" +require "rake" Rake.application.run diff --git a/spec/dummy/bin/setup b/spec/dummy/bin/setup index 2905c03cac..a3bdce2222 100755 --- a/spec/dummy/bin/setup +++ b/spec/dummy/bin/setup @@ -1,9 +1,9 @@ #!/usr/bin/env ruby # frozen_string_literal: true -require 'fileutils' +require "fileutils" # path to your application root. -APP_ROOT = File.expand_path('..', __dir__) +APP_ROOT = File.expand_path("..", __dir__) def system!(*args) system(*args) || abort("\n== Command #{args} failed ==") @@ -14,9 +14,9 @@ FileUtils.chdir APP_ROOT do # This script is idempotent, so that you can run it at anytime and get an expectable outcome. # Add necessary setup steps to this file. - puts '== Installing dependencies ==' - system! 'gem install bundler --conservative' - system('bundle check') || system!('bundle install') + puts "== Installing dependencies ==" + system! "gem install bundler --conservative" + system("bundle check") || system!("bundle install") # Install JavaScript dependencies if using Yarn # system('bin/yarn') @@ -27,11 +27,11 @@ FileUtils.chdir APP_ROOT do # end puts "\n== Preparing database ==" - system! 'bin/rails db:prepare' + system! "bin/rails db:prepare" puts "\n== Removing old logs and tempfiles ==" - system! 'bin/rails log:clear tmp:clear' + system! "bin/rails log:clear tmp:clear" puts "\n== Restarting application server ==" - system! 'bin/rails restart' + system! "bin/rails restart" end diff --git a/spec/dummy/bin/update b/spec/dummy/bin/update index b666346500..965978f20c 100755 --- a/spec/dummy/bin/update +++ b/spec/dummy/bin/update @@ -1,10 +1,10 @@ #!/usr/bin/env ruby # frozen_string_literal: true -require 'fileutils' +require "fileutils" include FileUtils # path to your application root. -APP_ROOT = File.expand_path('..', __dir__) +APP_ROOT = File.expand_path("..", __dir__) def system!(*args) system(*args) || abort("\n== Command #{args} failed ==") @@ -14,19 +14,19 @@ chdir APP_ROOT do # This script is a way to update your development environment automatically. # Add necessary update steps to this file. - puts '== Installing dependencies ==' - system! 'gem install bundler --conservative' - system('bundle check') || system!('bundle install') + puts "== Installing dependencies ==" + system! "gem install bundler --conservative" + system("bundle check") || system!("bundle install") # Install JavaScript dependencies if using Yarn # system('bin/yarn') puts "\n== Updating database ==" - system! 'bin/rails db:migrate' + system! "bin/rails db:migrate" puts "\n== Removing old logs and tempfiles ==" - system! 'bin/rails log:clear tmp:clear' + system! "bin/rails log:clear tmp:clear" puts "\n== Restarting application server ==" - system! 'bin/rails restart' + system! "bin/rails restart" end diff --git a/spec/dummy/config.ru b/spec/dummy/config.ru index 8c92c11334..a591fdd72c 100644 --- a/spec/dummy/config.ru +++ b/spec/dummy/config.ru @@ -1,5 +1,5 @@ # frozen_string_literal: true # This file is used by Rack-based servers to start the application. -require_relative 'config/environment' +require_relative "config/environment" run Rails.application diff --git a/spec/factories.rb b/spec/factories.rb index 700088afaa..f9ab08b0f3 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -2,8 +2,8 @@ FactoryBot.define do factory :event do - name { 'My Event' } - hidden_name { 'not shown' } + name { "My Event" } + hidden_name { "not shown" } location starts_at { Time.local(2012, 03, 02, 8, 15) } ends_at { Time.local(2012, 03, 02, 19, 30) } @@ -15,10 +15,10 @@ end factory :location do - name { 'Awesome Lodge' } + name { "Awesome Lodge" } end factory :series do - name { 'My Series' } + name { "My Series" } end end diff --git a/spec/features/admin/admin_layout_spec.rb b/spec/features/admin/admin_layout_spec.rb index 2a6569fb01..e0ff59dd8f 100644 --- a/spec/features/admin/admin_layout_spec.rb +++ b/spec/features/admin/admin_layout_spec.rb @@ -1,16 +1,16 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" -RSpec.describe 'Admin layout', type: :system do +RSpec.describe "Admin layout", type: :system do let(:user) { create(:alchemy_dummy_user, :as_admin, name: "Joe User") } before do authorize_user(user) end - it 'has controller and action name as body class' do + it "has controller and action name as body class" do visit admin_path - expect(page).to have_selector('body.dashboard.index') + expect(page).to have_selector("body.dashboard.index") end end diff --git a/spec/features/admin/attachment_assignment_overlay_spec.rb b/spec/features/admin/attachment_assignment_overlay_spec.rb index 665abd9226..f5fd45bcb2 100644 --- a/spec/features/admin/attachment_assignment_overlay_spec.rb +++ b/spec/features/admin/attachment_assignment_overlay_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" RSpec.describe "Attachment assignment overlay", type: :system do before do diff --git a/spec/features/admin/dashboard_spec.rb b/spec/features/admin/dashboard_spec.rb index 16f0a08a2d..480ea4038b 100644 --- a/spec/features/admin/dashboard_spec.rb +++ b/spec/features/admin/dashboard_spec.rb @@ -1,15 +1,15 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" -RSpec.describe 'Dashboard feature', type: :system do +RSpec.describe "Dashboard feature", type: :system do let(:user) { create(:alchemy_dummy_user, :as_admin, name: "Joe User") } before do authorize_user(user) end - describe 'Locked pages summary' do + describe "Locked pages summary" do let(:a_page) { create(:alchemy_page, :public, visible: true) } it "should initially show no pages are locked" do @@ -19,7 +19,7 @@ expect(locked_pages_widget).to have_content "no pages" end - context 'When locked by current user' do + context "When locked by current user" do it "should show locked by me" do a_page.lock_to!(user) visit admin_dashboard_path @@ -30,7 +30,7 @@ end end - context 'When locked by another user' do + context "When locked by another user" do let(:other_user) { create(:alchemy_dummy_user, :as_admin) } it "shows the name of the user who locked the page" do @@ -44,10 +44,10 @@ end end - describe 'Sites widget' do - context 'with multiple sites' do + describe "Sites widget" do + context "with multiple sites" do let!(:default_site) { create(:alchemy_site, :default) } - let!(:another_site) { create(:alchemy_site, name: 'Site', host: 'site.com') } + let!(:another_site) { create(:alchemy_site, name: "Site", host: "site.com") } it "lists all sites" do visit admin_dashboard_path @@ -57,9 +57,9 @@ expect(sites_widget).to have_content "Site" end - context 'with alchemy url proxy object having `login_url`' do + context "with alchemy url proxy object having `login_url`" do before do - allow_any_instance_of(ActionDispatch::Routing::RoutesProxy).to receive(:login_url).and_return('http://site.com/admin/login') + allow_any_instance_of(ActionDispatch::Routing::RoutesProxy).to receive(:login_url).and_return("http://site.com/admin/login") end it "links to login page of every site" do @@ -70,7 +70,7 @@ end end - context 'with only one site' do + context "with only one site" do it "does not display" do visit admin_dashboard_path sites_widget = all('div[@class="widget sites"]').first @@ -79,8 +79,8 @@ end end - describe 'Online users' do - context 'with alchemy users' do + describe "Online users" do + context "with alchemy users" do let(:other_user) { build_stubbed(:alchemy_dummy_user) } before do @@ -96,10 +96,10 @@ end end - context 'with non alchemy user class' do + context "with non alchemy user class" do class SomeUser; end before do - Alchemy.user_class_name = 'SomeUser' + Alchemy.user_class_name = "SomeUser" end it "does not list online users" do @@ -109,7 +109,7 @@ class SomeUser; end end after do - Alchemy.user_class_name = 'DummyUser' + Alchemy.user_class_name = "DummyUser" end end end diff --git a/spec/features/admin/edit_elements_feature_spec.rb b/spec/features/admin/edit_elements_feature_spec.rb index eecca5db14..69c87b8f88 100644 --- a/spec/features/admin/edit_elements_feature_spec.rb +++ b/spec/features/admin/edit_elements_feature_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" RSpec.describe "The edit elements feature", type: :system do let!(:a_page) { create(:alchemy_page) } @@ -9,30 +9,30 @@ authorize_user(:as_editor) end - context 'Visiting the new element form' do - context 'with a page_id passed' do - scenario 'a form to select a new element for the page appears.' do + context "Visiting the new element form" do + context "with a page_id passed" do + scenario "a form to select a new element for the page appears." do visit alchemy.new_admin_element_path(page_id: a_page.id) expect(page).to have_selector('select[name="element[name]"]') end end - context 'with a page_id and parent_element_id passed' do + context "with a page_id and parent_element_id passed" do let!(:element) { create(:alchemy_element, :with_nestable_elements, page: a_page) } - scenario 'a hidden field with parent element id is in the form.' do + scenario "a hidden field with parent element id is in the form." do visit alchemy.new_admin_element_path(page_id: a_page.id, parent_element_id: element.id) expect(page).to have_selector(%(input[type="hidden"][name="element[parent_element_id]"][value="#{element.id}"])) end end end - context 'With an element having nestable elements defined' do + context "With an element having nestable elements defined" do let!(:element) { create(:alchemy_element, :with_nestable_elements, page: a_page) } - scenario 'a button to add an nestable element appears.' do + scenario "a button to add an nestable element appears." do visit alchemy.admin_elements_path(page_id: element.page_id) - expect(page).to have_selector('.add-nestable-element-button') + expect(page).to have_selector(".add-nestable-element-button") end end end diff --git a/spec/features/admin/language_tree_feature_spec.rb b/spec/features/admin/language_tree_feature_spec.rb index 2e97e313f8..c3cfc0be34 100644 --- a/spec/features/admin/language_tree_feature_spec.rb +++ b/spec/features/admin/language_tree_feature_spec.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" -RSpec.describe 'Language tree feature', type: :system, js: true do +RSpec.describe "Language tree feature", type: :system, js: true do let(:klingon) { create(:alchemy_language, :klingon) } let(:user) { build(:alchemy_dummy_user, :as_admin) } @@ -13,34 +13,34 @@ context "with a single language" do it "one should not be able to switch the language tree" do - visit('/admin/pages') - expect(page).to_not have_selector('label', text: Alchemy.t("Language tree")) + visit("/admin/pages") + expect(page).to_not have_selector("label", text: Alchemy.t("Language tree")) end end context "in a multilangual environment" do - context 'even if one language is not public' do + context "even if one language is not public" do let(:klingon) { create(:alchemy_language, :klingon, public: false) } before do - create(:alchemy_page, :language_root, name: 'Klingon', language: klingon) + create(:alchemy_page, :language_root, name: "Klingon", language: klingon) end - context 'and an author' do + context "and an author" do let(:user) { build(:alchemy_dummy_user, :as_author) } it "one should not be able to switch the language tree" do - visit('/admin/pages') - expect(page).to_not have_selector('label', text: Alchemy.t("Language tree")) + visit("/admin/pages") + expect(page).to_not have_selector("label", text: Alchemy.t("Language tree")) end end - context 'and an editor' do + context "and an editor" do let(:user) { build(:alchemy_dummy_user, :as_editor) } it "one should be able to switch the language tree" do - visit('/admin/pages') - expect(page).to have_selector('label', text: Alchemy.t("Language tree")) + visit("/admin/pages") + expect(page).to have_selector("label", text: Alchemy.t("Language tree")) end end end @@ -50,11 +50,11 @@ before { klingon } it "displays a form for creating language root with preselected page layout and front page name" do - visit('/admin/pages') - select2 'Klingon', from: 'Language tree' - expect(page).to have_content('This language tree does not exist') + visit("/admin/pages") + select2 "Klingon", from: "Language tree" + expect(page).to have_content("This language tree does not exist") - within('form#create_language_tree') do + within("form#create_language_tree") do expect(page).to \ have_selector('input[type="text"][value="' + klingon.frontpage_name + '"]') expect(page).to have_selector('option[selected="selected"][value="' + klingon.page_layout + '"]') diff --git a/spec/features/admin/languages_features_spec.rb b/spec/features/admin/languages_features_spec.rb index ca18cf7c77..16a01c1636 100644 --- a/spec/features/admin/languages_features_spec.rb +++ b/spec/features/admin/languages_features_spec.rb @@ -1,27 +1,27 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" RSpec.describe "Admin Languages Features", type: :system do before do authorize_user(:as_admin) end - describe 'creating a new language' do - context 'when selected locale is not an available locale' do + describe "creating a new language" do + context "when selected locale is not an available locale" do before do create(:alchemy_site) allow(::I18n).to receive(:available_locales) { [:de, :en] } end - it 'shows a locale select and an error message' do + it "shows a locale select and an error message" do visit alchemy.new_admin_language_path - fill_in 'language_language_code', with: 'kl' - click_button 'Save' + fill_in "language_language_code", with: "kl" + click_button "Save" - expect(page).to have_select('language_locale', options: %w(de en)) - expect(page).to have_selector('.language_locale.field_with_errors .error') + expect(page).to have_select("language_locale", options: %w(de en)) + expect(page).to have_selector(".language_locale.field_with_errors .error") end end @@ -29,20 +29,20 @@ let!(:default_site) { create(:alchemy_site, :default) } let!(:site_2) do - create(:alchemy_site, host: 'another-site.com') + create(:alchemy_site, host: "another-site.com") end let(:language) do Alchemy::Language.last end - it 'creates language for current site' do + it "creates language for current site" do visit alchemy.new_admin_language_path - fill_in "language_name", with: 'Klingon' - fill_in "language_language_code", with: 'kl' - fill_in "language_frontpage_name", with: 'Tuq' - click_button 'Save' + fill_in "language_name", with: "Klingon" + fill_in "language_language_code", with: "kl" + fill_in "language_frontpage_name", with: "Tuq" + click_button "Save" expect(language.site_id).to eq(Alchemy::Site.pluck(:id).first) expect(language.site_id).to_not eq(site_2.id) @@ -50,42 +50,42 @@ end end - describe 'editing an language' do + describe "editing an language" do let!(:language) { create(:alchemy_language) } - context 'when selected locale has multiple matching locale files' do + context "when selected locale has multiple matching locale files" do before do allow(::I18n).to receive(:available_locales) { [:de, :'de-at', :en, :'en-uk'] } end - it 'shows a locale select with matching locales only' do + it "shows a locale select with matching locales only" do visit alchemy.edit_admin_language_path(language) - expect(page).to have_select('language_locale', options: ['de', 'de-at']) + expect(page).to have_select("language_locale", options: ["de", "de-at"]) end end - context 'when selected locale has one matching locale file' do + context "when selected locale has one matching locale file" do before do allow(::I18n).to receive(:available_locales) { [:de, :en, :'en-uk'] } end - it 'shows a locale select with matching locale only' do + it "shows a locale select with matching locale only" do visit alchemy.edit_admin_language_path(language) - expect(page).to have_select('language_locale', options: %w(de)) + expect(page).to have_select("language_locale", options: %w(de)) end end - context 'when selected locale has no matching locale files' do + context "when selected locale has no matching locale files" do before do allow(::I18n).to receive(:available_locales) { [:jp, :es] } end - it 'shows a locale select with all available locales' do + it "shows a locale select with all available locales" do visit alchemy.edit_admin_language_path(language) - expect(page).to have_select('language_locale', options: %w(jp es)) + expect(page).to have_select("language_locale", options: %w(jp es)) end end end diff --git a/spec/features/admin/legacy_page_url_management_spec.rb b/spec/features/admin/legacy_page_url_management_spec.rb index d644cc075a..8df5c163fc 100644 --- a/spec/features/admin/legacy_page_url_management_spec.rb +++ b/spec/features/admin/legacy_page_url_management_spec.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" -RSpec.describe 'Legacy page url management', type: :system, js: true do +RSpec.describe "Legacy page url management", type: :system, js: true do before do authorize_user(:as_admin) end @@ -16,45 +16,45 @@ def open_page_properties it "lets a user add a page link" do open_page_properties - click_link 'Links' - fill_in 'legacy_page_url_urlname', with: 'new-urlname' - click_button 'Add' - within '#legacy_page_urls' do - expect(page).to have_content('new-urlname') + click_link "Links" + fill_in "legacy_page_url_urlname", with: "new-urlname" + click_button "Add" + within "#legacy_page_urls" do + expect(page).to have_content("new-urlname") end - within '#legacy_urls_label' do - expect(page).to have_content('(1) Link') + within "#legacy_urls_label" do + expect(page).to have_content("(1) Link") end end - context 'with wrong url format' do + context "with wrong url format" do it "displays error message" do open_page_properties - click_link 'Links' - fill_in 'legacy_page_url_urlname', with: 'invalid url name' - click_button 'Add' - within '#new_legacy_page_url' do - expect(page).to have_content('URL path is invalid') + click_link "Links" + fill_in "legacy_page_url_urlname", with: "invalid url name" + click_button "Add" + within "#new_legacy_page_url" do + expect(page).to have_content("URL path is invalid") end end end - context 'with legacy page url present' do + context "with legacy page url present" do before do - a_page.legacy_urls.create!(urlname: 'a-page-link') + a_page.legacy_urls.create!(urlname: "a-page-link") open_page_properties - click_link '(1) Link' + click_link "(1) Link" end it "lets a user remove a page link" do - click_link 'Remove' - click_button 'Yes' - within '#legacy_page_urls' do - expect(page).to_not have_content('a-page-link') - expect(page).to have_content(Alchemy.t('No page links for this page found')) + click_link "Remove" + click_button "Yes" + within "#legacy_page_urls" do + expect(page).to_not have_content("a-page-link") + expect(page).to have_content(Alchemy.t("No page links for this page found")) end - within '#legacy_urls_label' do - expect(page).to have_content('(0) Links') + within "#legacy_urls_label" do + expect(page).to have_content("(0) Links") end end end diff --git a/spec/features/admin/link_overlay_spec.rb b/spec/features/admin/link_overlay_spec.rb index 9c45b11eab..4cedb1ac1f 100644 --- a/spec/features/admin/link_overlay_spec.rb +++ b/spec/features/admin/link_overlay_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" RSpec.describe "Link overlay", type: :system do let!(:language) { create(:alchemy_language) } @@ -12,22 +12,22 @@ context "GUI" do it "has a tab for linking internal pages" do visit link_admin_pages_path - within('#overlay_tabs') { expect(page).to have_content('Internal') } + within("#overlay_tabs") { expect(page).to have_content("Internal") } end it "has a tab for adding anchor links" do visit link_admin_pages_path - within('#overlay_tabs') { expect(page).to have_content('Anchor') } + within("#overlay_tabs") { expect(page).to have_content("Anchor") } end it "has a tab for linking external pages" do visit link_admin_pages_path - within('#overlay_tabs') { expect(page).to have_content('External') } + within("#overlay_tabs") { expect(page).to have_content("External") } end it "has a tab for linking files" do visit link_admin_pages_path - within('#overlay_tabs') { expect(page).to have_content('File') } + within("#overlay_tabs") { expect(page).to have_content("File") } end end @@ -47,33 +47,33 @@ let(:article) { page1.elements.named(:article).first } before do - page1.elements.create!(name: 'article') + page1.elements.create!(name: "article") end it "should be possible to link a page" do visit edit_admin_page_path(page1) within "#element_#{article.id}" do - fill_in 'Headline', with: 'Link me' - click_link 'Link text' + fill_in "Headline", with: "Link me" + click_link "Link text" end begin within "#overlay_tab_internal_link" do - expect(page).to have_selector('#s2id_page_urlname') - select2_search(page2.name, from: 'Page') - click_link 'apply' + expect(page).to have_selector("#s2id_page_urlname") + select2_search(page2.name, from: "Page") + click_link "apply" end within "#element_#{article.id}" do - click_button 'Save' + click_button "Save" end within "#flash_notices" do - expect(page).to have_content 'Saved element.' + expect(page).to have_content "Saved element." end - click_button_with_label 'Publish page' + click_button_with_label "Publish page" visit "/#{page1.urlname}" diff --git a/spec/features/admin/locale_select_feature_spec.rb b/spec/features/admin/locale_select_feature_spec.rb index e09221b9d7..2b8f885aec 100644 --- a/spec/features/admin/locale_select_feature_spec.rb +++ b/spec/features/admin/locale_select_feature_spec.rb @@ -1,46 +1,46 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" -RSpec.describe 'Locale select', type: :system do +RSpec.describe "Locale select", type: :system do let(:a_page) { create(:alchemy_page, :public) } before do - allow(Alchemy::I18n).to receive(:translation_files).and_return ['alchemy.kl.yml', 'alchemy.jp.yml', 'alchemy.cz.yml'] + allow(Alchemy::I18n).to receive(:translation_files).and_return ["alchemy.kl.yml", "alchemy.jp.yml", "alchemy.cz.yml"] authorize_user(:as_admin) end it "contains all locales in a selectbox" do visit admin_dashboard_path - expect(page).to have_select('change_locale', options: ['Kl', 'Jp', 'Cz']) + expect(page).to have_select("change_locale", options: ["Kl", "Jp", "Cz"]) end - context 'when having available_locales set for Alchemy::I18n' do + context "when having available_locales set for Alchemy::I18n" do before do allow(Alchemy::I18n).to receive(:available_locales).and_return [:jp, :cz] end it "provides only these locales" do visit admin_dashboard_path - expect(page).to have_select('change_locale', options: ['Jp', 'Cz']) + expect(page).to have_select("change_locale", options: ["Jp", "Cz"]) end end - describe 'user selects locale' do - context 'that is available' do + describe "user selects locale" do + context "that is available" do before do allow(Alchemy::I18n).to receive(:available_locales).and_return [:kl] end - it 'switches the locale' do - visit admin_dashboard_path(admin_locale: 'kl') + it "switches the locale" do + visit admin_dashboard_path(admin_locale: "kl") expect(page).to have_content("majQa' Dub") end end - context 'that is not available' do - it 'does not switch the locale' do - visit admin_dashboard_path(admin_locale: 'de') + context "that is not available" do + it "does not switch the locale" do + visit admin_dashboard_path(admin_locale: "de") expect(page).to have_content("Welcome back") end end diff --git a/spec/features/admin/locked_page_feature_spec.rb b/spec/features/admin/locked_page_feature_spec.rb index 3197a41f12..1570b79035 100644 --- a/spec/features/admin/locked_page_feature_spec.rb +++ b/spec/features/admin/locked_page_feature_spec.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" -RSpec.describe 'Locked pages feature', type: :system do +RSpec.describe "Locked pages feature", type: :system do let(:a_page) { create(:alchemy_page) } let(:user) do @@ -14,20 +14,20 @@ authorize_user(user) end - it 'displays tab for each locked page' do + it "displays tab for each locked page" do visit alchemy.admin_pages_path - within '#locked_pages' do + within "#locked_pages" do expect(page).to have_link a_page.name, href: alchemy.edit_admin_page_path(a_page) end end - context 'with multiple languages' do + context "with multiple languages" do let!(:language) do create(:alchemy_language, :klingon) end - it 'displays information for language' do + it "displays information for language" do visit alchemy.admin_pages_path within "#locked_page_#{a_page.id}" do @@ -36,12 +36,12 @@ end end - context 'with multiple sites' do + context "with multiple sites" do let!(:site) do - create(:alchemy_site, host: 'another-site.com') + create(:alchemy_site, host: "another-site.com") end - it 'displays information for site' do + it "displays information for site" do visit alchemy.admin_pages_path within "#locked_page_#{a_page.id}" do diff --git a/spec/features/admin/menus_features_spec.rb b/spec/features/admin/menus_features_spec.rb index 3bf001d6f1..5fec88c4a3 100644 --- a/spec/features/admin/menus_features_spec.rb +++ b/spec/features/admin/menus_features_spec.rb @@ -1,40 +1,40 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" RSpec.describe "Admin Menus Features", type: :system do before do authorize_user(:as_admin) end - describe 'adding a new menu' do - context 'on the index page' do + describe "adding a new menu" do + context "on the index page" do let!(:default_language) { create(:alchemy_language) } - it 'creates menu' do + it "creates menu" do visit alchemy.admin_nodes_path - select 'Main Menu', from: 'Name' - click_button 'create' + select "Main Menu", from: "Name" + click_button "create" - expect(page).to have_selector('.node_name', text: 'Main Menu') + expect(page).to have_selector(".node_name", text: "Main Menu") end end end - describe 'adding a new menu' do - context 'with multiple sites' do + describe "adding a new menu" do + context "with multiple sites" do let!(:default_site) { create(:alchemy_site, :default) } let!(:default_language) { create(:alchemy_language, site: default_site) } - let!(:site_2) { create(:alchemy_site, host: 'another-site.com') } + let!(:site_2) { create(:alchemy_site, host: "another-site.com") } let!(:site_2_language) { create(:alchemy_language, site: site_2) } let(:node) { Alchemy::Node.last } - it 'creates menu for current site' do + it "creates menu for current site" do visit alchemy.new_admin_node_path - select 'Main Menu', from: 'Name' - click_button 'create' + select "Main Menu", from: "Name" + click_button "create" expect(node.site_id).to eq(default_site.id) end diff --git a/spec/features/admin/modules_integration_spec.rb b/spec/features/admin/modules_integration_spec.rb index b14a4513e8..a2937abfaa 100644 --- a/spec/features/admin/modules_integration_spec.rb +++ b/spec/features/admin/modules_integration_spec.rb @@ -1,18 +1,18 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" RSpec.describe "Modules", type: :system do context "A custom module with a main-apps controller" do before { authorize_user(:as_admin) } it "should have a button in main_navigation, pointing to the configured controller" do - visit '/admin' - within '#main_navi' do - first('a', text: 'Events').click + visit "/admin" + within "#main_navi" do + first("a", text: "Events").click end - within '#main_content' do - expect(page).to have_content('0 Events') + within "#main_content" do + expect(page).to have_content("0 Events") end end end diff --git a/spec/features/admin/navigation_feature_spec.rb b/spec/features/admin/navigation_feature_spec.rb index 0a9746e98a..b847a04b57 100644 --- a/spec/features/admin/navigation_feature_spec.rb +++ b/spec/features/admin/navigation_feature_spec.rb @@ -1,25 +1,25 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" -RSpec.describe 'Admin navigation feature', type: :system do - context 'admin users' do +RSpec.describe "Admin navigation feature", type: :system do + context "admin users" do before { authorize_user(:as_admin) } it "can leave the admin area" do - visit '/admin/leave' - expect(page).to have_content('You are about to leave Alchemy') + visit "/admin/leave" + expect(page).to have_content("You are about to leave Alchemy") end end - context 'editor users' do + context "editor users" do let!(:default_site) { create(:alchemy_site) } before { authorize_user(:as_editor) } it "can access the languages page" do - visit '/admin' - click_on 'Languages' - expect(current_path).to eq('/admin/languages') + visit "/admin" + click_on "Languages" + expect(current_path).to eq("/admin/languages") end end end diff --git a/spec/features/admin/page_creation_feature_spec.rb b/spec/features/admin/page_creation_feature_spec.rb index af6fcd99dc..3f7401b100 100644 --- a/spec/features/admin/page_creation_feature_spec.rb +++ b/spec/features/admin/page_creation_feature_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" RSpec.describe "Page creation", type: :system do before { authorize_user(:as_admin) } @@ -9,7 +9,7 @@ context "without having a Page in the clipboard" do it "does not contain tabs" do visit new_admin_page_path - within('#main_content') { expect(page).to_not have_selector('#overlay_tabs') } + within("#main_content") { expect(page).to_not have_selector("#overlay_tabs") } end end @@ -20,7 +20,7 @@ it "contains tabs for creating a new page and pasting from clipboard" do visit new_admin_page_path - within('#overlay_tabs') { expect(page).to have_selector '#create_page_tab, #paste_page_tab' } + within("#overlay_tabs") { expect(page).to have_selector "#create_page_tab, #paste_page_tab" } end context "", js: true do @@ -32,18 +32,18 @@ end it "the create page tab is visible by default" do - within('#overlay_tabs') do - expect(page).to have_selector('#create_page_tab', visible: true) - expect(page).to have_selector('#paste_page_tab', visible: false) + within("#overlay_tabs") do + expect(page).to have_selector("#create_page_tab", visible: true) + expect(page).to have_selector("#paste_page_tab", visible: false) end end context "when clicking on an inactive tab" do it "shows that clicked tab" do - within('#overlay_tabs') do - click_link('Paste from clipboard') - expect(find('#create_page_tab')).to_not be_visible - expect(find('#paste_page_tab')).to be_visible + within("#overlay_tabs") do + click_link("Paste from clipboard") + expect(find("#create_page_tab")).to_not be_visible + expect(find("#paste_page_tab")).to be_visible end end end diff --git a/spec/features/admin/page_destroy_feature_spec.rb b/spec/features/admin/page_destroy_feature_spec.rb index d6d0ea0ae4..a8aa704d1d 100644 --- a/spec/features/admin/page_destroy_feature_spec.rb +++ b/spec/features/admin/page_destroy_feature_spec.rb @@ -1,11 +1,11 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" RSpec.describe "Page destroy feature", type: :system, js: true do before { authorize_user(:as_admin) } - context 'destroying a content page' do + context "destroying a content page" do let!(:content_page) { create(:alchemy_page) } it "deletes page and redirects to page tree" do @@ -13,8 +13,8 @@ page.find("a[href='#{admin_page_path(content_page.id)}']").click - within '.alchemy-dialog-buttons' do - click_button 'Yes' + within ".alchemy-dialog-buttons" do + click_button "Yes" end expect(page.current_path).to eq admin_pages_path @@ -22,7 +22,7 @@ end end - context 'destroying a layout page' do + context "destroying a layout page" do let!(:layout_page) { create(:alchemy_page, :layoutpage) } it "deletes page and redirects to layoutpages list" do @@ -30,8 +30,8 @@ page.find("a[href='#{admin_page_path(layout_page.id)}']").click - within '.alchemy-dialog-buttons' do - click_button 'Yes' + within ".alchemy-dialog-buttons" do + click_button "Yes" end expect(page.current_path).to eq admin_layoutpages_path diff --git a/spec/features/admin/page_editing_feature_spec.rb b/spec/features/admin/page_editing_feature_spec.rb index 74b5907136..5d15051463 100644 --- a/spec/features/admin/page_editing_feature_spec.rb +++ b/spec/features/admin/page_editing_feature_spec.rb @@ -1,16 +1,16 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" -RSpec.describe 'Page editing feature', type: :system do +RSpec.describe "Page editing feature", type: :system do let(:a_page) { create(:alchemy_page) } - context 'as author' do + context "as author" do before { authorize_user(:as_author) } - it 'cannot publish page.' do + it "cannot publish page." do visit alchemy.edit_admin_page_path(a_page) - expect(page).to_not have_selector('#publish_page_form') + expect(page).to_not have_selector("#publish_page_form") end describe "the preview frame", :js do @@ -21,26 +21,26 @@ end end - context 'as editor' do + context "as editor" do before { authorize_user(:as_editor) } - it 'can publish page.' do + it "can publish page." do visit alchemy.edit_admin_page_path(a_page) - find('#publish_page_form button').click + find("#publish_page_form button").click expect(page).to have_content Alchemy.t(:page_published, name: a_page.name) end - context 'while editing a global page' do + context "while editing a global page" do let(:a_page) { create(:alchemy_page, layoutpage: true) } - it 'can publish page.' do + it "can publish page." do visit alchemy.edit_admin_page_path(a_page) - expect(page).to have_selector('#publish_page_form') + expect(page).to have_selector("#publish_page_form") end end end - context 'as admin' do + context "as admin" do let(:a_page) { create(:alchemy_page, :public, visible: true) } before { authorize_user(:as_admin) } @@ -49,15 +49,15 @@ context "when editing a normal page" do it "should show all relevant input fields" do visit alchemy.configure_admin_page_path(a_page) - expect(page).to have_selector('input#page_urlname') - expect(page).to have_selector('input#page_title') - expect(page).to have_selector('input#page_robot_index') - expect(page).to have_selector('input#page_robot_follow') + expect(page).to have_selector("input#page_urlname") + expect(page).to have_selector("input#page_title") + expect(page).to have_selector("input#page_robot_index") + expect(page).to have_selector("input#page_robot_follow") end context "with sitemaps show_flag config option set to true" do before do - stub_alchemy_config(:sitemap, {'show_flag' => true}) + stub_alchemy_config(:sitemap, {"show_flag" => true}) end it "should show sitemap checkbox" do @@ -68,7 +68,7 @@ context "with sitemaps show_flag config option set to false" do before do - stub_alchemy_config(:sitemap, {'show_flag' => false}) + stub_alchemy_config(:sitemap, {"show_flag" => false}) end it "should not show sitemap checkbox" do @@ -83,10 +83,10 @@ it "should not show the input fields for normal pages" do visit alchemy.edit_admin_layoutpage_path(layout_page) - expect(page).to_not have_selector('input#page_urlname') - expect(page).to_not have_selector('input#page_title') - expect(page).to_not have_selector('input#page_robot_index') - expect(page).to_not have_selector('input#page_robot_follow') + expect(page).to_not have_selector("input#page_urlname") + expect(page).to_not have_selector("input#page_title") + expect(page).to_not have_selector("input#page_robot_index") + expect(page).to_not have_selector("input#page_robot_follow") end end @@ -98,7 +98,7 @@ it "should show the tag_list input field" do visit alchemy.configure_admin_page_path(a_page) - expect(page).to have_selector('input#page_tag_list') + expect(page).to have_selector("input#page_tag_list") end end end @@ -106,53 +106,53 @@ context "in preview frame" do it "the menubar does not render on the page" do visit alchemy.admin_page_path(a_page) - expect(page).not_to have_selector('#alchemy_menubar') + expect(page).not_to have_selector("#alchemy_menubar") end - context 'with menu available' do - let!(:menu) { create(:alchemy_node, name: 'Main Navigation') } - let!(:node) { create(:alchemy_node, url: '/page-1', parent: menu) } + context "with menu available" do + let!(:menu) { create(:alchemy_node, name: "Main Navigation") } + let!(:node) { create(:alchemy_node, url: "/page-1", parent: menu) } it "navigation links are not clickable" do visit alchemy.admin_page_path(a_page) - within('nav') do + within("nav") do expect(page).to have_selector('a[href="javascript: void(0)"]') end end end end - context 'in element panel' do + context "in element panel" do let!(:everything_page) do - create(:alchemy_page, page_layout: 'everything', autogenerate_elements: true) + create(:alchemy_page, page_layout: "everything", autogenerate_elements: true) end it "renders essence editors for all element contents" do visit alchemy.admin_elements_path(page_id: everything_page.id) - expect(page).to have_selector('div.content_editor.essence_boolean') - expect(page).to have_selector('div.content_editor.essence_date') - expect(page).to have_selector('div.content_editor.essence_file') - expect(page).to have_selector('div.content_editor.essence_html') - expect(page).to have_selector('div.content_editor.essence_link') - expect(page).to have_selector('div.content_editor.essence_picture') - expect(page).to have_selector('div.content_editor.essence_richtext') - expect(page).to have_selector('div.content_editor.essence_select') - expect(page).to have_selector('div.content_editor.essence_text') + expect(page).to have_selector("div.content_editor.essence_boolean") + expect(page).to have_selector("div.content_editor.essence_date") + expect(page).to have_selector("div.content_editor.essence_file") + expect(page).to have_selector("div.content_editor.essence_html") + expect(page).to have_selector("div.content_editor.essence_link") + expect(page).to have_selector("div.content_editor.essence_picture") + expect(page).to have_selector("div.content_editor.essence_richtext") + expect(page).to have_selector("div.content_editor.essence_select") + expect(page).to have_selector("div.content_editor.essence_text") end it "renders data attribute based on content name" do visit alchemy.admin_elements_path(page_id: everything_page.id) - expect(page).to have_selector('div[data-content-name=essence_boolean]') - expect(page).to have_selector('div[data-content-name=essence_date]') - expect(page).to have_selector('div[data-content-name=essence_file]') - expect(page).to have_selector('div[data-content-name=essence_html]') - expect(page).to have_selector('div[data-content-name=essence_link]') - expect(page).to have_selector('div[data-content-name=essence_picture]') - expect(page).to have_selector('div[data-content-name=essence_richtext]') - expect(page).to have_selector('div[data-content-name=essence_select]') - expect(page).to have_selector('div[data-content-name=essence_text]') + expect(page).to have_selector("div[data-content-name=essence_boolean]") + expect(page).to have_selector("div[data-content-name=essence_date]") + expect(page).to have_selector("div[data-content-name=essence_file]") + expect(page).to have_selector("div[data-content-name=essence_html]") + expect(page).to have_selector("div[data-content-name=essence_link]") + expect(page).to have_selector("div[data-content-name=essence_picture]") + expect(page).to have_selector("div[data-content-name=essence_richtext]") + expect(page).to have_selector("div[data-content-name=essence_select]") + expect(page).to have_selector("div[data-content-name=essence_text]") end end end @@ -181,10 +181,10 @@ context "when page has fixed attributes" do let!(:readonly_page) do - create(:alchemy_page, page_layout: 'readonly') + create(:alchemy_page, page_layout: "readonly") end - it 'is not possible to edit the attribute', :aggregate_failures do + it "is not possible to edit the attribute", :aggregate_failures do visit alchemy.configure_admin_page_path(readonly_page) readonly_page.fixed_attributes.all.each do |attribute, _v| expect(page).to have_selector("#page_#{attribute}[disabled=\"disabled\"]") diff --git a/spec/features/admin/page_sorting_feature_spec.rb b/spec/features/admin/page_sorting_feature_spec.rb index 1585a57f60..6f16bdf17b 100644 --- a/spec/features/admin/page_sorting_feature_spec.rb +++ b/spec/features/admin/page_sorting_feature_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" RSpec.describe "Admin page sorting", type: :system do let!(:alchemy_page) { create(:alchemy_page) } @@ -9,15 +9,15 @@ authorize_user(:as_admin) end - specify 'a sorting description is displayed to the user' do + specify "a sorting description is displayed to the user" do visit sort_admin_pages_path expect(page).to have_content(Alchemy.t(:explain_sitemap_dragndrop_sorting)) end - specify 'links to fold or edit the page and all action icons are hidden', :aggregate_failures do + specify "links to fold or edit the page and all action icons are hidden", :aggregate_failures do visit sort_admin_pages_path - expect(page).to_not have_selector('.page_folder') - expect(page).to_not have_selector('.sitemap_pagename_link') - expect(page).to_not have_selector('.sitemap_tool') + expect(page).to_not have_selector(".page_folder") + expect(page).to_not have_selector(".sitemap_pagename_link") + expect(page).to_not have_selector(".sitemap_tool") end end diff --git a/spec/features/admin/picture_assignment_overlay_spec.rb b/spec/features/admin/picture_assignment_overlay_spec.rb index f099585b3e..4b7913c808 100644 --- a/spec/features/admin/picture_assignment_overlay_spec.rb +++ b/spec/features/admin/picture_assignment_overlay_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" RSpec.describe "Picture assignment overlay", type: :system do before do @@ -37,10 +37,10 @@ describe "assigning an image" do let!(:picture) { create(:alchemy_picture) } - let(:element) { create(:alchemy_element, :with_contents, name: 'header') } + let(:element) { create(:alchemy_element, :with_contents, name: "header") } let(:content) { element.contents.last } - scenario 'it has link to assign picture to content' do + scenario "it has link to assign picture to content" do visit alchemy.admin_pictures_path(content_id: content.id) expect(page).to have_css('a[data-method="put"][href*="/admin/essence_pictures/assign"]') end diff --git a/spec/features/admin/picture_library_integration_spec.rb b/spec/features/admin/picture_library_integration_spec.rb index 94ba77d8c9..262e312cd3 100644 --- a/spec/features/admin/picture_library_integration_spec.rb +++ b/spec/features/admin/picture_library_integration_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" RSpec.describe "Picture Library", type: :system do before do @@ -8,57 +8,57 @@ end describe "Tagging" do - let!(:picture_1) { create(:alchemy_picture, tag_list: 'tag1', name: 'TaggedWith1') } - let!(:picture_2) { create(:alchemy_picture, tag_list: 'tag2', name: 'TaggedWith2') } + let!(:picture_1) { create(:alchemy_picture, tag_list: "tag1", name: "TaggedWith1") } + let!(:picture_2) { create(:alchemy_picture, tag_list: "tag2", name: "TaggedWith2") } scenario "it's possible to filter tags by clicking on its name in the tag list." do visit alchemy.admin_pictures_path - click_on 'tag1 (1)' + click_on "tag1 (1)" - expect(page).to have_content('TaggedWith1') - expect(page).not_to have_content('TaggedWith2') + expect(page).to have_content("TaggedWith1") + expect(page).not_to have_content("TaggedWith2") end scenario "it's possible to undo tag filtering by clicking on an active tag name" do visit alchemy.admin_pictures_path - click_on 'tag1 (1)' + click_on "tag1 (1)" - expect(page).to have_content('TaggedWith1') - expect(page).not_to have_content('TaggedWith2') + expect(page).to have_content("TaggedWith1") + expect(page).not_to have_content("TaggedWith2") - click_on 'tag1 (1)' + click_on "tag1 (1)" - expect(page).to have_content('TaggedWith1') - expect(page).to have_content('TaggedWith2') + expect(page).to have_content("TaggedWith1") + expect(page).to have_content("TaggedWith2") end scenario "it's possible to tighten the tag scope by clicking on another tag name." do visit alchemy.admin_pictures_path - click_on 'tag1 (1)' - click_on 'tag2 (1)' + click_on "tag1 (1)" + click_on "tag2 (1)" expect(page).to have_content("You don't have any images in your archive") end end describe "Filter by tag" do - let!(:picture) { create(:alchemy_picture, tag_list: 'bla') } + let!(:picture) { create(:alchemy_picture, tag_list: "bla") } scenario "lists all applied tags." do visit alchemy.admin_pictures_path - expect(page).to have_content('bla') + expect(page).to have_content("bla") end scenario "it's possible to filter pictures by tag." do visit alchemy.admin_pictures_path - click_on 'bla (1)' + click_on "bla (1)" - expect(page).to have_content('bla') + expect(page).to have_content("bla") end end end diff --git a/spec/features/admin/resources_integration_spec.rb b/spec/features/admin/resources_integration_spec.rb index fabb46dfe1..0e1fffe762 100644 --- a/spec/features/admin/resources_integration_spec.rb +++ b/spec/features/admin/resources_integration_spec.rb @@ -1,23 +1,23 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" RSpec.describe "Resources", type: :system do let(:event) { create(:event) } - let(:second_event) { create(:event, name: 'My second Event', entrance_fee: 12.32) } + let(:second_event) { create(:event, name: "My second Event", entrance_fee: 12.32) } before { authorize_user(:as_admin) } describe "index view" do it "should have a button for creating a new resource items" do - visit '/admin/events' - expect(page).to have_selector('#toolbar div.button_with_label a.icon_button .icon.fa-plus') + visit "/admin/events" + expect(page).to have_selector("#toolbar div.button_with_label a.icon_button .icon.fa-plus") end it "should list existing items" do event second_event - visit '/admin/events' + visit "/admin/events" expect(page).to have_content("My Event") expect(page).to have_content("something fancy") expect(page).to have_content("12.32") @@ -25,8 +25,8 @@ it "should list existing resource-items nicely formatted" do event - visit '/admin/events' - expect(page).to have_selector('div#archive_all table.list') + visit "/admin/events" + expect(page).to have_selector("div#archive_all table.list") end describe "date fields" do @@ -38,7 +38,7 @@ end it "displays date values" do - visit '/admin/bookings' + visit "/admin/bookings" expect(page).to have_content(yesterday) expect(page).to have_content(tomorrow) end @@ -47,26 +47,26 @@ describe "form for creating and updating items" do it "renders an input field according to the attribute's type" do - visit '/admin/events/new' + visit "/admin/events/new" expect(page).to have_selector('input#event_name[type="text"]') expect(page).to have_selector('input#event_starts_at[data-datepicker-type="datetime"]') expect(page).to have_selector('input#event_ends_at[data-datepicker-type="datetime"]') - expect(page).to have_selector('textarea#event_description') + expect(page).to have_selector("textarea#event_description") expect(page).to have_selector('input#event_published[type="checkbox"]') expect(page).to have_selector('input#event_lunch_starts_at[data-datepicker-type="time"]') expect(page).to have_selector('input#event_lunch_ends_at[data-datepicker-type="time"]') end it "should have a select box for associated models" do - visit '/admin/events/new' - within('form') do - expect(page).to have_selector('select') + visit "/admin/events/new" + within("form") do + expect(page).to have_selector("select") end end describe "date fields" do it "have date picker" do - visit '/admin/bookings/new' + visit "/admin/bookings/new" expect(page).to have_selector('input#booking_from[data-datepicker-type="date"]') end end @@ -78,11 +78,11 @@ let(:start_date) { 1.week.from_now } before do - visit '/admin/events/new' - fill_in 'event_name', with: 'My second event' - fill_in 'event_starts_at', with: start_date - select location.name, from: 'Location' - click_on 'Save' + visit "/admin/events/new" + fill_in "event_name", with: "My second event" + fill_in "event_starts_at", with: start_date + select location.name, from: "Location" + click_on "Save" end it "lists the new item" do @@ -97,9 +97,9 @@ context "when form filled with invalid data" do before do - visit '/admin/events/new' - fill_in 'event_name', with: '' # invalid! - click_on 'Save' + visit "/admin/events/new" + fill_in "event_name", with: "" # invalid! + click_on "Save" end it "shows the form again" do @@ -119,8 +119,8 @@ describe "updating an item" do before do visit("/admin/events/#{event.id}/edit") - fill_in 'event_name', with: 'New event name' - click_on 'Save' + fill_in "event_name", with: "New event name" + click_on "Save" end it "shows the updated value" do @@ -136,9 +136,9 @@ before do event second_event - visit '/admin/events' - within('tr', text: 'My second Event') do - click_on 'Delete' + visit "/admin/events" + within("tr", text: "My second Event") do + click_on "Delete" end end diff --git a/spec/features/admin/site_select_feature_spec.rb b/spec/features/admin/site_select_feature_spec.rb index cb4ca7207a..8d6561e8a4 100644 --- a/spec/features/admin/site_select_feature_spec.rb +++ b/spec/features/admin/site_select_feature_spec.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" -RSpec.describe 'Site select', type: :system do +RSpec.describe "Site select", type: :system do before do authorize_user(:as_admin) end @@ -10,7 +10,7 @@ context "without multiple sites" do it "does not display the site select" do visit admin_pages_path - expect(page).not_to have_select('change_site') + expect(page).not_to have_select("change_site") end end @@ -21,7 +21,7 @@ context "not on pages or languages module" do it "does not display the site select" do visit admin_dashboard_path - expect(page).not_to have_select('change_site') + expect(page).not_to have_select("change_site") end end @@ -29,26 +29,26 @@ it "contains all sites in a selectbox" do %w(admin_pages_path admin_layoutpages_path admin_languages_path).each do |module_path| visit send(module_path) - expect(page).to have_select('change_site', + expect(page).to have_select("change_site", options: [Alchemy::Site.default.name, a_site.name], selected: Alchemy::Site.default.name) end end end - context 'when switching site' do + context "when switching site" do it "stores the site in session" do visit admin_pages_path(site_id: a_site.id) - expect(page).to have_select('change_site', selected: a_site.name) + expect(page).to have_select("change_site", selected: a_site.name) visit admin_languages_path - expect(page).to have_select('change_site', selected: a_site.name) + expect(page).to have_select("change_site", selected: a_site.name) end - context 'when site id is not found' do + context "when site id is not found" do it "stores the default site in session" do - visit admin_pages_path(site_id: '') - expect(page).to have_select('change_site', selected: Alchemy::Site.default.name) + visit admin_pages_path(site_id: "") + expect(page).to have_select("change_site", selected: Alchemy::Site.default.name) end end end diff --git a/spec/features/admin/tinymce_feature_spec.rb b/spec/features/admin/tinymce_feature_spec.rb index 5577596940..604890f911 100644 --- a/spec/features/admin/tinymce_feature_spec.rb +++ b/spec/features/admin/tinymce_feature_spec.rb @@ -1,25 +1,25 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" -RSpec.describe 'TinyMCE Editor', type: :system do +RSpec.describe "TinyMCE Editor", type: :system do before do authorize_user(:as_admin) end - it 'base path should be set to tinymce asset folder' do + it "base path should be set to tinymce asset folder" do visit admin_dashboard_path expect(page).to have_content( "var tinyMCEPreInit = { base: '/assets/tinymce', suffix: '.min' };", ) end - context 'with asset host' do + context "with asset host" do before do expect(ActionController::Base.config).to receive(:asset_host_set?).and_return(true) end - it 'base path should be set to tinymce asset folder' do + it "base path should be set to tinymce asset folder" do visit admin_dashboard_path expect(page).to have_content( "var tinyMCEPreInit = { base: 'http://127.0.0.1/assets/tinymce', suffix: '.min' };", diff --git a/spec/features/navigation_spec.rb b/spec/features/navigation_spec.rb index 992e3636c1..a5283f5869 100644 --- a/spec/features/navigation_spec.rb +++ b/spec/features/navigation_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" RSpec.describe "Dummy App", type: :system do include Capybara::DSL diff --git a/spec/features/page_feature_spec.rb b/spec/features/page_feature_spec.rb index 729eb1d3a1..ea1409a6ec 100644 --- a/spec/features/page_feature_spec.rb +++ b/spec/features/page_feature_spec.rb @@ -1,20 +1,20 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" -RSpec.describe 'Show page feature:', type: :system do +RSpec.describe "Show page feature:", type: :system do let!(:default_language) { create(:alchemy_language) } let!(:default_language_root) do - create(:alchemy_page, :language_root, language: default_language, name: 'Home') + create(:alchemy_page, :language_root, language: default_language, name: "Home") end let(:public_page) do - create(:alchemy_page, :public, visible: true, name: 'Page 1') + create(:alchemy_page, :public, visible: true, name: "Page 1") end let(:public_child) do - create(:alchemy_page, :public, name: 'Public Child', parent_id: public_page.id) + create(:alchemy_page, :public, name: "Public Child", parent_id: public_page.id) end context "When no page is present" do @@ -27,26 +27,26 @@ Alchemy.user_class.delete_all end - it 'shows a welcome page' do + it "shows a welcome page" do visit "/" - expect(page).to have_content('Welcome to Alchemy') + expect(page).to have_content("Welcome to Alchemy") end end end - context 'rendered' do + context "rendered" do let(:public_page) { create(:alchemy_page, :public, autogenerate_elements: true) } - let(:article) { public_page.elements.find_by_name('article') } - let(:essence) { article.content_by_name('intro').essence } + let(:article) { public_page.elements.find_by_name("article") } + let(:essence) { article.content_by_name("intro").essence } before do - essence.update_columns(body: 'Welcome to Peters Petshop', public: true) + essence.update_columns(body: "Welcome to Peters Petshop", public: true) end it "should include all its elements and contents" do visit "/#{public_page.urlname}" - within('div#content div.article div.intro') do - expect(page).to have_content('Welcome to Peters Petshop') + within("div#content div.article div.intro") do + expect(page).to have_content("Welcome to Peters Petshop") end end end @@ -68,7 +68,7 @@ context "rendering for guest users" do it "is prohibited" do visit "/#{public_page.urlname}" - within('body') { expect(page).not_to have_selector('#alchemy_menubar') } + within("body") { expect(page).not_to have_selector("#alchemy_menubar") } end end @@ -76,7 +76,7 @@ it "is prohibited" do authorize_user(build(:alchemy_dummy_user)) visit "/#{public_page.urlname}" - within('body') { expect(page).not_to have_selector('#alchemy_menubar') } + within("body") { expect(page).not_to have_selector("#alchemy_menubar") } end end @@ -84,7 +84,7 @@ it "is allowed" do authorize_user(:as_author) visit "/#{public_page.urlname}" - within('body') { expect(page).to have_selector('#alchemy_menubar') } + within("body") { expect(page).to have_selector("#alchemy_menubar") } end end @@ -92,7 +92,7 @@ it "is allowed" do authorize_user(:as_editor) visit "/#{public_page.urlname}" - within('body') { expect(page).to have_selector('#alchemy_menubar') } + within("body") { expect(page).to have_selector("#alchemy_menubar") } end end @@ -100,7 +100,7 @@ it "is allowed" do authorize_user(:as_admin) visit "/#{public_page.urlname}" - within('body') { expect(page).to have_selector('#alchemy_menubar') } + within("body") { expect(page).to have_selector("#alchemy_menubar") } end end @@ -111,20 +111,20 @@ end it "a link to the admin area" do - within('#alchemy_menubar') do + within("#alchemy_menubar") do expect(page).to have_selector("li a[href='#{alchemy.admin_dashboard_url(host: Capybara.current_host)}']") end end it "a link to edit the current page" do - within('#alchemy_menubar') do + within("#alchemy_menubar") do expect(page).to \ have_selector("li a[href='#{alchemy.edit_admin_page_url(public_page, host: Capybara.current_host)}']") end end it "a form and button to logout of alchemy" do - within('#alchemy_menubar') do + within("#alchemy_menubar") do expect(page).to \ have_selector("li form[action='#{Alchemy.logout_path}'][method='post']") expect(page).to \ @@ -136,41 +136,41 @@ end end - describe 'navigation rendering' do - context 'with menu available' do - let(:menu) { create(:alchemy_node, name: 'Main Navigation') } - let(:page1) { create(:alchemy_page, :public, visible: true, name: 'Page 1') } - let(:page2) { create(:alchemy_page, :public, visible: true, name: 'Page 2') } + describe "navigation rendering" do + context "with menu available" do + let(:menu) { create(:alchemy_node, name: "Main Navigation") } + let(:page1) { create(:alchemy_page, :public, visible: true, name: "Page 1") } + let(:page2) { create(:alchemy_page, :public, visible: true, name: "Page 2") } let!(:node1) { create(:alchemy_node, page: page1, parent: menu) } let!(:node2) { create(:alchemy_node, page: page2, parent: menu) } it "should show the navigation with all visible pages" do - visit '/' - within('nav ul') do + visit "/" + within("nav ul") do expect(page).to have_selector('li a[href="/page-1"], li a[href="/page-2"]') end end - it 'shows the navigation in a custom controller' do - visit '/ns/locations' - within('nav ul') do + it "shows the navigation in a custom controller" do + visit "/ns/locations" + within("nav ul") do expect(page).to have_selector('li a[href="/page-1"], li a[href="/page-2"]') end end end end - describe 'accessing restricted pages' do + describe "accessing restricted pages" do let!(:restricted_page) { create(:alchemy_page, :restricted, public_on: Time.current) } - context 'as a guest user' do + context "as a guest user" do it "I am not able to visit the page" do visit restricted_page.urlname expect(current_path).to eq(Alchemy.login_path) end end - context 'as a member user' do + context "as a member user" do before do authorize_user(create(:alchemy_dummy_user)) end diff --git a/spec/features/page_redirects_spec.rb b/spec/features/page_redirects_spec.rb index e060a8daa6..465caebca0 100644 --- a/spec/features/page_redirects_spec.rb +++ b/spec/features/page_redirects_spec.rb @@ -1,28 +1,28 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" -RSpec.describe 'Requesting a page' do +RSpec.describe "Requesting a page" do let!(:default_language) { create(:alchemy_language, :english, default: true) } let!(:default_language_root) do - create(:alchemy_page, :language_root, language: default_language, name: 'Home') + create(:alchemy_page, :language_root, language: default_language, name: "Home") end let(:public_page) do - create(:alchemy_page, :public, visible: true, name: 'Page 1') + create(:alchemy_page, :public, visible: true, name: "Page 1") end let(:public_child) do - create(:alchemy_page, :public, name: 'Public Child', parent_id: public_page.id) + create(:alchemy_page, :public, name: "Public Child", parent_id: public_page.id) end context "in multi language mode" do - let(:second_page) { create(:alchemy_page, :public, name: 'Second Page') } + let(:second_page) { create(:alchemy_page, :public, name: "Second Page") } let(:legacy_url) do Alchemy::LegacyPageUrl.create( - urlname: 'index.php?option=com_content&view=article&id=48&Itemid=69', + urlname: "index.php?option=com_content&view=article&id=48&Itemid=69", page: second_page, ) end @@ -31,7 +31,7 @@ allow_any_instance_of(Alchemy::PagesController).to receive(:multi_language?).and_return(true) end - context 'if language params are given' do + context "if language params are given" do context "and page locale is default locale" do it "redirects to unprefixed locale url" do allow(::I18n).to receive(:default_locale) { public_page.language_code.to_sym } @@ -49,7 +49,7 @@ end end - context 'if no language params are given' do + context "if no language params are given" do context "and page locale is default locale" do it "doesn't prepend the url with the locale string" do allow(::I18n).to receive(:default_locale) { public_page.language_code.to_sym } @@ -90,8 +90,8 @@ public_page.update( public_on: nil, visible: false, - name: 'Not Public', - urlname: '', + name: "Not Public", + urlname: "", ) public_child end @@ -123,7 +123,7 @@ end context "if requested url is the index url" do - context 'and redirect_to_public_child is enabled' do + context "and redirect_to_public_child is enabled" do before do allow(Alchemy::Config).to receive(:get) do |arg| arg == :redirect_to_public_child ? true : Alchemy::Config.parameter(arg) @@ -132,22 +132,22 @@ context "if index page is unpublished" do let!(:public_child) do - create(:alchemy_page, :public, name: 'Public Child', parent_id: default_language_root.id) + create(:alchemy_page, :public, name: "Public Child", parent_id: default_language_root.id) end before do default_language_root.update( public_on: nil, visible: false, - name: 'Not Public', - urlname: '', + name: "Not Public", + urlname: "", ) end context "and index page locale is default locale" do - it 'redirects to public child without prefixed locale' do - visit '/' - expect(page.current_path).to eq('/public-child') + it "redirects to public child without prefixed locale" do + visit "/" + expect(page.current_path).to eq("/public-child") end end @@ -156,9 +156,9 @@ allow(::I18n).to receive(:default_locale).and_return(:de) end - it 'redirects to public child with prefixed locale' do - visit '/' - expect(page.current_path).to eq('/en/public-child') + it "redirects to public child with prefixed locale" do + visit "/" + expect(page.current_path).to eq("/en/public-child") end end end @@ -173,7 +173,7 @@ it "redirects to '/'" do visit "/#{default_language.code}" - expect(page.current_path).to eq('/') + expect(page.current_path).to eq("/") end end @@ -217,11 +217,11 @@ end context "not in multi language mode" do - let(:second_page) { create(:alchemy_page, :public, name: 'Second Page') } + let(:second_page) { create(:alchemy_page, :public, name: "Second Page") } let(:legacy_url) do Alchemy::LegacyPageUrl.create( - urlname: 'index.php?option=com_content&view=article&id=48&Itemid=69', + urlname: "index.php?option=com_content&view=article&id=48&Itemid=69", page: second_page, ) end @@ -247,24 +247,24 @@ public_page.update( visible: false, public_on: nil, - name: 'Not Public', - urlname: '', + name: "Not Public", + urlname: "", ) public_child end it "if requested page is unpublished" do - visit '/not-public' - expect(page.current_path).to eq('/public-child') + visit "/not-public" + expect(page.current_path).to eq("/public-child") end it "with normal url, if requested url has nested language code and is not public" do - visit '/en/not-public' - expect(page.current_path).to eq('/public-child') + visit "/en/not-public" + expect(page.current_path).to eq("/public-child") end end - context 'if requested url is index url' do + context "if requested url is index url" do context "when locale is prefixed" do it "redirects to normal url" do visit "/en" diff --git a/spec/features/page_seeder_spec.rb b/spec/features/page_seeder_spec.rb index a4fd1a8a8d..75b07c648b 100644 --- a/spec/features/page_seeder_spec.rb +++ b/spec/features/page_seeder_spec.rb @@ -1,16 +1,16 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" -RSpec.describe 'Page seeding', type: :system do - context 'when db/seeds/alchemy/pages.yml file is present' do +RSpec.describe "Page seeding", type: :system do + context "when db/seeds/alchemy/pages.yml file is present" do let(:seeds_file) do - 'spec/fixtures/pages.yml' + "spec/fixtures/pages.yml" end before do - FileUtils.mkdir_p(Rails.root.join('db/seeds/alchemy')) - FileUtils.cp(seeds_file, Rails.root.join('db/seeds/alchemy/pages.yml')) + FileUtils.mkdir_p(Rails.root.join("db/seeds/alchemy")) + FileUtils.cp(seeds_file, Rails.root.join("db/seeds/alchemy/pages.yml")) Alchemy::Seeder.instance_variable_set(:@_page_yml, nil) end @@ -19,26 +19,26 @@ Alchemy::Seeder.seed! end - context 'when no pages are present yet' do + context "when no pages are present yet" do before do Alchemy::Page.delete_all end - it 'seeds pages', :aggregate_failures do + it "seeds pages", :aggregate_failures do seed - expect(Alchemy::Page.find_by(name: 'Index')).to be_present - expect(Alchemy::Page.find_by(name: 'Home')).to be_present - expect(Alchemy::Page.find_by(name: 'About')).to be_present - expect(Alchemy::Page.find_by(name: 'Contact')).to be_present - expect(Alchemy::Page.find_by(name: 'Footer')).to be_present + expect(Alchemy::Page.find_by(name: "Index")).to be_present + expect(Alchemy::Page.find_by(name: "Home")).to be_present + expect(Alchemy::Page.find_by(name: "About")).to be_present + expect(Alchemy::Page.find_by(name: "Contact")).to be_present + expect(Alchemy::Page.find_by(name: "Footer")).to be_present end - context 'when more then one content root page is present' do + context "when more then one content root page is present" do let(:seeds_file) do - 'spec/fixtures/pages_with_two_roots.yml' + "spec/fixtures/pages_with_two_roots.yml" end - it 'aborts' do + it "aborts" do expect { expect { seed }.to output.to_stderr }.to raise_error(SystemExit) @@ -49,14 +49,14 @@ context "when pages are already present" do let!(:page) { create(:alchemy_page) } - it 'does not seed' do + it "does not seed" do seed - expect(Alchemy::Page.find_by(name: 'Home')).to_not be_present + expect(Alchemy::Page.find_by(name: "Home")).to_not be_present end end after do - FileUtils.rm_rf(Rails.root.join('db/seeds')) + FileUtils.rm_rf(Rails.root.join("db/seeds")) end end end diff --git a/spec/features/security_spec.rb b/spec/features/security_spec.rb index e86d38cfc6..c7fad0a782 100644 --- a/spec/features/security_spec.rb +++ b/spec/features/security_spec.rb @@ -1,11 +1,11 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" RSpec.describe "Security.", type: :system do context "If user is not logged in" do it "should see login form" do - visit '/admin/dashboard' + visit "/admin/dashboard" expect(current_path).to eq(Alchemy.login_path) end end @@ -19,8 +19,8 @@ end it "redirects every request to https." do - visit '/admin/dashboard' - expect(current_url).to eq('https://127.0.0.1/admin/dashboard') + visit "/admin/dashboard" + expect(current_url).to eq("https://127.0.0.1/admin/dashboard") end end end diff --git a/spec/features/user_seeder_spec.rb b/spec/features/user_seeder_spec.rb index 53853e6371..478f353a55 100644 --- a/spec/features/user_seeder_spec.rb +++ b/spec/features/user_seeder_spec.rb @@ -1,26 +1,26 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" -RSpec.describe 'User seeding', type: :system do - context 'when db/seeds/alchemy/users.yml file is present' do +RSpec.describe "User seeding", type: :system do + context "when db/seeds/alchemy/users.yml file is present" do let(:seeds_file) do - 'spec/fixtures/users.yml' + "spec/fixtures/users.yml" end before do - FileUtils.mkdir_p(Rails.root.join('db/seeds/alchemy')) - FileUtils.cp(seeds_file, Rails.root.join('db/seeds/alchemy/users.yml')) + FileUtils.mkdir_p(Rails.root.join("db/seeds/alchemy")) + FileUtils.cp(seeds_file, Rails.root.join("db/seeds/alchemy/users.yml")) end - it 'seeds users' do + it "seeds users" do Alchemy::Seeder.seed! - expect(DummyUser.find_by(email: 'admin@example.com')).to be_present - expect(DummyUser.find_by(email: 'member@example.com')).to be_present + expect(DummyUser.find_by(email: "admin@example.com")).to be_present + expect(DummyUser.find_by(email: "member@example.com")).to be_present end after do - FileUtils.rm_rf(Rails.root.join('db/seeds')) + FileUtils.rm_rf(Rails.root.join("db/seeds")) end end end diff --git a/spec/helpers/alchemy/admin/attachments_helper_spec.rb b/spec/helpers/alchemy/admin/attachments_helper_spec.rb index 1448495367..e5164f1724 100644 --- a/spec/helpers/alchemy/admin/attachments_helper_spec.rb +++ b/spec/helpers/alchemy/admin/attachments_helper_spec.rb @@ -1,17 +1,17 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" describe Alchemy::Admin::AttachmentsHelper do - describe '#mime_to_human' do - context 'when given mime type has no translation' do + describe "#mime_to_human" do + context "when given mime type has no translation" do it "should return the default" do - expect(helper.mime_to_human('something')).to eq('File') + expect(helper.mime_to_human("something")).to eq("File") end end it "should return the translation for the given mime type" do - expect(helper.mime_to_human('text/plain')).to eq('Text-Document') + expect(helper.mime_to_human("text/plain")).to eq("Text-Document") end end end diff --git a/spec/helpers/alchemy/admin/base_helper_spec.rb b/spec/helpers/alchemy/admin/base_helper_spec.rb index 49d9a8ef5a..abab59dd87 100644 --- a/spec/helpers/alchemy/admin/base_helper_spec.rb +++ b/spec/helpers/alchemy/admin/base_helper_spec.rb @@ -1,10 +1,10 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" module Alchemy describe Admin::BaseHelper do - describe '#toolbar_button' do + describe "#toolbar_button" do context "with permission" do before { allow(helper).to receive(:can?).and_return(true) } @@ -46,7 +46,7 @@ module Alchemy expect( helper.toolbar_button( url: admin_dashboard_path, - if_permitted_to: '', + if_permitted_to: "", ), ).not_to be_empty end @@ -76,44 +76,44 @@ module Alchemy end end - describe '#clipboard_select_tag_options' do + describe "#clipboard_select_tag_options" do let(:page) { build_stubbed(:alchemy_page) } - before { helper.instance_variable_set('@page', page) } + before { helper.instance_variable_set("@page", page) } - context 'with element items' do + context "with element items" do let(:element) { build_stubbed(:alchemy_element) } let(:clipboard_items) { [element] } it "should include select options with the display name and preview text" do - allow(element).to receive(:display_name_with_preview_text).and_return('Name with Preview text') - expect(helper.clipboard_select_tag_options(clipboard_items)).to have_selector('option', text: 'Name with Preview text') + allow(element).to receive(:display_name_with_preview_text).and_return("Name with Preview text") + expect(helper.clipboard_select_tag_options(clipboard_items)).to have_selector("option", text: "Name with Preview text") end end - context 'with page items' do - let(:page_in_clipboard) { build_stubbed(:alchemy_page, name: 'Page name') } + context "with page items" do + let(:page_in_clipboard) { build_stubbed(:alchemy_page, name: "Page name") } let(:clipboard_items) { [page_in_clipboard] } it "should include select options with page names" do - expect(helper.clipboard_select_tag_options(clipboard_items)).to have_selector('option', text: 'Page name') + expect(helper.clipboard_select_tag_options(clipboard_items)).to have_selector("option", text: "Page name") end end end - describe '#button_with_confirm' do + describe "#button_with_confirm" do subject { button_with_confirm } it "renders a button tag with a data attribute for confirm dialog" do - is_expected.to have_selector('button[data-alchemy-confirm]') + is_expected.to have_selector("button[data-alchemy-confirm]") end end - describe '#delete_button' do - subject { delete_button('/admin/pages') } + describe "#delete_button" do + subject { delete_button("/admin/pages") } it "renders a button tag" do - is_expected.to have_selector('button') + is_expected.to have_selector("button") end it "returns a form tag with method=delete" do @@ -121,7 +121,7 @@ module Alchemy end end - describe '#alchemy_datepicker' do + describe "#alchemy_datepicker" do subject { alchemy_datepicker(essence, :date, {value: value, type: type}) } let(:essence) { EssenceDate.new } @@ -156,8 +156,8 @@ module Alchemy end end - context 'with date stored on object' do - let(:date) { Time.parse('1976-10-07 00:00 Z') } + context "with date stored on object" do + let(:date) { Time.parse("1976-10-07 00:00 Z") } let(:essence) { EssenceDate.new(date: date) } it "sets this date as value" do @@ -166,35 +166,35 @@ module Alchemy end end - describe '#current_alchemy_user_name' do + describe "#current_alchemy_user_name" do subject { helper.current_alchemy_user_name } before { expect(helper).to receive(:current_alchemy_user).and_return(user) } - context 'with a user having a `alchemy_display_name` method' do - let(:user) { double('User', alchemy_display_name: 'Peter Schroeder') } + context "with a user having a `alchemy_display_name` method" do + let(:user) { double("User", alchemy_display_name: "Peter Schroeder") } it "Returns a span showing the name of the currently logged in user." do - is_expected.to have_content("#{Alchemy.t('Logged in as')} Peter Schroeder") + is_expected.to have_content("#{Alchemy.t("Logged in as")} Peter Schroeder") is_expected.to have_selector("span.current-user-name") end end - context 'with a user not having a `alchemy_display_name` method' do - let(:user) { double('User', name: 'Peter Schroeder') } + context "with a user not having a `alchemy_display_name` method" do + let(:user) { double("User", name: "Peter Schroeder") } it { is_expected.to be_nil } end end - describe '#link_url_regexp' do + describe "#link_url_regexp" do subject { helper.link_url_regexp } it "returns the regular expression for external link urls" do expect(subject).to be_a(Regexp) end - context 'if the expression from config is nil' do + context "if the expression from config is nil" do before do stub_alchemy_config(:format_matchers, {link_url: nil}) end @@ -205,20 +205,20 @@ module Alchemy end end - describe '#hint_with_tooltip' do - subject { helper.hint_with_tooltip('My hint') } + describe "#hint_with_tooltip" do + subject { helper.hint_with_tooltip("My hint") } - it 'renders a warning icon with hint text wrapped in tooltip', :aggregate_failures do - is_expected.to have_css 'span.hint-with-icon i.fa-exclamation-triangle' - is_expected.to have_css 'span.hint-with-icon span.hint-bubble' - is_expected.to have_content 'My hint' + it "renders a warning icon with hint text wrapped in tooltip", :aggregate_failures do + is_expected.to have_css "span.hint-with-icon i.fa-exclamation-triangle" + is_expected.to have_css "span.hint-with-icon span.hint-bubble" + is_expected.to have_content "My hint" end - context 'with icon set to info' do - subject { helper.hint_with_tooltip('My hint', icon: 'info') } + context "with icon set to info" do + subject { helper.hint_with_tooltip("My hint", icon: "info") } - it 'renders an info icon instead' do - is_expected.to have_css 'i.fa-info' + it "renders an info icon instead" do + is_expected.to have_css "i.fa-info" end end end diff --git a/spec/helpers/alchemy/admin/contents_helper_spec.rb b/spec/helpers/alchemy/admin/contents_helper_spec.rb index d3d88f183b..00f0b6399a 100644 --- a/spec/helpers/alchemy/admin/contents_helper_spec.rb +++ b/spec/helpers/alchemy/admin/contents_helper_spec.rb @@ -1,29 +1,29 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" describe Alchemy::Admin::ContentsHelper do - let(:element) { build_stubbed(:alchemy_element, name: 'article') } - let(:content) { mock_model('Content', essence_partial_name: 'essence_text') } + let(:element) { build_stubbed(:alchemy_element, name: "article") } + let(:content) { mock_model("Content", essence_partial_name: "essence_text") } - describe 'content_label' do + describe "content_label" do let(:content) do Alchemy::ContentEditor.new(build_stubbed(:alchemy_content, element: element)) end subject { helper.content_label(content) } - it 'has for attribute set to content form field id' do + it "has for attribute set to content form field id" do is_expected.to have_selector("label[for=\"#{content.form_field_id}\"]") end end - describe 'render_content_name' do + describe "render_content_name" do let(:content) do - mock_model 'Content', - name: 'intro', - definition: {name: 'intro', type: 'EssenceText'}, - name_for_label: 'Intro', + mock_model "Content", + name: "intro", + definition: {name: "intro", type: "EssenceText"}, + name_for_label: "Intro", has_validations?: false end subject { helper.render_content_name(content) } @@ -32,7 +32,7 @@ is_expected.to eq("Intro") end - context 'if content is nil' do + context "if content is nil" do let(:content) { nil } it "returns nil" do @@ -40,20 +40,20 @@ end end - context 'with missing definition' do + context "with missing definition" do before { expect(content).to receive(:definition).and_return({}) } it "renders a warning with tooltip" do - is_expected.to have_selector('.hint-with-icon .hint-bubble') - is_expected.to have_content('Intro') + is_expected.to have_selector(".hint-with-icon .hint-bubble") + is_expected.to have_content("Intro") end end - context 'with validations' do + context "with validations" do before { expect(content).to receive(:has_validations?).and_return(true) } it "show a validation indicator" do - is_expected.to have_selector('.validation_indicator') + is_expected.to have_selector(".validation_indicator") end end end diff --git a/spec/helpers/alchemy/admin/elements_helper_spec.rb b/spec/helpers/alchemy/admin/elements_helper_spec.rb index cddd13ae09..585ced135d 100644 --- a/spec/helpers/alchemy/admin/elements_helper_spec.rb +++ b/spec/helpers/alchemy/admin/elements_helper_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" module Alchemy describe Admin::ElementsHelper do @@ -8,33 +8,33 @@ module Alchemy context "passing element instances" do let(:element_objects) do [ - mock_model('Element', name: 'element_1', display_name: 'Element 1'), - mock_model('Element', name: 'element_2', display_name: 'Element 2'), + mock_model("Element", name: "element_1", display_name: "Element 1"), + mock_model("Element", name: "element_2", display_name: "Element 2"), ] end it "should return a array for option tags" do - expect(helper.elements_for_select(element_objects)).to include(['Element 1', 'element_1']) - expect(helper.elements_for_select(element_objects)).to include(['Element 2', 'element_2']) + expect(helper.elements_for_select(element_objects)).to include(["Element 1", "element_1"]) + expect(helper.elements_for_select(element_objects)).to include(["Element 2", "element_2"]) end end context "passing a hash with element definitions" do let(:element_definitions) do [{ - 'name' => 'headline', - 'contents' => [], + "name" => "headline", + "contents" => [], }] end subject { helper.elements_for_select(element_definitions) } it "should return a array for option tags" do - expect(subject).to include(['Headline', 'headline']) + expect(subject).to include(["Headline", "headline"]) end it "should render the elements display name" do - expect(Element).to receive(:display_name_for).with('headline') + expect(Element).to receive(:display_name_for).with("headline") subject end end diff --git a/spec/helpers/alchemy/admin/essences_helper_spec.rb b/spec/helpers/alchemy/admin/essences_helper_spec.rb index 0b4e661689..1ac3e99da9 100644 --- a/spec/helpers/alchemy/admin/essences_helper_spec.rb +++ b/spec/helpers/alchemy/admin/essences_helper_spec.rb @@ -1,15 +1,15 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" describe Alchemy::Admin::EssencesHelper do include Alchemy::Admin::ElementsHelper let(:element) do - create(:alchemy_element, :with_contents, name: 'article') + create(:alchemy_element, :with_contents, name: "article") end - describe '#essence_picture_thumbnail' do + describe "#essence_picture_thumbnail" do let(:essence) do build_stubbed(:alchemy_essence_picture) end @@ -28,7 +28,7 @@ have_selector("img[src].img_paddingtop") end - context 'when given content has no ingredient' do + context "when given content has no ingredient" do before { allow(content).to receive(:ingredient).and_return(nil) } it "should return nil" do @@ -47,7 +47,7 @@ allow(content).to receive(:settings) do { caption_as_textarea: true, - sizes: ['100x100', '200x200'], + sizes: ["100x100", "200x200"], } end @@ -72,7 +72,7 @@ allow(content).to receive(:settings) do { caption_as_textarea: false, - sizes: ['100x100', '200x200'], + sizes: ["100x100", "200x200"], } end diff --git a/spec/helpers/alchemy/admin/pages_helper_spec.rb b/spec/helpers/alchemy/admin/pages_helper_spec.rb index cebe8853b1..3d134e5705 100644 --- a/spec/helpers/alchemy/admin/pages_helper_spec.rb +++ b/spec/helpers/alchemy/admin/pages_helper_spec.rb @@ -1,41 +1,41 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" describe Alchemy::Admin::PagesHelper do - describe '#preview_sizes_for_select' do + describe "#preview_sizes_for_select" do it "returns a options string of preview screen sizes for select tag" do - expect(helper.preview_sizes_for_select).to include('option', 'auto', '240', '320', '480', '768', '1024', '1280') + expect(helper.preview_sizes_for_select).to include("option", "auto", "240", "320", "480", "768", "1024", "1280") end end - describe '#page_layout_label' do + describe "#page_layout_label" do let(:page) { build(:alchemy_page) } subject { helper.page_layout_label(page) } - context 'when page is not yet persisted' do - it 'displays text only' do + context "when page is not yet persisted" do + it "displays text only" do is_expected.to eq(Alchemy.t(:page_type)) end end - context 'when page is persisted' do + context "when page is persisted" do before { page.save! } - context 'with page layout existing' do - it 'displays text only' do + context "with page layout existing" do + it "displays text only" do is_expected.to eq(Alchemy.t(:page_type)) end end - context 'with page layout definition missing' do + context "with page layout definition missing" do before do expect(page).to receive(:definition).and_return([]) end - it 'displays icon with warning and tooltip' do - is_expected.to have_selector '.hint-with-icon .hint-bubble' + it "displays icon with warning and tooltip" do + is_expected.to have_selector ".hint-with-icon .hint-bubble" end end end diff --git a/spec/helpers/alchemy/admin/pictures_helper_spec.rb b/spec/helpers/alchemy/admin/pictures_helper_spec.rb index 6a5a64f619..c3c9a3320a 100644 --- a/spec/helpers/alchemy/admin/pictures_helper_spec.rb +++ b/spec/helpers/alchemy/admin/pictures_helper_spec.rb @@ -1,27 +1,27 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" describe Alchemy::Admin::PicturesHelper do describe "#preview_size" do subject { helper.preview_size(size) } context "when 'small' is passed in" do - let(:size) { 'small' } + let(:size) { "small" } - it { is_expected.to eq('80x60') } + it { is_expected.to eq("80x60") } end context "when 'large' is passed in" do - let(:size) { 'large' } + let(:size) { "large" } - it { is_expected.to eq('240x180') } + it { is_expected.to eq("240x180") } end context "when anything else is passed in" do let(:size) { nil } - it { is_expected.to eq('160x120') } + it { is_expected.to eq("160x120") } end end end diff --git a/spec/helpers/alchemy/admin/tags_helper_spec.rb b/spec/helpers/alchemy/admin/tags_helper_spec.rb index bbc87600f9..01a3a840ee 100644 --- a/spec/helpers/alchemy/admin/tags_helper_spec.rb +++ b/spec/helpers/alchemy/admin/tags_helper_spec.rb @@ -1,24 +1,24 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" module Alchemy describe Admin::TagsHelper do - let(:tag) { mock_model(Gutentag::Tag, name: 'foo', count: 1) } - let(:tag2) { mock_model(Gutentag::Tag, name: 'abc', count: 1) } + let(:tag) { mock_model(Gutentag::Tag, name: "foo", count: 1) } + let(:tag2) { mock_model(Gutentag::Tag, name: "abc", count: 1) } let(:params) do - ActionController::Parameters.new(tagged_with: 'foo') + ActionController::Parameters.new(tagged_with: "foo") end before do allow(helper).to receive(:search_filter_params) do - params.permit!.merge(controller: 'admin/attachments', action: 'index', use_route: 'alchemy') + params.permit!.merge(controller: "admin/attachments", action: "index", use_route: "alchemy") end end - describe '#render_tag_list' do - subject { helper.render_tag_list('Alchemy::Attachment') } + describe "#render_tag_list" do + subject { helper.render_tag_list("Alchemy::Attachment") } context "with tagged objects" do before { allow(Attachment).to receive(:tag_counts).and_return([tag, tag2]) } @@ -40,7 +40,7 @@ module Alchemy end context "with lowercase and uppercase tag names mixed" do - let(:tag) { mock_model(Gutentag::Tag, name: 'Foo', count: 1) } + let(:tag) { mock_model(Gutentag::Tag, name: "Foo", count: 1) } it "tags are sorted alphabetically correctly" do is_expected.to match(/li.+name="#{tag2.name}.+li.+name="#{tag.name}/) @@ -54,12 +54,12 @@ module Alchemy context "when filter and search params are present" do let(:params) do ActionController::Parameters.new( - filter: 'foo', - q: {name_eq: 'foo'}, + filter: "foo", + q: {name_eq: "foo"}, ) end - it 'keeps them' do + it "keeps them" do is_expected.to match(/filter/) is_expected.to match(/name_eq/) end @@ -82,17 +82,17 @@ module Alchemy describe "#filtered_by_tag?" do subject { helper.filtered_by_tag?(tag) } - context 'if the filter list params contains the given tag' do + context "if the filter list params contains the given tag" do let(:params) do - ActionController::Parameters.new(tagged_with: 'foo,bar,baz') + ActionController::Parameters.new(tagged_with: "foo,bar,baz") end it { is_expected.to eq(true) } end - context 'if the filter list params does not contain the given tag' do + context "if the filter list params does not contain the given tag" do let(:params) do - ActionController::Parameters.new(tagged_with: 'bar,baz') + ActionController::Parameters.new(tagged_with: "bar,baz") end it { is_expected.to eq(false) } @@ -122,7 +122,7 @@ module Alchemy context "if params[:tagged_with] contains some tag names" do let(:params) do - ActionController::Parameters.new(tagged_with: 'bar,baz') + ActionController::Parameters.new(tagged_with: "bar,baz") end it "should return a String of tag names including the given one" do @@ -132,7 +132,7 @@ module Alchemy context "if params[:tagged_with] contains current tag name" do let(:params) do - ActionController::Parameters.new(tagged_with: 'bar,baz,foo') + ActionController::Parameters.new(tagged_with: "bar,baz,foo") end it "should return a String of tag names without the current one" do diff --git a/spec/helpers/alchemy/base_helper_spec.rb b/spec/helpers/alchemy/base_helper_spec.rb index 9ee448a6f6..9d28e7887f 100644 --- a/spec/helpers/alchemy/base_helper_spec.rb +++ b/spec/helpers/alchemy/base_helper_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" module Alchemy describe BaseHelper do @@ -9,39 +9,39 @@ module Alchemy let(:options) { Hash.new } - it 'renders a solid fontawesome icon with fixed width' do - is_expected.to have_css 'i.icon.fa-info.fas.fa-fw' + it "renders a solid fontawesome icon with fixed width" do + is_expected.to have_css "i.icon.fa-info.fas.fa-fw" end - context 'with style set to regular' do - let(:options) { {style: 'regular'} } + context "with style set to regular" do + let(:options) { {style: "regular"} } - it 'renders a regular fontawesome icon' do - is_expected.to have_css 'i.far' + it "renders a regular fontawesome icon" do + is_expected.to have_css "i.far" end end - context 'with size set to xs' do - let(:options) { {size: 'xs'} } + context "with size set to xs" do + let(:options) { {size: "xs"} } - it 'renders a extra small fontawesome icon' do - is_expected.to have_css 'i.fa-xs' + it "renders a extra small fontawesome icon" do + is_expected.to have_css "i.fa-xs" end end - context 'with transform option given' do - let(:options) { {transform: 'flip-horizontal'} } + context "with transform option given" do + let(:options) { {transform: "flip-horizontal"} } - it 'renders a transformed fontawesome icon' do - is_expected.to have_css 'i.fa-flip-horizontal' + it "renders a transformed fontawesome icon" do + is_expected.to have_css "i.fa-flip-horizontal" end end - context 'with class option given' do - let(:options) { {class: 'disabled'} } + context "with class option given" do + let(:options) { {class: "disabled"} } - it 'renders a fontawesome icon with additional css class' do - is_expected.to have_css 'i.disabled' + it "renders a fontawesome icon with additional css class" do + is_expected.to have_css "i.disabled" end end end @@ -60,17 +60,17 @@ module Alchemy end end - describe '#page_or_find' do + describe "#page_or_find" do let(:page) { create(:alchemy_page, :public) } context "passing a page_layout string" do context "of a not existing page" do it "should return nil" do - expect(helper.page_or_find('contact')).to be_nil + expect(helper.page_or_find("contact")).to be_nil end end - context 'of an existing page' do + context "of an existing page" do it "should return the page object" do session[:alchemy_language_id] = page.language_id expect(helper.page_or_find(page.page_layout)).to eq(page) @@ -85,34 +85,34 @@ module Alchemy end end - describe '#message_icon_class' do + describe "#message_icon_class" do subject { helper.message_icon_class(message_type) } - context 'when `warning`, `warn` or `alert` message type is given' do + context "when `warning`, `warn` or `alert` message type is given" do %w(warning warn alert).each do |type| let(:message_type) { type } - it { is_expected.to eq 'exclamation' } + it { is_expected.to eq "exclamation" } end end - context 'when `notice` message type is given' do - let(:message_type) { 'notice' } + context "when `notice` message type is given" do + let(:message_type) { "notice" } - it { is_expected.to eq 'check' } + it { is_expected.to eq "check" } end - context 'when `error` message type is given' do - let(:message_type) { 'error' } + context "when `error` message type is given" do + let(:message_type) { "error" } - it { is_expected.to eq 'bug' } + it { is_expected.to eq "bug" } end - context 'when unknown message type is given' do - let(:message_type) { 'info' } + context "when unknown message type is given" do + let(:message_type) { "info" } - it 'returns the given message type as icon name' do - is_expected.to eq 'info' + it "returns the given message type as icon name" do + is_expected.to eq "info" end end end diff --git a/spec/helpers/alchemy/elements_block_helper_spec.rb b/spec/helpers/alchemy/elements_block_helper_spec.rb index 4b9a5c9d84..48c40765c7 100644 --- a/spec/helpers/alchemy/elements_block_helper_spec.rb +++ b/spec/helpers/alchemy/elements_block_helper_spec.rb @@ -1,16 +1,16 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" include Alchemy::ElementsHelper module Alchemy - describe 'ElementsBlockHelper' do - let(:page) { create(:alchemy_page, :public) } - let(:element) { create(:alchemy_element, page: page, tag_list: 'foo, bar') } + describe "ElementsBlockHelper" do + let(:page) { create(:alchemy_page, :public) } + let(:element) { create(:alchemy_element, page: page, tag_list: "foo, bar") } let(:expected_wrapper_tag) { "div.#{element.name}##{element_dom_id(element)}" } - describe '#element_view_for' do + describe "#element_view_for" do it "should yield an instance of ElementViewHelper" do expect { |b| element_view_for(element, &b) }. to yield_with_args(ElementsBlockHelper::ElementViewHelper) @@ -22,8 +22,8 @@ module Alchemy end it "should change the wrapping DOM element according to parameters" do - expect(element_view_for(element, tag: 'span', class: 'some_class', id: 'some_id')). - to have_css 'span.some_class#some_id' + expect(element_view_for(element, tag: "span", class: "some_class", id: "some_id")). + to have_css "span.some_class#some_id" end it "should include the element's tags in the wrapper DOM element" do @@ -38,8 +38,8 @@ module Alchemy it "should include the contents rendered by the block passed to it" do expect(element_view_for(element) do - 'view' - end).to have_content 'view' + "view" + end).to have_content "view" end context "when/if preview mode is not active" do @@ -59,15 +59,15 @@ module Alchemy end end - describe 'ElementsBlockHelper::ElementViewHelper' do + describe "ElementsBlockHelper::ElementViewHelper" do let(:scope) { double } subject { ElementsBlockHelper::ElementViewHelper.new(scope, element: element) } - it 'should have a reference to the specified element' do + it "should have a reference to the specified element" do subject.element == element end - describe '#render' do + describe "#render" do let(:element) { create(:alchemy_element, :with_contents) } let(:content) { element.content_by_name(:headline) } @@ -75,39 +75,39 @@ module Alchemy expect(scope).to receive(:render).with(content, { content: content, options: { - foo: 'bar', + foo: "bar", }, html_options: {}, }) - subject.render(:headline, foo: 'bar') + subject.render(:headline, foo: "bar") end end - describe '#content' do + describe "#content" do it "should delegate to the element's #content_by_name method" do expect(element).to receive(:content_by_name).with(:title) subject.content :title end end - describe '#ingredient' do + describe "#ingredient" do it "should delegate to the element's #ingredient method" do expect(element).to receive(:ingredient).with(:title) subject.ingredient :title end end - describe '#has?' do + describe "#has?" do it "should delegate to the element's #has_ingredient? method" do expect(element).to receive(:has_ingredient?).with(:title) subject.has? :title end end - describe '#essence' do + describe "#essence" do it "should provide the specified content essence" do expect(subject).to receive(:content).with(:title). - and_return(mock_model('Content', essence: mock_model('EssenceText'))) + and_return(mock_model("Content", essence: mock_model("EssenceText"))) subject.essence :title end diff --git a/spec/helpers/alchemy/elements_helper_spec.rb b/spec/helpers/alchemy/elements_helper_spec.rb index 4c0e0e689f..e8ff1ad9a4 100644 --- a/spec/helpers/alchemy/elements_helper_spec.rb +++ b/spec/helpers/alchemy/elements_helper_spec.rb @@ -1,38 +1,38 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" include Alchemy::BaseHelper module Alchemy describe ElementsHelper do let(:page) { build_stubbed(:alchemy_page, :public) } - let(:element) { build_stubbed(:alchemy_element, name: 'headline', page: page) } + let(:element) { build_stubbed(:alchemy_element, name: "headline", page: page) } before do assign(:page, page) allow_any_instance_of(Element).to receive(:store_page).and_return(true) end - describe '#render_element' do + describe "#render_element" do subject { render_element(element) } - context 'with nil element' do + context "with nil element" do let(:element) { nil } it { is_expected.to be_nil } end - context 'with element record given' do + context "with element record given" do let(:element) do - create(:alchemy_element, :with_contents, name: 'headline') + create(:alchemy_element, :with_contents, name: "headline") end it "renders the element's view partial" do is_expected.to have_selector("##{element.name}_#{element.id}") end - context 'with element view partial not found' do - let(:element) { build_stubbed(:alchemy_element, name: 'not_present') } + context "with element view partial not found" do + let(:element) { build_stubbed(:alchemy_element, name: "not_present") } it "renders the view not found partial" do is_expected.to match(/Missing view for not_present element/) @@ -40,24 +40,24 @@ module Alchemy end end - context 'with options given' do - subject { render_element(element, locals: { some: 'thing' }) } + context "with options given" do + subject { render_element(element, locals: { some: "thing" }) } - it 'passes them into the view' do + it "passes them into the view" do is_expected.to match(/thing/) end end - context 'with counter given' do + context "with counter given" do subject { render_element(element, {}, 2) } - it 'passes them into the view' do + it "passes them into the view" do is_expected.to match(/2\./) end end end - describe '#element_dom_id' do + describe "#element_dom_id" do subject { helper.element_dom_id(element) } it "should render a unique dom id for element" do @@ -69,10 +69,10 @@ module Alchemy subject { helper.render_elements(options) } let(:page) { create(:alchemy_page, :public) } - let!(:element) { create(:alchemy_element, name: 'headline', page: page) } + let!(:element) { create(:alchemy_element, name: "headline", page: page) } let!(:another_element) { create(:alchemy_element, page: page) } - context 'without any options' do + context "without any options" do let(:options) { {} } it "should render all elements from current page." do @@ -82,14 +82,14 @@ module Alchemy end context "with from_page option" do - context 'is a page object' do + context "is a page object" do let(:another_page) { create(:alchemy_page, :public) } let(:options) do { from_page: another_page } end - let!(:element) { create(:alchemy_element, name: 'headline', page: another_page) } + let!(:element) { create(:alchemy_element, name: "headline", page: another_page) } let!(:another_element) { create(:alchemy_element, page: another_page) } it "should render all elements from that page." do @@ -98,7 +98,7 @@ module Alchemy end end - context 'if from_page is nil' do + context "if from_page is nil" do let(:options) do { from_page: nil } end @@ -107,47 +107,47 @@ module Alchemy end end - context 'with option separator given' do - let(:options) { {separator: '<hr>'} } + context "with option separator given" do + let(:options) { {separator: "<hr>"} } it "joins element partials with given string" do - is_expected.to have_selector('hr') + is_expected.to have_selector("hr") end end - context 'with custom elements finder' do + context "with custom elements finder" do let(:options) do { finder: CustomNewsElementsFinder.new } end - it 'uses that to load elements to render' do + it "uses that to load elements to render" do is_expected.to have_selector("#news_1001") end end end - describe '#element_preview_code_attributes' do + describe "#element_preview_code_attributes" do subject { helper.element_preview_code_attributes(element) } - context 'in preview_mode' do + context "in preview_mode" do before { assign(:preview_mode, true) } it "should return the data-alchemy-element HTML attribute for element" do - is_expected.to eq({'data-alchemy-element' => element.id}) + is_expected.to eq({"data-alchemy-element" => element.id}) end end - context 'not in preview_mode' do + context "not in preview_mode" do it "should return an empty hash" do is_expected.to eq({}) end end end - describe '#element_preview_code' do + describe "#element_preview_code" do subject { helper.element_preview_code(element) } - context 'in preview_mode' do + context "in preview_mode" do before { assign(:preview_mode, true) } it "should return the data-alchemy-element HTML attribute for element" do @@ -155,14 +155,14 @@ module Alchemy end end - context 'not in preview_mode' do + context "not in preview_mode" do it "should not return the data-alchemy-element HTML attribute" do is_expected.not_to eq(" data-alchemy-element=\"#{element.id}\"") end end end - describe '#element_tags' do + describe "#element_tags" do subject { element_tags(element, options) } let(:element) { build_stubbed(:alchemy_element) } diff --git a/spec/helpers/alchemy/pages_helper_spec.rb b/spec/helpers/alchemy/pages_helper_spec.rb index 6a8e63de5d..f5e33af3ab 100644 --- a/spec/helpers/alchemy/pages_helper_spec.rb +++ b/spec/helpers/alchemy/pages_helper_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" module Alchemy describe PagesHelper do @@ -18,11 +18,11 @@ module Alchemy describe "#render_page_layout" do it "should render the current page layout" do @page = public_page - expect(helper.render_page_layout).to have_selector('div#content') + expect(helper.render_page_layout).to have_selector("div#content") end end - describe '#render_site_layout' do + describe "#render_site_layout" do let(:default_site) { Alchemy::Site.default } it "renders the partial for current site" do @@ -39,51 +39,51 @@ module Alchemy end end - describe '#render_menu' do + describe "#render_menu" do subject { helper.render_menu(name) } - let(:name) { 'Main Navigation' } + let(:name) { "Main Navigation" } - context 'if menu exists' do + context "if menu exists" do let(:menu) { create(:alchemy_node, name: name) } - let!(:node) { create(:alchemy_node, parent: menu, url: '/') } + let!(:node) { create(:alchemy_node, parent: menu, url: "/") } - context 'and the template exists' do - it 'renders the menu' do - is_expected.to have_selector('ul.nav > li.nav-item > a.nav-link') + context "and the template exists" do + it "renders the menu" do + is_expected.to have_selector("ul.nav > li.nav-item > a.nav-link") end end - context 'but the template does not exist' do - let(:name) { 'Unkown' } + context "but the template does not exist" do + let(:name) { "Unkown" } it { is_expected.to be_nil } end end - context 'if menu does not exist' do + context "if menu does not exist" do it { is_expected.to be_nil } end - context 'with multiple sites' do - let!(:site_2) { create(:alchemy_site, host: 'another-site.com') } + context "with multiple sites" do + let!(:site_2) { create(:alchemy_site, host: "another-site.com") } let!(:menu) { create(:alchemy_node, name: name, site: Alchemy::Site.current) } - let!(:node) { create(:alchemy_node, parent: menu, url: '/default-site') } + let!(:node) { create(:alchemy_node, parent: menu, url: "/default-site") } let!(:menu_2) { create(:alchemy_node, name: name, site: site_2) } - let!(:node_2) { create(:alchemy_node, parent: menu_2, site: site_2, url: '/site-2') } + let!(:node_2) { create(:alchemy_node, parent: menu_2, site: site_2, url: "/site-2") } - it 'renders menu from current site' do + it "renders menu from current site" do is_expected.to have_selector('ul.nav > li.nav-item > a.nav-link[href="/default-site"]') end end - context 'with multiple languages' do + context "with multiple languages" do let!(:menu) { create(:alchemy_node, name: name) } - let!(:node) { create(:alchemy_node, parent: menu, url: '/default') } + let!(:node) { create(:alchemy_node, parent: menu, url: "/default") } let!(:klingon_menu) { create(:alchemy_node, name: name, language: klingon) } - let!(:klingon_node) { create(:alchemy_node, parent: klingon_menu, language: klingon, url: '/klingon') } + let!(:klingon_node) { create(:alchemy_node, parent: klingon_menu, language: klingon, url: "/klingon") } - it 'should return the menu for the current language' do + it "should return the menu for the current language" do is_expected.to have_selector('ul.nav > li.nav-item > a.nav-link[href="/default"]') is_expected.not_to have_selector('ul.nav > li.nav-item > a.nav-link[href="/klingon"]') end @@ -106,7 +106,7 @@ module Alchemy context "with options[:separator] given" do it "should render a breadcrumb with an alternative separator" do - expect(helper.render_breadcrumb(page: page, separator: '<span>###</span>')).to have_selector('span[contains("###")]') + expect(helper.render_breadcrumb(page: page, separator: "<span>###</span>")).to have_selector('span[contains("###")]') end end @@ -120,7 +120,7 @@ module Alchemy let(:user) { build(:alchemy_dummy_user) } it "should render a breadcrumb of restricted pages only" do - page.update_columns(restricted: true, urlname: 'a-restricted-public-page', name: 'A restricted Public Page', title: 'A restricted Public Page') + page.update_columns(restricted: true, urlname: "a-restricted-public-page", name: "A restricted Public Page", title: "A restricted Public Page") result = helper.render_breadcrumb(page: page, restricted_only: true).strip expect(result).to have_selector("*[contains(\"#{page.name}\")]") expect(result).to_not have_selector("*[contains(\"#{parent.name}\")]") @@ -128,25 +128,25 @@ module Alchemy end it "should render a breadcrumb of visible pages only" do - page.update_columns(visible: false, urlname: 'a-invisible-page', name: 'A Invisible Page', title: 'A Invisible Page') + page.update_columns(visible: false, urlname: "a-invisible-page", name: "A Invisible Page", title: "A Invisible Page") expect(helper.render_breadcrumb(page: page)).not_to match(/A Invisible Page/) end it "should render a breadcrumb of visible and unpublished pages" do - page.update_columns(public_on: nil, urlname: 'a-unpublic-page', name: 'A Unpublic Page', title: 'A Unpublic Page') + page.update_columns(public_on: nil, urlname: "a-unpublic-page", name: "A Unpublic Page", title: "A Unpublic Page") expect(helper.render_breadcrumb(page: page)).to match(/A Unpublic Page/) end context "with options[:without]" do it "should render a breadcrumb without this page" do - page.update_columns(urlname: 'not-me', name: 'Not Me', title: 'Not Me') + page.update_columns(urlname: "not-me", name: "Not Me", title: "Not Me") expect(helper.render_breadcrumb(page: page, without: page)).not_to match(/Not Me/) end end context "with options[:without] as array" do it "should render a breadcrumb without these pages." do - page.update_columns(urlname: 'not-me', name: 'Not Me', title: 'Not Me') + page.update_columns(urlname: "not-me", name: "Not Me", title: "Not Me") expect(helper.render_breadcrumb(page: page, without: [page])).not_to match(/Not Me/) end end @@ -161,8 +161,8 @@ module Alchemy before { klingon_language_root } - it 'should still only render two links' do - expect(helper.language_links).to have_selector('a', count: 2) + it "should still only render two links" do + expect(helper.language_links).to have_selector("a", count: 2) end end @@ -181,7 +181,7 @@ module Alchemy before { klingon_language_root } it "should render two language links" do - expect(helper.language_links).to have_selector('a', count: 2) + expect(helper.language_links).to have_selector("a", count: 2) end it "should render language links referring to their language root page" do @@ -193,13 +193,13 @@ module Alchemy context "with options[:linkname]" do context "set to 'name'" do it "should render the name of the language" do - expect(helper.language_links(linkname: 'name')).to have_selector("span[contains('#{klingon_language_root.language.name}')]") + expect(helper.language_links(linkname: "name")).to have_selector("span[contains('#{klingon_language_root.language.name}')]") end end context "set to 'code'" do it "should render the code of the language" do - expect(helper.language_links(linkname: 'code')).to have_selector("span[contains('#{klingon_language_root.language.code}')]") + expect(helper.language_links(linkname: "code")).to have_selector("span[contains('#{klingon_language_root.language.code}')]") end end end @@ -234,7 +234,7 @@ module Alchemy context "set to false" do it "should render the language links without titles" do - expect(helper.language_links(show_title: false)).to_not have_selector('a[title]') + expect(helper.language_links(show_title: false)).to_not have_selector("a[title]") end end end @@ -356,8 +356,8 @@ module Alchemy end describe "#picture_essence_caption" do - let(:essence) { mock_model('EssencePicture', caption: 'my caption') } - let(:content) { mock_model('Content', essence: essence) } + let(:essence) { mock_model("EssencePicture", caption: "my caption") } + let(:content) { mock_model("Content", essence: essence) } it "should return the caption of the contents essence" do expect(helper.picture_essence_caption(content)).to eq "my caption" diff --git a/spec/helpers/alchemy/url_helper_spec.rb b/spec/helpers/alchemy/url_helper_spec.rb index 7ade0b762d..4da64270d3 100644 --- a/spec/helpers/alchemy/url_helper_spec.rb +++ b/spec/helpers/alchemy/url_helper_spec.rb @@ -1,18 +1,18 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" include Alchemy::ElementsHelper module Alchemy describe UrlHelper do - let(:page) { mock_model(Page, urlname: 'testpage', language_code: 'en') } + let(:page) { mock_model(Page, urlname: "testpage", language_code: "en") } before do helper.controller.class_eval { include Alchemy::ConfigurationMethods } end - context 'page path helpers' do + context "page path helpers" do describe "#show_page_path_params" do subject(:show_page_path_params) { helper.show_page_path_params(page) } @@ -22,20 +22,20 @@ module Alchemy end it "returns a Hash with urlname and no locale parameter" do - expect(show_page_path_params).to include(urlname: 'testpage') - expect(show_page_path_params).to_not include(locale: 'en') + expect(show_page_path_params).to include(urlname: "testpage") + expect(show_page_path_params).to_not include(locale: "en") end context "with addiitonal parameters" do subject(:show_page_path_params) do - helper.show_page_path_params(page, {query: 'test'}) + helper.show_page_path_params(page, {query: "test"}) end it "returns a Hash with urlname, no locale and query parameter" do expect(show_page_path_params).to \ - include(urlname: 'testpage', query: 'test') + include(urlname: "testpage", query: "test") expect(show_page_path_params).to_not \ - include(locale: 'en') + include(locale: "en") end end end @@ -47,17 +47,17 @@ module Alchemy it "returns a Hash with urlname and locale parameter" do expect(show_page_path_params).to \ - include(urlname: 'testpage', locale: 'en') + include(urlname: "testpage", locale: "en") end context "with additional parameters" do subject(:show_page_path_params) do - helper.show_page_path_params(page, {query: 'test'}) + helper.show_page_path_params(page, {query: "test"}) end it "returns a Hash with urlname, locale and query parameter" do expect(show_page_path_params).to \ - include(urlname: 'testpage', locale: 'en', query: 'test') + include(urlname: "testpage", locale: "en", query: "test") end end end @@ -74,7 +74,7 @@ module Alchemy end it "should return the correct relative path string with additional parameters" do - expect(helper.show_alchemy_page_path(page, {query: 'test'})).to \ + expect(helper.show_alchemy_page_path(page, {query: "test"})).to \ eq("/#{page.language_code}/testpage?query=test") end end @@ -89,7 +89,7 @@ module Alchemy end it "should return the correct relative path string with additional parameter" do - expect(helper.show_alchemy_page_path(page, {query: 'test'})).to \ + expect(helper.show_alchemy_page_path(page, {query: "test"})).to \ eq("/testpage?query=test") end end @@ -107,7 +107,7 @@ module Alchemy end it "should return the correct url string with additional parameters" do - expect(helper.show_alchemy_page_url(page, {query: 'test'})).to \ + expect(helper.show_alchemy_page_url(page, {query: "test"})).to \ eq("http://#{helper.request.host}/#{page.language_code}/testpage?query=test") end end @@ -123,32 +123,32 @@ module Alchemy end it "should return the correct url string with additional parameter" do - expect(helper.show_alchemy_page_url(page, {query: 'test'})).to \ + expect(helper.show_alchemy_page_url(page, {query: "test"})).to \ eq("http://#{helper.request.host}/testpage?query=test") end end end end - context 'attachment path helpers' do - let(:attachment) { mock_model(Attachment, urlname: 'test-attachment.pdf') } + context "attachment path helpers" do + let(:attachment) { mock_model(Attachment, urlname: "test-attachment.pdf") } - it 'should return the correct relative path to download an attachment' do + it "should return the correct relative path to download an attachment" do expect(helper.download_alchemy_attachment_path(attachment)).to \ eq("/attachment/#{attachment.id}/download/#{attachment.urlname}") end - it 'should return the correct url to download an attachment' do + it "should return the correct url to download an attachment" do expect(helper.download_alchemy_attachment_url(attachment)).to \ eq("http://#{helper.request.host}/attachment/#{attachment.id}/download/#{attachment.urlname}") end end - describe '#full_url_for_element' do + describe "#full_url_for_element" do subject { full_url_for_element(element) } - let(:element) { build_stubbed(:alchemy_element, name: 'headline', page: page) } - let(:current_server) { '' } + let(:element) { build_stubbed(:alchemy_element, name: "headline", page: page) } + let(:current_server) { "" } it "returns the url to this element" do is_expected.to eq("#{current_server}/#{element.page.urlname}##{element_dom_id(element)}") diff --git a/spec/libraries/auth_accessors_spec.rb b/spec/libraries/auth_accessors_spec.rb index 7913194844..a8f521a07b 100644 --- a/spec/libraries/auth_accessors_spec.rb +++ b/spec/libraries/auth_accessors_spec.rb @@ -1,16 +1,16 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" module Alchemy class MyCustomUser end - describe 'AuthAccessors' do - describe '.user_class_name' do + describe "AuthAccessors" do + describe ".user_class_name" do before do # prevent memoization - Alchemy.user_class_name = 'DummyClassName' + Alchemy.user_class_name = "DummyClassName" end it "raises error if user_class_name is not a String" do @@ -25,29 +25,29 @@ class MyCustomUser end after do - Alchemy.user_class_name = 'DummyClassName' + Alchemy.user_class_name = "DummyClassName" end end - describe 'defaults' do - it 'has default value for Alchemy.user_class_primary_key' do + describe "defaults" do + it "has default value for Alchemy.user_class_primary_key" do expect(Alchemy.user_class_primary_key).to eq(:id) end - it 'has default value for Alchemy.signup_path' do - expect(Alchemy.signup_path).to eq('/signup') + it "has default value for Alchemy.signup_path" do + expect(Alchemy.signup_path).to eq("/signup") end - it 'has default value for Alchemy.login_path' do - expect(Alchemy.login_path).to eq('/login') + it "has default value for Alchemy.login_path" do + expect(Alchemy.login_path).to eq("/login") end - it 'has default value for Alchemy.logout_path' do - expect(Alchemy.logout_path).to eq('/logout') + it "has default value for Alchemy.logout_path" do + expect(Alchemy.logout_path).to eq("/logout") end - it 'has default value for Alchemy.logout_method' do - expect(Alchemy.logout_method).to eq('delete') + it "has default value for Alchemy.logout_method" do + expect(Alchemy.logout_method).to eq("delete") end end end diff --git a/spec/libraries/config_spec.rb b/spec/libraries/config_spec.rb index d0b5c91d2f..f5ac55e063 100644 --- a/spec/libraries/config_spec.rb +++ b/spec/libraries/config_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" module Alchemy describe Config do @@ -11,26 +11,26 @@ module Alchemy end it "should return the requested part of the config" do - expect(Config).to receive(:show).and_return({'mailer' => {'setting' => 'true'}}) - expect(Config.get(:mailer)).to eq({'setting' => 'true'}) + expect(Config).to receive(:show).and_return({"mailer" => {"setting" => "true"}}) + expect(Config.get(:mailer)).to eq({"setting" => "true"}) end end - describe '.main_app_config' do + describe ".main_app_config" do let(:main_app_config_path) { "#{Rails.root}/config/alchemy/config.yml" } it "should call and return .read_file with the correct config path" do - expect(Config).to receive(:read_file).with(main_app_config_path).once.and_return({setting: 'true'}) - expect(Config.send(:main_app_config)).to eq({setting: 'true'}) + expect(Config).to receive(:read_file).with(main_app_config_path).once.and_return({setting: "true"}) + expect(Config.send(:main_app_config)).to eq({setting: "true"}) end end - describe '.env_specific_config' do + describe ".env_specific_config" do let(:env_specific_config_path) { "#{Rails.root}/config/alchemy/#{Rails.env}.config.yml" } it "should call and return .read_file with the correct config path" do - expect(Config).to receive(:read_file).with(env_specific_config_path).once.and_return({setting: 'true'}) - expect(Config.send(:env_specific_config)).to eq({setting: 'true'}) + expect(Config).to receive(:read_file).with(env_specific_config_path).once.and_return({setting: "true"}) + expect(Config.send(:env_specific_config)).to eq({setting: "true"}) end end @@ -39,65 +39,65 @@ module Alchemy before { Config.instance_variable_set("@config", nil) } it "should call and return .merge_configs!" do - expect(Config).to receive(:merge_configs!).once.and_return({setting: 'true'}) - expect(Config.show).to eq({setting: 'true'}) + expect(Config).to receive(:merge_configs!).once.and_return({setting: "true"}) + expect(Config.show).to eq({setting: "true"}) end end context "when ivar @config was already set" do - before { Config.instance_variable_set("@config", {setting: 'true'}) } + before { Config.instance_variable_set("@config", {setting: "true"}) } after { Config.instance_variable_set("@config", nil) } it "should have memoized the return value of .merge_configs!" do - expect(Config.send(:show)).to eq({setting: 'true'}) + expect(Config.send(:show)).to eq({setting: "true"}) end end end - describe '.read_file' do - context 'when given path to yml file exists' do - context 'and file is empty' do + describe ".read_file" do + context "when given path to yml file exists" do + context "and file is empty" do before do # YAML.safe_load returns nil if file is empty. allow(YAML).to receive(:safe_load) { nil } end it "should return an empty Hash" do - expect(Config.send(:read_file, 'empty_file.yml')).to eq({}) + expect(Config.send(:read_file, "empty_file.yml")).to eq({}) end end end - context 'when given path to yml file does not exist' do - it 'should return an empty Hash' do - expect(Config.send(:read_file, 'does/not/exist.yml')).to eq({}) + context "when given path to yml file does not exist" do + it "should return an empty Hash" do + expect(Config.send(:read_file, "does/not/exist.yml")).to eq({}) end end end - describe '.merge_configs!' do + describe ".merge_configs!" do let(:config_1) do - {setting_1: 'same', other_setting: 'something'} + {setting_1: "same", other_setting: "something"} end let(:config_2) do - {setting_1: 'same', setting_2: 'anything'} + {setting_1: "same", setting_2: "anything"} end it "should stringify the keys" do expect(Config.send(:merge_configs!, config_1)).to eq(config_1.stringify_keys!) end - context 'when all passed configs are empty' do + context "when all passed configs are empty" do it "should raise an error" do expect { Config.send(:merge_configs!, {}) }.to raise_error(LoadError) end end - context 'when configs containing same keys' do + context "when configs containing same keys" do it "should merge them together" do expect(Config.send(:merge_configs!, config_1, config_2)).to eq( - {'setting_1' => 'same', 'other_setting' => 'something', 'setting_2' => 'anything'}, + {"setting_1" => "same", "other_setting" => "something", "setting_2" => "anything"}, ) end end diff --git a/spec/libraries/configuration_methods_spec.rb b/spec/libraries/configuration_methods_spec.rb index 2adee6b2b6..5d01745be4 100644 --- a/spec/libraries/configuration_methods_spec.rb +++ b/spec/libraries/configuration_methods_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" describe Alchemy::ConfigurationMethods do let(:controller) do @@ -11,20 +11,20 @@ class SomeController < ActionController::Base SomeController.new end - describe '#prefix_locale?' do + describe "#prefix_locale?" do subject { controller.prefix_locale? } - context 'if no languages are present' do + context "if no languages are present" do it { is_expected.to be false } end - context 'if one language is present' do + context "if one language is present" do let!(:language) { create(:alchemy_language) } it { is_expected.to be false } end - context 'if more than one language is present' do + context "if more than one language is present" do let!(:german) { create(:alchemy_language) } let!(:english) { create(:alchemy_language, :english) } @@ -32,24 +32,24 @@ class SomeController < ActionController::Base around do |example| old_locale = I18n.default_locale - ::I18n.default_locale = 'de' + ::I18n.default_locale = "de" example.run ::I18n.default_locale = old_locale end - context 'and it is called with the default language' do - let(:args) { 'de' } + context "and it is called with the default language" do + let(:args) { "de" } it { is_expected.to be false } end - context 'and it is called with the non-default language' do - let(:args) { 'en' } + context "and it is called with the non-default language" do + let(:args) { "en" } it { is_expected.to be true } end - context 'and it is called with bogus stuff' do - let(:args) { 'kl' } + context "and it is called with bogus stuff" do + let(:args) { "kl" } it { is_expected.to be true } end diff --git a/spec/libraries/controller_actions_spec.rb b/spec/libraries/controller_actions_spec.rb index b43fc4fc23..b3857e7130 100644 --- a/spec/libraries/controller_actions_spec.rb +++ b/spec/libraries/controller_actions_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" # Here's a tiny custom matcher making it a bit easier to check the # current session for a language configuration. @@ -11,7 +11,7 @@ end end -describe 'Alchemy::ControllerActions', type: 'controller' do +describe "Alchemy::ControllerActions", type: "controller" do # Anonymous controller to test the integration against controller(ActionController::Base) do include Alchemy::ControllerActions @@ -27,9 +27,9 @@ context "with custom current_user_method" do around do |example| - Alchemy.current_user_method = 'current_admin' + Alchemy.current_user_method = "current_admin" example.run - Alchemy.current_user_method = 'current_user' + Alchemy.current_user_method = "current_user" end it "calls the custom method" do @@ -40,9 +40,9 @@ context "with not implemented current_user_method" do around do |example| - Alchemy.current_user_method = 'not_implemented_method' + Alchemy.current_user_method = "not_implemented_method" example.run - Alchemy.current_user_method = 'current_user' + Alchemy.current_user_method = "current_user" end it "raises an error" do @@ -124,7 +124,7 @@ context "if the language is not on the current site" do let(:french_site) do - create(:alchemy_site, host: 'french.fr') + create(:alchemy_site, host: "french.fr") end let(:french_language) do @@ -157,7 +157,7 @@ context "for language that does not exist" do before do - allow(controller).to receive(:params).and_return(locale: 'fo') + allow(controller).to receive(:params).and_return(locale: "fo") controller.send :set_alchemy_language end diff --git a/spec/libraries/elements_finder_spec.rb b/spec/libraries/elements_finder_spec.rb index 60f81deb08..33a2db02e5 100644 --- a/spec/libraries/elements_finder_spec.rb +++ b/spec/libraries/elements_finder_spec.rb @@ -1,37 +1,37 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" RSpec.describe Alchemy::ElementsFinder do let(:finder) { described_class.new(options) } let(:options) { {} } - describe '#elements' do + describe "#elements" do subject { finder.elements } let(:page) { create(:alchemy_page, :public) } let!(:visible_element) { create(:alchemy_element, public: true, page: page) } let!(:hidden_element) { create(:alchemy_element, public: false, page: page) } - context 'without page given' do + context "without page given" do it do expect { subject }.to raise_error(ArgumentError) end end - context 'with page object given' do + context "with page object given" do subject { finder.elements(page: page) } - it 'returns all public elements from page' do + it "returns all public elements from page" do is_expected.to eq([visible_element]) end - it 'does not return trashed elements' do + it "does not return trashed elements" do visible_element.remove_from_list is_expected.to eq([]) end - context 'with multiple ordered elements' do + context "with multiple ordered elements" do let!(:element_2) do create(:alchemy_element, public: true, page: page).tap { |el| el.update_columns(position: 3) } end @@ -40,40 +40,40 @@ create(:alchemy_element, public: true, page: page).tap { |el| el.update_columns(position: 2) } end - it 'returns elements ordered by position' do + it "returns elements ordered by position" do is_expected.to eq([visible_element, element_3, element_2]) end end - context 'with fixed elements present' do + context "with fixed elements present" do let!(:fixed_element) { create(:alchemy_element, :fixed, page: page) } - it 'does not include fixed elements' do + it "does not include fixed elements" do is_expected.to_not include(fixed_element) end - context 'with options[:fixed] set to true' do + context "with options[:fixed] set to true" do let(:options) do { fixed: true } end - it 'includes only fixed elements' do + it "includes only fixed elements" do is_expected.to eq([fixed_element]) end end end - context 'with nested elements present' do + context "with nested elements present" do let!(:nested_element) { create(:alchemy_element, :nested, page: page) } - it 'does not include nested elements' do + it "does not include nested elements" do is_expected.to_not include(nested_element) end end - context 'with options[:only] given' do + context "with options[:only] given" do let(:options) do - { only: 'article' } + { only: "article" } end it "returns only the elements with that name" do @@ -81,9 +81,9 @@ end end - context 'with options[:except] given' do + context "with options[:except] given" do let(:options) do - { except: 'article' } + { except: "article" } end it "does not return the elements with that name" do @@ -91,7 +91,7 @@ end end - context 'with options[:offset] given' do + context "with options[:offset] given" do let(:options) do { offset: 2 } end @@ -104,7 +104,7 @@ end end - context 'with options[:count] given' do + context "with options[:count] given" do let(:options) do { count: 1 } end @@ -116,7 +116,7 @@ end end - context 'with options[:reverse] given' do + context "with options[:reverse] given" do let(:options) do { reverse: true } end @@ -128,17 +128,17 @@ end end - context 'with options[:random] given' do + context "with options[:random] given" do let(:options) do { random: true } end let(:random_function) do case ActiveRecord::Base.connection_config[:adapter] - when 'postgresql', 'sqlite3' - 'RANDOM()' + when "postgresql", "sqlite3" + "RANDOM()" else - 'RAND()' + "RAND()" end end @@ -150,84 +150,84 @@ end end - context 'with page layout name given as options[:from_page]' do - subject { finder.elements(page: 'standard') } + context "with page layout name given as options[:from_page]" do + subject { finder.elements(page: "standard") } - let(:page) { create(:alchemy_page, :public, page_layout: 'standard') } + let(:page) { create(:alchemy_page, :public, page_layout: "standard") } let!(:visible_element) { create(:alchemy_element, public: true, page: page) } let!(:hidden_element) { create(:alchemy_element, public: false, page: page) } - it 'returns all public elements from page with given page layout' do + it "returns all public elements from page with given page layout" do is_expected.to eq([visible_element]) end - context 'that is not found' do - subject { finder.elements(page: 'foobaz') } + context "that is not found" do + subject { finder.elements(page: "foobaz") } - it 'returns empty active record relation' do + it "returns empty active record relation" do is_expected.to eq(Alchemy::Element.none) end end end - context 'with fallback options given' do + context "with fallback options given" do subject { finder.elements(page: page) } let(:options) do { fallback: { - for: 'download', + for: "download", from: page_2, }, } end - context 'and no element from that kind on current page' do - let(:page) { create(:alchemy_page, :public, page_layout: 'standard') } + context "and no element from that kind on current page" do + let(:page) { create(:alchemy_page, :public, page_layout: "standard") } - context 'but element of that kind on fallback page' do - let(:page_2) { create(:alchemy_page, :public, page_layout: 'standard') } - let!(:visible_element_2) { create(:alchemy_element, name: 'download', public: true, page: page_2) } + context "but element of that kind on fallback page" do + let(:page_2) { create(:alchemy_page, :public, page_layout: "standard") } + let!(:visible_element_2) { create(:alchemy_element, name: "download", public: true, page: page_2) } - it 'loads elements from fallback page' do + it "loads elements from fallback page" do is_expected.to eq([visible_element_2]) end end - context 'with fallback element defined' do + context "with fallback element defined" do let(:options) do { fallback: { - for: 'download', - with: 'header', + for: "download", + with: "header", from: page_2, }, } end - let(:page_2) { create(:alchemy_page, :public, page_layout: 'standard') } - let!(:visible_element_2) { create(:alchemy_element, name: 'header', public: true, page: page_2) } + let(:page_2) { create(:alchemy_page, :public, page_layout: "standard") } + let!(:visible_element_2) { create(:alchemy_element, name: "header", public: true, page: page_2) } - it 'loads fallback element from fallback page' do + it "loads fallback element from fallback page" do is_expected.to eq([visible_element_2]) end end - context 'with fallback page defined as pagelayout name' do + context "with fallback page defined as pagelayout name" do let(:options) do { fallback: { - for: 'download', - with: 'text', - from: 'everything', + for: "download", + with: "text", + from: "everything", }, } end - let(:page_2) { create(:alchemy_page, :public, page_layout: 'everything') } - let!(:visible_element_2) { create(:alchemy_element, name: 'text', public: true, page: page_2) } + let(:page_2) { create(:alchemy_page, :public, page_layout: "everything") } + let!(:visible_element_2) { create(:alchemy_element, name: "text", public: true, page: page_2) } - it 'loads fallback element from fallback page' do + it "loads fallback element from fallback page" do is_expected.to eq([visible_element_2]) end end diff --git a/spec/libraries/i18n_spec.rb b/spec/libraries/i18n_spec.rb index 6c48404eff..c27c32f841 100644 --- a/spec/libraries/i18n_spec.rb +++ b/spec/libraries/i18n_spec.rb @@ -1,83 +1,83 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" module Alchemy describe ".t" do - it 'scopes translations intro alchemy namespace' do - expect(::I18n).to receive(:t).with(:foo, default: 'Foo', scope: ['alchemy']) + it "scopes translations intro alchemy namespace" do + expect(::I18n).to receive(:t).with(:foo, default: "Foo", scope: ["alchemy"]) ::Alchemy.t(:foo) end end describe I18n do - describe '.available_locales' do + describe ".available_locales" do subject { I18n.available_locales } it { is_expected.to be_a Array } it { is_expected.to include(:en) } - context 'when locales are already set in @@available_locales' do + context "when locales are already set in @@available_locales" do before { I18n.class_variable_set(:@@available_locales, [:kl, :jp]) } it { is_expected.to match_array([:kl, :jp]) } after { I18n.class_variable_set(:@@available_locales, nil) } end - context 'when locales are present in other gems' do + context "when locales are present in other gems" do before do expect(::I18n).to receive(:load_path) do - ['/Users/tvd/gems/alchemy_i18n/config/locales/alchemy.de.yml'] + ["/Users/tvd/gems/alchemy_i18n/config/locales/alchemy.de.yml"] end end - it 'includes them' do + it "includes them" do is_expected.to eq([:de]) end end - context 'when same locales are present in multiple gems' do + context "when same locales are present in multiple gems" do before do expect(::I18n).to receive(:load_path) do [ - '/Users/tvd/gems/alchemy-devise/config/locales/alchemy.de.yml', - '/Users/tvd/gems/alchemy_i18n/config/locales/alchemy.de.yml', + "/Users/tvd/gems/alchemy-devise/config/locales/alchemy.de.yml", + "/Users/tvd/gems/alchemy_i18n/config/locales/alchemy.de.yml", ] end end - it 'includes them only once' do + it "includes them only once" do is_expected.to eq([:de]) end end - context 'when locales have long iso format' do + context "when locales have long iso format" do before do expect(::I18n).to receive(:load_path) do - ['/Users/tvd/gems/alchemy_i18n/config/locales/alchemy.zh-CN.yml'] + ["/Users/tvd/gems/alchemy_i18n/config/locales/alchemy.zh-CN.yml"] end end - it 'includes them in long format' do + it "includes them in long format" do is_expected.to eq([:'zh-CN']) end end - context 'multiple locales' do + context "multiple locales" do before do expect(::I18n).to receive(:load_path) do [ - '/Users/tvd/gems/alchemy_i18n/config/locales/alchemy.zh-CN.yml', - '/Users/tvd/gems/alchemy_i18n/config/locales/alchemy.de.yml', + "/Users/tvd/gems/alchemy_i18n/config/locales/alchemy.zh-CN.yml", + "/Users/tvd/gems/alchemy_i18n/config/locales/alchemy.de.yml", ] end end - it 'are sorted' do + it "are sorted" do is_expected.to eq([:de, :'zh-CN']) end end end - describe '.available_locales=' do + describe ".available_locales=" do it "assigns the given locales to @@available_locales" do I18n.available_locales = [:kl, :nl, :cn] expect(I18n.class_variable_get(:@@available_locales)).to eq([:kl, :nl, :cn]) diff --git a/spec/libraries/kaminari/scoped_pagination_url_helper_spec.rb b/spec/libraries/kaminari/scoped_pagination_url_helper_spec.rb index 1ddb38fc14..ce4995790a 100644 --- a/spec/libraries/kaminari/scoped_pagination_url_helper_spec.rb +++ b/spec/libraries/kaminari/scoped_pagination_url_helper_spec.rb @@ -1,14 +1,14 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" describe Kaminari::Helpers::Tag do subject { Kaminari::Helpers::Tag.new(template, options) } let(:template) { double(params: {}) } - let(:scope) { double(url_for: '') } + let(:scope) { double(url_for: "") } - describe '#page_url_for' do + describe "#page_url_for" do context "with scope option given" do let(:options) { {scope: scope} } diff --git a/spec/libraries/logger_spec.rb b/spec/libraries/logger_spec.rb index c478510a1f..9c7ba8dcfd 100644 --- a/spec/libraries/logger_spec.rb +++ b/spec/libraries/logger_spec.rb @@ -1,24 +1,24 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" RSpec.describe Alchemy::Logger do let(:message) { "Something bad happened" } - describe '.warn' do + describe ".warn" do let(:caller_string) { "file.rb:14" } subject { Alchemy::Logger.warn(message, caller_string) } it { is_expected.to be_nil } - it 'uses Rails debug logger' do + it "uses Rails debug logger" do expect(Rails.logger).to receive(:debug) { message } subject end end - describe '#log_warning' do + describe "#log_warning" do class Something include Alchemy::Logger end @@ -29,7 +29,7 @@ class Something expect_any_instance_of(Something).to receive(:caller).with(1..1) { ["second"] } end - it 'delegates to Alchemy::Logger.warn class method with second line of callstack' do + it "delegates to Alchemy::Logger.warn class method with second line of callstack" do expect(Alchemy::Logger).to receive(:warn).with(message, ["second"]) subject end diff --git a/spec/libraries/modules_spec.rb b/spec/libraries/modules_spec.rb index 269993c2a0..d242601dad 100644 --- a/spec/libraries/modules_spec.rb +++ b/spec/libraries/modules_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" module Alchemy class ModulesTestController < ApplicationController @@ -11,32 +11,32 @@ class ModulesTestController < ApplicationController let(:controller) { ModulesTestController.new } let(:alchemy_modules) do - YAML.load_file(File.expand_path('../../config/alchemy/modules.yml', __dir__)) + YAML.load_file(File.expand_path("../../config/alchemy/modules.yml", __dir__)) end - describe '#module_definition_for' do + describe "#module_definition_for" do subject { controller.module_definition_for(name) } let(:dashboard_module) { alchemy_modules.first } - context 'with a string given as name' do - let(:name) { 'dashboard' } + context "with a string given as name" do + let(:name) { "dashboard" } it "returns the module definition" do is_expected.to eq(dashboard_module) end end - context 'with a hash given as name' do - let(:controller_name) { 'alchemy/admin/dashboard' } - let(:name) { {controller: controller_name, action: 'index'} } + context "with a hash given as name" do + let(:controller_name) { "alchemy/admin/dashboard" } + let(:name) { {controller: controller_name, action: "index"} } it "returns the module definition" do is_expected.to eq(dashboard_module) end - context 'with leading slash in controller name' do - let(:controller_name) { '/alchemy/admin/dashboard' } + context "with leading slash in controller name" do + let(:controller_name) { "/alchemy/admin/dashboard" } it "returns the module definition" do is_expected.to eq(dashboard_module) @@ -44,44 +44,44 @@ class ModulesTestController < ApplicationController end end - context 'with nil given as name' do + context "with nil given as name" do let(:name) { nil } - it 'raises an error' do + it "raises an error" do expect { subject }.to raise_error(ArgumentError) end end end - describe '.register_module' do + describe ".register_module" do let(:alchemy_module) do { - 'name' => 'module', - 'navigation' => { - 'controller' => 'register_module_dummy', - 'action' => 'index', + "name" => "module", + "navigation" => { + "controller" => "register_module_dummy", + "action" => "index", }, } end let(:bad_alchemy_module_a) do { - 'name' => 'bad_module_a', - 'navigation' => { - 'controller' => 'bad_module', - 'action' => 'index', + "name" => "bad_module_a", + "navigation" => { + "controller" => "bad_module", + "action" => "index", }, } end let(:bad_alchemy_module_b) do { - 'name' => 'bad_module_b', - 'navigation' => { - 'controller' => 'register_module_dummy', - 'action' => 'index', - 'sub_navigation' => [{ - 'controller' => 'bad_module', - 'action' => 'index', + "name" => "bad_module_b", + "navigation" => { + "controller" => "register_module_dummy", + "action" => "index", + "sub_navigation" => [{ + "controller" => "bad_module", + "action" => "index", }], }, } diff --git a/spec/libraries/page_layout_spec.rb b/spec/libraries/page_layout_spec.rb index 003cf162e7..603e3f4ab3 100644 --- a/spec/libraries/page_layout_spec.rb +++ b/spec/libraries/page_layout_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" module Alchemy describe PageLayout do @@ -12,15 +12,15 @@ module Alchemy it "should return all page_layouts" do is_expected.to be_instance_of(Array) - expect(subject.collect { |l| l['name'] }).to include('standard') + expect(subject.collect { |l| l["name"] }).to include("standard") end it "should allow erb generated layouts" do - expect(subject.collect { |l| l['name'] }).to include('erb_layout') + expect(subject.collect { |l| l["name"] }).to include("erb_layout") end context "with a YAML file including a symbol" do - let(:yaml) { 'name: :symbol' } + let(:yaml) { "name: :symbol" } before do expect(File).to receive(:exist?).and_return(true) expect(File).to receive(:read).and_return(yaml) @@ -48,23 +48,23 @@ module Alchemy end end - describe '.add' do + describe ".add" do it "adds a definition to all definitions" do - PageLayout.add({'name' => 'foo'}) - expect(PageLayout.all).to include({'name' => 'foo'}) + PageLayout.add({"name" => "foo"}) + expect(PageLayout.all).to include({"name" => "foo"}) end it "adds a array of definitions to all definitions" do - PageLayout.add([{'name' => 'foo'}, {'name' => 'bar'}]) - expect(PageLayout.all).to include({'name' => 'foo'}) - expect(PageLayout.all).to include({'name' => 'bar'}) + PageLayout.add([{"name" => "foo"}, {"name" => "bar"}]) + expect(PageLayout.all).to include({"name" => "foo"}) + expect(PageLayout.all).to include({"name" => "bar"}) end end describe ".get" do it "should return the page_layout definition found by given name" do - allow(PageLayout).to receive(:all).and_return([{'name' => 'default'}, {'name' => 'contact'}]) - expect(PageLayout.get('default')).to eq({'name' => 'default'}) + allow(PageLayout).to receive(:all).and_return([{"name" => "default"}, {"name" => "contact"}]) + expect(PageLayout.get("default")).to eq({"name" => "default"}) end end @@ -72,42 +72,42 @@ module Alchemy subject { PageLayout.get_all_by_attributes(unique: true) } it "should return all page layout with the given attribute" do - expect(subject.map { |page_layout| page_layout['name'] }.to_a).to eq(['index', 'news', 'contact', 'erb_layout']) + expect(subject.map { |page_layout| page_layout["name"] }.to_a).to eq(["index", "news", "contact", "erb_layout"]) end end - describe '.layouts_with_own_for_select' do + describe ".layouts_with_own_for_select" do it "should not hold a layout twice" do - layouts = PageLayout.layouts_with_own_for_select('standard', 1, false) + layouts = PageLayout.layouts_with_own_for_select("standard", 1, false) layouts = layouts.collect(&:last) expect(layouts.select { |l| l == "standard" }.length).to eq(1) end end - describe '.selectable_layouts' do + describe ".selectable_layouts" do let(:site) { create(:alchemy_site) } let(:language) { create(:alchemy_language, code: :de) } before { language } subject { PageLayout.selectable_layouts(language.id) } it "should not display hidden page layouts" do - subject.each { |l| expect(l['hide']).not_to eq(true) } + subject.each { |l| expect(l["hide"]).not_to eq(true) } end context "with already taken layouts" do before do - allow(PageLayout).to receive(:all).and_return([{'unique' => true}]) + allow(PageLayout).to receive(:all).and_return([{"unique" => true}]) allow(Page).to receive(:where).and_return double(pluck: [1]) end it "should not include unique layouts" do - subject.each { |l| expect(l['unique']).not_to eq(true) } + subject.each { |l| expect(l["unique"]).not_to eq(true) } end end context "with sites layouts present" do let(:definition) do - {'name' => 'default_site', 'page_layouts' => %w(index)} + {"name" => "default_site", "page_layouts" => %w(index)} end before do @@ -116,46 +116,46 @@ module Alchemy it "should only return layouts for site" do expect(subject.length).to eq(1) - expect(subject.first['name']).to eq('index') + expect(subject.first["name"]).to eq("index") end end end describe ".element_names_for" do it "should return all element names for the given pagelayout" do - allow(PageLayout).to receive(:get).with('default').and_return({'name' => 'default', 'elements' => ['element_1', 'element_2']}) - expect(PageLayout.element_names_for('default')).to eq(['element_1', 'element_2']) + allow(PageLayout).to receive(:get).with("default").and_return({"name" => "default", "elements" => ["element_1", "element_2"]}) + expect(PageLayout.element_names_for("default")).to eq(["element_1", "element_2"]) end context "when given page_layout name does not exist" do it "should return an empty array" do - expect(PageLayout.element_names_for('layout_does_not_exist!')).to eq([]) + expect(PageLayout.element_names_for("layout_does_not_exist!")).to eq([]) end end context "when page_layout definition does not contain the elements key" do it "should return an empty array" do - allow(PageLayout).to receive(:get).with('layout_without_elements_key').and_return({'name' => 'layout_without_elements_key'}) - expect(PageLayout.element_names_for('layout_without_elements_key')).to eq([]) + allow(PageLayout).to receive(:get).with("layout_without_elements_key").and_return({"name" => "layout_without_elements_key"}) + expect(PageLayout.element_names_for("layout_without_elements_key")).to eq([]) end end end - describe '.human_layout_name' do - let(:layout) { {'name' => 'contact'} } - subject { PageLayout.human_layout_name(layout['name']) } + describe ".human_layout_name" do + let(:layout) { {"name" => "contact"} } + subject { PageLayout.human_layout_name(layout["name"]) } context "with no translation present" do it "returns the name capitalized" do - is_expected.to eq('Contact') + is_expected.to eq("Contact") end end context "with translation present" do - before { expect(Alchemy).to receive(:t).and_return('Kontakt') } + before { expect(Alchemy).to receive(:t).and_return("Kontakt") } it "returns the translated name" do - is_expected.to eq('Kontakt') + is_expected.to eq("Kontakt") end end end diff --git a/spec/libraries/paths_spec.rb b/spec/libraries/paths_spec.rb index 1673d88dbe..1c48ea682b 100644 --- a/spec/libraries/paths_spec.rb +++ b/spec/libraries/paths_spec.rb @@ -1,15 +1,15 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" module Alchemy - describe 'Paths' do - describe 'defaults' do - it 'has default value for Alchemy.admin_path' do - expect(Alchemy.admin_path).to eq('admin') + describe "Paths" do + describe "defaults" do + it "has default value for Alchemy.admin_path" do + expect(Alchemy.admin_path).to eq("admin") end - it 'has default value for Alchemy.admin_constraints' do + it "has default value for Alchemy.admin_constraints" do expect(Alchemy.admin_constraints).to eq({}) end end diff --git a/spec/libraries/permissions_spec.rb b/spec/libraries/permissions_spec.rb index c7e0bc1d08..07afe1d146 100644 --- a/spec/libraries/permissions_spec.rb +++ b/spec/libraries/permissions_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require 'rails_helper' -require 'cancan/matchers' +require "rails_helper" +require "cancan/matchers" describe Alchemy::Permissions do subject { ability } diff --git a/spec/libraries/resource_spec.rb b/spec/libraries/resource_spec.rb index 147cc0198e..3f95ebbf44 100644 --- a/spec/libraries/resource_spec.rb +++ b/spec/libraries/resource_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" class Party < ActiveRecord::Base belongs_to :location @@ -43,13 +43,13 @@ module Alchemy let(:columns) do [ - double(:column, {name: 'name', type: :string, array: false}), - double(:column, {name: 'hidden_value', type: :string, array: false}), - double(:column, {name: 'description', type: :text, array: false}), - double(:column, {name: 'id', type: :integer, array: false}), - double(:column, {name: 'starts_at', type: :datetime, array: false}), - double(:column, {name: 'location_id', type: :integer, array: false}), - double(:column, {name: 'organizer_id', type: :integer, array: false}), + double(:column, {name: "name", type: :string, array: false}), + double(:column, {name: "hidden_value", type: :string, array: false}), + double(:column, {name: "description", type: :text, array: false}), + double(:column, {name: "id", type: :integer, array: false}), + double(:column, {name: "starts_at", type: :datetime, array: false}), + double(:column, {name: "location_id", type: :integer, array: false}), + double(:column, {name: "organizer_id", type: :integer, array: false}), ] end @@ -90,7 +90,7 @@ module Alchemy context "when model has alchemy_resource_relations defined" do before do allow(Party).to receive(:alchemy_resource_relations) do - {location: {attr_method: 'name', type: 'string'}} + {location: {attr_method: "name", type: "string"}} end end @@ -145,17 +145,17 @@ module Alchemy describe "#namespaced_resource_name" do it "returns resource_name with namespace (namespace_party for Namespace::Party), i.e. for use in forms" do namespaced_resource = Resource.new("admin/namespace/parties") - expect(namespaced_resource.namespaced_resource_name).to eq('namespace_party') + expect(namespaced_resource.namespaced_resource_name).to eq("namespace_party") end it "equals resource_name if resource not namespaced" do namespaced_resource = Resource.new("admin/parties") - expect(namespaced_resource.namespaced_resource_name).to eq('party') + expect(namespaced_resource.namespaced_resource_name).to eq("party") end it "doesn't include the engine's name" do namespaced_resource = Resource.new("admin/party_engine/namespace/parties", module_definition) - expect(namespaced_resource.namespaced_resource_name).to eq('namespace_party') + expect(namespaced_resource.namespaced_resource_name).to eq("namespace_party") end end @@ -224,10 +224,10 @@ module Alchemy end end - describe '#attributes' do + describe "#attributes" do it "does not return the attributes returned by that method" do - expect(resource.attributes.detect { |a| a[:name] == 'hidden_name' }).to be_nil - expect(resource.attributes.detect { |a| a[:name] == 'name' }).not_to be_nil + expect(resource.attributes.detect { |a| a[:name] == "hidden_name" }).to be_nil + expect(resource.attributes.detect { |a| a[:name] == "name" }).not_to be_nil end end end @@ -268,8 +268,8 @@ module Alchemy context "with an array attribute" do let(:columns) do [ - double(:column, {name: 'name', type: :string, array: false}), - double(:column, {name: 'languages', type: :string, array: true}), + double(:column, {name: "name", type: :string, array: false}), + double(:column, {name: "languages", type: :string, array: true}), ] end @@ -292,10 +292,10 @@ module Alchemy let(:columns) do [ - double(:column, {name: 'name', type: :string}), - double(:column, {name: 'title', type: :string}), - double(:column, {name: 'synced_at', type: :datetime}), - double(:column, {name: 'remote_record_id', type: :string}), + double(:column, {name: "name", type: :string}), + double(:column, {name: "title", type: :string}), + double(:column, {name: "synced_at", type: :datetime}), + double(:column, {name: "remote_record_id", type: :string}), ] end @@ -315,10 +315,10 @@ module Alchemy let(:columns) do [ - double(:column, {name: 'title', type: :string}), - double(:column, {name: 'name', type: :string}), - double(:column, {name: 'updated_at', type: :datetime}), - double(:column, {name: 'public', type: :boolean}), + double(:column, {name: "title", type: :string}), + double(:column, {name: "name", type: :string}), + double(:column, {name: "updated_at", type: :datetime}), + double(:column, {name: "public", type: :boolean}), ] end @@ -343,7 +343,7 @@ module Alchemy end end - describe '#resource_relations' do + describe "#resource_relations" do it "should contain model_association from ActiveRecord::Reflections" do relation = resource.resource_relations[:location_id] expect(relation.keys).to include(:model_association) @@ -357,25 +357,25 @@ module Alchemy it "stores the relation name" do relation = resource.resource_relations[:location_id] expect(relation.keys).to include(:name) - expect(relation[:name]).to eq('location') + expect(relation[:name]).to eq("location") end end - describe '#model_associations' do + describe "#model_associations" do it "skip default alchemy model associations" do expect(resource.model_associations.collect(&:name)).not_to include(*resource.class.const_get(:DEFAULT_SKIPPED_ASSOCIATIONS).map(&:to_sym)) end end - describe '#model_association_names' do - it 'returns an array of association names' do + describe "#model_association_names" do + it "returns an array of association names" do expect(resource.model_association_names).to include(:location) end end - describe '#attributes' do + describe "#attributes" do it "contains the attribute of the related model" do - expect(resource.attributes.detect { |a| a[:name] == 'location_id' }.keys).to include(:relation) + expect(resource.attributes.detect { |a| a[:name] == "location_id" }.keys).to include(:relation) end it "contains the related model's column type as type" do diff --git a/spec/libraries/resources_helper_spec.rb b/spec/libraries/resources_helper_spec.rb index ad8d91d14b..8d09e7b396 100644 --- a/spec/libraries/resources_helper_spec.rb +++ b/spec/libraries/resources_helper_spec.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true -require_relative '../../lib/alchemy/i18n' -require_relative '../../lib/alchemy/resource' -require_relative '../../lib/alchemy/resources_helper' +require_relative "../../lib/alchemy/i18n" +require_relative "../../lib/alchemy/resource" +require_relative "../../lib/alchemy/resources_helper" module Namespace class MyResource @@ -16,7 +16,7 @@ class ResourcesController include Alchemy::ResourcesHelper def resource_handler - @resource_handler ||= Alchemy::Resource.new('admin/namespace/my_resources') + @resource_handler ||= Alchemy::Resource.new("admin/namespace/my_resources") end end @@ -24,32 +24,32 @@ class ResourcesControllerForEngine include Alchemy::ResourcesHelper def resource_handler - @resource_handler ||= Alchemy::Resource.new('admin/engine_resources', {'engine_name' => 'my_engine'}) + @resource_handler ||= Alchemy::Resource.new("admin/engine_resources", {"engine_name" => "my_engine"}) end end describe Alchemy::ResourcesHelper do let(:controller) { ResourcesController.new } - let(:resource_item) { double('resource-item') } + let(:resource_item) { double("resource-item") } before { - allow(controller).to receive(:main_app).and_return 'main_app_proxy' - controller.instance_variable_set('@my_resource', resource_item) - controller.instance_variable_set('@my_resources', [resource_item]) + allow(controller).to receive(:main_app).and_return "main_app_proxy" + controller.instance_variable_set("@my_resource", resource_item) + controller.instance_variable_set("@my_resources", [resource_item]) } describe "path-helpers" do describe "#resource_url_proxy" do it "returns the current proxy for url-helper-methods" do - expect(controller.resource_url_proxy).to eq('main_app_proxy') + expect(controller.resource_url_proxy).to eq("main_app_proxy") end context "when resource is in engine" do let(:controller_for_engine) { ResourcesControllerForEngine.new } - before { allow(controller_for_engine).to receive('my_engine').and_return('my_engine_proxy') } + before { allow(controller_for_engine).to receive("my_engine").and_return("my_engine_proxy") } it "returns the engine's proxy" do - expect(controller_for_engine.resource_url_proxy).to eq('my_engine_proxy') + expect(controller_for_engine.resource_url_proxy).to eq("my_engine_proxy") end end end @@ -119,71 +119,71 @@ def resource_handler subject { controller.render_attribute(resource_item, attributes, options) } let(:options) { {} } - let(:attributes) { {name: 'name'} } + let(:attributes) { {name: "name"} } it "should return the value from resource attribute" do - allow(resource_item).to receive(:name).and_return('my-name') - is_expected.to eq('my-name') + allow(resource_item).to receive(:name).and_return("my-name") + is_expected.to eq("my-name") end context "resource having a relation" do - let(:associated_object) { double("location", title: 'Title of related object') } + let(:associated_object) { double("location", title: "Title of related object") } let(:relation) do { - attr_method: 'title', - name: 'location', + attr_method: "title", + name: "location", } end let(:attributes) do { - name: 'name', + name: "name", relation: relation, } end before do - allow(resource_item).to receive(:name).and_return('my-name') + allow(resource_item).to receive(:name).and_return("my-name") expect(resource_item).to receive(:location).and_return(associated_object) end it "should return the value from the related object attribute" do - is_expected.to eq('Title of related object') + is_expected.to eq("Title of related object") end - context 'if the relation is empty' do + context "if the relation is empty" do let(:associated_object) { nil } it { is_expected.to eq("Not found") } end end - context 'with long values' do + context "with long values" do before do - allow(resource_item).to receive(:name).and_return('*' * 51) + allow(resource_item).to receive(:name).and_return("*" * 51) end - it 'truncates the values' do + it "truncates the values" do expect(subject.length).to eq(50) end - context 'but with options[:truncate] set to 10' do + context "but with options[:truncate] set to 10" do let(:options) { {truncate: 10} } - it 'does not truncate the values' do + it "does not truncate the values" do expect(subject.length).to eq(10) end end - context 'but with options[:truncate] set to false' do + context "but with options[:truncate] set to false" do let(:options) { {truncate: false} } - it 'does not truncate the values' do + it "does not truncate the values" do expect(subject.length).to eq(51) end end end - context 'format of timestamps' do + context "format of timestamps" do let(:attributes) do { name: :created_at, @@ -197,22 +197,22 @@ def resource_handler allow(resource_item).to receive(:created_at) { now } end - it 'formats the time with alchemy default format' do + it "formats the time with alchemy default format" do expect(controller).to receive(:l).with(now, format: :'alchemy.default') subject end - context 'with options[:datetime_format] set to other format' do - let(:options) { {datetime_format: 'OTHR'} } + context "with options[:datetime_format] set to other format" do + let(:options) { {datetime_format: "OTHR"} } - it 'uses this format' do - expect(controller).to receive(:l).with(now, format: 'OTHR') + it "uses this format" do + expect(controller).to receive(:l).with(now, format: "OTHR") subject end end end - context 'format of time values' do + context "format of time values" do let(:attributes) do { name: :created_at, @@ -226,16 +226,16 @@ def resource_handler allow(resource_item).to receive(:created_at) { now } end - it 'formats the time with alchemy datetime format' do + it "formats the time with alchemy datetime format" do expect(controller).to receive(:l).with(now, format: :'alchemy.time') subject end - context 'with options[:time_format] set to other format' do - let(:options) { {time_format: 'OTHR'} } + context "with options[:time_format] set to other format" do + let(:options) { {time_format: "OTHR"} } - it 'uses this format' do - expect(controller).to receive(:l).with(now, format: 'OTHR') + it "uses this format" do + expect(controller).to receive(:l).with(now, format: "OTHR") subject end end diff --git a/spec/libraries/shell_spec.rb b/spec/libraries/shell_spec.rb index 339d35e00f..639c008dcb 100644 --- a/spec/libraries/shell_spec.rb +++ b/spec/libraries/shell_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require 'rails_helper' -require 'alchemy/shell' +require "rails_helper" +require "alchemy/shell" module Alchemy # Class fixture @@ -12,31 +12,31 @@ class MyToDoList describe Shell do before { allow(MyToDoList).to receive(:puts) } - describe '.todo' do + describe ".todo" do it "should add given string as a todo by delegating to .add_todo" do expect(MyToDoList).to receive(:add_todo).with(["", "new todo"]) MyToDoList.todo("new todo") end end - describe '.todos' do + describe ".todos" do it "should be an Array" do expect(MyToDoList.todos).to be_a(Array) end end - describe '.add_todo' do + describe ".add_todo" do it "should add the given string to the .todos array" do - MyToDoList.add_todo('1') - MyToDoList.add_todo('2') - expect(MyToDoList.todos).to eq(['1', '2']) + MyToDoList.add_todo("1") + MyToDoList.add_todo("2") + expect(MyToDoList.todos).to eq(["1", "2"]) end end - describe '.display_todos' do - context 'if there are todos in the list' do + describe ".display_todos" do + context "if there are todos in the list" do before do - allow(MyToDoList).to receive(:todos).and_return(['My first todo', 'My second todo']) + allow(MyToDoList).to receive(:todos).and_return(["My first todo", "My second todo"]) end it "should log them" do @@ -50,7 +50,7 @@ class MyToDoList end end - context 'if there are todos in the list' do + context "if there are todos in the list" do before do allow(MyToDoList).to receive(:todos).and_return([]) end @@ -62,14 +62,14 @@ class MyToDoList end end - describe '.log' do + describe ".log" do before { Alchemy::Shell.verbose! } context 'if the message type is "skip"' do it "the output color should be yellow and cleared again" do expect(MyToDoList).to receive(:color).with(:yellow) expect(MyToDoList).to receive(:color).with(:clear) - MyToDoList.log('in yellow, please', :skip) + MyToDoList.log("in yellow, please", :skip) end end @@ -77,34 +77,34 @@ class MyToDoList it "the output color should be yellow and cleared again" do expect(MyToDoList).to receive(:color).with(:red) expect(MyToDoList).to receive(:color).with(:clear) - MyToDoList.log('in red, please', :error) + MyToDoList.log("in red, please", :error) end end context 'if the message type is "message"' do it "the output color should just be cleared" do expect(MyToDoList).to receive(:color).with(:clear) - MyToDoList.log('cleared, please', :message) + MyToDoList.log("cleared, please", :message) end end - context 'if no message type is given' do + context "if no message type is given" do it "the output color should be green" do expect(MyToDoList).to receive(:color).with(:green) expect(MyToDoList).to receive(:color).with(:clear) - MyToDoList.log('in green, please') + MyToDoList.log("in green, please") end end end - describe '.color' do - context 'if given name is a constant of Thor::Shell::Color' do + describe ".color" do + context "if given name is a constant of Thor::Shell::Color" do it "should call the constant" do expect(MyToDoList.send(:color, :red)).to eq(Thor::Shell::Color::RED) end end - context 'if given name is not a defined constant of Thor::Shell::Color' do + context "if given name is not a defined constant of Thor::Shell::Color" do it "should return nil" do expect(MyToDoList.send(:color, :not_existing)).to be_nil end diff --git a/spec/libraries/template_tracker_spec.rb b/spec/libraries/template_tracker_spec.rb index f93b266bf8..51f1ee6ce8 100644 --- a/spec/libraries/template_tracker_spec.rb +++ b/spec/libraries/template_tracker_spec.rb @@ -1,45 +1,45 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" module Alchemy module CacheDigests describe TemplateTracker do subject { TemplateTracker.call(name, nil) } - describe '#dependencies' do - context 'with alchemy/pages/show given as template name' do - let(:name) { 'alchemy/pages/show' } - before { allow(PageLayout).to receive(:all).and_return([{'name' => 'intro'}, {'name' => 'contact'}]) } + describe "#dependencies" do + context "with alchemy/pages/show given as template name" do + let(:name) { "alchemy/pages/show" } + before { allow(PageLayout).to receive(:all).and_return([{"name" => "intro"}, {"name" => "contact"}]) } it "returns all page layout view partial names" do - is_expected.to include('alchemy/page_layouts/_intro', 'alchemy/page_layouts/_contact') + is_expected.to include("alchemy/page_layouts/_intro", "alchemy/page_layouts/_contact") end end - context 'with a page layout given as template name' do - let(:name) { 'alchemy/page_layouts/_intro' } - let(:page_layout) { {'name' => 'intro', 'elements' => ['text']} } + context "with a page layout given as template name" do + let(:name) { "alchemy/page_layouts/_intro" } + let(:page_layout) { {"name" => "intro", "elements" => ["text"]} } before { allow(PageLayout).to receive(:get).and_return(page_layout) } it "returns all element layout view partial names for that layout" do - is_expected.to include('alchemy/elements/_text_view') + is_expected.to include("alchemy/elements/_text_view") end end - context 'with an element view given as name' do - let(:name) { 'alchemy/elements/_text_view' } - let(:elements) { [{'name' => 'text', 'contents' => [{'type' => 'EssenceText'}]}] } + context "with an element view given as name" do + let(:name) { "alchemy/elements/_text_view" } + let(:elements) { [{"name" => "text", "contents" => [{"type" => "EssenceText"}]}] } - context 'that is having a definition' do + context "that is having a definition" do before { allow(Element).to receive(:definitions).and_return(elements) } it "returns all essence layout view partial names for that element" do - is_expected.to include('alchemy/essences/_essence_text_view') + is_expected.to include("alchemy/essences/_essence_text_view") end end - context 'that has no definition' do + context "that has no definition" do before { allow(Element).to receive(:definitions).and_return([]) } it "returns empty array" do @@ -48,28 +48,28 @@ module CacheDigests end end - context 'with an element editor given as name' do - let(:name) { 'alchemy/elements/_text_editor' } - let(:elements) { [{'name' => 'text', 'contents' => [{'type' => 'EssenceText'}]}] } + context "with an element editor given as name" do + let(:name) { "alchemy/elements/_text_editor" } + let(:elements) { [{"name" => "text", "contents" => [{"type" => "EssenceText"}]}] } it do is_expected.to be_empty end end - context 'with an element given as name' do - let(:name) { 'alchemy/elements/_text' } - let(:elements) { [{'name' => 'text', 'contents' => [{'type' => 'EssenceText'}]}] } + context "with an element given as name" do + let(:name) { "alchemy/elements/_text" } + let(:elements) { [{"name" => "text", "contents" => [{"type" => "EssenceText"}]}] } - context 'that is having a definition' do + context "that is having a definition" do before { allow(Element).to receive(:definitions).and_return(elements) } it "returns all essence layout view partial names for that element" do - is_expected.to include('alchemy/essences/_essence_text_view') + is_expected.to include("alchemy/essences/_essence_text_view") end end - context 'that has no definition' do + context "that has no definition" do before { allow(Element).to receive(:definitions).and_return([]) } it "returns empty array" do @@ -78,8 +78,8 @@ module CacheDigests end end - context 'with not an alchemy template given as name' do - let(:name) { 'shop/cart' } + context "with not an alchemy template given as name" do + let(:name) { "shop/cart" } it "calls rails template tracker" do expect(ActionView::DependencyTracker::ERBTracker).to receive(:call).with(name, nil) diff --git a/spec/libraries/tinymce_spec.rb b/spec/libraries/tinymce_spec.rb index 07f7533035..8d4a2d9a7f 100644 --- a/spec/libraries/tinymce_spec.rb +++ b/spec/libraries/tinymce_spec.rb @@ -1,19 +1,19 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" module Alchemy describe Tinymce do - describe '.init' do + describe ".init" do subject { Tinymce.init } it "returns the default config" do - is_expected.to eq(Tinymce.class_variable_get('@@init')) + is_expected.to eq(Tinymce.class_variable_get("@@init")) end end - describe '.init=' do - let(:another_config) { {theme_advanced_buttons3: 'table'} } + describe ".init=" do + let(:another_config) { {theme_advanced_buttons3: "table"} } it "merges the default config with given config" do Tinymce.init = another_config @@ -21,13 +21,13 @@ module Alchemy end end - context 'Methods for contents with custom tinymce config.' do + context "Methods for contents with custom tinymce config." do let(:content_definition) do { - 'name' => 'text', - 'settings' => { - 'tinymce' => { - 'foo' => 'bar', + "name" => "text", + "settings" => { + "tinymce" => { + "foo" => "bar", }, }, } @@ -35,12 +35,12 @@ module Alchemy let(:element_definition) do { - 'name' => 'article', - 'contents' => [content_definition], + "name" => "article", + "contents" => [content_definition], } end - describe '.custom_config_contents' do + describe ".custom_config_contents" do let(:page) { build_stubbed(:alchemy_page) } let(:element_definitions) do @@ -57,23 +57,23 @@ module Alchemy and element name" do is_expected.to be_an(Array) is_expected.to include({ - 'element' => element_definition['name'], + "element" => element_definition["name"], }.merge(content_definition)) end - context 'with no contents having custom tinymce config' do + context "with no contents having custom tinymce config" do let(:content_definition) do - {'name' => 'text'} + {"name" => "text"} end it { is_expected.to eq([]) } end - context 'with element definition having nil as contents value' do + context "with element definition having nil as contents value" do let(:element_definition) do { - 'name' => 'element', - 'contents' => nil, + "name" => "element", + "contents" => nil, } end @@ -82,14 +82,14 @@ module Alchemy end end - context 'with content settings tinymce set to true only' do + context "with content settings tinymce set to true only" do let(:element_definition) do { - 'name' => 'element', - 'contents' => [ - 'name' => 'headline', - 'settings' => { - 'tinymce' => true, + "name" => "element", + "contents" => [ + "name" => "headline", + "settings" => { + "tinymce" => true, }, ], } @@ -100,20 +100,20 @@ module Alchemy end end - context 'with nestable_elements defined' do + context "with nestable_elements defined" do let(:element_definitions) do [ element_definition, { - 'name' => 'nested_element', - 'contents' => [content_definition], + "name" => "nested_element", + "contents" => [content_definition], }, ] end - it 'includes these configs' do + it "includes these configs" do is_expected.to include({ - 'element' => element_definition['name'], + "element" => element_definition["name"], }.merge(content_definition)) end end diff --git a/spec/libraries/userstamp_spec.rb b/spec/libraries/userstamp_spec.rb index 73dae06c16..91f6c90f09 100644 --- a/spec/libraries/userstamp_spec.rb +++ b/spec/libraries/userstamp_spec.rb @@ -1,9 +1,9 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" -describe 'Alchemy::AuthAccessors' do - describe '.user_class' do +describe "Alchemy::AuthAccessors" do + describe ".user_class" do it "injects userstamp class methods" do expect(Alchemy.user_class).to respond_to(:stamper_class_name) expect(Alchemy.user_class.stamper_class_name).to eq(:"::DummyUser") diff --git a/spec/mailers/alchemy/messages_mailer_spec.rb b/spec/mailers/alchemy/messages_mailer_spec.rb index 06406ebc42..eff2aec0be 100644 --- a/spec/mailers/alchemy/messages_mailer_spec.rb +++ b/spec/mailers/alchemy/messages_mailer_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" def reload_mailer_class(class_name) Alchemy.send(:remove_const, class_name) @@ -9,8 +9,8 @@ def reload_mailer_class(class_name) module Alchemy describe MessagesMailer do - let(:message) { Message.new(email: 'jon@doe.com', message: 'Lorem ipsum') } - let(:mail) { MessagesMailer.contact_form_mail(message, 'admin@page.com', 'contact@page.com', 'Subject') } + let(:message) { Message.new(email: "jon@doe.com", message: "Lorem ipsum") } + let(:mail) { MessagesMailer.contact_form_mail(message, "admin@page.com", "contact@page.com", "Subject") } it "inherits from ActionMailer::Base" do expect(MessagesMailer < ActionMailer::Base).to eq(true) @@ -29,8 +29,8 @@ class ::ApplicationMailer; end end it "delivers a mail to owner" do - expect(mail.to).to eq(['admin@page.com']) - expect(mail.subject).to eq('Subject') + expect(mail.to).to eq(["admin@page.com"]) + expect(mail.subject).to eq("Subject") end it "reply_to should be set to senders email" do diff --git a/spec/models/alchemy/attachment_spec.rb b/spec/models/alchemy/attachment_spec.rb index 9c17bfd400..5360774680 100644 --- a/spec/models/alchemy/attachment_spec.rb +++ b/spec/models/alchemy/attachment_spec.rb @@ -1,20 +1,20 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" module Alchemy describe Attachment do - let(:file) { File.new(File.expand_path('../../fixtures/image with spaces.png', __dir__)) } + let(:file) { File.new(File.expand_path("../../fixtures/image with spaces.png", __dir__)) } let(:attachment) { Attachment.new(file: file) } - describe 'after assign' do + describe "after assign" do it "stores the file mime type into database" do attachment.update(file: file) expect(attachment.file_mime_type).not_to be_blank end end - describe 'after save' do + describe "after save" do subject(:save) { attachment.save! } it "should have a humanized name" do @@ -24,7 +24,7 @@ module Alchemy context "when file_name has not changed" do before do - attachment.update(name: 'image with spaces') + attachment.update(name: "image with spaces") end it "should not change name" do @@ -32,7 +32,7 @@ module Alchemy end end - context 'assigned to contents' do + context "assigned to contents" do let(:attachment) { create(:alchemy_attachment) } let(:content) do @@ -45,39 +45,39 @@ module Alchemy content.essence.update(attachment: attachment) end - it 'touches contents' do + it "touches contents" do expect { attachment.save }.to change { content.reload.updated_at } end end end - describe 'urlname sanitizing' do + describe "urlname sanitizing" do it "escapes unsafe url characters" do - attachment.file_name = 'f#%&cking cute kitten pic.png' - expect(attachment.urlname).to eq('f%23%25%26cking+cute+kitten+pic') + attachment.file_name = "f#%&cking cute kitten pic.png" + expect(attachment.urlname).to eq("f%23%25%26cking+cute+kitten+pic") end it "removes format suffix from end of file name" do - attachment.file_name = 'pic.png.png' - expect(attachment.urlname).to eq('pic+png') + attachment.file_name = "pic.png.png" + expect(attachment.urlname).to eq("pic+png") end it "converts dots into escaped spaces" do - attachment.file_name = 'cute.kitten.pic.png' - expect(attachment.urlname).to eq('cute+kitten+pic') + attachment.file_name = "cute.kitten.pic.png" + expect(attachment.urlname).to eq("cute+kitten+pic") end it "escapes umlauts in the name" do - attachment.file_name = 'süßes katzenbild.png' - expect(attachment.urlname).to eq('s%C3%BC%C3%9Fes+katzenbild') + attachment.file_name = "süßes katzenbild.png" + expect(attachment.urlname).to eq("s%C3%BC%C3%9Fes+katzenbild") end end - describe 'validations' do + describe "validations" do context "having a png, but only pdf allowed" do before do allow(Config).to receive(:get) do - {'allowed_filetypes' => {'alchemy/attachments' => ['pdf']}} + {"allowed_filetypes" => {"alchemy/attachments" => ["pdf"]}} end end @@ -89,7 +89,7 @@ module Alchemy context "having a png and everything allowed" do before do allow(Config).to receive(:get) do - {'allowed_filetypes' => {'alchemy/attachments' => ['*']}} + {"allowed_filetypes" => {"alchemy/attachments" => ["*"]}} end end @@ -100,7 +100,7 @@ module Alchemy context "having a filename with special characters" do before do - attachment.file_name = 'my FileNämü.pdf' + attachment.file_name = "my FileNämü.pdf" attachment.save end @@ -110,107 +110,107 @@ module Alchemy end end - context 'PNG image' do - subject { stub_model(Attachment, file_name: 'kitten.png') } + context "PNG image" do + subject { stub_model(Attachment, file_name: "kitten.png") } - describe '#extension' do + describe "#extension" do subject { super().extension } it { is_expected.to eq("png") } end end - describe '#icon_css_class' do + describe "#icon_css_class" do subject { attachment.icon_css_class } - context 'mp3 file' do - let(:attachment) { stub_model(Attachment, file_mime_type: 'audio/mpeg') } + context "mp3 file" do + let(:attachment) { stub_model(Attachment, file_mime_type: "audio/mpeg") } it { is_expected.to eq("file-audio") } end - context 'video file' do - let(:attachment) { stub_model(Attachment, file_mime_type: 'video/mpeg') } + context "video file" do + let(:attachment) { stub_model(Attachment, file_mime_type: "video/mpeg") } it { is_expected.to eq("file-video") } end - context 'png file' do - let(:attachment) { stub_model(Attachment, file_mime_type: 'image/png') } + context "png file" do + let(:attachment) { stub_model(Attachment, file_mime_type: "image/png") } it { is_expected.to eq("file-image") } end - context 'vcard file' do - let(:attachment) { stub_model(Attachment, file_mime_type: 'application/vcard') } + context "vcard file" do + let(:attachment) { stub_model(Attachment, file_mime_type: "application/vcard") } it { is_expected.to eq("address-card") } end - context 'zip file' do - let(:attachment) { stub_model(Attachment, file_mime_type: 'application/zip') } + context "zip file" do + let(:attachment) { stub_model(Attachment, file_mime_type: "application/zip") } it { is_expected.to eq("file-archive") } end - context 'photoshop file' do - let(:attachment) { stub_model(Attachment, file_mime_type: 'image/x-psd') } + context "photoshop file" do + let(:attachment) { stub_model(Attachment, file_mime_type: "image/x-psd") } it { is_expected.to eq("file-image") } end - context 'text file' do - let(:attachment) { stub_model(Attachment, file_mime_type: 'text/plain') } + context "text file" do + let(:attachment) { stub_model(Attachment, file_mime_type: "text/plain") } it { is_expected.to eq("file-alt") } end - context 'rtf file' do - let(:attachment) { stub_model(Attachment, file_mime_type: 'application/rtf') } + context "rtf file" do + let(:attachment) { stub_model(Attachment, file_mime_type: "application/rtf") } it { is_expected.to eq("file-alt") } end - context 'pdf file' do - let(:attachment) { stub_model(Attachment, file_mime_type: 'application/pdf') } + context "pdf file" do + let(:attachment) { stub_model(Attachment, file_mime_type: "application/pdf") } it { is_expected.to eq("file-pdf") } end - context 'word file' do - let(:attachment) { stub_model(Attachment, file_mime_type: 'application/msword') } + context "word file" do + let(:attachment) { stub_model(Attachment, file_mime_type: "application/msword") } it { is_expected.to eq("file-word") } end - context 'excel file' do - let(:attachment) { stub_model(Attachment, file_mime_type: 'application/vnd.ms-excel') } + context "excel file" do + let(:attachment) { stub_model(Attachment, file_mime_type: "application/vnd.ms-excel") } it { is_expected.to eq("file-excel") } end - context 'xlsx file' do - let(:attachment) { stub_model(Attachment, file_mime_type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet') } + context "xlsx file" do + let(:attachment) { stub_model(Attachment, file_mime_type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") } it { is_expected.to eq("file-excel") } end - context 'csv file' do - let(:attachment) { stub_model(Attachment, file_mime_type: 'text/csv') } + context "csv file" do + let(:attachment) { stub_model(Attachment, file_mime_type: "text/csv") } it { is_expected.to eq("file-excel") } end - context 'unknown file' do - let(:attachment) { stub_model(Attachment, file_mime_type: '') } + context "unknown file" do + let(:attachment) { stub_model(Attachment, file_mime_type: "") } it { is_expected.to eq("file") } end end - describe '#restricted?' do + describe "#restricted?" do subject { attachment.restricted? } - context 'if only on restricted pages' do + context "if only on restricted pages" do before do pages = double(any?: true) expect(pages).to receive(:not_restricted).and_return([]) @@ -220,7 +220,7 @@ module Alchemy it { is_expected.to be_truthy } end - context 'if not only on restricted pages' do + context "if not only on restricted pages" do let(:page) { mock_model(Page) } before do diff --git a/spec/models/alchemy/content_spec.rb b/spec/models/alchemy/content_spec.rb index 373e3b3981..7df8c5297a 100644 --- a/spec/models/alchemy/content_spec.rb +++ b/spec/models/alchemy/content_spec.rb @@ -1,60 +1,60 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" module Alchemy describe Content do - let(:element) { create(:alchemy_element, :with_contents, name: 'headline') } - let(:content) { element.contents.find_by(essence_type: 'Alchemy::EssenceText') } + let(:element) { create(:alchemy_element, :with_contents, name: "headline") } + let(:content) { element.contents.find_by(essence_type: "Alchemy::EssenceText") } it "should return the ingredient from its essence" do content.essence.update_columns(body: "Hello") expect(content.ingredient).to eq("Hello") end - describe '.normalize_essence_type' do + describe ".normalize_essence_type" do context "passing namespaced essence type" do it "should not add alchemy namespace" do - expect(Content.normalize_essence_type('Alchemy::EssenceText')).to eq("Alchemy::EssenceText") + expect(Content.normalize_essence_type("Alchemy::EssenceText")).to eq("Alchemy::EssenceText") end end context "passing not namespaced essence type" do it "should add alchemy namespace" do - expect(Content.normalize_essence_type('EssenceText')).to eq("Alchemy::EssenceText") + expect(Content.normalize_essence_type("EssenceText")).to eq("Alchemy::EssenceText") end end context "passing non-namespaced essence type for an existing non-namespaced essence" do it "should not add alchemy namespace" do - expect(Content.normalize_essence_type('DummyModel')).to eq("DummyModel") + expect(Content.normalize_essence_type("DummyModel")).to eq("DummyModel") end end end - describe '#normalized_essence_type' do + describe "#normalized_essence_type" do context "without namespace in essence_type column" do it "should return the namespaced essence type" do - expect(Content.new(essence_type: 'EssenceText').normalized_essence_type).to eq('Alchemy::EssenceText') + expect(Content.new(essence_type: "EssenceText").normalized_essence_type).to eq("Alchemy::EssenceText") end end context "with namespace in essence_type column" do it "should return the namespaced essence type" do - expect(Content.new(essence_type: 'Alchemy::EssenceText').normalized_essence_type).to eq('Alchemy::EssenceText') + expect(Content.new(essence_type: "Alchemy::EssenceText").normalized_essence_type).to eq("Alchemy::EssenceText") end end end - describe '#update_essence' do + describe "#update_essence" do subject { content.update_essence(params) } - let(:element) { create(:alchemy_element, :with_contents, name: 'text') } + let(:element) { create(:alchemy_element, :with_contents, name: "text") } let(:content) { element.contents.first } let(:params) { {} } - context 'with params given' do - let(:params) { {body: 'Mikes Petshop'} } + context "with params given" do + let(:params) { {body: "Mikes Petshop"} } let(:essence) { content.essence } before do @@ -72,8 +72,8 @@ module Alchemy end end - context 'with validations and without params given' do - let(:element) { create(:alchemy_element, :with_contents, name: 'contactform') } + context "with validations and without params given" do + let(:element) { create(:alchemy_element, :with_contents, name: "contactform") } it "should add error messages if save fails and return false" do is_expected.to be_falsey @@ -81,7 +81,7 @@ module Alchemy end end - context 'if essence is missing' do + context "if essence is missing" do before do expect(content).to receive(:essence).and_return nil end @@ -92,13 +92,13 @@ module Alchemy end end - describe '.copy' do + describe ".copy" do let(:element) do - create(:alchemy_element, :with_contents, name: 'text') + create(:alchemy_element, :with_contents, name: "text") end let(:new_element) do - create(:alchemy_element, name: 'text') + create(:alchemy_element, name: "text") end let(:content) do @@ -116,7 +116,7 @@ module Alchemy end it "should copy source essence attributes" do - content.essence.update_column(:body, 'Lorem ipsum') + content.essence.update_column(:body, "Lorem ipsum") copy = Content.copy(content) copy.essence.body == content.essence.body end @@ -136,11 +136,11 @@ module Alchemy expect(Element).to receive(:definitions) do [ { - 'name' => 'foo', - 'contents' => [{'name' => 'title'}], + "name" => "foo", + "contents" => [{"name" => "title"}], }, { - 'name' => 'bar', + "name" => "bar", }, ] end @@ -148,16 +148,16 @@ module Alchemy it "returns only content definitions" do expect(Content.definitions).to match_array( - [{'name' => 'title'}], + [{"name" => "title"}], ) end end end - describe '.new' do + describe ".new" do let(:element) { build(:alchemy_element) } - subject { Content.new({element: element, name: 'headline'}) } + subject { Content.new({element: element, name: "headline"}) } it "builds a new content instance from elements.yml definition" do is_expected.to be_instance_of(Content) @@ -170,10 +170,10 @@ module Alchemy end end - describe '.create' do - let(:element) { create(:alchemy_element, name: 'article') } + describe ".create" do + let(:element) { create(:alchemy_element, name: "article") } - subject(:content) { Content.create(element: element, name: 'headline') } + subject(:content) { Content.create(element: element, name: "headline") } it "creates the content" do is_expected.to be_instance_of(Alchemy::Content) @@ -189,21 +189,21 @@ module Alchemy it "should have the ingredient column filled with default value." do allow_any_instance_of(Content).to receive(:definition) do { - 'name' => 'headline', - 'type' => 'EssenceText', - 'default' => 'Welcome', + "name" => "headline", + "type" => "EssenceText", + "default" => "Welcome", }.with_indifferent_access end expect(content.ingredient).to eq("Welcome") end - context 'with default value being a symbol' do + context "with default value being a symbol" do it "passes default value through I18n." do allow_any_instance_of(Content).to receive(:definition) do { - 'name' => 'headline', - 'type' => 'EssenceText', - 'default' => :welcome, + "name" => "headline", + "type" => "EssenceText", + "default" => :welcome, }.with_indifferent_access end expect(content.ingredient).to eq("Welcome to my site") @@ -212,18 +212,18 @@ module Alchemy end end - describe '#ingredient=' do - let(:element) { create(:alchemy_element, name: 'headline') } + describe "#ingredient=" do + let(:element) { create(:alchemy_element, name: "headline") } it "should set the given value to the ingredient column of essence" do - c = Content.create(element: element, name: 'headline') + c = Content.create(element: element, name: "headline") c.ingredient = "Welcome" expect(c.ingredient).to eq("Welcome") end context "no essence associated" do - let(:element) { create(:alchemy_element, name: 'headline') } - let(:content) { Alchemy::Content.new(element: element, name: 'headline').tap(&:save) } + let(:element) { create(:alchemy_element, name: "headline") } + let(:content) { Alchemy::Content.new(element: element, name: "headline").tap(&:save) } before do expect(content).to receive(:essence) { nil } @@ -246,7 +246,7 @@ module Alchemy before { expect(content).to receive(:essence).and_return nil } it "returns empty string" do - expect(content.dom_id).to eq('') + expect(content.dom_id).to eq("") end end end @@ -263,24 +263,24 @@ module Alchemy before { expect(content).to receive(:essence).and_return nil } it "returns empty string" do - expect(content.essence_partial_name).to eq('') + expect(content.essence_partial_name).to eq("") end end end - describe '#preview_content?' do + describe "#preview_content?" do let(:content) { build_stubbed(:alchemy_content) } - context 'not defined as preview content' do + context "not defined as preview content" do it "returns false" do expect(content.preview_content?).to be false end end - context 'defined as preview content' do + context "defined as preview content" do before do expect(content).to receive(:definition).at_least(:once).and_return({ - 'as_element_title' => true, + "as_element_title" => true, }) end @@ -290,8 +290,8 @@ module Alchemy end end - describe '#preview_text' do - let(:essence) { mock_model(EssenceText, preview_text: 'Lorem') } + describe "#preview_text" do + let(:essence) { mock_model(EssenceText, preview_text: "Lorem") } let(:content) { c = Content.new; c.essence = essence; c } it "should return the essences preview_text" do @@ -300,15 +300,15 @@ module Alchemy end end - describe '#has_tinymce?' do - let(:element) { build_stubbed(:alchemy_element, name: 'article') } - let(:content) { build_stubbed(:alchemy_content, name: 'text', element: element) } + describe "#has_tinymce?" do + let(:element) { build_stubbed(:alchemy_element, name: "article") } + let(:content) { build_stubbed(:alchemy_content, name: "text", element: element) } subject { content.has_tinymce? } it { is_expected.to eq(false) } - context 'having custom tinymce config hash' do + context "having custom tinymce config hash" do before do expect(content).to receive(:settings) do {tinymce: {toolbar: []}} @@ -318,7 +318,7 @@ module Alchemy it { is_expected.to eq(true) } end - context 'having essence that has_tinymce? eq true' do + context "having essence that has_tinymce? eq true" do before do expect(content.essence).to receive(:has_tinymce?) { true } end @@ -326,7 +326,7 @@ module Alchemy it { is_expected.to eq(true) } end - context 'having nil essence' do + context "having nil essence" do before do content.essence = nil end @@ -335,15 +335,15 @@ module Alchemy end end - describe '#has_custom_tinymce_config?' do - let(:element) { build_stubbed(:alchemy_element, name: 'article') } - let(:content) { build_stubbed(:alchemy_content, name: 'text', element: element) } + describe "#has_custom_tinymce_config?" do + let(:element) { build_stubbed(:alchemy_element, name: "article") } + let(:content) { build_stubbed(:alchemy_content, name: "text", element: element) } subject { content.has_custom_tinymce_config? } it { is_expected.to eq(false) } - context 'having custom tinymce config hash' do + context "having custom tinymce config hash" do before do expect(content).to receive(:settings) do {tinymce: {toolbar: []}} @@ -354,21 +354,21 @@ module Alchemy end end - describe '#tinymce_class_name' do - let(:element) { build_stubbed(:alchemy_element, name: 'article') } - let(:content) { build_stubbed(:alchemy_content, name: 'text', element: element) } + describe "#tinymce_class_name" do + let(:element) { build_stubbed(:alchemy_element, name: "article") } + let(:content) { build_stubbed(:alchemy_content, name: "text", element: element) } subject { content.tinymce_class_name } - it { is_expected.to eq('has_tinymce') } + it { is_expected.to eq("has_tinymce") } - context 'having custom tinymce config' do + context "having custom tinymce config" do before do expect(content).to receive(:has_custom_tinymce_config?).and_return(true) end - it 'returns name including element name' do - is_expected.to eq('has_tinymce article_text') + it "returns name including element name" do + is_expected.to eq("has_tinymce article_text") end end end @@ -377,16 +377,16 @@ module Alchemy let(:subject) { Content.new } end - describe '#settings' do - let(:element) { build_stubbed(:alchemy_element, name: 'article') } - let(:content) { build_stubbed(:alchemy_content, name: 'headline', element: element) } + describe "#settings" do + let(:element) { build_stubbed(:alchemy_element, name: "article") } + let(:content) { build_stubbed(:alchemy_content, name: "headline", element: element) } it "returns the settings hash from definition" do - expect(content.settings).to eq({'linkable' => true}) + expect(content.settings).to eq({"linkable" => true}) end - context 'if settings are not defined' do - let(:content) { build_stubbed(:alchemy_content, name: 'intro', element: element) } + context "if settings are not defined" do + let(:content) { build_stubbed(:alchemy_content, name: "intro", element: element) } it "returns empty hash" do expect(content.settings).to eq({}) @@ -394,7 +394,7 @@ module Alchemy end end - describe '#settings_value' do + describe "#settings_value" do let(:key) { :key } let(:settings) { Hash.new } @@ -404,73 +404,73 @@ module Alchemy allow(content).to receive(:settings) { settings } end - context 'with content having settings' do - let(:settings) { {key: 'settings_value'} } + context "with content having settings" do + let(:settings) { {key: "settings_value"} } - context 'and empty options' do + context "and empty options" do let(:options) { {} } it "returns the value for key from content settings" do - expect(subject).to eq('settings_value') + expect(subject).to eq("settings_value") end end - context 'and nil options' do + context "and nil options" do let(:options) { nil } it "returns the value for key from content settings" do - expect(subject).to eq('settings_value') + expect(subject).to eq("settings_value") end end - context 'but same key present in options' do - let(:options) { {key: 'options_value'} } + context "but same key present in options" do + let(:options) { {key: "options_value"} } it "returns the value for key from options" do - expect(subject).to eq('options_value') + expect(subject).to eq("options_value") end end end - context 'with content having no settings' do + context "with content having no settings" do let(:settings) { {} } - context 'and empty options' do + context "and empty options" do let(:options) { {} } it { expect(subject).to eq(nil) } end - context 'but key present in options' do - let(:options) { {key: 'options_value'} } + context "but key present in options" do + let(:options) { {key: "options_value"} } it "returns the value for key from options" do - expect(subject).to eq('options_value') + expect(subject).to eq("options_value") end end end - context 'with content having settings with string as key' do - let(:settings) { {'key' => 'value_from_string_key'} } + context "with content having settings with string as key" do + let(:settings) { {"key" => "value_from_string_key"} } let(:options) { {} } it "returns value" do - expect(subject).to eq('value_from_string_key') + expect(subject).to eq("value_from_string_key") end end - context 'with key passed as string' do - let(:settings) { {key: 'value_from_symbol_key'} } - let(:key) { 'key' } + context "with key passed as string" do + let(:settings) { {key: "value_from_symbol_key"} } + let(:key) { "key" } let(:options) { {} } it "returns value" do - expect(subject).to eq('value_from_symbol_key') + expect(subject).to eq("value_from_symbol_key") end end end - context 'delegations' do + context "delegations" do let(:page) { create(:alchemy_page, :restricted) } it "delegates restricted? to page" do diff --git a/spec/models/alchemy/element_spec.rb b/spec/models/alchemy/element_spec.rb index b3723ee9ae..7ef00b9c74 100644 --- a/spec/models/alchemy/element_spec.rb +++ b/spec/models/alchemy/element_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" module Alchemy describe Element do @@ -9,36 +9,36 @@ module Alchemy # ClassMethods - describe '.new' do + describe ".new" do it "should initialize an element by name from scratch" do - el = Element.new(name: 'article') + el = Element.new(name: "article") expect(el).to be_an(Alchemy::Element) - expect(el.name).to eq('article') + expect(el.name).to eq("article") end it "should raise an error if the given name is not defined in the elements.yml" do expect { - Element.new(name: 'foobar') + Element.new(name: "foobar") }.to raise_error(ElementDefinitionError) end it "should merge given attributes into defined ones" do - el = Element.new(name: 'article', page_id: 1) + el = Element.new(name: "article", page_id: 1) expect(el.page_id).to eq(1) end it "should not have forbidden attributes from definition" do - el = Element.new(name: 'article') + el = Element.new(name: "article") expect(el.contents).to eq([]) end end - describe '.create' do + describe ".create" do let(:page) { build(:alchemy_page) } - subject(:element) { described_class.create(page: page, name: 'article') } + subject(:element) { described_class.create(page: page, name: "article") } - it 'creates contents' do + it "creates contents" do expect(element.contents).to match_array([ an_instance_of(Alchemy::Content), an_instance_of(Alchemy::Content), @@ -47,88 +47,88 @@ module Alchemy ]) end - context 'if autogenerate_contents set to false' do + context "if autogenerate_contents set to false" do subject(:element) do described_class.create( page: page, - name: 'article', + name: "article", autogenerate_contents: false, ) end - it 'creates contents' do + it "creates contents" do expect(element.contents).to be_empty end end - context 'if autogenerate is given in definition' do + context "if autogenerate is given in definition" do subject(:element) do - described_class.create(page: page, name: 'slider') + described_class.create(page: page, name: "slider") end - it 'creates nested elements' do + it "creates nested elements" do expect(element.nested_elements).to match_array([ an_instance_of(Alchemy::Element), ]) end - context 'if element name is not a nestable element' do + context "if element name is not a nestable element" do subject(:element) do described_class.create( page: page, - name: 'slider', + name: "slider", ) end before do expect(Alchemy::Element).to receive(:definitions).at_least(:once) do [ - {'name' => 'slider', 'nestable_elements' => ['foo'], 'autogenerate' => ['bar']}, + { "name" => "slider", "nestable_elements" => ["foo"], "autogenerate" => ["bar"] }, ] end end - it 'logs error warning' do + it "logs error warning" do expect_any_instance_of(Alchemy::Logger).to \ receive(:log_warning).with("Element 'bar' not a nestable element for 'slider'. Skipping!") element end - it 'skips element' do + it "skips element" do expect(element.nested_elements).to be_empty end end - context 'if autogenerate_nested_elements set to false' do + context "if autogenerate_nested_elements set to false" do subject(:element) do described_class.create( page: page, - name: 'slider', + name: "slider", autogenerate_nested_elements: false, ) end - it 'creates contents' do + it "creates contents" do expect(element.contents).to be_empty end end end end - describe '.copy' do + describe ".copy" do subject { Element.copy(element) } let(:element) do - create(:alchemy_element, :with_contents, tag_list: 'red, yellow') + create(:alchemy_element, :with_contents, tag_list: "red, yellow") end it "should not create contents from scratch" do expect(subject.contents.count).to eq(element.contents.count) end - context 'with differences' do + context "with differences" do let(:new_page) { create(:alchemy_page) } - subject(:copy) { Element.copy(element, {page_id: new_page.id}) } + subject(:copy) { Element.copy(element, { page_id: new_page.id }) } it "should create a new record with all attributes of source except given differences" do expect(copy.page_id).to eq(new_page.id) @@ -144,27 +144,27 @@ module Alchemy expect(subject.tag_list).to eq(element.tag_list) end - context 'with nested elements' do + context "with nested elements" do let(:element) do create(:alchemy_element, :with_contents, :with_nestable_elements, { - tag_list: 'red, yellow', + tag_list: "red, yellow", page: create(:alchemy_page), }) end before do - element.nested_elements << create(:alchemy_element, name: 'slide') + element.nested_elements << create(:alchemy_element, name: "slide") end it "should copy nested elements" do expect(subject.nested_elements).to_not be_empty end - context 'copy to new page' do + context "copy to new page" do let(:new_page) { create(:alchemy_page) } subject(:new_element) do - Element.copy(element, {page_id: new_page.id}) + Element.copy(element, { page_id: new_page.id }) end it "should set page id to new page's id" do @@ -176,13 +176,13 @@ module Alchemy end end - describe '.definitions' do + describe ".definitions" do it "should allow erb generated elements" do - expect(Element.definitions.collect { |el| el['name'] }).to include('erb_element') + expect(Element.definitions.collect { |el| el["name"] }).to include("erb_element") end context "with a YAML file including a symbol" do - let(:yaml) { '- name: :symbol' } + let(:yaml) { "- name: :symbol" } before do expect(File).to receive(:exist?).and_return(true) @@ -195,7 +195,7 @@ module Alchemy end context "with a YAML file including a Date" do - let(:yaml) { '- default: 2017-12-24' } + let(:yaml) { "- default: 2017-12-24" } before do expect(File).to receive(:exist?).and_return(true) @@ -237,37 +237,37 @@ module Alchemy end end - describe '.display_name_for' do + describe ".display_name_for" do it "should return the translation for the given name" do - expect(Alchemy).to receive(:t).with('subheadline', scope: "element_names", default: 'Subheadline').and_return('Überschrift') - expect(Element.display_name_for('subheadline')).to eq('Überschrift') + expect(Alchemy).to receive(:t).with("subheadline", scope: "element_names", default: "Subheadline").and_return("Überschrift") + expect(Element.display_name_for("subheadline")).to eq("Überschrift") end it "should return the humanized name if no translation found" do - expect(Element.display_name_for('not_existing_one')).to eq('Not existing one') + expect(Element.display_name_for("not_existing_one")).to eq("Not existing one") end end - describe '.excluded' do + describe ".excluded" do it "should return all elements but excluded ones" do - create(:alchemy_element, name: 'article') - create(:alchemy_element, name: 'article') - excluded = create(:alchemy_element, name: 'claim') - expect(Element.excluded(['claim'])).not_to include(excluded) + create(:alchemy_element, name: "article") + create(:alchemy_element, name: "article") + excluded = create(:alchemy_element, name: "claim") + expect(Element.excluded(["claim"])).not_to include(excluded) end end - describe '.named' do + describe ".named" do it "should return all elements by name" do - element_1 = create(:alchemy_element, name: 'article') - element_2 = create(:alchemy_element, name: 'headline') - elements = Element.named(['article']) + element_1 = create(:alchemy_element, name: "article") + element_2 = create(:alchemy_element, name: "headline") + elements = Element.named(["article"]) expect(elements).to include(element_1) expect(elements).to_not include(element_2) end end - describe '.fixed' do + describe ".fixed" do let!(:fixed_element) { create(:alchemy_element, :fixed) } let!(:element) { create(:alchemy_element) } @@ -278,7 +278,7 @@ module Alchemy end end - describe '.unfixed' do + describe ".unfixed" do let!(:fixed_element) { create(:alchemy_element, :fixed) } let!(:element) { create(:alchemy_element) } @@ -289,7 +289,7 @@ module Alchemy end end - describe '.published' do + describe ".published" do it "should return all public elements" do element_1 = create(:alchemy_element, public: true) element_2 = create(:alchemy_element, public: false) @@ -299,7 +299,7 @@ module Alchemy end end - describe '.folded' do + describe ".folded" do it "returns all folded elements" do element_1 = create(:alchemy_element, folded: true) element_2 = create(:alchemy_element, folded: false) @@ -309,7 +309,7 @@ module Alchemy end end - describe '.expanded' do + describe ".expanded" do it "returns all expanded elements" do element_1 = create(:alchemy_element, folded: false) element_2 = create(:alchemy_element, folded: true) @@ -319,7 +319,7 @@ module Alchemy end end - describe '.not_nested' do + describe ".not_nested" do subject { Element.not_nested } let!(:element_1) { create(:alchemy_element) } @@ -330,10 +330,10 @@ module Alchemy end end - context 'trash' do + context "trash" do let(:element) { create(:alchemy_element) } - describe '.not_trashed' do + describe ".not_trashed" do before { element } it "should return a collection of not trashed elements" do @@ -350,11 +350,11 @@ module Alchemy end end - describe '.all_from_clipboard_for_page' do + describe ".all_from_clipboard_for_page" do let(:element_1) { build_stubbed(:alchemy_element) } - let(:element_2) { build_stubbed(:alchemy_element, name: 'news') } - let(:page) { build_stubbed(:alchemy_page, :public) } - let(:clipboard) { [{'id' => element_1.id.to_s}, {'id' => element_2.id.to_s}] } + let(:element_2) { build_stubbed(:alchemy_element, name: "news") } + let(:page) { build_stubbed(:alchemy_page, :public) } + let(:clipboard) { [{ "id" => element_1.id.to_s }, { "id" => element_2.id.to_s }] } before do allow(Element).to receive(:all_from_clipboard).and_return([element_1, element_2]) @@ -381,24 +381,24 @@ module Alchemy # InstanceMethods - describe '#all_contents_by_type' do + describe "#all_contents_by_type" do let(:element) { create(:alchemy_element, :with_contents) } let(:expected_contents) { element.contents.essence_texts } context "with namespaced essence type" do - subject { element.all_contents_by_type('Alchemy::EssenceText') } + subject { element.all_contents_by_type("Alchemy::EssenceText") } it { is_expected.not_to be_empty } - it('should return the correct list of essences') { is_expected.to eq(expected_contents) } + it("should return the correct list of essences") { is_expected.to eq(expected_contents) } end context "without namespaced essence type" do - subject { element.all_contents_by_type('EssenceText') } + subject { element.all_contents_by_type("EssenceText") } it { is_expected.not_to be_empty } - it('should return the correct list of essences') { is_expected.to eq(expected_contents) } + it("should return the correct list of essences") { is_expected.to eq(expected_contents) } end end - describe '#contents' do + describe "#contents" do let(:element) { create(:alchemy_element) } let!(:content1) { create(:alchemy_content, element: element) } let!(:content2) { create(:alchemy_content, element: element) } @@ -410,32 +410,32 @@ module Alchemy content2.update_column(:position, 1) end - it 'are ordered by position' do + it "are ordered by position" do is_expected.to eq([content2, content1]) end end - describe '#content_by_type' do + describe "#content_by_type" do before(:each) do - @element = create(:alchemy_element, name: 'headline') + @element = create(:alchemy_element, name: "headline") @content = @element.contents.first end context "with namespaced essence type" do it "should return content by passing a essence type" do - expect(@element.content_by_type('Alchemy::EssenceText')).to eq(@content) + expect(@element.content_by_type("Alchemy::EssenceText")).to eq(@content) end end context "without namespaced essence type" do it "should return content by passing a essence type" do - expect(@element.content_by_type('EssenceText')).to eq(@content) + expect(@element.content_by_type("EssenceText")).to eq(@content) end end end - describe '#display_name' do - let(:element) { Element.new(name: 'article') } + describe "#display_name" do + let(:element) { Element.new(name: "article") } it "should call .display_name_for" do expect(Element).to receive(:display_name_for).with(element.name) @@ -443,55 +443,56 @@ module Alchemy end end - describe '#essence_errors' do - let(:element) { Element.new(name: 'article') } - let(:content) { Content.new(name: 'headline') } - let(:essence) { EssenceText.new(body: '') } + describe "#essence_errors" do + let(:element) { Element.new(name: "article") } + let(:content) { Content.new(name: "headline") } + let(:essence) { EssenceText.new(body: "") } before do allow(element).to receive(:contents) { [content] } allow(content).to receive(:essence) { essence } allow(content).to receive(:essence_validation_failed?) { true } - allow(essence).to receive(:validation_errors) { 'Cannot be blank' } + allow(essence).to receive(:validation_errors) { "Cannot be blank" } end it "returns hash with essence errors" do - expect(element.essence_errors).to eq({'headline' => 'Cannot be blank'}) + expect(element.essence_errors).to eq({ "headline" => "Cannot be blank" }) end end - describe '#essence_error_messages' do - let(:element) { Element.new(name: 'article') } + describe "#essence_error_messages" do + let(:element) { Element.new(name: "article") } it "should return the translation with the translated content label" do expect(Alchemy).to receive(:t) - .with('content_names.content', default: 'Content') - .and_return('Content') + .with("content_names.content", default: "Content") + .and_return("Content") expect(Alchemy).to receive(:t) - .with('content', scope: "content_names.article", default: 'Content') - .and_return('Contenido') + .with("content", scope: "content_names.article", default: "Content") + .and_return("Contenido") expect(Alchemy).to receive(:t) - .with('article.content.invalid', { - scope: "content_validations", - default: [:"fields.content.invalid", :"errors.invalid"], - field: "Contenido", }) + .with("article.content.invalid", { + scope: "content_validations", + default: [:"fields.content.invalid", :"errors.invalid"], + field: "Contenido", + }) expect(element).to receive(:essence_errors) - .and_return({'content' => [:invalid]}) + .and_return({ "content" => [:invalid] }) element.essence_error_messages end end - describe '#display_name_with_preview_text' do - let(:element) { build_stubbed(:alchemy_element, name: 'Foo') } + describe "#display_name_with_preview_text" do + let(:element) { build_stubbed(:alchemy_element, name: "Foo") } it "returns a string with display name and preview text" do - allow(element).to receive(:preview_text).and_return('Fula') + allow(element).to receive(:preview_text).and_return("Fula") expect(element.display_name_with_preview_text).to eq("Foo: Fula") end end - describe '#dom_id' do + describe "#dom_id" do let(:element) { build_stubbed(:alchemy_element) } it "returns an string from element name and id" do @@ -499,21 +500,21 @@ module Alchemy end end - describe '#preview_text' do + describe "#preview_text" do let(:element) { build_stubbed(:alchemy_element) } let(:content) do - mock_model(Content, preview_text: 'Content 1', preview_content?: false) + mock_model(Content, preview_text: "Content 1", preview_content?: false) end let(:content_2) do - mock_model(Content, preview_text: 'Content 2', preview_content?: false) + mock_model(Content, preview_text: "Content 2", preview_content?: false) end let(:contents) { [] } let(:preview_content) do - mock_model(Content, preview_text: 'Preview Content', preview_content?: true) + mock_model(Content, preview_text: "Preview Content", preview_content?: true) end before do @@ -544,13 +545,13 @@ module Alchemy end end - context 'with nested elements' do + context "with nested elements" do let(:element) do build_stubbed(:alchemy_element, :with_nestable_elements) end let(:nested_element) do - build_stubbed(:alchemy_element, name: 'slide') + build_stubbed(:alchemy_element, name: "slide") end before do @@ -558,24 +559,24 @@ module Alchemy allow(element).to receive(:all_nested_elements) { [nested_element] } end - context 'when parent element has contents' do + context "when parent element has contents" do before do allow(element).to receive(:contents) { [content] } end - it 'returns the preview text from the parent element' do + it "returns the preview text from the parent element" do expect(content).to receive(:preview_text) expect(element.preview_text) end end - context 'when parent element has no contents but nestable element has' do + context "when parent element has no contents but nestable element has" do before do allow(element).to receive(:contents) { [] } allow(nested_element).to receive(:contents) { [content_2] } end - it 'returns the preview text from the first nested element' do + it "returns the preview text from the first nested element" do expect(content_2).to receive(:preview_text) expect(element.preview_text) end @@ -583,56 +584,56 @@ module Alchemy end end - context 'previous and next elements.' do + context "previous and next elements." do let(:page) { create(:alchemy_page, :language_root) } before(:each) do - @element1 = create(:alchemy_element, page: page, name: 'headline') + @element1 = create(:alchemy_element, page: page, name: "headline") @element2 = create(:alchemy_element, page: page) - @element3 = create(:alchemy_element, page: page, name: 'text') + @element3 = create(:alchemy_element, page: page, name: "text") end - describe '#prev' do + describe "#prev" do it "should return previous element on same page" do expect(@element3.prev).to eq(@element2) end context "with name as parameter" do it "should return previous of this kind" do - expect(@element3.prev('headline')).to eq(@element1) + expect(@element3.prev("headline")).to eq(@element1) end end end - describe '#next' do + describe "#next" do it "should return next element on same page" do expect(@element2.next).to eq(@element3) end context "with name as parameter" do it "should return next of this kind" do - expect(@element1.next('text')).to eq(@element3) + expect(@element1.next("text")).to eq(@element3) end end end end - context 'retrieving contents, essences and ingredients' do - let(:element) { create(:alchemy_element, :with_contents, name: 'news') } + context "retrieving contents, essences and ingredients" do + let(:element) { create(:alchemy_element, :with_contents, name: "news") } it "should return an ingredient by name" do - expect(element.ingredient('news_headline')).to eq(EssenceText.first.ingredient) + expect(element.ingredient("news_headline")).to eq(EssenceText.first.ingredient) end it "should return the content for rss title" do - expect(element.content_for_rss_title).to eq(element.contents.find_by_name('news_headline')) + expect(element.content_for_rss_title).to eq(element.contents.find_by_name("news_headline")) end it "should return the content for rss descdefinitionription" do - expect(element.content_for_rss_description).to eq(element.contents.find_by_name('body')) + expect(element.content_for_rss_description).to eq(element.contents.find_by_name("body")) end - context 'if no content is defined as rss title' do + context "if no content is defined as rss title" do before { expect(element).to receive(:content_definitions).and_return([]) } it "should return nil" do @@ -640,7 +641,7 @@ module Alchemy end end - context 'if no content is defined as rss description' do + context "if no content is defined as rss description" do before { expect(element).to receive(:content_definitions).and_return([]) } it "should return nil" do @@ -649,11 +650,11 @@ module Alchemy end end - describe '#update_contents' do + describe "#update_contents" do subject { element.update_contents(params) } - let(:page) { build_stubbed(:alchemy_page) } - let(:element) { build_stubbed(:alchemy_element, page: page) } + let(:page) { build_stubbed(:alchemy_page) } + let(:element) { build_stubbed(:alchemy_element, page: page) } let(:content1) { double(:content, id: 1) } let(:content2) { double(:content, id: 2) } @@ -665,23 +666,23 @@ module Alchemy end context "with valid attributes hash" do - let(:params) { {content1.id.to_s => {body: 'Title'}} } + let(:params) { { content1.id.to_s => { body: "Title" } } } - context 'when certain content is not part of the attributes hash (cause it was not filled by the user)' do + context "when certain content is not part of the attributes hash (cause it was not filled by the user)" do before do allow(element).to receive(:contents).and_return([content1, content2]) end - it 'does not try to update that content' do - expect(content1).to receive(:update_essence).with({body: 'Title'}).and_return(true) + it "does not try to update that content" do + expect(content1).to receive(:update_essence).with({ body: "Title" }).and_return(true) expect(content2).to_not receive(:update_essence) subject end end - context 'with passing validations' do + context "with passing validations" do before do - expect(content1).to receive(:update_essence).with({body: 'Title'}).and_return(true) + expect(content1).to receive(:update_essence).with({ body: "Title" }).and_return(true) end it { is_expected.to be_truthy } @@ -692,9 +693,9 @@ module Alchemy end end - context 'with failing validations' do + context "with failing validations" do it "adds error and returns false" do - expect(content1).to receive(:update_essence).with({body: 'Title'}).and_return(false) + expect(content1).to receive(:update_essence).with({ body: "Title" }).and_return(false) is_expected.to be_falsey expect(element.errors).not_to be_empty end @@ -702,7 +703,7 @@ module Alchemy end end - describe '.after_update' do + describe ".after_update" do let(:element) { create(:alchemy_element, page: page) } let(:page) do @@ -715,7 +716,7 @@ module Alchemy expect { element.save }.to change { page.updated_at } end - context 'with touchable pages' do + context "with touchable pages" do let(:touchable_page) do create(:alchemy_page).tap do |page| page.update_column(:updated_at, 3.hours.ago) @@ -729,14 +730,14 @@ module Alchemy end end - describe '#taggable?' do + describe "#taggable?" do let(:element) { build(:alchemy_element) } context "definition has 'taggable' key with true value" do it "should return true" do expect(element).to receive(:definition).and_return({ - 'name' => 'article', - 'taggable' => true, + "name" => "article", + "taggable" => true, }) expect(element.taggable?).to be_truthy end @@ -745,8 +746,8 @@ module Alchemy context "definition has 'taggable' key with foo value" do it "should return false" do expect(element).to receive(:definition).and_return({ - 'name' => 'article', - 'taggable' => 'foo', + "name" => "article", + "taggable" => "foo", }) expect(element.taggable?).to be_falsey end @@ -755,14 +756,14 @@ module Alchemy context "definition has no 'taggable' key" do it "should return false" do expect(element).to receive(:definition).and_return({ - 'name' => 'article', + "name" => "article", }) expect(element.taggable?).to be_falsey end end end - describe '#compact?' do + describe "#compact?" do subject { element.compact? } let(:element) { build(:alchemy_element) } @@ -772,22 +773,22 @@ module Alchemy end context "definition has 'compact' key with true value" do - let(:definition) { {'compact' => true} } + let(:definition) { { "compact" => true } } it { is_expected.to be(true) } end context "definition has 'compact' key with foo value" do - let(:definition) { {'compact' => 'foo'} } + let(:definition) { { "compact" => "foo" } } it { is_expected.to be(false) } end context "definition has no 'compact' key" do - let(:definition) { {'name' => 'article'} } + let(:definition) { { "name" => "article" } } it { is_expected.to be(false) } end end - describe '#trash!' do + describe "#trash!" do let(:element) { create(:alchemy_element) } let(:trashed_element) do @@ -800,7 +801,7 @@ module Alchemy it { is_expected.not_to be_public } it { is_expected.to be_folded } - describe '#position' do + describe "#position" do subject { super().position } it { is_expected.to be_nil } end @@ -826,11 +827,11 @@ module Alchemy describe "#to_partial_path" do it do - expect(Element.new(name: 'article').to_partial_path).to eq('alchemy/elements/article') + expect(Element.new(name: "article").to_partial_path).to eq("alchemy/elements/article") end end - describe '#cache_key' do + describe "#cache_key" do let(:page) { stub_model(Page, published_at: Time.current - 1.week) } let(:element) { stub_model(Element, page: page, updated_at: Time.current) } @@ -862,28 +863,28 @@ module Alchemy subject { element.nestable_elements } - context 'with nestable_elements defined' do + context "with nestable_elements defined" do before do allow(element).to receive(:definition) do { - 'nestable_elements' => %w(news article), + "nestable_elements" => %w(news article), } end end - it 'returns an array containing all available nested element names' do + it "returns an array containing all available nested element names" do is_expected.to eq %w(news article) end end - context 'without nestable_elements defined' do + context "without nestable_elements defined" do before do allow(element).to receive(:definition) do {} end end - it 'returns an empty array' do + it "returns an empty array" do is_expected.to eq [] end end @@ -896,26 +897,26 @@ module Alchemy let!(:element) { create(:alchemy_element, page: page) } let!(:nested_element) { create(:alchemy_element, parent_element: element, page: page) } - it 'returns nested elements' do + it "returns nested elements" do expect(subject).to eq([nested_element]) end - context 'with hidden nested elements' do + context "with hidden nested elements" do let!(:hidden_nested_element) do create(:alchemy_element, parent_element: element, page: page, public: false) end - it 'includes them' do + it "includes them" do expect(subject).to include(hidden_nested_element) end end - context 'with trashed nested elements' do + context "with trashed nested elements" do let!(:trashed_nested_element) do create(:alchemy_element, parent_element: element, page: page).tap(&:trash!) end - it 'does not include them' do + it "does not include them" do expect(subject).to_not include(trashed_nested_element) end end @@ -924,52 +925,52 @@ module Alchemy describe "#nested_elements" do subject { element.nested_elements } - context 'with nestable_elements defined' do + context "with nestable_elements defined" do let!(:page) { create(:alchemy_page) } let!(:element) { create(:alchemy_element, page: page) } let!(:nested_element) { create(:alchemy_element, parent_element: element, page: page) } - it 'returns nested elements' do + it "returns nested elements" do expect(subject).to eq([nested_element]) end - context 'with hidden nested elements' do + context "with hidden nested elements" do let!(:hidden_nested_element) do create(:alchemy_element, parent_element: element, page: page, public: false) end - it 'does not include them' do + it "does not include them" do expect(subject).to eq([nested_element]) end end - context 'with trashed nested elements' do + context "with trashed nested elements" do let!(:hidden_trashed_element) do create(:alchemy_element, parent_element: element, page: page).tap(&:trash!) end - it 'does not include them' do + it "does not include them" do expect(subject).to eq([nested_element]) end end end end - describe '#richtext_contents_ids' do + describe "#richtext_contents_ids" do subject { element.richtext_contents_ids } - let(:element) { create(:alchemy_element, :with_contents, name: 'text') } + let(:element) { create(:alchemy_element, :with_contents, name: "text") } it { is_expected.to eq(element.content_ids) } - context 'for element with nested elements' do + context "for element with nested elements" do let!(:element) do - create(:alchemy_element, :with_contents, name: 'text') + create(:alchemy_element, :with_contents, name: "text") end let!(:nested_element_1) do create(:alchemy_element, :with_contents, { - name: 'text', + name: "text", parent_element: element, folded: false, }) @@ -977,7 +978,7 @@ module Alchemy let!(:nested_element_2) do create(:alchemy_element, :with_contents, { - name: 'text', + name: "text", parent_element: nested_element_1, folded: false, }) @@ -985,13 +986,13 @@ module Alchemy let!(:folded_nested_element_3) do create(:alchemy_element, :with_contents, { - name: 'text', + name: "text", parent_element: nested_element_1, folded: true, }) end - it 'includes all richtext contents from all expanded descendent elements' do + it "includes all richtext contents from all expanded descendent elements" do is_expected.to eq( element.content_ids + nested_element_1.content_ids + @@ -1001,9 +1002,9 @@ module Alchemy end end - context 'with parent element' do + context "with parent element" do let!(:parent_element) { create(:alchemy_element, :with_nestable_elements) } - let!(:element) { create(:alchemy_element, name: 'slide', parent_element: parent_element) } + let!(:element) { create(:alchemy_element, name: "slide", parent_element: parent_element) } it "touches parent after update" do parent_element.update_column(:updated_at, 3.days.ago) diff --git a/spec/models/alchemy/element_to_page_spec.rb b/spec/models/alchemy/element_to_page_spec.rb index 9c7ca323d5..8f2113194b 100644 --- a/spec/models/alchemy/element_to_page_spec.rb +++ b/spec/models/alchemy/element_to_page_spec.rb @@ -1,14 +1,14 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" module Alchemy describe ElementToPage do # ClassMethods - describe '.table_name' do + describe ".table_name" do it "should return table name" do - expect(ElementToPage.table_name).to eq('alchemy_elements_alchemy_pages') + expect(ElementToPage.table_name).to eq("alchemy_elements_alchemy_pages") end end end diff --git a/spec/models/alchemy/essence_boolean_spec.rb b/spec/models/alchemy/essence_boolean_spec.rb index d401844c61..239796e59f 100644 --- a/spec/models/alchemy/essence_boolean_spec.rb +++ b/spec/models/alchemy/essence_boolean_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" module Alchemy describe EssenceBoolean do diff --git a/spec/models/alchemy/essence_date_spec.rb b/spec/models/alchemy/essence_date_spec.rb index 75c6e36f0e..7aaa8eb442 100644 --- a/spec/models/alchemy/essence_date_spec.rb +++ b/spec/models/alchemy/essence_date_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" module Alchemy describe EssenceDate do @@ -11,7 +11,7 @@ module Alchemy let(:ingredient_value) { Time.current.iso8601 } end - describe '#preview_text' do + describe "#preview_text" do subject { essence.preview_text } context "if no date set" do diff --git a/spec/models/alchemy/essence_file_spec.rb b/spec/models/alchemy/essence_file_spec.rb index 4b55bb47f9..5066d9c70b 100644 --- a/spec/models/alchemy/essence_file_spec.rb +++ b/spec/models/alchemy/essence_file_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" module Alchemy describe EssenceFile do @@ -12,21 +12,21 @@ module Alchemy let(:ingredient_value) { attachment } end - describe '#attachment_url' do + describe "#attachment_url" do subject { essence.attachment_url } it "returns the download attachment url." do is_expected.to match(/\/attachment\/#{attachment.id}\/download\/#{attachment.urlname}\.#{attachment.suffix}/) end - context 'without attachment assigned' do + context "without attachment assigned" do let(:attachment) { nil } it { is_expected.to be_nil } end end - describe '#preview_text' do + describe "#preview_text" do it "returns the attachment's name as preview text" do expect(essence.preview_text).to eq(attachment.name) end @@ -34,7 +34,7 @@ module Alchemy context "with no attachment assigned" do it "returns empty string" do essence.attachment = nil - expect(essence.preview_text).to eq('') + expect(essence.preview_text).to eq("") end end end diff --git a/spec/models/alchemy/essence_html_spec.rb b/spec/models/alchemy/essence_html_spec.rb index e5c659acda..fd4b0c7494 100644 --- a/spec/models/alchemy/essence_html_spec.rb +++ b/spec/models/alchemy/essence_html_spec.rb @@ -1,19 +1,19 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" module Alchemy describe EssenceHtml do - let(:essence) { EssenceHtml.new(source: '<p>hello!</p>') } + let(:essence) { EssenceHtml.new(source: "<p>hello!</p>") } it_behaves_like "an essence" do let(:essence) { EssenceHtml.new } - let(:ingredient_value) { '<p>hello!</p>' } + let(:ingredient_value) { "<p>hello!</p>" } end - describe '#preview_text' do + describe "#preview_text" do it "should return html escaped source code" do - expect(essence.preview_text).to eq('<p>hello!</p>') + expect(essence.preview_text).to eq("<p>hello!</p>") end end end diff --git a/spec/models/alchemy/essence_link_spec.rb b/spec/models/alchemy/essence_link_spec.rb index 088d020f02..3bc8c40ea3 100644 --- a/spec/models/alchemy/essence_link_spec.rb +++ b/spec/models/alchemy/essence_link_spec.rb @@ -1,12 +1,12 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" module Alchemy describe EssenceLink do it_behaves_like "an essence" do let(:essence) { EssenceLink.new } - let(:ingredient_value) { 'http://alchemy-cms.com' } + let(:ingredient_value) { "http://alchemy-cms.com" } end end end diff --git a/spec/models/alchemy/essence_node_spec.rb b/spec/models/alchemy/essence_node_spec.rb index b37b9e1ae3..162c3d3785 100644 --- a/spec/models/alchemy/essence_node_spec.rb +++ b/spec/models/alchemy/essence_node_spec.rb @@ -1,11 +1,11 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" RSpec.describe Alchemy::EssenceNode, type: :model do - it { is_expected.to belong_to(:ingredient_association).optional.class_name('Alchemy::Node') } + it { is_expected.to belong_to(:ingredient_association).optional.class_name("Alchemy::Node") } - describe '#ingredient' do + describe "#ingredient" do let(:node) { build(:alchemy_node) } subject { described_class.new(node: node).ingredient } @@ -13,7 +13,7 @@ it { is_expected.to eq(node) } end - describe '#preview_text' do + describe "#preview_text" do let(:node) { build(:alchemy_node) } subject { described_class.new(node: node).preview_text } diff --git a/spec/models/alchemy/essence_page_spec.rb b/spec/models/alchemy/essence_page_spec.rb index 0606e2a88c..963fb82e48 100644 --- a/spec/models/alchemy/essence_page_spec.rb +++ b/spec/models/alchemy/essence_page_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" RSpec.describe Alchemy::EssencePage, type: :model do let(:essence) { build(:alchemy_essence_page) } @@ -10,46 +10,46 @@ let(:ingredient_value) { page } end - describe 'eager loading' do + describe "eager loading" do let!(:essence_pages) { create_list(:alchemy_essence_page, 2) } - it 'eager loads pages' do + it "eager loads pages" do essences = described_class.all.includes(:ingredient_association) expect(essences[0].association(:ingredient_association)).to be_loaded end end - describe 'ingredient=' do + describe "ingredient=" do subject(:ingredient) { essence.page } - context 'when String value is only a number' do - let(:value) { '101' } + context "when String value is only a number" do + let(:value) { "101" } before do essence.ingredient = value end - it 'sets page to an page instance with that id' do + it "sets page to an page instance with that id" do is_expected.to be_a(Alchemy::Page) expect(ingredient.id).to eq(101) end end - context 'when value is an Alchemy Page' do + context "when value is an Alchemy Page" do let(:value) { page } before do essence.ingredient = value end - it 'sets page to an page instance with that id' do + it "sets page to an page instance with that id" do is_expected.to be_a(Alchemy::Page) expect(ingredient).to eq(page) end end - context 'when value is not only a number' do - let(:value) { 'page1' } + context "when value is not only a number" do + let(:value) { "page1" } it do expect { diff --git a/spec/models/alchemy/essence_picture_spec.rb b/spec/models/alchemy/essence_picture_spec.rb index 3fc0c04fdd..3e539b0000 100644 --- a/spec/models/alchemy/essence_picture_spec.rb +++ b/spec/models/alchemy/essence_picture_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" module Alchemy describe EssencePicture do @@ -9,10 +9,10 @@ module Alchemy let(:ingredient_value) { Picture.new } end - describe 'eager loading' do + describe "eager loading" do let!(:essence_pictures) { create_list(:alchemy_essence_picture, 2) } - it 'eager loads pictures' do + it "eager loads pictures" do essences = described_class.all.includes(:ingredient_association) expect(essences[0].association(:ingredient_association)).to be_loaded end @@ -23,14 +23,14 @@ module Alchemy end it "should not store negative values for crop values" do - essence = EssencePicture.new(crop_from: '-1x100', crop_size: '-20x30') + essence = EssencePicture.new(crop_from: "-1x100", crop_size: "-20x30") essence.save! expect(essence.crop_from).to eq("0x100") expect(essence.crop_size).to eq("0x30") end it "should not store float values for crop values" do - essence = EssencePicture.new(crop_from: '0.05x104.5', crop_size: '99.5x203.4') + essence = EssencePicture.new(crop_from: "0.05x104.5", crop_size: "99.5x203.4") essence.save! expect(essence.crop_from).to eq("0x105") expect(essence.crop_size).to eq("100x203") @@ -49,70 +49,70 @@ module Alchemy expect(essence.caption).to eq("hello<br/>kitty") end - describe '#picture_url' do + describe "#picture_url" do subject(:picture_url) { essence.picture_url(options) } let(:options) { {} } let(:picture) { create(:alchemy_picture) } let(:essence) { create(:alchemy_essence_picture, :with_content, picture: picture) } - context 'with no format in the options' do + context "with no format in the options" do it "includes the image's default render format." do expect(picture_url).to match(/\.png/) end end - context 'with format in the options' do - let(:options) { {format: 'gif'} } + context "with format in the options" do + let(:options) { {format: "gif"} } it "takes this as format." do expect(picture_url).to match(/\.gif/) end end - context 'when crop sizes are present' do + context "when crop sizes are present" do before do - expect(essence).to receive(:crop_size).and_return('200x200') - expect(essence).to receive(:crop_from).and_return('10x10') + expect(essence).to receive(:crop_size).and_return("200x200") + expect(essence).to receive(:crop_from).and_return("10x10") end it "passes these crop sizes to the picture's url method." do expect(picture).to receive(:url).with( - hash_including(crop_from: '10x10', crop_size: '200x200'), + hash_including(crop_from: "10x10", crop_size: "200x200"), ) picture_url end - context 'but with crop sizes in the options' do + context "but with crop sizes in the options" do let(:options) do - {crop_from: '30x30', crop_size: '75x75'} + {crop_from: "30x30", crop_size: "75x75"} end it "passes these crop sizes instead." do expect(picture).to receive(:url).with( - hash_including(crop_from: '30x30', crop_size: '75x75'), + hash_including(crop_from: "30x30", crop_size: "75x75"), ) picture_url end end end - context 'with other options' do - let(:options) { {foo: 'baz'} } + context "with other options" do + let(:options) { {foo: "baz"} } - it 'adds them to the url' do + it "adds them to the url" do expect(picture_url).to match /\?foo=baz/ end end - context 'without picture assigned' do + context "without picture assigned" do let(:picture) { nil } it { is_expected.to be_nil } end end - describe '#picture_url_options' do + describe "#picture_url_options" do subject(:picture_url_options) { essence.picture_url_options } let(:picture) { build_stubbed(:alchemy_picture) } @@ -121,27 +121,27 @@ module Alchemy it { is_expected.to be_a(HashWithIndifferentAccess) } it "includes the pictures default render format." do - expect(picture).to receive(:default_render_format) { 'img' } - expect(picture_url_options[:format]).to eq('img') + expect(picture).to receive(:default_render_format) { "img" } + expect(picture_url_options[:format]).to eq("img") end - context 'with crop sizes present' do + context "with crop sizes present" do before do - expect(essence).to receive(:crop_size) { '200x200' } - expect(essence).to receive(:crop_from) { '10x10' } + expect(essence).to receive(:crop_size) { "200x200" } + expect(essence).to receive(:crop_from) { "10x10" } end it "includes these crop sizes.", :aggregate_failures do - expect(picture_url_options[:crop_from]).to eq '10x10' - expect(picture_url_options[:crop_size]).to eq '200x200' + expect(picture_url_options[:crop_from]).to eq "10x10" + expect(picture_url_options[:crop_size]).to eq "200x200" end end # Regression spec for issue #1279 - context 'with crop sizes being empty strings' do + context "with crop sizes being empty strings" do before do - expect(essence).to receive(:crop_size) { '' } - expect(essence).to receive(:crop_from) { '' } + expect(essence).to receive(:crop_size) { "" } + expect(essence).to receive(:crop_from) { "" } end it "does not include these crop sizes.", :aggregate_failures do @@ -150,24 +150,24 @@ module Alchemy end end - context 'with content having size setting' do + context "with content having size setting" do before do - expect(essence.content).to receive(:settings) { {size: '30x70'} } + expect(essence.content).to receive(:settings) { {size: "30x70"} } end it "includes this size." do - expect(picture_url_options[:size]).to eq '30x70' + expect(picture_url_options[:size]).to eq "30x70" end end - context 'without picture assigned' do + context "without picture assigned" do let(:picture) { nil } it { is_expected.to be_a(Hash) } end end - describe '#thumbnail_url' do + describe "#thumbnail_url" do subject(:thumbnail_url) { essence.thumbnail_url } let(:settings) do @@ -200,21 +200,21 @@ module Alchemy thumbnail_url end - context 'when crop sizes are present' do + context "when crop sizes are present" do before do - allow(essence).to receive(:crop_size).and_return('200x200') - allow(essence).to receive(:crop_from).and_return('10x10') + allow(essence).to receive(:crop_size).and_return("200x200") + allow(essence).to receive(:crop_from).and_return("10x10") end it "passes these crop sizes to the picture's url method." do expect(picture).to receive(:url).with( - hash_including(crop_from: '10x10', crop_size: '200x200', crop: true), + hash_including(crop_from: "10x10", crop_size: "200x200", crop: true), ) thumbnail_url end end - context 'when no crop sizes are present' do + context "when no crop sizes are present" do it "it does not pass crop sizes to the picture's url method and disables cropping." do expect(picture).to receive(:url).with( hash_including(crop_from: nil, crop_size: nil, crop: false), @@ -222,7 +222,7 @@ module Alchemy thumbnail_url end - context 'when crop is explicitely enabled in the settings' do + context "when crop is explicitely enabled in the settings" do let(:settings) do { crop: true } end @@ -236,58 +236,58 @@ module Alchemy end end - context 'without picture assigned' do + context "without picture assigned" do let(:picture) { nil } it { is_expected.to be_nil } end end - describe '#cropping_mask' do + describe "#cropping_mask" do subject { essence.cropping_mask } - context 'with crop values given' do - let(:essence) { build_stubbed(:alchemy_essence_picture, crop_from: '0x0', crop_size: '100x100') } + context "with crop values given" do + let(:essence) { build_stubbed(:alchemy_essence_picture, crop_from: "0x0", crop_size: "100x100") } it "returns a hash containing cropping coordinates" do is_expected.to eq({x1: 0, y1: 0, x2: 100, y2: 100}) end end - context 'with no crop values given' do + context "with no crop values given" do let(:essence) { build_stubbed(:alchemy_essence_picture) } it { is_expected.to be_nil } end end - describe '#preview_text' do - let(:picture) { mock_model(Picture, name: 'Cute Cat Kittens') } + describe "#preview_text" do + let(:picture) { mock_model(Picture, name: "Cute Cat Kittens") } let(:essence) { EssencePicture.new } it "should return the pictures name as preview text" do allow(essence).to receive(:picture).and_return(picture) - expect(essence.preview_text).to eq('Cute Cat Kittens') + expect(essence.preview_text).to eq("Cute Cat Kittens") end context "with no picture assigned" do it "returns empty string" do - expect(essence.preview_text).to eq('') + expect(essence.preview_text).to eq("") end end end - describe '#serialized_ingredient' do + describe "#serialized_ingredient" do let(:content) do Content.new end let(:picture) do mock_model Picture, - name: 'Cute Cat Kittens', - urlname: 'cute-cat-kittens', - security_token: 'kljhgfd', - default_render_format: 'jpg' + name: "Cute Cat Kittens", + urlname: "cute-cat-kittens", + security_token: "kljhgfd", + default_render_format: "jpg" end let(:essence) do @@ -299,11 +299,11 @@ module Alchemy essence.serialized_ingredient end - context 'with image settings set as content settings' do + context "with image settings set as content settings" do let(:settings) do { - size: '150x150', - format: 'png', + size: "150x150", + format: "png", } end diff --git a/spec/models/alchemy/essence_picture_view_spec.rb b/spec/models/alchemy/essence_picture_view_spec.rb index caadcc0b7c..cfc56a5715 100644 --- a/spec/models/alchemy/essence_picture_view_spec.rb +++ b/spec/models/alchemy/essence_picture_view_spec.rb @@ -1,40 +1,40 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" describe Alchemy::EssencePictureView, type: :model do include Capybara::RSpecMatchers let(:image) do - File.new(File.expand_path('../../fixtures/image.png', __dir__)) + File.new(File.expand_path("../../fixtures/image.png", __dir__)) end let(:picture) do stub_model Alchemy::Picture, - image_file_format: 'png', + image_file_format: "png", image_file: image end let(:essence_picture) do stub_model Alchemy::EssencePicture, picture: picture, - caption: 'This is a cute cat' + caption: "This is a cute cat" end let(:content) do stub_model Alchemy::Content, - name: 'image', - essence_type: 'EssencePicture', + name: "image", + essence_type: "EssencePicture", essence: essence_picture end - let(:picture_url) { '/pictures/1/image.png' } + let(:picture_url) { "/pictures/1/image.png" } before do allow(picture).to receive(:url) { picture_url } end - describe 'DEFAULT_OPTIONS' do + describe "DEFAULT_OPTIONS" do it do expect(Alchemy::EssencePictureView::DEFAULT_OPTIONS). to be_a(HashWithIndifferentAccess) @@ -55,12 +55,12 @@ end it "should enclose the image in a <figure> element" do - expect(view).to have_selector('figure img') + expect(view).to have_selector("figure img") end it "should show the caption" do - expect(view).to have_selector('figure figcaption') - expect(view).to have_content('This is a cute cat') + expect(view).to have_selector("figure figcaption") + expect(view).to have_content("This is a cute cat") end it "does not pass default options to picture url" do @@ -74,12 +74,12 @@ end it "should not enclose the image in a <figure> element" do - expect(view).to_not have_selector('figure img') + expect(view).to_not have_selector("figure img") end it "should not show the caption" do - expect(view).to_not have_selector('figure figcaption') - expect(view).to_not have_content('This is a cute cat') + expect(view).to_not have_selector("figure figcaption") + expect(view).to_not have_content("This is a cute cat") end end @@ -89,57 +89,57 @@ end it "should not enclose the image in a <figure> element" do - expect(view).to_not have_selector('figure img') + expect(view).to_not have_selector("figure img") end it "should not show the caption" do - expect(view).to_not have_selector('figure figcaption') - expect(view).to_not have_content('This is a cute cat') + expect(view).to_not have_selector("figure figcaption") + expect(view).to_not have_content("This is a cute cat") end - context 'but enabled in the options hash' do + context "but enabled in the options hash" do let(:options) { {show_caption: true} } it "should enclose the image in a <figure> element" do - expect(view).to have_selector('figure img') + expect(view).to have_selector("figure img") end it "should show the caption" do - expect(view).to have_selector('figure figcaption') - expect(view).to have_content('This is a cute cat') + expect(view).to have_selector("figure figcaption") + expect(view).to have_content("This is a cute cat") end end end context "and essence with css class" do before do - essence_picture.css_class = 'left' + essence_picture.css_class = "left" end it "should have the class on the <figure> element" do - expect(view).to have_selector('figure.left img') + expect(view).to have_selector("figure.left img") end it "should not have the class on the <img> element" do - expect(view).not_to have_selector('figure img.left') + expect(view).not_to have_selector("figure img.left") end end context "and css class in the html_options" do before do - html_options[:class] = 'right' + html_options[:class] = "right" end it "should have the class from the html_options on the <figure> element" do - expect(view).to have_selector('figure.right img') + expect(view).to have_selector("figure.right img") end it "should not have the class from the essence on the <figure> element" do - expect(view).not_to have_selector('figure.left img') + expect(view).not_to have_selector("figure.left img") end it "should not have the class from the html_options on the <img> element" do - expect(view).not_to have_selector('figure img.right') + expect(view).not_to have_selector("figure img.right") end end end @@ -150,7 +150,7 @@ end subject(:view) do - essence_picture.link = '/home' + essence_picture.link = "/home" Alchemy::EssencePictureView.new(content, options).render end @@ -164,7 +164,7 @@ end it "should not enclose the image in a link tag" do - expect(view).not_to have_selector('a img') + expect(view).not_to have_selector("a img") end end end @@ -199,7 +199,7 @@ [] end - it 'does not pass srcset option to picture_url' do + it "does not pass srcset option to picture_url" do expect(essence_picture).to receive(:picture_url).with({}) { picture_url } view end @@ -209,9 +209,9 @@ %w(1024x768 800x) end - it 'adds srcset attribute including image url and width for each size' do - url1 = essence_picture.picture_url(size: '1024x768') - url2 = essence_picture.picture_url(size: '800x') + it "adds srcset attribute including image url and width for each size" do + url1 = essence_picture.picture_url(size: "1024x768") + url2 = essence_picture.picture_url(size: "800x") expect(view).to have_selector("img[srcset=\"#{url1} 1024w, #{url2} 800w\"]") end @@ -222,9 +222,9 @@ %w(x768 x600) end - it 'adds srcset attribute including image url and height for each size' do - url1 = essence_picture.picture_url(size: 'x768') - url2 = essence_picture.picture_url(size: 'x600') + it "adds srcset attribute including image url and height for each size" do + url1 = essence_picture.picture_url(size: "x768") + url2 = essence_picture.picture_url(size: "x600") expect(view).to have_selector("img[srcset=\"#{url1} 768h, #{url2} 600h\"]") end @@ -236,8 +236,8 @@ Alchemy::EssencePictureView.new(content).render end - it 'image tag has no srcset attribute' do - expect(view).not_to have_selector('img[srcset]') + it "image tag has no srcset attribute" do + expect(view).not_to have_selector("img[srcset]") end end @@ -254,17 +254,17 @@ let(:sizes) do [ - '(max-width: 1023px) 100vh', - '(min-width: 1024px) 33.333vh', + "(max-width: 1023px) 100vh", + "(min-width: 1024px) 33.333vh", ] end - it 'does not pass sizes option to picture_url' do + it "does not pass sizes option to picture_url" do expect(essence_picture).to receive(:picture_url).with({}) { picture_url } view end - it 'adds sizes attribute for each size' do + it "adds sizes attribute for each size" do expect(view).to have_selector("img[sizes=\"#{sizes[0]}, #{sizes[1]}\"]") end end @@ -274,8 +274,8 @@ Alchemy::EssencePictureView.new(content).render end - it 'image tag has no sizes attribute' do - expect(view).not_to have_selector('img[sizes]') + it "image tag has no sizes attribute" do + expect(view).not_to have_selector("img[sizes]") end end end diff --git a/spec/models/alchemy/essence_richtext_spec.rb b/spec/models/alchemy/essence_richtext_spec.rb index e59c9c0bf9..f60fbb43b1 100644 --- a/spec/models/alchemy/essence_richtext_spec.rb +++ b/spec/models/alchemy/essence_richtext_spec.rb @@ -1,16 +1,16 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" module Alchemy describe EssenceRichtext do let(:essence) do - EssenceRichtext.new(body: '<h1>Hello!</h1><p>Welcome to Peters Petshop.</p>') + EssenceRichtext.new(body: "<h1>Hello!</h1><p>Welcome to Peters Petshop.</p>") end it_behaves_like "an essence" do let(:essence) { EssenceRichtext.new } - let(:ingredient_value) { '<h1>Hello!</h1><p>Welcome to Peters Petshop.</p>' } + let(:ingredient_value) { "<h1>Hello!</h1><p>Welcome to Peters Petshop.</p>" } end it "should save a HTML tag free version of body column" do @@ -18,7 +18,7 @@ module Alchemy expect(essence.stripped_body).to eq("Hello!Welcome to Peters Petshop.") end - it 'has tinymce enabled' do + it "has tinymce enabled" do expect(essence.has_tinymce?).to eq(true) end end diff --git a/spec/models/alchemy/essence_select_spec.rb b/spec/models/alchemy/essence_select_spec.rb index 8b66c013eb..7a2e404b69 100644 --- a/spec/models/alchemy/essence_select_spec.rb +++ b/spec/models/alchemy/essence_select_spec.rb @@ -1,12 +1,12 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" module Alchemy describe EssenceSelect do it_behaves_like "an essence" do let(:essence) { EssenceSelect.new } - let(:ingredient_value) { 'select value' } + let(:ingredient_value) { "select value" } end end end diff --git a/spec/models/alchemy/essence_text_spec.rb b/spec/models/alchemy/essence_text_spec.rb index 12bf061256..d770e4020b 100644 --- a/spec/models/alchemy/essence_text_spec.rb +++ b/spec/models/alchemy/essence_text_spec.rb @@ -1,18 +1,18 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" module Alchemy describe EssenceText do let(:essence) { EssenceText.new } - let(:ingredient_value) { 'Lorem ipsum' } + let(:ingredient_value) { "Lorem ipsum" } it_behaves_like "an essence" do let(:essence) { EssenceText.new } - let(:ingredient_value) { 'Lorem ipsum' } + let(:ingredient_value) { "Lorem ipsum" } end - describe '#preview_text' do + describe "#preview_text" do before do ingredient_column = essence.ingredient_column essence.send("#{ingredient_column}=", ingredient_value) @@ -30,23 +30,23 @@ module Alchemy context "with another preview_text_column defined" do before do - allow(essence).to receive(:title).and_return('Title column') + allow(essence).to receive(:title).and_return("Title column") allow(essence).to receive(:preview_text_column).and_return(:title) end it "should use this column as preview text method" do - expect(essence.preview_text).to eq('Title column') + expect(essence.preview_text).to eq("Title column") end end end - describe '#open_link_in_new_window?' do + describe "#open_link_in_new_window?" do let(:essence) { EssenceText.new } subject { essence.open_link_in_new_window? } - context 'essence responds to link_taget' do + context "essence responds to link_taget" do context 'if link_target attribute is set to "blank"' do - before { essence.link_target = 'blank' } + before { essence.link_target = "blank" } it "should return true" do expect(subject).to eq(true) @@ -61,47 +61,47 @@ module Alchemy end end - describe 'validations' do - describe 'format' do - context 'given a regex string' do + describe "validations" do + describe "format" do + context "given a regex string" do before do - allow(essence).to receive(:definition).and_return({'validate' => [{'format' => /\Ahttps:\/\/[\S]+/}]}) + allow(essence).to receive(:definition).and_return({"validate" => [{"format" => /\Ahttps:\/\/[\S]+/}]}) end - context 'when ingredient string does not match the given regex' do - before { essence.update(essence.ingredient_column.to_sym => 'http://alchemy-cms.com') } + context "when ingredient string does not match the given regex" do + before { essence.update(essence.ingredient_column.to_sym => "http://alchemy-cms.com") } - it 'should not be valid' do + it "should not be valid" do expect(essence).to_not be_valid end end - context 'when ingredient string matches the given regex' do - before { essence.update(essence.ingredient_column.to_sym => 'https://alchemy-cms.com') } + context "when ingredient string matches the given regex" do + before { essence.update(essence.ingredient_column.to_sym => "https://alchemy-cms.com") } - it 'should be valid' do + it "should be valid" do expect(essence).to be_valid end end end - context 'given a key from the config`s format_matcher list' do + context "given a key from the config`s format_matcher list" do before do - allow(essence).to receive(:definition).and_return({'validate' => [{'format' => 'email'}]}) + allow(essence).to receive(:definition).and_return({"validate" => [{"format" => "email"}]}) end - context 'when ingredient string does not match the given format matcher' do + context "when ingredient string does not match the given format matcher" do before { essence.update(essence.ingredient_column.to_sym => ingredient_value) } - it 'should not be valid' do + it "should not be valid" do expect(essence).to_not be_valid end end - context 'when ingredient string matches the given format matcher' do - before { essence.update(essence.ingredient_column.to_sym => 'email@email.com') } + context "when ingredient string matches the given format matcher" do + before { essence.update(essence.ingredient_column.to_sym => "email@email.com") } - it 'should be valid' do + it "should be valid" do expect(essence).to be_valid end end diff --git a/spec/models/alchemy/folded_page_spec.rb b/spec/models/alchemy/folded_page_spec.rb index 41c8caacd1..49ebef16fd 100644 --- a/spec/models/alchemy/folded_page_spec.rb +++ b/spec/models/alchemy/folded_page_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" module Alchemy class NonArDummyUser; end diff --git a/spec/models/alchemy/language_spec.rb b/spec/models/alchemy/language_spec.rb index bf7aa54f7d..249b60af1a 100644 --- a/spec/models/alchemy/language_spec.rb +++ b/spec/models/alchemy/language_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" module Alchemy describe Language do @@ -8,43 +8,43 @@ module Alchemy let(:language) { create(:alchemy_language, :klingon) } let(:page) { create(:alchemy_page, language: language) } - it 'is valid with uppercase country code' do + it "is valid with uppercase country code" do language = Alchemy::Language.new( - country_code: 'AT', - language_code: 'de', - name: 'Österreich', - frontpage_name: 'Start', - page_layout: 'index', + country_code: "AT", + language_code: "de", + name: "Österreich", + frontpage_name: "Start", + page_layout: "index", site: build(:alchemy_site), ) expect(language).to be_valid end it "should return a label for code" do - expect(language.label(:code)).to eq('kl') + expect(language.label(:code)).to eq("kl") end it "should return a label for name" do - expect(language.label(:name)).to eq('Klingon') + expect(language.label(:name)).to eq("Klingon") end context "with language_code and empty country_code" do it "#code should return language locale only" do - language.country_code = '' - expect(language.code).to eq('kl') + language.country_code = "" + expect(language.code).to eq("kl") end context "adding a value for country code" do it "#code should return a joined locale" do - language.country_code = 'cr' - expect(language.code).to eq('kl-cr') + language.country_code = "cr" + expect(language.code).to eq("kl-cr") end it "should update all associated Pages with self.code as value for Page#language_code" do page = create(:alchemy_page, language: language) - language.country_code = 'cr' + language.country_code = "cr" language.save - page.reload; expect(page.language_code).to eq('kl-cr') + page.reload; expect(page.language_code).to eq("kl-cr") end end end @@ -52,8 +52,8 @@ module Alchemy context "with country_code and_language_code" do context "removing the country_code" do it "should update all associated Pages´s language_code with Language#code" do - language = create(:alchemy_language, country_code: 'kl') - language.country_code = '' + language = create(:alchemy_language, country_code: "kl") + language.country_code = "" language.save page.reload; expect(page.language_code).to eq("kl") end @@ -92,13 +92,13 @@ module Alchemy end end - describe '.default' do + describe ".default" do let!(:site_1) do - create(:alchemy_site, host: 'site-one.com') + create(:alchemy_site, host: "site-one.com") end let!(:site_2) do - create(:alchemy_site, host: 'site-two.com') + create(:alchemy_site, host: "site-two.com") end let!(:default_language) do @@ -109,13 +109,13 @@ module Alchemy Language.default end - it 'returns the default language of current site' do + it "returns the default language of current site" do expect(Site).to receive(:current) { site_2 } is_expected.to eq(default_language) end end - describe '.find_by_code' do + describe ".find_by_code" do subject do Language.find_by_code(code) end @@ -142,7 +142,7 @@ module Alchemy let!(:default_site) { create(:alchemy_site, :default) } let!(:current_site) do - create(:alchemy_site, host: 'other.com') + create(:alchemy_site, host: "other.com") end let!(:other_language) do @@ -159,11 +159,11 @@ module Alchemy end end - describe 'validations' do + describe "validations" do let(:language) { Language.new(default: true, public: false) } - describe 'publicity_of_default_language' do - context 'if language is not published' do + describe "publicity_of_default_language" do + context "if language is not published" do it "should add an error to the object" do expect(language.valid?).to eq(false) expect(language.errors.messages).to have_key(:public) @@ -171,8 +171,8 @@ module Alchemy end end - describe 'presence_of_default_language' do - context 'if no default language would exist anymore' do + describe "presence_of_default_language" do + context "if no default language would exist anymore" do before do allow(Language).to receive(:default).and_return(language) allow(language).to receive(:default_changed?).and_return(true) @@ -185,7 +185,7 @@ module Alchemy end end - describe 'before' do + describe "before" do subject do language.valid? language.locale @@ -197,43 +197,43 @@ module Alchemy end end - context 'when locale is already set' do + context "when locale is already set" do let(:language) do - build(:alchemy_language, language_code: 'de', locale: 'de') + build(:alchemy_language, language_code: "de", locale: "de") end - it 'does not set the locale again' do + it "does not set the locale again" do expect(language).to_not receive(:set_locale) end end - context 'when code is an available locale' do + context "when code is an available locale" do let(:language) do - build(:alchemy_language, language_code: 'de', country_code: 'at') + build(:alchemy_language, language_code: "de", country_code: "at") end - it 'sets the locale to code' do - is_expected.to eq('de-at') + it "sets the locale to code" do + is_expected.to eq("de-at") end end - context 'when code is not is an available locale, but language_code is' do + context "when code is not is an available locale, but language_code is" do let(:language) do - build(:alchemy_language, language_code: 'de', country_code: 'ch') + build(:alchemy_language, language_code: "de", country_code: "ch") end - it 'sets the locale to language code' do - is_expected.to eq('de') + it "sets the locale to language code" do + is_expected.to eq("de") end end context "when language_code is an available locale" do let(:language) do - build(:alchemy_language, language_code: 'en') + build(:alchemy_language, language_code: "en") end - it 'sets the locale to language_code' do - is_expected.to eq('en') + it "sets the locale to language_code" do + is_expected.to eq("en") end end @@ -242,13 +242,13 @@ module Alchemy end end - describe 'presence_of_locale_file' do + describe "presence_of_locale_file" do context "when locale file is missing for selected language code" do let(:language) do - build(:alchemy_language, language_code: 'jp') + build(:alchemy_language, language_code: "jp") end - it 'adds errors to locale attribute' do + it "adds errors to locale attribute" do expect(language).to_not be_valid expect(language.errors).to have_key(:locale) end @@ -259,7 +259,7 @@ module Alchemy build(:alchemy_language, :klingon) end - it 'adds no errors to locale attribute' do + it "adds no errors to locale attribute" do expect(language).to be_valid expect(language.errors).to_not have_key(:locale) end @@ -267,9 +267,9 @@ module Alchemy end end - describe '#matching_locales' do + describe "#matching_locales" do let(:language) do - build(:alchemy_language, language_code: 'de') + build(:alchemy_language, language_code: "de") end subject do @@ -282,35 +282,35 @@ module Alchemy end end - it 'returns locales matching the language code' do + it "returns locales matching the language code" do is_expected.to eq [:de, :'de-at'] end - context 'when language code is not is an available locale' do + context "when language code is not is an available locale" do let(:language) do - build(:alchemy_language, language_code: 'jp') + build(:alchemy_language, language_code: "jp") end it { is_expected.to eq [] } end end - describe '#destroy' do + describe "#destroy" do let(:language) { create(:alchemy_language) } subject { language.destroy } - context 'without pages' do - it 'works' do + context "without pages" do + it "works" do subject expect(language.errors[:pages]).to be_empty end end - context 'with pages' do + context "with pages" do let!(:page) { create(:alchemy_page, language: language) } - it 'must not work' do + it "must not work" do subject expect(language.errors[:pages]).to_not be_empty end diff --git a/spec/models/alchemy/legacy_page_url_spec.rb b/spec/models/alchemy/legacy_page_url_spec.rb index 7cff5c84f6..793db0fc54 100644 --- a/spec/models/alchemy/legacy_page_url_spec.rb +++ b/spec/models/alchemy/legacy_page_url_spec.rb @@ -1,23 +1,23 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" describe Alchemy::LegacyPageUrl do let(:page) { build_stubbed(:alchemy_page) } let(:page_url_with_parameters) do - Alchemy::LegacyPageUrl.new(urlname: 'index.php?id=2', page: page) + Alchemy::LegacyPageUrl.new(urlname: "index.php?id=2", page: page) end let(:valid_page_url) do - Alchemy::LegacyPageUrl.new(urlname: 'my/0-work+is-nice_stuff', page: page) + Alchemy::LegacyPageUrl.new(urlname: "my/0-work+is-nice_stuff", page: page) end - it 'is only valid with correct urlname format' do + it "is only valid with correct urlname format" do expect(valid_page_url).to be_valid end - it 'is also valid with get parameters in urlname' do + it "is also valid with get parameters in urlname" do expect(page_url_with_parameters).to be_valid end end diff --git a/spec/models/alchemy/message_spec.rb b/spec/models/alchemy/message_spec.rb index d1bb1b78bc..078289ea46 100644 --- a/spec/models/alchemy/message_spec.rb +++ b/spec/models/alchemy/message_spec.rb @@ -1,15 +1,15 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" module Alchemy - Config.get(:mailer)['fields'].push('email_of_my_boss') - Config.get(:mailer)['validate_fields'].push('email_of_my_boss') + Config.get(:mailer)["fields"].push("email_of_my_boss") + Config.get(:mailer)["validate_fields"].push("email_of_my_boss") describe Message do let(:message) { Message.new } - describe '.config' do + describe ".config" do it "should return the mailer config" do expect(Config).to receive(:get).with(:mailer) Message.config @@ -17,7 +17,7 @@ module Alchemy end it "has attributes writers and getters for all fields defined in mailer config" do - Config.get(:mailer)['fields'].each do |field| + Config.get(:mailer)["fields"].each do |field| expect(message).to respond_to(field) expect(message).to respond_to("#{field}=") end @@ -26,16 +26,16 @@ module Alchemy context "validation of" do context "all fields defined in mailer config" do it "adds errors on that fields" do - Config.get(:mailer)['validate_fields'].each do |field| + Config.get(:mailer)["validate_fields"].each do |field| expect(message).to_not be_valid expect(message.errors[field].size).to eq(1) end end end - context 'field containing email in its name' do + context "field containing email in its name" do context "when field has a value" do - before { message.email_of_my_boss = 'wrong email format' } + before { message.email_of_my_boss = "wrong email format" } it "adds error notice (is invalid) to the field" do expect(message).to_not be_valid @@ -44,7 +44,7 @@ module Alchemy end context "when field is blank" do - before { message.email_of_my_boss = '' } + before { message.email_of_my_boss = "" } it "adds error notice (can't be blank) to the field" do expect(message).to_not be_valid diff --git a/spec/models/alchemy/node_spec.rb b/spec/models/alchemy/node_spec.rb index 1cbdc3b938..00b4600a3c 100644 --- a/spec/models/alchemy/node_spec.rb +++ b/spec/models/alchemy/node_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" module Alchemy describe Node do @@ -9,16 +9,16 @@ module Alchemy expect(build(:alchemy_node)).to be_valid end - describe '.language_root_nodes' do - context 'with no current language present' do + describe ".language_root_nodes" do + context "with no current language present" do before { expect(Language).to receive(:current) { nil } } it "raises error if no current language is set" do - expect { Node.language_root_nodes }.to raise_error('No language found') + expect { Node.language_root_nodes }.to raise_error("No language found") end end - context 'with current language present' do + context "with current language present" do let!(:root_node) { create(:alchemy_node) } let!(:child_node) { create(:alchemy_node, parent_id: root_node.id) } @@ -29,34 +29,34 @@ module Alchemy end end - describe '.available_menu_names' do + describe ".available_menu_names" do subject { described_class.available_menu_names } - it { is_expected.to contain_exactly('main_menu', 'footer_menu') } + it { is_expected.to contain_exactly("main_menu", "footer_menu") } end - describe '#url' do - it 'is valid with leading slash' do - expect(build(:alchemy_node, url: '/something')).to be_valid + describe "#url" do + it "is valid with leading slash" do + expect(build(:alchemy_node, url: "/something")).to be_valid end - it 'is invalid without leading slash' do - expect(build(:alchemy_node, url: 'something')).to be_invalid + it "is invalid without leading slash" do + expect(build(:alchemy_node, url: "something")).to be_invalid end - it 'is valid with leading protocol scheme' do - expect(build(:alchemy_node, url: 'i2+ts-z.app:widget.io')).to be_valid + it "is valid with leading protocol scheme" do + expect(build(:alchemy_node, url: "i2+ts-z.app:widget.io")).to be_valid end - context 'with page attached' do + context "with page attached" do let(:node) { create(:alchemy_node, :with_page) } it "returns the url from page" do expect(node.url).to eq("/#{node.page.urlname}") end - context 'and with url set' do - let(:node) { build(:alchemy_node, :with_page, url: 'http://google.com') } + context "and with url set" do + let(:node) { build(:alchemy_node, :with_page, url: "http://google.com") } it "still returns the url from the page" do expect(node.url).to eq("/#{node.page.urlname}") @@ -64,14 +64,14 @@ module Alchemy end end - context 'without page attached' do - let(:node) { build(:alchemy_node, url: 'http://google.com') } + context "without page attached" do + let(:node) { build(:alchemy_node, url: "http://google.com") } it "returns the url from url attribute" do - expect(node.url).to eq('http://google.com') + expect(node.url).to eq("http://google.com") end - context 'and without url set' do + context "and without url set" do let(:node) { build(:alchemy_node) } it do @@ -81,45 +81,45 @@ module Alchemy end end - describe '#name' do - context 'with page attached' do + describe "#name" do + context "with page attached" do let(:node) { build_stubbed(:alchemy_node, :with_page) } it "returns the name from page" do expect(node.name).to eq(node.page.name) end - context 'but with name set' do - let(:node) { build_stubbed(:alchemy_node, :with_page, name: 'Google') } + context "but with name set" do + let(:node) { build_stubbed(:alchemy_node, :with_page, name: "Google") } it "still returns the name from name attribute" do - expect(node.name).to eq('Google') + expect(node.name).to eq("Google") end end end - context 'without page attached' do - let(:node) { build_stubbed(:alchemy_node, name: 'Google') } + context "without page attached" do + let(:node) { build_stubbed(:alchemy_node, name: "Google") } it "returns the name from name attribute" do - expect(node.name).to eq('Google') + expect(node.name).to eq("Google") end end end - describe '#to_partial_path' do - let(:node) { build(:alchemy_node, name: 'Main Menu') } + describe "#to_partial_path" do + let(:node) { build(:alchemy_node, name: "Main Menu") } - it 'returns the path to the menu wrapper partial' do - expect(node.to_partial_path).to eq('alchemy/menus/main_menu/wrapper') + it "returns the path to the menu wrapper partial" do + expect(node.to_partial_path).to eq("alchemy/menus/main_menu/wrapper") end end - describe '#view_folder_name' do - let(:node) { build(:alchemy_node, name: 'Main Menu') } + describe "#view_folder_name" do + let(:node) { build(:alchemy_node, name: "Main Menu") } - it 'returns the path to the menu view folder' do - expect(node.view_folder_name).to eq('alchemy/menus/main_menu') + it "returns the path to the menu view folder" do + expect(node.view_folder_name).to eq("alchemy/menus/main_menu") end end end diff --git a/spec/models/alchemy/page/fixed_attributes_spec.rb b/spec/models/alchemy/page/fixed_attributes_spec.rb index a4b91d7b91..6685a648bc 100644 --- a/spec/models/alchemy/page/fixed_attributes_spec.rb +++ b/spec/models/alchemy/page/fixed_attributes_spec.rb @@ -1,59 +1,59 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" RSpec.describe Alchemy::Page::FixedAttributes do let(:page) { Alchemy::Page.new } let(:definition_with_fixed_attributes) do { - 'name' => 'foo', - 'fixed_attributes' => { - name: 'Home', + "name" => "foo", + "fixed_attributes" => { + name: "Home", }, } end let(:definition_without_fixed_attributes) do { - 'name' => 'foo', + "name" => "foo", } end - describe '#all' do - it 'is an alias to attributes' do + describe "#all" do + it "is an alias to attributes" do described_class.new(page).attributes == described_class.new(page).all end end - describe '#attributes' do + describe "#attributes" do subject(:attributes) do described_class.new(page).attributes end - it 'returns empty hash' do + it "returns empty hash" do expect(attributes).to eq({}) end - context 'with page having fixed_attributes defined' do + context "with page having fixed_attributes defined" do before do allow(page).to receive(:definition) do definition_with_fixed_attributes end end - it 'returns fixed attributes from page definition' do - expect(attributes).to eq({name: 'Home'}) + it "returns fixed attributes from page definition" do + expect(attributes).to eq({name: "Home"}) end end end - describe '#any?' do + describe "#any?" do subject(:any?) do described_class.new(page).any? end - context 'when fixed attributes are defined' do + context "when fixed attributes are defined" do before do allow(page).to receive(:definition) do definition_with_fixed_attributes @@ -63,7 +63,7 @@ it { is_expected.to eq(true) } end - context 'when fixed attributes are not defined' do + context "when fixed attributes are not defined" do before do allow(page).to receive(:definition) do definition_without_fixed_attributes @@ -73,29 +73,29 @@ it { is_expected.to eq(false) } end - it 'has a `present?` alias' do + it "has a `present?` alias" do described_class.new(page).any? == described_class.new(page).present? end end - describe '#fixed?' do + describe "#fixed?" do subject(:fixed?) do described_class.new(page).fixed?(name) end - context 'with nil given as name' do + context "with nil given as name" do let(:name) { nil } it { is_expected.to eq(false) } end - context 'with name not defined as fixed attribute' do - let(:name) { 'lol' } + context "with name not defined as fixed attribute" do + let(:name) { "lol" } it { is_expected.to eq(false) } end - context 'with name defined as fixed attribute' do + context "with name defined as fixed attribute" do let(:name) { :name } before do @@ -108,24 +108,24 @@ end end - describe '#[]' do + describe "#[]" do subject(:fetch) do described_class.new(page)[name] end - context 'with nil given as name' do + context "with nil given as name" do let(:name) { nil } it { is_expected.to be(nil) } end - context 'with name not defined as fixed attribute' do - let(:name) { 'lol' } + context "with name not defined as fixed attribute" do + let(:name) { "lol" } it { is_expected.to be(nil) } end - context 'with name defined as fixed attribute' do + context "with name defined as fixed attribute" do let(:name) { :name } before do @@ -134,8 +134,8 @@ end end - it 'returns the value' do - is_expected.to eq('Home') + it "returns the value" do + is_expected.to eq("Home") end end end diff --git a/spec/models/alchemy/page_spec.rb b/spec/models/alchemy/page_spec.rb index b3d7c06f40..845b2ae5cc 100644 --- a/spec/models/alchemy/page_spec.rb +++ b/spec/models/alchemy/page_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" module Alchemy describe Page do @@ -8,15 +8,15 @@ module Alchemy let(:language) { create(:alchemy_language, :english, default: true) } let(:klingon) { create(:alchemy_language, :klingon) } let(:language_root) { create(:alchemy_page, :language_root) } - let(:page) { mock_model(Page, page_layout: 'foo') } + let(:page) { mock_model(Page, page_layout: "foo") } let(:public_page) { create(:alchemy_page, :public) } - let(:news_page) { create(:alchemy_page, :public, page_layout: 'news', autogenerate_elements: true) } + let(:news_page) { create(:alchemy_page, :public, page_layout: "news", autogenerate_elements: true) } it { is_expected.to have_one(:site) } # Validations - context 'validations' do + context "validations" do context "Creating a normal content page" do let(:contentpage) { build(:alchemy_page) } let(:with_same_urlname) { create(:alchemy_page, urlname: "existing_twice") } @@ -45,11 +45,11 @@ module Alchemy expect(contentpage.errors[:parent_id].size).to eq(1) end - context 'with page having same urlname' do + context "with page having same urlname" do before { with_same_urlname } it "should not be valid" do - contentpage.urlname = 'existing_twice' + contentpage.urlname = "existing_twice" expect(contentpage).not_to be_valid end end @@ -63,20 +63,20 @@ module Alchemy end it "should only validate urlname dependent of parent" do - contentpage.urlname = 'existing_twice' + contentpage.urlname = "existing_twice" contentpage.parent_id = other_parent.id expect(contentpage).to be_valid end it "should validate urlname dependent of parent" do - contentpage.urlname = 'existing_twice' + contentpage.urlname = "existing_twice" expect(contentpage).not_to be_valid end end end context "creating the rootpage without parent_id and page_layout" do - let(:rootpage) { build(:alchemy_page, parent_id: nil, page_layout: nil, name: 'Rootpage') } + let(:rootpage) { build(:alchemy_page, parent_id: nil, page_layout: nil, name: "Rootpage") } before do Page.delete_all @@ -98,12 +98,12 @@ module Alchemy # Callbacks - context 'callbacks' do + context "callbacks" do let(:page) do - create(:alchemy_page, name: 'My Testpage', language: language, parent_id: language_root.id) + create(:alchemy_page, name: "My Testpage", language: language, parent_id: language_root.id) end - context 'before_save' do + context "before_save" do it "should not set the title automatically if the name changed but title is not blank" do page.name = "My Renaming Test" page.save; page.reload @@ -117,29 +117,29 @@ module Alchemy end end - context 'after_update' do + context "after_update" do context "urlname has changed" do it "should store legacy url" do - page.urlname = 'new-urlname' + page.urlname = "new-urlname" page.save! expect(page.legacy_urls).not_to be_empty - expect(page.legacy_urls.first.urlname).to eq('my-testpage') + expect(page.legacy_urls.first.urlname).to eq("my-testpage") end it "should not store legacy url twice for same urlname" do - page.urlname = 'new-urlname' + page.urlname = "new-urlname" page.save! - page.urlname = 'my-testpage' + page.urlname = "my-testpage" page.save! - page.urlname = 'another-urlname' + page.urlname = "another-urlname" page.save! - expect(page.legacy_urls.select { |u| u.urlname == 'my-testpage' }.size).to eq(1) + expect(page.legacy_urls.select { |u| u.urlname == "my-testpage" }.size).to eq(1) end end context "urlname has not changed" do it "should not store a legacy url" do - page.urlname = 'my-testpage' + page.urlname = "my-testpage" page.save! expect(page.legacy_urls).to be_empty end @@ -187,15 +187,15 @@ module Alchemy end end - context 'after_move' do - let(:parent_1) { create(:alchemy_page, name: 'Parent 1', visible: true) } - let(:parent_2) { create(:alchemy_page, name: 'Parent 2', visible: true) } - let(:page) { create(:alchemy_page, parent_id: parent_1.id, name: 'Page', visible: true) } + context "after_move" do + let(:parent_1) { create(:alchemy_page, name: "Parent 1", visible: true) } + let(:parent_2) { create(:alchemy_page, name: "Parent 2", visible: true) } + let(:page) { create(:alchemy_page, parent_id: parent_1.id, name: "Page", visible: true) } it "updates the urlname" do - expect(page.urlname).to eq('parent-1/page') + expect(page.urlname).to eq("parent-1/page") page.move_to_child_of parent_2 - expect(page.urlname).to eq('parent-2/page') + expect(page.urlname).to eq("parent-2/page") end end @@ -214,21 +214,21 @@ module Alchemy expect(page.elements).not_to be_empty end - context 'with elements already on the page' do + context "with elements already on the page" do before do - page.elements << create(:alchemy_element, name: 'header') + page.elements << create(:alchemy_element, name: "header") end it "does not autogenerate" do page.save! - expect(page.elements.select { |e| e.name == 'header' }.length).to eq(1) + expect(page.elements.select { |e| e.name == "header" }.length).to eq(1) end end context "with children getting restricted set to true" do before do page.save - @child1 = create(:alchemy_page, name: 'Child 1', parent_id: page.id) + @child1 = create(:alchemy_page, name: "Child 1", parent_id: page.id) page.reload page.restricted = true page.save @@ -244,7 +244,7 @@ module Alchemy before do page.save page.parent.update!(restricted: true) - @new_page = create(:alchemy_page, name: 'New Page', parent_id: page.id) + @new_page = create(:alchemy_page, name: "New Page", parent_id: page.id) end it "is also be restricted" do @@ -277,26 +277,26 @@ module Alchemy end context "after changing the page layout" do - let(:news_element) { news_page.elements.find_by(name: 'news') } + let(:news_element) { news_page.elements.find_by(name: "news") } it "all elements not allowed on this page should be trashed" do expect(news_page.trashed_elements).to be_empty - news_page.update(page_layout: 'standard') + news_page.update(page_layout: "standard") trashed = news_page.trashed_elements.pluck(:name) - expect(trashed).to eq(['news']) - expect(trashed).to_not include('article', 'header') + expect(trashed).to eq(["news"]) + expect(trashed).to_not include("article", "header") end it "should autogenerate elements" do - news_page.update(page_layout: 'contact') - expect(news_page.elements.pluck(:name)).to include('contactform') + news_page.update(page_layout: "contact") + expect(news_page.elements.pluck(:name)).to include("contactform") end end - context 'destruction' do + context "destruction" do let!(:page) { create(:alchemy_page, autogenerate_elements: true) } - it 'destroys elements along with itself' do + it "destroys elements along with itself" do expect { page.destroy! }.to change(Alchemy::Element, :count).from(3).to(0) end end @@ -304,14 +304,14 @@ module Alchemy # ClassMethods (a-z) - describe '.all_from_clipboard_for_select' do + describe ".all_from_clipboard_for_select" do context "with clipboard holding pages having non unique page layout" do it "should return the pages" do page_1 = create(:alchemy_page, language: language) - page_2 = create(:alchemy_page, language: language, name: 'Another page') + page_2 = create(:alchemy_page, language: language, name: "Another page") clipboard = [ - {'id' => page_1.id.to_s, 'action' => 'copy'}, - {'id' => page_2.id.to_s, 'action' => 'copy'}, + {"id" => page_1.id.to_s, "action" => "copy"}, + {"id" => page_2.id.to_s, "action" => "copy"}, ] expect(Page.all_from_clipboard_for_select(clipboard, language.id)).to include(page_1, page_2) end @@ -319,9 +319,9 @@ module Alchemy context "with clipboard holding a page having unique page layout" do it "should not return any pages" do - page_1 = create(:alchemy_page, language: language, page_layout: 'contact') + page_1 = create(:alchemy_page, language: language, page_layout: "contact") clipboard = [ - {'id' => page_1.id.to_s, 'action' => 'copy'}, + {"id" => page_1.id.to_s, "action" => "copy"}, ] expect(Page.all_from_clipboard_for_select(clipboard, language.id)).to eq([]) end @@ -329,32 +329,32 @@ module Alchemy context "with clipboard holding two pages. One having a unique page layout." do it "should return one page" do - page_1 = create(:alchemy_page, language: language, page_layout: 'standard') - page_2 = create(:alchemy_page, name: 'Another page', language: language, page_layout: 'contact') + page_1 = create(:alchemy_page, language: language, page_layout: "standard") + page_2 = create(:alchemy_page, name: "Another page", language: language, page_layout: "contact") clipboard = [ - {'id' => page_1.id.to_s, 'action' => 'copy'}, - {'id' => page_2.id.to_s, 'action' => 'copy'}, + {"id" => page_1.id.to_s, "action" => "copy"}, + {"id" => page_2.id.to_s, "action" => "copy"}, ] expect(Page.all_from_clipboard_for_select(clipboard, language.id)).to eq([page_1]) end end end - describe '.locked' do + describe ".locked" do it "should return 1 page that is blocked by a user at the moment" do - create(:alchemy_page, :public, :locked, name: 'First Public Child', parent_id: language_root.id, language: language) + create(:alchemy_page, :public, :locked, name: "First Public Child", parent_id: language_root.id, language: language) expect(Page.locked.size).to eq(1) end end - describe '.locked_by' do + describe ".locked_by" do let(:user) { double(:user, id: 1, class: DummyUser) } before do create(:alchemy_page, :public, :locked, locked_by: 53) # This page must not be part of the collection allow(user.class) .to receive(:primary_key) - .and_return('id') + .and_return("id") end it "should return the correct page collection blocked by a certain user" do @@ -362,13 +362,13 @@ module Alchemy expect(Page.locked_by(user).pluck(:id)).to eq([page.id]) end - context 'with user class having a different primary key' do + context "with user class having a different primary key" do let(:user) { double(:user, user_id: 123, class: DummyUser) } before do allow(user.class) .to receive(:primary_key) - .and_return('user_id') + .and_return("user_id") end it "should return the correct page collection blocked by a certain user" do @@ -378,7 +378,7 @@ module Alchemy end end - describe '.ancestors_for' do + describe ".ancestors_for" do let(:lang_root) { Page.language_root_for(Language.default.id) } let(:parent) { create(:alchemy_page, :public) } let(:page) { create(:alchemy_page, :public, parent_id: parent.id) } @@ -398,14 +398,14 @@ module Alchemy end end - describe '.contentpages' do + describe ".contentpages" do let!(:layoutroot) do Page.find_or_create_layout_root_for(klingon.id) end let!(:layoutpage) do create :alchemy_page, :public, { - name: 'layoutpage', + name: "layoutpage", layoutpage: true, parent_id: layoutroot.id, language: klingon, @@ -414,7 +414,7 @@ module Alchemy let!(:klingon_lang_root) do create :alchemy_page, :language_root, { - name: 'klingon_lang_root', + name: "klingon_lang_root", layoutpage: nil, language: klingon, } @@ -422,7 +422,7 @@ module Alchemy let!(:contentpage) do create :alchemy_page, :public, { - name: 'contentpage', + name: "contentpage", parent_id: language_root.id, language: language, } @@ -447,8 +447,8 @@ module Alchemy end end - describe '.copy' do - let(:page) { create(:alchemy_page, name: 'Source') } + describe ".copy" do + let(:page) { create(:alchemy_page, name: "Source") } subject { Page.copy(page) } @@ -456,16 +456,16 @@ module Alchemy expect(subject.name).to eq("#{page.name} (Copy)") end - context 'a visible page' do - let(:page) { create(:alchemy_page, name: 'Source', visible: true) } + context "a visible page" do + let(:page) { create(:alchemy_page, name: "Source", visible: true) } it "the copy should not be visible" do expect(subject.visible).to be(false) end end - context 'a public page' do - let(:page) { create(:alchemy_page, :public, name: 'Source', public_until: Time.current) } + context "a public page" do + let(:page) { create(:alchemy_page, :public, name: "Source", public_until: Time.current) } it "the copy should not be public" do expect(subject.public_on).to be(nil) @@ -473,9 +473,9 @@ module Alchemy end end - context 'a locked page' do + context "a locked page" do let(:page) do - create(:alchemy_page, :public, :locked, name: 'Source') + create(:alchemy_page, :public, :locked, name: "Source") end it "the copy should not be locked" do @@ -486,7 +486,7 @@ module Alchemy context "page with tags" do before do - page.tag_list = 'red, yellow' + page.tag_list = "red, yellow" page.save! end @@ -529,9 +529,9 @@ module Alchemy before do page = create(:alchemy_page) allow(page).to receive(:definition).and_return({ - 'name' => 'standard', - 'elements' => ['headline'], - 'autogenerate' => ['headline'], + "name" => "standard", + "elements" => ["headline"], + "autogenerate" => ["headline"], }) end @@ -541,76 +541,76 @@ module Alchemy end context "with different page name given" do - subject { Page.copy(page, {name: 'Different name'}) } + subject { Page.copy(page, {name: "Different name"}) } it "should take this name" do - expect(subject.name).to eq('Different name') + expect(subject.name).to eq("Different name") end end end - describe '.create' do + describe ".create" do context "before/after filter" do it "should automatically set the title from its name" do - page = create(:alchemy_page, name: 'My Testpage', language: language, parent_id: language_root.id) - expect(page.title).to eq('My Testpage') + page = create(:alchemy_page, name: "My Testpage", language: language, parent_id: language_root.id) + expect(page.title).to eq("My Testpage") end it "should get a webfriendly urlname" do - page = create(:alchemy_page, name: 'klingon$&stößel ', language: language, parent_id: language_root.id) - expect(page.urlname).to eq('klingon-stoessel') + page = create(:alchemy_page, name: "klingon$&stößel ", language: language, parent_id: language_root.id) + expect(page.urlname).to eq("klingon-stoessel") end context "with no name set" do it "should not set a urlname" do - page = Page.create(name: '', language: language, parent_id: language_root.id) + page = Page.create(name: "", language: language, parent_id: language_root.id) expect(page.urlname).to be_blank end end it "should generate a three letter urlname from two letter name" do - page = create(:alchemy_page, name: 'Au', language: language, parent_id: language_root.id) - expect(page.urlname).to eq('-au') + page = create(:alchemy_page, name: "Au", language: language, parent_id: language_root.id) + expect(page.urlname).to eq("-au") end it "should generate a three letter urlname from two letter name with umlaut" do - page = create(:alchemy_page, name: 'Aü', language: language, parent_id: language_root.id) - expect(page.urlname).to eq('aue') + page = create(:alchemy_page, name: "Aü", language: language, parent_id: language_root.id) + expect(page.urlname).to eq("aue") end it "should generate a three letter urlname from one letter name" do - page = create(:alchemy_page, name: 'A', language: language, parent_id: language_root.id) - expect(page.urlname).to eq('--a') + page = create(:alchemy_page, name: "A", language: language, parent_id: language_root.id) + expect(page.urlname).to eq("--a") end it "should add a user stamper" do - page = create(:alchemy_page, name: 'A', language: language, parent_id: language_root.id) - expect(page.class.stamper_class.to_s).to eq('DummyUser') + page = create(:alchemy_page, name: "A", language: language, parent_id: language_root.id) + expect(page.class.stamper_class.to_s).to eq("DummyUser") end context "with language given" do it "does not set the language from parent" do expect_any_instance_of(Page).not_to receive(:set_language_from_parent_or_default) - Page.create!(name: 'A', parent_id: language_root.id, page_layout: 'standard', language: language) + Page.create!(name: "A", parent_id: language_root.id, page_layout: "standard", language: language) end end context "with no language given" do it "sets the language from parent" do expect_any_instance_of(Page).to receive(:set_language_from_parent_or_default) - Page.create!(name: 'A', parent_id: language_root.id, page_layout: 'standard') + Page.create!(name: "A", parent_id: language_root.id, page_layout: "standard") end end end end - describe '.find_or_create_layout_root_for' do + describe ".find_or_create_layout_root_for" do subject { Page.find_or_create_layout_root_for(language.id) } let!(:root_page) { create(:alchemy_page, :root) } - let(:language) { create(:alchemy_language, name: 'English') } + let(:language) { create(:alchemy_language, name: "English") } - context 'if no layout root page for given language id is present' do + context "if no layout root page for given language id is present" do it "creates one" do expect { subject @@ -618,7 +618,7 @@ module Alchemy end end - context 'if layout root page for given language id is present' do + context "if layout root page for given language id is present" do let!(:page) do create :alchemy_page, layoutpage: true, @@ -632,55 +632,55 @@ module Alchemy end end - describe '.language_roots' do + describe ".language_roots" do it "should return 1 language_root" do - create(:alchemy_page, :public, name: 'First Public Child', parent_id: language_root.id, language: language) + create(:alchemy_page, :public, name: "First Public Child", parent_id: language_root.id, language: language) expect(Page.language_roots.size).to eq(1) end end - describe '.layoutpages' do + describe ".layoutpages" do it "should return 1 layoutpage" do - create(:alchemy_page, :public, layoutpage: true, name: 'Layoutpage', parent_id: rootpage.id, language: language) + create(:alchemy_page, :public, layoutpage: true, name: "Layoutpage", parent_id: rootpage.id, language: language) expect(Page.layoutpages.size).to eq(1) end end - describe '.not_locked' do + describe ".not_locked" do it "should return pages that are not blocked by a user at the moment" do - create(:alchemy_page, :public, :locked, name: 'First Public Child', parent_id: language_root.id, language: language) - create(:alchemy_page, :public, name: 'Second Public Child', parent_id: language_root.id, language: language) + create(:alchemy_page, :public, :locked, name: "First Public Child", parent_id: language_root.id, language: language) + create(:alchemy_page, :public, name: "Second Public Child", parent_id: language_root.id, language: language) expect(Page.not_locked.size).to eq(3) end end - describe '.not_restricted' do + describe ".not_restricted" do it "should return 2 accessible pages" do - create(:alchemy_page, :public, name: 'First Public Child', restricted: true, parent_id: language_root.id, language: language) + create(:alchemy_page, :public, name: "First Public Child", restricted: true, parent_id: language_root.id, language: language) expect(Page.not_restricted.size).to eq(2) end end - describe '.published' do + describe ".published" do subject(:published) { Page.published } let!(:public_one) do create :alchemy_page, :public, - name: 'First Public Child', + name: "First Public Child", parent_id: language_root.id, language: language end let!(:public_two) do create :alchemy_page, :public, - name: 'Second Public Child', + name: "Second Public Child", parent_id: language_root.id, language: language end let!(:non_public_page) do create :alchemy_page, - name: 'Non Public Child', + name: "Non Public Child", parent_id: language_root.id, language: language end @@ -692,30 +692,30 @@ module Alchemy end end - describe '.public_language_roots' do + describe ".public_language_roots" do it "should return pages that public language roots" do - create(:alchemy_page, :public, name: 'First Public Child', parent_id: language_root.id, language: language) + create(:alchemy_page, :public, name: "First Public Child", parent_id: language_root.id, language: language) expect(Page.public_language_roots.size).to eq(1) end end - describe '.restricted' do + describe ".restricted" do it "should return 1 restricted page" do - create(:alchemy_page, :public, name: 'First Public Child', restricted: true, parent_id: language_root.id, language: language) + create(:alchemy_page, :public, name: "First Public Child", restricted: true, parent_id: language_root.id, language: language) expect(Page.restricted.size).to eq(1) end end - describe '.root' do - context 'when root page is present' do + describe ".root" do + context "when root page is present" do let!(:root_page) { Page.root } - it 'returns root page' do + it "returns root page" do expect(Page.root).to eq(root_page) end end - context 'when no root page is present yet' do + context "when no root page is present yet" do before do Page.delete_all end @@ -728,89 +728,89 @@ module Alchemy end end - describe '.visible' do + describe ".visible" do it "should return 1 visible page" do - create(:alchemy_page, :public, name: 'First Public Child', visible: true, parent_id: language_root.id, language: language) + create(:alchemy_page, :public, name: "First Public Child", visible: true, parent_id: language_root.id, language: language) expect(Page.visible.size).to eq(1) end end # InstanceMethods (a-z) - describe '#available_element_definitions' do + describe "#available_element_definitions" do subject { page.available_element_definitions } let(:page) { create(:alchemy_page, :public) } it "returns all element definitions of available elements" do expect(subject).to be_an(Array) - expect(subject.collect { |e| e['name'] }).to include('header') + expect(subject.collect { |e| e["name"] }).to include("header") end context "with unique elements already on page" do let!(:element) { create(:alchemy_element, :unique, page: page) } it "does not return unique element definitions" do - expect(subject.collect { |e| e['name'] }).to include('article') - expect(subject.collect { |e| e['name'] }).not_to include('header') + expect(subject.collect { |e| e["name"] }).to include("article") + expect(subject.collect { |e| e["name"] }).not_to include("header") end end - context 'limited amount' do - let(:page) { create(:alchemy_page, page_layout: 'columns') } + context "limited amount" do + let(:page) { create(:alchemy_page, page_layout: "columns") } let!(:unique_element) do - create(:alchemy_element, :unique, name: 'unique_headline', page: page) + create(:alchemy_element, :unique, name: "unique_headline", page: page) end - let!(:element_1) { create(:alchemy_element, name: 'column_headline', page: page) } - let!(:element_2) { create(:alchemy_element, name: 'column_headline', page: page) } - let!(:element_3) { create(:alchemy_element, name: 'column_headline', page: page) } + let!(:element_1) { create(:alchemy_element, name: "column_headline", page: page) } + let!(:element_2) { create(:alchemy_element, name: "column_headline", page: page) } + let!(:element_3) { create(:alchemy_element, name: "column_headline", page: page) } before do allow(Element).to receive(:definitions).and_return([ { - 'name' => 'column_headline', - 'amount' => 3, - 'contents' => [{'name' => 'headline', 'type' => 'EssenceText'}], + "name" => "column_headline", + "amount" => 3, + "contents" => [{"name" => "headline", "type" => "EssenceText"}], }, { - 'name' => 'unique_headline', - 'unique' => true, - 'amount' => 3, - 'contents' => [{'name' => 'headline', 'type' => 'EssenceText'}], + "name" => "unique_headline", + "unique" => true, + "amount" => 3, + "contents" => [{"name" => "headline", "type" => "EssenceText"}], }, ]) allow(PageLayout).to receive(:get).and_return({ - 'name' => 'columns', - 'elements' => ['column_headline', 'unique_headline'], - 'autogenerate' => ['unique_headline', 'column_headline', 'column_headline', 'column_headline'], + "name" => "columns", + "elements" => ["column_headline", "unique_headline"], + "autogenerate" => ["unique_headline", "column_headline", "column_headline", "column_headline"], }) end it "should be readable" do - element = page.element_definitions_by_name('column_headline').first - expect(element['amount']).to be 3 + element = page.element_definitions_by_name("column_headline").first + expect(element["amount"]).to be 3 end it "should limit elements" do - expect(subject.collect { |e| e['name'] }).not_to include('column_headline') + expect(subject.collect { |e| e["name"] }).not_to include("column_headline") end it "should be ignored if unique" do - expect(subject.collect { |e| e['name'] }).not_to include('unique_headline') + expect(subject.collect { |e| e["name"] }).not_to include("unique_headline") end end end - describe '#available_elements_within_current_scope' do - let(:page) { create(:alchemy_page, page_layout: 'columns') } + describe "#available_elements_within_current_scope" do + let(:page) { create(:alchemy_page, page_layout: "columns") } let(:nestable_element) { create(:alchemy_element, :with_nestable_elements) } let(:currently_available_elements) { page.available_elements_within_current_scope(nestable_element) } context "When unique element is already nested" do before do - nestable_element.nested_elements << create(:alchemy_element, name: 'slide', unique: true, page: page) + nestable_element.nested_elements << create(:alchemy_element, name: "slide", unique: true, page: page) page.elements << nestable_element end @@ -821,12 +821,12 @@ module Alchemy context "When unique element has not be nested" do it "returns available elements" do - expect(currently_available_elements.collect { |e| e['name'] }).to include('slide') + expect(currently_available_elements.collect { |e| e["name"] }).to include("slide") end end end - describe '#available_element_names' do + describe "#available_element_names" do let(:page) { build_stubbed(:alchemy_page) } it "returns all names of elements that could be placed on current page" do @@ -834,7 +834,7 @@ module Alchemy end end - describe '#cache_key' do + describe "#cache_key" do let(:page) do stub_model(Page, updated_at: Time.current, published_at: Time.current - 1.week) end @@ -868,44 +868,44 @@ module Alchemy element_3.move_to_top end - it 'returns a ordered active record collection of elements on that page' do + it "returns a ordered active record collection of elements on that page" do expect(page.all_elements).to eq([element_3, element_1, element_2]) end - context 'with nestable elements' do + context "with nestable elements" do let!(:nestable_element) do create(:alchemy_element, page: page) end let!(:nested_element) do - create(:alchemy_element, name: 'slide', parent_element: nestable_element, page: page) + create(:alchemy_element, name: "slide", parent_element: nestable_element, page: page) end - it 'contains nested elements of an element' do + it "contains nested elements of an element" do expect(page.all_elements).to include(nested_element) end end - context 'with trashed elements' do + context "with trashed elements" do let(:trashed_element) { create(:alchemy_element, page: page).tap(&:trash!) } - it 'contains trashed elements' do + it "contains trashed elements" do expect(page.all_elements).to include(trashed_element) end end - context 'with hidden elements' do + context "with hidden elements" do let(:hidden_element) { create(:alchemy_element, page: page, public: false) } - it 'contains hidden elements' do + it "contains hidden elements" do expect(page.all_elements).to include(hidden_element) end end - context 'with fixed elements' do + context "with fixed elements" do let(:fixed_element) { create(:alchemy_element, page: page, fixed: true) } - it 'contains hidden elements' do + it "contains hidden elements" do expect(page.all_elements).to include(fixed_element) end end @@ -921,40 +921,40 @@ module Alchemy element_3.move_to_top end - it 'returns a ordered active record collection of elements on that page' do + it "returns a ordered active record collection of elements on that page" do expect(page.elements).to eq([element_3, element_1, element_2]) end - context 'with nestable elements' do + context "with nestable elements" do let(:nestable_element) { create(:alchemy_element, :with_nestable_elements) } before do - nestable_element.nested_elements << create(:alchemy_element, name: 'slide') + nestable_element.nested_elements << create(:alchemy_element, name: "slide") page.elements << nestable_element end - it 'does not contain nested elements of an element' do + it "does not contain nested elements of an element" do expect(nestable_element.nested_elements).to_not be_empty expect(page.elements).to_not include(nestable_element.nested_elements.first) end end - context 'with trashed elements' do + context "with trashed elements" do let(:trashed_element) { create(:alchemy_element, page: page) } before do trashed_element.trash! end - it 'does not contain trashed elements' do + it "does not contain trashed elements" do expect(page.elements).to_not include(trashed_element) end end - context 'with hidden elements' do + context "with hidden elements" do let(:hidden_element) { create(:alchemy_element, page: page, public: false) } - it 'does not contain hidden elements' do + it "does not contain hidden elements" do expect(page.elements).to_not include(hidden_element) end end @@ -970,74 +970,74 @@ module Alchemy element_3.move_to_top end - it 'returns a ordered active record collection of fixed elements on that page' do + it "returns a ordered active record collection of fixed elements on that page" do expect(page.fixed_elements).to eq([element_3, element_1, element_2]) end - context 'with trashed fixed elements' do + context "with trashed fixed elements" do let(:trashed_element) { create(:alchemy_element, page: page, fixed: true) } before do trashed_element.trash! end - it 'does not contain trashed fixed elements' do + it "does not contain trashed fixed elements" do expect(page.fixed_elements).to_not include(trashed_element) end end - context 'with hidden fixed elements' do + context "with hidden fixed elements" do let(:hidden_element) { create(:alchemy_element, page: page, fixed: true, public: false) } - it 'does not contain hidden fixed elements' do + it "does not contain hidden fixed elements" do expect(page.fixed_elements).to_not include(hidden_element) end end end - describe '#element_definitions' do + describe "#element_definitions" do let(:page) { build_stubbed(:alchemy_page) } subject { page.element_definitions } - before { expect(Element).to receive(:definitions).and_return([{'name' => 'article'}, {'name' => 'header'}]) } + before { expect(Element).to receive(:definitions).and_return([{"name" => "article"}, {"name" => "header"}]) } it "returns all element definitions that could be placed on current page" do - is_expected.to include({'name' => 'article'}) - is_expected.to include({'name' => 'header'}) + is_expected.to include({"name" => "article"}) + is_expected.to include({"name" => "header"}) end end - describe '#descendent_element_definitions' do - let(:page) { build_stubbed(:alchemy_page, page_layout: 'standard') } + describe "#descendent_element_definitions" do + let(:page) { build_stubbed(:alchemy_page, page_layout: "standard") } subject(:descendent_element_definitions) { page.descendent_element_definitions } it "returns all element definitions including the nestable element definitions" do - is_expected.to include(Alchemy::Element.definition_by_name('slider')) - is_expected.to include(Alchemy::Element.definition_by_name('slide')) + is_expected.to include(Alchemy::Element.definition_by_name("slider")) + is_expected.to include(Alchemy::Element.definition_by_name("slide")) end - context 'with nestable element being defined on multiple elements' do + context "with nestable element being defined on multiple elements" do before do expect(page).to receive(:element_definition_names) do %w(slider gallery) end expect(Element).to receive(:definitions).at_least(:once) do [ - {'name' => 'slider', 'nestable_elements' => %w(slide)}, - {'name' => 'gallery', 'nestable_elements' => %w(slide)}, - {'name' => 'slide'}, + {"name" => "slider", "nestable_elements" => %w(slide)}, + {"name" => "gallery", "nestable_elements" => %w(slide)}, + {"name" => "slide"}, ] end end - it 'only includes the definition once' do - slide_definitions = descendent_element_definitions.select { |d| d['name'] == 'slide' } + it "only includes the definition once" do + slide_definitions = descendent_element_definitions.select { |d| d["name"] == "slide" } expect(slide_definitions.length).to eq(1) end end end - describe '#element_definitions_by_name' do + describe "#element_definitions_by_name" do let(:page) { build_stubbed(:alchemy_page, :public) } context "with no name given" do @@ -1049,7 +1049,7 @@ module Alchemy context "with 'all' passed as name" do it "returns all element definitions" do expect(Element).to receive(:definitions) - page.element_definitions_by_name('all') + page.element_definitions_by_name("all") end end @@ -1061,7 +1061,7 @@ module Alchemy end end - describe '#element_definition_names' do + describe "#element_definition_names" do let(:page) { build_stubbed(:alchemy_page, :public) } subject { page.element_definition_names } @@ -1072,7 +1072,7 @@ module Alchemy context "with elements assigned in page definition" do let(:page_definition) do - {'elements' => %w(article)} + {"elements" => %w(article)} end it "returns an array of the page's element names" do @@ -1087,12 +1087,12 @@ module Alchemy end end - describe '#feed_elements' do - let(:news_element) { create(:alchemy_element, name: 'news', public: false, page: news_page) } + describe "#feed_elements" do + let(:news_element) { create(:alchemy_element, name: "news", public: false, page: news_page) } it "should return all published rss feed elements" do expect(news_page.feed_elements).not_to be_empty - expect(news_page.feed_elements).to eq(Element.where(name: 'news').available.to_a) + expect(news_page.feed_elements).to eq(Element.where(name: "news").available.to_a) end it "should not return unpublished rss feed elements" do @@ -1106,31 +1106,31 @@ module Alchemy end end - describe '#find_elements' do + describe "#find_elements" do subject { page.find_elements(options) } let(:page) { build(:alchemy_page) } let(:options) { {} } let(:finder) { instance_double(Alchemy::ElementsFinder) } - it 'passes self and all options to elements finder' do + it "passes self and all options to elements finder" do expect(Alchemy::ElementsFinder).to receive(:new).with(options) { finder } expect(finder).to receive(:elements).with(page: page) subject end - context 'with a custom finder given in options' do + context "with a custom finder given in options" do let(:options) do { finder: CustomNewsElementsFinder.new } end - it 'uses that to load elements to render' do - expect(subject.map(&:name)).to eq(['news']) + it "uses that to load elements to render" do + expect(subject.map(&:name)).to eq(["news"]) end end end - describe '#first_public_child' do + describe "#first_public_child" do before do create :alchemy_page, name: "First child", @@ -1156,10 +1156,10 @@ module Alchemy end end - context 'folding' do + context "folding" do let(:user) { create(:alchemy_dummy_user) } - describe '#fold!' do + describe "#fold!" do context "with folded status set to true" do it "should create a folded page for user" do public_page.fold!(user.id, true) @@ -1168,15 +1168,15 @@ module Alchemy end end - describe '#folded?' do + describe "#folded?" do let(:page) { Page.new } - context 'with user is a active record model' do + context "with user is a active record model" do before do allow(Alchemy.user_class).to receive(:'<').and_return(true) end - context 'if page is folded' do + context "if page is folded" do before do expect(page) .to receive(:folded_pages) @@ -1188,7 +1188,7 @@ module Alchemy end end - context 'if page is not folded' do + context "if page is not folded" do it "should return false" do expect(page.folded?(101_093)).to eq(false) end @@ -1197,7 +1197,7 @@ module Alchemy end end - describe '#get_language_root' do + describe "#get_language_root" do before { language_root } subject { public_page.get_language_root } @@ -1206,9 +1206,9 @@ module Alchemy end end - describe '#definition' do - context 'if the page layout could not be found in the definition file' do - let(:page) { build_stubbed(:alchemy_page, page_layout: 'notexisting') } + describe "#definition" do + context "if the page layout could not be found in the definition file" do + let(:page) { build_stubbed(:alchemy_page, page_layout: "notexisting") } it "it loggs a warning." do expect(Alchemy::Logger).to receive(:warn) @@ -1222,7 +1222,7 @@ module Alchemy context "for a language root page" do it "it returns the page layout definition as hash." do - expect(language_root.definition['name']).to eq('index') + expect(language_root.definition["name"]).to eq("index") end it "it returns an empty hash for root page." do @@ -1231,9 +1231,9 @@ module Alchemy end end - describe '#lock_to!' do + describe "#lock_to!" do let(:page) { create(:alchemy_page) } - let(:user) { mock_model('DummyUser') } + let(:user) { mock_model("DummyUser") } it "sets locked_at timestamp" do page.lock_to!(user) @@ -1253,11 +1253,11 @@ module Alchemy end end - describe '#copy_and_paste' do + describe "#copy_and_paste" do let(:source) { build_stubbed(:alchemy_page) } let(:new_parent) { build_stubbed(:alchemy_page) } let(:page_name) { "Pagename (pasted)" } - let(:copied_page) { mock_model('Page') } + let(:copied_page) { mock_model("Page") } subject { Page.copy_and_paste(source, new_parent, page_name) } @@ -1279,17 +1279,17 @@ module Alchemy context "if source page has children" do it "should also copy and paste the children" do allow(Page).to receive(:copy).and_return(copied_page) - allow(source).to receive(:children).and_return([mock_model('Page')]) + allow(source).to receive(:children).and_return([mock_model("Page")]) expect(source).to receive(:copy_children_to).with(copied_page) subject end end end - context 'previous and next.' do - let(:center_page) { create(:alchemy_page, :public, name: 'Center Page') } - let(:next_page) { create(:alchemy_page, :public, name: 'Next Page') } - let(:non_public_page) { create(:alchemy_page, name: 'Not public Page') } + context "previous and next." do + let(:center_page) { create(:alchemy_page, :public, name: "Center Page") } + let(:next_page) { create(:alchemy_page, :public, name: "Next Page") } + let(:non_public_page) { create(:alchemy_page, name: "Not public Page") } let(:restricted_page) { create(:alchemy_page, :restricted, :public) } before do @@ -1300,7 +1300,7 @@ module Alchemy next_page end - describe '#previous' do + describe "#previous" do it "should return the previous page on the same level" do expect(center_page.previous).to eq(public_page) expect(next_page.previous).to eq(center_page) @@ -1341,7 +1341,7 @@ module Alchemy end end - describe '#next' do + describe "#next" do it "should return the next page on the same level" do expect(center_page.next).to eq(next_page) end @@ -1354,10 +1354,10 @@ module Alchemy end end - describe '#editable_by?' do + describe "#editable_by?" do subject { page.editable_by?(user) } - let(:user) { mock_model('DummyUser') } + let(:user) { mock_model("DummyUser") } let(:page) { create(:alchemy_page) } context "template defines one alchemy role" do @@ -1365,14 +1365,14 @@ module Alchemy allow(page).to receive(:definition).and_return({"editable_by" => ["freelancer"]}) end - context 'user has matching alchemy role' do + context "user has matching alchemy role" do before do allow(user).to receive(:alchemy_roles).at_least(:once) { ["freelancer"] } end it { is_expected.to be(true) } end - context 'user has a different alchemy role' do + context "user has a different alchemy role" do before do allow(user).to receive(:alchemy_roles).at_least(:once) { ["editor"] } end @@ -1386,14 +1386,14 @@ module Alchemy allow(page).to receive(:definition).and_return({"editable_by" => ["freelancer", "admin"]}) end - context 'user has matching alchemy role' do + context "user has matching alchemy role" do before do allow(user).to receive(:alchemy_roles).at_least(:once) { ["freelancer", "member"] } end it { is_expected.to be(true) } end - context 'user has a different alchemy role' do + context "user has a different alchemy role" do before do allow(user).to receive(:alchemy_roles).at_least(:once) { ["editor", "leader"] } end @@ -1407,7 +1407,7 @@ module Alchemy allow(page).to receive(:definition).and_return({}) end - context 'user has matching alchemy role' do + context "user has matching alchemy role" do before do allow(user).to receive(:alchemy_roles).at_least(:once) { ["freelancer", "member"] } end @@ -1417,55 +1417,55 @@ module Alchemy end end - describe '#public_on' do + describe "#public_on" do subject(:public_on) { page.public_on } - context 'when is fixed attribute' do + context "when is fixed attribute" do let(:page) do - create(:alchemy_page, page_layout: 'readonly') + create(:alchemy_page, page_layout: "readonly") end - it 'returns the fixed value' do + it "returns the fixed value" do is_expected.to eq(nil) end end - context 'when is not fixed attribute' do + context "when is not fixed attribute" do let(:page) do - create(:alchemy_page, page_layout: 'standard', public_on: '2016-11-01') + create(:alchemy_page, page_layout: "standard", public_on: "2016-11-01") end - it 'returns value' do - is_expected.to eq('2016-11-01'.to_time(:utc)) + it "returns value" do + is_expected.to eq("2016-11-01".to_time(:utc)) end end end - describe '#public_until' do + describe "#public_until" do subject(:public_until) { page.public_until } - context 'when is fixed attribute' do + context "when is fixed attribute" do let(:page) do - create(:alchemy_page, page_layout: 'readonly') + create(:alchemy_page, page_layout: "readonly") end - it 'returns the fixed value' do + it "returns the fixed value" do is_expected.to eq(nil) end end - context 'when is not fixed attribute' do + context "when is not fixed attribute" do let(:page) do - create(:alchemy_page, page_layout: 'standard', public_until: '2016-11-01') + create(:alchemy_page, page_layout: "standard", public_until: "2016-11-01") end - it 'returns value' do - is_expected.to eq('2016-11-01'.to_time(:utc)) + it "returns value" do + is_expected.to eq("2016-11-01".to_time(:utc)) end end end - describe '#public?' do + describe "#public?" do subject { page.public? } context "when public_on is not set" do @@ -1513,7 +1513,7 @@ module Alchemy end end - describe '#publish!' do + describe "#publish!" do let(:current_time) { Time.current.change(usec: 0) } let(:page) do create(:alchemy_page, @@ -1584,8 +1584,8 @@ module Alchemy end end - describe '#set_language_from_parent_or_default' do - let(:default_language) { mock_model('Language', code: 'es') } + describe "#set_language_from_parent_or_default" do + let(:default_language) { mock_model("Language", code: "es") } let(:page) { Page.new } before { allow(page).to receive(:parent).and_return(parent) } @@ -1593,38 +1593,38 @@ module Alchemy subject { page } context "parent has a language" do - let(:parent) { mock_model('Page', language: default_language, language_id: default_language.id, language_code: default_language.code) } + let(:parent) { mock_model("Page", language: default_language, language_id: default_language.id, language_code: default_language.code) } before do page.send(:set_language_from_parent_or_default) end - describe '#language_id' do + describe "#language_id" do subject { super().language_id } it { is_expected.to eq(parent.language_id) } end end context "parent has no language" do - let(:parent) { mock_model('Page', language: nil, language_id: nil, language_code: nil) } + let(:parent) { mock_model("Page", language: nil, language_id: nil, language_code: nil) } before do allow(Language).to receive(:default).and_return(default_language) page.send(:set_language_from_parent_or_default) end - describe '#language_id' do + describe "#language_id" do subject { super().language_id } it { is_expected.to eq(default_language.id) } end end end - describe '#taggable?' do + describe "#taggable?" do context "definition has 'taggable' key with true value" do it "should return true" do page = build(:alchemy_page) - allow(page).to receive(:definition).and_return({'name' => 'standard', 'taggable' => true}) + allow(page).to receive(:definition).and_return({"name" => "standard", "taggable" => true}) expect(page.taggable?).to be_truthy end end @@ -1632,7 +1632,7 @@ module Alchemy context "definition has 'taggable' key with foo value" do it "should return false" do page = build(:alchemy_page) - allow(page).to receive(:definition).and_return({'name' => 'standard', 'taggable' => 'foo'}) + allow(page).to receive(:definition).and_return({"name" => "standard", "taggable" => "foo"}) expect(page.taggable?).to be_falsey end end @@ -1640,13 +1640,13 @@ module Alchemy context "definition has no 'taggable' key" do it "should return false" do page = build(:alchemy_page) - allow(page).to receive(:definition).and_return({'name' => 'standard'}) + allow(page).to receive(:definition).and_return({"name" => "standard"}) expect(page.taggable?).to be_falsey end end end - describe '#unlock!' do + describe "#unlock!" do let(:page) { create(:alchemy_page, :locked) } before do @@ -1676,12 +1676,12 @@ module Alchemy end end - context 'urlname updating' do - let(:parentparent) { create(:alchemy_page, name: 'parentparent', visible: true) } - let(:parent) { create(:alchemy_page, parent_id: parentparent.id, name: 'parent', visible: true) } - let(:page) { create(:alchemy_page, parent_id: parent.id, name: 'page', visible: true) } - let(:invisible) { create(:alchemy_page, parent_id: page.id, name: 'invisible', visible: false) } - let(:contact) { create(:alchemy_page, parent_id: invisible.id, name: 'contact', visible: true) } + context "urlname updating" do + let(:parentparent) { create(:alchemy_page, name: "parentparent", visible: true) } + let(:parent) { create(:alchemy_page, parent_id: parentparent.id, name: "parent", visible: true) } + let(:page) { create(:alchemy_page, parent_id: parent.id, name: "page", visible: true) } + let(:invisible) { create(:alchemy_page, parent_id: page.id, name: "invisible", visible: false) } + let(:contact) { create(:alchemy_page, parent_id: invisible.id, name: "contact", visible: true) } let(:language_root) { parentparent.parent } context "with activated url_nesting" do @@ -1690,12 +1690,12 @@ module Alchemy end it "should store all parents urlnames delimited by slash" do - expect(page.urlname).to eq('parentparent/parent/page') + expect(page.urlname).to eq("parentparent/parent/page") end it "should not include the root page" do - Page.root.update_column(:urlname, 'root') - language_root.update(urlname: 'new-urlname') + Page.root.update_column(:urlname, "root") + language_root.update(urlname: "new-urlname") expect(language_root.urlname).not_to match(/root/) end @@ -1722,17 +1722,17 @@ module Alchemy context "after changing page's urlname" do it "updates urlnames of descendants" do page - parentparent.urlname = 'new-urlname' + parentparent.urlname = "new-urlname" parentparent.save! page.reload - expect(page.urlname).to eq('new-urlname/parent/page') + expect(page.urlname).to eq("new-urlname/parent/page") end it "should create a legacy url" do - allow(page).to receive(:slug).and_return('foo') + allow(page).to receive(:slug).and_return("foo") page.update_urlname! expect(page.legacy_urls).not_to be_empty - expect(page.legacy_urls.pluck(:urlname)).to include('parentparent/parent/page') + expect(page.legacy_urls.pluck(:urlname)).to include("parentparent/parent/page") end end @@ -1742,7 +1742,7 @@ module Alchemy parentparent.visible = false parentparent.save! page.reload - expect(page.urlname).to eq('parent/page') + expect(page.urlname).to eq("parent/page") end end end @@ -1753,7 +1753,7 @@ module Alchemy end it "should only store my urlname" do - expect(page.urlname).to eq('page') + expect(page.urlname).to eq("page") end end end @@ -1822,56 +1822,56 @@ module Alchemy end end - describe '#cache_page?' do + describe "#cache_page?" do let(:page) { Page.new(page_layout: "news") } subject { page.cache_page? } before { Rails.application.config.action_controller.perform_caching = true } after { Rails.application.config.action_controller.perform_caching = false } - it 'returns true when everthing is alright' do + it "returns true when everthing is alright" do expect(subject).to be true end - it 'returns false when the Rails app does not perform caching' do + it "returns false when the Rails app does not perform caching" do Rails.application.config.action_controller.perform_caching = false expect(subject).to be false end - it 'returns false when caching is deactivated in the Alchemy config' do + it "returns false when caching is deactivated in the Alchemy config" do stub_alchemy_config(:cache_pages, false) expect(subject).to be false end - it 'returns false when the page layout is set to cache = false' do - page_layout = PageLayout.get('news') - page_layout['cache'] = false - allow(PageLayout).to receive(:get).with('news').and_return(page_layout) + it "returns false when the page layout is set to cache = false" do + page_layout = PageLayout.get("news") + page_layout["cache"] = false + allow(PageLayout).to receive(:get).with("news").and_return(page_layout) expect(subject).to be false end - it 'returns false when the page layout is set to searchresults = true' do - page_layout = PageLayout.get('news') - page_layout['searchresults'] = true - allow(PageLayout).to receive(:get).with('news').and_return(page_layout) + it "returns false when the page layout is set to searchresults = true" do + page_layout = PageLayout.get("news") + page_layout["searchresults"] = true + allow(PageLayout).to receive(:get).with("news").and_return(page_layout) expect(subject).to be false end end - describe '#slug' do + describe "#slug" do context "with parents path saved in urlname" do - let(:page) { build(:alchemy_page, urlname: 'root/parent/my-name') } + let(:page) { build(:alchemy_page, urlname: "root/parent/my-name") } it "should return the last part of the urlname" do - expect(page.slug).to eq('my-name') + expect(page.slug).to eq("my-name") end end context "with single urlname" do - let(:page) { build(:alchemy_page, urlname: 'my-name') } + let(:page) { build(:alchemy_page, urlname: "my-name") } it "should return the last part of the urlname" do - expect(page.slug).to eq('my-name') + expect(page.slug).to eq("my-name") end end @@ -1884,40 +1884,40 @@ module Alchemy end end - context 'page status methods' do + context "page status methods" do let(:page) do build(:alchemy_page, :public, visible: true, restricted: false) end - describe '#status' do + describe "#status" do it "returns a combined status hash" do expect(page.status).to eq({public: true, visible: true, restricted: false, locked: false}) end end - describe '#status_title' do + describe "#status_title" do it "returns a translated status string for public status" do - expect(page.status_title(:public)).to eq('Page is published.') + expect(page.status_title(:public)).to eq("Page is published.") end it "returns a translated status string for visible status" do - expect(page.status_title(:visible)).to eq('Page is visible in navigation.') + expect(page.status_title(:visible)).to eq("Page is visible in navigation.") end it "returns a translated status string for locked status" do - expect(page.status_title(:locked)).to eq('') + expect(page.status_title(:locked)).to eq("") end it "returns a translated status string for restricted status" do - expect(page.status_title(:restricted)).to eq('Page is not restricted.') + expect(page.status_title(:restricted)).to eq("Page is not restricted.") end end end - describe 'page editor methods' do + describe "page editor methods" do let(:user) { create(:alchemy_dummy_user, :as_editor) } - describe '#creator' do + describe "#creator" do let(:page) { Page.new(creator: user) } subject(:creator) { page.creator } @@ -1925,13 +1925,13 @@ module Alchemy is_expected.to eq(user) end - it 'uses the primary key defined on user class' do + it "uses the primary key defined on user class" do expect(Alchemy.user_class).to receive(:primary_key).at_least(:once) { :id } subject end end - describe '#updater' do + describe "#updater" do let(:page) { Page.new(updater: user) } subject(:updater) { page.updater } @@ -1939,13 +1939,13 @@ module Alchemy is_expected.to eq(user) end - it 'uses the primary key defined on user class' do + it "uses the primary key defined on user class" do expect(Alchemy.user_class).to receive(:primary_key).at_least(:once) { :id } subject end end - describe '#locker' do + describe "#locker" do let(:page) { Page.new(locker: user) } subject(:locker) { page.locker } @@ -1953,96 +1953,96 @@ module Alchemy is_expected.to eq(user) end - it 'uses the primary key defined on user class' do + it "uses the primary key defined on user class" do expect(Alchemy.user_class).to receive(:primary_key).at_least(:once) { :id } subject end end - context 'with user class having a name accessor' do - let(:user) { build(:alchemy_dummy_user, name: 'Paul Page') } + context "with user class having a name accessor" do + let(:user) { build(:alchemy_dummy_user, name: "Paul Page") } - describe '#creator_name' do + describe "#creator_name" do let(:page) { Page.new(creator: user) } it "returns the name of the creator" do - expect(page.creator_name).to eq('Paul Page') + expect(page.creator_name).to eq("Paul Page") end end - describe '#updater_name' do + describe "#updater_name" do let(:page) { Page.new(updater: user) } it "returns the name of the updater" do - expect(page.updater_name).to eq('Paul Page') + expect(page.updater_name).to eq("Paul Page") end end - describe '#locker_name' do + describe "#locker_name" do let(:page) { Page.new(locker: user) } it "returns the name of the current page editor" do - expect(page.locker_name).to eq('Paul Page') + expect(page.locker_name).to eq("Paul Page") end end end - context 'with user class returning nil for name' do + context "with user class returning nil for name" do let(:user) { Alchemy.user_class.new } - describe '#creator_name' do + describe "#creator_name" do let(:page) { Page.new(creator: user) } it "returns unknown" do - expect(page.creator_name).to eq('unknown') + expect(page.creator_name).to eq("unknown") end end - describe '#updater_name' do + describe "#updater_name" do let(:page) { Page.new(updater: user) } it "returns unknown" do - expect(page.updater_name).to eq('unknown') + expect(page.updater_name).to eq("unknown") end end - describe '#locker_name' do + describe "#locker_name" do let(:page) { Page.new(locker: user) } it "returns unknown" do - expect(page.locker_name).to eq('unknown') + expect(page.locker_name).to eq("unknown") end end end - context 'with user class not responding to name' do + context "with user class not responding to name" do let(:user) { Alchemy.user_class.new } before do expect(user).to receive(:respond_to?).with(:name) { false } end - describe '#creator_name' do + describe "#creator_name" do let(:page) { Page.new(creator: user) } it "returns unknown" do - expect(page.creator_name).to eq('unknown') + expect(page.creator_name).to eq("unknown") end end - describe '#updater_name' do + describe "#updater_name" do let(:page) { Page.new(updater: user) } it "returns unknown" do - expect(page.updater_name).to eq('unknown') + expect(page.updater_name).to eq("unknown") end end - describe '#locker_name' do + describe "#locker_name" do let(:page) { Page.new(locker: user) } it "returns unknown" do - expect(page.locker_name).to eq('unknown') + expect(page.locker_name).to eq("unknown") end end end @@ -2052,16 +2052,16 @@ module Alchemy let(:subject) { Page.new } end - describe '#layout_partial_name' do - let(:page) { Page.new(page_layout: 'Standard Page') } + describe "#layout_partial_name" do + let(:page) { Page.new(page_layout: "Standard Page") } it "returns a partial renderer compatible name" do - expect(page.layout_partial_name).to eq('standard_page') + expect(page.layout_partial_name).to eq("standard_page") end end - describe '#published_at' do - context 'with published_at date set' do + describe "#published_at" do + context "with published_at date set" do let(:published_at) { 3.days.ago } let(:page) { build_stubbed(:alchemy_page, published_at: published_at) } @@ -2070,7 +2070,7 @@ module Alchemy end end - context 'with published_at is nil' do + context "with published_at is nil" do let(:updated_at) { 3.days.ago } let(:page) { build_stubbed(:alchemy_page, published_at: nil, updated_at: updated_at) } @@ -2085,31 +2085,31 @@ module Alchemy let!(:expanded_element) do create :alchemy_element, :with_contents, - name: 'article', + name: "article", page: page, folded: false end let!(:folded_element) do create :alchemy_element, :with_contents, - name: 'article', + name: "article", page: page, folded: true end subject(:richtext_contents_ids) { page.richtext_contents_ids } - it 'returns content ids for all expanded elements that have tinymce enabled' do + it "returns content ids for all expanded elements that have tinymce enabled" do expanded_rtf_contents = expanded_element.contents.essence_richtexts expect(richtext_contents_ids).to eq(expanded_rtf_contents.pluck(:id)) folded_rtf_content = folded_element.contents.essence_richtexts.first expect(richtext_contents_ids).to_not include(folded_rtf_content.id) end - context 'with nested elements' do + context "with nested elements" do let!(:nested_expanded_element) do create :alchemy_element, :with_contents, - name: 'article', + name: "article", page: page, parent_element: expanded_element, folded: false @@ -2117,13 +2117,13 @@ module Alchemy let!(:nested_folded_element) do create :alchemy_element, :with_contents, - name: 'article', + name: "article", page: page, parent_element: folded_element, folded: true end - it 'returns content ids for all expanded nested elements that have tinymce enabled' do + it "returns content ids for all expanded nested elements that have tinymce enabled" do expanded_rtf_contents = expanded_element.contents.essence_richtexts nested_expanded_rtf_contents = nested_expanded_element.contents.essence_richtexts rtf_content_ids = expanded_rtf_contents.pluck(:id) + @@ -2137,92 +2137,92 @@ module Alchemy end end - describe '#fixed_attributes' do + describe "#fixed_attributes" do let(:page) { Alchemy::Page.new } - it 'holds an instance of FixedAttributes' do + it "holds an instance of FixedAttributes" do expect(page.fixed_attributes).to be_a(Alchemy::Page::FixedAttributes) end end - describe '#attribute_fixed?' do + describe "#attribute_fixed?" do let(:page) { Alchemy::Page.new } - it 'delegates to instance of FixedAttributes' do - expect_any_instance_of(Alchemy::Page::FixedAttributes).to receive(:fixed?).with('yolo') - page.attribute_fixed?('yolo') + it "delegates to instance of FixedAttributes" do + expect_any_instance_of(Alchemy::Page::FixedAttributes).to receive(:fixed?).with("yolo") + page.attribute_fixed?("yolo") end end - describe '#set_fixed_attributes' do - context 'when fixed attributes are defined' do - let(:page) { create(:alchemy_page, page_layout: 'readonly') } + describe "#set_fixed_attributes" do + context "when fixed attributes are defined" do + let(:page) { create(:alchemy_page, page_layout: "readonly") } - it 'sets them before each save' do + it "sets them before each save" do expect { - page.update(name: 'Foo') + page.update(name: "Foo") }.to_not change { page.name } end end end - describe '#attach_to_menu!' do + describe "#attach_to_menu!" do let(:page) { create(:alchemy_page) } - context 'if menu_id is set' do + context "if menu_id is set" do let(:root_node) { create(:alchemy_node) } before do page.menu_id = root_node.id end - context 'and no nodes are present yet' do - it 'attaches to menu' do + context "and no nodes are present yet" do + it "attaches to menu" do expect { page.save }.to change { page.nodes.count }.from(0).to(1) end end - context 'and nodes are already present' do + context "and nodes are already present" do let!(:page_node) { create(:alchemy_node, page: page) } - it 'does not attach to menu' do + it "does not attach to menu" do expect { page.save }.not_to change { page.nodes.count } end end end - context 'if menu_id is not set' do - it 'does not attach to menu' do + context "if menu_id is not set" do + it "does not attach to menu" do expect { page.save }.not_to change { page.nodes.count } end end - context 'if menu_id is empty' do - it 'does not raise error' do + context "if menu_id is empty" do + it "does not raise error" do page.menu_id = "" expect { page.save }.not_to raise_error end end end - describe '#nodes' do + describe "#nodes" do let(:page) { create(:alchemy_page) } let(:node) { create(:alchemy_node, page: page, updated_at: 1.hour.ago) } - it 'returns all nodes the page is attached to' do + it "returns all nodes the page is attached to" do expect(page.nodes).to include(node) end - describe 'after page updates' do - it 'touches all nodes' do + describe "after page updates" do + it "touches all nodes" do expect { - page.update(name: 'foo') + page.update(name: "foo") }.to change { node.reload.updated_at } end end end - describe '#menus' do + describe "#menus" do let(:page) { create(:alchemy_page) } let(:root_node) { create(:alchemy_node) } @@ -2230,7 +2230,7 @@ module Alchemy create(:alchemy_node, page: page, parent: root_node) end - it 'returns all root nodes the page is attached to' do + it "returns all root nodes the page is attached to" do expect(page.menus).to include(root_node) end end diff --git a/spec/models/alchemy/picture_spec.rb b/spec/models/alchemy/picture_spec.rb index 4d252c49b2..2ec4c98033 100644 --- a/spec/models/alchemy/picture_spec.rb +++ b/spec/models/alchemy/picture_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" module Alchemy describe Picture do @@ -9,7 +9,7 @@ module Alchemy end let :image_file do - File.new(File.expand_path('../../fixtures/image.png', __dir__)) + File.new(File.expand_path("../../fixtures/image.png", __dir__)) end let(:picture) { Picture.new } @@ -25,86 +25,86 @@ module Alchemy end it "is valid with capitalized image file extension" do - image_file = File.new(File.expand_path('../../fixtures/image2.PNG', __dir__)) + image_file = File.new(File.expand_path("../../fixtures/image2.PNG", __dir__)) picture = Picture.new(image_file: image_file) expect(picture).to be_valid end it "is valid with jpeg image file extension" do - image_file = File.new(File.expand_path('../../fixtures/image3.jpeg', __dir__)) + image_file = File.new(File.expand_path("../../fixtures/image3.jpeg", __dir__)) picture = Picture.new(image_file: image_file) expect(picture).to be_valid end - context 'with enabled preprocess_image_resize config option' do + context "with enabled preprocess_image_resize config option" do let(:image_file) do - File.new(File.expand_path('../../fixtures/80x60.png', __dir__)) + File.new(File.expand_path("../../fixtures/80x60.png", __dir__)) end - context 'with > geometry string' do + context "with > geometry string" do before do allow(Config).to receive(:get) do |arg| if arg == :preprocess_image_resize - '10x10>' + "10x10>" end end end it "it resizes the image after upload" do picture = Picture.new(image_file: image_file) - expect(picture.image_file.data[0x10..0x18].unpack('NN')).to eq([10, 8]) + expect(picture.image_file.data[0x10..0x18].unpack("NN")).to eq([10, 8]) end end - context 'without > geometry string' do + context "without > geometry string" do before do allow(Config).to receive(:get) do |arg| if arg == :preprocess_image_resize - '10x10' + "10x10" end end end it "it resizes the image after upload" do picture = Picture.new(image_file: image_file) - expect(picture.image_file.data[0x10..0x18].unpack('NN')).to eq([10, 8]) + expect(picture.image_file.data[0x10..0x18].unpack("NN")).to eq([10, 8]) end end end - describe '#suffix' do + describe "#suffix" do it "should return the suffix of original filename" do - pic = stub_model(Picture, image_file_name: 'kitten.JPG') - allow(pic).to receive(:image_file).and_return(OpenStruct.new({ext: 'jpg'})) + pic = stub_model(Picture, image_file_name: "kitten.JPG") + allow(pic).to receive(:image_file).and_return(OpenStruct.new({ext: "jpg"})) expect(pic.suffix).to eq("jpg") end context "image has no suffix" do it "should return empty string" do - pic = stub_model(Picture, image_file_name: 'kitten') - allow(pic).to receive(:image_file).and_return(OpenStruct.new({ext: ''})) + pic = stub_model(Picture, image_file_name: "kitten") + allow(pic).to receive(:image_file).and_return(OpenStruct.new({ext: ""})) expect(pic.suffix).to eq("") end end end - describe '#humanized_name' do + describe "#humanized_name" do it "should return a humanized version of original filename" do - pic = stub_model(Picture, image_file_name: 'cute_kitten.JPG') - allow(pic).to receive(:image_file).and_return(OpenStruct.new({ext: 'jpg'})) + pic = stub_model(Picture, image_file_name: "cute_kitten.JPG") + allow(pic).to receive(:image_file).and_return(OpenStruct.new({ext: "jpg"})) expect(pic.humanized_name).to eq("cute kitten") end it "should not remove incidents of suffix from filename" do - pic = stub_model(Picture, image_file_name: 'cute_kitten_mo.jpgi.JPG') - allow(pic).to receive(:image_file).and_return(OpenStruct.new({ext: 'jpg'})) + pic = stub_model(Picture, image_file_name: "cute_kitten_mo.jpgi.JPG") + allow(pic).to receive(:image_file).and_return(OpenStruct.new({ext: "jpg"})) expect(pic.humanized_name).to eq("cute kitten mo.jpgi") expect(pic.humanized_name).not_to eq("cute kitten moi") end context "image has no suffix" do it "should return humanized name" do - pic = stub_model(Picture, image_file_name: 'cute_kitten') + pic = stub_model(Picture, image_file_name: "cute_kitten") allow(pic).to receive(:suffix).and_return("") expect(pic.humanized_name).to eq("cute kitten") end @@ -119,7 +119,7 @@ module Alchemy let(:query) { double(result: pictures) } let(:per_page) { nil } - it 'orders the result by name' do + it "orders the result by name" do expect(pictures).to receive(:order).with(:name) search_by end @@ -148,66 +148,66 @@ module Alchemy context "when params[:filter] is set" do let(:params) do - ActionController::Parameters.new(filter: 'recent') + ActionController::Parameters.new(filter: "recent") end it "filters the pictures collection by the given filter string" do expect(pictures).to \ - receive(:filtered_by).with(params['filter']).and_call_original + receive(:filtered_by).with(params["filter"]).and_call_original search_by end end context "when params[:tagged_with] is set" do let(:params) do - ActionController::Parameters.new(tagged_with: 'kitten') + ActionController::Parameters.new(tagged_with: "kitten") end it "filters the records by tags" do expect(pictures).to \ - receive(:tagged_with).with(params['tagged_with']).and_call_original + receive(:tagged_with).with(params["tagged_with"]).and_call_original search_by end end end - describe '.filtered_by' do + describe ".filtered_by" do let(:picture) { build_stubbed(:alchemy_picture) } context "with 'recent' as argument" do - it 'should call the .recent scope' do + it "should call the .recent scope" do expect(Picture).to receive(:recent).and_return(picture) - expect(Picture.filtered_by('recent')).to eq(picture) + expect(Picture.filtered_by("recent")).to eq(picture) end end context "with 'last_upload' as argument" do - it 'should call the .last_upload scope' do + it "should call the .last_upload scope" do expect(Picture).to receive(:last_upload).and_return(picture) - expect(Picture.filtered_by('last_upload')).to eq(picture) + expect(Picture.filtered_by("last_upload")).to eq(picture) end end context "with 'without_tag' as argument" do - it 'should call the .without_tag scope' do + it "should call the .without_tag scope" do expect(Picture).to receive(:without_tag).and_return(picture) - expect(Picture.filtered_by('without_tag')).to eq(picture) + expect(Picture.filtered_by("without_tag")).to eq(picture) end end context "with no argument" do - it 'should return the scoped collection' do + it "should return the scoped collection" do expect(Picture).to receive(:all).and_return(picture) - expect(Picture.filtered_by('')).to eq(picture) + expect(Picture.filtered_by("")).to eq(picture) end end end - describe '.last_upload' do + describe ".last_upload" do it "should return all pictures that have the same upload-hash as the most recent picture" do - other_upload = Picture.create!(image_file: image_file, upload_hash: '456') - same_upload = Picture.create!(image_file: image_file, upload_hash: '123') - most_recent = Picture.create!(image_file: image_file, upload_hash: '123') + other_upload = Picture.create!(image_file: image_file, upload_hash: "456") + same_upload = Picture.create!(image_file: image_file, upload_hash: "123") + most_recent = Picture.create!(image_file: image_file, upload_hash: "123") expect(Picture.last_upload).to include(most_recent) expect(Picture.last_upload).to include(same_upload) @@ -217,7 +217,7 @@ module Alchemy end end - describe '.recent' do + describe ".recent" do before do now = Time.current @recent = Picture.create!(image_file: image_file) @@ -235,7 +235,7 @@ module Alchemy end end - describe '#destroy' do + describe "#destroy" do context "a picture that is assigned in an essence" do let(:essence_picture) { EssencePicture.create } let(:picture) { create :alchemy_picture } @@ -253,46 +253,46 @@ module Alchemy describe "#image_file_dimensions" do it "should return the width and height in the format of '1024x768'" do picture.image_file = image_file - expect(picture.image_file_dimensions).to eq('1x1') + expect(picture.image_file_dimensions).to eq("1x1") end end - describe '#update_name_and_tag_list!' do + describe "#update_name_and_tag_list!" do let(:picture) { Picture.new(image_file: image_file) } before { allow(picture).to receive(:save!).and_return(true) } it "updates tag_list" do - expect(picture).to receive(:tag_list=).with('Foo') - picture.update_name_and_tag_list!({pictures_tag_list: 'Foo'}) + expect(picture).to receive(:tag_list=).with("Foo") + picture.update_name_and_tag_list!({pictures_tag_list: "Foo"}) end - context 'name is present' do + context "name is present" do it "updates name" do - expect(picture).to receive(:name=).with('Foo') - picture.update_name_and_tag_list!({pictures_name: 'Foo'}) + expect(picture).to receive(:name=).with("Foo") + picture.update_name_and_tag_list!({pictures_name: "Foo"}) end end - context 'name is not present' do + context "name is not present" do it "does not update name" do - expect(picture).not_to receive(:name=).with('Foo') - picture.update_name_and_tag_list!({pictures_name: ''}) + expect(picture).not_to receive(:name=).with("Foo") + picture.update_name_and_tag_list!({pictures_name: ""}) end end end - describe '#urlname' do + describe "#urlname" do subject { picture.urlname } - let(:picture) { build_stubbed(:alchemy_picture, name: 'Cute kittens.jpg') } + let(:picture) { build_stubbed(:alchemy_picture, name: "Cute kittens.jpg") } it "returns a uri escaped name" do - is_expected.to eq('Cute+kittens') + is_expected.to eq("Cute+kittens") end - context 'with blank name' do - let(:picture) { build_stubbed(:alchemy_picture, name: '') } + context "with blank name" do + let(:picture) { build_stubbed(:alchemy_picture, name: "") } it "returns generic name" do is_expected.to eq("image_#{picture.id}") @@ -300,10 +300,10 @@ module Alchemy end end - describe '#to_jq_upload' do + describe "#to_jq_upload" do subject { picture.to_jq_upload } - let(:picture) { build_stubbed(:alchemy_picture, image_file_name: 'cute-kittens.jpg', image_file_size: 1024) } + let(:picture) { build_stubbed(:alchemy_picture, image_file_name: "cute-kittens.jpg", image_file_size: 1024) } it "returns a hash containing data for jquery fileuploader" do is_expected.to be_an_instance_of(Hash) @@ -311,7 +311,7 @@ module Alchemy is_expected.to include(size: picture.image_file_size) end - context 'with error' do + context "with error" do let(:picture) { build_stubbed(:alchemy_picture) } before do @@ -320,18 +320,18 @@ module Alchemy it "returns hash with error message" do is_expected.to be_an_instance_of(Hash) - is_expected.to include(error: 'stupid_cats') + is_expected.to include(error: "stupid_cats") end end end - describe '#restricted?' do + describe "#restricted?" do subject { picture.restricted? } let(:picture) { build_stubbed(:alchemy_picture) } - context 'is assigned on pages' do - context 'that are all restricted' do + context "is assigned on pages" do + context "that are all restricted" do before do expect(picture).to receive(:pages).at_least(:once).and_return double( not_restricted: double(blank?: true), @@ -342,7 +342,7 @@ module Alchemy it { is_expected.to be_truthy } end - context 'that are not all restricted' do + context "that are not all restricted" do before do expect(picture).to receive(:pages).at_least(:once).and_return double( not_restricted: double(blank?: false), @@ -354,7 +354,7 @@ module Alchemy end end - context 'is not assigned on any page' do + context "is not assigned on any page" do before do expect(picture).to receive(:pages).and_return double(any?: false) end @@ -363,9 +363,9 @@ module Alchemy end end - context 'navigating records' do - let!(:picture1) { create(:alchemy_picture, name: 'abc') } - let!(:picture2) { create(:alchemy_picture, name: 'def') } + context "navigating records" do + let!(:picture1) { create(:alchemy_picture, name: "abc") } + let!(:picture2) { create(:alchemy_picture, name: "def") } describe "#previous" do subject { picture2.previous } @@ -384,48 +384,48 @@ module Alchemy end end - describe '#default_render_format' do + describe "#default_render_format" do let(:picture) do - Picture.new(image_file_format: 'png') + Picture.new(image_file_format: "png") end subject { picture.default_render_format } context "when `image_output_format` is configured to `original`" do before do - stub_alchemy_config(:image_output_format, 'original') + stub_alchemy_config(:image_output_format, "original") end it "returns the image file format" do - is_expected.to eq('png') + is_expected.to eq("png") end end context "when `image_output_format` is configured to an image format" do before do - stub_alchemy_config(:image_output_format, 'jpg') + stub_alchemy_config(:image_output_format, "jpg") end context "and the format is a convertible format" do it "returns the configured file format." do - is_expected.to eq('jpg') + is_expected.to eq("jpg") end end context "but the format is not a convertible format" do before do - allow(picture).to receive(:image_file_format) { 'svg' } + allow(picture).to receive(:image_file_format) { "svg" } end it "returns the original file format." do - is_expected.to eq('svg') + is_expected.to eq("svg") end end end end - describe 'after update' do - context 'assigned to contents' do + describe "after update" do + context "assigned to contents" do let(:picture) { create(:alchemy_picture) } let(:content) do @@ -438,7 +438,7 @@ module Alchemy content.essence.update(picture: picture) end - it 'touches contents' do + it "touches contents" do expect { picture.save }.to change { content.reload.updated_at } end end diff --git a/spec/models/alchemy/picture_url_spec.rb b/spec/models/alchemy/picture_url_spec.rb index 0d4ae9a9fe..b14d97688e 100644 --- a/spec/models/alchemy/picture_url_spec.rb +++ b/spec/models/alchemy/picture_url_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" module Alchemy describe "Picture::Url" do @@ -8,14 +8,14 @@ module Alchemy # Helper to dedoce a hashed dragonfly job def decode_dragon_fly_job(url) - job = url.split('/')[2] + job = url.split("/")[2] Dragonfly::Serializer.json_b64_decode(job) end let(:image) do fixture_file_upload( - File.expand_path('../../fixtures/500x500.png', __dir__), - 'image/png', + File.expand_path("../../fixtures/500x500.png", __dir__), + "image/png", ) end @@ -28,7 +28,7 @@ def decode_dragon_fly_job(url) let(:options) { Hash.new } - it 'includes the name and render format' do + it "includes the name and render format" do expect(url).to match /\/#{picture.name}\.#{picture.default_render_format}/ end @@ -37,7 +37,7 @@ def decode_dragon_fly_job(url) expect(picture).to receive(:image_file) { nil } end - it 'returns nil' do + it "returns nil" do expect(url).to be_nil end @@ -49,10 +49,10 @@ def decode_dragon_fly_job(url) context "when a size is passed in" do let(:options) do - {size: '120x160'} + {size: "120x160"} end - it 'resizes the image without upsampling it' do + it "resizes the image without upsampling it" do job = decode_dragon_fly_job(url) expect(job[1]).to include("120x160>") end @@ -60,7 +60,7 @@ def decode_dragon_fly_job(url) context "but upsample set to true" do let(:options) do { - size: '1600x1200', + size: "1600x1200", upsample: true, } end @@ -74,7 +74,7 @@ def decode_dragon_fly_job(url) context "and crop is set to true" do let(:options) do { - size: '160x120', + size: "160x120", crop: true, } end @@ -87,9 +87,9 @@ def decode_dragon_fly_job(url) context "and crop_from and crop_size is passed in" do let(:options) do { - crop_size: '123x44', - crop_from: '0x0', - size: '160x120', + crop_size: "123x44", + crop_from: "0x0", + size: "160x120", crop: true, } end @@ -104,7 +104,7 @@ def decode_dragon_fly_job(url) context "and crop is set to false" do let(:options) do { - size: '160x120', + size: "160x120", crop: false, } end @@ -117,9 +117,9 @@ def decode_dragon_fly_job(url) context "and crop_from and crop_size is passed in" do let(:options) do { - crop_size: '123x44', - crop_from: '0x0', - size: '160x120', + crop_size: "123x44", + crop_from: "0x0", + size: "160x120", crop: false, } end @@ -133,7 +133,7 @@ def decode_dragon_fly_job(url) context "with no height given" do let(:options) do - {size: '40'} + {size: "40"} end it "resizes the image inferring the height" do @@ -144,7 +144,7 @@ def decode_dragon_fly_job(url) context "with no width given" do let(:options) do - {size: 'x30'} + {size: "x30"} end it "resizes the image inferring the width" do @@ -155,7 +155,7 @@ def decode_dragon_fly_job(url) end context "when no size is passed in" do - it 'does not resize the image' do + it "does not resize the image" do # only the fetch step should be present expect(decode_dragon_fly_job(url).size).to eq(1) end @@ -163,10 +163,10 @@ def decode_dragon_fly_job(url) context "when a different format is requested" do let(:options) do - {format: 'gif'} + {format: "gif"} end - it 'converts the format' do + it "converts the format" do job = decode_dragon_fly_job(url) expect(job[1]).to include("encode", "gif") end @@ -174,30 +174,30 @@ def decode_dragon_fly_job(url) context "but image has not a convertible format (svg)" do let(:image) do fixture_file_upload( - File.expand_path('../../fixtures/icon.svg', __dir__), - 'image/svg+xml', + File.expand_path("../../fixtures/icon.svg", __dir__), + "image/svg+xml", ) end - it 'does not convert the picture format' do + it "does not convert the picture format" do # only the fetch step should be present expect(decode_dragon_fly_job(url).size).to eq(1) end end - context 'for an animated gif' do + context "for an animated gif" do let(:options) do - {format: 'png'} + {format: "png"} end let(:image) do fixture_file_upload( - File.expand_path('../../fixtures/animated.gif', __dir__), - 'image/gif', + File.expand_path("../../fixtures/animated.gif", __dir__), + "image/gif", ) end - it 'flattens the image.' do + it "flattens the image." do job = decode_dragon_fly_job(url) expect(job[1]).to include("-flatten") end @@ -206,7 +206,7 @@ def decode_dragon_fly_job(url) context "requesting a not allowed format" do let(:options) do - {format: 'zip'} + {format: "zip"} end it "returns nil" do @@ -221,20 +221,20 @@ def decode_dragon_fly_job(url) context "when jpg format is requested" do let(:options) do - {format: 'jpg'} + {format: "jpg"} end - it 'sets the default quality' do + it "sets the default quality" do job = decode_dragon_fly_job(url) expect(job[1]).to include("-quality 85") end context "and quality is passed" do let(:options) do - {format: 'jpg', quality: '30'} + {format: "jpg", quality: "30"} end - it 'sets the quality' do + it "sets the quality" do job = decode_dragon_fly_job(url) expect(job[1]).to include("-quality 30") end diff --git a/spec/models/alchemy/site_spec.rb b/spec/models/alchemy/site_spec.rb index a87c066d8d..994d426a80 100644 --- a/spec/models/alchemy/site_spec.rb +++ b/spec/models/alchemy/site_spec.rb @@ -1,24 +1,24 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" module Alchemy describe Site do let(:site) { create(:alchemy_site) } - describe 'new instances' do - subject { build(:alchemy_site, host: 'bla.com') } + describe "new instances" do + subject { build(:alchemy_site, host: "bla.com") } - it 'should start out with no languages' do + it "should start out with no languages" do expect(subject.languages).to be_empty end - context 'when being saved' do - context 'when it already has a language' do + context "when being saved" do + context "when it already has a language" do let(:language) { build(:alchemy_language, site: nil) } before { subject.languages << language } - it 'should not create any additional languages' do + it "should not create any additional languages" do expect(subject.languages).to eq([language]) expect { subject.save! }. @@ -28,10 +28,10 @@ module Alchemy end end - describe '.default' do + describe ".default" do subject { Site.default } - context 'when no default site is present' do + context "when no default site is present" do before do Site.delete_all end @@ -39,56 +39,56 @@ module Alchemy it { is_expected.to be nil } end - context 'when default site is present' do - it 'returns it' do + context "when default site is present" do + it "returns it" do is_expected.to eq(Site.default) end end end - describe '.find_for_host' do + describe ".find_for_host" do # No need to create a default site, as it has already been added through the seeds. # But let's add some more: # let(:default_site) { Site.default } - let!(:magiclabs_site) { create(:alchemy_site, host: 'www.magiclabs.de', aliases: 'magiclabs.de magiclabs.com www.magiclabs.com') } + let!(:magiclabs_site) { create(:alchemy_site, host: "www.magiclabs.de", aliases: "magiclabs.de magiclabs.com www.magiclabs.com") } subject { Site.find_for_host(host) } context "when the request doesn't match anything" do - let(:host) { 'oogabooga.com' } + let(:host) { "oogabooga.com" } it { is_expected.to eq(default_site) } end context "when the request matches a site's host field" do - let(:host) { 'www.magiclabs.de' } + let(:host) { "www.magiclabs.de" } it { is_expected.to eq(magiclabs_site) } end context "when the request matches one of the site's aliases" do - let(:host) { 'magiclabs.com' } + let(:host) { "magiclabs.com" } it { is_expected.to eq(magiclabs_site) } end context "when the request matches the site's first alias" do - let(:host) { 'magiclabs.de' } + let(:host) { "magiclabs.de" } it { is_expected.to eq(magiclabs_site) } end context "when the request matches the site's last alias" do - let(:host) { 'www.magiclabs.com' } + let(:host) { "www.magiclabs.com" } it { is_expected.to eq(magiclabs_site) } end context "when the request host matches only part of a site's aliases" do - let(:host) { 'labs.com' } + let(:host) { "labs.com" } it { is_expected.to eq(default_site) } end end - describe '.current' do - context 'when set to nil' do - let!(:site) { create(:alchemy_site, host: 'example.com') } + describe ".current" do + context "when set to nil" do + let!(:site) { create(:alchemy_site, host: "example.com") } before do Site.current = nil @@ -101,14 +101,14 @@ module Alchemy end end - describe '.definitions' do + describe ".definitions" do # To prevent memoization across specs before { Site.instance_variable_set("@definitions", nil) } subject { Site.definitions } context "with file present" do - let(:definitions) { [{'name' => 'lala'}] } + let(:definitions) { [{"name" => "lala"}] } before { expect(YAML).to receive(:load_file).and_return(definitions) } it { is_expected.to eq(definitions) } end @@ -123,50 +123,50 @@ module Alchemy end end - describe '#current?' do + describe "#current?" do let!(:default_site) { create(:alchemy_site, :default) } let!(:another_site) do - create(:alchemy_site, name: 'Another Site', host: 'another.com') + create(:alchemy_site, name: "Another Site", host: "another.com") end subject { default_site.current? } - context 'when Site.current is set to the same site' do + context "when Site.current is set to the same site" do before { Site.current = default_site } it { is_expected.to be(true) } end - context 'when Site.current is set to nil' do + context "when Site.current is set to nil" do before { Site.current = nil } it { is_expected.to be(true) } end - context 'when Site.current is set to a different site' do + context "when Site.current is set to a different site" do before { Site.current = another_site } it { is_expected.to be(false) } end end - describe '#to_partial_path' do - let(:site) { Site.new(name: 'My custom site') } + describe "#to_partial_path" do + let(:site) { Site.new(name: "My custom site") } it "returns the path to partial" do expect(site.to_partial_path).to eq("alchemy/site_layouts/my_custom_site") end end - describe '#partial_name' do - let(:site) { Site.new(name: 'My custom site') } + describe "#partial_name" do + let(:site) { Site.new(name: "My custom site") } it "returns the name for layout partial" do expect(site.partial_name).to eq("my_custom_site") end end - describe '#definition' do - let(:site) { Site.new(name: 'My custom site') } - let(:definitions) { [{'name' => 'my_custom_site', 'page_layouts' => %w(standard)}] } + describe "#definition" do + let(:site) { Site.new(name: "My custom site") } + let(:definitions) { [{"name" => "my_custom_site", "page_layouts" => %w(standard)}] } it "returns layout definition from site_layouts.yml file" do allow(Site).to receive(:definitions).and_return(definitions) @@ -174,7 +174,7 @@ module Alchemy end end - describe '#default_language' do + describe "#default_language" do let!(:default_language) do create(:alchemy_language, default: true, site: site) end @@ -187,29 +187,29 @@ module Alchemy site.default_language end - it 'returns the default language of site', :aggregate_failures do + it "returns the default language of site", :aggregate_failures do expect(site.languages.count).to eq(2) expect(site_default_language).to eq(default_language) expect(site_default_language).to_not eq(other_language) end end - describe '#destroy' do + describe "#destroy" do let(:site) { create(:alchemy_site) } subject { site.destroy } - context 'without languages' do - it 'works' do + context "without languages" do + it "works" do subject expect(site.errors[:languages]).to be_empty end end - context 'with languages' do + context "with languages" do let!(:language) { create(:alchemy_language, site: site) } - it 'must not work' do + it "must not work" do subject expect(site.errors[:languages]).to_not be_empty end diff --git a/spec/models/alchemy/tag_spec.rb b/spec/models/alchemy/tag_spec.rb index b063e1256c..34f3784074 100644 --- a/spec/models/alchemy/tag_spec.rb +++ b/spec/models/alchemy/tag_spec.rb @@ -1,18 +1,18 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" module Alchemy describe Tag do - describe '.replace' do + describe ".replace" do let(:picture) { Picture.new } let(:element) { Element.new } - let(:tag) { Tag.new(name: 'red') } - let(:new_tag) { Tag.new(name: 'green') } + let(:tag) { Tag.new(name: "red") } + let(:new_tag) { Tag.new(name: "green") } before do - allow(picture).to receive(:tag_list).and_return(['red']) - allow(element).to receive(:tag_list).and_return(['red']) + allow(picture).to receive(:tag_list).and_return(["red"]) + allow(element).to receive(:tag_list).and_return(["red"]) allow(picture).to receive(:save).and_return(true) allow(element).to receive(:save).and_return(true) allow(tag).to receive(:taggings).and_return([ @@ -23,8 +23,8 @@ module Alchemy it "should replace given tag with new one on all models tagged with tag" do Tag.replace(tag, new_tag) - expect(picture.tag_list).to eq(['green']) - expect(element.tag_list).to eq(['green']) + expect(picture.tag_list).to eq(["green"]) + expect(element.tag_list).to eq(["green"]) end end end diff --git a/spec/models/dummy_model_spec.rb b/spec/models/dummy_model_spec.rb index 53ebf9435d..b495b4913c 100644 --- a/spec/models/dummy_model_spec.rb +++ b/spec/models/dummy_model_spec.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" -describe 'A User-defined Essence' do +describe "A User-defined Essence" do describe DummyModel do it_behaves_like "an essence" do let(:essence) { DummyModel.new } diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 20d558b3ed..7aa12f3f82 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -1,33 +1,33 @@ # frozen_string_literal: true -require_relative './spec_helper' +require_relative "./spec_helper" # Configure Rails Environment ENV["RAILS_ENV"] = "test" -require_relative('dummy/config/environment.rb') - -require 'capybara/rails' -require 'capybara-screenshot/rspec' -require 'rails-controller-testing' -require 'rspec-activemodel-mocks' -require 'rspec/rails' -require 'webdrivers/chromedriver' -require 'shoulda-matchers' - -require 'alchemy/seeder' -require 'alchemy/test_support/config_stubbing' -require 'alchemy/test_support/essence_shared_examples' -require 'alchemy/test_support/integration_helpers' -require 'alchemy/test_support/factories' -require 'alchemy/test_support/shared_contexts' -require 'alchemy/test_support/shared_uploader_examples' - -require_relative 'factories' +require_relative("dummy/config/environment.rb") + +require "capybara/rails" +require "capybara-screenshot/rspec" +require "rails-controller-testing" +require "rspec-activemodel-mocks" +require "rspec/rails" +require "webdrivers/chromedriver" +require "shoulda-matchers" + +require "alchemy/seeder" +require "alchemy/test_support/config_stubbing" +require "alchemy/test_support/essence_shared_examples" +require "alchemy/test_support/integration_helpers" +require "alchemy/test_support/factories" +require "alchemy/test_support/shared_contexts" +require "alchemy/test_support/shared_uploader_examples" + +require_relative "factories" require_relative "support/hint_examples.rb" require_relative "support/transformation_examples.rb" require_relative "support/capybara_helpers.rb" -require_relative 'support/custom_news_elements_finder' +require_relative "support/custom_news_elements_finder" ActionMailer::Base.delivery_method = :test ActionMailer::Base.perform_deliveries = true @@ -46,11 +46,11 @@ Capybara.register_driver :selenium_chrome_headless do |app| Capybara::Selenium::Driver.load_selenium browser_options = ::Selenium::WebDriver::Chrome::Options.new.tap do |opts| - opts.args << '--headless' - opts.args << '--disable-gpu' if Gem.win_platform? + opts.args << "--headless" + opts.args << "--disable-gpu" if Gem.win_platform? # Workaround https://bugs.chromium.org/p/chromedriver/issues/detail?id=2650&q=load&sort=-id&colspec=ID%20Status%20Pri%20Owner%20Summary - opts.args << '--disable-site-isolation-trials' - opts.args << '--window-size=1280,800' + opts.args << "--disable-site-isolation-trials" + opts.args << "--window-size=1280,800" end Capybara::Selenium::Driver.new(app, browser: :chrome, options: browser_options) end diff --git a/spec/requests/alchemy/admin/contents_controller_spec.rb b/spec/requests/alchemy/admin/contents_controller_spec.rb index dd02b716c5..7086dbda2b 100644 --- a/spec/requests/alchemy/admin/contents_controller_spec.rb +++ b/spec/requests/alchemy/admin/contents_controller_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" module Alchemy describe Admin::ContentsController do @@ -8,13 +8,13 @@ module Alchemy authorize_user(:as_admin) end - context 'with element_id parameter' do - describe '#create' do - let(:element) { create(:alchemy_element, name: 'headline') } + context "with element_id parameter" do + describe "#create" do + let(:element) { create(:alchemy_element, name: "headline") } it "creates a content from name" do expect { - post admin_contents_path(content: {element_id: element.id, name: 'headline'}, format: :js) + post admin_contents_path(content: {element_id: element.id, name: "headline"}, format: :js) }.to change { Alchemy::Content.count }.by(1) end end diff --git a/spec/requests/alchemy/admin/pages_controller_spec.rb b/spec/requests/alchemy/admin/pages_controller_spec.rb index db0b86fadc..1bb2cd073e 100644 --- a/spec/requests/alchemy/admin/pages_controller_spec.rb +++ b/spec/requests/alchemy/admin/pages_controller_spec.rb @@ -1,35 +1,35 @@ # frozen_string_literal: true -require 'ostruct' -require 'rails_helper' +require "ostruct" +require "rails_helper" module Alchemy describe Admin::PagesController do let(:site) { create(:alchemy_site, host: "*") } - context 'a guest' do - it 'can not access page tree' do + context "a guest" do + it "can not access page tree" do get admin_pages_path expect(request).to redirect_to(Alchemy.login_path) end end - context 'a member' do + context "a member" do before { authorize_user(build(:alchemy_dummy_user)) } - it 'can not access page tree' do + it "can not access page tree" do get admin_pages_path expect(request).to redirect_to(root_path) end end - context 'with logged in editor user' do + context "with logged in editor user" do let(:user) { build(:alchemy_dummy_user, :as_editor) } before { authorize_user(user) } - describe '#index' do - context 'with existing language root page' do + describe "#index" do + context "with existing language root page" do let!(:language_root) { create(:alchemy_page, :language_root) } it "assigns @page_root variable" do @@ -38,17 +38,17 @@ module Alchemy end end - context 'without current language present' do + context "without current language present" do it "it redirects to the languages admin" do get admin_pages_path expect(response).to redirect_to(alchemy.admin_languages_path) end end - context 'with current language present' do + context "with current language present" do let!(:language) { create(:alchemy_language, site: site) } - context 'without language root page' do + context "without language root page" do before do expect_any_instance_of(Language).to receive(:root_page).and_return(nil) end @@ -60,11 +60,11 @@ module Alchemy context "with multiple sites" do let!(:site_1_language_2) do - create(:alchemy_language, code: 'fr') + create(:alchemy_language, code: "fr") end let!(:site_2) do - create(:alchemy_site, host: 'another-one.com') + create(:alchemy_site, host: "another-one.com") end let(:site_2_language) do @@ -86,54 +86,54 @@ module Alchemy end end - describe '#tree' do + describe "#tree" do let(:user) { create(:alchemy_dummy_user, :as_editor) } - let(:page_1) { create(:alchemy_page, visible: true, name: 'one') } - let(:page_2) { create(:alchemy_page, visible: true, name: 'two', parent_id: page_1.id) } - let(:page_3) { create(:alchemy_page, visible: true, name: 'three', parent_id: page_2.id) } + let(:page_1) { create(:alchemy_page, visible: true, name: "one") } + let(:page_2) { create(:alchemy_page, visible: true, name: "two", parent_id: page_1.id) } + let(:page_3) { create(:alchemy_page, visible: true, name: "three", parent_id: page_2.id) } let!(:pages) { [page_1, page_2, page_3] } subject :get_tree do - get tree_admin_pages_path(id: page_1.id, full: 'true') + get tree_admin_pages_path(id: page_1.id, full: "true") end - it 'returns a tree as JSON' do + it "returns a tree as JSON" do get_tree expect(response.status).to eq(200) - expect(response.media_type).to eq('application/json') + expect(response.media_type).to eq("application/json") result = JSON.parse(response.body) - expect(result).to have_key('pages') - expect(result['pages'].count).to eq(1) + expect(result).to have_key("pages") + expect(result["pages"].count).to eq(1) - page = result['pages'].first + page = result["pages"].first - expect(page).to have_key('id') - expect(page['id']).to eq(page_1.id) - expect(page).to have_key('name') - expect(page['name']).to eq(page_1.name) - expect(page).to have_key('children') - expect(page['children'].count).to eq(1) + expect(page).to have_key("id") + expect(page["id"]).to eq(page_1.id) + expect(page).to have_key("name") + expect(page["name"]).to eq(page_1.name) + expect(page).to have_key("children") + expect(page["children"].count).to eq(1) - page = page['children'].first + page = page["children"].first - expect(page).to have_key('id') - expect(page['id']).to eq(page_2.id) - expect(page).to have_key('name') - expect(page['name']).to eq(page_2.name) - expect(page).to have_key('children') - expect(page['children'].count).to eq(1) + expect(page).to have_key("id") + expect(page["id"]).to eq(page_2.id) + expect(page).to have_key("name") + expect(page["name"]).to eq(page_2.name) + expect(page).to have_key("children") + expect(page["children"].count).to eq(1) - page = page['children'].first + page = page["children"].first - expect(page).to have_key('id') - expect(page['id']).to eq(page_3.id) - expect(page).to have_key('name') - expect(page['name']).to eq(page_3.name) - expect(page).to have_key('children') - expect(page['children'].count).to eq(0) + expect(page).to have_key("id") + expect(page["id"]).to eq(page_3.id) + expect(page).to have_key("name") + expect(page["name"]).to eq(page_3.name) + expect(page).to have_key("children") + expect(page["children"].count).to eq(0) end context "when branch is folded" do @@ -141,16 +141,16 @@ module Alchemy page_2.fold!(user.id, true) end - it 'does not return a branch that is folded' do - get tree_admin_pages_path(id: page_1.id, full: 'false') + it "does not return a branch that is folded" do + get tree_admin_pages_path(id: page_1.id, full: "false") expect(response.status).to eq(200) - expect(response.media_type).to eq('application/json') + expect(response.media_type).to eq("application/json") result = JSON.parse(response.body) - page = result['pages'].first['children'].first + page = result["pages"].first["children"].first - expect(page['children'].count).to eq(0) + expect(page["children"].count).to eq(0) end end @@ -159,20 +159,20 @@ module Alchemy page_1.lock_to!(user) end - it 'includes locked_notice if page is locked' do + it "includes locked_notice if page is locked" do get_tree expect(response.status).to eq(200) - expect(response.media_type).to eq('application/json') + expect(response.media_type).to eq("application/json") result = JSON.parse(response.body) - expect(result).to have_key('pages') - expect(result['pages'].count).to eq(1) + expect(result).to have_key("pages") + expect(result["pages"].count).to eq(1) - page = result['pages'].first - expect(page).to have_key('locked_notice') - expect(page['locked_notice']).to match(/#{user.name}/) + page = result["pages"].first + expect(page).to have_key("locked_notice") + expect(page["locked_notice"]).to match(/#{user.name}/) end end end @@ -238,23 +238,23 @@ module Alchemy end end - describe '#new' do - context 'if no language is present' do - it 'redirects to the language admin' do + describe "#new" do + context "if no language is present" do + it "redirects to the language admin" do get new_admin_page_path expect(response).to redirect_to(admin_languages_path) end end - context 'with current language present' do + context "with current language present" do let!(:language) { create(:alchemy_language) } context "pages in clipboard" do - let(:page) { mock_model(Alchemy::Page, name: 'Foobar') } + let(:page) { mock_model(Alchemy::Page, name: "Foobar") } before do - allow_any_instance_of(described_class).to receive(:get_clipboard).with('pages') do - [{'id' => page.id.to_s, 'action' => 'copy'}] + allow_any_instance_of(described_class).to receive(:get_clipboard).with("pages") do + [{"id" => page.id.to_s, "action" => "copy"}] end end @@ -266,8 +266,8 @@ module Alchemy end end - describe '#show' do - let(:language) { create(:alchemy_language, locale: 'nl') } + describe "#show" do + let(:language) { create(:alchemy_language, locale: "nl") } let!(:page) { create(:alchemy_page, language: language) } it "should assign @preview_mode with true" do @@ -287,24 +287,24 @@ module Alchemy it "renders the application layout" do get admin_page_path(page) - expect(response).to render_template(layout: 'application') + expect(response).to render_template(layout: "application") end - context 'when layout is set to custom' do + context "when layout is set to custom" do before do allow(Alchemy::Config).to receive(:get) do |arg| - arg == :admin_page_preview_layout ? 'custom' : Alchemy::Config.parameter(arg) + arg == :admin_page_preview_layout ? "custom" : Alchemy::Config.parameter(arg) end end it "it renders custom layout instead" do get admin_page_path(page) - expect(response).to render_template(layout: 'custom') + expect(response).to render_template(layout: "custom") end end end - describe '#order' do + describe "#order" do let(:page_1) { create(:alchemy_page, visible: true) } let(:page_2) { create(:alchemy_page, visible: true) } let(:page_3) { create(:alchemy_page, visible: true) } @@ -319,7 +319,7 @@ module Alchemy expect(page_1.descendants).to eq([page_2, page_3]) end - context 'with url nesting enabled' do + context "with url nesting enabled" do before do stub_alchemy_config(:url_nesting, true) end @@ -332,7 +332,7 @@ module Alchemy expect(page_3.urlname).to eq("#{page_1.slug}/#{page_2.slug}/#{page_3.slug}") end - context 'with invisible page in tree' do + context "with invisible page in tree" do let(:page_item_2) do { id: page_2.id, @@ -351,7 +351,7 @@ module Alchemy end end - context 'with restricted page in tree' do + context "with restricted page in tree" do let(:page_2) { create(:alchemy_page, restricted: true) } let(:page_item_2) do { @@ -369,7 +369,7 @@ module Alchemy end end - context 'with page having number as slug' do + context "with page having number as slug" do let(:page_item_2) do { id: page_2.id, @@ -402,7 +402,7 @@ module Alchemy describe "#configure" do context "with page having nested urlname" do - let(:page) { create(:alchemy_page, name: 'Foobar', urlname: 'foobar') } + let(:page) { create(:alchemy_page, name: "Foobar", urlname: "foobar") } it "should always show the slug" do get configure_admin_page_path(page), xhr: true @@ -411,7 +411,7 @@ module Alchemy end end - describe '#create' do + describe "#create" do subject { post admin_pages_path(page: page_params) } let(:parent) { create(:alchemy_page) } @@ -419,8 +419,8 @@ module Alchemy let(:page_params) do { parent_id: parent.id, - name: 'new Page', - page_layout: 'standard', + name: "new Page", + page_layout: "standard", } end @@ -438,7 +438,7 @@ module Alchemy let(:page_params) do { parent_id: parent.id, - name: 'new Page', + name: "new Page", } end @@ -460,7 +460,7 @@ module Alchemy let(:page_params) do { parent_id: parent.id, - name: 'new Page', + name: "new Page", } end @@ -470,13 +470,13 @@ module Alchemy end end - context 'if page is scoped' do - context 'user role does not match' do + context "if page is scoped" do + context "user role does not match" do before do allow_any_instance_of(Page).to receive(:editable_by?).with(user).and_return(false) end - it 'redirects to admin pages path' do + it "redirects to admin pages path" do post admin_pages_path(page: page_params) expect(response).to redirect_to(admin_pages_path) end @@ -498,11 +498,11 @@ module Alchemy end end - describe '#copy_language_tree' do - let(:params) { {languages: {new_lang_id: '2', old_lang_id: '1'}} } + describe "#copy_language_tree" do + let(:params) { {languages: {new_lang_id: "2", old_lang_id: "1"}} } let(:language_root_to_copy_from) { build_stubbed(:alchemy_page, :language_root) } let(:copy_of_language_root) { build_stubbed(:alchemy_page, :language_root) } - let(:root_page) { mock_model('Page') } + let(:root_page) { mock_model("Page") } before do allow(Page).to receive(:copy).and_return(copy_of_language_root) @@ -510,11 +510,11 @@ module Alchemy allow(Page).to receive(:language_root_for).and_return(language_root_to_copy_from) allow_any_instance_of(Page).to receive(:move_to_child_of) allow_any_instance_of(Page).to receive(:copy_children_to) - allow(Language).to receive(:current).and_return(mock_model('Language', locale: 'de', code: 'de')) + allow(Language).to receive(:current).and_return(mock_model("Language", locale: "de", code: "de")) end it "should copy the language root page over to the other language" do - expect(Page).to receive(:copy).with(language_root_to_copy_from, {language_id: '2', language_code: 'de'}) + expect(Page).to receive(:copy).with(language_root_to_copy_from, {language_id: "2", language_code: "de"}) post copy_language_tree_admin_pages_path(params) end @@ -540,59 +540,59 @@ module Alchemy end end - describe '#edit' do + describe "#edit" do let!(:page) { create(:alchemy_page) } let!(:other_user) { create(:alchemy_dummy_user, :as_author) } - context 'if page is locked by another user' do + context "if page is locked by another user" do before { page.lock_to!(other_user) } - context 'that is signed in' do + context "that is signed in" do before do expect_any_instance_of(DummyUser).to receive(:logged_in?).and_return(true) end - it 'redirects to sitemap' do + it "redirects to sitemap" do get edit_admin_page_path(page) expect(response).to redirect_to(admin_pages_path) end end - context 'that is not signed in' do + context "that is not signed in" do before do expect_any_instance_of(DummyUser).to receive(:logged_in?).and_return(false) end - it 'renders the edit view' do + it "renders the edit view" do get edit_admin_page_path(page) expect(response).to render_template(:edit) end end end - context 'if page is locked by myself' do + context "if page is locked by myself" do before do expect_any_instance_of(Page).to receive(:locker).at_least(:once) { user } expect(user).to receive(:logged_in?).and_return(true) end - it 'renders the edit view' do + it "renders the edit view" do get edit_admin_page_path(page) expect(response).to render_template(:edit) end - it 'does not lock the page again' do + it "does not lock the page again" do expect_any_instance_of(Alchemy::Page).to_not receive(:lock_to!) get edit_admin_page_path(page) end end - context 'if page is not locked' do + context "if page is not locked" do before do expect_any_instance_of(Page).to receive(:locker).at_least(:once) { nil } end - it 'renders the edit view' do + it "renders the edit view" do get edit_admin_page_path(page) expect(response).to render_template(:edit) end @@ -603,25 +603,25 @@ module Alchemy end end - context 'if page is scoped' do - context 'to a single role' do - context 'user role matches' do + context "if page is scoped" do + context "to a single role" do + context "user role matches" do before do expect_any_instance_of(Page).to receive(:editable_by?).at_least(:once) { true } end - it 'renders the edit view' do + it "renders the edit view" do get edit_admin_page_path(page) expect(response).to render_template(:edit) end end - context 'user role does not match' do + context "user role does not match" do before do expect_any_instance_of(Page).to receive(:editable_by?).at_least(:once) { false } end - it 'redirects to admin dashboard' do + it "redirects to admin dashboard" do get edit_admin_page_path(page) expect(response).to redirect_to(admin_dashboard_path) end @@ -630,12 +630,12 @@ module Alchemy end end - describe '#destroy' do - let(:clipboard) { [{'id' => page.id.to_s}] } + describe "#destroy" do + let(:clipboard) { [{"id" => page.id.to_s}] } let(:page) { create(:alchemy_page, :public) } before do - allow_any_instance_of(described_class).to receive(:get_clipboard).with('pages') do + allow_any_instance_of(described_class).to receive(:get_clipboard).with("pages") do clipboard end end @@ -646,7 +646,7 @@ module Alchemy end end - describe '#publish' do + describe "#publish" do let(:page) { create(:alchemy_page, published_at: 3.days.ago) } it "should publish the page" do @@ -656,12 +656,12 @@ module Alchemy end end - describe '#visit' do + describe "#visit" do subject do post visit_admin_page_path(page) end - let(:page) { create(:alchemy_page, urlname: 'home', site: site) } + let(:page) { create(:alchemy_page, urlname: "home", site: site) } context "when the pages site is a catch-all" do let(:site) { create(:alchemy_site, host: "*") } @@ -680,7 +680,7 @@ module Alchemy end end - describe '#fold' do + describe "#fold" do let(:page) { create(:alchemy_page) } before do @@ -707,10 +707,10 @@ module Alchemy end end - describe '#unlock' do + describe "#unlock" do subject { post unlock_admin_page_path(page), xhr: true } - let(:page) { create(:alchemy_page, name: 'Best practices') } + let(:page) { create(:alchemy_page, name: "Best practices") } before do allow(Page).to receive(:find).with(page.id.to_s).and_return(page) @@ -723,18 +723,18 @@ module Alchemy is_expected.to eq(200) end - context 'requesting for html format' do + context "requesting for html format" do subject { post unlock_admin_page_path(page) } it "should redirect to admin_pages_path" do is_expected.to redirect_to(admin_pages_path) end - context 'if passing :redirect_to through params' do - subject { post unlock_admin_page_path(page, redirect_to: 'this/path') } + context "if passing :redirect_to through params" do + subject { post unlock_admin_page_path(page, redirect_to: "this/path") } it "should redirect to the given path" do - is_expected.to redirect_to('this/path') + is_expected.to redirect_to("this/path") end end end diff --git a/spec/requests/alchemy/admin/resources_requests_spec.rb b/spec/requests/alchemy/admin/resources_requests_spec.rb index 765816d6d1..94d3224a27 100644 --- a/spec/requests/alchemy/admin/resources_requests_spec.rb +++ b/spec/requests/alchemy/admin/resources_requests_spec.rb @@ -1,28 +1,28 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" -RSpec.describe 'Resource requests' do - describe 'csv export' do - it 'returns valid csv file' do - get '/admin/events.csv' - expect(response.media_type).to eq('text/csv') - expect(response.body).to include(';') +RSpec.describe "Resource requests" do + describe "csv export" do + it "returns valid csv file" do + get "/admin/events.csv" + expect(response.media_type).to eq("text/csv") + expect(response.body).to include(";") end - it 'includes id column' do + it "includes id column" do event = create(:event) - get '/admin/events.csv' + get "/admin/events.csv" csv = CSV.parse(response.body, col_sep: ";") - expect(csv[0][0]).to eq('Id') + expect(csv[0][0]).to eq("Id") expect(csv[1][0]).to eq(event.id.to_s) end - it 'body does not truncate long text columns' do - create(:event, description: '*' * 51) - get '/admin/events.csv' + it "body does not truncate long text columns" do + create(:event, description: "*" * 51) + get "/admin/events.csv" csv = CSV.parse(response.body, col_sep: ";") - expect(csv[1][7]).to_not include('...') + expect(csv[1][7]).to_not include("...") end end end diff --git a/spec/requests/alchemy/admin/site_requests_spec.rb b/spec/requests/alchemy/admin/site_requests_spec.rb index fb7c5dc2b4..2cd5abcf1c 100644 --- a/spec/requests/alchemy/admin/site_requests_spec.rb +++ b/spec/requests/alchemy/admin/site_requests_spec.rb @@ -1,18 +1,18 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" -RSpec.describe 'Admin site requests' do +RSpec.describe "Admin site requests" do before do authorize_user(:as_admin) end - context 'a site with host' do - let!(:site) { create(:alchemy_site, :public, host: 'alchemy-cms.com') } + context "a site with host" do + let!(:site) { create(:alchemy_site, :public, host: "alchemy-cms.com") } let(:another_site) { Alchemy::Site.default } - context 'in params' do - it 'loads dashboard of another site by id and stores it in the session' do + context "in params" do + it "loads dashboard of another site by id and stores it in the session" do get "http://#{site.host}/admin/dashboard?site_id=#{another_site.id}" expect(assigns(:current_alchemy_site).id).to eq(another_site.id) diff --git a/spec/requests/alchemy/api/nodes_controller_spec.rb b/spec/requests/alchemy/api/nodes_controller_spec.rb index 5c27ef0278..ba79ae0eb6 100644 --- a/spec/requests/alchemy/api/nodes_controller_spec.rb +++ b/spec/requests/alchemy/api/nodes_controller_spec.rb @@ -1,21 +1,21 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" module Alchemy describe Api::NodesController do - describe '#move' do - let!(:root_node) { create(:alchemy_node, name: 'main_menu') } + describe "#move" do + let!(:root_node) { create(:alchemy_node, name: "main_menu") } let!(:page_node) { create(:alchemy_node, :with_page, parent: root_node) } let!(:page_node_2) { create(:alchemy_node, :with_page, parent: root_node) } let!(:url_node) { create(:alchemy_node, :with_url, parent: root_node) } - context 'with authorized access' do + context "with authorized access" do before do authorize_user(:as_admin) end - it 'returns JSON and moves the node' do + it "returns JSON and moves the node" do expect(page_node.children).to be_empty expect(url_node.lft).to eq(6) patch alchemy.move_api_node_path(url_node, format: :json), params: { @@ -24,33 +24,33 @@ module Alchemy } expect(response.status).to eq(200) response_json = JSON.parse(response.body) - expect(response_json['parent_id']).to eq(page_node.id) + expect(response_json["parent_id"]).to eq(page_node.id) expect(page_node.children).to include(url_node) end end - context 'with unauthorized access' do + context "with unauthorized access" do before do authorize_user end - it 'returns an unauthorized error' do + it "returns an unauthorized error" do patch alchemy.move_api_node_path(url_node, format: :json), params: { target_parent_id: page_node.id, new_position: 0, } expect(response).to be_forbidden response_json = JSON.parse(response.body) - expect(response_json['error']).to eq('Not authorized') + expect(response_json["error"]).to eq("Not authorized") end end end - describe '#toggle_folded' do - context 'with expanded node' do + describe "#toggle_folded" do + context "with expanded node" do let(:node) { create(:alchemy_node, folded: false) } - context 'with authorized access' do + context "with authorized access" do before do authorize_user(:as_admin) end @@ -62,7 +62,7 @@ module Alchemy end end - context 'with unauthorized access' do + context "with unauthorized access" do before do authorize_user end @@ -74,12 +74,12 @@ module Alchemy expect(response).to be_forbidden response_json = JSON.parse(response.body) - expect(response_json['error']).to eq('Not authorized') + expect(response_json["error"]).to eq("Not authorized") end end end - context 'with folded node' do + context "with folded node" do let(:node) { create(:alchemy_node, folded: true) } before do @@ -92,7 +92,7 @@ module Alchemy }.to change { node.reload.folded }.to(false) end - context 'with node having children' do + context "with node having children" do before do create(:alchemy_node, parent: node) end @@ -101,7 +101,7 @@ module Alchemy patch alchemy.toggle_folded_api_node_path(node) expect(response).to be_successful response_json = JSON.parse(response.body) - expect(response_json['id']).to eq(node.id) + expect(response_json["id"]).to eq(node.id) end end end diff --git a/spec/requests/alchemy/legacy_page_redirecting_spec.rb b/spec/requests/alchemy/legacy_page_redirecting_spec.rb index a4ca2709f3..468db2d41f 100644 --- a/spec/requests/alchemy/legacy_page_redirecting_spec.rb +++ b/spec/requests/alchemy/legacy_page_redirecting_spec.rb @@ -1,36 +1,36 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" -RSpec.describe 'Redirecting to legacy page urls' do +RSpec.describe "Redirecting to legacy page urls" do let(:page) do - create(:alchemy_page, :public, name: 'New page name') + create(:alchemy_page, :public, name: "New page name") end let(:second_page) do - create(:alchemy_page, :public, name: 'Second Page') + create(:alchemy_page, :public, name: "Second Page") end let(:legacy_page) do - create(:alchemy_page, :public, name: 'Legacy Url') + create(:alchemy_page, :public, name: "Legacy Url") end let!(:legacy_url) do - Alchemy::LegacyPageUrl.create(urlname: 'legacy-url', page: page) + Alchemy::LegacyPageUrl.create(urlname: "legacy-url", page: page) end let(:legacy_url2) do - Alchemy::LegacyPageUrl.create(urlname: 'legacy-url', page: second_page) + Alchemy::LegacyPageUrl.create(urlname: "legacy-url", page: second_page) end let(:legacy_url4) do Alchemy::LegacyPageUrl.create( - urlname: 'index.php?option=com_content&view=article&id=48&Itemid=69', + urlname: "index.php?option=com_content&view=article&id=48&Itemid=69", page: second_page, ) end - context 'if url has an unknown format & get parameters' do + context "if url has an unknown format & get parameters" do it "redirects permanently to page that belongs to legacy page url" do get "/#{legacy_url4.urlname}" expect(response.status).to eq(301) @@ -54,9 +54,9 @@ expect(response).to redirect_to("/#{second_page.urlname}") end - context 'if the url has get parameters' do + context "if the url has get parameters" do let(:legacy_url3) do - Alchemy::LegacyPageUrl.create(urlname: 'index.php?id=2', page: second_page) + Alchemy::LegacyPageUrl.create(urlname: "index.php?id=2", page: second_page) end it "redirects" do @@ -65,9 +65,9 @@ end end - context 'when the url has nested urlname' do + context "when the url has nested urlname" do let(:legacy_url5) do - Alchemy::LegacyPageUrl.create(urlname: 'nested/legacy/url', page: second_page) + Alchemy::LegacyPageUrl.create(urlname: "nested/legacy/url", page: second_page) end it "redirects" do diff --git a/spec/requests/alchemy/page_request_caching_spec.rb b/spec/requests/alchemy/page_request_caching_spec.rb index e18682ce21..07c4b41b2e 100644 --- a/spec/requests/alchemy/page_request_caching_spec.rb +++ b/spec/requests/alchemy/page_request_caching_spec.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" -RSpec.describe 'Page request caching' do +RSpec.describe "Page request caching" do let!(:page) { create(:alchemy_page, :public) } context "when caching is disabled in app" do @@ -12,8 +12,8 @@ it "sets no-cache header" do get "/#{page.urlname}" - expect(response.headers).to have_key('Cache-Control') - expect(response.headers['Cache-Control']).to eq('no-cache') + expect(response.headers).to have_key("Cache-Control") + expect(response.headers["Cache-Control"]).to eq("no-cache") end end @@ -39,8 +39,8 @@ it "sets public cache control header" do get "/#{page.urlname}" - expect(response.headers).to have_key('Cache-Control') - expect(response.headers['Cache-Control']).to eq('public, must-revalidate') + expect(response.headers).to have_key("Cache-Control") + expect(response.headers["Cache-Control"]).to eq("public, must-revalidate") end end @@ -56,8 +56,8 @@ it "sets max-age cache control header" do get "/#{page.urlname}" - expect(response.headers).to have_key('Cache-Control') - expect(response.headers['Cache-Control']).to \ + expect(response.headers).to have_key("Cache-Control") + expect(response.headers["Cache-Control"]).to \ eq("max-age=#{expiration_time.to_i}, public, must-revalidate") end end @@ -70,20 +70,20 @@ it "sets private cache control header" do get "/#{page.urlname}" - expect(response.headers).to have_key('Cache-Control') - expect(response.headers['Cache-Control']).to eq('private, must-revalidate') + expect(response.headers).to have_key("Cache-Control") + expect(response.headers["Cache-Control"]).to eq("private, must-revalidate") end end it "sets etag header" do get "/#{page.urlname}" - expect(response.headers).to have_key('ETag') + expect(response.headers).to have_key("ETag") end it "sets last-modified header" do get "/#{page.urlname}" - expect(response.headers).to have_key('Last-Modified') - expect(response.headers['Last-Modified']).to eq(page.published_at.httpdate) + expect(response.headers).to have_key("Last-Modified") + expect(response.headers["Last-Modified"]).to eq(page.published_at.httpdate) end end @@ -94,13 +94,13 @@ it "sets no-cache header" do get "/#{page.urlname}" - expect(response.headers).to have_key('Cache-Control') - expect(response.headers['Cache-Control']).to eq('no-cache') + expect(response.headers).to have_key("Cache-Control") + expect(response.headers["Cache-Control"]).to eq("no-cache") end it "does not set last-modified header" do get "/#{page.urlname}" - expect(response.headers).to_not have_key('Last-Modified') + expect(response.headers).to_not have_key("Last-Modified") end end @@ -113,13 +113,13 @@ it "sets no-cache header" do get "/#{page.urlname}" - expect(response.headers).to have_key('Cache-Control') - expect(response.headers['Cache-Control']).to eq('no-cache') + expect(response.headers).to have_key("Cache-Control") + expect(response.headers["Cache-Control"]).to eq("no-cache") end it "does not set last-modified header" do get "/#{page.urlname}" - expect(response.headers).to_not have_key('Last-Modified') + expect(response.headers).to_not have_key("Last-Modified") end end diff --git a/spec/requests/alchemy/site_requests_spec.rb b/spec/requests/alchemy/site_requests_spec.rb index 88a277c6e7..50ff0d7704 100644 --- a/spec/requests/alchemy/site_requests_spec.rb +++ b/spec/requests/alchemy/site_requests_spec.rb @@ -1,10 +1,10 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" -RSpec.describe 'Site requests' do - context 'a site with host' do - let!(:site) { create(:alchemy_site, :public, host: 'alchemy-cms.com') } +RSpec.describe "Site requests" do + context "a site with host" do + let!(:site) { create(:alchemy_site, :public, host: "alchemy-cms.com") } let(:language) { create(:alchemy_language, site: site) } let(:page) do @@ -13,7 +13,7 @@ create(:alchemy_page, :public, parent: root) end - it 'loads this site by host' do + it "loads this site by host" do get "http://#{site.host}/#{page.urlname}" expect(assigns(:current_alchemy_site).host).to eq(site.host) end diff --git a/spec/requests/alchemy/sitemap_spec.rb b/spec/requests/alchemy/sitemap_spec.rb index 0482c3a206..44f02fd394 100644 --- a/spec/requests/alchemy/sitemap_spec.rb +++ b/spec/requests/alchemy/sitemap_spec.rb @@ -1,56 +1,56 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" -RSpec.describe 'Requests for PagesController#sitemap' do +RSpec.describe "Requests for PagesController#sitemap" do let!(:page) { create(:alchemy_page, :public, sitemap: true) } - it 'renders valid xml sitemap' do - get '/sitemap.xml' - expect(response.media_type).to eq('application/xml') + it "renders valid xml sitemap" do + get "/sitemap.xml" + expect(response.media_type).to eq("application/xml") xml_doc = Nokogiri::XML(response.body) - expect(xml_doc.namespaces).to have_key('xmlns') - expect(xml_doc.namespaces['xmlns']).to eq('http://www.sitemaps.org/schemas/sitemap/0.9') - expect(xml_doc.css('urlset url loc').length).to eq(2) + expect(xml_doc.namespaces).to have_key("xmlns") + expect(xml_doc.namespaces["xmlns"]).to eq("http://www.sitemaps.org/schemas/sitemap/0.9") + expect(xml_doc.css("urlset url loc").length).to eq(2) end - it 'lastmod dates are ISO 8601 timestamps' do - get '/sitemap.xml' - expect(response.media_type).to eq('application/xml') + it "lastmod dates are ISO 8601 timestamps" do + get "/sitemap.xml" + expect(response.media_type).to eq("application/xml") xml_doc = Nokogiri::XML(response.body) - xml_doc.css('urlset url lastmod').each do |timestamps| + xml_doc.css("urlset url lastmod").each do |timestamps| expect(timestamps.text).to match(/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z/) end end - context 'in multi language mode' do + context "in multi language mode" do let!(:root) { page.parent } let!(:pages) { [root, page] } before do - allow_any_instance_of(Alchemy::BaseController).to receive('prefix_locale?') { true } + allow_any_instance_of(Alchemy::BaseController).to receive("prefix_locale?") { true } end - it 'links in sitemap has locale code included' do - get '/sitemap.xml' + it "links in sitemap has locale code included" do + get "/sitemap.xml" xml_doc = Nokogiri::XML(response.body) - xml_doc.css('urlset url').each_with_index do |node, i| + xml_doc.css("urlset url").each_with_index do |node, i| page = pages[i] - expect(node.css('loc').text).to match(/\/#{page.language_code}\//) + expect(node.css("loc").text).to match(/\/#{page.language_code}\//) end end - context 'if the default locale is the page locale' do + context "if the default locale is the page locale" do before do - allow_any_instance_of(Alchemy::BaseController).to receive('prefix_locale?') { false } + allow_any_instance_of(Alchemy::BaseController).to receive("prefix_locale?") { false } end - it 'links in sitemap has no locale code included' do - get '/sitemap.xml' + it "links in sitemap has no locale code included" do + get "/sitemap.xml" xml_doc = Nokogiri::XML(response.body) - xml_doc.css('urlset url').each_with_index do |node, i| + xml_doc.css("urlset url").each_with_index do |node, i| page = pages[i] - expect(node.css('loc').text).to_not match(/\/#{page.language_code}\//) + expect(node.css("loc").text).to_not match(/\/#{page.language_code}\//) end end end diff --git a/spec/routing/api_routing_spec.rb b/spec/routing/api_routing_spec.rb index 607cbab205..29ade92dfd 100644 --- a/spec/routing/api_routing_spec.rb +++ b/spec/routing/api_routing_spec.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" -describe 'The API routes' do +describe "The API routes" do routes { Alchemy::Engine.routes } describe "for pages" do @@ -14,7 +14,7 @@ ) end - context 'with missing format' do + context "with missing format" do it "defaults to json." do expect({get: "/api/pages"}).to route_to( controller: "alchemy/api/pages", @@ -42,7 +42,7 @@ ) end - context 'with admin namespace' do + context "with admin namespace" do it "routes to api pages controller." do expect({get: "/api/admin/pages/8"}).to route_to( controller: "alchemy/api/pages", @@ -54,7 +54,7 @@ end end - describe 'for elements' do + describe "for elements" do it "has route to show all elements." do expect({get: "/api/elements.json"}).to route_to( controller: "alchemy/api/elements", @@ -63,7 +63,7 @@ ) end - context 'with missing format' do + context "with missing format" do it "defaults to json." do expect({get: "/api/elements"}).to route_to( controller: "alchemy/api/elements", @@ -102,7 +102,7 @@ end end - describe 'for contents' do + describe "for contents" do it "has route to show all contents." do expect({get: "/api/contents.json"}).to route_to( controller: "alchemy/api/contents", @@ -111,7 +111,7 @@ ) end - context 'with missing format' do + context "with missing format" do it "defaults to json." do expect({get: "/api/contents"}).to route_to( controller: "alchemy/api/contents", diff --git a/spec/routing/routing_spec.rb b/spec/routing/routing_spec.rb index e711f6fca7..d95fb41249 100644 --- a/spec/routing/routing_spec.rb +++ b/spec/routing/routing_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" describe "The Routing" do routes { Alchemy::Engine.routes } @@ -15,25 +15,25 @@ ) end - context 'with locale parameter' do - it 'routes to pages_controller#index' do + context "with locale parameter" do + it "routes to pages_controller#index" do expect({ - get: '/en', + get: "/en", }).to route_to( - controller: 'alchemy/pages', - action: 'index', - locale: 'en', + controller: "alchemy/pages", + action: "index", + locale: "en", ) end - context 'that contains uppercase country code' do - it 'routes to pages_controller#index' do + context "that contains uppercase country code" do + it "routes to pages_controller#index" do expect({ - get: '/en-UK', + get: "/en-UK", }).to route_to( - controller: 'alchemy/pages', - action: 'index', - locale: 'en-UK', + controller: "alchemy/pages", + action: "index", + locale: "en-UK", ) end end diff --git a/spec/serializers/alchemy/element_serializer_spec.rb b/spec/serializers/alchemy/element_serializer_spec.rb index 7c220dcfdd..ad067f8fe3 100644 --- a/spec/serializers/alchemy/element_serializer_spec.rb +++ b/spec/serializers/alchemy/element_serializer_spec.rb @@ -1,27 +1,27 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" RSpec.describe Alchemy::ElementSerializer do subject { described_class.new(element).to_json } let(:element) { build_stubbed(:alchemy_element) } - it 'includes all attributes' do + it "includes all attributes" do json = JSON.parse(subject) expect(json).to eq( - 'content_ids' => [], - 'created_at' => element.created_at.strftime('%FT%T.%LZ'), - 'display_name' => element.display_name_with_preview_text, - 'dom_id' => element.dom_id, - 'id' => element.id, - 'ingredients' => [], - 'name' => element.name, - 'nested_elements' => [], - 'page_id' => element.page_id, - 'position' => nil, - 'tag_list' => [], - 'updated_at' => element.updated_at.strftime('%FT%T.%LZ'), + "content_ids" => [], + "created_at" => element.created_at.strftime("%FT%T.%LZ"), + "display_name" => element.display_name_with_preview_text, + "dom_id" => element.dom_id, + "id" => element.id, + "ingredients" => [], + "name" => element.name, + "nested_elements" => [], + "page_id" => element.page_id, + "position" => nil, + "tag_list" => [], + "updated_at" => element.updated_at.strftime("%FT%T.%LZ"), ) end end diff --git a/spec/serializers/alchemy/node_serializer_spec.rb b/spec/serializers/alchemy/node_serializer_spec.rb index 20b3b4aa85..13d481ca2c 100644 --- a/spec/serializers/alchemy/node_serializer_spec.rb +++ b/spec/serializers/alchemy/node_serializer_spec.rb @@ -1,21 +1,21 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" RSpec.describe Alchemy::NodeSerializer do subject { described_class.new(node).to_json } let(:node) { build_stubbed(:alchemy_node) } - it 'includes all attributes' do + it "includes all attributes" do json = JSON.parse(subject) expect(json).to eq( - 'id' => node.id, - 'lft' => node.lft, - 'rgt' => node.rgt, - 'parent_id' => node.parent_id, - 'name' => node.name, - 'url' => node.url, + "id" => node.id, + "lft" => node.lft, + "rgt" => node.rgt, + "parent_id" => node.parent_id, + "name" => node.name, + "url" => node.url, ) end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 40956ae7ae..adf213972a 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,17 +1,17 @@ # frozen_string_literal: true -require 'simplecov' -if ENV['TRAVIS'] - require 'codeclimate-test-reporter' +require "simplecov" +if ENV["TRAVIS"] + require "codeclimate-test-reporter" end -SimpleCov.start 'rails' do +SimpleCov.start "rails" do add_filter "/lib/alchemy/upgrader" add_filter "/lib/alchemy/version" add_filter "/lib/rails" end -require 'rspec/core' -require 'webmock' +require "rspec/core" +require "webmock" RSpec.configure do |config| config.raise_errors_for_deprecations! diff --git a/spec/support/capybara_helpers.rb b/spec/support/capybara_helpers.rb index b0adf88d39..f43b7d9cae 100644 --- a/spec/support/capybara_helpers.rb +++ b/spec/support/capybara_helpers.rb @@ -6,10 +6,10 @@ def select2(value, options) label = find_label_by_text(options[:from]) within label.first(:xpath, ".//..") do - options[:from] = "##{find('.select2-container')['id']}" + options[:from] = "##{find(".select2-container")["id"]}" end - find(options[:from]).find('a').click + find(options[:from]).find("a").click within_entire_page do page.find("div.select2-result-label", @@ -21,34 +21,34 @@ def select2_search(value, options) label = find_label_by_text(options[:from]) within label.first(:xpath, ".//..") do - options[:from] = "##{find('.select2-container')['id']}" + options[:from] = "##{find(".select2-container")["id"]}" end find("#{options[:from]}:not(.select2-container-disabled):not(.select2-offscreen)").click within_entire_page do find("input.select2-input.select2-focused").set(value) - expect(page).to have_selector('.select2-result-label', visible: true) + expect(page).to have_selector(".select2-result-label", visible: true) find("div.select2-result-label", text: /#{Regexp.escape(value)}/i, match: :prefer_exact).click - expect(page).not_to have_selector('.select2-result-label') + expect(page).not_to have_selector(".select2-result-label") end end def click_button_with_label(label) - label = find('label', text: label) + label = find("label", text: label) within label.first(:xpath, ".//..") do - first('button').click + first("button").click end end private def within_entire_page(&block) - within(:xpath, '//body', &block) + within(:xpath, "//body", &block) end def find_label_by_text(text) - find 'label:not(.select2-offscreen)', + find "label:not(.select2-offscreen)", text: /#{Regexp.escape(text)}/i, match: :one end diff --git a/spec/support/custom_news_elements_finder.rb b/spec/support/custom_news_elements_finder.rb index 1c32d5f170..f883f5260c 100644 --- a/spec/support/custom_news_elements_finder.rb +++ b/spec/support/custom_news_elements_finder.rb @@ -2,6 +2,6 @@ class CustomNewsElementsFinder def elements(*) - [Alchemy::Element.new(name: 'news', id: 1001)] + [Alchemy::Element.new(name: "news", id: 1001)] end end diff --git a/spec/support/hint_examples.rb b/spec/support/hint_examples.rb index 48485abe19..031638d3bd 100644 --- a/spec/support/hint_examples.rb +++ b/spec/support/hint_examples.rb @@ -1,28 +1,28 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" module Alchemy shared_examples_for "having a hint" do - describe '#hint' do - context 'with hint as text' do + describe "#hint" do + context "with hint as text" do before do - expect(subject).to receive(:definition).and_return({'hint' => 'The hint'}) + expect(subject).to receive(:definition).and_return({"hint" => "The hint"}) end it "returns the hint" do - expect(subject.hint).to eq('The hint') + expect(subject.hint).to eq("The hint") end end - context 'with hint set to true' do + context "with hint set to true" do before do - expect(subject).to receive(:definition).and_return({'hint' => true}) - expect(Alchemy).to receive(:t).and_return('The hint') + expect(subject).to receive(:definition).and_return({"hint" => true}) + expect(Alchemy).to receive(:t).and_return("The hint") end it "returns the hint from translation" do - expect(subject.hint).to eq('The hint') + expect(subject.hint).to eq("The hint") end end end diff --git a/spec/support/transformation_examples.rb b/spec/support/transformation_examples.rb index 8dbf4b32be..79dcfc7ad9 100644 --- a/spec/support/transformation_examples.rb +++ b/spec/support/transformation_examples.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" module Alchemy shared_examples_for "has image transformations" do @@ -10,7 +10,7 @@ module Alchemy allow(picture).to receive(:image_file_width) { 400 } allow(picture).to receive(:image_file_height) { 300 } - expect(picture.thumbnail_size).to eq('160x120') + expect(picture.thumbnail_size).to eq("160x120") end end @@ -19,35 +19,35 @@ module Alchemy allow(picture).to receive(:image_file_width) { 300 } allow(picture).to receive(:image_file_height) { 400 } - expect(picture.thumbnail_size).to eq('90x120') + expect(picture.thumbnail_size).to eq("90x120") end end context "picture has crop_size of 400x300" do it "scales to 400x300 if that is the size of the cropped image" do allow(picture).to receive(:crop_size) { "400x300" } - expect(picture.thumbnail_size).to eq('160x120') + expect(picture.thumbnail_size).to eq("160x120") end end context "picture has crop_size of 0x0" do it "returns default thumbnail size" do allow(picture).to receive(:crop_size) { "0x0" } - expect(picture.thumbnail_size).to eq('160x120') + expect(picture.thumbnail_size).to eq("160x120") end end end - describe '#landscape_format?' do + describe "#landscape_format?" do subject { picture.landscape_format? } - context 'image has landscape format' do + context "image has landscape format" do before { allow(picture).to receive(:image_file).and_return double(landscape?: true) } it { is_expected.to be_truthy } end - context 'image has portrait format' do + context "image has portrait format" do before { allow(picture).to receive(:image_file).and_return double(landscape?: false) } it { is_expected.to be_falsey } @@ -58,16 +58,16 @@ module Alchemy end end - describe '#portrait_format?' do + describe "#portrait_format?" do subject { picture.portrait_format? } - context 'image has portrait format' do + context "image has portrait format" do before { allow(picture).to receive(:image_file).and_return double(portrait?: true) } it { is_expected.to be_truthy } end - context 'image has landscape format' do + context "image has landscape format" do before { allow(picture).to receive(:image_file).and_return double(portrait?: false) } it { is_expected.to be_falsey } @@ -78,16 +78,16 @@ module Alchemy end end - describe '#square_format?' do + describe "#square_format?" do subject { picture.square_format? } - context 'image has square format' do + context "image has square format" do before { expect(picture).to receive(:image_file).and_return double(aspect_ratio: 1.0) } it { is_expected.to be_truthy } end - context 'image has rectangle format' do + context "image has rectangle format" do before { expect(picture).to receive(:image_file).and_return double(aspect_ratio: 8.0) } it { is_expected.to be_falsey } @@ -98,7 +98,7 @@ module Alchemy end end - describe '#default_mask' do + describe "#default_mask" do before do allow(picture).to receive(:image_file_width) { 200 } allow(picture).to receive(:image_file_height) { 100 } diff --git a/spec/views/admin/pictures/show_spec.rb b/spec/views/admin/pictures/show_spec.rb index 8b2c619eb9..c7d972b172 100644 --- a/spec/views/admin/pictures/show_spec.rb +++ b/spec/views/admin/pictures/show_spec.rb @@ -1,26 +1,26 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" describe "alchemy/admin/pictures/show.html.erb" do let(:image) do fixture_file_upload( - File.expand_path('../../../fixtures/animated.gif', __dir__), - 'image/gif', + File.expand_path("../../../fixtures/animated.gif", __dir__), + "image/gif", ) end let(:picture) do create(:alchemy_picture, { image_file: image, - name: 'animated', - image_file_name: 'animated.gif', + name: "animated", + image_file_name: "animated.gif", }) end before do allow(view).to receive(:admin_picture_path).and_return("/path") - allow(view).to receive(:render_message) {} + allow(view).to receive(:render_message) allow(view).to receive(:search_filter_params) { {} } view.extend Alchemy::Admin::FormHelper end diff --git a/spec/views/alchemy/admin/elements/element_view_spec.rb b/spec/views/alchemy/admin/elements/element_view_spec.rb index 556cb604af..43de124c62 100644 --- a/spec/views/alchemy/admin/elements/element_view_spec.rb +++ b/spec/views/alchemy/admin/elements/element_view_spec.rb @@ -1,16 +1,16 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" -describe 'alchemy/admin/elements/_element' do +describe "alchemy/admin/elements/_element" do before do allow(element).to receive(:definition) { definition } end let(:definition) do { - name: 'with_message', - message: 'One nice message', + name: "with_message", + message: "One nice message", }.with_indifferent_access end @@ -19,18 +19,18 @@ rendered end - context 'with message given in element definition' do - let(:element) { create(:alchemy_element, name: 'with_message') } + context "with message given in element definition" do + let(:element) { create(:alchemy_element, name: "with_message") } it "renders the message" do is_expected.to have_css('.message:contains("One nice message")') end - context 'that contains HTML' do + context "that contains HTML" do let(:definition) do { - name: 'with_message', - message: '<h1>One nice message</h1>', + name: "with_message", + message: "<h1>One nice message</h1>", }.with_indifferent_access end @@ -40,13 +40,13 @@ end end - context 'with warning given in element definition' do - let(:element) { create(:alchemy_element, name: 'with_warning') } + context "with warning given in element definition" do + let(:element) { create(:alchemy_element, name: "with_warning") } let(:definition) do { - name: 'with_warning', - warning: 'One nice warning', + name: "with_warning", + warning: "One nice warning", }.with_indifferent_access end @@ -54,11 +54,11 @@ is_expected.to have_css('.warning:contains("One nice warning")') end - context 'that contains HTML' do + context "that contains HTML" do let(:definition) do { - name: 'with_warning', - warning: '<h1>One nice warning</h1>', + name: "with_warning", + warning: "<h1>One nice warning</h1>", }.with_indifferent_access end diff --git a/spec/views/alchemy/admin/partials/_main_navigation_entry.html.erb_spec.rb b/spec/views/alchemy/admin/partials/_main_navigation_entry.html.erb_spec.rb index 0b2f0fd126..1414556b13 100644 --- a/spec/views/alchemy/admin/partials/_main_navigation_entry.html.erb_spec.rb +++ b/spec/views/alchemy/admin/partials/_main_navigation_entry.html.erb_spec.rb @@ -1,17 +1,17 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" describe "alchemy/admin/partials/_main_navigation_entry.html.erb" do let(:alchemy_module) do { - engine_name: 'alchemy', - name: 'what_a_name', + engine_name: "alchemy", + name: "what_a_name", navigation: { - controller: 'alchemy/admin/pages', - action: 'index', - name: 'Pages', - image: 'alchemy/alchemy-logo.svg', + controller: "alchemy/admin/pages", + action: "index", + name: "Pages", + image: "alchemy/alchemy-logo.svg", data: { turbolinks: false }, sub_navigation: [], }, @@ -33,16 +33,16 @@ expect(rendered).to have_selector('div[data-turbolinks="false"]') end - context 'with no data attribute' do + context "with no data attribute" do let(:alchemy_module) do { - engine_name: 'alchemy', - name: 'what_a_name', + engine_name: "alchemy", + name: "what_a_name", navigation: { - controller: 'alchemy/admin/pages', - action: 'index', - name: 'Pages', - image: 'alchemy/alchemy-logo.svg', + controller: "alchemy/admin/pages", + action: "index", + name: "Pages", + image: "alchemy/alchemy-logo.svg", sub_navigation: [], }, }.with_indifferent_access diff --git a/spec/views/essences/essence_boolean_editor_spec.rb b/spec/views/essences/essence_boolean_editor_spec.rb index 63a914c21c..30df6d1b70 100644 --- a/spec/views/essences/essence_boolean_editor_spec.rb +++ b/spec/views/essences/essence_boolean_editor_spec.rb @@ -1,15 +1,15 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" -describe 'alchemy/essences/_essence_boolean_editor' do - let(:element) { create(:alchemy_element, name: 'all_you_can_eat') } - let(:content) { Alchemy::Content.create(name: 'essence_boolean', type: 'EssenceBoolean', element: element) } +describe "alchemy/essences/_essence_boolean_editor" do + let(:element) { create(:alchemy_element, name: "all_you_can_eat") } + let(:content) { Alchemy::Content.create(name: "essence_boolean", type: "EssenceBoolean", element: element) } let(:content_definition) do { - name: 'essence_boolean', - type: 'EssenceBoolean', + name: "essence_boolean", + type: "EssenceBoolean", }.with_indifferent_access end @@ -17,7 +17,7 @@ expect(element).to receive(:content_definition_for) { content_definition } allow_any_instance_of(Alchemy::Content).to receive(:definition) { content_definition } allow(view).to receive(:render_content_name).and_return(content.name) - allow(view).to receive(:render_hint_for).and_return('') + allow(view).to receive(:render_hint_for).and_return("") end subject do @@ -31,11 +31,11 @@ is_expected.to have_selector('input[type="checkbox"]') end - context 'with default value given in content settings' do + context "with default value given in content settings" do let(:content_definition) do { - name: 'essence_boolean', - type: 'EssenceBoolean', + name: "essence_boolean", + type: "EssenceBoolean", default: true, }.with_indifferent_access end diff --git a/spec/views/essences/essence_boolean_view_spec.rb b/spec/views/essences/essence_boolean_view_spec.rb index 320e7aefe6..1f69be058a 100644 --- a/spec/views/essences/essence_boolean_view_spec.rb +++ b/spec/views/essences/essence_boolean_view_spec.rb @@ -1,25 +1,25 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" -describe 'alchemy/essences/_essence_boolean_view' do - context 'with true as ingredient' do +describe "alchemy/essences/_essence_boolean_view" do + context "with true as ingredient" do let(:content) { Alchemy::EssenceBoolean.new(ingredient: true) } - before { allow(Alchemy).to receive(:t).and_return('true') } + before { allow(Alchemy).to receive(:t).and_return("true") } it "renders true" do render content, content: content - expect(rendered).to have_content('true') + expect(rendered).to have_content("true") end end - context 'with false as ingredient' do + context "with false as ingredient" do let(:content) { Alchemy::EssenceBoolean.new(ingredient: false) } - before { allow(Alchemy).to receive(:t).and_return('false') } + before { allow(Alchemy).to receive(:t).and_return("false") } it "renders false" do render content, content: content - expect(rendered).to have_content('false') + expect(rendered).to have_content("false") end end end diff --git a/spec/views/essences/essence_date_editor_spec.rb b/spec/views/essences/essence_date_editor_spec.rb index aa1ca2b6a9..57eb2c64ab 100644 --- a/spec/views/essences/essence_date_editor_spec.rb +++ b/spec/views/essences/essence_date_editor_spec.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" -RSpec.describe 'alchemy/essences/_essence_date_editor' do +RSpec.describe "alchemy/essences/_essence_date_editor" do let(:content) { Alchemy::Content.new(essence: essence) } let(:essence) { Alchemy::EssenceDate.new } @@ -12,7 +12,7 @@ end it "renders a datepicker" do - render 'alchemy/essences/essence_date_editor', essence_date_editor: Alchemy::ContentEditor.new(content) + render "alchemy/essences/essence_date_editor", essence_date_editor: Alchemy::ContentEditor.new(content) expect(rendered).to have_css('input[type="text"][data-datepicker-type="date"].date') end end diff --git a/spec/views/essences/essence_date_view_spec.rb b/spec/views/essences/essence_date_view_spec.rb index 5bd4387366..ecba8b136b 100644 --- a/spec/views/essences/essence_date_view_spec.rb +++ b/spec/views/essences/essence_date_view_spec.rb @@ -1,9 +1,9 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" -describe 'alchemy/essences/_essence_date_view' do - let(:essence) { Alchemy::EssenceDate.new(date: '2013-10-27 21:14:16 +0100'.to_datetime) } +describe "alchemy/essences/_essence_date_view" do + let(:essence) { Alchemy::EssenceDate.new(date: "2013-10-27 21:14:16 +0100".to_datetime) } let(:content) { Alchemy::Content.new(essence: essence) } let(:options) { {} } @@ -12,29 +12,29 @@ end context "with date value" do - context 'without date_format passed' do + context "without date_format passed" do it "translates the date value with default format" do render content, content: content - expect(rendered).to have_content('Sun, 27 Oct 2013 20:14:16 +0000') + expect(rendered).to have_content("Sun, 27 Oct 2013 20:14:16 +0000") end end - context 'with option date_format set to rfc822' do - let(:options) { {date_format: 'rfc822'} } + context "with option date_format set to rfc822" do + let(:options) { {date_format: "rfc822"} } it "renders the date rfc822 conform" do render content, content: content - expect(rendered).to have_content('Sun, 27 Oct 2013 20:14:16 +0000') + expect(rendered).to have_content("Sun, 27 Oct 2013 20:14:16 +0000") end end end - context 'with blank date value' do + context "with blank date value" do let(:essence) { Alchemy::EssenceDate.new(date: nil) } it "renders nothing" do render content, content: content - expect(rendered).to eq('') + expect(rendered).to eq("") end end end diff --git a/spec/views/essences/essence_file_editor_spec.rb b/spec/views/essences/essence_file_editor_spec.rb index 8bbc69c281..1abe478281 100644 --- a/spec/views/essences/essence_file_editor_spec.rb +++ b/spec/views/essences/essence_file_editor_spec.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" -describe 'alchemy/essences/_essence_file_editor' do +describe "alchemy/essences/_essence_file_editor" do let(:attachment) { build_stubbed(:alchemy_attachment) } let(:essence) { build_stubbed(:alchemy_essence_file, attachment: attachment) } let(:content) { build_stubbed(:alchemy_content, essence: essence) } @@ -16,10 +16,10 @@ before do view.class.send :include, Alchemy::Admin::BaseHelper - allow(view).to receive(:content_label).and_return('') + allow(view).to receive(:content_label).and_return("") end - context 'with ingredient present' do + context "with ingredient present" do before do allow(content).to receive(:ingredient).and_return(attachment) end @@ -29,37 +29,37 @@ end it "renders a link to open the attachment library overlay" do - within '.essence_file_tools' do + within ".essence_file_tools" do is_expected.to have_selector("a[href='/admin/attachments?content_id=#{content.id}']") end end it "renders a link to edit the essence" do - within '.essence_file_tools' do + within ".essence_file_tools" do is_expected.to have_selector("a[href='/admin/essence_files/#{essence.id}/edit']") end end - context 'with content settings `only`' do + context "with content settings `only`" do it "renders a link to open the attachment library overlay with only pdfs" do - within '.essence_file_tools' do - expect(content).to receive(:settings).at_least(:once).and_return({only: 'pdf'}) + within ".essence_file_tools" do + expect(content).to receive(:settings).at_least(:once).and_return({only: "pdf"}) is_expected.to have_selector("a[href='/admin/attachments?content_id=#{content.id}&only=pdf']") end end end - context 'with content settings `except`' do + context "with content settings `except`" do it "renders a link to open the attachment library overlay without pdfs" do - within '.essence_file_tools' do - expect(content).to receive(:settings).at_least(:once).and_return({except: 'pdf'}) + within ".essence_file_tools" do + expect(content).to receive(:settings).at_least(:once).and_return({except: "pdf"}) is_expected.to have_selector("a[href='/admin/attachments?content_id=#{content.id}&except=pdf']") end end end end - context 'without ingredient present' do + context "without ingredient present" do before do allow(content).to receive(:ingredient).and_return(nil) end diff --git a/spec/views/essences/essence_file_view_spec.rb b/spec/views/essences/essence_file_view_spec.rb index 8a8338999e..3c46c31b5f 100644 --- a/spec/views/essences/essence_file_view_spec.rb +++ b/spec/views/essences/essence_file_view_spec.rb @@ -1,29 +1,29 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" -describe 'alchemy/essences/_essence_file_view' do +describe "alchemy/essences/_essence_file_view" do let(:file) do - File.new(File.expand_path('../../fixtures/image with spaces.png', __dir__)) + File.new(File.expand_path("../../fixtures/image with spaces.png", __dir__)) end let(:attachment) do - build_stubbed(:alchemy_attachment, file: file, name: 'an image', file_name: 'image with spaces.png') + build_stubbed(:alchemy_attachment, file: file, name: "an image", file_name: "image with spaces.png") end let(:essence) { Alchemy::EssenceFile.new(attachment: attachment) } let(:content) { Alchemy::Content.new(essence: essence) } - context 'without attachment' do + context "without attachment" do let(:essence) { Alchemy::EssenceFile.new(attachment: nil) } it "renders nothing" do render content, content: content - expect(rendered).to eq('') + expect(rendered).to eq("") end end - context 'with attachment' do + context "with attachment" do it "renders a link to download the attachment" do render content, content: content expect(rendered).to have_selector( @@ -31,23 +31,23 @@ ) end - context 'with no link_text set' do + context "with no link_text set" do it "has this attachments name as link text" do render content, content: content expect(rendered).to have_selector("a:contains('#{attachment.name}')") end end - context 'with link_text set in the local options' do + context "with link_text set in the local options" do it "has this value as link text" do - render content, content: content, options: {link_text: 'Download this file'} + render content, content: content, options: {link_text: "Download this file"} expect(rendered).to have_selector("a:contains('Download this file')") end end - context 'with link_text set in the content settings' do + context "with link_text set in the content settings" do before do - allow(content).to receive(:settings) { {link_text: 'Download this file'} } + allow(content).to receive(:settings) { {link_text: "Download this file"} } end it "has this value as link text" do @@ -56,9 +56,9 @@ end end - context 'with link_text stored in the essence attribute' do + context "with link_text stored in the essence attribute" do before do - allow(essence).to receive(:link_text) { 'Download this file' } + allow(essence).to receive(:link_text) { "Download this file" } end it "has this value as link text" do @@ -67,9 +67,9 @@ end end - context 'with html_options given' do + context "with html_options given" do it "renders the linked ingredient with these options" do - render content, content: content, html_options: {title: 'Bar', class: 'blue'} + render content, content: content, html_options: {title: "Bar", class: "blue"} expect(rendered).to have_selector('a.blue[title="Bar"]') end end @@ -77,7 +77,7 @@ context "with css_class set" do before do - allow(essence).to receive(:css_class) { 'file-download' } + allow(essence).to receive(:css_class) { "file-download" } end it "has this class at the link" do diff --git a/spec/views/essences/essence_html_view_spec.rb b/spec/views/essences/essence_html_view_spec.rb index f510dfb409..3499809074 100644 --- a/spec/views/essences/essence_html_view_spec.rb +++ b/spec/views/essences/essence_html_view_spec.rb @@ -1,21 +1,21 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" -describe 'alchemy/essences/_essence_html_view' do +describe "alchemy/essences/_essence_html_view" do let(:essence) { Alchemy::EssenceHtml.new(source: '<script>alert("hacked");</script>') } let(:content) { Alchemy::Content.new(essence: essence) } - context 'without value' do + context "without value" do let(:essence) { Alchemy::EssenceHtml.new(source: nil) } it "renders nothing" do render content, content: content - expect(rendered).to eq('') + expect(rendered).to eq("") end end - context 'with value' do + context "with value" do it "renders the raw html source" do render content, content: content expect(rendered).to have_selector("script") diff --git a/spec/views/essences/essence_link_editor_spec.rb b/spec/views/essences/essence_link_editor_spec.rb index 87e474b084..c01d97e5a0 100644 --- a/spec/views/essences/essence_link_editor_spec.rb +++ b/spec/views/essences/essence_link_editor_spec.rb @@ -1,9 +1,9 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" -describe 'alchemy/essences/_essence_link_editor' do - let(:essence) { Alchemy::EssenceLink.new(link: 'http://alchemy-cms.com') } +describe "alchemy/essences/_essence_link_editor" do + let(:essence) { Alchemy::EssenceLink.new(link: "http://alchemy-cms.com") } let(:content) { Alchemy::Content.new(essence: essence) } let(:settings) { {} } diff --git a/spec/views/essences/essence_link_view_spec.rb b/spec/views/essences/essence_link_view_spec.rb index 6f191657ea..94fca8cfff 100644 --- a/spec/views/essences/essence_link_view_spec.rb +++ b/spec/views/essences/essence_link_view_spec.rb @@ -1,18 +1,18 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" -describe 'alchemy/essences/_essence_link_view' do - let(:essence) { Alchemy::EssenceLink.new(link: 'http://google.com') } +describe "alchemy/essences/_essence_link_view" do + let(:essence) { Alchemy::EssenceLink.new(link: "http://google.com") } let(:content) { Alchemy::Content.new(essence: essence) } let(:options) { {} } - context 'without value' do + context "without value" do let(:essence) { Alchemy::EssenceLink.new(link: nil) } it "renders nothing" do render content, content: content, options: options, html_options: {} - expect(rendered).to eq('') + expect(rendered).to eq("") end end @@ -21,8 +21,8 @@ expect(rendered).to eq('<a href="http://google.com">http://google.com</a>') end - context 'with text option' do - let(:options) { {text: 'Google'} } + context "with text option" do + let(:options) { {text: "Google"} } it "renders a link" do render content, content: content, options: options, html_options: {} @@ -30,9 +30,9 @@ end end - context 'with text setting on content definition' do + context "with text setting on content definition" do before do - allow(content).to receive(:settings).and_return({text: 'Yahoo'}) + allow(content).to receive(:settings).and_return({text: "Yahoo"}) end it "renders a link" do diff --git a/spec/views/essences/essence_page_editor_spec.rb b/spec/views/essences/essence_page_editor_spec.rb index f0b28621d1..5b992c5426 100644 --- a/spec/views/essences/essence_page_editor_spec.rb +++ b/spec/views/essences/essence_page_editor_spec.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" -RSpec.describe 'alchemy/essences/_essence_page_editor' do +RSpec.describe "alchemy/essences/_essence_page_editor" do let(:content) { Alchemy::Content.new(essence: essence) } let(:essence) { Alchemy::EssencePage.new } @@ -12,15 +12,15 @@ end subject do - render 'alchemy/essences/essence_page_editor', essence_page_editor: Alchemy::ContentEditor.new(content) + render "alchemy/essences/essence_page_editor", essence_page_editor: Alchemy::ContentEditor.new(content) rendered end it "renders a page input" do - is_expected.to have_css('input.alchemy_selectbox.full_width') + is_expected.to have_css("input.alchemy_selectbox.full_width") end - context 'with a page related to essence' do + context "with a page related to essence" do let(:page) { Alchemy::Page.new(id: 1) } let(:essence) { Alchemy::EssencePage.new(page_id: page.id) } diff --git a/spec/views/essences/essence_page_view_spec.rb b/spec/views/essences/essence_page_view_spec.rb index 03ba04b87e..bc8ddb98a3 100644 --- a/spec/views/essences/essence_page_view_spec.rb +++ b/spec/views/essences/essence_page_view_spec.rb @@ -1,22 +1,22 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" -describe 'alchemy/essences/_essence_page_view' do - let(:page) { build(:alchemy_page, urlname: 'a-page') } +describe "alchemy/essences/_essence_page_view" do + let(:page) { build(:alchemy_page, urlname: "a-page") } let(:essence) { Alchemy::EssencePage.new(page: page) } let(:content) { Alchemy::Content.new(essence: essence) } - context 'without page' do + context "without page" do let(:essence) { Alchemy::EssencePage.new } it "renders nothing" do render content, content: content - expect(rendered).to eq('') + expect(rendered).to eq("") end end - context 'with page' do + context "with page" do it "renders a link to the page" do render content, content: content expect(rendered).to have_selector("a[href='/#{page.urlname}']") diff --git a/spec/views/essences/essence_picture_editor_spec.rb b/spec/views/essences/essence_picture_editor_spec.rb index 722e0c3651..dfc6155ed1 100644 --- a/spec/views/essences/essence_picture_editor_spec.rb +++ b/spec/views/essences/essence_picture_editor_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" describe "essences/_essence_picture_editor" do let(:picture) { stub_model(Alchemy::Picture) } @@ -9,15 +9,15 @@ stub_model( Alchemy::EssencePicture, picture: picture, - caption: 'This is a cute cat', + caption: "This is a cute cat", ) end let(:content) do stub_model( Alchemy::Content, - name: 'image', - essence_type: 'EssencePicture', + name: "image", + essence_type: "EssencePicture", essence: essence_picture, ) end @@ -27,8 +27,8 @@ before do view.class.send(:include, Alchemy::Admin::BaseHelper) view.class.send(:include, Alchemy::Admin::EssencesHelper) - allow(view).to receive(:content_label).and_return('') - allow(view).to receive(:essence_picture_thumbnail).and_return('') + allow(view).to receive(:content_label).and_return("") + allow(view).to receive(:essence_picture_thumbnail).and_return("") end subject do @@ -39,7 +39,7 @@ end context "with settings[:deletable] being nil" do - it 'should not render a button to link and unlink the picture' do + it "should not render a button to link and unlink the picture" do is_expected.to have_selector("a .icon.fa-link") is_expected.to have_selector("a .icon.fa-unlink") end @@ -52,34 +52,34 @@ } end - it 'should not render a button to link and unlink the picture' do + it "should not render a button to link and unlink the picture" do is_expected.to_not have_selector("a .icon.fa-link") is_expected.to_not have_selector("a .icon.fa-unlink") end - it 'but renders the disabled link and unlink icons' do + it "but renders the disabled link and unlink icons" do is_expected.to have_selector(".icon.fa-link") is_expected.to have_selector(".icon.fa-unlink") end end - context 'with allow_image_cropping? true' do + context "with allow_image_cropping? true" do before do allow(essence_picture).to receive(:allow_image_cropping?) { true } end - it 'shows cropping link' do + it "shows cropping link" do is_expected.to have_selector('a[href*="crop"]') end end - context 'with allow_image_cropping? false' do + context "with allow_image_cropping? false" do before do allow(essence_picture).to receive(:allow_image_cropping?) { false } end - it 'shows disabled cropping link' do - is_expected.to have_selector('a.disabled .icon.fa-crop') + it "shows disabled cropping link" do + is_expected.to have_selector("a.disabled .icon.fa-crop") end end end diff --git a/spec/views/essences/essence_richtext_view_spec.rb b/spec/views/essences/essence_richtext_view_spec.rb index 94c03c7bf8..d838c52005 100644 --- a/spec/views/essences/essence_richtext_view_spec.rb +++ b/spec/views/essences/essence_richtext_view_spec.rb @@ -1,34 +1,34 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" -describe 'alchemy/essences/_essence_richtext_view' do - let(:essence) { Alchemy::EssenceRichtext.new(body: '<h1>Lorem ipsum dolor sit amet</h1> <p>consectetur adipiscing elit.</p>', stripped_body: 'Lorem ipsum dolor sit amet consectetur adipiscing elit.') } +describe "alchemy/essences/_essence_richtext_view" do + let(:essence) { Alchemy::EssenceRichtext.new(body: "<h1>Lorem ipsum dolor sit amet</h1> <p>consectetur adipiscing elit.</p>", stripped_body: "Lorem ipsum dolor sit amet consectetur adipiscing elit.") } let(:content) { Alchemy::Content.new(essence: essence) } it "renders the html body" do render content, content: content - expect(rendered).to have_content('Lorem ipsum dolor sit amet consectetur adipiscing elit.') - expect(rendered).to have_selector('h1') + expect(rendered).to have_content("Lorem ipsum dolor sit amet consectetur adipiscing elit.") + expect(rendered).to have_selector("h1") end - context 'with options[:plain_text] true' do + context "with options[:plain_text] true" do it "renders the text body" do render content, content: content, options: {plain_text: true} - expect(rendered).to have_content('Lorem ipsum dolor sit amet consectetur adipiscing elit.') - expect(rendered).to_not have_selector('h1') + expect(rendered).to have_content("Lorem ipsum dolor sit amet consectetur adipiscing elit.") + expect(rendered).to_not have_selector("h1") end end - context 'with content.settings[:plain_text] true' do + context "with content.settings[:plain_text] true" do before do allow(content).to receive(:settings).and_return({plain_text: true}) end it "renders the text body" do render content.essence, content: content - expect(rendered).to have_content('Lorem ipsum dolor sit amet consectetur adipiscing elit.') - expect(rendered).to_not have_selector('h1') + expect(rendered).to have_content("Lorem ipsum dolor sit amet consectetur adipiscing elit.") + expect(rendered).to_not have_selector("h1") end end end diff --git a/spec/views/essences/essence_select_editor_spec.rb b/spec/views/essences/essence_select_editor_spec.rb index 1c015662c0..f6f83f65af 100644 --- a/spec/views/essences/essence_select_editor_spec.rb +++ b/spec/views/essences/essence_select_editor_spec.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" -RSpec.describe 'alchemy/essences/_essence_select_editor' do +RSpec.describe "alchemy/essences/_essence_select_editor" do let(:content) { Alchemy::Content.new(essence: essence) } let(:essence) { Alchemy::EssenceSelect.new } @@ -12,17 +12,17 @@ end subject do - render 'alchemy/essences/essence_select_editor', essence_select_editor: Alchemy::ContentEditor.new(content) + render "alchemy/essences/essence_select_editor", essence_select_editor: Alchemy::ContentEditor.new(content) rendered end - context 'if no select values are set' do - it 'renders a warning' do - is_expected.to have_css('.warning') + context "if no select values are set" do + it "renders a warning" do + is_expected.to have_css(".warning") end end - context 'if select values are set' do + context "if select values are set" do before do expect(content).to receive(:settings).at_least(:once) do { @@ -32,7 +32,7 @@ end it "renders a select box" do - is_expected.to have_css('select.alchemy_selectbox') + is_expected.to have_css("select.alchemy_selectbox") end end end diff --git a/spec/views/essences/essence_select_view_spec.rb b/spec/views/essences/essence_select_view_spec.rb index 64bad44ea5..5e260f7bc7 100644 --- a/spec/views/essences/essence_select_view_spec.rb +++ b/spec/views/essences/essence_select_view_spec.rb @@ -1,13 +1,13 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" -describe 'alchemy/essences/_essence_select_view' do +describe "alchemy/essences/_essence_select_view" do let(:content) { Alchemy::Content.new(essence: essence) } - let(:essence) { Alchemy::EssenceSelect.new(ingredient: 'blue') } + let(:essence) { Alchemy::EssenceSelect.new(ingredient: "blue") } it "renders the ingredient" do render content, content: content - expect(rendered).to have_content('blue') + expect(rendered).to have_content("blue") end end diff --git a/spec/views/essences/essence_text_editor_spec.rb b/spec/views/essences/essence_text_editor_spec.rb index 3280b5600b..f976929760 100644 --- a/spec/views/essences/essence_text_editor_spec.rb +++ b/spec/views/essences/essence_text_editor_spec.rb @@ -1,9 +1,9 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" -describe 'alchemy/essences/_essence_text_editor' do - let(:essence) { Alchemy::EssenceText.new(body: '1234') } +describe "alchemy/essences/_essence_text_editor" do + let(:essence) { Alchemy::EssenceText.new(body: "1234") } let(:content) { Alchemy::Content.new(essence: essence) } let(:settings) { {} } @@ -16,13 +16,13 @@ } end - context 'with no input type set' do + context "with no input type set" do it "renders an input field of type number" do expect(rendered).to have_selector('input[type="text"]') end end - context 'with a different input type set' do + context "with a different input type set" do let(:settings) do { input_type: "number", @@ -34,7 +34,7 @@ end end - context 'with settings linkable set to true' do + context "with settings linkable set to true" do let(:settings) do { linkable: true, diff --git a/spec/views/essences/essence_text_view_spec.rb b/spec/views/essences/essence_text_view_spec.rb index 06048182ef..b3df308bbd 100644 --- a/spec/views/essences/essence_text_view_spec.rb +++ b/spec/views/essences/essence_text_view_spec.rb @@ -1,52 +1,52 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" -describe 'alchemy/essences/_essence_text_view' do - let(:essence) { Alchemy::EssenceText.new(body: 'Hello World') } +describe "alchemy/essences/_essence_text_view" do + let(:essence) { Alchemy::EssenceText.new(body: "Hello World") } let(:content) { Alchemy::Content.new(essence: essence) } - context 'with blank link value' do + context "with blank link value" do it "only renders the ingredient" do render content, content: content - expect(rendered).to have_content('Hello World') - expect(rendered).to_not have_selector('a') + expect(rendered).to have_content("Hello World") + expect(rendered).to_not have_selector("a") end end - context 'with a link set' do - let(:essence) { Alchemy::EssenceText.new(body: 'Hello World', link: 'http://google.com', link_title: 'Foo', link_target: 'blank') } + context "with a link set" do + let(:essence) { Alchemy::EssenceText.new(body: "Hello World", link: "http://google.com", link_title: "Foo", link_target: "blank") } it "renders the linked ingredient" do render content, content: content - expect(rendered).to have_content('Hello World') + expect(rendered).to have_content("Hello World") expect(rendered).to have_selector('a[title="Foo"][target="_blank"][data-link-target="blank"][href="http://google.com"]') end - context 'with html_options given' do + context "with html_options given" do it "renders the linked with these options" do - render content, content: content, html_options: {title: 'Bar', class: 'blue'} + render content, content: content, html_options: {title: "Bar", class: "blue"} expect(rendered).to have_selector('a.blue[title="Bar"][target="_blank"][data-link-target="blank"]') end end - context 'but with options disable_link set to true' do + context "but with options disable_link set to true" do it "only renders the ingredient" do render content, content: content, options: {disable_link: true} - expect(rendered).to have_content('Hello World') - expect(rendered).to_not have_selector('a') + expect(rendered).to have_content("Hello World") + expect(rendered).to_not have_selector("a") end end - context 'but with content settings disable_link set to true' do + context "but with content settings disable_link set to true" do before do allow(content).to receive(:settings).and_return({disable_link: true}) end it "only renders the ingredient" do render content.essence, content: content - expect(rendered).to have_content('Hello World') - expect(rendered).to_not have_selector('a') + expect(rendered).to have_content("Hello World") + expect(rendered).to_not have_selector("a") end end end diff --git a/spec/views/pages/meta_data_spec.rb b/spec/views/pages/meta_data_spec.rb index 7aa1937521..67aa23d9fd 100644 --- a/spec/views/pages/meta_data_spec.rb +++ b/spec/views/pages/meta_data_spec.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true -require 'rails_helper' +require "rails_helper" module Alchemy - describe 'alchemy/pages/_meta_data' do + describe "alchemy/pages/_meta_data" do let!(:language) { create(:alchemy_language, code: :en) } let(:root_page) { Page.new } let(:page) { Page.new(language_code: "en", title: "Road Runner", urlname: "roadrunner") } @@ -15,11 +15,11 @@ module Alchemy end context "when current page is set" do - before { view.instance_variable_set('@page', page) } + before { view.instance_variable_set("@page", page) } describe "meta keywords" do context "are set" do - before { allow(page).to receive_messages(meta_keywords: 'cartoon, road runner') } + before { allow(page).to receive_messages(meta_keywords: "cartoon, road runner") } it "renders the keywords in the correct meta tag" do is_expected.to match /meta name="keywords" content="cartoon, road runner" lang="en"/ @@ -47,7 +47,7 @@ module Alchemy describe "meta description" do context "is set" do - before { allow(page).to receive_messages(meta_description: 'road runner goes meep meep') } + before { allow(page).to receive_messages(meta_description: "road runner goes meep meep") } it "renders the description in the correct meta tag" do is_expected.to match /meta name="description" content="road runner goes meep meep"/ From 88cf055496d80ed56256bee0c4920a190101bd70 Mon Sep 17 00:00:00 2001 From: Thomas von Deyen <thomas@vondeyen.com> Date: Wed, 29 Apr 2020 21:40:55 +0200 Subject: [PATCH 5/5] Add Rufo as local dev dependency --- Gemfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Gemfile b/Gemfile index d87714e381..0bb99d75d7 100644 --- a/Gemfile +++ b/Gemfile @@ -29,5 +29,6 @@ group :development, :test do gem "github_fast_changelog", require: false gem "active_record_query_trace", require: false gem "rack-mini-profiler", require: false + gem "rufo", require: false end end