diff --git a/.hound.yml b/.hound.yml index dc6c8238f2..c950b073a9 100644 --- a/.hound.yml +++ b/.hound.yml @@ -1,5 +1,6 @@ -ruby: +rubocop: config_file: .rubocop.yml + version: 0.80.0 scss: enabled: false coffeescript: diff --git a/.rubocop.yml b/.rubocop.yml index 988f375927..076dc5c8a0 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,6 +1,7 @@ # Relaxed.Ruby.Style AllCops: + TargetRubyVersion: 2.3 Exclude: - 'bin/rspec' - 'vendor/**/*' @@ -9,17 +10,10 @@ AllCops: - 'alchemy_cms.gemspec' - 'Rakefile' - TargetRubyVersion: 2.3 - # Really, rubocop? Bundler/OrderedGems: Enabled: false -# Sometimes I believe this reads better -# This also causes spacing issues on multi-line fixes -Style/BracesAroundHashParameters: - Enabled: false - Style/EmptyLiteral: Enabled: false @@ -27,6 +21,9 @@ Style/EmptyLiteral: Style/ClassVars: Enabled: false +Style/FloatDivision: + EnforcedStyle: left_coerce + # This has been used for customization Style/MutableConstant: Enabled: false @@ -55,13 +52,13 @@ Style/MixinUsage: Exclude: - spec/**/* -Performance/Count: +Layout/ArgumentAlignment: Enabled: false -Layout/AlignHash: +Layout/HashAlignment: Enabled: false -Layout/AlignParameters: +Layout/ParameterAlignment: Enabled: false Layout/ClosingParenthesisIndentation: @@ -77,18 +74,22 @@ Layout/ElseAlignment: Layout/EmptyLineAfterMagicComment: Enabled: false -Layout/IndentArray: - Enabled: false +Layout/EmptyLinesAroundAccessModifier: + Exclude: + - lib/alchemy/test_support/factories/*.rb -Layout/IndentHash: +Layout/FirstArrayElementIndentation: Enabled: false -Layout/IndentHeredoc: - EnforcedStyle: active_support +Layout/FirstHashElementIndentation: + Enabled: false Layout/IndentationWidth: Enabled: false +Layout/LineLength: + Enabled: false + Layout/MultilineHashBraceLayout: Enabled: false @@ -115,7 +116,10 @@ Layout/SpaceInsideParens: Layout/EndAlignment: Enabled: false -Lint/HandleExceptions: +Layout/RescueEnsureAlignment: + Enabled: false + +Lint/SuppressedException: Exclude: - 'config/initializers/mini_profiler.rb' @@ -268,9 +272,6 @@ Metrics/ModuleLength: Metrics/CyclomaticComplexity: Enabled: false -Metrics/LineLength: - Enabled: false - Metrics/MethodLength: Enabled: false diff --git a/Gemfile b/Gemfile index 887b709c26..e43124be57 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,4 @@ +# frozen_string_literal: true source 'https://rubygems.org' gemspec @@ -21,7 +22,7 @@ group :development, :test do gem 'yard' gem 'redcarpet' gem 'pry-byebug' - gem 'rubocop', '0.54', require: false + gem 'rubocop', '~> 0.80.1', require: false gem 'listen' gem 'localeapp', '~> 3.0', require: false gem 'dotenv', '~> 2.2' diff --git a/app/controllers/alchemy/admin/base_controller.rb b/app/controllers/alchemy/admin/base_controller.rb index 764830370b..da2c916f06 100644 --- a/app/controllers/alchemy/admin/base_controller.rb +++ b/app/controllers/alchemy/admin/base_controller.rb @@ -89,6 +89,7 @@ def reset_stamper # Returns true if the current_alchemy_user (The logged-in Alchemy User) has the admin role. def is_admin? return false if !current_alchemy_user + current_alchemy_user.admin? end diff --git a/app/controllers/alchemy/admin/clipboard_controller.rb b/app/controllers/alchemy/admin/clipboard_controller.rb index 1c81b0ac49..3977e72ede 100644 --- a/app/controllers/alchemy/admin/clipboard_controller.rb +++ b/app/controllers/alchemy/admin/clipboard_controller.rb @@ -48,6 +48,7 @@ def set_clipboard def model_class raise ActionController::BadRequest unless remarkable_type + "alchemy/#{remarkable_type}".classify.constantize end diff --git a/app/controllers/alchemy/admin/dashboard_controller.rb b/app/controllers/alchemy/admin/dashboard_controller.rb index 3e50bc8ad6..0ec91fcedc 100644 --- a/app/controllers/alchemy/admin/dashboard_controller.rb +++ b/app/controllers/alchemy/admin/dashboard_controller.rb @@ -42,6 +42,7 @@ def update_check def latest_alchemy_version versions = get_alchemy_versions return '' if versions.blank? + # reject any non release version versions.reject! { |v| v =~ /[a-z]/ } versions.max diff --git a/app/controllers/alchemy/admin/essence_pictures_controller.rb b/app/controllers/alchemy/admin/essence_pictures_controller.rb index 561f77fdf5..3f736c17ea 100644 --- a/app/controllers/alchemy/admin/essence_pictures_controller.rb +++ b/app/controllers/alchemy/admin/essence_pictures_controller.rb @@ -87,7 +87,7 @@ def ratio_from_size_or_settings if @min_size.value?(0) && @essence_picture.content.settings[:fixed_ratio].to_s =~ FLOAT_REGEX @essence_picture.content.settings[:fixed_ratio].to_f elsif !@min_size[:width].zero? && !@min_size[:height].zero? - @min_size[:width].to_f / @min_size[:height].to_f + @min_size[:width].to_f / @min_size[:height] else false end diff --git a/app/controllers/alchemy/admin/pages_controller.rb b/app/controllers/alchemy/admin/pages_controller.rb index c6b19da21a..9fd0feee64 100644 --- a/app/controllers/alchemy/admin/pages_controller.rb +++ b/app/controllers/alchemy/admin/pages_controller.rb @@ -351,11 +351,13 @@ def secure_attributes def page_is_locked? return false if !@page.locker.try(:logged_in?) return false if !current_alchemy_user.respond_to?(:id) + @page.locked? && @page.locker.id != current_alchemy_user.id end def page_needs_lock? return true unless @page.locker + @page.locker.try!(:id) != current_alchemy_user.try!(:id) end diff --git a/app/controllers/alchemy/admin/pictures_controller.rb b/app/controllers/alchemy/admin/pictures_controller.rb index c92628bb75..75354555ed 100644 --- a/app/controllers/alchemy/admin/pictures_controller.rb +++ b/app/controllers/alchemy/admin/pictures_controller.rb @@ -123,8 +123,8 @@ def items_per_page end else cookies[:alchemy_pictures_per_page] = params[:per_page] || - cookies[:alchemy_pictures_per_page] || - pictures_per_page_for_size(params[:size]) + cookies[:alchemy_pictures_per_page] || + pictures_per_page_for_size(params[:size]) end end diff --git a/app/controllers/alchemy/admin/resources_controller.rb b/app/controllers/alchemy/admin/resources_controller.rb index 015c03e2d6..e6079942c8 100644 --- a/app/controllers/alchemy/admin/resources_controller.rb +++ b/app/controllers/alchemy/admin/resources_controller.rb @@ -93,6 +93,7 @@ def resource_handler # The key should look like "Modelname successfully created|updated|destroyed." def flash_notice_for_resource_action(action = params[:action]) return if resource_instance_variable.errors.any? + case action.to_sym when :create verb = "created" diff --git a/app/controllers/alchemy/admin/styleguide_controller.rb b/app/controllers/alchemy/admin/styleguide_controller.rb index e863c8abc6..16473cb13a 100644 --- a/app/controllers/alchemy/admin/styleguide_controller.rb +++ b/app/controllers/alchemy/admin/styleguide_controller.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module Alchemy module Admin class StyleguideController < BaseController diff --git a/app/controllers/alchemy/admin/tags_controller.rb b/app/controllers/alchemy/admin/tags_controller.rb index c219e44f4b..d418b7aca9 100644 --- a/app/controllers/alchemy/admin/tags_controller.rb +++ b/app/controllers/alchemy/admin/tags_controller.rb @@ -66,6 +66,7 @@ def tag_params def tags_from_term(term) return [] if term.blank? + Gutentag::Tag.where(['LOWER(name) LIKE ?', "#{term.downcase}%"]) end diff --git a/app/controllers/alchemy/base_controller.rb b/app/controllers/alchemy/base_controller.rb index 5f42290e40..5b7afc0382 100644 --- a/app/controllers/alchemy/base_controller.rb +++ b/app/controllers/alchemy/base_controller.rb @@ -98,7 +98,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.to_s}/, '') + 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 630d21956c..1503f71b6e 100644 --- a/app/controllers/alchemy/messages_controller.rb +++ b/app/controllers/alchemy/messages_controller.rb @@ -60,6 +60,7 @@ def create #:nodoc: if @element.nil? raise ActiveRecord::RecordNotFound, "Contact form id not found. Please pass the :contact_form_id in a hidden field. Example: <%= f.hidden_field :contact_form_id, value: element.id %>" end + @page = @element.page @root_page = @page.get_language_root if @message.valid? @@ -121,6 +122,7 @@ def get_page if @page.blank? raise "Page for page_layout #{mailer_config['page_layout_name']} not found" end + @root_page = @page.get_language_root end diff --git a/app/controllers/concerns/alchemy/admin/archive_overlay.rb b/app/controllers/concerns/alchemy/admin/archive_overlay.rb index 7b1d967a38..782228a730 100644 --- a/app/controllers/concerns/alchemy/admin/archive_overlay.rb +++ b/app/controllers/concerns/alchemy/admin/archive_overlay.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module Alchemy module Admin module ArchiveOverlay diff --git a/app/decorators/alchemy/element_editor.rb b/app/decorators/alchemy/element_editor.rb index ae9c4e1f7b..ba2b1ce838 100644 --- a/app/decorators/alchemy/element_editor.rb +++ b/app/decorators/alchemy/element_editor.rb @@ -24,6 +24,7 @@ def css_classes # Tells us, if we should show the element footer and form inputs. def editable? return false if folded? + content_definitions.present? || taggable? end diff --git a/app/helpers/alchemy/admin/base_helper.rb b/app/helpers/alchemy/admin/base_helper.rb index e8a04d5e16..ca7afd44c0 100644 --- a/app/helpers/alchemy/admin/base_helper.rb +++ b/app/helpers/alchemy/admin/base_helper.rb @@ -373,6 +373,7 @@ def alchemy_datepicker(object, method, html_options = {}) # The model class needs to include the hints module 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') diff --git a/app/helpers/alchemy/admin/elements_helper.rb b/app/helpers/alchemy/admin/elements_helper.rb index 7be2c728b6..07b01eb8ca 100644 --- a/app/helpers/alchemy/admin/elements_helper.rb +++ b/app/helpers/alchemy/admin/elements_helper.rb @@ -13,6 +13,7 @@ module ElementsHelper # def elements_for_select(elements) return [] if elements.nil? + elements.collect do |e| [ Element.display_name_for(e['name']), diff --git a/app/helpers/alchemy/admin/navigation_helper.rb b/app/helpers/alchemy/admin/navigation_helper.rb index 98651fa626..846e08a628 100644 --- a/app/helpers/alchemy/admin/navigation_helper.rb +++ b/app/helpers/alchemy/admin/navigation_helper.rb @@ -91,6 +91,7 @@ def url_for_module(alchemy_module) def url_for_module_sub_navigation(navigation) alchemy_module = module_definition_for(navigation) return if alchemy_module.nil? + route_from_engine_or_main_app( alchemy_module['engine_name'], url_options_for_navigation_entry(navigation) diff --git a/app/helpers/alchemy/admin/tags_helper.rb b/app/helpers/alchemy/admin/tags_helper.rb index 23e3133bb1..c9e7a9709a 100644 --- a/app/helpers/alchemy/admin/tags_helper.rb +++ b/app/helpers/alchemy/admin/tags_helper.rb @@ -13,6 +13,7 @@ module TagsHelper # def render_tag_list(class_name) 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 link_to( diff --git a/app/helpers/alchemy/base_helper.rb b/app/helpers/alchemy/base_helper.rb index 90787bd404..288da66e72 100644 --- a/app/helpers/alchemy/base_helper.rb +++ b/app/helpers/alchemy/base_helper.rb @@ -76,7 +76,7 @@ def page_or_find(page) end if page.blank? warning("No Page found for #{page.inspect}") - return + nil else page end diff --git a/app/helpers/alchemy/elements_helper.rb b/app/helpers/alchemy/elements_helper.rb index cfc50b71fd..981ee81503 100644 --- a/app/helpers/alchemy/elements_helper.rb +++ b/app/helpers/alchemy/elements_helper.rb @@ -173,6 +173,7 @@ def render_element(element, options = {}, counter = 1) # Returns a string for the id attribute of a html element for the given element def element_dom_id(element) return "" if element.nil? + "#{element.name}_#{element.id}".html_safe end @@ -189,6 +190,7 @@ def element_preview_code(element) # Returns a hash containing the HTML tag attributes required for preview mode. def element_preview_code_attributes(element) return {} unless element.present? && @preview_mode && element.page == @page + { 'data-alchemy-element' => element.id } end @@ -226,6 +228,7 @@ def element_tags_attributes(element, options = {}) }.merge(options) return {} if !element.taggable? || element.tag_list.blank? + { 'data-element-tags' => options[:formatter].call(element.tag_list) } end end diff --git a/app/helpers/alchemy/pages_helper.rb b/app/helpers/alchemy/pages_helper.rb index 414d9cebe1..5aa80e8c88 100644 --- a/app/helpers/alchemy/pages_helper.rb +++ b/app/helpers/alchemy/pages_helper.rb @@ -32,6 +32,7 @@ def language_links(options = {}) }.merge(options) languages = Language.on_current_site.published.with_root_page.order("name #{options[:reverse] ? 'DESC' : 'ASC'}") return nil if languages.count < 2 + render( partial: "alchemy/language_links/language", collection: languages, @@ -152,6 +153,7 @@ def render_breadcrumb(options = {}) # def page_title(options = {}) return "" if @page.title.blank? + options = { prefix: "", suffix: "", diff --git a/app/helpers/alchemy/url_helper.rb b/app/helpers/alchemy/url_helper.rb index 4360ead609..0ce6846d80 100644 --- a/app/helpers/alchemy/url_helper.rb +++ b/app/helpers/alchemy/url_helper.rb @@ -19,6 +19,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? + url_params = {urlname: page.urlname}.update(optional_params) prefix_locale? ? url_params.update(locale: page.language_code) : url_params end diff --git a/app/models/alchemy/attachment.rb b/app/models/alchemy/attachment.rb index 9a51accb20..a3b9a451eb 100644 --- a/app/models/alchemy/attachment.rb +++ b/app/models/alchemy/attachment.rb @@ -96,23 +96,23 @@ def extension def icon_css_class case file_mime_type when "application/pdf" - then "file-pdf" + "file-pdf" when "application/msword" - then "file-word" + "file-word" when *TEXT_FILE_TYPES - then "file-alt" + "file-alt" when *EXCEL_FILE_TYPES - then "file-excel" + "file-excel" when *VCARD_FILE_TYPES - then "address-card" + "address-card" when *ARCHIVE_FILE_TYPES - then "file-archive" + "file-archive" when *AUDIO_FILE_TYPES - then "file-audio" + "file-audio" when *IMAGE_FILE_TYPES - then "file-image" + "file-image" when *VIDEO_FILE_TYPES - then "file-video" + "file-video" else "file" end diff --git a/app/models/alchemy/base_record.rb b/app/models/alchemy/base_record.rb index 421d64f182..3a023c6460 100644 --- a/app/models/alchemy/base_record.rb +++ b/app/models/alchemy/base_record.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module Alchemy def self.table_name_prefix 'alchemy_' diff --git a/app/models/alchemy/content.rb b/app/models/alchemy/content.rb index f8594e7610..25621726c7 100644 --- a/app/models/alchemy/content.rb +++ b/app/models/alchemy/content.rb @@ -99,6 +99,7 @@ def to_partial_path # Settings from the elements.yml definition def settings return {} if definition.blank? + @settings ||= definition.fetch(:settings, {}) end @@ -114,12 +115,14 @@ def settings_value(key, options = {}) def siblings return [] if !element + element.contents end # Gets the ingredient from essence def ingredient return nil if essence.nil? + essence.ingredient end @@ -145,6 +148,7 @@ def serialized_ingredient # Sets the ingredient from essence def ingredient=(value) raise EssenceMissingError if essence.nil? + essence.ingredient = value end @@ -156,11 +160,12 @@ def ingredient=(value) # def update_essence(params = {}) raise EssenceMissingError if essence.nil? + if essence.update(params) - return true + true else errors.add(:essence, :validation_failed) - return false + false end end @@ -175,6 +180,7 @@ def has_validations? # Returns a string used as dom id on html elements. def dom_id return '' if essence.nil? + "#{essence_partial_name}_#{id}" end @@ -200,6 +206,7 @@ def preview_text(maxlength = 30) def essence_partial_name 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 0fa2203870..c01ba3505b 100644 --- a/app/models/alchemy/content/factory.rb +++ b/app/models/alchemy/content/factory.rb @@ -22,6 +22,7 @@ def new(attributes = {}) if definition.blank? raise ContentDefinitionError, "No definition found in elements.yml for #{attributes.inspect} and #{element.inspect}" end + super( name: definition[:name], essence_type: normalize_essence_type(definition[:type]), diff --git a/app/models/alchemy/element.rb b/app/models/alchemy/element.rb index ad3c7f213b..2385a3269c 100644 --- a/app/models/alchemy/element.rb +++ b/app/models/alchemy/element.rb @@ -131,6 +131,7 @@ class << self # def new(attributes = {}) return super if attributes[:name].blank? + element_attributes = attributes.to_h.merge(name: attributes[:name].split('#').first) element_definition = Element.definition_by_name(element_attributes[:name]) if element_definition.nil? @@ -176,6 +177,7 @@ def copy(source_element, differences = {}) def all_from_clipboard(clipboard) return [] if clipboard.nil? + where(id: clipboard.collect { |e| e['id'] }) end @@ -183,6 +185,7 @@ def all_from_clipboard(clipboard) # def all_from_clipboard_for_page(clipboard, page) return [] if clipboard.nil? || page.nil? + all_from_clipboard(clipboard).select { |ce| page.available_element_names.include?(ce.name) } @@ -210,6 +213,7 @@ def prev(name = nil) # Stores the page into +touchable_pages+ (Pages that have to be touched after updating the element). def store_page(page) return true if page.nil? + unless touchable_pages.include? page touchable_pages << page end @@ -311,6 +315,7 @@ def select_element(elements, name, order) # def touch_touchable_pages return unless respond_to?(:touchable_pages) + touchable_pages.each(&:touch) end end diff --git a/app/models/alchemy/element/element_contents.rb b/app/models/alchemy/element/element_contents.rb index 3ad95082e5..254b941740 100644 --- a/app/models/alchemy/element/element_contents.rb +++ b/app/models/alchemy/element/element_contents.rb @@ -47,6 +47,7 @@ def contents_by_type(essence_type) # def update_contents(contents_attributes) return true if contents_attributes.nil? + contents.each do |content| content_hash = contents_attributes[content.id.to_s] || next content.update_essence(content_hash) || errors.add(:base, :essence_validation_failed) @@ -92,6 +93,7 @@ def content_for_rss_description # 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'] end @@ -136,6 +138,7 @@ def contents_with_errors 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'] } end diff --git a/app/models/alchemy/element/element_essences.rb b/app/models/alchemy/element/element_essences.rb index 1e872011d9..706cde4fb2 100644 --- a/app/models/alchemy/element/element_essences.rb +++ b/app/models/alchemy/element/element_essences.rb @@ -6,6 +6,7 @@ module Element::ElementEssences def ingredient(name) content = content_by_name(name) return nil if content.blank? + content.ingredient end diff --git a/app/models/alchemy/element/presenters.rb b/app/models/alchemy/element/presenters.rb index bf97ee73e1..2f08573ef1 100644 --- a/app/models/alchemy/element/presenters.rb +++ b/app/models/alchemy/element/presenters.rb @@ -97,6 +97,7 @@ def preview_content def preview_text_from_nested_elements(maxlength) return if all_nested_elements.empty? + all_nested_elements.first.preview_text(maxlength) end diff --git a/app/models/alchemy/essence_date.rb b/app/models/alchemy/essence_date.rb index d7b12d292a..8b4bfa8534 100644 --- a/app/models/alchemy/essence_date.rb +++ b/app/models/alchemy/essence_date.rb @@ -19,6 +19,7 @@ class EssenceDate < BaseRecord # Returns self.date for the Element#preview_text method. def preview_text(_maxlength = nil) return "" if date.blank? + ::I18n.l(date, format: :'alchemy.essence_date') end end diff --git a/app/models/alchemy/essence_file.rb b/app/models/alchemy/essence_file.rb index ff36669fd8..c732875553 100644 --- a/app/models/alchemy/essence_file.rb +++ b/app/models/alchemy/essence_file.rb @@ -22,6 +22,7 @@ class EssenceFile < BaseRecord def attachment_url return if attachment.nil? + routes.download_attachment_path( id: attachment.id, name: attachment.urlname, @@ -31,6 +32,7 @@ def attachment_url def preview_text(max = 30) return "" if attachment.blank? + attachment.name.to_s[0..max - 1] end diff --git a/app/models/alchemy/essence_picture.rb b/app/models/alchemy/essence_picture.rb index fe949e1f42..4acb98e755 100644 --- a/app/models/alchemy/essence_picture.rb +++ b/app/models/alchemy/essence_picture.rb @@ -116,6 +116,7 @@ def thumbnail_url # @return [String] def preview_text(max = 30) return "" if picture.nil? + picture.name.to_s[0..max - 1] end @@ -124,6 +125,7 @@ def preview_text(max = 30) # @return [Hash] def cropping_mask return if crop_from.blank? || crop_size.blank? + crop_from = point_from_string(read_attribute(:crop_from)) crop_size = sizes_from_string(read_attribute(:crop_size)) @@ -166,11 +168,12 @@ def normalize_crop_value(crop_value) def normalize_number(number) number = number.to_f.round - number < 0 ? 0 : number + number.negative? ? 0 : number end def replace_newlines return nil if caption.nil? + caption.gsub!(/(\r\n|\r|\n)/, "
") end end diff --git a/app/models/alchemy/essence_picture_view.rb b/app/models/alchemy/essence_picture_view.rb index e5c5348b10..30c1f6e3d0 100644 --- a/app/models/alchemy/essence_picture_view.rb +++ b/app/models/alchemy/essence_picture_view.rb @@ -48,6 +48,7 @@ def render def caption return unless show_caption? + @_caption ||= content_tag(:figcaption, essence.caption) end diff --git a/app/models/alchemy/folded_page.rb b/app/models/alchemy/folded_page.rb index 9e7a41d109..6c3b9f370b 100644 --- a/app/models/alchemy/folded_page.rb +++ b/app/models/alchemy/folded_page.rb @@ -17,6 +17,7 @@ class FoldedPage < BaseRecord def self.folded_for_user(user) return none unless Alchemy.user_class < ActiveRecord::Base + where(user: user, folded: true) end end diff --git a/app/models/alchemy/language.rb b/app/models/alchemy/language.rb index a9d9b46275..b429fb82ec 100644 --- a/app/models/alchemy/language.rb +++ b/app/models/alchemy/language.rb @@ -157,6 +157,7 @@ def presence_of_default_language def remove_old_default lang = Language.on_site(site).default return true if lang.nil? + lang.default = false lang.save(validate: false) end diff --git a/app/models/alchemy/node.rb b/app/models/alchemy/node.rb index 20de97fb69..aa540fda5f 100644 --- a/app/models/alchemy/node.rb +++ b/app/models/alchemy/node.rb @@ -26,6 +26,7 @@ class << self # Returns all root nodes for current language def language_root_nodes raise 'No language found' if Language.current.nil? + roots.where(language_id: Language.current.id) end end diff --git a/app/models/alchemy/page.rb b/app/models/alchemy/page.rb index 01b926456e..f4d6b051d9 100644 --- a/app/models/alchemy/page.rb +++ b/app/models/alchemy/page.rb @@ -224,6 +224,7 @@ def layout_root_for(language_id) def find_or_create_layout_root_for(language_id) layoutroot = layout_root_for(language_id) return layoutroot if layoutroot + language = Language.find(language_id) Page.create!( name: "Layoutroot for #{language.name}", @@ -249,11 +250,13 @@ 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'] }) end def all_from_clipboard_for_select(clipboard, language_id, layoutpage = false) return [] if clipboard.blank? + 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'] } @@ -274,6 +277,7 @@ def link_target_options # I.e. used to find the active page in navigation. def ancestors_for(current) return [] if current.nil? + current.self_and_ancestors.contentpages end @@ -307,6 +311,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')})" end end @@ -427,6 +432,7 @@ def get_language_root def copy_children_to(new_parent) children.each do |child| next if child == new_parent + new_child = Page.copy(child, { language_id: new_parent.language_id, language_code: new_parent.language_code @@ -488,6 +494,7 @@ def attribute_fixed?(name) # def editable_by?(user) return true unless has_limited_editors? + (editor_roles & user.alchemy_roles).any? end diff --git a/app/models/alchemy/page/fixed_attributes.rb b/app/models/alchemy/page/fixed_attributes.rb index 9c3cf37f96..9a91116d92 100644 --- a/app/models/alchemy/page/fixed_attributes.rb +++ b/app/models/alchemy/page/fixed_attributes.rb @@ -52,6 +52,7 @@ def any? # def fixed?(name) return false if name.nil? + attributes.key?(name.to_sym) end @@ -59,6 +60,7 @@ def fixed?(name) # def [](name) return nil if name.nil? + attributes[name.to_sym] end end diff --git a/app/models/alchemy/page/page_elements.rb b/app/models/alchemy/page/page_elements.rb index ebd509b734..7caa06ce01 100644 --- a/app/models/alchemy/page/page_elements.rb +++ b/app/models/alchemy/page/page_elements.rb @@ -197,6 +197,7 @@ def generate_elements existing_element_names = existing_elements.pluck(:name).uniq definition.fetch('autogenerate', []).each do |element_name| next if existing_element_names.include?(element_name) + Element.create(page: self, name: element_name) end end diff --git a/app/models/alchemy/page/page_naming.rb b/app/models/alchemy/page/page_naming.rb index 26617172bf..dd55a5668f 100644 --- a/app/models/alchemy/page/page_naming.rb +++ b/app/models/alchemy/page/page_naming.rb @@ -52,6 +52,7 @@ def slug # Returns an array of visible/non-language_root ancestors. def visible_ancestors return [] unless parent + if new_record? parent.visible_ancestors.tap do |base| base.push(parent) if parent.visible? @@ -65,6 +66,7 @@ def visible_ancestors def should_update_descendants_urlnames? return false if !Config.get(:url_nesting) + if active_record_5_1? saved_change_to_urlname? || saved_change_to_visible? else @@ -74,9 +76,7 @@ def should_update_descendants_urlnames? def update_descendants_urlnames reload - descendants.each do |descendant| - descendant.update_urlname! - end + descendants.each(&:update_urlname!) end # Sets the urlname to a url friendly slug. @@ -118,6 +118,7 @@ def nested_url_name(value) # the root page itself, or url_nesting is off. def ancestor_slugs return [] if !Config.get(:url_nesting) || parent.nil? || parent.root? + visible_ancestors.map(&:slug).compact end end diff --git a/app/models/alchemy/page/page_natures.rb b/app/models/alchemy/page/page_natures.rb index 6520c0941e..63be5afe2b 100644 --- a/app/models/alchemy/page/page_natures.rb +++ b/app/models/alchemy/page/page_natures.rb @@ -23,11 +23,13 @@ def rootpage? def systempage? return true if Page.count.zero? + rootpage? || (parent_id == Page.root.id && !language_root?) end def folded?(user_id) return unless Alchemy.user_class < ActiveRecord::Base + folded_pages.where(user_id: user_id, folded: true).any? end @@ -51,6 +53,7 @@ def has_limited_editors? def editor_roles return unless has_limited_editors? + definition["editable_by"] end @@ -150,6 +153,7 @@ def published_at # def cache_page? return false unless caching_enabled? + page_layout = PageLayout.get(self.page_layout) page_layout['cache'] != false && page_layout['searchresults'] != true end diff --git a/app/models/alchemy/picture.rb b/app/models/alchemy/picture.rb index c9c51644e9..9deb1fd11e 100644 --- a/app/models/alchemy/picture.rb +++ b/app/models/alchemy/picture.rb @@ -102,6 +102,7 @@ def searchable_alchemy_resource_attributes def last_upload last_picture = Picture.last return Picture.all unless last_picture + Picture.where(upload_hash: last_picture.upload_hash) end @@ -190,6 +191,7 @@ def suffix # def humanized_name return "" if image_file_name.blank? + convert_to_humanized_name(image_file_name, suffix) end diff --git a/app/models/alchemy/picture/transformations.rb b/app/models/alchemy/picture/transformations.rb index 3ec44fd380..1475a8c845 100644 --- a/app/models/alchemy/picture/transformations.rb +++ b/app/models/alchemy/picture/transformations.rb @@ -49,6 +49,7 @@ def thumbnail_size(size_string = "0x0", crop = false) # def crop(size, crop_from = nil, crop_size = nil, upsample = false) raise "No size given!" if size.empty? + render_to = sizes_from_string(size) if crop_from && crop_size top_left = point_from_string(crop_from) @@ -118,6 +119,7 @@ def image_size # def can_be_cropped_to(string, upsample = false) return true if upsample + is_bigger_than sizes_from_string(string) end diff --git a/app/models/concerns/alchemy/content_touching.rb b/app/models/concerns/alchemy/content_touching.rb index f906d0d0e4..f7fe71d1be 100644 --- a/app/models/concerns/alchemy/content_touching.rb +++ b/app/models/concerns/alchemy/content_touching.rb @@ -17,6 +17,7 @@ def self.included(base) # def touch_contents return unless respond_to?(:contents) + contents.update_all(updated_at: Time.current) end end diff --git a/app/serializers/alchemy/essence_picture_serializer.rb b/app/serializers/alchemy/essence_picture_serializer.rb index 08f42068f7..3082b78b39 100644 --- a/app/serializers/alchemy/essence_picture_serializer.rb +++ b/app/serializers/alchemy/essence_picture_serializer.rb @@ -16,6 +16,7 @@ class EssencePictureSerializer < ActiveModel::Serializer def link return if object.link.blank? + { url: object.link, css_class: object.link_class_name, diff --git a/app/serializers/alchemy/essence_text_serializer.rb b/app/serializers/alchemy/essence_text_serializer.rb index 5158b6c1ca..3f1d9c6ec6 100644 --- a/app/serializers/alchemy/essence_text_serializer.rb +++ b/app/serializers/alchemy/essence_text_serializer.rb @@ -10,6 +10,7 @@ class EssenceTextSerializer < ActiveModel::Serializer def link return if object.link.blank? + { url: object.link, title: object.link_title, diff --git a/app/views/alchemy/pages/show.rss.builder b/app/views/alchemy/pages/show.rss.builder index 756d798c5e..19377b16b8 100644 --- a/app/views/alchemy/pages/show.rss.builder +++ b/app/views/alchemy/pages/show.rss.builder @@ -1,3 +1,4 @@ +# frozen_string_literal: true xml.instruct! :xml, version: "1.0" xml.rss version: "2.0" do xml.channel do diff --git a/bin/rails b/bin/rails index 1af3ba7e2c..5d8a41f30e 100755 --- a/bin/rails +++ b/bin/rails @@ -1,4 +1,5 @@ #!/usr/bin/env ruby +# 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__) diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb index bfed98cab0..150ad0fdc4 100644 --- a/config/initializers/assets.rb +++ b/config/initializers/assets.rb @@ -1,2 +1,3 @@ +# frozen_string_literal: true # Add Alchemy assets for precompiling Rails.application.config.assets.precompile << 'alchemy_manifest.js' diff --git a/config/initializers/dragonfly.rb b/config/initializers/dragonfly.rb index 94a59f5a01..8ed78220d8 100644 --- a/config/initializers/dragonfly.rb +++ b/config/initializers/dragonfly.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require 'dragonfly_svg' # Logger diff --git a/config/initializers/mime_types.rb b/config/initializers/mime_types.rb index b20d2806d1..9b8a75469f 100644 --- a/config/initializers/mime_types.rb +++ b/config/initializers/mime_types.rb @@ -1 +1,2 @@ +# frozen_string_literal: true Mime::Type.register "image/svg+xml", :svg diff --git a/config/initializers/mini_profiler.rb b/config/initializers/mini_profiler.rb index bda41d3edd..af008dc7c7 100644 --- a/config/initializers/mini_profiler.rb +++ b/config/initializers/mini_profiler.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true begin require 'rack-mini-profiler' Rack::MiniProfiler.config.position = 'right' diff --git a/config/routes.rb b/config/routes.rb index 23fce4c059..7cd725778e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require 'alchemy/routing_constraints' Alchemy::Engine.routes.draw do diff --git a/config/spring.rb b/config/spring.rb index 2982ff9cdf..9ee5253fd9 100755 --- a/config/spring.rb +++ b/config/spring.rb @@ -1,2 +1,3 @@ +# frozen_string_literal: true Spring.application_root = './spec/dummy' Spring.watch 'lib/**/*' diff --git a/lib/alchemy/admin/locale.rb b/lib/alchemy/admin/locale.rb index b06638dd93..7300e4b5e1 100644 --- a/lib/alchemy/admin/locale.rb +++ b/lib/alchemy/admin/locale.rb @@ -47,6 +47,7 @@ def available_locale # Try to get the locale from user settings. def locale_from_user return if !current_alchemy_user + if user_has_preferred_language? current_alchemy_user.language end @@ -55,6 +56,7 @@ def locale_from_user # Checks if the +current_alchemy_user+ has a preferred language set or not. def user_has_preferred_language? return if !current_alchemy_user + current_alchemy_user.respond_to?(:language) && current_alchemy_user.language.present? && current_alchemy_user.language.respond_to?(:to_sym) diff --git a/lib/alchemy/auth_accessors.rb b/lib/alchemy/auth_accessors.rb index 1de619d8a6..d35fa6afe3 100644 --- a/lib/alchemy/auth_accessors.rb +++ b/lib/alchemy/auth_accessors.rb @@ -78,6 +78,7 @@ 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.' end + "::#{@@user_class_name}" end diff --git a/lib/alchemy/cache_digests/template_tracker.rb b/lib/alchemy/cache_digests/template_tracker.rb index be599f992e..ef1e646759 100644 --- a/lib/alchemy/cache_digests/template_tracker.rb +++ b/lib/alchemy/cache_digests/template_tracker.rb @@ -34,6 +34,7 @@ def dependencies def essence_types(name) element = Element.definitions.detect { |e| e['name'] == name } return [] unless element + element.fetch('contents', []).collect { |c| c['type'] } end end diff --git a/lib/alchemy/config.rb b/lib/alchemy/config.rb index 6f7f371707..7b60a8919d 100644 --- a/lib/alchemy/config.rb +++ b/lib/alchemy/config.rb @@ -55,6 +55,7 @@ def read_file(file) # def merge_configs!(*config_files) raise LoadError, 'No Alchemy config file found!' if config_files.map(&:blank?).all? + config = {} config_files.each { |h| config.merge!(h.stringify_keys!) } config diff --git a/lib/alchemy/controller_actions.rb b/lib/alchemy/controller_actions.rb index 5bfbb26cdf..ce7330d442 100644 --- a/lib/alchemy/controller_actions.rb +++ b/lib/alchemy/controller_actions.rb @@ -36,6 +36,7 @@ def current_server def current_alchemy_user current_user_method = Alchemy.current_user_method raise NoCurrentUserFoundError if !respond_to?(current_user_method, true) + send current_user_method end @@ -66,8 +67,8 @@ def set_alchemy_language(lang = nil) else # find the best language and remember it for later @language = load_alchemy_language_from_params || - load_alchemy_language_from_session || - Language.default + load_alchemy_language_from_session || + Language.default end store_current_alchemy_language(@language) end @@ -96,7 +97,7 @@ def load_alchemy_language_from_id_or_code(id_or_code) # Also stores language in +Language.current+ # def store_current_alchemy_language(language) - if language && language.id + if language&.id session[:alchemy_language_id] = language.id Language.current = language end diff --git a/lib/alchemy/deprecation.rb b/lib/alchemy/deprecation.rb index 74a57e5d03..c2ccd9c987 100644 --- a/lib/alchemy/deprecation.rb +++ b/lib/alchemy/deprecation.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module Alchemy Deprecation = ActiveSupport::Deprecation.new('5.0', 'Alchemy') end diff --git a/lib/alchemy/elements_finder.rb b/lib/alchemy/elements_finder.rb index 42f09afc4b..0befac9a8b 100644 --- a/lib/alchemy/elements_finder.rb +++ b/lib/alchemy/elements_finder.rb @@ -105,7 +105,7 @@ def fallback_elements def random_function case ActiveRecord::Base.connection_config[:adapter] when 'postgresql', 'sqlite3' - then 'RANDOM()' + 'RANDOM()' else 'RAND()' end diff --git a/lib/alchemy/engine.rb b/lib/alchemy/engine.rb index 2b73074b72..c041313997 100644 --- a/lib/alchemy/engine.rb +++ b/lib/alchemy/engine.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module Alchemy class Engine < Rails::Engine isolate_namespace Alchemy diff --git a/lib/alchemy/essence.rb b/lib/alchemy/essence.rb index 359a1f04d6..81baa58d20 100644 --- a/lib/alchemy/essence.rb +++ b/lib/alchemy/essence.rb @@ -187,6 +187,7 @@ def validate_presence(validate = true) def validate_uniqueness(validate = true) return if !validate || !public? + if duplicates.any? errors.add(ingredient_column, :taken) validation_errors << :taken @@ -231,12 +232,14 @@ def ingredient_setter_method # 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 } || {} end # Touch content. Called after update. def touch_content return nil if content.nil? + content.touch end diff --git a/lib/alchemy/i18n.rb b/lib/alchemy/i18n.rb index 48f84db4c3..4f139709fd 100644 --- a/lib/alchemy/i18n.rb +++ b/lib/alchemy/i18n.rb @@ -74,6 +74,7 @@ def translation_files def humanize_default_string!(msg, options) return if options[:default].present? + options[:default] = msg.is_a?(Symbol) ? msg.to_s.humanize : msg end diff --git a/lib/alchemy/on_page_layout/callbacks_runner.rb b/lib/alchemy/on_page_layout/callbacks_runner.rb index aca05f0835..2947481e7b 100644 --- a/lib/alchemy/on_page_layout/callbacks_runner.rb +++ b/lib/alchemy/on_page_layout/callbacks_runner.rb @@ -18,6 +18,7 @@ def run_on_page_layout_callbacks? def run_on_page_layout_callbacks OnPageLayout.callbacks.each do |page_layout, callbacks| next unless call_page_layout_callback_for?(page_layout) + callbacks.each do |callback| if callback.respond_to?(:call) instance_eval(&callback) diff --git a/lib/alchemy/page_layout.rb b/lib/alchemy/page_layout.rb index 735949ea00..de1685040b 100644 --- a/lib/alchemy/page_layout.rb +++ b/lib/alchemy/page_layout.rb @@ -37,6 +37,7 @@ def add(page_layout) # def get(name) return {} if name.blank? + all.detect { |a| a['name'].casecmp(name).zero? } end diff --git a/lib/alchemy/permissions.rb b/lib/alchemy/permissions.rb index 951a6c118a..81bb3b606b 100644 --- a/lib/alchemy/permissions.rb +++ b/lib/alchemy/permissions.rb @@ -200,6 +200,7 @@ def alchemy_admin_rules def user_role_rules return alchemy_guest_user_rules if @user.alchemy_roles.blank? + @user.alchemy_roles.each do |role| exec_role_rules(role) end diff --git a/lib/alchemy/resource.rb b/lib/alchemy/resource.rb index 272af441ad..7bd647217f 100644 --- a/lib/alchemy/resource.rb +++ b/lib/alchemy/resource.rb @@ -113,6 +113,7 @@ def initialize(controller_path, module_definition = nil, custom_model = nil) if !model.respond_to?(:reflect_on_all_associations) raise MissingActiveRecordAssociation end + store_model_associations map_relations end @@ -152,6 +153,7 @@ def namespace_for_scope # def model_association_names return unless model_associations + model_associations.map do |assoc| assoc.name.to_sym end @@ -160,6 +162,7 @@ def model_association_names def attributes @_attributes ||= model.columns.collect do |col| next if skipped_attributes.include?(col.name) + { name: col.name, type: resource_column_type(col), diff --git a/lib/alchemy/seeder.rb b/lib/alchemy/seeder.rb index 73de84bbda..e8ac5c5e6a 100644 --- a/lib/alchemy/seeder.rb +++ b/lib/alchemy/seeder.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "alchemy/shell" module Alchemy @@ -23,6 +24,7 @@ def seed! def try_seed_pages return unless page_seeds_file.file? + if Alchemy::Page.exists? desc "Seeding Alchemy pages" log "There are already pages present in your database. " \ @@ -66,7 +68,7 @@ def seed_users if Alchemy.user_class.exists? log "There are already users present in your database. " \ "Please use `rake db:reset' if you want to rebuild your database.", :skip - return false + false else users = YAML.load_file(user_seeds_file) users.each do |draft| diff --git a/lib/alchemy/shell.rb b/lib/alchemy/shell.rb index 3a931cd3f6..b15b2ebbd4 100644 --- a/lib/alchemy/shell.rb +++ b/lib/alchemy/shell.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require 'thor/shell/color' module Alchemy @@ -5,6 +6,13 @@ module Alchemy # in a list on the shell / log # module Shell + COLORS = { + clear: Thor::Shell::Color::CLEAR, + green: Thor::Shell::Color::GREEN, + red: Thor::Shell::Color::RED, + yellow: Thor::Shell::Color::YELLOW + }.freeze + def self.silence! @silenced = true end @@ -96,12 +104,7 @@ def log(message, type = nil) # @return [String] # def color(name) - color_const = name.to_s.upcase - if Thor::Shell::Color.const_defined?(color_const) - "Thor::Shell::Color::#{color_const}".constantize - else - "" - end + COLORS[name] end end end diff --git a/lib/alchemy/taggable.rb b/lib/alchemy/taggable.rb index b948eddb60..7ec5b0ed21 100644 --- a/lib/alchemy/taggable.rb +++ b/lib/alchemy/taggable.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module Alchemy # ActsAsTaggableOn to Gutentag interface compatibility module # Include this module to add tagging support to your model. diff --git a/lib/alchemy/tasks/helpers.rb b/lib/alchemy/tasks/helpers.rb index 243d6b54bc..d742e25ef4 100644 --- a/lib/alchemy/tasks/helpers.rb +++ b/lib/alchemy/tasks/helpers.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module Alchemy module Tasks module Helpers @@ -11,6 +12,7 @@ def database_import_command(adapter) def database_config raise "Could not find #{database_config_file}!" if !File.exist?(database_config_file) + @database_config ||= begin config_file = YAML.safe_load(ERB.new(File.read(database_config_file)).result, [], [], true) config_file.fetch(environment) diff --git a/lib/alchemy/tasks/tidy.rb b/lib/alchemy/tasks/tidy.rb index 31d4e208c1..ef2c662cad 100644 --- a/lib/alchemy/tasks/tidy.rb +++ b/lib/alchemy/tasks/tidy.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require 'alchemy/shell' module Alchemy diff --git a/lib/alchemy/test_support/config_stubbing.rb b/lib/alchemy/test_support/config_stubbing.rb index 8717bd23d6..77de5d7e8b 100644 --- a/lib/alchemy/test_support/config_stubbing.rb +++ b/lib/alchemy/test_support/config_stubbing.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module Alchemy module TestSupport # Allows you to stub the Alchemy configuration in your specs diff --git a/lib/alchemy/test_support/factories.rb b/lib/alchemy/test_support/factories.rb index d709a0c6dd..73c3392771 100644 --- a/lib/alchemy/test_support/factories.rb +++ b/lib/alchemy/test_support/factories.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true -Dir["#{File.dirname(__FILE__)}/factories/*.rb"].each do |file| +Dir["#{File.dirname(__FILE__)}/factories/*.rb"].sort.each do |file| require file end diff --git a/lib/alchemy/test_support/factories/language_factory.rb b/lib/alchemy/test_support/factories/language_factory.rb index 58680e15d8..4896b2c8dd 100644 --- a/lib/alchemy/test_support/factories/language_factory.rb +++ b/lib/alchemy/test_support/factories/language_factory.rb @@ -10,7 +10,9 @@ default { true } frontpage_name { 'Intro' } page_layout { Alchemy::Config.get(:default_language)['page_layout'] } + public { true } + site { Alchemy::Site.default } trait :klingon do diff --git a/lib/alchemy/test_support/factories/site_factory.rb b/lib/alchemy/test_support/factories/site_factory.rb index d77e2e0f1b..834318090d 100644 --- a/lib/alchemy/test_support/factories/site_factory.rb +++ b/lib/alchemy/test_support/factories/site_factory.rb @@ -9,6 +9,7 @@ trait :default do public { true } + name { Alchemy::Config.get(:default_site)['name'] } host { Alchemy::Config.get(:default_site)['host'] } end diff --git a/lib/alchemy/test_support/integration_helpers.rb b/lib/alchemy/test_support/integration_helpers.rb index f93e41aa99..9977410b96 100644 --- a/lib/alchemy/test_support/integration_helpers.rb +++ b/lib/alchemy/test_support/integration_helpers.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module Alchemy module TestSupport # Helpers for integration specs diff --git a/lib/alchemy/test_support/shared_contexts.rb b/lib/alchemy/test_support/shared_contexts.rb index 39a8297691..c14a28b53e 100644 --- a/lib/alchemy/test_support/shared_contexts.rb +++ b/lib/alchemy/test_support/shared_contexts.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true RSpec.shared_context 'with invalid file' do let(:invalid_file) do fixture_file_upload( diff --git a/lib/alchemy/test_support/shared_uploader_examples.rb b/lib/alchemy/test_support/shared_uploader_examples.rb index bce349e684..f35d5249c7 100644 --- a/lib/alchemy/test_support/shared_uploader_examples.rb +++ b/lib/alchemy/test_support/shared_uploader_examples.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true RSpec.shared_examples_for "having a json uploader error message" do it "renders json response with error message" do subject diff --git a/lib/alchemy/tinymce.rb b/lib/alchemy/tinymce.rb index 51fe96b789..2d52de9040 100644 --- a/lib/alchemy/tinymce.rb +++ b/lib/alchemy/tinymce.rb @@ -43,10 +43,12 @@ def custom_config_contents(page) def content_definitions_from_elements(definitions) definitions.collect do |el| next if el['contents'].blank? + 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']) } end.flatten.compact end diff --git a/lib/alchemy/upgrader.rb b/lib/alchemy/upgrader.rb index 3f26d05f75..7d628ad41e 100644 --- a/lib/alchemy/upgrader.rb +++ b/lib/alchemy/upgrader.rb @@ -1,10 +1,11 @@ +# frozen_string_literal: true require 'alchemy/shell' module Alchemy class Upgrader extend Alchemy::Shell - Dir["#{File.dirname(__FILE__)}/upgrader/*.rb"].each { |f| require f } + Dir["#{File.dirname(__FILE__)}/upgrader/*.rb"].sort.each { |f| require f } class << self def copy_new_config_file diff --git a/lib/alchemy_cms.rb b/lib/alchemy_cms.rb index dfa6fca647..73df9914f3 100644 --- a/lib/alchemy_cms.rb +++ b/lib/alchemy_cms.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # Instantiate the global Alchemy namespace module Alchemy Alchemy::YAML_WHITELIST_CLASSES = %w(Symbol Date Regexp) diff --git a/lib/kaminari/scoped_pagination_url_helper.rb b/lib/kaminari/scoped_pagination_url_helper.rb index 8aec5d223e..53881d6237 100644 --- a/lib/kaminari/scoped_pagination_url_helper.rb +++ b/lib/kaminari/scoped_pagination_url_helper.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # A Kaminari patch for scoping the urls. Kaminari::Helpers::Tag.class_eval do def page_url_for(page) diff --git a/lib/rails/generators/alchemy/base.rb b/lib/rails/generators/alchemy/base.rb index 2e1de6f856..43c3c1811a 100644 --- a/lib/rails/generators/alchemy/base.rb +++ b/lib/rails/generators/alchemy/base.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require 'rails' module Alchemy diff --git a/lib/rails/generators/alchemy/elements/elements_generator.rb b/lib/rails/generators/alchemy/elements/elements_generator.rb index 4292301a6f..e3c182dfda 100644 --- a/lib/rails/generators/alchemy/elements/elements_generator.rb +++ b/lib/rails/generators/alchemy/elements/elements_generator.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require_relative '../base' module Alchemy diff --git a/lib/rails/generators/alchemy/essence/essence_generator.rb b/lib/rails/generators/alchemy/essence/essence_generator.rb index 050e18799f..72688d8a4d 100644 --- a/lib/rails/generators/alchemy/essence/essence_generator.rb +++ b/lib/rails/generators/alchemy/essence/essence_generator.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require 'rails' module Alchemy @@ -19,16 +20,16 @@ def create_model def act_as_essence essence_class_file = "app/models/#{@essence_name}.rb" essence_class = @essence_name.classify - inject_into_class essence_class_file, essence_class, <<-CLASSMETHOD - acts_as_essence( - # Your options: - # - # ingredient_column: [String or Symbol] - Specifies the column name you use for storing the content in the database. (Default :body) - # validate_column: [String or Symbol] - Which column should be validated. (Default: ingredient_column) - # preview_text_column: [String or Symbol] - Specifies the column for the preview_text method. (Default: ingredient_column) - # preview_text_method: [String or Symbol] - A method called on ingredient to get the preview text. (Default: ingredient_column) - ) -CLASSMETHOD + inject_into_class essence_class_file, essence_class, <<~CLASSMETHOD + acts_as_essence( + # Your options: + # + # ingredient_column: [String or Symbol] - Specifies the column name you use for storing the content in the database. (Default :body) + # validate_column: [String or Symbol] - Which column should be validated. (Default: ingredient_column) + # preview_text_column: [String or Symbol] - Specifies the column for the preview_text method. (Default: ingredient_column) + # preview_text_method: [String or Symbol] - A method called on ingredient to get the preview text. (Default: ingredient_column) + ) + CLASSMETHOD end def copy_templates diff --git a/lib/rails/generators/alchemy/install/install_generator.rb b/lib/rails/generators/alchemy/install/install_generator.rb index eb7432dc6f..ee30f5b570 100644 --- a/lib/rails/generators/alchemy/install/install_generator.rb +++ b/lib/rails/generators/alchemy/install/install_generator.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require 'rails' module Alchemy diff --git a/lib/rails/generators/alchemy/module/module_generator.rb b/lib/rails/generators/alchemy/module/module_generator.rb index 74b8aef6ad..7d6651b1c6 100644 --- a/lib/rails/generators/alchemy/module/module_generator.rb +++ b/lib/rails/generators/alchemy/module/module_generator.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require 'rails' module Alchemy 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 25a7c87806..1ceb9ce2b1 100644 --- a/lib/rails/generators/alchemy/page_layouts/page_layouts_generator.rb +++ b/lib/rails/generators/alchemy/page_layouts/page_layouts_generator.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require_relative '../base' module Alchemy @@ -9,6 +10,7 @@ class PageLayoutsGenerator < Base def create_partials @page_layouts = load_alchemy_yaml('page_layouts.yml') return unless @page_layouts + @page_layouts.each do |page_layout| @page_layout_name = page_layout["name"].underscore conditional_template "layout.html.#{template_engine}", "#{page_layouts_dir}/_#{@page_layout_name}.html.#{template_engine}" 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 a519da5abe..aba495be9d 100644 --- a/lib/rails/generators/alchemy/site_layouts/site_layouts_generator.rb +++ b/lib/rails/generators/alchemy/site_layouts/site_layouts_generator.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require_relative '../base' module Alchemy @@ -9,6 +10,7 @@ class SiteLayoutsGenerator < Base def create_partials @sites = Alchemy::Site.all return unless @sites + @sites.each do |site| @site_name = site.name.parameterize.underscore conditional_template "layout.html.#{template_engine}", "#{site_layouts_dir}/_#{@site_name}.html.#{template_engine}" diff --git a/lib/rails/generators/alchemy/views/views_generator.rb b/lib/rails/generators/alchemy/views/views_generator.rb index 93e263781b..a9750a87ef 100644 --- a/lib/rails/generators/alchemy/views/views_generator.rb +++ b/lib/rails/generators/alchemy/views/views_generator.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require 'rails' module Alchemy diff --git a/lib/tasks/alchemy/convert.rake b/lib/tasks/alchemy/convert.rake index be1ded824b..2ae48e28e6 100644 --- a/lib/tasks/alchemy/convert.rake +++ b/lib/tasks/alchemy/convert.rake @@ -1,3 +1,4 @@ +# frozen_string_literal: true namespace :alchemy do namespace :convert do namespace :urlnames do @@ -6,6 +7,7 @@ namespace :alchemy do unless Alchemy::Config.get(:url_nesting) raise "\nURL nesting is disabled! Please enable url_nesting in `config/alchemy/config.yml` first.\n\n" end + puts "Converting..." pages = Alchemy::Page.contentpages count = pages.count @@ -21,6 +23,7 @@ namespace :alchemy do if Alchemy::Config.get(:url_nesting) raise "\nURL nesting is enabled! Please disable url_nesting in `config/alchemy/config.yml` first.\n\n" end + puts "Converting..." pages = Alchemy::Page.contentpages count = pages.count diff --git a/lib/tasks/alchemy/db.rake b/lib/tasks/alchemy/db.rake index cbd5c38bcf..f090e9fe8a 100644 --- a/lib/tasks/alchemy/db.rake +++ b/lib/tasks/alchemy/db.rake @@ -1,3 +1,4 @@ +# frozen_string_literal: true require 'shellwords' require 'alchemy/seeder' require 'alchemy/tasks/helpers' diff --git a/lib/tasks/alchemy/install.rake b/lib/tasks/alchemy/install.rake index 8425f7eb40..27fd3d62ff 100644 --- a/lib/tasks/alchemy/install.rake +++ b/lib/tasks/alchemy/install.rake @@ -1,3 +1,4 @@ +# frozen_string_literal: true require 'thor' class Alchemy::InstallTask < Thor diff --git a/lib/tasks/alchemy/tidy.rake b/lib/tasks/alchemy/tidy.rake index 88b92b4dd9..856ab588f4 100644 --- a/lib/tasks/alchemy/tidy.rake +++ b/lib/tasks/alchemy/tidy.rake @@ -1,3 +1,4 @@ +# frozen_string_literal: true require 'alchemy/tasks/tidy' namespace :alchemy do diff --git a/lib/tasks/alchemy/upgrade.rake b/lib/tasks/alchemy/upgrade.rake index 59bbd42941..ccf58bed5e 100644 --- a/lib/tasks/alchemy/upgrade.rake +++ b/lib/tasks/alchemy/upgrade.rake @@ -1,3 +1,4 @@ +# frozen_string_literal: true require 'alchemy/upgrader' require 'alchemy/version' diff --git a/spec/controllers/alchemy/on_page_layout_mixin_spec.rb b/spec/controllers/alchemy/on_page_layout_mixin_spec.rb index 5e90d120f8..2c07c94a9d 100644 --- a/spec/controllers/alchemy/on_page_layout_mixin_spec.rb +++ b/spec/controllers/alchemy/on_page_layout_mixin_spec.rb @@ -6,7 +6,7 @@ routes { Alchemy::Engine.routes } before(:all) do - ApplicationController.send(:extend, Alchemy::OnPageLayout) + ApplicationController.extend Alchemy::OnPageLayout end let(:page) { create(:alchemy_page, :public, page_layout: 'standard') } @@ -269,7 +269,7 @@ def run_method RSpec.describe ApplicationController, 'OnPageLayout mixin', type: :controller do before(:all) do - ApplicationController.send(:extend, Alchemy::OnPageLayout) + ApplicationController.extend Alchemy::OnPageLayout end controller do @@ -300,7 +300,7 @@ def index routes { Alchemy::Engine.routes } before(:all) do - ApplicationController.send(:extend, Alchemy::OnPageLayout) + ApplicationController.extend Alchemy::OnPageLayout end context 'in admin/pages_controller' do diff --git a/spec/controllers/alchemy/pages_controller_spec.rb b/spec/controllers/alchemy/pages_controller_spec.rb index 2e5ae5736d..4fa6c66a72 100644 --- a/spec/controllers/alchemy/pages_controller_spec.rb +++ b/spec/controllers/alchemy/pages_controller_spec.rb @@ -65,7 +65,7 @@ module Alchemy context "when a page layout callback is set" do before do - ApplicationController.send(:extend, Alchemy::OnPageLayout) + ApplicationController.extend Alchemy::OnPageLayout ApplicationController.class_eval do on_page_layout('index') { "do something" } end diff --git a/spec/dummy/app/controllers/admin/series_controller.rb b/spec/dummy/app/controllers/admin/series_controller.rb index 587d5684de..4901fbc4b2 100644 --- a/spec/dummy/app/controllers/admin/series_controller.rb +++ b/spec/dummy/app/controllers/admin/series_controller.rb @@ -1,2 +1,3 @@ +# frozen_string_literal: true class Admin::SeriesController < Alchemy::Admin::ResourcesController end diff --git a/spec/dummy/app/controllers/application_controller.rb b/spec/dummy/app/controllers/application_controller.rb index 4c2557d3cf..4dd61d7cad 100644 --- a/spec/dummy/app/controllers/application_controller.rb +++ b/spec/dummy/app/controllers/application_controller.rb @@ -9,6 +9,7 @@ class ApplicationController < ActionController::Base def current_user return if Rails.env.test? + @_dummy_user ||= DummyUser.find_or_create_by(email: "dummy@alchemy.com") end end diff --git a/spec/dummy/app/models/series.rb b/spec/dummy/app/models/series.rb index 08c8286a59..006d1e8490 100644 --- a/spec/dummy/app/models/series.rb +++ b/spec/dummy/app/models/series.rb @@ -1,2 +1,3 @@ +# frozen_string_literal: true class Series < ActiveRecord::Base end diff --git a/spec/dummy/bin/bundle b/spec/dummy/bin/bundle index cd6c652eea..7b9c7cdc8a 100755 --- a/spec/dummy/bin/bundle +++ b/spec/dummy/bin/bundle @@ -1,3 +1,4 @@ #!/usr/bin/env ruby +# frozen_string_literal: true 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 0739660237..dd027b406c 100755 --- a/spec/dummy/bin/rails +++ b/spec/dummy/bin/rails @@ -1,4 +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' diff --git a/spec/dummy/bin/rake b/spec/dummy/bin/rake index 17240489f6..609af74703 100755 --- a/spec/dummy/bin/rake +++ b/spec/dummy/bin/rake @@ -1,4 +1,5 @@ #!/usr/bin/env ruby +# frozen_string_literal: true require_relative '../config/boot' require 'rake' Rake.application.run diff --git a/spec/dummy/bin/setup b/spec/dummy/bin/setup index d07552fad3..2905c03cac 100755 --- a/spec/dummy/bin/setup +++ b/spec/dummy/bin/setup @@ -1,4 +1,5 @@ #!/usr/bin/env ruby +# frozen_string_literal: true require 'fileutils' # path to your application root. diff --git a/spec/dummy/bin/update b/spec/dummy/bin/update index 58bfaed518..b666346500 100755 --- a/spec/dummy/bin/update +++ b/spec/dummy/bin/update @@ -1,4 +1,5 @@ #!/usr/bin/env ruby +# frozen_string_literal: true require 'fileutils' include FileUtils diff --git a/spec/dummy/config.ru b/spec/dummy/config.ru index 3ab73beb9d..8c92c11334 100644 --- a/spec/dummy/config.ru +++ b/spec/dummy/config.ru @@ -1,3 +1,4 @@ +# frozen_string_literal: true # This file is used by Rack-based servers to start the application. require_relative 'config/environment' diff --git a/spec/features/admin/attachment_assignment_overlay_spec.rb b/spec/features/admin/attachment_assignment_overlay_spec.rb index 8edfaad063..665abd9226 100644 --- a/spec/features/admin/attachment_assignment_overlay_spec.rb +++ b/spec/features/admin/attachment_assignment_overlay_spec.rb @@ -33,9 +33,9 @@ expect(page).to have_selector("#assign_file_list .list a", count: 1) expect(page).to have_selector("#assign_file_list .list a span", text: "job alert") end - rescue Capybara::ElementNotFound => error - pending error.message - raise error + rescue Capybara::ElementNotFound => e + pending e.message + raise e end end end diff --git a/spec/features/admin/link_overlay_spec.rb b/spec/features/admin/link_overlay_spec.rb index ea3e4b1402..81628187e1 100644 --- a/spec/features/admin/link_overlay_spec.rb +++ b/spec/features/admin/link_overlay_spec.rb @@ -76,9 +76,9 @@ visit "/#{page1.urlname}" expect(page).to have_link("Link me", href: "/#{page2.urlname}") - rescue Capybara::ElementNotFound => error - pending error.message - raise error + rescue Capybara::ElementNotFound => e + pending e.message + raise e end end end diff --git a/spec/libraries/elements_finder_spec.rb b/spec/libraries/elements_finder_spec.rb index bdade2004f..9d4583c396 100644 --- a/spec/libraries/elements_finder_spec.rb +++ b/spec/libraries/elements_finder_spec.rb @@ -136,7 +136,7 @@ let(:random_function) do case ActiveRecord::Base.connection_config[:adapter] when 'postgresql', 'sqlite3' - then 'RANDOM()' + 'RANDOM()' else 'RAND()' end diff --git a/spec/libraries/resource_spec.rb b/spec/libraries/resource_spec.rb index d6aa5381a5..6f040eb3b6 100644 --- a/spec/libraries/resource_spec.rb +++ b/spec/libraries/resource_spec.rb @@ -99,9 +99,9 @@ module Alchemy allow(Party).to receive(:respond_to?) do |arg| case arg when :reflect_on_all_associations - then false + false when :alchemy_resource_relations - then true + true end end end diff --git a/spec/libraries/shell_spec.rb b/spec/libraries/shell_spec.rb index 4b8d573c84..339d35e00f 100644 --- a/spec/libraries/shell_spec.rb +++ b/spec/libraries/shell_spec.rb @@ -99,23 +99,14 @@ class MyToDoList describe '.color' do context 'if given name is a constant of Thor::Shell::Color' do - before do - allow(Thor::Shell::Color).to receive(:const_defined?).and_return(true) - end - it "should call the constant" do - expect_any_instance_of(String).to receive(:constantize).and_return('') - MyToDoList.send(:color, :red) + 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 - before do - allow(Thor::Shell::Color).to receive(:const_defined?).and_return(false) - end - - it "should return en empty string" do - expect(MyToDoList.send(:color, :not_existing)).to eq('') + it "should return nil" do + expect(MyToDoList.send(:color, :not_existing)).to be_nil end end end diff --git a/spec/models/alchemy/page_spec.rb b/spec/models/alchemy/page_spec.rb index 163af3531b..a72cb37a6a 100644 --- a/spec/models/alchemy/page_spec.rb +++ b/spec/models/alchemy/page_spec.rb @@ -2127,7 +2127,7 @@ module Alchemy 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) + - nested_expanded_rtf_contents.pluck(:id) + nested_expanded_rtf_contents.pluck(:id) expect(richtext_contents_ids.sort).to eq(rtf_content_ids) nested_folded_rtf_content = nested_folded_element.contents.essence_richtexts.first