Permalink
Browse files

Inline Class: Step One

* Inline and move methods from inlined class
  • Loading branch information...
jferris committed Mar 21, 2013
1 parent 6b5273d commit dcc40d60b228666015ac905052d226fe415a53eb
Showing with 12 additions and 6 deletions.
  1. +2 −1 example_app/app/models/invitation.rb
  2. +10 −5 example_app/spec/models/invitation_spec.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
@@ -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

0 comments on commit dcc40d6

Please sign in to comment.