aboutsummaryrefslogtreecommitdiffstats
path: root/guides
diff options
context:
space:
mode:
Diffstat (limited to 'guides')
-rw-r--r--guides/rails_guides.rb2
-rw-r--r--guides/rails_guides/generator.rb4
-rw-r--r--guides/source/active_record_basics.md2
-rw-r--r--guides/source/active_storage_overview.md2
-rw-r--r--guides/source/configuring.md2
-rw-r--r--guides/source/routing.md2
-rw-r--r--guides/source/testing.md69
7 files changed, 69 insertions, 14 deletions
diff --git a/guides/rails_guides.rb b/guides/rails_guides.rb
index 28a7c94ca9..a72acdbd06 100644
--- a/guides/rails_guides.rb
+++ b/guides/rails_guides.rb
@@ -26,5 +26,5 @@ RailsGuides::Generator.new(
only: env_value["ONLY"],
kindle: env_flag["KINDLE"],
language: env_value["GUIDES_LANGUAGE"],
- direction: env_value["DIRECTION"].to_sym
+ direction: env_value["DIRECTION"]
).generate
diff --git a/guides/rails_guides/generator.rb b/guides/rails_guides/generator.rb
index 1f0a2063f2..48e90510e1 100644
--- a/guides/rails_guides/generator.rb
+++ b/guides/rails_guides/generator.rb
@@ -17,7 +17,7 @@ module RailsGuides
class Generator
GUIDES_RE = /\.(?:erb|md)\z/
- def initialize(edge:, version:, all:, only:, kindle:, language:, direction: :ltr)
+ def initialize(edge:, version:, all:, only:, kindle:, language:, direction: "ltr")
@edge = edge
@version = version
@all = all
@@ -118,7 +118,7 @@ module RailsGuides
def copy_assets
FileUtils.cp_r(Dir.glob("#{@guides_dir}/assets/*"), @output_dir)
- if @direction == :rtl
+ if @direction == "rtl"
overwrite_css_with_right_to_left_direction
end
end
diff --git a/guides/source/active_record_basics.md b/guides/source/active_record_basics.md
index b9e24099b1..a67e2924d7 100644
--- a/guides/source/active_record_basics.md
+++ b/guides/source/active_record_basics.md
@@ -202,6 +202,8 @@ class Product < ApplicationRecord
end
```
+NOTE: Active Record does not support using non-primary key columns named `id`.
+
CRUD: Reading and Writing Data
------------------------------
diff --git a/guides/source/active_storage_overview.md b/guides/source/active_storage_overview.md
index d5387219f5..65d4e2934f 100644
--- a/guides/source/active_storage_overview.md
+++ b/guides/source/active_storage_overview.md
@@ -635,7 +635,7 @@ input.addEventListener('change', (event) => {
input.value = null
})
-const uploadFile = (file) {
+const uploadFile = (file) => {
// your form needs the file_field direct_upload: true, which
// provides data-direct-upload-url
const url = input.dataset.directUploadUrl
diff --git a/guides/source/configuring.md b/guides/source/configuring.md
index 960a43406b..029ae1a5ff 100644
--- a/guides/source/configuring.md
+++ b/guides/source/configuring.md
@@ -782,6 +782,8 @@ There are a few configuration options available in Active Support:
* `config.active_job.custom_serializers` allows to set custom argument serializers. Defaults to `[]`.
+* `config.active_job.return_false_on_aborted_enqueue` change the return value of `#enqueue` to false instead of the job instance when the enqueuing is aborted. Defaults to `false`.
+
### Configuring Action Cable
* `config.action_cable.url` accepts a string for the URL for where
diff --git a/guides/source/routing.md b/guides/source/routing.md
index 84de727c11..0a0f1b6754 100644
--- a/guides/source/routing.md
+++ b/guides/source/routing.md
@@ -543,6 +543,8 @@ resources :photos do
end
```
+NOTE: If you're defining additional resource routes with a symbol as the first positional argument, be mindful that it is not equivalent to using a string. Symbols infer controller actions while strings infer paths.
+
#### Adding Routes for Additional New Actions
To add an alternate new action using the `:on` shortcut:
diff --git a/guides/source/testing.md b/guides/source/testing.md
index f0a1a8a3f0..9541598b26 100644
--- a/guides/source/testing.md
+++ b/guides/source/testing.md
@@ -474,12 +474,11 @@ takes your entire test suite to run.
The default parallelization method is to fork processes using Ruby's DRb system. The processes
are forked based on the number of workers provided. The default is 2, but can be changed by the
-number passed to the parallelize method. Active Record automatically handles creating and
-migrating a new database for each worker to use.
+number passed to the parallelize method.
To enable parallelization add the following to your `test_helper.rb`:
-```
+```ruby
class ActiveSupport::TestCase
parallelize(workers: 2)
end
@@ -489,32 +488,32 @@ The number of workers passed is the number of times the process will be forked.
parallelize your local test suite differently from your CI, so an environment variable is provided
to be able to easily change the number of workers a test run should use:
-```
+```bash
PARALLEL_WORKERS=15 rails test
```
-When parallelizing tests, Active Record automatically handles creating and migrating a database for each
+When parallelizing tests, Active Record automatically handles creating a database and loading the schema into the database for each
process. The databases will be suffixed with the number corresponding to the worker. For example, if you
have 2 workers the tests will create `test-database-0` and `test-database-1` respectively.
If the number of workers passed is 1 or fewer the processes will not be forked and the tests will not
be parallelized and the tests will use the original `test-database` database.
-Two hooks are provided, one runs when the process is forked, and one runs before the processes are closed.
+Two hooks are provided, one runs when the process is forked, and one runs before the forked process is closed.
These can be useful if your app uses multiple databases or perform other tasks that depend on the number of
workers.
The `parallelize_setup` method is called right after the processes are forked. The `parallelize_teardown` method
is called right before the processes are closed.
-```
+```ruby
class ActiveSupport::TestCase
parallelize_setup do |worker|
# setup databases
end
parallelize_teardown do |worker|
- # cleanup database
+ # cleanup databases
end
parallelize(workers: 2)
@@ -530,7 +529,7 @@ parallelizer is backed by Minitest's `Parallel::Executor`.
To change the parallelization method to use threads over forks put the following in your `test_helper.rb`
-```
+```ruby
class ActiveSupport::TestCase
parallelize(workers: 2, with: :threads)
end
@@ -542,7 +541,7 @@ The number of workers passed to `parallelize` determines the number of threads t
want to parallelize your local test suite differently from your CI, so an environment variable is provided
to be able to easily change the number of workers a test run should use:
-```
+```bash
PARALLEL_WORKERS=15 rails test
```
@@ -1398,6 +1397,56 @@ class ProfileControllerTest < ActionDispatch::IntegrationTest
end
```
+#### Using Separate Files
+
+If you find your helpers are cluttering `test_helper.rb`, you can extract them into separate files. One good place to store them is `lib/test`.
+
+```ruby
+# lib/test/multiple_assertions.rb
+module MultipleAssertions
+ def assert_multiple_of_fourty_two(number)
+ assert (number % 42 == 0), 'expected #{number} to be a multiple of 42'
+ end
+end
+```
+
+These helpers can then be explicitly required as needed and included as needed
+
+```ruby
+require 'test_helper'
+require 'test/multiple_assertions'
+
+class NumberTest < ActiveSupport::TestCase
+ include MultipleAssertions
+
+ test '420 is a multiple of fourty two' do
+ assert_multiple_of_fourty_two 420
+ end
+end
+```
+
+or they can continue to be included directly into the relevant parent classes
+
+```ruby
+# test/test_helper.rb
+require 'test/sign_in_helper'
+
+class ActionDispatch::IntegrationTest
+ include SignInHelper
+end
+```
+
+#### Eagerly Requiring Helpers
+
+You may find it convenient to eagerly require helpers in `test_helper.rb` so your test files have implicit access to them. This can be accomplished using globbing, as follows
+
+```ruby
+# test/test_helper.rb
+Dir[Rails.root.join('lib', 'test', '**', '*.rb')].each { |file| require file }
+```
+
+This has the downside of increasing the boot-up time, as opposed to manually requiring only the necessary files in your individual tests.
+
Testing Routes
--------------