Commit Graph

331 Commits

Author SHA1 Message Date
Justin Perkins ad1d2bed4a Clarify YAML boolean caveat in en.yml template
This clarifies that the boolean interpretation (1) is due to YAML rather
than I18n, (2) is case insensitive, and (3) affects both keys and
values.

Co-authored-by: Jonathan Hefner <jonathan@hefner.pro>
2023-05-24 13:35:53 -05:00
Jon Dufresne e28f147329 Make the test environment show rescuable exceptions in responses
Background
----------

During integration tests, it is desirable for the application to respond
as closely as possible to the way it would in production. This improves
confidence that the application behavior acts as it should.

In Rails tests, one major mismatch between the test and production
environments is that exceptions raised during an HTTP request (e.g.
`ActiveRecord::RecordNotFound`) are re-raised within the test rather
than rescued and then converted to a 404 response.

Setting `config.action_dispatch.show_exceptions` to `true` will make the
test environment act like production, however, when an unexpected
internal server error occurs, the test will be left with a opaque 500
response rather than presenting a useful stack trace. This makes
debugging more difficult.

This leaves the developer with choosing between higher quality
integration tests or an improved debugging experience on a failure.

I propose that we can achieve both.

Solution
--------

Change the configuration option `config.action_dispatch.show_exceptions`
from a boolean to one of 3 values: `:all`, `:rescuable`, `:none`. The
values `:all` and `:none` behaves the same as the previous `true` and
`false` respectively. What was previously `true` (now `:all`) continues
to be the default for non-test environments.

The new `:rescuable` value is the new default for the test environment.
It will show exceptions in the response only for rescuable exceptions as
defined by `ActionDispatch::ExceptionWrapper.rescue_responses`. In the
event of an unexpected internal server error, the exception that caused
the error will still be raised within the test so as to provide a useful
stack trace and a good debugging experience.
2023-05-17 06:30:28 -07:00
zzak f397f47212
Use double quotes for escaping yaml (re #47983) 2023-05-16 20:34:40 +09:00
Guillermo Iguaran 2d069be22b
Merge pull request #48143 from p8/actiontext/document-partial-paths
Document more methods for ActionText::Attachable [ci-skip]
2023-05-11 02:27:47 -07:00
Joe Dupuis fc839e980b Fix a race condition in Action Text's test suite
`assert_queries` in Action Text's test helpers can detect queries from
a previous test if background jobs are allowed to run during its
execution.

Changing the queue_adapter to the test adapter for all tests using the
helper ensure no jobs can run during its execution.
2023-05-07 16:44:08 -07:00
Petrik 71a89d5e29 Document more methods for ActionText::Attachable [ci-skip]
Document the `*_partial_path`, `attachable_sgid` and `as_json` methods.
2023-05-05 22:06:27 +02:00
Petrik de Heus 68b500e739
Merge pull request #48142 from p8/actiontext/document-actiontext-content
Some cleanups for ActionText documentation [ci-skip]
2023-05-05 21:26:55 +02:00
Petrik fdf9682301 Some cleanups for ActionText documentation [ci-skip]
Add some escaping of namespaces.
2023-05-05 21:12:10 +02:00
Petrik 344bb00eab Add documentation for ActionText::Attachment [ci-skip]
Co-authored-by: Adrianna Chang <adrianna.chang@shopify.com>
2023-05-05 18:34:35 +02:00
Petrik de Heus 6a665a597d
Merge pull request #48133 from p8/actiontext/document-actiontext-content
Add documentation for ActionText::Content [ci-skip]
2023-05-05 18:28:05 +02:00
Petrik d6d57ae35a Document ActionText::Attachable [ci-skip] 2023-05-05 11:34:52 +02:00
Petrik 6f6d1f91bd Add documentation for ActionText::Content [ci-skip] 2023-05-05 10:23:39 +02:00
Josh Brito 43ec5737c7 Update comment to reference values with single quotes as opposed to double 2023-04-18 21:32:37 -07:00
Petrik e0d77a9f5c Document ActionText::RichText methods [ci-skip] 2023-04-15 21:53:21 +02:00
Aditya Pandit cf13f34262 Fixed activestorage version in action text 2023-04-06 19:22:26 +05:30
Petrik c09f5fa956 Add missing headers to Action Mailbox/Mailer/Text/View docs [ci-skip]
Having a h1 heading will improve SEO and makes things look more consistent.
2023-04-02 17:47:17 +02:00
Petrik de Heus dc0f20595d
Merge pull request #47717 from p8/docs/include-readmes
Include READMEs in main framework pages of the API documentation
2023-03-30 16:43:14 +02:00
Sarah Ridge de317f9d6a
Combine CHANGELOG entries
Co-authored-by: Hartley McGuire <skipkayhil@gmail.com>
2023-03-28 12:23:01 -04:00
Sarah Ridge 48b8285f4d
Update Action Text's Trix dependency (2.0.4) 2023-03-28 12:23:01 -04:00
Rafael Mendonça França 30683cbf85
Copy-edit CHANGELOG 2023-03-25 16:50:19 +00:00
Rafael Mendonça França 6aaa9db647
Merge pull request #46101 from swanson/swanson/missing-attachable-partial
Allow Attachables to override default template when attachment is missing
2023-03-25 12:49:54 -04:00
justin talbott beb43e0182
Add `ActiveSupport` load hook for `ActionText::EncryptedRichText`
Both `ActionText::Record` and `ActionText::RichText` have dedicated `ActiveSupport` load hooks. This adds an
additional hook for `ActionText::EncryptedRichText`, so that external libraries have a similarly simple way
to run code after the subclass is loaded.
2023-03-22 16:00:08 -04:00
Petrik 7c94708d24 Include READMEs in main framework pages of the API documentation
Currently when opening the main framework pages there is no introduction
to the framework. Instead we only see a whole lot of modules and the
`gem_version` and `version` methods.

By including the READMEs using the `:include:` directive each frameworks
has a nice introduction.
For markdown READMEs we need to add the :markup: directive.

[ci-skip]

Co-authored-by: zzak <zzakscott@gmail.com>
2023-03-21 21:16:28 +01:00
Andrew Novoselac 6902cbce1b Introducs `TestFixtures#fixture_paths`.
Multiple fixture paths can now be specified using the `#fixture_paths` accessor.
2023-03-14 19:02:56 -04:00
Rafael Mendonça França 20d87500a4
Merge pull request #46126 from alexandreruban/fix-as-json-action-text-attachables
Fix ActionText::Attachable#as_json
2023-03-06 17:32:27 -05:00
Alexandre Ruban 6c2132b332
Fix ActionText::Attachable#as_json
Before this commit, using ActionText and calling `#as_json` on a
non-persisted `ActiveStorage::Blob` raised an error.

This is because `ActionText::Attachable` is included in
`ActiveStorage::Blob` and overrides the `#as_json` method to
expose a global signed id. However, a global signed id can only
be generated on a persisted instance.

This commit fixes the issue by making sure the blob is persisted
before exposing the global signed id.
2023-03-06 13:55:01 +01:00
Rafael Mendonça França e78ed07e00
Merge pull request #47259 from skipkayhil/hm-regenerate-dummies
Full refresh of framework dummy applications
2023-03-01 18:08:58 -05:00
Yasuo Honda 70e9c89ddc
Merge pull request #46129 from yahonda/actiontext_isolated
Add `rake test:isolated` for Action Text
2023-02-28 15:10:38 +09:00
Hartley McGuire ba028a48f6
Fix Action Mailbox, Action Text strict warnings
These appear to have been missed when the change was made in
d917896f45
2023-02-23 17:34:55 -05:00
zzak d2af670dba
Remove Copyright years (#47467)
* Remove Copyright years

* Basecamp is now 37signals... again

Co-authored-by: David Heinemeier Hansson <dhh@hey.com>

---------

Co-authored-by: David Heinemeier Hansson <dhh@hey.com>
2023-02-23 11:38:16 +01:00
Jean Boussier 185f2d718d Allow to define the default column serializer
YAML has quite a bit of footguns, as such it's desirable
to be able to substitute it for something else or even
simply to force users to define a serializer explictly for
every serialized columns.
2023-02-22 19:32:28 +01:00
Hartley McGuire 2e5d060537
Remove Webpacker files in Action Text dummy app
These are leftover after Webpacker was replaced with importmaps in
89a24d6216
2023-02-18 17:51:27 -05:00
Hartley McGuire 9795eb9194
Regenerate Action Text dummy app
Generated using the following script and manually reviewed after:
skipkayhil/rails-bin@38e2aacb1b
2023-02-18 17:51:27 -05:00
Matt Swanson fbf0145f19 Allow Attachables to override default template when attachment is missing 2023-02-13 10:45:12 -05:00
Yasuo Honda f838a74212
Merge pull request #46866 from ghousemohamed/change-year-2022-to-2023 2023-02-13 13:15:43 +09:00
Koichi ITO 5726b1d1d7 Use RuboCop Performance 1.16.0
## Summary

This PR bumps RuboCop Performance to 1.16.0 and suppresses the following new offenses:

```console
% bundle exec rubocop
(snip)

Offenses:

actionpack/lib/action_dispatch/routing/mapper.rb:309:16:
C: [Correctable] Performance/StringInclude: Use String#include? instead of a regex match with literal-only pattern.
            if /#/.match?(to)
               ^^^^^^^^^^^^^^
actionpack/lib/action_dispatch/routing/mapper.rb:1643:18:
C: [Correctable] Performance/StringInclude: Use String#include? instead of a regex match with literal-only pattern.
              if /#/.match?(to)
                 ^^^^^^^^^^^^^^
actionpack/lib/action_dispatch/routing/route_set.rb:887:67:
C: [Correctable] Performance/StringInclude: Use String#include? instead of a regex match with literal-only pattern.
        path = Journey::Router::Utils.normalize_path(path) unless %r{://}.match?(path)
                                                                  ^^^^^^^^^^^^^^^^^^^^
actionpack/lib/action_dispatch/testing/assertions/routing.rb:86:12:
C: [Correctable] Performance/StringInclude: Use String#include? instead of a regex match with literal-only pattern.
        if %r{://}.match?(expected_path)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
actionpack/lib/action_dispatch/testing/assertions/routing.rb:205:14:
C: [Correctable] Performance/StringInclude: Use String#include? instead of a regex match with literal-only pattern.
          if %r{://}.match?(path)
             ^^^^^^^^^^^^^^^^^^^^
actionpack/lib/action_dispatch/testing/integration.rb:235:12:
C: [Correctable] Performance/StringInclude: Use String#include? instead of a regex match with literal-only pattern.
        if %r{://}.match?(path)
           ^^^^^^^^^^^^^^^^^^^^
actiontext/bin/webpack:18:6:
C: [Correctable] Performance/StringInclude: Use String#include? instead of a regex match with literal-only pattern.
  if /This file was generated by Bundler/.match?(File.read(bundle_binstub, 150))
     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
actiontext/bin/webpack-dev-server:18:6:
C: [Correctable] Performance/StringInclude: Use String#include? instead of a regex match with literal-only pattern.
  if /This file was generated by Bundler/.match?(File.read(bundle_binstub, 150))
     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb:120:64:
C: [Correctable] Performance/StringInclude: Use String#include? instead of a regex match with literal-only pattern.
          elsif column.type == :uuid && value.is_a?(String) && /\(\)/.match?(value)
                                                               ^^^^^^^^^^^^^^^^^^^^
railties/lib/rails/commands/secrets/secrets_command.rb:28:12:
C: [Correctable] Performance/StringInclude: Use String#include? instead of a regex match with literal-only pattern.
        if /secrets\.yml\.enc/.match?(error.message)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

3088 files inspected, 10 offenses detected, 10 offenses autocorrectable
```

## Additional Information

This behavior change is based on:
https://github.com/rubocop/rubocop-performance/pull/332
2023-02-06 13:06:31 +09:00
zzak f8544410a2 Use stable guides link for package READMEs
E.g.: These show up here:
https://api.rubyonrails.org/files/actioncable/README_md.html
2023-02-04 09:01:00 +09:00
David Heinemeier Hansson 2b1fa89e44
Log to stdout in production by default (#47138)
* Logging to a file doesn't make sense in production

You're going to run out of space, and it doesn't play well with containers. Either you log to STDOUT, and let your container setup aggregate the logs, or you'll be switching to syslogger or whatever. You won't be logging to a file in production any more.

* Remove from Dockerfile too

* Did not mean to change this default

But we should make it easy to see how to change it.

* Restore what we had
2023-01-25 21:10:22 +01:00
David Heinemeier Hansson e8f481b924
Turn on static file server by default (#47137)
Modern deployments don't need NGINX/Apache when using CDNs or caching LBs in front. This means file serving works out of the box too.
2023-01-25 18:19:05 +01:00
Rafael Mendonça França 4af571c22d
Merge pull request #47105 from ghiculescu/i18n-raise
Make `raise_on_missing_translations` raise on any missing translation
2023-01-23 14:10:50 -05:00
Alex Ghiculescu e18c23fc2b Make `raise_on_missing_translations` raise on any missing translation
Fixes https://github.com/rails/rails/issues/47057
Superseeds https://github.com/rails/rails/pull/45361
2023-01-23 10:17:11 -07:00
Sean Doyle fab1b522cd Update Action Text's Trix dependency
There is a new [Trix.js][] release, bumping the version from `1.3.1` to
`2.0.4`.

Applications that consume Action Text through the `@rails/actiontext`
npm package can manage their own Trix dependency version.

Similarly, Importmaps users can `pin "trix", to: "..."` to a CDN serving
`2.0.4`.

For the sake of applications that depend on Trix through the
`action_text` gem, this commit updates the pre-bundled JS and CSS code.

These changes were generated by executing the following:

```sh
cd actiontext
yarn build
cp ../node_modules/trix/dist/trix.css app/assets/stylesheets/trix.css
cp ../node_modules/trix/dist/trix.esm.js app/assets/javascripts/trix.js
```

[Trix.js]: https://trix-editor.org
[v2.0.4]: https://github.com/basecamp/trix/releases/tag/v2.0.4
2023-01-23 10:39:51 -05:00
Rafael Mendonça França 5c835bd669
Make explicit this config only affects controllers are views 2023-01-19 20:21:29 +00:00
Eileen M. Uchitelle ebf2540fac
Merge pull request #46928 from hahmed/fix-action-text-tests
Fix action text dummy app so integration tests can run
2023-01-13 16:52:46 -05:00
Jonathan Hefner 6225b5f59f Load version.rb for Action Mailbox and Action Text
This matches the other frameworks, ensuring that `ActionMailbox.version`
and `ActionText.version` are available when using Action Mailbox and
Action Text, respectively.

__Before__

  ```console
  $ bin/rails runner 'puts ActiveRecord.version'
  7.1.0.alpha

  $ bin/rails runner 'puts ActionMailbox.version'
  undefined method `version' for ActionMailbox:Module

  $ bin/rails runner 'puts ActionText.version'
  undefined method `version' for ActionText:Module
  ```

__After__

  ```console
  $ bin/rails runner 'puts ActiveRecord.version'
  7.1.0.alpha

  $ bin/rails runner 'puts ActionMailbox.version'
  7.1.0.alpha

  $ bin/rails runner 'puts ActionText.version'
  7.1.0.alpha
  ```
2023-01-12 17:34:49 -06:00
Haroon Ahmed 89a24d6216 Fix action text tests by updating dummy app to use import maps instead
of webpacker.

Include the js and css in the application.html.erb which now shows the
rich text editor on the page. This allows the integration tests to run.

Fixes https://github.com/rails/rails/issues/46804
2023-01-08 22:33:30 +00:00
Ghouse Mohamed e0559d2c1c Change 2022 -> 2023 2023-01-03 13:22:00 +05:30
Drew Breunig 04177c1b7b
Prepend a '\n' to the string to be added to `application.js` to prevent errors occurring when `application.js` doesn't end in a blank line.
Running `bin/rails action_text:install` appends `import "trix"` to the `application.js` file without inserting a newline.

In my app this resulted in the following:

```js
// import statements....

import Rails from "@rails/ujs"
Rails.start()import "trix"
import "@rails/actiontext"

```

I assume this bug occurred because my `application.js` was listed at some point and removed an extra line, which was not expected by this generator.

I recommend prepending the string to be inserted with a `\n` just to be safe.
2023-01-02 13:36:03 -08:00
Akira Matsuda e28e2f784e
Ignore local .sqlite3 files that are created under storage directory
Follows up d18fc32999
2022-12-27 11:35:26 +09:00
Sean Doyle 0e9013081e Revert "Focus editor after calling `fill_in_rich_text_area`"
Closes [rails/rails#46803][].

This reverts commit 67a4ac6c56.

Once the system test helper test suite executes in CI, we can
re-introduce the changes as part of [rails/rails#46807][].

[rails/rails#46803]: https://github.com/rails/rails/issues/46803#issuecomment-1364112967
[rails/rails#46807]: https://github.com/rails/rails/pull/46807
2022-12-23 14:19:25 -05:00
Kaíque Kandy Koga 0dc71acf39 Apply field_error_proc to rich_text_area fields 2022-12-22 11:52:30 -06:00
Jorge Manrubia 14cd0c4dee
Avoid unnecessary replacements when the node doesn't change
This represents a +2x performance optimization when the replacement
logic is based on some condition, and it returns the same unchanged
node when it wants to skip it:

 ```ruby
 html = <<~HTML
       <div>
         #{'<p>ignore me</p>' * 1000}
         #{'<p>replace me</p>' * 1000}
       </div>
 HTML

 content = content_from_html(html)

 replacement_example = -> do
   content.fragment.replace("p") do |node|
     if node.text =~ /replace me/
       "<p>replace me</p>"
     else
       node
     end
   end
 end

 current_implementation = -> do
   class ActionText::Fragment
     def replace(selector)
       update do |source|
         source.css(selector).each do |node|
           replacement_node = yield(node)
           node.replace(replacement_node.to_s)
         end
       end
     end
   end

   replacement_example.call
 end

 new_implementation = -> do
   class ActionText::Fragment
     def replace(selector)
       update do |source|
         source.css(selector).each do |node|
           replacement_node = yield(node)
           node.replace(replacement_node.to_s) if node != replacement_node
         end
       end
     end
   end

   replacement_example.call
 end

 Benchmark.ips do |x|
   x.report "Current implementation", &current_implementation
   x.report "New implementation", &new_implementation

   x.compare!
 end
 ```

 Results:

 ```
 Warming up --------------------------------------
 Current implementation
                          2.000  i/100ms
   New implementation     5.000  i/100ms
 Calculating -------------------------------------
   Current implementation
                          32.484  (±30.8%) i/s -    134.000  in   5.036419s
   New implementation     74.878  (±38.7%) i/s -    250.000  in   5.052168s

 Comparison:
   New implementation:       74.9 i/s
   Current implementation:       32.5 i/s - 2.31x  (± 0.00) slower
 ```
2022-12-17 22:39:51 +01:00
Jonathan Hefner 93038baad7 Use routes.default_url_options in AC::Renderer env
When a host is not specified for an `ActionController::Renderer`'s env,
the host and related options will now be derived from the routes'
`default_url_options` and `ActionDispatch::Http::URL.secure_protocol`.

For example, with:

  ```ruby
  Rails.application.default_url_options = { host: "rubyonrails.org" }
  Rails.application.config.force_ssl = true
  ```

Before:

  ```ruby
  ApplicationController.renderer.render inline: "<%= blog_url %>"
  # => "http://example.org/blog"
  ```

After:

  ```ruby
  ApplicationController.renderer.render inline: "<%= blog_url %>"
  # => "https://rubyonrails.org/blog"
  ```

As a consequence, Action Text attachment URLs rendered in a background
job (a la Turbo Streams) will now use `Rails.application.default_url_options`.

Fixes #41795.
Fixes hotwired/turbo-rails#54.
Fixes hotwired/turbo-rails#155.
2022-12-15 16:22:07 -06:00
David Heinemeier Hansson d18fc32999
Use storage/ instead of db/ for sqlite3 db files (#46699)
* Use storage/ instead of db/ for sqlite3 db files

db/ should be for configuration only, not data. This will make it easier to mount a single volume into a container for testing, development, and even sqlite3 in production.
2022-12-12 08:32:12 +01:00
Sean Doyle 67a4ac6c56 Focus editor after calling `fill_in_rich_text_area`
When System Tests call `fill_in_rich_text_area`, they interact with
`<trix-editor>` elements by changing the contents programmatically.

This is unlike how end-users will interact with the element. Overhauling
the test helper to more accurately reflect Real World usage would
require a sizable effort.

With that being said, leaving the `<trix-editor>` with focus after
populating its contents is a minor change that makes it a more genuine
recreation.
2022-12-09 09:48:27 -05:00
Eileen M. Uchitelle f002536a5d
Merge pull request #46271 from seanpdoyle/has-rich-text-strict-loading
Support `has_rich_text` with `strict_loading:`
2022-12-09 08:44:07 -05:00
Étienne Barrié 3d6a7b2faa Initialize deprecators before configuring them
Since engine initializers run later in the process, we need to run this
initializer earlier than the default.

This ensures they're all registered before the environments are loaded.
2022-11-28 10:47:26 +01:00
Yasuo Honda 9da6dd1c45
Merge pull request #46501 from evaniainbrooks/fix-mailer-template
Update meta tag in mailer template layout.html.erb.tt
2022-11-22 22:22:34 +09:00
Jonathan Hefner ec4e34034d Remove unnecessary link markup [ci-skip]
Because they are CamelCase, RDoc will automatically link these
references.  Automatic links have monospace formatting, whereas, in some
cases, manual links do not.
2022-11-15 13:57:15 -06:00
Evan Brooks 8d3408e41a Update mailer templates meta tag mailer.html.erb 2022-11-14 21:38:07 -04:00
Jonathan Hefner b2bc006815 Add ActionText.deprecator
This commit adds `ActionText.deprecator`, and adds it to
`Rails.application.deprecators` so that it can be configured via
settings such as `config.active_support.report_deprecations`.
2022-11-01 17:39:39 -05:00
Sean Doyle 4a743b9e0a Support `has_rich_text` with `strict_loading:`
Expand the `has_rich_text` signature to accept a `strict_loading:`
value. Forward that value along to the `has_one` declaration made under
the hood. When omitted, `strict_loading:` will be set to the value of
the `strict_loading_by_default` class attribute (false by default).
2022-10-18 17:06:26 -04:00
Eike Send 5ba8aa5854
Facilitate use of any regular ERB in database.yml
Commit 37d1429ab1 introduced the DummyERB to avoid loading the environment when
running `rake -T`.

The DummyCompiler simply replaced all output from `<%=` with a fixed string and
removed everything else. This worked okay when it was used for YAML values.
When using `<%=` within a YAML key, it caused an error in the YAML parser,
making it impossible to use ERB as you would expect. For example a
`database.yml` file containing the following should be possible:

  development:
    <% 5.times do |i| %>
    shard_<%= i %>:
      database: db/development_shard_<%= i %>.sqlite3
      adapter: sqlite3
    <% end %>

Instead of using a broken ERB compiler we can temporarily use a
`Rails.application.config` that does not raise an error when configurations are
accessed which have not been set as described in #35468.

This change removes the `DummyCompiler` and uses the standard `ERB::Compiler`.
It introduces the `DummyConfig` which delegates all known configurations to the
real `Rails::Application::Configuration` instance and returns a dummy string for
everything else. This restores the full ERB capabilities without compromising on
speed when generating the rake tasks for multiple databases.

Deprecates `config.active_record.suppress_multiple_database_warning`.
2022-09-27 17:07:40 +02:00
Yasuo Honda 52d058ceda Add `rake test:isolated` for Action Text
This commit implementes `rake test:isolated` for Action Text.
While many of modules have `rake test:isolated`, Action Text does not.
This could find #46113 in advance.

- Usage
```
cd actiontext
bundle exec rake test:isolated
```

- It detects #46113 by reverting the merge commit via #46119

```
$ git revert -m 1 4e7f876

$ bundle exec rake test:isolated
/home/yahonda/.rbenv/versions/3.1.2/bin/ruby -w -Ilib -Itest test/integration/controller_render_test.rb
... snip ...

E

Error:
ActionText::ControllerRenderTest#test_renders_as_HTML_when_the_request_format_is_not_HTML:
NoMethodError: undefined method `render_to_string' for nil:NilClass

        (renderer || default_renderer).render_to_string(*args, &block)
                                      ^^^^^^^^^^^^^^^^^
    test/integration/controller_render_test.rb:19:in `block in <class:ControllerRenderTest>'

bin/test test/integration/controller_render_test.rb:17
```

To run isolated tests at Rails CI,
https://github.com/rails/buildkite-config also needs updated.
2022-09-26 20:42:59 +09:00
Jonathan Hefner 763941e81b Always provide a fallback renderer for Action Text
Follow-up to #45144.

This ensures that a renderer is always available for Action Text, even
when `ActionController::Base` was not previously loaded.

Fixes #46113.

As with #45144, this still avoids loading `ActionController::Base`
unnecessarily when rendering mail after Action Text has been loaded.

**Before:**

```
$ bin/rails r 'Benchmark.memory { |x| x.report("load"){ MyBlankMailer.blank_email.body } }'
Calculating -------------------------------------
                load     4.466M memsize (     1.205M retained)
                        29.202k objects (    11.943k retained)
                        50.000  strings (    50.000  retained)
```

**After:**

```
$ bin/rails r 'Benchmark.memory { |x| x.report("load"){ MyBlankMailer.blank_email.body } }'
Calculating -------------------------------------
                load     4.462M memsize (     1.205M retained)
                        29.141k objects (    11.940k retained)
                        50.000  strings (    50.000  retained)
```

Co-authored-by: Christopher Louvet <cl@nonplaces.com>
2022-09-23 14:36:04 -05:00
Yasuo Honda 0b80408b24 Use `system(.., exception: true)` for dummy apps
Related to #46064
2022-09-20 22:53:05 +09:00
Jeremy Daer 01d345c4d6
Merge pull request #45739 from basecamp/content-attachment-update
update ContentAttachment so that it works with "content" attributes
2022-09-06 11:15:10 -07:00
Rafael Mendonça França aa0952d349
Merge pull request #45412 from skipkayhil/fix-actiontext-js-main
Fix actiontext js not pointing to compiled file
2022-08-10 19:11:48 -03:00
Jonathan Hefner b13107fe5e Fix typos [ci-skip] 2022-08-05 21:36:18 -05:00
Jamis Buck 5f342cfdbe make sure rendering the content attachment actually works 2022-08-04 10:07:23 -06:00
Jamis Buck 9918ce4a78 linter appeasement 2022-08-03 08:19:41 -06:00
Jamis Buck 67ab654dfa ContentAttachment is an internal API; let's indicate that with :nodoc: 2022-08-02 16:06:38 -06:00
Jamis Buck c8ea92cf27 update CHANGELOG 2022-08-02 16:05:25 -06:00
Jamis Buck 4499a3cdd0 update ContentAttachment so that it works with "content" attributes
this makes it possible for an application to embed markup in a document
that would otherwise be undesirable or expensive to process. For example,
an incoming email may include a complicated bit of DOM in a quote, and
while you don't want to have to process and rewrite it, you also don't want
to discard it; the content attribute of ContentAttachment allows you to
make that work.
2022-08-02 15:08:16 -06:00
Hartley McGuire d67963f14a
Fix actiontext js not pointing to compiled file
This caused issues with bundlers like Webpack since it tries to strictly
follow the ESM spec which says that imports must include file
extensions.
2022-06-20 12:47:20 -04:00
Jonathan Hefner 471ab2347f Omit workers and preload_app! from Puma config
Since Puma 5.0 (puma/puma@05936689c8),
Puma will automatically set `workers` to `ENV["WEB_CONCURRENCY"] || 0`.
Additionally, if `ENV["WEB_CONCURRENCY"]` > 1, Puma will automatically
set `preload_app`.

This can lead to confusing scenarios for users who are unaware of this
behavior and have customized `config/puma.rb`.  For example, if a user
uncomments the `workers` and `preload_app!` directives, it is clear that
Puma will preload the app, and the number of workers can be configured
by setting `ENV["WEB_CONCURRENCY"]`.  If the user sets
`ENV["WEB_CONCURRENCY"]` > 1, but then changes their mind and removes
the `workers` or `preload_app!` directives *without* clearing
`ENV["WEB_CONCURRENCY"]`, Puma will still preload the app and launch
`ENV["WEB_CONCURRENCY"]` number of workers.  Similarly, if a user
uncomments *only* the `workers` directive and sets
`ENV["WEB_CONCURRENCY"]` > 1, Puma will preload the app even though the
`preload_app!` directive is still commented out.

To avoid such scenarios, this commit removes the commented-out `workers`
and `preload_app!` directives from the default `config/puma.rb`.

Also, to improve discoverability of available configuration options,
this commit adds a link to the Puma DSL documentation at the top of the
file.
2022-06-03 12:38:21 -05:00
Jonathan Hefner 327ba2d979
Merge pull request #43706 from jacobherrington/jacobherrington/address-actiontext-multiple-renders
Avoid renders in equality check of rich_text content
2022-05-22 10:10:09 -05:00
Jonathan Hefner c2a3ff0027 Avoid ActionController when render mail, AT loaded
This avoids unnecessarily loading `ActionController::Base` when
rendering mail after Action Text has been loaded.

Before:

```
$ bin/rails r 'Benchmark.memory { |x| x.report("load"){ MyBlankMailer.blank_email.body } }'
Calculating -------------------------------------
                load    12.679M memsize (     1.927M retained)
                       101.143k objects (    19.947k retained)
                        50.000  strings (    50.000  retained)
```

After:

```
$ bin/rails r 'Benchmark.memory { |x| x.report("load"){ MyBlankMailer.blank_email.body } }'
Calculating -------------------------------------
                load     7.678M memsize (     1.302M retained)
                        61.420k objects (    13.644k retained)
                        50.000  strings (    50.000  retained)
```
2022-05-20 11:57:47 -05:00
Xavier Noria 2953ae5c8a Define config.enable_reloading to be !config.cache_classes
Every time I write `config.cache_classes` I have to pause for a moment to make
sure I get it right. It makes you think.

On the other hand, if you read `config.enable_reloading = true`, does the
application reload? You do not need to spend 1 cycle of brain CPU to nod.
2022-04-14 18:11:36 +02:00
Andrew White e9e2fd6f9f
Fix deprecation warnings in Action Text tests
Support for the image/jpg content type will be removed in Rails 7.1
and the use of it within the Action Text tests appears to be a typo.
2022-03-19 07:20:31 +00:00
Ghouse Mohamed 6ee6cb554b Fix #version docs and some typos 2022-03-16 01:48:37 +05:30
Koichi ITO 819871cc4e Enable `Style/MapToHash` cop
Ruby 2.6 added block argument processing to `Enumerable#to_h`.
https://bugs.ruby-lang.org/issues/15143

Rails 7 requires Ruby 2.7.0 or higher, so the new feature can use it.
`Style/MapToHash` cop will detect it. And this cop in the `Style` department,
but this seems to improve performance as follows:

```ruby
# map_to_hash.rb
require 'benchmark/ips'

ARRAY = (1..100).to_a
HASH = {foo: 1, bar: 2}

Benchmark.ips do |x|
  x.report('array.map.to_h') { ARRAY.map { |v| [v, v * 2] }.to_h }
  x.report('array.to_h')     { ARRAY.to_h { |v| [v, v * 2] } }

  x.compare!
end

Benchmark.ips do |x|
  x.report('hash.map.to_h') { HASH.map { |k, v| [k.to_s, v * 2] }.to_h }
  x.report('hash.to_h')     { HASH.to_h { |k, v| [k.to_s, v * 2] } }

  x.compare!
end
```

```console
% ruby map_to_hash.rb
Warming up --------------------------------------
      array.map.to_h     9.063k i/100ms
          array.to_h     9.609k i/100ms
Calculating -------------------------------------
      array.map.to_h     89.063k (± 3.9%) i/s -    453.150k in  5.096572s
          array.to_h     96.449k (± 1.7%) i/s -    490.059k in  5.082529s

Comparison:
          array.to_h:    96448.7 i/s
      array.map.to_h:    89063.4 i/s - 1.08x  (± 0.00) slower

Warming up --------------------------------------
       hash.map.to_h   106.284k i/100ms
           hash.to_h   149.354k i/100ms
Calculating -------------------------------------
       hash.map.to_h      1.102M (± 2.2%) i/s -      5.527M in   5.019657s
           hash.to_h      1.490M (± 0.9%) i/s -      7.468M in   5.013264s

Comparison:
           hash.to_h:  1489707.0 i/s
       hash.map.to_h:  1101561.5 i/s - 1.35x  (± 0.00) slower
```

`Style/MapToHash` cop ... https://docs.rubocop.org/rubocop/1.25/cops_style.html#stylemaptohash
2022-02-26 04:31:03 +09:00
Jonathan Hefner a199aaedb8 Cross-link API docs [ci-skip]
RDoc will automatically format and link API references as long as they
are not already marked up as inline code.

This commit removes markup from various API references so that those
references will link to the relevant API docs.
2022-02-21 11:45:25 -06:00
Jean Boussier e26372b713 Implicitly assert no exception is raised in `assert_queries` & al
Fix: https://github.com/rails/rails/pull/44397
Ref: https://github.com/rails/rails/pull/37313
Ref: https://github.com/rails/rails/pull/42459

This avoid mistakes such as:

```ruby
assert_raise Something do
  assert_queries(1) do
    raise Something
  end
end
```

Co-Authored-By: Alex Coomans <alexc@squareup.com>
2022-02-19 09:11:14 +01:00
Jacob Herrington 5811097ece Avoid renders in equality check of rich_text content 2022-02-18 14:33:12 -06:00
Jonathan Hefner 8cc8fe9628 Don't render layout in ActionText::Content#inspect
Prior to this commit, `ActionText::Content#inspect` called `#to_s` and
truncated the result to 25 characters.  However, `#to_s` calls
`#to_rendered_html_with_layout` which, by default, renders the same
first 25 characters for every instance.

For example, with models such as:

```ruby
class Message < ActiveRecord::Base
  has_rich_text :content
end

Message.create(content: "first message")
Message.create(content: "second message")
Message.create(content: "third message")
```

The output of `#inspect` is indistinguishable:

```irb
irb> Message.all.map { |message| message.content.body }
  Rendered .../actiontext/app/views/action_text/contents/_content.html.erb within layouts/action_text/contents/_content (Duration: 2.4ms | Allocations: 881)
  Rendered .../actiontext/app/views/action_text/contents/_content.html.erb within layouts/action_text/contents/_content (Duration: 0.7ms | Allocations: 257)
  Rendered .../actiontext/app/views/action_text/contents/_content.html.erb within layouts/action_text/contents/_content (Duration: 0.6ms | Allocations: 257)
=> [#<ActionText::Content "<div class=\"trix-conte...">,
    #<ActionText::Content "<div class=\"trix-conte...">,
    #<ActionText::Content "<div class=\"trix-conte...">]
```

This commit changes `#inspect` to call `#to_html`, which does not render
the Action Text layout.  So the output of `#inspect` will be:

```irb
irb> Message.all.map { |message| message.content.body }
=> [#<ActionText::Content "first message">,
    #<ActionText::Content "second message">,
    #<ActionText::Content "third message">]
```
2022-02-01 11:58:12 -06:00
Gannon McGibbon aaa64687e8
Revert #38957 (#44287)
* Revert "Pass service_name param to DirectUploadsController"

This reverts commit 193289dbbe.

* Revert "Multi-service direct uploads in Action Text attachment uploads"

This reverts commit 0b69ad4de6.
2022-01-29 14:27:45 +01:00
Brian Kelly e9cf3e4e1c Fixes Options documention formatting for has_rich_text 2022-01-22 13:57:47 -06:00
Ryuta Kamizono 65766ebcc8 Bump license years to 2022 [ci-skip] 2022-01-01 15:22:15 +09:00
Jonathan Hefner 4917ee9df6 Use dynamic Rails version in framework dummy apps
This matches what we currently generate for plugin dummy apps.
2021-12-08 11:31:49 -06:00
Rafael Mendonça França 83d85b2207
Start Rails 7.1 development 2021-12-07 15:52:30 +00:00
Rafael Mendonça França 5fa7049856
Use `ActiveRecord::FixtureSet.signed_global_id` defined by the globalid gem
Also make explicit that actiontext depends on the globalid gem.
2021-11-24 22:34:37 +00:00
Rafael Mendonça França 1fde031e89 Fix gemspec 2021-11-15 21:06:21 +00:00
Rafael Mendonça França 9195b7fd0a
Require MFA to release rails 2021-11-15 20:37:42 +00:00
Gannon McGibbon 0b69ad4de6 Multi-service direct uploads in Action Text attachment uploads 2021-11-15 14:00:00 -05:00
DmitryTsepelev 193289dbbe Support direct uploads to multiple services 2021-11-14 11:49:06 +03:00
Jacob Herrington 78b4a776d0 Import actiontext.css when actiontext is installed
When a Rails app is generated with the --css option and the
action_text:install task is run, the Trix editor will not work as
expected. This occurs because using cssbundling-rails does not create an
application.css file, which would normally automatically require
actiontext.css.

Adding a step to append an import statement to the base CSS or SCSS
file, when one can be detected, solves the issue. In the case a base CSS
or SCSS file can't be detected, we output a warning to import the
necessary CSS file.
2021-10-13 16:23:04 -05:00
matt swanson 0b1f83d0bc
Better ActionText plain text output for nested lists (#37976)
* Improve plaintext output for nested lists

* Update plain_text_conversion_test.rb

* Add additional test cases

* Refactor a bit

* Add changelog entry

* Rearrange methods

Co-authored-by: Matt Swanson <matt@mdswanson.com>
2021-10-12 18:05:04 +02:00
Sean Doyle 969830451c DOCS: Improve ActionText FixtureSet Ruby docs
* Resolves test directory inconsistencies
* Separates Ruby code fences from YAML code fences
* Various prose edits
2021-10-12 09:45:06 -04:00
Ryan Baumann 58127ec6d5 Fix tests for actiontext with hidden inputs defaulting to autocomplete="off" 2021-09-21 21:16:01 -04:00