Flowdock

Notes posted by cyu

RSS feed
September 21, 2008 - (>= v2.1.0)
0 thanks

Test Example

UserMailerTest Example

class UserMailerTest < ActionMailer::TestCase
  tests UserMailer

  def test_welcome_mail
    user = users(:quentin)

    MyMailer.deliver_welcome_email
    assert !ActionMailer::Base.deliveries.empty?

    sent = ActionMailer::Base.deliveries.first
    assert_equal [@user.email], sent.to
    assert_equalexpected subject”, sent.subject
    assert sent.body =~ /^Welcome to my App/
    assert sent.body =~ /^Username: #{@user.login}$/
    assert sent.body =~ /^Password: [a-z0-9]{10}$/i
  end
end

This example is a modified version of the one in this blog post:

http://sablog.com/archives/2006/03/14/how-to-test-actionmailer-in-ruby-on-rails

June 27, 2008
15 thanks

Passing find() arguments

I you need to pass additional arguments to a scope (e.g. limit), do this:

Shirt.colored('red').all(:limit => 10)