diff --git a/.gitignore b/.gitignore index d4484ab46..54e603b88 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ test/dummy/public/uploads/* .DS_Store Gemfile.lock dragonfly.log +public/ diff --git a/.semaphore/semaphore.yml b/.semaphore/semaphore.yml new file mode 100644 index 000000000..5bd2bbbc8 --- /dev/null +++ b/.semaphore/semaphore.yml @@ -0,0 +1,31 @@ +version: v1.0 +name: Test CKEditor gem +agent: + machine: + type: e1-standard-2 + os_image: ubuntu2004 +blocks: + - name: 'Test' + task: + env_vars: + - name: RAILS_ENV + value: test + jobs: + - name: Test + commands: + - checkout + - sem-service start mongodb + - sem-version ruby 2.7.6 + - cache restore + - bundle install --path vendor/bundle + - cache store + # - bundle exec rake test CKEDITOR_BACKEND=paperclip + - bundle exec rake test CKEDITOR_BACKEND=active_storage + - bundle exec rake test CKEDITOR_BACKEND=carrierwave + - bundle exec rake test CKEDITOR_BACKEND=dragonfly + - bundle exec rake test CKEDITOR_BACKEND=shrine + - bundle exec rake test CKEDITOR_ORM=mongoid CKEDITOR_BACKEND=carrierwave + - bundle exec rake test:controllers + - bundle exec rake test:generators + - bundle exec rake test:integration + - bundle exec rake test:models diff --git a/CHANGELOG.md b/CHANGELOG.md index d39c51277..096076638 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ * Upgrade CKEditor to 4.22.1 version * Bump ruby version to 2.7.6 + * Temporarily turn off paperclip gem support ## Ckeditor 5.1.1 (12-1-2021) diff --git a/Gemfile b/Gemfile index 4e0bb01d5..4c36b0c74 100644 --- a/Gemfile +++ b/Gemfile @@ -4,19 +4,16 @@ source 'http://rubygems.org' gemspec -gem 'rails', '~> 5.2.4.6' +gem 'rails', '~> 6.1' platforms :ruby do gem 'sass' - gem 'sqlite3', '~> 1.3.6' - gem 'sprockets', '~> 3.7.2' + gem 'sqlite3' + gem 'sprockets-rails' + gem 'sassc' group :development, :test do - gem 'capybara', '>= 0.4.0' - gem 'jquery-rails', '~> 4.3.3' - gem 'mynyml-redgreen', '~> 0.7.1', require: 'redgreen' - gem 'rails-controller-testing' - + gem 'capybara' gem 'rubocop-rails' end @@ -24,14 +21,13 @@ platforms :ruby do gem 'carrierwave' gem 'dragonfly' gem 'mini_magick' - gem 'paperclip', '~> 6.1.0' + # gem 'paperclip', '~> 6.1.0' end group :mongoid do - gem 'bson_ext' gem 'carrierwave-mongoid', require: 'carrierwave/mongoid' - gem 'mongoid', '~> 7.0.2' - gem 'mongoid-paperclip', require: 'mongoid_paperclip' + gem 'mongoid' + # gem 'mongoid-paperclip', require: 'mongoid_paperclip' gem 'shrine' gem 'shrine-mongoid' gem 'image_processing' diff --git a/Gemfile.lock b/Gemfile.lock index 8f57ae3f6..6ad24f670 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,270 +1,283 @@ PATH remote: . specs: - ckeditor (5.1.1) + ckeditor (5.1.2) orm_adapter (~> 0.5.0) GEM remote: http://rubygems.org/ specs: - actioncable (5.2.4.6) - actionpack (= 5.2.4.6) + actioncable (6.1.7.8) + actionpack (= 6.1.7.8) + activesupport (= 6.1.7.8) nio4r (~> 2.0) websocket-driver (>= 0.6.1) - actionmailer (5.2.4.6) - actionpack (= 5.2.4.6) - actionview (= 5.2.4.6) - activejob (= 5.2.4.6) + actionmailbox (6.1.7.8) + actionpack (= 6.1.7.8) + activejob (= 6.1.7.8) + activerecord (= 6.1.7.8) + activestorage (= 6.1.7.8) + activesupport (= 6.1.7.8) + mail (>= 2.7.1) + actionmailer (6.1.7.8) + actionpack (= 6.1.7.8) + actionview (= 6.1.7.8) + activejob (= 6.1.7.8) + activesupport (= 6.1.7.8) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 2.0) - actionpack (5.2.4.6) - actionview (= 5.2.4.6) - activesupport (= 5.2.4.6) - rack (~> 2.0, >= 2.0.8) + actionpack (6.1.7.8) + actionview (= 6.1.7.8) + activesupport (= 6.1.7.8) + rack (~> 2.0, >= 2.0.9) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (5.2.4.6) - activesupport (= 5.2.4.6) + rails-html-sanitizer (~> 1.0, >= 1.2.0) + actiontext (6.1.7.8) + actionpack (= 6.1.7.8) + activerecord (= 6.1.7.8) + activestorage (= 6.1.7.8) + activesupport (= 6.1.7.8) + nokogiri (>= 1.8.5) + actionview (6.1.7.8) + activesupport (= 6.1.7.8) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.0.3) - activejob (5.2.4.6) - activesupport (= 5.2.4.6) + rails-html-sanitizer (~> 1.1, >= 1.2.0) + activejob (6.1.7.8) + activesupport (= 6.1.7.8) globalid (>= 0.3.6) - activemodel (5.2.4.6) - activesupport (= 5.2.4.6) - activerecord (5.2.4.6) - activemodel (= 5.2.4.6) - activesupport (= 5.2.4.6) - arel (>= 9.0) - activestorage (5.2.4.6) - actionpack (= 5.2.4.6) - activerecord (= 5.2.4.6) - marcel (~> 0.3.1) - activesupport (5.2.4.6) + activemodel (6.1.7.8) + activesupport (= 6.1.7.8) + activerecord (6.1.7.8) + activemodel (= 6.1.7.8) + activesupport (= 6.1.7.8) + activestorage (6.1.7.8) + actionpack (= 6.1.7.8) + activejob (= 6.1.7.8) + activerecord (= 6.1.7.8) + activesupport (= 6.1.7.8) + marcel (~> 1.0) + mini_mime (>= 1.1.0) + activesupport (6.1.7.8) concurrent-ruby (~> 1.0, >= 1.0.2) - i18n (>= 0.7, < 2) - minitest (~> 5.1) - tzinfo (~> 1.1) - addressable (2.8.0) - public_suffix (>= 2.0.2, < 5.0) - arel (9.0.0) + i18n (>= 1.6, < 2) + minitest (>= 5.1) + tzinfo (~> 2.0) + zeitwerk (~> 2.3) + addressable (2.8.7) + public_suffix (>= 2.0.2, < 7.0) ast (2.4.2) - bson (4.12.0) - bson_ext (1.5.1) - builder (3.2.4) - capybara (3.35.3) + bson (5.0.0) + builder (3.3.0) + capybara (3.39.2) addressable + matrix mini_mime (>= 0.1.3) nokogiri (~> 1.8) rack (>= 1.6.0) rack-test (>= 0.6.3) regexp_parser (>= 1.5, < 3.0) xpath (~> 3.2) - carrierwave (2.2.0) + carrierwave (2.2.6) activemodel (>= 5.0.0) activesupport (>= 5.0.0) addressable (~> 2.6) image_processing (~> 1.1) - mimemagic (>= 0.3.0) + marcel (~> 1.0.0) mini_mime (>= 0.1.3) ssrf_filter (~> 1.0) - carrierwave-mongoid (1.3.0) + carrierwave-mongoid (1.4.0) carrierwave (>= 0.8, < 3) - mongoid (>= 3.0, < 8.0) + mongoid (>= 3.0, < 9.0) mongoid-grid_fs (>= 1.3, < 3.0) - climate_control (0.2.0) - concurrent-ruby (1.1.9) + concurrent-ruby (1.3.3) content_disposition (1.0.0) crass (1.0.6) - down (5.2.0) - addressable (~> 2.5) + date (3.3.4) + down (5.4.2) + addressable (~> 2.8) dragonfly (1.4.0) addressable (~> 2.3) multi_json (~> 1.0) rack (>= 1.3) - erubi (1.10.0) - ffi (1.15.0) - globalid (0.5.2) - activesupport (>= 5.0) - i18n (1.8.11) + erubi (1.13.0) + ffi (1.17.0-arm64-darwin) + globalid (1.2.1) + activesupport (>= 6.1) + i18n (1.14.5) concurrent-ruby (~> 1.0) - image_processing (1.12.1) + image_processing (1.12.2) mini_magick (>= 4.9.5, < 5) ruby-vips (>= 2.0.17, < 3) - jquery-rails (4.3.5) - rails-dom-testing (>= 1, < 3) - railties (>= 4.2.0) - thor (>= 0.14, < 2.0) - loofah (2.12.0) + json (2.7.2) + language_server-protocol (3.17.0.3) + loofah (2.22.0) crass (~> 1.0.2) - nokogiri (>= 1.5.9) - mail (2.7.1) + nokogiri (>= 1.12.0) + mail (2.8.1) mini_mime (>= 0.1.1) - marcel (0.3.3) - mimemagic (~> 0.3.2) - method_source (1.0.0) - mime-types (3.3.1) + net-imap + net-pop + net-smtp + marcel (1.0.4) + matrix (0.4.2) + method_source (1.1.0) + mime-types (3.5.2) mime-types-data (~> 3.2015) - mime-types-data (3.2021.0225) - mimemagic (0.3.10) - nokogiri (~> 1) - rake - mini_magick (4.11.0) - mini_mime (1.1.2) - mini_portile2 (2.6.1) - minitest (5.14.4) - mongo (2.14.0) - bson (>= 4.8.2, < 5.0.0) - mongoid (7.0.12) - activemodel (>= 5.1, < 6.2) - mongo (>= 2.7.0, < 3.0.0) - mongoid-grid_fs (2.4.0) + mime-types-data (3.2024.0604) + mini_magick (4.13.1) + mini_mime (1.1.5) + mini_portile2 (2.8.7) + minitest (5.24.1) + mongo (2.20.0) + bson (>= 4.14.1, < 6.0.0) + mongoid (8.1.5) + activemodel (>= 5.1, < 7.2, != 7.0.0) + concurrent-ruby (>= 1.0.5, < 2.0) + mongo (>= 2.18.0, < 3.0.0) + ruby2_keywords (~> 0.0.5) + mongoid-grid_fs (2.5.0) mime-types (>= 1.0, < 4.0) - mongoid (>= 3.0, < 8.0) - mongoid-paperclip (0.0.11) - mongoid - paperclip (>= 2.3.6, != 4.3.0) + mongoid (>= 3.0, < 9.0) multi_json (1.15.0) - mynyml-redgreen (0.7.1) - term-ansicolor (>= 1.0.4) - nio4r (2.5.8) - nokogiri (1.12.5) - mini_portile2 (~> 2.6.1) + net-imap (0.4.14) + date + net-protocol + net-pop (0.1.2) + net-protocol + net-protocol (0.2.2) + timeout + net-smtp (0.5.0) + net-protocol + nio4r (2.7.3) + nokogiri (1.15.6-arm64-darwin) racc (~> 1.4) orm_adapter (0.5.0) - paperclip (6.1.0) - activemodel (>= 4.2.0) - activesupport (>= 4.2.0) - mime-types - mimemagic (~> 0.3.0) - terrapin (~> 0.6.0) - parallel (1.21.0) - parser (3.0.2.0) + parallel (1.25.1) + parser (3.3.3.0) ast (~> 2.4.1) - public_suffix (4.0.6) - racc (1.6.0) - rack (2.2.3) - rack-test (1.1.0) - rack (>= 1.0, < 3) - rails (5.2.4.6) - actioncable (= 5.2.4.6) - actionmailer (= 5.2.4.6) - actionpack (= 5.2.4.6) - actionview (= 5.2.4.6) - activejob (= 5.2.4.6) - activemodel (= 5.2.4.6) - activerecord (= 5.2.4.6) - activestorage (= 5.2.4.6) - activesupport (= 5.2.4.6) - bundler (>= 1.3.0) - railties (= 5.2.4.6) + racc + public_suffix (5.1.1) + racc (1.8.0) + rack (2.2.9) + rack-test (2.1.0) + rack (>= 1.3) + rails (6.1.7.8) + actioncable (= 6.1.7.8) + actionmailbox (= 6.1.7.8) + actionmailer (= 6.1.7.8) + actionpack (= 6.1.7.8) + actiontext (= 6.1.7.8) + actionview (= 6.1.7.8) + activejob (= 6.1.7.8) + activemodel (= 6.1.7.8) + activerecord (= 6.1.7.8) + activestorage (= 6.1.7.8) + activesupport (= 6.1.7.8) + bundler (>= 1.15.0) + railties (= 6.1.7.8) sprockets-rails (>= 2.0.0) - rails-controller-testing (1.0.5) - actionpack (>= 5.0.1.rc1) - actionview (>= 5.0.1.rc1) - activesupport (>= 5.0.1.rc1) - rails-dom-testing (2.0.3) - activesupport (>= 4.2.0) + rails-dom-testing (2.2.0) + activesupport (>= 5.0.0) + minitest nokogiri (>= 1.6) - rails-html-sanitizer (1.4.2) - loofah (~> 2.3) - railties (5.2.4.6) - actionpack (= 5.2.4.6) - activesupport (= 5.2.4.6) + rails-html-sanitizer (1.6.0) + loofah (~> 2.21) + nokogiri (~> 1.14) + railties (6.1.7.8) + actionpack (= 6.1.7.8) + activesupport (= 6.1.7.8) method_source - rake (>= 0.8.7) - thor (>= 0.19.0, < 2.0) - rainbow (3.0.0) - rake (13.0.6) - rb-fsevent (0.10.4) - rb-inotify (0.10.1) + rake (>= 12.2) + thor (~> 1.0) + rainbow (3.1.1) + rake (13.2.1) + rb-fsevent (0.11.2) + rb-inotify (0.11.1) ffi (~> 1.0) - regexp_parser (2.1.1) - rexml (3.2.5) - rubocop (1.22.3) + regexp_parser (2.9.2) + rexml (3.3.1) + strscan + rubocop (1.64.1) + json (~> 2.3) + language_server-protocol (>= 3.17.0) parallel (~> 1.10) - parser (>= 3.0.0.0) + parser (>= 3.3.0.2) rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 1.8, < 3.0) - rexml - rubocop-ast (>= 1.12.0, < 2.0) + rexml (>= 3.2.5, < 4.0) + rubocop-ast (>= 1.31.1, < 2.0) ruby-progressbar (~> 1.7) - unicode-display_width (>= 1.4.0, < 3.0) - rubocop-ast (1.13.0) - parser (>= 3.0.1.1) - rubocop-rails (2.12.4) + unicode-display_width (>= 2.4.0, < 3.0) + rubocop-ast (1.31.3) + parser (>= 3.3.1.0) + rubocop-rails (2.25.1) activesupport (>= 4.2.0) rack (>= 1.1) - rubocop (>= 1.7.0, < 2.0) - ruby-progressbar (1.11.0) - ruby-vips (2.1.0) + rubocop (>= 1.33.0, < 2.0) + rubocop-ast (>= 1.31.1, < 2.0) + ruby-progressbar (1.13.0) + ruby-vips (2.2.1) ffi (~> 1.12) + ruby2_keywords (0.0.5) sass (3.7.4) sass-listen (~> 4.0.0) sass-listen (4.0.0) rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) - shrine (3.3.0) + sassc (2.4.0) + ffi (~> 1.9) + shrine (3.6.0) content_disposition (~> 1.0) down (~> 5.1) shrine-mongoid (1.0.0) mongoid (>= 5.0) shrine (>= 3.0.0.beta3, < 4) - sprockets (3.7.2) + sprockets (4.2.1) concurrent-ruby (~> 1.0) - rack (> 1, < 3) - sprockets-rails (3.3.0) - actionpack (>= 5.2) - activesupport (>= 5.2) + rack (>= 2.2.4, < 4) + sprockets-rails (3.5.1) + actionpack (>= 6.1) + activesupport (>= 6.1) sprockets (>= 3.0.0) - sqlite3 (1.3.13) - ssrf_filter (1.0.7) - sync (0.5.0) - term-ansicolor (1.7.1) - tins (~> 1.0) - terrapin (0.6.0) - climate_control (>= 0.0.3, < 1.0) - thor (1.1.0) - thread_safe (0.3.6) - tins (1.28.0) - sync - tzinfo (1.2.9) - thread_safe (~> 0.1) - unicode-display_width (2.1.0) - websocket-driver (0.7.5) + sqlite3 (1.7.3) + mini_portile2 (~> 2.8.0) + ssrf_filter (1.1.2) + strscan (3.1.0) + thor (1.3.1) + timeout (0.4.1) + tzinfo (2.0.6) + concurrent-ruby (~> 1.0) + unicode-display_width (2.5.0) + websocket-driver (0.7.6) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) xpath (3.2.0) nokogiri (~> 1.8) + zeitwerk (2.6.16) PLATFORMS - ruby + arm64-darwin-21 DEPENDENCIES - bson_ext - capybara (>= 0.4.0) + capybara carrierwave carrierwave-mongoid ckeditor! dragonfly image_processing - jquery-rails (~> 4.3.3) mini_magick - mongoid (~> 7.0.2) - mongoid-paperclip - mynyml-redgreen (~> 0.7.1) - paperclip (~> 6.1.0) - rails (~> 5.2.4.6) - rails-controller-testing + mongoid + rails (~> 6.1) rubocop-rails sass + sassc shrine shrine-mongoid - sprockets (~> 3.7.2) - sqlite3 (~> 1.3.6) + sprockets-rails + sqlite3 BUNDLED WITH - 1.17.3 + 2.3.25 diff --git a/README.md b/README.md index fc845987e..4916867ad 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Ckeditor -[![Build Status](https://semaphoreci.com/api/v1/igor-galeta/ckeditor/branches/master/shields_badge.svg)](https://semaphoreci.com/igor-galeta/ckeditor) +[![Build Status](https://galetahub.semaphoreci.com/badges/ckeditor/branches/master.svg?style=shields&key=eabcab57-9b51-4460-9b27-9c61c28efcdb)](https://galetahub.semaphoreci.com/projects/ckeditor) [![Code Climate](https://codeclimate.com/github/galetahub/ckeditor/badges/gpa.svg)](https://codeclimate.com/github/galetahub/ckeditor) [![Stand With Ukraine](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/badges/StandWithUkraine.svg)](https://stand-with-ukraine.pp.ua) diff --git a/app/assets/config/manifest.js b/app/assets/config/manifest.js new file mode 100644 index 000000000..0245ca2af --- /dev/null +++ b/app/assets/config/manifest.js @@ -0,0 +1,7 @@ +//= link_tree ../images + +//= link_directory ../javascripts .js +//= link_directory ../stylesheets .css + +//= link ckeditor/application.css +//= link application.css diff --git a/lib/ckeditor/backend/shrine.rb b/lib/ckeditor/backend/shrine.rb index a37a95e15..b991cecd2 100644 --- a/lib/ckeditor/backend/shrine.rb +++ b/lib/ckeditor/backend/shrine.rb @@ -8,8 +8,12 @@ def self.included(base) end module InstanceMethods + def data=(value) + self.attachment = value + end + def url - data_url + attachment&.url end def data_file_name @@ -21,7 +25,7 @@ def data_file_size end def datasource - @datasource ||= data&.metadata || {} + @datasource ||= attachment&.metadata || {} end end end diff --git a/lib/generators/ckeditor/install_generator.rb b/lib/generators/ckeditor/install_generator.rb index 4f5effdd0..e56ac9e22 100644 --- a/lib/generators/ckeditor/install_generator.rb +++ b/lib/generators/ckeditor/install_generator.rb @@ -47,14 +47,21 @@ def create_models template "#{generator_dir}/ckeditor/#{filename}.rb", File.join('app/models', ckeditor_dir, "#{filename}.rb") end + end + def create_uploaders if backend_carrierwave? - template "#{uploaders_dir}/uploaders/ckeditor_attachment_file_uploader.rb", + template "#{uploaders_dir}/ckeditor_attachment_file_uploader.rb", File.join('app/uploaders', 'ckeditor_attachment_file_uploader.rb') - template "#{uploaders_dir}/uploaders/ckeditor_picture_uploader.rb", + template "#{uploaders_dir}/ckeditor_picture_uploader.rb", File.join('app/uploaders', 'ckeditor_picture_uploader.rb') end + + if backend_shrine? + template "#{uploaders_dir}/ckeditor_attachment_uploader.rb", + File.join('app/uploaders', 'ckeditor_attachment_uploader.rb') + end end def create_ckeditor_migration @@ -87,7 +94,7 @@ def generator_dir end def uploaders_dir - @uploaders_dir ||= 'base/carrierwave' + @uploaders_dir ||= "base/#{backend}/uploaders" end def orm diff --git a/lib/generators/ckeditor/templates/active_record/active_storage/migration.rb b/lib/generators/ckeditor/templates/active_record/active_storage/migration.rb index 0d27b624a..a4d905c4c 100644 --- a/lib/generators/ckeditor/templates/active_record/active_storage/migration.rb +++ b/lib/generators/ckeditor/templates/active_record/active_storage/migration.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class CreateCkeditorAssets < ActiveRecord::Migration[5.2] +class CreateCkeditorAssets < ActiveRecord::Migration[6.1] def up create_table :ckeditor_assets do |t| t.string :data_file_name, null: false diff --git a/lib/generators/ckeditor/templates/active_record/carrierwave/migration.rb b/lib/generators/ckeditor/templates/active_record/carrierwave/migration.rb index cbb307e66..c657599be 100644 --- a/lib/generators/ckeditor/templates/active_record/carrierwave/migration.rb +++ b/lib/generators/ckeditor/templates/active_record/carrierwave/migration.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class CreateCkeditorAssets < ActiveRecord::Migration[5.2] +class CreateCkeditorAssets < ActiveRecord::Migration[6.1] def up create_table :ckeditor_assets do |t| t.string :data_file_name, null: false diff --git a/lib/generators/ckeditor/templates/active_record/dragonfly/migration.rb b/lib/generators/ckeditor/templates/active_record/dragonfly/migration.rb index ca60e72ed..7c2025cd7 100644 --- a/lib/generators/ckeditor/templates/active_record/dragonfly/migration.rb +++ b/lib/generators/ckeditor/templates/active_record/dragonfly/migration.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class CreateCkeditorAssets < ActiveRecord::Migration[5.2] +class CreateCkeditorAssets < ActiveRecord::Migration[6.1] def up create_table :ckeditor_assets do |t| t.string :data_uid, null: false diff --git a/lib/generators/ckeditor/templates/active_record/paperclip/migration.rb b/lib/generators/ckeditor/templates/active_record/paperclip/migration.rb index 0d27b624a..a4d905c4c 100644 --- a/lib/generators/ckeditor/templates/active_record/paperclip/migration.rb +++ b/lib/generators/ckeditor/templates/active_record/paperclip/migration.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class CreateCkeditorAssets < ActiveRecord::Migration[5.2] +class CreateCkeditorAssets < ActiveRecord::Migration[6.1] def up create_table :ckeditor_assets do |t| t.string :data_file_name, null: false diff --git a/lib/generators/ckeditor/templates/active_record/shrine/ckeditor/asset.rb b/lib/generators/ckeditor/templates/active_record/shrine/ckeditor/asset.rb new file mode 100644 index 000000000..ded33403d --- /dev/null +++ b/lib/generators/ckeditor/templates/active_record/shrine/ckeditor/asset.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +class Ckeditor::Asset < ActiveRecord::Base + include Ckeditor::Orm::ActiveRecord::AssetBase + include Ckeditor::Backend::Shrine + + include CkeditorAttachmentUploader::Attachment(:attachment) + + validates :attachment_data, presence: true +end diff --git a/lib/generators/ckeditor/templates/active_record/shrine/ckeditor/attachment_file.rb b/lib/generators/ckeditor/templates/active_record/shrine/ckeditor/attachment_file.rb new file mode 100644 index 000000000..dc315b5d1 --- /dev/null +++ b/lib/generators/ckeditor/templates/active_record/shrine/ckeditor/attachment_file.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class Ckeditor::AttachmentFile < Ckeditor::Asset + def url_thumb + Ckeditor::Utils.filethumb(filename) + end +end diff --git a/lib/generators/ckeditor/templates/active_record/shrine/ckeditor/picture.rb b/lib/generators/ckeditor/templates/active_record/shrine/ckeditor/picture.rb new file mode 100644 index 000000000..6920853df --- /dev/null +++ b/lib/generators/ckeditor/templates/active_record/shrine/ckeditor/picture.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +class Ckeditor::Picture < Ckeditor::Asset + def url_content + attachment&.url + end + + def url_thumb + attachment&.url + end +end diff --git a/lib/generators/ckeditor/templates/active_record/shrine/migration.rb b/lib/generators/ckeditor/templates/active_record/shrine/migration.rb new file mode 100644 index 000000000..cf8a9ca4f --- /dev/null +++ b/lib/generators/ckeditor/templates/active_record/shrine/migration.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +class CreateCkeditorAssets < ActiveRecord::Migration[6.1] + def up + create_table :ckeditor_assets do |t| + t.integer :data_size + t.string :type, limit: 30 + + # Shrine column + t.text :attachment_data + + # Uncomment these to save image dimensions, if your need them. + # t.integer :data_width + # t.integer :data_height + + t.timestamps null: false + end + + add_index :ckeditor_assets, :type + end + + def down + drop_table :ckeditor_assets + end +end diff --git a/lib/generators/ckeditor/templates/base/shrine/initializer.rb b/lib/generators/ckeditor/templates/base/shrine/initializer.rb index 981e36f56..56dac3d3f 100644 --- a/lib/generators/ckeditor/templates/base/shrine/initializer.rb +++ b/lib/generators/ckeditor/templates/base/shrine/initializer.rb @@ -8,16 +8,15 @@ require 'image_processing/mini_magick' SHRINE_PICTURE_PROCESSOR = ImageProcessing::MiniMagick -# require 'image_processing/vips' -# SHRINE_PICTURE_PROCESSOR = ImageProcessing::Vips - Shrine.storages = { cache: Shrine::Storage::FileSystem.new('public', prefix: 'uploads/cache'), store: Shrine::Storage::FileSystem.new('public', prefix: 'system') } -Shrine.plugin :determine_mime_type Shrine.plugin :mongoid +Shrine.plugin :activerecord + +Shrine.plugin :determine_mime_type Shrine.plugin :instrumentation Shrine.plugin :validation_helpers diff --git a/lib/generators/ckeditor/templates/base/shrine/uploaders/ckeditor_attachment_uploader.rb b/lib/generators/ckeditor/templates/base/shrine/uploaders/ckeditor_attachment_uploader.rb new file mode 100644 index 000000000..30d7921f2 --- /dev/null +++ b/lib/generators/ckeditor/templates/base/shrine/uploaders/ckeditor_attachment_uploader.rb @@ -0,0 +1,8 @@ +class CkeditorAttachmentUploader < Shrine + plugin :validation_helpers + + Attacher.validate do + validate_max_size 5*1024*1024 # file size must not be greater than 5 MB + validate_min_size 1024 # file size must not be less than 1 KB + end +end diff --git a/test/controllers/attachment_files_controller_test.rb b/test/controllers/attachment_files_controller_test.rb index ac4f8d1d3..8f86878bb 100644 --- a/test/controllers/attachment_files_controller_test.rb +++ b/test/controllers/attachment_files_controller_test.rb @@ -6,7 +6,8 @@ class AttachmentFilesControllerTest < ActionController::TestCase tests Ckeditor::AttachmentFilesController def setup - @attachment = fixture_file_upload('files/rails.tar.gz', 'application/x-gzip') + @attachment = Rack::Test::UploadedFile.new('test/dummy/test/fixtures/files/rails.tar.gz', 'application/x-gzip') + @routes = Ckeditor::Engine.routes end @@ -18,7 +19,6 @@ def teardown get :index assert_equal 200, @response.status - assert_template 'ckeditor/attachment_files/index' end test 'create action via filebrowser' do diff --git a/test/controllers/pictures_controller_test.rb b/test/controllers/pictures_controller_test.rb index b9d7ac3ef..942d6b188 100644 --- a/test/controllers/pictures_controller_test.rb +++ b/test/controllers/pictures_controller_test.rb @@ -6,7 +6,7 @@ class PicturesControllerTest < ActionController::TestCase tests Ckeditor::PicturesController def setup - @image = fixture_file_upload('files/rails.png', 'image/png') + @image = Rack::Test::UploadedFile.new('test/dummy/test/fixtures/files/rails.png', 'image/png') @routes = Ckeditor::Engine.routes end @@ -18,7 +18,6 @@ def teardown get :index assert_equal 200, @response.status - assert_template 'ckeditor/pictures/index' end test 'create action via filebrowser' do @@ -54,7 +53,7 @@ def teardown end test 'destroy action via filebrowser' do - @picture = Ckeditor::Picture.create data: @image + @picture = Ckeditor::Picture.create! data: @image assert_difference 'Ckeditor::Picture.count', -1 do delete :destroy, params: { id: @picture.id } diff --git a/test/dummy/app/assets/config/manifest.js b/test/dummy/app/assets/config/manifest.js new file mode 100644 index 000000000..03c818ac1 --- /dev/null +++ b/test/dummy/app/assets/config/manifest.js @@ -0,0 +1,5 @@ +//= link_directory ../javascripts .js +//= link_directory ../stylesheets .css + +//= link ckeditor/application.css +//= link application.css diff --git a/test/dummy/app/assets/javascripts/application.js b/test/dummy/app/assets/javascripts/application.js index fc19b8e61..c06621454 100644 --- a/test/dummy/app/assets/javascripts/application.js +++ b/test/dummy/app/assets/javascripts/application.js @@ -4,5 +4,3 @@ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the // the compiled file. // -//= require jquery -//= require jquery_ujs diff --git a/test/dummy/config/environments/test.rb b/test/dummy/config/environments/test.rb index 59e0419fc..1ba44f88f 100644 --- a/test/dummy/config/environments/test.rb +++ b/test/dummy/config/environments/test.rb @@ -37,5 +37,5 @@ config.active_support.test_order = :sorted - config.active_record.sqlite3.represent_boolean_as_integer = true + config.assets.precompile += %w( ckeditor/application.css ckeditor/application.js application.css ) end diff --git a/test/dummy/db/migrate/20110623120047_create_posts.rb b/test/dummy/db/migrate/20110623120047_create_posts.rb index 15b0eba6d..774b41807 100644 --- a/test/dummy/db/migrate/20110623120047_create_posts.rb +++ b/test/dummy/db/migrate/20110623120047_create_posts.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class CreatePosts < ActiveRecord::Migration[5.2] +class CreatePosts < ActiveRecord::Migration[6.1] def up create_table :posts do |t| t.string :title diff --git a/test/dummy/db/migrate/20170806125915_create_active_storage_tables.rb b/test/dummy/db/migrate/20170806125915_create_active_storage_tables.rb index cfaf01cd5..54dfa0d6a 100644 --- a/test/dummy/db/migrate/20170806125915_create_active_storage_tables.rb +++ b/test/dummy/db/migrate/20170806125915_create_active_storage_tables.rb @@ -1,4 +1,4 @@ -class CreateActiveStorageTables < ActiveRecord::Migration[5.2] +class CreateActiveStorageTables < ActiveRecord::Migration[6.1] def change create_table :active_storage_blobs do |t| t.string :key, null: false @@ -8,6 +8,7 @@ def change t.bigint :byte_size, null: false t.string :checksum, null: false t.datetime :created_at, null: false + t.string :service_name, null: false t.index [ :key ], unique: true end diff --git a/test/dummy/db/migrate/20240702124877_create_active_storage_variant_records.rb b/test/dummy/db/migrate/20240702124877_create_active_storage_variant_records.rb new file mode 100644 index 000000000..70185bbf4 --- /dev/null +++ b/test/dummy/db/migrate/20240702124877_create_active_storage_variant_records.rb @@ -0,0 +1,13 @@ +# This migration comes from active_storage (originally 20191206030411) +class CreateActiveStorageVariantRecords < ActiveRecord::Migration[6.1] + def up + create_table :active_storage_variant_records do |t| + t.belongs_to :blob, null: false, index: false + t.string :variation_digest, null: false + + t.index %i[ blob_id variation_digest ], name: "index_active_storage_variant_records_uniqueness", + unique: true + t.foreign_key :active_storage_blobs, column: :blob_id + end + end +end diff --git a/test/models/picture_test.rb b/test/models/picture_test.rb index 57809b91e..4de3b3390 100644 --- a/test/models/picture_test.rb +++ b/test/models/picture_test.rb @@ -10,7 +10,8 @@ def teardown test 'Set file content_type and size' do @picture = create_picture - assert_equal 'rails.png', @picture.data_file_name unless CKEDITOR_BACKEND == :shrine + assert_equal 'rails.png', @picture.data_file_name + case CKEDITOR_BACKEND when :dragonfly assert @picture.url_thumb.include?('thumb_rails') @@ -18,7 +19,6 @@ def teardown assert @picture.url_thumb =~ /\/representations\/.*\/rails.png/ when :shrine assert @picture.url_thumb =~ /\S{32}\.png/ - assert @picture.data_file_name =~ /image_processing(\d{8})-(\d{5})-(\S{,7})\.png/ else assert @picture.url_thumb.include?('thumb_rails.png') end diff --git a/test/orm/active_record.rb b/test/orm/active_record.rb index dc7c09c43..2d475fb2a 100644 --- a/test/orm/active_record.rb +++ b/test/orm/active_record.rb @@ -7,5 +7,6 @@ def activerecord_below_5_2? if activerecord_below_5_2? ActiveRecord::Migrator.migrate('test/dummy/db/migrate') else - ActiveRecord::MigrationContext.new('test/dummy/db/migrate').migrate + schema_migration = ActiveRecord::Base.connection.schema_migration + ActiveRecord::MigrationContext.new('test/dummy/db/migrate', schema_migration).migrate end diff --git a/test/support/helpers.rb b/test/support/helpers.rb index 3a2987d28..61431a25a 100644 --- a/test/support/helpers.rb +++ b/test/support/helpers.rb @@ -7,9 +7,9 @@ class ActiveSupport::TestCase include ActionDispatch::TestProcess def new_attachment(data = nil) - data ||= fixture_file_upload('files/rails.tar.gz', 'application/x-gzip') + data ||= Rack::Test::UploadedFile.new('test/dummy/test/fixtures/files/rails.tar.gz', 'application/x-gzip') - Ckeditor.attachment_file_model.new(:data => data) + Ckeditor.attachment_file_model.new(data: data) end def create_attachment(data = nil) @@ -19,9 +19,9 @@ def create_attachment(data = nil) end def new_picture(data = nil) - data ||= fixture_file_upload('files/rails.png', 'image/png') + data ||= Rack::Test::UploadedFile.new('test/dummy/test/fixtures/files/rails.png', 'image/png') - Ckeditor.picture_model.new(:data => data) + Ckeditor.picture_model.new(data: data) end def create_picture(data = nil) diff --git a/test/test_helper.rb b/test/test_helper.rb index 83f89afa5..e1e2f7080 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -3,7 +3,7 @@ # Configure Rails Envinronment ENV['RAILS_ENV'] = 'test' CKEDITOR_ORM = (ENV['CKEDITOR_ORM'] || :active_record).to_sym -CKEDITOR_BACKEND = (ENV['CKEDITOR_BACKEND'] || :paperclip).to_sym +CKEDITOR_BACKEND = (ENV['CKEDITOR_BACKEND'] || :carrierwave).to_sym $:.unshift File.dirname(__FILE__) puts "\n==> Ckeditor.orm = #{CKEDITOR_ORM.inspect}. CKEDITOR_ORM = (active_record|mongoid)" @@ -11,7 +11,6 @@ require File.expand_path('../dummy/config/environment.rb', __FILE__) require 'rails/test_help' -require 'redgreen' Rails.backtrace_cleaner.remove_silencers!