Skip to content

Commit

Permalink
Make mail storage compatible with Rails 3
Browse files Browse the repository at this point in the history
  • Loading branch information
bjorntrondsen committed Aug 29, 2017
1 parent 551c138 commit ea431d5
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 6 deletions.
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
source "http://rubygems.org"
ruby File.read(".ruby-version").strip
#ruby '1.9.3', :patchlevel => "125"

group :test, :development do

#gem "rails", '3.0.20'
#gem "rack-test", '0.5.7'
#gem 'mongoid'
#gem 'bson_ext'
#gem 'nokogiri', '1.6.8.1'

#gem "rails", '3.2.22.5'
#gem "rack-test", '0.6.2'
#gem 'mongoid'
#gem 'nokogiri', '1.6.8.1'

#gem "rails", '4.0.13'
#gem "rack-test", '0.6.3'
Expand Down
8 changes: 7 additions & 1 deletion lib/rails_exception_handler/storage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@ def self.remote_url(target, info)

# Notify application admin that an error occured
def self.email(recipients,info)
RailsExceptionHandler::ErrorMailer.send_error_mail_to_admin(info.to_json,recipients).deliver_later unless recipients.blank?
return if recipients.blank?
if Rails::VERSION::MAJOR == 3 || (Rails::VERSION::MAJOR == 4 && Rails::VERSION::MINOR < 2)
delivery_method = :deliver
else
delivery_method = :deliver_later
end
RailsExceptionHandler::ErrorMailer.send_error_mail_to_admin(info.to_json,recipients).send(delivery_method)
end

private
Expand Down
Binary file modified spec/db/test.sqlite3
Binary file not shown.
3 changes: 3 additions & 0 deletions spec/dummy_30/app/mailers/application_mailer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class ApplicationMailer < ActionMailer::Base
default from: 'from@example.com'
end
3 changes: 3 additions & 0 deletions spec/dummy_32/app/mailers/application_mailer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class ApplicationMailer < ActionMailer::Base
default from: 'from@example.com'
end
3 changes: 3 additions & 0 deletions spec/dummy_40/app/mailers/application_mailer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class ApplicationMailer < ActionMailer::Base
default from: 'from@example.com'
end
3 changes: 3 additions & 0 deletions spec/dummy_42/app/mailers/application_mailer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class ApplicationMailer < ActionMailer::Base
default from: 'from@example.com'
end
10 changes: 5 additions & 5 deletions spec/integration/storage_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@
RailsExceptionHandler.configure { |config| config.storage_strategies = [] }
@handler.handle_exception
if Rails::VERSION::MAJOR > 4
read_test_log.should == " Rendering html template within layouts/application\n\\n Rendered html template within layouts/application (0.0ms)\n\\n"
read_test_log.should match /Rendering html template within layouts\/application/
elsif Rails::VERSION::MAJOR == 4 && Rails::VERSION::MINOR > 0
read_test_log.should == " Rendered text template within layouts/fallback (0.0ms)\n\\n"
read_test_log.should match /Rendered text template within layouts\/fallback/
elsif Rails::VERSION::MAJOR == 4 && Rails::VERSION::MINOR == 0
read_test_log.should == " Rendered text template within layouts/application (0.0ms)\n\\n"
read_test_log.should match /Rendered text template within layouts\/application/
else
read_test_log.should == ''
end
Expand Down Expand Up @@ -127,11 +127,11 @@
text_body = email.body.parts.first.to_s
text_body.should include('TARGET_URL')
text_body.should include('http://example.org/home?foo=bar')
text_body.should include("undefined method `foo' for nil:NilClass")
text_body.should include("undefined method `foo")
html_body = email.body.parts.last.to_s
html_body.should include('TARGET_URL')
html_body.should include('http://example.org/home?foo=bar')
html_body.should include("undefined method `foo&#39; for nil:NilClass")
html_body.should include("undefined method `foo")
end

it "should not send the error_message as an email when :email is not included" do
Expand Down

0 comments on commit ea431d5

Please sign in to comment.