<commit_before>require 'spec_helper'

describe "Pages" do
  before(:each) do
    @page=Context::Page.create!(:name      => 'Test Page', 
                                :body      => 'I am a test page!', 
                                :slug      => 'test_page',
                                :published => true)
  end

  it "should render correctly from the slug" do
    visit "/test_page"
    page.body.should_not be_blank
    # Make sure we are in the application layout
    page.body.should =~ /Context Test Layout/
    page.body.should =~ /I am a test page!/
  end

  it "should render with a custom layout if set by the subclass" do
    @page.should_receive(:layout).and_return('custom')
    Context::Page.should_receive(:find_by_path).with('test_page').and_return(@page)
    visit "/test_page"
    page.body.should_not be_blank
    # Make sure we are in the custom layout
    page.body.should =~ /Custom Layout/
    page.body.should_not =~ /Context Test Layout/
    page.body.should =~ /I am a test page!/
  end

  it "should raise the normal 404 when the Page can't be found" do
    lambda {
      visit "/a_missing_test_page"
    }.should raise_exception(AbstractController::ActionNotFound)
  end
  
  it "should raise the normal 4040 when the page is not published" do
    @page.update_attribute(:published, false)
    @page.save
    lambda {
      visit @page.path
    }.should raise_exception(AbstractController::ActionNotFound)
  end

  it "should use Context::Configuration.page_show_template_path to render a different view template" do
    Context::Configuration.should_receive(:page_show_template_path).twice.and_return(File.join(Rails.root, 'app', 'views', 'test', 'custom_show.html.erb'))
    visit "/test_page"
    page.body.should =~ /CUSTOM VIEW TEMPLATE/
  end
  
  it "generates the correct path" do
    @page.path.should eql("test_page")
  end
  
  it "allows for custom page paths" do
    @page = Context::Page.create!(:name => 'Test Page', 
                                  :body => 'I am a test page!', 
                                  :slug => 'not-so-sluggish')<commit_msg>Don't generate custom paths for simple page tests<commit_after>require 'spec_helper'

describe "Pages" do
  before(:each) do
    @page=Context::Page.create!(:name      => '<NAME>', 
                                :body      => 'I am a test page!',
                                :published => true)
  end

  it "should render correctly from the slug" do
    visit "/test-page"
    page.body.should_not be_blank
    # Make sure we are in the application layout
    page.body.should =~ /Context Test Layout/
    page.body.should =~ /I am a test page!/
  end

  it "should render with a custom layout if set by the subclass" do
    @page.should_receive(:layout).and_return('custom')
    Context::Page.should_receive(:find_by_path).with('test-page').and_return(@page)
    visit "/test-page"
    page.body.should_not be_blank
    # Make sure we are in the custom layout
    page.body.should =~ /Custom Layout/
    page.body.should_not =~ /Context Test Layout/
    page.body.should =~ /I am a test page!/
  end

  it "should raise the normal 404 when the Page can't be found" do
    lambda {
      visit "/a_missing_test_page"
    }.should raise_exception(AbstractController::ActionNotFound)
  end
  
  it "should raise the normal 4040 when the page is not published" do
    @page.update_attribute(:published, false)
    @page.save
    lambda {
      visit @page.path
    }.should raise_exception(AbstractController::ActionNotFound)
  end

  it "should use Context::Configuration.page_show_template_path to render a different view template" do
    Context::Configuration.should_receive(:page_show_template_path).twice.and_return(File.join(Rails.root, 'app', 'views', 'test', 'custom_show.html.erb'))
    visit "/test-page"
    page.body.should =~ /CUSTOM VIEW TEMPLATE/
  end
  
  it "generates the correct path" do
    @page.path.should eql("test-page")
  end
  
  it "allows for custom page paths" do
    @page = Context::Page.create!(:name => 'Test Page', 
                                  :body => 'I am a test page!', 
                                  :slug => 'not-so-sluggish')
{'fraction_non_alphanumeric': 0.10832736816988786, 'fraction_numerical': 0.0033404915294679076, 'mean_word_length': 2.598283261802575, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5192203', 'n_tokens_mistral': 1297, 'n_tokens_neox': 1237, 'n_words': 373}