<commit_before>require 'spec_helper'

describe SessionsController do
  describe 'GET "new"' do
    it 'should be successful' do
      get :new
      response.should be_success
    end

    it 'should render the new page' do
      get :new
      response.should render_template('new')
    end

    it 'should generate a login ticket' do
      lambda do
        get :new
      end.should change(LoginTicket, :count).by(1)
    end
  end

  describe 'GET "index"' do
    describe 'as a not loggedin user' do
      it 'should redirect to the login page' do
        get :index
        response.should redirect_to(new_session_path)
      end
    end
  end

  describe 'POST "create"' do
    describe 'without a valid login ticket' do
      before(:each) do
        post :create
      end

      it 'should redirect to the login page' do
        response.should redirect_to(login_path)
      end

      it 'should have a flash message' do
        flash[:error].should =~ /no valid login ticket/i
      end
    end

    describe 'with a valid login ticket' do
      describe 'with invalid data' do
        before(:each) do
          ticket = LoginTicket.create! ticket: 'LT-54321'
          post :create, {
            lt: ticket.ticket,
            username: 'bla',
            password: '<PASSWORD>'
          }
        end

        it 'should render the new page' do
          response.should render_template('new')
        end

        it 'should have a flash message' do
          flash[:error].should =~ /incorrect/i
        end

        it 'should response with a 403' do
          response.response_code.should == 403
        end
      end

      describe 'with valid data' do
        before(:each) do
          ticket = LoginTicket.create! ticket: 'LT-43821'
          post :create, {
            lt: ticket.ticket,
            username: 'testuser',
            password: '<PASSWORD>'
          }
        end

        it 'should redirect to the index page' do
          response.should redirect_to(sessions_path)
        end
      end
    end
  end
end
<commit_msg>use context instead of describe where appropriate<commit_after>require 'spec_helper'

describe SessionsController do
  describe 'GET "new"' do
    it 'should be successful' do
      get :new
      response.should be_success
    end

    it 'should render the new page' do
      get :new
      response.should render_template('new')
    end

    it 'should generate a login ticket' do
      lambda do
        get :new
      end.should change(LoginTicket, :count).by(1)
    end
  end

  describe 'GET "index"' do
    context 'when logged out' do
      it 'should redirect to the login page' do
        get :index
        response.should redirect_to(new_session_path)
      end
    end
  end

  describe 'POST "create"' do
    context 'without a valid login ticket' do
      before(:each) do
        post :create
      end

      it 'should redirect to the login page' do
        response.should redirect_to(login_path)
      end

      it 'should have a flash message' do
        flash[:error].should =~ /no valid login ticket/i
      end
    end

    context 'with a valid login ticket' do
      context 'with invalid login data' do
        before(:each) do
          ticket = LoginTicket.create! ticket: 'LT-54321'
          post :create, {
            lt: ticket.ticket,
            username: 'bla',
            password: '<PASSWORD>'
          }
        end

        it 'should render the new page' do
          response.should render_template('new')
        end

        it 'should have a flash message' do
          flash[:error].should =~ /incorrect/i
        end

        it 'should response with a 403' do
          response.response_code.should == 403
        end
      end

      context 'with valid login data' do
        before(:each) do
          ticket = LoginTicket.create! ticket: 'LT-43821'
          post :create, {
            lt: ticket.ticket,
            username: 'testuser',
            password: '<PASSWORD>'
          }
        end

        it 'should redirect to the index page' do
          response.should redirect_to(sessions_path)
        end
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.07441190590494479, 'fraction_numerical': 0.00816130580892943, 'mean_word_length': 1.8212593094109681, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '4895165', 'n_tokens_mistral': 1196, 'n_tokens_neox': 1127, 'n_words': 420}