<commit_before>require 'rails_helper'

RSpec.describe Offspring, type: :model do
  let(:child) { FactoryGirl.build(:offspring) }
  it "has a valid factory" do
    expect(child).to be_valid
  end

  it "is invalid without a name" do
    child.first_name = nil
    expect(child).not_to be_valid
    child.valid?
    expect(child.errors[:first_name]).to include("no puede estar vacío")
  end

  it "is invalid without a surname" do
    child.last_name = nil
    expect(child).not_to be_valid
    child.valid?
    expect(child.errors[:last_name]).to include("no puede estar vacío")
  end

  it "should have the same surname than the brothers" do
    child.save
    brother = FactoryGirl.build(:offspring, user: child.user, last_name: "aaassssddd")
    brother.valid?
    expect(brother.errors[:last_name]).to include("tiene que coincidir con el de sus hermanos")
  end

  it "is invalid wihout an course" do
    child.grade = nil
    expect(child).not_to be_valid
    child.valid?
    expect(child.errors[:grade]).to include("no puede estar vacío")
  end

  it 'is in any grade' do
    Offspring.grades.keys.each do |i|
      child.grade = i
      expect(child).to be_valid
    end
  end

  it "is invalid without a user associated" do
    child.user = nil
    expect(child).not_to be_valid
  end

  it "is destroyed when the user associated is" do
    child = FactoryGirl.create(:offspring)
    expect { child.user.destroy! }.to change { Offspring.count }.by(-1)
  end
end<commit_msg>Improvements in spec for offspring model<commit_after>require 'rails_helper'

RSpec.describe Offspring, type: :model do
  let(:child) { FactoryGirl.build(:offspring) }
  it "has a valid factory" do
    expect(child).to be_valid
  end

  it "is invalid without a name" do
    child.first_name = nil
    child.valid?
    expect(child.errors[:first_name]).to include("no puede estar vacío")
  end

  it "is invalid without a surname" do
    child.last_name = nil
    child.valid?
    expect(child.errors[:last_name]).to include("no puede estar vacío")
  end

  it "should have the same surname than the brothers" do
    child.save
    brother = FactoryGirl.build(:offspring, user: child.user, last_name: "aaassssddd")
    brother.valid?
    expect(brother.errors[:last_name]).to include("tiene que coincidir con el de sus hermanos")
  end

  it "is invalid wihout a grade" do
    child.grade = nil
    expect(child.errors[:grade]).to include("no puede estar vacío")
  end

  it 'is in any grade' do
    Offspring.grades.keys.each do |i|
      child.grade = i
      expect(child).to be_valid
    end
  end

  it "is invalid with grades that don't belong to the grade list" do
    expect { child.grade = 100 }.to raise_error(ArgumentError).with_message(/is not a valid grade/)
  end

  it "is invalid without a user associated" do
    child.user = nil
    expect(child.errors[:user]).to include("no puede faltar")
  end

  it "is destroyed when the user associated is" do
    child = FactoryGirl.create(:offspring)
    expect { child.user.destroy! }.to change { Offspring.count }.by(-1)
  end
end
{'fraction_non_alphanumeric': 0.1015625, 'fraction_numerical': 0.0016276041666666667, 'mean_word_length': 3.3712660028449504, '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': '4096346', 'n_tokens_mistral': 1004, 'n_tokens_neox': 968, 'n_words': 316}