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

MarkUsProject / Markus / 26985068800

04 Jun 2026 11:09PM UTC coverage: 84.913% (-5.3%) from 90.19%
26985068800

Pull #7972

github

web-flow
Merge c74925818 into 9a5124c61
Pull Request #7972: Parallelize rspec tests

1023 of 2226 branches covered (45.96%)

Branch coverage included in aggregate %.

36935 of 42476 relevant lines covered (86.95%)

113.68 hits per line

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

89.71
/app/controllers/application_controller.rb
1
# Filters added to this controller apply to all controllers in the application.
2
# Likewise, all the methods added will be available for all controllers.
3
class ApplicationController < ActionController::Base
4✔
4
  include SessionHandler
4✔
5
  include ApplicationHelper
4✔
6
  include UploadHelper
4✔
7
  include DownloadHelper
4✔
8

9
  authorize :role, through: :current_role
4✔
10
  authorize :real_user, through: :real_user
4✔
11
  authorize :real_role, through: :real_role
4✔
12
  verify_authorized
4✔
13
  rescue_from ActionPolicy::Unauthorized, with: :user_not_authorized
4✔
14

15
  # responder set up
16
  self.responder = ApplicationResponder
4✔
17
  respond_to :html
4✔
18

19
  protect_from_forgery with: :exception
4✔
20

21
  layout 'content'
4✔
22

23
  helper :all # include all helpers in the views, all the time
4✔
24

25
  # set user time zone based on their settings
26
  around_action :use_time_zone, if: :current_user
4✔
27
  # activate i18n for renaming constants in views
28
  before_action :set_locale, :get_file_encodings
4✔
29
  # check for active session on every page
30
  before_action :authenticate, :check_record,
4✔
31
                except: [:login, :page_not_found, :check_timeout, :login_remote_auth]
32
  before_action :check_course_switch
4✔
33
  # check for AJAX requests
34
  after_action :flash_to_headers
4✔
35

36
  # Define default URL options to include the locale if the user is not logged in
37
  def default_url_options(_options = {})
4✔
38
    if current_user
4,389✔
39
      {}
4,330✔
40
    else
41
      { locale: I18n.locale }
59✔
42
    end
43
  end
44

45
  def page_not_found
4✔
46
    if current_user
6✔
47
      current_role unless current_course.nil?
6✔
48
      render 'shared/error_page',
6✔
49
             locals: { code: '404', message: HttpStatusHelper::ERROR_CODE['message']['404'] },
50
             status: :not_found,
51
             layout: 'content'
52
    else
53
      redirect_to root_path
×
54
    end
55
  end
56

57
  protected
4✔
58

59
  def use_time_zone(&)
4✔
60
    Time.use_zone(current_user.time_zone, &)
1,996✔
61
  end
62

63
  # Set locale according to URL parameter. If unknown parameter is
64
  # requested, fall back to default locale.
65
  def set_locale
4✔
66
    if params[:locale].nil?
2,044✔
67
      if current_user && I18n.available_locales.include?(current_user.locale.to_sym)
2,041✔
68
        I18n.locale = current_user.locale
1,996✔
69
      else
70
        I18n.locale = I18n.default_locale
45✔
71
      end
72
    elsif I18n.available_locales.include? params[:locale].to_sym
3✔
73
      I18n.locale = params[:locale]
3✔
74
    else
75
      flash_now(:notice, I18n.t('locale_not_available', locale: params[:locale]))
×
76
    end
77
  end
78

79
  def get_file_encodings
4✔
80
    @encodings = [%w[Unicode UTF-8], %w[ISO-8859-1 ISO-8859-1]]
2,044✔
81
  end
82

83
  # add flash message to HTTP response headers
84
  def flash_to_headers
4✔
85
    [:error, :success, :warning, :notice].each do |key|
1,802✔
86
      unless flash[key].nil?
7,208✔
87
        if flash[key].is_a?(Array)
635✔
88
          str = flash[key].join(';')
580✔
89
        else
90
          str = flash[key]
55✔
91
        end
92
        response.headers["X-Message-#{key}"] = str
635✔
93
      end
94
    end
95
    if request.xhr?
1,802✔
96
      flash.discard
1,395✔
97
    end
98
  end
99

100
  # dynamically hide a flash message (for HTTP requests)
101
  def hide_flash(key)
4✔
102
    discard_header = response.headers['X-Message-Discard']
×
103
    if discard_header.nil?
×
104
      response.headers['X-Message-Discard'] = key.to_s
×
105
    else
106
      response.headers['X-Message-Discard'] = "#{key};#{discard_header}"
×
107
    end
108
  end
109

110
  def user_not_authorized
4✔
111
    if current_user
215✔
112
      render 'shared/error_page',
215✔
113
             locals: { code: '403', message: HttpStatusHelper::ERROR_CODE['message']['403'] },
114
             status: :forbidden,
115
             layout: 'content'
116
    else
117
      redirect_to root_path
×
118
    end
119
  end
120

121
  # Render 403 if the current user is switching roles and they try to view a route for a different course
122
  def check_course_switch
4✔
123
    if session[:role_switch_course_id] && current_course&.id != session[:role_switch_course_id]
1,952✔
124
      flash_message(:error, I18n.t('main.role_switch.forbidden_warning'))
2✔
125
      redirect_back(fallback_location: course_assignments_path(session[:role_switch_course_id]))
2✔
126
    end
127
  end
128

129
  def implicit_authorization_target
4✔
130
    controller_name.classify.constantize.find_or_initialize_by(identification_params)
4,245✔
131
  end
132

133
  def identification_params
4✔
134
    params.permit(:id)
4,147✔
135
  end
136
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc