diff --git a/app/helpers/spree/admin/navigation_helper_decorator.rb b/app/helpers/spree/admin/navigation_helper_decorator.rb index d7d0bd2370..5d0716b9f8 100644 --- a/app/helpers/spree/admin/navigation_helper_decorator.rb +++ b/app/helpers/spree/admin/navigation_helper_decorator.rb @@ -1,6 +1,15 @@ module Spree module Admin module NavigationHelper + # TEMP: import method until it is re-introduced into Spree. + def klass_for(name) + model_name = name.to_s + + ["Spree::#{model_name.classify}", model_name.classify, model_name.gsub('_', '/').classify].find do |t| + t.safe_constantize + end.try(:safe_constantize) + end + # Make it so that the Reports admin tab can be enabled/disabled through the cancan # :report resource, since it does not have a corresponding resource class (unlike # eg. Spree::Product). @@ -12,6 +21,17 @@ module Spree # klass # end # alias_method_chain :klass_for, :sym_fallback + + # TEMP: override method until it is fixed in Spree. + def tab_with_cancan_check(*args) + options = {:label => args.first.to_s} + if args.last.is_a?(Hash) + options = options.merge(args.last) + end + return '' if klass = klass_for(options[:label]) and cannot?(:admin, klass) + tab_without_cancan_check(*args) + end + alias_method_chain :tab, :cancan_check end end end diff --git a/spec/features/admin/authentication_spec.rb b/spec/features/admin/authentication_spec.rb index fe2eb156c5..5cdbbbd6de 100644 --- a/spec/features/admin/authentication_spec.rb +++ b/spec/features/admin/authentication_spec.rb @@ -18,6 +18,7 @@ feature "Authentication", js: true do click_login_button expect(page).to have_content "DASHBOARD" expect(page).to have_current_path spree.admin_path + expect(page).to have_no_content "CONFIGURATION" end end