# Testing anomaly

**URL:** <https://www.ruby-forum.com/t/testing-anomaly/119309>\
**Category:** Rails\
**Created:** [November 5, 2007, 11:36pm UTC](https://www.ruby-forum.com/t/testing-anomaly/119309 "2007-11-05T23:36:07Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![keynan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/8dc957/32.png) [@keynan](https://www.ruby-forum.com/u/keynan)\
**Post date:** [November 5, 2007, 11:36pm UTC](https://www.ruby-forum.com/t/testing-anomaly/119309/1 "2007-11-05T23:36:07Z")

</div>

I am attempting to load relations via database data

# in the model

```
    belongs_to :asset_type

```

AssetType.asset\_connection\_names.each do |at|  
belongs\_to at, :foreign\_key =\> ‘asset\_id’  
end

# def method\_missing(method, \*args) if(method.to\_s =~ /^asset/) send asset\_type.name + method.to\_s.gsub(/^asset/, ‘’) else super(method, args) end end

# the test

fixtures :contents, :htmls, :asset\_types

# Replace this with your real tests.

def test\_belongs\_to\_asset  
content = Content.find(1)  
assert\_equal(contents(:one), content)  
assert\_equal(asset\_types(:html).name, content.asset\_type.name)  
assert\_respond\_to(content, :html)  
assert\_equal(htmls(:hello\_world).headline,  
content.asset.headline)  
end

# =============================================================================== the weird shit

when running the test suite individualy it passes

when runnning rake test:units

AssetType.asset\_connection\_names.each do |at|  
belongs\_to at, :foreign\_key =\> ‘asset\_id’  
end

fails to execute

==============================================================================

any ideas?

---

<div class="post-metadata">

**Author:** ![keynan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/8dc957/32.png) [@keynan](https://www.ruby-forum.com/u/keynan)\
**Post date:** [November 5, 2007, 11:45pm UTC](https://www.ruby-forum.com/t/testing-anomaly/119309/2 "2007-11-05T23:45:54Z")

</div>

you can see the full app via

svn checkout [http://duality-cms.rubyforge.org/svn/](http://duality-cms.rubyforge.org/svn/)  
or  
svn checkout svn://rubyforge.org/var/svn/duality-cms

---

<div class="post-metadata">

**Author:** ![keynan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/8dc957/32.png) [@keynan](https://www.ruby-forum.com/u/keynan)\
**Post date:** [November 6, 2007, 12:46am UTC](https://www.ruby-forum.com/t/testing-anomaly/119309/3 "2007-11-06T00:46:51Z")

</div>

On 5 Nov 2007, at 22:36, Keynan P. wrote:

> when runnning rake test:units
> 
> AssetType.asset\_connection\_names.each do |at|  
> belongs\_to at, :foreign\_key =\> ‘asset\_id’  
> end

what do you mean by fails to execute ? Doesn’t run at all, throws some  
weird error, something else?.  
The model is only going to be loaded once, so if you had a test which  
used that model but didn’t say fixtures asset\_types, weirdness could  
quite easily happen.

Fred

---

<div class="post-metadata">

**Author:** ![keynan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/8dc957/32.png) [@keynan](https://www.ruby-forum.com/u/keynan)\
**Post date:** [November 6, 2007, 8:33pm UTC](https://www.ruby-forum.com/t/testing-anomaly/119309/4 "2007-11-06T20:33:49Z")

</div>

> what do you mean by fails to execute ? Doesn’t run at all, throws some  
> weird error, something else?.  
> The model is only going to be loaded once, so if you had a test which  
> used that model but didn’t say fixtures asset\_types, weirdness could  
> quite easily happen.
> 
> Fred

The code Doesn’t run at all. And asset\_types is included in the fixtures  
for this test suite so it should be reloaded before the test executes  
should it not?

Do you mean to say that the code

AssetType.asset\_connection\_names.each do |at|  
belongs\_to at, :foreign\_key =\> ‘asset\_id’  
end

is executed on load and not on instantiation?

---

<div class="post-metadata">

**Author:** ![keynan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/8dc957/32.png) [@keynan](https://www.ruby-forum.com/u/keynan)\
**Post date:** [November 6, 2007, 9:38pm UTC](https://www.ruby-forum.com/t/testing-anomaly/119309/5 "2007-11-06T21:38:23Z")

</div>

On 6 Nov 2007, at 19:33, Keynan P. wrote:

> belongs\_to at, :foreign\_key =\> ‘asset\_id’  
> end

It’s executed at the point the model is loaded. I wouldn’t want to bet  
when exactly that is (stick a breakpoint in and find out).

Fred
