<commit_before>require 'spec_helper'

describe Group do
  it { should belong_to :branch }
  it { should have_many :srpms }
  it { should have_many :packages }

  it { should validate_presence_of :branch }
  it { should validate_presence_of :name }

  it { should have_db_index :branch_id }

  it "should return full group name on #full_name" do
    branch = Branch.create!(:name => 'Sisyphus', :vendor => 'ALT Linux')
    Group.import_group(branch, 'System/Configuration/Boot and Init')
    Group.all.last.full_name.should == 'System/Configuration/Boot and Init'
  end

  it "should import group 'Shells'" do
    branch = Branch.create!(:name => 'Sisyphus', :vendor => 'ALT Linux')
    Group.import_group(branch, 'Shells')
    Group.all.count.should == 1
    Group.all.first.branch_id.should == branch.id
    Group.all.first.name.should == 'Shells'
    Group.all.first.parent_id.should be_nil
  end

  it "should import group 'Archiving/Backup'" do
    branch = Branch.create!(:name => 'Sisyphus', :vendor => 'ALT Linux')
    Group.import_group(branch, 'Archiving/Backup')
    Group.all.count.should == 2
    Group.all.first.branch_id.should == branch.id
    Group.all.first.name.should == 'Archiving'
    Group.all.first.parent_id.should be_nil
    Group.all.second.branch_id.should == branch.id
    Group.all.second.name.should == 'Backup'
    Group.all.second.parent_id.should == Group.all.first.id
  end

  it "should import group 'System/Configuration/Boot and Init'" do
    branch = Branch.create!(:name => 'Sisyphus', :vendor => 'ALT Linux')
    Group.import_group(branch, 'System/Configuration/Boot and Init')
    Group.all.count.should == 3
    Group.all.first.branch_id.should == branch.id
    Group.all.first.name.should == 'System'
    Group.all.first.parent_id.should be_nil
    Group.all.second.branch_id.should == branch.id
    Group.all.second.name.should == 'Configuration'
    Group.all.second.parent_id.should == Group.all.first.id
    Group.all.third.branch_id.should == branch.id
    Group.all.third.name.should == 'Boot and Init'
    Group.all.third.parent_id.should == Group.all.second.id
  end
end
<commit_msg>More specs for Group model<commit_after># encoding: utf-8
require 'spec_helper'

describe Group do
  it { should belong_to :branch }
  it { should have_many :srpms }
  it { should have_many :packages }

  it { should validate_presence_of :branch }
  it { should validate_presence_of :name }

  it { should have_db_index :branch_id }

  it "should return full group name on #full_name" do
    branch = Branch.create!(:name => 'Sisyphus', :vendor => 'ALT Linux')
    Group.import_group(branch, 'System/Configuration/Boot and Init')
    Group.all.last.full_name.should == 'System/Configuration/Boot and Init'
  end

  it "should import group 'Shells'" do
    branch = Branch.create!(:name => 'Sisyphus', :vendor => 'ALT Linux')
    Group.import_group(branch, 'Shells')
    Group.all.count.should == 1
    Group.all.first.branch_id.should == branch.id
    Group.all.first.name.should == 'Shells'
    Group.all.first.parent_id.should be_nil
  end

  it "should import group 'Archiving/Backup'" do
    branch = Branch.create!(:name => 'Sisyphus', :vendor => 'ALT Linux')
    Group.import_group(branch, 'Archiving/Backup')
    Group.all.count.should == 2
    Group.all.first.branch_id.should == branch.id
    Group.all.first.name.should == 'Archiving'
    Group.all.first.parent_id.should be_nil
    Group.all.second.branch_id.should == branch.id
    Group.all.second.name.should == 'Backup'
    Group.all.second.parent_id.should == Group.all.first.id
  end

  it "should import group 'System/Configuration/Boot and Init'" do
    branch = Branch.create!(:name => 'Sisyphus', :vendor => 'ALT Linux')
    Group.import_group(branch, 'System/Configuration/Boot and Init')
    Group.all.count.should == 3
    Group.all.first.branch_id.should == branch.id
    Group.all.first.name.should == 'System'
    Group.all.first.parent_id.should be_nil
    Group.all.second.branch_id.should == branch.id
    Group.all.second.name.should == 'Configuration'
    Group.all.second.parent_id.should == Group.all.first.id
    Group.all.third.branch_id.should == branch.id
    Group.all.third.name.should == 'Boot and Init'
    Group.all.third.parent_id.should == Group.all.second.id
  end

  it "should allow translate Group.name to russian" do
    I18n.locale = :en
    branch = Branch.create!(:name => 'Sisyphus', :vendor => 'ALT Linux')
    Group.create(:branch_id => branch.id, :name => 'Toys')
    I18n.locale = :ru
    group = Group.all.first
    group.name = 'Развлечения'
    group.save!
    I18n.locale = :en
    Group.first.name.should == 'Toys'
    I18n.locale = :ru
    Group.first.name.should == 'Развлечения'
  end
end

{'fraction_non_alphanumeric': 0.13631567841316733, 'fraction_numerical': 0.0031652247309558977, 'mean_word_length': 3.509990485252141, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, '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': '4301022', 'n_tokens_mistral': 1607, 'n_tokens_neox': 1578, 'n_words': 337}