Display products cache integrity checker results on cache settings admin page

This commit is contained in:
Rohan Mitchell
2016-03-02 11:05:03 +11:00
parent 2abee3fcdd
commit ec55af5b8a
5 changed files with 81 additions and 0 deletions

View 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

View File

@@ -0,0 +1,4 @@
/ insert_bottom "[data-hook='admin_configurations_sidebar_menu']"
%li
= link_to 'Caching', main_app.admin_cache_settings_path

View 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)

View File

@@ -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

View 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