From 463028a1f706a169503c913b992d9cc07507a2a7 Mon Sep 17 00:00:00 2001 From: Richard Anthony Date: Sun, 23 Jan 2022 18:54:32 +1100 Subject: [PATCH 1/5] Update rails conductor command controller --- .../controllers/rails/conductor/command_controller.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/conductor/app/controllers/rails/conductor/command_controller.rb b/conductor/app/controllers/rails/conductor/command_controller.rb index e98f879228bff..38042678d0dd5 100644 --- a/conductor/app/controllers/rails/conductor/command_controller.rb +++ b/conductor/app/controllers/rails/conductor/command_controller.rb @@ -1,6 +1,11 @@ # frozen_string_literal: true class Rails::Conductor::CommandController < Rails::Conductor::BaseController + def generate + Rails::Command.invoke "generate", command_params + end + + private def capture_stdout original_stdout, $stdout = $stdout, StringIO.new @@ -9,4 +14,8 @@ def capture_stdout ensure $stdout = original_stdout end + + def command_params + @command_params ||= params.require(:command).permit(:namespace, options:[]) + end end From aa98a2bd8edc2bcf27175d8e911378de2a678442 Mon Sep 17 00:00:00 2001 From: Richard Anthony Date: Sun, 23 Jan 2022 18:55:43 +1100 Subject: [PATCH 2/5] Copy the Rakefile from actionmailbox --- conductor/Rakefile | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 conductor/Rakefile diff --git a/conductor/Rakefile b/conductor/Rakefile new file mode 100644 index 0000000000000..36aed17282614 --- /dev/null +++ b/conductor/Rakefile @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +require "bundler/setup" +require "bundler/gem_tasks" +require "rake/testtask" + +task :package + +Rake::TestTask.new do |t| + t.libs << "test" + t.pattern = "test/**/*_test.rb" + t.verbose = true +end + +task default: :test From fa57c7e650f95b44474adb6238709c797e1a7f00 Mon Sep 17 00:00:00 2001 From: Richard Anthony Date: Sun, 23 Jan 2022 18:56:14 +1100 Subject: [PATCH 3/5] Janky test for CommandController --- .../conductor/command_controller_test.rb | 31 +++++++++++++++++++ conductor/test/test_helper.rb | 6 ++++ 2 files changed, 37 insertions(+) create mode 100644 conductor/test/controllers/rails/conductor/command_controller_test.rb create mode 100644 conductor/test/test_helper.rb diff --git a/conductor/test/controllers/rails/conductor/command_controller_test.rb b/conductor/test/controllers/rails/conductor/command_controller_test.rb new file mode 100644 index 0000000000000..27f23ccecf779 --- /dev/null +++ b/conductor/test/controllers/rails/conductor/command_controller_test.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +require "test_helper" + +class Rails::Conductor::CommandControllerTest < ActionDispatch::IntegrationTest + def dummy_user + "#{Rails.root}/app/models/user.rb" + end + test "generate scaffold" do + with_rails_env("development") do + post rails_conductor_generator_path, params: { + user: { + name: :string + } + } + + assert File.exist?(dummy_user) + + Rails::Command.invoke "destroy", ["scaffold", "User"] + end + end + + private + def with_rails_env(env) + old_rails_env = Rails.env + Rails.env = env + yield + ensure + Rails.env = old_rails_env + end +end diff --git a/conductor/test/test_helper.rb b/conductor/test/test_helper.rb new file mode 100644 index 0000000000000..d28dfb10352f0 --- /dev/null +++ b/conductor/test/test_helper.rb @@ -0,0 +1,6 @@ + +ENV["RAILS_ENV"] = "test" + +require_relative "../../actionmailbox/test/dummy/config/environment" +ActiveRecord::Migrator.migrations_paths = [File.expand_path("../../actionmailbox/test/dummy/db/migrate", __dir__)] +require "rails/test_help" From 9514670f5828b4af38cbc23711286f5d99331d38 Mon Sep 17 00:00:00 2001 From: Richard Anthony Date: Sun, 23 Jan 2022 18:57:01 +1100 Subject: [PATCH 4/5] Add an API route for CommandController --- conductor/config/routes.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/conductor/config/routes.rb b/conductor/config/routes.rb index 32f0fb72eea6c..1767d4488c3e4 100644 --- a/conductor/config/routes.rb +++ b/conductor/config/routes.rb @@ -4,4 +4,5 @@ get "rails/conductor" => "rails/conductor/panels#show", as: :rails_conductor get "rails/conductor/source/statistics" => "rails/conductor/source/statistics#show", as: :rails_conductor_source_statistics get "rails/conductor/source/notes" => "rails/conductor/source/notes#show", as: :rails_conductor_source_notes + post "rails/conductor" => "rails/conductor/command#generate", as: :rails_conductor_generator end From 76aa0e70100249ae2facca23efb869f3b8f1faf3 Mon Sep 17 00:00:00 2001 From: Richard Anthony Date: Sun, 23 Jan 2022 18:57:46 +1100 Subject: [PATCH 5/5] mount Conductor in actionmailbox dummy app TODO conductor should have it's own dummy app --- actionmailbox/test/dummy/config/routes.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/actionmailbox/test/dummy/config/routes.rb b/actionmailbox/test/dummy/config/routes.rb index 1fc667e2425de..73cc82a2c81d6 100644 --- a/actionmailbox/test/dummy/config/routes.rb +++ b/actionmailbox/test/dummy/config/routes.rb @@ -1,4 +1,5 @@ Rails.application.routes.draw do resources :messages + mount Conductor::Engine, at: "/" # For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html end