|
1 | 1 | require "spec_helper" |
2 | 2 |
|
3 | 3 | RSpec.describe OrganizationNotifier do |
4 | | - let (:test_organization) { Fabricate(:organization) } |
5 | | - let! (:offer) { Fabricate(:offer, organization: test_organization) } |
6 | | - let! (:inquiry) { Fabricate(:inquiry, organization: test_organization) } |
7 | | - let (:user) do |
8 | | - Fabricate(:user, sign_in_count: 2, email: "[email protected]") |
9 | | - end |
10 | | - let (:another_user) { Fabricate(:user, sign_in_count: 1) } |
11 | | - let (:yet_another_user) { Fabricate(:user, sign_in_count: 0) } |
12 | | - let! (:member) do |
13 | | - Fabricate(:member, |
14 | | - organization: test_organization, |
15 | | - user: user, |
16 | | - active: true) |
17 | | - end |
18 | | - let! (:another_member) do |
19 | | - Fabricate(:member, |
20 | | - organization: test_organization, |
21 | | - user: another_user, |
22 | | - active: false) |
23 | | - end |
24 | | - let! (:yet_another_member) do |
25 | | - Fabricate(:member, |
26 | | - organization: test_organization, |
27 | | - user: yet_another_user, |
28 | | - active: true) |
29 | | - end |
30 | | - |
31 | | - before(:each) do |
32 | | - ActionMailer::Base.delivery_method = :test |
33 | | - ActionMailer::Base.perform_deliveries = true |
34 | | - ActionMailer::Base.deliveries = [] |
35 | | - OrganizationNotifier.recent_posts(test_organization.posts).deliver_now |
36 | | - end |
37 | | - |
38 | | - after(:each) do |
39 | | - ActionMailer::Base.deliveries.clear |
40 | | - end |
| 4 | + let(:test_organization) { Fabricate(:organization) } |
| 5 | + let!(:offer) { Fabricate(:offer, organization: test_organization) } |
| 6 | + let!(:inquiry) { Fabricate(:inquiry, organization: test_organization) } |
| 7 | + let(:user) { Fabricate(:user, email: "[email protected]", locale: :en) } |
| 8 | + let(:member) { Fabricate(:member, organization: test_organization, user: user) } |
41 | 9 |
|
42 | 10 | describe "send an email" do |
43 | 11 | it "should send an email" do |
44 | | - expect(ActionMailer::Base.deliveries.count).to eq(1) |
| 12 | + expect { |
| 13 | + OrganizationNotifier.recent_posts(test_organization.posts, :en, [user]).deliver_now |
| 14 | + }.to change { ActionMailer::Base.deliveries.count }.by(1) |
45 | 15 | end |
46 | 16 | end |
47 | 17 |
|
48 | 18 | describe "recent posts" do |
49 | | - let(:mail) { OrganizationNotifier.recent_posts(test_organization.posts) } |
| 19 | + let(:mail) { OrganizationNotifier.recent_posts(test_organization.posts, :en, [user]) } |
50 | 20 |
|
51 | 21 | it "receive email only active and online users" do |
52 | 22 | expect(mail.bcc).to eql(["[email protected]"]) |
53 | 23 | end |
54 | 24 | it "to should be null" do |
55 | 25 | expect(mail.to).to be_nil |
56 | 26 | end |
57 | | - it "assigns @organization_name" do |
| 27 | + it "body contains organization name" do |
58 | 28 | expect(mail.body.encoded).to match(test_organization.name) |
59 | 29 | end |
60 | 30 | end |
|
0 commit comments