add tests for Organization mailer

This commit is contained in:
Patri
2015-03-29 21:24:15 +02:00
parent 929ca89863
commit fbf2066e11

View File

@ -0,0 +1,61 @@
require "spec_helper"
describe OrganizationNotifier do
let (:test_organization) { Fabricate(:organization) }
let! (:offer) { Fabricate(:offer, organization: test_organization) }
let! (:inquiry) { Fabricate(:inquiry, organization: test_organization) }
let (:user) do
Fabricate(:user, sign_in_count: 2, active: true, email: "user@example.com")
end
let (:another_user) { Fabricate(:user, sign_in_count: 1) }
let (:yet_another_user) { Fabricate(:user, sign_in_count: 0) }
let! (:member) do
Fabricate(:member,
organization: test_organization,
user: user,
active: true)
end
let! (:another_member) do
Fabricate(:member,
organization: test_organization,
user: another_user,
active: false)
end
let! (:yet_another_member) do
Fabricate(:member,
organization: test_organization,
user: yet_another_user,
active: true)
end
before(:each) do
ActionMailer::Base.delivery_method = :test
ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.deliveries = []
OrganizationNotifier.recent_posts(test_organization.posts).deliver
end
after(:each) do
ActionMailer::Base.deliveries.clear
end
describe "send an email" do
it "should send an email" do
ActionMailer::Base.deliveries.count.should == 1
end
end
describe "recent post" do
let(:mail) { OrganizationNotifier.recent_posts(test_organization.posts) }
it "receive email only active and online users" do
expect(mail.bcc).to eql(["user@example.com"])
end
it "to should be null" do
expect(mail.to).to be_nil
end
it "assigns @organization_name" do
expect(mail.body.encoded).to match(test_organization.name)
end
end
end