Skip to content

Commit

Permalink
Refactor letsencrypt configutation spec
Browse files Browse the repository at this point in the history
  • Loading branch information
elct9620 committed Nov 8, 2023
1 parent e54f17e commit 59f97b3
Showing 1 changed file with 11 additions and 30 deletions.
41 changes: 11 additions & 30 deletions spec/letsencrypt/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,24 @@
require 'rails_helper'

RSpec.describe LetsEncrypt::Configuration do
subject(:config) { LetsEncrypt::Configuration.new }

describe '#use_redis?' do
it 'reture is user enable save to redis value' do
subject.save_to_redis = true
expect(subject.use_redis?).to be_truthy
end
before { config.save_to_redis = true }

it { is_expected.to be_use_redis }
end

describe '#use_staging?' do
it 'return same value as #use_staging config attribute' do
subject.use_staging = true
expect(subject.use_staging?).to eq(subject.use_staging)
end
before { config.use_staging = true }

it { is_expected.to be_use_staging }
end

describe 'customize certificate model' do
before(:each) do
stub_const('OtherModel', Class.new(LetsEncrypt::Certificate))

OtherModel.after_update :success
OtherModel.class_eval do
def success
'success'
end
end

LetsEncrypt.config.certificate_model = 'OtherModel'
allow(LetsEncrypt).to receive(:certificate_model).and_return(OtherModel)
LetsEncrypt.certificate_model.create(
domain: 'example.com',
verification_path: '.well-known/acme-challenge/valid_path',
verification_string: 'verification'
)
end
before(:each) { config.certificate_model = 'OtherModel' }
after { LetsEncrypt.config.certificate_model = 'LetsEncrypt::Certificate' }
it 'update data' do
expect_any_instance_of(OtherModel).to receive(:success)
LetsEncrypt.certificate_model.first.update(renew_after: 3.days.ago)
end

it { is_expected.to have_attributes(certificate_model: 'OtherModel') }
end
end

0 comments on commit 59f97b3

Please sign in to comment.