Add tests for toggling unmask

This commit is contained in:
Karina Kwiatek 2022-06-24 22:50:05 +02:00 committed by Andreas Nedbal
parent 93f8bf35d2
commit a9cfa3fccc
4 changed files with 45 additions and 0 deletions

View File

@ -95,6 +95,7 @@ group :development, :test do
gem "rspec-sidekiq", "~> 3.0", require: false
gem "rubocop", "~> 1.22", ">= 1.22.1"
gem "rubocop-rails", "~> 2.13", ">= 2.13.1"
gem "shoulda-matchers", "~> 5.0"
gem "simplecov", require: false
gem "simplecov-cobertura", require: false
gem "simplecov-json", require: false

View File

@ -515,6 +515,8 @@ GEM
sentry-ruby-core (~> 5.2.1)
sidekiq (>= 3.0)
shellany (0.0.1)
shoulda-matchers (5.1.0)
activesupport (>= 5.2.0)
sidekiq (5.2.10)
connection_pool (~> 2.2, >= 2.2.2)
rack (~> 2.0)
@ -659,6 +661,7 @@ DEPENDENCIES
sentry-rails
sentry-ruby
sentry-sidekiq
shoulda-matchers (~> 5.0)
sidekiq (< 6)
simplecov
simplecov-cobertura

View File

@ -0,0 +1,34 @@
# frozen_string_literal: true
require "rails_helper"
describe ModerationController, type: :controller do
describe "#toggle_unmask" do
let(:user) { FactoryBot.create(:user, roles: [:moderator]) }
before do
sign_in(user)
post :toggle_unmask, session: { moderation_view: moderation_view }
end
context "when moderation view flag is true" do
let(:moderation_view) { true }
it { is_expected.to set_session[:moderation_view].to(false) }
it { is_expected.to redirect_to(root_path) }
end
context "when moderation view flag is false" do
let(:moderation_view) { false }
it { is_expected.to set_session[:moderation_view].to(true) }
end
context "when moderation view flag is not set" do
let(:moderation_view) { nil }
it { is_expected.to set_session[:moderation_view].to(true) }
end
end
end

View File

@ -80,4 +80,11 @@ RSpec.configure do |config|
config.include Devise::Test::ControllerHelpers, type: :helper
end
Shoulda::Matchers.configure do |config|
config.integrate do |with|
with.test_framework :rspec
with.library :rails
end
end
Dir[Rails.root.join "spec", "shared_examples", "*.rb"].sort.each { |f| require f }