<commit_before>require 'application_system_test_case'

class TrialFeedbacksTest < ApplicationSystemTestCase
  def setup
    @user_volunteer = create :user_volunteer, email: '<EMAIL>'
    @volunteer = create :volunteer, user: @user_volunteer
    @assignment = create :assignment, volunteer: @volunteer
    @superadmin = create :user
    @other_volunteer = create :volunteer_with_user
    @group_offer = create :group_offer, title: 'some_group_offer',
      volunteers: [@volunteer, @other_volunteer]
  end

  def setup_feedbacks
    @assignment_volunteer_feedback = create :trial_feedback, volunteer: @volunteer,
      author: @user_volunteer, trial_feedbackable: @assignment,
      body: 'author_volunteer_assignment_feedback'
    create :trial_feedback, trial_feedbackable: @assignment,
      volunteer: @volunteer, author: @superadmin, body: 'author_superadmin_assignment_feedback'
    create :trial_feedback, trial_feedbackable: @group_offer, author: @user_volunteer,
      volunteer: @volunteer, body: 'author_volunteer_group_offer_feedback'
    create :trial_feedback, trial_feedbackable: @group_offer, author: @superadmin,
      volunteer: @volunteer, body: 'author_superadmin_group_offer_feedback'
    create :trial_feedback, volunteer: @other_volunteer, trial_feedbackable: @group_offer,
      author: @superadmin, body: 'author_other_volunteer_group_offer_feedback'
  end

  test 'volunteer_can_see_assignment_trial_feedbacks_index' do
    setup_feedbacks
    login_as @user_volunteer
    visit root_url
    within '.navbar-top' do
      click_link I18n.t("role.#{@user_volunteer.role}"), href: '#'
    end
    click_link 'Profil anzeigen'
    within '.assignments-table' do
      click_link 'Probezeit Feedback index'
    end
    refute page.has_text? 'author_superadmin_assignment_feedback'
    assert page.has_text? 'author_volunteer_assignment_feedback'
  end

  test 'volunteer_can_see_group_offer_trial_feedbacks_index' do
    setup_feedbacks
    login_as @user_volunteer
    visit root_url
    within '.navbar-top' do
      click_link I18n.t("role.#{@user_volunteer.role}"), href: '#'
    end
    click_link 'Profil anzeigen'
    within '.group-assignments-table' do
      click_link 'Probezeit Feedback index'
    end
    refute page.has_text? 'author_superadmin_group_offer_feedback'
    assert page.has_text? 'author_volunteer_group_offer_feedback'
  end

  test 'assignment_trial_feedback_index_contains_only_the_feedbacks_of_one_assignment' do
    setup_feedbacks
    login_as @user_volunteer
    visit polymorphic_path([@volunteer, @assignment, @assignment_volunteer_feedback])
    click_link 'Zurück'
    within '.assignments-table' do
      click_link 'Probezeit Feedback index'
    end
    refute page.has_text? 'author_superadmin_assignment_feedback'
    assert page.has_text? 'author_volunteer_assignment_feedback'
  end

  test 'group_offer_trial_feedbacks_index_contains_only_feedbacks_related_to_that_group_offer' do
    setup_feedbacks
    other_group_offer = create :group_offer, title: 'some_other_group_offer',
      volunteers: [@volunteer, @other_volunteer]
    create :trial_feedback, volunteer: @volunteer, trial_feedbackable: other_group_offer,
      author: @user_volunteer, body: 'same_volunteer_other_groupoffer_feedback'
    login_as @user_volunteer
    visit polymorphic_path([@volunteer, @group_offer, TrialFeedback])
    assert page.has_text? 'author_volunteer_group_offer_feedback'
    refute page.has_text? 'author_superadmin_group_offer_feedback'
    refute page.has_text? 'author_other_volunteer_group_offer_feedback'
    refute page.has_text? 'same_volunteer_other_groupoffer_feedback'
    login_as @superadmin
    visit polymorphic_path([@volunteer, @group_offer, TrialFeedback])
    assert page.has_text? 'author_volunteer_group_offer_feedback'
    assert page.has_text? 'author_superadmin_group_offer_feedback'
    assert page.has_text? 'author_other_volunteer_group_offer_feedback'
    refute page.has_text? 'same_volunteer_other_groupoffer_feedback'
  end

  test 'assignment_trial_feedbacks_index_contains_only_the_feedbacks_related_to_that_assignment' do
    setup_feedbacks
    other_assignment = create :assignment, volunteer: @volunteer
    create :trial_feedback, trial_feedbackable: other_assignment, volunteer: @volunteer,
      author: @user_volunteer, body: 'same_volunteer_other_assignment_feedback'
    login_as @user_volunteer
    visit polymorphic_path([@volunteer, @assignment, TrialFeedback])
    assert page.has_text? 'author_volunteer_assignment_feedback'
    refute page.has_text? 'author_superadmin_assignment_feedback'
    refute page.has_text? 'same_volunteer_other_assignment_feedback'
    login_as @superadmin
    visit polymorphic_path([@volunteer, @assignment, TrialFeedback])
    assert page.has_text? 'author_volunteer_assignment_feedback'
    assert page.has_text? 'author_superadmin_assignment_feedback'
    refute page.has_text? 'same_volunteer_other_assignment_feedback'
  end

  test 'volunteer_can_create_only_their_trial_feedbacks_on_assignment' do
    other_assignment = create :assignment,
      volunteer: create(:volunteer, user: create(:user_volunteer))
    login_as @user_volunteer
    visit new_polymorphic_path([@volunteer, other_assignment, TrialFeedback])
    assert page.has_text? 'You are not authorized to perform this action.'
  end

  test 'volunteer_can_create_only_their_trial_feedbacks_on_group_offer' do
    other_group_offer = create :group_offer, title: 'other_group_offer',
      volunteers: [
        create(:volunteer, user: create(:user_volunteer)),
        create(:volunteer, user: create(:user_volunteer))
      ]
    login_as @user_volunteer
    visit new_polymorphic_path([@volunteer, other_group_offer, TrialFeedback])
    assert page.has_text? 'You are not authorized to perform this action.'
  end

  test 'create_new_assignment_trial_feedback_as_volunteer' do
    login_as @user_volunteer
    play_create_new_assignment_feedback
  end

  test 'create_new_assignment_trial_feedback_as_superadmin' do
    login_as @superadmin
    play_create_new_assignment_feedback
  end

  test 'create_new_group_offer_trial_feedback_as_volunteer' do
    login_as @user_volunteer
    play_create_new_group_offer_feedback
  end

  test 'create_new_group_offer_trial_feedback_as_superadmin' do
    login_as @superadmin
    play_create_new_group_offer_feedback
  end

  def play_create_new_assignment_feedback
    visit volunteer_path(@volunteer)
    within '.assignments-table' do
      click_link 'New Probezeit Feedback'
    end
    fill_in 'Text', with: 'Probezeit assignment feedback text'
    click_button 'Create Probezeit Feedback'
    assert page.has_text? 'Probezeit Feedback was successfully created.'
    within '.assignments-table' do
      click_link 'Probezeit Feedback index'
    end
    click_link 'Show'
    assert page.has_text? 'Probezeit assignment feedback text'
  end

  def play_create_new_group_offer_feedback
    visit volunteer_path(@volunteer)
    within '.group-assignments-table' do
      click_link 'New Probezeit Feedback'
    end
    fill_in 'Text', with: 'Probezeit group assignment feedback text'
    click_button 'Create Probezeit Feedback'
    assert page.has_text? 'Probezeit Feedback was successfully created.'
    within '.group-assignments-table' do
      click_link 'Probezeit Feedback index'
    end
    click_link 'Show'
    assert page.has_text? 'Probezeit group assignment feedback text'
  end
end
<commit_msg>use rack driver for all runs in trial_feedbacks_test<commit_after>require 'application_system_test_case'

class TrialFeedbacksTest < ApplicationSystemTestCase
  def setup
    use_rack_driver
    @user_volunteer = create :user_volunteer, email: '<EMAIL>'
    @volunteer = create :volunteer, user: @user_volunteer
    @assignment = create :assignment, volunteer: @volunteer
    @superadmin = create :user
    @other_volunteer = create :volunteer_with_user
    @group_offer = create :group_offer, title: 'some_group_offer',
      volunteers: [@volunteer, @other_volunteer]
  end

  def setup_feedbacks
    @assignment_volunteer_feedback = create :trial_feedback, volunteer: @volunteer,
      author: @user_volunteer, trial_feedbackable: @assignment,
      body: 'author_volunteer_assignment_feedback'
    create :trial_feedback, trial_feedbackable: @assignment,
      volunteer: @volunteer, author: @superadmin, body: 'author_superadmin_assignment_feedback'
    create :trial_feedback, trial_feedbackable: @group_offer, author: @user_volunteer,
      volunteer: @volunteer, body: 'author_volunteer_group_offer_feedback'
    create :trial_feedback, trial_feedbackable: @group_offer, author: @superadmin,
      volunteer: @volunteer, body: 'author_superadmin_group_offer_feedback'
    create :trial_feedback, volunteer: @other_volunteer, trial_feedbackable: @group_offer,
      author: @superadmin, body: 'author_other_volunteer_group_offer_feedback'
  end

  test 'volunteer_can_see_assignment_trial_feedbacks_index' do
    setup_feedbacks
    login_as @user_volunteer
    visit root_url
    within '.navbar-top' do
      click_link I18n.t("role.#{@user_volunteer.role}"), href: '#'
    end
    click_link 'Profil anzeigen'
    within '.assignments-table' do
      click_link 'Probezeit Feedback index'
    end
    refute page.has_text? 'author_superadmin_assignment_feedback'
    assert page.has_text? 'author_volunteer_assignment_feedback'
  end

  test 'volunteer_can_see_group_offer_trial_feedbacks_index' do
    setup_feedbacks
    login_as @user_volunteer
    visit root_url
    within '.navbar-top' do
      click_link I18n.t("role.#{@user_volunteer.role}"), href: '#'
    end
    click_link 'Profil anzeigen'
    within '.group-assignments-table' do
      click_link 'Probezeit Feedback index'
    end
    refute page.has_text? 'author_superadmin_group_offer_feedback'
    assert page.has_text? 'author_volunteer_group_offer_feedback'
  end

  test 'assignment_trial_feedback_index_contains_only_the_feedbacks_of_one_assignment' do
    setup_feedbacks
    login_as @user_volunteer
    visit polymorphic_path([@volunteer, @assignment, @assignment_volunteer_feedback])
    click_link 'Zurück'
    within '.assignments-table' do
      click_link 'Probezeit Feedback index'
    end
    refute page.has_text? 'author_superadmin_assignment_feedback'
    assert page.has_text? 'author_volunteer_assignment_feedback'
  end

  test 'group_offer_trial_feedbacks_index_contains_only_feedbacks_related_to_that_group_offer' do
    setup_feedbacks
    other_group_offer = create :group_offer, title: 'some_other_group_offer',
      volunteers: [@volunteer, @other_volunteer]
    create :trial_feedback, volunteer: @volunteer, trial_feedbackable: other_group_offer,
      author: @user_volunteer, body: 'same_volunteer_other_groupoffer_feedback'
    login_as @user_volunteer
    visit polymorphic_path([@volunteer, @group_offer, TrialFeedback])
    assert page.has_text? 'author_volunteer_group_offer_feedback'
    refute page.has_text? 'author_superadmin_group_offer_feedback'
    refute page.has_text? 'author_other_volunteer_group_offer_feedback'
    refute page.has_text? 'same_volunteer_other_groupoffer_feedback'
    login_as @superadmin
    visit polymorphic_path([@volunteer, @group_offer, TrialFeedback])
    assert page.has_text? 'author_volunteer_group_offer_feedback'
    assert page.has_text? 'author_superadmin_group_offer_feedback'
    assert page.has_text? 'author_other_volunteer_group_offer_feedback'
    refute page.has_text? 'same_volunteer_other_groupoffer_feedback'
  end

  test 'assignment_trial_feedbacks_index_contains_only_the_feedbacks_related_to_that_assignment' do
    setup_feedbacks
    other_assignment = create :assignment, volunteer: @volunteer
    create :trial_feedback, trial_feedbackable: other_assignment, volunteer: @volunteer,
      author: @user_volunteer, body: 'same_volunteer_other_assignment_feedback'
    login_as @user_volunteer
    visit polymorphic_path([@volunteer, @assignment, TrialFeedback])
    assert page.has_text? 'author_volunteer_assignment_feedback'
    refute page.has_text? 'author_superadmin_assignment_feedback'
    refute page.has_text? 'same_volunteer_other_assignment_feedback'
    login_as @superadmin
    visit polymorphic_path([@volunteer, @assignment, TrialFeedback])
    assert page.has_text? 'author_volunteer_assignment_feedback'
    assert page.has_text? 'author_superadmin_assignment_feedback'
    refute page.has_text? 'same_volunteer_other_assignment_feedback'
  end

  test 'volunteer_can_create_only_their_trial_feedbacks_on_assignment' do
    other_assignment = create :assignment,
      volunteer: create(:volunteer, user: create(:user_volunteer))
    login_as @user_volunteer
    visit new_polymorphic_path([@volunteer, other_assignment, TrialFeedback])
    assert page.has_text? 'You are not authorized to perform this action.'
  end

  test 'volunteer_can_create_only_their_trial_feedbacks_on_group_offer' do
    other_group_offer = create :group_offer, title: 'other_group_offer',
      volunteers: [
        create(:volunteer, user: create(:user_volunteer)),
        create(:volunteer, user: create(:user_volunteer))
      ]
    login_as @user_volunteer
    visit new_polymorphic_path([@volunteer, other_group_offer, TrialFeedback])
    assert page.has_text? 'You are not authorized to perform this action.'
  end

  test 'create_new_assignment_trial_feedback_as_volunteer' do
    login_as @user_volunteer
    play_create_new_assignment_feedback
  end

  test 'create_new_assignment_trial_feedback_as_superadmin' do
    login_as @superadmin
    play_create_new_assignment_feedback
  end

  test 'create_new_group_offer_trial_feedback_as_volunteer' do
    login_as @user_volunteer
    play_create_new_group_offer_feedback
  end

  test 'create_new_group_offer_trial_feedback_as_superadmin' do
    login_as @superadmin
    play_create_new_group_offer_feedback
  end

  def play_create_new_assignment_feedback
    visit volunteer_path(@volunteer)
    within '.assignments-table' do
      click_link 'New Probezeit Feedback'
    end
    fill_in 'Text', with: 'Probezeit assignment feedback text'
    click_button 'Create Probezeit Feedback'
    assert page.has_text? 'Probezeit Feedback was successfully created.'
    within '.assignments-table' do
      click_link 'Probezeit Feedback index'
    end
    click_link 'Show'
    assert page.has_text? 'Probezeit assignment feedback text'
  end

  def play_create_new_group_offer_feedback
    visit volunteer_path(@volunteer)
    within '.group-assignments-table' do
      click_link 'New Probezeit Feedback'
    end
    fill_in 'Text', with: 'Probezeit group assignment feedback text'
    click_button 'Create Probezeit Feedback'
    assert page.has_text? 'Probezeit Feedback was successfully created.'
    within '.group-assignments-table' do
      click_link 'Probezeit Feedback index'
    end
    click_link 'Show'
    assert page.has_text? 'Probezeit group assignment feedback text'
  end
end

{'fraction_non_alphanumeric': 0.06902997529875159, 'fraction_numerical': 0.0005340810467988517, 'mean_word_length': 5.286193873268989, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '348257', 'n_tokens_mistral': 5127, 'n_tokens_neox': 4821, 'n_words': 962}