Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rake task Execution #3

Merged
merged 2 commits into from
Feb 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
/test/dummy/log/*.log
/test/dummy/storage/
/test/dummy/tmp/cache/
/test/dummy/tmp/*.txt
/test/dummy/tmp/development_secret.txt

.byebug_history
9 changes: 9 additions & 0 deletions app/controllers/rake_ui/rake_tasks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,14 @@ def show
format.html
end
end


def execute
@rake_task = RakeUi::RakeTask.find_by_id(params[:id])

@rake_task.call(args: params[:args], environment: params[:environment])

redirect_to rake_task_path @rake_task.id
end
end
end
10 changes: 10 additions & 0 deletions app/views/rake_ui/rake_tasks/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<%= @rake_task.name %>
<%= form_with url: rake_task_execute_path(@rake_task), method: :post do |f| %>
<%= f.label :args, "Arguments, as if you were raking" %>
<%= f.text_field :arguments %>

<%= f.label :env, "Environment overrides" %>
<%= f.text_field :environment %>

<%= f.submit "Submit" %>
<% end %>
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
RakeUi::Engine.routes.draw do
resources :rake_tasks, only: [:index, :show]

post "/rake_tasks/:id/execute", to: "rake_tasks#execute", as: "rake_task_execute"
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
id: 2021-02-02-20-03-41-0600____double_nested%3Ainside_double_nested%3Adouble_nested_task
name: double_nested:inside_double_nested:double_nested_task
args:
environment:
rake_command: rake double_nested:inside_double_nested:double_nested_task
rake_definition_file #<Proc:0x000055765dacd248@/home/talos/projects/dox/seeder/lib/tasks/double_nested_tasks.rake:4>
log_file_name: 2021-02-02-20-03-41-0600____double_nested%3Ainside_double_nested%3Adouble_nested_task.txt
log_file_full_path: /home/talos/projects/dox/seeder/tmp/raker/2021-02-02-20-03-41-0600____double_nested%3Ainside_double_nested%3Adouble_nested_task.txt
-------------------------------
INVOKED RAKE TASK OUTPUT BELOW
-------------------------------
double_nested_task start
#<Rake::TaskArguments >
double_nested_task end
17 changes: 17 additions & 0 deletions test/integration/rake_tasks_request_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,21 @@ class RakeTasksRequestTest < ActionDispatch::IntegrationTest
assert_equal task.id, json_response[:rake_task][:id]
assert_equal task.name_with_args, json_response[:rake_task][:name_with_args]
end

test "post executes the task" do
mock_task = Minitest::Mock.new
def mock_task.id; "some_identifier"; end
mock_task.expect :call, true, [{ args: "1,2,3", environment: "FOO=bar" }]

mock_find_by_id = lambda do |args|
assert args, "some_identifier"

mock_task
end

RakeUi::RakeTask.stub :find_by_id, mock_find_by_id do
post "/rake-ui/rake_tasks/#{mock_task.id}/execute", params: { environment: "FOO=bar",
args: "1,2,3" }
end
end
end
1 change: 1 addition & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
ActiveRecord::Migrator.migrations_paths = [File.expand_path("../test/dummy/db/migrate", __dir__)]
ActiveRecord::Migrator.migrations_paths << File.expand_path('../db/migrate', __dir__)
require "rails/test_help"
require "minitest/mock"


# Load fixtures from the engine
Expand Down