From 34fb09f4aaa1a289d4354d6d4bb00c10057b65ea Mon Sep 17 00:00:00 2001 From: Yasumasa Ashida Date: Wed, 27 Jan 2021 11:46:57 +0900 Subject: [PATCH 01/13] introduce Appraisal --- .gitignore | 2 ++ Appraisals | 40 +++++++++++++++++++++++++++++++++++++++ Gemfile | 10 ++++++++++ gemfiles/rails_52.gemfile | 24 +++++++++++++++++++++++ gemfiles/rails_61.gemfile | 25 ++++++++++++++++++++++++ refile.gemspec | 2 ++ 6 files changed, 103 insertions(+) create mode 100644 Appraisals create mode 100644 Gemfile create mode 100644 gemfiles/rails_52.gemfile create mode 100644 gemfiles/rails_61.gemfile diff --git a/.gitignore b/.gitignore index 29e9b965..4174cf68 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,5 @@ s3.yml spec/refile/test_app/log spec/refile/test_app/tmp spec/refile/test_app/db/*.sqlite + +vendor/bundle diff --git a/Appraisals b/Appraisals new file mode 100644 index 00000000..a1bee978 --- /dev/null +++ b/Appraisals @@ -0,0 +1,40 @@ +appraise "rails_52" do + gem "webmock", "~> 3.5.1" + gem "rspec", "~> 3.0" + gem "rspec-rails", "~> 3.3" + gem "jquery-rails" + gem "capybara" + gem "aws-sdk-s3" + gem "rack-test", "~> 0.6.2" + gem "rails", "~> 5.2" + gem "sqlite3", "~> 1.3.6", platforms: [:ruby] + gem "activerecord-jdbcsqlite3-adapter", "~> 52.1", platforms: [:jruby] + gem "poltergeist" + gem "yard" + gem "rubocop", "~> 0.49.0" + gem "puma" + gem "mini_magick" + gem "simple_form" + gem "i18n", "~> 1.2.0" +end + +appraise "rails_61" do + gem "webmock" + gem "rake" + gem "rspec" + gem "rspec-rails" + gem "jquery-rails" + gem "capybara" + gem "aws-sdk-s3" + gem "rack-test" + gem "rails", "~> 6.1.1" + gem "sqlite3", ">= 1.3.6", platforms: [:ruby] + gem "activerecord-jdbcsqlite3-adapter", ">= 52.1", platforms: [:jruby] + gem "poltergeist" + gem "yard" + gem "rubocop", ">= 0.49.0" + gem "puma" + gem "mini_magick" + gem "simple_form" + gem "i18n", ">= 1.2.0", "< 1.60" +end \ No newline at end of file diff --git a/Gemfile b/Gemfile new file mode 100644 index 00000000..a987534d --- /dev/null +++ b/Gemfile @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +source "https://rubygems.org" + +git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } + +gemspec + +# This here to make sure appraisal works with Rails 3.0.0. +gem "thor", ">= 0.14.0" diff --git a/gemfiles/rails_52.gemfile b/gemfiles/rails_52.gemfile new file mode 100644 index 00000000..2606c358 --- /dev/null +++ b/gemfiles/rails_52.gemfile @@ -0,0 +1,24 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "thor", ">= 0.14.0" +gem "webmock", "~> 3.5.1" +gem "rspec", "~> 3.0" +gem "rspec-rails", "~> 3.3" +gem "jquery-rails" +gem "capybara" +gem "aws-sdk-s3" +gem "rack-test", "~> 0.6.2" +gem "rails", "~> 5.2" +gem "sqlite3", "~> 1.3.6", platforms: [:ruby] +gem "activerecord-jdbcsqlite3-adapter", "~> 52.1", platforms: [:jruby] +gem "poltergeist" +gem "yard" +gem "rubocop", "~> 0.49.0" +gem "puma" +gem "mini_magick" +gem "simple_form" +gem "i18n", "~> 1.2.0" + +gemspec path: "../" diff --git a/gemfiles/rails_61.gemfile b/gemfiles/rails_61.gemfile new file mode 100644 index 00000000..db18da30 --- /dev/null +++ b/gemfiles/rails_61.gemfile @@ -0,0 +1,25 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "thor", ">= 0.14.0" +gem "webmock" +gem "rake" +gem "rspec" +gem "rspec-rails" +gem "jquery-rails" +gem "capybara" +gem "aws-sdk-s3" +gem "rack-test" +gem "rails", "~> 6.1.1" +gem "sqlite3", ">= 1.3.6", platforms: [:ruby] +gem "activerecord-jdbcsqlite3-adapter", ">= 52.1", platforms: [:jruby] +gem "poltergeist" +gem "yard" +gem "rubocop", ">= 0.49.0" +gem "puma" +gem "mini_magick" +gem "simple_form" +gem "i18n", ">= 1.2.0", "< 1.60" + +gemspec path: "../" diff --git a/refile.gemspec b/refile.gemspec index 73725fc1..25b07117 100644 --- a/refile.gemspec +++ b/refile.gemspec @@ -16,4 +16,6 @@ Gem::Specification.new do |spec| spec.add_dependency "sinatra", ">= 2.0.0", "<= 3.0.0" spec.add_dependency "mime-types" + + spec.add_development_dependency "appraisal" end From 00833d6e1a3d2587777cf2cd23dc6cf5d1072065 Mon Sep 17 00:00:00 2001 From: Yasumasa Ashida Date: Wed, 27 Jan 2021 18:12:10 +0900 Subject: [PATCH 02/13] fix rubocop errors --- .rubocop.yml | 15 ++++++++++----- Appraisals | 8 ++++++-- Gemfile | 2 +- Rakefile | 2 ++ config.ru | 2 ++ config/routes.rb | 2 ++ gemfiles/rails_52.gemfile | 3 ++- gemfiles/rails_61.gemfile | 1 + lib/refile.rb | 8 +++++--- lib/refile/app.rb | 2 ++ lib/refile/attacher.rb | 12 ++++++++---- lib/refile/attachment.rb | 14 ++++++++------ lib/refile/attachment/active_record.rb | 4 +++- lib/refile/attachment/multiple_attachments.rb | 6 +++--- lib/refile/attachment_definition.rb | 11 +++++++---- lib/refile/backend/file_system.rb | 3 +++ lib/refile/backend/s3.rb | 2 ++ lib/refile/backend_macros.rb | 11 +++++------ lib/refile/custom_logger.rb | 4 +++- lib/refile/download.rb | 18 ++++++++---------- lib/refile/file.rb | 2 ++ lib/refile/file_double.rb | 3 +++ lib/refile/image_processing.rb | 2 ++ lib/refile/rails.rb | 6 ++++-- lib/refile/rails/attachment_helper.rb | 6 ++++-- lib/refile/random_hasher.rb | 2 ++ lib/refile/signature.rb | 2 ++ lib/refile/simple_form.rb | 2 ++ lib/refile/type.rb | 2 ++ lib/refile/version.rb | 2 ++ refile.gemspec | 6 ++++-- spec/refile/active_record_helper.rb | 2 ++ spec/refile/app_spec.rb | 2 ++ spec/refile/attachment/active_record_spec.rb | 2 ++ spec/refile/attachment_helper_spec.rb | 2 ++ spec/refile/attachment_spec.rb | 2 ++ spec/refile/backend/file_system_spec.rb | 2 ++ spec/refile/backend_examples.rb | 2 ++ spec/refile/backend_macros_spec.rb | 2 ++ spec/refile/custom_logger_spec.rb | 2 ++ spec/refile/download_spec.rb | 2 ++ spec/refile/features/direct_upload_spec.rb | 2 ++ spec/refile/features/multiple_upload_spec.rb | 2 ++ spec/refile/features/normal_upload_spec.rb | 2 ++ spec/refile/features/presigned_upload_spec.rb | 2 ++ spec/refile/features/simple_form_spec.rb | 2 ++ spec/refile/features/single_upload_spec.rb | 2 ++ spec/refile/spec_helper.rb | 2 ++ .../accepts_attachments_for_shared_examples.rb | 2 ++ spec/refile/test_app.rb | 2 ++ .../app/controllers/application_controller.rb | 2 ++ .../app/controllers/direct_posts_controller.rb | 2 ++ .../app/controllers/home_controller.rb | 2 ++ .../controllers/multiple_posts_controller.rb | 2 ++ .../app/controllers/normal_posts_controller.rb | 2 ++ .../controllers/presigned_posts_controller.rb | 2 ++ .../simple_form_posts_controller.rb | 2 ++ .../app/controllers/single_posts_controller.rb | 2 ++ spec/refile/test_app/app/models/document.rb | 2 ++ spec/refile/test_app/app/models/post.rb | 2 ++ spec/refile/test_app/config/routes.rb | 2 ++ spec/refile_spec.rb | 3 +++ 62 files changed, 175 insertions(+), 53 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 359fa6d8..f9cf7ddf 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,10 +1,12 @@ +require: + - rubocop-performance AllCops: Exclude: - 'gemfiles/**/*' - 'vendor/**/*' DisplayCopNames: true -Metrics/LineLength: +Layout/LineLength: Max: 150 # TODO: we should decrease this to 120 Metrics/ClassLength: @@ -31,7 +33,7 @@ Metrics/CyclomaticComplexity: Metrics/PerceivedComplexity: Enabled: false -Layout/AlignParameters: +Layout/ParameterAlignment: EnforcedStyle: with_fixed_indentation Style/StringLiterals: @@ -79,13 +81,13 @@ Layout/IndentationWidth: Style/TrivialAccessors: ExactNameMatch: true -Lint/EndAlignment: +Layout/EndAlignment: EnforcedStyleAlignWith: variable -Lint/DefEndAlignment: +Layout/DefEndAlignment: Enabled: false -Lint/HandleExceptions: +Lint/SuppressedException: Enabled: false Style/SpecialGlobalVars: @@ -117,3 +119,6 @@ Style/GuardClause: Layout/MultilineMethodCallBraceLayout: Enabled: false + +Naming/MethodParameterName: + MinNameLength: 2 diff --git a/Appraisals b/Appraisals index a1bee978..74d71728 100644 --- a/Appraisals +++ b/Appraisals @@ -1,3 +1,5 @@ +# frozen_string_literal: true + appraise "rails_52" do gem "webmock", "~> 3.5.1" gem "rspec", "~> 3.0" @@ -11,7 +13,8 @@ appraise "rails_52" do gem "activerecord-jdbcsqlite3-adapter", "~> 52.1", platforms: [:jruby] gem "poltergeist" gem "yard" - gem "rubocop", "~> 0.49.0" + gem "rubocop", ">= 0.49.0" + gem "rubocop-performance" gem "puma" gem "mini_magick" gem "simple_form" @@ -33,8 +36,9 @@ appraise "rails_61" do gem "poltergeist" gem "yard" gem "rubocop", ">= 0.49.0" + gem "rubocop-performance" gem "puma" gem "mini_magick" gem "simple_form" gem "i18n", ">= 1.2.0", "< 1.60" -end \ No newline at end of file +end diff --git a/Gemfile b/Gemfile index a987534d..cee5a741 100644 --- a/Gemfile +++ b/Gemfile @@ -2,7 +2,7 @@ source "https://rubygems.org" -git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } +git_source(:github) { |repo_name| "https://github.com/#{repo_name}" } gemspec diff --git a/Rakefile b/Rakefile index f2bed83a..eac533f0 100644 --- a/Rakefile +++ b/Rakefile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + $LOAD_PATH.unshift(File.expand_path("lib", File.dirname(__FILE__))) $LOAD_PATH.unshift(File.expand_path("spec", File.dirname(__FILE__))) diff --git a/config.ru b/config.ru index 3fbebb6d..c7329da9 100644 --- a/config.ru +++ b/config.ru @@ -1,3 +1,5 @@ +# frozen_string_literal: true + $LOAD_PATH.unshift(File.expand_path("spec", File.dirname(__FILE__))) require "refile/test_app" diff --git a/config/routes.rb b/config/routes.rb index 1395e328..b1df0102 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + if Refile.automount Rails.application.routes.draw do mount Refile.app, at: Refile.mount_point, as: :refile_app diff --git a/gemfiles/rails_52.gemfile b/gemfiles/rails_52.gemfile index 2606c358..b1bf0c7f 100644 --- a/gemfiles/rails_52.gemfile +++ b/gemfiles/rails_52.gemfile @@ -15,7 +15,8 @@ gem "sqlite3", "~> 1.3.6", platforms: [:ruby] gem "activerecord-jdbcsqlite3-adapter", "~> 52.1", platforms: [:jruby] gem "poltergeist" gem "yard" -gem "rubocop", "~> 0.49.0" +gem "rubocop", ">= 0.49.0" +gem "rubocop-performance" gem "puma" gem "mini_magick" gem "simple_form" diff --git a/gemfiles/rails_61.gemfile b/gemfiles/rails_61.gemfile index db18da30..9e3e9dc4 100644 --- a/gemfiles/rails_61.gemfile +++ b/gemfiles/rails_61.gemfile @@ -17,6 +17,7 @@ gem "activerecord-jdbcsqlite3-adapter", ">= 52.1", platforms: [:jruby] gem "poltergeist" gem "yard" gem "rubocop", ">= 0.49.0" +gem "rubocop-performance" gem "puma" gem "mini_magick" gem "simple_form" diff --git a/lib/refile.rb b/lib/refile.rb index c2870134..5735ea1f 100644 --- a/lib/refile.rb +++ b/lib/refile.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "uri" require "fileutils" require "tempfile" @@ -259,7 +261,7 @@ def extract_content_type(uploadable) filename = extract_filename(uploadable) if filename content_type = MIME::Types.of(filename).first - content_type.to_s if content_type + content_type&.to_s end end end @@ -316,7 +318,7 @@ def app_url(host: nil, prefix: nil) # @param [String, nil] expires_at Adds a sulfix to the URL that sets the expiration time of the URL # @param [String, nil] force_download Adds a sulfix to the URL to force the download of the file when URL is accessed # @return [String, nil] The generated URL - def file_url(file, *args, expires_at: nil, host: nil, prefix: nil, filename:, format: nil, force_download: nil) + def file_url(file, *args, filename:, expires_at: nil, host: nil, prefix: nil, format: nil, force_download: nil) return unless file host ||= Refile.cdn_host @@ -512,7 +514,7 @@ def parse_json(data, *args) config.allow_uploads_to = ["cache"] config.allow_downloads_from = :all config.allow_origin = "*" - config.logger = Logger.new(STDOUT) unless ENV["RACK_ENV"] == "test" + config.logger = Logger.new($stdout) unless ENV["RACK_ENV"] == "test" config.mount_point = "/attachments" config.automount = true config.content_max_age = 60 * 60 * 24 * 365 diff --git a/lib/refile/app.rb b/lib/refile/app.rb index e61c7942..f4112e2c 100644 --- a/lib/refile/app.rb +++ b/lib/refile/app.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "json" require "sinatra/base" require "tempfile" diff --git a/lib/refile/attacher.rb b/lib/refile/attacher.rb index 42773c02..00f0d144 100644 --- a/lib/refile/attacher.rb +++ b/lib/refile/attacher.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Refile # @api private class Attacher @@ -82,9 +84,10 @@ def set(value) end def retrieve!(value) - if value.is_a?(String) + case value + when String @metadata = Refile.parse_json(value, symbolize_names: true) || {} - elsif value.is_a?(Hash) + when Hash @metadata = value end write_metadata if cache_id @@ -163,14 +166,15 @@ def valid? private - def read(column, strict = false) + def read(column, strict: false) m = "#{name}_#{column}" value ||= record.send(m) if strict or record.respond_to?(m) value end - def write(column, value, strict = false) + def write(column, value, strict: false) return if record.frozen? + m = "#{name}_#{column}=" record.send(m, value) if strict or record.respond_to?(m) end diff --git a/lib/refile/attachment.rb b/lib/refile/attachment.rb index 7abf0d8f..af7719f4 100644 --- a/lib/refile/attachment.rb +++ b/lib/refile/attachment.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Refile module Attachment # Macro which generates accessors for the given column which make it @@ -38,12 +40,12 @@ module Attachment # @return [void] def attachment(name, cache: :cache, store: :store, raise_errors: true, type: nil, extension: nil, content_type: nil) definition = AttachmentDefinition.new(name, - cache: cache, - store: store, - raise_errors: raise_errors, - type: type, - extension: extension, - content_type: content_type + cache: cache, + store: store, + raise_errors: raise_errors, + type: type, + extension: extension, + content_type: content_type ) define_singleton_method :"#{name}_attachment_definition" do diff --git a/lib/refile/attachment/active_record.rb b/lib/refile/attachment/active_record.rb index fc53f892..c1836db5 100644 --- a/lib/refile/attachment/active_record.rb +++ b/lib/refile/attachment/active_record.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Refile module ActiveRecord module Attachment @@ -80,7 +82,7 @@ def accepts_attachments_for(association_name, attachment: :file, append: false) association = reflect_on_association(association_name) attachment_pluralized = attachment.to_s.pluralize name = "#{association_name}_#{attachment_pluralized}" - collection_class = association && association.klass + collection_class = association&.klass options = { collection_class: collection_class, diff --git a/lib/refile/attachment/multiple_attachments.rb b/lib/refile/attachment/multiple_attachments.rb index 1ee262f2..bf7ee599 100644 --- a/lib/refile/attachment/multiple_attachments.rb +++ b/lib/refile/attachment/multiple_attachments.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Refile module Attachment # Builds a module to be used by "accepts_attachments_for" @@ -30,9 +32,7 @@ def self.new(collection_name, collection_class:, name:, attachment:, append:, &b cache = cache.reject(&:empty?) files = files.compact - if not append and (!files.empty? or !cache.empty?) - send("#{collection_name}=", []) - end + send("#{collection_name}=", []) if not append and (!files.empty? or !cache.empty?) collection = send(collection_name) diff --git a/lib/refile/attachment_definition.rb b/lib/refile/attachment_definition.rb index 010d66a5..a4453e37 100644 --- a/lib/refile/attachment_definition.rb +++ b/lib/refile/attachment_definition.rb @@ -1,7 +1,9 @@ +# frozen_string_literal: true + module Refile # @api private class AttachmentDefinition - attr_reader :record, :name, :cache, :store, :options, :type, :valid_content_types + attr_reader :record, :name, :options, :type, :valid_content_types attr_accessor :remove def initialize(name, cache:, store:, raise_errors: true, type: nil, extension: nil, content_type: nil) @@ -37,6 +39,7 @@ def raise_errors? def valid_extensions return unless @extension + if @extension.is_a?(Proc) Array(@extension.call) else @@ -60,15 +63,15 @@ def validate(attacher) private def extension_error_params(extension) - [:invalid_extension, extension: format_param(extension), permitted: valid_extensions.to_sentence] + [:invalid_extension, { extension: format_param(extension), permitted: valid_extensions.to_sentence }] end def content_type_error_params(content_type) - [:invalid_content_type, content: format_param(content_type), permitted: valid_content_types.to_sentence] + [:invalid_content_type, { content: format_param(content_type), permitted: valid_content_types.to_sentence }] end def invalid_extension?(extension) - extension_included = valid_extensions && valid_extensions.map(&:downcase).include?(extension) + extension_included = valid_extensions&.map(&:downcase)&.include?(extension) valid_extensions and not extension_included end diff --git a/lib/refile/backend/file_system.rb b/lib/refile/backend/file_system.rb index cfed70c0..d71bad29 100644 --- a/lib/refile/backend/file_system.rb +++ b/lib/refile/backend/file_system.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Refile module Backend # A backend which stores uploaded files in the local filesystem @@ -104,6 +106,7 @@ def initialize(directory, max_size: nil, hasher: Refile::RandomHasher.new) # @return [void] def clear!(confirm = nil) raise Refile::Confirm unless confirm == :confirm + FileUtils.rm_rf(@directory) FileUtils.mkdir_p(@directory) end diff --git a/lib/refile/backend/s3.rb b/lib/refile/backend/s3.rb index 4eb1a641..5af275bb 100644 --- a/lib/refile/backend/s3.rb +++ b/lib/refile/backend/s3.rb @@ -1 +1,3 @@ +# frozen_string_literal: true + raise "[Refile] the S3 backend has been extracted into a separate gem, see https://github.com/refile/refile-s3" diff --git a/lib/refile/backend_macros.rb b/lib/refile/backend_macros.rb index 15c1c4d9..7541aee2 100644 --- a/lib/refile/backend_macros.rb +++ b/lib/refile/backend_macros.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Refile # Macros which make it easier to write secure backends. # @@ -21,13 +23,10 @@ def verify_uploadable(method) mod = Module.new do define_method(method) do |uploadable| [:size, :read, :eof?, :rewind, :close].each do |m| - unless uploadable.respond_to?(m) - raise Refile::InvalidFile, "does not respond to `#{m}`." - end - end - if max_size and uploadable.size > max_size - raise Refile::InvalidMaxSize, "#{uploadable.inspect} is too large" + raise Refile::InvalidFile, "does not respond to `#{m}`." unless uploadable.respond_to?(m) end + raise Refile::InvalidMaxSize, "#{uploadable.inspect} is too large" if max_size and uploadable.size > max_size + super(uploadable) end end diff --git a/lib/refile/custom_logger.rb b/lib/refile/custom_logger.rb index 47047c8f..3f4e4823 100644 --- a/lib/refile/custom_logger.rb +++ b/lib/refile/custom_logger.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "rack/body_proxy" module Refile @@ -29,7 +31,7 @@ def log(env, status, began_at) now.strftime("%F %T %z"), env["REQUEST_METHOD"], env["PATH_INFO"], - env["QUERY_STRING"].empty? ? "" : "?" + env["QUERY_STRING"], + env["QUERY_STRING"].empty? ? "" : "?#{env["QUERY_STRING"]}", status.to_s[0..3], (now - began_at) * 1000 ) diff --git a/lib/refile/download.rb b/lib/refile/download.rb index 798170e7..96d0a7f6 100644 --- a/lib/refile/download.rb +++ b/lib/refile/download.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "open-uri" require "forwardable" require "cgi" @@ -43,19 +45,17 @@ def download(uri) begin uri.open(OPTIONS) - rescue OpenURI::HTTPRedirect => exception + rescue OpenURI::HTTPRedirect => e raise Refile::TooManyRedirects if follows_remaining.zero? - uri = ensure_uri(exception.uri) + uri = ensure_uri(e.uri) follows_remaining -= 1 retry - rescue OpenURI::HTTPError => exception - if exception.message.include?("(Invalid Location URI)") - raise Refile::InvalidUrl, "Invalid Redirect URI: #{response["Location"]}" - end + rescue OpenURI::HTTPError => e + raise Refile::InvalidUrl, "Invalid Redirect URI: #{response["Location"]}" if e.message.include?("(Invalid Location URI)") - raise exception + raise e end end @@ -66,9 +66,7 @@ def ensure_uri(url) raise Refile::InvalidUrl, "Invalid URI: #{uri.inspect}" end - unless uri.is_a?(URI::HTTP) - raise Refile::InvalidUrl, "URL scheme needs to be http or https: #{uri}" - end + raise Refile::InvalidUrl, "URL scheme needs to be http or https: #{uri}" unless uri.is_a?(URI::HTTP) uri end diff --git a/lib/refile/file.rb b/lib/refile/file.rb index f46cc08c..f53a693c 100644 --- a/lib/refile/file.rb +++ b/lib/refile/file.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Refile class File # @return [Backend] the backend the file is stored in diff --git a/lib/refile/file_double.rb b/lib/refile/file_double.rb index 31f62d97..c0c8a6c4 100644 --- a/lib/refile/file_double.rb +++ b/lib/refile/file_double.rb @@ -1,6 +1,9 @@ +# frozen_string_literal: true + module Refile class FileDouble attr_reader :original_filename, :content_type + def initialize(data, name = nil, content_type: nil) @io = StringIO.new(data) @original_filename = name diff --git a/lib/refile/image_processing.rb b/lib/refile/image_processing.rb index 839ad795..de37ab44 100644 --- a/lib/refile/image_processing.rb +++ b/lib/refile/image_processing.rb @@ -1 +1,3 @@ +# frozen_string_literal: true + raise "[Refile] image processing has been extracted into a separate gem, see https://github.com/refile/refile-mini_magick" diff --git a/lib/refile/rails.rb b/lib/refile/rails.rb index f49ef59b..6ad49605 100644 --- a/lib/refile/rails.rb +++ b/lib/refile/rails.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "refile" require "refile/rails/attachment_helper" @@ -17,8 +19,8 @@ class Engine < Rails::Engine require "refile/attachment/active_record" end - ActionView::Base.send(:include, Refile::AttachmentHelper) - ActionView::Helpers::FormBuilder.send(:include, AttachmentHelper::FormBuilder) + ActionView::Base.include Refile::AttachmentHelper + ActionView::Helpers::FormBuilder.include AttachmentHelper::FormBuilder end initializer "refile.app" do diff --git a/lib/refile/rails/attachment_helper.rb b/lib/refile/rails/attachment_helper.rb index 9204b375..f41c1ea4 100644 --- a/lib/refile/rails/attachment_helper.rb +++ b/lib/refile/rails/attachment_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Refile # Rails view helpers which aid in using Refile from views. module AttachmentHelper @@ -30,7 +32,7 @@ def attachment_cache_field(method, options = {}) # @param [String, nil] host Override the host # @return [String, nil] The generated URL def attachment_url(record, name, *args, fallback: nil, **opts) - file = record && record.public_send(name) + file = record&.public_send(name) if file Refile.attachment_url(record, name, *args, **opts) elsif fallback @@ -49,7 +51,7 @@ def attachment_url(record, name, *args, fallback: nil, **opts) # @see #attachment_url # @return [ActiveSupport::SafeBuffer, nil] The generated image tag def attachment_image_tag(record, name, *args, fallback: nil, host: nil, prefix: nil, format: nil, **options) - file = record && record.public_send(name) + file = record&.public_send(name) classes = ["attachment", (record.class.model_name.singular if record), name, *options[:class]] if file diff --git a/lib/refile/random_hasher.rb b/lib/refile/random_hasher.rb index 5ae1b5cd..0f858401 100644 --- a/lib/refile/random_hasher.rb +++ b/lib/refile/random_hasher.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Refile # A file hasher which ignores the file contents and always returns a random string. class RandomHasher diff --git a/lib/refile/signature.rb b/lib/refile/signature.rb index 4832126a..3fbc23ef 100644 --- a/lib/refile/signature.rb +++ b/lib/refile/signature.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Refile # A signature summarizes an HTTP request a client can make to upload a file # to directly upload a file to a backend. This signature is usually generated diff --git a/lib/refile/simple_form.rb b/lib/refile/simple_form.rb index 88eb897e..fc89f224 100644 --- a/lib/refile/simple_form.rb +++ b/lib/refile/simple_form.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # make attachment_field behave like a normal input type so we get nice wrapper and labels # <%= f.input :cover_image, as: :attachment, direct: true, presigned: true %> module SimpleForm diff --git a/lib/refile/type.rb b/lib/refile/type.rb index a24d1c2a..a57eb069 100644 --- a/lib/refile/type.rb +++ b/lib/refile/type.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Refile # A type represents an alias for one or multiple content types. # By adding types, you could simplify this: diff --git a/lib/refile/version.rb b/lib/refile/version.rb index 11a35d46..c533ad4d 100644 --- a/lib/refile/version.rb +++ b/lib/refile/version.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Refile VERSION = "0.7.0" end diff --git a/refile.gemspec b/refile.gemspec index 25b07117..702d5dee 100644 --- a/refile.gemspec +++ b/refile.gemspec @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "./lib/refile/version" Gem::Specification.new do |spec| @@ -12,10 +14,10 @@ Gem::Specification.new do |spec| spec.files = `git ls-files lib spec app config Readme.md`.split($/).reject { |f| f.include?("test_app") } spec.require_paths = %w[lib spec] # spec is used by backend gems to run their tests - spec.required_ruby_version = ">= 2.1.0" + spec.required_ruby_version = ">= 2.4.0" - spec.add_dependency "sinatra", ">= 2.0.0", "<= 3.0.0" spec.add_dependency "mime-types" + spec.add_dependency "sinatra", ">= 2.0.0", "<= 3.0.0" spec.add_development_dependency "appraisal" end diff --git a/spec/refile/active_record_helper.rb b/spec/refile/active_record_helper.rb index 7fbbf46a..af593e28 100644 --- a/spec/refile/active_record_helper.rb +++ b/spec/refile/active_record_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "active_record" I18n.enforce_available_locales = true diff --git a/spec/refile/app_spec.rb b/spec/refile/app_spec.rb index 2efa04c5..ce19caf6 100644 --- a/spec/refile/app_spec.rb +++ b/spec/refile/app_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "rack/test" describe Refile::App do diff --git a/spec/refile/attachment/active_record_spec.rb b/spec/refile/attachment/active_record_spec.rb index b2c052f2..3b7d9ce1 100644 --- a/spec/refile/attachment/active_record_spec.rb +++ b/spec/refile/attachment/active_record_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "refile/active_record_helper" require "refile/attachment/active_record" require_relative "../support/accepts_attachments_for_shared_examples" diff --git a/spec/refile/attachment_helper_spec.rb b/spec/refile/attachment_helper_spec.rb index 517a29a6..4d749e92 100644 --- a/spec/refile/attachment_helper_spec.rb +++ b/spec/refile/attachment_helper_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "refile/rails/attachment_helper" require "refile/active_record_helper" require "refile/attachment/active_record" diff --git a/spec/refile/attachment_spec.rb b/spec/refile/attachment_spec.rb index 794d2e65..64b23101 100644 --- a/spec/refile/attachment_spec.rb +++ b/spec/refile/attachment_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "refile/active_record_helper" require_relative "support/accepts_attachments_for_shared_examples" diff --git a/spec/refile/backend/file_system_spec.rb b/spec/refile/backend/file_system_spec.rb index 9544c474..63de55c3 100644 --- a/spec/refile/backend/file_system_spec.rb +++ b/spec/refile/backend/file_system_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + RSpec.describe Refile::Backend::FileSystem do let(:backend) { Refile::Backend::FileSystem.new(File.expand_path("tmp/store1", Dir.pwd), max_size: 100) } diff --git a/spec/refile/backend_examples.rb b/spec/refile/backend_examples.rb index 007aba6f..0929270a 100644 --- a/spec/refile/backend_examples.rb +++ b/spec/refile/backend_examples.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + RSpec.shared_examples_for :backend do def uploadable(data = "hello") Refile::FileDouble.new(data) diff --git a/spec/refile/backend_macros_spec.rb b/spec/refile/backend_macros_spec.rb index 6c202b2c..b40546ff 100644 --- a/spec/refile/backend_macros_spec.rb +++ b/spec/refile/backend_macros_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + RSpec.describe Refile::BackendMacros do let(:klass) do Class.new do diff --git a/spec/refile/custom_logger_spec.rb b/spec/refile/custom_logger_spec.rb index 91d91aca..fd7ac3d5 100644 --- a/spec/refile/custom_logger_spec.rb +++ b/spec/refile/custom_logger_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "refile/custom_logger" describe Refile::CustomLogger do diff --git a/spec/refile/download_spec.rb b/spec/refile/download_spec.rb index 196c0ee8..c8613581 100644 --- a/spec/refile/download_spec.rb +++ b/spec/refile/download_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + describe Refile::Download do context "without redirects" do it "fetches the file" do diff --git a/spec/refile/features/direct_upload_spec.rb b/spec/refile/features/direct_upload_spec.rb index f22bed06..b1ecc2ed 100644 --- a/spec/refile/features/direct_upload_spec.rb +++ b/spec/refile/features/direct_upload_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "refile/test_app" feature "Direct HTTP post file uploads", :js do diff --git a/spec/refile/features/multiple_upload_spec.rb b/spec/refile/features/multiple_upload_spec.rb index 03d80c0a..97c4cc47 100644 --- a/spec/refile/features/multiple_upload_spec.rb +++ b/spec/refile/features/multiple_upload_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "refile/test_app" feature "Multiple file uploads", :js do diff --git a/spec/refile/features/normal_upload_spec.rb b/spec/refile/features/normal_upload_spec.rb index 0f7eb5b5..8f0b10f6 100644 --- a/spec/refile/features/normal_upload_spec.rb +++ b/spec/refile/features/normal_upload_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "refile/test_app" feature "Normal HTTP Post file uploads" do diff --git a/spec/refile/features/presigned_upload_spec.rb b/spec/refile/features/presigned_upload_spec.rb index b94696af..410781cb 100644 --- a/spec/refile/features/presigned_upload_spec.rb +++ b/spec/refile/features/presigned_upload_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "refile/test_app" feature "Direct HTTP post file uploads", :js do diff --git a/spec/refile/features/simple_form_spec.rb b/spec/refile/features/simple_form_spec.rb index d10e2ffb..6492ca52 100644 --- a/spec/refile/features/simple_form_spec.rb +++ b/spec/refile/features/simple_form_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "refile/test_app" feature "simple form upload" do diff --git a/spec/refile/features/single_upload_spec.rb b/spec/refile/features/single_upload_spec.rb index 3e498e7d..fddc11de 100644 --- a/spec/refile/features/single_upload_spec.rb +++ b/spec/refile/features/single_upload_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "refile/test_app" feature "single attribute form upload" do diff --git a/spec/refile/spec_helper.rb b/spec/refile/spec_helper.rb index 8c0538b5..940f70d8 100644 --- a/spec/refile/spec_helper.rb +++ b/spec/refile/spec_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + ENV["RACK_ENV"] = "test" require "refile" diff --git a/spec/refile/support/accepts_attachments_for_shared_examples.rb b/spec/refile/support/accepts_attachments_for_shared_examples.rb index b64b435d..38e69d1f 100644 --- a/spec/refile/support/accepts_attachments_for_shared_examples.rb +++ b/spec/refile/support/accepts_attachments_for_shared_examples.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + RSpec.shared_examples "accepts_attachments_for" do describe "#:association_:name=" do it "builds records from assigned files" do diff --git a/spec/refile/test_app.rb b/spec/refile/test_app.rb index 2ce4176a..5c7e1213 100644 --- a/spec/refile/test_app.rb +++ b/spec/refile/test_app.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "yaml" require "rails/all" diff --git a/spec/refile/test_app/app/controllers/application_controller.rb b/spec/refile/test_app/app/controllers/application_controller.rb index 09705d12..7944f9f9 100644 --- a/spec/refile/test_app/app/controllers/application_controller.rb +++ b/spec/refile/test_app/app/controllers/application_controller.rb @@ -1,2 +1,4 @@ +# frozen_string_literal: true + class ApplicationController < ActionController::Base end diff --git a/spec/refile/test_app/app/controllers/direct_posts_controller.rb b/spec/refile/test_app/app/controllers/direct_posts_controller.rb index d9664fcd..616f25d9 100644 --- a/spec/refile/test_app/app/controllers/direct_posts_controller.rb +++ b/spec/refile/test_app/app/controllers/direct_posts_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class DirectPostsController < ApplicationController def new @post = Post.new diff --git a/spec/refile/test_app/app/controllers/home_controller.rb b/spec/refile/test_app/app/controllers/home_controller.rb index 95f29929..54634189 100644 --- a/spec/refile/test_app/app/controllers/home_controller.rb +++ b/spec/refile/test_app/app/controllers/home_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class HomeController < ApplicationController def index end diff --git a/spec/refile/test_app/app/controllers/multiple_posts_controller.rb b/spec/refile/test_app/app/controllers/multiple_posts_controller.rb index bd19327b..8cc67635 100644 --- a/spec/refile/test_app/app/controllers/multiple_posts_controller.rb +++ b/spec/refile/test_app/app/controllers/multiple_posts_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class MultiplePostsController < ApplicationController def new @post = Post.new diff --git a/spec/refile/test_app/app/controllers/normal_posts_controller.rb b/spec/refile/test_app/app/controllers/normal_posts_controller.rb index 905627a8..b3d352b2 100644 --- a/spec/refile/test_app/app/controllers/normal_posts_controller.rb +++ b/spec/refile/test_app/app/controllers/normal_posts_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class NormalPostsController < ApplicationController def index @posts = Post.all diff --git a/spec/refile/test_app/app/controllers/presigned_posts_controller.rb b/spec/refile/test_app/app/controllers/presigned_posts_controller.rb index a1cb7435..2bc89929 100644 --- a/spec/refile/test_app/app/controllers/presigned_posts_controller.rb +++ b/spec/refile/test_app/app/controllers/presigned_posts_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class PresignedPostsController < ApplicationController def new @post = Post.new diff --git a/spec/refile/test_app/app/controllers/simple_form_posts_controller.rb b/spec/refile/test_app/app/controllers/simple_form_posts_controller.rb index 53462e4f..4cb8f449 100644 --- a/spec/refile/test_app/app/controllers/simple_form_posts_controller.rb +++ b/spec/refile/test_app/app/controllers/simple_form_posts_controller.rb @@ -1,2 +1,4 @@ +# frozen_string_literal: true + class SimpleFormPostsController < DirectPostsController end diff --git a/spec/refile/test_app/app/controllers/single_posts_controller.rb b/spec/refile/test_app/app/controllers/single_posts_controller.rb index 31591169..4aee367b 100644 --- a/spec/refile/test_app/app/controllers/single_posts_controller.rb +++ b/spec/refile/test_app/app/controllers/single_posts_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class SinglePostsController < ApplicationController def new @post = Post.new diff --git a/spec/refile/test_app/app/models/document.rb b/spec/refile/test_app/app/models/document.rb index d7b527ab..7c583475 100644 --- a/spec/refile/test_app/app/models/document.rb +++ b/spec/refile/test_app/app/models/document.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Document < ActiveRecord::Base belongs_to :post attachment :file, cache: :limited_cache diff --git a/spec/refile/test_app/app/models/post.rb b/spec/refile/test_app/app/models/post.rb index d232b4c9..848ac734 100644 --- a/spec/refile/test_app/app/models/post.rb +++ b/spec/refile/test_app/app/models/post.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Post < ActiveRecord::Base attr_accessor :requires_document diff --git a/spec/refile/test_app/config/routes.rb b/spec/refile/test_app/config/routes.rb index 890dfeec..996f529c 100644 --- a/spec/refile/test_app/config/routes.rb +++ b/spec/refile/test_app/config/routes.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Refile::TestApp.routes.draw do root to: "home#index" diff --git a/spec/refile_spec.rb b/spec/refile_spec.rb index c33b5968..641acced 100644 --- a/spec/refile_spec.rb +++ b/spec/refile_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "refile" RSpec.describe Refile do @@ -11,6 +13,7 @@ Class.new do extend Refile::Attachment attr_accessor :document_id + attachment :document end end From e30fa6169c35ce5044610e104bcf933b7e825513 Mon Sep 17 00:00:00 2001 From: Yasumasa Ashida Date: Wed, 27 Jan 2021 20:01:59 +0900 Subject: [PATCH 03/13] fix rspec errors --- lib/refile/attacher.rb | 6 +++--- lib/refile/attachment/active_record.rb | 2 +- lib/refile/attachment/multiple_attachments.rb | 2 +- lib/refile/file.rb | 2 +- spec/refile/backend/file_system_spec.rb | 2 +- spec/refile/backend_examples.rb | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/refile/attacher.rb b/lib/refile/attacher.rb index 00f0d144..250d76bf 100644 --- a/lib/refile/attacher.rb +++ b/lib/refile/attacher.rb @@ -1,4 +1,4 @@ -# frozen_string_literal: true +# frozen_string_literal: false module Refile # @api private @@ -166,13 +166,13 @@ def valid? private - def read(column, strict: false) + def read(column, strict= false) m = "#{name}_#{column}" value ||= record.send(m) if strict or record.respond_to?(m) value end - def write(column, value, strict: false) + def write(column, value, strict= false) return if record.frozen? m = "#{name}_#{column}=" diff --git a/lib/refile/attachment/active_record.rb b/lib/refile/attachment/active_record.rb index c1836db5..cf9b9044 100644 --- a/lib/refile/attachment/active_record.rb +++ b/lib/refile/attachment/active_record.rb @@ -1,4 +1,4 @@ -# frozen_string_literal: true +# frozen_string_literal: false module Refile module ActiveRecord diff --git a/lib/refile/attachment/multiple_attachments.rb b/lib/refile/attachment/multiple_attachments.rb index bf7ee599..4c2af0d3 100644 --- a/lib/refile/attachment/multiple_attachments.rb +++ b/lib/refile/attachment/multiple_attachments.rb @@ -1,4 +1,4 @@ -# frozen_string_literal: true +# frozen_string_literal: false module Refile module Attachment diff --git a/lib/refile/file.rb b/lib/refile/file.rb index f53a693c..5ac43831 100644 --- a/lib/refile/file.rb +++ b/lib/refile/file.rb @@ -1,4 +1,4 @@ -# frozen_string_literal: true +# frozen_string_literal: false module Refile class File diff --git a/spec/refile/backend/file_system_spec.rb b/spec/refile/backend/file_system_spec.rb index 63de55c3..88f2f727 100644 --- a/spec/refile/backend/file_system_spec.rb +++ b/spec/refile/backend/file_system_spec.rb @@ -1,4 +1,4 @@ -# frozen_string_literal: true +# frozen_string_literal: false RSpec.describe Refile::Backend::FileSystem do let(:backend) { Refile::Backend::FileSystem.new(File.expand_path("tmp/store1", Dir.pwd), max_size: 100) } diff --git a/spec/refile/backend_examples.rb b/spec/refile/backend_examples.rb index 0929270a..8c7ee200 100644 --- a/spec/refile/backend_examples.rb +++ b/spec/refile/backend_examples.rb @@ -1,4 +1,4 @@ -# frozen_string_literal: true +# frozen_string_literal: false RSpec.shared_examples_for :backend do def uploadable(data = "hello") From e4fe6406675f417ebb5a432cfe3a3c4288788ea0 Mon Sep 17 00:00:00 2001 From: Yasumasa Ashida Date: Wed, 27 Jan 2021 20:10:43 +0900 Subject: [PATCH 04/13] modify .rubocop.yml --- .rubocop.yml | 3 +++ lib/refile/attacher.rb | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index f9cf7ddf..9bfcb70d 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -122,3 +122,6 @@ Layout/MultilineMethodCallBraceLayout: Naming/MethodParameterName: MinNameLength: 2 + +Style/OptionalBooleanParameter: + Enabled: false diff --git a/lib/refile/attacher.rb b/lib/refile/attacher.rb index 250d76bf..97290ea3 100644 --- a/lib/refile/attacher.rb +++ b/lib/refile/attacher.rb @@ -166,13 +166,13 @@ def valid? private - def read(column, strict= false) + def read(column, strict = false) m = "#{name}_#{column}" value ||= record.send(m) if strict or record.respond_to?(m) value end - def write(column, value, strict= false) + def write(column, value, strict = false) return if record.frozen? m = "#{name}_#{column}=" From 744d4ff73a2a0a70589b40a644e2a62616ae6063 Mon Sep 17 00:00:00 2001 From: Yasumasa Ashida Date: Wed, 27 Jan 2021 23:19:46 +0900 Subject: [PATCH 05/13] fix rspec(refile_spec) error on Travis CI --- spec/refile_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/refile_spec.rb b/spec/refile_spec.rb index 641acced..8dd27ee5 100644 --- a/spec/refile_spec.rb +++ b/spec/refile_spec.rb @@ -1,4 +1,4 @@ -# frozen_string_literal: true +# frozen_string_literal: false require "refile" From 90e3338ff01ce076df46c9b84eaeb71719b9a77f Mon Sep 17 00:00:00 2001 From: Yasumasa Ashida Date: Thu, 28 Jan 2021 08:12:13 +0900 Subject: [PATCH 06/13] fix rspec(refile_spec) error on Travis CI --- lib/refile.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/refile.rb b/lib/refile.rb index 5735ea1f..ed8ee7cd 100644 --- a/lib/refile.rb +++ b/lib/refile.rb @@ -1,4 +1,4 @@ -# frozen_string_literal: true +# frozen_string_literal: false require "uri" require "fileutils" From 8521f669913a1a2e95abf280a84d28c6cc0f0b40 Mon Sep 17 00:00:00 2001 From: Yasumasa Ashida Date: Fri, 29 Jan 2021 00:02:25 +0900 Subject: [PATCH 07/13] fix rspec error on Travis CI --- Appraisals | 2 +- gemfiles/Gemfile_Rails_5_2 | 3 ++- gemfiles/rails_52.gemfile | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Appraisals b/Appraisals index 74d71728..053950bc 100644 --- a/Appraisals +++ b/Appraisals @@ -13,7 +13,7 @@ appraise "rails_52" do gem "activerecord-jdbcsqlite3-adapter", "~> 52.1", platforms: [:jruby] gem "poltergeist" gem "yard" - gem "rubocop", ">= 0.49.0" + gem "rubocop", "~> 0.81.0" gem "rubocop-performance" gem "puma" gem "mini_magick" diff --git a/gemfiles/Gemfile_Rails_5_2 b/gemfiles/Gemfile_Rails_5_2 index 7c93f351..69584167 100644 --- a/gemfiles/Gemfile_Rails_5_2 +++ b/gemfiles/Gemfile_Rails_5_2 @@ -16,7 +16,8 @@ gem "sqlite3", "~> 1.3.6", platforms: [:ruby] gem "activerecord-jdbcsqlite3-adapter", "~> 52.1", platforms: [:jruby] gem "poltergeist" gem "yard" -gem "rubocop", "~> 0.49.0" +gem "rubocop", "~> 0.81.0" +gem "rubocop-performance" gem "puma" gem "mini_magick" gem "simple_form" diff --git a/gemfiles/rails_52.gemfile b/gemfiles/rails_52.gemfile index b1bf0c7f..f1338206 100644 --- a/gemfiles/rails_52.gemfile +++ b/gemfiles/rails_52.gemfile @@ -15,7 +15,7 @@ gem "sqlite3", "~> 1.3.6", platforms: [:ruby] gem "activerecord-jdbcsqlite3-adapter", "~> 52.1", platforms: [:jruby] gem "poltergeist" gem "yard" -gem "rubocop", ">= 0.49.0" +gem "rubocop", "~> 0.81.0" gem "rubocop-performance" gem "puma" gem "mini_magick" From 2cc274ca795f40cb9a7a6dea1314cd0621c1aa4b Mon Sep 17 00:00:00 2001 From: Yasumasa Ashida Date: Fri, 29 Jan 2021 02:29:50 +0900 Subject: [PATCH 08/13] fix rspec error on Travis CI --- refile.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/refile.gemspec b/refile.gemspec index 702d5dee..990bba0a 100644 --- a/refile.gemspec +++ b/refile.gemspec @@ -14,7 +14,7 @@ Gem::Specification.new do |spec| spec.files = `git ls-files lib spec app config Readme.md`.split($/).reject { |f| f.include?("test_app") } spec.require_paths = %w[lib spec] # spec is used by backend gems to run their tests - spec.required_ruby_version = ">= 2.4.0" + spec.required_ruby_version = ">= 2.3.0" spec.add_dependency "mime-types" spec.add_dependency "sinatra", ">= 2.0.0", "<= 3.0.0" From dd4dc7769bb186c8a6fd08d59c5149fc3613c777 Mon Sep 17 00:00:00 2001 From: Yasumasa Ashida Date: Fri, 29 Jan 2021 07:57:56 +0900 Subject: [PATCH 09/13] fix Travis CI rubocop error --- .rubocop.yml | 3 --- Appraisals | 2 +- gemfiles/rails_61.gemfile | 2 +- lib/refile/backend/file_system.rb | 2 +- 4 files changed, 3 insertions(+), 6 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 9bfcb70d..f9cf7ddf 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -122,6 +122,3 @@ Layout/MultilineMethodCallBraceLayout: Naming/MethodParameterName: MinNameLength: 2 - -Style/OptionalBooleanParameter: - Enabled: false diff --git a/Appraisals b/Appraisals index 053950bc..eae9ad6d 100644 --- a/Appraisals +++ b/Appraisals @@ -35,7 +35,7 @@ appraise "rails_61" do gem "activerecord-jdbcsqlite3-adapter", ">= 52.1", platforms: [:jruby] gem "poltergeist" gem "yard" - gem "rubocop", ">= 0.49.0" + gem "rubocop", "~> 0.81.0" gem "rubocop-performance" gem "puma" gem "mini_magick" diff --git a/gemfiles/rails_61.gemfile b/gemfiles/rails_61.gemfile index 9e3e9dc4..312b1307 100644 --- a/gemfiles/rails_61.gemfile +++ b/gemfiles/rails_61.gemfile @@ -16,7 +16,7 @@ gem "sqlite3", ">= 1.3.6", platforms: [:ruby] gem "activerecord-jdbcsqlite3-adapter", ">= 52.1", platforms: [:jruby] gem "poltergeist" gem "yard" -gem "rubocop", ">= 0.49.0" +gem "rubocop", "~> 0.81.0" gem "rubocop-performance" gem "puma" gem "mini_magick" diff --git a/lib/refile/backend/file_system.rb b/lib/refile/backend/file_system.rb index d71bad29..f63482d8 100644 --- a/lib/refile/backend/file_system.rb +++ b/lib/refile/backend/file_system.rb @@ -39,7 +39,7 @@ def initialize(directory, max_size: nil, hasher: Refile::RandomHasher.new) IO.copy_stream(uploadable, path(id)) Refile::File.new(self, id) - ensure + ensure uploadable.close end From 3c8185e56a1d4d55923da834999e21cca05b2953 Mon Sep 17 00:00:00 2001 From: Yasumasa Ashida Date: Sat, 30 Jan 2021 03:22:57 +0900 Subject: [PATCH 10/13] fix Travis CI rspec error (Ruby2.5) --- gemfiles/Gemfile_Rails_5_2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gemfiles/Gemfile_Rails_5_2 b/gemfiles/Gemfile_Rails_5_2 index 69584167..ec050719 100644 --- a/gemfiles/Gemfile_Rails_5_2 +++ b/gemfiles/Gemfile_Rails_5_2 @@ -8,7 +8,7 @@ gem "rake", "< 11.0" gem "rspec", "~> 3.0" gem "rspec-rails", "~> 3.3" gem "jquery-rails" -gem "capybara", "< 3.16" +gem "capybara" gem "aws-sdk-s3" gem "rack-test", "~> 0.6.2" gem "rails", "~> 5.2" From 8496b8acf8053dbe2c118bd27f6583ddbe392426 Mon Sep 17 00:00:00 2001 From: Yasumasa Ashida Date: Sun, 7 Feb 2021 00:07:54 +0900 Subject: [PATCH 11/13] modify .travis.yml --- .travis.yml | 18 ++++++++++---- Appraisals | 9 ++++--- gemfiles/Gemfile_Rails_5_2 | 24 ------------------- .../{rails_52.gemfile => rails_5_2.gemfile} | 4 +++- .../{rails_61.gemfile => rails_6_1.gemfile} | 1 + 5 files changed, 23 insertions(+), 33 deletions(-) delete mode 100644 gemfiles/Gemfile_Rails_5_2 rename gemfiles/{rails_52.gemfile => rails_5_2.gemfile} (90%) rename gemfiles/{rails_61.gemfile => rails_6_1.gemfile} (97%) diff --git a/.travis.yml b/.travis.yml index 76fa95ed..428903d5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,13 +15,21 @@ jobs: # See https://github.com/rails/rails/commit/892eab777c418135ce0646e91bc9ebb08a29ab9b # # - rvm: 2.2 - # gemfile: gemfiles/Gemfile_Rails_5_2 + # gemfile: + # - gemfiles/Gemfile_Rails_5_2 + # - rvm: 2.3 - gemfile: gemfiles/Gemfile_Rails_5_2 + gemfile: + - gemfiles/rails_5_2.gemfile - rvm: 2.4 - gemfile: gemfiles/Gemfile_Rails_5_2 + gemfile: + - gemfiles/rails_5_2.gemfile - rvm: 2.5 - gemfile: gemfiles/Gemfile_Rails_5_2 + gemfile: + - gemfiles/rails_5_2.gemfile + #- gemfiles/rails_6_1.gemfile - rvm: 2.6 - gemfile: gemfiles/Gemfile_Rails_5_2 + gemfile: + - gemfiles/rails_5_2.gemfile + #- gemfiles/rails_6_1.gemfile diff --git a/Appraisals b/Appraisals index eae9ad6d..b44f87c1 100644 --- a/Appraisals +++ b/Appraisals @@ -1,7 +1,9 @@ # frozen_string_literal: true -appraise "rails_52" do +appraise "rails_5_2" do gem "webmock", "~> 3.5.1" + gem "bundler" + gem "rake" gem "rspec", "~> 3.0" gem "rspec-rails", "~> 3.3" gem "jquery-rails" @@ -18,11 +20,12 @@ appraise "rails_52" do gem "puma" gem "mini_magick" gem "simple_form" - gem "i18n", "~> 1.2.0" + gem "i18n", "~> 1.2.0", "< 1.60" end -appraise "rails_61" do +appraise "rails_6_1" do gem "webmock" + gem "bundler" gem "rake" gem "rspec" gem "rspec-rails" diff --git a/gemfiles/Gemfile_Rails_5_2 b/gemfiles/Gemfile_Rails_5_2 deleted file mode 100644 index ec050719..00000000 --- a/gemfiles/Gemfile_Rails_5_2 +++ /dev/null @@ -1,24 +0,0 @@ -source "https://rubygems.org" - -gemspec path: '../' - -gem "webmock", "~> 3.5.1" -gem "bundler", ">= 1.7", "<= 2.0.1" -gem "rake", "< 11.0" -gem "rspec", "~> 3.0" -gem "rspec-rails", "~> 3.3" -gem "jquery-rails" -gem "capybara" -gem "aws-sdk-s3" -gem "rack-test", "~> 0.6.2" -gem "rails", "~> 5.2" -gem "sqlite3", "~> 1.3.6", platforms: [:ruby] -gem "activerecord-jdbcsqlite3-adapter", "~> 52.1", platforms: [:jruby] -gem "poltergeist" -gem "yard" -gem "rubocop", "~> 0.81.0" -gem "rubocop-performance" -gem "puma" -gem "mini_magick" -gem "simple_form" -gem "i18n", "~> 1.2.0", "< 1.60" diff --git a/gemfiles/rails_52.gemfile b/gemfiles/rails_5_2.gemfile similarity index 90% rename from gemfiles/rails_52.gemfile rename to gemfiles/rails_5_2.gemfile index f1338206..c0d31f99 100644 --- a/gemfiles/rails_52.gemfile +++ b/gemfiles/rails_5_2.gemfile @@ -4,6 +4,8 @@ source "https://rubygems.org" gem "thor", ">= 0.14.0" gem "webmock", "~> 3.5.1" +gem "bundler" +gem "rake" gem "rspec", "~> 3.0" gem "rspec-rails", "~> 3.3" gem "jquery-rails" @@ -20,6 +22,6 @@ gem "rubocop-performance" gem "puma" gem "mini_magick" gem "simple_form" -gem "i18n", "~> 1.2.0" +gem "i18n", "~> 1.2.0", "< 1.60" gemspec path: "../" diff --git a/gemfiles/rails_61.gemfile b/gemfiles/rails_6_1.gemfile similarity index 97% rename from gemfiles/rails_61.gemfile rename to gemfiles/rails_6_1.gemfile index 312b1307..f0b3ae44 100644 --- a/gemfiles/rails_61.gemfile +++ b/gemfiles/rails_6_1.gemfile @@ -4,6 +4,7 @@ source "https://rubygems.org" gem "thor", ">= 0.14.0" gem "webmock" +gem "bundler" gem "rake" gem "rspec" gem "rspec-rails" From 4dd87f2c3164f63b9da493c637ff6c53e5e24c11 Mon Sep 17 00:00:00 2001 From: Yasumasa Ashida Date: Sun, 7 Feb 2021 01:10:19 +0900 Subject: [PATCH 12/13] modidy .travis.yml (accept Ruby2.7) --- .travis.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.travis.yml b/.travis.yml index 428903d5..89bcc8e9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -32,4 +32,8 @@ jobs: gemfile: - gemfiles/rails_5_2.gemfile #- gemfiles/rails_6_1.gemfile + - rvm: 2.7 + gemfile: + - gemfiles/rails_5_2.gemfile + #- gemfiles/rails_6_1.gemfile From 0b2e3d04a04a8ad113f3c2ab43afb9a1eef16d03 Mon Sep 17 00:00:00 2001 From: Yasumasa Ashida Date: Sun, 7 Feb 2021 02:01:29 +0900 Subject: [PATCH 13/13] modify .travis.yml (modify comment) --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 89bcc8e9..a3589353 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,7 +16,7 @@ jobs: # # - rvm: 2.2 # gemfile: - # - gemfiles/Gemfile_Rails_5_2 + # - gemfiles/rails_5_2.gemfile # - rvm: 2.3 gemfile: