diff --git a/app/controllers/admin/cache_settings_controller.rb b/app/controllers/admin/cache_settings_controller.rb new file mode 100644 index 0000000000..ada153a6d5 --- /dev/null +++ b/app/controllers/admin/cache_settings_controller.rb @@ -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 diff --git a/app/overrides/spree/admin/shared/_configuration_menu/add_caching.html.haml.deface b/app/overrides/spree/admin/shared/_configuration_menu/add_caching.html.haml.deface new file mode 100644 index 0000000000..1eb416e72a --- /dev/null +++ b/app/overrides/spree/admin/shared/_configuration_menu/add_caching.html.haml.deface @@ -0,0 +1,4 @@ +/ insert_bottom "[data-hook='admin_configurations_sidebar_menu']" + +%li + = link_to 'Caching', main_app.admin_cache_settings_path diff --git a/app/views/admin/cache_settings/show.html.haml b/app/views/admin/cache_settings/show.html.haml new file mode 100644 index 0000000000..79b3e5acaf --- /dev/null +++ b/app/views/admin/cache_settings/show.html.haml @@ -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) diff --git a/config/routes.rb b/config/routes.rb index 62c4153d14..c44f8395de 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 diff --git a/spec/features/admin/caching_spec.rb b/spec/features/admin/caching_spec.rb new file mode 100644 index 0000000000..22d372e19b --- /dev/null +++ b/spec/features/admin/caching_spec.rb @@ -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