Commit Graph

348 Commits

Author SHA1 Message Date
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
Rafael Mendonça França 49bc29a8fb
Fix CHANGELOG [ci skip] 2021-09-20 17:56:06 -04:00
Alexandre Ruban 458908ed42 Fix ActionText::Serialization when dumping an ActionText::RichText 2021-09-20 10:36:20 +02:00
Lucas Mansur bac0038e20
Don't overwrite default opts in rich_text_area_tag (#43156)
You may want to use your own controller to authenticate requests or
perform server-side validations.
2021-09-19 20:56:17 +02:00
Alex Ghiculescu 5acc32ac54
Generate less initializers in new/upgraded Rails apps (part 2) (#43237) 2021-09-17 09:06:17 +02:00
Rafael Mendonça França d177551c30
Preparing for 7.0.0.alpha2 release 2021-09-15 18:22:51 -04:00
Rafael Mendonça França 325d34eb58
Don't use exact version in the actiontext npm dependencies
We should be able to use alpha2 or newer.
2021-09-15 18:08:12 -04:00
Rafael Mendonça França 6ab1feea79
Fix actiontext npm package dependency 2021-09-15 18:05:36 -04:00
Rafael Mendonça França 9b7be48212
Preparing for 7.0.0.alpha1 release 2021-09-15 17:55:08 -04:00
Rafael Mendonça França fd41ea1f2d
Merge branch 'main' into less-initializers 2021-09-15 17:18:49 -04:00
Jean Boussier 532ef0d13c Add back Lint/UselessAssignment
Fix: #43169
2021-09-06 16:24:37 +02:00
David Heinemeier Hansson 82e4432058
Javascript generator option with choices (#43160)
* Switch to a single controller option for choosing JavaScript approach

* Remove remnants of webpacker specific work within Rails

* No longer used

* Missing space

* Raise if unknown option is passed

* Style

* Use latest versions

* Make channels setup generic to all node setups

* Make Action Text installer work with any node package manager

* Explaining variables are not useless

* Rubocop pleasing

* Don't rely on Rails.root

Tests don't like it!

* Rubocopping

* Assume importmap

* No longer relevant

* Another cop

* Style

* Correct installation notice

* Add dependencies for action cable when adding a channel

* Fix paths to be relative to generator

* Just go straight to yarn, forget about binstub

* Fix tests

* Fixup installer, only yarn once

* Test generically with run

* Style

* Fix reference and reversibility

* Style

* Fix test

* Test pinning dependencies

* Remove extra space

* Add more tests

* Use latest dependencies

* Relegated this to controllers

* Refactor ChannelGenerator + more tests

Use a uniform level of abstraction
2021-09-04 11:53:57 +02:00
Jean Boussier 4b4d1452d9 Eliminate some `Integer() rescue nil` patterns in Action Text 2021-08-26 19:39:44 +02:00
David Heinemeier Hansson d5b9618da1
Remove default reliance on Sass and CSS generators (#43110)
* No benefit to having actiontext css as scss

* Update test

* Update docs

* No more css assets to be generated

New world, new CSS frameworks, new needs.

* SCSS is becoming optional

* Remove Sass as a default-on setting

But continue to make it easy to add.

* Update docs

* No longer used

* Update tests

* Update docs

* Update docs

* No longer used

* No longer by default

* Fix tests

* Promote Tailwind CSS as an alternative to Sass

* Fix test and copy task

* Update railties/lib/rails/generators/rails/app/templates/Gemfile.tt

Co-authored-by: Kevin Newton <kddnewton@gmail.com>

Co-authored-by: Kevin Newton <kddnewton@gmail.com>
2021-08-26 13:40:25 +02:00
David Heinemeier Hansson af7428c4ac
Replace webpack with importmapped Hotwire as default js (#42999)
* Turbolinks is being replaced with Hotwire

* Make --webpack opt-in

* Don't use specific webpacker installers any more in preparation for next Webpacker

* Update railties/lib/rails/app_updater.rb

Co-authored-by: Alex Ghiculescu <alex@tanda.co>

* Trailing whitespace

* Convert to Turbo data attribute for tracking

* Default is no webpack, no hotwire

* Swap out turbolinks references for hotwire

* Drop explicit return

* Only generate package.json if using webpack

* Only create package.json in webpack mode

* Only create app/javascript in webpack mode

* Generate correct style/js links based on js mode

* Fix tests from changed output format

Not sure why these are showing up in this PR, though.

* Rubocopping

* Stick with webpack for the test app for now

* Adjust tests

* Replace minitest-reporters with minitest-ci (#43016)

minitest-reporters is used to create junit xml reports on CI.

But when it loads before rails minitest plugin makes
`Rails::TestUnitReporter` not being added as a reporter.

minitest-ci is now only loaded at ci and does not interferes with
rails minitest plugins. And keeps junit reports workings

* Too heavy handed to actually run bundle

Just like we don't auto-migrate

* Pin js frameworks in importmap

Instead of having importmap preconfigure it.

* Match updated app/javascript path

* No need for the explaining comment

* Fixes test cases for replace webpack with importmapped Hotwire as default js (#42999)

* Fix rubocop issues

* Fix more railities test cases

* Fix plugin generator railties shared test cases

* Fix Action Text install generator asset pipeline spec

* They're modules, not files

* Let dev use the latest release as well

So we don't have to replace unexisting dev releases with latest release

* Make Webpack responsible for generating all the JS files it needs

Webpacker 6 has already moved from app/javascript to app/packs.

* Don't add rails/ujs by default any longer

All the ajax/form functionality has been superseded by Turbo. The rest lives in a weird inbetween land we need to address through other means.

* Use new importmap location

* Switch to using turbo-rails and stimulus-rails directly

The hotwire-rails gem does not offer enough value for its indirection

* Use latest Webpacker

* Prevent version resolution requests from getting swallowed

* Use ESM syntax for imports

* Move management of yarn, package.json, etc to Webpacker 6

* Update for Webpacker 6

* Move bin/setup addition to Webpacker as well

* Remove dead tests

* Bump to Webpacker 6.0.0.rc.2

* No longer relevant given the new default is no webpacker

* Rely on Webpacker 6

* No longer relevant

* No longer relevant

* Make cable channel generator work for both webpacker and importmap setups

* Fix tests

* For tests testing importmap way

* Use Webpacker 6 dummy

* RuboCopping

* One more bump to fix webpack-dev-server

* Another bump. Hopefully the last one!

* Also enough to not want turbo tracking on

* Fix tests

* Latest

* Fix tests

* Fix more tests

* Fix tests

Co-authored-by: Alex Ghiculescu <alex@tanda.co>
Co-authored-by: André Luis Leal Cardoso Junior <andrehjr@gmail.com>
Co-authored-by: Abhay Nikam <nikam.abhay1@gmail.com>
Co-authored-by: Guillermo Iguaran <guilleiguaran@gmail.com>
2021-08-26 10:39:36 +02:00
David Heinemeier Hansson 6ec669b65d
Action Text installer should assume importmap for asset pipeline (#43011)
* Action Text installer should assume importmap for asset pipeline

* Fix test
2021-08-13 14:43:06 +02:00
David Heinemeier Hansson a2cd0a57f7
Ensure image processing gem is enabled when turning on action text so image uploads work out-of-the-box (#43010)
* Ensure image processing gem is enabled when turning on action text so uploads will work

* Test enabling image_processing gem

* Fix rubocop issue
2021-08-13 14:05:23 +02:00
David Heinemeier Hansson a2a28e6c90 Switch to ESM compatible build of trix
The mirror setup isn't doing what we need to get a ESM-compatible version of Trix. So grab a build from Snowpack that's compatible for now.
2021-08-13 11:10:05 +02:00
David Heinemeier Hansson e34300a921
Stop trying to configure listen by default on compatible platforms (#42985)
* Stop trying to configure listen by default on compatible platforms

Modern computers with SSDs don't see much/any benefit from having an evented file update watcher. Remove complexity by taking this spinning-drive concession out.

* Actually need listen for testing the opt-in

* Test no longer relevant
2021-08-11 15:18:43 +02:00
Rafael Mendonça França 18707ab17f
Standardize nodoc comments 2021-07-29 21:18:07 +00:00
David Heinemeier Hansson 0c2a94c265
No underscore style (#42898)
Just like activestorage.js
2021-07-28 15:34:59 -04:00
David Heinemeier Hansson 6c96e1cd7b
Move Active Storage JS to ESM and drop Babel transpiling (#42895)
* Move to ESM and drop Babel transpiling

* Make the activestorage JS directly available through the asset pipeline as a precompiled asset

* Use example with direct attachment

* Explain that direct reference is possible

* Active Storage JS is a module

* Retain umd asset for backwards compatibility, add ESM file in addition

* Explain how to use activestorage.esm with importmap

* Use untranspiled activestorage inclusion

* Don't repeat terser options
2021-07-28 15:17:13 -04:00
David Heinemeier Hansson 9c73d4aeab
Make Action Text + Trix JS/CSS available via the asset pipeline (#42857)
* Action Text JS should be available via the asset pipeline too

* Main was a module anyway, no need to reference that twice

* Fix rollup references

* Precompile action text JS for asset pipeline

* No JavaScript dependencies needed with the asset pipeline

* Stub Webpacker::Engine to trigger webpack path for testing

* Extract asset paths

* Exercise asset pipeline path

* Terser doesn't do anything useful on this small package

* Make trix directly available to the asset pipeline

* Indirect doesn't carry its worth

* Reminder for development about keeping things in sync for the asset pipeline

* Ensure this isn't turned into undefined while mirroring

* Mirror Trix CSS for asset pipeline

* Add the needed JS include tag automatically under the asset pipeline

* Please RuboCop

* Keep the peer dependency

Even though we also need it explicitly as a dev dependency in order to generate the mirror output for trix.

* Fix test

* Add CHANGELOG entry
2021-07-26 18:57:42 -04:00
Ryuta Kamizono 30033e6a1d
Merge pull request #42657 from abhaynikam/ensure-foreign-key-type-respect-generator-config
Ensure Action Text migration use config set primary_key_type
2021-07-03 11:36:36 +09:00
Abhay Nikam fa6067d0dc Ensure Action Text migration use config set primary_key_type
Similar to: #42378

Tried adding test cases for the changes but
migration file would always use id as primary_key_type
and reference type as foreign_key_type. Did not find
any good way to assert the changes.

Tested locally and following is the schema
generated for Action Text migration if
`primary_key_type: :uuid`

```
create_table "action_text_rich_texts", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
    t.string "name", null: false
    t.text "body"
    t.string "record_type", null: false
    t.uuid "record_id", null: false
    t.datetime "created_at", precision: 6, null: false
    t.datetime "updated_at", precision: 6, null: false
    t.index ["record_type", "record_id", "name"], name: "index_action_text_rich_texts_uniqueness", unique: true
  end
```
2021-06-30 23:17:36 +05:30
Dirkjan Bussink 0523532a3c
Always use OpenSSL constants for Digest operations
As also previously discussed in
https://github.com/rails/rails/pull/40770#issuecomment-748347066, this
moves the usage of Digest constants to always use the OpenSSL version of
those Digest implementations.
2021-06-30 13:57:54 +02:00
Hartley McGuire bcb300dccb Replace uglifier with terser in dummy applications
Terser is more up to date with modern javascript features, and the
uglifier gem repository recommends using it for minifying ES6+.

Followup for 955041b
2021-06-28 00:48:56 -04:00
Zachary Scott c797ce966c Update test dummy application defaults
Affected gems:

* actionmailbox
* activestorage
* actiontext

This fixes the following warning:

DEPRECATION WARNING: Using legacy connection handling is deprecated. Please set
`legacy_connection_handling` to `false` in your application.

The new connection handling does not support `connection_handlers`
getter and setter.

Read more about how to migrate at: https://guides.rubyonrails.org/active_record_multiple_databases.html#migrate-to-the-new-connection-handling
 (called from require at ~/.gem/ruby/3.1.0/gems/zeitwerk-2.4.2/lib/zeitwerk/kernel.rb:34)
2021-06-21 07:00:32 +09:00
Alex Ghiculescu de238125ef Generate less initializers in new/upgraded Rails apps
Currently when you make a new Rails app, we generate a lot of initializers. For new users, I think we should try and include as few as possible - the less files, the less daunting a new app is. And for upgrades I'd like to [continue to simplify the update process](https://github.com/rails/rails/pull/41083), in this case by not bringing back initializers you have probably already dismissed or modified.

In this PR I'm proposing we remove two initializers: `application_controller_renderer.rb` and `cookies_serializer.rb`:

**`application_controller_renderer.rb`**. This configures [`ActionController::Renderer`](https://api.rubyonrails.org/classes/ActionController/Renderer.html), for rendering views outside of controller actions. I don't think this is something most Rails apps will need (certainly not on day 1); users can configure this feature when they need it.

**`cookies_serializer.rb`**. This was added for [Rails 4.1](https://guides.rubyonrails.org/upgrading_ruby_on_rails.html#cookies-serializer). The behaviour is:

- For new apps, the initializer says `:json`.
- For upgraded apps that don't have the initializer, it is added with value `:marshal`.
- If there's no initializer, the [default value](c9a89a4067/actionpack/lib/action_dispatch/middleware/cookies.rb (L589)) is `:marshal`.

Since nobody should be upgrading direct from Rails 4.0 to Rails 7.0, we can simplify this by using new framework defaults. So the behavior will now be:

- For new apps, `config.load_defaults("7.0")` sets the value to `:json`.
- The `new_framework_defaults_7_0.rb` file explains this, and suggests using `:hybrid` to be upgrade to JSON cookies.
- No changes to [the code](c9a89a4067/actionpack/lib/action_dispatch/middleware/cookies.rb (L589)); the default value is `:marshal` if you don't set one.

So if you were not setting a `cookies_serializer` previously and you want to keep using `:marshal`, you'll need to explicitly set this before using `config.load_defaults("7.0")`, otherwise it will switch to `:json`. The upside of this is you won't get the `cookies_serializer.rb` file created for you every time you upgrade.
2021-06-18 16:13:05 -05:00
Rafael França 58ed26f616
Revert "Extract methods `assert_queries` and `assert_no_queries`" 2021-06-17 13:35:25 -04:00
Andrew White 26c00cb3da
Merge pull request #42465 from ricardotk002/extract-assert-queries
Extract methods `assert_queries` and `assert_no_queries`
2021-06-14 19:56:40 +01:00
Alex Ghiculescu 7f348eb9d4 Document Active Storage & Action Text eager loading
Docs for https://github.com/rails/rails/pull/40842 + https://github.com/rails/rails/pull/39397

[ci skip]
2021-06-14 11:03:48 -05:00
Ricardo Díaz f644f7d35b Extract methods `assert_queries` and `assert_no_queries`
Both methods are defined in multiple parts of the framework. It would
be useful to put them in a proper place, so that repetition is
avoided.

I chose the implementation from `ActiveRecord` because it's a bit more
complete with the `SQLCounter` class, and also because other parts
depend on it.
2021-06-14 09:55:13 -05:00
Steve Polito e0d57541ab Add note regarding "trix-content" class 2021-05-30 10:37:21 -05:00
Aditya Pandit 848cda0609 Updated actiontext package file to use latest version 2021-04-28 03:29:24 +05:30
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 bbbc861f71 Enable `Performance/MapCompact` cop
Follow up to #42053.
2021-04-23 16:33:02 +09:00
Matheus Richard c3d7794f16 Replace map + compact with filter_map 2021-04-22 22:08:34 -03:00
John Bampton eef63e05fb chore: fix case of CSS and JavaScript 2021-04-15 21:52:58 +10:00
John Bampton 4b681bd50f
Fix spelling in ActionText::FixtureSet.attachment docs [ci skip] 2021-04-11 10:56:31 -04:00
Jorge Manrubia 28145c3cee Rename master_key => primary_key 2021-04-01 15:02:15 +02:00
Jorge Manrubia 588c972d21 Removes the Action Text dependency from Active Record
Move the Action Text stuff to its own concern in `actiontext`.
2021-04-01 15:02:15 +02:00
Jorge Manrubia f046617853 Temporary change just to confirm this is the problem with some intermittent failures in buildkite
[skip ci]
2021-04-01 15:02:14 +02:00
Jorge Manrubia 1406ac294f Remove new lines 2021-04-01 15:02:14 +02:00
Jorge Manrubia 638a92f734 Initial extraction from active_record_encryption gem 2021-04-01 15:02:13 +02:00
Abhay Nikam 5de2dbff16 Fixes failing ActionText::ContentTest test cases
The test cases where failing because the test
`test_converts_Trix-formatted_attachments_with_custom_tag_name` set a
custom tag_name to `arbitrary-tag`. This test would also set the
ActionText::AttachmentGallery::ATTACHMENT_SELECTOR private constant
to `arbitrary-tag`.

Other test cases had proper ActionText::Attachment.tag_name set to
`action-text-attachment` but the constant once defined would not
reset.

This PR attempts to fix the issue by converting the
ActionText::AttachmentGallery::{ATTACHMENT_}SELECTOR to class methods

Fixes #41782
2021-03-30 16:38:11 -04:00
Henrik Nyh 515108ee03 'lookup' -> 'look up' in dummy webpacker.ymls
Corresponding to this fix: https://github.com/rails/webpacker/pull/2961
2021-03-21 12:36:56 +00:00
James Brooks b1b0b22f50
Always render attachment partials as HTML with :html format inside trix editor 2021-03-19 13:35:09 -04:00
Xavier Noria c431432f93 Add app/{helpers,models} to autoload_once_paths
The helpers of Action Text are added to a couple of non-reloadable
base classes:

  initializer "action_text.helper" do
    %i[action_controller_base action_mailer].each do |abstract_controller|
      ActiveSupport.on_load(abstract_controller) do
        helper ActionText::Engine.helpers
      end
    end
  end

Therefore, it does not make sense that they are reloadable themselves.

For the same price, we can also make the models non-reloadable, thus
saving parent applications from the unnecessary work of reloading this
engine.

We did this for turbo-rails as well.
2021-03-07 23:05:24 +01:00
Abhay Nikam ddbf01c52e @rails/actiontext: depend on released @rails/activestorage 2021-03-06 11:32:44 -05:00
Mark VanLandingham bece535c98
Add config.action_text.attachment_tag_name 2021-03-05 16:57:36 -05:00
Christian Schmidt 6cd184ff0f
Use image/jpeg instead of non-standard image/jpg 2021-03-05 13:14:11 -05:00
Abhay Nikam adc5eb66f8
Action Text: call #to_trix_html on rich_text_area_tag value 2021-02-28 11:20:59 -05:00
Ryuta Kamizono 7b680baea2 Remove `require "active_support/core_ext/symbol/starts_ends_with"`
Ruby 2.7 has native `Symbol#start_with?` and `Symbol#end_with?`.
2021-02-09 22:31:09 +09:00
Rafael Mendonça França 1b455e2e9d
Rails 6.2 is now Rails 7.0
We have big plans for the next version of Rails and that
require big versions.
2021-02-04 16:47:16 +00:00
Rafael Mendonça França 6487836af8
Rails 7 requires Ruby 2.7 and prefer Ruby 3+
The code cleanup is comming in later commits but this
already remove support to Ruby < 2.7.
2021-02-04 16:34:53 +00:00
Sean Doyle 0ad777cdcc
Improve ActionText::FixtureSet documentation (#41062)
* Improve ActionText::FixtureSet documentation

Support for Action Text attachments in fixtures was added by [76b33aa][] and
released as part of [6.1.1][], but has not yet been documented.

This commit documents the `ActionText::FixtureSet` for the API
documentation, and mentions it in the Rails Guides pages.

[76b33aa]: 76b33aa3d1
[6.1.1]: https://github.com/rails/rails/releases/tag/v6.1.1

* Fix indention of comments

Co-authored-by: David Heinemeier Hansson <david@loudthinking.com>
2021-01-24 11:16:27 +01:00
Jonathan Hefner 44d1006de3 Run bin/yarn via Ruby
Windows cannot directly run shebang scripts, such as `bin/yarn`.
Therefore, run `bin/yarn` via Ruby.

Actually fixes #40942.
Fixes #41123.
2021-01-21 11:51:15 -06:00
Santiago Bartesaghi e83d7dcb2f Use 4XX instead of 2XX for validation errors responses 2021-01-06 00:10:26 -03:00
Ryuta Kamizono 2b0b5a75c0 Bump license years to 2021 [ci skip] 2021-01-01 12:21:20 +09:00
Sean Doyle 3500571b43 Improve ActionText extensiblibility
Extensible layout
---

Expose how we render the HTML _surrounding_ rich text content as an
extensible `layouts/action_text/contents/_content.html.erb` template to
encourage user-land customizations, while retaining private API control
over how the rich text itself is rendered by moving the
`#render_action_text_content` helper invocation to the
`action_text/contents/_content.html.erb` partial.

Extensible Attachable `#to_attachable_partial_path`
---

When an application declares a canonical partial for a record, there is
no way to override which partial is used when transformed to Rich Text.
For example, a default `Person < ApplicationRecord` instance returns
`"people/person"` from calls to `#to_partial_path`, resulting in the
`app/views/people/_person.html.erb` partial being rendered.

Prior to this change, when encountering an `<action-text-attachment
sgid="...">` element, ActionText retrieved the corresponding
`Attachable` instance (usually an `ActiveRecord::Base` instance) and
transformed it to rich text HTML by rendering the partial that
corresponds to its `#to_partial_path`.

This proposed change instead invokes
`Attachable#to_attachable_partial_path`. By default,
`#to_attachable_partial_path` is an alias for `#to_partial_path`.

Guides
---

Extend the `guides/action_text_overview` document to
describe how to customize these templates, and to better illustrate how
ActionText::Attachable instances are rendered into HTML.
2020-12-29 20:06:45 -05:00
Ryuta Kamizono 401ce9dd3d Tweak CHANGELOGs [ci skip]
* Remove trailing space
* Add period
* etc
2020-12-29 21:11:16 +09:00
Jonathan Hefner ef61c9c8a3
Fix rendering Action Text HTML in new threads
Because `ActionText::Content.renderer` is implemented as a
`thread_cattr_accessor`, any default value set in the main thread will
be inaccessible from other threads.  Therefore, use a `cattr_accessor`
to store the default renderer, and fall back to it when `renderer` has
not been set by e.g. `with_renderer`.

Fixes #40757.
2020-12-07 16:41:44 -05:00
Rafael Mendonça França 59f7f5889e
Start Rails 6.2 development 🎉 2020-12-03 01:35:29 +00:00
Petrik 0a583c73c1 Change form_with to generate non remote forms by default
`form_with` would generate a remote form by default.
This confused users because they were forced to handle remote requests.

All new 6.1 applications will generate non-remote forms by default.
When upgrading a 6.0 application you can enable remote forms by default by
setting `config.action_view.form_with_generates_remote_forms` to `true`.
2020-12-01 21:14:37 +01:00
Alex Ghiculescu 76e432341c Always recommend config.asset_host in examples 2020-11-30 16:33:51 -06:00
Kasper Timm Hansen 835dba24cb
Merge pull request #40673 from jonathanhefner/actiontext-test-install-generator
Test Action Text install generator
2020-11-27 20:35:08 +01:00
Jonathan Hefner 76e111395c Always render Action Text HTML with :html format
Since #40222, Action Text HTML is rendered in the context of the current
request.  This causes the Action Text template format to default to the
request format, which prevents the template from being resolved when the
request format is not `:html` (e.g. `:json`).  Therefore, override the
template format to always be `:html`.

Fixes #40695.
2020-11-27 10:59:24 -06:00
Ryuta Kamizono 64c254017e Add explicit require for `Symbol#start_with?` 2020-11-25 15:22:32 +09:00
Yasuo Honda 6edc61970e Address "ArgumentError: missing keywords: :sql, :name" when unit tests run by ruby 3.0.0dev
This pull request addresses the `ArgumentError: missing keywords: :sql, :name`,
which has been reported at https://buildkite.com/rails/rails/builds/72990#c78d1e4c-5775-4758-9010-9ba71fdb6138

Follow up #39397

```ruby
$ ruby -v
ruby 3.0.0dev (2020-11-24T22:48:19Z master 63ad55cd88) [x86_64-linux]
$ cd actiontext
$ bin/test test/unit/model_test.rb -n test_eager_loading
Run options: -n test_eager_loading --seed 16493

E

Error:
ActionText::ModelTest#test_eager_loading:
ArgumentError: missing keywords: :sql, :name
    /home/yahonda/src/github.com/rails/rails/actiontext/test/test_helper.rb:29:in `block in assert_queries'
    /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/notifications/fanout.rb:186:in `finish'
    /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/notifications/fanout.rb:63:in `block in finish'
    /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/notifications/fanout.rb:63:in `each'
    /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/notifications/fanout.rb:63:in `finish'
    /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/notifications/instrumenter.rb:45:in `finish_with_state'
    /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/notifications/instrumenter.rb:30:in `instrument'
    /home/yahonda/src/github.com/rails/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:688:in `log'
    /home/yahonda/src/github.com/rails/rails/activerecord/lib/active_record/connection_adapters/sqlite3/database_statements.rb:46:in `exec_query'
    /home/yahonda/src/github.com/rails/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:536:in `select_prepared'
    /home/yahonda/src/github.com/rails/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:67:in `select_all'
    /home/yahonda/src/github.com/rails/rails/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb:103:in `select_all'
    /home/yahonda/src/github.com/rails/rails/activerecord/lib/active_record/querying.rb:47:in `find_by_sql'
    /home/yahonda/src/github.com/rails/rails/activerecord/lib/active_record/relation.rb:850:in `block in exec_queries'
    /home/yahonda/src/github.com/rails/rails/activerecord/lib/active_record/relation.rb:868:in `skip_query_cache_if_necessary'
    /home/yahonda/src/github.com/rails/rails/activerecord/lib/active_record/relation.rb:835:in `exec_queries'
    /home/yahonda/src/github.com/rails/rails/activerecord/lib/active_record/relation.rb:638:in `load'
    /home/yahonda/src/github.com/rails/rails/activerecord/lib/active_record/relation.rb:249:in `records'
    /home/yahonda/src/github.com/rails/rails/activerecord/lib/active_record/relation.rb:244:in `to_ary'
    /home/yahonda/src/github.com/rails/rails/activerecord/lib/active_record/relation/finder_methods.rb:553:in `find_nth_with_limit'
    /home/yahonda/src/github.com/rails/rails/activerecord/lib/active_record/relation/finder_methods.rb:538:in `find_nth'
    /home/yahonda/src/github.com/rails/rails/activerecord/lib/active_record/relation/finder_methods.rb:122:in `first'
    /home/yahonda/src/github.com/rails/rails/activerecord/lib/active_record/relation/finder_methods.rb:153:in `last'
    /home/yahonda/src/github.com/rails/rails/actiontext/test/unit/model_test.rb:93:in `block (2 levels) in <class:ModelTest>'
    /home/yahonda/src/github.com/rails/rails/actiontext/test/test_helper.rb:33:in `assert_queries'
    /home/yahonda/src/github.com/rails/rails/actiontext/test/unit/model_test.rb:93:in `block in <class:ModelTest>'

Error:
ActionText::ModelTest#test_eager_loading:
ArgumentError: missing keywords: :sql, :name
    /home/yahonda/src/github.com/rails/rails/actiontext/test/test_helper.rb:29:in `block in assert_queries'
    /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/notifications/fanout.rb:186:in `finish'
    /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/notifications/fanout.rb:63:in `block in finish'
    /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/notifications/fanout.rb:63:in `each'
    /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/notifications/fanout.rb:63:in `finish'
    /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/notifications/instrumenter.rb:45:in `finish_with_state'
    /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/notifications/instrumenter.rb:30:in `instrument'
    /home/yahonda/src/github.com/rails/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:688:in `log'
    /home/yahonda/src/github.com/rails/rails/activerecord/lib/active_record/connection_adapters/sqlite3/database_statements.rb:98:in `exec_rollback_db_transaction'
    /home/yahonda/src/github.com/rails/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:378:in `rollback_db_transaction'
    /home/yahonda/src/github.com/rails/rails/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb:22:in `rollback_db_transaction'
    /home/yahonda/src/github.com/rails/rails/activerecord/lib/active_record/connection_adapters/abstract/transaction.rb:205:in `rollback'
    /home/yahonda/src/github.com/rails/rails/activerecord/lib/active_record/connection_adapters/abstract/transaction.rb:302:in `block in rollback_transaction'
    /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb:26:in `block (2 levels) in synchronize'
    /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `handle_interrupt'
    /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `block in synchronize'
    /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `handle_interrupt'
    /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `synchronize'
    /home/yahonda/src/github.com/rails/rails/activerecord/lib/active_record/connection_adapters/abstract/transaction.rb:300:in `rollback_transaction'
    /home/yahonda/src/github.com/rails/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:328:in `rollback_transaction'
    /home/yahonda/src/github.com/rails/rails/activerecord/lib/active_record/test_fixtures.rb:168:in `block in teardown_fixtures'
    /home/yahonda/src/github.com/rails/rails/activerecord/lib/active_record/test_fixtures.rb:167:in `each'
    /home/yahonda/src/github.com/rails/rails/activerecord/lib/active_record/test_fixtures.rb:167:in `teardown_fixtures'
    /home/yahonda/src/github.com/rails/rails/activerecord/lib/active_record/test_fixtures.rb:16:in `after_teardown'
    /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/testing/setup_and_teardown.rb:51:in `after_teardown'

bin/test test/unit/model_test.rb:90

Finished in 0.117256s, 8.5284 runs/s, 0.0000 assertions/s.
1 runs, 0 assertions, 0 failures, 1 errors, 0 skips
$
```

Co-authored-by: Ryuta Kamizono <kamipo@gmail.com>
2020-11-25 12:58:03 +09:00
matt swanson 9b6459aab6
Add support for eager loading all rich text associations at once (#39397)
* Add `with_all_rich_text` method to eager load all RichText models at once

* Update actiontext/test/test_helper.rb

Co-authored-by: Kasper Timm Hansen <kaspth@gmail.com>

* Update actiontext/lib/action_text/attribute.rb

Co-authored-by: Kasper Timm Hansen <kaspth@gmail.com>

Co-authored-by: Kasper Timm Hansen <kaspth@gmail.com>
2020-11-24 18:19:46 +01:00
Jonathan Hefner a6b503c052 Test Action Text install generator
This commit adds tests for the Action Text install generator.  It also
includes a few changes in and around `generators_test_helper.rb` to make
writing similar tests easier in the future.

Closes #39317.

Co-authored-by: Abhay Nikam <nikam.abhay1@gmail.com>
2020-11-23 18:07:54 -06:00
Rafael Mendonça França 8389f9902c
Preparing for 6.1.0.rc1 release 2020-11-02 21:12:47 +00:00
Eugene Kenny b7eaaf73fb Update comment about reloading in development.rb [ci skip]
This comment predates the existence of `reload_classes_only_on_change`.
2020-11-02 19:36:26 +00:00
Sean Doyle 76b33aa3d1
Add ActionText::FixtureSet.attachment
Permit generating rich-text attachment markup in YAML fixtures:

    hello_world_review_content:
      record: hello_world (Review)
      name: content
      body: <p><%= ActionText::FixtureSet.attachment("messages", :hello_world) %> is great!</p>
2020-10-30 15:53:35 -04:00
Jonathan Hefner 614e813161
Disentangle Action Text from ApplicationController
This commit allows Action Text to be used without having an
ApplicationController defined.  In doing so, it also fixes Action Text
attachments to render the correct URL host in mailers.

It also avoids allocating an ActionController::Renderer per request.

Fixes #37183.
Fixes #35578.
Fixes #36963.
Closes #38714.

Co-authored-by: Jeremy Daer <jeremydaer@gmail.com>
2020-10-30 01:01:42 +00:00
Omri Gabay 43d83e96c9
Add option to mute multiple database yaml warning
Adds an option to silence the warning that database configurations can
throw when it's unparsable.
2020-10-29 16:57:57 -04:00
Jonathan Hefner 33fdae0584 Fix backtraces for generated plugin tests
`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.
2020-10-07 15:40:56 -05:00
Sean Doyle 614580270d Locate `fill_in_rich_text_area` by `<label>` text
This commit dovetails with [#38551] in its focus on improving the
ability to test calls to `rich_text_area` in accessibility-minded ways.

In addition to searching for `<trix-editor>` elements with the
appropriate [`aria-label`][aria-label] attribute, also support locating
elements that match the corresponding `<label>` element's text.

Now that [basecamp/trix#829][] has been merged and released, clicking on
`<label>` elements that reference `<trix-editor>` elements will move
focus into the `<trix-editor>` element.

There are still some accessible [label text][] improvements that could
be made, but extending `fill_in_rich_text_area` to account for `<label
for="...">` elements is a good start.

[#38551]: https://github.com/rails/rails/pull/38551
[aria-label]: https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques/Using_the_aria-label_attribute
[basecamp/trix#829]: https://github.com/basecamp/trix/pull/829
[label text]: https://github.com/basecamp/trix/pull/829#issuecomment-699119852
2020-10-02 18:02:14 -04:00
George Claghorn b0287d0681 Extract ActionText::Record
Permit applications to hack in custom DB config for ActionText::RichText until AT has first-class multi-DB support:

    ActiveSupport.on_load(:action_text_record) do
      connects_to reading: :action_text_replica, writing: :action_text_primary
    end
2020-09-29 11:59:14 -04:00
Paulo Ancheta b9571ae45f
Add value option to ActionView::Helpers::FormBuilder#rich_text_area 2020-09-01 21:43:07 -04:00
Rafael França 56ab961dee
Remove white list word 2020-06-09 13:41:51 -04:00
fatkodima 6c4f3be929 Unify raise_on_missing_translations for views and controllers 2020-05-20 02:42:59 +03:00
Rafael França a80115b7c5
Merge pull request #39204 from prathamesh-sonpatki/template-annotation
Add the configuration option for annotating templates with file names to the generated app
2020-05-19 19:11:31 -04:00