Files
growstuff/spec/controllers/charts/crops_controller_spec.rb
google-labs-jules[bot] ff9d99afe5 Improve Charts::CropsController with caching and refactoring
- Added Rails.cache.fetch to `sunniness` and `planted_from` actions.
- Refactored crop loading into a `before_action :set_crop`.
- Updated specs to verify caching behavior and ensure coverage.

Co-authored-by: CloCkWeRX <365751+CloCkWeRX@users.noreply.github.com>
2026-04-27 07:46:08 +00:00

49 lines
1.5 KiB
Ruby

# frozen_string_literal: true
require 'rails_helper'
describe Charts::CropsController do
describe 'GET charts' do
let(:crop) { create(:crop) }
describe 'sunniness' do
it "returns a successful response" do
get :sunniness, params: { crop_slug: crop.to_param }
expect(response).to be_successful
end
it "caches the result" do
cache_key = "#{crop.cache_key_with_version}/sunniness"
expect(Rails.cache).to receive(:fetch).with(cache_key, expires_in: 1.day).and_call_original
get :sunniness, params: { crop_slug: crop.to_param }
end
end
describe 'planted_from' do
it "returns a successful response" do
get :planted_from, params: { crop_slug: crop.to_param }
expect(response).to be_successful
end
it "caches the result" do
cache_key = "#{crop.cache_key_with_version}/planted_from"
expect(Rails.cache).to receive(:fetch).with(cache_key, expires_in: 1.day).and_call_original
get :planted_from, params: { crop_slug: crop.to_param }
end
end
describe 'harvested_for' do
it "returns a successful response" do
get :harvested_for, params: { crop_slug: crop.to_param }
expect(response).to be_successful
end
it "caches the result" do
cache_key = "#{crop.cache_key_with_version}/harvested_for"
expect(Rails.cache).to receive(:fetch).with(cache_key, expires_in: 1.day).and_call_original
get :harvested_for, params: { crop_slug: crop.to_param }
end
end
end
end