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

tulibraries / manifold / 20754304347

06 Jan 2026 04:11PM UTC coverage: 87.025% (-0.06%) from 87.081%
20754304347

push

github

cdoyle-temple
remove inadvertantly added tests

3092 of 3553 relevant lines covered (87.03%)

28.55 hits per line

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

85.19
/app/controllers/forms_controller.rb
1
# frozen_string_literal: true
2

3
class FormsController < ApplicationController
1✔
4
  before_action :use_unsafe_params, only: [:persist_form!]
1✔
5
  def index
1✔
6
    form_groups = FormInfo.for_index.group_by(&:grouping)
2✔
7
    # Remove 'No Grouping' from form_groups
8
    form_groups.delete("No Grouping")
2✔
9
    @form_groups = Hash[form_groups.sort_by { |k, v| k == "Administrative Services" ? 1 : 0 }]
5✔
10
    respond_to do |format|
2✔
11
      format.html {}
2✔
12
      format.json do
2✔
13
        @forms = form_objects_for_json
1✔
14
        render json: FormSerializer.new(@forms)
1✔
15
      end
16
    end
17
  end
18

19
  def show
1✔
20
    @form = Form.new
17✔
21
    if existing_forms.include? params[:id]
17✔
22
      @type = params[:id]
17✔
23
      info = FormInfo.find_by(slug: @type)
17✔
24
      if info.present?
17✔
25
        @title = info.title
17✔
26
        @intro = info.intro
17✔
27
        @recipients = info.recipients
17✔
28
      end
29
    else
30
      render "errors/not_found", status: :not_found
×
31
    end
32
  end
33

34
  def create
1✔
35
    @form = Form.new(params[:form])
15✔
36
    @form.request = request
15✔
37
    form_type = params[:form][:form_type]
15✔
38
    info = FormInfo.find_by(slug: form_type)
15✔
39
    @form.recipients = info.recipients.reject(&:empty?).to_json if info.present?
15✔
40
    excel_form_data = if params[:form]&.respond_to?(:to_unsafe_h)
15✔
41
      params[:form].to_unsafe_h.deep_dup
15✔
42
    else
43
      {}
×
44
    end
45
    excel_form_data["form_type"] = form_type if form_type
15✔
46

47
    email_sent = false
15✔
48
    begin
49
      email_sent = @form.deliver
15✔
50
    rescue Net::ReadTimeout => e
51
      Rails.logger.warn("Form delivery timed out: #{e.class} - #{e.message}")
×
52
    end
53
    persist_form!
15✔
54
    queue_excel_update(excel_form_data)
15✔
55

56
    if form_type == "av-requests" || form_type == "copy-requests"
15✔
57
      if email_sent
2✔
58
        redirect_to form_path(form_type, success: form_type)
2✔
59
      else
60
        redirect_to form_path(form_type, success: "false")
×
61
      end
62
    else
63
      if email_sent
13✔
64
        redirect_to forms_path(success: "true")
13✔
65
      else
66
        redirect_to forms_path(success: "false")
×
67
      end
68
    end
69
  end
70

71
  def persist_form!
1✔
72
    type = params[:form].delete(:form_type)
15✔
73
    params[:form].delete(:recipients) # Remove recipients from params before storing
15✔
74
    FormSubmission.create(
15✔
75
      form_type: type,
76
      form_attributes: use_unsafe_params
77
    )
78
  end
79

80
  def existing_forms
1✔
81
    Dir.glob(Rails.root.join("app/views/forms/*/"))
18✔
82
      .map { |template_path| template_path.split("/").last }
288✔
83
      .reject { |template_name| template_name == "shared" }
288✔
84
  end
85

86
  def form_objects_for_json
1✔
87
    existing_forms.map do |form|
1✔
88
        OpenStruct.new(
16✔
89
          id: form,
90
          label: t("manifold.forms.#{form.underscore}.title"),
91
          link: "#{request.base_url}/forms/#{form}",
92
          updated_at: DateTime.new(0)
93
        )
94
      end
95
  end
96

97
  def queue_excel_update(form_data)
1✔
98
    form_type = form_data["form_type"] || form_data[:form_type]
15✔
99
    config = excel_form_destination_config(form_type)
15✔
100
    sheet_id = config[:spreadsheet_file_id]
15✔
101

102
    if sheet_id.blank?
15✔
103
      Rails.logger.info "Skipping Excel update: spreadsheet_file_id missing for form_type=#{form_type.inspect}"
15✔
104
      return
15✔
105
    end
106

107
    worksheet = config[:worksheet_name] || worksheet_name_for(form_data)
×
108

109
    Rails.logger.info "Queueing ExcelUpdateJob for form_type=#{form_data['form_type']} to worksheet=#{worksheet}"
×
110

111
    ExcelUpdateJob.perform_later(
×
112
      form_data,
113
      sheet_id,
114
      worksheet,
115
    )
116
  end
117

118
  def use_unsafe_params
1✔
119
    request.parameters
15✔
120
  end
121

122
  def worksheet_name_for(form_data)
1✔
123
    form_type = form_data["form_type"] || form_data[:form_type]
×
124
    case form_type
×
125
    when "copy-requests"
126
      "Copy-Requests"
×
127
    else
128
      "AV-Requests"
×
129
    end
130
  end
131

132
  # Looks up destination details for a form. Credentials should have structure:
133
  # microsoft:
134
  #   forms:
135
  #     scrc_requests:
136
  #       spreadsheet_file_id: "..."
137
  def excel_form_destination_config(form_type)
1✔
138
    credentials = Rails.application.credentials.microsoft || {}
15✔
139
    forms_config = credentials[:forms] || {}
15✔
140

141
    key = case form_type
15✔
142
          when "av-requests", "copy-requests"
143
            :scrc_requests
2✔
144
    else
145
            form_type&.to_sym
13✔
146
    end
147

148
    config = forms_config[key] || {}
15✔
149
    config = config.to_h if config.respond_to?(:to_h)
15✔
150
    config = config.deep_symbolize_keys if config.respond_to?(:deep_symbolize_keys)
15✔
151
    config || {}
15✔
152
  end
153
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