Testing Mailers with RSpec

Standard

Important Gems:

1)E-mail Spec

2)Shoulda

3)Shoulda Matchers

Example:

email = UserMailer.create_signup("jojo@yahoo.com", "Jojo Binks")
email.should reply_to("support@myapp.com")

Sending e-mails successfully

it "Should send e-mails successfully" do
        lambda { RegistrationMailer.register(@clients) }.should_not raise_error
 end
it "Should send e-mail to alll admins" do
        admin_emails = Array.new
        @produts.each do |produt|
          produt.company.adminis.each do |admin|
            admins_emails << admin.email
          end
        end
        
        lambda { SalesMailer.send_all(@products).should deliver_to(admins_emails) }
      end
Advertisements

Generating CPFs + Factory Girl

Standard

If you want to make a Factory and in your factory you have a Brazillian CPF number, you can do this:

1)Use the gem CPF Faker

2) Using

require 'cpf_faker'

FactoryGirl.define do
   factory :user do
        cpf {Faker::CPF.numeric}
        sequence(:nome) {|n| "Nome_#{n}"}
        sequence(:email) {|n| "Nome_#{n}@email.com"}
        sequence(:password) {|n| "senha_#{n}"}
        association(:empresa)
    end
end