From a08827a90b5a9be79379019cf5b242bd7236d2e3 Mon Sep 17 00:00:00 2001 From: Kasper Timm Hansen Date: Tue, 15 Jan 2019 20:21:32 +0100 Subject: Exercise Active Storage and Action Text in verification app. Allows the releaser to verify that: - A rich text description can be edited and shown *richly*. - An image/PDF can be uploaded and generate a variant that's shown. Also moves the generated app to a tmp directory for less cleanup need. --- tasks/release.rb | 45 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 3 deletions(-) (limited to 'tasks') diff --git a/tasks/release.rb b/tasks/release.rb index c1816cf533..214c1fd16e 100644 --- a/tasks/release.rb +++ b/tasks/release.rb @@ -173,17 +173,56 @@ namespace :all do end task verify: :install do - app_name = "pkg/verify-#{version}-#{Time.now.to_i}" + require "tmpdir" + + cd Dir.tmpdir + app_name = "verify-#{version}-#{Time.now.to_i}" sh "rails _#{version}_ new #{app_name} --skip-bundle" # Generate with the right version. cd app_name + substitute = -> (file_name, regex, replacement) do + File.write(file_name, File.read(file_name).sub(regex, replacement)) + end + # Replace the generated gemfile entry with the exact version. - File.write("Gemfile", File.read("Gemfile").sub(/^gem 'rails.*/, "gem 'rails', '#{version}'")) + substitute.call("Gemfile", /^gem 'rails.*/, "gem 'rails', '#{version}'") + substitute.call("Gemfile", /^# gem 'image_processing/, "gem 'image_processing") sh "bundle" sh "rails action_mailbox:install" sh "rails action_text:install" - sh "rails generate scaffold user name admin:boolean && rails db:migrate" + sh "rails generate scaffold user name description:text admin:boolean" + sh "rails db:migrate" + + # Replace the generated gemfile entry with the exact version. + substitute.call("app/models/user.rb", /end\n\z/, <<~CODE) + has_one_attached :avatar + has_rich_text :description + end + CODE + + substitute.call("app/views/users/_form.html.erb", /text_area :description %>\n <\/div>/, <<~CODE) + rich_text_area :description %>\n + +
+ Avatar: <%= form.file_field :avatar %> +
+ CODE + + substitute.call("app/views/users/show.html.erb", /description %>\n<\/p>/, <<~CODE) + description %>\n

+ +

+ <%= image_tag @user.avatar.representation(resize_to_fit: [500, 500]) %> +

+ CODE + + # Permit the avatar param. + substitute.call("app/controllers/users_controller.rb", /:admin/, ":admin, :avatar") + + if ENV["EDITOR"] + `#{ENV["EDITOR"]} #{File.expand_path(app_name)}` + end puts "Booting a Rails server. Verify the release by:" puts -- cgit v1.2.3