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

pulibrary / tigerdata-app / 1f9ee909-20b2-467d-b493-b5be4964430d

22 Oct 2025 04:57PM UTC coverage: 91.212%. Remained the same
1f9ee909-20b2-467d-b493-b5be4964430d

push

circleci

web-flow
Fixing flaky tests (#2080)

10 times out of 10 one of these tests would fail for me locally.

Really we just have to look at the page for something new so that we are
sure the controller action has finished before we check for something
that is not waiting.

2740 of 3004 relevant lines covered (91.21%)

755.12 hits per line

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

89.53
/app/controllers/application_controller.rb
1
# frozen_string_literal: true
2
class ApplicationController < ActionController::Base
6✔
3
  protect_from_forgery with: :exception
6✔
4
  before_action :authenticate_user!
6✔
5
  before_action :mediaflux_session
6✔
6
  around_action :mediaflux_session_errors
6✔
7
  around_action :mediaflux_login_errors
6✔
8
  before_action :emulate_user
6✔
9
  before_action :downtime_check
6✔
10

11
  helper_method :breadcrumbs
6✔
12

13
  def new_session_path(_scope)
6✔
14
    new_user_session_path
×
15
  end
16

17
  def after_sign_in_path_for(_resource)
6✔
18
    mediaflux_passthru_path
2✔
19
    # "/users/#{@user.id}"
20
  end
21

22
  def require_admin_user
6✔
23
    head :forbidden unless current_user&.eligible_sysadmin?
8✔
24
  end
25

26
  def breadcrumbs
6✔
27
    @breadcrumbs ||= []
1,669✔
28
  end
29

30
  def add_breadcrumb(name, path = nil)
6✔
31
    breadcrumbs << Breadcrumb.new(name, path)
961✔
32
  end
33

34
  # Render a 404 page for any undefined route
35
  def render_not_found
6✔
36
    render file: Rails.public_path.join("404.html").to_s, layout: false, status: :not_found
2✔
37
  end
38

39
  private
6✔
40

41
    def mediaflux_session
6✔
42
      logger.debug "Application Session #{session[:mediaflux_session]} cas: #{session[:active_web_user]}"
1,072✔
43
      unless ["passthru", "cas"].include?(action_name)
1,072✔
44
        current_user&.mediaflux_from_session(session)
1,060✔
45
      end
46
    end
47

48
    def mediaflux_session_errors
6✔
49
      yield
1,072✔
50
    rescue ActionView::Template::Error, Mediaflux::SessionExpired => e
51
      raise unless e.is_a?(Mediaflux::SessionExpired) || e.cause.is_a?(Mediaflux::SessionExpired)
12✔
52
      if session[:active_web_user]
12✔
53
        redirect_to mediaflux_passthru_path(path: request.path)
6✔
54
      elsif session_error_handler
6✔
55
        retry
4✔
56
      else
57
        raise
2✔
58
      end
59
    end
60

61
    def mediaflux_login_errors
6✔
62
      yield
1,072✔
63
    rescue Mediaflux::SessionError
64
      if session_error_handler
×
65
        retry
×
66
      else
67
        raise
×
68
      end
69
    end
70

71
    def session_error_handler
6✔
72
      @retry_count ||= 0
6✔
73
      @retry_count += 1
6✔
74

75
      current_user.clear_mediaflux_session(session)
6✔
76
      current_user.mediaflux_from_session(session)
6✔
77
      @retry_count < 3 # If the session is expired we should not have to retry more than once, but let's have a little wiggle room
6✔
78
    end
79

80
    def emulate_user
6✔
81
      return if Rails.env.production?
1,072✔
82
      return if current_user.blank? || !current_user.trainer
1,012✔
83

84
      if session[:emulation_role]
84✔
85
        if session[:emulation_role] == "Eligible Data Sponsor"
38✔
86
          emulate_sponsor
6✔
87
        elsif session[:emulation_role] == "Eligible Data Manager"
32✔
88
          emulate_manager
6✔
89
        elsif session[:emulation_role] == "System Administrator"
26✔
90
          emulate_sysadmin
24✔
91
        elsif session[:emulation_role] == "Eligible Data User"
2✔
92
          emulate_data_user
2✔
93
        elsif session[:emulation_role] == "Return to Self"
×
94
          return_to_self
×
95
        end
96
      end
97
    end
98

99
    def emulate_sponsor
6✔
100
      current_user.eligible_sponsor = true
6✔
101
      current_user.eligible_manager = false
6✔
102
      current_user.sysadmin = false
6✔
103
    end
104

105
    def emulate_manager
6✔
106
      current_user.eligible_manager = true
6✔
107
      current_user.eligible_sponsor = false
6✔
108
      current_user.sysadmin = false
6✔
109
    end
110

111
    def emulate_sysadmin
6✔
112
      current_user.sysadmin = true
24✔
113
      current_user.eligible_manager = false
24✔
114
      current_user.eligible_sponsor = false
24✔
115
    end
116

117
    def emulate_data_user
6✔
118
      current_user.eligible_sponsor = false
2✔
119
      current_user.eligible_manager = false
2✔
120
      current_user.sysadmin = false
2✔
121
      current_user.trainer = false
2✔
122
    end
123

124
    def return_to_self
6✔
125
      current_user.eligible_sponsor = false
×
126
      current_user.eligible_manager = false
×
127
      current_user.sysadmin = false
×
128
    end
129

130
    def downtime_check
6✔
131
      if Flipflop.disable_login?
1,011✔
132
        if current_user&.eligible_sysadmin?
6✔
133
          flash[:notice] = I18n.t(:only_sysadmin_users)
4✔
134
        else
135
          redirect_to root_path
2✔
136
          flash[:notice] = I18n.t(:no_login_currently)
2✔
137
        end
138
      end
139
    end
140
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

© 2025 Coveralls, Inc