Commit Graph

78556 Commits

Author SHA1 Message Date
Yasuo Honda
aa026ee105 Revert "Work around getaddrinfo deadlock in forked process"
This reverts commit 7cf8e30902119b22c5f9fa1f4d80185ba3f3a5f7.
2020-12-06 23:01:56 +09:00
Yasuo Honda
8ae1738a14 Revert "Merge pull request #40451 from yahonda/sneakers"
This reverts commit 3b9807f3de9d4231cb914946f53f164fbd6d0b7a, reversing
changes made to 7e2d8434ed42d6fbf7f4743d033d50ad92ebe4da.
2020-12-06 23:01:41 +09:00
Yasuo Honda
fa3d47018b Revert "Merge pull request #40453 from yahonda/resque_start_workers"
This reverts commit 1fddc8023ec1e7f65e9b0c299ade1084dc7a3bf4, reversing
changes made to 1f5a4d1d5e68106eaa897e49a874bef24bf4c63c.
2020-12-06 23:01:19 +09:00
Ryuta Kamizono
9b6008924d
Merge pull request #40749 from kamipo/dont_use_explicit_references_for_join_aliases
Don't use explicit references for join aliases
2020-12-04 17:24:27 +09:00
Ryuta Kamizono
947a5de75d Don't use explicit references for join aliases
As the API doc shows, `references` should be given table names.

https://api.rubyonrails.org/classes/ActiveRecord/QueryMethods.html#method-i-references

However, people (and test cases in the our codebase) sometimes give
association names for `references`.

Since the API example and all test cases in the codebase use symbols as
arguments, so I regarded symbols as user given values in #40106.

But as #40743 indicates, people also use string association names, it
would have unexpected side-effect especially if singular association
names given.

As much as possible to avoid to use user given values, mark internal
references for `where` and use only them for join aliases.

Fixes #40743.
2020-12-04 15:19:20 +09:00
Rafael França
6ef39975d6
Merge pull request #40740 from abhaynikam/add-spec-for-action-text-warning
Adds the missing spec for Action Text installer warning
2020-12-03 19:09:57 -05:00
Rafael Mendonça França
c1528c905c
Fix the cop violation 👮 2020-12-03 23:14:28 +00:00
Rafael Mendonça França
ee647d4b0a
Impove the RoutesReloader to not expose internal API
We don't need a callback and we should not expose the attribute to the
API given this is only internal.

I also removed the CHANGELOG entry because this is a bugfix for a change
that was not released yet.
2020-12-03 23:01:53 +00:00
Rafael França
bcb3383256
Merge pull request #40742 from dotLou/development_only_execute_route_reloader_once
Only execute route reloads once on boot for development environment
2020-12-03 17:29:34 -05:00
Rafael Mendonça França
028faabc5f
Align all the assigments 2020-12-03 22:28:45 +00:00
Louis Cloutier
796e7129e6
Only execute route reloads once on boot for development environment
Signed-off-by: Louis Cloutier <louis.cloutier@shopify.com>
2020-12-03 15:55:41 -05:00
Daniel Colson
8ef5bd9ced
Allow custom purpose for ActiveStorage signed IDs
This commit allows passing a custom `purpose:` keyword argument to both
`find_signed!` and `signed_id`. This matches the signature of the
`super` methods in ActiveRecord, and it is already possible with the
non-bang [`find_signed`][find_signed] method, since that one doesn't
have an override in ActiveStorage (although perhaps it should, to set
the default :blob_id purpose)

This is useful in cases where you want to further isolate different
types of blobs, for example if they have different levels of
authorization.

[find_signed]: be11d1b6e8/activerecord/lib/active_record/signed_id.rb (L42-L48)
2020-12-03 12:36:52 -05:00
Rafael França
cafdd18721
Merge pull request #40731 from ghiculescu/patch-2
ActiveStorage Direct Upload docs improvements [ci skip]
2020-12-03 10:49:08 -05:00
Rafael França
ad8f7604fa
Merge pull request #40739 from tricknotes/fix-to-handle-missing-yarn-environment
Fix to handle missing yarn environment in bin/yarn
2020-12-03 10:35:58 -05:00
Abhay Nikam
89af594ec9 Adds the missing spec for Action Text installer warning for incomplete webpacker configuration 2020-12-03 19:11:02 +05:30
Ryunosuke Sato
78e0e183c5
Fix to handle missing yarn environment in bin/yarn
When we use `bin/yarn` without original yarn,
the following error will be occurred:
```
bin/yarn:12:in `initialize': no implicit conversion of nil into String (TypeError)
```

This means `executable_path` is `nil`.

To handle missing yarn correctly, checking `executable_path` seems good.
This is a result of my local without yarn.
```
Yarn executable was not detected in the system.
Download Yarn at https://yarnpkg.com/en/docs/install
rake aborted!
```

This commit follows up https://github.com/rails/rails/pull/40646.
2020-12-03 22:27:43 +09:00
Rafael França
855e782979
Merge pull request #40717 from cindygshopify/remove_sprockets_related_files
removed sprocket related files
2020-12-02 20:51:06 -05:00
Rafael Mendonça França
59f7f5889e
Start Rails 6.2 development 🎉 2020-12-03 01:35:29 +00:00
Rafael Mendonça França
d04f74dd72
Make sure that attribute_for_inspect respect filter_attributes
Before this change while inspect was respecting that option, attribute_for_inspect
was not.

I also changed inspect to use attribute_for_inspect so we make sure the behavior
is consistent in the two places and simplified the implementation.

Fixes #40725.
2020-12-02 23:01:34 +00:00
Rafael França
9f1623bd34
Merge pull request #40736 from jonathanhefner/guide-action_cable_overview-link-api
Link to API docs in Action Cable Overview guide [ci-skip]
2020-12-02 17:33:37 -05:00
Jonathan Hefner
0e9530b053 Link to API docs in Action Cable Overview guide [ci-skip]
This links the first mention of each method to its API documentation,
similar to a Wikipedia article.

This also modifies the text in a few places to ensure that methods are
explicitly mentioned and linked.
2020-12-02 16:08:37 -06:00
Rafael França
be11d1b6e8
Merge pull request #40733 from ghiculescu/patch-3
Incorrect default for `config.autoload_paths` [ci skip]
2020-12-02 16:00:23 -05:00
Cindy Gao
d620f068c2 removed sprocket related files manifest.js and application.css from generated rails app when --skip-sprockets flag passed into rails new and app:update 2020-12-02 14:52:46 -05:00
Alex Ghiculescu
f6c4815e9a
Incorrect default for config.autoload_paths [ci skip]
The docs implied that the default for `config.autoload_paths` was the output of `Dir.glob("app/*")`. In reality, on a new Rails app the default is `[]`.

Internally, Rails sets `ActiveSupport::Dependencies.autoload_paths` based on the union of [several configs](https://github.com/rails/rails/blob/v6.0.3.4/railties/lib/rails/engine.rb#L707), which is how `app` ends up being autoloaded (it is in `config.eager_load_paths` [by default](https://github.com/rails/rails/blob/v6.0.3.4/railties/lib/rails/engine/configuration.rb#L42)).

I think this is worth clarifying, because the current docs implies code like this will do something:

```ruby
config.autoload_paths -= ["#{config.root}/app/middleware"]
```

In reality it does nothing. This style of code is [discouraged](https://guides.rubyonrails.org/upgrading_ruby_on_rails.html#globs-in-config-autoload-paths) but that doesn't mean it's not out there :) :(
2020-12-02 12:06:20 -06:00
Alex Ghiculescu
435b4666fb
ActiveStorage Direct Upload docs improvements [ci skip]
- Clarifies the wording of step 2 of https://edgeguides.rubyonrails.org/active_storage_overview.html#usage to better reflect what you should do, and to match the code sample immediately after it.
- Adds a note about how to use Direct Upload without a FormBuilder.
2020-12-02 10:41:57 -06:00
Ryuta Kamizono
5384bbc4ce
Merge pull request #40727 from kamipo/fix_or_to_raise_argument_error
Fix `or` to raise structurally incompatible error for single values
2020-12-02 20:40:52 +09:00
Ryuta Kamizono
d99dcdd9e1 Fix or to raise structurally incompatible error for single values
It is a regression for f854b46, to match empty values greedy.
But that it not important part, so I've removed that to fix #40723.
2020-12-02 20:05:01 +09:00
Eileen M. Uchitelle
600132afc1
Merge pull request #40720 from eileencodes/default-scope-all-queries
Add option for `default_scope` to run on all queries
2020-12-01 16:29:44 -05:00
Rafael França
dc4dd50ac3
Merge pull request #40708 from p8/form-with-generates-local-forms
Change form_with to generate non-remote forms by default
2020-12-01 16:28:28 -05:00
Petrik
0a583c73c1 Change form_with to generate non remote forms by default
`form_with` would generate a remote form by default.
This confused users because they were forced to handle remote requests.

All new 6.1 applications will generate non-remote forms by default.
When upgrading a 6.0 application you can enable remote forms by default by
setting `config.action_view.form_with_generates_remote_forms` to `true`.
2020-12-01 21:14:37 +01:00
Rafael França
366df0397f
Merge pull request #40721 from d12/optimize_hash_with_indifferent_access_initializer
55% speedup for HashWithIndifferentAccess.new when no args provided
2020-12-01 14:56:56 -05:00
Jonathan Hefner
e067a2a3f6
Merge pull request #40706 from jonathanhefner/guide-active_storage_overview-link-api
Link to API docs in Active Storage Overview guide [ci-skip]
2020-12-01 12:58:43 -06:00
Nathaniel Woodthorpe
0841cdf268 Optimize HashWithIndifferentAccess.new when no args are provided 2020-12-01 13:25:11 -05:00
eileencodes
816f6194b6
Add option for default_scope to run on all queries
This change allows for applications to optionally run a `default_scope`
on `update` and `delete` queries. Default scopes already ran on select
and insert queries.

Applications can now run a set default scope on all queries for a model
by setting a `all_queries` option:

```ruby
class Article < ApplicationRecord
  default_scope -> { where(blog_id: 1) }, all_queries: true
end
```

Using the default scope in this way is useful for applications that need
to query by more than the primary key by default. An example of this
would be in an application using a sharding strategy like Vitess like.
For Rails sharding, we route connections first and then query the
database. However, Vitess and other solutions use a parameter in the
query to figure out how to route the queries. By extending
`default_scope` to apply to all queries we can allow applications to
optionally apply additional constraints to all queries. Note that this
only works with `where` queries as it does not make sense to select a
record by primary key with an order. With this change we're allowing
apps to select with a primary key and an additional key.

To make this change dynamic for routing queries in a tenant sharding
strategy applications can use the `Current` API or parameters in a
request to route queries:

```ruby
class Article < ApplicationRecord
  default_scope -> { where(blog_id: Current.blog.id) }, all_queries: true
end
```

In order to achieve this I created a new object when default scopes are
created. This allows us to store both the scope itself and whether we
should run this on all queries. I chose not to implement an `on:` option
that takes an array of actions because there is no simple or clear way
to turn off the default scope for create/select. It also doesn't really
make sense to only have a default scope for delete queries. The decision
to use `all_queries` here allows for the implementation to be more
flexible than it was without creating a mess in an application.
2020-12-01 11:15:08 -05:00
Akira Matsuda
6f9d4a000b
Merge pull request #40663 from amatsuda/keep_safe_buffer
Let AS::SafeBuffer#[] and * return value be an instance of SafeBuffer in Ruby 3.0
2020-12-01 17:42:37 +09:00
Akira Matsuda
4cb20843eb Mark scrub as an unsafe method on SafeBuffer 2020-12-01 17:40:17 +09:00
Rafael França
38998af1d9
Merge pull request #40127 from seanpdoyle/form-tag-ids
Declare ActionView::Helpers::FormBuilder#id and #field_id
2020-11-30 19:41:42 -05:00
Rafael Mendonça França
a173a65730
Merge pull request #39472
Closes #39472.
2020-12-01 00:40:52 +00:00
Sean Doyle
59ca21c011 Declare ActionView::Helpers::FormBuilder#id
`ActionView::Helpers::FormBuilder#id`
---

Generate an HTML `id` attribute value.

Return the [`<form>` element's][mdn-form] `id` attribute.

```html+erb
<%= form_for @post do |f| %>
  <%# ... %>

  <% content_for :sticky_footer do %>
    <%= form.button(form: f.id) %>
  <% end %>
<% end %>
```

In the example above, the `:sticky_footer` content area will exist
outside of the `<form>` element. [By declaring the `form` HTML
attribute][mdn-button-attr-form], we hint to the browser that the
generated `<button>` element should be treated as the `<form>` element's
submit button, regardless of where it exists in the DOM.

[A similar pattern could be used for `<input>`
elements][mdn-input-attr-form] (or other form controls) that do not
descend from the `<form>` element.

`ActionView::Helpers::FormBuilder#field_id`
---

Generate an HTML <tt>id</tt> attribute value for the given field

Return the value generated by the <tt>FormBuilder</tt> for the given
attribute name.

```html+erb
<%= form_for @post do |f| %>
  <%= f.label :title %>
  <%= f.text_field :title, aria: { describedby: form.field_id(:title, :error) } %>
  <span id="<%= f.field_id(:title, :error) %>">is blank</span>
<% end %>
```

In the example above, the <tt><input type="text"></tt> element built by
the call to <tt>FormBuilder#text_field</tt> declares an
<tt>aria-describedby</tt> attribute referencing the <tt><span></tt>
element, sharing a common <tt>id</tt> root (<tt>post_title</tt>, in this
case).

This method is powered by the `field_id` helper declared in
`action_view/helpers/form_tag_helper`, which is made available for
general template calls, separate from a `FormBuilder` instance.

[mdn-form]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form
[mdn-button-attr-form]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#attr-form
[mdn-input-attr-form]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attr-form
[mdn-aria-describedby]: https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques/Using_the_aria-describedby_attribute
[w3c-wai]: https://www.w3.org/WAI/tutorials/forms/notifications/#listing-errors
2020-11-30 18:47:49 -05:00
Rafael França
89414f561a
Merge pull request #40045 from sandip-mane/40041-hosts-case-fix
Adds a fix to whitelist hostnames with case-insensitive matching
2020-11-30 18:44:12 -05:00
Rafael França
363cd6d5c0
Merge pull request #40503 from juanmanuelramallo/increase-worker-timeout-in-development
Increasing Puma's worker timeout in development
2020-11-30 18:43:05 -05:00
Rafael França
10c34f07ab
Merge pull request #40709 from francois-ferrandis/update-guide-on-delivery-method-in-callbacks
Update Action Mailer guide on delivery methods in callbacks
2020-11-30 18:36:33 -05:00
Rafael França
3446efc8bc
Merge pull request #40703 from d12/fix_deep_transform_keys_for_indifferent_access_hash
Fix bad return value of `HashWithIndifferentAccess#deep_transform_keys`
2020-11-30 18:16:57 -05:00
Rafael França
8ad477aa31
Merge pull request #40716 from ghiculescu/asset-host-config
Always recommend `config.asset_host` in guides, examples, and docs
2020-11-30 18:16:20 -05:00
Alex Ghiculescu
76e432341c Always recommend config.asset_host in examples 2020-11-30 16:33:51 -06:00
Kasper Timm Hansen
79d0c17c65
Merge pull request #39929 from jonathanhefner/decorate-original-attribute-type
Unify `decorate_attribute_type` and `attribute`
2020-11-30 23:28:22 +01:00
Nathaniel Woodthorpe
f5e5976388 Fix the return value of #deep_transform_keys from a Hash to a HashWithIndifferentAccess 2020-11-30 17:13:53 -05:00
Rafael França
bc828f74df
Merge pull request #40069 from abhaynikam/add-test-cases-for-action-mailbox-generator
Added test cases for Action Mailbox generator
2020-11-30 16:55:10 -05:00
Jonathan Hefner
4cc9c0f504 Unify decorate_attribute_type and attribute
Follow-up to 75c309c7ad6517a7fad482f1efd50baadf4bdf45.

As a result of these changes, attributes can have their type and default
value configured separately.  Similar behavior was implemented in #39380,
but only for attributes that derive (and do not override) their type
from the database.
2020-11-30 15:51:19 -06:00
Abhay Nikam
d8f182101c Added test cases for Action Mailbox generator 2020-11-30 23:15:41 +05:30