Numericality validations for aliased attributes are not able
to get the value of the attribute before type cast because
activerecord was trying to get the value of the attribute based
on attribute alias name and not the original attribute name.
Example of validation which would pass even if a invalid value
would be provided
class MyModel < ActiveRecord::Base
validates :aliased_balance, numericality: { greater_than_or_equal_to: 0 }
end
If we instantiate MyModel like bellow it will be valid because
when numericality validation runs it will not be able to get the
value before type cast, so it uses the type casted value
which will be `0.0` and the validation will match.
subject = MyModel.new(aliased_balance: "abcd")
subject.valid?
But if we declare MyModel like this
class MyModel < ActiveRecord::Base
validates :balance, numericality: { greater_than_or_equal_to: 0 }
end
and assign "abcd" value to `balance` when the validations
run the model will be invalid because activerecord will be able
to get the value before type cast.
With this change `read_attribute_before_type_cast` will be able to
get the value before type cast even when the attr_name is an
attribute_alias.
The current Rails documentation has a frames based implementation. This
prevents deep linking to documentation and removes navigation if the page
is opened without frames.
We can keep the same layout with a css based implementation.
Turbolinks is used to persisted the navigation/search bar across
requests.
In https://github.com/rails/rails/pull/37919, support
for rendering objects that respond_to render_in in
controllers was added. However, the implementation
did not support layouts.
This change updates the implementation from #37919
to more closely match the rest of the
ActionView::Template classes, enabling the use of layouts.
Co-authored-by: Felipe Sateler <fsateler@gmail.com>
Serialized attributes stored in BLOB columns will be loaded
with the `ASCII-8BIT` (AKA BINARY) encoding.
So unless the serialized payload is pure ASCII, they need
to have the same internal encoding to be properly compared.
Since the serializer have no way to know how the string will
be stored, it's up to the column type to properly set the
encoding.
Random failures due to active connection checking within the
assert_no_changes block.
Failure:
MigrationTest#test_with_advisory_lock_closes_connection [/rails/activerecord/test/cases/migration_test.rb:947]:
--- expected
+++ actual
@@ -1 +1 @@
-["SELECT 1", "SELECT 1"]
+["SELECT 1", "SELECT 1", "SELECT 1"]
This commit scopes the query down further to ensure that the advisory
unlock query is not left in pg_stat_activity which is an indication that
the connection pool was not disconnected.
This shifts the primary focus from the bare `select_*` helpers to the
equivalent `FormBuilder#*_select` helpers. It also links all covered
helpers to their API documentation.
`Minitest.plugin_rails_init` sets `Minitest.backtrace_filter` to
`Rails.backtrace_cleaner` right before tests are run, overwriting the
value set in test_helper.rb.
`Rails.backtrace_cleaner` silences backtrace lines that do not start
with `Rails.root` followed by e.g. "lib/" or "test/". Thus when
`Rails.root` is a subdirectory of the project directory -- for example,
when testing a plugin that has a dummy app -- all lines of the backtrace
are silenced.
This commit adds a fallback such that when all backtrace lines are
silenced, the original `Minitest.backtrace_filter` is used instead.
Additionally, this commit refactors and expands existing test coverage.