From 05a938c5f7804fd59c76c45df096e6ebff871a18 Mon Sep 17 00:00:00 2001 From: Christoffer Sawicki Date: Tue, 18 Nov 2008 23:00:35 +0100 Subject: Added ActiveSupport::OrderedHash#each_key and ActiveSupport::OrderedHash#each_value [#1410 state:resolved] Signed-off-by: Pratik Naik --- activesupport/CHANGELOG | 2 ++ activesupport/lib/active_support/ordered_hash.rb | 8 ++++++++ activesupport/test/ordered_hash_test.rb | 12 ++++++++++++ 3 files changed, 22 insertions(+) diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG index 9e7dc458b4..d142f21d61 100644 --- a/activesupport/CHANGELOG +++ b/activesupport/CHANGELOG @@ -1,5 +1,7 @@ *2.3.0 [Edge]* +* Added ActiveSupport::OrderedHash#each_key and ActiveSupport::OrderedHash#each_value #1410 [Christoffer Sawicki] + * Added ActiveSupport::MessageVerifier and MessageEncryptor to aid users who need to store signed and/or encrypted messages. [Koz] * Added ActiveSupport::BacktraceCleaner to cut down on backtrace noise according to filters and silencers [DHH] diff --git a/activesupport/lib/active_support/ordered_hash.rb b/activesupport/lib/active_support/ordered_hash.rb index 9757054e43..5de94c67e0 100644 --- a/activesupport/lib/active_support/ordered_hash.rb +++ b/activesupport/lib/active_support/ordered_hash.rb @@ -53,6 +53,14 @@ module ActiveSupport end alias_method :value?, :has_value? + + def each_key + each { |key, value| yield key } + end + + def each_value + each { |key, value| yield value } + end end end end diff --git a/activesupport/test/ordered_hash_test.rb b/activesupport/test/ordered_hash_test.rb index 98a6ad6b26..17dffbd624 100644 --- a/activesupport/test/ordered_hash_test.rb +++ b/activesupport/test/ordered_hash_test.rb @@ -61,4 +61,16 @@ class OrderedHashTest < Test::Unit::TestCase assert_equal false, @ordered_hash.has_value?('ABCABC') assert_equal false, @ordered_hash.value?('ABCABC') end + + def test_each_key + keys = [] + @ordered_hash.each_key { |k| keys << k } + assert_equal @keys, keys + end + + def test_each_value + values = [] + @ordered_hash.each_value { |v| values << v } + assert_equal @values, values + end end -- cgit v1.2.3 From 17940a82e8cb0ed278e1552b943dd033763978a1 Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Wed, 26 Nov 2008 15:01:59 +0100 Subject: Don't re-require 'rexml/document' --- activesupport/lib/active_support/xml_mini.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/activesupport/lib/active_support/xml_mini.rb b/activesupport/lib/active_support/xml_mini.rb index d0b660f7bd..bfc3d7b00b 100644 --- a/activesupport/lib/active_support/xml_mini.rb +++ b/activesupport/lib/active_support/xml_mini.rb @@ -17,7 +17,7 @@ module XmlMini # string:: # XML Document string to parse def parse(string) - require 'rexml/document' + require 'rexml/document' unless defined?(REXML::Document) doc = REXML::Document.new(string) merge_element!({}, doc.root) end -- cgit v1.2.3 From 9a4d557713acb0fc8e80f61af18094034aca029a Mon Sep 17 00:00:00 2001 From: Paul Date: Wed, 26 Nov 2008 15:21:12 +0100 Subject: Ensure hash conditions on referenced tables are considered when eager loading with limit/offset. [#1404 state:resolved] Signed-off-by: Pratik Naik --- activerecord/lib/active_record/associations.rb | 1 + activerecord/test/cases/associations/eager_test.rb | 20 ++++++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index 63e28a43ab..0546b76c63 100755 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -1733,6 +1733,7 @@ module ActiveRecord case cond when nil then all when Array then all << cond.first + when Hash then all << cond.keys else all << cond end end diff --git a/activerecord/test/cases/associations/eager_test.rb b/activerecord/test/cases/associations/eager_test.rb index a4f1f65f9a..3c8408d14b 100644 --- a/activerecord/test/cases/associations/eager_test.rb +++ b/activerecord/test/cases/associations/eager_test.rb @@ -385,12 +385,28 @@ class EagerAssociationTest < ActiveRecord::TestCase assert_equal count, posts.size end - def test_eager_with_has_many_and_limit_ond_high_offset + def test_eager_with_has_many_and_limit_and_high_offset posts = Post.find(:all, :include => [ :author, :comments ], :limit => 2, :offset => 10, :conditions => [ "authors.name = ?", 'David' ]) assert_equal 0, posts.size end - def test_count_eager_with_has_many_and_limit_ond_high_offset + def test_eager_with_has_many_and_limit_and_high_offset_and_multiple_array_conditions + assert_queries(1) do + posts = Post.find(:all, :include => [ :author, :comments ], :limit => 2, :offset => 10, + :conditions => [ "authors.name = ? and comments.body = ?", 'David', 'go crazy' ]) + assert_equal 0, posts.size + end + end + + def test_eager_with_has_many_and_limit_and_high_offset_and_multiple_hash_conditions + assert_queries(1) do + posts = Post.find(:all, :include => [ :author, :comments ], :limit => 2, :offset => 10, + :conditions => { 'authors.name' => 'David', 'comments.body' => 'go crazy' }) + assert_equal 0, posts.size + end + end + + def test_count_eager_with_has_many_and_limit_and_high_offset posts = Post.count(:all, :include => [ :author, :comments ], :limit => 2, :offset => 10, :conditions => [ "authors.name = ?", 'David' ]) assert_equal 0, posts end -- cgit v1.2.3