Skip to content

Commit

Permalink
Refactor verification controller spec
Browse files Browse the repository at this point in the history
  • Loading branch information
elct9620 committed Nov 8, 2023
1 parent 4a92177 commit 90d166c
Showing 1 changed file with 31 additions and 32 deletions.
63 changes: 31 additions & 32 deletions spec/controllers/lets_encrypt/verifications_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 90d166c

Please sign in to comment.