From 2645ee69e5537667e518172f2f7873b2cbea5da5 Mon Sep 17 00:00:00 2001 From: Filip H.F. "FiXato" Slagter Date: Thu, 30 Oct 2008 11:40:09 +0100 Subject: [PATCH] Strip whitespaces when merging string joins. --- activerecord/lib/active_record/base.rb | 2 +- activerecord/test/cases/method_scoping_test.rb | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletions(-) diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index a36a137..0c002e4 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -1643,7 +1643,7 @@ module ActiveRecord #:nodoc: end join end - joins.flatten.uniq + joins.flatten.map{|j|j.strip}.uniq else joins.collect{|j| safe_to_array(j)}.flatten.uniq end diff --git a/activerecord/test/cases/method_scoping_test.rb b/activerecord/test/cases/method_scoping_test.rb index ff10bfa..486b1ad 100644 --- a/activerecord/test/cases/method_scoping_test.rb +++ b/activerecord/test/cases/method_scoping_test.rb @@ -168,6 +168,16 @@ class MethodScopingTest < ActiveRecord::TestCase 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 -- 1.5.6.4