<commit_before># frozen_string_literal: true

# == Schema Information
#
# Table name: groups
#
#  id          :integer          not null, primary key
#  name        :string
#  created_at  :datetime
#  updated_at  :datetime
#  description :text
#  slug        :string
#

describe Group do
  it 'creates a group' do
    new_group = create(:group, description: 'Test Description')
    expect(Group.count).to eq(1)
  end

  it 'does not create a group' do
    new_group = build(:bad_group)
    expect(new_group).to have(1).error_on(:description)
  end

  describe '#led_by?' do
    context 'when user is not a leader of the group' do
      it 'returns false' do
        user = create :user1
        group = create :group_with_member, user_id: user.id, leader: false

        result = group.led_by?(user)

        expect(result).to be false
      end
    end

    context 'when user is a leader of the group' do
      it 'returns true' do
        user = create :user1
        group = create :group_with_member, user_id: user.id, leader: true

        result = group.led_by?(user)

        expect(result).to be true
      end
    end
  end

  describe '#member?' do
    context 'when user is not a member of the group' do
      it 'returns false' do
        user = create :user1
        group = create :group_with_member

        result = group.member?(user)

        expect(result).to be false
      end
    end

    context 'when user is a member of the group' do
      it 'returns true' do
        user = create :user1
        group = create :group_with_member, user_id: user.id

        result = group.member?(user)

        expect(result).to be true
      end<commit_msg>Fix flakey group spec (#1146)<commit_after># frozen_string_literal: true

# == Schema Information
#
# Table name: groups
#
#  id          :integer          not null, primary key
#  name        :string
#  created_at  :datetime
#  updated_at  :datetime
#  description :text
#  slug        :string
#

describe Group do
  it 'creates a group' do
    new_group = create(:group, description: 'Test Description')
    expect(Group.count).to eq(1)
  end

  it 'does not create a group' do
    new_group = build(:bad_group)
    expect(new_group).to have(1).error_on(:description)
  end

  describe '#led_by?' do
    context 'when user is not a leader of the group' do
      it 'returns false' do
        user = create :user1
        group = create :group_with_member, user_id: user.id, leader: false

        result = group.led_by?(user)

        expect(result).to be false
      end
    end

    context 'when user is a leader of the group' do
      it 'returns true' do
        user = create :user1
        group = create :group_with_member, user_id: user.id, leader: true

        result = group.led_by?(user)

        expect(result).to be true
      end
    end
  end

  describe '#member?' do
    context 'when user is not a member of the group' do
      it 'returns false' do
        member_user = create :user
        non_member_user = create :user1
        group = create :group_with_member, user_id: member_user.id

        result = group.member?(non_member_user)

        expect(result).to be false
      end
    end

    context 'when user is a member of the group' do
      it 'returns true' do
        user = create :user1
        group = create :group_with_member, user_id: user.id

        result = group.member?(user)

        expect(result).to be true
      end
{'fraction_non_alphanumeric': 0.08493310063990692, 'fraction_numerical': 0.004653868528214078, 'mean_word_length': 2.3259187620889747, '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': '5738246', 'n_tokens_mistral': 1060, 'n_tokens_neox': 1035, 'n_words': 364}