require 'spec_helper' describe Notifier do include ActionView::Helpers::TextHelper let(:person) { Factory(:person) } before do Notifier.deliveries = [] end describe '.administrative' do it 'mails a user' do mails = Notifier.admin("Welcome to bureaucracy!", [bob]) mails.length.should == 1 mail = mails.first mail.to.should == [bob.email] mail.body.encoded.should match /Welcome to bureaucracy!/ mail.body.encoded.should match /#{bob.username}/ end it 'mails a bunch of users' do users = [] 5.times do users << Factory.create(:user) end mails = Notifier.admin("Welcome to bureaucracy!", users) mails.length.should == 5 mails.each{|mail| this_user = users.detect{|u| mail.to == [u.email]} mail.body.encoded.should match /Welcome to bureaucracy!/ mail.body.encoded.should match /#{this_user.username}/ } end end describe '.single_admin' do it 'mails a user' do mail = Notifier.single_admin("Welcome to bureaucracy!", bob) mail.to.should == [bob.email] mail.body.encoded.should match /Welcome to bureaucracy!/ mail.body.encoded.should match /#{bob.username}/ end it 'has the layout' do mail = Notifier.single_admin("Welcome to bureaucracy!", bob) mail.body.encoded.should match /change your notification settings/ end end describe ".started_sharing" do let!(:request_mail) {Notifier.started_sharing(bob.id, person.id)} it 'goes to the right person' do request_mail.to.should == [bob.email] end it 'has the name of person sending the request' do request_mail.body.encoded.include?(person.name).should be true end it 'has the css' do request_mail.body.encoded.include?("