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

sleede / fab-manager / #98

pending completion
#98

push

coveralls-ruby

sylvainbx
Merge branch 'dev' for release 5.7.0

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

7383 of 12030 relevant lines covered (61.37%)

14.06 hits per line

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

87.5
/app/controllers/api/trainings_controller.rb
1
# frozen_string_literal: true
2

3
# API Controller for resources of type Training
4
class API::TrainingsController < API::ApiController
1✔
5
  include ApplicationHelper
1✔
6

7
  before_action :authenticate_user!, except: %i[index show]
1✔
8
  before_action :set_training, only: %i[update destroy]
1✔
9

10
  def index
1✔
11
    @requested_attributes = params[:requested_attributes]
×
12
    @trainings = TrainingService.list(params)
×
13
  end
14

15
  def show
1✔
16
    @training = Training.friendly.find(params[:id])
×
17
  end
18

19
  def create
1✔
20
    authorize Training
1✔
21
    @training = Training.new(training_params)
1✔
22
    if @training.save
1✔
23
      render :show, status: :created, location: @training
1✔
24
    else
25
      render json: @training.errors, status: :unprocessable_entity
×
26
    end
27
  end
28

29
  def update
1✔
30
    authorize Training
2✔
31
    if params[:training][:users].present?
2✔
32
      members = User.where(id: valid_training_params[:users])
1✔
33
      members.each do |m|
1✔
34
        m.trainings << @training
1✔
35
      end
36

37
      head :no_content
1✔
38
    elsif current_user.admin? && @training.update(training_params)
1✔
39
      # only admins can fully update a training, not managers
40
      render :show, status: :ok, location: @training
1✔
41
    else
42
      render json: @training.errors, status: :unprocessable_entity
×
43
    end
44
  end
45

46
  def destroy
1✔
47
    authorize @training
1✔
48
    @training.destroy
1✔
49
    head :no_content
1✔
50
  end
51

52
  # This endpoint is used to get a list of trainings to validate
53
  def availabilities
1✔
54
    authorize Training
1✔
55
    @training = Training.find(params[:id])
1✔
56
    @availabilities = @training.availabilities
1✔
57
                               .includes(slots: {
58
                                           slots_reservations: {
59
                                             reservation: {
60
                                               statistic_profile: [:trainings, { user: [:profile] }]
61
                                             }
62
                                           }
63
                                         })
64
                               .where('slots_reservations.canceled_at': nil)
65
                               .order('availabilities.start_at DESC')
66
  end
67

68
  private
1✔
69

70
  def set_training
1✔
71
    @training = Training.find(params[:id])
3✔
72
  end
73

74
  def valid_training_params
1✔
75
    params.require(:training).permit(:id, users: [])
1✔
76
  end
77

78
  def training_params
1✔
79
    params.require(:training)
2✔
80
          .permit(:id, :name, :description, :machine_ids, :plan_ids, :nb_total_places, :public_page, :disabled,
81
                  :auto_cancel, :auto_cancel_threshold, :auto_cancel_deadline, :authorization, :authorization_period,
82
                  :invalidation, :invalidation_period,
83
                  training_image_attributes: %i[id attachment], machine_ids: [], plan_ids: [],
84
                  advanced_accounting_attributes: %i[code analytical_section])
85
  end
86
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