Sha256: 8639ecdc1bbe499910cf29be00c45e084351e3c9a4f89cb8b798a8985b97954e

Contents?: true

Size: 1.3 KB

Versions: 3

Compression:

Stored size: 1.3 KB

Contents

class NoCachePage < Page
  description 'Turns caching off for testing.'
  
  def cache?
    false
  end
end

class TestPage < Page
  description 'this is just a test page'
  
  tag 'test1' do
    'Hello world!'
  end
  
  tag 'test2' do
    'Another test.'
  end
  
  def headers
    {
      'cool' => 'beans',
      'request' => @request.inspect[20..30],
      'response' => @response.inspect[20..31]
    }
  end
  
end

module PageTestHelper
  
  VALID_PAGE_PARAMS = {
    :title => 'New Page',
    :slug => 'page',
    :breadcrumb => 'New Page',
    :status_id => '1',
    :parent_id => nil
  }
  
  def page_params(options = {})
    params = VALID_PAGE_PARAMS.dup
    params.merge!(:title => @page_title) if @page_title
    params.merge!(:status_id => '5')
    params.merge!(options)
  end
  
  def destroy_test_page(title = @page_title)
    while page = get_test_page(title) do
      page.destroy
    end
  end
  
  def get_test_page(title = @page_title)
    Page.find_by_title(title)
  end
  
  def create_test_page(options = {})
    options[:title] ||= @page_title
    klass = options.delete(:class_name) || Page
    klass = Kernel.eval(klass) if klass.kind_of? String
    page = klass.new page_params(options)
    if page.save
      page
    else
      raise "page <#{page.inspect}> could not be saved"
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
radiant-0.6.0 test/helpers/page_test_helper.rb
radiant-0.6.1 test/helpers/page_test_helper.rb
radiant-0.6.2 test/helpers/page_test_helper.rb