notify_spec.rb 2.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
require 'spec_helper'

describe Notify do
  include EmailSpec::Helpers
  include EmailSpec::Matchers

  before :all do
    default_url_options[:host] = 'example.com'
  end

  let(:example_email) { 'user@example.com' }

  describe 'new user email' do
    let(:example_password) { 'thisismypassword' }
    let(:example_site_url) { root_url }
    let(:new_user) { Factory.new(:user, :email => example_email, :password => example_password) }

    subject { Notify.new_user_email(new_user, new_user.password) }

    it 'is sent to the new user' do
      should deliver_to new_user.email
    end

    it 'has the correct subject' do
      should have_subject /Account was created for you/
    end

    it 'contains the new user\'s login name' do
      should have_body_text /#{new_user.email}/
    end

    it 'contains the new user\'s password' do
      should have_body_text /#{new_user.password}/
    end

    it 'includes a link to the site' do
      should have_body_text /#{example_site_url}/
    end
  end

  describe 'new issue email' do
    let(:project) { Factory.create(:project) }
    let(:assignee) { Factory.create(:user, :email => example_email) }
    let(:issue) { Factory.create(:issue, :assignee => assignee, :project => project ) }

    subject { Notify.new_issue_email(issue) }

    it 'is sent to the assignee' do
      should deliver_to assignee.email
    end

    it 'has the correct subject' do
      should have_subject /New Issue was created/
    end

    it 'contains a link to the new issue' do
      should have_body_text /#{project_issue_url project, issue}/
    end
  end

  describe 'note wall email' do
    let(:project) { Factory.create(:project) }
    let(:recipient) { Factory.create(:user, :email => example_email) }
    let(:author) { Factory.create(:user) }
    let(:note) { Factory.create(:note, :project => project, :author => author) }
    let(:note_url) { wall_project_url(project, :anchor => "note_#{note.id}") }

    subject { Notify.note_wall_email(recipient, note) }

    it 'is sent to the given recipient' do
      should deliver_to recipient.email
    end

    it 'has the correct subject' do
      should have_subject /#{project.name}/
    end

    it 'contains a link to the wall note' do
      should have_body_text /#{note_url}/
    end
  end
end