diff options
-rw-r--r-- | Gemfile | 2 | ||||
-rw-r--r-- | actionpack/CHANGELOG.md | 21 | ||||
-rw-r--r-- | actionpack/lib/action_view/asset_paths.rb | 2 | ||||
-rw-r--r-- | actionpack/test/template/asset_tag_helper_test.rb | 40 | ||||
-rw-r--r-- | activerecord/CHANGELOG.md | 4 | ||||
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb | 8 | ||||
-rw-r--r-- | activerecord/test/cases/disconnected_test.rb | 26 | ||||
-rw-r--r-- | activesupport/CHANGELOG.md | 4 | ||||
-rw-r--r-- | activesupport/lib/active_support/core_ext/time/calculations.rb | 12 | ||||
-rw-r--r-- | activesupport/test/core_ext/time_ext_test.rb | 22 |
10 files changed, 126 insertions, 15 deletions
@@ -53,7 +53,7 @@ end platforms :ruby do gem 'yajl-ruby' - gem 'nokogiri', '>= 1.4.5' + gem 'nokogiri', '>= 1.4.5', '< 1.6' # AR gem 'sqlite3', '~> 1.3.5' diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md index 9d50342867..585cad24db 100644 --- a/actionpack/CHANGELOG.md +++ b/actionpack/CHANGELOG.md @@ -1,5 +1,26 @@ ## unreleased ## +* Use a case insensitive URI Regexp for #asset_path. + + This fix a problem where the same asset path using different case are generating + different URIs. + + Before: + + image_tag("HTTP://google.com") + # => "<img alt=\"Google\" src=\"/assets/HTTP://google.com\" />" + image_tag("http://google.com") + # => "<img alt=\"Google\" src=\"http://google.com\" />" + + After: + + image_tag("HTTP://google.com") + # => "<img alt=\"Google\" src=\"HTTP://google.com\" />" + image_tag("http://google.com") + # => "<img alt=\"Google\" src=\"http://google.com\" />" + + *David Celis + Rafael Mendonça França* + * Fix explicit names on multiple file fields. If a file field tag has the multiple option, it is turned into an array field (appending `[]`), but if an explicit name is passed to `file_field` the `[]` is not diff --git a/actionpack/lib/action_view/asset_paths.rb b/actionpack/lib/action_view/asset_paths.rb index c192d3704e..636a37b699 100644 --- a/actionpack/lib/action_view/asset_paths.rb +++ b/actionpack/lib/action_view/asset_paths.rb @@ -43,7 +43,7 @@ module ActionView end def is_uri?(path) - path =~ %r{^[-a-z]+://|^(?:cid|data):|^//} + path =~ %r{^[-a-z]+://|^(?:cid|data):|^//}i end private diff --git a/actionpack/test/template/asset_tag_helper_test.rb b/actionpack/test/template/asset_tag_helper_test.rb index b1a01b53b1..6b1bc01f54 100644 --- a/actionpack/test/template/asset_tag_helper_test.rb +++ b/actionpack/test/template/asset_tag_helper_test.rb @@ -79,13 +79,17 @@ class AssetTagHelperTest < ActionView::TestCase JavascriptPathToTag = { %(javascript_path("xmlhr")) => %(/javascripts/xmlhr.js), %(javascript_path("super/xmlhr")) => %(/javascripts/super/xmlhr.js), - %(javascript_path("/super/xmlhr.js")) => %(/super/xmlhr.js) + %(javascript_path("/super/xmlhr.js")) => %(/super/xmlhr.js), + %(javascript_path("http://www.outside.com/foo.js")) => %(http://www.outside.com/foo.js), + %(javascript_path("HTTP://www.outside.com/foo.js")) => %(HTTP://www.outside.com/foo.js) } PathToJavascriptToTag = { %(path_to_javascript("xmlhr")) => %(/javascripts/xmlhr.js), %(path_to_javascript("super/xmlhr")) => %(/javascripts/super/xmlhr.js), - %(path_to_javascript("/super/xmlhr.js")) => %(/super/xmlhr.js) + %(path_to_javascript("/super/xmlhr.js")) => %(/super/xmlhr.js), + %(path_to_javascript("http://www.outside.com/foo.js")) => %(http://www.outside.com/foo.js), + %(path_to_javascript("HTTP://www.outside.com/foo.js")) => %(HTTP://www.outside.com/foo.js) } JavascriptIncludeToTag = { @@ -109,14 +113,18 @@ class AssetTagHelperTest < ActionView::TestCase %(stylesheet_path("bank")) => %(/stylesheets/bank.css), %(stylesheet_path("bank.css")) => %(/stylesheets/bank.css), %(stylesheet_path('subdir/subdir')) => %(/stylesheets/subdir/subdir.css), - %(stylesheet_path('/subdir/subdir.css')) => %(/subdir/subdir.css) + %(stylesheet_path('/subdir/subdir.css')) => %(/subdir/subdir.css), + %(stylesheet_path("http://www.outside.com/foo.css")) => %(http://www.outside.com/foo.css), + %(stylesheet_path("HTTP://www.outside.com/foo.css")) => %(HTTP://www.outside.com/foo.css) } PathToStyleToTag = { %(path_to_stylesheet("style")) => %(/stylesheets/style.css), %(path_to_stylesheet("style.css")) => %(/stylesheets/style.css), %(path_to_stylesheet('dir/file')) => %(/stylesheets/dir/file.css), - %(path_to_stylesheet('/dir/file.rcss')) => %(/dir/file.rcss) + %(path_to_stylesheet('/dir/file.rcss')) => %(/dir/file.rcss), + %(path_to_stylesheet("http://www.outside.com/foo.css")) => %(http://www.outside.com/foo.css), + %(path_to_stylesheet("HTTP://www.outside.com/foo.css")) => %(HTTP://www.outside.com/foo.css) } StyleLinkToTag = { @@ -139,14 +147,18 @@ class AssetTagHelperTest < ActionView::TestCase %(image_path("xml")) => %(/images/xml), %(image_path("xml.png")) => %(/images/xml.png), %(image_path("dir/xml.png")) => %(/images/dir/xml.png), - %(image_path("/dir/xml.png")) => %(/dir/xml.png) + %(image_path("/dir/xml.png")) => %(/dir/xml.png), + %(image_path("http://www.outside.com/foo.png")) => %(http://www.outside.com/foo.png), + %(image_path("HTTP://www.outside.com/foo.png")) => %(HTTP://www.outside.com/foo.png) } PathToImageToTag = { %(path_to_image("xml")) => %(/images/xml), %(path_to_image("xml.png")) => %(/images/xml.png), %(path_to_image("dir/xml.png")) => %(/images/dir/xml.png), - %(path_to_image("/dir/xml.png")) => %(/dir/xml.png) + %(path_to_image("/dir/xml.png")) => %(/dir/xml.png), + %(path_to_image("http://www.outside.com/foo.png")) => %(http://www.outside.com/foo.png), + %(path_to_image("HTTP://www.outside.com/foo.png")) => %(HTTP://www.outside.com/foo.png) } ImageLinkToTag = { @@ -181,14 +193,18 @@ class AssetTagHelperTest < ActionView::TestCase %(video_path("xml")) => %(/videos/xml), %(video_path("xml.ogg")) => %(/videos/xml.ogg), %(video_path("dir/xml.ogg")) => %(/videos/dir/xml.ogg), - %(video_path("/dir/xml.ogg")) => %(/dir/xml.ogg) + %(video_path("/dir/xml.ogg")) => %(/dir/xml.ogg), + %(video_path("http://www.outside.com/foo.ogg")) => %(http://www.outside.com/foo.ogg), + %(video_path("HTTP://www.outside.com/foo.ogg")) => %(HTTP://www.outside.com/foo.ogg) } PathToVideoToTag = { %(path_to_video("xml")) => %(/videos/xml), %(path_to_video("xml.ogg")) => %(/videos/xml.ogg), %(path_to_video("dir/xml.ogg")) => %(/videos/dir/xml.ogg), - %(path_to_video("/dir/xml.ogg")) => %(/dir/xml.ogg) + %(path_to_video("/dir/xml.ogg")) => %(/dir/xml.ogg), + %(path_to_video("http://www.outside.com/foo.ogg")) => %(http://www.outside.com/foo.ogg), + %(path_to_video("HTTP://www.outside.com/foo.ogg")) => %(HTTP://www.outside.com/foo.ogg) } VideoLinkToTag = { @@ -211,14 +227,18 @@ class AssetTagHelperTest < ActionView::TestCase %(audio_path("xml")) => %(/audios/xml), %(audio_path("xml.wav")) => %(/audios/xml.wav), %(audio_path("dir/xml.wav")) => %(/audios/dir/xml.wav), - %(audio_path("/dir/xml.wav")) => %(/dir/xml.wav) + %(audio_path("/dir/xml.wav")) => %(/dir/xml.wav), + %(audio_path("http://www.outside.com/foo.wav")) => %(http://www.outside.com/foo.wav), + %(audio_path("HTTP://www.outside.com/foo.wav")) => %(HTTP://www.outside.com/foo.wav) } PathToAudioToTag = { %(path_to_audio("xml")) => %(/audios/xml), %(path_to_audio("xml.wav")) => %(/audios/xml.wav), %(path_to_audio("dir/xml.wav")) => %(/audios/dir/xml.wav), - %(path_to_audio("/dir/xml.wav")) => %(/dir/xml.wav) + %(path_to_audio("/dir/xml.wav")) => %(/dir/xml.wav), + %(path_to_audio("http://www.outside.com/foo.wav")) => %(http://www.outside.com/foo.wav), + %(path_to_audio("HTTP://www.outside.com/foo.wav")) => %(HTTP://www.outside.com/foo.wav) } AudioLinkToTag = { diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index 29d218277f..199150232c 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -1,4 +1,8 @@ ## unreleased ## +* Fix mysql2 adapter raises the correct exception when executing a query on a + closed connection. + + *Yves Senn* * Fix the `:primary_key` option for `has_many` associations. Fixes #10693. diff --git a/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb b/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb index 524a7d30fc..c690b982a1 100644 --- a/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb @@ -204,9 +204,11 @@ module ActiveRecord # Executes the SQL statement in the context of this connection. def execute(sql, name = nil) - # make sure we carry over any changes to ActiveRecord::Base.default_timezone that have been - # made since we established the connection - @connection.query_options[:database_timezone] = ActiveRecord::Base.default_timezone + if @connection + # make sure we carry over any changes to ActiveRecord::Base.default_timezone that have been + # made since we established the connection + @connection.query_options[:database_timezone] = ActiveRecord::Base.default_timezone + end super end diff --git a/activerecord/test/cases/disconnected_test.rb b/activerecord/test/cases/disconnected_test.rb new file mode 100644 index 0000000000..cc2c1f6489 --- /dev/null +++ b/activerecord/test/cases/disconnected_test.rb @@ -0,0 +1,26 @@ +require "cases/helper" + +class TestRecord < ActiveRecord::Base +end + +class TestDisconnectedAdapter < ActiveRecord::TestCase + self.use_transactional_fixtures = false + + def setup + @connection = ActiveRecord::Base.connection + end + + def teardown + spec = ActiveRecord::Base.connection_config + ActiveRecord::Base.establish_connection(spec) + @connection = nil + end + + test "can't execute statements while disconnected" do + @connection.execute "SELECT count(*) from products" + @connection.disconnect! + assert_raises(ActiveRecord::StatementInvalid) do + @connection.execute "SELECT count(*) from products" + end + end +end diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md index 7f2acb2f65..d612c644af 100644 --- a/activesupport/CHANGELOG.md +++ b/activesupport/CHANGELOG.md @@ -1,5 +1,9 @@ ## unreleased ## +* Override `Time.at` to support the passing of Time-like values when called with a single argument. + + *Andrew White* + * Revert the changes on unicode character encoding from `ActiveSupport::JSON.encode`. This was causing a regression where the resulting string is always returning UTF-8. Also it changes the behavior of this method on a stable release. diff --git a/activesupport/lib/active_support/core_ext/time/calculations.rb b/activesupport/lib/active_support/core_ext/time/calculations.rb index 9146d82bd8..7524063efb 100644 --- a/activesupport/lib/active_support/core_ext/time/calculations.rb +++ b/activesupport/lib/active_support/core_ext/time/calculations.rb @@ -45,6 +45,18 @@ class Time def current ::Time.zone ? ::Time.zone.now : ::Time.now end + + # Layers additional behavior on Time.at so that ActiveSupport::TimeWithZone and DateTime + # instances can be used when called with a single argument + def at_with_coercion(*args) + if args.size == 1 && args.first.acts_like?(:time) + at_without_coercion(args.first.to_i) + else + at_without_coercion(*args) + end + end + alias_method :at_without_coercion, :at + alias_method :at, :at_with_coercion end # Tells whether the Time object's time lies in the past diff --git a/activesupport/test/core_ext/time_ext_test.rb b/activesupport/test/core_ext/time_ext_test.rb index 0d680832ef..a22e161279 100644 --- a/activesupport/test/core_ext/time_ext_test.rb +++ b/activesupport/test/core_ext/time_ext_test.rb @@ -774,6 +774,28 @@ class TimeExtCalculationsTest < ActiveSupport::TestCase assert_equal(-1, Time.utc(2000) <=> ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1, 0, 0, 1), ActiveSupport::TimeZone['UTC'] )) end + def test_at_with_datetime + assert_equal Time.utc(2000, 1, 1, 0, 0, 0), Time.at(DateTime.civil(2000, 1, 1, 0, 0, 0)) + + # Only test this if the underlying Time.at raises a TypeError + begin + Time.at_without_coercion(Time.now, 0) + rescue TypeError + assert_raise(TypeError) { assert_equal(Time.utc(2000, 1, 1, 0, 0, 0), Time.at(DateTime.civil(2000, 1, 1, 0, 0, 0), 0)) } + end + end + + def test_at_with_time_with_zone + assert_equal Time.utc(2000, 1, 1, 0, 0, 0), Time.at(ActiveSupport::TimeWithZone.new(Time.utc(2000, 1, 1, 0, 0, 0), ActiveSupport::TimeZone['UTC'])) + + # Only test this if the underlying Time.at raises a TypeError + begin + Time.at_without_coercion(Time.now, 0) + rescue TypeError + assert_raise(TypeError) { assert_equal(Time.utc(2000, 1, 1, 0, 0, 0), Time.at(ActiveSupport::TimeWithZone.new(Time.utc(2000, 1, 1, 0, 0, 0), ActiveSupport::TimeZone['UTC']), 0)) } + end + end + def test_eql? assert_equal true, Time.utc(2000).eql?( ActiveSupport::TimeWithZone.new(Time.utc(2000), ActiveSupport::TimeZone['UTC']) ) assert_equal true, Time.utc(2000).eql?( ActiveSupport::TimeWithZone.new(Time.utc(2000), ActiveSupport::TimeZone["Hawaii"]) ) |