<commit_before>require 'rails_helper'

describe Membership do
  let(:membership) { Membership.new }
  let(:user) { create(:user) }
  let(:user2) { create(:user) }
  let(:group) { create(:group, is_visible_to_public: true) }

  it { should have_many(:events).dependent(:destroy) }

  describe "validation" do
    it "cannot have duplicate memberships" do
      create(:membership, :user => user, :group => group)
      membership.user = user
      membership.group = group
      membership.valid?
      membership.errors_on(:user_id).should include("has already been taken")
    end

    it "membership_count should be less than the group max_size" do
      group.max_size = 1
      group.memberships_count = 1
      group.save
      expect { group.add_member!(user) }.to raise_error
    end
  end

  it "can have an inviter" do
    membership = user.memberships.new(:group_id => group.id)
    membership.inviter = user2
    membership.save!
    expect(membership.inviter).to eq user2
  end

  context "destroying a membership" do
    before do
      @membership = group.add_member! user
    end

    it "removes subgroup memberships if parent is hidden" do
      group.is_visible_to_public = false
      group.save
      subgroup = create(:group, parent: group, is_visible_to_public: false)
      subgroup.add_member! user
      group.reload
      @membership.reload
      @membership.destroy
      subgroup.users.should_not include(user)
    end

    it "doesn't remove subgroup memberships if parent is not hidden" do
      subgroup = create(:group, parent: group)
      subgroup.add_member! user
      group.reload<commit_msg>remove spec for removed dumb idea<commit_after>require 'rails_helper'

describe Membership do
  let(:membership) { Membership.new }
  let(:user) { create(:user) }
  let(:user2) { create(:user) }
  let(:group) { create(:group, is_visible_to_public: true) }

  it { should have_many(:events).dependent(:destroy) }

  describe "validation" do
    it "cannot have duplicate memberships" do
      create(:membership, :user => user, :group => group)
      membership.user = user
      membership.group = group
      membership.valid?
      membership.errors_on(:user_id).should include("has already been taken")
    end
  end

  it "can have an inviter" do
    membership = user.memberships.new(:group_id => group.id)
    membership.inviter = user2
    membership.save!
    expect(membership.inviter).to eq user2
  end

  context "destroying a membership" do
    before do
      @membership = group.add_member! user
    end

    it "removes subgroup memberships if parent is hidden" do
      group.is_visible_to_public = false
      group.save
      subgroup = create(:group, parent: group, is_visible_to_public: false)
      subgroup.add_member! user
      group.reload
      @membership.reload
      @membership.destroy
      subgroup.users.should_not include(user)
    end

    it "doesn't remove subgroup memberships if parent is not hidden" do
      subgroup = create(:group, parent: group)
      subgroup.add_member! user
      group.reload
{'fraction_non_alphanumeric': 0.093841642228739, 'fraction_numerical': 0.002606712284131639, 'mean_word_length': 3.188267394270123, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '6621581', 'n_tokens_mistral': 936, 'n_tokens_neox': 917, 'n_words': 256}