Sha256: d56fa8f99d8e16fbf97e7d5b1f5e679c4a45d8bb2cf0d61317362c8e01d67cff

Contents?: true

Size: 1.27 KB

Versions: 2

Compression:

Stored size: 1.27 KB

Contents

shared_examples 'a friendship model' do

  describe 'custom data' do
    it 'allows for a one-to-one mapping between friendship and a friendship_profile' do
      friendship = custom_popular_model.befriend another_custom_popular_model

      expect( friendship.friendship_profile ).to_not be_nil
    end

    it 'model does not get created unless explicitly opted in' do
      friendship = popular_model.befriend another_popular_model

      expect( friendship.friendship_profile ).to be_nil
    end
  end

  it 'ensures the friend is not the same as the popular_model' do
    invalid_model = described_class.new(
      friend: popular_model,
      popular_model: popular_model
    )

    expect( invalid_model ).to_not be_valid
  end

  it 'validates presence of popular_model' do
    invalid_model = described_class.new friend: popular_model

    expect( invalid_model ).to_not be_valid
  end

  it 'validates uniqueness of friend' do
    popular_model.befriend another_popular_model
    invalid_model = described_class.new popular_model: popular_model, friend: another_popular_model

    expect( invalid_model ).to_not be_valid
  end

  it 'validates presence of friend' do
    invalid_model = described_class.new popular_model: popular_model

    expect( invalid_model ).to_not be_valid
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
popular-0.7.4 spec/popular/friendship_model_spec.rb
popular-0.7.3 spec/popular/friendship_model_spec.rb