From 7ce795e48ca15218fddeb887ca46eea4c490b620 Mon Sep 17 00:00:00 2001 From: Denny de la Haye <2021@denny.me> Date: Sat, 17 Apr 2021 15:49:51 +0100 Subject: [PATCH 1/4] Moneky-patch around deprecated method --- config/initializers/paperclip_url_escape_fix.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 config/initializers/paperclip_url_escape_fix.rb diff --git a/config/initializers/paperclip_url_escape_fix.rb b/config/initializers/paperclip_url_escape_fix.rb new file mode 100644 index 0000000..be0ccac --- /dev/null +++ b/config/initializers/paperclip_url_escape_fix.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +# Monkey-patch Paperclip to use Addressable::URI normalization instead of deprecated URI.escape +module Paperclip + module UrlGeneratorExtensions + def escape_url(url) + Addressable::URI.parse(url).normalize.to_str.gsub(escape_regex) { |m| "%#{m.ord.to_s(16).upcase}" } + end + end +end + +Paperclip::UrlGenerator.prepend(Paperclip::UrlGeneratorExtensions) From 6f827b8dfcb28c310d1f50d3e50a7d63241bf604 Mon Sep 17 00:00:00 2001 From: Denny de la Haye <2021@denny.me> Date: Sat, 17 Apr 2021 15:50:42 +0100 Subject: [PATCH 2/4] Update to Ruby 3.0.1, bump gems --- .ruby-version | 2 +- Gemfile | 38 ++++------ Gemfile.lock | 170 +++++++++++++++++++++---------------------- spec/rails_helper.rb | 2 +- 4 files changed, 99 insertions(+), 113 deletions(-) diff --git a/.ruby-version b/.ruby-version index 2c9b4ef..cb2b00e 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -2.7.3 +3.0.1 diff --git a/Gemfile b/Gemfile index 74892a5..f88fad3 100644 --- a/Gemfile +++ b/Gemfile @@ -1,27 +1,22 @@ source 'https://rubygems.org' do - gem 'rails', '~> 6.0.3' + # Rails 6.1 + gem 'rails', '~> 6.1' # Use postgres as the database for Active Record gem 'pg' - # Use Puma as the app server - gem 'puma', '~> 5.0' - # Use SCSS for stylesheets - gem 'sass-rails', '~> 6.0' - # Use Uglifier as compressor for JavaScript assets - gem 'uglifier', '>= 1.3.0' - # Use CoffeeScript for .coffee assets and views - gem 'coffee-rails', '~> 5.0' + # Use Puma as the webserver + gem 'puma' # Use jquery as the JavaScript library gem 'jquery-rails' - # Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks - gem 'turbolinks', '~> 5' - # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder - gem 'jbuilder', '~> 2.10' - # Use Redis adapter to run Action Cable in production - # gem 'redis', '~> 3.0' - # Use ActiveModel has_secure_password - # gem 'bcrypt', '~> 3.1.7' + # Use Uglifier as compressor for JavaScript assets + gem 'uglifier' + # Use SCSS for stylesheets + gem 'sass-rails' + # Use CoffeeScript for .coffee assets and views + gem 'coffee-rails' + # Turbolinks makes navigating your webapp faster: https://github.com/turbolinks/turbolinks + gem 'turbolinks' # Authenticate via Google OAuth gem 'omniauth', '~> 1.9.1' @@ -29,7 +24,7 @@ source 'https://rubygems.org' do # Store files on Amazon S3 gem 'aws-sdk-s3' - gem 'paperclip', '~> 6.1.0' + gem 'paperclip' gem 'paperclip-meta' # Add tag features @@ -45,22 +40,19 @@ source 'https://rubygems.org' do gem "nokogiri", ">= 1.11.0.rc4" group :development, :test do - # Audit gems for security vulnerabilities gem 'brakeman' gem 'bundler-audit', require: false gem 'capybara' gem 'pry-rails' - gem 'rspec-rails', '~> 4.0' + gem 'rspec-rails' end group :development do - gem 'listen', '~> 3.2.1' - gem 'rails-erd' + gem 'listen' gem 'rubocop', require: false gem 'rubocop-performance', require: false gem 'rubocop-rails', require: false gem 'rubocop-rspec', require: false - end group :test do diff --git a/Gemfile.lock b/Gemfile.lock index d5fa0b7..c9997e5 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,61 +1,68 @@ +GEM + specs: + GEM remote: https://rubygems.org/ specs: - actioncable (6.0.3.6) - actionpack (= 6.0.3.6) + actioncable (6.1.3.1) + actionpack (= 6.1.3.1) + activesupport (= 6.1.3.1) nio4r (~> 2.0) websocket-driver (>= 0.6.1) - actionmailbox (6.0.3.6) - actionpack (= 6.0.3.6) - activejob (= 6.0.3.6) - activerecord (= 6.0.3.6) - activestorage (= 6.0.3.6) - activesupport (= 6.0.3.6) + actionmailbox (6.1.3.1) + actionpack (= 6.1.3.1) + activejob (= 6.1.3.1) + activerecord (= 6.1.3.1) + activestorage (= 6.1.3.1) + activesupport (= 6.1.3.1) mail (>= 2.7.1) - actionmailer (6.0.3.6) - actionpack (= 6.0.3.6) - actionview (= 6.0.3.6) - activejob (= 6.0.3.6) + actionmailer (6.1.3.1) + actionpack (= 6.1.3.1) + actionview (= 6.1.3.1) + activejob (= 6.1.3.1) + activesupport (= 6.1.3.1) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 2.0) - actionpack (6.0.3.6) - actionview (= 6.0.3.6) - activesupport (= 6.0.3.6) - rack (~> 2.0, >= 2.0.8) + actionpack (6.1.3.1) + actionview (= 6.1.3.1) + activesupport (= 6.1.3.1) + rack (~> 2.0, >= 2.0.9) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.2.0) - actiontext (6.0.3.6) - actionpack (= 6.0.3.6) - activerecord (= 6.0.3.6) - activestorage (= 6.0.3.6) - activesupport (= 6.0.3.6) + actiontext (6.1.3.1) + actionpack (= 6.1.3.1) + activerecord (= 6.1.3.1) + activestorage (= 6.1.3.1) + activesupport (= 6.1.3.1) nokogiri (>= 1.8.5) - actionview (6.0.3.6) - activesupport (= 6.0.3.6) + actionview (6.1.3.1) + activesupport (= 6.1.3.1) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.1, >= 1.2.0) - activejob (6.0.3.6) - activesupport (= 6.0.3.6) + activejob (6.1.3.1) + activesupport (= 6.1.3.1) globalid (>= 0.3.6) - activemodel (6.0.3.6) - activesupport (= 6.0.3.6) - activerecord (6.0.3.6) - activemodel (= 6.0.3.6) - activesupport (= 6.0.3.6) - activestorage (6.0.3.6) - actionpack (= 6.0.3.6) - activejob (= 6.0.3.6) - activerecord (= 6.0.3.6) + activemodel (6.1.3.1) + activesupport (= 6.1.3.1) + activerecord (6.1.3.1) + activemodel (= 6.1.3.1) + activesupport (= 6.1.3.1) + activestorage (6.1.3.1) + actionpack (= 6.1.3.1) + activejob (= 6.1.3.1) + activerecord (= 6.1.3.1) + activesupport (= 6.1.3.1) marcel (~> 1.0.0) - activesupport (6.0.3.6) + mini_mime (~> 1.0.2) + activesupport (6.1.3.1) concurrent-ruby (~> 1.0, >= 1.0.2) - i18n (>= 0.7, < 2) - minitest (~> 5.1) - tzinfo (~> 1.1) - zeitwerk (~> 2.2, >= 2.2.2) + i18n (>= 1.6, < 2) + minitest (>= 5.1) + tzinfo (~> 2.0) + zeitwerk (~> 2.3) acts-as-taggable-on (7.0.0) activerecord (>= 5.0, < 6.2) addressable (2.7.0) @@ -91,7 +98,6 @@ GEM regexp_parser (>= 1.5, < 3.0) xpath (~> 3.2) childprocess (3.0.0) - choice (0.2.0) climate_control (0.2.0) codecov (0.5.1) simplecov (>= 0.15, < 0.22) @@ -134,8 +140,6 @@ GEM hashie (4.1.0) i18n (1.8.10) concurrent-ruby (~> 1.0) - jbuilder (2.11.2) - activesupport (>= 5.0.0) jmespath (1.4.0) jquery-rails (4.4.0) rails-dom-testing (>= 1, < 3) @@ -154,7 +158,7 @@ GEM activerecord kaminari-core (= 1.2.1) kaminari-core (1.2.1) - listen (3.2.1) + listen (3.5.1) rb-fsevent (~> 0.10, >= 0.10.3) rb-inotify (~> 0.9, >= 0.9.10) loofah (2.9.1) @@ -170,7 +174,7 @@ GEM mimemagic (0.3.10) nokogiri (~> 1) rake - mini_mime (1.1.0) + mini_mime (1.0.3) mini_portile2 (2.5.0) minitest (5.14.4) multi_json (1.15.0) @@ -224,37 +228,32 @@ GEM rack (2.2.3) rack-test (1.1.0) rack (>= 1.0, < 3) - rails (6.0.3.6) - actioncable (= 6.0.3.6) - actionmailbox (= 6.0.3.6) - actionmailer (= 6.0.3.6) - actionpack (= 6.0.3.6) - actiontext (= 6.0.3.6) - actionview (= 6.0.3.6) - activejob (= 6.0.3.6) - activemodel (= 6.0.3.6) - activerecord (= 6.0.3.6) - activestorage (= 6.0.3.6) - activesupport (= 6.0.3.6) - bundler (>= 1.3.0) - railties (= 6.0.3.6) + rails (6.1.3.1) + actioncable (= 6.1.3.1) + actionmailbox (= 6.1.3.1) + actionmailer (= 6.1.3.1) + actionpack (= 6.1.3.1) + actiontext (= 6.1.3.1) + actionview (= 6.1.3.1) + activejob (= 6.1.3.1) + activemodel (= 6.1.3.1) + activerecord (= 6.1.3.1) + activestorage (= 6.1.3.1) + activesupport (= 6.1.3.1) + bundler (>= 1.15.0) + railties (= 6.1.3.1) sprockets-rails (>= 2.0.0) rails-dom-testing (2.0.3) activesupport (>= 4.2.0) nokogiri (>= 1.6) - rails-erd (1.6.1) - activerecord (>= 4.2) - activesupport (>= 4.2) - choice (~> 0.2.0) - ruby-graphviz (~> 1.2) rails-html-sanitizer (1.3.0) loofah (~> 2.3) - railties (6.0.3.6) - actionpack (= 6.0.3.6) - activesupport (= 6.0.3.6) + railties (6.1.3.1) + actionpack (= 6.1.3.1) + activesupport (= 6.1.3.1) method_source rake (>= 0.8.7) - thor (>= 0.20.3, < 2.0) + thor (~> 1.0) rainbow (3.0.0) rake (13.0.3) rb-fsevent (0.10.4) @@ -274,10 +273,10 @@ GEM rspec-mocks (3.10.2) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.10.0) - rspec-rails (4.1.2) - actionpack (>= 4.2) - activesupport (>= 4.2) - railties (>= 4.2) + rspec-rails (5.0.1) + actionpack (>= 5.2) + activesupport (>= 5.2) + railties (>= 5.2) rspec-core (~> 3.10) rspec-expectations (~> 3.10) rspec-mocks (~> 3.10) @@ -306,8 +305,6 @@ GEM rubocop-rspec (2.2.0) rubocop (~> 1.0) rubocop-ast (>= 1.1.0) - ruby-graphviz (1.2.5) - rexml ruby-progressbar (1.11.0) ruby2_keywords (0.0.4) rubyzip (2.3.0) @@ -340,13 +337,12 @@ GEM terrapin (0.6.0) climate_control (>= 0.0.3, < 1.0) thor (1.1.0) - thread_safe (0.3.6) tilt (2.0.10) turbolinks (5.2.1) turbolinks-source (~> 5.2) turbolinks-source (5.2.0) - tzinfo (1.2.9) - thread_safe (~> 0.1) + tzinfo (2.0.4) + concurrent-ruby (~> 1.0) uglifier (4.2.0) execjs (>= 0.3.0, < 3) unicode-display_width (2.0.0) @@ -371,35 +367,33 @@ DEPENDENCIES bundler-audit! capybara! codecov! - coffee-rails (~> 5.0)! + coffee-rails! database_cleaner! - jbuilder (~> 2.10)! jquery-rails! kaminari! - listen (~> 3.2.1)! + listen! newrelic_rpm! nokogiri (>= 1.11.0.rc4)! omniauth (~> 1.9.1)! omniauth-google-oauth2! - paperclip (~> 6.1.0)! + paperclip! paperclip-meta! pg! pry-rails! - puma (~> 5.0)! - rails (~> 6.0.3)! - rails-erd! + puma! + rails (~> 6.1)! rspec! - rspec-rails (~> 4.0)! + rspec-rails! rspec_junit_formatter! rubocop! rubocop-performance! rubocop-rails! rubocop-rspec! - sass-rails (~> 6.0)! + sass-rails! selenium-webdriver! - turbolinks (~> 5)! - uglifier (>= 1.3.0)! + turbolinks! + uglifier! webdrivers (~> 4.4)! BUNDLED WITH - 2.2.5 + 2.2.15 diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index db99d8b..801aefc 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -24,7 +24,7 @@ # directory. Alternatively, in the individual `*_spec.rb` files, manually # require only the support files necessary. # -Dir[Rails.root.join('spec/support/**/*.rb')].sort.each { |f| require f } +Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f } # Checks for pending migration and applies them before tests are run. # If you are not using ActiveRecord, you can remove this line. From ff8a1c9170294faf918d2da530fcc7b64b092604 Mon Sep 17 00:00:00 2001 From: Denny de la Haye <2021@denny.me> Date: Sat, 17 Apr 2021 16:10:15 +0100 Subject: [PATCH 3/4] Update ruby+rails versions, add note re. paperclip deprecation --- README.md | 43 +++++++++++++++++++------------------------ 1 file changed, 19 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 9007e59..3873586 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,13 @@ -# README +# MahBucket - a simple file library using S3 -Mah Bucket is a simple file library with search and tagging, which uses Amazon -S3 for storage. +Mah Bucket is a simple file library with search and tagging, which uses Amazon S3 for storage. -It has primarily been developed for storing and organising image files, but -should hopefully be useful (or at least usable) for other file types too. +It has primarily been developed for storing and organising image files, but should hopefully be useful (or at least usable) for other file types too. ## Ruby and Rails versions -Mah Bucket was initially developed using Ruby 2.3.1 and Rails 5.0.1, and is -currently using Ruby 2.7.1 and Rails 6.0.3 - so it should have a fairly wide -compatibility range. If you find a version of either that it won't run with, -please let me know. +Mah Bucket was initially developed using Ruby 2.3.1 and Rails 5.0.1, and is currently using Ruby 3.0.1 and Rails 6.1.3 - so it should have a fairly wide compatibility range. If you find a version of either that it won't run with, please let me know. ## System dependencies @@ -20,11 +15,16 @@ please let me know. The paperclip gem requires ImageMagick to be installed. +### Paperflip deprecation + +The paperclip gem has been deprecated, but this app still works (with minor monkey-patching to fix the URL.escape deprecation in Ruby 3.x). + +Rewriting Mah Bucket to use ActiveStorage is on my TODO list. + + ## Services -Mah Bucket uses Amazon S3 for file storage, Google OAuth for authentication, -and was developed using Postgres for data storage - although any database -supported by ActiveRecord should work. +Mah Bucket uses Amazon S3 for file storage, Google OAuth for authentication, and was developed using Postgres for data storage - although any database supported by ActiveRecord should work in theory. ## Configuration @@ -53,15 +53,12 @@ the following command: export $(cat .env | grep -v ^# | xargs) ## How to run the test suite -`rspec` - - -## Author +`rspec` (this will visibly launch and drive a web browser on your screen) -## Copyright and Credits +## Author, Copyright, and Credits -Mah Bucket is copyright (c) 2017-2020 Denny de la Haye - https://denny.me +Mah Bucket is copyright 2017-2021 Denny de la Haye - https://denny.me Initial development was largely paid for by [38 Degrees](https://38degrees.org.uk) @@ -70,13 +67,11 @@ Initial development was greatly assisted by [Eliot Sykes](https://eliotsykes.com ## Licensing -Mah Bucket is free software; you can redistribute it and/or modify it under -the terms of the GPL (version 2 or later). There are copies of v2 and v3 of -the GPL in [docs/Licensing](docs/Licensing), or you can read them online: -https://opensource.org/licenses/gpl-2.0 -https://opensource.org/licenses/gpl-3.0 +Mah Bucket is free software; you can redistribute it and/or modify it under the terms of the GPL (version 2 or later). There are copies of v2 and v3 of the GPL in [docs/Licensing](docs/Licensing), or you can read them online: + https://opensource.org/licenses/gpl-2.0 + https://opensource.org/licenses/gpl-3.0 ## Current Status -[![CircleCI](https://circleci.com/gh/denny/MahBucket.svg?style=svg)](https://circleci.com/gh/denny/MahBucket) [![Travis CI](https://travis-ci.org/denny/MahBucket.svg?branch=main)](https://travis-ci.org/denny/MahBucket) [![codecov](https://codecov.io/gh/denny/MahBucket/branch/main/graph/badge.svg)](https://codecov.io/gh/denny/MahBucket) [![CodeClimate](https://api.codeclimate.com/v1/badges/7bc3b576f0265db7b8f8/maintainability)](https://codeclimate.com/github/denny/MahBucket/maintainability) +[![CircleCI](https://circleci.com/gh/denny/MahBucket.svg?style=svg)](https://circleci.com/gh/denny/MahBucket) [![codecov](https://codecov.io/gh/denny/MahBucket/branch/main/graph/badge.svg)](https://codecov.io/gh/denny/MahBucket) [![CodeClimate](https://api.codeclimate.com/v1/badges/7bc3b576f0265db7b8f8/maintainability)](https://codeclimate.com/github/denny/MahBucket/maintainability) From ad92642982574657e535054e567868983eb780c5 Mon Sep 17 00:00:00 2001 From: Denny de la Haye <2021@denny.me> Date: Tue, 20 Apr 2021 21:36:56 +0100 Subject: [PATCH 4/4] Update CircleCI ruby version too --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index ca4b60d..2b49dd3 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -8,7 +8,7 @@ orbs: jobs: build: docker: - - image: circleci/ruby:2.7.1-node-browsers + - image: circleci/ruby:3.0.1-node-browsers environment: - RACK_ENV=test - RAILS_ENV=test