Frederick Cheung
2008-Sep-15 12:59 UTC
Anyone know what test_with_limiting_with_custom_select is testing ?
finder_test.rb (in active_record) has this test: def test_with_limiting_with_custom_select posts = Post.find(:all, :include => :author, :select => '' posts.*, authors.id as "author_id"'', :limit => 3, :order => ''posts.id'') assert_equal 3, posts.size assert_equal [0, 1, 1], posts.map(&:author_id).sort end But what is it testing (given that :include overwrites the select option) ? If the select wasn''t ignored then the test fails as the author_id from posts would be overwritten by the one from the select, ie the post with author_id 0 would get an author_id of NULL (which I found out precisely because I have altered old-skool include not to squash :select and this is the one failing test) Fred --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
Michael Koziarski
2008-Sep-15 15:18 UTC
Re: Anyone know what test_with_limiting_with_custom_select is testing ?
Frederick Cheung wrote:> finder_test.rb (in active_record) has this test: > > def test_with_limiting_with_custom_select > posts = Post.find(:all, :include => :author, :select => '' posts.*, > authors.id as "author_id"'', :limit => 3, :order => ''posts.id'') > assert_equal 3, posts.size > assert_equal [0, 1, 1], posts.map(&:author_id).sort > end > > But what is it testing (given that :include overwrites the select > option) ?Looks like what it''s *meant* to be testing is that you can specify a custom :select while using :include. It''s obviously doing a pretty poor job if this because: 1) You can''t do this 2) the piggy-back attribute would be selected anyway. So if you want to fix it you could update the column selected to be something else, with another name say REVERSE(authors.name) AS backwards_name. -- Cheers, Koz --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Sep-15 16:13 UTC
Re: Anyone know what test_with_limiting_with_custom_select is testing ?
On 15 Sep 2008, at 16:18, Michael Koziarski wrote:> > Frederick Cheung wrote: >> finder_test.rb (in active_record) has this test: >> >> def test_with_limiting_with_custom_select >> posts = Post.find(:all, :include => :author, :select => '' posts.*, >> authors.id as "author_id"'', :limit => 3, :order => ''posts.id'') >> assert_equal 3, posts.size >> assert_equal [0, 1, 1], posts.map(&:author_id).sort >> end >> >> But what is it testing (given that :include overwrites the select >> option) ? > > Looks like what it''s *meant* to be testing is that you can specify a > custom :select while using :include. It''s obviously doing a pretty > poor > job if this because: > > 1) You can''t do this > 2) the piggy-back attribute would be selected anyway. > > So if you want to fix it you could update the column selected to be > something else, with another name say REVERSE(authors.name) AS > backwards_name.Cool, that''s what I thought. i''ll do something like that then. Fred --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---