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

tulibraries / Press-6 / ba9970a6-538f-4468-a949-9d5661b05483

26 Jun 2025 04:44PM UTC coverage: 88.187%. Remained the same
ba9970a6-538f-4468-a949-9d5661b05483

push

circleci

web-flow
corrects syntax for template call (#1335)

0 of 1 new or added line in 1 file covered. (0.0%)

1299 of 1473 relevant lines covered (88.19%)

8.89 hits per line

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

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

3
class FormsController < ApplicationController
1✔
4
  def new
1✔
5
    @form = (params[:form].present? ? Form.new(params[:form]) : Form.new)
10✔
6
    @notice = flash.now[:notice] if :notice.present?
10✔
7
    if existing_forms.include? params[:type]
10✔
8
      @type = params[:type]
10✔
9
      existing_forms.each do |form|
10✔
10
        @intro = Webpage.find_by(slug: "#{form}-intro") if form == @type
40✔
11
        @footer = Webpage.find_by(slug: "#{form}-footer") if form == @type
40✔
12
      end
13
      @books = Book.displayable.requestable.order(:sort_title)
10✔
14
      @book = Book.find(params[:id]) if params[:id].present?
10✔
15
      create if params[:form].present?
10✔
16
    else
NEW
17
      render template: "errors/not_found", status: :not_found
×
18
    end
19
  end
20

21
  def create
1✔
22
    @form = Form.new(params[:form])
5✔
23
    @form.request = request
5✔
24
    @type = params[:form][:form_type]
5✔
25
    @books = Book.displayable.requestable.order(:sort_title)
5✔
26

27
    if params[:form][:comments].present? && (params[:form][:comments].include? "<")
5✔
28
      failure("html")
×
29
    elsif params[:form][:survey].present?
5✔
30
      failure("survey")
×
31
    elsif params[:form][:add_to_mailing_list].present? && params[:form][:remove_from_mailing_list].present?
5✔
32
      failure("mailers")
1✔
33
    else
34
      @form.deliver ? success : failure("mail")
4✔
35
    end
36
  end
37

38
  def success
1✔
39
    redirect_to root_path, notice: "Thank you for your message. We will contact you soon!"
4✔
40
  end
41

42
  def failure(mode)
1✔
43
    case mode
1✔
44
    when "html"
45
      notice = t("tupress.forms.errors.html")
×
46
      flash.now[:notice] = notice
×
47
    when "survey"
48
      notice = t("tupress.forms.errors.survey")
×
49
      flash.now[:notice] = notice
×
50
    when "mailers"
51
      notice = t("tupress.forms.errors.mailers")
1✔
52
      flash.now[:notice] = notice
1✔
53
    when "mail"
54
      notice = t("tupress.forms.errors.smtp")
×
55
      flash.now[:notice] = notice
×
56
    end
57
    render :new, notice:
1✔
58
  end
59

60
  def existing_forms
1✔
61
    Dir.glob(Rails.root.join("app/views/forms/*/"))
20✔
62
       .map { |template_path| template_path.split("/").last }
80✔
63
  end
64
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