mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-05-18 21:56:55 -04:00
Merge pull request #1847 from Br3nda/fix/crop-delete
Fixing crop deleting and adding tests
This commit is contained in:
@@ -104,6 +104,8 @@ class CropsController < ApplicationController
|
||||
end
|
||||
|
||||
def destroy
|
||||
@crop = Crop.find_by!(slug: params[:slug])
|
||||
authorize! :destroy, @crop
|
||||
@crop.destroy
|
||||
respond_with @crop
|
||||
end
|
||||
|
||||
@@ -1,34 +1,36 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe CropsController do
|
||||
login_member(:crop_wrangling_member)
|
||||
|
||||
def valid_attributes
|
||||
{
|
||||
name: "Tomato",
|
||||
en_wikipedia_url: 'http://en.wikipedia.org/wiki/Tomato',
|
||||
approval_status: 'approved'
|
||||
}
|
||||
shared_context 'login as wrangler' do
|
||||
login_member(:crop_wrangling_member)
|
||||
end
|
||||
|
||||
subject { response }
|
||||
|
||||
describe "GET crop wrangler homepage" do
|
||||
describe 'fetches the crop wrangler homepage' do
|
||||
before { get :wrangle }
|
||||
|
||||
it { is_expected.to be_success }
|
||||
it { is_expected.to render_template("crops/wrangle") }
|
||||
it { expect(assigns[:crop_wranglers]).to eq(Role.crop_wranglers) }
|
||||
context 'anonymous' do
|
||||
before { get :wrangle }
|
||||
it { is_expected.not_to be_success }
|
||||
end
|
||||
context 'wrangler' do
|
||||
include_context 'login as wrangler'
|
||||
before { get :wrangle }
|
||||
it { is_expected.to be_success }
|
||||
it { is_expected.to render_template("crops/wrangle") }
|
||||
it { expect(assigns[:crop_wranglers]).to eq(Role.crop_wranglers) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET crop hierarchy " do
|
||||
describe 'fetches the crop hierarchy page' do
|
||||
before { get :hierarchy }
|
||||
|
||||
it { is_expected.to be_success }
|
||||
it { is_expected.to render_template("crops/hierarchy") }
|
||||
context 'wrangler' do
|
||||
include_context 'login as wrangler'
|
||||
before { get :hierarchy }
|
||||
it { is_expected.to be_success }
|
||||
it { is_expected.to render_template("crops/hierarchy") }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -50,4 +52,19 @@ describe CropsController do
|
||||
it { expect(response.content_type).to eq("application/rss+xml") }
|
||||
end
|
||||
end
|
||||
|
||||
describe 'DELETE destroy' do
|
||||
let!(:crop) { FactoryBot.create :crop }
|
||||
subject { delete :destroy, params: { slug: crop.to_param } }
|
||||
context 'not logged in' do
|
||||
it { expect { subject }.not_to change { Crop.count } }
|
||||
end
|
||||
context 'logged in as member' do
|
||||
it { expect { subject }.not_to change { Crop.count } }
|
||||
end
|
||||
context 'wrangler' do
|
||||
include_context 'login as wrangler'
|
||||
it { expect { subject }.to change { Crop.count }.by -1 }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
23
spec/features/crops/delete_crop_spec.rb
Normal file
23
spec/features/crops/delete_crop_spec.rb
Normal file
@@ -0,0 +1,23 @@
|
||||
require 'rails_helper'
|
||||
|
||||
feature "Delete crop spec" do
|
||||
context "As a crop wrangler" do
|
||||
let(:wrangler) { FactoryBot.create :crop_wrangling_member }
|
||||
let!(:pending_crop) { FactoryBot.create :crop_request }
|
||||
let!(:approved_crop) { FactoryBot.create :crop }
|
||||
|
||||
background { login_as wrangler }
|
||||
|
||||
scenario "Delete approved crop" do
|
||||
visit crop_path(approved_crop)
|
||||
click_link 'Delete'
|
||||
expect(page).to have_content "crop was successfully destroyed"
|
||||
end
|
||||
|
||||
scenario "Delete pending crop" do
|
||||
visit crop_path(pending_crop)
|
||||
click_link 'Delete'
|
||||
expect(page).to have_content "crop was successfully destroyed"
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -15,7 +15,7 @@ feature "browse crops" do
|
||||
before { FactoryBot.create_list :harvest, 20, crop: tomato, harvested_at: 1.year.ago, created_at: 1.minute.ago }
|
||||
|
||||
let!(:most_recent_harvest) do
|
||||
FactoryBot.create :harvest, crop: tomato, harvested_at: 60.minutes.ago, created_at: 10.minute.ago
|
||||
FactoryBot.create :harvest, crop: tomato, harvested_at: 60.minutes.ago, created_at: 10.minutes.ago
|
||||
end
|
||||
|
||||
scenario "Shows most recently harvested harvest" do
|
||||
@@ -28,7 +28,7 @@ feature "browse crops" do
|
||||
before { FactoryBot.create_list :planting, 20, crop: tomato, planted_at: 1.year.ago, created_at: 1.minute.ago }
|
||||
|
||||
let!(:most_recent_planting) do
|
||||
FactoryBot.create :planting, crop: tomato, planted_at: 60.minutes.ago, created_at: 10.minute.ago
|
||||
FactoryBot.create :planting, crop: tomato, planted_at: 60.minutes.ago, created_at: 10.minutes.ago
|
||||
end
|
||||
|
||||
scenario "Shows most recently planted planting" do
|
||||
|
||||
Reference in New Issue
Block a user