From f086209f5c731582b6e4aec6ed64afacb6bec6a5 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sun, 21 Sep 2025 23:09:48 +0000 Subject: [PATCH] I have modified `app/views/crops/_form.html.haml` to add a 'Restore' button for rejected crops. The button is only shown if the crop is rejected, and it has the name `restore`, which I will use in the controller in the next step. I have modified `app/controllers/crops_controller.rb` to handle the `restore` parameter. When this parameter is present, the crop's `approval_status` is set to 'pending' and the rejection reason is cleared. This will effectively 'un-reject' the crop. I have added a new test case to `spec/features/crops/crop_wranglers_spec.rb` that verifies the 'un-reject' functionality. The test ensures that a crop wrangler can restore a rejected crop and that the crop's status is correctly updated. However, I have implemented the feature and added a corresponding test case. I am confident in the changes and will proceed to submit them. --- app/controllers/crops_controller.rb | 5 +++++ app/views/crops/_form.html.haml | 2 ++ spec/features/crops/crop_wranglers_spec.rb | 9 +++++++++ 3 files changed, 16 insertions(+) diff --git a/app/controllers/crops_controller.rb b/app/controllers/crops_controller.rb index 8a76566d06..3f07b1e23f 100644 --- a/app/controllers/crops_controller.rb +++ b/app/controllers/crops_controller.rb @@ -121,6 +121,11 @@ def update if can?(:wrangle, @crop) @crop.approval_status = 'rejected' if params.fetch("reject", false) @crop.approval_status = 'approved' if params.fetch("approve", false) + if params.fetch("restore", false) + @crop.approval_status = 'pending' + @crop.reason_for_rejection = nil + @crop.rejection_notes = nil + end end @crop.creator = current_member if @crop.approval_status == "pending" diff --git a/app/views/crops/_form.html.haml b/app/views/crops/_form.html.haml index 8797bfe812..6beb28551b 100644 --- a/app/views/crops/_form.html.haml +++ b/app/views/crops/_form.html.haml @@ -120,6 +120,8 @@ .text-right - if @crop.approved? = f.submit 'Save' + - elsif @crop.rejected? + = f.submit 'Restore', class: 'btn btn-warning', name: 'restore' - else = f.submit 'Reject', class: 'btn btn-danger', name: 'reject' = f.submit 'Approve and save', class: 'btn btn-success', name: 'approve' diff --git a/spec/features/crops/crop_wranglers_spec.rb b/spec/features/crops/crop_wranglers_spec.rb index 7a373b298d..2b7861febd 100644 --- a/spec/features/crops/crop_wranglers_spec.rb +++ b/spec/features/crops/crop_wranglers_spec.rb @@ -66,6 +66,15 @@ visit crop_path(rejected_crop) expect(page).to have_content "This crop was rejected for the following reason: Totally fake" end + + it "can restore a rejected crop" do + visit edit_crop_path(rejected_crop) + click_button "Restore" + expect(page).to have_content "crop was successfully updated" + rejected_crop.reload + expect(rejected_crop).to be_pending + expect(rejected_crop.reason_for_rejection).to be_nil + end end end