I''m having problems unit testing my model- I have a kind of quiz functionality user table and a question table and a user_question_response table that contains the id for the user, the id for the question and the user''s response. The user_question_response has it''s own model belongs_to/has_many with users and questions and it works fine in the actual application but when I try to do any unit-testing of my User model I get this: ActiveRecord::RecordNotFound: Couldn''t find UserQuestionResponse without an ID .../gems/activerecord_1.14.2/lib/active_record/base.rb:932:in ''find_from_ids'' Any ideas what is going on and what I can do about it? -- Posted via http://www.ruby-forum.com/.
ben moxon
2006-Jun-07 16:08 UTC
[Rails] Re: Unit Tests crashing out for a table without an ID
ben moxon wrote:> I''m having problems unit testing my model- I have a kind of quiz > functionality user table and a question table and a > user_question_response table that contains the id for the user, the id > for the question and the user''s response. The user_question_response has > it''s own model belongs_to/has_many with users and questions and it works > fine in the actual application but when I try to do any unit-testing of > my User model I get this: > > ActiveRecord::RecordNotFound: Couldn''t find UserQuestionResponse without > an ID > .../gems/activerecord_1.14.2/lib/active_record/base.rb:932:in > ''find_from_ids'' > > Any ideas what is going on and what I can do about it?I still haven''t found an explanation for this- I''m figuring it''s a problem with the current version of Rails, but I don''t understand the internals of the platform enough to be able to resolve it. Does anyone have any working unit tests involving a table without an id field? -- Posted via http://www.ruby-forum.com/.
Alex Wayne
2006-Jun-07 16:29 UTC
[Rails] Re: Unit Tests crashing out for a table without an ID
ben moxon wrote:> ActiveRecord::RecordNotFound: Couldn''t find UserQuestionResponse without > an ID > .../gems/activerecord_1.14.2/lib/active_record/base.rb:932:in > ''find_from_ids''Is that as far back as the stack trace goes? Take it back all the way to see if at any point you are executing app code rather than framework code. Also make sure your fixtures are correct, and not trying to insert ids where they shouldnt. -- Posted via http://www.ruby-forum.com/.
Forrest Chang
2006-Jun-07 17:24 UTC
[Rails] Unit Tests crashing out for a table without an ID
I''ve gotten this error when I''ve accidentally passed nil as the id (due to some processing error that sets the variable passed to find() ) You might check that the id you passed is legit Forrest On 6/2/06, ben moxon <glenatron@gmail.com> wrote:> I''m having problems unit testing my model- I have a kind of quiz > functionality user table and a question table and a > user_question_response table that contains the id for the user, the id > for the question and the user''s response. The user_question_response has > it''s own model belongs_to/has_many with users and questions and it works > fine in the actual application but when I try to do any unit-testing of > my User model I get this: > > ActiveRecord::RecordNotFound: Couldn''t find UserQuestionResponse without > an ID > .../gems/activerecord_1.14.2/lib/active_record/base.rb:932:in > ''find_from_ids'' > > Any ideas what is going on and what I can do about it? > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Brian Hogan
2006-Jun-07 17:35 UTC
[Rails] Unit Tests crashing out for a table without an ID
What database are you using for your test database? Have you loaded all fixtures in your test? On 6/7/06, Forrest Chang <fkchang2000@gmail.com> wrote:> I''ve gotten this error when I''ve accidentally passed nil as the id > (due to some processing error that sets the variable passed to find() > ) > > You might check that the id you passed is legit > > Forrest > > On 6/2/06, ben moxon <glenatron@gmail.com> wrote: > > I''m having problems unit testing my model- I have a kind of quiz > > functionality user table and a question table and a > > user_question_response table that contains the id for the user, the id > > for the question and the user''s response. The user_question_response has > > it''s own model belongs_to/has_many with users and questions and it works > > fine in the actual application but when I try to do any unit-testing of > > my User model I get this: > > > > ActiveRecord::RecordNotFound: Couldn''t find UserQuestionResponse without > > an ID > > .../gems/activerecord_1.14.2/lib/active_record/base.rb:932:in > > ''find_from_ids'' > > > > Any ideas what is going on and what I can do about it? > > > > -- > > Posted via http://www.ruby-forum.com/. > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
ben moxon
2006-Jun-08 14:15 UTC
[Rails] Re: Unit Tests crashing out for a table without an ID
Brian Hogan wrote:> What database are you using for your test database? > Have you loaded all fixtures in your test?Using MySQL, 4.current - the error comes during the fixture loading part - the fixture itself I generated directly from my development database, where it is working fine, so I know the data works when the application is up and running. The table is a classic annotated link so it has user_id, question_id and question_response - no normal id field because there will only ever be one response for any combination of user_id and question_id. I''m pretty sure this is the root of the problem but I don''t understand why it only comes up during testing. -- Posted via http://www.ruby-forum.com/.
ben moxon
2006-Jun-08 14:21 UTC
[Rails] Re: Unit Tests crashing out for a table without an ID
Alex Wayne wrote:> ben moxon wrote: >> ActiveRecord::RecordNotFound: Couldn''t find UserQuestionResponse without >> an ID >> .../gems/activerecord_1.14.2/lib/active_record/base.rb:932:in >> ''find_from_ids'' > > > Is that as far back as the stack trace goes? Take it back all the way > to see if at any point you are executing app code rather than framework > code. > > Also make sure your fixtures are correct, and not trying to insert ids > where they shouldnt.That is the top of the stack trace. It begins with .../gems/activerecord_1.14.2/lib/active_record/fixtures.rb:547:in ''setup'' My code doesn''t appear in the stack trace at all, which is why I don''t really know where to start fixing it. It''s like ActiveRecord is trying to perform an UPDATE but doesn''t know what to do it with because it can''t find the ID field. I don''t know why it would be doing that, though... -- Posted via http://www.ruby-forum.com/.