# Extension Testing troubles

**URL:** <https://www.ruby-forum.com/t/extension-testing-troubles/119673>\
**Category:** Radiant CMS\
**Created:** [November 9, 2007, 2:46am UTC](https://www.ruby-forum.com/t/extension-testing-troubles/119673 "2007-11-09T02:46:11Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![andrewneal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/4491bb/32.png) [@andrewneal](https://www.ruby-forum.com/u/andrewneal)\
**Post date:** [November 9, 2007, 2:46am UTC](https://www.ruby-forum.com/t/extension-testing-troubles/119673/1 "2007-11-09T02:46:11Z")

</div>

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](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

---

<div class="post-metadata">

**Author:** ![andrewneal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/4491bb/32.png) [@andrewneal](https://www.ruby-forum.com/u/andrewneal)\
**Post date:** [November 9, 2007, 3:35am UTC](https://www.ruby-forum.com/t/extension-testing-troubles/119673/2 "2007-11-09T03:35:59Z")

</div>

> 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

---

<div class="post-metadata">

**Author:** ![andrewneal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/4491bb/32.png) [@andrewneal](https://www.ruby-forum.com/u/andrewneal)\
**Post date:** [November 9, 2007, 12:54pm UTC](https://www.ruby-forum.com/t/extension-testing-troubles/119673/3 "2007-11-09T12:54:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![andrewneal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/4491bb/32.png) [@andrewneal](https://www.ruby-forum.com/u/andrewneal)\
**Post date:** [November 9, 2007, 9:19am UTC](https://www.ruby-forum.com/t/extension-testing-troubles/119673/4 "2007-11-09T09:19:42Z")

</div>

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. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

---

<div class="post-metadata">

**Author:** ![andrewneal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/4491bb/32.png) [@andrewneal](https://www.ruby-forum.com/u/andrewneal)\
**Post date:** [November 9, 2007, 12:59pm UTC](https://www.ruby-forum.com/t/extension-testing-troubles/119673/5 "2007-11-09T12:59:55Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![andrewneal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/4491bb/32.png) [@andrewneal](https://www.ruby-forum.com/u/andrewneal)\
**Post date:** [November 9, 2007, 1:04pm UTC](https://www.ruby-forum.com/t/extension-testing-troubles/119673/6 "2007-11-09T13:04:00Z")

</div>

2007/11/9, Andrew N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> 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.
