Showing posts with label templates. Show all posts
Showing posts with label templates. Show all posts

20140330

mail_view for human — and also for automatic — testing

I've come to use a nice gem called mail_view for visual testing of email templates in Rails.
I think it is totally legit and desirable to re-use that code in the views testing suite, so here we go:
(provided that your MailView's subclass is MailPreview, put this in ./spec/views/mail_spec.rb)

This just checks for the lack of exceptions and any content, but it's a starting point.

p.s. A nice complementary pull request of mine is here.

20110326

a jQuery templates tip: checking for optional fields

One tip regarding the templates

“Comments for this page are closed.” for some reason, so here:
When rendering an optional numerical field, the safest way to check on its existence is:
{{if typeof $item.data.optional_field == "number"}}...{{/if}}
(for other types, change the right side of the == accordingly)

The main problem with the way described in the doc is possible accidental name collision of the field's name with some other variable in the scope.