Extension Testing troubles

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

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?

There was a problem in the fixture loading code where any syntax
problems in the yaml file would be silently ignored. If you update
to the latest trunk, you might get a more meaningful error message.

Dan

Dan

There was a problem in the fixture loading code where any syntax
problems in the yaml file would be silently ignored.

If you update to the latest trunk, you might get a more meaningful
error message.

I’m running Radiant from the gem at the moment. Am I right in
thinking I just need to run the following commands:

% rake radiant:freeze:edge
% rake radiant:update
% rake db:migrate

to update to trunk? Are there likely to be any repercussions in doing
so?

Thanks,

A

When writing tests for an extension i discovered that the tests load
radiant default fixtures by default. You have to change test helper so
you include your extension’s fixtures path. (This was on an older
version of radiant)

2007/11/9, Andrew N. [email protected]:

Thanks Giovanni,
When writing tests for an extension i discovered that the tests load
radiant default fixtures by default. You have to change test helper so
you include your extension’s fixtures path.

I think it does this already. This is the relevant line:

Add the fixture directory to the fixture path

self.fixture_path << File.dirname(FILE) + “/fixtures”

I notice that it appends the extension fixture path to
self.fixture_path. Could this mean that Radiant fixtures are still in
place, and being used instead of mine? Should I replace the ‘<<’
operator with ‘=’?

The test_helper.rb file was generated automatically. Here is the
whole thing:

require ‘test/unit’

# Load the environment

unless defined? RADIANT_ROOT
ENV[“RAILS_ENV”] = “test”
require “#{File.expand_path(File.dirname(FILE) +
“/…/…/…/…/”)}/config/environment”
end
require “#{RADIANT_ROOT}/test/test_helper”

class Test::Unit::TestCase

Include a helper to make testing Radius tags easier

test_helper :extension_tags

Add the fixture directory to the fixture path

self.fixture_path << File.dirname(FILE) + “/fixtures”

Add more helper methods to be used by all extension tests here…

end

p.s. Sorry if this appears twice. The first was overlarge, so I’ve
pruned it.

2007/11/9, Andrew N. [email protected]:

I notice that it appends the extension fixture path to
self.fixture_path. Could this mean that Radiant fixtures are still in
place, and being used instead of mine? Should I replace the ‘<<’
operator with ‘=’?

I wouldn’t replace radiant’s fixtures, just use them in your tests.