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

MarkUsProject / Markus / 16733098629

04 Aug 2025 08:07PM UTC coverage: 91.884%. Remained the same
16733098629

Pull #7631

github

web-flow
Merge b638afd4e into 795d39e35
Pull Request #7631: [pre-commit.ci] pre-commit autoupdate

658 of 1419 branches covered (46.37%)

Branch coverage included in aggregate %.

16 of 16 new or added lines in 16 files covered. (100.0%)

155 existing lines in 10 files now uncovered.

42034 of 45044 relevant lines covered (93.32%)

118.71 hits per line

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

78.85
/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
    DEFAULT_FIELDS = [:id, :name, :is_hidden, :display_name].freeze
1✔
6

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

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

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

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

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

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

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

107
    private
1✔
108

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

113
    protected
1✔
114

115
    def implicit_authorization_target
1✔
116
      Course
80✔
117
    end
118
  end
119
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