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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(description): Add description option for tasks #831

Closed
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
10 changes: 10 additions & 0 deletions app/models/maintenance_tasks/task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ def named(name)
task
end

# Sets/Returns a description of the task
#
# @param [String] the description of the task.
#
# @return [Array<Class>] the list of classes.
def description(desc = nil)
@description = desc if desc
@description
end

# Returns a list of concrete classes that inherit from the Task
# superclass.
#
Expand Down
5 changes: 5 additions & 0 deletions app/models/maintenance_tasks/task_data_show.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ def parameter_names
end
end

# @return [String] the description of the task.
def description
!deleted? && Task.named(name).description
end

# @return [MaintenanceTasks::Task, nil] an instance of the Task class.
# @return [nil] if the Task file was deleted.
def new
Expand Down
5 changes: 5 additions & 0 deletions app/views/maintenance_tasks/tasks/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
<%= @task %>
</h1>

<% if @task.description.present? %>
<div class="block">
<%= @task.description %>
</div>
<% end %>
<div class="buttons">
<%= form_with url: task_runs_path(@task), method: :post do |form| %>
<% if @task.csv_task? %>
Expand Down
2 changes: 2 additions & 0 deletions lib/generators/maintenance_tasks/templates/task.rb.tt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
module <%= tasks_module %>
<% module_namespacing do -%>
class <%= class_name %>Task < MaintenanceTasks::Task
description "TODO"

def collection
# Collection to be iterated over
# Must be Active Record Relation or Array
Expand Down
2 changes: 2 additions & 0 deletions test/dummy/app/tasks/maintenance/params_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

module Maintenance
class ParamsTask < MaintenanceTasks::Task
description "An example task containing the different types of parameters."

attribute :post_ids, :string

validates :post_ids,
Expand Down
2 changes: 2 additions & 0 deletions test/dummy/app/tasks/maintenance/update_posts_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

module Maintenance
class UpdatePostsTask < MaintenanceTasks::Task
description "Updates every post with new content"

class << self
attr_accessor :fast_task
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def teardown
assert_file "app/tasks/maintenance/sleepy_task.rb" do |task|
assert_match(/module Maintenance/, task)
assert_match(/class SleepyTask < MaintenanceTasks::Task/, task)
assert_match(/description "TODO"/, task)
assert_match(/def collection/, task)
assert_match(/def process\(element\)/, task)
assert_match(/def count/, task)
Expand Down
1 change: 1 addition & 0 deletions test/system/maintenance_tasks/tasks_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class TasksTest < ApplicationSystemTestCase
click_on("Maintenance::UpdatePostsTask")

assert_title "Maintenance::UpdatePostsTask"
assert_text "Updates every post with new content"
assert_selector "time", text: "January 01, 2020" do |tag|
assert_equal "2020-01-01T01:00:00Z", tag[:title]
end
Expand Down