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 context 'mails a bunch of users' do before do @users = [] 5.times do @users << Factory(:user) end end it 'has a body' do 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 it "has attachments" do mails = Notifier.admin("Welcome to bureaucracy!", @users, :attachments => [{:name => "retention stats", :file => "here is some file content"}]) mails.length.should == 5 mails.each{|mail| mail.attachments.count.should == 1 } end 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 it 'has an optional attachment' do mail = Notifier.single_admin("Welcome to bureaucracy!", bob, :attachments => [{:name => "retention stats", :file => "here is some file content"}]) mail.attachments.length.should == 1 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?("