Skip to content

Commit

Permalink
Evaluate metadata block in the context of the controller (#873)
Browse files Browse the repository at this point in the history
  • Loading branch information
jennaleeb authored Aug 24, 2023
1 parent 53e232c commit f868920
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
maintenance_tasks (2.3.0)
maintenance_tasks (2.3.1)
actionpack (>= 6.0)
activejob (>= 6.0)
activerecord (>= 6.0)
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -840,8 +840,8 @@ or email of the user who performed the maintenance task.

```ruby
# config/initializers/maintenance_tasks.rb
MaintenanceTasks.metadata = -> do
{ user_email: current_user.email }
MaintenanceTasks.metadata = ->(context) do
{ user_email: context.current_user.email }
end
```

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/maintenance_tasks/runs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def create(&block)
name: params.fetch(:task_id),
csv_file: params[:csv_file],
arguments: params.fetch(:task_arguments, {}).permit!.to_h,
metadata: MaintenanceTasks.metadata&.call,
metadata: instance_exec(&MaintenanceTasks.metadata || -> {}),
&block
)
redirect_to(task_path(task))
Expand Down
2 changes: 1 addition & 1 deletion maintenance_tasks.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Gem::Specification.new do |spec|
spec.name = "maintenance_tasks"
spec.version = "2.3.0"
spec.version = "2.3.1"
spec.author = "Shopify Engineering"
spec.email = "[email protected]"
spec.homepage = "https://github.com/Shopify/maintenance_tasks"
Expand Down
2 changes: 1 addition & 1 deletion test/system/maintenance_tasks/runs_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class RunsTest < ApplicationSystemTestCase
assert_equal "enqueued", run.status
end

test "run a Task and log the user email" do
test "run a Task and log the provided metadata" do
MaintenanceTasks.metadata = -> { { user_email: "[email protected]" } }
visit(maintenance_tasks_path)

Expand Down

0 comments on commit f868920

Please sign in to comment.