Updated

spec/controllers/admin / rate_limits_controller_spec.rb

F
159 lines of codes
0 methods
N/A complexity/method
4 churn
237.84 complexity
257 duplications
require 'rails_helper' RSpec.describe Admin::RateLimitsController, type: :controller, admin: true do context "when not logged in" do
  1. Similar code found in 4 nodes Locations: 0 1 2 3
[ ["GET", "/admin/rate-limits/edit", :edit, {}], ["PATCH", "/admin/rate-limits", :update, {}] ].each do |method, path, action, params| describe "#{method} #{path}" do before { process action, method, params } it "redirects to the login page" do expect(response).to redirect_to("https://moderate.petition.parliament.uk/admin/login") end end end end context "when logged in as a moderator" do
  1. Similar code found in 3 nodes Locations: 0 1 2
let(:moderator) { FactoryBot.create(:moderator_user) } before { login_as(moderator) } [ ["GET", "/admin/rate-limits/edit", :edit, {}], ["PATCH", "/admin/rate-limits", :update, {}] ].each do |method, path, action, params| describe "#{method} #{path}" do before { process action, method, params } it "redirects to the admin hub page" do expect(response).to redirect_to("https://moderate.petition.parliament.uk/admin") end end end end context "when logged in as a sysadmin" do let(:sysadmin) { FactoryBot.create(:sysadmin_user) } before { login_as(sysadmin) } describe "GET /admin/rate-limits/edit" do
  1. Similar code found in 10 nodes Locations: 0 1 2 3 4 5 6 7 8 9
before { get :edit } it "returns 200 OK" do expect(response).to have_http_status(:ok) end it "renders the :edit template" do expect(response).to render_template("admin/rate_limits/edit") end end describe "PATCH /admin/rate-limits" do before { patch :update, rate_limit: params } context "when the params are invalid" do let :params do { burst_rate: "", burst_period: "", sustained_rate: "", sustained_period: "" } end it "returns 200 OK" do expect(response).to have_http_status(:ok) end it "renders the :edit template" do expect(response).to render_template("admin/rate_limits/edit") end end context "when the params are valid" do let :params do { burst_rate: "1", burst_period: "60", sustained_rate: "5", sustained_period: "300" } end it "redirects to the edit page" do expect(response).to redirect_to("https://moderate.petition.parliament.uk/admin/rate-limits/edit") end it "sets the flash notice message" do expect(flash[:notice]).to eq("Rate limits updated successfully") end end context "when submitting just the allowed domains list" do
  1. Similar code found in 7 nodes Locations: 0 1 2 3 4 5 6
let :params do { allowed_domains: "example.com" } end it "redirects to the edit page" do expect(response).to redirect_to("https://moderate.petition.parliament.uk/admin/rate-limits/edit") end it "sets the flash notice message" do expect(flash[:notice]).to eq("Rate limits updated successfully") end end context "when submitting just the blocked domains list" do
  1. Similar code found in 7 nodes Locations: 0 1 2 3 4 5 6
let :params do { blocked_domains: "example.com" } end it "redirects to the edit page" do expect(response).to redirect_to("https://moderate.petition.parliament.uk/admin/rate-limits/edit") end it "sets the flash notice message" do expect(flash[:notice]).to eq("Rate limits updated successfully") end end context "when submitting just the allowed IPs list" do
  1. Similar code found in 7 nodes Locations: 0 1 2 3 4 5 6
let :params do { allowed_ips: "127.0.0.1" } end it "redirects to the edit page" do expect(response).to redirect_to("https://moderate.petition.parliament.uk/admin/rate-limits/edit") end it "sets the flash notice message" do expect(flash[:notice]).to eq("Rate limits updated successfully") end end context "when submitting just the blocked IPs list" do
  1. Similar code found in 7 nodes Locations: 0 1 2 3 4 5 6
let :params do { blocked_ips: "127.0.0.1" } end it "redirects to the edit page" do expect(response).to redirect_to("https://moderate.petition.parliament.uk/admin/rate-limits/edit") end it "sets the flash notice message" do expect(flash[:notice]).to eq("Rate limits updated successfully") end end context "when submitting just the countries list" do
  1. Similar code found in 3 nodes Locations: 0 1 2
let :params do { countries: "127.0.0.1", geoblocking_enabled: "true" } end it "redirects to the edit page" do expect(response).to redirect_to("https://moderate.petition.parliament.uk/admin/rate-limits/edit") end it "sets the flash notice message" do expect(flash[:notice]).to eq("Rate limits updated successfully") end end end end end