Commit Graph

74495 Commits

Author SHA1 Message Date
George Claghorn d41e282a94 Prefer assert_not_includes 2019-09-13 13:56:12 -04:00
George Claghorn ffc8475db8
Fix setting a more verbose thread-local log level
We prepend a check against the thread-local level to Logger#add, but because it proceeds to check against the thread-global level, only setting a quieter thread-local level works. The quietest of the two wins. Fix by reimplementing #add entirely.

It's unfortunate to have to do this, but I've already patched upstream Logger to prefer the level instance method over the @level instance variable, so we'll be able to avoid touching #add at all in the future. See https://github.com/ruby/logger/pull/41.
2019-09-13 13:54:18 -04:00
Eileen M. Uchitelle 42dea6b0f6
Merge pull request #37185 from seejohnrun/config-symbols
Use symbols everywhere for database configurations
2019-09-13 13:03:11 -04:00
eileencodes ce9b197cc9 Use symbols everywhere for database configurations
Previously in some places we used symbol keys, and in some places we used
string keys. That made it pretty confusing to figure out in a particular
place what type of configuration object you were working with.

Now internally, all configuration hashes are keyed by symbols and
converted to such on the way in.

A few exceptions:

- `DatabaseConfigurations#to_h` still returns strings for backward compatibility
- Same for `legacy_hash`
- `default_hash` previously could return strings, but the associated
  comment mentions it returns symbol-key `Hash` and now it always does

Because this is a change in behavior, a few method renames have happened:

- `DatabaseConfig#config` is now `DatabaseConfig#configuration_hash` and returns a symbol-key `Hash`
- `ConnectionSpecification#config` is now `ConnectionSpecification#underlying_configuration_hash` and returns the `Hash` of the underlying `DatabaseConfig`
- `DatabaseConfig#config` was added back, returns `String`-keys for backward compatibility, and is deprecated in favor of the new `configuration_hash`

Co-authored-by: eileencodes <eileencodes@gmail.com>
2019-09-13 08:53:22 -04:00
Akira Matsuda 9e4ff29f74 No need to dup before double-splatting a Hash 2019-09-13 20:20:28 +09:00
Akira Matsuda cd31e113c0 Use keyword arguments instead of last parameter Hash
this would eliminate warnings when calling keyworded method,
and this still works with methods taking last parameter Hash
2019-09-13 19:22:05 +09:00
Akira Matsuda 154b7ffd97 Tests for OptionMerger with keyword arguments 2019-09-13 18:11:22 +09:00
Akira Matsuda 926cfdb4e3 get gets keyworded options 2019-09-13 17:36:11 +09:00
Akira Matsuda 95a8be46ea require open-uri where opening URI 2019-09-13 17:22:16 +09:00
Akira Matsuda 9845cd6338 Separate keyword arguments from parameters 2019-09-13 16:21:32 +09:00
Ryuta Kamizono 923439777a
Merge pull request #37191 from kamipo/required_mysql2_0.5
Required mysql2 gem 0.5.0
2019-09-13 14:56:29 +09:00
Ryuta Kamizono 4674d77764 Required mysql2 gem 0.5.0
This follows up #36692, `Mysql2::Error::TimeoutError` is introduced from
mysql2 gem 0.5.0. https://github.com/brianmario/mysql2/pull/911
2019-09-13 11:15:44 +09:00
Ryuta Kamizono d79ad3f890 Fix ArgumentError: wrong number of arguments (given 3, expected 2) 2019-09-13 10:43:29 +09:00
Ryuta Kamizono b13c518ddf Fix keyword arguments warnings 2019-09-13 10:03:48 +09:00
Ryuta Kamizono 4bfa30e957
Merge pull request #37187 from eugeneius/abstract_adapter_autoload
Stop autoloading AbstractAdapter prematurely
2019-09-13 09:49:53 +09:00
Eugene Kenny b744372f2d Stop autoloading AbstractAdapter prematurely
In 7254d23764, an autoload for
`ConnectionAdapters::AbstractAdapter` was added to `active_record.rb`.

Later in d6b923adbd, a manual require for
that class was added to `active_record/base.rb` as some constants under
`ConnectionAdapters` weren't defined until `AbstractAdapter` was loaded.

In 1efd88283e, the require was removed and
replaced with an autoload in `active_record.rb`, above the previous one.

Because the first autoload was for the `ConnectionAdapters` constant and
the second one tried to create it, the autoload would fire immediately.
Rather than fixing the autoload problem, the require had effectively
just been moved from `active_record/base.rb` to `active_record.rb`.

Instead of defining autoloads for constants under `ConnectionAdapters`
in the `abstract_adapter.rb` file, we can create a separate, autoloaded
`connection_adapters.rb` file for this purpose.

To avoid a "circular require considered harmful" warning from Ruby, we
have to fix the module nesting in `schema_creation.rb`, as a followup to
e4108fc619.

`AbstractAdapter` loads many other dependencies, so making it autoload
properly has a noticeable impact on the load time of `active_record.rb`.

Benchmark:

    $ cat test.rb
    require "bundler/setup"
    before = ObjectSpace.each_object(Module).count
    start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
    require "active_record"
    finish = Process.clock_gettime(Process::CLOCK_MONOTONIC)
    after = ObjectSpace.each_object(Module).count
    puts "took #{finish - start} and created #{after - before} modules"

Before:

    $ ruby test.rb
    took 0.47532399999909103 and created 901 modules

After:

    $ ruby test.rb
    took 0.3299509999342263 and created 608 modules
2019-09-13 01:10:14 +01:00
Rafael França 12b964c50f
Merge pull request #37184 from dylanahsmith/read-query-comment-prefix
activerecord: Allow comment prefix in queries when preventing writes
2019-09-12 15:52:50 -04:00
Dylan Thacker-Smith b94efe9f1b activerecord: Allow comment prefix in queries when preventing writes 2019-09-12 15:11:02 -04:00
Eileen M. Uchitelle ff7a88d456
Merge pull request #37180 from seejohnrun/fix-error-hash-access
Fix error message for AdapterNotFound in spec
2019-09-12 10:21:42 -04:00
John Crepezzi e47f0da77b Fix error message for AdapterNotFound in spec
When this case was his previously, an error would be thrown like:
`<NoMethodError: "undefined method config for...">` because we were
erroneously calling `config` on a `Hash`.

This commit adds a test for this case, and fixes the hash access.
2019-09-12 09:59:03 -04:00
Carlos Antonio da Silva 5463e8522d
Merge pull request #37175 from adammw/patch-1
Fix typo in connection specification error handling
2019-09-12 07:34:27 -03:00
yuuji.yaginuma b5949f7f12 Fix `credentials:diff` option
The option name is `enroll` since f1f5024b91.
2019-09-12 17:00:36 +09:00
Adam Malcontenti-Wilson 7b08201ea2
Fix typo in connection specification error handling 2019-09-12 12:15:40 +10:00
Ryuta Kamizono 6bf2e59bec
Merge pull request #37170 from eugeneius/insert_all_query_cache_test
Skip insert all tests when features are unavailable
2019-09-11 18:18:47 +09:00
Eugene Kenny 36b639bd5f Skip insert all tests when features are unavailable
These tests are causing the Ruby master build to fail in CI. The Docker
image we use is based on Ubuntu Bionic which provides SQLite 3.22.0, and
the features required to use `insert_all` and `upsert_all` are not
available in that version.
2019-09-11 09:31:23 +01:00
Akira Matsuda 048436213e Workaround for kwargs 2.7 and 2.6 incompatibility
Current Ruby 2.7 implementation behaves differently from 2.6 (by design)
where receiving an empty keyword arguments.

Thus, for now we need this if branch everywhere we're asserting such a method call
in order for the CI to pass.

We could revert this workaround if Ruby 2.7 decides to revert back to the 2.6 behavior,
or maybe we'll need to fix Minitest::Mock once the 2.7 spec became stable.
2019-09-11 12:24:32 +09:00
Akira Matsuda 70afbf245f Unify `add_column` method definition with other ones that take keyword arguments 2019-09-11 10:48:29 +09:00
Akira Matsuda 3796cd628f Fix keyword arguments warnings 2019-09-11 10:48:29 +09:00
Akira Matsuda fd305732b8 Unify `transaction` method signature for eliminating kwargs warning 2019-09-11 10:48:29 +09:00
John Hawthorn 2f44c3b00b
Merge pull request #37119 from jonathanhefner/fix-escaping-in-view-path-resolver
Fix escaping in OptimizedFileSystemResolver
2019-09-10 17:36:22 -07:00
Kasper Timm Hansen da54c73cae
Merge pull request #37168 from eugeneius/remove_index_column_names_with_options
Accept columns passed with options in remove_index
2019-09-11 00:00:42 +02:00
Eugene Kenny 0cc13d3169 Accept columns passed with options in remove_index
Before this patch, column names could only be passed as a positional
argument when no other options were supplied:

    remove_index :reports, :report_id

Passing column names positionally along with other options would fail:

    remove_index :reports, :report_id, unique: true
    # => ArgumentError: wrong number of arguments (given 3, expected 1..2)
2019-09-10 22:21:20 +01:00
Kasper Timm Hansen ae2cbf4044
Merge pull request #37161 from eugeneius/bulk_alter_recreate_index
Allow bulk alter to drop and recreate named index
2019-09-10 13:12:33 +02:00
Kasper Timm Hansen 8ca16693e8
Merge pull request #37159 from kddeisz/serialize-classes
Serialize classes and modules with ActiveJob
2019-09-10 13:05:42 +02:00
Richard Schneeman 7af44f49db
Merge pull request #37162 from giraffate/fix_docs_to_replace_http_with_https
Fix documents to replace http with https in reference URL
2019-09-09 19:48:29 -05:00
Takayuki Nakata 4db23d0b31 Fix documents to replace http with https in reference URL [ci skip] 2019-09-10 09:29:21 +09:00
Eugene Kenny edb23791d2 Allow bulk alter to drop and recreate named index
In 3809c80cd5, adding an index with a
name that's already in use was changed from an error to a warning, to
allow other statements in the same migration to complete successfully.

In 55d0d57bfc this decision was reversed,
but instead of allowing the statement to execute and raise an adapter-
specific error as it did before, an `ArgumentError` was raised instead.

This interferes with a legitimate use case: on MySQL, it's possible to
drop an index and add another one with the same name in a single `ALTER`
statement. Right now an `ArgumentError` is raised when trying to do so,
even though the resulting statement would execute successfully.

There's no corresponding `ArgumentError` raised when attempting to add a
duplicate column, so I think we can safely remove the check and allow
the adapter to raise its own error about duplicate indexes again.
2019-09-10 00:26:14 +01:00
Kevin Deisz fbebeabd6d
Serialize classes and modules with ActiveJob
This commit allows ActiveJob to serialize classes and modules without a custom serializer. This allows for workflows like:

```
class EmailJob < ApplicationJob
  queue_as :default
  def perform(template_class, *arguments)
    template_class.new(*arguments).send!
  end
end

module Email
  class FooTemplate ... end
  class BarTemplate ... end
end

EmailJob.perform_later(Email::FooTemplate, ...)
EmailJob.perform_later(Email::BarTemplate, ...)
```

Currently this is only achieveable through a custom serializer or through constantizing in each instance.
2019-09-09 16:45:12 -04:00
Jonathan Hefner 897cdc721e Fix escaping in OptimizedFileSystemResolver
`OptimizedFileSystemResolver` builds a regular expression to match view
template paths.  Prior to this patch, only file globbing special
characters were escaped when building this regular expression, leaving
other regular expression special characters unescaped.

This patch properly escapes all regular expression special characters,
and adds test coverage for paths that include these characters.

Fixes #37107.
2019-09-09 12:20:02 -05:00
Akira Matsuda 352560308b Fix keyword arguments warnings 2019-09-09 22:49:09 +09:00
Akira Matsuda af45834139 nil.try accepts keyword arguments (and does nothing with them) 2019-09-09 22:48:22 +09:00
Sébastien Puyet 179a5b8770 Fix folders update watcher with no folders to watch (#36163)
* boot when there is folders to watch

* raise argument error when paths are empty

* add space between curly braces

* Revert "add space between curly braces"

This reverts commit 90cff20c87.

* Revert "raise argument error when paths are empty"

This reverts commit 349adff0f5.

* stop lazy loading listem gem

* back with any?

* require listen gem at top of the file

* improve

* remove scope resolution operator
2019-09-09 13:50:01 +02:00
Kasper Timm Hansen 52a897aefa
Merge pull request #37096 from npras/master
Markdown `word highlight` doesn't work inside lists. Add CSS to fix […
2019-09-09 13:49:02 +02:00
Eugene Kenny 95a6a8fc0d
Merge pull request #37125 from p8/fix-autosave-docs
Improve autosave documentation [ci skip]
2019-09-09 12:21:35 +01:00
Petrik ad050486ee Improve autosave documentation [ci skip]
When :autosave is not declared existing children are not saved.
2019-09-09 13:16:56 +02:00
Ryuta Kamizono 692145e8d1
Merge pull request #37154 from eugeneius/insert_all_query_cache
Clear query cache when insert all is used
2019-09-09 13:19:53 +09:00
Ryuta Kamizono f7d7351f21
Merge pull request #37155 from giraffate/fix_docs_to_update_http_and_www_ruby-doc_org
Fix docs to update http and www.ruby-doc.org [ci skip]
2019-09-09 13:16:11 +09:00
Ryuta Kamizono bfacd45be0
Merge pull request #36460 from aldhsu/fix-endless-range-include
Fix endless range include
2019-09-09 13:14:03 +09:00
Takayuki Nakata a0249aed8c Fix docs to update http and www.ruby-doc.org [ci skip]
- Replace http with https
- Replace www.ruby-doc.org with ruby-doc.org
2019-09-09 09:34:09 +09:00
Eugene Kenny fad44a6999 Clear query cache when insert all is used
The `InsertAll` class currently calls `exec_query`, which doesn't give
the query cache enough information to know that it needs to be cleared.

By adding an `exec_insert_all` method that calls `exec_query` internally
we can configure the query cache to clear when that method is called.
2019-09-09 00:55:16 +01:00