Skip to content
This repository
Browse code

Ensure whitespaces are stripped when merging string joins. [#1297 sta…

…te:resolved]

Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
  • Loading branch information...
commit a0d8202bb9fa55c328a3170836b0cddb40631e83 1 parent f725b19
Filip H.F. "FiXato" Slagter authored October 30, 2008 lifo committed January 28, 2009
2  activerecord/lib/active_record/base.rb
@@ -1715,7 +1715,7 @@ def merge_joins(*joins)
1715 1715
               end
1716 1716
               join
1717 1717
             end
1718  
-            joins.flatten.uniq
  1718
+            joins.flatten.map{|j| j.strip}.uniq
1719 1719
           else
1720 1720
             joins.collect{|j| safe_to_array(j)}.flatten.uniq
1721 1721
           end
10  activerecord/test/cases/method_scoping_test.rb
@@ -186,6 +186,16 @@ def test_scoped_find_merges_joins_and_eliminates_duplicate_string_joins
186 186
     assert_equal authors(:david).attributes, scoped_authors.first.attributes
187 187
   end
188 188
 
  189
+  def test_scoped_find_strips_spaces_from_string_joins_and_eliminates_duplicate_string_joins
  190
+    scoped_authors = Author.with_scope(:find => { :joins => ' INNER JOIN posts ON posts.author_id = authors.id '}) do
  191
+      Author.find(:all, :select => 'DISTINCT authors.*', :joins => ['INNER JOIN posts ON posts.author_id = authors.id'], :conditions => 'posts.id = 1')
  192
+    end
  193
+    assert scoped_authors.include?(authors(:david))
  194
+    assert !scoped_authors.include?(authors(:mary))
  195
+    assert_equal 1, scoped_authors.size
  196
+    assert_equal authors(:david).attributes, scoped_authors.first.attributes
  197
+  end
  198
+
189 199
   def test_scoped_count_include
190 200
     # with the include, will retrieve only developers for the given project
191 201
     Developer.with_scope(:find => { :include => :projects }) do

0 notes on commit a0d8202

Please sign in to comment.
Something went wrong with that request. Please try again.