I''m testing the relation between two of my models: MessageThread (parent), which has_many Message (children). When I run the following test, it gives me an error: --------------------------------- # test with a valid message def test_valid_message_new thread = MessageThread.new :title => ''awesome thread'' message = thread.messages.build(:body =>''total awesomeness'') assert thread.valid?, ''thread not valid'' assert (thread.messages.size == 1) assert_equal ''total awesomeness'', message.body assert !thread.messages[0].nil? #line 182, and the line below, line 183 assert thread.messages.find(:first, :conditions => {:body => ''total awesomeness''}), ''Cannot find message'' end --------------------------------- Loaded suite message_thread_test Started .............F Finished in 0.285501 seconds. 1) Failure: test_valid_message_new(MessageThreadTest) [message_thread_test.rb: 183]: Cannot find message. <nil> is not true. --------------------------------- Why doesn''t method find() find anything? Is the :condition parameter incorrect? I tried saving message, but it still didn''t find the message I was looking for. Is the find method deprecated? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 4 Jan 2008, at 16:37, Taro wrote:> > I''m testing the relation between two of my models: MessageThread > (parent), which has_many Message (children). When I run the following > test, it gives me an error: > --------------------------------- > # test with a valid message > def test_valid_message_new > thread = MessageThread.new :title => ''awesome thread'' > message = thread.messages.build(:body =>''total awesomeness'') > assert thread.valid?, ''thread not valid'' > assert (thread.messages.size == 1) > assert_equal ''total awesomeness'', message.body > assert !thread.messages[0].nil? > #line 182, and the line below, line 183 > assert thread.messages.find(:first, :conditions => {:body => > ''total awesomeness''}), ''Cannot find message'' > end > > --------------------------------- > Loaded suite message_thread_test > Started > .............F > Finished in 0.285501 seconds. > > 1) Failure: > test_valid_message_new(MessageThreadTest) [message_thread_test.rb: > 183]: > Cannot find message. > <nil> is not true. > --------------------------------- > Why doesn''t method find() find anything? Is the :condition parameter > incorrect? I tried saving message, but it still didn''t find the > message I was looking for. Is the find method deprecated?Neither of those objects have been saved, so there is nothing to find. you would have to save both thread & message. Fred> > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung wrote:> On 4 Jan 2008, at 16:37, Taro wrote: > >> assert (thread.messages.size == 1) >> .............F >> message I was looking for. Is the find method deprecated? > Neither of those objects have been saved, so there is nothing to find. > you would have to save both thread & message. > > FredFred is a genius.... -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Ahhh..I have to save the thread....I see. Thank you. On Jan 4, 11:46 am, "gemblon (t.b.)" <rails-mailing-l...@andreas- s.net> wrote:> Frederick Cheung wrote: > > On 4 Jan 2008, at 16:37, Taro wrote: > > >> assert (thread.messages.size == 1) > >> .............F > >> message I was looking for. Is the find method deprecated? > > Neither of those objects have been saved, so there is nothing to find. > > you would have to save both thread & message. > > > Fred > > Fred is a genius.... > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
OK, new problem: This time, I''m using MessageBoard (child) to acts_as_list for Forum (parent). The models looks as such: ----------------------------- class Forum < ActiveRecord::Base #This is a superset of message boards has_many :message_boards, :order => :order, :dependent => :destroy ... end ----------------------------- class MessageBoard < ActiveRecord::Base #This is a subset of forums belongs_to :forum #This causes MessageBoard to act as a list #it uses order as its index acts_as_list :scope => :forum_id ... end ----------------------------- A slight mistake on my part, I wanted the message boards to be ordered by the MySQL (I use Rails 1.2.5) column :order (as seen in line :order => :order). However, this error arises: ----------------------------- Loaded suite message_board_test Started ........E. Finished in 0.347567 seconds. 1) Error: test_title_overlap(MessageBoardTest): ActiveRecord::StatementInvalid: Mysql::Error: #42S22Unknown column ''position'' in ''order clause'': SELECT * FROM message_boards WHERE (forum_id = 2) ORDER BY position DESC LIMIT 1 .... ----------------------------- Does the column name HAVE to be "position"? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 4 Jan 2008, at 21:26, Taro wrote:> > 1) Error: > test_title_overlap(MessageBoardTest): > ActiveRecord::StatementInvalid: Mysql::Error: #42S22Unknown column > ''position'' in ''order clause'': SELECT * FROM message_boards WHERE > (forum_id = 2) ORDER BY position DESC LIMIT 1 > .... > ----------------------------- > Does the column name HAVE to be "position"?No: use the :column option to acts_as_list Fred> > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Maybe Matching Threads
- 2.3 Nested Model Forms; build new without updating existing
- To field was not correct indexed by FTS
- install DVD mounted -noexec by default == bad interpreter permission denied
- textilize/markdown/sanitize for messageboards, oh my!
- The Agile Book Messageboard?