require "spec_helper" describe Notifier, type: :mailer do let(:person) { FactoryGirl.create(:person) } before do Notifier.deliveries = [] end describe ".administrative" do it "mails a user" do mails = Notifier.admin("Welcome to bureaucracy!", [bob]) expect(mails.length).to eq(1) mail = mails.first expect(mail.to).to eq([bob.email]) expect(mail.body.encoded).to match /Welcome to bureaucracy!/ expect(mail.body.encoded).to match /#{bob.username}/ end context "mails a bunch of users" do before do @users = [] 5.times do @users << FactoryGirl.create(:user) end end it "has a body" do mails = Notifier.admin("Welcome to bureaucracy!", @users) expect(mails.length).to eq(5) mails.each {|mail| this_user = @users.find {|u| mail.to == [u.email] } expect(mail.body.encoded).to match /Welcome to bureaucracy!/ expect(mail.body.encoded).to 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"}]) expect(mails.length).to eq(5) mails.each {|mail| expect(mail.attachments.count).to eq(1) } end end end describe ".single_admin" do it "mails a user" do mail = Notifier.single_admin("Welcome to bureaucracy!", bob) expect(mail.to).to eq([bob.email]) expect(mail.body.encoded).to match /Welcome to bureaucracy!/ expect(mail.body.encoded).to match /#{bob.username}/ end it "has the layout" do mail = Notifier.single_admin("Welcome to bureaucracy!", bob) expect(mail.body.encoded).to 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"}]) expect(mail.attachments.length).to eq(1) end end describe ".started_sharing" do let!(:request_mail) { Notifier.started_sharing(bob.id, person.id) } it "goes to the right person" do expect(request_mail.to).to eq([bob.email]) end it "has the name of person sending the request" do expect(request_mail.body.encoded.include?(person.name)).to be true end it "has the css" do request_mail.body.encoded.include?("