Commit Graph

74209 Commits

Author SHA1 Message Date
Gannon McGibbon
4b65173479
Merge pull request #36791 from peterzhu2118/s3-upload-disposition
Upload with filename and disposition for S3
2019-07-31 12:55:00 -04:00
Eileen M. Uchitelle
33671d30f4
Merge pull request #36824 from eileencodes/fix-db-seed
Fix db:seed
2019-07-31 12:50:44 -04:00
eileencodes
cd148be072 Fix db:seed
The `rake db:seed` command was broken for the primary environment if the
application is using multiple databases. We never implemented `rake
db:seed` for other databases (coming soon), but that shouldn't break the
default case.

The reason this was broken was because `abort_if_pending_migrations`
would loop through the configs for all databases and check for
migrations but would leave the last established connection. So `db:seed`
was looking in the wrong database for the table to seed.

This PR doesn't fix the fact that `db:seed` doesn't work for multiple
databases but does fix the default case.

Fixes #36817

Co-authored-by: John Crepezzi <john.crepezzi@gmail.com>
2019-07-31 12:22:01 -04:00
Cliff Pruitt
fc6ec7bfc7 Prevent error on transliterate with frozen strings.
ActiveSupport::Inflector.transliterate mutates strings by changing encodings. Prior to this commit passing a frozen string would raise a `FrozenError`. This change duplicates the internal string, if frozen, before transliterating.
2019-07-31 12:11:31 -04:00
Peter Zhu
e6d2e8bf9b Upload file with filename and disposition for S3 2019-07-31 09:54:51 -04:00
Ryuta Kamizono
4c8c8c87b0 Address to rubocop offences 2019-07-31 17:48:14 +09:00
Akira Matsuda
511d1abc8a Reduce method invocations and object allocations in head() 2019-07-31 17:41:34 +09:00
Akira Matsuda
34a7e68bb9 Reduce Array allocations 2019-07-31 17:41:34 +09:00
Akira Matsuda
c46172171b Reduce block execution 2019-07-31 17:41:34 +09:00
Akira Matsuda
f0fdeaa175 Reduce method calls 2019-07-31 17:41:34 +09:00
Akira Matsuda
5ae814d016 Reduce Array assignment by not giving a name for unused *args 2019-07-31 17:41:34 +09:00
Akira Matsuda
7e299ce230 Reduce Array allocations 2019-07-31 17:41:34 +09:00
Akira Matsuda
acf7642ece Reduce some more Hash#fetch + default object allocations 2019-07-31 17:40:05 +09:00
Kasper Timm Hansen
40fc31c103
Merge pull request #36708 from rails/has-one-polymorphic-touch-dont-cache-association-result-inside-create-transaction
Polymorphic has_one touch: Don't cache association result inside crea…
2019-07-31 06:31:50 +02:00
Ryuta Kamizono
151a39c4f2
Merge pull request #36819 from yamato-payforward/payforward-branch
fix a  typo
2019-07-31 13:30:57 +09:00
yamato-payforward
b8309e85b9 fix a typo 2019-07-31 13:17:32 +09:00
Kasper Timm Hansen
cea392eb96
Polymorphic has_one touch: Reset association cache result after create transaction
In case of a polymorphic association there's no automatic inverse_of to assign the
inverse record. So to get the record there needs to be a query executed,
however, if the query fires within the transaction that's trying to create
the associated record, no record can be found. And worse, the nil result is cached
on the association so after the transaction commits the record can't be found.

That's what happens if touch is enabled on a polymorphic has_one association.

Consider a Comment with a commentable association that needs to be touched.

For `Comment.create(commentable: Post.new)`, the existing code essentially
does `commentable.send(:comment)` within the create transaction for the comment
and thus not finding the comment.

Now we're purposefully clearing the cache in case we've tried accessing
the association within the transaction and found no object.

Before:

```
kaspth-imac 2.6.3 ~/code/rails/activerecord master *= ARCONN=postgresql bin/test test/cases/associations/has_one_associations_test.rb -n /commit/
Using postgresql
Run options: -n /commit/ --seed 46022

D, [2019-07-19T03:30:37.864537 #96022] DEBUG -- :   Chef Load (0.2ms)  SELECT "chefs".* FROM "chefs" WHERE "chefs"."employable_id" = $1 AND "chefs"."employable_type" = $2 LIMIT $3  [["employable_id", 1], ["employable_type", "DrinkDesignerWithPolymorphicTouchChef"], ["LIMIT", 1]]
D, [2019-07-19T03:30:37.865013 #96022] DEBUG -- :   Chef Create (0.2ms)  INSERT INTO "chefs" ("employable_id", "employable_type") VALUES ($1, $2) RETURNING "id"  [["employable_id", 1], ["employable_type", "DrinkDesignerWithPolymorphicTouchChef"]]
D, [2019-07-19T03:30:37.865201 #96022] DEBUG -- :   TRANSACTION (0.1ms)  RELEASE SAVEPOINT active_record_1
D, [2019-07-19T03:30:37.874136 #96022] DEBUG -- :   TRANSACTION (0.1ms)  ROLLBACK
D, [2019-07-19T03:30:37.874323 #96022] DEBUG -- :   TRANSACTION (0.1ms)  ROLLBACK
F

Failure:
HasOneAssociationsTest#test_polymorphic_has_one_with_touch_option_on_create_wont_cache_assocation_so_fetching_after_transaction_commit_works [/Users/kaspth/code/rails/activerecord/test/cases/associations/has_one_associations_test.rb:716]:
--- expected
+++ actual
@@ -1 +1 @@
-#<Chef id: 1, employable_id: 1, employable_type: "DrinkDesignerWithPolymorphicTouchChef", department_id: nil, employable_list_type: nil, employable_list_id: nil>
+nil
```

After:

```
kaspth-imac 2.6.3 ~/code/rails/activerecord master *= ARCONN=postgresql bin/test test/cases/associations/has_one_associations_test.rb -n /commit/
Using postgresql
Run options: -n /commit/ --seed 46022

D, [2019-07-19T03:30:22.479387 #95973] DEBUG -- :   Chef Create (0.3ms)  INSERT INTO "chefs" ("employable_id", "employable_type") VALUES ($1, $2) RETURNING "id"  [["employable_id", 1], ["employable_type", "DrinkDesignerWithPolymorphicTouchChef"]]
D, [2019-07-19T03:30:22.479574 #95973] DEBUG -- :   TRANSACTION (0.1ms)  RELEASE SAVEPOINT active_record_1
D, [2019-07-19T03:30:22.482051 #95973] DEBUG -- :   Chef Load (0.1ms)  SELECT "chefs".* FROM "chefs" WHERE "chefs"."employable_id" = $1 AND "chefs"."employable_type" = $2 LIMIT $3  [["employable_id", 1], ["employable_type", "DrinkDesignerWithPolymorphicTouchChef"], ["LIMIT", 1]]
D, [2019-07-19T03:30:22.482317 #95973] DEBUG -- :   TRANSACTION (0.1ms)  ROLLBACK
D, [2019-07-19T03:30:22.482437 #95973] DEBUG -- :   TRANSACTION (0.1ms)  ROLLBACK
.

Finished in 0.088498s, 11.2997 runs/s, 22.5994 assertions/s.
1 runs, 2 assertions, 0 failures, 0 errors, 0 skips
```

Notice the select now fires after the commit.
2019-07-31 05:59:23 +02:00
Ryuta Kamizono
f40eb4a408
Merge pull request #36818 from hc0208/fix_typo_in_data_remote_js
Fix typo submited → submitted
2019-07-31 12:39:08 +09:00
hc0208
6a409f7341 Fix typo submited → submitted [ci skip] 2019-07-31 12:22:21 +09:00
Akira Matsuda
6dbfc67734 Accessing ivar with Symbols might be just a very little bit better than with fstrings 2019-07-31 12:18:44 +09:00
Akira Matsuda
46d207fde4 Avoid creating new Array when looking up already registered detail 2019-07-31 12:18:42 +09:00
Akira Matsuda
a1d7d4c6dc Reduce Hash object creation when normalizing request env 2019-07-31 11:51:59 +09:00
Akira Matsuda
05060ddba1 Cache tags_text to avoid computing tags each time when logging 2019-07-31 11:51:59 +09:00
Akira Matsuda
b8d29f35f0 Reduce object allocations in Middleware::Static 2019-07-31 11:51:59 +09:00
Akira Matsuda
f915341628 Reduce unnecessary String creation by not to_sing until nothing matches 2019-07-31 11:51:19 +09:00
Akira Matsuda
303f388d93 Reduce String allocation when finding controller class 2019-07-31 11:51:19 +09:00
Akira Matsuda
23009e3e33 No need to dup the payload for an instrumentation 2019-07-31 11:51:19 +09:00
Akira Matsuda
79520879e9 Speedup and reduce Array creation when constantizing a non-namespaced string 2019-07-31 11:51:19 +09:00
Ryuta Kamizono
7195455561
Merge pull request #36815 from emp823/master
Fix typo in autoload documentation [ci skip]
2019-07-31 01:54:39 +09:00
Erik Pearson
fab42177c1 Fix typo in autoload documentation [ci skip] 2019-07-30 12:39:51 -04:00
Javan Makhmali
aa00aec32a Bump Trix to ^1.2.0
Adds an attachment button to the Trix toolbar that improves overall file upload usability, especially on mobile devices where files can't be dragged / dropped.

References:
- https://github.com/basecamp/trix/releases/tag/1.2.0
- https://github.com/basecamp/trix/pull/619
- https://github.com/basecamp/trix/issues/582
2019-07-30 10:12:14 -04:00
Prem Sichanugrist
004f223f33
Merge pull request #36813 from haruyuki97/haruyuki97/fix-comment-in-url-helper
Fix a/an usage on `phone_to` documentation.

[ci skip]
2019-07-30 18:59:31 +09:00
Prem Sichanugrist
bd822a45be
Merge pull request #36812 from nigh7m4r3/readme-comma-usage
Fix comma usage on project's README.md

[ci skip]
2019-07-30 18:58:14 +09:00
haruyuki97
96e8a817fa fix a typo [ci skip] 2019-07-30 18:49:25 +09:00
Rifatul Islam Chayon
56b3f79254
Update README.md
A very minor change of comma usage.
2019-07-30 13:39:14 +06:00
Ryuta Kamizono
1e5c0a7836
Merge pull request #36805 from kamipo/user_supplied_joins_order_should_be_preserved
Preserve user supplied joins order as much as possible
2019-07-30 12:39:50 +09:00
Ryuta Kamizono
fff120c752 Add silence_warnings for defining 'not_' prefix enum elements
To suppress the following warnings in tests.

```
~/rails/activerecord/lib/active_record/scoping/named.rb:190: warning: method redefined; discarding old not_sent
~/rails/activerecord/lib/active_record/scoping/named.rb:190: warning: previous definition of not_sent was here
```
2019-07-30 04:54:55 +09:00
Ryuta Kamizono
b4478ae8bc Preserve user supplied joins order as much as possible
Currently, string joins are always applied as last joins part, and Arel
join nodes are always applied as leading joins part (since #36304), it
makes people struggled to preserve user supplied joins order.

To mitigate this problem, preserve the order of string joins and Arel
join nodes either before or after of association joins.

Fixes #36761.
Fixes #34328.
Fixes #24281.
Fixes #12953.
2019-07-30 04:02:58 +09:00
Vipul A M
8d2e75e84c
Merge pull request #36804 from vzvu3k6k/tt
[ci skip] Fix unclosed tags in `Inflector` docs
2019-07-30 02:37:28 +08:00
vzvu3k6k
515238bc6c [ci skip] Fix unclosed tags in Inflector docs 2019-07-30 03:18:05 +09:00
John Hawthorn
8b0b591296
Merge pull request #36782 from jhawthorn/move_database_exists_to_adapter
Move DatabaseAlreadyExists detection to DB adapter
2019-07-29 11:06:27 -07:00
Ryuta Kamizono
e0b19a3622 Expand CHANGELOG for #36800 [ci skip] 2019-07-30 02:50:11 +09:00
John Hawthorn
69700c9ee7 Move DatabaseAlreadyExists detection to DB adapter
Previously it was the responsibility of the database tasks to translate
the invalid statement from creating a duplicate database into an
ActiveRecord::Tasks::DatabaseAlreadyExists error.

It's actually easier for us to do this detection inside of the adapter,
where we already do a case statement on the return code to translate the
error.

This commit introduces ActiveRecord::DatabaseAlreadyExists, a subclass
of StatementInvalid, and updates both AbstractMysqlAdapter and
PostgresqlAdapter to return this more specific exception in that case.

Because this is a subclass of the old exception, StatementInvalid, it
should be backwards compatible with any code expecting that from
create_database.

This works for both create_database and exectute("CREATE DATABASE")
2019-07-29 08:40:57 -07:00
Carlos Antonio da Silva
17b8cde6d1 Call raise with parentheses like a normal method call with arguments
Using `(raise FooError, "error")` is like forcing a "new scope" around
the `raise` call, it's simpler to just wrap the `raise` arguments with
parentheses just like any other method call would.
2019-07-29 12:28:36 -03:00
Ryuta Kamizono
2e6d9af6c8
Merge pull request #36800 from jamespearson/matches_regex_mysql
Enabled matches_regex for MySql
2019-07-30 00:08:27 +09:00
James Pearson
92c265b3ad Enabled matches_regex for MySql
Previously matches_regex was only availble on PostgreSql, this will enable it for MySql

Usage example:

    users = User.arel_table;
    users = User.arel_table; User.where(users[:email].matches_regexp('(.*)\@gmail.com'))

Update activerecord/test/cases/arel/visitors/mysql_test.rb

Co-Authored-By: Ryuta Kamizono <kamipo@gmail.com>
2019-07-29 15:53:29 +01:00
Ryuta Kamizono
79740de065
Merge pull request #36198 from oneiros/actionmailer_ssl_option
Documentation for ActionMailer's SMTP over SSL/TLS option

[ci skip]
2019-07-29 23:30:35 +09:00
David Roetzel
1480b87f31 Improve documentation of :ssl/:tls option [ci skip]
Add missing bullet point to make clear this is
actually a separate option from
`:openssl_verify_mode`.

Add `:ssl/:tls`-option to guides as well [ci skip]
2019-07-29 15:42:32 +02:00
Robin Dupret
682f664819 Tiny documentation fix [ci skip] 2019-07-29 12:42:24 +02:00
Ryuta Kamizono
36c5a74988
Merge pull request #36798 from meganemura/remove-redundant-empty-line
Remove redundant empty line when we don't use system test
2019-07-29 19:34:14 +09:00