diff --git a/.github/workflows/coveralls.yml b/.github/workflows/coveralls.yml index 630a28f7..9dd276b6 100644 --- a/.github/workflows/coveralls.yml +++ b/.github/workflows/coveralls.yml @@ -10,9 +10,9 @@ jobs: strategy: matrix: ruby-version: - - "3.2" + - "3.3" rails-version: - - "7.0" + - "7.1" continue-on-error: [true] name: ${{ format('Coverage (Ruby {0}, Rails {1})', matrix.ruby-version, matrix.rails-version) }} runs-on: ubuntu-latest diff --git a/.github/workflows/rubyonrails.yml b/.github/workflows/rubyonrails.yml index b5ee6a84..1b2c896d 100644 --- a/.github/workflows/rubyonrails.yml +++ b/.github/workflows/rubyonrails.yml @@ -10,7 +10,6 @@ jobs: strategy: matrix: ruby-version: - - "2.7" - "3.1" - "3.2" - "3.3" diff --git a/.rubocop.yml b/.rubocop.yml index 963d3934..2bf523be 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,3 +1,7 @@ +require: + # - rubocop-rails + # - rubocop-minitest + AllCops: TargetRubyVersion: 2.7 NewCops: enable diff --git a/CHANGELOG.md b/CHANGELOG.md index 633df7d5..a99d6f4c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # Changelog +## v.1.1.1 19 May 2024 + +- bump to Rails 7.1.3.3 +- bugfix: uploaded files index page was blank +- create cms:image tag, simplifying from cms:file_link +- add 'title' attribute to images +- update and optimize test suite +- dropped support for ruby < 3.0 - no longer supported + ## v.1.1.0 13 May 2024 - Rails 7.1 compatibility, all tests passing diff --git a/Gemfile b/Gemfile index a503a216..565f6bcb 100644 --- a/Gemfile +++ b/Gemfile @@ -5,35 +5,34 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" } gemspec -gem 'rails', '~> 7.1.2' +gem 'rails', '~> 7.1.3' group :development, :test do - gem 'autoprefixer-rails', '~> 8.1.0' + gem 'autoprefixer-rails', '~> 10.4.16.0' gem 'byebug', '~> 11.1.0', platforms: %i[mri mingw x64_mingw] - gem 'image_processing', '>= 1.2' + gem 'image_processing', '>= 1.12.0' gem 'sqlite3', '~> 1.6.7' # gem 'mysql2', '~> 0.5' # gem 'pg', '~> 1.5.4' end group :development do - gem 'listen', '~> 3.8.0' + gem 'listen', '~> 3.9.0' gem 'web-console', '~> 4.2' end group :test do - gem 'brakeman', '~> 5.4.1' + gem 'brakeman', '~> 6.1.2' gem 'bundler-audit', '~> 0.9.1' - gem 'capybara', '~> 3.39.0' gem 'coveralls_reborn', '~> 0.28.0', require: false - gem 'cuprite', '~> 0.14.3' - gem 'diffy', '~> 3.4.2' + gem 'cuprite', '>= 0.15' gem 'equivalent-xml', '~> 0.6.0' - gem 'minitest', '~> 5.20.0' - gem 'minitest-reporters', '~> 1.6.1' - gem 'mocha', '~> 2.1.0', require: false - gem 'puma', '~> 6.4.0' + gem 'minitest', '>= 5.23.0' + gem 'minitest-reporters', '>= 1.6.1' + gem 'mocha', '>= 2.3.0', require: false gem 'rails-controller-testing', '~> 1.0.5' - gem 'rubocop', '~> 1.56.0', require: false - gem 'simplecov', '~> 0.22.0', require: false + gem 'rubocop', '~> 1.63.0', require: false + gem 'rubocop-minitest' + gem 'rubocop-rails' + gem 'simplecov', '~> 0.22.0', require: false end diff --git a/README.md b/README.md index 6b4dbe72..2b068652 100644 --- a/README.md +++ b/README.md @@ -47,8 +47,8 @@ ocCaM'S, pronounced "AH-kums" is a nod to [Occam's Razor](https://en.wikipedia.o ## Compatibility -- [Test suite](https://github.com/avonderluft/occams/actions/workflows/rubyonrails.yml) on Ruby >= 2.7 with Rails >= 6.1 -- On Ruby 3.2, Rails 7.x + is recommended, since performance is noticably better than on 6.x +- [Test suite](https://github.com/avonderluft/occams/actions/workflows/rubyonrails.yml) on Ruby >= 3.0 with Rails >= 6.1 +- On Ruby 3.x, Rails 7.x + is recommended, since performance is noticably better than on 6.x ## Installation diff --git a/TODOS.md b/TODOS.md index c9239dab..9993b7aa 100644 --- a/TODOS.md +++ b/TODOS.md @@ -1,7 +1,6 @@ # ToDos -- set up Buildkite CI and add build badge to README - add duplicate page function in admin UI - add admin content search to list layouts, pages and snippets - see https://blog.robertsj.com/search/ -- add application console for testing -- add feature to resize file_link'd images +- diagnose and correct failure of ImageMagick params in file_link and image cms tags +- lint for rubocop-rails and rubocop-minitest diff --git a/app/controllers/concerns/occams/paginate.rb b/app/controllers/concerns/occams/paginate.rb index 9fd1b91d..64d46a40 100644 --- a/app/controllers/concerns/occams/paginate.rb +++ b/app/controllers/concerns/occams/paginate.rb @@ -2,8 +2,10 @@ module Occams::Paginate def occams_paginate(scope, per_page: 50) - return unless defined?(Kaminari) - - scope.page(params[:page]).per(per_page) + if defined?(Kaminari) + scope.page(params[:page]).per(per_page) + else + scope + end end end diff --git a/app/controllers/occams/admin/cms/pages_controller.rb b/app/controllers/occams/admin/cms/pages_controller.rb index 8d830b0a..e6bbc012 100644 --- a/app/controllers/occams/admin/cms/pages_controller.rb +++ b/app/controllers/occams/admin/cms/pages_controller.rb @@ -127,8 +127,8 @@ def check_for_layouts def build_page @page = @site.pages.new(page_params) - @page.parent ||= (@site.pages.find_by_id(params[:parent_id]) || @site.pages.root) - @page.layout ||= (@page.parent&.layout || @site.layouts.first) + @page.parent ||= @site.pages.find_by_id(params[:parent_id]) || @site.pages.root + @page.layout ||= @page.parent&.layout || @site.layouts.first end def load_page diff --git a/app/helpers/occams/admin/cms_helper.rb b/app/helpers/occams/admin/cms_helper.rb index 9395f273..bbf7678d 100644 --- a/app/helpers/occams/admin/cms_helper.rb +++ b/app/helpers/occams/admin/cms_helper.rb @@ -39,8 +39,11 @@ def cms_page_file_link_tag(fragment_id:, attachment:, multiple:) # @param [Occams::Cms::File] file # @return [String] {{ cms:file_link #{file.id}, ... }} def cms_file_link_tag(file) - as = ', as: image' if file.attachment.image? - "{{ cms:file_link #{file.id}#{as} }}" + if file.attachment.image? + "{{ cms:image #{file.label} }}" + else + "{{ cms:file_link #{file.id} }}" + end end end end diff --git a/app/helpers/occams/cms_helper.rb b/app/helpers/occams/cms_helper.rb index c0512fe5..0399789f 100644 --- a/app/helpers/occams/cms_helper.rb +++ b/app/helpers/occams/cms_helper.rb @@ -65,9 +65,7 @@ def cms_site_detect def occams_paginate(collection) return unless collection - return unless defined?(Kaminari) - - paginate collection, theme: 'occams' + paginate collection, theme: 'occams' if defined?(Kaminari) end end end diff --git a/config/initializers/content_security_policy.rb b/config/initializers/content_security_policy.rb index af395e46..35ab3fd6 100644 --- a/config/initializers/content_security_policy.rb +++ b/config/initializers/content_security_policy.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # Be sure to restart your server when you modify this file. # Define an application-wide content security policy. diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb index 6c78420e..9e049dcc 100644 --- a/config/initializers/inflections.rb +++ b/config/initializers/inflections.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # Be sure to restart your server when you modify this file. # Add new inflection rules using the following format. Inflections diff --git a/config/initializers/new_framework_defaults_7_1.rb b/config/initializers/new_framework_defaults_7_1.rb index 974cc2aa..707271fd 100644 --- a/config/initializers/new_framework_defaults_7_1.rb +++ b/config/initializers/new_framework_defaults_7_1.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # Be sure to restart your server when you modify this file. # # This file eases your Rails 7.1 framework defaults upgrade. diff --git a/config/initializers/permissions_policy.rb b/config/initializers/permissions_policy.rb index b635b527..e8d0b2ae 100644 --- a/config/initializers/permissions_policy.rb +++ b/config/initializers/permissions_policy.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # Be sure to restart your server when you modify this file. # Define an application-wide HTTP permissions policy. For further diff --git a/gemfiles/6.1.gemfile b/gemfiles/6.1.gemfile index 788b5569..f127de8c 100644 --- a/gemfiles/6.1.gemfile +++ b/gemfiles/6.1.gemfile @@ -8,31 +8,24 @@ gemspec path: '../' gem 'rails', '~> 6.1.0' group :development, :test do - gem 'autoprefixer-rails', '~> 8.1.0' - gem 'byebug', '~> 10.0.0', platforms: %i[mri mingw x64_mingw] - gem 'image_processing', '>= 1.2' + gem 'autoprefixer-rails', '~> 10.4.16.0' + gem 'byebug', '~> 11.1.0', platforms: %i[mri mingw x64_mingw] + gem 'image_processing', '>= 1.12.0' gem 'sqlite3', '~> 1.6.7' end -group :development do - gem 'listen', '~> 3.8.0' - gem 'web-console', '~> 4.2' -end - group :test do - gem 'brakeman', '~> 5.4.1' + gem 'brakeman', '~> 6.1.2' gem 'bundler-audit', '~> 0.9.1' - gem 'capybara', '~> 3.39.0' gem 'coveralls_reborn', '~> 0.28.0', require: false - gem 'cuprite', '~> 0.14.3' - gem 'diffy', '~> 3.4.2' + gem 'cuprite', '>= 0.15' gem 'equivalent-xml', '~> 0.6.0' - gem 'minitest', '~> 5.20.0' - gem 'minitest-reporters', '~> 1.6.1' - gem 'mocha', '~> 2.1.0', require: false - gem 'puma', '~> 6.4.0' + gem 'minitest', '>= 5.23.0' + gem 'minitest-reporters', '>= 1.6.1' + gem 'mocha', '>= 2.3.0', require: false gem 'rails-controller-testing', '~> 1.0.5' - gem 'rubocop', '~> 1.56.0', require: false - gem 'selenium-webdriver', '~> 4.9.0' + gem 'rubocop', '~> 1.63.0', require: false + gem 'rubocop-minitest' + gem 'rubocop-rails' gem 'simplecov', '~> 0.22.0', require: false end diff --git a/gemfiles/7.0.gemfile b/gemfiles/7.0.gemfile index 2cc11e1e..dfc3f66d 100644 --- a/gemfiles/7.0.gemfile +++ b/gemfiles/7.0.gemfile @@ -8,30 +8,24 @@ gemspec path: '../' gem 'rails', '~> 7.0.0' group :development, :test do - gem 'autoprefixer-rails', '~> 8.1.0' - gem 'byebug', '~> 10.0.0', platforms: %i[mri mingw x64_mingw] - gem 'image_processing', '>= 1.2' + gem 'autoprefixer-rails', '~> 10.4.16.0' + gem 'byebug', '~> 11.1.0', platforms: %i[mri mingw x64_mingw] + gem 'image_processing', '>= 1.12.0' gem 'sqlite3', '~> 1.6.7' end -group :development do - gem 'listen', '~> 3.8.0' - gem 'web-console', '~> 4.2' -end - group :test do - gem 'brakeman', '~> 5.4.1' + gem 'brakeman', '~> 6.1.2' gem 'bundler-audit', '~> 0.9.1' - gem 'capybara', '~> 3.39.0' gem 'coveralls_reborn', '~> 0.28.0', require: false - gem 'cuprite', '~> 0.14.3' - gem 'diffy', '~> 3.4.2' + gem 'cuprite', '>= 0.15' gem 'equivalent-xml', '~> 0.6.0' - gem 'minitest', '~> 5.20.0' - gem 'minitest-reporters', '~> 1.6.1' - gem 'mocha', '~> 2.1.0', require: false - gem 'puma', '~> 6.4.0' + gem 'minitest', '>= 5.23.0' + gem 'minitest-reporters', '>= 1.6.1' + gem 'mocha', '>= 2.3.0', require: false gem 'rails-controller-testing', '~> 1.0.5' - gem 'rubocop', '~> 1.56.0', require: false - gem 'simplecov', '~> 0.22.0', require: false + gem 'rubocop', '~> 1.63.0', require: false + gem 'rubocop-minitest' + gem 'rubocop-rails' + gem 'simplecov', '~> 0.22.0', require: false end diff --git a/gemfiles/7.1.gemfile b/gemfiles/7.1.gemfile index a13fe560..97d04107 100644 --- a/gemfiles/7.1.gemfile +++ b/gemfiles/7.1.gemfile @@ -8,30 +8,24 @@ gemspec path: '../' gem 'rails', '~> 7.1.0', '>= 7.1.1' group :development, :test do - gem 'autoprefixer-rails', '~> 8.1.0' - gem 'byebug', '~> 10.0.0', platforms: %i[mri mingw x64_mingw] - gem 'image_processing', '>= 1.2' + gem 'autoprefixer-rails', '~> 10.4.16.0' + gem 'byebug', '~> 11.1.0', platforms: %i[mri mingw x64_mingw] + gem 'image_processing', '>= 1.12.0' gem 'sqlite3', '~> 1.6.7' end -group :development do - gem 'listen', '~> 3.8.0' - gem 'web-console', '~> 4.2' -end - group :test do - gem 'brakeman', '~> 5.4.1' + gem 'brakeman', '~> 6.1.2' gem 'bundler-audit', '~> 0.9.1' - gem 'capybara', '~> 3.39.0' gem 'coveralls_reborn', '~> 0.28.0', require: false - gem 'cuprite', '~> 0.14.3' - gem 'diffy', '~> 3.4.2' + gem 'cuprite', '>= 0.15' gem 'equivalent-xml', '~> 0.6.0' - gem 'minitest', '~> 5.20.0' - gem 'minitest-reporters', '~> 1.6.1' - gem 'mocha', '~> 2.1.0', require: false - gem 'puma', '~> 6.4.0' + gem 'minitest', '>= 5.23.0' + gem 'minitest-reporters', '>= 1.6.1' + gem 'mocha', '>= 2.3.0', require: false gem 'rails-controller-testing', '~> 1.0.5' - gem 'rubocop', '~> 1.56.0', require: false - gem 'simplecov', '~> 0.22.0', require: false + gem 'rubocop', '~> 1.63.0', require: false + gem 'rubocop-minitest' + gem 'rubocop-rails' + gem 'simplecov', '~> 0.22.0', require: false end diff --git a/lib/occams/content/tags.rb b/lib/occams/content/tags.rb index e371c466..daafd7d7 100644 --- a/lib/occams/content/tags.rb +++ b/lib/occams/content/tags.rb @@ -18,6 +18,7 @@ module Occams::Content::Tags require_relative 'tags/snippet' require_relative 'tags/asset' require_relative 'tags/file_link' +require_relative 'tags/image' require_relative 'tags/page_file_link' require_relative 'tags/helper' require_relative 'tags/partial' diff --git a/lib/occams/content/tags/file_link.rb b/lib/occams/content/tags/file_link.rb index b8c4864b..4d46385e 100644 --- a/lib/occams/content/tags/file_link.rb +++ b/lib/occams/content/tags/file_link.rb @@ -7,23 +7,19 @@ # {{cms:file_link id, as: image}} # # `as` - url (default) | link | image - how file gets rendered out -# `label` - attach label attribute to link or image tag -# `resize` - imagemagic option. For example: "100x50>" -# `gravity` - imagemagic option. For example: "center" -# `crop` - imagemagic option. For example: "100x50+0+0" # `class` - any html classes that you want on the result link or image tag. For example "class1 class2" # +# - variant_attrs are not functional, perhaps due to some change in ImageMagick +# - Simply use a class in your CSS / SASS to style your image display +# `label` - attach label attribute to link or image tag +# `resize` - imagemagick option. For example: "100x50>" +# `gravity` - imagemagick option. For example: "center" +# `crop` - imagemagick option. For example: "100x50+0+0" +# class Occams::Content::Tags::FileLink < Occams::Content::Tag include Occams::Content::Tags::Mixins::FileContent - # @return [String] A {Occams::Cms::Site#files} ID. - attr_reader :identifier - - # @type ["url", "link", "image"] - attr_reader :as - - # @type [{String => String}] - attr_reader :variant_attrs + attr_reader :identifier, :as, :variant_attrs def initialize(context:, params: [], source: nil) super @@ -32,7 +28,7 @@ def initialize(context:, params: [], source: nil) @identifier = params[0] @as = options['as'] || 'url' @class = options['class'] - @variant_attrs = options.slice('resize', 'gravity', 'crop') + @variant_attrs = options.slice('resize', 'gravity', 'crop') # broken for ImageMagick return if @identifier.present? diff --git a/lib/occams/content/tags/image.rb b/lib/occams/content/tags/image.rb new file mode 100644 index 00000000..3ecffe23 --- /dev/null +++ b/lib/occams/content/tags/image.rb @@ -0,0 +1,56 @@ +# frozen_string_literal: true + +require_relative 'mixins/file_content' + +# This is like the the file_link tag, but specifically for images +# Identify the image by its label {{ cms:image label }} +# +# `class` - any html classes that you want on the image tag. For example "class1 class2" +# +# - variant_attrs are not functional, perhaps due to some change in ImageMagick +# - Simply use a class in your CSS / SASS to style your image display +# `label` - attach label attribute to link or image tag +# `resize` - imagemagick option. For example: "100x50>" +# `gravity` - imagemagick option. For example: "center" +# `crop` - imagemagick option. For example: "100x50+0+0" + +class Occams::Content::Tags::Image < Occams::Content::Tag + include Occams::Content::Tags::Mixins::FileContent + + attr_reader :identifier, :as, :variant_attrs + + def initialize(context:, params: [], source: nil) + super + + options = params.extract_options! + @identifier = params[0] + @as = 'image' + @class = options['class'] + @variant_attrs = options.slice('resize', 'gravity', 'crop') # broken for ImageMagick + + return if @identifier.present? + + raise Error, 'Missing identifier label for image tag' + end + + # @return [Occams::Cms::File] + def file_record + @file_record ||= context.site.files.detect { |f| f.label == identifier } + end + + # @return [ActiveStorage::Blob] + def file + file_record&.attachment + end + + # @return [String] + def label + return '' if file_record.nil? + + file_record.label.presence || file.filename.to_s + end +end + +Occams::Content::Renderer.register_tag( + :image, Occams::Content::Tags::Image +) diff --git a/lib/occams/content/tags/mixins/file_content.rb b/lib/occams/content/tags/mixins/file_content.rb index 8f816691..ee1bda22 100644 --- a/lib/occams/content/tags/mixins/file_content.rb +++ b/lib/occams/content/tags/mixins/file_content.rb @@ -25,7 +25,7 @@ def content(file: self.file, as: self.as, variant_attrs: self.variant_attrs, lab when 'link' "#{label}" when 'image' - "#{label}" + "#{label}" else attachment_url end diff --git a/lib/occams/content/tags/page_file_link.rb b/lib/occams/content/tags/page_file_link.rb index 551361f5..ab14b1e8 100644 --- a/lib/occams/content/tags/page_file_link.rb +++ b/lib/occams/content/tags/page_file_link.rb @@ -16,11 +16,14 @@ # {{ cms:page_file_link attachments, filename: "cat.jpg" }} # # `as` - url (default) | link | image - how file gets rendered out +# `class` - any html classes that you want on the result link or image tag. For example "class1 class2" +# +# - the following params are deprecated / not functional, perhaps due to some change in ImageMagick +# - Simply use a class in your CSS / SASS to style your image display # `label` - attach label attribute to link or image tag # `resize` - imagemagick option. For example: "100x50>" # `gravity` - imagemagick option. For example: "center" # `crop` - imagemagick option. For example: "100x50+0+0" -# `class` - any html classes that you want on the result link or image tag. For example "class1 class2" # class Occams::Content::Tags::PageFileLink < Occams::Content::Tag include Occams::Content::Tags::Mixins::FileContent diff --git a/lib/occams/error.rb b/lib/occams/error.rb index 396edaa3..f212cceb 100644 --- a/lib/occams/error.rb +++ b/lib/occams/error.rb @@ -6,19 +6,19 @@ class Error < StandardError class MissingSite < Occams::Error def initialize(identifier) - super "Cannot find CMS Site with identifier: #{identifier}" + super("Cannot find CMS Site with identifier: #{identifier}") end end class MissingLayout < Occams::Error def initialize(identifier) - super "Cannot find CMS Layout with identifier: #{identifier}" + super("Cannot find CMS Layout with identifier: #{identifier}") end end class MissingPage < Occams::Error def initialize(path) - super "Cannot find CMS Page at #{path}" + super("Cannot find CMS Page at #{path}") end end end diff --git a/lib/occams/version.rb b/lib/occams/version.rb index 7e380a55..0b7bc245 100644 --- a/lib/occams/version.rb +++ b/lib/occams/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Occams - VERSION = '1.1.0' + VERSION = '1.1.1' end diff --git a/test/helpers/admin_cms_helper_test.rb b/test/helpers/admin_cms_helper_test.rb index 4a596187..801eaee2 100644 --- a/test/helpers/admin_cms_helper_test.rb +++ b/test/helpers/admin_cms_helper_test.rb @@ -67,7 +67,7 @@ def test_cms_page_file_link_multiple def test_cms_file_link_tag actual = cms_file_link_tag(@file) - assert_equal '{{ cms:file_link 593363170, as: image }}', actual + assert_equal '{{ cms:image default file }}', actual end def test_cms_file_link_tag_non_image diff --git a/test/integration/seeds_test.rb b/test/integration/seeds_test.rb index dcca44bd..2feccaa9 100644 --- a/test/integration/seeds_test.rb +++ b/test/integration/seeds_test.rb @@ -40,7 +40,7 @@ def test_seeds_enabled out = <<~HTML - header.png + header.png

Home Page Seed Contént Default Seed Snippet Content

diff --git a/test/lib/content/renderer_test.rb b/test/lib/content/renderer_test.rb index dfb428fe..1aea92e0 100644 --- a/test/lib/content/renderer_test.rb +++ b/test/lib/content/renderer_test.rb @@ -33,6 +33,7 @@ class TestBlockTag < Occams::Content::Block 'snippet' => Occams::Content::Tags::Snippet, 'asset' => Occams::Content::Tags::Asset, 'file_link' => Occams::Content::Tags::FileLink, + 'image' => Occams::Content::Tags::Image, 'page_file_link' => Occams::Content::Tags::PageFileLink, 'helper' => Occams::Content::Tags::Helper, 'partial' => Occams::Content::Tags::Partial, diff --git a/test/lib/content/tags/file_link_test.rb b/test/lib/content/tags/file_link_test.rb index 0159d40c..fa1daacc 100644 --- a/test/lib/content/tags/file_link_test.rb +++ b/test/lib/content/tags/file_link_test.rb @@ -78,7 +78,7 @@ def test_content_as_image params: [@file.id, { 'as' => 'image', 'class' => 'html-class' }] ) url = rails_blob_path(tag.file, only_path: true) - out = "default file" + out = "default file" assert_equal out, tag.content assert_equal out, tag.render end diff --git a/test/lib/content/tags/file_test.rb b/test/lib/content/tags/file_test.rb index 3f2ef806..890ac283 100644 --- a/test/lib/content/tags/file_test.rb +++ b/test/lib/content/tags/file_test.rb @@ -63,7 +63,7 @@ def test_content_as_image params: [frag.identifier, { 'as' => 'image', 'class' => 'html-class' }] ) path = rails_blob_path(frag.attachments.first, only_path: true) - out = "fragment.jpeg" + out = "fragment.jpeg" assert_equal out, tag.content end @@ -75,7 +75,7 @@ def test_content_as_image_with_variant ) variant = frag.attachments.first.variant(combine_options: { 'resize' => '50x50' }) path = rails_representation_path(variant, only_path: true) - out = "fragment.jpeg" + out = "fragment.jpeg" assert_equal out, tag.content end diff --git a/test/lib/content/tags/image_test.rb b/test/lib/content/tags/image_test.rb new file mode 100644 index 00000000..99fc1697 --- /dev/null +++ b/test/lib/content/tags/image_test.rb @@ -0,0 +1,52 @@ +# frozen_string_literal: true + +require_relative '../../../test_helper' + +class ContentTagsImageTest < ActiveSupport::TestCase + delegate :rails_blob_path, to: 'Rails.application.routes.url_helpers' + + setup do + @page = occams_cms_pages(:default) + @file = occams_cms_files(:default) + end + + # -- Tests ------------------------------------------------------------------- + + def test_init + tag = Occams::Content::Tags::Image.new(context: @page, params: ['my_image']) + assert_equal 'my_image', tag.identifier + assert_equal 'image', tag.as + end + + def test_init_without_identifier + message = 'Missing identifier label for image tag' + assert_raises Occams::Content::Tag::Error, message do + Occams::Content::Tags::Image.new(context: @page) + end + end + + def test_file + tag = Occams::Content::Tags::Image.new(context: @page, params: [@file.label]) + assert_instance_of Occams::Cms::File, tag.file_record + + tag = Occams::Content::Tags::Image.new(context: @page, params: ['invalid']) + assert_nil tag.file_record + end + + def test_content + tag = Occams::Content::Tags::Image.new( + context: @page, + params: [@file.label, { 'as' => 'image', 'class' => 'html-class' }] + ) + url = rails_blob_path(tag.file, only_path: true) + out = "default file" + assert_equal out, tag.content + assert_equal out, tag.render + end + + def test_content_when_not_found + tag = Occams::Content::Tags::Image.new(context: @page, params: ['invalid']) + assert_equal '', tag.content + assert_equal '', tag.render + end +end diff --git a/test/test_helper.rb b/test/test_helper.rb index c64321fa..e0c4b602 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -35,7 +35,7 @@ Dir[Rails.root.join('lib/**/*.rb')].each { |f| load f } end -reporter_options = { color: true, slow_count: 3 } +reporter_options = { color: true, slow_count: 4 } Minitest::Reporters.use! [Minitest::Reporters::DefaultReporter.new(reporter_options)] Rails.backtrace_cleaner.remove_silencers! @@ -43,7 +43,7 @@ class ActiveSupport::TestCase include ActionDispatch::TestProcess fixtures :all - self.use_transactional_tests = false + self.use_transactional_tests = true setup :reset_config, :reset_locale