diff options
author | Douwe Maan <douwe@gitlab.com> | 2015-10-18 11:58:53 +0200 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2015-10-18 11:58:53 +0200 |
commit | 3b1c702572facf3aff58beb91b2c5de4903d7a83 (patch) | |
tree | 70db1e753a09c6808454350e1eff3e9e382ac1f6 /spec/controllers | |
parent | 9f6dc2a4b2e5eca01f5712bd7ec4d007ad4e57e5 (diff) | |
download | gitlab-ce-3b1c702572facf3aff58beb91b2c5de4903d7a83.tar.gz |
Fix spec.
Diffstat (limited to 'spec/controllers')
-rw-r--r-- | spec/controllers/abuse_reports_controller_spec.rb | 86 |
1 files changed, 53 insertions, 33 deletions
diff --git a/spec/controllers/abuse_reports_controller_spec.rb b/spec/controllers/abuse_reports_controller_spec.rb index 6d157406a2b..10a2cc3c3a4 100644 --- a/spec/controllers/abuse_reports_controller_spec.rb +++ b/spec/controllers/abuse_reports_controller_spec.rb @@ -9,45 +9,65 @@ describe AbuseReportsController do sign_in(reporter) end - describe "with admin notification_email set" do - let(:admin_email) { "admin@example.com"} - before(:example) { allow(current_application_settings).to receive(:admin_notification_email).and_return(admin_email) } - - it "sends a notification email" do - post(:create, - abuse_report: { - user_id: user.id, - message: message - } - ) - - expect(response).to have_http_status(:redirect) - expect(flash[:notice]).to start_with("Thank you for your report") - - email = ActionMailer::Base.deliveries.last - - expect(email).to be_present - expect(email.subject).to eq("[Gitlab] Abuse report filed for `#{user.username}`") - expect(email.to).to eq([admin_email]) - expect(email.body).to include(message) - end - end + describe "POST create" do + context "with admin notification email set" do + let(:admin_email) { "admin@example.com"} - describe "without admin notification email set" do - before(:example) { allow(current_application_settings).to receive(:admin_notification_email).and_return(nil) } + before(:each) do + stub_application_setting(admin_notification_email: admin_email) + end - it "does not send a notification email" do - expect do - post(:create, + it "sends a notification email" do + post :create, abuse_report: { user_id: user.id, message: message } - ) - end.to_not change{ActionMailer::Base.deliveries} - expect(response).to have_http_status(:redirect) - expect(flash[:notice]).to start_with("Thank you for your report") + email = ActionMailer::Base.deliveries.last + + expect(email.to).to eq([admin_email]) + expect(email.subject).to include(user.username) + expect(email.text_part.body).to include(message) + end + + it "saves the abuse report" do + expect { + post :create, + abuse_report: { + user_id: user.id, + message: message + } + }.to change { AbuseReport.count }.by(1) + end + end + + context "without admin notification email set" do + before(:each) do + stub_application_setting(admin_notification_email: nil) + end + + it "does not send a notification email" do + expect { + post :create, + abuse_report: { + user_id: user.id, + message: message + } + + }.not_to change { ActionMailer::Base.deliveries.count } + end + + it "saves the abuse report" do + expect { + post :create, + abuse_report: { + user_id: user.id, + message: message + } + }.to change { AbuseReport.count }.by(1) + end end end -end
\ No newline at end of file + +end |