<commit_before>require_relative '../spec_helper'

def app
  ProjectsController
end

describe ProjectsController do
  describe "Projects index" do
    it "lists the users projects when logged in" do
      user = create_and_login_user('user','pass')
      projects = [user.projects.create(name:"Test_Project_1"), user.projects.create(name:"Test_Project_2")]

      visit "/projects"
      projects.each do |project|
        expect(page).to have_content(project.name)
      end
    end
    it "does not list other users projects" do
      user = User.create(name:"user", email: "mail", password: "<PASSWORD>")
      user2 = create_and_login_user('user','pass')
      projects = [user.projects.create(name:"Test_Project_1"), user.projects.create(name:"Test_Project_2")]

      visit "/projects"
      projects.each do |project|
        expect(page).not_to have_content(project.name)
      end
    end
    it "redirects the user to the homepage when not logged in" do
      visit "/projects"
      expect(page).to have_current_path("/")
    end
  end
end<commit_msg>Add test for creating a project<commit_after>require_relative '../spec_helper'

def app
  ProjectsController
end

describe ProjectsController do
  describe "Projects index" do
    it "lists the users projects when logged in" do
      user = create_and_login_user('user','pass')
      projects = [user.projects.create(name:"Test_Project_1"), user.projects.create(name:"Test_Project_2")]

      visit "/projects"
      projects.each do |project|
        expect(page).to have_content(project.name)
      end
    end
    it "does not list other users projects" do
      user = User.create(name:"user", email: "mail", password: "<PASSWORD>")
      user2 = create_and_login_user('user','pass')
      projects = [user.projects.create(name:"Test_Project_1"), user.projects.create(name:"Test_Project_2")]

      visit "/projects"
      projects.each do |project|
        expect(page).not_to have_content(project.name)
      end
    end
    it "redirects the user to the homepage when not logged in" do
      visit "/projects"
      expect(page).to have_current_path("/")
    end
  end

  describe "Creating Projects" do
    it "Allows the user to create a project" do
      user = create_and_login_user('user','pass')
      visit "/projects/new"
      fill_in "name", with: "<NAME>"
      fill_in "description", with: "Test Description"
      click_on "create-project"
      project = Projects.last
      expect(page).to have_current_path("/projects/"+project.id)
      expect(project.name).to eq("Test Project")
      expect(project.description).to eq("Test Description")
      expect(project.user).to eq(user)
    end
    it "Redirects to homepage if not logged in" do
      visit "/projects/new"
      expect(page).to have_current_path("/")
    end
    it "Doesn't let a user create a project with an empty name" do
      user = create_and_login_user('user','pass')
      visit "/projects/new"
      fill_in "name", with: ""
      fill_in "description", with: "Test Description"
      click_on "create-project"
      expect(page).to have_current_path("/projects/new")
    end
    it "Doesn't let a user create a project with an empty description" do
      user = create_and_login_user('user','pass')
      visit "/projects/new"
      fill_in "name", with: "<NAME>"
      fill_in "description", with: ""
      click_on "create-project"
      expect(page).to have_current_path("/projects/new")
    end
  end
end
{'fraction_non_alphanumeric': 0.11605080831408776, 'fraction_numerical': 0.002886836027713626, 'mean_word_length': 3.2567567567567566, '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': '7548454', 'n_tokens_mistral': 1030, 'n_tokens_neox': 1014, 'n_words': 285}