<commit_before>require 'spec_helper'

feature "Admin projects CRUD" do

  # let :jared do
  #   covered.users.create!(
  #     name: '<NAME>',
  #     email_address: '<EMAIL>',
  #     admin: true,
  #     password: 'password',
  #     password_confirmation: 'password',
  #   )
  # end

  let(:jared) { covered.users.find_by_email_address! '<EMAIL>'  }
  let(:ian)   { covered.users.find_by_email_address! '<EMAIL>'    }
  let(:nicole){ covered.users.find_by_email_address! '<EMAIL>' }
  let(:aaron) { covered.users.find_by_email_address! '<EMAIL>'  }

  def members_table
    all('.members.table tbody tr').map do |tr|
      tr.all('td').first(3).map(&:text)
    end
  end

  scenario %(creating a project) do
    sign_in_as '<EMAIL>'
    visit admin_new_project_path
    fill_in 'Name', with: 'United Nations'
    click_on 'Create Project'
    expect(page).to have_text 'Notice! Project was successfully created.'
    expect(page).to have_text 'Edit project'
    expect(current_url).to eq admin_edit_project_url('united-nations')

    within '.edit-project-form' do
      expect(page).to have_field "Name",                   with: "United Nations"
      expect(page).to have_field "Subject tag",            with: "United Nations"
      expect(page).to have_field "Slug",                   with: "united-nations"
      expect(page).to have_field "Email address username", with: "united.nations"
    end

    project = covered.projects.find_by_name!("United Nations")
    expect(project.name                  ).to eq "United Nations"
    expect(project.subject_tag           ).to eq "United Nations"
    expect(project.slug                  ).to eq "united-nations"
    expect(project.email_address_username).to eq "united.nations"

    within '.edit-project-form' do
      fill_in "Name",                   with: "United Hations"
      fill_in "Subject tag",            with: "United Hations"
      fill_in "Slug",                   with: "united-hations"
      fill_in "Email address username", with: "united.hations"
      click_on 'Update Project'
    end
    expect(page).to have_text 'Notice! Project was successfully updated.'
    project = covered.projects.find_by_name!("United Hations")
    expect(project.name                  ).to eq "United Hations"
    expect(project.subject_tag           ).to eq "United Hations"
    expect(project.slug                  ).to eq "united-hations"
    expect(project.email_address_username).to eq "united.hations"

    expect(project.members.all).to be_empty

    expect(members_table).to eq [["This project has no members."]]

    within '.add-existing-member-form' do
      select '<NAME> <<EMAIL>>', from: 'user[id]'
      click_on 'Add Member'
    end

    expect(members_table).to eq [
      ["<NAME>", "<EMAIL>", "yes"],
    ]
    expect( project.members ).to include nicole

    within '.add-existing-member-form' do
      select '<NAME> <<EMAIL>>', from: 'user[id]'
      uncheck 'Gets email?'
      uncheck 'Send join notice?'
      click_on 'Add Member'
    end

    expect(members_table).to match_array [
      ["<NAME>", "<EMAIL>", "yes"],
      ["<NAME>",      "<EMAIL>",    "no" ],
    ]
    expect( project.members ).to include ian

    assert_background_job_enqueued     SendEmailWorker, args: [covered.env, "join_notice", project.id, nicole.id, nil]
    assert_background_job_not_enqueued SendEmailWorker, args: [covered.env, "join_notice", project.id, ian.id,    nil]

    expect( project.members.find_by_user_id!(nicole.id).gets_email? ).to be_true
    expect( project.members.find_by_user_id!(ian.id   ).gets_email? ).to be_false

    within '.add-new-member-form' do
      fill_in 'Name', with: '<NAME>'
      fill_in 'Email address', with: '<EMAIL>'
      click_on 'Add Member'
    end

    expect(members_table).to match_array [
      ["<NAME>", "<EMAIL>", "yes"],
      ["<NAME>",      "<EMAIL>",    "no" ],
      ["You Face",       "<EMAIL>",     "yes"],
    ]
    you_face = project.members.find_by_user_slug!('you-face')
    expect( you_face.gets_email? ).to be_true
    assert_background_job_enqueued SendEmailWorker, args: [covered.env, "join_notice", project.id, you_face.id, nil]

    within '.add-new-member-form' do
      fill_in 'Name', with: '<NAME>'
      fill_in 'Email address', with: '<EMAIL>'
      uncheck 'Gets email?'
      uncheck 'Send join notice?'
      click_on 'Add Member'
    end

    expect(members_table).to match_array [
      ["<NAME>", "<EMAIL>", "yes"],
      ["<NAME>",      "<EMAIL>",    "no" ],
      ["You Face",       "<EMAIL>",     "yes"],
      ["Someone Else",   "<EMAIL>", "no" ],
    ]
    someone_else = project.members.find_by_user_slug!('someone-else')
    expect( someone_else.gets_email? ).to be_false
    assert_background_job_not_enqueued SendEmailWorker, args: [covered.env, "join_notice", project.id, someone_else.id, nil]

    within first('.members.table tbody tr') do
      click_on 'remove'
      accept_prompt!
    end

    expect(page).to have_text 'Edit project'

    expect(members_table).to match_array [
      ["<NAME>",      "<EMAIL>",    "no" ],
      ["You Face",       "<EMAIL>",     "yes"],
      ["Someone Else",   "<EMAIL>", "no" ],
    ]

    expect( project.members ).to_not include nicole

    visit admin_projects_url
    within('.projects.table tbody tr', text: 'United Hations') do
      click_on 'destroy'
      accept_prompt!
    end
    expect(page).to have_text 'Projects'
    expect(current_url).to eq admin_projects_url
    expect(page).to_not have_text 'United Hations'

  end

end<commit_msg>adjusted project spec to not require shitty precise ordering<commit_after>require 'spec_helper'

feature "Admin projects CRUD" do

  # let :jared do
  #   covered.users.create!(
  #     name: '<NAME>',
  #     email_address: '<EMAIL>',
  #     admin: true,
  #     password: 'password',
  #     password_confirmation: 'password',
  #   )
  # end

  let(:jared) { covered.users.find_by_email_address! '<EMAIL>'  }
  let(:ian)   { covered.users.find_by_email_address! '<EMAIL>'    }
  let(:nicole){ covered.users.find_by_email_address! '<EMAIL>' }
  let(:aaron) { covered.users.find_by_email_address! '<EMAIL>'  }

  def members_table
    all('.members.table tbody tr').map do |tr|
      tr.all('td').first(3).map(&:text)
    end
  end

  scenario %(creating a project) do
    sign_in_as '<EMAIL>'
    visit admin_new_project_path
    fill_in 'Name', with: 'United Nations'
    click_on 'Create Project'
    expect(page).to have_text 'Notice! Project was successfully created.'
    expect(page).to have_text 'Edit project'
    expect(current_url).to eq admin_edit_project_url('united-nations')

    within '.edit-project-form' do
      expect(page).to have_field "Name",                   with: "United Nations"
      expect(page).to have_field "Subject tag",            with: "United Nations"
      expect(page).to have_field "Slug",                   with: "united-nations"
      expect(page).to have_field "Email address username", with: "united.nations"
    end

    project = covered.projects.find_by_name!("United Nations")
    expect(project.name                  ).to eq "United Nations"
    expect(project.subject_tag           ).to eq "United Nations"
    expect(project.slug                  ).to eq "united-nations"
    expect(project.email_address_username).to eq "united.nations"

    within '.edit-project-form' do
      fill_in "Name",                   with: "United Hations"
      fill_in "Subject tag",            with: "United Hations"
      fill_in "Slug",                   with: "united-hations"
      fill_in "Email address username", with: "united.hations"
      click_on 'Update Project'
    end
    expect(page).to have_text 'Notice! Project was successfully updated.'
    project = covered.projects.find_by_name!("United Hations")
    expect(project.name                  ).to eq "United Hations"
    expect(project.subject_tag           ).to eq "United Hations"
    expect(project.slug                  ).to eq "united-hations"
    expect(project.email_address_username).to eq "united.hations"

    expect(project.members.all).to be_empty

    expect(members_table).to eq [["This project has no members."]]

    within '.add-existing-member-form' do
      select '<NAME> <<EMAIL>>', from: 'user[id]'
      click_on 'Add Member'
    end

    expect(members_table).to eq [
      ["<NAME>", "<EMAIL>", "yes"],
    ]
    expect( project.members ).to include nicole

    within '.add-existing-member-form' do
      select '<NAME> <<EMAIL>>', from: 'user[id]'
      uncheck 'Gets email?'
      uncheck 'Send join notice?'
      click_on 'Add Member'
    end

    expect(members_table).to match_array [
      ["<NAME>", "<EMAIL>", "yes"],
      ["<NAME>",      "<EMAIL>",    "no" ],
    ]
    expect( project.members ).to include ian

    assert_background_job_enqueued     SendEmailWorker, args: [covered.env, "join_notice", project.id, nicole.id, nil]
    assert_background_job_not_enqueued SendEmailWorker, args: [covered.env, "join_notice", project.id, ian.id,    nil]

    expect( project.members.find_by_user_id!(nicole.id).gets_email? ).to be_true
    expect( project.members.find_by_user_id!(ian.id   ).gets_email? ).to be_false

    within '.add-new-member-form' do
      fill_in 'Name', with: '<NAME>'
      fill_in 'Email address', with: '<EMAIL>'
      click_on 'Add Member'
    end

    expect(members_table).to match_array [
      ["<NAME>", "<EMAIL>", "yes"],
      ["<NAME>",      "<EMAIL>",    "no" ],
      ["You Face",       "<EMAIL>",     "yes"],
    ]
    you_face = project.members.find_by_user_slug!('you-face')
    expect( you_face.gets_email? ).to be_true
    assert_background_job_enqueued SendEmailWorker, args: [covered.env, "join_notice", project.id, you_face.id, nil]

    within '.add-new-member-form' do
      fill_in 'Name', with: '<NAME>'
      fill_in 'Email address', with: '<EMAIL>'
      uncheck 'Gets email?'
      uncheck 'Send join notice?'
      click_on 'Add Member'
    end

    expect(members_table).to match_array [
      ["<NAME>", "<EMAIL>", "yes"],
      ["<NAME>",      "<EMAIL>",    "no" ],
      ["You Face",       "<EMAIL>",     "yes"],
      ["Someone Else",   "<EMAIL>", "no" ],
    ]
    someone_else = project.members.find_by_user_slug!('someone-else')
    expect( someone_else.gets_email? ).to be_false
    assert_background_job_not_enqueued SendEmailWorker, args: [covered.env, "join_notice", project.id, someone_else.id, nil]

    within first('.members.table tbody tr', text: '<NAME>') do
      click_on 'remove'
      accept_prompt!
    end

    expect(page).to have_text 'Edit project'

    expect(members_table).to match_array [
      ["<NAME>",      "<EMAIL>",    "no" ],
      ["You Face",       "<EMAIL>",     "yes"],
      ["Someone Else",   "<EMAIL>", "no" ],
    ]

    expect( project.members ).to_not include nicole

    visit admin_projects_url
    within('.projects.table tbody tr', text: 'United Hations') do
      click_on 'destroy'
      accept_prompt!
    end
    expect(page).to have_text 'Projects'
    expect(current_url).to eq admin_projects_url
    expect(page).to_not have_text 'United Hations'

  end

end
{'fraction_non_alphanumeric': 0.14089809088464642, 'fraction_numerical': 0.00017925965761405395, 'mean_word_length': 2.84361005856011, 'pattern_counts': {'":': 0, '<': 80, '<?xml version=': 0, '>': 80, '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': '7469984', 'n_tokens_mistral': 3652, 'n_tokens_neox': 3573, 'n_words': 845}