• 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

27.59
/app/controllers/api/courses_controller.rb
1
module Api
1✔
2
  # API controller for Courses
3
  class CoursesController < MainApiController
1✔
4
    include AutomatedTestsHelper::AutotestApi
1✔
5

6
    DEFAULT_FIELDS = [:id, :name, :is_hidden, :display_name, :start_at, :end_at].freeze
1✔
7

8
    def index
1✔
9
      if current_user.admin_user?
×
10
        courses = get_collection(Course)
×
11
      else
12
        courses = get_collection(current_user.visible_courses)
×
13
      end
14
      respond_to do |format|
×
15
        format.xml { render xml: courses.to_xml(only: DEFAULT_FIELDS, root: 'courses', skip_types: 'true') }
×
16
        format.json { render json: courses.to_json(only: DEFAULT_FIELDS) }
×
17
      end
18
    end
19

20
    def show
1✔
21
      course = current_course
×
22
      respond_to do |format|
×
23
        format.xml { render xml: course.to_xml(only: DEFAULT_FIELDS, root: 'course', skip_types: 'true') }
×
24
        format.json { render json: course.to_json(only: DEFAULT_FIELDS) }
×
25
      end
26
    end
27

28
    def create
1✔
29
      Course.create!(course_params)
×
30
    rescue ActiveRecord::SubclassNotFound, ActiveRecord::RecordInvalid => e
31
      render 'shared/http_status', locals: { code: '422', message: e.to_s }, status: :unprocessable_content
×
32
    rescue StandardError
33
      render 'shared/http_status', locals: { code: '500', message:
×
34
        HttpStatusHelper::ERROR_CODE['message']['500'] }, status: :internal_server_error
35
    else
36
      render 'shared/http_status', locals: { code: '200', message:
×
37
        HttpStatusHelper::ERROR_CODE['message']['200'] }, status: :ok
38
    end
39

40
    def update
1✔
41
      current_course.update!(course_params)
×
42
    rescue ActiveRecord::SubclassNotFound, ActiveRecord::RecordInvalid => e
43
      render 'shared/http_status', locals: { code: '422', message: e.to_s }, status: :unprocessable_content
×
44
    rescue StandardError
45
      render 'shared/http_status', locals: { code: '500', message:
×
46
        HttpStatusHelper::ERROR_CODE['message']['500'] }, status: :internal_server_error
47
    else
48
      render 'shared/http_status', locals: { code: '200', message:
×
49
        HttpStatusHelper::ERROR_CODE['message']['200'] }, status: :ok
50
    end
51

52
    def update_autotest_url
1✔
53
      AutotestResetUrlJob.perform_now(current_course, params[:url], request.protocol + request.host_with_port)
×
54
    rescue ActiveRecord::SubclassNotFound, ActiveRecord::RecordInvalid => e
55
      render 'shared/http_status', locals: { code: '422', message: e.to_s }, status: :unprocessable_content
×
56
    rescue StandardError
57
      render 'shared/http_status', locals: { code: '500', message:
×
58
        HttpStatusHelper::ERROR_CODE['message']['500'] }, status: :internal_server_error
59
    else
60
      render 'shared/http_status', locals: { code: '200', message:
×
61
        HttpStatusHelper::ERROR_CODE['message']['200'] }, status: :ok
62
    end
63

64
    def test_autotest_connection
1✔
65
      settings = current_course.autotest_setting
×
66
      if settings&.url
×
67
        begin
68
          get_schema(current_course.autotest_setting)
×
69
          render 'shared/http_status', locals: { code: '200', message:
×
70
            I18n.t('automated_tests.manage_connection.test_success', url: settings.url) }, status: :ok
71
        rescue JSON::ParserError
72
          render 'shared/http_status',
×
73
                 locals: { code: '500',
74
                           message: I18n.t('automated_tests.manage_connection.test_schema_failure',
75
                                           url: settings.url) },
76
                 status: :internal_server_error
77
        rescue StandardError => e
78
          render 'shared/http_status',
×
79
                 locals: { code: '500',
80
                           message: I18n.t('automated_tests.manage_connection.test_failure',
81
                                           url: settings.url,
82
                                           error: e.to_s) },
83
                 status: :internal_server_error
84
        end
85
      else
86
        render 'shared/http_status', locals: { code: '422', message:
×
87
          I18n.t('automated_tests.no_autotest_settings') }, status: :unprocessable_content
88
      end
89
    end
90

91
    def reset_autotest_connection
1✔
92
      settings = current_course.autotest_setting
×
93
      if settings&.url
×
94
        begin
95
          AutotestResetUrlJob.perform_now(current_course, settings.url,
×
96
                                          request.protocol + request.host_with_port, refresh: true)
97
          render 'shared/http_status', locals: { code: '200', message:
×
98
            HttpStatusHelper::ERROR_CODE['message']['200'] }, status: :ok
99
        rescue StandardError => e
100
          render 'shared/http_status', locals: { code: '500', message: e.to_s }, status: :internal_server_error
×
101
        end
102
      else
103
        render 'shared/http_status', locals: { code: '422', message:
×
104
          I18n.t('automated_tests.no_autotest_settings') }, status: :unprocessable_content
105
      end
106
    end
107

108
    private
1✔
109

110
    def check_course
1✔
111
      super unless action_name == 'index'
×
112
    end
113

114
    def course_params
1✔
115
      fields = [:name, :is_hidden, :display_name]
×
116
      if allowed_to?(:edit?, with: Admin::CoursePolicy)
×
117
        fields << :start_at
×
118
        fields << :end_at
×
119
      end
120
      params.permit(*fields)
×
121
    end
122

123
    protected
1✔
124

125
    def implicit_authorization_target
1✔
126
      Course
×
127
    end
128
  end
129
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