<commit_before>require 'test_helper'

class ProjectsControllerTest < ActionController::TestCase
  fixtures :customers, :projects

  signed_in_admin_context do
    setup do
      @project = projects(:test_project)
    end

    should "get list page" do
      get :index
      assert_response :success
    end

    should "get new project page" do
      get :new
      assert_response :success
    end

    should "get project view page" do
      get :show, :id => @project.id
      assert_response :success
    end

    should "create project and copy project permissions" do
      project_hash = {
        name: 'New Project',
        description: 'Some description',
        customer_id: customers(:internal_customer).id,
        company_id: companies(:cit).id
      }
      assert_difference("Project.count", +1) do
        post :create, {
          project: project_hash,
          copy_project_id: @project.id
        }
      end
      filter = TaskFilter.where(:name => project_hash[:name]).first
      assert filter
      assert filter.qualifiers.detect {|q| q.qualifiable.name == project_hash[:name]}
      assert filter.qualifiers.detect {|q| q.qualifiable == companies(:cit).statuses.first }
      assert_equal 3, assigns[:project].project_permissions.size
      assert_redirected_to :action => :index
    end

    should "get edit project page" do
      get :edit, :id => @project.id
      assert_response :success
    end

    should "update project" do
      post :update, {:project=>{:name=>"New Project Name", :description=>"New Project Description",
                     :customer_id=>customers(:internal_customer).id},
                     :id=>@project.id,
                     :customer=>{:name=>customers(:internal_customer).name}}
      assert_equal "New Project Name", assigns[:project].name
      assert_equal "New Project Description", assigns[:project].description
      assert_redirected_to :action=> "index"
    end

    should "complete project" do
      post :complete, {:id => @project.id}
      assert_not_nil @project.reload.completed_at
      assert_redirected_to root_url
    end

    should "revert project" do
      post :revert, {:id => projects(:completed_project).id}
      assert_nil projects(:completed_project).reload.completed_at
      assert_redirected_to root_url
    end
    context "destroy project" do
      setup do
        task = Task.make
        @project.sheets << Sheet.make(:user => @user, :task => task)
        @project.work_logs << WorkLog.make(:user => @user)
      end

      context "without tasks" do
        setup do
          other = Project.where("id !=?", @project.id).first
          @project.tasks.each{ |task|
            task.project=other
            task.save!
          }
        end
        should "remove project and its worklogs, tasks, pages, milestones, sheets, project permissions" do<commit_msg>fix projects functional test<commit_after>require 'test_helper'

class ProjectsControllerTest < ActionController::TestCase
  fixtures :customers, :projects

  signed_in_admin_context do
    setup do
      @project = projects(:test_project)
    end

    should "get list page" do
      get :index
      assert_response :success
    end

    should "get new project page" do
      get :new
      assert_response :success
    end

    should "get project view page" do
      get :show, :id => @project.id
      assert_response :success
    end

    should "create project and copy project permissions" do
      project_hash = {
        name: 'New Project',
        description: 'Some description',
        customer_id: customers(:internal_customer).id,
        company_id: companies(:cit).id
      }
      assert_difference("Project.count", +1) do
        post :create, {
          project: project_hash,
          copy_project_id: @project.id
        }
      end
      filter = TaskFilter.where(:name => project_hash[:name]).first
      assert filter
      assert filter.qualifiers.detect {|q| q.qualifiable.name == project_hash[:name]}
      assert filter.qualifiers.detect {|q| q.qualifiable == companies(:cit).statuses.first }
      assert_equal 3, assigns[:project].project_permissions.size
      assert_redirected_to :action => :index
    end

    should "get edit project page" do
      get :edit, :id => @project.id
      assert_response :success
    end

    should "update project" do
      post :update, {:project=>{:name=>"New Project Name", :description=>"New Project Description",
                     :customer_id=>customers(:internal_customer).id},
                     :id=>@project.id,
                     :customer=>{:name=>customers(:internal_customer).name}}
      assert_equal "New Project Name", assigns[:project].name
      assert_equal "New Project Description", assigns[:project].description
      assert_redirected_to :action=> "index"
    end

    should "complete project" do
      post :complete, {:id => @project.id}
      assert_not_nil @project.reload.completed_at
      assert_redirected_to edit_project_path(@project)
    end

    should "revert project" do
      post :revert, {:id => projects(:completed_project).id}
      assert_nil projects(:completed_project).reload.completed_at
      assert_redirected_to edit_project_path(projects(:completed_project))
    end
    context "destroy project" do
      setup do
        task = Task.make
        @project.sheets << Sheet.make(:user => @user, :task => task)
        @project.work_logs << WorkLog.make(:user => @user)
      end

      context "without tasks" do
        setup do
          other = Project.where("id !=?", @project.id).first
          @project.tasks.each{ |task|
            task.project=other
            task.save!
          }
        end
        should "remove project and its worklogs, tasks, pages, milestones, sheets, project permissions" do
{'fraction_non_alphanumeric': 0.10276679841897234, 'fraction_numerical': 0.0006874033339061695, 'mean_word_length': 2.6511919698870767, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 37, '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': '2756267', 'n_tokens_mistral': 1629, 'n_tokens_neox': 1569, 'n_words': 426}