Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Ensure whitespaces are stripped when merging string joins. [#1297 sta…
…te:resolved]

Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
  • Loading branch information
FiXato authored and lifo committed Jan 28, 2009
1 parent f725b19 commit a0d8202
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/base.rb
Expand Up @@ -1715,7 +1715,7 @@ def merge_joins(*joins)
end
join
end
joins.flatten.uniq
joins.flatten.map{|j| j.strip}.uniq
else
joins.collect{|j| safe_to_array(j)}.flatten.uniq
end
Expand Down
10 changes: 10 additions & 0 deletions activerecord/test/cases/method_scoping_test.rb
Expand Up @@ -186,6 +186,16 @@ def test_scoped_find_merges_joins_and_eliminates_duplicate_string_joins
assert_equal authors(:david).attributes, scoped_authors.first.attributes
end

def test_scoped_find_strips_spaces_from_string_joins_and_eliminates_duplicate_string_joins
scoped_authors = Author.with_scope(:find => { :joins => ' INNER JOIN posts ON posts.author_id = authors.id '}) do
Author.find(:all, :select => 'DISTINCT authors.*', :joins => ['INNER JOIN posts ON posts.author_id = authors.id'], :conditions => 'posts.id = 1')
end
assert scoped_authors.include?(authors(:david))
assert !scoped_authors.include?(authors(:mary))
assert_equal 1, scoped_authors.size
assert_equal authors(:david).attributes, scoped_authors.first.attributes
end

def test_scoped_count_include
# with the include, will retrieve only developers for the given project
Developer.with_scope(:find => { :include => :projects }) do
Expand Down

0 comments on commit a0d8202

Please sign in to comment.