Files
growstuff/spec/requests/crop_dismissals_spec.rb
T
Brenda Wallace ef06bab74f Add crop suggestions feature and dashboard enhancements
- Introduced crop suggestions functionality allowing users to receive tailored crop recommendations based on their location and preferences.
- Implemented the ability for users to dismiss specific crop suggestions, preventing them from receiving recommendations for crops they are not interested in.
- Added a location picker for users to set their gardening location, enhancing the accuracy of crop suggestions.
- Enhanced the dashboard to display relevant statistics, including plantings and harvests, with comparisons to previous years.
- Created new views and partials for displaying statistics, crop suggestions, and user interactions on the dashboard.
- Updated routes to accommodate new features related to crop suggestions and member locations.
- Added migrations for new database tables and columns to support crop dismissal and suggestion preferences.
- Developed tests for the new features, ensuring functionality and user experience are maintained.
2026-10-12 19:12:18 +13:00

56 lines
1.7 KiB
Ruby

# frozen_string_literal: true
require 'rails_helper'
# "Not for me" on a suggested crop on the home page.
describe 'Dismissing a suggested crop' do
include Devise::Test::IntegrationHelpers
let(:member) { create(:member) }
let(:crop) { create(:crop, name: 'persian lime') }
context 'when signed in' do
before { sign_in member }
it 'remembers the crop is not for them' do
post crop_dismissals_path, params: { crop_id: crop.id }
expect(member.dismissed_crops).to eq [crop]
end
it 'does not mind being told twice' do
2.times { post crop_dismissals_path, params: { crop_id: crop.id } }
expect(member.crop_dismissals.count).to eq 1
end
it 'says it will not suggest the crop again' do
post crop_dismissals_path, params: { crop_id: crop.id }
expect(flash[:notice]).to eq "We won't suggest persian lime again."
end
it 'does not take a crop that is not approved' do
pending_crop = create(:crop, approval_status: 'pending')
post crop_dismissals_path, params: { crop_id: pending_crop.id }
expect(response).to have_http_status(:not_found)
end
it 'brings every hidden suggestion back' do
create(:crop_dismissal, member:, crop:)
delete '/my/dismissed_crops'
expect(member.crop_dismissals.count).to eq 0
end
it 'leaves other members\' dismissals alone' do
create(:crop_dismissal, crop:)
delete '/my/dismissed_crops'
expect(CropDismissal.count).to eq 1
end
end
context 'when signed out' do
it 'does not record anything' do
post crop_dismissals_path, params: { crop_id: crop.id }
expect(CropDismissal.count).to eq 0
end
end
end