in my test
context "test"do
should have_many :phrases
end
in language.rb
belongs_to :name, :class_name => "Phrase", :foreign_key => "name"
error is
1) Failure:
test: check has_many and belongs_to association should have many
languages. (PhraseTest) [/usr/local/lib/ruby/gems/1.9.1/gems/
shoulda-2.11.3/lib/shoulda/context.rb:324]:
Expected Phrase to have a has_many association called languages
(Language does not have a phrase_id foreign key.).
Expected block to return true value.
test file phrase_test.rb
context "check has_many and belongs_to association" do
should belong_to :category
should have_many :phrases
should have_many :languages
end
error
Started
..........F.......................................
Finished in 1.313199 seconds.
1) Failure:
test: check has_many and belongs_to association should have many
languages. (PhraseTest) [/usr/local/lib/ruby/gems/1.9.1/gems/
shoulda-2.11.3/lib/shoulda/context.rb:324]:
Expected Phrase to have a has_many association called languages
(Language does not have a phrase_id foreign key.).
Expected block to return true value
in my test
context "test"do
should have_many :phrases
end
in language.rb
belongs_to :name, :class_name => "Phrase", :foreign_key => "name"
error is
1) Failure:
test: check has_many and belongs_to association should have many
languages. (PhraseTest) [/usr/local/lib/ruby/gems/1.9.1/gems/
shoulda-2.11.3/lib/shoulda/context.rb:324]:
Expected Phrase to have a has_many association called languages
(Language does not have a phrase_id foreign key.).
Expected block to return true value.
I dont really understand what it's warning now..
It might help us if you showed us the failing test. Also I think it
would be better to use name_id as the foreign key for language
belongs_to :name.
Colin
model language.rb
class Language < ActiveRecord::Base
belongs_to :phraes, :class_name => "Phrase", :foreign_key => "name"
end
test file phrase_test.rb
context "check has_many and belongs_to association" do
should belong_to :category
should have_many :phrases
should have_many :languages
end
error
Started
..........F.......................................
Finished in 1.313199 seconds.
1) Failure:
test: check has_many and belongs_to association should have many
languages. (PhraseTest) [/usr/local/lib/ruby/gems/1.9.1/gems/
shoulda-2.11.3/lib/shoulda/context.rb:324]:
Expected Phrase to have a has_many association called languages
(Language does not have a phrase_id foreign key.).
Expected block to return true value
The test claims to be failing because the languages table does not have a phrase_id column. Does it?
>>> 1) Failure:
>>> test: checkhas_manyandbelongs_to associationshould have many
>>> languages. (PhraseTest) [/usr/local/lib/ruby/gems/1.9.1/gems/
>>> shoulda-2.11.3/lib/shoulda/context.rb:324]:
>>> Expected Phrase to have ahas_manyassociationcalled languages
>>> (Language does not have a phrase_id foreign key.).
>>> Expected block to return true value.
>>> I dont really understand what it's warning now..
>> It might help us if you showed us the failing test. Also I think it
>> would be better to use name_id as the foreign key for language
>>belongs_to:name.
>> Colin
> model language.rb
> class Language < ActiveRecord::Base
>belongs_to:phraes, :class_name => "Phrase", :foreign_key => "name"
> end
> test file phrase_test.rb
> context "checkhas_manyandbelongs_to association" do
> should belong_to :category
> should have_many :phrases
> should have_many :languages
> end
> error
> Started
> ..........F.......................................
> Finished in 1.313199 seconds.
> 1) Failure:
> test: checkhas_manyandbelongs_to associationshould have many
> languages. (PhraseTest) [/usr/local/lib/ruby/gems/1.9.1/gems/
> shoulda-2.11.3/lib/shoulda/context.rb:324]:
> Expected Phrase to have ahas_manyassociationcalled languages
> (Language does not have a phrase_id foreign key.).
> Expected block to return true value
The test claims to be failing because the languages table does not have a phrase_id column. Does it?
Fred
I have language table
id
name (integer)
language_name (varchar)
phrase table
id
name (varchar)
category_id (integer)
I have name as references to phrase..
can anyone help me plzz??
> 1) Failure:
> test: check has_many and belongs_to association should have many
> languages. (PhraseTest) [/usr/local/lib/ruby/gems/1.9.1/gems/
> shoulda-2.11.3/lib/shoulda/context.rb:324]:
> Expected Phrase to have a has_many association called languages
> (Language does not have a phrase_id foreign key.).
> Expected block to return true value.
> I dont really understand what it's warning now..
It might help us if you showed us the failing test. Also I think it
would be better to use name_id as the foreign key for language
belongs_to :name.
Colin
model language.rb
class Language < ActiveRecord::Base
belongs_to :phraes, :class_name => "Phrase", :foreign_key => "name"
test: check has_many and belongs_to association should have many languages. (PhraseTest) [/usr/local/lib/ruby/gems/1.9.1/gems/shoulda-2.11.3/lib/shoulda/context.rb:324]:
Expected Phrase to have a has_many association called languages (Language does not have a phrase_id foreign key.).
Why is the foreign key "name"? Is the "name" field in language a text
field, or an integer? It needs to be an integer to store the id of the
Phrase, and would make more sense as "name_id".
By having the relationship named the same as an attribute, that's
going to confuse things, because when something calls "language.name",
is it expecting the phrase object back, or the integer value of the
name field?
In Language, you have "belongs_to :name" (which is really Phrase), and
belongs_to :phrase. So you need a phrase_id field, and a name_id field
- one for each of the relationships.
In Phrase, you "has_many :languages", but language doesn't yet have a
phrase_id field. Or did you mean for this has_many to point at the
name_id field as foreign key?
In Language, you have "belongs_to :name" (which is really Phrase), and
belongs_to :phrase. So you need a phrase_id field, and a name_id field
- one for each of the relationships.
belongs_to phrase, I add it because the languageTest is complaining there is
no association with phrase.
so that i added it to language model
If you don't want it, take it out.
Change the "name" field to "name_id" for all our sakes....
In Phrase, you "has_many :languages", but language doesn't yet have a
phrase_id field. Or did you mean for this has_many to point at the
name_id field as foreign key?
yes. I want to point the name_id as foreign key of phrase
one phrase(id) can have many language (name_id/phrase_id)
So do that then (how's Rails supposed to know that you've decided for
no reason not to use "phrase_id" as the foreign key field in
Language?!):
has_many :languages, :foreign_key => :name_id
test: belongs to and has many association should belong to phrase. (LanguageTest) [/usr/local/lib/ruby/gems/1.9.1/gems/shoulda-2.11.3/lib/shoulda/context.rb:324]:
Expected Language to have a belongs_to association called phrase (no association called phrase).
Expected block to return true value.
Failure:
test: check has_many and belongs_to association should have many languages. (PhraseTest) [/usr/local/lib/ruby/gems/1.9.1/gems/shoulda-2.11.3/lib/shoulda/context.rb:324]:
Expected Phrase to have a has_many association called languages (Language does not have a name_id foreign key.).