27.02.2013 Views

Rails%203%20In%20Action

Rails%203%20In%20Action

Rails%203%20In%20Action

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

324 CHAPTER 12 Sending email<br />

message itself. For your multipart emails, the text and HTML versions will be split into<br />

two separate parts.<br />

Defining a HTML version of your email is very easy. All you have to do is create<br />

another file that begins with comment_updated inside of app/views/notifier, and Action<br />

Mailer will automatically detect that you have a multipart message. If you use the html<br />

format in your template’s filename, Action Mailer will do some more automatic detection<br />

and work out that the parsed content of this file should be sent as text/html.<br />

Inside of this new file you want to put the content from the following listing.<br />

Listing 12.4 app/views/notifier/comment_updated.html.erb<br />

<br />

<br />

Hello.<br />

<br />

<br />

has just updated the<br />

ticket for<br />

. They wrote:<br />

<br />

<br />

You can <br />

<br />

Now that you have an HTML template, Action Mailer will send a multipart email containing<br />

both the HTML and text version of the mail without having to configure anything,<br />

which is always nice!<br />

When you run bin/cucumber features/ticket_notifications.feature, you see<br />

that the feature fails:<br />

Then they click the first link in the email<br />

No route matches [GET] "/images/logo.png'" ...<br />

This is because the scenario is attempting to click the first link it comes across, which<br />

is the link to the image at the top of the HTML version of your email. What you really<br />

want it to do is to click the View This Ticket Online Here link, and you can make it do<br />

just that by replacing this line in the scenario<br />

Then they click the first link in the email<br />

with this one:<br />

Then they follow "view this ticket online here" in the email<br />

This will now make the scenario click the correct link. Let’s re-run bin/cucumber<br />

features/ticket_notifications.feature to see that this feature is now passing:<br />

1 scenario (1 passed)<br />

21 steps (21 passed)

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!