Testing anomaly

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?

you can see the full app via

svn checkout http://duality-cms.rubyforge.org/svn/
or
svn checkout svn://rubyforge.org/var/svn/duality-cms

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

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?

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