<commit_before>require 'rails_helper'

describe Admin::TodolistController do

  describe "not logged in" do
    with_ssl do
      describe "GET 'index'" do
        it "should redirect to the login page" do
          get 'index'
          expect(response).to redirect_to(admin_login_path)
        end
      end
    end
  end

  context "logged in as admin user but need to reset password" do
    before :each do
      @user = FactoryGirl.create(:admin_user, :force_password_reset => true)
      login_as(@user)
    end

    with_ssl do
      it "should redirect to edit profile page" do
        expect(@user.has_to_change_password?).to be_truthy
        get :index
        expect(response).to redirect_to(edit_admin_profile_path(@user))
      end
    end
  end

  describe "logged in" do
    before :each do
      @treasury = FactoryGirl.create(:department)
      @dfid = FactoryGirl.create(:department)
      @home_office = FactoryGirl.create(:department)
      @p1 = FactoryGirl.create(:petition, :department => @treasury, :created_at => 3.days.ago, :state => Petition::SPONSORED_STATE)
      @p2 = FactoryGirl.create(:petition, :department => @treasury, :created_at => 12.days.ago, :state => Petition::SPONSORED_STATE)
      @p3 = FactoryGirl.create(:petition, :department => @home_office, :created_at => 7.days.ago, :state => Petition::SPONSORED_STATE)
      @p4 = FactoryGirl.create(:petition, :department => @home_office, :state => Petition::PENDING_STATE)
      @p5 = FactoryGirl.create(:open_petition, :department => @dfid)
    end

    describe "logged in as sysadmin user" do
      before :each do
        @user = FactoryGirl.create(:sysadmin_user)
        login_as(@user)
      end

      with_ssl do
        describe "GET 'index'" do
          it "should be successful" do
            get :index
            expect(response).to be_success
          end

          it "should return all validated petitions ordered by created_at" do
            get :index
            expect(assigns[:petitions]).to eq([@p2, @p3, @p1])
          end
        end
      end
    end

    describe "logged in as threshold user" do
      before :each do
        @user = FactoryGirl.create(:threshold_user)
        login_as(@user)
      end

      with_ssl do
        describe "GET 'index'" do
          it "should be successful" do
            get :index
            expect(response).to be_success
          end

          it "should return all validated petitions ordered by created_at" do
            get :index
            expect(assigns[:petitions]).to eq([@p2, @p3, @p1])
          end
        end
      end
    end

    describe "logged in as admin user" do
      before :each do
        @user = FactoryGirl.create(:admin_user)
        @user.departments << @treasury << @dfid
        login_as(@user)
      end

      with_ssl do
        describe "GET 'index'" do
          it "should be successful" do
            get :index
            expect(response).to be_success
          end
<commit_msg>No departments needed for admin user in todolist controller spec<commit_after>require 'rails_helper'

describe Admin::TodolistController do

  describe "not logged in" do
    with_ssl do
      describe "GET 'index'" do
        it "should redirect to the login page" do
          get 'index'
          expect(response).to redirect_to(admin_login_path)
        end
      end
    end
  end

  context "logged in as admin user but need to reset password" do
    let(:user) { FactoryGirl.create(:admin_user, :force_password_reset => true) }
    before { login_as(user) }

    with_ssl do
      it "should redirect to edit profile page" do
        expect(user.has_to_change_password?).to be_truthy
        get :index
        expect(response).to redirect_to(edit_admin_profile_path(user))
      end
    end
  end

  describe "logged in" do
    before :each do
      @treasury = FactoryGirl.create(:department)
      @dfid = FactoryGirl.create(:department)
      @home_office = FactoryGirl.create(:department)
      @p1 = FactoryGirl.create(:petition, :department => @treasury, :created_at => 3.days.ago, :state => Petition::SPONSORED_STATE)
      @p2 = FactoryGirl.create(:petition, :department => @treasury, :created_at => 12.days.ago, :state => Petition::SPONSORED_STATE)
      @p3 = FactoryGirl.create(:petition, :department => @home_office, :created_at => 7.days.ago, :state => Petition::SPONSORED_STATE)
      @p4 = FactoryGirl.create(:petition, :department => @home_office, :state => Petition::PENDING_STATE)
      @p5 = FactoryGirl.create(:open_petition, :department => @dfid)
    end

    describe "logged in as sysadmin user" do
      let(:user) { FactoryGirl.create(:sysadmin_user) }
      before { login_as(user) }

      with_ssl do
        describe "GET 'index'" do
          it "should be successful" do
            get :index
            expect(response).to be_success
          end

          it "should return all validated petitions ordered by created_at" do
            get :index
            expect(assigns[:petitions]).to eq([@p2, @p3, @p1])
          end
        end
      end
    end

    describe "logged in as threshold user" do
      let(:user) { FactoryGirl.create(:threshold_user) }
      before { login_as(user) }

      with_ssl do
        describe "GET 'index'" do
          it "should be successful" do
            get :index
            expect(response).to be_success
          end

          it "should return all validated petitions ordered by created_at" do
            get :index
            expect(assigns[:petitions]).to eq([@p2, @p3, @p1])
          end
        end
      end
    end

    describe "logged in as admin user" do
      let(:user) { FactoryGirl.create(:admin_user) }
      before { login_as(user) }

      with_ssl do
        describe "GET 'index'" do
          it "should be successful" do
            get :index
            expect(response).to be_success
          end

{'fraction_non_alphanumeric': 0.09618966977138019, 'fraction_numerical': 0.005080440304826418, 'mean_word_length': 2.3671607753705817, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5101569', 'n_tokens_mistral': 1824, 'n_tokens_neox': 1714, 'n_words': 500}