Commit Graph

92266 Commits

Author SHA1 Message Date
Gannon McGibbon 1b40bfc8ff Deprecate hash key path mapping
Drawing routes with has keys complicates route drawing enough to warrant
deprecation. Transitioning the routing mapper to use keywords
would result in a 1.25-1.5x improvement in speed, and it would be
substantially easier to do if we drop this feature.

```ruby
get "/users" => "users#index"
post "/logout" => :sessions
mount MyApp => "/my_app"

get "/users", to: "users#index"
post "/logout", to: "sessions#logout"
mount MyApp, at: "/my_app"
```
2024-07-31 01:41:46 -05:00
John Hawthorn 2bb82965a6
Merge pull request #52448 from jhawthorn/symbol_as_json
Use name for Symbol#as_json
2024-07-30 14:28:19 -07:00
Xavier Noria 4b9e874cce Still more CHANGELOG formatting 2024-07-30 21:39:41 +02:00
Xavier Noria 1f30ec20f1 Revise formatting in railties/CHANGELOG.md
Main motivation here was to fix the listings, they lacked markup.
Since I was on it, I edited the H1 Markdown headers, these are
not really used in individual CHANGELOG entries.
2024-07-30 21:37:30 +02:00
Xavier Noria 9262ca443a
Merge pull request #52454 from rails/fxn/sript-edits
Edits to the scripts entry in CHANGELOG
2024-07-30 21:25:16 +02:00
Xavier Noria a71ec56343 Edits to the scripts entry in CHANGELOG 2024-07-30 21:18:00 +02:00
David Heinemeier Hansson 0e65871dd6
lib/assets is too rare of a use case to warrant a default directory (#52447)
* lib/assets is too rare of a use case to warrant a default directory

Either these assets are part of your app, and should be in app/assets,
or you're getting them from a vendor, and they should be in
vendor/assets.

* Fix test
2024-07-30 08:14:40 -07:00
Jean Boussier 2038c9d46a
Merge pull request #52193 from p8/activestorage/variable-error
Improve ActiveStorage::InvariableError message
2024-07-30 12:35:59 +02:00
Petrik 240cbd9ca5 Improve InvariableError, UnpreviewableError and UnrepresentableError message
Mention which blob can't be transformed/previewed and what content_type
it has.

Co-authored-by: zzak <zzakscott@gmail.com>
2024-07-30 12:27:44 +02:00
Jean Boussier f376782296
Merge pull request #50838 from fractaledmind/ar-fix-sqlite-table-structure-parsing
Fix SQLite table definition parsing bug to handle commas in default function definitions
2024-07-30 12:20:05 +02:00
John Hawthorn 103bce2d13 Use name for Symbol#as_json 2024-07-29 23:49:58 -07:00
Jean Boussier 3acf87e26d
Merge pull request #52426 from shouichi/raise-on-missing-translations
Change ActiveModel human_attribute_name to raise an error
2024-07-29 23:59:46 +02:00
Jean Boussier 042f2d7d72
Merge pull request #52444 from dijonkitchen/patch-1
[ci skip] docs: use `as_json` per method instead of `to_json`
2024-07-29 23:55:34 +02:00
Shouichi Kamiya f6c0a35b1b Change ActiveModel human_attribute_name to raise an error
When config.i18n.raise_on_missing_translations = true, controllers and
views raise an error on missing translations. However, models won't.
This commit changes models to raise an error when
raise_on_missing_translations is true

Co-authored-by: Alex Ghiculescu <alex@tanda.co>
Co-authored-by: Jean Boussier <jean.boussier@gmail.com>
2024-07-29 23:47:34 +02:00
Jean Boussier bba9cbae2f
Merge pull request #52384 from fatkodima/custom-batch-columns
Support batching using custom columns
2024-07-29 23:43:04 +02:00
JC (Jonathan Chen) 23299757ed
docs: use `as_json` per method instead of `to_json`
The docs usage should align with the method. 

Here are the examples:
```
[29] pry(main)> ActiveSupport::JSON::Encoding.use_standard_json_time_format = true
=> true
[30] pry(main)> Time.utc(2005,2,1,15,15,10).in_time_zone("Hawaii").to_json
=> "\"2005-02-01T05:15:10.000-10:00\""
[31] pry(main)> Time.utc(2005,2,1,15,15,10).in_time_zone("Hawaii").as_json
=> "2005-02-01T05:15:10.000-10:00"
[32] pry(main)> ActiveSupport::JSON::Encoding.use_standard_json_time_format = false
=> false
[33] pry(main)> Time.utc(2005,2,1,15,15,10).in_time_zone("Hawaii").as_json
=> "2005/02/01 05:15:10 -1000"
[34] pry(main)> Time.utc(2005,2,1,15,15,10).in_time_zone("Hawaii").to_json
=> "\"2005/02/01 05:15:10 -1000\""
```
2024-07-29 16:00:49 -04:00
David Heinemeier Hansson d5faea5b8f
Add bin/dev by default (#52433)
* Add bin/dev by default

Then we have a uniform way of starting dev mode whether someone is using
jsbundling or importmaps.

* Also generated here
2024-07-29 12:09:37 -07:00
Jean Boussier ecff81463d
Merge pull request #52443 from Shopify/optimize-fast_string_to_time
Optimize `fast_string_to_time`
2024-07-29 21:03:34 +02:00
Jean Boussier 217104ec70 Optimize `fast_string_to_time`
It's slower than it needs to because it contains a workaround for
a bug affecting early Ruby 3.2 releases.

It also matches against a regexp which isn't necessary given
that starting in Ruby 3.2, `Time.new(str)` is strict enough
for this purpose.

```
ruby 3.3.3 (2024-06-12 revision f1c7b6f435) +YJIT [arm64-darwin23]
Warming up --------------------------------------
              bugged   265.827k i/100ms
                good   394.774k i/100ms
Calculating -------------------------------------
              bugged      2.759M (± 5.8%) i/s -     13.823M in   5.031296s
                good      4.128M (± 7.8%) i/s -     20.528M in   5.010538s

Comparison:
              bugged:  2758945.6 i/s
                good:  4128323.9 i/s - 1.50x  faster
```

```ruby
require "bundler/inline"

gemfile(true) do
  source "https://rubygems.org"

  gem "benchmark-ips"
end

require 'benchmark/ips'

ISO_DATETIME = /
  \A
  (\d{4})-(\d\d)-(\d\d)(?:T|\s)            # 2020-06-20T
  (\d\d):(\d\d):(\d\d)(?:\.(\d{1,6})\d*)?  # 10:20:30.123456
  (?:(Z(?=\z)|[+-]\d\d)(?::?(\d\d))?)?     # +09:00
  \z
/x

def old(string)
  return unless ISO_DATETIME.match?(string)

  ::Time.at(::Time.new(string, in: "UTC"))
end

def fast(string)
  return unless string.include?("-") #  Time.new("1234") # => 1234-01-01 00:00:00

  ::Time.new(string, in: "UTC")
end

str = "2024-01-01T12:43:13"
Benchmark.ips do |x|
  x.report("bugged") { old(str) }
  x.report("good") { fast(str) }
  x.compare!(order: :baseline)
end
```
2024-07-29 20:35:08 +02:00
David Heinemeier Hansson e4f67a6bff We dont actually need this
Not worth the complication. Let them login again. It doesn't matter.
2024-07-29 10:51:29 -07:00
Mike Dalessio eaa4052f69
Authentication generator supports an `--api` flag (#52442)
and the sessions view template has been moved into an erb generator so
that gems like tailwindcss-rails can provide a specialized template.
2024-07-29 10:48:11 -07:00
Jean Boussier 4294d71c8a
Merge pull request #52428 from Shopify/refactor-adapters 2024-07-29 15:59:50 +02:00
Jean Boussier 8078ebc26d Simplify some `perform_query` implementation
Inline simple operations like reseting the timezone.
2024-07-29 15:29:41 +02:00
Jean Boussier b57dcec6fb Refactor Active Record connection adapters further
A `raw_execute` implementation is now provided, instead adapters
have to implement `perform_query`.

It's a much simpler method that no longer need to concern itself
with Active Support notifications nor calling `with_raw_connection`.
2024-07-29 15:29:41 +02:00
Jean Boussier f9f7debc26 Refactor `PostgresqlAdapter#raw_execute` to be less unique
The postgres adapter used to be more complex than the others to
be able to pass the prepared statement key to the `log` method.

If we instead add it to the payload later, we can simplify the method
further and it opens the door to refactor `log` and `with_raw_connection`
out of `raw_execute`.
2024-07-29 15:29:41 +02:00
Jean Boussier fd24e5bfc9 Refactor Active Record adapters to have a similar internal interface
Adapters have very inconsistent internal APIs to perform queries.

This refactoring tries to improve consistency with a common provite
API for all of them.

Abstract methods:

- `raw_execute`: the only method where an adapter should perform
  a query. It returns a native, adapter specific result object.
  Does not apply query transformations. Does not check for writes.

- `cast_result`: receives the native result object and returns
  a generic `ActiveRecord::Result`.

- `affected_rows`: receives the native result object and returns
  the number of affected rows.

By just implementing these 3 methods all adapters automatically get:

- `raw_exec_query`: same as `raw_execute` but returns an `ActiveRecord::Result`.

- `internal_exec_query`: same as `raw_exec_query` but check for writes and
  apply query transformations.

- `internal_execute`: same as `internal_exec_query` but retuns the native,
  adapter specific, result object.

With this increased conisistency, we can now reduce the ammount of
duplicated code in every adapter. There's some room for futher
improvments but I tried to not go too far all at once.

Also previously some adapters had a block based query interface that
allowed to eagerly clear the native result object.

It may make sense to bring that capability back in a consistent
way, but short term I opted for consistency.
2024-07-29 15:29:41 +02:00
Jean Boussier 0b3320bcd5
Merge pull request #52438 from Shopify/fix-delegate-to-missing
Fix `delegate_missing_to allow_nil: true` when called with implict self
2024-07-29 10:16:36 +02:00
Jean Boussier 8c3afef912 Fix `delegate_missing_to allow_nil: true` when called with implict self
Fix: https://github.com/rails/rails/issues/52429

The previous implementation assumed `NoMethodError` would be raised
when calling `super`, but that's not always true.

If the receiver is an implicit self, the raised error will be
`NameError`.

It's better not to rely on exceptions for this anyways.
2024-07-29 09:57:50 +02:00
Jean Boussier 077d6e89c7
Merge pull request #52436 from chaadow/fix_collection_checkboxes 2024-07-29 07:30:39 +02:00
David Heinemeier Hansson d1cefb48d1 Update CHANGELOG from the rename 2024-07-28 15:44:58 -07:00
chaadow 16809c0d97 Add missing alias for collection_checkboxes
Related to #52432
2024-07-29 00:25:59 +02:00
David Heinemeier Hansson f50bfbab29
Rename sessions generator to authentication generator (#52435)
Sessions is only one part of the equation. We also have users. And will
have other elements too.
2024-07-28 15:25:19 -07:00
David Heinemeier Hansson 9c8716a27c
Set memory store to be default in development mode (#52434)
Otherwise our new rate limit feature won't be testable out-of-the-box in
development mode.
2024-07-28 15:05:03 -07:00
David Heinemeier Hansson 1dd37e0193 Fix the redirect
Need to attempt to resume session to know whether we are authenticated.
2024-07-28 14:57:38 -07:00
Jean Boussier c01ee683aa
Merge pull request #52432 from byroot/checkbox
Rename check_box in checkbox
2024-07-28 13:40:25 +02:00
Jean Boussier 038a314ded Rename check_box in checkbox
But add aliases for backward compatibility.

Fix: https://github.com/rails/rails/issues/52430
2024-07-28 13:35:45 +02:00
Hartley McGuire 9826d743ae
Merge pull request #51759 from trebeil/patch-1
Update active_storage_overview.md [ci skip]
2024-07-27 15:46:39 +00:00
Hartley McGuire 1b3f4a2dc0
Reflow Active Storage transforms section [ci-skip]
Both "optional arguments" and "migrating processors" seem too specific
for where they were previously located within the section. Both ideas
are more complicated/processor specific, but are located very early on
when the ideas should be more simple/introductory.

This commit reorders the paragraphs a bit to improve the section's flow.
Now, the most basic examples are presented first, then the idea of
processors and what they have in common, and finally the more advanced
options and how the processors differ.
2024-07-27 11:31:21 -04:00
trebeil 8887b65602
Update active_storage_overview.md [ci-skip]
Adds information about how to pass additional arguments to transformations.

Co-authored-by: Vipul A M <vipul@hey.com>
2024-07-27 10:51:39 -04:00
fatkodima fd52a754f2 Support batching using custom columns 2024-07-27 11:55:52 +03:00
Jean Boussier 7c1db0dfab
Merge pull request #52325 from northeastprince/sqlite-dump--nosys
Exclude system tables from SQLite schema dumps
2024-07-27 09:53:53 +02:00
Jean Boussier 0e00fe4236 Merge pull request #52416 from spickermann/fix-nested-error-for-singular-associations
[Rails 7.2.0.beta3] Fix bug with indexed nested error for singular associations
2024-07-27 09:37:00 +02:00
Gannon McGibbon 92d9231627
Merge pull request #52409 from Shopify/multiple_path_mapping_deprecation
Deprecate multiple path route mapping
2024-07-26 22:42:17 -05:00
Rafael Mendonça França 27f3fa72a3
Merge pull request #52417 from seanpdoyle/active-model-assigned-unknown-attribute
Introduce `ActiveModel::AttributeAssignment#attribute_writer_missing`
2024-07-26 15:48:16 -07:00
John Hawthorn dbbee5f7c3
Merge pull request #52418 from jhawthorn/revert_exists
Revert change to exists? from #51987
2024-07-26 14:01:50 -07:00
John Hawthorn 79b80b2845
Merge pull request #52424 from Earlopain/drop-hash-except-core-ext
Drop Hash `except` core extension
2024-07-26 14:00:29 -07:00
Sean Doyle 20d156d489 Introduce `ActiveModel::AttributeAssignment#attribute_writer_missing`
Provide instances with an opportunity to gracefully handle assigning to
an unknown attribute:

```ruby
class Rectangle
  include ActiveModel::AttributeAssignment

  attr_accessor :length, :width

  def attribute_writer_missing(name, value)
    Rails.logger.warn "Tried to assign to unknown attribute #{name}"
  end
end

rectangle = Rectangle.new
rectangle.assign_attributes(height: 10) # => Logs "Tried to assign to unknown attribute 'height'"
```

By default, classes that do not override `#attribute_writer_missing`
will raise an `ActiveModel::UnknownAttributeError`.

The `attribute_writer_missing` aims to mimic the naming of
`BasicObject#method_missing`. There is also an
[ActiveModel::AttributeMethods#attribute_missing][] method, but that
pertains to attribute _access_.

[ActiveModel::AttributeMethods#attribute_missing]: https://edgeapi.rubyonrails.org/classes/ActiveModel/AttributeMethods.html#method-i-attribute_missing
2024-07-26 21:57:57 +01:00
John Hawthorn 3b6af165df Revert "Merge pull request #51987 from fatkodima/exists-and-loaded2"
This reverts commit c9075e3643, reversing
changes made to a14eb2dc84.
2024-07-26 13:23:55 -07:00
Earlopain 8d98a52eef
Drop Hash `except` core extension
Rails 8.0 will be Ruby 3.1 or greater only
`except` natively got added in Ruby 3.0 so this is dead code now
2024-07-26 17:39:26 +02:00
Jean Boussier def0397e59
Merge pull request #50371 from fractaledmind/ar-sqlite-immediate-transactions
Ensure SQLite transaction default to IMMEDIATE mode
2024-07-26 09:15:38 +02:00