mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-05-12 01:36:26 -04:00
- 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>
49 lines
1.5 KiB
Ruby
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
|