From 90d166cbafde765ffeb3d7e46ac3531c1a56ebd9 Mon Sep 17 00:00:00 2001 From: Aotokitsuruya Date: Wed, 8 Nov 2023 19:48:30 +0800 Subject: [PATCH] Refactor verification controller spec --- .../verifications_controller_spec.rb | 63 +++++++++---------- 1 file changed, 31 insertions(+), 32 deletions(-) diff --git a/spec/controllers/lets_encrypt/verifications_controller_spec.rb b/spec/controllers/lets_encrypt/verifications_controller_spec.rb index dcb1569..cbc1e03 100644 --- a/spec/controllers/lets_encrypt/verifications_controller_spec.rb +++ b/spec/controllers/lets_encrypt/verifications_controller_spec.rb @@ -5,46 +5,45 @@ RSpec.describe LetsEncrypt::VerificationsController, type: :controller do routes { LetsEncrypt::Engine.routes } + subject { get :show, params: { verification_path: verification_path } } + let(:verification_path) { :invalid_path } + before do stub_const('LetsEncrypt::Certificate', Class.new(LetsEncrypt::Certificate)) end - it 'returns 404 status when no valid verification path found' do - get :show, params: { verification_path: :invalid_path } - expect(response.status).to eq(404) + describe 'with invalid path' do + it { is_expected.to be_not_found } end - describe 'has certificate' do - context 'with default model' do - let!(:certificate) do - LetsEncrypt.certificate_model.create( - domain: 'example.com', - verification_path: '.well-known/acme-challenge/valid_path', - verification_string: 'verification' - ) - end - it 'returns verification string when found verification path' do - get :show, params: { verification_path: 'valid_path' } - expect(response.status).to eq(200) - expect(response.body).to eq(certificate.verification_string) - end + describe 'with default model' do + let!(:certificate) do + LetsEncrypt.certificate_model.create( + domain: 'example.com', + verification_path: '.well-known/acme-challenge/valid_path', + verification_string: 'verification' + ) end + let(:verification_path) { 'valid_path' } + + it { is_expected.to be_ok } + it { is_expected.to have_attributes(body: certificate.verification_string) } + end - context 'with customize model' do - before { LetsEncrypt.config.certificate_model = 'OtherModel' } - let!(:certificate) do - LetsEncrypt.certificate_model.create( - domain: 'example.com', - verification_path: '.well-known/acme-challenge/valid_path', - verification_string: 'verification' - ) - end - after { LetsEncrypt.config.certificate_model = 'LetsEncrypt::Certificate' } - it 'returns verification string when found verification path' do - get :show, params: { verification_path: 'valid_path' } - expect(response.status).to eq(200) - expect(response.body).to eq(certificate.verification_string) - end + describe 'with customize model' do + let!(:certificate) do + LetsEncrypt.certificate_model.create( + domain: 'example.com', + verification_path: '.well-known/acme-challenge/valid_path', + verification_string: 'verification' + ) end + let(:verification_path) { 'valid_path' } + + before { LetsEncrypt.config.certificate_model = 'OtherModel' } + after { LetsEncrypt.config.certificate_model = 'LetsEncrypt::Certificate' } + + it { is_expected.to be_ok } + it { is_expected.to have_attributes(body: certificate.verification_string) } end end