From f7b27513f794a17e90b1a709e22e9777d88eb487 Mon Sep 17 00:00:00 2001 From: abhishekkanojia Date: Thu, 1 Mar 2018 19:25:51 +0530 Subject: Remove index:true option from belongs to as defaults to true. --- guides/source/association_basics.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'guides/source') diff --git a/guides/source/association_basics.md b/guides/source/association_basics.md index 9616647f15..5fddf67171 100644 --- a/guides/source/association_basics.md +++ b/guides/source/association_basics.md @@ -109,7 +109,7 @@ class CreateBooks < ActiveRecord::Migration[5.0] end create_table :books do |t| - t.belongs_to :author, index: true + t.belongs_to :author t.datetime :published_at t.timestamps end @@ -140,7 +140,7 @@ class CreateSuppliers < ActiveRecord::Migration[5.0] end create_table :accounts do |t| - t.belongs_to :supplier, index: true + t.belongs_to :supplier t.string :account_number t.timestamps end @@ -184,7 +184,7 @@ class CreateAuthors < ActiveRecord::Migration[5.0] end create_table :books do |t| - t.belongs_to :author, index: true + t.belongs_to :author t.datetime :published_at t.timestamps end @@ -231,8 +231,8 @@ class CreateAppointments < ActiveRecord::Migration[5.0] end create_table :appointments do |t| - t.belongs_to :physician, index: true - t.belongs_to :patient, index: true + t.belongs_to :physician + t.belongs_to :patient t.datetime :appointment_date t.timestamps end @@ -312,13 +312,13 @@ class CreateAccountHistories < ActiveRecord::Migration[5.0] end create_table :accounts do |t| - t.belongs_to :supplier, index: true + t.belongs_to :supplier t.string :account_number t.timestamps end create_table :account_histories do |t| - t.belongs_to :account, index: true + t.belongs_to :account t.integer :credit_rating t.timestamps end @@ -358,8 +358,8 @@ class CreateAssembliesAndParts < ActiveRecord::Migration[5.0] end create_table :assemblies_parts, id: false do |t| - t.belongs_to :assembly, index: true - t.belongs_to :part, index: true + t.belongs_to :assembly + t.belongs_to :part end end end @@ -517,7 +517,7 @@ In your migrations/schema, you will add a references column to the model itself. class CreateEmployees < ActiveRecord::Migration[5.0] def change create_table :employees do |t| - t.references :manager, index: true + t.references :manager t.timestamps end end -- cgit v1.2.3 From 06ab7bb729f83bb5fbf0733baff1c0053b99d105 Mon Sep 17 00:00:00 2001 From: James Baer Date: Thu, 4 Oct 2018 16:13:17 -0400 Subject: Add observing emails to action mailer guide [ci skip] Adds information on using email observer classes with Action Mailer. Intercepting Emails section is changed to "Intercepting and Observing Emails", with a sub-section on each topic. Also includes slight reworking of the Intercepting Emails summary to flow with the new structure. --- guides/source/action_mailer_basics.md | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) (limited to 'guides/source') diff --git a/guides/source/action_mailer_basics.md b/guides/source/action_mailer_basics.md index 041a427f7c..1acb993cad 100644 --- a/guides/source/action_mailer_basics.md +++ b/guides/source/action_mailer_basics.md @@ -839,13 +839,14 @@ Mailer Testing You can find detailed instructions on how to test your mailers in the [testing guide](testing.html#testing-your-mailers). -Intercepting Emails +Intercepting and Observing Emails ------------------- -There are situations where you need to edit an email before it's -delivered. Fortunately Action Mailer provides hooks to intercept every -email. You can register an interceptor to make modifications to mail messages -right before they are handed to the delivery agents. +Action Mailer provides hooks into the Mail observer and interceptor methods. These allow you to register classes that are called during the mail delivery life cycle of every email sent. + +### Intercepting Emails + +Interceptors allow you to make modifications to emails before they are handed off to the delivery agents. An interceptor class must implement the `:delivering_email(message)` method which will be called before the email is sent. ```ruby class SandboxEmailInterceptor @@ -869,3 +870,21 @@ NOTE: The example above uses a custom environment called "staging" for a production like server but for testing purposes. You can read [Creating Rails environments](configuring.html#creating-rails-environments) for more information about custom Rails environments. + +### Observing Emails + +Observers give you access to the email message after it has been sent. An observer class must implement the `:delivered_email(message)` method, which will be called after the email is sent. + +```ruby +class EmailDeliveryObserver + def self.delivered_email(message) + EmailDelivery.log(message) + end +end +``` +Like interceptors, you need to register observers with the Action Mailer framework. You can do this in an initializer file +`config/initializers/email_delivery_observer.rb` + +```ruby +ActionMailer::Base.register_observer(EmailDeliveryObserver) +``` -- cgit v1.2.3 From 4c15ed775304abd9e3e41afef4e7fec4077f699b Mon Sep 17 00:00:00 2001 From: Adam Demirel Date: Mon, 15 Oct 2018 15:14:48 +1100 Subject: Update snippet to rails 5 syntax --- guides/source/action_controller_overview.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides/source') diff --git a/guides/source/action_controller_overview.md b/guides/source/action_controller_overview.md index 43bc9306ce..aa746e4731 100644 --- a/guides/source/action_controller_overview.md +++ b/guides/source/action_controller_overview.md @@ -166,7 +166,7 @@ NOTE: Support for parsing XML parameters has been extracted into a gem named `ac The `params` hash will always contain the `:controller` and `:action` keys, but you should use the methods `controller_name` and `action_name` instead to access these values. Any other parameters defined by the routing, such as `:id`, will also be available. As an example, consider a listing of clients where the list can show either active or inactive clients. We can add a route which captures the `:status` parameter in a "pretty" URL: ```ruby -get '/clients/:status' => 'clients#index', foo: 'bar' +get '/clients/:status', to: 'clients#index', foo: 'bar' ``` In this case, when a user opens the URL `/clients/active`, `params[:status]` will be set to "active". When this route is used, `params[:foo]` will also be set to "bar", as if it were passed in the query string. Your controller will also receive `params[:action]` as "index" and `params[:controller]` as "clients". -- cgit v1.2.3 From b69a6c3214800dafb4d467e8181dfaeb4f98ab4f Mon Sep 17 00:00:00 2001 From: Adam Demirel Date: Wed, 17 Oct 2018 07:57:56 +1100 Subject: Fix mapping of content --- guides/source/active_record_basics.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides/source') diff --git a/guides/source/active_record_basics.md b/guides/source/active_record_basics.md index fad4c19827..b9e24099b1 100644 --- a/guides/source/active_record_basics.md +++ b/guides/source/active_record_basics.md @@ -82,9 +82,9 @@ of two or more words, the model class name should follow the Ruby conventions, using the CamelCase form, while the table name must contain the words separated by underscores. Examples: -* Database Table - Plural with underscores separating words (e.g., `book_clubs`). * Model Class - Singular with the first letter of each word capitalized (e.g., `BookClub`). +* Database Table - Plural with underscores separating words (e.g., `book_clubs`). | Model / Class | Table / Schema | | ---------------- | -------------- | -- cgit v1.2.3 From 2c01714d2d27c80008f479611e7fcf66eec86987 Mon Sep 17 00:00:00 2001 From: Trevor Wistaff Date: Tue, 6 Jun 2017 14:48:18 +1000 Subject: [ci skip] Remove explicit to_s for consistency with other example --- guides/source/i18n.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides/source') diff --git a/guides/source/i18n.md b/guides/source/i18n.md index 78e5f27448..b1bb13e0f8 100644 --- a/guides/source/i18n.md +++ b/guides/source/i18n.md @@ -116,7 +116,7 @@ NOTE: The backend lazy-loads these translations when a translation is looked up You can change the default locale as well as configure the translations load paths in `config/application.rb` as follows: ```ruby - config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] + config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}')] config.i18n.default_locale = :de ``` -- cgit v1.2.3 From 8d5a2c4da12725beeb14ba70508762242c86696f Mon Sep 17 00:00:00 2001 From: Lucas Oliveira Date: Tue, 16 Oct 2018 20:52:34 -0400 Subject: Update guide for the counter variable when rendering with the `as:` option [ci skip] --- guides/source/layouts_and_rendering.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides/source') diff --git a/guides/source/layouts_and_rendering.md b/guides/source/layouts_and_rendering.md index 00da65b784..ad08e5a5a9 100644 --- a/guides/source/layouts_and_rendering.md +++ b/guides/source/layouts_and_rendering.md @@ -1266,7 +1266,7 @@ You can also pass in arbitrary local variables to any partial you are rendering In this case, the partial will have access to a local variable `title` with the value "Products Page". -TIP: Rails also makes a counter variable available within a partial called by the collection, named after the title of the partial followed by `_counter`. For example, when rendering a collection `@products` the partial `_product.html.erb` can access the variable `product_counter` which indexes the number of times it has been rendered within the enclosing view. +TIP: Rails also makes a counter variable available within a partial called by the collection, named after the title of the partial followed by `_counter`. For example, when rendering a collection `@products` the partial `_product.html.erb` can access the variable `product_counter` which indexes the number of times it has been rendered within the enclosing view. Note that it also applies for when the partial name was changed by using the `as:` option. For example, the counter variable for the code above would be `item_counter`. You can also specify a second partial to be rendered between instances of the main partial by using the `:spacer_template` option: -- cgit v1.2.3 From 12c7b101f8cfa9ecb9d9483a02b0b6ebf792b77e Mon Sep 17 00:00:00 2001 From: Ryuta Kamizono Date: Wed, 17 Oct 2018 21:28:12 +0900 Subject: Remove and flip `index: true` for `references` in the doc [ci skip] Follow up #32146. --- guides/source/association_basics.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides/source') diff --git a/guides/source/association_basics.md b/guides/source/association_basics.md index 406b65d223..b0a905c754 100644 --- a/guides/source/association_basics.md +++ b/guides/source/association_basics.md @@ -487,7 +487,7 @@ class CreatePictures < ActiveRecord::Migration[5.0] def change create_table :pictures do |t| t.string :name - t.references :imageable, polymorphic: true, index: true + t.references :imageable, polymorphic: true t.timestamps end end -- cgit v1.2.3 From e50debf1ae0c7211f48b93693ec7e49eafd1e487 Mon Sep 17 00:00:00 2001 From: anthonygharvey Date: Wed, 17 Oct 2018 20:50:16 -0400 Subject: Fix typo in testing guide --- guides/source/testing.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides/source') diff --git a/guides/source/testing.md b/guides/source/testing.md index 9de2229672..8c21ccfba6 100644 --- a/guides/source/testing.md +++ b/guides/source/testing.md @@ -1562,7 +1562,7 @@ class UserMailerTest < ActionMailer::TestCase end ``` -In the test we send the email and store the returned object in the `email` +In the test we create the email and store the returned object in the `email` variable. We then ensure that it was sent (the first assert), then, in the second batch of assertions, we ensure that the email does indeed contain what we expect. The helper `read_fixture` is used to read in the content from this file. -- cgit v1.2.3 From 8c3a2283541261cf69d9bbb62a24c5386fcbb9fe Mon Sep 17 00:00:00 2001 From: Olivier Lacan Date: Thu, 18 Oct 2018 22:28:47 -0400 Subject: Add guides section on verbose query logs to Debugging Since this is a useful tool in debugging it made sense to document its existence and usage, especially in the console where it's disabled by default. [ci skip] --- guides/source/debugging_rails_applications.md | 49 +++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 6 deletions(-) (limited to 'guides/source') diff --git a/guides/source/debugging_rails_applications.md b/guides/source/debugging_rails_applications.md index 88d205e1ab..7f7766e7d7 100644 --- a/guides/source/debugging_rails_applications.md +++ b/guides/source/debugging_rails_applications.md @@ -186,14 +186,17 @@ end Here's an example of the log generated when this controller action is executed: ``` -Started POST "/articles" for 127.0.0.1 at 2017-08-20 20:53:10 +0900 +Started POST "/articles" for 127.0.0.1 at 2018-10-18 20:09:23 -0400 Processing by ArticlesController#create as HTML - Parameters: {"utf8"=>"✓", "authenticity_token"=>"xhuIbSBFytHCE1agHgvrlKnSVIOGD6jltW2tO+P6a/ACjQ3igjpV4OdbsZjIhC98QizWH9YdKokrqxBCJrtoqQ==", "article"=>{"title"=>"Debugging Rails", "body"=>"I'm learning how to print in logs!!!", "published"=>"0"}, "commit"=>"Create Article"} -New article: {"id"=>nil, "title"=>"Debugging Rails", "body"=>"I'm learning how to print in logs!!!", "published"=>false, "created_at"=>nil, "updated_at"=>nil} + Parameters: {"utf8"=>"✓", "authenticity_token"=>"XLveDrKzF1SwaiNRPTaMtkrsTzedtebPPkmxEFIU0ordLjICSnXsSNfrdMa4ccyBjuGwnnEiQhEoMN6H1Gtz3A==", "article"=>{"title"=>"Debugging Rails", "body"=>"I'm learning how to print in logs.", "published"=>"0"}, "commit"=>"Create Article"} +New article: {"id"=>nil, "title"=>"Debugging Rails", "body"=>"I'm learning how to print in logs.", "published"=>false, "created_at"=>nil, "updated_at"=>nil} Article should be valid: true - (0.1ms) BEGIN - SQL (0.4ms) INSERT INTO "articles" ("title", "body", "published", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5) RETURNING "id" [["title", "Debugging Rails"], ["body", "I'm learning how to print in logs!!!"], ["published", "f"], ["created_at", "2017-08-20 11:53:10.010435"], ["updated_at", "2017-08-20 11:53:10.010435"]] - (0.3ms) COMMIT + (0.0ms) begin transaction + ↳ app/controllers/articles_controller.rb:31 + Article Create (0.5ms) INSERT INTO "articles" ("title", "body", "published", "created_at", "updated_at") VALUES (?, ?, ?, ?, ?) [["title", "Debugging Rails"], ["body", "I'm learning how to print in logs."], ["published", 0], ["created_at", "2018-10-19 00:09:23.216549"], ["updated_at", "2018-10-19 00:09:23.216549"]] + ↳ app/controllers/articles_controller.rb:31 + (2.3ms) commit transaction + ↳ app/controllers/articles_controller.rb:31 The article was saved and now the user is going to be redirected... Redirected to http://localhost:3000/articles/1 Completed 302 Found in 4ms (ActiveRecord: 0.8ms) @@ -201,6 +204,40 @@ Completed 302 Found in 4ms (ActiveRecord: 0.8ms) Adding extra logging like this makes it easy to search for unexpected or unusual behavior in your logs. If you add extra logging, be sure to make sensible use of log levels to avoid filling your production logs with useless trivia. +### Verbose Query Logs + +When looking at database query output in logs, it may not be immediately clear why multiple database queries are triggered when a single method is called: + +``` +irb(main):001:0> Article.pamplemousse + Article Load (0.4ms) SELECT "articles".* FROM "articles" + Comment Load (0.2ms) SELECT "comments".* FROM "comments" WHERE "comments"."article_id" = ? [["article_id", 1]] + Comment Load (0.1ms) SELECT "comments".* FROM "comments" WHERE "comments"."article_id" = ? [["article_id", 2]] + Comment Load (0.1ms) SELECT "comments".* FROM "comments" WHERE "comments"."article_id" = ? [["article_id", 3]] +=> # +``` + +After running `ActiveRecord::Base.verbose_query_logs = true` in the `rails console` session to enable verbose query logs and running the method again, it becomes obvious what single line of code is generating all these discrete database calls: + +``` +irb(main):003:0> Article.pamplemousse + Article Load (0.2ms) SELECT "articles".* FROM "articles" + ↳ app/models/article.rb:5 + Comment Load (0.1ms) SELECT "comments".* FROM "comments" WHERE "comments"."article_id" = ? [["article_id", 1]] + ↳ app/models/article.rb:6 + Comment Load (0.1ms) SELECT "comments".* FROM "comments" WHERE "comments"."article_id" = ? [["article_id", 2]] + ↳ app/models/article.rb:6 + Comment Load (0.1ms) SELECT "comments".* FROM "comments" WHERE "comments"."article_id" = ? [["article_id", 3]] + ↳ app/models/article.rb:6 +=> # +``` + +Below each database statement you can see arrows pointing to the specific source filename (and line number) of the method that resulted in a database call. This can help you identity and address performance problems caused by N+1 queries: single database queries that generates multiple additional queries. + +Verbose query logs are enabled by default in the development environment logs after Rails 5.2. + +WARNING: We recommend against using this setting in production environments. It relies on Ruby's `Kernel#caller` method which tends to allocate a lot of memory in order to generate stacktraces of method calls. + ### Tagged Logging When running multi-user, multi-account applications, it's often useful -- cgit v1.2.3 From 317f465542116f4ef6af710120465ba0a8d951bd Mon Sep 17 00:00:00 2001 From: Matilda Smeds Date: Fri, 19 Oct 2018 19:20:04 +0300 Subject: Remove "Upgrading Old Versions" from Asset Pipeline Guide [skip ci] * How to upgrade Rails 2.x/3.2 not relevant for this Guide * All configuration changes are already included in Upgrading Ruby on Rails Guide --- guides/source/asset_pipeline.md | 57 ----------------------------------------- 1 file changed, 57 deletions(-) (limited to 'guides/source') diff --git a/guides/source/asset_pipeline.md b/guides/source/asset_pipeline.md index 66cf9da33b..faf5f7e1ca 100644 --- a/guides/source/asset_pipeline.md +++ b/guides/source/asset_pipeline.md @@ -1234,60 +1234,3 @@ it as a preprocessor for your mime type. Sprockets.register_preprocessor 'text/css', AddComment ``` -Upgrading from Old Versions of Rails ------------------------------------- - -There are a few issues when upgrading from Rails 3.0 or Rails 2.x. The first is -moving the files from `public/` to the new locations. See [Asset -Organization](#asset-organization) above for guidance on the correct locations -for different file types. - -Next is updating the various environment files with the correct default -options. - -In `application.rb`: - -```ruby -# Version of your assets, change this if you want to expire all your assets -config.assets.version = '1.0' - -# Change the path that assets are served from config.assets.prefix = "/assets" -``` - -In `development.rb`: - -```ruby -# Expands the lines which load the assets -config.assets.debug = true -``` - -And in `production.rb`: - -```ruby -# Choose the compressors to use (if any) -config.assets.js_compressor = :uglifier -# config.assets.css_compressor = :yui - -# Don't fallback to assets pipeline if a precompiled asset is missed -config.assets.compile = false - -# Generate digests for assets URLs. -config.assets.digest = true - -# Precompile additional assets (application.js, application.css, and all -# non-JS/CSS are already added) -# config.assets.precompile += %w( admin.js admin.css ) -``` - -Rails 4 and above no longer set default config values for Sprockets in `test.rb`, so -`test.rb` now requires Sprockets configuration. The old defaults in the test -environment are: `config.assets.compile = true`, `config.assets.compress = false`, -`config.assets.debug = false` and `config.assets.digest = false`. - -The following should also be added to your `Gemfile`: - -```ruby -gem 'sass-rails', "~> 3.2.3" -gem 'coffee-rails', "~> 3.2.1" -gem 'uglifier' -``` -- cgit v1.2.3 From 068413431cd2b247c084ffd567a29f1abe5c41ff Mon Sep 17 00:00:00 2001 From: Olivier Lacan Date: Fri, 19 Oct 2018 18:41:32 -0400 Subject: Use CSS flexbox for Guides index menu This notably allows us to tile each category without pushing the page down vertically as much as we previously did on any viewport wider than mobile sizes. It also means we can fit more guides which will become useful in the future since we have several new guides in the work. Finally the new layout allows three clearly distinct columns to emerge: - Start Here and Rails basics: Models, Views, Controllers, Other Components - Digging Deeper, Extending Rails, Contributing, Maintenance - Release Notes Having Release Notes shoot back up to the top of the third column is great because that makes finding the latest released version and its associated release notes much easier without having to scroll down a bunch. [ci skip] --- guides/source/layout.html.erb | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'guides/source') diff --git a/guides/source/layout.html.erb b/guides/source/layout.html.erb index dd9175e312..1f42d72756 100644 --- a/guides/source/layout.html.erb +++ b/guides/source/layout.html.erb @@ -45,16 +45,16 @@ Guides Index
  • Contribute
  • -- cgit v1.2.3 From af6dbcf1ed61ee089bfd22a67d9888ed72061d3f Mon Sep 17 00:00:00 2001 From: Olivier Lacan Date: Fri, 19 Oct 2018 18:47:51 -0400 Subject: Shorten unnecessarily long names for Guides MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The names are only used in the Guides Index overlay and several of them are longer than they need to be. For example “Ruby on Rails” is mentioned over and over again in the Release Notes section although these are obviously all Rails versions we’re listing. There’s a Maintenance Policy category with a Maintenance Policy article which is redundant. Policies makes much more sense as a category. Similarly, Contributing to Ruby on Rails is both a category and an article. “Contributions” is a better category title. “Ruby on Rails Guides Guidelines” is a gigantic mouthful. We are *in* the Rails Guides, we don’t need to specify what guides we’re talking about here. As a final added advantage, all of these shortenings make the index much easier to parse in order to find an article. [ci skip] --- guides/source/documents.yaml | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'guides/source') diff --git a/guides/source/documents.yaml b/guides/source/documents.yaml index 8f2312458d..551179c523 100644 --- a/guides/source/documents.yaml +++ b/guides/source/documents.yaml @@ -173,7 +173,7 @@ description: This guide describes the considerations needed and tools available when working directly with concurrency in a Rails application. work_in_progress: true - - name: Contributing to Ruby on Rails + name: Contributions documents: - name: Contributing to Ruby on Rails @@ -184,14 +184,14 @@ url: api_documentation_guidelines.html description: This guide documents the Ruby on Rails API documentation guidelines. - - name: Ruby on Rails Guides Guidelines + name: Guides Guidelines url: ruby_on_rails_guides_guidelines.html description: This guide documents the Ruby on Rails guides guidelines. - - name: Maintenance Policy + name: Policies documents: - - name: Maintenance Policy for Ruby on Rails + name: Maintenance Policy url: maintenance_policy.html description: What versions of Ruby on Rails are currently supported, and when to expect new versions. - @@ -202,51 +202,51 @@ url: upgrading_ruby_on_rails.html description: This guide helps in upgrading applications to latest Ruby on Rails versions. - - name: Ruby on Rails 6.0 Release Notes + name: 6.0 Release Notes work_in_progress: true url: 6_0_release_notes.html description: Release notes for Rails 6.0. - - name: Ruby on Rails 5.2 Release Notes + name: 5.2 Release Notes url: 5_2_release_notes.html description: Release notes for Rails 5.2. - - name: Ruby on Rails 5.1 Release Notes + name: 5.1 Release Notes url: 5_1_release_notes.html description: Release notes for Rails 5.1. - - name: Ruby on Rails 5.0 Release Notes + name: 5.0 Release Notes url: 5_0_release_notes.html description: Release notes for Rails 5.0. - - name: Ruby on Rails 4.2 Release Notes + name: 4.2 Release Notes url: 4_2_release_notes.html description: Release notes for Rails 4.2. - - name: Ruby on Rails 4.1 Release Notes + name: 4.1 Release Notes url: 4_1_release_notes.html description: Release notes for Rails 4.1. - - name: Ruby on Rails 4.0 Release Notes + name: 4.0 Release Notes url: 4_0_release_notes.html description: Release notes for Rails 4.0. - - name: Ruby on Rails 3.2 Release Notes + name: 3.2 Release Notes url: 3_2_release_notes.html description: Release notes for Rails 3.2. - - name: Ruby on Rails 3.1 Release Notes + name: 3.1 Release Notes url: 3_1_release_notes.html description: Release notes for Rails 3.1. - - name: Ruby on Rails 3.0 Release Notes + name: 3.0 Release Notes url: 3_0_release_notes.html description: Release notes for Rails 3.0. - - name: Ruby on Rails 2.3 Release Notes + name: 2.3 Release Notes url: 2_3_release_notes.html description: Release notes for Rails 2.3. - - name: Ruby on Rails 2.2 Release Notes + name: 2.2 Release Notes url: 2_2_release_notes.html description: Release notes for Rails 2.2. -- cgit v1.2.3 From 24367edbe6dae8fa1878423254d445177540e739 Mon Sep 17 00:00:00 2001 From: bogdanvlviv Date: Mon, 22 Oct 2018 00:12:15 +0300 Subject: Remove `javascripts` and `javascript_engine` options for generators It is unused since #33079 --- guides/source/configuring.md | 2 -- 1 file changed, 2 deletions(-) (limited to 'guides/source') diff --git a/guides/source/configuring.md b/guides/source/configuring.md index 812565b207..61bb35cf93 100644 --- a/guides/source/configuring.md +++ b/guides/source/configuring.md @@ -200,8 +200,6 @@ The full set of methods that can be used in this block are as follows: * `helper` defines whether or not to generate helpers. Defaults to `true`. * `integration_tool` defines which integration tool to use to generate integration tests. Defaults to `:test_unit`. * `system_tests` defines which integration tool to use to generate system tests. Defaults to `:test_unit`. -* `javascripts` turns on the hook for JavaScript files in generators. Used in Rails for when the `scaffold` generator is run. Defaults to `true`. -* `javascript_engine` configures the engine to be used (for eg. coffee) when generating assets. Defaults to `:js`. * `orm` defines which orm to use. Defaults to `false` and will use Active Record by default. * `resource_controller` defines which generator to use for generating a controller when using `rails generate resource`. Defaults to `:controller`. * `resource_route` defines whether a resource route definition should be generated -- cgit v1.2.3 From 5c62bd53f6589be67bd0037acbeaa9b7db7a67a3 Mon Sep 17 00:00:00 2001 From: Gannon McGibbon Date: Tue, 16 Oct 2018 17:40:29 -0400 Subject: [ci skip] Clarify load_paths behaviour Clarify `I18n.load_paths` vs `Rails.application.config.i18n.load_paths` behaviour. [Gannon McGibbon + Alberto Almagro Sotelo] --- guides/source/i18n.md | 2 ++ 1 file changed, 2 insertions(+) (limited to 'guides/source') diff --git a/guides/source/i18n.md b/guides/source/i18n.md index b1bb13e0f8..eba71eec60 100644 --- a/guides/source/i18n.md +++ b/guides/source/i18n.md @@ -135,6 +135,8 @@ I18n.available_locales = [:en, :pt] I18n.default_locale = :pt ``` +Note that appending directly to `I18n.load_paths` instead of to the application's configured i18n will _not_ override translations from external gems. + ### Managing the Locale across Requests The default locale is used for all translations unless `I18n.locale` is explicitly set. -- cgit v1.2.3 From b2e74b36bf3b858e3d08fff3ef66351c1e259caa Mon Sep 17 00:00:00 2001 From: Raghu Kamat Date: Sun, 21 Oct 2018 22:59:48 -0400 Subject: [ci skip] Fix #33914 This commit removes the dependent: :destroy option from the belong_to example since there is a warning associated with the usage of dependent: :destroy along with belongs_to. Based on the feedback on the issue #33914, I replaced dependent: :destroy with touch: :books_updated_at which will make the example consistent with the example that already exists on that page. * Also Removing the touch option from the belong_to scopes example as the option doesnt have any relation to association scope. --- guides/source/association_basics.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'guides/source') diff --git a/guides/source/association_basics.md b/guides/source/association_basics.md index b0a905c754..78a1f47407 100644 --- a/guides/source/association_basics.md +++ b/guides/source/association_basics.md @@ -868,7 +868,7 @@ While Rails uses intelligent defaults that will work well in most situations, th ```ruby class Book < ApplicationRecord - belongs_to :author, dependent: :destroy, + belongs_to :author, touch: :books_updated_at, counter_cache: true end ``` @@ -1048,8 +1048,7 @@ There may be times when you wish to customize the query used by `belongs_to`. Su ```ruby class Book < ApplicationRecord - belongs_to :author, -> { where active: true }, - dependent: :destroy + belongs_to :author, -> { where active: true } end ``` -- cgit v1.2.3 From 3b8307e8305c1b7d0ac046ae5bc448f9b3effdb3 Mon Sep 17 00:00:00 2001 From: bogdanvlviv Date: Mon, 22 Oct 2018 14:18:25 +0300 Subject: Remove mentions about `javascripts` option from the guide about generators [ci skip] This option is unused since #33079. Follow up #34277 --- guides/source/generators.md | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'guides/source') diff --git a/guides/source/generators.md b/guides/source/generators.md index f028d14998..88ce4be8da 100644 --- a/guides/source/generators.md +++ b/guides/source/generators.md @@ -219,7 +219,7 @@ If we want to avoid generating the default `app/assets/stylesheets/scaffolds.scs end ``` -The next customization on the workflow will be to stop generating stylesheet, JavaScript, and test fixture files for scaffolds altogether. We can achieve that by changing our configuration to the following: +The next customization on the workflow will be to stop generating stylesheet and test fixture files for scaffolds altogether. We can achieve that by changing our configuration to the following: ```ruby config.generators do |g| @@ -227,7 +227,6 @@ config.generators do |g| g.template_engine :erb g.test_framework :test_unit, fixture: false g.stylesheets false - g.javascripts false end ``` @@ -285,7 +284,6 @@ config.generators do |g| g.template_engine :erb g.test_framework :test_unit, fixture: false g.stylesheets false - g.javascripts false g.helper :my_helper end ``` @@ -350,7 +348,6 @@ config.generators do |g| g.template_engine :erb g.test_framework :test_unit, fixture: false g.stylesheets false - g.javascripts false end ``` @@ -385,7 +382,6 @@ config.generators do |g| g.template_engine :erb g.test_framework :shoulda, fixture: false g.stylesheets false - g.javascripts false # Add a fallback! g.fallbacks[:shoulda] = :test_unit -- cgit v1.2.3 From d77823146afd8f770e3fee55423bf66630cd8459 Mon Sep 17 00:00:00 2001 From: tzmfreedom Date: Tue, 23 Oct 2018 18:34:37 +0900 Subject: Fix PullRequest link to datetime_field changes on Rails 5.1 Release Notes --- guides/source/5_1_release_notes.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides/source') diff --git a/guides/source/5_1_release_notes.md b/guides/source/5_1_release_notes.md index d26d3d3b95..a5a7eb4b2e 100644 --- a/guides/source/5_1_release_notes.md +++ b/guides/source/5_1_release_notes.md @@ -399,7 +399,7 @@ Please refer to the [Changelog][action-view] for detailed changes. * Change `datetime_field` and `datetime_field_tag` to generate `datetime-local` fields. - ([Pull Request](https://github.com/rails/rails/pull/28061)) + ([Pull Request](https://github.com/rails/rails/pull/25469)) * New Builder-style syntax for HTML tags (`tag.div`, `tag.br`, etc.) ([Pull Request](https://github.com/rails/rails/pull/25543)) -- cgit v1.2.3 From 7217179d1e03ab3d6ece4f3aa19fe29af2a496da Mon Sep 17 00:00:00 2001 From: ohbarye Date: Wed, 24 Oct 2018 01:16:02 +0900 Subject: Fix typo of duplicated `the` [ci skip] --- guides/source/i18n.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides/source') diff --git a/guides/source/i18n.md b/guides/source/i18n.md index eba71eec60..7465726dca 100644 --- a/guides/source/i18n.md +++ b/guides/source/i18n.md @@ -1105,7 +1105,7 @@ For several reasons the Simple backend shipped with Active Support only does the That does not mean you're stuck with these limitations, though. The Ruby I18n gem makes it very easy to exchange the Simple backend implementation with something else that fits better for your needs, by passing a backend instance to the `I18n.backend=` setter. -For example, you can replace the Simple backend with the the Chain backend to chain multiple backends together. This is useful when you want to use standard translations with a Simple backend but store custom application translations in a database or other backends. +For example, you can replace the Simple backend with the Chain backend to chain multiple backends together. This is useful when you want to use standard translations with a Simple backend but store custom application translations in a database or other backends. With the Chain backend, you could use the Active Record backend and fall back to the (default) Simple backend: -- cgit v1.2.3 From 9b1da318d91c605adeef57ff6d324df97ce0f51b Mon Sep 17 00:00:00 2001 From: Alberto Almagro Date: Tue, 23 Oct 2018 19:10:08 +0200 Subject: Fully remove duplicated upgrade information [ci skip] On #34261 we removed the whole upgrade section. This warning is also included in the Upgrade guides [here](https://github.com/rails/rails/blame/master/guides/source/upgrading_ruby_on_rails.md#L1390) and should also be removed. --- guides/source/asset_pipeline.md | 5 ----- 1 file changed, 5 deletions(-) (limited to 'guides/source') diff --git a/guides/source/asset_pipeline.md b/guides/source/asset_pipeline.md index faf5f7e1ca..500e230ff9 100644 --- a/guides/source/asset_pipeline.md +++ b/guides/source/asset_pipeline.md @@ -233,11 +233,6 @@ code for JavaScript plugins and CSS frameworks. Keep in mind that third party code with references to other files also processed by the asset Pipeline (images, stylesheets, etc.), will need to be rewritten to use helpers like `asset_path`. -WARNING: If you are upgrading from Rails 3, please take into account that assets -under `lib/assets` or `vendor/assets` are available for inclusion via the -application manifests but no longer part of the precompile array. See -[Precompiling Assets](#precompiling-assets) for guidance. - #### Search Paths When a file is referenced from a manifest or a helper, Sprockets searches the -- cgit v1.2.3 From 4692ed7e12b72f2bd3adee9a243bd270f0de402e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20G=C3=BCnther?= Date: Thu, 25 Oct 2018 07:46:58 +0200 Subject: Document `deep_interpolation` parameter for bulk lookups Bulk lookups are sort of an edge case, I have not heard of them until a colleague of mine decided to dynamically iterate over a growing set of translations and receiving them in bulk as a hash with `I18n.t 'welcome'` as in the example above. When passing an interpolation to these bulk lookups, they will only be performed when also passing `deep_interpolation: true`. **Without passing `deep_interpolation` flag:** ```ruby I18n.t 'welcome', app_name: 'book store' # => {:title=>"Welcome!", :content=>"Welcome to the %{app_name}"} **With passing `deep_interpolation`:** I18n.t 'welcome', deep_interpolation: true, app_name: 'book store' # => {:title=>"Welcome!", :content=>"Welcome to the book store"} ``` I found this digging in the I18n lookup backend, the flag is listed on [I18n's Rubydoc](https://www.rubydoc.info/github/svenfuchs/i18n/master/I18n) but not otherwise listed. Since bulk lookups are mentioned here, I suggest to add a note with this flag along with it. --- guides/source/i18n.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'guides/source') diff --git a/guides/source/i18n.md b/guides/source/i18n.md index 7465726dca..c61b6ad214 100644 --- a/guides/source/i18n.md +++ b/guides/source/i18n.md @@ -664,6 +664,26 @@ I18n.t 'activerecord.errors.messages' # => {:inclusion=>"is not included in the list", :exclusion=> ... } ``` +If you want to perform interpolation on a bulk hash of translations, you need to pass `deep_interpolation: true` as a parameter. When you have the following dictionary: + +```yaml +en: + welcome: + title: "Welcome!" + content: "Welcome to the %{app_name}" +``` + +then the nested interpolation will be ignored without the setting: + +```ruby +I18n.t 'welcome', app_name: 'book store' +# => {:title=>"Welcome!", :content=>"Welcome to the %{app_name}"} + +I18n.t 'welcome', deep_interpolation: true, app_name: 'book store' +# => {:title=>"Welcome!", :content=>"Welcome to the book store"} +``` + + #### "Lazy" Lookup Rails implements a convenient way to look up the locale inside _views_. When you have the following dictionary: -- cgit v1.2.3 From 3295e23755744b7f9426d752481bb928fb02a89e Mon Sep 17 00:00:00 2001 From: Olivier Lacan Date: Sun, 21 Oct 2018 00:22:17 -0400 Subject: Use release dates for versions in Rails Guides index We repeat the phrase "Release Notes" even though release note are listed under a... "Release Notes" category already. With this change, instead of repeating ourselves, we can give people a sense of the recency of each release by simply listing the month and year of each release. This is a follow-up to #34265 as suggested by @jeremy. [ci skip] --- guides/source/documents.yaml | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'guides/source') diff --git a/guides/source/documents.yaml b/guides/source/documents.yaml index 551179c523..25c159d471 100644 --- a/guides/source/documents.yaml +++ b/guides/source/documents.yaml @@ -207,46 +207,46 @@ url: 6_0_release_notes.html description: Release notes for Rails 6.0. - - name: 5.2 Release Notes + name: Version 5.2 - April 2018 url: 5_2_release_notes.html description: Release notes for Rails 5.2. - - name: 5.1 Release Notes + name: Version 5.1 - April 2017 url: 5_1_release_notes.html description: Release notes for Rails 5.1. - - name: 5.0 Release Notes + name: Version 5.0 - June 2016 url: 5_0_release_notes.html description: Release notes for Rails 5.0. - - name: 4.2 Release Notes + name: Version 4.2 - December 2014 url: 4_2_release_notes.html description: Release notes for Rails 4.2. - - name: 4.1 Release Notes + name: Version 4.1 - April 2014 url: 4_1_release_notes.html description: Release notes for Rails 4.1. - - name: 4.0 Release Notes + name: Version 4.0 - June 2013 url: 4_0_release_notes.html description: Release notes for Rails 4.0. - - name: 3.2 Release Notes + name: Version 3.2 - January 2012 url: 3_2_release_notes.html description: Release notes for Rails 3.2. - - name: 3.1 Release Notes + name: Version 3.1 - August 2011 url: 3_1_release_notes.html description: Release notes for Rails 3.1. - - name: 3.0 Release Notes + name: Version 3.0 - August 2010 url: 3_0_release_notes.html description: Release notes for Rails 3.0. - - name: 2.3 Release Notes + name: Version 2.3 - March 2009 url: 2_3_release_notes.html description: Release notes for Rails 2.3. - - name: 2.2 Release Notes + name: Version 2.2 - November 2008 url: 2_2_release_notes.html description: Release notes for Rails 2.2. -- cgit v1.2.3 From 20ea01bd649138c46460995a3e565471b8386945 Mon Sep 17 00:00:00 2001 From: Malcolm Locke Date: Mon, 29 Oct 2018 10:26:22 +1300 Subject: Document exception from restrict_with_exception [ci skip] --- guides/source/association_basics.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'guides/source') diff --git a/guides/source/association_basics.md b/guides/source/association_basics.md index 78a1f47407..f75517c5ab 100644 --- a/guides/source/association_basics.md +++ b/guides/source/association_basics.md @@ -1258,7 +1258,7 @@ Controls what happens to the associated object when its owner is destroyed: * `:destroy` causes the associated object to also be destroyed * `:delete` causes the associated object to be deleted directly from the database (so callbacks will not execute) * `:nullify` causes the foreign key to be set to `NULL`. Callbacks are not executed. -* `:restrict_with_exception` causes an exception to be raised if there is an associated record +* `:restrict_with_exception` causes an `ActiveRecord::DeleteRestrictionError` exception to be raised if there is an associated record * `:restrict_with_error` causes an error to be added to the owner if there is an associated object It's necessary not to set or leave `:nullify` option for those associations @@ -1659,7 +1659,7 @@ Controls what happens to the associated objects when their owner is destroyed: * `:destroy` causes all the associated objects to also be destroyed * `:delete_all` causes all the associated objects to be deleted directly from the database (so callbacks will not execute) * `:nullify` causes the foreign keys to be set to `NULL`. Callbacks are not executed. -* `:restrict_with_exception` causes an exception to be raised if there are any associated records +* `:restrict_with_exception` causes an `ActiveRecord::DeleteRestrictionError` exception to be raised if there are any associated records * `:restrict_with_error` causes an error to be added to the owner if there are any associated objects ##### `:foreign_key` -- cgit v1.2.3 From 639f8fd9e51e6aa0405ac8cebdced8abe9bedaf3 Mon Sep 17 00:00:00 2001 From: Yasuo Honda Date: Tue, 30 Oct 2018 12:17:48 +0000 Subject: Restore `encoding: utf8mb4` in database.yml rails/rails#33853 and rails/rails#33929 removed `encoding: utf8mb4` from database.yml since at that time MySQL 5.1 is supported with the master branch. Since MySQL 5.1 has been dropped, we can restore `encoding: utf8mb4` in database.yml --- guides/source/configuring.md | 1 + 1 file changed, 1 insertion(+) (limited to 'guides/source') diff --git a/guides/source/configuring.md b/guides/source/configuring.md index 61bb35cf93..d03943ba4a 100644 --- a/guides/source/configuring.md +++ b/guides/source/configuring.md @@ -1011,6 +1011,7 @@ If you choose to use MySQL or MariaDB instead of the shipped SQLite3 database, y ```yaml development: adapter: mysql2 + encoding: utf8mb4 database: blog_development pool: 5 username: root -- cgit v1.2.3 From bcccf8b6a23d66f78d8b1349f92dcc19373daa9d Mon Sep 17 00:00:00 2001 From: Gannon McGibbon Date: Mon, 29 Oct 2018 15:58:29 -0400 Subject: Make i18n locale setting docs use around_action Changes `I18n.locale` assignment in docs to use `I18n.with_locale` in `around_action` to ensure locale resetting after action processing. [ci skip] [Gannon McGibbon + Leonardo Tegon] --- guides/source/i18n.md | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) (limited to 'guides/source') diff --git a/guides/source/i18n.md b/guides/source/i18n.md index c61b6ad214..10b1a6de7e 100644 --- a/guides/source/i18n.md +++ b/guides/source/i18n.md @@ -143,13 +143,14 @@ The default locale is used for all translations unless `I18n.locale` is explicit A localized application will likely need to provide support for multiple locales. To accomplish this, the locale should be set at the beginning of each request so that all strings are translated using the desired locale during the lifetime of that request. -The locale can be set in a `before_action` in the `ApplicationController`: +The locale can be set in an `around_action` in the `ApplicationController`: ```ruby -before_action :set_locale +around_action :switch_locale -def set_locale - I18n.locale = params[:locale] || I18n.default_locale +def switch_locale(&action) + locale = params[:locale] || I18n.default_locale + I18n.with_locale(locale, &action) end ``` @@ -169,10 +170,11 @@ One option you have is to set the locale from the domain name where your applica You can implement it like this in your `ApplicationController`: ```ruby -before_action :set_locale +around_action :switch_locale -def set_locale - I18n.locale = extract_locale_from_tld || I18n.default_locale +def switch_locale(&action) + locale = extract_locale_from_tld || I18n.default_locale + I18n.with_locale(locale, &action) end # Get locale from top-level domain or return +nil+ if such locale is not available @@ -212,7 +214,7 @@ This solution has aforementioned advantages, however, you may not be able or may #### Setting the Locale from URL Params -The most usual way of setting (and passing) the locale would be to include it in URL params, as we did in the `I18n.locale = params[:locale]` _before_action_ in the first example. We would like to have URLs like `www.example.com/books?locale=ja` or `www.example.com/ja/books` in this case. +The most usual way of setting (and passing) the locale would be to include it in URL params, as we did in the `I18n.with_locale(params[:locale], &action)` _around_action_ in the first example. We would like to have URLs like `www.example.com/books?locale=ja` or `www.example.com/ja/books` in this case. This approach has almost the same set of advantages as setting the locale from the domain name: namely that it's RESTful and in accord with the rest of the World Wide Web. It does require a little bit more work to implement, though. @@ -275,8 +277,11 @@ NOTE: Have a look at various gems which simplify working with routes: [routing_f An application with authenticated users may allow users to set a locale preference through the application's interface. With this approach, a user's selected locale preference is persisted in the database and used to set the locale for authenticated requests by that user. ```ruby -def set_locale - I18n.locale = current_user.try(:locale) || I18n.default_locale +around_action :switch_locale + +def switch_locale(&action) + locale = current_user.try(:locale) || I18n.default_locale + I18n.with_locale(locale, &action) end ``` @@ -291,10 +296,11 @@ The `Accept-Language` HTTP header indicates the preferred language for request's A trivial implementation of using an `Accept-Language` header would be: ```ruby -def set_locale +def switch_locale(&action) logger.debug "* Accept-Language: #{request.env['HTTP_ACCEPT_LANGUAGE']}" - I18n.locale = extract_locale_from_accept_language_header + locale = extract_locale_from_accept_language_header logger.debug "* Locale set to '#{I18n.locale}'" + I18n.with_locale(locale, &action) end private @@ -335,10 +341,12 @@ end ```ruby # app/controllers/application_controller.rb class ApplicationController < ActionController::Base - before_action :set_locale - def set_locale - I18n.locale = params[:locale] || I18n.default_locale + around_action :switch_locale + + def switch_locale(&action) + locale = params[:locale] || I18n.default_locale + I18n.with_locale(locale, &action) end end ``` -- cgit v1.2.3 From 0f19d7b3c2f90d8cb67c323a1233cfeb7ce96eee Mon Sep 17 00:00:00 2001 From: Nick Coyne Date: Mon, 5 Nov 2018 08:46:44 +1300 Subject: Fix typo Just a small typo fix for the recently merged #34257 --- guides/source/debugging_rails_applications.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides/source') diff --git a/guides/source/debugging_rails_applications.md b/guides/source/debugging_rails_applications.md index 7f7766e7d7..3a383cbd4d 100644 --- a/guides/source/debugging_rails_applications.md +++ b/guides/source/debugging_rails_applications.md @@ -232,7 +232,7 @@ irb(main):003:0> Article.pamplemousse => # ``` -Below each database statement you can see arrows pointing to the specific source filename (and line number) of the method that resulted in a database call. This can help you identity and address performance problems caused by N+1 queries: single database queries that generates multiple additional queries. +Below each database statement you can see arrows pointing to the specific source filename (and line number) of the method that resulted in a database call. This can help you identify and address performance problems caused by N+1 queries: single database queries that generates multiple additional queries. Verbose query logs are enabled by default in the development environment logs after Rails 5.2. -- cgit v1.2.3 From 1c11688b5624394c3792d1bb37599fd1e3452c9c Mon Sep 17 00:00:00 2001 From: Gannon McGibbon Date: Tue, 6 Nov 2018 14:17:23 -0500 Subject: Add CVE note to security guide and gemspecs [ci skip] --- guides/source/security.md | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'guides/source') diff --git a/guides/source/security.md b/guides/source/security.md index bb996cc39c..66b922ea35 100644 --- a/guides/source/security.md +++ b/guides/source/security.md @@ -1235,6 +1235,11 @@ version: Rails.application.credentials.some_api_key! # => raises KeyError: :some_api_key is blank ``` +Dependency Management and CVEs +------------------------------ + +Please note that we do not accept patches for CVE version bumps. This is because application owners need to manually update their gems regardless of our efforts. Use `bundle update --conservative gem_name` to safely update vulnerable dependencies. + Additional Resources -------------------- -- cgit v1.2.3 From e74fdbe00cd0f403d34f2bc83eb09e7a5bc56109 Mon Sep 17 00:00:00 2001 From: Gannon McGibbon Date: Tue, 6 Nov 2018 18:05:40 -0500 Subject: Amend CVE note and security guide section wordings Reword first sentence of dep management and CVE section of security guide. Also, reword and move gemspec notes above deps. [ci skip] --- guides/source/security.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides/source') diff --git a/guides/source/security.md b/guides/source/security.md index 66b922ea35..dbec3cdd2d 100644 --- a/guides/source/security.md +++ b/guides/source/security.md @@ -1238,7 +1238,7 @@ Rails.application.credentials.some_api_key! # => raises KeyError: :some_api_key Dependency Management and CVEs ------------------------------ -Please note that we do not accept patches for CVE version bumps. This is because application owners need to manually update their gems regardless of our efforts. Use `bundle update --conservative gem_name` to safely update vulnerable dependencies. +We don’t bump dependencies just to encourage use of new versions, including for security issues. This is because application owners need to manually update their gems regardless of our efforts. Use `bundle update --conservative gem_name` to safely update vulnerable dependencies. Additional Resources -------------------- -- cgit v1.2.3 From a6b0c4a2d2fd466c99de483ee3a3396bc270e9a7 Mon Sep 17 00:00:00 2001 From: Viktor Fonic Date: Sun, 13 May 2018 21:37:44 +0200 Subject: Docs: Update Development Dependencies Install * Move all the testing related stuff to the contributing guide and redirect the reader to this guide once the installation process is finished as running tests is the logical next step. * Group documentation instructions by OS, not by gem * It eases the installation process and lessen the need to scroll through the guide * There's still a list of all additional services required for each of the gems above the instructions for each OS. * Also update a bit the instructions * Update some package names * Add `yarn` to the package list for Arch Linux and FreeBSD * Use `dnf` instead of `yum` for Fedora and CentOS * Advise the user to use `brew bundle` on macOS to lessen the maintenance burden for this OS and ease the process for the user. [ci skip] --- guides/source/contributing_to_ruby_on_rails.md | 23 +- guides/source/development_dependencies_install.md | 364 ++++++---------------- guides/source/ruby_on_rails_guides_guidelines.md | 4 +- 3 files changed, 121 insertions(+), 270 deletions(-) (limited to 'guides/source') diff --git a/guides/source/contributing_to_ruby_on_rails.md b/guides/source/contributing_to_ruby_on_rails.md index ed47a0de0f..709a5146e9 100644 --- a/guides/source/contributing_to_ruby_on_rails.md +++ b/guides/source/contributing_to_ruby_on_rails.md @@ -324,6 +324,26 @@ $ cd actionmailer $ bundle exec rake test ``` +#### For a Specific Directory + +If you want to run the tests located in a specific directory use the `TEST_DIR` +environment variable. For example, this will run the tests in the +`railties/test/generators` directory only: + +```bash +$ cd railties +$ TEST_DIR=generators bundle exec rake test +``` + +#### For a Specific File + +You can run the tests for a particular file by using: + +```bash +$ cd actionpack +$ bundle exec ruby -w -Itest test/template/form_helper_test.rb +``` + #### Running a Single Test You can run a single test through ruby. For instance: @@ -333,8 +353,7 @@ $ cd actionmailer $ bundle exec ruby -w -Itest test/mail_layout_test.rb -n test_explicit_class_layout ``` -The `-n` option allows you to run a single method instead of the whole -file. +The `-n` option allows you to run a single method instead of the whole file. #### Running tests with a specific seed diff --git a/guides/source/development_dependencies_install.md b/guides/source/development_dependencies_install.md index 07538a1cb7..d52946be08 100644 --- a/guides/source/development_dependencies_install.md +++ b/guides/source/development_dependencies_install.md @@ -8,8 +8,6 @@ This guide covers how to setup an environment for Ruby on Rails core development After reading this guide, you will know: * How to set up your machine for Rails development -* How to run specific groups of unit tests from the Rails test suite -* How the Active Record portion of the Rails test suite operates -------------------------------------------------------------------------------- @@ -43,195 +41,131 @@ $ git clone https://github.com/rails/rails.git $ cd rails ``` -### Set up and Run the Tests +### Install Additional Tools and Services -The test suite must pass with any submitted code. No matter whether you are writing a new patch, or evaluating someone else's, you need to be able to run the tests. +Some Rails tests depend on additional tools that you need to install before running those specific tests. -Install first SQLite3 and its development files for the `sqlite3` gem. On macOS -users are done with: +Here's the list of each gems' additional dependencies: -```bash -$ brew install sqlite3 -``` - -In Ubuntu you're done with just: - -```bash -$ sudo apt-get install sqlite3 libsqlite3-dev -``` - -If you are on Fedora or CentOS, you're done with - -```bash -$ sudo yum install libsqlite3x libsqlite3x-devel -``` - -If you are on Arch Linux, you will need to run: - -```bash -$ sudo pacman -S sqlite -``` - -For FreeBSD users, you're done with: - -```bash -# pkg install sqlite3 -``` +* Action Cable depends on Redis +* Active Record depends on SQLite3, MySQL and PostgreSQL +* Active Storage depends on Yarn (additionally Yarn depends on + [Node.js](https://nodejs.org/)), ImageMagick, FFmpeg, muPDF, and on macOS + also XQuartz and Poppler. +* Active Support depends on memcached and Redis +* Railties depend on a JavaScript runtime environment, such as having + [Node.js](https://nodejs.org/) installed. -Or compile the `databases/sqlite3` port. +Install all the services you need to properly test the full gem you'll be +making changes to. -Get a recent version of [Bundler](https://bundler.io/) +NOTE: Redis' documentation discourage installations with package managers as those are usually outdated. Installing from source and bringing the server up is straight forward and well documented on [Redis' documentation](https://redis.io/download#installation). -```bash -$ gem install bundler -$ gem update bundler -``` +NOTE: Active Record tests _must_ pass for at least MySQL, PostgreSQL, and SQLite3. Subtle differences between the various adapters have been behind the rejection of many patches that looked OK when tested only against single adapter. -and run: +Below you can find instructions on how to install all of the additional +tools for different OSes. -```bash -$ bundle install --without db -``` - -This command will install all dependencies except the MySQL and PostgreSQL Ruby drivers. We will come back to these soon. +#### macOS -NOTE: If you would like to run the tests that use memcached, you need to ensure that you have it installed and running. +On macOS you can use [Homebrew](https://brew.sh/) to install all of the +additional tools. -You can use [Homebrew](https://brew.sh/) to install memcached on macOS: +To install all run: ```bash -$ brew install memcached +$ brew bundle ``` -On Ubuntu you can install it with apt-get: +You'll also need to start each of the installed services. To list all +available services run: ```bash -$ sudo apt-get install memcached +$ brew services list ``` -Or use yum on Fedora or CentOS: +You can then start each of the services one by one like this: ```bash -$ sudo yum install memcached +$ brew services start mysql ``` -If you are running on Arch Linux: - -```bash -$ sudo pacman -S memcached -``` - -For FreeBSD users, you're done with: - -```bash -# pkg install memcached -``` +Replace `mysql` with the name of the service you want to start. -Alternatively, you can compile the `databases/memcached` port. +#### Ubuntu -With the dependencies now installed, you can run the test suite with: +To install all run: ```bash -$ bundle exec rake test -``` - -You can also run tests for a specific component, like Action Pack, by going into its directory and executing the same command: +$ sudo apt-get update +$ sudo apt-get install sqlite3 libsqlite3-dev + mysql-server libmysqlclient-dev + postgresql postgresql-client postgresql-contrib libpq-dev + redis-server memcached imagemagick ffmpeg mupdf mupdf-tools -```bash -$ cd actionpack -$ bundle exec rake test +# Install Yarn +$ curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add - +$ echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list +$ sudo apt-get install yarn ``` -If you want to run the tests located in a specific directory use the `TEST_DIR` environment variable. For example, this will run the tests in the `railties/test/generators` directory only: - -```bash -$ cd railties -$ TEST_DIR=generators bundle exec rake test -``` +#### Fedora or CentOS -You can run the tests for a particular file by using: +To install all run: ```bash -$ cd actionpack -$ bundle exec ruby -Itest test/template/form_helper_test.rb -``` - -Or, you can run a single test in a particular file: +$ sudo dnf install sqlite-devel sqlite-libs + mysql-server mysql-devel + postgresql-server postgresql-devel + redis memcached imagemagick ffmpeg mupdf -```bash -$ cd actionpack -$ bundle exec ruby -Itest path/to/test.rb -n test_name +# Install Yarn +# Use this command if you do not have Node.js installed +$ curl --silent --location https://rpm.nodesource.com/setup_8.x | sudo bash - +# If you have Node.js installed, use this command instead +$ curl --silent --location https://dl.yarnpkg.com/rpm/yarn.repo | sudo tee /etc/yum.repos.d/yarn.repo +$ sudo dnf install yarn ``` -### Railties Setup - -Some Railties tests depend on a JavaScript runtime environment, such as having [Node.js](https://nodejs.org/) installed. - -### Active Record Setup - -Active Record's test suite runs three times: once for SQLite3, once for MySQL, and once for PostgreSQL. We are going to see now how to set up the environment for them. - -WARNING: If you're working with Active Record code, you _must_ ensure that the tests pass for at least MySQL, PostgreSQL, and SQLite3. Subtle differences between the various adapters have been behind the rejection of many patches that looked OK when tested only against MySQL. - -#### Database Configuration - -The Active Record test suite requires a custom config file: `activerecord/test/config.yml`. An example is provided in `activerecord/test/config.example.yml` which can be copied and used as needed for your environment. +#### Arch Linux -#### MySQL and PostgreSQL - -To be able to run the suite for MySQL and PostgreSQL we need their gems. Install -first the servers, their client libraries, and their development files. - -On macOS, you can run: - -```bash -$ brew install mysql -$ brew install postgresql -``` - -Follow the instructions given by Homebrew to start these. - -On Ubuntu, just run: - -```bash -$ sudo apt-get install mysql-server libmysqlclient-dev -$ sudo apt-get install postgresql postgresql-client postgresql-contrib libpq-dev -``` - -On Fedora or CentOS, just run: +To install all run: ```bash -$ sudo yum install mysql-server mysql-devel -$ sudo yum install postgresql-server postgresql-devel +$ sudo pacman -S sqlite + mariadb libmariadbclient mariadb-clients + postgresql postgresql-libs + redis memcached imagemagick ffmpeg mupdf mupdf-tools poppler + yarn +$ sudo systemctl start redis ``` -If you are running Arch Linux, MySQL isn't supported anymore so you will need to -use MariaDB instead (see [this announcement](https://www.archlinux.org/news/mariadb-replaces-mysql-in-repositories/)): +NOTE: If you are running Arch Linux, MySQL isn't supported anymore so you will need to +use MariaDB instead (see [this announcement](https://www.archlinux.org/news/mariadb-replaces-mysql-in-repositories/)). -```bash -$ sudo pacman -S mariadb libmariadbclient mariadb-clients -$ sudo pacman -S postgresql postgresql-libs -``` +#### FreeBSD -FreeBSD users will have to run the following: +To install all run: ```bash -# pkg install mysql56-client mysql56-server -# pkg install postgresql94-client postgresql94-server +# pkg install sqlite3 + mysql80-client mysql80-server + postgresql11-client postgresql11-server + memcached imagemagick ffmpeg mupdf + yarn +# portmaster databases/redis ``` -Or install them through ports (they are located under the `databases` folder). -If you run into troubles during the installation of MySQL, please see -[the MySQL documentation](http://dev.mysql.com/doc/refman/5.1/en/freebsd-installation.html). +Or install everyting through ports (these packages are located under the +`databases` folder). -After that, run: +NOTE: If you run into troubles during the installation of MySQL, please see +[the MySQL documentation](https://dev.mysql.com/doc/refman/8.0/en/freebsd-installation.html). -```bash -$ rm .bundle/config -$ bundle install -``` +### Database Configuration -First, we need to delete `.bundle/config` because Bundler remembers in that file that we didn't want to install the "db" group (alternatively you can edit the file). +There are couple of additional steps required to configure database engines +required for running Active Record tests. In order to be able to run the test suite against MySQL you need to create a user named `rails` with privileges on the test databases: @@ -247,13 +181,6 @@ mysql> GRANT ALL PRIVILEGES ON inexistent_activerecord_unittest.* to 'rails'@'localhost'; ``` -and create the test databases: - -```bash -$ cd activerecord -$ bundle exec rake db:mysql:build -``` - PostgreSQL's authentication works differently. To setup the development environment with your development account, on Linux or BSD, you just have to run: @@ -267,21 +194,24 @@ and for macOS: $ createuser --superuser $USER ``` -Then, you need to create the test databases with: +Then, you need to create the test databases for both MySQL and PostgreSQL with: ```bash $ cd activerecord -$ bundle exec rake db:postgresql:build +$ bundle exec rake db:create ``` -It is possible to build databases for both PostgreSQL and MySQL with: +NOTE: You'll see the following warning (or localized warning) during activating HStore extension in PostgreSQL 9.1.x or earlier: "WARNING: => is deprecated as an operator". + +You can also create test databases for each database engine separately: ```bash $ cd activerecord -$ bundle exec rake db:create +$ bundle exec rake db:mysql:build +$ bundle exec rake db:postgresql:build ``` -You can cleanup the databases using: +and you can drop the databases using: ```bash $ cd activerecord @@ -290,138 +220,40 @@ $ bundle exec rake db:drop NOTE: Using the Rake task to create the test databases ensures they have the correct character set and collation. -NOTE: You'll see the following warning (or localized warning) during activating HStore extension in PostgreSQL 9.1.x or earlier: "WARNING: => is deprecated as an operator". - If you're using another database, check the file `activerecord/test/config.yml` or `activerecord/test/config.example.yml` for default connection information. You can edit `activerecord/test/config.yml` to provide different credentials on your machine if you must, but obviously you should not push any such changes back to Rails. -### Action Cable Setup - -Action Cable uses Redis as its default subscriptions adapter ([read more](action_cable_overview.html#broadcasting)). Thus, in order to have Action Cable's tests passing you need to install and have Redis running. - -#### Install Redis From Source +### Install JavaScript dependencies -Redis' documentation discourage installations with package managers as those are usually outdated. Installing from source and bringing the server up is straight forward and well documented on [Redis' documentation](https://redis.io/download#installation). - -#### Install Redis From Package Manager - -On macOS, you can run: - -```bash -$ brew install redis -``` - -Follow the instructions given by Homebrew to start these. - -On Ubuntu, just run: - -```bash -$ sudo apt-get install redis-server -``` - -On Fedora or CentOS (requires EPEL enabled), just run: - -```bash -$ sudo yum install redis -``` - -If you are running Arch Linux, just run: - -```bash -$ sudo pacman -S redis -$ sudo systemctl start redis -``` - -FreeBSD users will have to run the following: - -```bash -# portmaster databases/redis -``` - -### Active Storage Setup - -When working on Active Storage, it is important to note that you need to -install its JavaScript dependencies while working on that section of the -codebase. In order to install these dependencies, it is necessary to -have Yarn, a Node.js package manager, available on your system. A -prerequisite for installing this package manager is that -[Node.js](https://nodejs.org) is installed. - - -On macOS, you can run: - -```bash -$ brew install yarn -``` - -On Ubuntu, you can run: - -```bash -$ curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add - -$ echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list - -$ sudo apt-get update && sudo apt-get install yarn -``` - -On Fedora or CentOS, just run: - -```bash -$ sudo wget https://dl.yarnpkg.com/rpm/yarn.repo -O /etc/yum.repos.d/yarn.repo - -$ sudo yum install yarn -``` - -Finally, after installing Yarn, you will need to run the following -command inside of the `activestorage` directory to install the dependencies: +If you installed Yarn, you will need to install the javascript dependencies: ```bash +$ cd activestorage $ yarn install ``` -Extracting previews, tested in Active Storage's test suite requires third-party -applications, ImageMagick for images, FFmpeg for video and muPDF for PDFs, and on macOS also XQuartz -and Poppler. Without these applications installed, Active Storage tests will -raise errors. +### Install Bundler gem -On macOS you can run: +Get a recent version of [Bundler](https://bundler.io/) ```bash -$ brew install ffmpeg -$ brew install imagemagick -$ brew cask install xquartz -$ brew install mupdf-tools -$ brew install poppler +$ gem install bundler +$ gem update bundler ``` -On Ubuntu, you can run: +and run: ```bash -$ sudo apt-get update -$ sudo apt-get install ffmpeg -$ sudo apt-get install imagemagick -$ sudo apt-get install mupdf mupdf-tools +$ bundle install ``` -On Fedora or CentOS, just run: +or: ```bash -$ sudo yum install ffmpeg -$ sudo yum install imagemagick -$ sudo yum install mupdf +$ bundle install --without db ``` -FreeBSD users can just run: +if you don't need to run Active Record tests. -```bash -# pkg install imagemagick -# pkg install ffmpeg -# pkg install mupdf -``` - -On Arch Linux, you can run: +### Contribute to Rails -```bash -$ sudo pacman -S ffmpeg -$ sudo pacman -S imagemagick -$ sudo pacman -S mupdf mupdf-tools -$ sudo pacman -S poppler -``` +After you've setup everything, read how you can start [contributing](contributing_to_ruby_on_rails.html#running-an-application-against-your-local-branch). diff --git a/guides/source/ruby_on_rails_guides_guidelines.md b/guides/source/ruby_on_rails_guides_guidelines.md index f5c0ba5b2d..4b56cf6296 100644 --- a/guides/source/ruby_on_rails_guides_guidelines.md +++ b/guides/source/ruby_on_rails_guides_guidelines.md @@ -107,8 +107,8 @@ HTML Guides ----------- Before generating the guides, make sure that you have the latest version of -Bundler installed on your system. As of this writing, you must install Bundler -1.3.5 or later on your device. +Bundler installed on your system. You can find the latest Bundler version +[here](https://rubygems.org/gems/bundler). As of this writing, it's v1.17.1. To install the latest version of Bundler, run `gem install bundler`. -- cgit v1.2.3 From e53d2325d52f42c4646696a4db7af472c3a1ec7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ana=20Mar=C3=ADa=20Mart=C3=ADnez=20G=C3=B3mez?= Date: Fri, 9 Nov 2018 15:09:24 +0100 Subject: Clarify the validation of present associations I think that it is not clear what means that _an association is present_. Add that it is checking that the foreign key is not empty and that the referenced object exists to clarify it. --- guides/source/active_record_validations.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'guides/source') diff --git a/guides/source/active_record_validations.md b/guides/source/active_record_validations.md index afe837a97c..25f6f7bd2c 100644 --- a/guides/source/active_record_validations.md +++ b/guides/source/active_record_validations.md @@ -538,7 +538,8 @@ end If you want to be sure that an association is present, you'll need to test whether the associated object itself is present, and not the foreign key used -to map the association. +to map the association. This way, it is not only checked that the foreign key +is not empty but also that the referenced object exists. ```ruby class LineItem < ApplicationRecord -- cgit v1.2.3 From 9a7f95c229fe6f1ac0251488d337788bfa99b308 Mon Sep 17 00:00:00 2001 From: Evgeny Sugakov Date: Sat, 10 Nov 2018 11:19:58 +0100 Subject: Update `action_cable_overview.md`: fix typo. [ci skip] --- guides/source/action_cable_overview.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'guides/source') diff --git a/guides/source/action_cable_overview.md b/guides/source/action_cable_overview.md index e6c0ae31a8..2f602c3e0a 100644 --- a/guides/source/action_cable_overview.md +++ b/guides/source/action_cable_overview.md @@ -242,9 +242,9 @@ WebNotificationsChannel.broadcast_to( ``` The `WebNotificationsChannel.broadcast_to` call places a message in the current -subscription adapter (by default `redis` for production and `async` for development and -test environments)'s pubsub queue under a separate broadcasting name for each user. -For a user with an ID of 1, the broadcasting name would be `web_notifications:1`. +subscription adapter's pubsub queue under a separate broadcasting name for each user. +The default pubsub queue for Action Cable is `redis` in production and `async` in development and +test environments. For a user with an ID of 1, the broadcasting name would be `web_notifications:1`. The channel has been instructed to stream everything that arrives at `web_notifications:1` directly to the client by invoking the `received` -- cgit v1.2.3 From bfc4d8be0a61b795ee122c5f426e0873938d0e41 Mon Sep 17 00:00:00 2001 From: Jacob Evelyn Date: Mon, 15 Oct 2018 15:00:07 -0400 Subject: Add support for UNLOGGED Postgresql tables This commit adds support for the `ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.create_unlogged_tables` setting, which turns `CREATE TABLE` SQL statements into `CREATE UNLOGGED TABLE` statements. This can improve PostgreSQL performance but at the cost of data durability, and thus it is highly recommended that you *DO NOT* enable this in a production environment. --- guides/source/configuring.md | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'guides/source') diff --git a/guides/source/configuring.md b/guides/source/configuring.md index d03943ba4a..706964090e 100644 --- a/guides/source/configuring.md +++ b/guides/source/configuring.md @@ -379,6 +379,14 @@ The MySQL adapter adds one additional configuration option: * `ActiveRecord::ConnectionAdapters::Mysql2Adapter.emulate_booleans` controls whether Active Record will consider all `tinyint(1)` columns as booleans. Defaults to `true`. +The PostgreSQL adapter adds one additional configuration option: + +* `ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.create_unlogged_tables` + controls whether database tables created should be "unlogged," which can speed + up performance but adds a risk of data loss if the database crashes. It is + highly recommended that you do not enable this in a production environment. + Defaults to `false` in all environments. + The SQLite3Adapter adapter adds one additional configuration option: * `ActiveRecord::ConnectionAdapters::SQLite3Adapter.represent_boolean_as_integer` -- cgit v1.2.3 From 39806b6d98c1dbcbaac6748274e2cc3fbfba3495 Mon Sep 17 00:00:00 2001 From: "Marcel M. Cary" Date: Tue, 13 Nov 2018 15:29:43 -0800 Subject: Describe how has_many's :dependent option affects #delete I was puzzled about why `collection=` was destroying the removed records on an association with `dependent: :destroy`, even after consulting the documentation for that option. I had to dive into the Active Record source to understand what was going on: eventually `collection=` calls `collection.delete` on the ousted records, and it also uses the `:dependent` option to decide how to remove records. It would have helped me to have mention of this in the documentation for `:dependent`, not just under `collection.delete` (which I found much later). Briefly mention the broader impacts of `:dependent` in the Association Basics guide. [ci skip] --- guides/source/association_basics.md | 2 ++ 1 file changed, 2 insertions(+) (limited to 'guides/source') diff --git a/guides/source/association_basics.md b/guides/source/association_basics.md index f75517c5ab..822dee08f0 100644 --- a/guides/source/association_basics.md +++ b/guides/source/association_basics.md @@ -1662,6 +1662,8 @@ Controls what happens to the associated objects when their owner is destroyed: * `:restrict_with_exception` causes an `ActiveRecord::DeleteRestrictionError` exception to be raised if there are any associated records * `:restrict_with_error` causes an error to be added to the owner if there are any associated objects +The `:destroy` and `:delete_all` options also affect the samantics of the `collection.delete` and `collection=` methods by causing them to destroy associated objects when they are removed from the collection. + ##### `:foreign_key` By convention, Rails assumes that the column used to hold the foreign key on the other model is the name of this model with the suffix `_id` added. The `:foreign_key` option lets you set the name of the foreign key directly: -- cgit v1.2.3 From 9b0b066ef72f64571ce0a97ee5a70886a95afc25 Mon Sep 17 00:00:00 2001 From: Espartaco Palma Date: Wed, 14 Nov 2018 00:10:02 -0800 Subject: fix typo on association_basics.md [ci skip] --- guides/source/association_basics.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides/source') diff --git a/guides/source/association_basics.md b/guides/source/association_basics.md index 822dee08f0..4f3e8b2cff 100644 --- a/guides/source/association_basics.md +++ b/guides/source/association_basics.md @@ -1662,7 +1662,7 @@ Controls what happens to the associated objects when their owner is destroyed: * `:restrict_with_exception` causes an `ActiveRecord::DeleteRestrictionError` exception to be raised if there are any associated records * `:restrict_with_error` causes an error to be added to the owner if there are any associated objects -The `:destroy` and `:delete_all` options also affect the samantics of the `collection.delete` and `collection=` methods by causing them to destroy associated objects when they are removed from the collection. +The `:destroy` and `:delete_all` options also affect the semantics of the `collection.delete` and `collection=` methods by causing them to destroy associated objects when they are removed from the collection. ##### `:foreign_key` -- cgit v1.2.3 From 96a31c41afc0ca1ee84f1927822dea33992c8db8 Mon Sep 17 00:00:00 2001 From: tnantoka Date: Fri, 16 Nov 2018 10:20:27 +0900 Subject: Replace cache_key with cache_key_with_version on caching_with_rails guides [ci skip] --- guides/source/caching_with_rails.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'guides/source') diff --git a/guides/source/caching_with_rails.md b/guides/source/caching_with_rails.md index 321eee637f..67b097f2ae 100644 --- a/guides/source/caching_with_rails.md +++ b/guides/source/caching_with_rails.md @@ -302,7 +302,7 @@ class Product < ApplicationRecord end ``` -NOTE: Notice that in this example we used the `cache_key` method, so the resulting cache key will be something like `products/233-20140225082222765838000/competing_price`. `cache_key` generates a string based on the model's `id` and `updated_at` attributes. This is a common convention and has the benefit of invalidating the cache whenever the product is updated. In general, when you use low-level caching for instance level information, you need to generate a cache key. +NOTE: Notice that in this example we used the `cache_key_with_version` method, so the resulting cache key will be something like `products/233-20140225082222765838000/competing_price`. `cache_key_with_version` generates a string based on the model's `id` and `updated_at` attributes. This is a common convention and has the benefit of invalidating the cache whenever the product is updated. In general, when you use low-level caching for instance level information, you need to generate a cache key. ### SQL Caching @@ -563,7 +563,7 @@ class ProductsController < ApplicationController # If the request is stale according to the given timestamp and etag value # (i.e. it needs to be processed again) then execute this block - if stale?(last_modified: @product.updated_at.utc, etag: @product.cache_key) + if stale?(last_modified: @product.updated_at.utc, etag: @product.cache_key_with_version) respond_to do |wants| # ... normal response processing end @@ -577,7 +577,7 @@ class ProductsController < ApplicationController end ``` -Instead of an options hash, you can also simply pass in a model. Rails will use the `updated_at` and `cache_key` methods for setting `last_modified` and `etag`: +Instead of an options hash, you can also simply pass in a model. Rails will use the `updated_at` and `cache_key_with_version` methods for setting `last_modified` and `etag`: ```ruby class ProductsController < ApplicationController -- cgit v1.2.3 From 308d637550f4b1ec7550df3fa6ab8db9fe7c81e8 Mon Sep 17 00:00:00 2001 From: jacobherrington Date: Sun, 18 Nov 2018 22:36:44 -0600 Subject: Change queueing to queuing in docs and comments [skip ci] My spellchecker flagged this as an incorrect spelling, upon further research it appears to be a point of contention in English. Either way might work. After further examination queuing is much more common in the Rails codebase so making this change will serve to standardize the spelling. --- guides/source/configuring.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides/source') diff --git a/guides/source/configuring.md b/guides/source/configuring.md index 706964090e..de6766e12e 100644 --- a/guides/source/configuring.md +++ b/guides/source/configuring.md @@ -731,7 +731,7 @@ There are a few configuration options available in Active Support: `config.active_job` provides the following configuration options: -* `config.active_job.queue_adapter` sets the adapter for the queueing backend. The default adapter is `:async`. For an up-to-date list of built-in adapters see the [ActiveJob::QueueAdapters API documentation](http://api.rubyonrails.org/classes/ActiveJob/QueueAdapters.html). +* `config.active_job.queue_adapter` sets the adapter for the queuing backend. The default adapter is `:async`. For an up-to-date list of built-in adapters see the [ActiveJob::QueueAdapters API documentation](http://api.rubyonrails.org/classes/ActiveJob/QueueAdapters.html). ```ruby # Be sure to have the adapter's gem in your Gemfile -- cgit v1.2.3 From 97412e08a65bbc3a32aa5f71e9e2121c2420fa34 Mon Sep 17 00:00:00 2001 From: Shota Iguchi Date: Mon, 19 Nov 2018 15:59:14 +0900 Subject: [ci skip] Update active_job_basics.md ApplicationJob should be inherits ActiveJob::Base --- guides/source/active_job_basics.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides/source') diff --git a/guides/source/active_job_basics.md b/guides/source/active_job_basics.md index 4dc69ef911..39239852ca 100644 --- a/guides/source/active_job_basics.md +++ b/guides/source/active_job_basics.md @@ -289,7 +289,7 @@ style if the code inside your block is so short that it fits in a single line. For example, you could send metrics for every job enqueued: ```ruby -class ApplicationJob +class ApplicationJob < ActiveJob::Base before_enqueue { |job| $statsd.increment "#{job.class.name.underscore}.enqueue" } end ``` -- cgit v1.2.3 From 41e47f5155211ff0f9bbd89fefb88546696fc3a3 Mon Sep 17 00:00:00 2001 From: Alberto Almagro Date: Fri, 5 Oct 2018 00:49:40 +0200 Subject: Indent guides as rails help command output[ci skip] The output from `rails help` actually leaves an empty space when printing the command lists. This commit adapts this guide to have the same format. --- guides/source/command_line.md | 50 +++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 25 deletions(-) (limited to 'guides/source') diff --git a/guides/source/command_line.md b/guides/source/command_line.md index 5fd3ad17de..bbebf97c3f 100644 --- a/guides/source/command_line.md +++ b/guides/source/command_line.md @@ -36,35 +36,35 @@ $ rails --help Usage: rails COMMAND [ARGS] The most common rails commands are: -generate Generate new code (short-cut alias: "g") -console Start the Rails console (short-cut alias: "c") -server Start the Rails server (short-cut alias: "s") -... + generate Generate new code (short-cut alias: "g") + console Start the Rails console (short-cut alias: "c") + server Start the Rails server (short-cut alias: "s") + ... All commands can be run with -h (or --help) for more information. In addition to those commands, there are: -about List versions of all Rails ... -assets:clean[keep] Remove old compiled assets -assets:clobber Remove compiled assets -assets:environment Load asset compile environment -assets:precompile Compile all the assets ... -... -db:fixtures:load Loads fixtures into the ... -db:migrate Migrate the database ... -db:migrate:status Display status of migrations -db:rollback Rolls the schema back to ... -db:schema:cache:clear Clears a db/schema_cache.yml file -db:schema:cache:dump Creates a db/schema_cache.yml file -db:schema:dump Creates a db/schema.rb file ... -db:schema:load Loads a schema.rb file ... -db:seed Loads the seed data ... -db:structure:dump Dumps the database structure ... -db:structure:load Recreates the databases ... -db:version Retrieves the current schema ... -... -restart Restart app by touching ... -tmp:create Creates tmp directories ... + about List versions of all Rails ... + assets:clean[keep] Remove old compiled assets + assets:clobber Remove compiled assets + assets:environment Load asset compile environment + assets:precompile Compile all the assets ... + ... + db:fixtures:load Loads fixtures into the ... + db:migrate Migrate the database ... + db:migrate:status Display status of migrations + db:rollback Rolls the schema back to ... + db:schema:cache:clear Clears a db/schema_cache.yml file + db:schema:cache:dump Creates a db/schema_cache.yml file + db:schema:dump Creates a db/schema.rb file ... + db:schema:load Loads a schema.rb file ... + db:seed Loads the seed data ... + db:structure:dump Dumps the database structure ... + db:structure:load Recreates the databases ... + db:version Retrieves the current schema ... + ... + restart Restart app by touching ... + tmp:create Creates tmp directories ... ``` Let's create a simple Rails application to step through each of these commands in context. -- cgit v1.2.3 From d8611eba352ebc455c380f8e178a0f885420cc25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alfonso=20Jim=C3=A9nez?= Date: Tue, 20 Nov 2018 16:36:47 +0100 Subject: Fix typo in development_dependencies_install.md [ci skip] --- guides/source/development_dependencies_install.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides/source') diff --git a/guides/source/development_dependencies_install.md b/guides/source/development_dependencies_install.md index d52946be08..b3baf726e3 100644 --- a/guides/source/development_dependencies_install.md +++ b/guides/source/development_dependencies_install.md @@ -156,7 +156,7 @@ To install all run: # portmaster databases/redis ``` -Or install everyting through ports (these packages are located under the +Or install everything through ports (these packages are located under the `databases` folder). NOTE: If you run into troubles during the installation of MySQL, please see -- cgit v1.2.3 From 455a122ef0135bd133b51014467211bc9a0a11f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maurice=20Ku=CC=88hlborn?= Date: Thu, 15 Nov 2018 12:11:36 +0100 Subject: Add progressive JPG to default variable content types --- guides/source/configuring.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides/source') diff --git a/guides/source/configuring.md b/guides/source/configuring.md index 706964090e..1ede31c1cd 100644 --- a/guides/source/configuring.md +++ b/guides/source/configuring.md @@ -813,7 +813,7 @@ normal Rails server. config.active_storage.paths[:ffprobe] = '/usr/local/bin/ffprobe' ``` -* `config.active_storage.variable_content_types` accepts an array of strings indicating the content types that Active Storage can transform through ImageMagick. The default is `%w(image/png image/gif image/jpg image/jpeg image/vnd.adobe.photoshop image/vnd.microsoft.icon)`. +* `config.active_storage.variable_content_types` accepts an array of strings indicating the content types that Active Storage can transform through ImageMagick. The default is `%w(image/png image/gif image/jpg image/jpeg image/pjpeg image/vnd.adobe.photoshop image/vnd.microsoft.icon)`. * `config.active_storage.content_types_to_serve_as_binary` accepts an array of strings indicating the content types that Active Storage will always serve as an attachment, rather than inline. The default is `%w(text/html text/javascript image/svg+xml application/postscript application/x-shockwave-flash text/xml application/xml application/xhtml+xml)`. -- cgit v1.2.3 From 6fb128d14427019b10e1ac5205f48f72feffe767 Mon Sep 17 00:00:00 2001 From: Yasuo Honda Date: Sun, 23 Sep 2018 04:45:19 +0000 Subject: Bump the minimum version of PostgreSQL to 9.3 https://www.postgresql.org/support/versioning/ - 9.1 EOLed on September 2016. - 9.2 EOLed on September 2017. 9.3 is also not supported since Nov 8, 2018. https://www.postgresql.org/about/news/1905/ I think it may be a little bit early to drop PostgreSQL 9.3 yet. * Deprecated `supports_ranges?` since no other databases support range data type * Add `supports_materialized_views?` to abstract adapter Materialized views itself is supported by other databases, other connection adapters may support them * Remove `with_manual_interventions` It was only necessary for PostgreSQL 9.1 or earlier * Drop CI against PostgreSQL 9.2 --- guides/source/active_record_postgresql.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides/source') diff --git a/guides/source/active_record_postgresql.md b/guides/source/active_record_postgresql.md index 16c1567c69..536a7138e9 100644 --- a/guides/source/active_record_postgresql.md +++ b/guides/source/active_record_postgresql.md @@ -14,7 +14,7 @@ After reading this guide, you will know: -------------------------------------------------------------------------------- -In order to use the PostgreSQL adapter you need to have at least version 9.1 +In order to use the PostgreSQL adapter you need to have at least version 9.3 installed. Older versions are not supported. To get started with PostgreSQL have a look at the -- cgit v1.2.3 From ee8dce180e8d659d879504fd051c3132af9cc8b7 Mon Sep 17 00:00:00 2001 From: Tom Rossi Date: Sun, 25 Nov 2018 16:57:59 -0500 Subject: Updating the Testing Guide to Reflect Emails Enqueued With ActiveJob [ci skip] --- guides/source/testing.md | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) (limited to 'guides/source') diff --git a/guides/source/testing.md b/guides/source/testing.md index 8c21ccfba6..f0a1a8a3f0 100644 --- a/guides/source/testing.md +++ b/guides/source/testing.md @@ -1593,27 +1593,43 @@ NOTE: The `ActionMailer::Base.deliveries` array is only reset automatically in If you want to have a clean slate outside these test cases, you can reset it manually with: `ActionMailer::Base.deliveries.clear` -### Functional Testing +### Functional and System Testing -Functional testing for mailers involves more than just checking that the email body, recipients, and so forth are correct. In functional mail tests you call the mail deliver methods and check that the appropriate emails have been appended to the delivery list. It is fairly safe to assume that the deliver methods themselves do their job. You are probably more interested in whether your own business logic is sending emails when you expect them to go out. For example, you can check that the invite friend operation is sending an email appropriately: +Unit testing allows us to test the attributes of the email while functional and system testing allows us to test whether user interactions appropriately trigger the email to be delivered. For example, you can check that the invite friend operation is sending an email appropriately: ```ruby +# Integration Test require 'test_helper' class UsersControllerTest < ActionDispatch::IntegrationTest test "invite friend" do - assert_difference 'ActionMailer::Base.deliveries.size', +1 do + # Asserts the difference in the ActionMailer::Base.deliveries + assert_emails 1 do post invite_friend_url, params: { email: 'friend@example.com' } end - invite_email = ActionMailer::Base.deliveries.last + end +end +``` + +```ruby +# System Test +require 'test_helper' + +class UsersTest < ActionDispatch::SystemTestCase + driven_by :selenium, using: :headless_chrome - assert_equal "You have been invited by me@example.com", invite_email.subject - assert_equal 'friend@example.com', invite_email.to[0] - assert_match(/Hi friend@example\.com/, invite_email.body.to_s) + test "inviting a friend" do + visit invite_users_url + fill_in 'Email', with: 'friend@example.com' + assert_emails 1 do + click_on 'Invite' + end end end ``` +NOTE: The `assert_emails` method is not tied to a particular deliver method and will work with emails delivered with either the `deliver_now` or `deliver_later` method. If we explicitly want to assert that the email has been enqueued we can use the `assert_enqueued_emails` method. More information can be found in the [documentation here](https://api.rubyonrails.org/classes/ActionMailer/TestHelper.html). + Testing Jobs ------------ -- cgit v1.2.3 From 95f9af8257d85764cc2938f0b81bdd39f60de468 Mon Sep 17 00:00:00 2001 From: tnantoka Date: Mon, 26 Nov 2018 13:21:24 +0900 Subject: Use cache_key_with_version instead of cache_key for the example in Low-Level Caching [ci skip] --- guides/source/caching_with_rails.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides/source') diff --git a/guides/source/caching_with_rails.md b/guides/source/caching_with_rails.md index 67b097f2ae..3ac3f8fa8b 100644 --- a/guides/source/caching_with_rails.md +++ b/guides/source/caching_with_rails.md @@ -295,7 +295,7 @@ Consider the following example. An application has a `Product` model with an ins ```ruby class Product < ApplicationRecord def competing_price - Rails.cache.fetch("#{cache_key}/competing_price", expires_in: 12.hours) do + Rails.cache.fetch("#{cache_key_with_version}/competing_price", expires_in: 12.hours) do Competitor::API.find_price(id) end end -- cgit v1.2.3 From 7e4eeca3708d8e9085fa1a539e72a5a6f139b4b6 Mon Sep 17 00:00:00 2001 From: Gannon McGibbon Date: Mon, 26 Nov 2018 13:42:27 -0500 Subject: Clarify scope body requirements [ci skip] --- guides/source/active_record_querying.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides/source') diff --git a/guides/source/active_record_querying.md b/guides/source/active_record_querying.md index 02055e59f0..fd1dcf22c0 100644 --- a/guides/source/active_record_querying.md +++ b/guides/source/active_record_querying.md @@ -1267,7 +1267,7 @@ This is because it is ambiguous whether they should appear on the parent record, Scopes ------ -Scoping allows you to specify commonly-used queries which can be referenced as method calls on the association objects or models. With these scopes, you can use every method previously covered such as `where`, `joins` and `includes`. All scope methods will return an `ActiveRecord::Relation` object which will allow for further methods (such as other scopes) to be called on it. +Scoping allows you to specify commonly-used queries which can be referenced as method calls on the association objects or models. With these scopes, you can use every method previously covered such as `where`, `joins` and `includes`. All scope bodies should return an `ActiveRecord::Relation` or `nil` to allow for further methods (such as other scopes) to be called on it. To define a simple scope, we use the `scope` method inside the class, passing the query that we'd like to run when this scope is called: -- cgit v1.2.3 From 4a88915db735e05c3f49bec2713bbe29db72b0b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ton=C4=8Di=20Damjani=C4=87?= Date: Thu, 29 Nov 2018 08:15:40 +0100 Subject: [ci skip] Add a Delayed Job project link. Delayed Job is mentioned multiple times in the document, but it is not linked from anywhere. --- guides/source/active_job_basics.md | 1 + 1 file changed, 1 insertion(+) (limited to 'guides/source') diff --git a/guides/source/active_job_basics.md b/guides/source/active_job_basics.md index 39239852ca..0ebef46373 100644 --- a/guides/source/active_job_basics.md +++ b/guides/source/active_job_basics.md @@ -165,6 +165,7 @@ Here is a noncomprehensive list of documentation: - [Sneakers](https://github.com/jondot/sneakers/wiki/How-To:-Rails-Background-Jobs-with-ActiveJob) - [Sucker Punch](https://github.com/brandonhilkert/sucker_punch#active-job) - [Queue Classic](https://github.com/QueueClassic/queue_classic#active-job) +- [Delayed Job](https://github.com/collectiveidea/delayed_job#active-job) Queues ------ -- cgit v1.2.3 From 220494185c84cf62d60ddcb1fa3527da9d758578 Mon Sep 17 00:00:00 2001 From: Gannon McGibbon Date: Fri, 30 Nov 2018 13:17:33 -0500 Subject: Clarify no support for non PK id columns [ci skip] --- guides/source/active_record_basics.md | 2 ++ 1 file changed, 2 insertions(+) (limited to 'guides/source') 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 ------------------------------ -- cgit v1.2.3 From e06e53e28527a7f90f7e22117174f6376bf6eaf1 Mon Sep 17 00:00:00 2001 From: Greg Molnar Date: Sat, 1 Dec 2018 09:44:28 +0100 Subject: fix example code syntax [ci skip] --- guides/source/active_storage_overview.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides/source') 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 -- cgit v1.2.3 From 4973a7643b9e6e2710efefa40595c3f6aac37f94 Mon Sep 17 00:00:00 2001 From: bogdanvlviv Date: Sun, 2 Dec 2018 22:50:00 +0200 Subject: Improve parallel testing guide [ci skip] - Fix formatting - Don't repeat "Active Record automatically handles creating and migrating a new database for each worker to use." - Tell that AR loads the schema to a database for each process(Related to #33479) - Clarify that `parallelize_teardown` is executed for each process --- guides/source/testing.md | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'guides/source') diff --git a/guides/source/testing.md b/guides/source/testing.md index f0a1a8a3f0..02b60a395b 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 ``` -- cgit v1.2.3 From 797317089301ca469e113ca3f46f29c129246c3e Mon Sep 17 00:00:00 2001 From: Gannon McGibbon Date: Tue, 4 Dec 2018 13:45:45 -0500 Subject: Add note about symbols vs strings --- guides/source/routing.md | 2 ++ 1 file changed, 2 insertions(+) (limited to 'guides/source') 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: -- cgit v1.2.3 From d45b74e89708bb26c68f04e17090eb1c56898ed8 Mon Sep 17 00:00:00 2001 From: Sam Bostock Date: Wed, 28 Nov 2018 22:40:41 -0500 Subject: Add advanced test helpers docs to guides [ci skip] --- guides/source/testing.md | 50 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'guides/source') diff --git a/guides/source/testing.md b/guides/source/testing.md index 02b60a395b..9541598b26 100644 --- a/guides/source/testing.md +++ b/guides/source/testing.md @@ -1397,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 -------------- -- cgit v1.2.3 From 884310fdd031ed8121944f9ea07c8b7723c4e6b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Wed, 5 Dec 2018 13:37:48 -0500 Subject: Improve deprecation message for enqueue returning false And make sure new applications in Rails 6.0 has this config enabled. Also, improve test coverage and add a CHANGELOG entry. --- guides/source/configuring.md | 2 ++ 1 file changed, 2 insertions(+) (limited to 'guides/source') 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 -- cgit v1.2.3 From f173ec77fc35ce57e94398310308e868689366bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Fri, 7 Dec 2018 07:01:32 +0100 Subject: Abort early if generator command fails (#34420) * No need to go through ruby * Abort early if a generator command fails * Reuse `rails_command` method * Bump thor minimum dependency to 0.20.3 * Add some minimal docs * Add a changelog entry * Restore original logging --- guides/source/rails_application_templates.md | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'guides/source') diff --git a/guides/source/rails_application_templates.md b/guides/source/rails_application_templates.md index bc68a555c5..982df26987 100644 --- a/guides/source/rails_application_templates.md +++ b/guides/source/rails_application_templates.md @@ -195,6 +195,12 @@ You can also run commands as a super-user: rails_command "log:clear", sudo: true ``` +You can also run commands that should abort application generation if they fail: + +```ruby +rails_command "db:migrate", abort_on_failure: true +``` + ### route(routing_code) Adds a routing entry to the `config/routes.rb` file. In the steps above, we generated a person scaffold and also removed `README.rdoc`. Now, to make `PeopleController#index` the default page for the application: -- cgit v1.2.3 From af90af42a748551d6dd2690be313186e7b0d8301 Mon Sep 17 00:00:00 2001 From: Randy Antler Date: Fri, 7 Dec 2018 14:08:54 -0800 Subject: Fix typo in per-form CSRF token docs [ci skip] --- guides/source/upgrading_ruby_on_rails.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides/source') diff --git a/guides/source/upgrading_ruby_on_rails.md b/guides/source/upgrading_ruby_on_rails.md index a0553c1ccc..e74985c5b0 100644 --- a/guides/source/upgrading_ruby_on_rails.md +++ b/guides/source/upgrading_ruby_on_rails.md @@ -407,7 +407,7 @@ want to add this feature it will need to be turned on in an initializer. Rails 5 now supports per-form CSRF tokens to mitigate against code-injection attacks with forms created by JavaScript. With this option turned on, forms in your application will each have their -own CSRF token that is specified to the action and method for that form. +own CSRF token that is specific to the action and method for that form. config.action_controller.per_form_csrf_tokens = true -- cgit v1.2.3