From dcc40d60b228666015ac905052d226fe415a53eb Mon Sep 17 00:00:00 2001 From: Joe Ferris Date: Thu, 21 Mar 2013 11:58:11 -0400 Subject: [PATCH] Inline Class: Step One * Inline and move methods from inlined class --- example_app/app/models/invitation.rb | 3 ++- example_app/spec/models/invitation_spec.rb | 15 ++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/example_app/app/models/invitation.rb b/example_app/app/models/invitation.rb index 31d49f5..0d004ca 100644 --- a/example_app/app/models/invitation.rb +++ b/example_app/app/models/invitation.rb @@ -15,7 +15,8 @@ def to_param end def deliver - EmailInviter.new(self).deliver + body = InvitationMessage.new(self).body + Mailer.invitation_notification(self, body).deliver end private diff --git a/example_app/spec/models/invitation_spec.rb b/example_app/spec/models/invitation_spec.rb index 3797288..9b4415f 100644 --- a/example_app/spec/models/invitation_spec.rb +++ b/example_app/spec/models/invitation_spec.rb @@ -13,15 +13,20 @@ end describe Invitation, '#deliver' do + include Rails.application.routes.url_helpers + self.default_url_options = ActionMailer::Base.default_url_options + it 'sends email notifications to new users' do - inviter = stub('inviter', deliver: true) - EmailInviter.stubs(new: inviter) - invitation = build_stubbed(:invitation) + survey = create(:survey) + invitation = create(:invitation, message: 'hello', survey: survey) invitation.deliver - EmailInviter.should have_received(:new).with(invitation) - inviter.should have_received(:deliver) + message = ActionMailer::Base.deliveries.last + message.should deliver_to(invitation.recipient_email) + message.should have_body_text(invitation.sender.email) + message.should have_body_text(invitation.message) + message.should have_body_text(survey_url(survey)) end end