mirror of
https://github.com/Evolix/chexpire.git
synced 2024-05-19 08:58:39 +02:00
Adapt new check form to predefined kind, more i18n
This commit is contained in:
parent
a384585256
commit
c619d39bde
|
@ -20,4 +20,14 @@ class ApplicationController < ActionController::Base
|
||||||
def set_locale
|
def set_locale
|
||||||
I18n.locale = current_user.try(:locale) || I18n.default_locale
|
I18n.locale = current_user.try(:locale) || I18n.default_locale
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def not_found
|
||||||
|
fail ActionController::RoutingError, "Not Found"
|
||||||
|
rescue StandardError
|
||||||
|
render_404
|
||||||
|
end
|
||||||
|
|
||||||
|
def render_404
|
||||||
|
render file: "#{Rails.root}/public/404", status: :not_found
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -10,8 +10,14 @@ class ChecksController < ApplicationController
|
||||||
|
|
||||||
def new
|
def new
|
||||||
@check = Check.new
|
@check = Check.new
|
||||||
build_empty_notification
|
|
||||||
authorize @check
|
authorize @check
|
||||||
|
|
||||||
|
if params[:kind].present?
|
||||||
|
return not_found unless Check.kinds.key?(params[:kind])
|
||||||
|
@check.kind = params[:kind]
|
||||||
|
end
|
||||||
|
|
||||||
|
build_empty_notification
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
|
@ -20,10 +26,10 @@ class ChecksController < ApplicationController
|
||||||
authorize @check
|
authorize @check
|
||||||
|
|
||||||
if @check.save
|
if @check.save
|
||||||
flash[:notice] = "Your check has been saved."
|
flash[:notice] = t(".saved")
|
||||||
redirect_to checks_path
|
redirect_to checks_path
|
||||||
else
|
else
|
||||||
flash.now[:alert] = "An error occured."
|
flash.now[:alert] = t(".invalid")
|
||||||
render :new
|
render :new
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
<%= simple_form_for(check) do |f| %>
|
<%= simple_form_for(check) do |f| %>
|
||||||
<%= f.input :domain, autofocus: true, input_html: { autocapitalize: :none, autocorrect: :off } %>
|
<%= f.input :domain,
|
||||||
|
autofocus: true,
|
||||||
|
input_html: { autocapitalize: :none, autocorrect: :off },
|
||||||
|
label: t(".#{check.kind || "generic" }.domain") %>
|
||||||
|
|
||||||
<% if check.new_record? %>
|
<% if check.new_record? %>
|
||||||
<%= f.input :kind, as: :radio_buttons, collection: Check.kinds.keys if check.new_record? %>
|
<%= f.input :kind, as: check.kind.present? ? :hidden : :radio_buttons, collection: Check.kinds.keys %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<%= f.input :comment %>
|
<%= f.input :comment %>
|
||||||
|
|
|
@ -3,10 +3,10 @@
|
||||||
<div class="col-12 col-lg-10">
|
<div class="col-12 col-lg-10">
|
||||||
<% if @checks.empty? %>
|
<% if @checks.empty? %>
|
||||||
<div class="alert alert-info">
|
<div class="alert alert-info">
|
||||||
<%= t(".no_check_yet_html", new_domain_path: new_check_path, new_ssl_path: new_check_path) %>
|
<%= t(".no_check_yet_html", new_domain_path: new_check_path(kind: :domain), new_ssl_path: new_check_path(kind: :ssl)) %>
|
||||||
</div>
|
</div>
|
||||||
<% else %>
|
<% else %>
|
||||||
<h1>List of your checks</h1>
|
<h1><%= t(".title") %></h1>
|
||||||
<%= render "table", checks: @checks %>
|
<%= render "table", checks: @checks %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="row justify-content-center">
|
<div class="row justify-content-center">
|
||||||
<div class="col-12 col-lg-10">
|
<div class="col-12 col-lg-10">
|
||||||
<h1>Create a new check</h1>
|
<h1><%= t(".#{@check.kind}.title") %></h1>
|
||||||
|
|
||||||
<%= render "form", check: @check %>
|
<%= render "form", check: @check %>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -8,10 +8,13 @@
|
||||||
<ul class="navbar-nav mr-auto">
|
<ul class="navbar-nav mr-auto">
|
||||||
<% if user_signed_in? %>
|
<% if user_signed_in? %>
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<%= link_to("My checks", checks_path, class: "nav-link") %>
|
<%= link_to(t(".my_checks"), checks_path, class: "nav-link") %>
|
||||||
</li>
|
</li>
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<%= link_to("Add a check", new_check_path, class: "nav-link") %>
|
<%= link_to(t(".new_domain_check"), new_check_path(kind: :domain), class: "nav-link") %>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<%= link_to(t(".new_ssl_check"), new_check_path(kind: :ssl), class: "nav-link") %>
|
||||||
</li>
|
</li>
|
||||||
<% end %>
|
<% end %>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
|
@ -53,6 +53,9 @@ en:
|
||||||
en: English
|
en: English
|
||||||
fr: French
|
fr: French
|
||||||
navbar:
|
navbar:
|
||||||
|
my_checks: "My checks"
|
||||||
|
new_domain_check: "New domain check"
|
||||||
|
new_ssl_check: "New SSL check"
|
||||||
sign_up: "Sign up"
|
sign_up: "Sign up"
|
||||||
sign_in: "Sign in"
|
sign_in: "Sign in"
|
||||||
sign_out: "Sign out"
|
sign_out: "Sign out"
|
||||||
|
@ -60,11 +63,30 @@ en:
|
||||||
|
|
||||||
checks:
|
checks:
|
||||||
index:
|
index:
|
||||||
|
title: List of your checks
|
||||||
no_check_yet_html: |
|
no_check_yet_html: |
|
||||||
You have not set up a check yet.
|
You have not set up a check yet.
|
||||||
Please add a <a href="%{new_domain_path}">domain</a>
|
Please add a <a href="%{new_domain_path}">domain</a>
|
||||||
or a <a href="%{new_ssl_path}">ssl</a> !
|
or a <a href="%{new_ssl_path}">ssl</a> !
|
||||||
|
|
||||||
|
new:
|
||||||
|
title: New check
|
||||||
|
domain:
|
||||||
|
title: New domain check
|
||||||
|
ssl:
|
||||||
|
title: New SSL check
|
||||||
|
|
||||||
|
create:
|
||||||
|
saved: "Your check has been saved."
|
||||||
|
invalid: "Please check the form."
|
||||||
|
|
||||||
form:
|
form:
|
||||||
|
generic:
|
||||||
|
domain: Domain
|
||||||
|
domain:
|
||||||
|
domain: Domain name
|
||||||
|
ssl:
|
||||||
|
domain: Hostname
|
||||||
notifications_hint: |
|
notifications_hint: |
|
||||||
Receive notifications to warn you when our system detects that the
|
Receive notifications to warn you when our system detects that the
|
||||||
expiration date is coming. The time is set in number of days.
|
expiration date is coming. The time is set in number of days.
|
||||||
|
|
|
@ -2,8 +2,15 @@ fr:
|
||||||
activerecord:
|
activerecord:
|
||||||
attributes:
|
attributes:
|
||||||
check:
|
check:
|
||||||
|
domain: "Domaine"
|
||||||
|
comment: "Commentaire"
|
||||||
|
vendor: "Fournisseur"
|
||||||
|
kind: Type
|
||||||
domain_created_at: "Date de création"
|
domain_created_at: "Date de création"
|
||||||
domain_updated_at: "Date de modification"
|
domain_updated_at: "Date de modification"
|
||||||
|
notification:
|
||||||
|
interval: Délai
|
||||||
|
recipient: Destinataire
|
||||||
user:
|
user:
|
||||||
tos_accepted: "Conditions d'utilisation"
|
tos_accepted: "Conditions d'utilisation"
|
||||||
notifications_enabled: "Notifications activées"
|
notifications_enabled: "Notifications activées"
|
||||||
|
@ -11,6 +18,11 @@ fr:
|
||||||
models:
|
models:
|
||||||
check:
|
check:
|
||||||
past: "ne peut être dans le futur"
|
past: "ne peut être dans le futur"
|
||||||
|
helpers:
|
||||||
|
submit:
|
||||||
|
check:
|
||||||
|
create: "Créer"
|
||||||
|
update: "Valider"
|
||||||
|
|
||||||
time:
|
time:
|
||||||
am: am
|
am: am
|
||||||
|
@ -61,6 +73,9 @@ fr:
|
||||||
en: Anglais
|
en: Anglais
|
||||||
fr: Français
|
fr: Français
|
||||||
navbar:
|
navbar:
|
||||||
|
my_checks: "Mes vérifications"
|
||||||
|
new_domain_check: "Nouveau nom de domaine"
|
||||||
|
new_ssl_check: "Nouveau certificat SSL"
|
||||||
sign_up: "Enregistrement"
|
sign_up: "Enregistrement"
|
||||||
sign_in: "Connexion"
|
sign_in: "Connexion"
|
||||||
sign_out: "Déconnexion"
|
sign_out: "Déconnexion"
|
||||||
|
@ -68,11 +83,30 @@ fr:
|
||||||
|
|
||||||
checks:
|
checks:
|
||||||
index:
|
index:
|
||||||
|
title: "Liste de vos vérifications"
|
||||||
no_check_yet_html: |
|
no_check_yet_html: |
|
||||||
Vous n'avez pas encore créé de vérification.
|
Vous n'avez pas encore créé de vérification.
|
||||||
Vous pouvez en ajouter pour un <a href="%{new_domain_path}">domaine</a>
|
Vous pouvez en ajouter pour un <a href="%{new_domain_path}">domaine</a>
|
||||||
ou un <a href="%{new_ssl_path}">SSL</a> !
|
ou un <a href="%{new_ssl_path}">SSL</a> !
|
||||||
|
|
||||||
|
new:
|
||||||
|
title: Nouvelle vérification
|
||||||
|
domain:
|
||||||
|
title: Nouvelle vérification d'un nom de domaine
|
||||||
|
ssl:
|
||||||
|
title: Nouvelle vérification d'un certificat SSL
|
||||||
|
|
||||||
|
create:
|
||||||
|
saved: La vérification est enregistrée.
|
||||||
|
invalid: Veuillez vérifier le formulaire.
|
||||||
|
|
||||||
form:
|
form:
|
||||||
|
generic:
|
||||||
|
domain: Domaine
|
||||||
|
domain:
|
||||||
|
domain: Nom de domaine
|
||||||
|
ssl:
|
||||||
|
domain: Nom d'hôte
|
||||||
notifications_hint: |
|
notifications_hint: |
|
||||||
Recevez des notifications pour vous avertir lorsque notre système détecte
|
Recevez des notifications pour vous avertir lorsque notre système détecte
|
||||||
que la date d'expiration approche. Le délais est indiqué ennombre de jours.
|
que la date d'expiration approche. Le délai est indiqué ennombre de jours.
|
||||||
|
|
|
@ -1,7 +1,34 @@
|
||||||
require "test_helper"
|
require "test_helper"
|
||||||
|
|
||||||
class ChecksControllerTest < ActionDispatch::IntegrationTest
|
class ChecksControllerTest < ActionDispatch::IntegrationTest
|
||||||
# test "the truth" do
|
setup do
|
||||||
# assert true
|
@user = create(:user)
|
||||||
# end
|
login_as(@user)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "no logged users are redirected to signin form" do
|
||||||
|
logout
|
||||||
|
get new_check_path
|
||||||
|
assert_redirected_to new_user_session_path
|
||||||
|
end
|
||||||
|
|
||||||
|
test "new without kind does not trigger an error" do
|
||||||
|
get new_check_path
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
test "new with kind domain does not trigger an error" do
|
||||||
|
get new_check_path(kind: :domain)
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
test "new with kind ssl does not trigger an error" do
|
||||||
|
get new_check_path(kind: :ssl)
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
test "new with an invalid kind returns an error" do
|
||||||
|
get new_check_path(kind: :invalid)
|
||||||
|
assert_response :not_found
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -8,29 +8,28 @@ class ChecksTest < ApplicationSystemTestCase
|
||||||
@check = create(:check, :with_notifications, user: @user)
|
@check = create(:check, :with_notifications, user: @user)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "create a check and a notification" do
|
test "create a check and a notification without kind" do
|
||||||
visit new_check_path
|
visit new_check_path
|
||||||
|
|
||||||
domain = "domain-test.fr"
|
|
||||||
fill_in("check[domain]", with: domain)
|
|
||||||
choose "domain"
|
choose "domain"
|
||||||
|
|
||||||
recipient = "recipient@example.org"
|
fill_and_valid_new_check
|
||||||
fill_in("check[notifications_attributes][0][recipient]", with: recipient)
|
end
|
||||||
fill_in("check[notifications_attributes][0][interval]", with: 30)
|
|
||||||
|
|
||||||
click_button
|
test "create a predefined domain check" do
|
||||||
|
visit new_check_path(kind: :domain)
|
||||||
|
|
||||||
assert_equal checks_path, page.current_path
|
refute page.has_css? "domain[kind]"
|
||||||
|
|
||||||
assert page.has_css?(".alert-success")
|
fill_and_valid_new_check
|
||||||
assert page.has_content?(domain)
|
end
|
||||||
|
|
||||||
notification = Notification.last
|
test "create a predefined ssl check" do
|
||||||
assert_equal recipient, notification.recipient
|
visit new_check_path(kind: :ssl)
|
||||||
assert_equal 30, notification.interval
|
|
||||||
assert notification.email?
|
refute page.has_css? "domain[kind]"
|
||||||
assert notification.pending?
|
|
||||||
|
fill_and_valid_new_check
|
||||||
end
|
end
|
||||||
|
|
||||||
test "remove a notification" do
|
test "remove a notification" do
|
||||||
|
@ -83,4 +82,32 @@ class ChecksTest < ApplicationSystemTestCase
|
||||||
assert notification.email?
|
assert notification.email?
|
||||||
assert notification.pending?
|
assert notification.pending?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
# rubocop:disable Metrics/AbcSize
|
||||||
|
# rubocop:disable Metrics/MethodLength
|
||||||
|
def fill_and_valid_new_check
|
||||||
|
domain = "domain-test.fr"
|
||||||
|
fill_in("check[domain]", with: domain)
|
||||||
|
|
||||||
|
recipient = "recipient@example.org"
|
||||||
|
fill_in("check[notifications_attributes][0][recipient]", with: recipient)
|
||||||
|
fill_in("check[notifications_attributes][0][interval]", with: 30)
|
||||||
|
|
||||||
|
click_button
|
||||||
|
|
||||||
|
assert_equal checks_path, page.current_path
|
||||||
|
|
||||||
|
assert page.has_css?(".alert-success")
|
||||||
|
assert page.has_content?(domain)
|
||||||
|
|
||||||
|
notification = Notification.last
|
||||||
|
assert_equal recipient, notification.recipient
|
||||||
|
assert_equal 30, notification.interval
|
||||||
|
assert notification.email?
|
||||||
|
assert notification.pending?
|
||||||
|
end
|
||||||
|
# rubocop:enable Metrics/AbcSize
|
||||||
|
# rubocop:enable Metrics/MethodLength
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue