<commit_before>require 'rails_helper'

RSpec.describe SubmissionsController, type: :controller do
  # GET new just displays a view.
  # Use view or request specs

  let!(:contest) { Contest.create }
  let!(:team)    { contest.teams.create }

  describe 'POST create' do
    FIXTURE_NAME = 'Submission.java'

    let(:file) { fixture_file_upload 'files/' + FIXTURE_NAME }
    let(:problem) { contest.problems.create }
    let(:valid_params) { { submission: { attachment: file, problem: problem.id } } }

    it 'rejects submission without file' do
      puts Submission.count
      expect {
        post :create, params: { submission: { problem_id: problem.id } }
      }.not_to change(Submission, :count)

      expect(response).to have_http_status :ok
      expect(flash.alert).not_to be_empty
    end

    it 'rejects submission without problem' do
      expect {
        post :create, params: { submission: { file: file } }
      }.not_to change(Submission, :count)

      expect(response).to have_http_status :ok
      expect(flash.alert).not_to be_empty
    end

    it 'reject submission if contest is not started'
    it 'rejects submission if team not logged in'

    describe 'with valid data' do
      # TODO: Start contest

      it 'creates the Submission' do
        expect {
          post :create, params: valid_params
        }.to change(Submission, :count).by(1)
      end

      let(:submission) { Submission.last }

      it 'redirects to show' do
        post :create, params: valid_params
        expect(submission).to be_a Submission
        expect(response).to redirect_to submission_url(submission)
      end

      it 'submits to correct problem' do<commit_msg>Delete Submission files after each test<commit_after>require 'rails_helper'

RSpec.describe SubmissionsController, type: :controller do
  # GET new just displays a view.
  # Use view or request specs

  let!(:contest) { Contest.create }
  let!(:team)    { contest.teams.create }

  describe 'POST create' do
    FIXTURE_NAME = 'Submission.java'

    let(:file) { fixture_file_upload 'files/' + FIXTURE_NAME }
    let(:problem) { contest.problems.create }
    let(:valid_params) { { submission: { attachment: file, problem: problem.id } } }

    it 'rejects submission without file' do
      puts Submission.count
      expect {
        post :create, params: { submission: { problem_id: problem.id } }
      }.not_to change(Submission, :count)

      expect(response).to have_http_status :ok
      expect(flash.alert).not_to be_empty
    end

    it 'rejects submission without problem' do
      expect {
        post :create, params: { submission: { file: file } }
      }.not_to change(Submission, :count)

      expect(response).to have_http_status :ok
      expect(flash.alert).not_to be_empty
    end

    it 'reject submission if contest is not started'
    it 'rejects submission if team not logged in'

    describe 'with valid data' do
      # TODO: Start contest

      it 'creates the Submission' do
        expect {
          post :create, params: valid_params
        }.to change(Submission, :count).by(1)
      end

      let(:submission) { Submission.last }

      after(:each) { submission.attachment.path.delete }

      it 'redirects to show' do
        post :create, params: valid_params
        expect(submission).to be_a Submission
        expect(response).to redirect_to submission_url(submission)
      end

      it 'submits to correct problem' do
{'fraction_non_alphanumeric': 0.0954861111111111, 'fraction_numerical': 0.0005787037037037037, 'mean_word_length': 2.8668903803131993, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6194565', 'n_tokens_mistral': 1047, 'n_tokens_neox': 999, 'n_words': 302}