mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-05 22:26:07 +00:00
Display products cache integrity checker results on cache settings admin page
This commit is contained in:
14
app/controllers/admin/cache_settings_controller.rb
Normal file
14
app/controllers/admin/cache_settings_controller.rb
Normal file
@@ -0,0 +1,14 @@
|
||||
require 'open_food_network/products_cache_integrity_checker'
|
||||
|
||||
class Admin::CacheSettingsController < Spree::Admin::BaseController
|
||||
|
||||
def show
|
||||
active_exchanges = OpenFoodNetwork::ProductsCacheIntegrityChecker.active_exchanges
|
||||
@results = active_exchanges.map do |exchange|
|
||||
checker = OpenFoodNetwork::ProductsCacheIntegrityChecker.new(exchange.receiver, exchange.order_cycle)
|
||||
|
||||
{distributor: exchange.receiver, order_cycle: exchange.order_cycle, status: checker.ok?, diff: checker.diff}
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
@@ -0,0 +1,4 @@
|
||||
/ insert_bottom "[data-hook='admin_configurations_sidebar_menu']"
|
||||
|
||||
%li
|
||||
= link_to 'Caching', main_app.admin_cache_settings_path
|
||||
18
app/views/admin/cache_settings/show.html.haml
Normal file
18
app/views/admin/cache_settings/show.html.haml
Normal file
@@ -0,0 +1,18 @@
|
||||
- content_for :page_title do
|
||||
= t(:cache_settings)
|
||||
|
||||
%table.index
|
||||
%thead
|
||||
%tr
|
||||
%th Distributor
|
||||
%th Order Cycle
|
||||
%th Status
|
||||
%th Diff
|
||||
%tbody
|
||||
- @results.each do |result|
|
||||
%tr
|
||||
%td= result[:distributor].name
|
||||
%td= result[:order_cycle].name
|
||||
%td= result[:status] ? 'OK' : 'Error'
|
||||
%td
|
||||
%pre= result[:diff].to_s(:text)
|
||||
@@ -122,6 +122,8 @@ Openfoodnetwork::Application.routes.draw do
|
||||
|
||||
resource :business_model_configuration, only: [:edit, :update], controller: 'business_model_configuration'
|
||||
|
||||
resource :cache_settings
|
||||
|
||||
resource :account, only: [:show], controller: 'account'
|
||||
end
|
||||
|
||||
|
||||
43
spec/features/admin/caching_spec.rb
Normal file
43
spec/features/admin/caching_spec.rb
Normal file
@@ -0,0 +1,43 @@
|
||||
require 'spec_helper'
|
||||
require 'open_food_network/products_renderer'
|
||||
|
||||
feature 'Caching' do
|
||||
include AuthenticationWorkflow
|
||||
include WebHelper
|
||||
|
||||
before { quick_login_as_admin }
|
||||
|
||||
describe "displaying integrity checker results" do
|
||||
let(:distributor) { create(:distributor_enterprise) }
|
||||
let(:order_cycle) { create(:open_order_cycle, distributors: [distributor]) }
|
||||
|
||||
it "displays results when things are good" do
|
||||
# Given matching data
|
||||
Rails.cache.write "products-json-#{distributor.id}-#{order_cycle.id}", "[1, 2, 3]\n"
|
||||
OpenFoodNetwork::ProductsRenderer.stub(:new) { double(:pr, products_json: "[1, 2, 3]\n") }
|
||||
|
||||
# When I visit the cache status page
|
||||
visit spree.admin_path
|
||||
click_link 'Configuration'
|
||||
click_link 'Caching'
|
||||
|
||||
# Then I should see some status information
|
||||
page.should have_content "OK"
|
||||
end
|
||||
|
||||
it "displays results when there are errors" do
|
||||
# Given matching data
|
||||
Rails.cache.write "products-json-#{distributor.id}-#{order_cycle.id}", "[1, 2, 3]\n"
|
||||
OpenFoodNetwork::ProductsRenderer.stub(:new) { double(:pr, products_json: "[1, 3]\n") }
|
||||
|
||||
# When I visit the cache status page
|
||||
visit spree.admin_path
|
||||
click_link 'Configuration'
|
||||
click_link 'Caching'
|
||||
|
||||
# Then I should see some status information
|
||||
page.should have_content "Error"
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user