<commit_before>require 'spec_helper'

describe Portal::StudentsController do
  integrate_views

  before(:each) do
    generate_default_project_and_jnlps_with_mocks
    generate_portal_resources_with_mocks
    Admin::Project.should_receive(:default_project).and_return(@mock_project)
  end

  describe "POST create" do
    before(:each) do
      @params_for_creation = {
        :user => {
          :first_name => "Test",
          :last_name => "User",
          :password => "<PASSWORD>",
          :password_confirmation => "<PASSWORD>"
        },
        :clazz => {
          :class_word => "classword"
        },
        :security_questions => {
          :question0 => {
            :question_idx => 0,
            :answer => "test"
          },
          :question1 => {
            :question_idx => 1,
            :answer => "test"
          },
          :question2 => {
            :question_idx => 2,
            :answer => "test"
          }
        }
      }

      @grade_level = Portal::GradeLevel.create({ :name => "9" }) # default grade level
      @clazz = Factory.create(:portal_clazz, :class_word => @params_for_creation[:clazz][:class_word])
    end

    def stub_user_with_params(user_attributes = nil)
      user_attributes ||= @params_for_creation[:user]
      user_attributes[:login] = Portal::Student.generate_user_login(user_attributes[:first_name], user_attributes[:last_name])
      user_attributes[:email] = Portal::Student.generate_user_email

      @new_user = User.new(user_attributes)
      User.stub!(:new).and_return(@new_user)
    end

    it "creates a user and a student when given valid parameters" do
      stub_user_with_params

      current_user_count = User.count(:all)
      current_student_count = Portal::Student.count(:all)

      post :create, @params_for_creation

      User.count(:all).should == current_user_count + 1
      Portal::Student.count(:all).should == current_student_count + 1

    end


    # after creating a new account, students still need to login.
    # this is because they need to remember their username and password
    it "clearly shows that the student needs to login after successful create" do
      stub_user_with_params
      post :create, @params_for_creation

      # should show text "your username is"
      assert_select "p", /username\s+is/i

      # should show directions to login:
      assert_select "p", /log\s+in/i
    end

    # student is not logged in, so we shouldn't display their classes!
    it "does not show any of the students classes after successful creation" do
      stub_user_with_params
      post :create, @params_for_creation
      assert_select "*#clazzes_nav", false
      assert_select "input#login"
    end
<commit_msg>regex in test was matching nonexistent copy<commit_after>require 'spec_helper'

describe Portal::StudentsController do
  integrate_views

  before(:each) do
    generate_default_project_and_jnlps_with_mocks
    generate_portal_resources_with_mocks
    Admin::Project.should_receive(:default_project).and_return(@mock_project)
  end

  describe "POST create" do
    before(:each) do
      @params_for_creation = {
        :user => {
          :first_name => "Test",
          :last_name => "User",
          :password => "<PASSWORD>",
          :password_confirmation => "<PASSWORD>"
        },
        :clazz => {
          :class_word => "classword"
        },
        :security_questions => {
          :question0 => {
            :question_idx => 0,
            :answer => "test"
          },
          :question1 => {
            :question_idx => 1,
            :answer => "test"
          },
          :question2 => {
            :question_idx => 2,
            :answer => "test"
          }
        }
      }

      @grade_level = Portal::GradeLevel.create({ :name => "9" }) # default grade level
      @clazz = Factory.create(:portal_clazz, :class_word => @params_for_creation[:clazz][:class_word])
    end

    def stub_user_with_params(user_attributes = nil)
      user_attributes ||= @params_for_creation[:user]
      user_attributes[:login] = Portal::Student.generate_user_login(user_attributes[:first_name], user_attributes[:last_name])
      user_attributes[:email] = Portal::Student.generate_user_email

      @new_user = User.new(user_attributes)
      User.stub!(:new).and_return(@new_user)
    end

    it "creates a user and a student when given valid parameters" do
      stub_user_with_params

      current_user_count = User.count(:all)
      current_student_count = Portal::Student.count(:all)

      post :create, @params_for_creation

      User.count(:all).should == current_user_count + 1
      Portal::Student.count(:all).should == current_student_count + 1

    end


    # after creating a new account, students still need to login.
    # this is because they need to remember their username and password
    it "clearly shows that the student needs to login after successful create" do
      stub_user_with_params
      post :create, @params_for_creation

      # should show text "your username is"
      assert_select "p", /username\s+is/i

      # should show directions to login:
      assert_select "p", /login/i
    end

    # student is not logged in, so we shouldn't display their classes!
    it "does not show any of the students classes after successful creation" do
      stub_user_with_params
      post :create, @params_for_creation
      assert_select "*#clazzes_nav", false
      assert_select "input#login"
    end

{'fraction_non_alphanumeric': 0.10187374931780971, 'fraction_numerical': 0.003274513370929598, 'mean_word_length': 2.729986431478969, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 45, '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': '671017', 'n_tokens_mistral': 1623, 'n_tokens_neox': 1571, 'n_words': 386}