Updated

spec/controllers/admin/archived / petition_tags_controller_spec.rb

F
90 lines of codes
0 methods
N/A complexity/method
3 churn
175.57 complexity
216 duplications
require 'rails_helper' RSpec.describe Admin::Archived::PetitionTagsController, type: :controller, admin: true do let!(:petition) { FactoryBot.create(:archived_petition) } let!(:creator) { FactoryBot.create(:archived_signature, :validated, creator: true, petition: petition) } context "when not logged in" do
  1. Similar code found in 13 nodes Locations: 0 1 2 3 4 5 6 7 8 9 10 11 12
describe "GET /admin/archived/petitions/:petition_id/tags" do it "redirects to the login page" do get :show, petition_id: petition.id expect(response).to redirect_to("https://moderate.petition.parliament.uk/admin/login") end end describe "PATCH /admin/archived/petitions/:petition_id/tags" do it "redirects to the login page" do patch :update, petition_id: petition.id 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
  1. Similar code found in 13 nodes Locations: 0 1 2 3 4 5 6 7 8 9 10 11 12
let(:user) { FactoryBot.create(:moderator_user, force_password_reset: true) } before { login_as(user) } describe "GET /admin/archived/petitions/:petition_id/tags" do it "redirects to the edit profile page" do get :show, petition_id: petition.id expect(response).to redirect_to("https://moderate.petition.parliament.uk/admin/profile/#{user.id}/edit") end end describe "PATCH /admin/archived/petitions/:petition_id/tags" do it "redirects to the edit profile page" do patch :update, petition_id: petition.id 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
  1. Similar code found in 2 nodes Locations: 0 1
let(:user) { FactoryBot.create(:moderator_user) } before { login_as(user) } describe "GET /admin/archived/petitions/:petition_id/tags" do before { get :show, petition_id: petition.id } it "returns 200 OK" do expect(response).to have_http_status(:ok) end it "renders the :show template" do expect(response).to render_template("admin/archived/petitions/show") end end describe "PATCH /admin/archived/petitions/:petition_id/tags" do before { patch :update, petition_id: petition.id, petition: params } context "and the params are invalid" do let :params do { tags: ["999"] } end it "returns 200 OK" do expect(response).to have_http_status(:ok) end it "renders the :show template" do expect(response).to render_template("admin/archived/petitions/show") end end context "and the params are valid" do let :params do { tags: [""] } end it "redirects to the petition page" do expect(response).to redirect_to("https://moderate.petition.parliament.uk/admin/archived/petitions/#{petition.id}") end it "sets the flash notice message" do expect(flash[:notice]).to eq("Petition has been successfully updated") end end end end end