Updated

spec/controllers/archived / petitions_controller_spec.rb

F
86 lines of codes
0 methods
N/A complexity/method
3 churn
161.43 complexity
187 duplications
require 'rails_helper' RSpec.describe Archived::PetitionsController, type: :controller do let!(:parliament) { FactoryBot.create(:parliament, :archived) } describe "GET #index" do context "when no state param is provided" do
  1. Identical code found in 2 nodes Locations: 0 1
it "is successful" do get :index expect(response).to be_success end it "exposes a search scoped to the all facet" do get :index expect(assigns(:petitions).scope).to eq :all end end context "when a state param is provided" do
  1. Similar code found in 2 nodes Locations: 0 1
context "but it is not a public facet from the locale file" do it "redirects to itself with state=all" do get :index, state: "awaiting_monkey" expect(response).to redirect_to "https://petition.parliament.uk/archived/petitions?state=all" end it "preserves other params when it redirects" do get :index, q: "what is clocks", state: "awaiting_monkey" expect(response).to redirect_to "https://petition.parliament.uk/archived/petitions?q=what+is+clocks&state=all" end end context "and it is a public facet from the locale file" do it "is successful" do get :index, state: "published" expect(response).to be_success end it "exposes a search scoped to the state param" do get :index, state: "published" expect(assigns(:petitions).scope).to eq :published end end end end describe "GET #show" do context "when the petition is visible" do let!(:petition) { FactoryBot.create(:archived_petition) } it "assigns the given petition" do get :show, id: petition.id expect(assigns(:petition)).to eq(petition) end end context "when the petition is hidden" do
  1. Similar code found in 2 nodes Locations: 0 1
let!(:petition) { FactoryBot.create(:archived_petition, :hidden) } it "raises a ActiveRecord::RecordNotFound error" do expect { get :show, id: petition.id }.to raise_error(ActiveRecord::RecordNotFound) end end context "when the petition is stopped" do
  1. Similar code found in 2 nodes Locations: 0 1
let!(:petition) { FactoryBot.create(:archived_petition, :stopped) } it "raises a ActiveRecord::RecordNotFound error" do expect { get :show, id: petition.id }.to raise_error(ActiveRecord::RecordNotFound) end end context "when the petition is archived but the parliament is not" do
  1. Similar code found in 2 nodes Locations: 0 1
let!(:parliament) { FactoryBot.create(:parliament) } let!(:petition) { FactoryBot.create(:archived_petition, parliament: parliament) } it "redirects to the current petition" do get :show, id: petition.id expect(response).to redirect_to "https://petition.parliament.uk/petitions/#{petition.id}" end end end end