模型代码如下:
class Agent < ActiveRecord::Base
has_many :stars
#,:dependent =>:nullify
end
has_many :stars
#,:dependent =>:nullify
end
以一个测试用例作为说明
开头:
classAgentTest
<
Test
::
Unit
TestCase
fixtures : agents ,: stars
defsetup
@agent = Agent . find( 1 )
end
..........................................
fixtures : agents ,: stars
defsetup
@agent = Agent . find( 1 )
end
..........................................
测试读取:
deftest_read
stars @agent.stars
assert_equal " 谭咏麟 0 ].name_cn
end
stars @agent.stars
assert_equal " 谭咏麟 0 ].name_cn
end