Updated

spec/controllers/admin / trending_ips_controller_spec.rb

F
106 lines of codes
0 methods
N/A complexity/method
1 churn
212.78 complexity
276 duplications
require 'rails_helper' RSpec.describe Admin::TrendingIpsController, type: :controller, admin: true do
  1. Similar code found in 2 nodes Locations: 0 1
context "when not logged in" do describe "GET /admin/petitions/200000/trending-ips" do before do get :index, petition_id: "200000" end it "redirects to the login page" do expect(response).to redirect_to("https://moderate.petition.parliament.uk/admin/login") end end end context "when logged in as moderator user but need to reset password" do let(:user) { FactoryBot.create(:moderator_user, force_password_reset: true) } before do login_as(user) end describe "GET /admin/petitions/200000/trending-ips" do before do get :index, petition_id: "200000" end it "redirects to edit profile page" do expect(response).to redirect_to("https://moderate.petition.parliament.uk/admin/profile/#{user.id}/edit") end end end context "when logged in as moderator user" do let(:user) { FactoryBot.create(:moderator_user) } let(:petition) { double(Petition) } let(:scope) { double(Petition.all) } let(:trending_ips) { double(TrendingIp.all) } before do login_as(user) end describe "GET /admin/petitions/200000/trending-ips" do
  1. context(when logged in as moderator user)::describe#GET /admin/petitions/200000/trending-ips has a flog score of 27
before do allow(Petition).to receive(:find).with("200000").and_return(petition) allow(petition).to receive(:trending_ips).and_return(scope) end shared_examples_for "trending ip addresses index page" do it "responds successfully" do expect(response).to be_successful end it "assigns the @petition instance variable" do expect(assigns(:petition)).to eq(petition) end it "assigns the @trending_ips instance variable" do expect(assigns(:trending_ips)).to eq(trending_ips) end it "renders the trending_ips/index template" do expect(response).to render_template("trending_ips/index") end end context "when viewing all trending ip addresses" do before do expect(scope).to receive(:search).with(nil, page: nil).and_return(trending_ips) get :index, petition_id: "200000" end include_examples("trending ip addresses index page") end context "when viewing page 2 of all trending ip addresses" do before do expect(scope).to receive(:search).with(nil, page: "2").and_return(trending_ips) get :index, petition_id: "200000", page: "2" end include_examples("trending ip addresses index page") end context "when searching trending ip addresses" do before do expect(scope).to receive(:search).with("127.0.0.1", page: nil).and_return(trending_ips) get :index, petition_id: "200000", q: "127.0.0.1" end include_examples("trending ip addresses index page") end context "when viewing page 2 of a trending ip addresses search" do before do expect(scope).to receive(:search).with("127.0.0.1", page: "2").and_return(trending_ips) get :index, petition_id: "200000", q: "127.0.0.1", page: "2" end include_examples("trending ip addresses index page") end end end end