Commit Graph

14953 Commits

Author SHA1 Message Date
Rafael Mendonça França
fb6c6007d0
Development of Rails 7.2 starts now
🎉
2023-09-27 03:59:11 +00:00
Rafael Mendonça França
e5386cb402
Preparing for 7.1.0.rc1 release 2023-09-27 03:08:31 +00:00
Rafael Mendonça França
d87ecd0467
Merge pull request #49396 from jonfoster9999/fix-typo-in-new_framework_defaults_7_1
fix typo in new_framework_defaults_7_1.rb.tt
2023-09-26 21:24:49 -04:00
Jonathan Foster
b729d7efda fix typo in new_framework_defaults_7_1.rb.tt 2023-09-26 20:31:11 -04:00
Jess Brown
c32813ddc6
Update description for filter_parameter_logging (#49347)
* Update description for filter_parameter_logging

* Update railties/lib/rails/generators/rails/app/templates/config/initializers/filter_parameter_logging.rb.tt

Thanks Rob!!. I did all this in the github ui and was a little out of sorts with the wrapping.

Co-authored-by: Rob Zolkos <rob@zolkos.com>

---------

Co-authored-by: Rob Zolkos <rob@zolkos.com>
Co-authored-by: Rafael Mendonça França <rafael@rubyonrails.org>
2023-09-25 23:21:03 -04:00
Edouard CHIN
1fbd812c47
Add a public API for broadcasting logs:
- ## Context

  While working on https://github.com/rails/rails/pull/44695, I
  realised that Broadcasting was still a private API, although it’s
  commonly used. Rafael mentioned that making it public would require
  some refactor because of the original implementation which was hard
  to understand and maintain.

  ### Changing how broadcasting works:

  Broadcasting in a nutshell worked by “transforming” an existing
  logger into a broadcasted one.
  The logger would then be responsible to log and format its own
  messages as well as passing the message along to other logger it
  broadcasts to.

  The problem with this approach was the following:

  - Heavy use of metaprogramming.
  - Accessing the loggers in the broadcast wasn’t possible.
    Removing a logger from the broadcast either.
  - More importantly, modifying the main logger (the one that broadcasts
    logs to the others) wasn’t possible and the main source of
    misunderstanding.

    ```ruby
      logger = Logger.new(STDOUT)
      stderr_logger = Logger.new(STDER))
      logger.extend(AS::Logger.broadcast(stderr_logger))

      logger.level = DEBUG # This modifies the level on all other loggers
      logger.formatter = … # Modified the formatter on all other loggers
    ```

  To keep the contract unchanged on what Rails.logger returns, the new
  BroadcastLogger class implement duck typing with all methods
  that has the vanilla Ruby Logger class.

  It's a simple and boring PORO that keeps an array of all the loggers
  that are part of the broadcast and iterate over whenever a log is
  sent.
  Now, users can access all loggers inside the broadcast and modify
  them on the fly. They can also remove any logger from the broadcast
  at any time.

  ```ruby
  # Before

  stdout_logger = Logger.new(STDOUT)
  stderr_logger = Logger.new(STDER)
  file_logger = Logger.new(“development.log”)
  stdout_logger.extend(AS::Logger.broadcast(stderr_logger))
  stdout_logger.extend(AS::Logger.broadcast(file_logger))

  # After

  broadcast = BroadcastLogger.new(stdout_logger, stderr_logger, file_logger)
  ```

  I also think that now, it should be more clear for users that the
  broadcast sole job is to pass everything to the whole loggers in
  the broadcast. So there should be no surprise that all loggers in
  the broadcast get their level modified when they call
  `broadcast.level = DEBUG` .

  It’s also easier to wrap your head around more complex setup such
  as broadcasting logs to another broadcast:
  `broadcast.broadcast_to(stdout_logger, other_broadcast)`
2023-09-25 20:40:51 +00:00
Xavier Noria
8eed5083b7 Reword stuff related to config.autoload_lib 2023-09-21 21:14:03 +02:00
Jean-Francois Labbé
90d5a5c2ab [CI skip] Update rails new USAGE with specific version request 2023-09-21 20:00:49 +02:00
Guillermo Iguaran
a02444723e
Merge pull request #49325 from mattbrictson/bugs/fix-missing-concurrent-constant
Fix uninitialized constant error on Puma boot
2023-09-20 08:57:05 -07:00
Matt Brictson
39ccb97e3c
Fix uninitialized constant error on Puma boot
Before, using the default `puma/config.rb` generated by `rails new`,
Puma would fail to boot in production with this error:

```
./config/puma.rb:16:in `block in _load_from': uninitialized constant Puma::DSL::Concurrent (NameError)
	from ./config/puma.rb:16:in `fetch'
	from ./config/puma.rb:16:in `_load_from'
```

This was because `Concurrent.physical_processor_count` was being
referenced before the `Concurrent` constant was initialized.

Fix by requiring `concurrent-ruby` just before the `Concurrent` constant
is needed.

Fixes #49323
2023-09-20 06:54:30 -07:00
Guillermo Iguaran
3c7a8d7d8d
Merge pull request #49311 from paulreece/change_db_dockerfile
This enhancement automatically updates the Dockerfile to the desired db.
2023-09-19 22:16:50 -07:00
paulreece
ac9f08d1c3 This enhancement automatically updates the Dockerfile to the desired db when using db:system:change. 2023-09-19 15:33:36 -04:00
dhh
af20a14e3a Make example align with most common demo runs 2023-09-17 09:17:51 -07:00
Sam Ruby
1437ff7899 Sorry I didn't catch these the first time, but two more... 2023-09-16 15:22:21 -04:00
Sam Ruby
e21856f783 Consistency/semantics: BUN_VERSION vs bun-v
All the other VERSION ARGS in the Dockerfile are pure version numbers.
Any other additions are handled elsewhere.

Arguably, this is just cosmetic/foolish consistency, but it is a source
of subtle bugs.  For example, the fallback if `bun -version` fails is
defined here:

af1d77abfb/railties/lib/rails/generators/app_base.rb (L19)

Note the _lack_ of bun_v, which ultimately will cause the docker build
to fail.
2023-09-16 13:21:57 -04:00
Sam Ruby
48879ee332 eliminate extra blank lines in dockerfile template
The rule should be:
  * one blank line between "stanzas" or groups of lines
  * two blanks lines preceed FROM statements
2023-09-16 10:56:51 -04:00
Sean Doyle
32faee0e52 Action View: docs use application/ instead of shared/
Change mentions of `app/views/shared` in the guides to be
`app/views/application` instead. View partials rely on the same
[Template Inheritance][] as their template counterparts, so the guides
should encourage end-users to benefit from that inheritance.

> This makes `app/views/application/` a great place for your shared
> partials, which can then be rendered in your ERB as such:
>

```html+erb
<%# app/views/admin/products/index.html.erb %>
<%= render @products || "empty_list" %>

<%# app/views/application/_empty_list.html.erb %>
There are no items in this list <em>yet</em>.
```

To enforce that template resolution, this commit also replaces
references to `shared/` with `application/` in the Rails test suite.

[Template Inheritance]: https://guides.rubyonrails.org/layouts_and_rendering.html#template-inheritance
2023-09-15 12:06:22 -04:00
Petrik
5d31d33860 Make GeneratedAttribute work without ActiveRecord
If GeneratedAttribute is used in a project that doesn't require
ActiveRecord, it should still work.

Co-authored-by: Ryuta Kamizono <kamipo@gmail.com>
2023-09-15 10:02:46 +02:00
dhh
83f36d5390 Remove duplication from #49278 2023-09-14 15:15:08 -07:00
David Heinemeier Hansson
757861889d
Ignore env files (except templates) (#49278)
Help prevent security issues out of the box.
2023-09-14 14:53:27 -07:00
Akhil G Krishnan
0d3a4ca7e9
Add missing dollar sign for bash script [skip ci] 2023-09-14 17:48:20 +00:00
Petrik
99b1316fd9 Raise error when generating attribute with dangerous name
Generating a model with attributes named `hash` or `save` should raise
an error, instead of generating a migration with an invalid attribute.
2023-09-14 12:58:36 +02:00
fatkodima
e4206c64d9 Add changelog entry for profiling slow tests
The change was added in #49082.
[skip ci]
2023-09-13 21:41:50 +03:00
Ryuta Kamizono
bd4996bdfd
Merge pull request #49247 from koic/remove_redundant_blank_line_from_gemfile_of_new_app
Remove a redundant blank line from Gemfile of new app
2023-09-13 15:09:48 +09:00
Koichi ITO
f47d082bea Remove a redundant blank line from Gemfile of new app
## Motivation / Background

Continuous Integrating rubocop-rails_config after upgrading from Rails 7.0.7.2 to Rails 7.0.8 now fails:

```console
(snip)
rubocop --except=Style/StringLiterals,Style/FrozenStringLiteralComment .
cp ./test/fixture/.rubocop.yml rails_test/.rubocop.yml
cd rails_test
Inspecting 28 files
C...........................

Offenses:

Gemfile:71:1: C: [Correctable] Layout/EmptyLinesAroundBlockBody: Extra empty line detected at block body end.

28 files inspected, 1 offense detected, 1 offense autocorrectable
rake aborted!
```

https://github.com/toshimaru/rubocop-rails_config/actions/runs/6167995304/job/16739825926

Upon checking, redundant blank was added from version 7.0.8. This was `gem "webdrivers"` before 7.0.7.2.

### Rails 7.0.7.2

```console
$ ruby -v
ruby 3.3.0dev (2023-09-08T16:09:30Z master af5df9ee5e) [x86_64-darwin22]

$ cat Gemfile
# frozen_string_literal: true

source "https://rubygems.org"

gem "rails", "7.0.7.2"

$ bundle install
(snip)

$ bundle exec rails new example && cd $_
(snip)

% tail -n5 Gemfile
  # Use system testing [https://guides.rubyonrails.org/testing.html#system-testing]
  gem "capybara"
  gem "selenium-webdriver"
  gem "webdrivers"
end
```

### Rails 7.0.8

```console
$ cat Gemfile
# frozen_string_literal: true

source "https://rubygems.org"

gem "rails", "7.0.8"

$ bundle install
(snip)

$ bundle exec rails new example && cd $_
(snip)

% tail -n5 Gemfile
  # Use system testing [https://guides.rubyonrails.org/testing.html#system-testing]
  gem "capybara"
  gem "selenium-webdriver"

end
```

This is reproduced with Rails 7.0.8, Rails 7.1.0.beta1 and the main branch.

I understand this might not be of utmost importance, but I would appreciate
it if it could be backported to the Rails 7.0 branch, if possible.

## Detail

The blank line is filled in by https://github.com/rails/rails/pull/48847.
This PR removes the redundant blank line from Gemfile of new app.
2023-09-13 14:47:45 +09:00
Shouichi Kamiya
51ac8b9f6f Enable Minitest/LiteralAsActualArgument
There are assertions that expected/actual arguments are passed in the
reversed order by mistake. Enabling the LiteralAsActualArgument rule
prevents this mistake from happening.

The existing tests were auto-corrected by rubocop with a bit of
indentation adjustment.

Co-authored-by: Jonathan Hefner <jonathan@hefner.pro>
2023-09-13 10:09:32 +09:00
Rafael Mendonça França
699dfdb426
Preparing for 7.1.0.beta1 release 2023-09-13 00:36:01 +00:00
Jason Meller
274bc97d63
Add Bun support (#49241)
* Add Bun support to `rails new -j` generator

* Add additional generation consideration for Bun

* Use development gems to test the whole workflow

* Remove custom gems from local testing

* Revert lock

* Revert errant custom gem declaration

* Fix linting errors

* Fix remnants of bad merge

* Always use latest bun

* Update actioncable/lib/rails/generators/channel/channel_generator.rb

Co-authored-by: Cadu Ribeiro <mail@cadu.dev>

* Update guides/source/working_with_javascript_in_rails.md

Co-authored-by: Rafael Mendonça França <rafael@franca.dev>

* Only use the latest bun if nothing is specified

* Hardcode known good version

---------

Co-authored-by: Cadu Ribeiro <mail@cadu.dev>
Co-authored-by: Rafael Mendonça França <rafael@franca.dev>
2023-09-12 16:55:27 -04:00
Rafael Mendonça França
b67bdfb803
Merge pull request #49215 from andyw8/andyw8/update-require_master_key-description
Update description for `require_master_key` setting
2023-09-11 21:23:53 -04:00
Rafael Mendonça França
d469436074
Merge pull request #49229 from duduribeiro/make-bin-setup-work-with-bun
Make bin/setup work with bun
2023-09-11 21:21:38 -04:00
Cadu Ribeiro
9a98235ced Make bin/setup work with bun 2023-09-11 21:11:06 -03:00
Hartley McGuire
7fd0aab4b8
Fixup links, code tags in Rails::Paths::Root 2023-09-11 19:00:15 -04:00
Andy Waite
4e76a97174 Update description for require_master_key setting 2023-09-10 12:32:53 -04:00
Alex Ghiculescu
ff6881d2b2
Remove old raise_on_missing_translations behaviour
ref: https://github.com/rails/rails/pull/47105#issuecomment-1400843060

Removes the old `raise_on_missing_translations` accessors, that used to live [here](fee61e3abc/actionpack/lib/abstract_controller/translation.rb (L7)) and [here](5c835bd669/actionview/lib/action_view/helpers/translation_helper.rb (L15)).

Closes https://github.com/rails/rails/pull/45361
2023-09-09 19:59:49 +00:00
Sam Ruby
5c3cd36626 Exclude pids, storage directories in dockerignore
Fixes #49210
2023-09-09 10:17:00 -04:00
Akhil G Krishnan
57425e5353
Remove unused method from secret test 2023-09-09 08:14:06 +00:00
Jonathan Hefner
4986cfb26e
Merge pull request #49141 from ghiculescu/declarative-specs-2
Fix more bugs in declarative specs filter
2023-09-06 21:47:59 -05:00
Alex
0a8e5374b9 Simplify normalization of regexp test filters
Follow-up to #47942.

This commit simplifies the normalization of regexp test filters.
Instead of modifying a given regexp to match a union of whitespace and
underscores, the regexp is unioned with the underscore-normalized
version of itself.  This allows filters that include escaped spaces,
such as `/foo\ bar/`.

This commit also fixes `Rails::LineFiltering#run` such that
normalization isn't reapplied for every test suite.  Thus
`normalize_declarative_test_filter` is no longer required to be
idempotent.

Co-authored-by: Jonathan Hefner <jonathan@hefner.pro>
2023-09-06 21:30:51 -05:00
Akhil G Krishnan
59854da1bf
Removed Webpacker files 2023-09-06 17:11:58 +00:00
Javier Aranda
ea351f0f49
Do not generate configuration for sprockets if propshaft is used 2023-09-05 10:11:45 +02:00
Sean Doyle
e85a3ec624
Change has_secure_token default to on: :initialize
Follow-up to [#47420][]

With the changes made in [#47420][], `has_secure_token` declarations can
be configured to execute in an `after_initialize` callback. This commit
proposed a new Rails 7.1 default: generate all `has_secure_token` values
when their corresponding models are initialized.

To preserve pre-7.1 behavior, applications can set
`config.active_record.generate_secure_token_on = :create`.

By default, generate the value when the model is initialized:

```ruby
class User < ApplicationRecord
  has_secure_token
end

record = User.new
record.token # => "fwZcXX6SkJBJRogzMdciS7wf"
```

With `config.active_record.generate_secure_token_on = :create`, generate
the value when the model is created:

```ruby
 # config/application.rb
config.active_record.generate_secure_token_on = :create

 # app/models/user.rb
class User < ApplicationRecord
  has_secure_token on: :create
end

record = User.new
record.token # => nil
record.save!
record.token # => "fwZcXX6SkJBJRogzMdciS7wf"
```

[#47420]: https://github.com/rails/rails/pull/47420

Co-authored-by: Hartley McGuire <skipkayhil@gmail.com>
2023-09-01 20:17:22 +00:00
Jean Boussier
a7fdc1cdb4 Optimize ActiveRecord::LogSubscriber#query_source_location
`Kernel#caller` has linear performance based on how deep the
stack is. While this is a development only feature, it can end
up being quite slow.

Ruby 3.2 introduced `Thread.each_caller_location`, which lazily
yield `Backtrace::Location` objects.

Ref: https://bugs.ruby-lang.org/issues/16663

This is perfect for this use case as we are searching for the
closest frame that matches a pattern, saving us from collecting
the entire backtrace.
2023-08-31 11:56:55 +02:00
fatkodima
14d9b3e07e Add ability to show slow tests to the test runner 2023-08-30 00:08:56 +03:00
Wojciech Wnętrzak
b872b36e0c
Rename MRSK to Kamal
https://github.com/basecamp/kamal/releases/tag/v0.16.0

[ci skip]
2023-08-28 09:42:15 +02:00
Xavier Noria
b16adcd4e4 Generate config.autoload_lib(...) for new apps 2023-08-25 09:22:25 +02:00
Akhil G Krishnan
0f7f9e3d5e [skip ci] Moved sh to bash and added missing $ 2023-08-24 18:48:20 +05:30
Aaron Patterson
3338621efa
Use a temporary file for storing unencrypted files while editing
When we're editing the contents of encrypted files, we should use the
`Tempfile` class because it creates temporary files with restrictive
permissions.  This prevents other users on the same system from reading
the contents of those files while the user is editing them.

[CVE-2023-38037]
2023-08-22 10:23:15 -07:00
Shouichi Kamiya
b8decf79d8 Add an option to start rails console in sandbox mode by default
To avoid accidental writing to the production database, I always start
rails console in sandbox mode. I only start rails console in non-sandbox
mode when I'm sure I want to write to the production database.

`sandbox_by_default` option is added to start rails console in sandbox
mode by default. With this option turned on, `--no-sandbox` must be
specified to start rails in non-sandbox mode.

Note that this option is ignored when rails environment is development
or test.
2023-08-22 09:23:52 +09:00
Guillermo Iguaran
4ec3a986d5
Merge pull request #48959 from skipkayhil/hm-clean-filters-requires
Remove uneeded requires of core_ext/string/filters
2023-08-18 16:03:44 -07:00
Hartley McGuire
2d61a206f4
Fix served_url printed when using Puma & Rack 3
This `#use_puma?` check was [introduced][1] because Rails could
potentially display the wrong server URL in development if another host
or port is configured in `config/puma.rb`.

However, in Rack 3 the the name of the server class changed from
`Rack::Handler::Puma` to `Rackup::Handler::Puma`, which means that the
served_url is being logged again.

This commit fixes the check to accept either version of the class.
Additionally, puma was updated in Gemfile.lock because Puma 6.0.x prints
a deprecation warning about Rack::Handler that's fixed in 6.1.0.

[1]: 29648ff60e66c674b3cc49151df15dc100ffb4f4
2023-08-17 20:01:19 -04:00