<commit_before>require_relative 'spec_helper'

describe "Working With Projects" do

  before do
    @session = create_session
  end

  describe "getting info" do
    it "should get a project list if there are projects" do
      proj_list = @session.projects.project_list
      unless proj_list == nil
        @session.projects.project_list.class.must_be :==, Array
        %w{ id name status enabled view_state access_min 
              file_path description subprojects }.each { |w|
          @session.projects.project_list[0].must_include w.to_sym
        }
      end
    end 

  end # getting info

  describe "addition" do
    it "should create a new, basic project" do
      new_project_id = @session.projects.create params={
        :name => random_alphanumeric,
        :status => "development",
        :enabled => true,
        :view_state => "public",
        :inherit_global => true
      }
      new_project_id.wont_be_nil
    end

    it "should create a project with only a name" do
      new_project_id = @session.projects.create params={
        name: random_alphanumeric 
      }
      new_project_id.wont_be_nil
    end

    it "shouldn't accept incorrect project status types" do
      assert_raises RuntimeError do
        @session.projects.create params={
          name: random_alphanumeric,
          status: "something that doesn't exist",
        }
      end
    end

    it "shouldn't accept incorrect view_states" do
      assert_raises RuntimeError do
        @session.projects.create params={
          name: random_alphanumeric,
          view_state: "something non-existent"
        }
      end
    end

    it "shouldn't accept incorrect access minimum level" do
      assert_raises RuntimeError do
        @session.projects.create params={
          name: random_alphanumeric,
          access_min: "I know this doesn't exist"
        }
      end
    end

    it "shouldn't accept incorrect subprojects" do
      assert_raises RuntimeError do
        @session.projects.create params={
          subprojects: "blah blah blah bad"
        }
      end
    end

    describe "of subprojects" do
      it "can create projects as subprojects" do
        skip
      end

      it "can move subprojects from one to another" do
        skip
      end

      it "can have multiple nestings of subprojects" do
        skip
      end
    end

  end # addition

  describe "deletion" do

    before do
      @id = @session.projects.create params={
        name: random_alphanumeric }
    end

    it "should delete a project with a valid project_id" do
      @session.projects.delete?(@id).must_equal true
    end
  end # deletion

  describe "listing" do
    before do
      @id = @session.projects.create params={
        name: random_alphanumeric }
    end

    it "should return an array of hashes" do
      skip
    end

    it "should load a project if id is known" do
      proj = @session.projects.find_by_id @id.to_i
      proj[:id].to_i.must_be_same_as @id.to_i
    end
  end # listing

  # Delete out all the projects that I was creating
  after do
    clear_projects @session
  end

end # Working With Projects
<commit_msg>add nil check for find_by_id<commit_after>require_relative 'spec_helper'

describe "Working With Projects" do

  before do
    @session = create_session
  end

  describe "getting info" do
    it "should get a project list if there are projects" do
      proj_list = @session.projects.project_list
      unless proj_list == nil
        @session.projects.project_list.class.must_be :==, Array
        %w{ id name status enabled view_state access_min 
              file_path description subprojects }.each { |w|
          @session.projects.project_list[0].must_include w.to_sym
        }
      end
    end 

  end # getting info

  describe "addition" do
    it "should create a new, basic project" do
      new_project_id = @session.projects.create params={
        :name => random_alphanumeric,
        :status => "development",
        :enabled => true,
        :view_state => "public",
        :inherit_global => true
      }
      new_project_id.wont_be_nil
    end

    it "should create a project with only a name" do
      new_project_id = @session.projects.create params={
        name: random_alphanumeric 
      }
      new_project_id.wont_be_nil
    end

    it "shouldn't accept incorrect project status types" do
      assert_raises RuntimeError do
        @session.projects.create params={
          name: random_alphanumeric,
          status: "something that doesn't exist",
        }
      end
    end

    it "shouldn't accept incorrect view_states" do
      assert_raises RuntimeError do
        @session.projects.create params={
          name: random_alphanumeric,
          view_state: "something non-existent"
        }
      end
    end

    it "shouldn't accept incorrect access minimum level" do
      assert_raises RuntimeError do
        @session.projects.create params={
          name: random_alphanumeric,
          access_min: "I know this doesn't exist"
        }
      end
    end

    it "shouldn't accept incorrect subprojects" do
      assert_raises RuntimeError do
        @session.projects.create params={
          subprojects: "blah blah blah bad"
        }
      end
    end

    describe "of subprojects" do
      it "can create projects as subprojects" do
        skip
      end

      it "can move subprojects from one to another" do
        skip
      end

      it "can have multiple nestings of subprojects" do
        skip
      end
    end

  end # addition

  describe "deletion" do

    before do
      @id = @session.projects.create params={
        name: random_alphanumeric }
    end

    it "should delete a project with a valid project_id" do
      @session.projects.delete?(@id).must_equal true
    end
  end # deletion

  describe "listing" do
    before do
      @id = @session.projects.create params={
        name: random_alphanumeric }
    end

    it "should return an array of hashes" do
      skip
    end

    it "should load a project if id is known" do
      proj = @session.projects.find_by_id @id.to_i
      proj[:id].to_i.must_be_same_as @id.to_i
    end

    it "should return nil if no project is found with a given id" do
      @session.projects.find_by_id("million").must_be_nil
    end
  end # listing

  # Delete out all the projects that I was creating
  after do
    clear_projects @session
  end

end # Working With Projects

{'fraction_non_alphanumeric': 0.06717226435536294, 'fraction_numerical': 0.00030954960532425323, 'mean_word_length': 2.2554156171284636, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '3586490', 'n_tokens_mistral': 1912, 'n_tokens_neox': 1833, 'n_words': 614}