diff --git a/CHANGELOG.markdown b/CHANGELOG.markdown index 5d27c49..991f42e 100644 --- a/CHANGELOG.markdown +++ b/CHANGELOG.markdown @@ -1,3 +1,7 @@ +#### Unreleased +* ActionMailerCheck: Support :sendmail and :test + > awilfox: https://github.com/emmahsax/okcomputer/pull/21 + #### v1.19.1 * Add rspec for higher versions of Ruby and Rails > emmahsax: https://github.com/emmahsax/okcomputer/pull/19 diff --git a/lib/ok_computer/built_in_checks/action_mailer_check.rb b/lib/ok_computer/built_in_checks/action_mailer_check.rb index 024db9f..860f24a 100644 --- a/lib/ok_computer/built_in_checks/action_mailer_check.rb +++ b/lib/ok_computer/built_in_checks/action_mailer_check.rb @@ -14,11 +14,26 @@ def initialize(klass = ActionMailer::Base, timeout = 5) # Public: Return the status of the check def check - tcp_socket_request - mark_message "#{klass} check to #{host}:#{port} successful" - rescue => e - mark_message "#{klass} at #{host}:#{port} is not accepting connections: '#{e}'" - mark_failure + case klass.delivery_method + when :smtp + begin + tcp_socket_request + mark_message "#{klass} check to #{host}:#{port} successful" + rescue => e + mark_message "#{klass} at #{host}:#{port} is not accepting connections: '#{e}'" + mark_failure + end + when :sendmail + location = klass.sendmail_settings[:location] + if File.executable?(location) + mark_message "#{klass} sendmail executable #{location} can be executed" + else + mark_message "#{klass} sendmail executable #{location} is not executable" + mark_failure + end + when :test + mark_message "#{klass} is in test mode" + end end end end diff --git a/spec/ok_computer/built_in_checks/action_mailer_check_spec.rb b/spec/ok_computer/built_in_checks/action_mailer_check_spec.rb index e66f23a..80cc544 100644 --- a/spec/ok_computer/built_in_checks/action_mailer_check_spec.rb +++ b/spec/ok_computer/built_in_checks/action_mailer_check_spec.rb @@ -54,6 +54,7 @@ class ActionMailerSubclass < ActionMailer::Base describe '#check' do context "when mailer is accepting connections" do before do + ActionMailer::Base.delivery_method = :smtp ActionMailer::Base.smtp_settings[:address] = 'localhost' ActionMailer::Base.smtp_settings[:port] = 25 expect(TCPSocket).to receive(:new).with('localhost', 25).and_return(double(:socket, :close => true)) @@ -64,6 +65,7 @@ class ActionMailerSubclass < ActionMailer::Base end context "when mailer does not accept connection" do + before { ActionMailer::Base.delivery_method = :smtp } let(:amcheck) { described_class.new(ActionMailerSubclass) } it 'is not successful' do expect(amcheck).to receive(:tcp_socket_request).and_raise(Errno::ECONNREFUSED) @@ -74,6 +76,35 @@ class ActionMailerSubclass < ActionMailer::Base expect(amcheck).to have_message "OkComputer::ActionMailerSubclass at mail.example.com:666 is not accepting connections: 'Connection refused'" end end + + context "when mailer is in sendmail mode" do + before do + ActionMailer::Base.delivery_method = :sendmail + ActionMailer::Base.sendmail_settings[:location] = '/usr/sbin/sendmail' + expect(File).to receive(:executable?).with('/usr/sbin/sendmail').and_return(true) + end + + it { is_expected.to be_successful_check } + it { is_expected.to have_message "ActionMailer::Base sendmail executable /usr/sbin/sendmail can be executed" } + end + + context "when sendmail is not installed" do + before do + ActionMailer::Base.delivery_method = :sendmail + ActionMailer::Base.sendmail_settings[:location] = '/usr/sbin/sendmail' + expect(File).to receive(:executable?).with('/usr/sbin/sendmail').and_return(false) + end + + it { is_expected.not_to be_successful_check } + it { is_expected.to have_message "ActionMailer::Base sendmail executable /usr/sbin/sendmail is not executable" } + end + + context "when mailer is in test mode" do + before { ActionMailer::Base.delivery_method = :test } + + it { is_expected.to be_successful_check } + it { is_expected.to have_message "ActionMailer::Base is in test mode" } + end end end end