Add test for logging in while banned

This commit is contained in:
Karina Kwiatek 2022-06-26 11:00:29 +02:00 committed by Karina Kwiatek
parent 94aec26588
commit 7330d50023
1 changed files with 29 additions and 1 deletions

View File

@ -1,4 +1,6 @@
require 'rails_helper'
# frozen_string_literal: true
require "rails_helper"
describe User::SessionsController do
before do
@ -72,5 +74,31 @@ describe User::SessionsController do
end
end
end
context "permanently banned user sign in attempt" do
before do
user.ban(nil, "Do not feed the animals")
end
it "redirects to the sign in page" do
expect(subject).to redirect_to :new_user_session
expect(flash[:notice]).to eq "#{I18n.t('flash.ban.error', name: user.screen_name)}\n#{I18n.t('flash.ban.reason', reason: 'Do not feed the animals')}"
end
end
context "temporarily banned user sign in attempt" do
let(:expiry) { DateTime.now.utc + 3.hours }
before do
user.ban(expiry, "Do not feed the animals")
end
it "redirects to the sign in page" do
expect(subject).to redirect_to :new_user_session
expect(flash[:notice]).to eq I18n.t("flash.ban.error", name: user.screen_name) +
"\n#{I18n.t('flash.ban.reason', reason: 'Do not feed the animals')}" \
"\n#{I18n.t('flash.ban.until', time: expiry)}"
end
end
end
end