require 'test_helper'

class PageTest < ActiveSupport::TestCase
  context "Page:" do
    setup do
      @theme = Theme.create(:name => "theme")
      @site = Site.create(:subdomain => "my_site", :theme => @theme)
    end
  
    context "An instance of a Page" do
      setup do
        @valid_attributes = {
          :title => "Test Page Title",
          :theme_id => @theme.id,
          :site_id => @site.id,
          :template_name => 'page.tpl'
        }
        def create_page(options={})
          Page.create(@valid_attributes.merge(options))
        end
      end
      
      should "save with valid attributes" do
        assert_difference 'Page.count' do
          page = create_page
          assert page.errors.blank?
        end
      end
      
      should "require a template name" do
        assert_no_difference 'Page.count' do
          page = create_page(:template_name => '')
          assert page.errors.on(:template_name)
        end
      end
    end
  end
end

require 'test_helper'

class PageTest < ActiveSupport::TestCase
  context "A page" do
    should_validate_presence_of :template_name, :body
    
    should "know its liquid name" do
      assert_equal "page", Page.make.liquid_name
    end
    
    should "have a default template name of page.tpl on initialize" do
      assert_equal "page.tpl", Page.new.template_name
    end

    should_eventually "return its template"
  end
end

Rewrite Page tests. * Require body * Require template name * Validate default template name
Rewrite Page tests.
* Require body
* Require template name
* Validate default template name