|
1 | 1 | require 'spec_helper' |
2 | 2 |
|
3 | 3 | describe MailerController do |
4 | | - describe "GET 'new'" do |
| 4 | + let(:user) { Fabricate(:user) } |
| 5 | + let(:users) { Fabricate.sequence(:user, 5)} |
| 6 | + |
| 7 | + describe "GET 'new' for a single user email" do |
5 | 8 | it "returns http success" do |
6 | | - get 'new' |
| 9 | + get 'new', user: Array(user) |
7 | 10 | response.should be_success |
8 | 11 | end |
9 | 12 | end |
| 13 | + |
| 14 | + describe "GET 'new' for a diffusion" do |
| 15 | + it "returns http success" do |
| 16 | + get 'new', user: Array(users) |
| 17 | + response.should be_success |
| 18 | + end |
| 19 | + end |
| 20 | + |
| 21 | + describe "POST 'create' for a single user email" do |
| 22 | + it "returns http success" do |
| 23 | + @message = Fabricate.build(:message) |
| 24 | + post 'create', message: @message |
| 25 | + response.should be_success |
| 26 | + #We expect after send a message that the deliveries raise one |
| 27 | + expect { MessageMailer.new_message(@message, @message.email).deliver }.to change { ActionMailer::Base.deliveries.size }.by(1) |
| 28 | + end |
| 29 | + end |
| 30 | + |
| 31 | + describe "POST 'create' for a diffusion" do |
| 32 | + it "returns http success" do |
| 33 | + @diffusion = Fabricate.build(:diffusion) |
| 34 | + post 'create', message: @diffusion |
| 35 | + response.should be_success |
| 36 | + |
| 37 | + @before_send = ActionMailer::Base.deliveries.size |
| 38 | + @diffusion.email.each do |email| |
| 39 | + MessageMailer.new_message(@diffusion, email).deliver |
| 40 | + end |
| 41 | + ActionMailer::Base.deliveries.size.should eq @before_send + @diffusion.email.size |
| 42 | + end |
| 43 | + end |
10 | 44 | end |
0 commit comments