<commit_before>require 'rails_helper'

describe Leagues::Matches::CommsController do
  let(:user) { create(:user) }
  let(:match) { create(:league_match) }

  describe 'POST #create' do
    it 'succeeds for authorized user' do
      user.grant(:edit, match.home_team.team)
      sign_in user

      post :create, params: { league_id: match.league.id, match_id: match.id, comm: { content: 'A' } }

      comm = match.comms.first
      expect(comm).to_not be nil
      expect(comm.match).to eq(match)
      expect(comm.content).to eq('A')
    end

    it 'fails with invalid data' do
      user.grant(:edit, match.home_team.team)
      sign_in user

      post :create, params: { league_id: match.league.id, match_id: match.id, comm: { content: nil } }

      expect(match.comms.first).to be(nil)
    end

    it 'fails for unauthorized user' do
      sign_in user

      post :create, params: { league_id: match.league.id, match_id: match.id, comm: { content: 'A' } }

      expect(match.comms.first).to be(nil)
    end
  end
end<commit_msg>Rubocop<commit_after>require 'rails_helper'

describe Leagues::Matches::CommsController do
  let(:user) { create(:user) }
  let(:match) { create(:league_match) }

  describe 'POST #create' do
    it 'succeeds for authorized user' do
      user.grant(:edit, match.home_team.team)
      sign_in user

      post :create, params: {
        league_id: match.league.id, match_id: match.id, comm: { content: 'A' }
      }

      comm = match.comms.first
      expect(comm).to_not be nil
      expect(comm.match).to eq(match)
      expect(comm.content).to eq('A')
    end

    it 'fails with invalid data' do
      user.grant(:edit, match.home_team.team)
      sign_in user

      post :create, params: {
        league_id: match.league.id, match_id: match.id, comm: { content: nil }
      }

      expect(match.comms.first).to be(nil)
    end

    it 'fails for unauthorized user' do
      sign_in user

      post :create, params: {
        league_id: match.league.id, match_id: match.id, comm: { content: 'A' }
      }

      expect(match.comms.first).to be(nil)
    end
  end
end
{'fraction_non_alphanumeric': 0.1266540642722117, 'fraction_numerical': 0.0, 'mean_word_length': 2.7736185383244205, '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': '2765770', 'n_tokens_mistral': 750, 'n_tokens_neox': 710, 'n_words': 177}