Error of testing has_many :through

Hi everyone,

I am testing the validation of association of the model but i can a
error… plzz help

error
/usr/local/lib/ruby/gems/1.9.1/gems/shoulda-2.11.3/lib/shoulda/
active_record/matchers/association_matcher.rb:27:in have_many': wrong number of arguments (2 for 1) (ArgumentError) from /usr/local/lib/ruby/gems/1.9.1/gems/shoulda-2.11.3/lib/shoulda/ context.rb:429:inmethod_missing’
from test/unit/prescription_test.rb:71:in block in <class:PrescriptionTest>' from /usr/local/lib/ruby/gems/1.9.1/gems/shoulda-2.11.3/lib/shoulda/ context.rb:306:incall’
from /usr/local/lib/ruby/gems/1.9.1/gems/shoulda-2.11.3/lib/shoulda/
context.rb:306:in merge_block' from /usr/local/lib/ruby/gems/1.9.1/gems/shoulda-2.11.3/lib/shoulda/ context.rb:301:ininitialize’
from /usr/local/lib/ruby/gems/1.9.1/gems/shoulda-2.11.3/lib/shoulda/
context.rb:199:in new' from /usr/local/lib/ruby/gems/1.9.1/gems/shoulda-2.11.3/lib/shoulda/ context.rb:199:incontext’
from test/unit/prescription_test.rb:64:in <class:PrescriptionTest>' from test/unit/prescription_test.rb:3:in<top (required)>’
from /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.0.9/lib/
active_support/dependencies.rb:235:in load' from /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.0.9/lib/ active_support/dependencies.rb:235:inblock in load’
from /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.0.9/lib/
active_support/dependencies.rb:227:in load_dependency' from /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.0.9/lib/ active_support/dependencies.rb:235:inload’
from /usr/local/lib/ruby/1.9.1/rake/rake_test_loader.rb:5:in block in <main>' from /usr/local/lib/ruby/1.9.1/rake/rake_test_loader.rb:5:ineach’
from /usr/local/lib/ruby/1.9.1/rake/rake_test_loader.rb:5:in `’
Loaded suite /usr/local/lib/ruby/1.9.1/rake/rake_test_loader
Started

there is one

prescription model
has _many :others
has_many :phrases, :through => :reasons

phrase model
has_many :others

reason model
validates_presence_of :phrase_id, :message => “ERROR_MISSING_PHRASE”
belongs_to :phrase

other model
validates_presence_of :phrase_id, :message => “ERROR_MISSING_PHRASE”
belongs_to :phrase

test file of prescription_test.rb
context “checking assocciation” do
should have_many :phrases, :through => :others
end

On 8 July 2011 21:19, Yennie [email protected] wrote:

from /usr/local/lib/ruby/gems/1.9.1/gems/shoulda-2.11.3/lib/shoulda/
context.rb:199:in `new’
from /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.0.9/lib/
there is one

prescription model
has _many :others
has_many :phrases, :through => :reasons

You also need has_many :reasons in order to specify has_many through
(I think). Or should this be through :others?

phrase model
has_many :others

reason model
validates_presence_of :phrase_id, :message => “ERROR_MISSING_PHRASE”
belongs_to :phrase

Again you will need belongs_to prescription.

other model
validates_presence_of :phrase_id, :message => “ERROR_MISSING_PHRASE”
belongs_to :phrase

and belongs_to prescription.

test file of prescription_test.rb
context “checking assocciation” do
should have_many :phrases, :through => :others

Above you have specified through reasons not through others. Either
the test or the relation is wrong.

Colin

On Fri, Jul 8, 2011 at 4:28 PM, Colin L. [email protected]
wrote:

number of arguments (2 for 1) (ArgumentError)
context.rb:306:in merge_block' class:PrescriptionTest
`block
there is one
has_many :others
belongs_to :phrase

I follow the way that you said and edit “belongs to prescription”
right now it gives an error
/usr/local/lib/ruby/gems/1.9.1/gems/shoulda-2.11.3/lib/shoulda/active_record/matchers/association_matcher.rb:27:in
have_many': wrong number of arguments (2 for 1) (ArgumentError) from /usr/local/lib/ruby/gems/1.9.1/gems/shoulda-2.11.3/lib/shoulda/context.rb:429:in method_missing’
from test/unit/prescription_test.rb:71:in block in <class:PrescriptionTest>' from /usr/local/lib/ruby/gems/1.9.1/gems/shoulda-2.11.3/lib/shoulda/context.rb:306:in call’
from
/usr/local/lib/ruby/gems/1.9.1/gems/shoulda-2.11.3/lib/shoulda/context.rb:306:in
merge_block' from /usr/local/lib/ruby/gems/1.9.1/gems/shoulda-2.11.3/lib/shoulda/context.rb:301:in initialize’
from
/usr/local/lib/ruby/gems/1.9.1/gems/shoulda-2.11.3/lib/shoulda/context.rb:199:in
new' from /usr/local/lib/ruby/gems/1.9.1/gems/shoulda-2.11.3/lib/shoulda/context.rb:199:in context’
from test/unit/prescription_test.rb:64:in <class:PrescriptionTest>' from test/unit/prescription_test.rb:3:in <top (required)>’
from
/usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.0.9/lib/active_support/dependencies.rb:235:in
load' from /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.0.9/lib/active_support/dependencies.rb:235:in block in load’
from
/usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.0.9/lib/active_support/dependencies.rb:227:in
load_dependency' from /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.0.9/lib/active_support/dependencies.rb:235:in load’
from /usr/local/lib/ruby/1.9.1/rake/rake_test_loader.rb:5:in `block
in

' from /usr/local/lib/ruby/1.9.1/rake/rake_test_loader.rb:5:in `each' from /usr/local/lib/ruby/1.9.1/rake/rake_test_loader.rb:5:in `' Loaded suite /usr/local/lib/ruby/1.9.1/rake/rake_test_loader Started

plz help