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

codebar / planner / 7255085967

18 Dec 2023 11:24PM UTC coverage: 95.25% (-0.2%) from 95.457%
7255085967

push

github

matyikriszta
Customizes pagy_info item name (x of y items)

3148 of 3305 relevant lines covered (95.25%)

35.96 hits per line

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

84.27
/app/controllers/application_controller.rb
1
class ApplicationController < ActionController::Base
1✔
2
  protect_from_forgery with: :exception
1✔
3

4
  include Pundit::Authorization
1✔
5
  include Pagy::Backend
1✔
6

7
  rescue_from Exception do |ex|
1✔
8
    Rollbar.error(ex)
×
9
    Rails.logger.fatal(ex)
×
10
    respond_to do |format|
×
11
      format.html { render 'errors/error', layout: false, status: :internal_server_error }
×
12
      format.all  { head :internal_server_error }
×
13
    end
14
  end
15

16
  rescue_from ActionController::RoutingError, with: :render_not_found
1✔
17
  rescue_from ActiveRecord::RecordNotFound, with: :render_not_found
1✔
18

19
  rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized
1✔
20
  rescue_from Pundit::AuthorizationNotPerformedError, with: :user_not_authorized
1✔
21

22
  helper_method :logged_in?
1✔
23
  helper_method :current_user
1✔
24
  helper_method :current_service
1✔
25

26
  before_action :set_locale
1✔
27
  before_action :accept_terms, if: :logged_in?
1✔
28

29
  def render_not_found
1✔
30
    respond_to do |format|
3✔
31
      format.html { render template: 'errors/not_found', layout: false, status: :not_found }
6✔
32
      format.all  { head :not_found }
3✔
33
    end
34
  end
35

36
  protected
1✔
37

38
  def current_user
1✔
39
    if session.key?(:member_id)
867✔
40
      @current_member ||= Member.find(session[:member_id])
376✔
41
    end
42
  rescue ActiveRecord::RecordNotFound
43
    session[:member_id] = nil
×
44
  end
45

46
  def current_service
1✔
47
    if session.key?(:service_id)
×
48
      @current_service ||= Service.find_by(member_id: session[:member_id],
×
49
                                           id: session[:service_id])
50
    end
51
  rescue ActiveRecord::RecordNotFound
52
    session[:service_id] = nil
×
53
  end
54

55
  def current_user?
1✔
56
    !!current_user
1,694✔
57
  end
58

59
  def logged_in?
1✔
60
    current_user?
1,694✔
61
  end
62

63
  def accept_terms
1✔
64
    store_path
500✔
65
    redirect_to terms_and_conditions_path if current_user.accepted_toc_at.blank?
500✔
66
  end
67

68
  def authenticate_member!
1✔
69
    if current_user
29✔
70
      finish_registration
28✔
71
    else
72
      redirect_to redirect_path
1✔
73
    end
74
  end
75

76
  def store_path
1✔
77
    session[:previous_request_url] = request.url
500✔
78
  end
79

80
  def previous_path
1✔
81
    session[:previous_request_url]
7✔
82
  end
83

84
  def finish_registration
1✔
85
    if current_user.requires_additional_details?
36✔
86
      redirect_to edit_member_details_path unless providing_additional_details?
×
87
    end
88
  end
89

90
  def providing_additional_details?
1✔
91
    [edit_member_path, edit_member_details_path].include? request.path
×
92
  end
93

94
  def logout!
1✔
95
    @current_member = nil
×
96
    reset_session
×
97
  end
98

99
  helper_method :redirect_path
1✔
100
  def redirect_path
1✔
101
    '/auth/github'
8✔
102
  end
103

104
  def authenticate_admin!
1✔
105
    redirect_to root_path, notice: "You can't be here" unless logged_in? && current_user.has_role?(:admin)
4✔
106
  end
107

108
  def authenticate_admin_or_organiser!
1✔
109
    redirect_to root_path, notice: "You can't be here" unless manager?
221✔
110
  end
111

112
  def manager?
1✔
113
    logged_in? && (current_user.is_admin? || current_user.has_role?(:organiser, :any))
221✔
114
  end
115

116
  helper_method :manager?
1✔
117

118
  def is_logged_in?
1✔
119
    unless logged_in?
63✔
120
      flash[:notice] = t('notifications.not_logged_in')
1✔
121
      redirect_to root_path
1✔
122
    end
123
  end
124

125
  def has_access?
1✔
126
    is_logged_in?
53✔
127
  end
128

129
  private
1✔
130

131
  def set_locale
1✔
132
    store_locale_to_cookie(params[:locale]) if locale
723✔
133
    I18n.locale = cookies[:locale] || I18n.default_locale
723✔
134
  end
135

136
  def user_not_authorized
1✔
137
    redirect_to(user_path, notice: 'You are not authorized to perform this action.')
1✔
138
  end
139

140
  def user_path
1✔
141
    request.referrer || root_path
1✔
142
  end
143

144
  def chapters
1✔
145
    @chapters ||= Chapter.all
×
146
  end
147

148
  def redirect_back(fallback_location:, **args)
1✔
149
    if referer = request.headers['Referer']
82✔
150
      redirect_to referer, **args
64✔
151
    else
152
      redirect_to fallback_location, **args
18✔
153
    end
154
  end
155

156
  def store_locale_to_cookie(locale)
1✔
157
    cookies[:locale] = { value: locale,
1✔
158
                         expires: Time.zone.now + 36_000 }
159
  end
160

161
  def locale
1✔
162
    params[:locale] if params[:locale] && I18n.available_locales.include?(params[:locale].to_sym)
723✔
163
  end
164
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