<commit_before>require 'test_helper'

class TaskEditTest < ActionDispatch::IntegrationTest
  def self.make_test_for_due_date
    should "not change due_at if user not change it" do
      old_due=find_by_id("due_at").value
      fill_in "task_description", :with => 'changed description'
      click_button "Save"
      visit "/tasks/edit/#{@task.task_num}"
      assert_equal find_by_id("due_at").value, old_due
      assert_equal 'changed description', @task.reload.description
    end
    should "change due_at " do
      fill_in "due_at", :with => "27/07/2009"
      click_button "Save"
      visit "/tasks/edit/#{@task.task_num}"
      assert_equal find_by_id("due_at").value,  "27/07/2009"
    end
  end
  context "A logged in user" do
    setup do
      @user = login
      @user.option_tracktime=true
      @user.save!
    end

    context "with some existing tasks" do
      setup do
        @project = project_with_some_tasks(@user)
        @project2 = project_with_some_tasks(@user)

        2.times { @project.milestones.make(:project => @project, :user => @user,
                                 :company => @project.company) }
      end

      context "with email from unkown" do
        setup do
          @task = @project.tasks.first
          @email = Sham.email
        end

        should "be able to attach email to user" do
          @task.email_addresses.create(:email => @email, :company => @user.company)
          visit "/tasks/edit/#{@task.task_num}"
          assert_not_nil find_link(@email)
          visit find_link(@email)[:href]

          user = User.make(:customer => @user.customer, :company => @user.company)
          hidden_field = find_by_id("email_attach_user_id")
          hidden_field.set(user.id)
          click_button('Save')

          visit "/tasks/edit/#{@task.task_num}"
          assert_raise(Capybara::ElementNotFound) { find_link(@email) }
          assert_not_nil find_link(user.name)
        end

      end

      context "edit tasks created from email" do
        setup do
          @task = TaskRecord.new(:description => "test task", :company => @project.company, :project => @project)
          @task.save(:validate => false)
          visit "/tasks/edit/#{@task.task_num}"
        end

        should "be able to keep comment on error" do
          fill_in "comment", :with => "a new comment"
          click_button "Save"
          assert page.has_content?("Name can't be blank")
          assert page.has_content?("a new comment")
        end<commit_msg>Used xpath to trace button<commit_after>require 'test_helper'

class TaskEditTest < ActionDispatch::IntegrationTest
  def self.make_test_for_due_date
    should "not change due_at if user not change it" do
      old_due=find_by_id("due_at").value
      fill_in "task_description", :with => 'changed description'
      click_button "Save"
      visit "/tasks/edit/#{@task.task_num}"
      assert_equal find_by_id("due_at").value, old_due
      assert_equal 'changed description', @task.reload.description
    end
    should "change due_at " do
      fill_in "due_at", :with => "27/07/2009"
      click_button "Save"
      visit "/tasks/edit/#{@task.task_num}"
      assert_equal find_by_id("due_at").value,  "27/07/2009"
    end
  end
  context "A logged in user" do
    setup do
      @user = login
      @user.option_tracktime=true
      @user.save!
    end

    context "with some existing tasks" do
      setup do
        @project = project_with_some_tasks(@user)
        @project2 = project_with_some_tasks(@user)

        2.times { @project.milestones.make(:project => @project, :user => @user,
                                 :company => @project.company) }
      end

      context "with email from unkown" do
        setup do
          @task = @project.tasks.first
          @email = Sham.email
        end

        should "be able to attach email to user" do
          @task.email_addresses.create(:email => @email, :company => @user.company)
          visit "/tasks/edit/#{@task.task_num}"
          assert_not_nil find_link(@email)
          visit find_link(@email)[:href]

          user = User.make(:customer => @user.customer, :company => @user.company)
          hidden_field = find_by_id("email_attach_user_id")
          hidden_field.set(user.id)
          click_button('Save')

          visit "/tasks/edit/#{@task.task_num}"
          assert_raise(Capybara::ElementNotFound) { find_link(@email) }
          assert_not_nil find_link(user.name)
        end

      end

      context "edit tasks created from email" do
        setup do
          @task = TaskRecord.new(:description => "test task", :company => @project.company, :project => @project)
          @task.save(:validate => false)
          visit "/tasks/edit/#{@task.task_num}"
        end

        should "be able to keep comment on error" do
          fill_in "comment", :with => "a new comment"
          # Click li of Save and log...
          find("div[@id='save-dropdown']/ul[@class='dropdown-menu']/li[1]").click
          assert page.has_content?("a new comment")
        end
{'fraction_non_alphanumeric': 0.1174384236453202, 'fraction_numerical': 0.00729064039408867, 'mean_word_length': 2.413584398117014, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5089543', 'n_tokens_mistral': 1557, 'n_tokens_neox': 1513, 'n_words': 369}