diff --git a/spec/controllers/user/sessions_controller_spec.rb b/spec/controllers/user/sessions_controller_spec.rb index 7e079a52..1562da36 100644 --- a/spec/controllers/user/sessions_controller_spec.rb +++ b/spec/controllers/user/sessions_controller_spec.rb @@ -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 \ No newline at end of file