diff --git a/admin/cert_watch/certificates.rb b/admin/cert_watch/certificates.rb index f97ce0d..6115675 100644 --- a/admin/cert_watch/certificates.rb +++ b/admin/cert_watch/certificates.rb @@ -1,7 +1,7 @@ require 'cert_watch/views/all' module CertWatch - ActiveAdmin.register Certificate do + ActiveAdmin.register Certificate, as: 'Certificate' do menu priority: 100 actions :index, :new, :create, :show, :edit, :update @@ -10,7 +10,7 @@ module CertWatch index do column :domain do |certificate| - link_to(certificate.domain, admin_cert_watch_certificate_path(certificate)) + link_to(certificate.domain, admin_certificate_path(certificate)) end column :state do |certificate| cert_watch_certificate_state(certificate) @@ -41,10 +41,10 @@ module CertWatch f.actions end - action_item(only: :show) do + action_item(:renew, only: :show) do if resource.can_renew? button_to(I18n.t('cert_watch.admin.certificates.renew'), - renew_admin_cert_watch_certificate_path(resource), + renew_admin_certificate_path(resource), method: :post, data: { rel: 'renew', @@ -53,10 +53,10 @@ module CertWatch end end - action_item(only: :show) do + action_item(:install, only: :show) do if resource.can_install? button_to(I18n.t('cert_watch.admin.certificates.install'), - install_admin_cert_watch_certificate_path(resource), + install_admin_certificate_path(resource), method: :post, data: { rel: 'install', @@ -68,13 +68,13 @@ module CertWatch member_action :renew, method: :post do resource = Certificate.find(params[:id]) resource.renew - redirect_to(admin_cert_watch_certificate_path(resource)) + redirect_to(admin_certificate_path(resource)) end member_action :install, method: :post do resource = Certificate.find(params[:id]) resource.install - redirect_to(admin_cert_watch_certificate_path(resource)) + redirect_to(admin_certificate_path(resource)) end show title: :domain do |certificate| diff --git a/spec/controllers/admin/cert_watch/certificates_controller_spec.rb b/spec/controllers/admin/cert_watch/certificates_controller_spec.rb index 1f1e8ac..3573cbf 100644 --- a/spec/controllers/admin/cert_watch/certificates_controller_spec.rb +++ b/spec/controllers/admin/cert_watch/certificates_controller_spec.rb @@ -1,7 +1,60 @@ require 'rails_helper' module Admin - RSpec.describe CertWatchCertificatesController, type: :controller do + RSpec.describe CertificatesController, type: :controller do + describe '#index' do + render_views + + it 'renders table with certificate domains' do + create(:certificate, :custom, domain: 'some-custom.example.com') + create(:certificate, :auto_renewable) + + get(:index) + + expect(response.body).to have_selector('td a', text: 'some-custom.example.com') + end + end + + describe '#show' do + render_views + + it 'displays renew button for auto renewable certificate' do + certificate = create(:certificate, :auto_renewable) + + get(:show, id: certificate) + + expect(response.body).to have_selector('[data-rel=renew]') + end + + it 'displays install button for complete certificate' do + certificate = create(:certificate, :custom, :complete) + + get(:show, id: certificate) + + expect(response.body).to have_selector('[data-rel=install]') + end + end + + describe '#renew' do + it 'renews certificate' do + certificate = create(:certificate, :auto_renewable) + + post(:renew, id: certificate) + + expect(certificate.reload.state).to eq('renewing') + end + end + + describe '#install' do + it 'installs certificate' do + certificate = create(:certificate, :complete, :auto_renewable) + + post(:install, id: certificate) + + expect(certificate.reload.state).to eq('installing') + end + end + describe '#create' do it 'creates custom certificate' do post(:create, certificate: {