From 686e820c48ec8d1509e160816626b7418fb04b13 Mon Sep 17 00:00:00 2001 From: Robin Dupret Date: Mon, 3 Mar 2014 14:15:59 +0100 Subject: Add a comment to ensure that a test won't be removed [ci skip] The 'cow' => 'kine' inflection has gone with c300dca9 but it should not be removed from the tested irregularities since it ensures that inflections work with words that do not begin with the same letters. --- activesupport/test/inflector_test_cases.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activesupport') diff --git a/activesupport/test/inflector_test_cases.rb b/activesupport/test/inflector_test_cases.rb index 4bd1b2e47c..dd03a61176 100644 --- a/activesupport/test/inflector_test_cases.rb +++ b/activesupport/test/inflector_test_cases.rb @@ -314,7 +314,7 @@ module InflectorTestCases 'child' => 'children', 'sex' => 'sexes', 'move' => 'moves', - 'cow' => 'kine', + 'cow' => 'kine', # Test inflections with different starting letters 'zombie' => 'zombies', 'genus' => 'genera' } -- cgit v1.2.3 From 7d98247446e9f043dc9b6b5cbdb938877dd00a81 Mon Sep 17 00:00:00 2001 From: Arthur Neves Date: Mon, 3 Mar 2014 20:50:31 -0500 Subject: Cache key should be different when is Array. `cache.fetch(['foo'])` and `cache.fetch('foo')` should generate different cache keys as they are not equivalents. [related #8615] [related #8614] --- activesupport/CHANGELOG.md | 5 +++++ activesupport/lib/active_support/cache.rb | 7 ++++--- activesupport/test/caching_test.rb | 6 +++++- 3 files changed, 14 insertions(+), 4 deletions(-) (limited to 'activesupport') diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md index 38a761384e..47580ca0a3 100644 --- a/activesupport/CHANGELOG.md +++ b/activesupport/CHANGELOG.md @@ -1,3 +1,8 @@ +* Cache key should add a trailing slash when the key is an array, + so `cache.fetch('foo')` and `cache.fetch(['foo'])` wont conflict. + + *arthurnn* + * Change the signature of `fetch_multi` to return a hash rather than an array. This makes it consistent with the output of `read_multi`. diff --git a/activesupport/lib/active_support/cache.rb b/activesupport/lib/active_support/cache.rb index a627fa8651..f23f6f16d6 100644 --- a/activesupport/lib/active_support/cache.rb +++ b/activesupport/lib/active_support/cache.rb @@ -511,7 +511,7 @@ module ActiveSupport # called. If the key is a Hash, then keys will be sorted alphabetically. def expanded_key(key) # :nodoc: return key.cache_key.to_s if key.respond_to?(:cache_key) - + trailing_slash = false case key when Array if key.size > 1 @@ -519,11 +519,12 @@ module ActiveSupport else key = key.first end + trailing_slash = true when Hash key = key.sort_by { |k,_| k.to_s }.collect{|k,v| "#{k}=#{v}"} end - - key.to_param + key = key.to_param + trailing_slash ? "#{key}/" : key end # Prefix a key with the namespace. Namespace and key will be delimited diff --git a/activesupport/test/caching_test.rb b/activesupport/test/caching_test.rb index 18923f61d1..64d8792dde 100644 --- a/activesupport/test/caching_test.rb +++ b/activesupport/test/caching_test.rb @@ -257,6 +257,10 @@ module CacheStoreBehavior assert_nil @cache.fetch('foo') { 'baz' } end + def test_fetch_with_array_and_without + assert_not_equal @cache.fetch('foo') { 'barz' }, @cache.fetch(['foo']) { 'barr' } + end + def test_should_read_and_write_hash assert @cache.write('foo', {:a => "b"}) assert_equal({:a => "b"}, @cache.read('foo')) @@ -349,7 +353,7 @@ module CacheStoreBehavior def test_array_as_cache_key @cache.write([:fu, "foo"], "bar") - assert_equal "bar", @cache.read("fu/foo") + assert_equal "bar", @cache.read("fu/foo/") end def test_hash_as_cache_key -- cgit v1.2.3 From ccf8f27dddcc36fa5c91f614647e0b0bac861d83 Mon Sep 17 00:00:00 2001 From: Godfrey Chan Date: Tue, 4 Mar 2014 17:58:58 -0800 Subject: Revert "Merge pull request #14269 from arthurnn/expanded_key_array" This reverts commit 475c96589ca65282e1a61350271c2f83f0d4044f, reversing changes made to 705915ab5cf24430892107764b0050c07e1df583. We decided that this is not worth busting everyone's cache as this seems like a very unlikely problem. The problem only occurs when the user is 1) not using a namespace, or 2) using the same namesapce for different *kinds* of cache items. The recommended "fix" is to put those cache items into their own namspace: id = 1 Rails.cache.fetch(id, namespace: "user"){ User.find(id) } ids = [1] Rails.cache.fetch(ids, namespace: "users"){ User.find(ids) } See the discussion on #14269 for details. --- activesupport/CHANGELOG.md | 5 ----- activesupport/lib/active_support/cache.rb | 7 +++---- activesupport/test/caching_test.rb | 6 +----- 3 files changed, 4 insertions(+), 14 deletions(-) (limited to 'activesupport') diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md index 47580ca0a3..38a761384e 100644 --- a/activesupport/CHANGELOG.md +++ b/activesupport/CHANGELOG.md @@ -1,8 +1,3 @@ -* Cache key should add a trailing slash when the key is an array, - so `cache.fetch('foo')` and `cache.fetch(['foo'])` wont conflict. - - *arthurnn* - * Change the signature of `fetch_multi` to return a hash rather than an array. This makes it consistent with the output of `read_multi`. diff --git a/activesupport/lib/active_support/cache.rb b/activesupport/lib/active_support/cache.rb index f23f6f16d6..a627fa8651 100644 --- a/activesupport/lib/active_support/cache.rb +++ b/activesupport/lib/active_support/cache.rb @@ -511,7 +511,7 @@ module ActiveSupport # called. If the key is a Hash, then keys will be sorted alphabetically. def expanded_key(key) # :nodoc: return key.cache_key.to_s if key.respond_to?(:cache_key) - trailing_slash = false + case key when Array if key.size > 1 @@ -519,12 +519,11 @@ module ActiveSupport else key = key.first end - trailing_slash = true when Hash key = key.sort_by { |k,_| k.to_s }.collect{|k,v| "#{k}=#{v}"} end - key = key.to_param - trailing_slash ? "#{key}/" : key + + key.to_param end # Prefix a key with the namespace. Namespace and key will be delimited diff --git a/activesupport/test/caching_test.rb b/activesupport/test/caching_test.rb index 64d8792dde..18923f61d1 100644 --- a/activesupport/test/caching_test.rb +++ b/activesupport/test/caching_test.rb @@ -257,10 +257,6 @@ module CacheStoreBehavior assert_nil @cache.fetch('foo') { 'baz' } end - def test_fetch_with_array_and_without - assert_not_equal @cache.fetch('foo') { 'barz' }, @cache.fetch(['foo']) { 'barr' } - end - def test_should_read_and_write_hash assert @cache.write('foo', {:a => "b"}) assert_equal({:a => "b"}, @cache.read('foo')) @@ -353,7 +349,7 @@ module CacheStoreBehavior def test_array_as_cache_key @cache.write([:fu, "foo"], "bar") - assert_equal "bar", @cache.read("fu/foo/") + assert_equal "bar", @cache.read("fu/foo") end def test_hash_as_cache_key -- cgit v1.2.3 From 2dd2fcf89673afbcf95240ecebaf34826a195164 Mon Sep 17 00:00:00 2001 From: Prem Sichanugrist Date: Tue, 18 Feb 2014 16:13:23 -0500 Subject: Introduce `Rails.gem_version` This method return `Gem::Version.new(Rails.version)`, suggesting a more reliable way to perform version comparison. Example: Rails.version #=> "4.1.2" Rails.gem_version #=> # Rails.version > "4.1.10" #=> false Rails.gem_version > Gem::Version.new("4.1.10") #=> true Gem::Requirement.new("~> 4.1.2") =~ Rails.gem_version #=> true This was originally introduced as `.version` by @charliesome in #8501 but got reverted in #10002 since it was not backward compatible. Also, updating template for `rake update_versions`. --- activesupport/lib/active_support/gem_version.rb | 15 +++++++++++++++ activesupport/lib/active_support/version.rb | 11 ++++------- 2 files changed, 19 insertions(+), 7 deletions(-) create mode 100644 activesupport/lib/active_support/gem_version.rb (limited to 'activesupport') diff --git a/activesupport/lib/active_support/gem_version.rb b/activesupport/lib/active_support/gem_version.rb new file mode 100644 index 0000000000..83a3bf7a5d --- /dev/null +++ b/activesupport/lib/active_support/gem_version.rb @@ -0,0 +1,15 @@ +module ActiveSupport + # Returns the version of the currently loaded ActiveSupport as a Gem::Version + def self.gem_version + Gem::Version.new VERSION::STRING + end + + module VERSION + MAJOR = 4 + MINOR = 2 + TINY = 0 + PRE = "alpha" + + STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".") + end +end diff --git a/activesupport/lib/active_support/version.rb b/activesupport/lib/active_support/version.rb index 38f726ea34..fe03984546 100644 --- a/activesupport/lib/active_support/version.rb +++ b/activesupport/lib/active_support/version.rb @@ -1,11 +1,8 @@ +require_relative 'gem_version' + module ActiveSupport - # Returns the version of the currently loaded ActiveSupport as a Gem::Version + # Returns the version of the currently loaded ActiveSupport as a Gem::Version def self.version - Gem::Version.new "4.2.0.alpha" - end - - module VERSION #:nodoc: - MAJOR, MINOR, TINY, PRE = ActiveSupport.version.segments - STRING = ActiveSupport.version.to_s + gem_version end end -- cgit v1.2.3 From a94966ea094fcfd94cf09642d3a561af80c64602 Mon Sep 17 00:00:00 2001 From: Arthur Neves Date: Wed, 26 Feb 2014 15:22:52 -0500 Subject: Fix OrderedHash.select to return self instance. On ruby 2.1.1 the behavior of .select and .reject has changed. They will return a Hash new instance, so we need to override them to keep the instance object class. --- activesupport/lib/active_support/ordered_hash.rb | 4 ++++ activesupport/test/ordered_hash_test.rb | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/ordered_hash.rb b/activesupport/lib/active_support/ordered_hash.rb index 58a2ce2105..4680d5acb7 100644 --- a/activesupport/lib/active_support/ordered_hash.rb +++ b/activesupport/lib/active_support/ordered_hash.rb @@ -28,6 +28,10 @@ module ActiveSupport coder.represent_seq '!omap', map { |k,v| { k => v } } end + def select(*args, &block) + dup.tap { |hash| hash.select!(*args, &block) } + end + def reject(*args, &block) dup.tap { |hash| hash.reject!(*args, &block) } end diff --git a/activesupport/test/ordered_hash_test.rb b/activesupport/test/ordered_hash_test.rb index 0b54026c64..460a61613e 100644 --- a/activesupport/test/ordered_hash_test.rb +++ b/activesupport/test/ordered_hash_test.rb @@ -120,7 +120,9 @@ class OrderedHashTest < ActiveSupport::TestCase end def test_select - assert_equal @keys, @ordered_hash.select { true }.map(&:first) + new_ordered_hash = @ordered_hash.select { true } + assert_equal @keys, new_ordered_hash.map(&:first) + assert_instance_of ActiveSupport::OrderedHash, new_ordered_hash end def test_delete_if @@ -143,6 +145,7 @@ class OrderedHashTest < ActiveSupport::TestCase assert_equal copy, @ordered_hash assert !new_ordered_hash.keys.include?('pink') assert @ordered_hash.keys.include?('pink') + assert_instance_of ActiveSupport::OrderedHash, new_ordered_hash end def test_clear -- cgit v1.2.3 From 28d05f0a80e640cc66a9cf77dcc44a673e85d4eb Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 12 Mar 2014 13:34:07 -0700 Subject: use method_defined? to check whether or not a method is defined --- activesupport/lib/active_support/testing/declarative.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/testing/declarative.rb b/activesupport/lib/active_support/testing/declarative.rb index c349bb5fb1..e709e6edf5 100644 --- a/activesupport/lib/active_support/testing/declarative.rb +++ b/activesupport/lib/active_support/testing/declarative.rb @@ -34,7 +34,7 @@ module ActiveSupport # end def test(name, &block) test_name = "test_#{name.gsub(/\s+/,'_')}".to_sym - defined = instance_method(test_name) rescue false + defined = method_defined? test_name raise "#{test_name} is already defined in #{self}" if defined if block_given? define_method(test_name, &block) -- cgit v1.2.3 From e88da370f190cabd1e9750c5b3531735950ab415 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Thu, 13 Mar 2014 10:55:52 -0700 Subject: make tests pass on Ruby 2.2 Apparently we've been using a buggy feature for the past 6 years: https://bugs.ruby-lang.org/issues/9593 --- activesupport/lib/active_support/values/time_zone.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/values/time_zone.rb b/activesupport/lib/active_support/values/time_zone.rb index eb785d46ce..38f0d268f4 100644 --- a/activesupport/lib/active_support/values/time_zone.rb +++ b/activesupport/lib/active_support/values/time_zone.rb @@ -282,7 +282,7 @@ module ActiveSupport # # Time.zone.now # => Fri, 31 Dec 1999 14:00:00 HST -10:00 # Time.zone.parse('22:30:00') # => Fri, 31 Dec 1999 22:30:00 HST -10:00 - def parse(str, now=now) + def parse(str, now=now()) parts = Date._parse(str, false) return if parts.empty? -- cgit v1.2.3