• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

foodcoops / foodsoft / 19301552637

12 Nov 2025 02:52PM UTC coverage: 42.744% (-7.3%) from 50.014%
19301552637

Pull #1246

github

web-flow
Merge a2a39fb72 into e233764c5
Pull Request #1246: Resize input fields in group order form

3081 of 7208 relevant lines covered (42.74%)

11.87 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

85.42
/app/controllers/application_controller.rb
1
class ApplicationController < ActionController::Base
1✔
2
  include Concerns::FoodcoopScope
1✔
3
  include Concerns::Auth
1✔
4
  include Concerns::Locale
1✔
5
  include PathHelper
1✔
6
  helper_method :current_user
1✔
7
  helper_method :available_locales
1✔
8

9
  protect_from_forgery
1✔
10
  before_action :authenticate, :set_user_last_activity, :store_controller, :items_per_page
1✔
11
  after_action  :remove_controller
1✔
12
  around_action :set_time_zone, :set_currency
1✔
13

14
  # Returns the controller handling the current request.
15
  def self.current
1✔
16
    Thread.current[:application_controller]
×
17
  end
18

19
  private
1✔
20

21
  def set_user_last_activity
1✔
22
    return unless current_user && (session[:last_activity].nil? || session[:last_activity] < 1.minute.ago)
6✔
23

24
    current_user.update_attribute(:last_activity, Time.now)
2✔
25
    session[:last_activity] = Time.now
2✔
26
  end
27

28
  # Many plugins can be turned on and off on the fly with a `use_` configuration option.
29
  # To disable a controller in the plugin, you can use this as a `before_action`:
30
  #
31
  #     class MypluginController < ApplicationController
32
  #       before_action -> { require_plugin_enabled FoodsoftMyplugin }
33
  #     end
34
  #
35
  def require_plugin_enabled(plugin)
1✔
36
    redirect_to_root_with_feature_disabled_alert unless plugin.enabled?
×
37
  end
38

39
  def require_config_enabled(config)
1✔
40
    redirect_to_root_with_feature_disabled_alert unless FoodsoftConfig[config]
×
41
  end
42

43
  def require_config_disabled(config)
1✔
44
    redirect_to_root_with_feature_disabled_alert if FoodsoftConfig[config]
×
45
  end
46

47
  def redirect_to_root_with_feature_disabled_alert
1✔
48
    redirect_to root_path, alert: I18n.t('application.controller.error_feature_disabled')
×
49
  end
50

51
  # Stores this controller instance as a thread local varibale to be accessible from outside ActionController/ActionView.
52
  def store_controller
1✔
53
    Thread.current[:application_controller] = self
6✔
54
  end
55

56
  # Sets the thread local variable that holds a reference to the current controller to nil.
57
  def remove_controller
1✔
58
    Thread.current[:application_controller] = nil
6✔
59
  end
60

61
  # Get supplier in nested resources
62
  def find_supplier
1✔
63
    @supplier = Supplier.find(params[:supplier_id]) if params[:supplier_id]
×
64
  end
65

66
  def items_per_page
1✔
67
    @per_page = if params[:per_page] && params[:per_page].to_i > 0 && params[:per_page].to_i <= 500
6✔
68
                  params[:per_page].to_i
×
69
                else
70
                  20
6✔
71
                end
72
  end
73

74
  # Set timezone according to foodcoop preference.
75
  # @see http://stackoverflow.com/questions/4362663/timezone-with-rails-3
76
  # @see http://archives.ryandaigle.com/articles/2008/1/25/what-s-new-in-edge-rails-easier-timezones
77
  def set_time_zone
1✔
78
    old_time_zone = Time.zone
6✔
79
    Time.zone = FoodsoftConfig[:time_zone] if FoodsoftConfig[:time_zone]
6✔
80
    yield
6✔
81
  ensure
82
    Time.zone = old_time_zone
6✔
83
  end
84

85
  # Set currency according to foodcoop preference.
86
  # @see #set_time_zone
87
  def set_currency
1✔
88
    old_currency = ::I18n.t('number.currency.format.unit')
6✔
89
    new_currency = FoodsoftConfig[:currency_unit] || ''
6✔
90
    new_currency += "\u202f" if FoodsoftConfig[:currency_space]
6✔
91
    ::I18n.backend.store_translations(::I18n.locale, number: { currency: { format: { unit: new_currency } } })
6✔
92
    yield
6✔
93
  ensure
94
    ::I18n.backend.store_translations(::I18n.locale, number: { currency: { format: { unit: old_currency } } })
6✔
95
  end
96
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc