Commit Graph

80041 Commits

Author SHA1 Message Date
Jean Boussier
0beae875ee
Merge pull request #42076 from Shopify/document-as-cache-upgrade
Document the new Active Support cache format
2021-04-26 12:14:56 +02:00
Jean Boussier
fbf3bf8cac Document the new Active Support cache format 2021-04-26 11:20:59 +02:00
Sean Doyle
68bb2650d5 Action Text: forward form: option to hidden input
Trix's `<trix-editor>` doesn't support the [form][] property like
`<textarea>` or other form fields.

For example, consider the following HTML and event listener:

```html
<form action="/articles" method="post">
  <textarea name="content"></textarea>

  <button type="submit">Save</button>
</form>

<script>
  addEventListener("keydown", ({ key, metaKey, target }) => {
    if (target.form && key == "Enter" && (metaKey || ctrlKey)) {
      form.requestSubmit()
    }
  })
</script>
```

The `target` (an instance of `HTMLTextAreaElement` relies on the
[HTMLTextAreaElement.form][] property for access to its associated
`<form>`. While it's usually equivalent to `target.closest("form")`,
that isn't always the case. Declaring a `[form]` attribute with another
`<form>` element's `[id]` value can associate a field to a `<form>` that
is _not an ancestor_. That means that the event listener from above
would continue to work with this HTML:

```html
<textarea name="content" form="new_article"></textarea>

<!-- elsewhere -->
<form id="new_article" action="/articles" method="post">
  <button type="submit">Save</button>
</form>
```

Unfortunately, if the `<textarea>` element were replaced with a
`<trix-editor>`, the event listener's reliance on accessing the form as
a property would break, since the `<trix-editor>` custom element doesn't
declare that property. There is currently a pull request
([basecamp/trix#899][]) to add support for accessing the `form` as a
property of the `<trix-editor>` element.

The [feedback][] provided on that pull request suggests that we
implement the `form` property by delegating to the `<input
type="hidden">` element. Currently, `<input type="hidden">` elements
constructed by Action Text helpers cannot declare the `[form]`
attribute.

This commit adds support by special-casing the `options[:form]` key
within `ActionText::TagHelper#rich_text_area_tag`.

[form]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLTextAreaElement#properties
[basecamp/trix#899]: https://github.com/basecamp/trix/pull/899#discussion_r618543357
[feedback]: https://github.com/basecamp/trix/pull/899#discussion_r618543357
2021-04-25 20:27:24 -04:00
Ryuta Kamizono
95b45c826d Change send back to public_send
It was accidentally changed in #40095.
2021-04-26 03:23:51 +09:00
Ryuta Kamizono
052f307b23
Merge pull request #42070 from shioyama/changes_applied_public
Make changes_applied public again
2021-04-25 23:31:45 +09:00
Chris Salzberg
883292fdca
Make changes_applied public again
This was (accidentally?) made private, whereas previously it was public.
2021-04-25 22:58:46 +09:00
Jean Boussier
ac3910791d
Merge pull request #42066 from abhaynikam/minor-issues-in-comparsion-validator
Fixes a typo nor -> or in ComparisonValidator exception message
2021-04-25 13:13:39 +02:00
Ryuta Kamizono
2d040e756e Fix typo s/PostgresSQL/PostgreSQL/ [ci skip] 2021-04-25 20:09:39 +09:00
Ryuta Kamizono
90db24436a Fix typo s/limitions/limitations/ [ci skip] 2021-04-25 20:04:57 +09:00
Jean Boussier
18db06286a
Merge pull request #42025 from Shopify/optimized-entry-serialization-2
Implement an optimized Cache::Entry coder
2021-04-25 12:22:17 +02:00
Jean Boussier
3b71f3eb68 Implement an optimized Cache::Entry coder
Active Support's cache have for long been limited because
of its format. It directly serialize its `Entry` object with
`Marshal`, so any internal change might break the format.

The current shortcommings are:

  - The minimum entry overhead is quite ridiculous:
    `Marshal.dump(ActiveSupport::Cache::Entry.new("")).bytesize # => 107`
  - Only the internal `value` is compressed, but unless it's a String, to do so
    it first need to be serialized. So we end up with `Marshal.dump(Zlib.deflate(Marshal.dump(value)))`
    which is wasteful.
2021-04-25 08:27:58 +02:00
Eugene Kenny
79744bc335 Fix fixture tests that replace connection handler
These tests have been failing intermittently since
054e19d08638e64fa9eacc9be32fb7fde4e7415c was merged.

They replace the connection handler during setup, but before that can
happen the existing handler's pool configuration has already been saved
by `setup_shared_connection_pool`. Later when the test calls
`teardown_shared_connection_pool`, it tries to restore connection pools
that do not exist in the new handler and blows up.

We can avoid this problem by calling `teardown_shared_connection_pool`
to clear the saved pools before replacing the connection handler.
2021-04-25 01:27:06 +01:00
Abhay Nikam
0b0b22a46a Fixes a typo and wordsmithing in the exception message. Typo: nor -> or 2021-04-24 21:10:24 +05:30
Ryuta Kamizono
3c5cbe8401
Merge pull request #42063 from ashiksp/comparison-validation-tests
Added more test coverage for comparison validator.
2021-04-25 00:06:58 +09:00
Ryuta Kamizono
c0c77e28ad Enable Layout/EndOfLine to prevent \r\n is included in the future
Follow up to a1afc7726b3f9a59eb2dbc21fbd7aa59927cc889.
2021-04-24 23:59:19 +09:00
Ashik Salman
b0241f300c Added more test coverage for comparison validator. 2021-04-24 19:36:35 +05:30
Ryuta Kamizono
aa7a8db604 Fix numericality validator :in with invalid args to raise ArgumentError 2021-04-24 14:35:35 +09:00
Ryuta Kamizono
f83dbe358e Fix error message on comparison validator 2021-04-24 14:26:08 +09:00
Ryuta Kamizono
a1afc7726b Convert \r\n to \n 2021-04-24 14:10:18 +09:00
Ryuta Kamizono
8a23c85f6e Fix "uninitialized constant ActiveModel::Validations::NumericalityValidator::Comparability (NameError)"
Somehow it isn't caused on CI, but it consistently causes on locally.

```
% bin/test -w
/Users/kamipo/src/github.com/rails/rails/activemodel/lib/active_model/validations.rb:85: warning: method redefined; discarding old validates_each
/Users/kamipo/src/github.com/rails/rails/activemodel/lib/active_model/validations.rb:85: warning: previous definition of validates_each was here
/Users/kamipo/src/github.com/rails/rails/activemodel/lib/active_model/validations.rb:89: warning: already initialized constant ActiveModel::Validations::ClassMethods::VALID_OPTIONS_FOR_VALIDATE
/Users/kamipo/src/github.com/rails/rails/activemodel/lib/active_model/validations.rb:89: warning: previous definition of VALID_OPTIONS_FOR_VALIDATE was here
/Users/kamipo/src/github.com/rails/rails/activemodel/lib/active_model/validations.rb:152: warning: method redefined; discarding old validate
/Users/kamipo/src/github.com/rails/rails/activemodel/lib/active_model/validations.rb:152: warning: previous definition of validate was here
/Users/kamipo/src/github.com/rails/rails/activemodel/lib/active_model/validations.rb:192: warning: method redefined; discarding old validators
/Users/kamipo/src/github.com/rails/rails/activemodel/lib/active_model/validations.rb:192: warning: previous definition of validators was here
/Users/kamipo/src/github.com/rails/rails/activemodel/lib/active_model/validations.rb:234: warning: method redefined; discarding old clear_validators!
/Users/kamipo/src/github.com/rails/rails/activemodel/lib/active_model/validations.rb:234: warning: previous definition of clear_validators! was here
/Users/kamipo/src/github.com/rails/rails/activemodel/lib/active_model/validations.rb:254: warning: method redefined; discarding old validators_on
/Users/kamipo/src/github.com/rails/rails/activemodel/lib/active_model/validations.rb:254: warning: previous definition of validators_on was here
/Users/kamipo/src/github.com/rails/rails/activemodel/lib/active_model/validations.rb:270: warning: method redefined; discarding old attribute_method?
/Users/kamipo/src/github.com/rails/rails/activemodel/lib/active_model/validations.rb:270: warning: previous definition of attribute_method? was here
/Users/kamipo/src/github.com/rails/rails/activemodel/lib/active_model/validations.rb:275: warning: method redefined; discarding old inherited
/Users/kamipo/src/github.com/rails/rails/activemodel/lib/active_model/validations.rb:275: warning: previous definition of inherited was here
/Users/kamipo/src/github.com/rails/rails/activemodel/lib/active_model/validations.rb:283: warning: method redefined; discarding old initialize_dup
/Users/kamipo/src/github.com/rails/rails/activemodel/lib/active_model/validations.rb:283: warning: previous definition of initialize_dup was here
/Users/kamipo/src/github.com/rails/rails/activemodel/lib/active_model/validations.rb:301: warning: method redefined; discarding old errors
/Users/kamipo/src/github.com/rails/rails/activemodel/lib/active_model/validations.rb:301: warning: previous definition of errors was here
/Users/kamipo/src/github.com/rails/rails/activemodel/lib/active_model/validations.rb:373: warning: method redefined; discarding old invalid?
/Users/kamipo/src/github.com/rails/rails/activemodel/lib/active_model/validations.rb:373: warning: previous definition of invalid? was here
/Users/kamipo/src/github.com/rails/rails/activemodel/lib/active_model/validations.rb:382: warning: method redefined; discarding old validate!
/Users/kamipo/src/github.com/rails/rails/activemodel/lib/active_model/validations.rb:382: warning: previous definition of validate! was here
/Users/kamipo/src/github.com/rails/rails/activemodel/lib/active_model/validations.rb:405: warning: method redefined; discarding old run_validations!
/Users/kamipo/src/github.com/rails/rails/activemodel/lib/active_model/validations.rb:405: warning: previous definition of run_validations! was here
/Users/kamipo/src/github.com/rails/rails/activemodel/lib/active_model/validations.rb:410: warning: method redefined; discarding old raise_validation_error
/Users/kamipo/src/github.com/rails/rails/activemodel/lib/active_model/validations.rb:410: warning: previous definition of raise_validation_error was here
/Users/kamipo/src/github.com/rails/rails/activemodel/lib/active_model/validations.rb:426: warning: method redefined; discarding old model
/Users/kamipo/src/github.com/rails/rails/activemodel/lib/active_model/validations.rb:428: warning: method redefined; discarding old initialize
/Users/kamipo/src/github.com/rails/rails/activemodel/lib/active_model/validations.rb:428: warning: previous definition of initialize was here
Traceback (most recent call last):
	23: from bin/test:5:in `<main>'
	22: from bin/test:5:in `require_relative'
	21: from /Users/kamipo/src/github.com/rails/rails/tools/test.rb:18:in `<top (required)>'
	20: from /Users/kamipo/src/github.com/rails/rails/railties/lib/rails/test_unit/runner.rb:40:in `run'
	19: from /Users/kamipo/src/github.com/rails/rails/railties/lib/rails/test_unit/runner.rb:52:in `load_tests'
	18: from /Users/kamipo/src/github.com/rails/rails/railties/lib/rails/test_unit/runner.rb:52:in `each'
	17: from /Users/kamipo/src/github.com/rails/rails/railties/lib/rails/test_unit/runner.rb:52:in `block in load_tests'
	16: from /Users/kamipo/src/github.com/rails/rails/railties/lib/rails/test_unit/runner.rb:52:in `require'
	15: from /Users/kamipo/src/github.com/rails/rails/activemodel/test/cases/attributes_dirty_test.rb:5:in `<top (required)>'
	14: from /Users/kamipo/src/github.com/rails/rails/activemodel/test/cases/attributes_dirty_test.rb:6:in `<class:AttributesDirtyTest>'
	13: from /Users/kamipo/src/github.com/rails/rails/activemodel/test/cases/attributes_dirty_test.rb:7:in `<class:DirtyModel>'
	12: from /Users/kamipo/src/github.com/rails/rails/activemodel/test/cases/attributes_dirty_test.rb:7:in `require'
	11: from /Users/kamipo/src/github.com/rails/rails/activemodel/lib/active_model/model.rb:3:in `<top (required)>'
	10: from /Users/kamipo/src/github.com/rails/rails/activemodel/lib/active_model/model.rb:59:in `<module:ActiveModel>'
	 9: from /Users/kamipo/src/github.com/rails/rails/activemodel/lib/active_model/model.rb:62:in `<module:Model>'
	 8: from /Users/kamipo/src/github.com/rails/rails/activemodel/lib/active_model/model.rb:62:in `require'
	 7: from /Users/kamipo/src/github.com/rails/rails/activemodel/lib/active_model/validations.rb:436:in `<top (required)>'
	 6: from /Users/kamipo/src/github.com/rails/rails/activemodel/lib/active_model/validations.rb:436:in `each'
	 5: from /Users/kamipo/src/github.com/rails/rails/activemodel/lib/active_model/validations.rb:436:in `block in <top (required)>'
	 4: from /Users/kamipo/src/github.com/rails/rails/activemodel/lib/active_model/validations.rb:436:in `require'
	 3: from /Users/kamipo/src/github.com/rails/rails/activemodel/lib/active_model/validations/numericality.rb:5:in `<top (required)>'
	 2: from /Users/kamipo/src/github.com/rails/rails/activemodel/lib/active_model/validations/numericality.rb:6:in `<module:ActiveModel>'
	 1: from /Users/kamipo/src/github.com/rails/rails/activemodel/lib/active_model/validations/numericality.rb:7:in `<module:Validations>'
/Users/kamipo/src/github.com/rails/rails/activemodel/lib/active_model/validations/numericality.rb:8:in `<class:NumericalityValidator>': uninitialized constant ActiveModel::Validations::NumericalityValidator::Comparability (NameError)
```
2021-04-24 13:46:45 +09:00
Matthew Draper
536a2c0011
Merge pull request #40095 from ChaelCodes/cc-comparablity-validator
Add ComparisonValidator to validate comparison of any objects
2021-04-24 13:20:57 +09:30
Ryuta Kamizono
bbbc861f71 Enable Performance/MapCompact cop
Follow up to #42053.
2021-04-23 16:33:02 +09:00
Ryuta Kamizono
c4b944a273 Enable Performance/StringReplacement cop
Follow up to #42054.
2021-04-23 16:17:55 +09:00
Rafael França
9437958e56
Merge pull request #42055 from stefannibrasil/update-actionpack-documentation
Update ActionPack documentation to remove views mention [ci skip]
2021-04-22 22:09:01 -04:00
Rafael França
7d88c8657d
Merge pull request #42053 from MatheusRich/replace-map-compact-with-filter-map
Replace `map + compact` with `filter_map`
2021-04-22 22:06:16 -04:00
Rafael França
f42a88f36c
Merge pull request #42054 from MatheusRich/replace-gsub-with-tr
Replace `gsub` with `tr`
2021-04-22 22:03:26 -04:00
Stefanni Brasil
cca46bb77f Update ActionPack documentation to remove views mention 2021-04-22 19:00:45 -07:00
Matheus Richard
63e7ef6fe1 Replace gsub with tr 2021-04-22 22:31:49 -03:00
Matheus Richard
c3d7794f16 Replace map + compact with filter_map 2021-04-22 22:08:34 -03:00
Jean Boussier
487ff1330c
Merge pull request #42008 from iridakos/bugs/42007-runner-file-load
Expand path of user provided file in runner
2021-04-22 20:21:29 +02:00
Jean Boussier
e56a5146cf
Merge pull request #39880 from hennevogel/bugfix/instrument-status
Fix instrumenting internal server errors
2021-04-22 17:22:37 +02:00
Henne Vogelsang
1966806cd0
Fix instrumenting internal server errors
In case of an exception we never reach setting the status in the
payload so it is unset afterward.

Let's catch the exception and set status based on the exception class name.
Then re-raise it.

This is basically the equivalent of what happens in

ActionController::LogSubscriber.process_action
2021-04-22 17:19:20 +02:00
Jean Boussier
738ca3595f Eagerly close Dalli connections in MemCachedStoreTest
Otherwise the test suite is flaky when ran repeatedly
on the same machine because of file descriptors exhaustion.
2021-04-22 15:32:22 +02:00
Jean Boussier
6e9f9b46b9 Get rid of another SecureRandom.hex in MemCachedStoreTest
This random value doesn't need to be "secure", and calling
SecureRandom so much cause /dev/urandom exhaustion on macOS
2021-04-22 15:15:57 +02:00
Jean Boussier
d42a34a8c9
Merge pull request #42049 from Shopify/refactor-entry-compression
Refactor Cache::Entry compression handling
2021-04-22 14:50:35 +02:00
Jorge Manrubia
6107209361 Add test to validate that ciphertext is returned when all previous schemes fail 2021-04-22 08:03:48 -04:00
Jorge Manrubia
9b7aafac98 Extract helper method for common logic across tests 2021-04-22 08:03:48 -04:00
Jorge Manrubia
30b96c7cf3 Add missing text for encryption exception raising 2021-04-22 08:03:48 -04:00
Jorge Manrubia
e249fb8817 We want to check previous_types ignoring clean text type here
This wasn't causing any issue because the behavior was virtually the
same (returning the ciphertext), but it was confusing to read.
2021-04-22 08:03:48 -04:00
Jorge Manrubia
9ed49b76fb Rename previous_types_including_clean_text => previous_types
It's make more sense to revert the naming approach:

- `#previous_types`, the exposed public method, always include the clean
 text type when suport for unencrypted data is enabled
- `#previous_types_without_clean_text` is a private method used
internally by the type
2021-04-22 08:03:48 -04:00
Jean Boussier
a0e4920296 Refactor Cache::Entry compression handling
Rather than immediately compressing the cache value
in the constructor, this operation is delayed until
we need to serialize the entry.
2021-04-22 13:46:46 +02:00
Eugene Kenny
2c79d2b260 Don't remove pool managers for test classes
These models have their own connections since
8b83793549fed994bf0231aff444aa74648b3c35.

Removing them was breaking 054e19d08638e64fa9eacc9be32fb7fde4e7415c in a
way that couldn't happen in a real app: pool managers are never removed,
except by this test helper.
2021-04-22 00:55:51 +01:00
Gannon McGibbon
7578e6f141
Merge pull request #41872 from gmcgibbon/nested_engine_locales
Allow loading nested locales in engines
2021-04-21 18:35:44 -04:00
Rafael França
9dc692bdc0
Merge pull request #42044 from basecamp/fix-are-multiple-schemes
Fix: use previous encryption schemes when support_unencrypted_data is on
2021-04-21 17:46:44 -04:00
Gannon McGibbon
cc557db0e2 Allow loading nested locales in engines 2021-04-21 17:45:09 -04:00
Jorge Manrubia
b908c8876e Split method with boolean argument into two to improve clarity
We were using the same method for 2 things: fetching previous types, and
fetching previous types with the cleantext type. This was making logic
harder to follow.
2021-04-21 23:28:29 +02:00
Eugene Kenny
19a4bfda7f
Merge pull request #40384 from eugeneius/teardown_shared_connection_pool
Restore connection pools after transactional tests
2021-04-21 22:03:19 +01:00
Jorge Manrubia
26b4da371b Fix: use previous encryption schemes when support_unencrypted_data is on
This fixes a problem in Active Record Encryption where, when `config
.support_unencrypted_data` was on, it was failing to try additional
previous encryption schemes beyond the first one.

The reason is that, witwh the previous implementation, when this flag
was toggled on, it was never raising encryption errors when checking
previous types.
2021-04-21 22:40:01 +02:00
Jean Boussier
89b904a165
Merge pull request #42041 from Shopify/duration-to-sentence-disable-i18n
Stop internationalizing Duration#inspect
2021-04-21 21:57:03 +02:00
Jean Boussier
18313071fa Stop internationalizing Duration#inspect
This can cause infinite recursions if you do have a
complex i18n backend that calls `Duration#inspect`.

There is not really any point making `inspect` internationalized
anyway, as most apps will have `:en` as default locale.
2021-04-21 21:44:44 +02:00