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