Compare commits

..

1 Commits

Author SHA1 Message Date
google-labs-jules[bot]
f086209f5c 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.
2025-09-21 23:09:48 +00:00
3 changed files with 16 additions and 0 deletions

View File

@@ -121,6 +121,11 @@ class CropsController < ApplicationController
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"

View File

@@ -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'

View File

@@ -66,6 +66,15 @@ describe "crop wranglers", :js do
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