<commit_before>require_relative '../spec_helper'

describe User do
  it "should describe the right role" do
    u_admin = FactoryGirl.build(:user, :role => 2)
    u_super = FactoryGirl.build(:user, :role => 1)
    u_participant = FactoryGirl.build(:user, :role => 0)

    u_admin.is_supervisor?.should       be_true
    u_admin.is_admin?.should            be_true
    u_super.is_supervisor?.should       be_true
    u_super.is_admin?.should            be_false
    u_participant.is_supervisor?.should be_false
    u_participant.is_admin?.should      be_false
  end

  it "should be able to determine if a user can send a message to followers" do
    kees = FactoryGirl.create(:user, :email => "<EMAIL>")
    daan = FactoryGirl.create(:user, :email => "<EMAIL>")
    lina = FactoryGirl.create(:user, :email => "<EMAIL>")

    kees.followers << [lina, daan]
    lina.followers << [kees, daan]

    kees.can_send_message_to_user?(daan).should be_true
    lina.can_send_message_to_user?(daan).should be_true
    daan.can_send_message_to_user?(kees).should be_false
  end

  it "should be able to determine if a user can send a message to a user in same challenge" do
    kees = FactoryGirl.create(:user, :email => "<EMAIL>")
    daan = FactoryGirl.create(:user, :email => "<EMAIL>")
    lina = FactoryGirl.create(:user, :email => "<EMAIL>")

    koek_challenge = FactoryGirl.create(:challenge)
    data_challenge = FactoryGirl.create(:challenge)

    kees.participating_challenges << koek_challenge
    lina.participating_challenges << [koek_challenge, data_challenge]
    daan.participating_challenges << data_challenge

    kees.can_send_message_to_user?(daan).should be_false
    kees.can_send_message_to_user?(lina).should be_true
    lina.can_send_message_to_user?(daan).should be_true
    lina.can_send_message_to_user?(kees).should be_true
    daan.can_send_message_to_user?(lina).should be_true
  end

  it "should be able to determine if a user can send a message to a challenge" do
    kees = FactoryGirl.create(:user, :email => "<EMAIL>", :role => 1)
    daan = FactoryGirl.create(:user, :email => "<EMAIL>", :role => 1)

    koek_challenge = FactoryGirl.create(:challenge, :supervisor => kees)
    data_challenge = FactoryGirl.create(:challenge, :supervisor => daan)

    kees.can_send_message_to_participants?(koek_challenge).should be_true
    daan.can_send_message_to_participants?(data_challenge).should be_true
    daan.can_send_message_to_participants?(koek_challenge).should be_false
  end<commit_msg>Changes rspec to comply with new message rules<commit_after>require_relative '../spec_helper'

describe User do
  it "should describe the right role" do
    u_admin = FactoryGirl.build(:user, :role => 2)
    u_super = FactoryGirl.build(:user, :role => 1)
    u_participant = FactoryGirl.build(:user, :role => 0)

    u_admin.is_supervisor?.should       be_true
    u_admin.is_admin?.should            be_true
    u_super.is_supervisor?.should       be_true
    u_super.is_admin?.should            be_false
    u_participant.is_supervisor?.should be_false
    u_participant.is_admin?.should      be_false
  end

  it "should be able to determine if a user can send a message to followers" do
    kees = FactoryGirl.create(:user, :email => "<EMAIL>")
    daan = FactoryGirl.create(:user, :email => "<EMAIL>")
    lina = FactoryGirl.create(:user, :email => "<EMAIL>")

    kees.followers << [lina, daan]
    lina.followers << [kees, daan]

    kees.can_send_message_to_user?(daan).should be_true
    lina.can_send_message_to_user?(daan).should be_true
    # daan.can_send_message_to_user?(kees).should be_false
    daan.can_send_message_to_user?(kees).should be_true
  end

  it "should be able to determine if a user can send a message to a user in same challenge" do
    kees = FactoryGirl.create(:user, :email => "<EMAIL>")
    daan = FactoryGirl.create(:user, :email => "<EMAIL>")
    lina = FactoryGirl.create(:user, :email => "<EMAIL>")

    koek_challenge = FactoryGirl.create(:challenge)
    data_challenge = FactoryGirl.create(:challenge)

    kees.participating_challenges << koek_challenge
    lina.participating_challenges << [koek_challenge, data_challenge]
    daan.participating_challenges << data_challenge

    # kees.can_send_message_to_user?(daan).should be_false
    kees.can_send_message_to_user?(daan).should be_true
    kees.can_send_message_to_user?(lina).should be_true
    lina.can_send_message_to_user?(daan).should be_true
    lina.can_send_message_to_user?(kees).should be_true
    daan.can_send_message_to_user?(lina).should be_true
  end

  it "should be able to determine if a user can send a message to a challenge" do
    kees = FactoryGirl.create(:user, :email => "<EMAIL>", :role => 1)
    daan = FactoryGirl.create(:user, :email => "<EMAIL>", :role => 1)

    koek_challenge = FactoryGirl.create(:challenge, :supervisor => kees)
    data_challenge = FactoryGirl.create(:challenge, :supervisor => daan)

    kees.can_send_message_to_participants?(koek_challenge).should be_true
    daan.can_send_message_to_participants?(data_challenge).should be_true
    daan.can_send_message_to_participants?(koek_challenge).should be_false
  end
{'fraction_non_alphanumeric': 0.11040339702760085, 'fraction_numerical': 0.0019301293186643506, 'mean_word_length': 4.234343434343434, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 49, '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': '1040781', 'n_tokens_mistral': 1845, 'n_tokens_neox': 1701, 'n_words': 362}