mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-03-26 10:45:04 -04:00
* feat(admin): add revert functionality to crops page This change adds a "Revert" button to the admin crops page, allowing crop wranglers to revert changes to a previous version. It introduces a new `Admin::VersionsController` with a `revert` action that uses `paper_trail`'s `reify` method to restore a previous version of a `Crop` object. The view is updated to include a "Revert" button, which is guarded by a `can?(:wrangle, Crop)` check to ensure only authorized users can see it. The controller also includes an authorization check to prevent unauthorized users from accessing the revert action directly. A feature spec is added to test the new functionality, including the authorization logic. * Consistent UX * Specs --------- Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> Co-authored-by: Daniel O'Connor <daniel.oconnor@gmail.com>
39 lines
900 B
Ruby
39 lines
900 B
Ruby
# frozen_string_literal: true
|
|
|
|
require 'rails_helper'
|
|
|
|
RSpec.feature 'Reverting crops' do
|
|
let(:wrangler) { create(:crop_wrangling_member) }
|
|
let(:member) { create(:member) }
|
|
let!(:crop) { create(:crop, name: 'Initial Name') }
|
|
|
|
before do
|
|
crop.update(name: 'Updated Name')
|
|
end
|
|
|
|
context 'when logged in as an wrangler' do
|
|
before do
|
|
login_as(wrangler, scope: :member)
|
|
end
|
|
|
|
scenario 'Admin reverts a crop' do
|
|
visit admin_crops_path
|
|
click_link 'Revert', match: :first
|
|
expect(page).to have_content('Reverted to version from')
|
|
crop.reload
|
|
expect(crop.name).to eq('Initial Name')
|
|
end
|
|
end
|
|
|
|
context 'when logged in as a regular member' do
|
|
before do
|
|
login_as(member, scope: :member)
|
|
end
|
|
|
|
scenario 'Member cannot revert a crop' do
|
|
visit admin_crops_path
|
|
expect(page).not_to have_link('Revert')
|
|
end
|
|
end
|
|
end
|