Skip to content
Open
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
5 changes: 5 additions & 0 deletions app/controllers/crops_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions app/views/crops/_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
9 changes: 9 additions & 0 deletions spec/features/crops/crop_wranglers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading