Hi,
I’m having trouble writing unit tests for a Radiant extension. I’ve
created fixtures for layouts, pages and page_parts, which are pasted
below. In my unit test, I find that if I call:
@page = pages(:homepage)
the tests work. Whereas if I try:
@page = pages(:lazypage)
I get an error:
StandardError: No fixture with name ‘lazypage’ found for table ‘pages’
There is a lazypage in my pages fixture, so I don’t know why it does
this. Any ideas?
Thanks,
Andrew
Here is my unit test:
require File.dirname(FILE) + ‘/…/test_helper’
class MetaTagsTest < Test::Unit::TestCase
fixtures :pages, :layouts, :page_parts
test_helper :render, :pages, :page_parts
def setup
@page = pages(:lazypage)
end
def test_meta_tag
default = “<r:meta />”
assert_render_match %r{<meta [^>]name=“description” .>}, default
assert_render_match %r{<meta [^>]content="".>}, default
end
def test_name_as_keywords
assert_render_match %r{<meta [^>]name=“keywords” .>}, “<r:meta
name=‘keywords’/>”
end
def test_inherit
assert_render_match %r{<meta [^>].>}, “<r:meta inherit=‘false’/>”
assert_render_error %{inherit' attribute of
meta’ tag must be
set to either “true” or “false”}, “<r:meta inherit=‘gamma’/>”
end
def test_page
@page = pages(:homepage)
assert_page_renders :homepage, “This is the body portion of the
Ruby home page.”
assert_equal "This is a description of the Ruby home page, which
will appear in the meta description tag", @page.render_part
(:description)
# assert_render_match %r{<meta [^>]*content="fe".*>}, "<r:meta /
", “/”
# assert_page_renders :homepage, “This is an extended portion of
the Ruby home page.”
# assert_page_renders :eagerpage, “This is the body portion of
the Ruby home page.”
# assert_renders “This is an extended portion of the Ruby home
page.”, :homepage
end
end
My fixtures:
layouts.yaml
main:
id: 1
name: Home Page
content: |
<r:title />
<r:meta />
<r:content />
alternate:
id: 2
name: Home Page
content: |
<r:title />
<r:meta part=“body”/>
<r:meta part=“keys” name=“keywords”/>
<r:content />
pages.yaml
homepage:
id: 1
title: Homepage
breadcrumb: Home
slug: /
status_id: 100
layout_id: 1
parent_id:
published_at: 2006-01-30 08:41:07
lazypage:
id: 2
title: Lazy
breadcrumb: Lazy
slug: lazy
status_id: 100
layout_id: 1
parent_id: 1
published_at: 2006-01-30 08:43:07
eagerpage:
id: 3
title: Eager
breadcrumb: Eager
slug: eager
status_id: 100
layout_id: 1
parent_id: 1
published_at: 2006-01-30 08:45:07
ecopage:
id: 4
title: Eco
breadcrumb: Eco
slug: eco
status_id: 100
layout_id: 2
parent_id: 1
published_at: 2006-01-30 08:46:07
page_parts.yaml
Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
body:
id: 1
name: body
content: This is the body portion of the Ruby home page.
page_id: 1
extended:
id: 2
name: extended
content: This is an extended portion of the Ruby home page.
page_id: 1
description:
id: 3
name: description
content: This is a description of the Ruby home page, which will
appear in the meta description tag
page_id: 1
body:
id: 4
name: body
content: Body portion of the Lazy page.
page_id: 2
extended:
id: 5
name: body
content: Body portion of the Eager page.
page_id: 3
description:
id: 6
name: description
content: The eager page defines its own meta description
page_id: 3
body:
id: 7
name: body
content: Body portion of the Eco page, which doubles as meta
description.
page_id: 4
body:
id: 8
name: keys
content: SEO,meta,google
page_id: 4