Skip to content

Commit

Permalink
Inline Class: Step One
Browse files Browse the repository at this point in the history
* Inline and move methods from inlined class
  • Loading branch information
jferris committed Mar 21, 2013
1 parent 6b5273d commit dcc40d6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
3 changes: 2 additions & 1 deletion example_app/app/models/invitation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 10 additions & 5 deletions example_app/spec/models/invitation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit dcc40d6

Please sign in to comment.