How to test the model dependence?

Good morning,

I’m new to rails and am having some basic questions in development. See
if anyone can help me with a test problem. I need to test if my model
“Procedure” is linked to the workflow. If not, the system must
acknowledge an error. Below is the code that is in the file test \ unit
\ procedure_test.rb.

require ‘test_helper’

class ProcedureTest < ActiveSupport::TestCase
should belong_to :workflow
should has_many :tasks, :through => :workflow
#should has_one :timeline
#should has_many :timeline_items, :through => :timeline
end

The shoul “belong_to” is working normally but when running “rake test”
appears the following error:

$ Rake test
/ home / guilhermec / iba_jornais / test / unit / procedure_test.rb: 5:
in ‘: undefined methodhas_many’ for ProcedureTest:Class
(NoMethodError)
from /home/guilhermec/iba_jornais/test/unit/procedure_test.rb:3:in <top (required)>’ from /home/guilhermec/.rvm/gems/ruby-1.9.2-p180@iba-jornais/gems/activesupport-3.1.3/lib/active_support/dependencies.rb:240:inrequire’
from
/home/guilhermec/.rvm/gems/ruby-1.9.2-p180@iba-jornais/gems/activesupport-3.1.3/lib/active_support/dependencies.rb:240:in
block in require’ from /home/guilhermec/.rvm/gems/ruby-1.9.2-p180@iba-jornais/gems/activesupport-3.1.3/lib/active_support/dependencies.rb:225:inload_dependency’
from
/home/guilhermec/.rvm/gems/ruby-1.9.2-p180@iba-jornais/gems/activesupport-3.1.3/lib/active_support/dependencies.rb:240:in
require’ from /home/guilhermec/.rvm/gems/ruby-1.9.2-p180@iba-jornais/gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb:10:inblock (2 levels) in ’
from Each ' fromBlock in’
from Select ' from
Loaded suite

Does anyone know what I should do to fix this?

I usually use Shoulda for this:

http://rubydoc.info/gems/shoulda/frames

should belong_to(:user) should have_many(:tags).through(:taggings)

Dheeraj K.

On 27 January 2012 11:21, Guilherme R. [email protected] wrote:

class ProcedureTest < ActiveSupport::TestCase
should belong_to :workflow
should has_many :tasks, :through => :workflow

Try have_many rather than has_many

Colin

(NoMethodError)
`load_dependency
Loaded suite
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.


gplus.to/clanlaw

I was using “has” and de corretly is “have” . Tks everbody.