diff --git a/lib/mailhandler/receiving/notification/email.rb b/lib/mailhandler/receiving/notification/email.rb index c4cd09b..65b17dc 100644 --- a/lib/mailhandler/receiving/notification/email.rb +++ b/lib/mailhandler/receiving/notification/email.rb @@ -11,17 +11,19 @@ module Notification class Email attr_reader :sender, + :from, :contacts, :min_time_to_notify, :max_time_to_notify, :current_state - def initialize(sender, contacts, min_time_to_notify = 60) + def initialize(sender, from, to, min_time_to_notify = 60) @min_time_to_notify = min_time_to_notify @sender = sender - @contacts = contacts + @from = from + @contacts = to init_state set_content_handler(EmailContent.new) @@ -44,8 +46,7 @@ def set_state(state) def send_email(type, search) verify_email_type(type) - content = @content_handler.retrieve(type, search.options, Time.now - search.started_at, - sender.dispatcher.username, contacts) + content = @content_handler.retrieve(type, search.options, Time.now - search.started_at, from, contacts) sender.send_email content end diff --git a/lib/mailhandler/version.rb b/lib/mailhandler/version.rb index 3744673..6855d9d 100644 --- a/lib/mailhandler/version.rb +++ b/lib/mailhandler/version.rb @@ -1,3 +1,3 @@ module MailHandler - VERSION = '1.0.35' + VERSION = '1.0.36' end \ No newline at end of file diff --git a/readme.md b/readme.md index 168e45e..2414f36 100644 --- a/readme.md +++ b/readme.md @@ -105,13 +105,14 @@ Console notification is a good option if you are testing email delivery and want To add console or email notifications, to your email searching all you need to do is: ``` ruby -email_receiver.add_observer(MailHandler::Receiving::Notification::Email.new(email_sender, contacts)) +email_receiver.add_observer(MailHandler::Receiving::Notification::Email.new(email_sender, from, contacts)) email_receiver.add_observer(MailHandler::Receiving::Notification::Console.new) ``` For email notifications, the parameters you need are: * `email_sender` - email sender you will use for sending an email (it should be one of senders described below) +* `from` - email address from which email is sent * `contacts` - list of contacts to receive the notification (for example: `john@example.com, igor@example.com` # Email sending diff --git a/spec/unit/mailhandler/receiving/notification/email_spec.rb b/spec/unit/mailhandler/receiving/notification/email_spec.rb index 9c500f6..5387af9 100644 --- a/spec/unit/mailhandler/receiving/notification/email_spec.rb +++ b/spec/unit/mailhandler/receiving/notification/email_spec.rb @@ -4,74 +4,60 @@ let(:search) { double('search') } let(:sender) { double('sender') } - let(:notification) { MailHandler::Receiving::Notification::Email.new(sender, 'igor@example.com',1) } + let(:notification) { MailHandler::Receiving::Notification::Email.new(sender, 'from@example.com', 'igor@example.com',1) } before(:each) do - allow(sender).to receive(:send_email) { true } allow(search).to receive(:max_duration) { 5 } - end it '.create' do aggregate_failures "init details" do - expect(notification.min_time_to_notify).to eq 1 expect(notification.max_time_to_notify).to eq nil expect(notification.contacts).to eq 'igor@example.com' expect(notification.sender).to eq sender - end end it '.notify' do - allow(search).to receive(:started_at) { Time.now } notification.notify(search) expect(notification.max_time_to_notify).to eq search.max_duration - end context 'states' do it 'no delay' do - allow(search).to receive(:started_at) { Time.now } notification.notify(search) expect(notification.current_state).to be_kind_of MailHandler::Receiving::Notification::NoDelay - end it 'delayed' do - allow(search).to receive(:started_at) { Time.now - 2} allow(search).to receive(:result) { false } allow(notification).to receive(:send_email) { } notification.notify(search) expect(notification.current_state).to be_kind_of MailHandler::Receiving::Notification::Delay - end it 'received' do - allow(search).to receive(:started_at) { Time.now - 2} allow(search).to receive(:result) { true } allow(notification).to receive(:send_email) { } notification.notify(search) expect(notification.current_state).to be_kind_of MailHandler::Receiving::Notification::Received - end it 'max delayed' do - allow(search).to receive(:started_at) { Time.now - 10} allow(search).to receive(:result) { false } allow(notification).to receive(:send_email) { } notification.notify(search) expect(notification.current_state).to be_kind_of MailHandler::Receiving::Notification::MaxDelay - end end