<commit_before>require 'rails_helper'

describe InvitationsController, type: :controller do
  it { should use_before_action :verify_current_user_owns_classrooms }
  it { should use_before_action :set_classroom_ids_and_inviteee_email }

  let(:classroom) { create(:classroom) }
  let(:user) { classroom.owner }

  before do
    # It is necessary to load Invitation here explicitly.
    # Otherwise, RSpec will stub Invitation as a Module (rather than an ActiveRecord::Base descendent) 
    # when stub_const is called within a spec.
    # Reference: 
    # https://stackoverflow.com/questions/32563359/stubing-a-model-constant-for-assosiation-undefined-method-relation-delegate-cl
    Invitation.class 
    allow(controller).to receive(:current_user) { user }
  end

  describe '#create_coteacher_invitation' do
    it 'should set the classroom ids' do
      post :create_coteacher_invitation, classroom_ids: [classroom.id], invitee_email: "<EMAIL>"
      expect(assigns(:classroom_ids)).to eq([classroom.id.to_s])
    end

    it 'should give error for invalid email format' do
      post :create_coteacher_invitation, classroom_ids: [classroom.id], invitee_email: "<EMAIL>"
      expect(response.body).to eq({error: "Please make sure you've entered a valid email."}.to_json)
    end

    it 'should give error for empty email' do
      post :create_coteacher_invitation, classroom_ids: [classroom.id], invitee_email: ""
      expect(response.body).to eq({error: "Please make sure you've entered a valid email and selected at least one classroom."}.to_json)
    end
<commit_msg>fixing intermittently failing specs (#7419)<commit_after>require 'rails_helper'

describe InvitationsController, type: :controller do
  it { should use_before_action :verify_current_user_owns_classrooms }
  it { should use_before_action :set_classroom_ids_and_inviteee_email }

  let(:classroom) { create(:classroom) }
  let(:user) { classroom.owner }

  before(:each) do
    # It is necessary to load Invitation here explicitly.
    # Otherwise, RSpec will stub Invitation as a Module (rather than an ActiveRecord::Base descendent) 
    # when stub_const is called within a spec.
    # Reference: 
    # https://stackoverflow.com/questions/32563359/stubing-a-model-constant-for-assosiation-undefined-method-relation-delegate-cl
    # rubocop:disable all
    CoteacherClassroomInvitation
    # rubocop:enable all
    allow(controller).to receive(:current_user) { user }
  end

  describe '#create_coteacher_invitation' do
    it 'should set the classroom ids' do
      post :create_coteacher_invitation, classroom_ids: [classroom.id], invitee_email: "<EMAIL>"
      expect(assigns(:classroom_ids)).to eq([classroom.id.to_s])
    end

    it 'should give error for invalid email format' do
      post :create_coteacher_invitation, classroom_ids: [classroom.id], invitee_email: "<EMAIL>"
      expect(response.body).to eq({error: "Please make sure you've entered a valid email."}.to_json)
    end

    it 'should give error for empty email' do
      post :create_coteacher_invitation, classroom_ids: [classroom.id], invitee_email: ""
      expect(response.body).to eq({error: "Please make sure you've entered a valid email and selected at least one classroom."}.to_json)
    end

{'fraction_non_alphanumeric': 0.09493087557603687, 'fraction_numerical': 0.006144393241167435, 'mean_word_length': 4.39966832504146, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 2, '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': '6540962', 'n_tokens_mistral': 1008, 'n_tokens_neox': 968, 'n_words': 270}