From b36f123d09e947fa2e1d35ffb0e973b028673d92 Mon Sep 17 00:00:00 2001 From: Claudius Nicolae Date: Wed, 24 Sep 2014 01:15:27 +0300 Subject: Explicit route test class shows the class that the test must extend in order to have the assert_routing method available --- guides/source/testing.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/guides/source/testing.md b/guides/source/testing.md index 29724ae011..f6baccb105 100644 --- a/guides/source/testing.md +++ b/guides/source/testing.md @@ -904,8 +904,10 @@ Testing Routes Like everything else in your Rails application, it is recommended that you test your routes. An example test for a route in the default `show` action of `Articles` controller above should look like: ```ruby -test "should route to article" do - assert_routing '/articles/1', {controller: "articles", action: "show", id: "1"} +class ArticleRoutesTest < ActionController::TestCase + test "should route to article" do + assert_routing '/articles/1', { controller: "articles", action: "show", id: "1" } + end end ``` -- cgit v1.2.3 From d1123f2056eff3696ae76e5116a6ab53e6c33f57 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Fri, 10 Oct 2014 16:00:03 -0700 Subject: FileHandler should not be called for files outside the root FileHandler#matches? should return false for files that are outside the "root" path. --- .../lib/action_dispatch/middleware/static.rb | 14 ++++++++++++-- actionpack/test/dispatch/static_test.rb | 22 ++++++++++++++++++++-- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/actionpack/lib/action_dispatch/middleware/static.rb b/actionpack/lib/action_dispatch/middleware/static.rb index e66c21ef85..002bf8b11a 100644 --- a/actionpack/lib/action_dispatch/middleware/static.rb +++ b/actionpack/lib/action_dispatch/middleware/static.rb @@ -24,9 +24,19 @@ module ActionDispatch path = URI.parser.unescape(path) return false unless path.valid_encoding? - paths = [path, "#{path}#{ext}", "#{path}/index#{ext}"] + paths = [path, "#{path}#{ext}", "#{path}/index#{ext}"].map { |v| + Rack::Utils.clean_path_info v + } - if match = paths.detect {|p| File.file?(File.join(@root, p)) } + if match = paths.detect { |p| + path = File.join(@root, p) + begin + File.file?(path) && File.readable?(path) + rescue SystemCallError + false + end + + } return ::Rack::Utils.escape(match) end end diff --git a/actionpack/test/dispatch/static_test.rb b/actionpack/test/dispatch/static_test.rb index 6f7373201c..7f1207eaed 100644 --- a/actionpack/test/dispatch/static_test.rb +++ b/actionpack/test/dispatch/static_test.rb @@ -200,7 +200,8 @@ class StaticTest < ActiveSupport::TestCase } def setup - @app = ActionDispatch::Static.new(DummyApp, "#{FIXTURE_LOAD_PATH}/public", "public, max-age=60") + @root = "#{FIXTURE_LOAD_PATH}/public" + @app = ActionDispatch::Static.new(DummyApp, @root, "public, max-age=60") end def public_path @@ -208,11 +209,28 @@ class StaticTest < ActiveSupport::TestCase end include StaticTests + + def test_custom_handler_called_when_file_is_outside_root + filename = 'shared.html.erb' + assert File.exist?(File.join(@root, '..', filename)) + env = { + "REQUEST_METHOD"=>"GET", + "REQUEST_PATH"=>"/..%2F#{filename}", + "PATH_INFO"=>"/..%2F#{filename}", + "REQUEST_URI"=>"/..%2F#{filename}", + "HTTP_VERSION"=>"HTTP/1.1", + "SERVER_NAME"=>"localhost", + "SERVER_PORT"=>"8080", + "QUERY_STRING"=>"" + } + assert_equal(DummyApp.call(nil), @app.call(env)) + end end class StaticEncodingTest < StaticTest def setup - @app = ActionDispatch::Static.new(DummyApp, "#{FIXTURE_LOAD_PATH}/公共", "public, max-age=60") + @root = "#{FIXTURE_LOAD_PATH}/公共" + @app = ActionDispatch::Static.new(DummyApp, @root, "public, max-age=60") end def public_path -- cgit v1.2.3 From d611036c7709d7c30cbab3110e20e248283af364 Mon Sep 17 00:00:00 2001 From: Frank Groeneveld Date: Fri, 17 Oct 2014 08:21:56 +0200 Subject: Use include_blank value as option label Update select_tag to reflect documentation and behave the same as form builder select. If the value of include_blank is not boolean true, use that value as the option label. --- actionview/lib/action_view/helpers/form_tag_helper.rb | 10 ++++++++-- actionview/test/template/form_tag_helper_test.rb | 6 ++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/actionview/lib/action_view/helpers/form_tag_helper.rb b/actionview/lib/action_view/helpers/form_tag_helper.rb index 7d1cdc5a68..cf1e20cf55 100644 --- a/actionview/lib/action_view/helpers/form_tag_helper.rb +++ b/actionview/lib/action_view/helpers/form_tag_helper.rb @@ -133,8 +133,14 @@ module ActionView option_tags ||= "" html_name = (options[:multiple] == true && !name.to_s.ends_with?("[]")) ? "#{name}[]" : name - if options.delete(:include_blank) - option_tags = content_tag(:option, '', :value => '').safe_concat(option_tags) + + if options.include?(:include_blank) + include_blank = options.delete(:include_blank) + if include_blank == true + include_blank = '' + end + + option_tags = content_tag(:option, include_blank, :value => '').safe_concat(option_tags) end if prompt = options.delete(:prompt) diff --git a/actionview/test/template/form_tag_helper_test.rb b/actionview/test/template/form_tag_helper_test.rb index 771e3fefc3..5b9c1948db 100644 --- a/actionview/test/template/form_tag_helper_test.rb +++ b/actionview/test/template/form_tag_helper_test.rb @@ -224,6 +224,12 @@ class FormTagHelperTest < ActionView::TestCase expected = %() assert_dom_equal expected, actual end + + def test_select_tag_with_include_blank_string + actual = select_tag "places", "".html_safe, :include_blank => 'Choose' + expected = %() + assert_dom_equal expected, actual + end def test_select_tag_with_prompt actual = select_tag "places", "".html_safe, :prompt => "string" -- cgit v1.2.3 From 032605f08bdb8a911554276122b9feddff3eb1da Mon Sep 17 00:00:00 2001 From: Dan Olson Date: Sun, 19 Oct 2014 19:44:27 -0500 Subject: Fix Relation.rewhere to work with Range values --- activerecord/CHANGELOG.md | 4 ++++ activerecord/lib/active_record/relation/query_methods.rb | 2 +- activerecord/test/cases/relation/where_chain_test.rb | 7 +++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index e0e107e89d..fa9e023d52 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -1,3 +1,7 @@ +* Fix `Relation.rewhere` to work with Range values. + + *Dan Olson* + * `AR::UnknownAttributeError` now includes the class name of a record. User.new(name: "Yuki Nishijima", project_attributes: {name: "kaminari"}) diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb index bbddd28ccc..a53e8c9d0a 100644 --- a/activerecord/lib/active_record/relation/query_methods.rb +++ b/activerecord/lib/active_record/relation/query_methods.rb @@ -913,7 +913,7 @@ module ActiveRecord where_values.reject! do |rel| case rel - when Arel::Nodes::In, Arel::Nodes::NotIn, Arel::Nodes::Equality, Arel::Nodes::NotEqual + when Arel::Nodes::Between, Arel::Nodes::In, Arel::Nodes::NotIn, Arel::Nodes::Equality, Arel::Nodes::NotEqual subrelation = (rel.left.kind_of?(Arel::Attributes::Attribute) ? rel.left : rel.right) subrelation.name == target_value end diff --git a/activerecord/test/cases/relation/where_chain_test.rb b/activerecord/test/cases/relation/where_chain_test.rb index b9e69bdb08..478ac1bc42 100644 --- a/activerecord/test/cases/relation/where_chain_test.rb +++ b/activerecord/test/cases/relation/where_chain_test.rb @@ -149,5 +149,12 @@ module ActiveRecord assert_bound_ast value, Post.arel_table['title'], Arel::Nodes::Equality assert_equal 'alone', bind.last end + + def test_rewhere_with_range + relation = Post.where(comments_count: 1..3).rewhere(comments_count: 3..5) + + assert_equal 1, relation.where_values.size + assert_equal Post.where(comments_count: 3..5), relation + end end end -- cgit v1.2.3 From 5024f6180afb19085d77e0378e1375a42a91d2b5 Mon Sep 17 00:00:00 2001 From: Keith Gable Date: Fri, 17 Oct 2014 16:12:44 -0700 Subject: If Rails is not defined, check ENV["RAILS_ENV"] and ENV["RACK_ENV"]. This fixes a regression introduced by 6cc03675d30b58e28f585720dad14e947a57ff5b. ActiveRecord, if used without Rails, always checks the "default_env" environment. This would be OK, except that Sinatra also supports environments, and it runs with {RACK|RAILS}_ENV=production. This patch adds a fallback to RAILS_ENV and RACK_ENV (and ultimately default_env) if Rails.env doesn't exist. --- .../lib/active_record/connection_handling.rb | 2 +- .../merge_and_resolve_default_url_config_test.rb | 89 ++++++++++++++++++++++ 2 files changed, 90 insertions(+), 1 deletion(-) diff --git a/activerecord/lib/active_record/connection_handling.rb b/activerecord/lib/active_record/connection_handling.rb index 31e7390bf7..8f51590c99 100644 --- a/activerecord/lib/active_record/connection_handling.rb +++ b/activerecord/lib/active_record/connection_handling.rb @@ -1,6 +1,6 @@ module ActiveRecord module ConnectionHandling - RAILS_ENV = -> { Rails.env if defined?(Rails) } + RAILS_ENV = -> { (Rails.env if defined?(Rails)) || ENV["RAILS_ENV"] || ENV["RACK_ENV"] } DEFAULT_ENV = -> { RAILS_ENV.call || "default_env" } # Establishes the connection to the database. Accepts a hash as input where diff --git a/activerecord/test/cases/connection_adapters/merge_and_resolve_default_url_config_test.rb b/activerecord/test/cases/connection_adapters/merge_and_resolve_default_url_config_test.rb index e1b2804a18..37ad469476 100644 --- a/activerecord/test/cases/connection_adapters/merge_and_resolve_default_url_config_test.rb +++ b/activerecord/test/cases/connection_adapters/merge_and_resolve_default_url_config_test.rb @@ -5,10 +5,14 @@ module ActiveRecord class MergeAndResolveDefaultUrlConfigTest < ActiveRecord::TestCase def setup @previous_database_url = ENV.delete("DATABASE_URL") + @previous_rack_env = ENV.delete("RACK_ENV") + @previous_rails_env = ENV.delete("RAILS_ENV") end teardown do ENV["DATABASE_URL"] = @previous_database_url + ENV["RACK_ENV"] = @previous_rack_env + ENV["RAILS_ENV"] = @previous_rails_env end def resolve_config(config) @@ -27,6 +31,26 @@ module ActiveRecord assert_equal expected, actual end + def test_resolver_with_database_uri_and_current_env_symbol_key_and_rails_env + ENV['DATABASE_URL'] = "postgres://localhost/foo" + ENV['RAILS_ENV'] = "foo" + + config = { "not_production" => { "adapter" => "not_postgres", "database" => "not_foo" } } + actual = resolve_spec(:foo, config) + expected = { "adapter" => "postgresql", "database" => "foo", "host" => "localhost" } + assert_equal expected, actual + end + + def test_resolver_with_database_uri_and_current_env_symbol_key_and_rack_env + ENV['DATABASE_URL'] = "postgres://localhost/foo" + ENV['RACK_ENV'] = "foo" + + config = { "not_production" => { "adapter" => "not_postgres", "database" => "not_foo" } } + actual = resolve_spec(:foo, config) + expected = { "adapter" => "postgresql", "database" => "foo", "host" => "localhost" } + assert_equal expected, actual + end + def test_resolver_with_database_uri_and_and_current_env_string_key ENV['DATABASE_URL'] = "postgres://localhost/foo" config = { "default_env" => { "adapter" => "not_postgres", "database" => "not_foo" } } @@ -35,6 +59,26 @@ module ActiveRecord assert_equal expected, actual end + def test_resolver_with_database_uri_and_and_current_env_string_key_and_rails_env + ENV['DATABASE_URL'] = "postgres://localhost/foo" + ENV['RAILS_ENV'] = "foo" + + config = { "not_production" => {"adapter" => "not_postgres", "database" => "not_foo" } } + actual = assert_deprecated { resolve_spec("foo", config) } + expected = { "adapter" => "postgresql", "database" => "foo", "host" => "localhost" } + assert_equal expected, actual + end + + def test_resolver_with_database_uri_and_and_current_env_string_key_and_rack_env + ENV['DATABASE_URL'] = "postgres://localhost/foo" + ENV['RACK_ENV'] = "foo" + + config = { "not_production" => {"adapter" => "not_postgres", "database" => "not_foo" } } + actual = assert_deprecated { resolve_spec("foo", config) } + expected = { "adapter" => "postgresql", "database" => "foo", "host" => "localhost" } + assert_equal expected, actual + end + def test_resolver_with_database_uri_and_known_key ENV['DATABASE_URL'] = "postgres://localhost/foo" config = { "production" => { "adapter" => "not_postgres", "database" => "not_foo", "host" => "localhost" } } @@ -139,6 +183,51 @@ module ActiveRecord assert_equal nil, actual["production"] assert_equal nil, actual["development"] assert_equal nil, actual["test"] + assert_equal nil, actual[:default_env] + assert_equal nil, actual[:production] + assert_equal nil, actual[:development] + assert_equal nil, actual[:test] + end + + def test_blank_with_database_url_with_rails_env + ENV['RAILS_ENV'] = "not_production" + ENV['DATABASE_URL'] = "postgres://localhost/foo" + + config = {} + actual = resolve_config(config) + expected = { "adapter" => "postgresql", + "database" => "foo", + "host" => "localhost" } + + assert_equal expected, actual["not_production"] + assert_equal nil, actual["production"] + assert_equal nil, actual["default_env"] + assert_equal nil, actual["development"] + assert_equal nil, actual["test"] + assert_equal nil, actual[:default_env] + assert_equal nil, actual[:not_production] + assert_equal nil, actual[:production] + assert_equal nil, actual[:development] + assert_equal nil, actual[:test] + end + + def test_blank_with_database_url_with_rack_env + ENV['RACK_ENV'] = "not_production" + ENV['DATABASE_URL'] = "postgres://localhost/foo" + + config = {} + actual = resolve_config(config) + expected = { "adapter" => "postgresql", + "database" => "foo", + "host" => "localhost" } + + assert_equal expected, actual["not_production"] + assert_equal nil, actual["production"] + assert_equal nil, actual["default_env"] + assert_equal nil, actual["development"] + assert_equal nil, actual["test"] + assert_equal nil, actual[:default_env] + assert_equal nil, actual[:not_production] assert_equal nil, actual[:production] assert_equal nil, actual[:development] assert_equal nil, actual[:test] -- cgit v1.2.3 From dbcbbcf2bc58e8971672b143d1c52c0244e33f26 Mon Sep 17 00:00:00 2001 From: Byron Bischoff Date: Thu, 23 Oct 2014 09:53:43 -0700 Subject: =?UTF-8?q?Show=20the=20user=E2=80=99s=20application=20in=20the=20?= =?UTF-8?q?source=20window=20and=20select=20the=20correct=20trace=20list,?= =?UTF-8?q?=20closes=20#17312?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../action_dispatch/middleware/debug_exceptions.rb | 56 +++++++++++++--------- .../middleware/templates/rescues/_source.erb | 2 +- .../middleware/templates/rescues/_trace.html.erb | 2 +- actionpack/test/dispatch/debug_exceptions_test.rb | 42 +++++++++++++++- 4 files changed, 76 insertions(+), 26 deletions(-) diff --git a/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb b/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb index 274f6f2f22..ff72592b94 100644 --- a/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb +++ b/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb @@ -35,10 +35,23 @@ module ActionDispatch if env['action_dispatch.show_detailed_exceptions'] request = Request.new(env) + traces = traces_from_wrapper(wrapper) + + trace_to_show = 'Application Trace' + if traces[trace_to_show].empty? + trace_to_show = 'Full Trace' + end + + if source_to_show = traces[trace_to_show].first + source_to_show_id = source_to_show[:id] + end + template = ActionView::Base.new([RESCUES_TEMPLATE_PATH], request: request, exception: wrapper.exception, - traces: traces_from_wrapper(wrapper), + traces: traces, + show_source_idx: source_to_show_id, + trace_to_show: trace_to_show, routes_inspector: routes_inspector(exception), source_extract: wrapper.source_extract, line_number: wrapper.line_number, @@ -97,31 +110,28 @@ module ActionDispatch # Augment the exception traces by providing ids for all unique stack frame def traces_from_wrapper(wrapper) application_trace = wrapper.application_trace - framework_trace = wrapper.framework_trace - full_trace = wrapper.full_trace - - if application_trace && framework_trace - id_counter = 0 - - application_trace = application_trace.map do |trace| - prev = id_counter - id_counter += 1 - { id: prev, trace: trace } - end - - framework_trace = framework_trace.map do |trace| - prev = id_counter - id_counter += 1 - { id: prev, trace: trace } + framework_trace = wrapper.framework_trace + full_trace = wrapper.full_trace + + appplication_trace_with_ids = [] + framework_trace_with_ids = [] + full_trace_with_ids = [] + + if full_trace + full_trace.each_with_index do |trace, idx| + id_trace = { + id: idx, + trace: trace + } + appplication_trace_with_ids << id_trace if application_trace.include? trace + framework_trace_with_ids << id_trace if framework_trace.include? trace + full_trace_with_ids << id_trace end - - full_trace = application_trace + framework_trace end - { - "Application Trace" => application_trace, - "Framework Trace" => framework_trace, - "Full Trace" => full_trace + "Application Trace" => appplication_trace_with_ids, + "Framework Trace" => framework_trace_with_ids, + "Full Trace" => full_trace_with_ids } end end diff --git a/actionpack/lib/action_dispatch/middleware/templates/rescues/_source.erb b/actionpack/lib/action_dispatch/middleware/templates/rescues/_source.erb index ba29e26930..eabac3a9d2 100644 --- a/actionpack/lib/action_dispatch/middleware/templates/rescues/_source.erb +++ b/actionpack/lib/action_dispatch/middleware/templates/rescues/_source.erb @@ -1,7 +1,7 @@ <% if @source_extract %> <% @source_extract.each_with_index do |extract_source, index| %> <% if extract_source[:code] %> -
" id="frame-source-<%=index%>"> +
" id="frame-source-<%=index%>">
Extracted source (around line #<%= extract_source[:line_number] %>):
diff --git a/actionpack/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb b/actionpack/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb index f62caf51d7..ab57b11c7d 100644 --- a/actionpack/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb +++ b/actionpack/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb @@ -12,7 +12,7 @@ <% end %> <% @traces.each do |name, trace| %> -
;"> +
<% trace.each do |frame| %><%= frame[:trace] %>
<% end %>
<% end %> diff --git a/actionpack/test/dispatch/debug_exceptions_test.rb b/actionpack/test/dispatch/debug_exceptions_test.rb index 0add9fa3b0..f8851f0152 100644 --- a/actionpack/test/dispatch/debug_exceptions_test.rb +++ b/actionpack/test/dispatch/debug_exceptions_test.rb @@ -19,6 +19,10 @@ class DebugExceptionsTest < ActionDispatch::IntegrationTest @closed = true end + def method_that_raises + raise StandardError.new 'error in framework' + end + def call(env) env['action_dispatch.show_detailed_exceptions'] = @detailed req = ActionDispatch::Request.new(env) @@ -57,7 +61,8 @@ class DebugExceptionsTest < ActionDispatch::IntegrationTest {}) raise ActionView::Template::Error.new(template, e) end - + when "/framework_raises" + method_that_raises else raise "puke!" end @@ -280,4 +285,39 @@ class DebugExceptionsTest < ActionDispatch::IntegrationTest assert_select 'pre code', /\(eval\):1: syntax error, unexpected/ end end + + test 'debug exceptions app shows user code that caused the error in source view' do + @app = DevelopmentApp + Rails.stubs(:root).returns(Pathname.new('.')) + cleaner = ActiveSupport::BacktraceCleaner.new.tap do |bc| + bc.add_silencer { |line| line =~ /method_that_raises/ } + bc.add_silencer { |line| line !~ %r{test/dispatch/debug_exceptions_test.rb} } + end + + get '/framework_raises', {}, {'action_dispatch.backtrace_cleaner' => cleaner} + + # Assert correct error + assert_response 500 + assert_select 'h2', /error in framework/ + + # assert source view line is the call to method_that_raises + assert_select 'div.source:not(.hidden)' do + assert_select 'pre .line.active', /method_that_raises/ + end + + # assert first source view (hidden) that throws the error + assert_select 'div.source:first' do + assert_select 'pre .line.active', /raise StandardError\.new/ + end + + # assert application trace refers to line that calls method_that_raises is first + assert_select '#Application-Trace' do + assert_select 'pre code a:first', %r{test/dispatch/debug_exceptions_test\.rb:\d+:in `call} + end + + # assert framework trace that that threw the error is first + assert_select '#Framework-Trace' do + assert_select 'pre code a:first', /method_that_raises/ + end + end end -- cgit v1.2.3 From b570b6b1768f4e89b4f21526763cae77c2ff03fe Mon Sep 17 00:00:00 2001 From: Mauro George Date: Thu, 23 Oct 2014 19:48:12 -0200 Subject: Raises ArgumentError when try to define a scope without a callable This changes the actual exception `NoMethodError: undefined method `call' for #` to a `ArgumentError` when try to define a scope without a callable. --- activerecord/lib/active_record/scoping/named.rb | 3 +++ activerecord/test/cases/scoping/named_scoping_test.rb | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/activerecord/lib/active_record/scoping/named.rb b/activerecord/lib/active_record/scoping/named.rb index 49cadb66d0..04aeeeb4fa 100644 --- a/activerecord/lib/active_record/scoping/named.rb +++ b/activerecord/lib/active_record/scoping/named.rb @@ -139,6 +139,9 @@ module ActiveRecord # Article.published.featured.latest_article # Article.featured.titles def scope(name, body, &block) + raise ArgumentError, 'You need to suply a callable as scope body' unless + body.respond_to?(:call) + if dangerous_class_method?(name) raise ArgumentError, "You tried to define a scope named \"#{name}\" " \ "on the model \"#{self.name}\", but Active Record already defined " \ diff --git a/activerecord/test/cases/scoping/named_scoping_test.rb b/activerecord/test/cases/scoping/named_scoping_test.rb index d3546bd471..d8906b2299 100644 --- a/activerecord/test/cases/scoping/named_scoping_test.rb +++ b/activerecord/test/cases/scoping/named_scoping_test.rb @@ -132,6 +132,12 @@ class NamedScopingTest < ActiveRecord::TestCase assert_equal Post.ranked_by_comments.limit_by(5), Post.top(5) end + def test_scopes_body_is_a_callable + assert_raises(ArgumentError, 'You need to suply a callable as scope body') do + Post.class_eval { scope :containing_the_letter_z, where("body LIKE '%z%'") } + end + end + def test_active_records_have_scope_named__all__ assert !Topic.all.empty? -- cgit v1.2.3 From 9cdd0a1fdf8308985231242d378e3a1c29c4ab00 Mon Sep 17 00:00:00 2001 From: Derek Prior Date: Fri, 21 Feb 2014 11:33:36 -0500 Subject: Use type column first in multi-column indexes `add_reference` can very helpfully add a multi-column index when you use it to add a polymorphic reference. However, the first column in the index is the `id` column, which is less than ideal. The [PostgreSQL docs][1] say: > A multicolumn B-tree index can be used with query conditions that > involve any subset of the index's columns, but the index is most > efficient when there are constraints on the leading (leftmost) > columns. The [MySQL docs][2] say: > MySQL can use multiple-column indexes for queries that test all the > columns in the index, or queries that test just the first column, the > first two columns, the first three columns, and so on. If you specify > the columns in the right order in the index definition, a single > composite index can speed up several kinds of queries on the same > table. In a polymorphic relationship, the type column is much more likely to be useful as the first column in an index than the id column. That is, I'm more likely to query on type without an id than I am to query on id without a type. [1]: http://www.postgresql.org/docs/9.3/static/indexes-multicolumn.html [2]: http://dev.mysql.com/doc/refman/5.0/en/multiple-column-indexes.html --- activerecord/CHANGELOG.md | 4 ++++ .../active_record/connection_adapters/abstract/schema_definitions.rb | 2 +- .../active_record/connection_adapters/abstract/schema_statements.rb | 2 +- activerecord/test/cases/migration/references_index_test.rb | 4 ++-- activerecord/test/cases/migration/references_statements_test.rb | 2 +- 5 files changed, 9 insertions(+), 5 deletions(-) diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index e0e107e89d..205a43f5fb 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -1,3 +1,7 @@ +* Use type column first in multi-column indexes created with `add-reference` + + *Derek Prior* + * `AR::UnknownAttributeError` now includes the class name of a record. User.new(name: "Yuki Nishijima", project_attributes: {name: "kaminari"}) diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb index adb9fcaeb8..7534fde03e 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb @@ -312,7 +312,7 @@ module ActiveRecord args.each do |col| column("#{col}_id", type, options) column("#{col}_type", :string, polymorphic.is_a?(Hash) ? polymorphic : options) if polymorphic - index(polymorphic ? %w(id type).map { |t| "#{col}_#{t}" } : "#{col}_id", index_options.is_a?(Hash) ? index_options : {}) if index_options + index(polymorphic ? %w(type id).map { |t| "#{col}_#{t}" } : "#{col}_id", index_options.is_a?(Hash) ? index_options : {}) if index_options end end alias :belongs_to :references diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb index 7105df1ee4..cbf87df356 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb @@ -629,7 +629,7 @@ module ActiveRecord type = options.delete(:type) || :integer add_column(table_name, "#{ref_name}_id", type, options) add_column(table_name, "#{ref_name}_type", :string, polymorphic.is_a?(Hash) ? polymorphic : options) if polymorphic - add_index(table_name, polymorphic ? %w[id type].map{ |t| "#{ref_name}_#{t}" } : "#{ref_name}_id", index_options.is_a?(Hash) ? index_options : {}) if index_options + add_index(table_name, polymorphic ? %w[type id].map{ |t| "#{ref_name}_#{t}" } : "#{ref_name}_id", index_options.is_a?(Hash) ? index_options : {}) if index_options end alias :add_belongs_to :add_reference diff --git a/activerecord/test/cases/migration/references_index_test.rb b/activerecord/test/cases/migration/references_index_test.rb index 4485701a4e..ad6b828d0b 100644 --- a/activerecord/test/cases/migration/references_index_test.rb +++ b/activerecord/test/cases/migration/references_index_test.rb @@ -55,7 +55,7 @@ module ActiveRecord t.references :foo, :polymorphic => true, :index => true end - assert connection.index_exists?(table_name, [:foo_id, :foo_type], :name => :index_testings_on_foo_id_and_foo_type) + assert connection.index_exists?(table_name, [:foo_type, :foo_id], name: :index_testings_on_foo_type_and_foo_id) end end @@ -93,7 +93,7 @@ module ActiveRecord t.references :foo, :polymorphic => true, :index => true end - assert connection.index_exists?(table_name, [:foo_id, :foo_type], :name => :index_testings_on_foo_id_and_foo_type) + assert connection.index_exists?(table_name, [:foo_type, :foo_id], name: :index_testings_on_foo_type_and_foo_id) end end end diff --git a/activerecord/test/cases/migration/references_statements_test.rb b/activerecord/test/cases/migration/references_statements_test.rb index b8b4fa1135..988bd9c89f 100644 --- a/activerecord/test/cases/migration/references_statements_test.rb +++ b/activerecord/test/cases/migration/references_statements_test.rb @@ -42,7 +42,7 @@ module ActiveRecord def test_creates_polymorphic_index add_reference table_name, :taggable, polymorphic: true, index: true - assert index_exists?(table_name, [:taggable_id, :taggable_type]) + assert index_exists?(table_name, [:taggable_type, :taggable_id]) end def test_creates_reference_type_column_with_default -- cgit v1.2.3 From 53df0c4ebba7f7021e193890ebcc2bddd4d5179b Mon Sep 17 00:00:00 2001 From: Prathamesh Sonpatki Date: Sat, 25 Oct 2014 23:10:25 +0530 Subject: Fix description of OID in TypeMapInitializer [ci skip] --- .../connection_adapters/postgresql/oid/type_map_initializer.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/oid/type_map_initializer.rb b/activerecord/lib/active_record/connection_adapters/postgresql/oid/type_map_initializer.rb index e396ff4a1e..35e699eeda 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/oid/type_map_initializer.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/oid/type_map_initializer.rb @@ -4,7 +4,7 @@ module ActiveRecord module OID # :nodoc: # This class uses the data from PostgreSQL pg_type table to build # the OID -> Type mapping. - # - OID is and integer representing the type. + # - OID is an integer representing the type. # - Type is an OID::Type object. # This class has side effects on the +store+ passed during initialization. class TypeMapInitializer # :nodoc: -- cgit v1.2.3 From 95acea5498f1e9ac43cf87b55578e0a8d576680b Mon Sep 17 00:00:00 2001 From: Prathamesh Sonpatki Date: Sat, 25 Oct 2014 23:19:27 +0530 Subject: Clarify comments about sanitized_allowed_tags - Clarify that arguments are expected in array format. - Extension of https://github.com/rails/rails/pull/17390. - https://github.com/rails/rails/pull/17390 was targeted against 4-1-stable branch. This commit updates master. - [ci skip] --- actionview/lib/action_view/helpers/sanitize_helper.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/actionview/lib/action_view/helpers/sanitize_helper.rb b/actionview/lib/action_view/helpers/sanitize_helper.rb index 4f2db0a0c4..7cb55cc214 100644 --- a/actionview/lib/action_view/helpers/sanitize_helper.rb +++ b/actionview/lib/action_view/helpers/sanitize_helper.rb @@ -57,7 +57,7 @@ module ActionView # Add table tags to the default allowed tags # # class Application < Rails::Application - # config.action_view.sanitized_allowed_tags = 'table', 'tr', 'td' + # config.action_view.sanitized_allowed_tags = ['table', 'tr', 'td'] # end # # Remove tags to the default allowed tags @@ -176,7 +176,7 @@ module ActionView # Replaces the allowed tags for the +sanitize+ helper. # # class Application < Rails::Application - # config.action_view.sanitized_allowed_tags = 'table', 'tr', 'td' + # config.action_view.sanitized_allowed_tags = ['table', 'tr', 'td'] # end # -- cgit v1.2.3 From 73ad15103019f94b789a3b0f13209a0a988df584 Mon Sep 17 00:00:00 2001 From: Pavel Pravosud Date: Fri, 24 Oct 2014 13:25:55 -0400 Subject: Make `String#remove` and `String#remove!` accept multiple arguments --- activesupport/CHANGELOG.md | 4 ++++ .../lib/active_support/core_ext/string/filters.rb | 16 ++++++++++------ activesupport/test/core_ext/string_ext_test.rb | 14 ++++++++++++-- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md index f9df972929..0c90549826 100644 --- a/activesupport/CHANGELOG.md +++ b/activesupport/CHANGELOG.md @@ -1,3 +1,7 @@ +* `String#remove` and `String#remove!` accept multiple arguments. + + *Pavel Pravosud* + * Corrected Inflector#underscore handling of multiple successive acroynms. *James Le Cuirot* diff --git a/activesupport/lib/active_support/core_ext/string/filters.rb b/activesupport/lib/active_support/core_ext/string/filters.rb index 2b1583d4ac..499b9b26bc 100644 --- a/activesupport/lib/active_support/core_ext/string/filters.rb +++ b/activesupport/lib/active_support/core_ext/string/filters.rb @@ -20,14 +20,18 @@ class String self end - # Returns a new string with all occurrences of the pattern removed. Short-hand for String#gsub(pattern, ''). - def remove(pattern) - gsub pattern, '' + # Returns a new string with all occurrences of the patterns removed. + def remove(*patterns) + dup.remove!(*patterns) end - # Alters the string by removing all occurrences of the pattern. Short-hand for String#gsub!(pattern, ''). - def remove!(pattern) - gsub! pattern, '' + # Alters the string by removing all occurrences of the patterns. + def remove!(*patterns) + patterns.each do |pattern| + gsub! pattern, "" + end + + self end # Truncates a given +text+ after a given length if +text+ is longer than length: diff --git a/activesupport/test/core_ext/string_ext_test.rb b/activesupport/test/core_ext/string_ext_test.rb index 2f4691817f..35095f2b2d 100644 --- a/activesupport/test/core_ext/string_ext_test.rb +++ b/activesupport/test/core_ext/string_ext_test.rb @@ -260,8 +260,18 @@ class StringInflectionsTest < ActiveSupport::TestCase end def test_remove - assert_equal "Summer", "Fast Summer".remove(/Fast /) - assert_equal "Summer", "Fast Summer".remove!(/Fast /) + original = "This is a good day to die" + assert_equal "This is a good day", original.remove(" to die") + assert_equal "This is a good day", original.remove(" to ", /die/) + assert_equal "This is a good day to die", original + end + + def test_remove! + original = "This is a very good day to die" + assert_equal "This is a good day to die", original.remove!(" very") + assert_equal "This is a good day to die", original + assert_equal "This is a good day", original.remove!(" to ", /die/) + assert_equal "This is a good day", original end def test_constantize -- cgit v1.2.3 From f28340a5ef3dafd3f96e7032b6b21352ebd11f57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Sat, 25 Oct 2014 16:13:58 -0700 Subject: :scissors: --- actionview/lib/action_view/helpers/form_tag_helper.rb | 3 +-- actionview/test/template/form_tag_helper_test.rb | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/actionview/lib/action_view/helpers/form_tag_helper.rb b/actionview/lib/action_view/helpers/form_tag_helper.rb index 74cfec962e..5aeb138f7a 100644 --- a/actionview/lib/action_view/helpers/form_tag_helper.rb +++ b/actionview/lib/action_view/helpers/form_tag_helper.rb @@ -133,13 +133,12 @@ module ActionView option_tags ||= "" html_name = (options[:multiple] == true && !name.to_s.ends_with?("[]")) ? "#{name}[]" : name - if options.include?(:include_blank) include_blank = options.delete(:include_blank) if include_blank == true include_blank = '' end - + option_tags = content_tag(:option, include_blank, :value => '').safe_concat(option_tags) end diff --git a/actionview/test/template/form_tag_helper_test.rb b/actionview/test/template/form_tag_helper_test.rb index 4844398c13..e8170d43e1 100644 --- a/actionview/test/template/form_tag_helper_test.rb +++ b/actionview/test/template/form_tag_helper_test.rb @@ -231,7 +231,7 @@ class FormTagHelperTest < ActionView::TestCase expected = %() assert_dom_equal expected, actual end - + def test_select_tag_with_include_blank_string actual = select_tag "places", "".html_safe, :include_blank => 'Choose' expected = %() -- cgit v1.2.3 From b2278aa1a0c02f8793587f625900504b447b4517 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Sat, 25 Oct 2014 16:14:28 -0700 Subject: Use new hash syntax --- actionview/lib/action_view/helpers/form_tag_helper.rb | 5 +++-- actionview/test/template/form_tag_helper_test.rb | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/actionview/lib/action_view/helpers/form_tag_helper.rb b/actionview/lib/action_view/helpers/form_tag_helper.rb index 5aeb138f7a..c0218fd55d 100644 --- a/actionview/lib/action_view/helpers/form_tag_helper.rb +++ b/actionview/lib/action_view/helpers/form_tag_helper.rb @@ -135,15 +135,16 @@ module ActionView if options.include?(:include_blank) include_blank = options.delete(:include_blank) + if include_blank == true include_blank = '' end - option_tags = content_tag(:option, include_blank, :value => '').safe_concat(option_tags) + option_tags = content_tag(:option, include_blank, value: '').safe_concat(option_tags) end if prompt = options.delete(:prompt) - option_tags = content_tag(:option, prompt, :value => '').safe_concat(option_tags) + option_tags = content_tag(:option, prompt, value: '').safe_concat(option_tags) end content_tag :select, option_tags, { "name" => html_name, "id" => sanitize_to_id(name) }.update(options.stringify_keys) diff --git a/actionview/test/template/form_tag_helper_test.rb b/actionview/test/template/form_tag_helper_test.rb index e8170d43e1..f8fd642809 100644 --- a/actionview/test/template/form_tag_helper_test.rb +++ b/actionview/test/template/form_tag_helper_test.rb @@ -233,7 +233,7 @@ class FormTagHelperTest < ActionView::TestCase end def test_select_tag_with_include_blank_string - actual = select_tag "places", "".html_safe, :include_blank => 'Choose' + actual = select_tag "places", "".html_safe, include_blank: 'Choose' expected = %() assert_dom_equal expected, actual end -- cgit v1.2.3 From 450743cf56125d153b64c3509e75b0e4f86851d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Sat, 25 Oct 2014 16:20:44 -0700 Subject: Add CHANGELOG entry for #17064 --- actionview/CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/actionview/CHANGELOG.md b/actionview/CHANGELOG.md index 8ac74dc938..e388e6ecd3 100644 --- a/actionview/CHANGELOG.md +++ b/actionview/CHANGELOG.md @@ -1,3 +1,9 @@ +* Update `select_tag` to work correctly with `:include_blank` option passing a string. + + Fixes #16483. + + *Frank Groeneveld* + * Changed the meaning of `render "foo/bar"`. Previously, calling `render "foo/bar"` in a controller action is equivalent -- cgit v1.2.3 From 89397d09ebb7ca4089f17820d05d5eb223913652 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Sat, 25 Oct 2014 17:12:19 -0700 Subject: Prefix internal method with _ This will avoid naming clash with user defined methods --- activemodel/lib/active_model/validations.rb | 2 +- activemodel/lib/active_model/validations/callbacks.rb | 2 +- .../active_record/associations/has_many_through_association.rb | 2 +- activerecord/lib/active_record/callbacks.rb | 10 +++++----- .../connection_adapters/abstract/connection_pool.rb | 4 ++-- activerecord/lib/active_record/core.rb | 8 ++++---- activerecord/lib/active_record/transactions.rb | 4 ++-- activesupport/lib/active_support/callbacks.rb | 4 ++-- 8 files changed, 18 insertions(+), 18 deletions(-) diff --git a/activemodel/lib/active_model/validations.rb b/activemodel/lib/active_model/validations.rb index 1116f6b8ee..c1e344b215 100644 --- a/activemodel/lib/active_model/validations.rb +++ b/activemodel/lib/active_model/validations.rb @@ -392,7 +392,7 @@ module ActiveModel protected def run_validations! #:nodoc: - run_validate_callbacks + _run_validate_callbacks errors.empty? end end diff --git a/activemodel/lib/active_model/validations/callbacks.rb b/activemodel/lib/active_model/validations/callbacks.rb index 1a5192b0ff..25ccabd66b 100644 --- a/activemodel/lib/active_model/validations/callbacks.rb +++ b/activemodel/lib/active_model/validations/callbacks.rb @@ -110,7 +110,7 @@ module ActiveModel # Overwrite run validations to include callbacks. def run_validations! #:nodoc: - run_validation_callbacks { super } + _run_validation_callbacks { super } end end end diff --git a/activerecord/lib/active_record/associations/has_many_through_association.rb b/activerecord/lib/active_record/associations/has_many_through_association.rb index 455a540bdb..57affce4f7 100644 --- a/activerecord/lib/active_record/associations/has_many_through_association.rb +++ b/activerecord/lib/active_record/associations/has_many_through_association.rb @@ -159,7 +159,7 @@ module ActiveRecord count = scope.destroy_all.length else scope.to_a.each do |record| - record.run_destroy_callbacks + record._run_destroy_callbacks end arel = scope.arel diff --git a/activerecord/lib/active_record/callbacks.rb b/activerecord/lib/active_record/callbacks.rb index 1aa760157a..523d492a48 100644 --- a/activerecord/lib/active_record/callbacks.rb +++ b/activerecord/lib/active_record/callbacks.rb @@ -289,25 +289,25 @@ module ActiveRecord end def destroy #:nodoc: - run_destroy_callbacks { super } + _run_destroy_callbacks { super } end def touch(*) #:nodoc: - run_touch_callbacks { super } + _run_touch_callbacks { super } end private def create_or_update #:nodoc: - run_save_callbacks { super } + _run_save_callbacks { super } end def _create_record #:nodoc: - run_create_callbacks { super } + _run_create_callbacks { super } end def _update_record(*) #:nodoc: - run_update_callbacks { super } + _run_update_callbacks { super } end end end diff --git a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb index da43e5bb10..eba51baba1 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb @@ -360,7 +360,7 @@ module ActiveRecord synchronize do owner = conn.owner - conn.run_checkin_callbacks do + conn._run_checkin_callbacks do conn.expire end @@ -449,7 +449,7 @@ module ActiveRecord end def checkout_and_verify(c) - c.run_checkout_callbacks do + c._run_checkout_callbacks do c.verify! end c diff --git a/activerecord/lib/active_record/core.rb b/activerecord/lib/active_record/core.rb index 5571a2d297..f9b6375459 100644 --- a/activerecord/lib/active_record/core.rb +++ b/activerecord/lib/active_record/core.rb @@ -272,7 +272,7 @@ module ActiveRecord init_attributes(attributes, options) if attributes yield self if block_given? - run_initialize_callbacks + _run_initialize_callbacks end # Initialize an empty model object from +coder+. +coder+ must contain @@ -294,8 +294,8 @@ module ActiveRecord self.class.define_attribute_methods - run_find_callbacks - run_initialize_callbacks + _run_find_callbacks + _run_initialize_callbacks self end @@ -331,7 +331,7 @@ module ActiveRecord @attributes = @attributes.dup @attributes.reset(self.class.primary_key) - run_initialize_callbacks + _run_initialize_callbacks @aggregation_cache = {} @association_cache = {} diff --git a/activerecord/lib/active_record/transactions.rb b/activerecord/lib/active_record/transactions.rb index bb06d0304b..f92e1de03b 100644 --- a/activerecord/lib/active_record/transactions.rb +++ b/activerecord/lib/active_record/transactions.rb @@ -309,7 +309,7 @@ module ActiveRecord # Ensure that it is not called if the object was never persisted (failed create), # but call it after the commit of a destroyed object. def committed!(should_run_callbacks = true) #:nodoc: - run_commit_callbacks if should_run_callbacks && destroyed? || persisted? + _run_commit_callbacks if should_run_callbacks && destroyed? || persisted? ensure force_clear_transaction_record_state end @@ -317,7 +317,7 @@ module ActiveRecord # Call the +after_rollback+ callbacks. The +force_restore_state+ argument indicates if the record # state should be rolled back to the beginning or just to the last savepoint. def rolledback!(force_restore_state = false, should_run_callbacks = true) #:nodoc: - run_rollback_callbacks if should_run_callbacks + _run_rollback_callbacks if should_run_callbacks ensure restore_transaction_record_state(force_restore_state) clear_transaction_record_state diff --git a/activesupport/lib/active_support/callbacks.rb b/activesupport/lib/active_support/callbacks.rb index 45231bc101..24c702b602 100644 --- a/activesupport/lib/active_support/callbacks.rb +++ b/activesupport/lib/active_support/callbacks.rb @@ -78,7 +78,7 @@ module ActiveSupport # save # end def run_callbacks(kind, &block) - send "run_#{kind}_callbacks", &block + send "_run_#{kind}_callbacks", &block end private @@ -730,7 +730,7 @@ module ActiveSupport set_callbacks name, CallbackChain.new(name, options) module_eval <<-RUBY, __FILE__, __LINE__ + 1 - def run_#{name}_callbacks(&block) + def _run_#{name}_callbacks(&block) _run_callbacks(_#{name}_callbacks, &block) end RUBY -- cgit v1.2.3 From d8ea9938f4231dcfb5ad5f5f8dedd19e9ccd22b7 Mon Sep 17 00:00:00 2001 From: Prathamesh Sonpatki Date: Sun, 26 Oct 2014 12:23:22 +0530 Subject: Fix typo in error message when non-boolean value is assigned to boolean column --- activerecord/lib/active_record/type/boolean.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/activerecord/lib/active_record/type/boolean.rb b/activerecord/lib/active_record/type/boolean.rb index 1311be3944..612478e67d 100644 --- a/activerecord/lib/active_record/type/boolean.rb +++ b/activerecord/lib/active_record/type/boolean.rb @@ -15,7 +15,7 @@ module ActiveRecord else if !ConnectionAdapters::Column::FALSE_VALUES.include?(value) ActiveSupport::Deprecation.warn(<<-EOM) - You attempted to assign a value which is not explicitly true or false to a boolean column. Currently this value casts to false. This will change to match Ruby's sematics, and will cast to true in Rails 5.0. If you would like to maintain the current behavior, you should explicitly handle the values you would like cast to false. + You attempted to assign a value which is not explicitly true or false to a boolean column. Currently this value casts to false. This will change to match Ruby's semantics, and will cast to true in Rails 5.0. If you would like to maintain the current behavior, you should explicitly handle the values you would like cast to false. EOM end false -- cgit v1.2.3 From 747a1c9b281d274f00e2732b84f0f34b8bbce188 Mon Sep 17 00:00:00 2001 From: Rishi Jain Date: Sun, 26 Oct 2014 00:17:51 -0500 Subject: Making the actionmailer docs more explicit to understand [ci skip] --- actionmailer/lib/action_mailer/base.rb | 7 ++++--- actionmailer/lib/action_mailer/delivery_job.rb | 2 ++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index 798241aaf8..a70bf1544a 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -84,7 +84,8 @@ module ActionMailer # name as the method in your mailer model. For example, in the mailer defined above, the template at # app/views/notifier/welcome.text.erb would be used to generate the email. # - # Variables defined in the model are accessible as instance variables in the view. + # Variables defined in the methods of your mailer model are accessible as instance variables in their + # corresponding view. # # Emails by default are sent in plain text, so a sample view for our model example might look like this: # @@ -702,8 +703,8 @@ module ActionMailer # The main method that creates the message and renders the email templates. There are # two ways to call this method, with a block, or without a block. # - # Both methods accept a headers hash. This hash allows you to specify the most used headers - # in an email message, these are: + # It accepts a headers hash. This hash allows you to specify + # the most used headers in an email message, these are: # # * +:subject+ - The subject of the message, if this is omitted, Action Mailer will # ask the Rails I18n class for a translated +:subject+ in the scope of diff --git a/actionmailer/lib/action_mailer/delivery_job.rb b/actionmailer/lib/action_mailer/delivery_job.rb index 622f202695..95231411fb 100644 --- a/actionmailer/lib/action_mailer/delivery_job.rb +++ b/actionmailer/lib/action_mailer/delivery_job.rb @@ -1,6 +1,8 @@ require 'active_job' module ActionMailer + # The ActionMailer::DeliveryJob class is used when you + # want to send emails outside of the request-response cycle. class DeliveryJob < ActiveJob::Base #:nodoc: queue_as :mailers -- cgit v1.2.3 From bf17c8a531bc8059d50ad731398002a3e7162a7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Sun, 26 Oct 2014 20:47:47 -0500 Subject: Add back --skip-turbolinks and remove --skip-gems For the most part of cases --skip-gems option just remove one line in the Gemfile. This is not worth for the complexity it adds. Closes #17196 --- railties/CHANGELOG.md | 8 +------- railties/lib/rails/generators/app_base.rb | 15 +++++++++------ railties/test/generators/app_generator_test.rb | 5 ++--- 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index e1a11482e6..2960eccb3f 100644 --- a/railties/CHANGELOG.md +++ b/railties/CHANGELOG.md @@ -89,13 +89,7 @@ *Rafael Mendonça França* -* Add a generic --skip-gems options to generator - - This option is useful if users want to remove some gems like jbuilder, - turbolinks, coffee-rails, etc that don't have specific options on the - generator. - - rails new my_app --skip-gems turbolinks coffee-rails +* Add a generic --skip-turbolinks options to generator. *Rafael Mendonça França* diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb index 1eca86bd30..92ed9136a0 100644 --- a/railties/lib/rails/generators/app_base.rb +++ b/railties/lib/rails/generators/app_base.rb @@ -41,9 +41,6 @@ module Rails class_option :skip_active_record, type: :boolean, aliases: '-O', default: false, desc: 'Skip Active Record files' - class_option :skip_gems, type: :array, default: [], - desc: 'Skip the provided gems files' - class_option :skip_sprockets, type: :boolean, aliases: '-S', default: false, desc: 'Skip Sprockets files' @@ -65,6 +62,9 @@ module Rails class_option :edge, type: :boolean, default: false, desc: "Setup the #{name} with Gemfile pointing to Rails repository" + class_option :skip_turbolinks, type: :boolean, default: false, + desc: 'Skip turbolinks gem' + class_option :skip_test_unit, type: :boolean, aliases: '-T', default: false, desc: 'Skip Test::Unit files' @@ -79,7 +79,7 @@ module Rails end def initialize(*args) - @gem_filter = lambda { |gem| !options[:skip_gems].include?(gem.name) } + @gem_filter = lambda { |gem| true } @extra_entries = [] super convert_database_option_for_jruby @@ -287,8 +287,11 @@ module Rails "Use #{options[:javascript]} as the JavaScript library") end - gems << GemfileEntry.version("turbolinks", nil, - "Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks") + unless options[:skip_turbolinks] + gems << GemfileEntry.version("turbolinks", nil, + "Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks") + end + gems end end diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index b492258efb..501b2e0811 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -450,12 +450,11 @@ class AppGeneratorTest < Rails::Generators::TestCase end end - def test_generator_if_skip_gems_is_given - run_generator [destination_root, "--skip-gems", "turbolinks", "coffee-rails"] + def test_generator_if_skip_turbolinks_is_given + run_generator [destination_root, "--skip-turbolinks"] assert_file "Gemfile" do |content| assert_no_match(/turbolinks/, content) - assert_no_match(/coffee-rails/, content) end assert_file "app/views/layouts/application.html.erb" do |content| assert_no_match(/data-turbolinks-track/, content) -- cgit v1.2.3 From 11ab04b11170253e96515c3ada6f2566b092533a Mon Sep 17 00:00:00 2001 From: Terry Meacham Date: Tue, 23 Sep 2014 15:51:44 -0500 Subject: Added queue_name_delimiter attribute. - Added ActiveJob::Base#queue_name_delimiter to allow for developers using ActiveJob to change the delimiter from the default ('_') to whatever else they may be using (e.g., '.', '-', ...). - Updated source guide to include a blurb about the delimiter. --- activejob/lib/active_job/queue_name.rb | 5 ++++- activejob/test/cases/queue_naming_test.rb | 19 ++++++++++++++++++- guides/source/active_job_basics.md | 23 +++++++++++++++++++++++ 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/activejob/lib/active_job/queue_name.rb b/activejob/lib/active_job/queue_name.rb index d167617e4e..6ee7142ce6 100644 --- a/activejob/lib/active_job/queue_name.rb +++ b/activejob/lib/active_job/queue_name.rb @@ -26,13 +26,16 @@ module ActiveJob def queue_name_from_part(part_name) #:nodoc: queue_name = part_name || default_queue_name name_parts = [queue_name_prefix.presence, queue_name] - name_parts.compact.join('_') + name_parts.compact.join(queue_name_delimiter) end end included do class_attribute :queue_name, instance_accessor: false + class_attribute :queue_name_delimiter, instance_accessor: false + self.queue_name = default_queue_name + self.queue_name_delimiter = '_' # set default delimiter to '_' end # Returns the name of the queue the job will be run on diff --git a/activejob/test/cases/queue_naming_test.rb b/activejob/test/cases/queue_naming_test.rb index 886f41271a..898016a704 100644 --- a/activejob/test/cases/queue_naming_test.rb +++ b/activejob/test/cases/queue_naming_test.rb @@ -64,7 +64,7 @@ class QueueNamingTest < ActiveSupport::TestCase end end - test 'queu_name_prefix prepended to the queue name' do + test 'queue_name_prefix prepended to the queue name with default delimiter' do original_queue_name_prefix = ActiveJob::Base.queue_name_prefix original_queue_name = HelloJob.queue_name @@ -78,6 +78,23 @@ class QueueNamingTest < ActiveSupport::TestCase end end + test 'queue_name_prefix prepended to the queue name with custom delimiter' do + original_queue_name_prefix = ActiveJob::Base.queue_name_prefix + original_queue_name_delimiter = ActiveJob::Base.queue_name_delimiter + original_queue_name = HelloJob.queue_name + + begin + ActiveJob::Base.queue_name_delimiter = '.' + ActiveJob::Base.queue_name_prefix = 'aj' + HelloJob.queue_as :low + assert_equal 'aj.low', HelloJob.queue_name + ensure + ActiveJob::Base.queue_name_prefix = original_queue_name_prefix + ActiveJob::Base.queue_name_delimiter = original_queue_name_delimiter + HelloJob.queue_name = original_queue_name + end + end + test 'uses queue passed to #set' do job = HelloJob.set(queue: :some_queue).perform_later assert_equal "some_queue", job.queue_name diff --git a/guides/source/active_job_basics.md b/guides/source/active_job_basics.md index 9c34418fab..0f63a1c7e7 100644 --- a/guides/source/active_job_basics.md +++ b/guides/source/active_job_basics.md @@ -149,6 +149,29 @@ end # environment ``` +The default queue name prefix delimiter is '_'. This can be changed by setting +`config.active_job.queue_name_delimiter` in `application.rb`: + +```ruby +# config/application.rb +module YourApp + class Application < Rails::Application + config.active_job.queue_name_prefix = Rails.env + config.active_job.queue_name_delimiter = '.' + end +end + +# app/jobs/guests_cleanup.rb +class GuestsCleanupJob < ActiveJob::Base + queue_as :low_priority + #.... +end + +# Now your job will run on queue production.low_priority on your +# production environment and on staging.low_priority on your staging +# environment +``` + If you want more control on what queue a job will be run you can pass a :queue option to #set: -- cgit v1.2.3 From 68bad9960a07508e24726d598d86fc26a2931264 Mon Sep 17 00:00:00 2001 From: Dan Olson Date: Mon, 27 Oct 2014 09:35:34 -0500 Subject: Allow Relation#rewhere to work with infinite range values --- .../lib/active_record/relation/query_methods.rb | 2 +- .../test/cases/relation/where_chain_test.rb | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb index a53e8c9d0a..e4bebf78e8 100644 --- a/activerecord/lib/active_record/relation/query_methods.rb +++ b/activerecord/lib/active_record/relation/query_methods.rb @@ -913,7 +913,7 @@ module ActiveRecord where_values.reject! do |rel| case rel - when Arel::Nodes::Between, Arel::Nodes::In, Arel::Nodes::NotIn, Arel::Nodes::Equality, Arel::Nodes::NotEqual + when Arel::Nodes::Between, Arel::Nodes::In, Arel::Nodes::NotIn, Arel::Nodes::Equality, Arel::Nodes::NotEqual, Arel::Nodes::LessThanOrEqual, Arel::Nodes::GreaterThanOrEqual subrelation = (rel.left.kind_of?(Arel::Attributes::Attribute) ? rel.left : rel.right) subrelation.name == target_value end diff --git a/activerecord/test/cases/relation/where_chain_test.rb b/activerecord/test/cases/relation/where_chain_test.rb index 478ac1bc42..619055f1e7 100644 --- a/activerecord/test/cases/relation/where_chain_test.rb +++ b/activerecord/test/cases/relation/where_chain_test.rb @@ -156,5 +156,26 @@ module ActiveRecord assert_equal 1, relation.where_values.size assert_equal Post.where(comments_count: 3..5), relation end + + def test_rewhere_with_infinite_upper_bound_range + relation = Post.where(comments_count: 1..Float::INFINITY).rewhere(comments_count: 3..5) + + assert_equal 1, relation.where_values.size + assert_equal Post.where(comments_count: 3..5), relation + end + + def test_rewhere_with_infinite_lower_bound_range + relation = Post.where(comments_count: -Float::INFINITY..1).rewhere(comments_count: 3..5) + + assert_equal 1, relation.where_values.size + assert_equal Post.where(comments_count: 3..5), relation + end + + def test_rewhere_with_infinite_range + relation = Post.where(comments_count: -Float::INFINITY..Float::INFINITY).rewhere(comments_count: 3..5) + + assert_equal 1, relation.where_values.size + assert_equal Post.where(comments_count: 3..5), relation + end end end -- cgit v1.2.3 From 8e1362be3fa8afa352a7acc4a1561205bcdada1e Mon Sep 17 00:00:00 2001 From: Jean Boussier Date: Sat, 19 Jul 2014 10:32:48 -0400 Subject: UrlGenerationError are not catched as 404 anymore --- actionpack/lib/action_controller/metal/exceptions.rb | 2 +- railties/test/application/middleware/exceptions_test.rb | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/actionpack/lib/action_controller/metal/exceptions.rb b/actionpack/lib/action_controller/metal/exceptions.rb index 3844dbf2a6..18e003741d 100644 --- a/actionpack/lib/action_controller/metal/exceptions.rb +++ b/actionpack/lib/action_controller/metal/exceptions.rb @@ -25,7 +25,7 @@ module ActionController end end - class ActionController::UrlGenerationError < RoutingError #:nodoc: + class ActionController::UrlGenerationError < ActionControllerError #:nodoc: end class MethodNotAllowed < ActionControllerError #:nodoc: diff --git a/railties/test/application/middleware/exceptions_test.rb b/railties/test/application/middleware/exceptions_test.rb index 42096cfec4..a7472b37f1 100644 --- a/railties/test/application/middleware/exceptions_test.rb +++ b/railties/test/application/middleware/exceptions_test.rb @@ -60,6 +60,21 @@ module ApplicationTests assert_equal "YOU FAILED BRO", last_response.body end + test "url generation error when action_dispatch.show_exceptions is set raises an exception" do + controller :foo, <<-RUBY + class FooController < ActionController::Base + def index + raise ActionController::UrlGenerationError + end + end + RUBY + + app.config.action_dispatch.show_exceptions = true + + get '/foo' + assert_equal 500, last_response.status + end + test "unspecified route when action_dispatch.show_exceptions is not set raises an exception" do app.config.action_dispatch.show_exceptions = false -- cgit v1.2.3 From a7fd386b63752df861398ec74ae2ad945ec33741 Mon Sep 17 00:00:00 2001 From: Benjamin Fleischer Date: Mon, 27 Oct 2014 16:03:47 -0500 Subject: Fix rbx generated Gemfile regex https://travis-ci.org/rails/rails/jobs/39190983#L460 1) Failure: AppGeneratorTest#test_psych_gem [test/generators/app_generator_test.rb:495]: Expected /gem 'psych',\s+'~> 2.0', \s+platforms: :rbx/ to match http://git.io/uuLVag)\ngem 'psych', '~> 2.0', platforms: :rbx\n\n --- railties/test/generators/app_generator_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 501b2e0811..b7cbe04003 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -490,7 +490,7 @@ class AppGeneratorTest < Rails::Generators::TestCase def test_psych_gem run_generator - gem_regex = /gem 'psych',\s+'~> 2.0', \s+platforms: :rbx/ + gem_regex = /gem 'psych',\s+'~> 2.0',\s+platforms: :rbx/ assert_file "Gemfile" do |content| if defined?(Rubinius) -- cgit v1.2.3 From 1897d3a5d240a962dc89d2cab1d36bedb08974f7 Mon Sep 17 00:00:00 2001 From: Pablo Herrero Date: Sat, 18 Oct 2014 04:47:40 -0300 Subject: Optimize TimeWithZoneTest#strftime --- activesupport/CHANGELOG.md | 5 +++++ activesupport/lib/active_support/time_with_zone.rb | 16 ++++++---------- activesupport/test/core_ext/time_with_zone_test.rb | 5 +++++ 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md index f9df972929..4ad602b066 100644 --- a/activesupport/CHANGELOG.md +++ b/activesupport/CHANGELOG.md @@ -1,3 +1,8 @@ +* TimeWithZone#strftime now delegates every directive to Time#strftime except for '%Z', + it also now correctly handles escaped '%' characters placed just before time zone related directives. + + *Pablo Herrero* + * Corrected Inflector#underscore handling of multiple successive acroynms. *James Le Cuirot* diff --git a/activesupport/lib/active_support/time_with_zone.rb b/activesupport/lib/active_support/time_with_zone.rb index 4a0ed356b1..dbee145196 100644 --- a/activesupport/lib/active_support/time_with_zone.rb +++ b/activesupport/lib/active_support/time_with_zone.rb @@ -75,8 +75,8 @@ module ActiveSupport # Returns a Time.local() instance of the simultaneous time in your # system's ENV['TZ'] zone. - def localtime - utc.respond_to?(:getlocal) ? utc.getlocal : utc.to_time.getlocal + def localtime(utc_offset = nil) + utc.respond_to?(:getlocal) ? utc.getlocal(utc_offset) : utc.to_time.getlocal(utc_offset) end alias_method :getlocal, :localtime @@ -201,15 +201,11 @@ module ActiveSupport end alias_method :to_formatted_s, :to_s - # Replaces %Z and %z directives with +zone+ and - # +formatted_offset+, respectively, before passing to Time#strftime, so - # that zone information is correct + # Replaces %Z directive with +zone before passing to Time#strftime, + # so that zone information is correct. def strftime(format) - format = format.gsub('%Z', zone) - .gsub('%z', formatted_offset(false)) - .gsub('%:z', formatted_offset(true)) - .gsub('%::z', formatted_offset(true) + ":00") - time.strftime(format) + format = format.gsub(/((?:\A|[^%])(?:%%)*)%Z/, "\\1#{zone}") + getlocal(utc_offset).strftime(format) end # Use the time in UTC for comparisons. diff --git a/activesupport/test/core_ext/time_with_zone_test.rb b/activesupport/test/core_ext/time_with_zone_test.rb index 3000da8da4..ad4062e5fe 100644 --- a/activesupport/test/core_ext/time_with_zone_test.rb +++ b/activesupport/test/core_ext/time_with_zone_test.rb @@ -79,6 +79,11 @@ class TimeWithZoneTest < ActiveSupport::TestCase assert_equal '1999-12-31 19:00:00 EST -0500', @twz.strftime('%Y-%m-%d %H:%M:%S %Z %z') end + def test_strftime_with_escaping + assert_equal '%Z %z', @twz.strftime('%%Z %%z') + assert_equal '%EST %-0500', @twz.strftime('%%%Z %%%z') + end + def test_inspect assert_equal 'Fri, 31 Dec 1999 19:00:00 EST -05:00', @twz.inspect end -- cgit v1.2.3 From 44260581bec06e4ce05f3dd838c8b4736fc7eb1d Mon Sep 17 00:00:00 2001 From: Ryunosuke SATO Date: Wed, 29 Oct 2014 00:32:43 +0900 Subject: Fix doc markup for `NumberHelper` [ci skip] The character "*" is unnecessary in option candidates. This incorrect markup was injected in e8c9aeca . --- actionview/lib/action_view/helpers/number_helper.rb | 10 +++++----- activesupport/lib/active_support/number_helper.rb | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/actionview/lib/action_view/helpers/number_helper.rb b/actionview/lib/action_view/helpers/number_helper.rb index 7220bded3c..f66dbfe7d3 100644 --- a/actionview/lib/action_view/helpers/number_helper.rb +++ b/actionview/lib/action_view/helpers/number_helper.rb @@ -306,12 +306,12 @@ module ActionView # string containing an i18n scope where to find this hash. It # might have the following keys: # * *integers*: :unit, :ten, - # *:hundred, :thousand, :million, - # *:billion, :trillion, - # *:quadrillion + # :hundred, :thousand, :million, + # :billion, :trillion, + # :quadrillion # * *fractionals*: :deci, :centi, - # *:mili, :micro, :nano, - # *:pico, :femto + # :mili, :micro, :nano, + # :pico, :femto # * :format - Sets the format of the output string # (defaults to "%n %u"). The field types are: # * %u - The quantifier (ex.: 'thousand') diff --git a/activesupport/lib/active_support/number_helper.rb b/activesupport/lib/active_support/number_helper.rb index 5ecda9593a..34439ee8be 100644 --- a/activesupport/lib/active_support/number_helper.rb +++ b/activesupport/lib/active_support/number_helper.rb @@ -272,12 +272,12 @@ module ActiveSupport # string containing an i18n scope where to find this hash. It # might have the following keys: # * *integers*: :unit, :ten, - # *:hundred, :thousand, :million, - # *:billion, :trillion, - # *:quadrillion + # :hundred, :thousand, :million, + # :billion, :trillion, + # :quadrillion # * *fractionals*: :deci, :centi, - # *:mili, :micro, :nano, - # *:pico, :femto + # :mili, :micro, :nano, + # :pico, :femto # * :format - Sets the format of the output string # (defaults to "%n %u"). The field types are: # * %u - The quantifier (ex.: 'thousand') -- cgit v1.2.3 From aa1fadd48fb40dd9396a383696134a259aa59db9 Mon Sep 17 00:00:00 2001 From: Godfrey Chan Date: Tue, 28 Oct 2014 09:43:33 -0700 Subject: Deprecate the `only_path` option on `*_path` helpers. In cases where this option is set to `true`, the option is redundant and can be safely removed; otherwise, the corresponding `*_url` helper should be used instead. Fixes #17294. See also #17363. [Dan Olson, Godfrey Chan] --- actionpack/CHANGELOG.md | 10 +++ .../lib/action_dispatch/routing/route_set.rb | 28 +++++++- actionpack/test/dispatch/routing/route_set_test.rb | 80 ++++++++++++++++++++++ 3 files changed, 116 insertions(+), 2 deletions(-) diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md index 4626c2650a..158b22c0cc 100644 --- a/actionpack/CHANGELOG.md +++ b/actionpack/CHANGELOG.md @@ -1,3 +1,13 @@ +* Deprecate the `only_path` option on `*_path` helpers. + + In cases where this option is set to `true`, the option is redundant and can + be safely removed; otherwise, the corresponding `*_url` helper should be + used instead. + + Fixes #17294. + + *Dan Olson*, *Godfrey Chan* + * Improve Journey compliance to RFC 3986. The scanner in Journey failed to recognize routes that use literals diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb index f51bee3b31..8d4a3c5670 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -134,8 +134,8 @@ module ActionDispatch @url_helpers_module.send :undef_method, url_name end routes[key] = route - define_url_helper @path_helpers_module, route, path_name, route.defaults, name, PATH - define_url_helper @url_helpers_module, route, url_name, route.defaults, name, FULL + define_url_helper @path_helpers_module, route, path_name, route.defaults, name, LEGACY + define_url_helper @url_helpers_module, route, url_name, route.defaults, name, UNKNOWN @path_helpers << path_name @url_helpers << url_name @@ -322,6 +322,30 @@ module ActionDispatch PATH = ->(options) { ActionDispatch::Http::URL.path_for(options) } FULL = ->(options) { ActionDispatch::Http::URL.full_url_for(options) } UNKNOWN = ->(options) { ActionDispatch::Http::URL.url_for(options) } + LEGACY = ->(options) { + if options.key?(:only_path) + if options[:only_path] + ActiveSupport::Deprecation.warn \ + "You are calling a `*_path` helper with the `only_path` option " \ + "expicitly set to `true`. This option will stop working on " \ + "path helpers in Rails 5. Simply remove the `only_path: true` " \ + "argument from your call as it is redundant when applied to a " \ + "path helper." + + PATH.call(options) + else + ActiveSupport::Deprecation.warn \ + "You are calling a `*_path` helper with the `only_path` option " \ + "expicitly set to `false`. This option will stop working on " \ + "path helpers in Rails 5. Use the corresponding `*_url` helper " \ + "instead." + + FULL.call(options) + end + else + PATH.call(options) + end + } # :startdoc: attr_accessor :formatter, :set, :named_routes, :default_scope, :router diff --git a/actionpack/test/dispatch/routing/route_set_test.rb b/actionpack/test/dispatch/routing/route_set_test.rb index c465d56bde..a7acc0de41 100644 --- a/actionpack/test/dispatch/routing/route_set_test.rb +++ b/actionpack/test/dispatch/routing/route_set_test.rb @@ -69,6 +69,86 @@ module ActionDispatch end end + test "only_path: true with *_url and no :host option" do + draw do + get 'foo', to: SimpleApp.new('foo#index') + end + + assert_equal '/foo', url_helpers.foo_url(only_path: true) + end + + test "only_path: false with *_url and no :host option" do + draw do + get 'foo', to: SimpleApp.new('foo#index') + end + + assert_raises ArgumentError do + assert_equal 'http://example.com/foo', url_helpers.foo_url(only_path: false) + end + end + + test "only_path: false with *_url and local :host option" do + draw do + get 'foo', to: SimpleApp.new('foo#index') + end + + assert_equal 'http://example.com/foo', url_helpers.foo_url(only_path: false, host: 'example.com') + end + + test "only_path: false with *_url and global :host option" do + @set.default_url_options = { host: 'example.com' } + + draw do + get 'foo', to: SimpleApp.new('foo#index') + end + + assert_equal 'http://example.com/foo', url_helpers.foo_url(only_path: false) + end + + test "only_path: true with *_path" do + draw do + get 'foo', to: SimpleApp.new('foo#index') + end + + assert_deprecated do + assert_equal '/foo', url_helpers.foo_path(only_path: true) + end + end + + test "only_path: false with *_path with global :host option" do + @set.default_url_options = { host: 'example.com' } + + draw do + get 'foo', to: SimpleApp.new('foo#index') + end + + assert_deprecated do + assert_equal 'http://example.com/foo', url_helpers.foo_path(only_path: false) + end + end + + test "only_path: false with *_path with local :host option" do + draw do + get 'foo', to: SimpleApp.new('foo#index') + end + + assert_deprecated do + assert_equal 'http://example.com/foo', url_helpers.foo_path(only_path: false, host: 'example.com') + end + end + + test "only_path: false with *_path with no :host option" do + draw do + get 'foo', to: SimpleApp.new('foo#index') + end + + assert_deprecated do + assert_raises ArgumentError do + assert_equal 'http://example.com/foo', url_helpers.foo_path(only_path: false) + end + end + end + test "explicit keys win over implicit keys" do draw do resources :foo do -- cgit v1.2.3 From 0cd6c0842d6e003c49b3ea549b9a7d4be182c02a Mon Sep 17 00:00:00 2001 From: Godfrey Chan Date: Tue, 28 Oct 2014 09:48:01 -0700 Subject: Mention only_path deprecation in release notes [ci skip] --- guides/source/4_2_release_notes.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/guides/source/4_2_release_notes.md b/guides/source/4_2_release_notes.md index d903752cff..d9f49aac55 100644 --- a/guides/source/4_2_release_notes.md +++ b/guides/source/4_2_release_notes.md @@ -395,6 +395,9 @@ Please refer to the [Changelog][action-pack] for detailed changes. ### Deprecations +* Deprecated the `only_path` option on `*_path` helpers. + ([Commit](https://github.com/rails/rails/commit/aa1fadd48fb40dd9396a383696134a259aa59db9)) + * Deprecated `assert_tag`, `assert_no_tag`, `find_tag` and `find_all_tag` in favor of `assert_select`. ([Commit](https://github.com/rails/rails-dom-testing/commit/b12850bc5ff23ba4b599bf2770874dd4f11bf750)) -- cgit v1.2.3 From 777142d3a7b9ea36fcc8562613749299ac6dc243 Mon Sep 17 00:00:00 2001 From: Godfrey Chan Date: Tue, 28 Oct 2014 11:05:54 -0700 Subject: Typos in the deprecation message --- actionpack/lib/action_dispatch/routing/route_set.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb index 8d4a3c5670..6acee80513 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -327,7 +327,7 @@ module ActionDispatch if options[:only_path] ActiveSupport::Deprecation.warn \ "You are calling a `*_path` helper with the `only_path` option " \ - "expicitly set to `true`. This option will stop working on " \ + "explicitly set to `true`. This option will stop working on " \ "path helpers in Rails 5. Simply remove the `only_path: true` " \ "argument from your call as it is redundant when applied to a " \ "path helper." @@ -336,7 +336,7 @@ module ActionDispatch else ActiveSupport::Deprecation.warn \ "You are calling a `*_path` helper with the `only_path` option " \ - "expicitly set to `false`. This option will stop working on " \ + "explicitly set to `false`. This option will stop working on " \ "path helpers in Rails 5. Use the corresponding `*_url` helper " \ "instead." -- cgit v1.2.3 From fa7c004df124cbfdc919d5581c83a9c694a0100a Mon Sep 17 00:00:00 2001 From: Sean Griffin Date: Tue, 28 Oct 2014 16:57:52 -0600 Subject: Call value methods when merging relations, rather than accessing keys The change to accessing keys directly was originally added to allow `merge` to take a hash. The implementation of `HashMerger` no longer requires us to be doing so. Accessing the values directly makes it impossible to change internal storage details, even if shim methods are added temporarily --- activerecord/lib/active_record/relation/merger.rb | 28 +++++++++++------------ 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/activerecord/lib/active_record/relation/merger.rb b/activerecord/lib/active_record/relation/merger.rb index 545bf5debc..f6bfbe59e2 100644 --- a/activerecord/lib/active_record/relation/merger.rb +++ b/activerecord/lib/active_record/relation/merger.rb @@ -83,12 +83,12 @@ module ActiveRecord private def merge_joins - return if values[:joins].blank? + return if other.joins_values.blank? if other.klass == relation.klass - relation.joins!(*values[:joins]) + relation.joins!(*other.joins_values) else - joins_dependency, rest = values[:joins].partition do |join| + joins_dependency, rest = other.joins_values.partition do |join| case join when Hash, Symbol, Array true @@ -108,10 +108,10 @@ module ActiveRecord def merge_multi_values lhs_wheres = relation.where_values - rhs_wheres = values[:where] || [] + rhs_wheres = other.where_values || [] lhs_binds = relation.bind_values - rhs_binds = values[:bind] || [] + rhs_binds = other.bind_values || [] removed, kept = partition_overwrites(lhs_wheres, rhs_wheres) @@ -133,23 +133,23 @@ module ActiveRecord relation.where_values = where_values relation.bind_values = bind_values - if values[:reordering] + if other.reordering_value # override any order specified in the original relation - relation.reorder! values[:order] - elsif values[:order] + relation.reorder! other.order_values + elsif other.order_values # merge in order_values from relation - relation.order! values[:order] + relation.order! other.order_values end - relation.extend(*values[:extending]) unless values[:extending].blank? + relation.extend(*other.extending_values) unless other.extending_values.blank? end def merge_single_values - relation.from_value = values[:from] unless relation.from_value - relation.lock_value = values[:lock] unless relation.lock_value + relation.from_value = other.from_value unless relation.from_value + relation.lock_value = other.lock_value unless relation.lock_value - unless values[:create_with].blank? - relation.create_with_value = (relation.create_with_value || {}).merge(values[:create_with]) + unless other.create_with_value.blank? + relation.create_with_value = (relation.create_with_value || {}).merge(other.create_with_value) end end -- cgit v1.2.3 From 4c248a0280f695c87757eacc8f30506cb6c1e90a Mon Sep 17 00:00:00 2001 From: Sean Griffin Date: Tue, 28 Oct 2014 17:00:47 -0600 Subject: Fix uninitialized ivar warning in tests --- activerecord/lib/active_record/attribute_methods.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/activerecord/lib/active_record/attribute_methods.rb b/activerecord/lib/active_record/attribute_methods.rb index f4a4e3f605..c797a11cec 100644 --- a/activerecord/lib/active_record/attribute_methods.rb +++ b/activerecord/lib/active_record/attribute_methods.rb @@ -90,7 +90,7 @@ module ActiveRecord def undefine_attribute_methods # :nodoc: generated_attribute_methods.synchronize do - super if @attribute_methods_generated + super if defined?(@attribute_methods_generated) && @attribute_methods_generated @attribute_methods_generated = false end end -- cgit v1.2.3 From 521532342452b3024c9cb2e7ebbd7170ee0d42e5 Mon Sep 17 00:00:00 2001 From: Sean Griffin Date: Tue, 28 Oct 2014 17:03:06 -0600 Subject: Remove unneccessary default values from relation merger The value methods will default to an empty array for us automatically --- activerecord/lib/active_record/relation/merger.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/activerecord/lib/active_record/relation/merger.rb b/activerecord/lib/active_record/relation/merger.rb index f6bfbe59e2..a8febf6a18 100644 --- a/activerecord/lib/active_record/relation/merger.rb +++ b/activerecord/lib/active_record/relation/merger.rb @@ -108,10 +108,10 @@ module ActiveRecord def merge_multi_values lhs_wheres = relation.where_values - rhs_wheres = other.where_values || [] + rhs_wheres = other.where_values lhs_binds = relation.bind_values - rhs_binds = other.bind_values || [] + rhs_binds = other.bind_values removed, kept = partition_overwrites(lhs_wheres, rhs_wheres) -- cgit v1.2.3 From b3bfa361c503e107aff4dee5edf79bd7fd3d3725 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Tue, 28 Oct 2014 16:17:33 -0700 Subject: let's warn with heredocs The current style for warning messages without newlines uses concatenation of string literals with manual trailing spaces where needed. Heredocs have better readability, and with `squish` we can still produce a single line. This is a similar use case to the one that motivated defining `strip_heredoc`, heredocs are super clean. --- actionmailer/lib/action_mailer/message_delivery.rb | 17 +++++++++--- .../action_controller/metal/strong_parameters.rb | 11 +++++--- actionpack/lib/action_dispatch/http/response.rb | 8 +++++- .../lib/action_dispatch/routing/route_set.rb | 25 ++++++++++-------- actionview/lib/action_view/template/resolver.rb | 8 +++--- .../associations/has_many_through_association.rb | 13 ++++++---- .../lib/active_record/attribute_methods.rb | 9 ++++--- .../attribute_methods/serialization.rb | 8 ++++-- .../abstract/connection_pool.rb | 10 +++++--- .../abstract/schema_definitions.rb | 11 ++++---- .../connection_specification.rb | 9 +++++-- .../connection_adapters/postgresql/oid/range.rb | 11 +++++--- activerecord/lib/active_record/core.rb | 15 +++++++---- activerecord/lib/active_record/reflection.rb | 30 ++++++++++++++-------- .../lib/active_record/relation/finder_methods.rb | 13 +++++++--- .../relation/predicate_builder/array_handler.rb | 11 +++++--- .../lib/active_record/relation/query_methods.rb | 7 +++-- .../lib/active_record/tasks/database_tasks.rb | 9 ++++--- 18 files changed, 149 insertions(+), 76 deletions(-) diff --git a/actionmailer/lib/action_mailer/message_delivery.rb b/actionmailer/lib/action_mailer/message_delivery.rb index c18e914f37..e058b3b15d 100644 --- a/actionmailer/lib/action_mailer/message_delivery.rb +++ b/actionmailer/lib/action_mailer/message_delivery.rb @@ -1,4 +1,5 @@ require 'delegate' +require 'active_support/core_ext/string/filters' module ActionMailer @@ -85,14 +86,22 @@ module ActionMailer end def deliver! #:nodoc: - ActiveSupport::Deprecation.warn "#deliver! is deprecated and will be removed in Rails 5. " \ - "Use #deliver_now! to deliver immediately or #deliver_later! to deliver through Active Job." + ActiveSupport::Deprecation.warn(<<-MSG.squish) + #deliver! is deprecated and will be removed in Rails 5. Use + #deliver_now! to deliver immediately or #deliver_later! to + deliver through Active Job. + MSG + deliver_now! end def deliver #:nodoc: - ActiveSupport::Deprecation.warn "#deliver is deprecated and will be removed in Rails 5. " \ - "Use #deliver_now to deliver immediately or #deliver_later to deliver through Active Job." + ActiveSupport::Deprecation.warn(<<-MSG.squish) + #deliver is deprecated and will be removed in Rails 5. Use + #deliver_now to deliver immediately or #deliver_later to + deliver through Active Job. + MSG + deliver_now end diff --git a/actionpack/lib/action_controller/metal/strong_parameters.rb b/actionpack/lib/action_controller/metal/strong_parameters.rb index 7038f0997f..a5ee1e2159 100644 --- a/actionpack/lib/action_controller/metal/strong_parameters.rb +++ b/actionpack/lib/action_controller/metal/strong_parameters.rb @@ -1,5 +1,6 @@ require 'active_support/core_ext/hash/indifferent_access' require 'active_support/core_ext/array/wrap' +require 'active_support/core_ext/string/filters' require 'active_support/deprecation' require 'active_support/rescuable' require 'action_dispatch/http/upload' @@ -114,10 +115,12 @@ module ActionController def self.const_missing(const_name) super unless const_name == :NEVER_UNPERMITTED_PARAMS - ActiveSupport::Deprecation.warn "`ActionController::Parameters::NEVER_UNPERMITTED_PARAMS`"\ - " has been deprecated. Use "\ - "`ActionController::Parameters.always_permitted_parameters` instead." - self.always_permitted_parameters + ActiveSupport::Deprecation.warn(<<-MSG.squish) + `ActionController::Parameters::NEVER_UNPERMITTED_PARAMS` has been deprecated. + Use `ActionController::Parameters.always_permitted_parameters` instead. + MSG + + always_permitted_parameters end # Returns a new instance of ActionController::Parameters. diff --git a/actionpack/lib/action_dispatch/http/response.rb b/actionpack/lib/action_dispatch/http/response.rb index 99d46af953..2918a98796 100644 --- a/actionpack/lib/action_dispatch/http/response.rb +++ b/actionpack/lib/action_dispatch/http/response.rb @@ -1,4 +1,5 @@ require 'active_support/core_ext/module/attribute_accessors' +require 'active_support/core_ext/string/filters' require 'active_support/deprecation' require 'action_dispatch/http/filter_redirect' require 'monitor' @@ -288,7 +289,12 @@ module ActionDispatch # :nodoc: # as arrays work, and "flattening" responses, cascading to the rack body! # Not sensible behavior. def to_ary - ActiveSupport::Deprecation.warn 'ActionDispatch::Response#to_ary no longer performs implicit conversion to an Array. Please use response.to_a instead, or a splat like `status, headers, body = *response`' + ActiveSupport::Deprecation.warn(<<-MSG.squish) + 'ActionDispatch::Response#to_ary no longer performs implicit conversion + to an Array. Please use response.to_a instead, or a splat like `status, + headers, body = *response` + MSG + to_a end diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb index 6acee80513..746742a85f 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -6,6 +6,7 @@ require 'active_support/core_ext/object/to_query' require 'active_support/core_ext/hash/slice' require 'active_support/core_ext/module/remove_method' require 'active_support/core_ext/array/extract_options' +require 'active_support/core_ext/string/filters' require 'action_controller/metal/exceptions' require 'action_dispatch/http/request' require 'action_dispatch/routing/endpoint' @@ -325,20 +326,22 @@ module ActionDispatch LEGACY = ->(options) { if options.key?(:only_path) if options[:only_path] - ActiveSupport::Deprecation.warn \ - "You are calling a `*_path` helper with the `only_path` option " \ - "explicitly set to `true`. This option will stop working on " \ - "path helpers in Rails 5. Simply remove the `only_path: true` " \ - "argument from your call as it is redundant when applied to a " \ - "path helper." + ActiveSupport::Deprecation.warn(<<-MSG.squish) + You are calling a `*_path` helper with the `only_path` option + explicitly set to `true`. This option will stop working on + path helpers in Rails 5. Simply remove the `only_path: true` + argument from your call as it is redundant when applied to a + path helper. + MSG PATH.call(options) else - ActiveSupport::Deprecation.warn \ - "You are calling a `*_path` helper with the `only_path` option " \ - "explicitly set to `false`. This option will stop working on " \ - "path helpers in Rails 5. Use the corresponding `*_url` helper " \ - "instead." + ActiveSupport::Deprecation.warn(<<-MSG.squish) + You are calling a `*_path` helper with the `only_path` option + explicitly set to `false`. This option will stop working on + path helpers in Rails 5. Use the corresponding `*_url` helper + instead. + MSG FULL.call(options) end diff --git a/actionview/lib/action_view/template/resolver.rb b/actionview/lib/action_view/template/resolver.rb index d77421d5f5..b65507f4a2 100644 --- a/actionview/lib/action_view/template/resolver.rb +++ b/actionview/lib/action_view/template/resolver.rb @@ -1,6 +1,7 @@ require "pathname" require "active_support/core_ext/class" require "active_support/core_ext/module/attribute_accessors" +require 'active_support/core_ext/string/filters' require "action_view/template" require "thread" require "thread_safe" @@ -251,9 +252,10 @@ module ActionView extension = pieces.pop unless extension - message = "The file #{path} did not specify a template handler. The default is currently ERB, " \ - "but will change to RAW in the future." - ActiveSupport::Deprecation.warn message + ActiveSupport::Deprecation.warn(<<-MSG.squish) + The file #{path} did not specify a template handler. The default is + currently ERB, but will change to RAW in the future. + MSG end handler = Template.handler_for_extension(extension) diff --git a/activerecord/lib/active_record/associations/has_many_through_association.rb b/activerecord/lib/active_record/associations/has_many_through_association.rb index 57affce4f7..1b84fdf5f2 100644 --- a/activerecord/lib/active_record/associations/has_many_through_association.rb +++ b/activerecord/lib/active_record/associations/has_many_through_association.rb @@ -1,3 +1,5 @@ +require 'active_support/core_ext/string/filters' + module ActiveRecord # = Active Record Has Many Through Association module Associations @@ -63,11 +65,12 @@ module ActiveRecord save_through_record(record) if has_cached_counter? && !through_reflection_updates_counter_cache? - ActiveSupport::Deprecation.warn \ - "Automatic updating of counter caches on through associations has been " \ - "deprecated, and will be removed in Rails 5.0. Instead, please set the " \ - "appropriate counter_cache options on the has_many and belongs_to for " \ - "your associations to #{through_reflection.name}." + ActiveSupport::Deprecation.warn(<<-MSG.squish) + Automatic updating of counter caches on through associations has been + deprecated, and will be removed in Rails 5.0. Instead, please set the + appropriate counter_cache options on the has_many and belongs_to for + your associations to #{through_reflection.name}. + MSG update_counter_in_database(1) end diff --git a/activerecord/lib/active_record/attribute_methods.rb b/activerecord/lib/active_record/attribute_methods.rb index f4a4e3f605..368a0e3822 100644 --- a/activerecord/lib/active_record/attribute_methods.rb +++ b/activerecord/lib/active_record/attribute_methods.rb @@ -1,4 +1,5 @@ require 'active_support/core_ext/enumerable' +require 'active_support/core_ext/string/filters' require 'mutex_m' require 'thread_safe' @@ -205,9 +206,11 @@ module ActiveRecord def column_for_attribute(name) column = columns_hash[name.to_s] if column.nil? - ActiveSupport::Deprecation.warn \ - "`column_for_attribute` will return a null object for non-existent columns " \ - "in Rails 5.0. Use `has_attribute?` if you need to check for an attribute's existence." + ActiveSupport::Deprecation.warn(<<-MSG.squish) + `column_for_attribute` will return a null object for non-existent + columns in Rails 5.0. Use `has_attribute?` if you need to check for + an attribute's existence. + MSG end column end diff --git a/activerecord/lib/active_record/attribute_methods/serialization.rb b/activerecord/lib/active_record/attribute_methods/serialization.rb index cc82d00b20..e5ec5ddca5 100644 --- a/activerecord/lib/active_record/attribute_methods/serialization.rb +++ b/activerecord/lib/active_record/attribute_methods/serialization.rb @@ -1,3 +1,5 @@ +require 'active_support/core_ext/string/filters' + module ActiveRecord module AttributeMethods module Serialization @@ -51,8 +53,10 @@ module ActiveRecord end def serialized_attributes - ActiveSupport::Deprecation.warn "`serialized_attributes` is deprecated " \ - "without replacement, and will be removed in Rails 5.0." + ActiveSupport::Deprecation.warn(<<-MSG.squish) + `serialized_attributes` is deprecated without replacement, and will + be removed in Rails 5.0. + MSG @serialized_attributes ||= Hash[ columns.select { |t| t.cast_type.is_a?(Type::Serialized) }.map { |c| diff --git a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb index eba51baba1..e197f7f2f9 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb @@ -2,6 +2,7 @@ require 'thread' require 'thread_safe' require 'monitor' require 'set' +require 'active_support/core_ext/string/filters' module ActiveRecord # Raised when a connection could not be obtained within the connection @@ -518,10 +519,11 @@ module ActiveRecord end def connection_pools - ActiveSupport::Deprecation.warn( - "In the next release, this will return the same as #connection_pool_list. " \ - "(An array of pools, rather than a hash mapping specs to pools.)" - ) + ActiveSupport::Deprecation.warn(<<-MSG.squish) + In the next release, this will return the same as #connection_pool_list. + (An array of pools, rather than a hash mapping specs to pools.) + MSG + Hash[connection_pool_list.map { |pool| [pool.spec, pool] }] end diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb index 7534fde03e..1aed8b0457 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb @@ -60,11 +60,12 @@ module ActiveRecord def emit_warning_if_null_unspecified(options) return if options.key?(:null) - ActiveSupport::Deprecation.warn \ - "`timestamp` was called without specifying an option for `null`. In Rails " \ - "5.0, this behavior will change to `null: false`. You should manually " \ - "specify `null: true` to prevent the behavior of your existing migrations " \ - "from changing." + ActiveSupport::Deprecation.warn(<<-MSG.squish) + `timestamp` was called without specifying an option for `null`. In Rails + 5.0, this behavior will change to `null: false`. You should manually + specify `null: true` to prevent the behavior of your existing migrations + from changing. + MSG end end diff --git a/activerecord/lib/active_record/connection_adapters/connection_specification.rb b/activerecord/lib/active_record/connection_adapters/connection_specification.rb index e02824b33d..af405fc690 100644 --- a/activerecord/lib/active_record/connection_adapters/connection_specification.rb +++ b/activerecord/lib/active_record/connection_adapters/connection_specification.rb @@ -1,4 +1,5 @@ require 'uri' +require 'active_support/core_ext/string/filters' module ActiveRecord module ConnectionAdapters @@ -221,8 +222,12 @@ module ActiveRecord # this ambiguous behaviour and in the future this function # can be removed in favor of resolve_url_connection. if configurations.key?(spec) || spec !~ /:/ - ActiveSupport::Deprecation.warn "Passing a string to ActiveRecord::Base.establish_connection " \ - "for a configuration lookup is deprecated, please pass a symbol (#{spec.to_sym.inspect}) instead" + ActiveSupport::Deprecation.warn(<<-MSG.squish) + Passing a string to ActiveRecord::Base.establish_connection for a + configuration lookup is deprecated, please pass a symbol + (#{spec.to_sym.inspect}) instead + MSG + resolve_symbol_connection(spec) else resolve_url_connection(spec) diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/oid/range.rb b/activerecord/lib/active_record/connection_adapters/postgresql/oid/range.rb index 84b9490ba3..961e6224c4 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/oid/range.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/oid/range.rb @@ -1,3 +1,5 @@ +require 'active_support/core_ext/string/filters' + module ActiveRecord module ConnectionAdapters module PostgreSQL @@ -25,10 +27,11 @@ module ActiveRecord if !infinity?(from) && extracted[:exclude_start] if from.respond_to?(:succ) from = from.succ - ActiveSupport::Deprecation.warn \ - "Excluding the beginning of a Range is only partialy supported " \ - "through `#succ`. This is not reliable and will be removed in " \ - "the future." + ActiveSupport::Deprecation.warn(<<-MSG.squish) + Excluding the beginning of a Range is only partialy supported + through `#succ`. This is not reliable and will be removed in + the future. + MSG else raise ArgumentError, "The Ruby Range object does not support excluding the beginning of a Range. (unsupported value: '#{value}')" end diff --git a/activerecord/lib/active_record/core.rb b/activerecord/lib/active_record/core.rb index f9b6375459..9ab27bbac5 100644 --- a/activerecord/lib/active_record/core.rb +++ b/activerecord/lib/active_record/core.rb @@ -1,6 +1,7 @@ +require 'thread' require 'active_support/core_ext/hash/indifferent_access' require 'active_support/core_ext/object/duplicable' -require 'thread' +require 'active_support/core_ext/string/filters' module ActiveRecord module Core @@ -88,8 +89,10 @@ module ActiveRecord mattr_accessor :maintain_test_schema, instance_accessor: false def self.disable_implicit_join_references=(value) - ActiveSupport::Deprecation.warn("Implicit join references were removed with Rails 4.1." \ - "Make sure to remove this configuration because it does nothing.") + ActiveSupport::Deprecation.warn(<<-MSG.squish) + Implicit join references were removed with Rails 4.1. + Make sure to remove this configuration because it does nothing. + MSG end class_attribute :default_connection_handler, instance_writer: false @@ -135,8 +138,10 @@ module ActiveRecord id = ids.first if ActiveRecord::Base === id id = id.id - ActiveSupport::Deprecation.warn "You are passing an instance of ActiveRecord::Base to `find`." \ - "Please pass the id of the object by calling `.id`" + ActiveSupport::Deprecation.warn(<<-MSG.squish) + You are passing an instance of ActiveRecord::Base to `find`. + Please pass the id of the object by calling `.id` + MSG end key = primary_key diff --git a/activerecord/lib/active_record/reflection.rb b/activerecord/lib/active_record/reflection.rb index 22aa175ce2..4b58f2deb7 100644 --- a/activerecord/lib/active_record/reflection.rb +++ b/activerecord/lib/active_record/reflection.rb @@ -1,4 +1,5 @@ require 'thread' +require 'active_support/core_ext/string/filters' module ActiveRecord # = Active Record Reflection @@ -153,8 +154,11 @@ module ActiveRecord end def source_macro - ActiveSupport::Deprecation.warn("ActiveRecord::Base.source_macro is deprecated and " \ - "will be removed without replacement.") + ActiveSupport::Deprecation.warn(<<-MSG.squish) + ActiveRecord::Base.source_macro is deprecated and will be removed + without replacement. + MSG + macro end end @@ -339,13 +343,14 @@ module ActiveRecord return unless scope if scope.arity > 0 - ActiveSupport::Deprecation.warn \ - "The association scope '#{name}' is instance dependent (the scope " \ - "block takes an argument). Preloading happens before the individual " \ - "instances are created. This means that there is no instance being " \ - "passed to the association scope. This will most likely result in " \ - "broken or incorrect behavior. Joining, Preloading and eager loading " \ - "of these associations is deprecated and will be removed in the future." + ActiveSupport::Deprecation.warn(<<-MSG.squish) + The association scope '#{name}' is instance dependent (the scope + block takes an argument). Preloading happens before the individual + instances are created. This means that there is no instance being + passed to the association scope. This will most likely result in + broken or incorrect behavior. Joining, Preloading and eager loading + of these associations is deprecated and will be removed in the future. + MSG end end alias :check_eager_loadable! :check_preloadable! @@ -746,8 +751,11 @@ module ActiveRecord # The macro used by the source association def source_macro - ActiveSupport::Deprecation.warn("ActiveRecord::Base.source_macro is deprecated and " \ - "will be removed without replacement.") + ActiveSupport::Deprecation.warn(<<-MSG.squish) + ActiveRecord::Base.source_macro is deprecated and will be removed + without replacement. + MSG + source_reflection.source_macro end diff --git a/activerecord/lib/active_record/relation/finder_methods.rb b/activerecord/lib/active_record/relation/finder_methods.rb index c95ec2522b..ddb392a6d4 100644 --- a/activerecord/lib/active_record/relation/finder_methods.rb +++ b/activerecord/lib/active_record/relation/finder_methods.rb @@ -1,4 +1,5 @@ require 'active_support/deprecation' +require 'active_support/core_ext/string/filters' module ActiveRecord module FinderMethods @@ -284,8 +285,10 @@ module ActiveRecord def exists?(conditions = :none) if Base === conditions conditions = conditions.id - ActiveSupport::Deprecation.warn "You are passing an instance of ActiveRecord::Base to `exists?`." \ - "Please pass the id of the object by calling `.id`" + ActiveSupport::Deprecation.warn(<<-MSG.squish) + You are passing an instance of ActiveRecord::Base to `exists?`. + Please pass the id of the object by calling `.id` + MSG end return false if !conditions @@ -435,8 +438,10 @@ module ActiveRecord def find_one(id) if ActiveRecord::Base === id id = id.id - ActiveSupport::Deprecation.warn "You are passing an instance of ActiveRecord::Base to `find`." \ - "Please pass the id of the object by calling `.id`" + ActiveSupport::Deprecation.warn(<<-MSG.squish) + You are passing an instance of ActiveRecord::Base to `find`. + Please pass the id of the object by calling `.id` + MSG end column = columns_hash[primary_key] diff --git a/activerecord/lib/active_record/relation/predicate_builder/array_handler.rb b/activerecord/lib/active_record/relation/predicate_builder/array_handler.rb index b8d9240bf8..b6a9b4f63a 100644 --- a/activerecord/lib/active_record/relation/predicate_builder/array_handler.rb +++ b/activerecord/lib/active_record/relation/predicate_builder/array_handler.rb @@ -1,3 +1,5 @@ +require 'active_support/core_ext/string/filters' + module ActiveRecord class PredicateBuilder class ArrayHandler # :nodoc: @@ -6,9 +8,12 @@ module ActiveRecord nils, values = values.partition(&:nil?) if values.any? { |val| val.is_a?(Array) } - ActiveSupport::Deprecation.warn "Passing a nested array to Active Record " \ - "finder methods is deprecated and will be removed. Flatten your array " \ - "before using it for 'IN' conditions." + ActiveSupport::Deprecation.warn(<<-MSG.squish) + Passing a nested array to Active Record finder methods is + deprecated and will be removed. Flatten your array before using + it for 'IN' conditions. + MSG + values = values.flatten end diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb index e4bebf78e8..2c3cfb7631 100644 --- a/activerecord/lib/active_record/relation/query_methods.rb +++ b/activerecord/lib/active_record/relation/query_methods.rb @@ -1,4 +1,5 @@ require 'active_support/core_ext/array/wrap' +require 'active_support/core_ext/string/filters' require 'active_model/forbidden_attributes_protection' module ActiveRecord @@ -94,8 +95,10 @@ module ActiveRecord def check_cached_relation # :nodoc: if defined?(@arel) && @arel @arel = nil - ActiveSupport::Deprecation.warn "Modifying already cached Relation. The " \ - "cache will be reset. Use a cloned Relation to prevent this warning." + ActiveSupport::Deprecation.warn(<<-MSG.squish) + Modifying already cached Relation. The cache will be reset. Use a + cloned Relation to prevent this warning. + MSG end end diff --git a/activerecord/lib/active_record/tasks/database_tasks.rb b/activerecord/lib/active_record/tasks/database_tasks.rb index f9b54139d5..22a6f9af7e 100644 --- a/activerecord/lib/active_record/tasks/database_tasks.rb +++ b/activerecord/lib/active_record/tasks/database_tasks.rb @@ -1,3 +1,5 @@ +require 'active_support/core_ext/string/filters' + module ActiveRecord module Tasks # :nodoc: class DatabaseAlreadyExists < StandardError; end # :nodoc: @@ -187,9 +189,10 @@ module ActiveRecord end def load_schema(format = ActiveRecord::Base.schema_format, file = nil) - ActiveSupport::Deprecation.warn \ - "This method will act on a specific connection in the future. " \ - "To act on the current connection, use `load_schema_current` instead." + ActiveSupport::Deprecation.warn(<<-MSG.squish) + This method will act on a specific connection in the future. + To act on the current connection, use `load_schema_current` instead. + MSG load_schema_current(format, file) end -- cgit v1.2.3 From 79437642d537f24a36d9e649713941eebfff35c2 Mon Sep 17 00:00:00 2001 From: Sean Griffin Date: Tue, 28 Oct 2014 17:35:55 -0600 Subject: Implement #== for column We shouldn't rely on reference equality of these objects in tests --- activerecord/lib/active_record/connection_adapters/column.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/activerecord/lib/active_record/connection_adapters/column.rb b/activerecord/lib/active_record/connection_adapters/column.rb index 5f9cc6edd0..cdbcca3728 100644 --- a/activerecord/lib/active_record/connection_adapters/column.rb +++ b/activerecord/lib/active_record/connection_adapters/column.rb @@ -56,6 +56,14 @@ module ActiveRecord clone.instance_variable_set('@cast_type', type) end end + + def ==(other) + other.name == name && + other.default == default && + other.cast_type == cast_type && + other.sql_type == sql_type && + other.null == null + end end end # :startdoc: -- cgit v1.2.3 From e13ac306a09611c2d7f7e3ca813e8409d7dfc834 Mon Sep 17 00:00:00 2001 From: Sean Griffin Date: Tue, 28 Oct 2014 17:39:27 -0600 Subject: Implement hash equality on column The query cache uses bind values as hash keys. The current implementation relies on reference equality for hash equality. This is brittle, and can easily break in the future. --- activerecord/lib/active_record/connection_adapters/column.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/activerecord/lib/active_record/connection_adapters/column.rb b/activerecord/lib/active_record/connection_adapters/column.rb index cdbcca3728..01f06af348 100644 --- a/activerecord/lib/active_record/connection_adapters/column.rb +++ b/activerecord/lib/active_record/connection_adapters/column.rb @@ -64,6 +64,11 @@ module ActiveRecord other.sql_type == sql_type && other.null == null end + alias :eql? :== + + def hash + [self.class, name, default, cast_type, sql_type, null].hash + end end end # :startdoc: -- cgit v1.2.3 From 21f081c0ca86df65c2598e3a273a4c9a785dd5d6 Mon Sep 17 00:00:00 2001 From: Sean Griffin Date: Tue, 28 Oct 2014 17:43:58 -0600 Subject: =?UTF-8?q?=F0=9F=92=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We were relying on hash inequality in tests --- activerecord/test/cases/base_test.rb | 5 ++++- activerecord/test/schema/schema.rb | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb index fb535e74fc..4ad27c0e8d 100644 --- a/activerecord/test/cases/base_test.rb +++ b/activerecord/test/cases/base_test.rb @@ -1383,7 +1383,10 @@ class BasicsTest < ActiveRecord::TestCase c1 = Post.connection.schema_cache.columns('posts') ActiveRecord::Base.clear_cache! c2 = Post.connection.schema_cache.columns('posts') - assert_not_equal c1, c2 + c1.each_with_index do |v, i| + assert_not_same v, c2[i] + end + assert_equal c1, c2 end def test_current_scope_is_reset diff --git a/activerecord/test/schema/schema.rb b/activerecord/test/schema/schema.rb index 10de3d34cb..2b68236256 100644 --- a/activerecord/test/schema/schema.rb +++ b/activerecord/test/schema/schema.rb @@ -311,7 +311,7 @@ ActiveRecord::Schema.define do end create_table :cold_jokes, force: true do |t| - t.string :name + t.string :cold_name end create_table :friendships, force: true do |t| -- cgit v1.2.3 From ec012e446ad5a502ce5fcf5139a3ed7ee9e220ba Mon Sep 17 00:00:00 2001 From: Sean Griffin Date: Tue, 28 Oct 2014 17:52:58 -0600 Subject: Add mysql and pg specific attributes to Column#== and hash --- .../connection_adapters/abstract_mysql_adapter.rb | 11 +++++++++++ activerecord/lib/active_record/connection_adapters/column.rb | 11 +++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb index e4cfe843a8..c5dd93ee89 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb @@ -91,6 +91,13 @@ module ActiveRecord collation && !collation.match(/_ci$/) end + def ==(other) + super && + collation == other.collation && + strict == other.strict && + extra == other.extra + end + private # MySQL misreports NOT NULL column default when none is given. @@ -109,6 +116,10 @@ module ActiveRecord raise ArgumentError, "#{type} columns cannot have a default value: #{default.inspect}" end end + + def attributes_for_hash + super + [collation, strict, extra] + end end ## diff --git a/activerecord/lib/active_record/connection_adapters/column.rb b/activerecord/lib/active_record/connection_adapters/column.rb index 01f06af348..dd303c73d5 100644 --- a/activerecord/lib/active_record/connection_adapters/column.rb +++ b/activerecord/lib/active_record/connection_adapters/column.rb @@ -62,12 +62,19 @@ module ActiveRecord other.default == default && other.cast_type == cast_type && other.sql_type == sql_type && - other.null == null + other.null == null && + other.default_function == default_function end alias :eql? :== def hash - [self.class, name, default, cast_type, sql_type, null].hash + attributes_for_hash.hash + end + + private + + def attributes_for_hash + [self.class, name, default, cast_type, sql_type, null, default_function] end end end -- cgit v1.2.3 From e595d91ac2c07371b441f8b04781e7c03ac44135 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Tue, 28 Oct 2014 17:33:36 -0700 Subject: edit pass over all warnings This patch uniformizes warning messages. I used the most common style already present in the code base: * Capitalize the first word. * End the message with a full stop. * "Rails 5" instead of "Rails 5.0". * Backticks for method names and inline code. Also, converted a few long strings into the new heredoc convention. --- actionmailer/lib/action_mailer/message_delivery.rb | 8 ++++---- actionpack/lib/action_dispatch/http/parameters.rb | 2 +- actionpack/lib/action_dispatch/http/request.rb | 2 +- actionpack/lib/action_dispatch/http/response.rb | 6 +++--- actionpack/lib/action_dispatch/routing/mapper.rb | 13 +++++++++++-- actionpack/lib/action_dispatch/routing/route_set.rb | 5 ++++- actionpack/lib/action_dispatch/testing/assertions/tag.rb | 2 +- actionview/lib/action_view/view_paths.rb | 6 +++++- activemodel/lib/active_model/dirty.rb | 12 ++++++++++-- .../associations/has_many_through_association.rb | 6 +++--- activerecord/lib/active_record/attribute_methods.rb | 4 ++-- .../connection_adapters/abstract/connection_pool.rb | 2 +- .../connection_adapters/abstract/schema_definitions.rb | 7 +++---- .../connection_adapters/connection_specification.rb | 2 +- activerecord/lib/active_record/inheritance.rb | 4 ++-- activerecord/lib/active_record/type/boolean.rb | 10 +++++++--- .../lib/active_support/core_ext/kernel/reporting.rb | 6 +++--- activesupport/lib/active_support/json/encoding.rb | 2 +- activesupport/lib/active_support/test_case.rb | 2 +- railties/lib/rails/rack/log_tailer.rb | 2 +- 20 files changed, 65 insertions(+), 38 deletions(-) diff --git a/actionmailer/lib/action_mailer/message_delivery.rb b/actionmailer/lib/action_mailer/message_delivery.rb index e058b3b15d..b5dc2d7497 100644 --- a/actionmailer/lib/action_mailer/message_delivery.rb +++ b/actionmailer/lib/action_mailer/message_delivery.rb @@ -87,8 +87,8 @@ module ActionMailer def deliver! #:nodoc: ActiveSupport::Deprecation.warn(<<-MSG.squish) - #deliver! is deprecated and will be removed in Rails 5. Use - #deliver_now! to deliver immediately or #deliver_later! to + `#deliver!` is deprecated and will be removed in Rails 5. Use + `#deliver_now!` to deliver immediately or `#deliver_later!` to deliver through Active Job. MSG @@ -97,8 +97,8 @@ module ActionMailer def deliver #:nodoc: ActiveSupport::Deprecation.warn(<<-MSG.squish) - #deliver is deprecated and will be removed in Rails 5. Use - #deliver_now to deliver immediately or #deliver_later to + `#deliver` is deprecated and will be removed in Rails 5. Use + `#deliver_now` to deliver immediately or `#deliver_later` to deliver through Active Job. MSG diff --git a/actionpack/lib/action_dispatch/http/parameters.rb b/actionpack/lib/action_dispatch/http/parameters.rb index 20ae48d458..a5cd26a3c1 100644 --- a/actionpack/lib/action_dispatch/http/parameters.rb +++ b/actionpack/lib/action_dispatch/http/parameters.rb @@ -27,7 +27,7 @@ module ActionDispatch def symbolized_path_parameters ActiveSupport::Deprecation.warn( - "`symbolized_path_parameters` is deprecated. Please use `path_parameters`" + '`symbolized_path_parameters` is deprecated. Please use `path_parameters`.' ) path_parameters end diff --git a/actionpack/lib/action_dispatch/http/request.rb b/actionpack/lib/action_dispatch/http/request.rb index a8785ee6bf..2a7bb374a5 100644 --- a/actionpack/lib/action_dispatch/http/request.rb +++ b/actionpack/lib/action_dispatch/http/request.rb @@ -328,7 +328,7 @@ module ActionDispatch # Extracted into ActionDispatch::Request::Utils.deep_munge, but kept here for backwards compatibility. def deep_munge(hash) ActiveSupport::Deprecation.warn( - "This method has been extracted into ActionDispatch::Request::Utils.deep_munge. Please start using that instead." + 'This method has been extracted into `ActionDispatch::Request::Utils.deep_munge`. Please start using that instead.' ) Utils.deep_munge(hash) diff --git a/actionpack/lib/action_dispatch/http/response.rb b/actionpack/lib/action_dispatch/http/response.rb index 2918a98796..33de2f8b5f 100644 --- a/actionpack/lib/action_dispatch/http/response.rb +++ b/actionpack/lib/action_dispatch/http/response.rb @@ -290,9 +290,9 @@ module ActionDispatch # :nodoc: # Not sensible behavior. def to_ary ActiveSupport::Deprecation.warn(<<-MSG.squish) - 'ActionDispatch::Response#to_ary no longer performs implicit conversion - to an Array. Please use response.to_a instead, or a splat like `status, - headers, body = *response` + `ActionDispatch::Response#to_ary` no longer performs implicit conversion + to an array. Please use `response.to_a` instead, or a splat like `status, + headers, body = *response`. MSG to_a diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index a121fef663..ac03ecb2c8 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -4,6 +4,7 @@ require 'active_support/core_ext/hash/slice' require 'active_support/core_ext/enumerable' require 'active_support/core_ext/array/extract_options' require 'active_support/core_ext/module/remove_method' +require 'active_support/core_ext/string/filters' require 'active_support/inflector' require 'action_dispatch/routing/redirection' require 'action_dispatch/routing/endpoint' @@ -282,11 +283,19 @@ module ActionDispatch def split_to(to) case to when Symbol - ActiveSupport::Deprecation.warn "defining a route where `to` is a symbol is deprecated. Please change \"to: :#{to}\" to \"action: :#{to}\"" + ActiveSupport::Deprecation.warn(<<-MSG.squish) + Defining a route where `to` is a symbol is deprecated. + Please change `to: :#{to}` to `action: :#{to}`. + MSG + [nil, to.to_s] when /#/ then to.split('#') when String - ActiveSupport::Deprecation.warn "defining a route where `to` is a controller without an action is deprecated. Please change \"to: :#{to}\" to \"controller: :#{to}\"" + ActiveSupport::Deprecation.warn(<<-MSG.squish) + Defining a route where `to` is a controller without an action is deprecated. + Please change `to: :#{to}` to `controller: :#{to}`. + MSG + [to, nil] else [] diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb index 746742a85f..a641ea3ea9 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -103,7 +103,10 @@ module ActionDispatch end def helpers - ActiveSupport::Deprecation.warn("`named_routes.helpers` is deprecated, please use `route_defined?(route_name)` to see if a named route was defined.") + ActiveSupport::Deprecation.warn(<<-MSG.squish) + `named_routes.helpers` is deprecated, please use `route_defined?(route_name)` + to see if a named route was defined. + MSG @path_helpers + @url_helpers end diff --git a/actionpack/lib/action_dispatch/testing/assertions/tag.rb b/actionpack/lib/action_dispatch/testing/assertions/tag.rb index 5c2905d1ac..da98b1d6ce 100644 --- a/actionpack/lib/action_dispatch/testing/assertions/tag.rb +++ b/actionpack/lib/action_dispatch/testing/assertions/tag.rb @@ -1,3 +1,3 @@ require 'active_support/deprecation' -ActiveSupport::Deprecation.warn("ActionDispatch::Assertions::TagAssertions has been extracted to the rails-dom-testing gem.") +ActiveSupport::Deprecation.warn('`ActionDispatch::Assertions::TagAssertions` has been extracted to the rails-dom-testing gem.') diff --git a/actionview/lib/action_view/view_paths.rb b/actionview/lib/action_view/view_paths.rb index 80a41f2418..2e203a7590 100644 --- a/actionview/lib/action_view/view_paths.rb +++ b/actionview/lib/action_view/view_paths.rb @@ -38,7 +38,11 @@ module ActionView def handle_deprecated_parent_prefixes # TODO: remove in 4.3/5.0. return unless respond_to?(:parent_prefixes) - ActiveSupport::Deprecation.warn "Overriding ActionController::Base::parent_prefixes is deprecated, override .local_prefixes instead." + ActiveSupport::Deprecation.warn(<<-MSG.squish) + Overriding `ActionController::Base::parent_prefixes` is deprecated, + override `.local_prefixes` instead. + MSG + local_prefixes + parent_prefixes end end diff --git a/activemodel/lib/active_model/dirty.rb b/activemodel/lib/active_model/dirty.rb index ca04f48c1c..ae185694ca 100644 --- a/activemodel/lib/active_model/dirty.rb +++ b/activemodel/lib/active_model/dirty.rb @@ -1,5 +1,6 @@ require 'active_support/hash_with_indifferent_access' require 'active_support/core_ext/object/duplicable' +require 'active_support/core_ext/string/filters' module ActiveModel # == Active \Model \Dirty @@ -200,7 +201,11 @@ module ActiveModel end def reset_changes - ActiveSupport::Deprecation.warn "#reset_changes is deprecated and will be removed on Rails 5. Please use #clear_changes_information instead." + ActiveSupport::Deprecation.warn(<<-MSG.squish) + `#reset_changes` is deprecated and will be removed on Rails 5. + Please use `#clear_changes_information` instead. + MSG + clear_changes_information end @@ -224,7 +229,10 @@ module ActiveModel # Handle reset_*! for +method_missing+. def reset_attribute!(attr) - ActiveSupport::Deprecation.warn "#reset_#{attr}! is deprecated and will be removed on Rails 5. Please use #restore_#{attr}! instead." + ActiveSupport::Deprecation.warn(<<-MSG.squish) + `#reset_#{attr}!` is deprecated and will be removed on Rails 5. + Please use `#restore_#{attr}!` instead. + MSG restore_attribute!(attr) end diff --git a/activerecord/lib/active_record/associations/has_many_through_association.rb b/activerecord/lib/active_record/associations/has_many_through_association.rb index 1b84fdf5f2..04a69ba446 100644 --- a/activerecord/lib/active_record/associations/has_many_through_association.rb +++ b/activerecord/lib/active_record/associations/has_many_through_association.rb @@ -67,9 +67,9 @@ module ActiveRecord if has_cached_counter? && !through_reflection_updates_counter_cache? ActiveSupport::Deprecation.warn(<<-MSG.squish) Automatic updating of counter caches on through associations has been - deprecated, and will be removed in Rails 5.0. Instead, please set the - appropriate counter_cache options on the has_many and belongs_to for - your associations to #{through_reflection.name}. + deprecated, and will be removed in Rails 5. Instead, please set the + appropriate `counter_cache` options on the `has_many` and `belongs_to` + for your associations to #{through_reflection.name}. MSG update_counter_in_database(1) diff --git a/activerecord/lib/active_record/attribute_methods.rb b/activerecord/lib/active_record/attribute_methods.rb index 6ee4efe7f6..34ec397aee 100644 --- a/activerecord/lib/active_record/attribute_methods.rb +++ b/activerecord/lib/active_record/attribute_methods.rb @@ -207,8 +207,8 @@ module ActiveRecord column = columns_hash[name.to_s] if column.nil? ActiveSupport::Deprecation.warn(<<-MSG.squish) - `column_for_attribute` will return a null object for non-existent - columns in Rails 5.0. Use `has_attribute?` if you need to check for + `#column_for_attribute` will return a null object for non-existent + columns in Rails 5. Use `#has_attribute?` if you need to check for an attribute's existence. MSG end diff --git a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb index e197f7f2f9..46812b75bb 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb @@ -520,7 +520,7 @@ module ActiveRecord def connection_pools ActiveSupport::Deprecation.warn(<<-MSG.squish) - In the next release, this will return the same as #connection_pool_list. + In the next release, this will return the same as `#connection_pool_list`. (An array of pools, rather than a hash mapping specs to pools.) MSG diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb index 1aed8b0457..f8b6daea5a 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb @@ -61,10 +61,9 @@ module ActiveRecord return if options.key?(:null) ActiveSupport::Deprecation.warn(<<-MSG.squish) - `timestamp` was called without specifying an option for `null`. In Rails - 5.0, this behavior will change to `null: false`. You should manually - specify `null: true` to prevent the behavior of your existing migrations - from changing. + `#timestamp` was called without specifying an option for `null`. In Rails 5, + this behavior will change to `null: false`. You should manually specify + `null: true` to prevent the behavior of your existing migrations from changing. MSG end end diff --git a/activerecord/lib/active_record/connection_adapters/connection_specification.rb b/activerecord/lib/active_record/connection_adapters/connection_specification.rb index af405fc690..609ec7dabd 100644 --- a/activerecord/lib/active_record/connection_adapters/connection_specification.rb +++ b/activerecord/lib/active_record/connection_adapters/connection_specification.rb @@ -225,7 +225,7 @@ module ActiveRecord ActiveSupport::Deprecation.warn(<<-MSG.squish) Passing a string to ActiveRecord::Base.establish_connection for a configuration lookup is deprecated, please pass a symbol - (#{spec.to_sym.inspect}) instead + (#{spec.to_sym.inspect}) instead. MSG resolve_symbol_connection(spec) diff --git a/activerecord/lib/active_record/inheritance.rb b/activerecord/lib/active_record/inheritance.rb index 251d682a02..f58145ab05 100644 --- a/activerecord/lib/active_record/inheritance.rb +++ b/activerecord/lib/active_record/inheritance.rb @@ -80,12 +80,12 @@ module ActiveRecord end def symbolized_base_class - ActiveSupport::Deprecation.warn("ActiveRecord::Base.symbolized_base_class is deprecated and will be removed without replacement.") + ActiveSupport::Deprecation.warn('`ActiveRecord::Base.symbolized_base_class` is deprecated and will be removed without replacement.') @symbolized_base_class ||= base_class.to_s.to_sym end def symbolized_sti_name - ActiveSupport::Deprecation.warn("ActiveRecord::Base.symbolized_sti_name is deprecated and will be removed without replacement.") + ActiveSupport::Deprecation.warn('`ActiveRecord::Base.symbolized_sti_name` is deprecated and will be removed without replacement.') @symbolized_sti_name ||= sti_name.present? ? sti_name.to_sym : symbolized_base_class end diff --git a/activerecord/lib/active_record/type/boolean.rb b/activerecord/lib/active_record/type/boolean.rb index 612478e67d..978d16d524 100644 --- a/activerecord/lib/active_record/type/boolean.rb +++ b/activerecord/lib/active_record/type/boolean.rb @@ -14,9 +14,13 @@ module ActiveRecord true else if !ConnectionAdapters::Column::FALSE_VALUES.include?(value) - ActiveSupport::Deprecation.warn(<<-EOM) - You attempted to assign a value which is not explicitly true or false to a boolean column. Currently this value casts to false. This will change to match Ruby's semantics, and will cast to true in Rails 5.0. If you would like to maintain the current behavior, you should explicitly handle the values you would like cast to false. - EOM + ActiveSupport::Deprecation.warn(<<-MSG.squish) + You attempted to assign a value which is not explicitly `true` or `false` + to a boolean column. Currently this value casts to `false`. This will + change to match Ruby's semantics, and will cast to `true` in Rails 5. + If you would like to maintain the current behavior, you should + explicitly handle the values you would like cast to `false`. + MSG end false end diff --git a/activesupport/lib/active_support/core_ext/kernel/reporting.rb b/activesupport/lib/active_support/core_ext/kernel/reporting.rb index 80c531b694..f5179552bb 100644 --- a/activesupport/lib/active_support/core_ext/kernel/reporting.rb +++ b/activesupport/lib/active_support/core_ext/kernel/reporting.rb @@ -32,7 +32,7 @@ module Kernel # For compatibility def silence_stderr #:nodoc: ActiveSupport::Deprecation.warn( - "#silence_stderr is deprecated and will be removed in the next release" + "`#silence_stderr` is deprecated and will be removed in the next release." ) #not thread-safe silence_stream(STDERR) { yield } end @@ -87,7 +87,7 @@ module Kernel # stream # => "error\n" def capture(stream) ActiveSupport::Deprecation.warn( - "#capture(stream) is deprecated and will be removed in the next release" + "`#capture(stream)` is deprecated and will be removed in the next release." ) #not thread-safe stream = stream.to_s captured_stream = Tempfile.new(stream) @@ -113,7 +113,7 @@ module Kernel # This method is not thread-safe. def quietly ActiveSupport::Deprecation.warn( - "#quietly is deprecated and will be removed in the next release" + "`#quietly` is deprecated and will be removed in the next release." ) #not thread-safe silence_stream(STDOUT) do silence_stream(STDERR) do diff --git a/activesupport/lib/active_support/json/encoding.rb b/activesupport/lib/active_support/json/encoding.rb index a14ed7ee94..c0ac5af153 100644 --- a/activesupport/lib/active_support/json/encoding.rb +++ b/activesupport/lib/active_support/json/encoding.rb @@ -131,7 +131,7 @@ module ActiveSupport "The JSON encoder in Rails 4.1 no longer supports encoding BigDecimals as JSON numbers. Instead, " \ "the new encoder will always encode them as strings.\n\n" \ "You are seeing this error because you are trying to check the value of the related configuration, " \ - "'active_support.encode_big_decimal_as_string'. If your application depends on this option, you should " \ + "`active_support.encode_big_decimal_as_string`. If your application depends on this option, you should " \ "add the 'activesupport-json_encoder' gem to your Gemfile. For now, this option will always be true. " \ "In the future, it will be removed from Rails, so you should stop checking its value." diff --git a/activesupport/lib/active_support/test_case.rb b/activesupport/lib/active_support/test_case.rb index 4c3e77b7fd..a4ba5989b1 100644 --- a/activesupport/lib/active_support/test_case.rb +++ b/activesupport/lib/active_support/test_case.rb @@ -25,7 +25,7 @@ module ActiveSupport if test_order.nil? ActiveSupport::Deprecation.warn "You did not specify a value for the " \ - "configuration option 'active_support.test_order'. In Rails 5.0, " \ + "configuration option `active_support.test_order`. In Rails 5, " \ "the default value of this option will change from `:sorted` to " \ "`:random`.\n" \ "To disable this warning and keep the current behavior, you can add " \ diff --git a/railties/lib/rails/rack/log_tailer.rb b/railties/lib/rails/rack/log_tailer.rb index bc26421a9e..46517713c9 100644 --- a/railties/lib/rails/rack/log_tailer.rb +++ b/railties/lib/rails/rack/log_tailer.rb @@ -4,7 +4,7 @@ module Rails module Rack class LogTailer def initialize(app, log = nil) - ActiveSupport::Deprecation.warn "LogTailer is deprecated and will be removed on Rails 5" + ActiveSupport::Deprecation.warn('LogTailer is deprecated and will be removed on Rails 5.') @app = app -- cgit v1.2.3 From cfc924d3186d3ae74dbbebb8be3e97fa30210468 Mon Sep 17 00:00:00 2001 From: Tony Miller Date: Tue, 14 Oct 2014 16:58:45 +0900 Subject: :nodoc: for abstract_mysql_adapter --- .../lib/active_record/connection_adapters/abstract_mysql_adapter.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb index e4cfe843a8..d1baeac6ac 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb @@ -485,7 +485,7 @@ module ActiveRecord end end - def change_column_default(table_name, column_name, default) + def change_column_default(table_name, column_name, default) #:nodoc: column = column_for(table_name, column_name) change_column table_name, column_name, column.sql_type, :default => default end -- cgit v1.2.3 From bf993fac57bb1cb69ec46d2bbc2f2752bcd844ae Mon Sep 17 00:00:00 2001 From: Luca Simone Date: Wed, 29 Oct 2014 07:56:01 +0100 Subject: Added 'tzinfo-data' if we are using jruby --- railties/lib/rails/generators/rails/app/templates/Gemfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/railties/lib/rails/generators/rails/app/templates/Gemfile b/railties/lib/rails/generators/rails/app/templates/Gemfile index 827039f144..5961f7515c 100644 --- a/railties/lib/rails/generators/rails/app/templates/Gemfile +++ b/railties/lib/rails/generators/rails/app/templates/Gemfile @@ -40,7 +40,7 @@ group :development, :test do <% end -%> end -<% if RUBY_PLATFORM.match(/bccwin|cygwin|emx|mingw|mswin|wince/) -%> +<% if RUBY_PLATFORM.match(/bccwin|cygwin|emx|mingw|mswin|wince|java/) -%> # Windows does not include zoneinfo files, so bundle the tzinfo-data gem -gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw] +gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] <% end -%> -- cgit v1.2.3 From 82ce157844f38ac144e2185786f8875df07a7a37 Mon Sep 17 00:00:00 2001 From: Yves Senn Date: Wed, 29 Oct 2014 09:37:01 +0100 Subject: fix MySQL enum type lookup with values matching another type. Closes #17402. The MySQLAdapter type map used the lowest priority for enum types. This was the result of a recent refactoring and lead to some broken lookups for enums with values that match other types. Like `8bit`. This patch restores the priority to what we had before the refactoring. /cc @sgrif --- activerecord/CHANGELOG.md | 7 +++++++ .../connection_adapters/abstract_mysql_adapter.rb | 12 ++++++------ .../test/cases/connection_adapters/mysql_type_lookup_test.rb | 4 ++++ 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index 79dc390f0a..ad4ee0f489 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -1,3 +1,10 @@ +* MySQL enum type lookups, with values matching another type, no longer result + in an endless loop. + + Fixes #17402. + + *Yves Senn* + * Raise `ArgumentError` when the body of a scope is not callable. *Mauro George* diff --git a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb index c5dd93ee89..9077a9cfe3 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb @@ -656,12 +656,6 @@ module ActiveRecord def initialize_type_map(m) # :nodoc: super - m.register_type(%r(enum)i) do |sql_type| - limit = sql_type[/^enum\((.+)\)/i, 1] - .split(',').map{|enum| enum.strip.length - 2}.max - Type::String.new(limit: limit) - end - m.register_type %r(tinytext)i, Type::Text.new(limit: 2**8 - 1) m.register_type %r(tinyblob)i, Type::Binary.new(limit: 2**8 - 1) m.register_type %r(text)i, Type::Text.new(limit: 2**16 - 1) @@ -682,6 +676,12 @@ module ActiveRecord m.alias_type %r(set)i, 'varchar' m.alias_type %r(year)i, 'integer' m.alias_type %r(bit)i, 'binary' + + m.register_type(%r(enum)i) do |sql_type| + limit = sql_type[/^enum\((.+)\)/i, 1] + .split(',').map{|enum| enum.strip.length - 2}.max + Type::String.new(limit: limit) + end end # MySQL is too stupid to create a temporary table for use subquery, so we have diff --git a/activerecord/test/cases/connection_adapters/mysql_type_lookup_test.rb b/activerecord/test/cases/connection_adapters/mysql_type_lookup_test.rb index d4d67487db..80244d1439 100644 --- a/activerecord/test/cases/connection_adapters/mysql_type_lookup_test.rb +++ b/activerecord/test/cases/connection_adapters/mysql_type_lookup_test.rb @@ -22,6 +22,10 @@ module ActiveRecord assert_lookup_type :string, "SET('one', 'two', 'three')" end + def test_enum_type_with_value_matching_other_type + assert_lookup_type :string, "ENUM('unicode', '8bit', 'none')" + end + def test_binary_types assert_lookup_type :binary, 'bit' assert_lookup_type :binary, 'BIT' -- cgit v1.2.3 From be318260a3983f6eabd4f81d42ae4116d5aa7a62 Mon Sep 17 00:00:00 2001 From: Robin Tweedie Date: Wed, 29 Oct 2014 13:10:01 +0000 Subject: better example for tokenizer lambda [ci skip] Splitting on whitespace makes more sense in the context of counting words in an essay. --- guides/source/active_record_validations.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guides/source/active_record_validations.md b/guides/source/active_record_validations.md index 1c1b863fe9..6f45ca698d 100644 --- a/guides/source/active_record_validations.md +++ b/guides/source/active_record_validations.md @@ -427,7 +427,7 @@ class Essay < ActiveRecord::Base validates :content, length: { minimum: 300, maximum: 400, - tokenizer: lambda { |str| str.scan(/\w+/) }, + tokenizer: lambda { |str| str.split(/\s+/) }, too_short: "must have at least %{count} words", too_long: "must have at most %{count} words" } -- cgit v1.2.3 From c3857355b81e458f4f8da59cb833dc19c467a412 Mon Sep 17 00:00:00 2001 From: Edwin Wills Date: Wed, 29 Oct 2014 18:24:05 +0000 Subject: On larger screens the email preview iframe is being limited to a height of 800 pixels, and the full available screen size is not being used. --- railties/lib/rails/templates/rails/mailers/email.html.erb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/railties/lib/rails/templates/rails/mailers/email.html.erb b/railties/lib/rails/templates/rails/mailers/email.html.erb index 1dc1d70f8d..0b08a01896 100644 --- a/railties/lib/rails/templates/rails/mailers/email.html.erb +++ b/railties/lib/rails/templates/rails/mailers/email.html.erb @@ -2,6 +2,10 @@ -- cgit v1.2.3 From c02a7e4f8239006ad01d1ca5d28f47cf9563920e Mon Sep 17 00:00:00 2001 From: Pablo Herrero Date: Sat, 18 Oct 2014 03:47:05 -0300 Subject: Do gsub with a regexp instead of a string --- activesupport/lib/active_support/inflector/methods.rb | 2 +- .../lib/active_support/number_helper/number_to_currency_converter.rb | 2 +- .../lib/active_support/number_helper/number_to_percentage_converter.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/activesupport/lib/active_support/inflector/methods.rb b/activesupport/lib/active_support/inflector/methods.rb index 0e3c8517d1..637736c5df 100644 --- a/activesupport/lib/active_support/inflector/methods.rb +++ b/activesupport/lib/active_support/inflector/methods.rb @@ -90,7 +90,7 @@ module ActiveSupport # 'SSLError'.underscore.camelize # => "SslError" def underscore(camel_cased_word) return camel_cased_word unless camel_cased_word =~ /[A-Z-]|::/ - word = camel_cased_word.to_s.gsub('::', '/') + word = camel_cased_word.to_s.gsub(/::/, '/') word.gsub!(/(?:(?<=([A-Za-z\d]))|\b)(#{inflections.acronym_regex})(?=\b|[^a-z])/) { "#{$1 && '_'}#{$2.downcase}" } word.gsub!(/([A-Z\d]+)([A-Z][a-z])/,'\1_\2') word.gsub!(/([a-z\d])([A-Z])/,'\1_\2') diff --git a/activesupport/lib/active_support/number_helper/number_to_currency_converter.rb b/activesupport/lib/active_support/number_helper/number_to_currency_converter.rb index 9ae27a896a..fb5adb574a 100644 --- a/activesupport/lib/active_support/number_helper/number_to_currency_converter.rb +++ b/activesupport/lib/active_support/number_helper/number_to_currency_converter.rb @@ -13,7 +13,7 @@ module ActiveSupport end rounded_number = NumberToRoundedConverter.convert(number, options) - format.gsub('%n', rounded_number).gsub('%u', options[:unit]) + format.gsub(/%n/, rounded_number).gsub(/%u/, options[:unit]) end private diff --git a/activesupport/lib/active_support/number_helper/number_to_percentage_converter.rb b/activesupport/lib/active_support/number_helper/number_to_percentage_converter.rb index eafe2844f7..1af294a03e 100644 --- a/activesupport/lib/active_support/number_helper/number_to_percentage_converter.rb +++ b/activesupport/lib/active_support/number_helper/number_to_percentage_converter.rb @@ -5,7 +5,7 @@ module ActiveSupport def convert rounded_number = NumberToRoundedConverter.convert(number, options) - options[:format].gsub('%n', rounded_number) + options[:format].gsub(/%n/, rounded_number) end end end -- cgit v1.2.3 From 8185fc734a50867de5349875e4b6548ab217819e Mon Sep 17 00:00:00 2001 From: Hannah Briggs Date: Wed, 29 Oct 2014 11:45:18 -0700 Subject: [ci skip] Fixes typos in section 2.7 "Rails Html Sanitizer", adds content to section 2.8 "Rails DOM Testing" --- guides/source/upgrading_ruby_on_rails.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/guides/source/upgrading_ruby_on_rails.md b/guides/source/upgrading_ruby_on_rails.md index 8a1d7af923..f07dcd04f7 100644 --- a/guides/source/upgrading_ruby_on_rails.md +++ b/guides/source/upgrading_ruby_on_rails.md @@ -177,7 +177,7 @@ after_bundle do end ``` -### Rails Html Sanitizer +### Rails HTML Sanitizer There's a new choice for sanitizing HTML fragments in your applications. The venerable html-scanner approach is now officially being deprecated in favor of @@ -200,15 +200,15 @@ Read the [gem's readme](https://github.com/rails/rails-html-sanitizer) for more The documentation for `PermitScrubber` and `TargetScrubber` explains how you can gain complete control over when and how elements should be stripped. -If your application needs to use the old behaviour, include `rails-deprecated_sanitizer` in your Gemfile: +If your application needs to use the old sanitizer implementation, include `rails-deprecated_sanitizer` in your Gemfile: ```ruby gem 'rails-deprecated_sanitizer' ``` ### Rails DOM Testing +The [`TagAssertions` module](http://api.rubyonrails.org/classes/ActionDispatch/Assertions/TagAssertions.html) (containing methods such as `assert_tag`), [has been deprecated](https://github.com/rails/rails/blob/6061472b8c310158a2a2e8e9a6b81a1aef6b60fe/actionpack/lib/action_dispatch/testing/assertions/dom.rb) in favor of the `assert_select` methods from the `SelectorAssertions` module, which has been extracted into the [rails-dom-testing gem](https://github.com/rails/rails-dom-testing). -TODO: Mention https://github.com/rails/rails/commit/4e97d7585a2f4788b9eed98c6cdaf4bb6f2cf5ce Upgrading from Rails 4.0 to Rails 4.1 ------------------------------------- -- cgit v1.2.3 From 79e5c0de6d87a7957889a0ff1fe9063337e627a2 Mon Sep 17 00:00:00 2001 From: Chris Moylan Date: Wed, 29 Oct 2014 16:36:16 -0500 Subject: correct GlobalID mixin name in the guides --- guides/source/active_job_basics.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guides/source/active_job_basics.md b/guides/source/active_job_basics.md index 0f63a1c7e7..875919e237 100644 --- a/guides/source/active_job_basics.md +++ b/guides/source/active_job_basics.md @@ -286,7 +286,7 @@ class TrashableCleanupJob end ``` -This works with any class that mixes in `ActiveModel::GlobalIdentification`, which +This works with any class that mixes in `GlobalID::Identification`, which by default has been mixed into Active Model classes. -- cgit v1.2.3 From 352b031aa1acc42fdaa8b16d2c83affd62e6d963 Mon Sep 17 00:00:00 2001 From: claudiob Date: Wed, 29 Oct 2014 16:02:04 -0700 Subject: Remove redundant `to_s` in interpolation --- .../lib/active_record/connection_adapters/abstract_mysql_adapter.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb index 0bf17d3351..7f04e35042 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb @@ -836,9 +836,9 @@ module ActiveRecord # Gather up all of the SET variables... variable_assignments = variables.map do |k, v| if v == ':default' || v == :default - "@@SESSION.#{k.to_s} = DEFAULT" # Sets the value to the global or compile default + "@@SESSION.#{k} = DEFAULT" # Sets the value to the global or compile default elsif !v.nil? - "@@SESSION.#{k.to_s} = #{quote(v)}" + "@@SESSION.#{k} = #{quote(v)}" end # or else nil; compact to clear nils out end.compact.join(', ') -- cgit v1.2.3 From 724db9eb6236eb21051d85438b62e452765ee291 Mon Sep 17 00:00:00 2001 From: Pablo Herrero Date: Wed, 29 Oct 2014 20:51:32 -0300 Subject: Fix typo at form_helper docs [ci skip] --- actionview/lib/action_view/helpers/form_helper.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/actionview/lib/action_view/helpers/form_helper.rb b/actionview/lib/action_view/helpers/form_helper.rb index 038f9e384b..03f80ff360 100644 --- a/actionview/lib/action_view/helpers/form_helper.rb +++ b/actionview/lib/action_view/helpers/form_helper.rb @@ -1231,8 +1231,8 @@ module ActionView # end # # The above code creates a new method +div_radio_button+ which wraps a div - # around the a new radio button. Note that when options are passed in, you - # must called +objectify_options+ in order for the model object to get + # around the new radio button. Note that when options are passed in, you + # must call +objectify_options+ in order for the model object to get # correctly passed to the method. If +objectify_options+ is not called, # then the newly created helper will not be linked back to the model. # -- cgit v1.2.3 From 6dc178711de036ae9a441e83978b7ed740be2f63 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 29 Oct 2014 18:11:51 -0700 Subject: add bigserial pk support --- .../connection_adapters/postgresql_adapter.rb | 1 + activerecord/lib/active_record/schema_dumper.rb | 2 ++ .../test/cases/adapters/postgresql/uuid_test.rb | 20 ++++++++++++++++++++ 3 files changed, 23 insertions(+) diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb index 3294238fa0..bf2941b777 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb @@ -78,6 +78,7 @@ module ActiveRecord NATIVE_DATABASE_TYPES = { primary_key: "serial primary key", + bigserial: "bigserial", string: { name: "character varying" }, text: { name: "text" }, integer: { name: "integer" }, diff --git a/activerecord/lib/active_record/schema_dumper.rb b/activerecord/lib/active_record/schema_dumper.rb index 82c5ca291c..261fb9d992 100644 --- a/activerecord/lib/active_record/schema_dumper.rb +++ b/activerecord/lib/active_record/schema_dumper.rb @@ -118,6 +118,8 @@ HEADER if pkcol if pk != 'id' tbl.print %Q(, primary_key: "#{pk}") + elsif pkcol.sql_type == 'bigint' + tbl.print ", id: :bigserial" elsif pkcol.sql_type == 'uuid' tbl.print ", id: :uuid" tbl.print %Q(, default: "#{pkcol.default_function}") if pkcol.default_function diff --git a/activerecord/test/cases/adapters/postgresql/uuid_test.rb b/activerecord/test/cases/adapters/postgresql/uuid_test.rb index ae5b409f99..376dc2490e 100644 --- a/activerecord/test/cases/adapters/postgresql/uuid_test.rb +++ b/activerecord/test/cases/adapters/postgresql/uuid_test.rb @@ -110,6 +110,26 @@ class PostgresqlUUIDTest < ActiveRecord::TestCase end end +class PostgresqlLargeKeysTest < ActiveRecord::TestCase + include PostgresqlUUIDHelper + def setup + connection.create_table('big_serials', id: :bigserial) do |t| + t.string 'name' + end + end + + def test_omg + schema = StringIO.new + ActiveRecord::SchemaDumper.dump(connection, schema) + assert_match "create_table \"big_serials\", id: :bigserial, force: true", + schema.string + end + + def teardown + drop_table "big_serials" + end +end + class PostgresqlUUIDGenerationTest < ActiveRecord::TestCase include PostgresqlUUIDHelper -- cgit v1.2.3 From b6a025551910621ef8e86aba88a09161ed0a6fd3 Mon Sep 17 00:00:00 2001 From: Sean Griffin Date: Thu, 30 Oct 2014 09:45:29 -0600 Subject: Use `#between`, rather than `#in` for passing Ranges to Arel Passing ranges to `#in` has been deprecated in Arel. --- Gemfile | 1 + activerecord/lib/active_record/relation/predicate_builder.rb | 2 +- .../lib/active_record/relation/predicate_builder/array_handler.rb | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index 1bc25a2842..6f4e91100b 100644 --- a/Gemfile +++ b/Gemfile @@ -14,6 +14,7 @@ gem 'rack-cache', '~> 1.2' gem 'jquery-rails', '~> 4.0.0.beta2' gem 'coffee-rails', '~> 4.1.0' gem 'turbolinks' +gem 'arel', github: 'rails/arel', branch: 'master' # require: false so bcrypt is loaded only when has_secure_password is used. # This is to avoid ActiveModel (and by extension the entire framework) diff --git a/activerecord/lib/active_record/relation/predicate_builder.rb b/activerecord/lib/active_record/relation/predicate_builder.rb index 3df0df40ee..e4b6b49087 100644 --- a/activerecord/lib/active_record/relation/predicate_builder.rb +++ b/activerecord/lib/active_record/relation/predicate_builder.rb @@ -109,7 +109,7 @@ module ActiveRecord # FIXME: I think we need to deprecate this behavior register_handler(Class, ->(attribute, value) { attribute.eq(value.name) }) register_handler(Base, ->(attribute, value) { attribute.eq(value.id) }) - register_handler(Range, ->(attribute, value) { attribute.in(value) }) + register_handler(Range, ->(attribute, value) { attribute.between(value) }) register_handler(Relation, RelationHandler.new) register_handler(Array, ArrayHandler.new) diff --git a/activerecord/lib/active_record/relation/predicate_builder/array_handler.rb b/activerecord/lib/active_record/relation/predicate_builder/array_handler.rb index b6a9b4f63a..b8f3285c3e 100644 --- a/activerecord/lib/active_record/relation/predicate_builder/array_handler.rb +++ b/activerecord/lib/active_record/relation/predicate_builder/array_handler.rb @@ -32,7 +32,7 @@ module ActiveRecord values_predicate = values_predicate.or(attribute.eq(nil)) end - array_predicates = ranges.map { |range| attribute.in(range) } + array_predicates = ranges.map { |range| attribute.between(range) } array_predicates.unshift(values_predicate) array_predicates.inject { |composite, predicate| composite.or(predicate) } end -- cgit v1.2.3 From 64b09823e6a6b1e19218d3fd815bb65cd2e44f1e Mon Sep 17 00:00:00 2001 From: claudiob Date: Wed, 29 Oct 2014 18:18:48 -0700 Subject: Remove redundant `to_s` in interpolation --- actionpack/lib/action_dispatch/routing/inspector.rb | 2 +- actionpack/test/controller/mime/respond_to_test.rb | 4 ++-- .../lib/active_record/connection_adapters/abstract/quoting.rb | 2 +- .../lib/active_record/connection_adapters/abstract/schema_dumper.rb | 2 +- .../lib/active_record/connection_adapters/postgresql/oid/cidr.rb | 6 +++--- .../lib/active_record/connection_adapters/postgresql/quoting.rb | 2 +- .../lib/active_record/connection_adapters/postgresql_adapter.rb | 4 ++-- activerecord/test/cases/helper.rb | 6 +++--- activesupport/test/json/encoding_test.rb | 2 +- 9 files changed, 15 insertions(+), 15 deletions(-) diff --git a/actionpack/lib/action_dispatch/routing/inspector.rb b/actionpack/lib/action_dispatch/routing/inspector.rb index ea3b2f419d..cfe2237512 100644 --- a/actionpack/lib/action_dispatch/routing/inspector.rb +++ b/actionpack/lib/action_dispatch/routing/inspector.rb @@ -48,7 +48,7 @@ module ActionDispatch def reqs @reqs ||= begin reqs = endpoint - reqs += " #{constraints.to_s}" unless constraints.empty? + reqs += " #{constraints}" unless constraints.empty? reqs end end diff --git a/actionpack/test/controller/mime/respond_to_test.rb b/actionpack/test/controller/mime/respond_to_test.rb index 1bc7ad3015..66d2fd7716 100644 --- a/actionpack/test/controller/mime/respond_to_test.rb +++ b/actionpack/test/controller/mime/respond_to_test.rb @@ -579,10 +579,10 @@ class RespondToControllerTest < ActionController::TestCase end get :using_defaults - assert_equal "using_defaults - #{[:html].to_s}", @response.body + assert_equal "using_defaults - #{[:html]}", @response.body get :using_defaults, :format => "xml" - assert_equal "using_defaults - #{[:xml].to_s}", @response.body + assert_equal "using_defaults - #{[:xml]}", @response.body end def test_format_with_custom_response_type diff --git a/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb b/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb index eb88845913..679878d860 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb @@ -108,7 +108,7 @@ module ActiveRecord when Numeric, ActiveSupport::Duration then value.to_s when Date, Time then "'#{quoted_date(value)}'" when Symbol then "'#{quote_string(value.to_s)}'" - when Class then "'#{value.to_s}'" + when Class then "'#{value}'" else "'#{quote_string(YAML.dump(value))}'" end diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_dumper.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_dumper.rb index b05a4f8440..6eab11b88b 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/schema_dumper.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_dumper.rb @@ -8,7 +8,7 @@ module ActiveRecord module ColumnDumper def column_spec(column, types) spec = prepare_column_options(column, types) - (spec.keys - [:name, :type]).each{ |k| spec[k].insert(0, "#{k.to_s}: ")} + (spec.keys - [:name, :type]).each{ |k| spec[k].insert(0, "#{k}: ")} spec end diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/oid/cidr.rb b/activerecord/lib/active_record/connection_adapters/postgresql/oid/cidr.rb index a53b4ee8e2..222f10fa8f 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/oid/cidr.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/oid/cidr.rb @@ -12,15 +12,15 @@ module ActiveRecord # If the subnet mask is equal to /32, don't output it if subnet_mask == (2**32 - 1) - "\"#{value.to_s}\"" + "\"#{value}\"" else - "\"#{value.to_s}/#{subnet_mask.to_s(2).count('1')}\"" + "\"#{value}/#{subnet_mask.to_s(2).count('1')}\"" end end def type_cast_for_database(value) if IPAddr === value - "#{value.to_s}/#{value.instance_variable_get(:@mask_addr).to_s(2).count('1')}" + "#{value}/#{value.instance_variable_get(:@mask_addr).to_s(2).count('1')}" else value end diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb b/activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb index cf5c8d288e..f95f45c689 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb @@ -21,7 +21,7 @@ module ActiveRecord case value when Float if value.infinite? || value.nan? - "'#{value.to_s}'" + "'#{value}'" else super end diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb index bf2941b777..8e209e1051 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb @@ -679,9 +679,9 @@ module ActiveRecord variables.map do |k, v| if v == ':default' || v == :default # Sets the value to the global or compile default - execute("SET SESSION #{k.to_s} TO DEFAULT", 'SCHEMA') + execute("SET SESSION #{k} TO DEFAULT", 'SCHEMA') elsif !v.nil? - execute("SET SESSION #{k.to_s} TO #{quote(v)}", 'SCHEMA') + execute("SET SESSION #{k} TO #{quote(v)}", 'SCHEMA') end end end diff --git a/activerecord/test/cases/helper.rb b/activerecord/test/cases/helper.rb index f5be8a044b..80ac57ec7c 100644 --- a/activerecord/test/cases/helper.rb +++ b/activerecord/test/cases/helper.rb @@ -95,7 +95,7 @@ EXPECTED_TIME_ZONE_AWARE_ATTRIBUTES = false def verify_default_timezone_config if Time.zone != EXPECTED_ZONE $stderr.puts <<-MSG -\n#{self.to_s} +\n#{self} Global state `Time.zone` was leaked. Expected: #{EXPECTED_ZONE} Got: #{Time.zone} @@ -103,7 +103,7 @@ def verify_default_timezone_config end if ActiveRecord::Base.default_timezone != EXPECTED_DEFAULT_TIMEZONE $stderr.puts <<-MSG -\n#{self.to_s} +\n#{self} Global state `ActiveRecord::Base.default_timezone` was leaked. Expected: #{EXPECTED_DEFAULT_TIMEZONE} Got: #{ActiveRecord::Base.default_timezone} @@ -111,7 +111,7 @@ def verify_default_timezone_config end if ActiveRecord::Base.time_zone_aware_attributes != EXPECTED_TIME_ZONE_AWARE_ATTRIBUTES $stderr.puts <<-MSG -\n#{self.to_s} +\n#{self} Global state `ActiveRecord::Base.time_zone_aware_attributes` was leaked. Expected: #{EXPECTED_TIME_ZONE_AWARE_ATTRIBUTES} Got: #{ActiveRecord::Base.time_zone_aware_attributes} diff --git a/activesupport/test/json/encoding_test.rb b/activesupport/test/json/encoding_test.rb index ad358ad21d..7e976aa772 100644 --- a/activesupport/test/json/encoding_test.rb +++ b/activesupport/test/json/encoding_test.rb @@ -68,7 +68,7 @@ class TestJSONEncoding < ActiveSupport::TestCase [ 1.0/0.0, %(null) ], [ -1.0/0.0, %(null) ], [ BigDecimal('0.0')/BigDecimal('0.0'), %(null) ], - [ BigDecimal('2.5'), %("#{BigDecimal('2.5').to_s}") ]] + [ BigDecimal('2.5'), %("#{BigDecimal('2.5')}") ]] StringTests = [[ 'this is the ', %("this is the \\u003cstring\\u003e")], [ 'a "string" with quotes & an ampersand', %("a \\"string\\" with quotes \\u0026 an ampersand") ], -- cgit v1.2.3 From 568c057e80b5a5c33baca6b27ce6ebf356b42777 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Strza=C5=82kowski?= Date: Thu, 30 Oct 2014 16:55:39 +0100 Subject: Add :db_runtime to table [ci skip] It was missing from table, but is present in sample hash below --- guides/source/active_support_instrumentation.md | 1 + 1 file changed, 1 insertion(+) diff --git a/guides/source/active_support_instrumentation.md b/guides/source/active_support_instrumentation.md index 7033947468..3d9c45a3de 100644 --- a/guides/source/active_support_instrumentation.md +++ b/guides/source/active_support_instrumentation.md @@ -136,6 +136,7 @@ Action Controller | `:method` | HTTP request verb | | `:path` | Request path | | `:view_runtime` | Amount spent in view in ms | +| `:db_runtime` | Amount spent executing database queries in ms | ```ruby { -- cgit v1.2.3 From d20f7b043a537b57ff4a7911f65de2fb7b7aea7d Mon Sep 17 00:00:00 2001 From: Zachary Scott Date: Thu, 30 Oct 2014 09:01:18 -0700 Subject: Add status code to AS::Instrumentation table, like #17441 [ci skip] --- guides/source/active_support_instrumentation.md | 1 + 1 file changed, 1 insertion(+) diff --git a/guides/source/active_support_instrumentation.md b/guides/source/active_support_instrumentation.md index 3d9c45a3de..83f3645b31 100644 --- a/guides/source/active_support_instrumentation.md +++ b/guides/source/active_support_instrumentation.md @@ -135,6 +135,7 @@ Action Controller | `:format` | html/js/json/xml etc | | `:method` | HTTP request verb | | `:path` | Request path | +| `:status` | HTTP status code | | `:view_runtime` | Amount spent in view in ms | | `:db_runtime` | Amount spent executing database queries in ms | -- cgit v1.2.3 From c747d4c48c2213da7946090450c250dfca6870f8 Mon Sep 17 00:00:00 2001 From: Godfrey Chan Date: Thu, 30 Oct 2014 14:07:24 -0700 Subject: Use released arel --- Gemfile | 2 +- activerecord/activerecord.gemspec | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index 6f4e91100b..f6fd0f3ac0 100644 --- a/Gemfile +++ b/Gemfile @@ -14,7 +14,7 @@ gem 'rack-cache', '~> 1.2' gem 'jquery-rails', '~> 4.0.0.beta2' gem 'coffee-rails', '~> 4.1.0' gem 'turbolinks' -gem 'arel', github: 'rails/arel', branch: 'master' +gem 'arel', '~> 6.0.0.beta2' # require: false so bcrypt is loaded only when has_secure_password is used. # This is to avoid ActiveModel (and by extension the entire framework) diff --git a/activerecord/activerecord.gemspec b/activerecord/activerecord.gemspec index 6231851be5..bc10e96244 100644 --- a/activerecord/activerecord.gemspec +++ b/activerecord/activerecord.gemspec @@ -24,5 +24,5 @@ Gem::Specification.new do |s| s.add_dependency 'activesupport', version s.add_dependency 'activemodel', version - s.add_dependency 'arel', '>= 6.0.0.beta1', '< 6.1' + s.add_dependency 'arel', '>= 6.0.0.beta2', '< 6.1' end -- cgit v1.2.3 From 4daebedcc41e35079c47d5f130f5c7ad12db8bbb Mon Sep 17 00:00:00 2001 From: Godfrey Chan Date: Thu, 30 Oct 2014 14:09:21 -0700 Subject: Prepare for 4.2.0.beta4 release --- RAILS_VERSION | 2 +- actionmailer/lib/action_mailer/gem_version.rb | 2 +- actionpack/lib/action_pack/gem_version.rb | 2 +- actionview/lib/action_view/gem_version.rb | 2 +- activejob/lib/active_job/gem_version.rb | 2 +- activemodel/lib/active_model/gem_version.rb | 2 +- activerecord/lib/active_record/gem_version.rb | 2 +- activesupport/lib/active_support/gem_version.rb | 2 +- railties/lib/rails/gem_version.rb | 2 +- version.rb | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/RAILS_VERSION b/RAILS_VERSION index a771777d25..b86dc8c0c6 100644 --- a/RAILS_VERSION +++ b/RAILS_VERSION @@ -1 +1 @@ -4.2.0.beta2 +4.2.0.beta4 diff --git a/actionmailer/lib/action_mailer/gem_version.rb b/actionmailer/lib/action_mailer/gem_version.rb index 0c5c55be84..e568b8f6f2 100644 --- a/actionmailer/lib/action_mailer/gem_version.rb +++ b/actionmailer/lib/action_mailer/gem_version.rb @@ -8,7 +8,7 @@ module ActionMailer MAJOR = 4 MINOR = 2 TINY = 0 - PRE = "beta2" + PRE = "beta4" STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".") end diff --git a/actionpack/lib/action_pack/gem_version.rb b/actionpack/lib/action_pack/gem_version.rb index 6834845d4f..9b3ea30f69 100644 --- a/actionpack/lib/action_pack/gem_version.rb +++ b/actionpack/lib/action_pack/gem_version.rb @@ -8,7 +8,7 @@ module ActionPack MAJOR = 4 MINOR = 2 TINY = 0 - PRE = "beta2" + PRE = "beta4" STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".") end diff --git a/actionview/lib/action_view/gem_version.rb b/actionview/lib/action_view/gem_version.rb index 076b8ec30b..752eafee3c 100644 --- a/actionview/lib/action_view/gem_version.rb +++ b/actionview/lib/action_view/gem_version.rb @@ -8,7 +8,7 @@ module ActionView MAJOR = 4 MINOR = 2 TINY = 0 - PRE = "beta2" + PRE = "beta4" STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".") end diff --git a/activejob/lib/active_job/gem_version.rb b/activejob/lib/active_job/gem_version.rb index f80e6563b8..ac364f77d1 100644 --- a/activejob/lib/active_job/gem_version.rb +++ b/activejob/lib/active_job/gem_version.rb @@ -8,7 +8,7 @@ module ActiveJob MAJOR = 4 MINOR = 2 TINY = 0 - PRE = "beta2" + PRE = "beta4" STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".") end diff --git a/activemodel/lib/active_model/gem_version.rb b/activemodel/lib/active_model/gem_version.rb index e37edcf581..932fe3e5a9 100644 --- a/activemodel/lib/active_model/gem_version.rb +++ b/activemodel/lib/active_model/gem_version.rb @@ -8,7 +8,7 @@ module ActiveModel MAJOR = 4 MINOR = 2 TINY = 0 - PRE = "beta2" + PRE = "beta4" STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".") end diff --git a/activerecord/lib/active_record/gem_version.rb b/activerecord/lib/active_record/gem_version.rb index 91747d2ccf..e820835626 100644 --- a/activerecord/lib/active_record/gem_version.rb +++ b/activerecord/lib/active_record/gem_version.rb @@ -8,7 +8,7 @@ module ActiveRecord MAJOR = 4 MINOR = 2 TINY = 0 - PRE = "beta2" + PRE = "beta4" STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".") end diff --git a/activesupport/lib/active_support/gem_version.rb b/activesupport/lib/active_support/gem_version.rb index 6233c45787..bc7933e38b 100644 --- a/activesupport/lib/active_support/gem_version.rb +++ b/activesupport/lib/active_support/gem_version.rb @@ -8,7 +8,7 @@ module ActiveSupport MAJOR = 4 MINOR = 2 TINY = 0 - PRE = "beta2" + PRE = "beta4" STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".") end diff --git a/railties/lib/rails/gem_version.rb b/railties/lib/rails/gem_version.rb index 4411ec33ef..8abed99f2c 100644 --- a/railties/lib/rails/gem_version.rb +++ b/railties/lib/rails/gem_version.rb @@ -8,7 +8,7 @@ module Rails MAJOR = 4 MINOR = 2 TINY = 0 - PRE = "beta2" + PRE = "beta4" STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".") end diff --git a/version.rb b/version.rb index 4411ec33ef..8abed99f2c 100644 --- a/version.rb +++ b/version.rb @@ -8,7 +8,7 @@ module Rails MAJOR = 4 MINOR = 2 TINY = 0 - PRE = "beta2" + PRE = "beta4" STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".") end -- cgit v1.2.3 From a34db582049a5e802b6cde8a8bdf64c9a5734582 Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Fri, 31 Oct 2014 09:39:40 +0900 Subject: [ci skip] fix incorrect key in Active Support Instrumentation guide --- guides/source/active_support_instrumentation.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/guides/source/active_support_instrumentation.md b/guides/source/active_support_instrumentation.md index 83f3645b31..9dfacce560 100644 --- a/guides/source/active_support_instrumentation.md +++ b/guides/source/active_support_instrumentation.md @@ -225,11 +225,11 @@ Active Record ### sql.active_record -| Key | Value | -| ------------ | --------------------- | -| `:sql` | SQL statement | -| `:name` | Name of the operation | -| `:object_id` | `self.object_id` | +| Key | Value | +| ---------------- | --------------------- | +| `:sql` | SQL statement | +| `:name` | Name of the operation | +| `:connection_id` | `self.object_id` | INFO. The adapters will add their own data as well. -- cgit v1.2.3 From 828c64241c34668bb540019cd71e232400335e74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Fri, 31 Oct 2014 12:24:28 -0200 Subject: Do not package the guides output Fixes #17455 --- rails.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rails.gemspec b/rails.gemspec index a304b16f57..99685252e0 100644 --- a/rails.gemspec +++ b/rails.gemspec @@ -16,7 +16,7 @@ Gem::Specification.new do |s| s.email = 'david@loudthinking.com' s.homepage = 'http://www.rubyonrails.org' - s.files = ['README.md'] + Dir['guides/**/*'] + s.files = ['README.md'] + Dir['guides/**/*'] - Dir['guides/output/**/*'] s.add_dependency 'activesupport', version s.add_dependency 'actionpack', version -- cgit v1.2.3 From 53ec0bc0551c696add0a5ffff506fc9e83065bc0 Mon Sep 17 00:00:00 2001 From: Sean Griffin Date: Fri, 31 Oct 2014 08:38:40 -0600 Subject: Don't require calculations to be aliased to a column Arel has changed so that `.sum` no longer aliases `SUM(the_column)` to `sum_id`. This means the type returned by the adapter will be at the key `"SUM(the_column)"`. Longer term, we should eventually be able to retain type information from the AR::Base subclasses used in joined queries --- activerecord/lib/active_record/relation/calculations.rb | 2 +- activerecord/test/cases/calculations_test.rb | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/activerecord/lib/active_record/relation/calculations.rb b/activerecord/lib/active_record/relation/calculations.rb index eaaa409636..e20cc0e76d 100644 --- a/activerecord/lib/active_record/relation/calculations.rb +++ b/activerecord/lib/active_record/relation/calculations.rb @@ -253,7 +253,7 @@ module ActiveRecord select_value = operation_over_aggregate_column(column, operation, distinct) - column_alias = select_value.alias + column_alias = select_value.alias || select_value.to_sql relation.select_values = [select_value] query_builder = relation.arel diff --git a/activerecord/test/cases/calculations_test.rb b/activerecord/test/cases/calculations_test.rb index ec6a319ab5..e886268a72 100644 --- a/activerecord/test/cases/calculations_test.rb +++ b/activerecord/test/cases/calculations_test.rb @@ -461,7 +461,6 @@ class CalculationsTest < ActiveRecord::TestCase assert_equal 7, Company.includes(:contracts).sum(:developer_id) end - def test_from_option_with_specified_index if Edge.connection.adapter_name == 'MySQL' or Edge.connection.adapter_name == 'Mysql2' assert_equal Edge.count(:all), Edge.from('edges USE INDEX(unique_edge_index)').count(:all) -- cgit v1.2.3 From 9b9f0197b7e645ae5b05a5581ba82f32f0971183 Mon Sep 17 00:00:00 2001 From: Sean Griffin Date: Fri, 31 Oct 2014 11:30:14 -0600 Subject: Rename `default_attributes` to `_default_attributes` It is internal use only. This is to avoid conflicting with users' method names. Fixes #17458 --- activerecord/lib/active_record/core.rb | 2 +- activerecord/lib/active_record/model_schema.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/activerecord/lib/active_record/core.rb b/activerecord/lib/active_record/core.rb index 9ab27bbac5..a0382f99e6 100644 --- a/activerecord/lib/active_record/core.rb +++ b/activerecord/lib/active_record/core.rb @@ -266,7 +266,7 @@ module ActiveRecord # # Instantiates a single new object # User.new(first_name: 'Jamie') def initialize(attributes = nil, options = {}) - @attributes = self.class.default_attributes.dup + @attributes = self.class._default_attributes.dup init_internals initialize_internals_callback diff --git a/activerecord/lib/active_record/model_schema.rb b/activerecord/lib/active_record/model_schema.rb index 48e82d28d9..31ff08a89d 100644 --- a/activerecord/lib/active_record/model_schema.rb +++ b/activerecord/lib/active_record/model_schema.rb @@ -247,10 +247,10 @@ module ActiveRecord # Returns a hash where the keys are column names and the values are # default values when instantiating the AR object for this table. def column_defaults - default_attributes.to_hash + _default_attributes.to_hash end - def default_attributes # :nodoc: + def _default_attributes # :nodoc: @default_attributes ||= attributes_builder.build_from_database( columns_hash.transform_values(&:default)) end -- cgit v1.2.3 From d38d8d579c78650b02e367df490226869aef954b Mon Sep 17 00:00:00 2001 From: Hannah Briggs Date: Fri, 31 Oct 2014 10:33:24 -0700 Subject: Add masked authenticity token section, details on finder options, misc typos [ci skip] --- guides/source/upgrading_ruby_on_rails.md | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/guides/source/upgrading_ruby_on_rails.md b/guides/source/upgrading_ruby_on_rails.md index 8a1d7af923..c66fa4df27 100644 --- a/guides/source/upgrading_ruby_on_rails.md +++ b/guides/source/upgrading_ruby_on_rails.md @@ -177,7 +177,7 @@ after_bundle do end ``` -### Rails Html Sanitizer +### Rails HTML Sanitizer There's a new choice for sanitizing HTML fragments in your applications. The venerable html-scanner approach is now officially being deprecated in favor of @@ -210,6 +210,9 @@ gem 'rails-deprecated_sanitizer' TODO: Mention https://github.com/rails/rails/commit/4e97d7585a2f4788b9eed98c6cdaf4bb6f2cf5ce +### Masked Authenticity Tokens +In order to mitigate SSL attacks, `form_authenticity_token` is now masked so that it varies with each request. Thus, tokens are validated by unmasking and then decrypting. As a result, any strategies for verifying requests from non-rails forms that relied on a static session CSRF token have to take this into account. + Upgrading from Rails 4.0 to Rails 4.1 ------------------------------------- @@ -233,7 +236,7 @@ will now trigger CSRF protection. Switch to xhr :get, :index, format: :js ``` -to explicitly test an XmlHttpRequest. +to explicitly test an `XmlHttpRequest`. If you really mean to load JavaScript from remote `