<commit_before>require 'spec_helper'

describe Kuhsaft::Page do
  
  before do
    Kuhsaft::Page.translation_locales = ['en', 'de']
    Kuhsaft::Page.current_translation_locale = :en
  end
  
  before :each do 
    Kuhsaft::Page.all.each { |p| p.destroy }
    @page = Factory.create :page
  end
  
  it 'should have many localized_pages' do
    @page.localized_pages.count.should >= 1
  end
  
  it 'should have child pages' do
    p = Factory.create(:page)
    @page.childs << p
    @page.childs.count.should >= 1
  end
  
  it 'should be the root page' do
    @page.root?.should be(true)
  end
  
  it 'should have a parent page' do
    child = Factory.create(:page)
    @page.childs << child
    child.parent.id.should be(@page.id)
  end
  
  it 'should have a list of root pages' do
    root_page = Factory.create :page
    root_page.childs << Factory.create(:page)
    root_page.childs << Factory.create(:page)
    Kuhsaft::Page.root_pages.count.should >= 1
  end
  
  it 'should increment it\'s position by 1' do
    page = Factory.create :page
    position = page.position
    page.increment_position
    page.position.should == (position + 1)
  end
  
  it 'should decrement it\'s position by 1' do
    page = Factory.create :page
    position = page.position
    page.decrement_position
    page.position.should == (position - 1)
  end
  
  it 'should find the position of a page' do
    page = Factory.create :page
    position = page.position
    Kuhsaft::Page.position_of(page.id).should == position
  end
  
  it 'should find the predecing sibling' do
    page1 = Factory.create :page
    page2 = Factory.create :page
    page3 = Factory.create :page
    page3.preceding_sibling.id.should == page2.id
  end
  
  it 'should find the succeeding sibling' do
    page1 = Factory.create :page
    page2 = Factory.create :page
    page3 = Factory.create :page
    page2.succeeding_sibling.id.should == page3.id
  end
  
  it 'should reposition before a page' do
    page1 = Factory.create :page
    page2 = Factory.create :page
    page3 = Factory.create :page
    page3.reposition page1.id
    page3.preceding_sibling.id.should == page1.id
  end
  
  it 'should reposition before all siblings' do
    page1 = Factory.create :page
    page2 = Factory.create :page
    page2.reposition nil
    page2.position.should == 1
  end
  
  it 'should save the translation when saved' do
    @page.translation.title = 'some localized title'
    @page.should_receive(:save_translation)
    @page.save
  end
  
  it 'should have an url when saved' do
    page = Factory.create :page
    page.url.should == 'en/english-title'
  end
  
  it 'should have a link' do
    page = Factory.create :page
    page.link.should == '/en/english-title'
  end
  
  it 'should include the parents slug in its url' do
    page = Factory.create :page
    child = Factory.create :page
    page.childs << child
    page.save
    child.url.should == 'en/english-title/english-title'
  end
  
  it 'should return the link of its first child when its empty' do
    page = Factory.create :page
    child = Factory.create :page
    page.childs << child
    page.body = nil
    page.save
    page.link.should == child.link
  end
  
  it 'should find its translated content by url' do
    Kuhsaft::Page.all.each { |p| p.destroy }
    Kuhsaft::LocalizedPage.all.each{ |p| p.destroy }
    page = Factory.create(:page)
    Kuhsaft::Page.find_by_url(page.url).id.should == page.id
  end
  
  it 'should provide an array of translation locales' do
    Kuhsaft::Page.translation_locales.should be_a(Array)<commit_msg>refine page spec<commit_after>require 'spec_helper'

describe Kuhsaft::Page do
  
  before :each do 
    destroy_all_pages
    @page = Factory.create :page
  end
  
  it 'should have many localized_pages' do
    @page.localized_pages.should have_at_least(1).page
  end
  
  it 'should have child pages' do
    p = Factory.create(:page)
    @page.childs << p
    @page.childs.should have_at_least(1).page
  end
  
  it 'should be the root page' do
    @page.root?.should be(true)
  end
  
  it 'should have a parent page' do
    child = Factory.create(:page)
    @page.childs << child
    child.parent.should eq(@page)
  end
  
  it 'should have a list of root pages' do
    root_page = Factory.create :page
    root_page.childs << Factory.create(:page)
    root_page.childs << Factory.create(:page)
    Kuhsaft::Page.root_pages.should have_at_least(2).pages
  end
  
  it 'should increment it\'s position by 1' do
    page = Factory.create :page
    position = page.position
    page.increment_position
    page.position.should == (position + 1)
  end
  
  it 'should decrement it\'s position by 1' do
    page = Factory.create :page
    position = page.position
    page.decrement_position
    page.position.should == (position - 1)
  end
  
  it 'should find the position of a page' do
    page = Factory.create :page
    position = page.position
    Kuhsaft::Page.position_of(page.id).should == position
  end
  
  it 'should find the predecing sibling' do
    page1 = Factory.create :page
    page2 = Factory.create :page
    page3 = Factory.create :page
    page3.preceding_sibling.id.should == page2.id
  end
  
  it 'should find the succeeding sibling' do
    page1 = Factory.create :page
    page2 = Factory.create :page
    page3 = Factory.create :page
    page2.succeeding_sibling.id.should == page3.id
  end
  
  it 'should reposition before a page' do
    page1 = Factory.create :page
    page2 = Factory.create :page
    page3 = Factory.create :page
    page3.reposition page1.id
    page3.preceding_sibling.id.should == page1.id
  end
  
  it 'should reposition before all siblings' do
    page1 = Factory.create :page
    page2 = Factory.create :page
    page2.reposition nil
    page2.position.should == 1
  end
  
  it 'should save the translation when saved' do
    @page.translation.title = 'some localized title'
    @page.should_receive(:save_translation)
    @page.save
  end
  
  it 'should have an url when saved' do
    page = Factory.create :page
    page.url.should == 'en/english-title'
  end
  
  it 'should have a link' do
    page = Factory.create :page
    page.link.should == '/en/english-title'
  end
  
  it 'should include the parents slug in its url' do
    page = Factory.create :page
    child = Factory.create :page
    page.childs << child
    page.save
    child.url.should == 'en/english-title/english-title'
  end
  
  it 'should return the link of its first child when its empty' do
    page = Factory.create :page
    child = Factory.create :page
    page.childs << child
    page.body = nil
    page.save
    page.link.should == child.link
  end
  
  it 'should find its translated content by url' do
    destroy_all_pages
    page = Factory.create(:page)
    Kuhsaft::Page.find_by_url(page.url).should eq(page)
  end
  
  it 'should provide an array of translation locales' do
    Kuhsaft::Page.translation_locales.should be_a(Array)
{'fraction_non_alphanumeric': 0.09583333333333334, 'fraction_numerical': 0.008333333333333333, 'mean_word_length': 2.835261707988981, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 6, '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': '5291299', 'n_tokens_mistral': 2312, 'n_tokens_neox': 2289, 'n_words': 664}