From 30433253eda59656b1060d6ccc5e1b8e5913c331 Mon Sep 17 00:00:00 2001 From: Kirill Zhuravlov Date: Wed, 23 Nov 2016 03:04:55 +0200 Subject: Add link to API documentation Add a link to http://api.rubyonrails.org/classes/ActionController.html in the beginning of an article. --- guides/source/action_controller_overview.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides') diff --git a/guides/source/action_controller_overview.md b/guides/source/action_controller_overview.md index 40eb838d32..69c4a00c5f 100644 --- a/guides/source/action_controller_overview.md +++ b/guides/source/action_controller_overview.md @@ -61,7 +61,7 @@ end The [Layouts & Rendering Guide](layouts_and_rendering.html) explains this in more detail. -`ApplicationController` inherits from `ActionController::Base`, which defines a number of helpful methods. This guide will cover some of these, but if you're curious to see what's in there, you can see all of them in the API documentation or in the source itself. +`ApplicationController` inherits from `ActionController::Base`, which defines a number of helpful methods. This guide will cover some of these, but if you're curious to see what's in there, you can see all of them in the [API documentation](http://api.rubyonrails.org/classes/ActionController.html) or in the source itself. Only public methods are callable as actions. It is a best practice to lower the visibility of methods (with `private` or `protected`) which are not intended to be actions, like auxiliary methods or filters. -- cgit v1.2.3 From 36176c51d363e0640c1f9820308c69602c0bee64 Mon Sep 17 00:00:00 2001 From: Erol Fornoles Date: Fri, 17 Feb 2017 16:38:38 +0800 Subject: Fix typo in I18n Guide [ci skip] --- guides/source/i18n.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides') diff --git a/guides/source/i18n.md b/guides/source/i18n.md index 0b7cc055be..ed8cf8a344 100644 --- a/guides/source/i18n.md +++ b/guides/source/i18n.md @@ -417,7 +417,7 @@ If your translations are stored in YAML files, certain keys must be escaped. The Examples: ```erb -# confing/locales/en.yml +# config/locales/en.yml en: success: 'true': 'True!' -- cgit v1.2.3 From fc9a2dc14ca3a5684e3cd1a4006ebebbb1e00318 Mon Sep 17 00:00:00 2001 From: Richard Date: Fri, 17 Feb 2017 11:50:49 +0000 Subject: Change engines guide to demonstrate maintained forum Change Rails engine guide to references a maintained project Thredded instead of the abandoned project Forem. I chose Thredded as Forem's closing note (below) suggests the choice. https://github.com/rubysherpas/forem/blob/rails4/README.md --- guides/source/engines.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides') diff --git a/guides/source/engines.md b/guides/source/engines.md index 0020112a1c..180a786237 100644 --- a/guides/source/engines.md +++ b/guides/source/engines.md @@ -59,7 +59,7 @@ only be enhancing it, rather than changing it drastically. To see demonstrations of other engines, check out [Devise](https://github.com/plataformatec/devise), an engine that provides authentication for its parent applications, or -[Forem](https://github.com/radar/forem), an engine that provides forum +[Thredded](https://github.com/thredded/thredded), an engine that provides forum functionality. There's also [Spree](https://github.com/spree/spree) which provides an e-commerce platform, and [RefineryCMS](https://github.com/refinery/refinerycms), a CMS engine. -- cgit v1.2.3 From 53ff5fc62f9d11b6f60d371df959137f4bf40728 Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Sat, 18 Feb 2017 10:36:51 +0900 Subject: Remove deprecate passing string to `:if` and `:unless` conditional options [ci skip] Follow up to #27608 --- guides/source/active_record_callbacks.md | 12 +----------- guides/source/active_record_validations.md | 12 ------------ 2 files changed, 1 insertion(+), 23 deletions(-) (limited to 'guides') diff --git a/guides/source/active_record_callbacks.md b/guides/source/active_record_callbacks.md index 666d987f8c..77bd3c97e8 100644 --- a/guides/source/active_record_callbacks.md +++ b/guides/source/active_record_callbacks.md @@ -288,7 +288,7 @@ Article destroyed Conditional Callbacks --------------------- -As with validations, we can also make the calling of a callback method conditional on the satisfaction of a given predicate. We can do this using the `:if` and `:unless` options, which can take a symbol, a string, a `Proc` or an `Array`. You may use the `:if` option when you want to specify under which conditions the callback **should** be called. If you want to specify the conditions under which the callback **should not** be called, then you may use the `:unless` option. +As with validations, we can also make the calling of a callback method conditional on the satisfaction of a given predicate. We can do this using the `:if` and `:unless` options, which can take a symbol, a `Proc` or an `Array`. You may use the `:if` option when you want to specify under which conditions the callback **should** be called. If you want to specify the conditions under which the callback **should not** be called, then you may use the `:unless` option. ### Using `:if` and `:unless` with a `Symbol` @@ -300,16 +300,6 @@ class Order < ApplicationRecord end ``` -### Using `:if` and `:unless` with a String - -You can also use a string that will be evaluated using `eval` and hence needs to contain valid Ruby code. You should use this option only when the string represents a really short condition: - -```ruby -class Order < ApplicationRecord - before_save :normalize_card_number, if: "paid_with_card?" -end -``` - ### Using `:if` and `:unless` with a `Proc` Finally, it is possible to associate `:if` and `:unless` with a `Proc` object. This option is best suited when writing short validation methods, usually one-liners: diff --git a/guides/source/active_record_validations.md b/guides/source/active_record_validations.md index 665e97c470..32b38cde5e 100644 --- a/guides/source/active_record_validations.md +++ b/guides/source/active_record_validations.md @@ -916,18 +916,6 @@ class Order < ApplicationRecord end ``` -### Using a String with `:if` and `:unless` - -You can also use a string that will be evaluated using `eval` and needs to -contain valid Ruby code. You should use this option only when the string -represents a really short condition. - -```ruby -class Person < ApplicationRecord - validates :surname, presence: true, if: "name.nil?" -end -``` - ### Using a Proc with `:if` and `:unless` Finally, it's possible to associate `:if` and `:unless` with a `Proc` object -- cgit v1.2.3 From 7718d470e9027fb1925237be65ba82f3ace660df Mon Sep 17 00:00:00 2001 From: Vitali Tatarintev Date: Mon, 20 Feb 2017 14:44:39 +0100 Subject: [ci skip] Update Guides to use macOS instead of Mac OS X --- guides/source/5_0_release_notes.md | 2 +- guides/source/asset_pipeline.md | 4 ++-- guides/source/configuring.md | 2 +- guides/source/development_dependencies_install.md | 2 +- guides/source/getting_started.md | 8 ++++---- 5 files changed, 9 insertions(+), 9 deletions(-) (limited to 'guides') diff --git a/guides/source/5_0_release_notes.md b/guides/source/5_0_release_notes.md index e1b3b0a42e..5f4be07351 100644 --- a/guides/source/5_0_release_notes.md +++ b/guides/source/5_0_release_notes.md @@ -242,7 +242,7 @@ Please refer to the [Changelog][railties] for detailed changes. [Pull Request](https://github.com/rails/rails/pull/22288)) * New applications are generated with the evented file system monitor enabled - on Linux and Mac OS X. The feature can be opted out by passing + on Linux and macOS. The feature can be opted out by passing `--skip-listen` to the generator. ([commit](https://github.com/rails/rails/commit/de6ad5665d2679944a9ee9407826ba88395a1003), [commit](https://github.com/rails/rails/commit/94dbc48887bf39c241ee2ce1741ee680d773f202)) diff --git a/guides/source/asset_pipeline.md b/guides/source/asset_pipeline.md index 360de9a584..68dde4482f 100644 --- a/guides/source/asset_pipeline.md +++ b/guides/source/asset_pipeline.md @@ -207,7 +207,7 @@ default .coffee and .scss files will not be precompiled on their own. See precompiling works. NOTE: You must have an ExecJS supported runtime in order to use CoffeeScript. -If you are using Mac OS X or Windows, you have a JavaScript runtime installed in +If you are using macOS or Windows, you have a JavaScript runtime installed in your operating system. Check [ExecJS](https://github.com/rails/execjs#readme) documentation to know all supported JavaScript runtimes. You can also disable generation of controller specific asset files by adding the @@ -1117,7 +1117,7 @@ config.assets.js_compressor = :uglifier ``` NOTE: You will need an [ExecJS](https://github.com/rails/execjs#readme) -supported runtime in order to use `uglifier`. If you are using Mac OS X or +supported runtime in order to use `uglifier`. If you are using macOS or Windows you have a JavaScript runtime installed in your operating system. diff --git a/guides/source/configuring.md b/guides/source/configuring.md index 251b038ec9..de921e2705 100644 --- a/guides/source/configuring.md +++ b/guides/source/configuring.md @@ -1308,7 +1308,7 @@ end Otherwise, in every request Rails walks the application tree to check if anything has changed. -On Linux and Mac OS X no additional gems are needed, but some are required +On Linux and macOS no additional gems are needed, but some are required [for *BSD](https://github.com/guard/listen#on-bsd) and [for Windows](https://github.com/guard/listen#on-windows). diff --git a/guides/source/development_dependencies_install.md b/guides/source/development_dependencies_install.md index 16c7e782bc..7ec038eb4d 100644 --- a/guides/source/development_dependencies_install.md +++ b/guides/source/development_dependencies_install.md @@ -46,7 +46,7 @@ $ cd rails 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. -Install first SQLite3 and its development files for the `sqlite3` gem. Mac OS X +Install first SQLite3 and its development files for the `sqlite3` gem. On macOS users are done with: ```bash diff --git a/guides/source/getting_started.md b/guides/source/getting_started.md index 8a451ab793..57b8472462 100644 --- a/guides/source/getting_started.md +++ b/guides/source/getting_started.md @@ -86,7 +86,7 @@ your prompt will look something like `c:\source_code>` ### Installing Rails -Open up a command line prompt. On Mac OS X open Terminal.app, on Windows choose +Open up a command line prompt. On macOS open Terminal.app, on Windows choose "Run" from your Start menu and type 'cmd.exe'. Any commands prefaced with a dollar sign `$` should be run in the command line. Verify that you have a current version of Ruby installed: @@ -98,7 +98,7 @@ ruby 2.3.1p112 TIP: A number of tools exist to help you quickly install Ruby and Ruby on Rails on your system. Windows users can use [Rails Installer](http://railsinstaller.org), -while Mac OS X users can use [Tokaido](https://github.com/tokaido/tokaidoapp). +while macOS users can use [Tokaido](https://github.com/tokaido/tokaidoapp). For more installation methods for most Operating Systems take a look at [ruby-lang.org](https://www.ruby-lang.org/en/documentation/installation/). @@ -206,7 +206,7 @@ folder directly to the Ruby interpreter e.g. `ruby bin\rails server`. TIP: Compiling CoffeeScript and JavaScript asset compression requires you have a JavaScript runtime available on your system, in the absence of a runtime you will see an `execjs` error during asset compilation. -Usually Mac OS X and Windows come with a JavaScript runtime installed. +Usually macOS and Windows come with a JavaScript runtime installed. Rails adds the `therubyracer` gem to the generated `Gemfile` in a commented line for new apps and you can uncomment if you need it. `therubyrhino` is the recommended runtime for JRuby users and is added by @@ -221,7 +221,7 @@ your application in action, open a browser window and navigate to TIP: To stop the web server, hit Ctrl+C in the terminal window where it's running. To verify the server has stopped you should see your command prompt -cursor again. For most UNIX-like systems including Mac OS X this will be a +cursor again. For most UNIX-like systems including macOS this will be a dollar sign `$`. In development mode, Rails does not generally require you to restart the server; changes you make in files will be automatically picked up by the server. -- cgit v1.2.3 From 62c7d983848726bb9a512d687d2765c1dd78fe8d Mon Sep 17 00:00:00 2001 From: eileencodes Date: Tue, 27 Dec 2016 15:06:27 -0500 Subject: Add guides for system testing This adds the required guides for how to write and use system tests in your application. --- guides/source/testing.md | 254 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 251 insertions(+), 3 deletions(-) (limited to 'guides') diff --git a/guides/source/testing.md b/guides/source/testing.md index 6f783089a9..7b9fe5a74c 100644 --- a/guides/source/testing.md +++ b/guides/source/testing.md @@ -8,7 +8,7 @@ This guide covers built-in mechanisms in Rails for testing your application. After reading this guide, you will know: * Rails testing terminology. -* How to write unit, functional, and integration tests for your application. +* How to write unit, functional, integration, and system tests for your application. * Other popular testing approaches and plugins. -------------------------------------------------------------------------------- @@ -33,18 +33,25 @@ Rails creates a `test` directory for you as soon as you create a Rails project u ```bash $ ls -F test -controllers/ helpers/ mailers/ test_helper.rb -fixtures/ integration/ models/ +controllers/ helpers/ mailers/ system/ test_helper.rb +fixtures/ integration/ models/ system_test_helper.rb ``` The `helpers`, `mailers`, and `models` directories are meant to hold tests for view helpers, mailers, and models, respectively. The `controllers` directory is meant to hold tests for controllers, routes, and views. The `integration` directory is meant to hold tests for interactions between controllers. +The system test directory holds system tests, also known as acceptance tests. +System tests inherit from Capybara and perform in browser tests for your +application. + Fixtures are a way of organizing test data; they reside in the `fixtures` directory. A `jobs` directory will also be created when an associated test is first generated. The `test_helper.rb` file holds the default configuration for your tests. +The `system_test_helper.rb` holds the default configuration for your system +tests. + ### The Test Environment @@ -358,6 +365,7 @@ All the basic assertions such as `assert_equal` defined in `Minitest::Assertions * [`ActionView::TestCase`](http://api.rubyonrails.org/classes/ActionView/TestCase.html) * [`ActionDispatch::IntegrationTest`](http://api.rubyonrails.org/classes/ActionDispatch/IntegrationTest.html) * [`ActiveJob::TestCase`](http://api.rubyonrails.org/classes/ActiveJob/TestCase.html) +* [`ActionSystemTestCase`](http://api.rubyonrails.org/classes/ActionSystemTest.html) Each of these classes include `Minitest::Assertions`, allowing us to use all of the basic assertions in our tests. @@ -587,6 +595,246 @@ create test/fixtures/articles.yml Model tests don't have their own superclass like `ActionMailer::TestCase` instead they inherit from [`ActiveSupport::TestCase`](http://api.rubyonrails.org/classes/ActiveSupport/TestCase.html). +System Testing +-------------- + +System tests are full-browser acceptance tests that inherit from Capybara. +System tests allow for running tests in either a real browser or a headless +browser for testing full user interactions with your application. + +For creating Rails system tests, you use the `test/system` directory in your +application. Rails provides a generator to create a system test skeleton for us. + +```bash +$ bin/rails generate system_test users_create_test.rb + invoke test_unit + create test/system/users_create_test.rb +``` + +Here's what a freshly-generated system test looks like: + +```ruby +require 'test_helper' + +class UsersCreateTest < ActionSystemTestCase + # test "the truth" do + # assert true + # end +end +``` + +Here the test is inheriting from `ActionSystemTestCase`. This allows for no-setup +Capybara integration with Selenium Webdriver. + +### Changing the default settings + +Capybara requires that a driver be selected. Rails defaults to the Selenium +Driver and provides default settings to Capyara and Selenium so that system +tests work out of the box with no required configuration on your part. + +Some may prefer to use a headless driver so Rails provides a shim to set other +drivers for Capybara with minimal configuration. + +In the `system_test_helper.rb` that is generated with the application or test +you can set the driver: + +```ruby +require 'test_helper' + +class ActionSystemTestCase < ActionSystemTest::Base + ActionSystemTest.driver = :poltergeist +end +``` + +The drivers that Rails and Capybara support are `:rack_test`, `:poltergeist`, +`:capybara_webkit`, and of course `:selenium`. + +For selenium you can choose either the Rails configured driver `:rails_selenium` +or `:selenium`. The `:selenium` driver inherits from `CabybaraDriver` and is +the vanilla setup of selenium with Capybara if you don't want to use the +Rails defaults. + +The default settings for `:rails_selenium` driver uses the Chrome browser, +sets the server to Puma on port 28100 and the screen size to 1400 x 1400. + +You can change the default settings by initializing a new driver object. + +```ruby +require 'test_helper' + +class ActionSystemTestCase < ActionSystemTest::Base + ActionSystemTest.driver = ActionSystemTest::DriverAdapters::RailsSeleniumDriver.new( + browser: :firefox, + server: :webkit + ) +end +``` + +The shim for other Capybara drivers provide some defaults such as driver name +server, and port. To change any of those settings, you can initialize a new +`CapybaraDriver` object. + +```ruby +require 'test_helper' + +class ActionSystemTestCase < ActionSystemTest::Base + ActionSystemTest.driver = ActionSystemTest::DriverAdapters::CapybaraDriver.new( + driver: :poltergeist, + server: :webrick + ) +end +``` + +If your Capybara configuration requires more setup than provided by Rails, all +of that configuration can be put into the `system_test_helper.rb` file provided +by Rails. + +Please see Capybara's documentation for additional settings. + +### Helpers Available for System Tests + +`ActionSystemTest` provides a few helpers in addition to those provided previously +by Rails or by Capybara. + +The `ScreenshotHelper` is a helper designed to capture screenshots of your test. +This can be helpful for viewing the browser at the point a test failed, or +to view screenshots later for debugging. + +Two methods are provided: `take_screenshot` and `take_failed_screenshot`. +`take_failed_screenshot` is automatically included in the `system_test_helper.rb` +file and will take a screenshot only if the test fails. + +The `take_screenshot` helper method can be included anywhere in your tests to +take a screenshot of the browser. + +A method is provided by the drivers to determine whether the driver is capable +of taking screenshots. The `RackTest` driver for example does not support +screenshots. `supports_screenshots?` checks whether the driver supports +screenshots: + +```ruby +ActionSystemTest.driver.supports_screenshots? +=> true +``` + +The `ActiveJobSetup` helper configures your system tests for handling Active Job. + +Two helper methods are included in the setup and teardown blocks in the +`system_test_helper.rb` file. `set_queue_adapter_to_async` sets your Active Job +queue adapter to the async adapter and remembers the original adapter. + +In teardown the `reset_queue_adapter_to_original` method resets the Active Job +queue adapter back to the adapter your application has set for other environments. + +This is helpful for ensuring that jobs run async so that the test's that rely +on job code are correctly tested at the time they run. + +If you don't want these helper methods you can remove them from the setup and +teardown code in your `system_test_helper.rb`. + +The `AssertionsHelper` provides two helper methods for assertions. In Capybara +you can assert that a selector does or does not exist, but often you have cases +where you need to assert the same selector exsits multiple times with different +values. For example, if you have 6 avatars on the page and you want to assert +that each of them has the respective title for each person you can use +`assert_all_of_selectors` and pass the selector, items you are asserting exist, +and options. + +```ruby +assert_all_of_selectors(:avatar, 'Eileen', 'Jeremy') +assert_all_of_selectors(:avatar, 'Eileen', 'Jeremy', visible: all) +``` + +You can also assert that none of the selectors match with +`assert_none_of_selectors`: + +```ruby +assert_none_of_selectors(:avatar, 'Tom', 'Dan') +assert_none_of_selectors(:avatar, 'Tom', 'Dan') +``` + +### Implementing a system test + +Now we're going to add a system test to our blog application. We'll demonstrate +writing a system test by visiting the index page and creating a new blog article. + +If you used the scaffold generator, a system test skeleton is automatically +created for you. If you did not use the generator start by creating a system +test skeleton. + +```bash +$ bin/rails generate system_test articles +``` + +It should have created a test file placeholder for us. With the output of the +previous command we should see: + +```bash + invoke test_unit + create test/system/articles_test.rb +``` + +Now let's open that file and write our first assertion: + +```ruby +require 'system_test_helper' + +class UsersTest < ActionSystemTestCase + test "viewing the index" do + visit articles_path + assert_text "h1", "Articles" + end +end +``` + +The test should see that there is an h1 on the articles index and pass. + +Run the system tests. + +```bash +bin/rails test:system +``` + +#### Creating articles system test + +Now let's test the flow for creating a new article in our blog. + +```ruby +test "creating an article" do + visit articles_path + + click_on "New Article" + + fill_in "Title", with: "Creating an Article" + fill_in "Body", with: "Created this article successfully!" + + click_on "Create Article" + + assert_text "Creating an Article" +end +``` + +The first step is to call `visit articles_path`. This will take the test to the +articles index page. + +Then the `click_on "New Article"` will find the "New Article" button on the +index page. This will redirect the browser to `/articles/new`. + +Then the test will fill in the title and body of the article with the specified +text. Once the fields are filled in "Create Article" is clicked on which will +send a POST request to create the new article in the database. + +We will be redirected back to the the articles index page and there we assert +that the text from the article title is on the articles index page. + +#### Taking it further + +The beauty of system testing is that it is similar to integration testing in +that it tests the user's interaction with your controller, model, and view, but +system testing is much more robust and actually tests your application as if +a real user were using it. Going forward you can test anything that the user +themselves would do in your application such as commenting, deleting articles, +publishing draft articles, etc. Integration Testing ------------------- -- cgit v1.2.3 From 893c3b6282bc87c1f07a1f4084de8ff6709917b1 Mon Sep 17 00:00:00 2001 From: eileencodes Date: Fri, 10 Feb 2017 09:13:48 -0500 Subject: Update documentation and guides Update the documentation after rewriting a majority of the functionality for system testing. --- guides/source/testing.md | 134 +++++++++++++---------------------------------- 1 file changed, 36 insertions(+), 98 deletions(-) (limited to 'guides') diff --git a/guides/source/testing.md b/guides/source/testing.md index 7b9fe5a74c..5b8e14f296 100644 --- a/guides/source/testing.md +++ b/guides/source/testing.md @@ -39,7 +39,9 @@ fixtures/ integration/ models/ system_test The `helpers`, `mailers`, and `models` directories are meant to hold tests for view helpers, mailers, and models, respectively. The `controllers` directory is meant to hold tests for controllers, routes, and views. The `integration` directory is meant to hold tests for interactions between controllers. -The system test directory holds system tests, also known as acceptance tests. +The system test directory holds system tests, which are used for full browser +testing of your application. System tests allow you to test your application +the way your users experience it and help you test your JavaScript as well. System tests inherit from Capybara and perform in browser tests for your application. @@ -598,9 +600,11 @@ Model tests don't have their own superclass like `ActionMailer::TestCase` instea System Testing -------------- -System tests are full-browser acceptance tests that inherit from Capybara. +System tests are full-browser tests that can be used to test your application's +JavaScript and user experience. System tests use Capybara as a base. + System tests allow for running tests in either a real browser or a headless -browser for testing full user interactions with your application. +driver for testing full user interactions with your application. For creating Rails system tests, you use the `test/system` directory in your application. Rails provides a generator to create a system test skeleton for us. @@ -614,7 +618,7 @@ $ bin/rails generate system_test users_create_test.rb Here's what a freshly-generated system test looks like: ```ruby -require 'test_helper' +require "system_test_helper" class UsersCreateTest < ActionSystemTestCase # test "the truth" do @@ -623,78 +627,58 @@ class UsersCreateTest < ActionSystemTestCase end ``` -Here the test is inheriting from `ActionSystemTestCase`. This allows for no-setup -Capybara integration with Selenium Webdriver. +By default, system tests are run with the Selenium driver, using the Chrome +browser, on port 21800 with Puma, and a screen size of 1400x1400. The next +section explains how to change the default settings. ### Changing the default settings -Capybara requires that a driver be selected. Rails defaults to the Selenium -Driver and provides default settings to Capyara and Selenium so that system -tests work out of the box with no required configuration on your part. +Rails makes changing the default settings for system test very simple. All +the setup is abstracted away so you can focus on writing your tests. -Some may prefer to use a headless driver so Rails provides a shim to set other -drivers for Capybara with minimal configuration. +When you generate a new application or scaffold, a `system_test_helper.rb` file +is created in the test directory. This is where all the configuration for your +system tests should live. -In the `system_test_helper.rb` that is generated with the application or test -you can set the driver: +If you want to change the default settings you can simple change what the system +tests are "driven by". Say you want to change the driver from Selenium to +Poltergeist. First add the Poltergeist gem to your Gemfile. Then in your +`system_test_helper.rb` file do the following: ```ruby -require 'test_helper' +require "test_helper" +require "capybara/poltergeist" class ActionSystemTestCase < ActionSystemTest::Base - ActionSystemTest.driver = :poltergeist + driven_by :poltergeist end ``` -The drivers that Rails and Capybara support are `:rack_test`, `:poltergeist`, -`:capybara_webkit`, and of course `:selenium`. - -For selenium you can choose either the Rails configured driver `:rails_selenium` -or `:selenium`. The `:selenium` driver inherits from `CabybaraDriver` and is -the vanilla setup of selenium with Capybara if you don't want to use the -Rails defaults. - -The default settings for `:rails_selenium` driver uses the Chrome browser, -sets the server to Puma on port 28100 and the screen size to 1400 x 1400. - -You can change the default settings by initializing a new driver object. +If you want to keep the Selenium driver but change the browser or port you +can pass Firefox and the port to driven by. The driver is a required +argument, all other arguments are optional. ```ruby -require 'test_helper' +require "test_helper" class ActionSystemTestCase < ActionSystemTest::Base - ActionSystemTest.driver = ActionSystemTest::DriverAdapters::RailsSeleniumDriver.new( - browser: :firefox, - server: :webkit - ) + driven_by :selenium, using: :firefox, on: 3000 end ``` -The shim for other Capybara drivers provide some defaults such as driver name -server, and port. To change any of those settings, you can initialize a new -`CapybaraDriver` object. - -```ruby -require 'test_helper' - -class ActionSystemTestCase < ActionSystemTest::Base - ActionSystemTest.driver = ActionSystemTest::DriverAdapters::CapybaraDriver.new( - driver: :poltergeist, - server: :webrick - ) -end -``` +The driver name is a required argument for `driven_by`. The optional arguments +that can be passed to `driven_by` are `:using` for the browser (this will only +be used for non-headless drivers like Selenium), `:on` for the port Puma should +use, and `:screen_size` to change the size of the screen for screenshots. If your Capybara configuration requires more setup than provided by Rails, all of that configuration can be put into the `system_test_helper.rb` file provided by Rails. -Please see Capybara's documentation for additional settings. +Please see [Capybara's documentation](https://github.com/teamcapybara/capybara#setup) +for additional settings. -### Helpers Available for System Tests - -`ActionSystemTest` provides a few helpers in addition to those provided previously -by Rails or by Capybara. +### Screenshot Helper The `ScreenshotHelper` is a helper designed to capture screenshots of your test. This can be helpful for viewing the browser at the point a test failed, or @@ -707,52 +691,6 @@ file and will take a screenshot only if the test fails. The `take_screenshot` helper method can be included anywhere in your tests to take a screenshot of the browser. -A method is provided by the drivers to determine whether the driver is capable -of taking screenshots. The `RackTest` driver for example does not support -screenshots. `supports_screenshots?` checks whether the driver supports -screenshots: - -```ruby -ActionSystemTest.driver.supports_screenshots? -=> true -``` - -The `ActiveJobSetup` helper configures your system tests for handling Active Job. - -Two helper methods are included in the setup and teardown blocks in the -`system_test_helper.rb` file. `set_queue_adapter_to_async` sets your Active Job -queue adapter to the async adapter and remembers the original adapter. - -In teardown the `reset_queue_adapter_to_original` method resets the Active Job -queue adapter back to the adapter your application has set for other environments. - -This is helpful for ensuring that jobs run async so that the test's that rely -on job code are correctly tested at the time they run. - -If you don't want these helper methods you can remove them from the setup and -teardown code in your `system_test_helper.rb`. - -The `AssertionsHelper` provides two helper methods for assertions. In Capybara -you can assert that a selector does or does not exist, but often you have cases -where you need to assert the same selector exsits multiple times with different -values. For example, if you have 6 avatars on the page and you want to assert -that each of them has the respective title for each person you can use -`assert_all_of_selectors` and pass the selector, items you are asserting exist, -and options. - -```ruby -assert_all_of_selectors(:avatar, 'Eileen', 'Jeremy') -assert_all_of_selectors(:avatar, 'Eileen', 'Jeremy', visible: all) -``` - -You can also assert that none of the selectors match with -`assert_none_of_selectors`: - -```ruby -assert_none_of_selectors(:avatar, 'Tom', 'Dan') -assert_none_of_selectors(:avatar, 'Tom', 'Dan') -``` - ### Implementing a system test Now we're going to add a system test to our blog application. We'll demonstrate @@ -777,7 +715,7 @@ previous command we should see: Now let's open that file and write our first assertion: ```ruby -require 'system_test_helper' +require "system_test_helper" class UsersTest < ActionSystemTestCase test "viewing the index" do -- cgit v1.2.3 From 1a0ca84a064b07ecab798793a3d7ebe89bb6367c Mon Sep 17 00:00:00 2001 From: eileencodes Date: Sun, 19 Feb 2017 11:50:42 -0500 Subject: Move and rename system tests * Move system tests back into Action Pack * Rename `ActionSystemTest` to `ActionDispatch::SystemTestCase` * Remove private base module and only make file for public `SystemTestCase` class, name private module `SystemTesting` * Rename `ActionSystemTestCase` to `ApplicationSystemTestCase` * Update corresponding documentation and guides * Delete old `ActionSystemTest` files --- guides/source/testing.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'guides') diff --git a/guides/source/testing.md b/guides/source/testing.md index 5b8e14f296..366ab0b2a1 100644 --- a/guides/source/testing.md +++ b/guides/source/testing.md @@ -367,7 +367,7 @@ All the basic assertions such as `assert_equal` defined in `Minitest::Assertions * [`ActionView::TestCase`](http://api.rubyonrails.org/classes/ActionView/TestCase.html) * [`ActionDispatch::IntegrationTest`](http://api.rubyonrails.org/classes/ActionDispatch/IntegrationTest.html) * [`ActiveJob::TestCase`](http://api.rubyonrails.org/classes/ActiveJob/TestCase.html) -* [`ActionSystemTestCase`](http://api.rubyonrails.org/classes/ActionSystemTest.html) +* [`ActionDispatch::SystemTestCase`](http://api.rubyonrails.org/classes/ActionDispatch/SystemTestCase.html) Each of these classes include `Minitest::Assertions`, allowing us to use all of the basic assertions in our tests. @@ -620,7 +620,7 @@ Here's what a freshly-generated system test looks like: ```ruby require "system_test_helper" -class UsersCreateTest < ActionSystemTestCase +class UsersCreateTest < ApplicationSystemTestCase # test "the truth" do # assert true # end @@ -649,7 +649,7 @@ Poltergeist. First add the Poltergeist gem to your Gemfile. Then in your require "test_helper" require "capybara/poltergeist" -class ActionSystemTestCase < ActionSystemTest::Base +class ApplicationSystemTestCase < ActionDispatch::SystemTestCase driven_by :poltergeist end ``` @@ -661,7 +661,7 @@ argument, all other arguments are optional. ```ruby require "test_helper" -class ActionSystemTestCase < ActionSystemTest::Base +class ApplicationSystemTestCase < ActionDispatch::SystemTestCase driven_by :selenium, using: :firefox, on: 3000 end ``` @@ -717,7 +717,7 @@ Now let's open that file and write our first assertion: ```ruby require "system_test_helper" -class UsersTest < ActionSystemTestCase +class UsersTest < ApplicationSystemTestCase test "viewing the index" do visit articles_path assert_text "h1", "Articles" -- cgit v1.2.3 From 2d61c5d846f8dd3a02080fedce7ab63b8d314db6 Mon Sep 17 00:00:00 2001 From: eileencodes Date: Mon, 20 Feb 2017 14:38:46 -0500 Subject: Rename system_test_helper -> application_system_test_case This renames the system test helper file to be application system test case to match what the rest of Rails does. In the future we should consider changing the test_helper to match. --- guides/source/testing.md | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'guides') diff --git a/guides/source/testing.md b/guides/source/testing.md index 366ab0b2a1..fe0dbf6c50 100644 --- a/guides/source/testing.md +++ b/guides/source/testing.md @@ -34,7 +34,7 @@ Rails creates a `test` directory for you as soon as you create a Rails project u ```bash $ ls -F test controllers/ helpers/ mailers/ system/ test_helper.rb -fixtures/ integration/ models/ system_test_helper.rb +fixtures/ integration/ models/ application_system_test_case.rb ``` The `helpers`, `mailers`, and `models` directories are meant to hold tests for view helpers, mailers, and models, respectively. The `controllers` directory is meant to hold tests for controllers, routes, and views. The `integration` directory is meant to hold tests for interactions between controllers. @@ -51,7 +51,7 @@ A `jobs` directory will also be created when an associated test is first generat The `test_helper.rb` file holds the default configuration for your tests. -The `system_test_helper.rb` holds the default configuration for your system +The `application_system_test_case.rb` holds the default configuration for your system tests. @@ -618,12 +618,12 @@ $ bin/rails generate system_test users_create_test.rb Here's what a freshly-generated system test looks like: ```ruby -require "system_test_helper" +require "application_system_test_case" class UsersCreateTest < ApplicationSystemTestCase - # test "the truth" do - # assert true - # end + visit users_url + + assert_selector "h1", text: "Users" end ``` @@ -636,14 +636,14 @@ section explains how to change the default settings. Rails makes changing the default settings for system test very simple. All the setup is abstracted away so you can focus on writing your tests. -When you generate a new application or scaffold, a `system_test_helper.rb` file +When you generate a new application or scaffold, a `application_system_test_case.rb` file is created in the test directory. This is where all the configuration for your system tests should live. If you want to change the default settings you can simple change what the system tests are "driven by". Say you want to change the driver from Selenium to Poltergeist. First add the Poltergeist gem to your Gemfile. Then in your -`system_test_helper.rb` file do the following: +`application_system_test_case.rb` file do the following: ```ruby require "test_helper" @@ -672,7 +672,7 @@ be used for non-headless drivers like Selenium), `:on` for the port Puma should use, and `:screen_size` to change the size of the screen for screenshots. If your Capybara configuration requires more setup than provided by Rails, all -of that configuration can be put into the `system_test_helper.rb` file provided +of that configuration can be put into the `application_system_test_case.rb` file provided by Rails. Please see [Capybara's documentation](https://github.com/teamcapybara/capybara#setup) @@ -685,7 +685,7 @@ This can be helpful for viewing the browser at the point a test failed, or to view screenshots later for debugging. Two methods are provided: `take_screenshot` and `take_failed_screenshot`. -`take_failed_screenshot` is automatically included in the `system_test_helper.rb` +`take_failed_screenshot` is automatically included in the `application_system_test_case.rb` file and will take a screenshot only if the test fails. The `take_screenshot` helper method can be included anywhere in your tests to @@ -715,12 +715,12 @@ previous command we should see: Now let's open that file and write our first assertion: ```ruby -require "system_test_helper" +require "application_system_test_case" class UsersTest < ApplicationSystemTestCase test "viewing the index" do visit articles_path - assert_text "h1", "Articles" + assert_selector "h1", text: "Articles" end end ``` -- cgit v1.2.3 From 42a6dbdf8480b96c4a0ac6e1dab215ae9dd77d1d Mon Sep 17 00:00:00 2001 From: eileencodes Date: Mon, 20 Feb 2017 16:08:20 -0500 Subject: Clean up documentation There were some grammar issues and incorrect information in the system tests documentation. --- guides/source/testing.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'guides') diff --git a/guides/source/testing.md b/guides/source/testing.md index fe0dbf6c50..c7897a42a1 100644 --- a/guides/source/testing.md +++ b/guides/source/testing.md @@ -628,8 +628,8 @@ end ``` By default, system tests are run with the Selenium driver, using the Chrome -browser, on port 21800 with Puma, and a screen size of 1400x1400. The next -section explains how to change the default settings. +browser, and a screen size of 1400x1400. The next section explains how to +change the default settings. ### Changing the default settings @@ -654,7 +654,7 @@ class ApplicationSystemTestCase < ActionDispatch::SystemTestCase end ``` -If you want to keep the Selenium driver but change the browser or port you +If you want to keep the Selenium driver but change the browser you can pass Firefox and the port to driven by. The driver is a required argument, all other arguments are optional. @@ -662,7 +662,7 @@ argument, all other arguments are optional. require "test_helper" class ApplicationSystemTestCase < ActionDispatch::SystemTestCase - driven_by :selenium, using: :firefox, on: 3000 + driven_by :selenium, using: :firefox end ``` @@ -680,13 +680,13 @@ for additional settings. ### Screenshot Helper -The `ScreenshotHelper` is a helper designed to capture screenshots of your test. +The `ScreenshotHelper` is a helper designed to capture screenshots of your tests. This can be helpful for viewing the browser at the point a test failed, or to view screenshots later for debugging. Two methods are provided: `take_screenshot` and `take_failed_screenshot`. -`take_failed_screenshot` is automatically included in the `application_system_test_case.rb` -file and will take a screenshot only if the test fails. +`take_failed_screenshot` is automatically included in `after_teardown` inside +Rails. The `take_screenshot` helper method can be included anywhere in your tests to take a screenshot of the browser. -- cgit v1.2.3 From 5d3abc06c39a366cc4da3cda1725d92809e2f168 Mon Sep 17 00:00:00 2001 From: kenta-s Date: Thu, 2 Mar 2017 13:03:03 +0900 Subject: Fix some grammar in docs [ci skip] --- guides/source/testing.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'guides') diff --git a/guides/source/testing.md b/guides/source/testing.md index c7897a42a1..113314a5b8 100644 --- a/guides/source/testing.md +++ b/guides/source/testing.md @@ -636,11 +636,11 @@ change the default settings. Rails makes changing the default settings for system test very simple. All the setup is abstracted away so you can focus on writing your tests. -When you generate a new application or scaffold, a `application_system_test_case.rb` file +When you generate a new application or scaffold, an `application_system_test_case.rb` file is created in the test directory. This is where all the configuration for your system tests should live. -If you want to change the default settings you can simple change what the system +If you want to change the default settings you can simply change what the system tests are "driven by". Say you want to change the driver from Selenium to Poltergeist. First add the Poltergeist gem to your Gemfile. Then in your `application_system_test_case.rb` file do the following: @@ -685,7 +685,7 @@ This can be helpful for viewing the browser at the point a test failed, or to view screenshots later for debugging. Two methods are provided: `take_screenshot` and `take_failed_screenshot`. -`take_failed_screenshot` is automatically included in `after_teardown` inside +`take_failed_screenshot` is automatically included in `after_teardown` inside Rails. The `take_screenshot` helper method can be included anywhere in your tests to -- cgit v1.2.3 From 658b5244356feba2b262e87d8b333c5a46999a5d Mon Sep 17 00:00:00 2001 From: Robin Dupret Date: Tue, 21 Feb 2017 16:23:49 +0100 Subject: Tiny documentation edits [ci skip] --- guides/source/testing.md | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) (limited to 'guides') diff --git a/guides/source/testing.md b/guides/source/testing.md index 113314a5b8..2937a23a67 100644 --- a/guides/source/testing.md +++ b/guides/source/testing.md @@ -607,7 +607,7 @@ System tests allow for running tests in either a real browser or a headless driver for testing full user interactions with your application. For creating Rails system tests, you use the `test/system` directory in your -application. Rails provides a generator to create a system test skeleton for us. +application. Rails provides a generator to create a system test skeleton for you. ```bash $ bin/rails generate system_test users_create_test.rb @@ -633,7 +633,7 @@ change the default settings. ### Changing the default settings -Rails makes changing the default settings for system test very simple. All +Rails makes changing the default settings for system tests very simple. All the setup is abstracted away so you can focus on writing your tests. When you generate a new application or scaffold, an `application_system_test_case.rb` file @@ -654,9 +654,10 @@ class ApplicationSystemTestCase < ActionDispatch::SystemTestCase end ``` -If you want to keep the Selenium driver but change the browser you -can pass Firefox and the port to driven by. The driver is a required -argument, all other arguments are optional. +The driver name is a required argument for `driven_by`. The optional arguments +that can be passed to `driven_by` are `:using` for the browser (this will only +be used for non-headless drivers like Selenium), `:on` for the port Puma should +use, and `:screen_size` to change the size of the screen for screenshots. ```ruby require "test_helper" @@ -666,14 +667,8 @@ class ApplicationSystemTestCase < ActionDispatch::SystemTestCase end ``` -The driver name is a required argument for `driven_by`. The optional arguments -that can be passed to `driven_by` are `:using` for the browser (this will only -be used for non-headless drivers like Selenium), `:on` for the port Puma should -use, and `:screen_size` to change the size of the screen for screenshots. - If your Capybara configuration requires more setup than provided by Rails, all -of that configuration can be put into the `application_system_test_case.rb` file provided -by Rails. +of that configuration can be put into the `application_system_test_case.rb` file. Please see [Capybara's documentation](https://github.com/teamcapybara/capybara#setup) for additional settings. @@ -705,7 +700,7 @@ $ bin/rails generate system_test articles ``` It should have created a test file placeholder for us. With the output of the -previous command we should see: +previous command you should see: ```bash invoke test_unit @@ -759,7 +754,7 @@ Then the `click_on "New Article"` will find the "New Article" button on the index page. This will redirect the browser to `/articles/new`. Then the test will fill in the title and body of the article with the specified -text. Once the fields are filled in "Create Article" is clicked on which will +text. Once the fields are filled in, "Create Article" is clicked on which will send a POST request to create the new article in the database. We will be redirected back to the the articles index page and there we assert @@ -770,7 +765,7 @@ that the text from the article title is on the articles index page. The beauty of system testing is that it is similar to integration testing in that it tests the user's interaction with your controller, model, and view, but system testing is much more robust and actually tests your application as if -a real user were using it. Going forward you can test anything that the user +a real user were using it. Going forward, you can test anything that the user themselves would do in your application such as commenting, deleting articles, publishing draft articles, etc. @@ -1054,7 +1049,7 @@ class ArticlesControllerTest < ActionDispatch::IntegrationTest assert_equal "index", @controller.action_name assert_equal "application/x-www-form-urlencoded", @request.media_type - assert_match "Articles", @response.body + assert_match "Articles", @response.body end end ``` -- cgit v1.2.3 From ea9566f6cd1b4d3f0d8a5f03283b49423b89044d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Tue, 21 Feb 2017 11:46:03 -0500 Subject: Use released arel --- guides/bug_report_templates/active_job_master.rb | 1 - guides/bug_report_templates/active_record_master.rb | 1 - guides/bug_report_templates/active_record_migrations_master.rb | 1 - guides/bug_report_templates/benchmark.rb | 1 - guides/bug_report_templates/generic_master.rb | 1 - 5 files changed, 5 deletions(-) (limited to 'guides') diff --git a/guides/bug_report_templates/active_job_master.rb b/guides/bug_report_templates/active_job_master.rb index 7591470440..f61518713f 100644 --- a/guides/bug_report_templates/active_job_master.rb +++ b/guides/bug_report_templates/active_job_master.rb @@ -8,7 +8,6 @@ end gemfile(true) do source "https://rubygems.org" gem "rails", github: "rails/rails" - gem "arel", github: "rails/arel" end require "active_job" diff --git a/guides/bug_report_templates/active_record_master.rb b/guides/bug_report_templates/active_record_master.rb index 8bbc1ef19e..7265a671b0 100644 --- a/guides/bug_report_templates/active_record_master.rb +++ b/guides/bug_report_templates/active_record_master.rb @@ -8,7 +8,6 @@ end gemfile(true) do source "https://rubygems.org" gem "rails", github: "rails/rails" - gem "arel", github: "rails/arel" gem "sqlite3" end diff --git a/guides/bug_report_templates/active_record_migrations_master.rb b/guides/bug_report_templates/active_record_migrations_master.rb index 84a4b71909..13a375d1ba 100644 --- a/guides/bug_report_templates/active_record_migrations_master.rb +++ b/guides/bug_report_templates/active_record_migrations_master.rb @@ -8,7 +8,6 @@ end gemfile(true) do source "https://rubygems.org" gem "rails", github: "rails/rails" - gem "arel", github: "rails/arel" gem "sqlite3" end diff --git a/guides/bug_report_templates/benchmark.rb b/guides/bug_report_templates/benchmark.rb index a0b541d012..54433b34dd 100644 --- a/guides/bug_report_templates/benchmark.rb +++ b/guides/bug_report_templates/benchmark.rb @@ -8,7 +8,6 @@ end gemfile(true) do source "https://rubygems.org" gem "rails", github: "rails/rails" - gem "arel", github: "rails/arel" gem "benchmark-ips" end diff --git a/guides/bug_report_templates/generic_master.rb b/guides/bug_report_templates/generic_master.rb index ed45726e92..d3a7ae4ac4 100644 --- a/guides/bug_report_templates/generic_master.rb +++ b/guides/bug_report_templates/generic_master.rb @@ -8,7 +8,6 @@ end gemfile(true) do source "https://rubygems.org" gem "rails", github: "rails/rails" - gem "arel", github: "rails/arel" end require "active_support" -- cgit v1.2.3 From 5f1430564ff8c2e651786521e9e3278becfd326b Mon Sep 17 00:00:00 2001 From: Celso Fernandes Date: Tue, 21 Feb 2017 21:42:44 -0300 Subject: [doc] Fix wrong class name in testing.md As the specified command is `rails g system_test articles`, the generated class name is `ArticlesTest`, not `UsersTest` --- guides/source/testing.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides') diff --git a/guides/source/testing.md b/guides/source/testing.md index 2937a23a67..2a474507e6 100644 --- a/guides/source/testing.md +++ b/guides/source/testing.md @@ -712,7 +712,7 @@ Now let's open that file and write our first assertion: ```ruby require "application_system_test_case" -class UsersTest < ApplicationSystemTestCase +class ArticlesTest < ApplicationSystemTestCase test "viewing the index" do visit articles_path assert_selector "h1", text: "Articles" -- cgit v1.2.3 From 6987c7c763406a38a883e9d8305857fada3b13eb Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Wed, 22 Feb 2017 11:01:13 +0900 Subject: remove needless extension from system test example [ci skip] --- guides/source/testing.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides') diff --git a/guides/source/testing.md b/guides/source/testing.md index 2a474507e6..652030a733 100644 --- a/guides/source/testing.md +++ b/guides/source/testing.md @@ -610,7 +610,7 @@ For creating Rails system tests, you use the `test/system` directory in your application. Rails provides a generator to create a system test skeleton for you. ```bash -$ bin/rails generate system_test users_create_test.rb +$ bin/rails generate system_test users_create_test invoke test_unit create test/system/users_create_test.rb ``` -- cgit v1.2.3 From f4acdd83ff76e2338895073ed914c525e7bb33b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Thu, 23 Feb 2017 14:53:12 -0500 Subject: Preparing for 5.1.0.beta1 release --- guides/CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'guides') diff --git a/guides/CHANGELOG.md b/guides/CHANGELOG.md index 2730d2dfea..3a602efb3d 100644 --- a/guides/CHANGELOG.md +++ b/guides/CHANGELOG.md @@ -1,2 +1,6 @@ +## Rails 5.1.0.beta1 (February 23, 2017) ## + +* No changes. + Please check [5-0-stable](https://github.com/rails/rails/blob/5-0-stable/guides/CHANGELOG.md) for previous changes. -- cgit v1.2.3 From d150ef00c5f0d2f132dce503b68c467ce825a54f Mon Sep 17 00:00:00 2001 From: Laurent Arnoud Date: Thu, 23 Feb 2017 21:57:01 +0100 Subject: Fix w3c_validator.rb validation script --- guides/w3c_validator.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'guides') diff --git a/guides/w3c_validator.rb b/guides/w3c_validator.rb index c0a32c6b91..4671e040ca 100644 --- a/guides/w3c_validator.rb +++ b/guides/w3c_validator.rb @@ -32,7 +32,8 @@ include W3CValidators module RailsGuides class Validator def validate - validator = MarkupValidator.new + # https://github.com/w3c-validators/w3c_validators/issues/25 + validator = NuValidator.new STDOUT.sync = true errors_on_guides = {} @@ -44,11 +45,11 @@ module RailsGuides next end - if results.validity - print "." - else + if results.errors.length > 0 print "E" errors_on_guides[f] = results.errors + else + print "." end end -- cgit v1.2.3 From e690a92b4498f2b65998656c625919767854623d Mon Sep 17 00:00:00 2001 From: Robin Dupret Date: Fri, 24 Feb 2017 23:27:15 +0100 Subject: Soft-deprecate the top-level HashWithIndifferentAccess class Since using a `ActiveSupport::Deprecation::DeprecatedConstantProxy` would prevent people from inheriting this class and extending it from the `ActiveSupport::HashWithIndifferentAccess` one would break the ancestors chain, that's the best option we have here. --- guides/source/upgrading_ruby_on_rails.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'guides') diff --git a/guides/source/upgrading_ruby_on_rails.md b/guides/source/upgrading_ruby_on_rails.md index 8ba00a2b10..6005298127 100644 --- a/guides/source/upgrading_ruby_on_rails.md +++ b/guides/source/upgrading_ruby_on_rails.md @@ -65,6 +65,25 @@ Overwrite /myapp/config/application.rb? (enter "h" for help) [Ynaqdh] Don't forget to review the difference, to see if there were any unexpected changes. +Upgrading from Rails 5.0 to Rails 5.1 +------------------------------------- + +For more information on changes made to Rails 5.1 please see the [release notes](5_1_release_notes.html). + +### Top-level `HashWithIndifferentAccess` is soft-deprecated + +If your application uses the the top-level `HashWithIndifferentAccess` class, you +should slowly move your code to use the `ActiveSupport::HashWithIndifferentAccess` +one. + +It is only soft-deprecated, which means that your code will not break at the +moment and no deprecation warning will be displayed but this constant will be +removed in the future. + +Also, if you have pretty old YAML documents containg dumps of such objects, +you may need to load and dump them again to make sure that they reference +the right constant and that loading them won't break in the future. + Upgrading from Rails 4.2 to Rails 5.0 ------------------------------------- -- cgit v1.2.3 From 08df808b41c496bcb8c1035b4c50601a4d11f7f6 Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Sun, 26 Feb 2017 19:55:52 +0900 Subject: Use released arel Follow up to ea9566f6cd1b4d3f0d8a5f03283b49423b89044d --- guides/bug_report_templates/action_controller_master.rb | 1 - 1 file changed, 1 deletion(-) (limited to 'guides') diff --git a/guides/bug_report_templates/action_controller_master.rb b/guides/bug_report_templates/action_controller_master.rb index 7644f6fe4a..486c7243ad 100644 --- a/guides/bug_report_templates/action_controller_master.rb +++ b/guides/bug_report_templates/action_controller_master.rb @@ -8,7 +8,6 @@ end gemfile(true) do source "https://rubygems.org" gem "rails", github: "rails/rails" - gem "arel", github: "rails/arel" end require "action_controller/railtie" -- cgit v1.2.3 From acb4b4607655b4fc9f0e3ea70b9452fefe41ca6e Mon Sep 17 00:00:00 2001 From: Anne Johnson Date: Sun, 26 Feb 2017 15:31:06 -0500 Subject: Update i18n guide to cover :zero key support in pluralization [ci skip] --- guides/source/i18n.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'guides') diff --git a/guides/source/i18n.md b/guides/source/i18n.md index ed8cf8a344..6c8706bc13 100644 --- a/guides/source/i18n.md +++ b/guides/source/i18n.md @@ -707,6 +707,7 @@ The `:count` interpolation variable has a special role in that it both is interp ```ruby I18n.backend.store_translations :en, inbox: { + zero: 'no messages', # optional one: 'one message', other: '%{count} messages' } @@ -715,15 +716,20 @@ I18n.translate :inbox, count: 2 I18n.translate :inbox, count: 1 # => 'one message' + +I18n.translate :inbox, count: 0 +# => 'no messages' ``` The algorithm for pluralizations in `:en` is as simple as: ```ruby -entry[count == 1 ? 0 : 1] +lookup_key = :zero if count == 0 && entry.has_key?(:zero) +lookup_key ||= count == 1 ? :one : :other +entry[lookup_key] ``` -I.e. the translation denoted as `:one` is regarded as singular, the other is used as plural (including the count being zero). +The translation denoted as `:one` is regarded as singular, and the `:other` is used as plural. If the count is zero, and a `:zero` entry is present, then it will be used instead of `:other`. If the lookup for the key does not return a Hash suitable for pluralization, an `I18n::InvalidPluralizationData` exception is raised. -- cgit v1.2.3 From 6bee72db6a0261d72280cbc3a5d934245135622a Mon Sep 17 00:00:00 2001 From: James Baer Date: Mon, 27 Feb 2017 10:17:27 -0500 Subject: Improve documentation for Testing Your Mailers [ci skip] The current Basic Test Case example has the following assertion ``` assert_equal read_fixture('invite').join, email.body.to_s ``` email.body.to_s returns an empty string if both HTML and text templates exist for a given mailer. This commit adds a note to section 11.2.2 explaining this and also suggests using email.text_part.body.to_s and email.html_part.body.to_s as alternatives. --- guides/source/testing.md | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'guides') diff --git a/guides/source/testing.md b/guides/source/testing.md index 652030a733..4231500729 100644 --- a/guides/source/testing.md +++ b/guides/source/testing.md @@ -1435,6 +1435,10 @@ 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. +NOTE: `email.body.to_s` is present when there's only one (HTML or text) part present. +If the mailer provides both, you can test your fixture against specific parts +with `email.text_part.body.to_s` or `email.html_part.body.to_s`. + Here's the content of the `invite` fixture: ``` -- cgit v1.2.3 From 069e33de666b64deae1e6dc3992a6b46e2687ee4 Mon Sep 17 00:00:00 2001 From: Shay Date: Thu, 2 Mar 2017 20:55:30 +0200 Subject: fixed suspected typo in sample sql query --- guides/source/active_record_querying.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides') diff --git a/guides/source/active_record_querying.md b/guides/source/active_record_querying.md index 31220f9be2..38a9d61f4b 100644 --- a/guides/source/active_record_querying.md +++ b/guides/source/active_record_querying.md @@ -1871,7 +1871,7 @@ Which will execute: ```sql SELECT count(DISTINCT clients.id) AS count_all FROM clients - LEFT OUTER JOIN orders ON orders.client_id = client.id WHERE + LEFT OUTER JOIN orders ON orders.client_id = clients.id WHERE (clients.first_name = 'Ryan' AND orders.status = 'received') ``` -- cgit v1.2.3 From ff7a0efced5f267752a7dfd9f3e63322391fc5b7 Mon Sep 17 00:00:00 2001 From: Prathamesh Sonpatki Date: Tue, 21 Feb 2017 22:23:37 +0530 Subject: Add first draft of release notes for Rails 5.1 :tada: [ci skip] --- guides/source/5_1_release_notes.md | 98 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 guides/source/5_1_release_notes.md (limited to 'guides') diff --git a/guides/source/5_1_release_notes.md b/guides/source/5_1_release_notes.md new file mode 100644 index 0000000000..6733426aaa --- /dev/null +++ b/guides/source/5_1_release_notes.md @@ -0,0 +1,98 @@ +**DO NOT READ THIS FILE ON GITHUB, GUIDES ARE PUBLISHED ON http://guides.rubyonrails.org.** + +Ruby on Rails 5.1 Release Notes +=============================== + +Highlights in Rails 5.1: + +* Yarn Support +* Optional Webpack support +* jQuery no longer a default dependency +* System tests +* Encrypted secrets +* Parameterized mailers +* Direct & resolved routes +* Unification of form_for and form_tag into form_with + +These release notes cover only the major changes. To learn about various bug +fixes and changes, please refer to the change logs or check out the [list of +commits](https://github.com/rails/rails/commits/5-1-stable) in the main Rails +repository on GitHub. + +-------------------------------------------------------------------------------- + +Upgrading to Rails 5.1 +---------------------- + +ToDo + +Major Features +-------------- + +### Yarn Support + +### System tests + +### Encrypted secrets + +### Parameterized mailers + +### Direct & resolved routes + +Railties +-------- + +Please refer to the [Changelog][railties] for detailed changes. + +Action Pack +----------- + +Please refer to the [Changelog][action-pack] for detailed changes. + +Action View +------------- + +Please refer to the [Changelog][action-view] for detailed changes. + +Action Mailer +------------- + +Please refer to the [Changelog][action-mailer] for detailed changes. + +Active Record +------------- + +Please refer to the [Changelog][active-record] for detailed changes. + +Active Model +------------ + +Please refer to the [Changelog][active-model] for detailed changes. + +Active Job +----------- + +Please refer to the [Changelog][active-job] for detailed changes. + +Active Support +-------------- + +Please refer to the [Changelog][active-support] for detailed changes. + +Credits +------- + +See the +[full list of contributors to Rails](http://contributors.rubyonrails.org/) for +the many people who spent many hours making Rails, the stable and robust +framework it is. Kudos to all of them. + +[railties]: https://github.com/rails/rails/blob/5-1-stable/railties/CHANGELOG.md +[action-pack]: https://github.com/rails/rails/blob/5-1-stable/actionpack/CHANGELOG.md +[action-view]: https://github.com/rails/rails/blob/5-1-stable/actionview/CHANGELOG.md +[action-mailer]: https://github.com/rails/rails/blob/5-1-stable/actionmailer/CHANGELOG.md +[action-cable]: https://github.com/rails/rails/blob/5-1-stable/actioncable/CHANGELOG.md +[active-record]: https://github.com/rails/rails/blob/5-1-stable/activerecord/CHANGELOG.md +[active-model]: https://github.com/rails/rails/blob/5-1-stable/activemodel/CHANGELOG.md +[active-support]: https://github.com/rails/rails/blob/5-1-stable/activesupport/CHANGELOG.md +[active-job]: https://github.com/rails/rails/blob/5-1-stable/activejob/CHANGELOG.md -- cgit v1.2.3 From d8fd067969c4be4d8c38624a7cb79f770e087760 Mon Sep 17 00:00:00 2001 From: Prathamesh Sonpatki Date: Tue, 21 Feb 2017 22:38:30 +0530 Subject: Add PR links for major features [ci skip] --- guides/source/5_1_release_notes.md | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'guides') diff --git a/guides/source/5_1_release_notes.md b/guides/source/5_1_release_notes.md index 6733426aaa..f195922dca 100644 --- a/guides/source/5_1_release_notes.md +++ b/guides/source/5_1_release_notes.md @@ -31,14 +31,25 @@ Major Features ### Yarn Support +[Pull Request](https://github.com/rails/rails/pull/26836) + ### System tests +[Pull Request](https://github.com/rails/rails/pull/26703) + ### Encrypted secrets +[Pull Request](https://github.com/rails/rails/pull/28038) + ### Parameterized mailers +[Pull Request](https://github.com/rails/rails/pull/27825) + ### Direct & resolved routes +[Pull Request](https://github.com/rails/rails/pull/23138) + + Railties -------- -- cgit v1.2.3 From 3a35f101b7375cb18799986006c5c53e0c77f8f7 Mon Sep 17 00:00:00 2001 From: Erol Fornoles Date: Fri, 3 Mar 2017 17:02:00 +0800 Subject: Fix typo in Upgrading Ruby on Rails Guide [skip ci] --- guides/source/upgrading_ruby_on_rails.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides') diff --git a/guides/source/upgrading_ruby_on_rails.md b/guides/source/upgrading_ruby_on_rails.md index 6005298127..3afc0e5309 100644 --- a/guides/source/upgrading_ruby_on_rails.md +++ b/guides/source/upgrading_ruby_on_rails.md @@ -80,7 +80,7 @@ It is only soft-deprecated, which means that your code will not break at the moment and no deprecation warning will be displayed but this constant will be removed in the future. -Also, if you have pretty old YAML documents containg dumps of such objects, +Also, if you have pretty old YAML documents containing dumps of such objects, you may need to load and dump them again to make sure that they reference the right constant and that loading them won't break in the future. -- cgit v1.2.3 From 8b4e39b13d9f48abf5add5d1013030f933a549ca Mon Sep 17 00:00:00 2001 From: 0oneo Date: Fri, 3 Mar 2017 22:22:27 +0800 Subject: passing unique parameter to belongs_to wrongly passing `unique` parameter to belongs_to not right, --- guides/source/association_basics.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides') diff --git a/guides/source/association_basics.md b/guides/source/association_basics.md index 6e68935f9b..73c9c10c1f 100644 --- a/guides/source/association_basics.md +++ b/guides/source/association_basics.md @@ -154,7 +154,7 @@ case, the column definition might look like this: ```ruby create_table :accounts do |t| - t.belongs_to :supplier, index: true, unique: true, foreign_key: true + t.belongs_to :supplier, index: { unique: true }, foreign_key: true # ... end ``` -- cgit v1.2.3 From 8efda4a9c05c328f9b9bc5718f9f34272462cc74 Mon Sep 17 00:00:00 2001 From: Jonathan Chen Date: Fri, 3 Mar 2017 15:20:00 -0500 Subject: Fix spelling [ci skip] --- guides/source/active_model_basics.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides') diff --git a/guides/source/active_model_basics.md b/guides/source/active_model_basics.md index 732e553c62..72daa29f7f 100644 --- a/guides/source/active_model_basics.md +++ b/guides/source/active_model_basics.md @@ -320,7 +320,7 @@ person.serializable_hash # => {"name"=>"Bob"} #### ActiveModel::Serializers Rails provides an `ActiveModel::Serializers::JSON` serializer. -This module automatically include the `ActiveModel::Serialization`. +This module automatically includes the `ActiveModel::Serialization`. ##### ActiveModel::Serializers::JSON -- cgit v1.2.3 From c0f621ae63b048c02a1c8341a7c093e8a76c0e7e Mon Sep 17 00:00:00 2001 From: Vipul A M Date: Sat, 4 Mar 2017 11:44:25 +0530 Subject: Fix generated query in Retrieving specific data from multiple tables section [ci skip] --- guides/source/active_record_querying.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides') diff --git a/guides/source/active_record_querying.md b/guides/source/active_record_querying.md index 31220f9be2..690884caf9 100644 --- a/guides/source/active_record_querying.md +++ b/guides/source/active_record_querying.md @@ -1547,7 +1547,7 @@ SELECT people.id, people.name, comments.text FROM people INNER JOIN comments ON comments.person_id = people.id -WHERE comments.created_at = '2015-01-01' +WHERE comments.created_at > '2015-01-01' ``` ### Retrieving specific data from multiple tables -- cgit v1.2.3 From fd3c6eadbbc1fbd4782138a28a87cb96df3ca450 Mon Sep 17 00:00:00 2001 From: Vipul A M Date: Sat, 4 Mar 2017 12:19:28 +0530 Subject: Escapes and edits to configuring guide [ci skip] (#28280) --- guides/source/configuring.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'guides') diff --git a/guides/source/configuring.md b/guides/source/configuring.md index de921e2705..a4f3882124 100644 --- a/guides/source/configuring.md +++ b/guides/source/configuring.md @@ -350,9 +350,9 @@ All these configuration options are delegated to the `I18n` library. `config/environments/production.rb` which is generated by Rails. The default value is `true` if this configuration is not set. -* `config.active_record.dump_schemas` controls which database schemas will be dumped when calling db:structure:dump. - The options are `:schema_search_path` (the default) which dumps any schemas listed in schema_search_path, - `:all` which always dumps all schemas regardless of the schema_search_path, +* `config.active_record.dump_schemas` controls which database schemas will be dumped when calling `db:structure:dump`. + The options are `:schema_search_path` (the default) which dumps any schemas listed in `schema_search_path`, + `:all` which always dumps all schemas regardless of the `schema_search_path`, or a string of comma separated schemas. * `config.active_record.belongs_to_required_by_default` is a boolean value and @@ -362,10 +362,10 @@ All these configuration options are delegated to the `I18n` library. * `config.active_record.warn_on_records_fetched_greater_than` allows setting a warning threshold for query result size. If the number of records returned by a query exceeds the threshold, a warning is logged. This can be used to - identify queries which might be causing memory bloat. + identify queries which might be causing a memory bloat. * `config.active_record.index_nested_attribute_errors` allows errors for nested - has_many relationships to be displayed with an index as well as the error. + `has_many` relationships to be displayed with an index as well as the error. Defaults to `false`. * `config.active_record.use_schema_cache_dump` enables users to get schema cache information -- cgit v1.2.3 From 780434d88fb29543612c05a34a3dc6efbe661909 Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Sat, 4 Mar 2017 19:09:40 +0900 Subject: Fx system test example [ci skip] Since test suffix is automatically granted, it is not necessary to specify it in generator. Also, updated the generated file to contents actually generated. --- guides/source/testing.md | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'guides') diff --git a/guides/source/testing.md b/guides/source/testing.md index 4231500729..f7640d097f 100644 --- a/guides/source/testing.md +++ b/guides/source/testing.md @@ -610,9 +610,9 @@ For creating Rails system tests, you use the `test/system` directory in your application. Rails provides a generator to create a system test skeleton for you. ```bash -$ bin/rails generate system_test users_create_test +$ bin/rails generate system_test users_create invoke test_unit - create test/system/users_create_test.rb + create test/system/users_creates_test.rb ``` Here's what a freshly-generated system test looks like: @@ -620,10 +620,12 @@ Here's what a freshly-generated system test looks like: ```ruby require "application_system_test_case" -class UsersCreateTest < ApplicationSystemTestCase - visit users_url - - assert_selector "h1", text: "Users" +class UsersCreatesTest < ApplicationSystemTestCase + # test "visiting the index" do + # visit users_creates_url + # + # assert_selector "h1", text: "UsersCreate" + # end end ``` @@ -1436,7 +1438,7 @@ 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. NOTE: `email.body.to_s` is present when there's only one (HTML or text) part present. -If the mailer provides both, you can test your fixture against specific parts +If the mailer provides both, you can test your fixture against specific parts with `email.text_part.body.to_s` or `email.html_part.body.to_s`. Here's the content of the `invite` fixture: -- cgit v1.2.3 From 4a77213eead0e33a8158e47525bad3d5e1996300 Mon Sep 17 00:00:00 2001 From: Robin Dupret Date: Sat, 4 Mar 2017 14:54:03 +0100 Subject: Avoid running system tests by default These tests may be expansive so let's only allow users to run them through `bin/rails test:system` or by passing a path to the `test` command. The same applies for `bin/rake test`. Refs #28109. --- guides/source/testing.md | 3 +++ 1 file changed, 3 insertions(+) (limited to 'guides') diff --git a/guides/source/testing.md b/guides/source/testing.md index f7640d097f..3f53ccb242 100644 --- a/guides/source/testing.md +++ b/guides/source/testing.md @@ -730,6 +730,9 @@ Run the system tests. bin/rails test:system ``` +NOTE: By default, running `bin/rails test` won't run your system tests. +Make sure to run `bin/rails test:system` to actually run them. + #### Creating articles system test Now let's test the flow for creating a new article in our blog. -- cgit v1.2.3 From e1567d0d3a3c0ae1f4da1fb8b5b77a85767fb6ae Mon Sep 17 00:00:00 2001 From: Krzysztof Maicher Date: Sat, 4 Mar 2017 17:26:23 +0100 Subject: Improve foreign key description in guides [ci skip] --- guides/source/association_basics.md | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'guides') diff --git a/guides/source/association_basics.md b/guides/source/association_basics.md index 73c9c10c1f..5794bfa666 100644 --- a/guides/source/association_basics.md +++ b/guides/source/association_basics.md @@ -582,14 +582,30 @@ class CreateBooks < ActiveRecord::Migration[5.0] t.string :book_number t.integer :author_id end - - add_index :books, :author_id end end ``` If you create an association some time after you build the underlying model, you need to remember to create an `add_column` migration to provide the necessary foreign key. +It's a good practice to add an index on the foreign key to improve queries +performance and a foreign key constraint to ensure referential data integrity: + +```ruby +class CreateBooks < ActiveRecord::Migration[5.0] + def change + create_table :books do |t| + t.datetime :published_at + t.string :book_number + t.integer :author_id + end + + add_index :books, :author_id + add_foreign_key :books, :authors + end +end +``` + #### Creating Join Tables for `has_and_belongs_to_many` Associations If you create a `has_and_belongs_to_many` association, you need to explicitly create the joining table. Unless the name of the join table is explicitly specified by using the `:join_table` option, Active Record creates the name by using the lexical book of the class names. So a join between author and book models will give the default join table name of "authors_books" because "a" outranks "b" in lexical ordering. -- cgit v1.2.3 From 12cadc6f62da270eb7d9cfb010450f4123da75df Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Tue, 7 Mar 2017 15:40:52 +0900 Subject: Remove `:on` option that does ot exist [ci skip] That option was removed in 0a683085b1db435b7371350b2799a0f248cd717a --- guides/source/testing.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'guides') diff --git a/guides/source/testing.md b/guides/source/testing.md index 3f53ccb242..4caf55ab12 100644 --- a/guides/source/testing.md +++ b/guides/source/testing.md @@ -658,8 +658,8 @@ end The driver name is a required argument for `driven_by`. The optional arguments that can be passed to `driven_by` are `:using` for the browser (this will only -be used for non-headless drivers like Selenium), `:on` for the port Puma should -use, and `:screen_size` to change the size of the screen for screenshots. +be used for non-headless drivers like Selenium), and `:screen_size` to change +the size of the screen for screenshots. ```ruby require "test_helper" -- cgit v1.2.3 From 37770bc8d13c5c7af024e66539c79f966718aec0 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Thu, 9 Mar 2017 09:22:33 +0100 Subject: force UTF-8 as external encoding in guides generation [ci skip] See the rationale in the comment found in the patch. --- guides/Rakefile | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'guides') diff --git a/guides/Rakefile b/guides/Rakefile index ccb42f3273..0a591558e1 100644 --- a/guides/Rakefile +++ b/guides/Rakefile @@ -2,15 +2,28 @@ namespace :guides do desc 'Generate guides (for authors), use ONLY=foo to process just "foo.md"' task generate: "generate:html" + # Guides are written in UTF-8, but the environment may be configured for some + # other locale, these tasks are responsible for ensuring the default external + # encoding is UTF-8. + # + # Real use cases: Generation was reported to fail on a machine configured with + # GBK (Chinese). The docs server once got misconfigured somehow and had "C", + # which broke generation too. + task :encoding do + %w(LANG LANGUAGE LC_ALL).each do |env_var| + ENV[env_var] = "en_US.UTF-8" + end + end + namespace :generate do desc "Generate HTML guides" - task :html do + task :html => :encoding do ENV["WARNINGS"] = "1" # authors can't disable this ruby "rails_guides.rb" end desc "Generate .mobi file. The kindlegen executable must be in your PATH. You can get it for free from http://www.amazon.com/gp/feature.html?docId=1000765211" - task :kindle do + task :kindle => :encoding do require "kindlerb" unless Kindlerb.kindlegen_available? abort "Please run `setupkindlerb` to install kindlegen" @@ -25,7 +38,7 @@ namespace :guides do # Validate guides ------------------------------------------------------------------------- desc 'Validate guides, use ONLY=foo to process just "foo.html"' - task :validate do + task :validate => :encoding do ruby "w3c_validator.rb" end -- cgit v1.2.3 From 7724c8cb53093ba09f5b8f08feb8321d376d56dd Mon Sep 17 00:00:00 2001 From: Vipul A M Date: Thu, 9 Mar 2017 20:05:13 +0530 Subject: Edits to Systems testing section [ci skip] --- guides/source/testing.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'guides') diff --git a/guides/source/testing.md b/guides/source/testing.md index f7640d097f..ada7c2da76 100644 --- a/guides/source/testing.md +++ b/guides/source/testing.md @@ -644,7 +644,7 @@ system tests should live. If you want to change the default settings you can simply change what the system tests are "driven by". Say you want to change the driver from Selenium to -Poltergeist. First add the Poltergeist gem to your Gemfile. Then in your +Poltergeist. First add the `poltergeist` gem to your Gemfile. Then in your `application_system_test_case.rb` file do the following: ```ruby @@ -722,7 +722,7 @@ class ArticlesTest < ApplicationSystemTestCase end ``` -The test should see that there is an h1 on the articles index and pass. +The test should see that there is an `h1` on the articles index page and pass. Run the system tests. @@ -760,7 +760,7 @@ text. Once the fields are filled in, "Create Article" is clicked on which will send a POST request to create the new article in the database. We will be redirected back to the the articles index page and there we assert -that the text from the article title is on the articles index page. +that the text from the new article's title is on the articles index page. #### Taking it further -- cgit v1.2.3 From dcc9bd35e248f9e038c0fbc6a2024cd2d5228cbc Mon Sep 17 00:00:00 2001 From: James Baer Date: Fri, 10 Mar 2017 12:33:21 -0500 Subject: Improve readability of testing guide [ci skip] Small change to improve the readability in section 2.3 of the testing guide. --- guides/source/testing.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides') diff --git a/guides/source/testing.md b/guides/source/testing.md index 4caf55ab12..27f5b5e916 100644 --- a/guides/source/testing.md +++ b/guides/source/testing.md @@ -123,7 +123,7 @@ def test_the_truth end ``` -However only the `test` macro allows a more readable test name. You can still use regular method definitions though. +Although you can still use regular method definitions, using the `test` macro allows for a more readable test name. NOTE: The method name is generated by replacing spaces with underscores. The result does not need to be a valid Ruby identifier though, the name may contain punctuation characters etc. That's because in Ruby technically any string may be a method name. This may require use of `define_method` and `send` calls to function properly, but formally there's little restriction on the name. -- cgit v1.2.3 From 5c2678056ac5d7af1a2f82a6e1e98401467cb5eb Mon Sep 17 00:00:00 2001 From: bogdanvlviv Date: Sun, 12 Mar 2017 12:06:48 +0200 Subject: Fix typo in the security guide [ci skip] --- guides/source/security.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'guides') diff --git a/guides/source/security.md b/guides/source/security.md index a81a782cf2..a57c6ea247 100644 --- a/guides/source/security.md +++ b/guides/source/security.md @@ -615,7 +615,7 @@ The two dashes start a comment ignoring everything after it. So the query return Usually a web application includes access control. The user enters their login credentials and the web application tries to find the matching record in the users table. The application grants access when it finds a record. However, an attacker may possibly bypass this check with SQL injection. The following shows a typical database query in Rails to find the first record in the users table which matches the login credentials parameters supplied by the user. ```ruby -User.first("login = '#{params[:name]}' AND password = '#{params[:password]}'") +User.find_by("login = '#{params[:name]}' AND password = '#{params[:password]}'") ``` If an attacker enters ' OR '1'='1 as the name, and ' OR '2'>'1 as the password, the resulting SQL query will be: @@ -762,7 +762,7 @@ s = sanitize(user_input, tags: tags, attributes: %w(href title)) This allows only the given tags and does a good job, even against all kinds of tricks and malformed tags. -As a second step, _it is good practice to escape all output of the application_, especially when re-displaying user input, which hasn't been input-filtered (as in the search form example earlier on). _Use `escapeHTML()` (or its alias `h()`) method_ to replace the HTML input characters &, ", <, and > by their uninterpreted representations in HTML (`&`, `"`, `<`, and `>`). +As a second step, _it is good practice to escape all output of the application_, especially when re-displaying user input, which hasn't been input-filtered (as in the search form example earlier on). _Use `escapeHTML()` (or its alias `h()`) method_ to replace the HTML input characters &, ", <, and > by their uninterpreted representations in HTML (`&`, `"`, `<`, and `>`). ##### Obfuscation and Encoding Injection -- cgit v1.2.3 From 4d5060072b5446e0d13873f7edbecaf3527e7846 Mon Sep 17 00:00:00 2001 From: Vipul A M Date: Sun, 12 Mar 2017 19:37:48 +0530 Subject: Add link to mentioned API [ci skip] (#28392) --- guides/source/form_helpers.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides') diff --git a/guides/source/form_helpers.md b/guides/source/form_helpers.md index 8ad76ad01e..0508b0fb38 100644 --- a/guides/source/form_helpers.md +++ b/guides/source/form_helpers.md @@ -531,7 +531,7 @@ To leverage time zone support in Rails, you have to ask your users what time zon <%= time_zone_select(:person, :time_zone) %> ``` -There is also `time_zone_options_for_select` helper for a more manual (therefore more customizable) way of doing this. Read the API documentation to learn about the possible arguments for these two methods. +There is also `time_zone_options_for_select` helper for a more manual (therefore more customizable) way of doing this. Read the [API documentation](http://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-time_zone_options_for_select) to learn about the possible arguments for these two methods. Rails _used_ to have a `country_select` helper for choosing countries, but this has been extracted to the [country_select plugin](https://github.com/stefanpenner/country_select). When using this, be aware that the exclusion or inclusion of certain names from the list can be somewhat controversial (and was the reason this functionality was extracted from Rails). -- cgit v1.2.3 From 8f9241b076c836a318649f26e7677ae1390c3b9a Mon Sep 17 00:00:00 2001 From: Jon Moss Date: Sun, 12 Mar 2017 11:25:24 -0400 Subject: First editing pass on "Active Model Basics" guide Lots of grammar, etc fixes. [ci skip] --- guides/source/active_model_basics.md | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'guides') diff --git a/guides/source/active_model_basics.md b/guides/source/active_model_basics.md index 72daa29f7f..a35d0e4067 100644 --- a/guides/source/active_model_basics.md +++ b/guides/source/active_model_basics.md @@ -87,7 +87,7 @@ end ### Conversion If a class defines `persisted?` and `id` methods, then you can include the -`ActiveModel::Conversion` module in that class and call the Rails conversion +`ActiveModel::Conversion` module in that class, and call the Rails conversion methods on objects of that class. ```ruby @@ -132,7 +132,7 @@ class Person end def last_name - @last_name + @last_nameperson.changes # => {"first_name"=>[nil, "First Name"]} end def last_name=(value) @@ -156,16 +156,17 @@ person.changed? # => false person.first_name = "First Name" person.first_name # => "First Name" -# returns true if any of the attributes have unsaved changes, false otherwise. +# returns true if any of the attributes have unsaved changes. person.changed? # => true # returns a list of attributes that have changed before saving. person.changed # => ["first_name"] -# returns a hash of the attributes that have changed with their original values. +# returns a Hash of the attributes that have changed with their original values. person.changed_attributes # => {"first_name"=>nil} -# returns a hash of changes, with the attribute names as the keys, and the values will be an array of the old and new value for that field. +# returns a Hash of changes, with the attribute names as the keys, and the +# values as an array of the old and new values for that field. person.changes # => {"first_name"=>[nil, "First Name"]} ``` @@ -179,7 +180,7 @@ person.first_name # => "First Name" person.first_name_changed? # => true ``` -Track what was the previous value of the attribute. +Track the previous value of the attribute. ```ruby # attr_name_was accessor @@ -187,7 +188,7 @@ person.first_name_was # => nil ``` Track both previous and current value of the changed attribute. Returns an array -if changed, else returns nil. +if changed, otherwise returns nil. ```ruby # attr_name_change @@ -197,7 +198,7 @@ person.last_name_change # => nil ### Validations -The `ActiveModel::Validations` module adds the ability to validate class objects +The `ActiveModel::Validations` module adds the ability to validate objects like in Active Record. ```ruby @@ -225,7 +226,7 @@ person.valid? # => raises ActiveModel::StrictValidationFa ### Naming -`ActiveModel::Naming` adds a number of class methods which make the naming and routing +`ActiveModel::Naming` adds a number of class methods which make naming and routing easier to manage. The module defines the `model_name` class method which will define a number of accessors using some `ActiveSupport::Inflector` methods. @@ -248,7 +249,7 @@ Person.model_name.singular_route_key # => "person" ### Model -`ActiveModel::Model` adds the ability to a class to work with Action Pack and +`ActiveModel::Model` adds the ability for a class to work with Action Pack and Action View right out of the box. ```ruby @@ -308,7 +309,7 @@ class Person end ``` -Now you can access a serialized hash of your object using the `serializable_hash`. +Now you can access a serialized hash of your object using the `serializable_hash` method. ```ruby person = Person.new -- cgit v1.2.3 From 21a44916ae39cb622c11c3e206a74925d114cfa8 Mon Sep 17 00:00:00 2001 From: Jon Moss Date: Sun, 12 Mar 2017 11:37:15 -0400 Subject: Second editing pass on "Active Model Basics" guide Lots of grammar, etc fixes. [ci skip] --- guides/source/active_model_basics.md | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) (limited to 'guides') diff --git a/guides/source/active_model_basics.md b/guides/source/active_model_basics.md index a35d0e4067..ce33734f41 100644 --- a/guides/source/active_model_basics.md +++ b/guides/source/active_model_basics.md @@ -294,7 +294,7 @@ objects. ### Serialization `ActiveModel::Serialization` provides basic serialization for your object. -You need to declare an attributes hash which contains the attributes you want to +You need to declare an attributes Hash which contains the attributes you want to serialize. Attributes must be strings, not symbols. ```ruby @@ -309,7 +309,7 @@ class Person end ``` -Now you can access a serialized hash of your object using the `serializable_hash` method. +Now you can access a serialized Hash of your object using the `serializable_hash` method. ```ruby person = Person.new @@ -320,13 +320,14 @@ person.serializable_hash # => {"name"=>"Bob"} #### ActiveModel::Serializers -Rails provides an `ActiveModel::Serializers::JSON` serializer. -This module automatically includes the `ActiveModel::Serialization`. +Active Model also provides the `ActiveModel::Serializers::JSON` module +for JSON serializing / deserializing. This module automatically includes the +previously discussed `ActiveModel::Serialization` module. ##### ActiveModel::Serializers::JSON -To use the `ActiveModel::Serializers::JSON` you only need to change from -`ActiveModel::Serialization` to `ActiveModel::Serializers::JSON`. +To use `ActiveModel::Serializers::JSON` you only need to change the +module you are including from `ActiveModel::Serialization` to `ActiveModel::Serializers::JSON`. ```ruby class Person @@ -340,7 +341,8 @@ class Person end ``` -With the `as_json` method you have a hash representing the model. +The `as_json` method, similar to `serializable_hash`, provides a Hash representing +the model. ```ruby person = Person.new @@ -349,8 +351,8 @@ person.name = "Bob" person.as_json # => {"name"=>"Bob"} ``` -From a JSON string you define the attributes of the model. -You need to have the `attributes=` method defined on your class: +You can also define the attributes for a model from a JSON string. +However, you need to define the `attributes=` method on your class: ```ruby class Person @@ -370,7 +372,7 @@ class Person end ``` -Now it is possible to create an instance of person and set the attributes using `from_json`. +Now it is possible to create an instance of `Person` and set attributes using `from_json`. ```ruby json = { name: 'Bob' }.to_json @@ -390,8 +392,8 @@ class Person end ``` -With the `human_attribute_name` you can transform attribute names into a more -human format. The human format is defined in your locale file. +With the `human_attribute_name` method, you can transform attribute names into a +more human-readable format. The human-readable format is defined in your locale file(s). * config/locales/app.pt-BR.yml @@ -412,7 +414,7 @@ Person.human_attribute_name('name') # => "Nome" `ActiveModel::Lint::Tests` allows you to test whether an object is compliant with the Active Model API. -* app/models/person.rb +* `app/models/person.rb` ```ruby class Person @@ -420,7 +422,7 @@ the Active Model API. end ``` -* test/models/person_test.rb +* `test/models/person_test.rb` ```ruby require 'test_helper' @@ -455,9 +457,9 @@ features out of the box. ### SecurePassword `ActiveModel::SecurePassword` provides a way to securely store any -password in an encrypted form. On including this module, a +password in an encrypted form. When you include this module, a `has_secure_password` class method is provided which defines -an accessor named `password` with certain validations on it. +a `password` accessor with certain validations on it. #### Requirements -- cgit v1.2.3 From 89d66410892b9c42bf2a11f7308d6c8bf8d656c8 Mon Sep 17 00:00:00 2001 From: Jon Moss Date: Sun, 12 Mar 2017 13:11:53 -0400 Subject: Fix weird documentation line [ci skip] --- guides/source/active_model_basics.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides') diff --git a/guides/source/active_model_basics.md b/guides/source/active_model_basics.md index ce33734f41..e26805d22c 100644 --- a/guides/source/active_model_basics.md +++ b/guides/source/active_model_basics.md @@ -132,7 +132,7 @@ class Person end def last_name - @last_nameperson.changes # => {"first_name"=>[nil, "First Name"]} + @last_name end def last_name=(value) -- cgit v1.2.3 From b4dbe8c7338f0b531d60dbae12031a51ab7a7dcc Mon Sep 17 00:00:00 2001 From: Prathamesh Sonpatki Date: Fri, 3 Mar 2017 12:31:31 +0530 Subject: Add blurbs about each new feature [ci skip] --- guides/source/5_1_release_notes.md | 158 +++++++++++++++++++++++++++++++++++++ 1 file changed, 158 insertions(+) (limited to 'guides') diff --git a/guides/source/5_1_release_notes.md b/guides/source/5_1_release_notes.md index f195922dca..f3c8f1f155 100644 --- a/guides/source/5_1_release_notes.md +++ b/guides/source/5_1_release_notes.md @@ -33,22 +33,180 @@ Major Features [Pull Request](https://github.com/rails/rails/pull/26836) +Rails 5.1 will allow managing JavaScript dependencies +from NPM via Yarn.This will make it easy to use libraries like React, VueJS +or any other library from NPM world. The Yarn support is integrated with +the asset pipeline so that all dependencies will work seamlessly with the +Rails 5.1 app. + +### Optional Webpack support + +Rails apps can use Webpack easily now using the [Webpacker](https://github.com/rails/webpacker) +gem. New Rails 5.1 app can be generated using `--webpack` switch to enable Webpack integration. + +This is fully compatible with the asset pipeline, which you can continue to use for +images, fonts, sounds, whatever. You can even have some JavaScript on the asset pipeline +and some done via Webpack. It’s all managed via Yarn that’s on by default. + +### jQuery no longer a default dependency + +jQuery was required by default in earlier versions of Rails to provide features like +`data-remote`, `data-confirm` and other parts of Rails UJS. It is no longer required, +as the `rails-ujs` is now written using plain vanilla JavaScript. + +You can still use jQuery if needed, but it is no longer required by default. + ### System tests [Pull Request](https://github.com/rails/rails/pull/26703) +Rails 5.1 has support for writing Capybara tests baked in in the form of +System tests. Now you don't have to worry about configuring Capybara and +database cleaning strategies for such tests. Rails 5.1 provides a wrapper +for running such tests in chrome with additional features such as failure +screenshots. + ### Encrypted secrets [Pull Request](https://github.com/rails/rails/pull/28038) +Rails will now allow management of application secrets in a secure way +built on top of [sekrets](https://github.com/ahoward/sekrets) gem. + +Run `bin/rails secrets:setup` to setup a new encrypted secrets file. It will +generate a master key which needs to be stored outside of the repository and it will +allow checking in the actual secrets in the revision control. + +The secrets will be decrypted in production either using `RAILS_MASTER_KEY` from +the ENV or injected key file. + ### Parameterized mailers [Pull Request](https://github.com/rails/rails/pull/27825) +Allows specifying common params used for all methods in a mailer class +to share instance variables, headers and other common setup. + +``` ruby +class InvitationsMailer < ApplicationMailer + + before_action { @inviter, @invitee = params[:inviter], params[:invitee] } + before_action { @account = params[:inviter].account } + + def account_invitation + mail subject: "#{@inviter.name} invited you to their Basecamp (#{@account.name})" + end + + def project_invitation + @project = params[:project] + @summarizer = ProjectInvitationSummarizer.new(@project.bucket) + + mail subject: "#{@inviter.name.familiar} added you to a project in Basecamp (#{@account.name})" + end +end + +InvitationsMailer.with(inviter: person_a, invitee: person_b).account_invitation.deliver_later +``` + ### Direct & resolved routes [Pull Request](https://github.com/rails/rails/pull/23138) +Rails 5.1 has added two new methods - `resolve` and `direct` to the routing +DSL. + +The `resolve` method allows customizing polymorphic mapping of models. + +``` ruby +resource :basket + +resolve(class: "Basket") { [:basket] } +``` + +``` erb +<%= form_for @basket do |form| %> + +<% end %> +``` + +This will generate the singular URL `/basket` instead of usual `/baskets/:id`. + +The `direct` method allows creation of custom URL helpers. + +``` ruby +direct(:homepage) { "http://www.rubyonrails.org" } + +>> homepage_url +=> "http://www.rubyonrails.org" +``` + +The return value of the block must be a valid argument for the `url_for` +method. So you can pass a valid string URL, or a hash, or an array, or an +Active Model instance or an Active Model class. + +``` ruby +direct :commentable do |model| + [ model, anchor: model.dom_id ] +end + +direct :main do + { controller: 'pages', action: 'index', subdomain: 'www' } +end +``` + +### Unification of form_for and form_tag into form_with + +[Pull Request](https://github.com/rails/rails/pull/26976) + +Before Rails 5.1, there were two interfaces for handling HTML forms, +`form_for` for model instances and `form_tag` for custom URLs. + +Rails 5.1 combines both of these interfaces with `form_with` and +can generate form tags based on URLs, scopes or models. + +``` erb +# Using just a URL: + +<%= form_with url: posts_path do |form| %> + <%= form.text_field :title %> +<% end %> + +# => +
+ +
+ +# Adding a scope prefixes the input field names: + +<%= form_with scope: :post, url: posts_path do |form| %> + <%= form.text_field :title %> +<% end %> +# => +
+ +
+ +# Using a model infers both the URL and scope: + +<%= form_with model: Post.new do |form| %> + <%= form.text_field :title %> +<% end %> +# => +
+ +
+ +# An existing model makes an update form and fills out field values: + +<%= form_with model: Post.first do |form| %> + <%= form.text_field :title %> +<% end %> +# => +
+ + +
+``` Railties -------- -- cgit v1.2.3 From 96c525f2509a9ec1890c5218f6a65b22660b97f7 Mon Sep 17 00:00:00 2001 From: Philipe Fatio Date: Tue, 14 Mar 2017 10:57:50 +0100 Subject: Remove obsolete warning about regular expression This warning became obsolete when the regular expression was changed to use `\z` instead of `\Z` in fce9c4e5e1ecb31cff2ca43a04fbe332816c3c45. "-1234\n" =~ /\A[+-]?\d+\Z/ => 0 "-1234\n" =~ /\A[+-]?\d+\z/ => nil [ci skip] --- guides/source/active_record_validations.md | 3 --- 1 file changed, 3 deletions(-) (limited to 'guides') diff --git a/guides/source/active_record_validations.md b/guides/source/active_record_validations.md index 32b38cde5e..5313361dfd 100644 --- a/guides/source/active_record_validations.md +++ b/guides/source/active_record_validations.md @@ -490,9 +490,6 @@ If you set `:only_integer` to `true`, then it will use the regular expression to validate the attribute's value. Otherwise, it will try to convert the value to a number using `Float`. -WARNING. Note that the regular expression above allows a trailing newline -character. - ```ruby class Player < ApplicationRecord validates :points, numericality: true -- cgit v1.2.3 From a05845e0a699e169c11962212200dc8e72934dff Mon Sep 17 00:00:00 2001 From: Eugene Kenny Date: Wed, 15 Mar 2017 12:14:46 +0000 Subject: Remove unused `@txn` variable This was added in c24c885209ac2334dc6f798c394a821ee270bec6, removed in b89ffe7f0047eb614e42232a21201b317b880755, and then (unintentionally?) reintroduced in 2d7ae1b08ee2a10b12cbfeef3a6cc6da55b57df6. --- guides/source/debugging_rails_applications.md | 1 - 1 file changed, 1 deletion(-) (limited to 'guides') diff --git a/guides/source/debugging_rails_applications.md b/guides/source/debugging_rails_applications.md index ba0cdbf3af..33dee6a868 100644 --- a/guides/source/debugging_rails_applications.md +++ b/guides/source/debugging_rails_applications.md @@ -606,7 +606,6 @@ You can also inspect for an object method this way: @new_record = true @readonly = false @transaction_state = nil -@txn = nil ``` You can also use `display` to start watching variables. This is a good way of -- cgit v1.2.3 From 5a072ba317aa180b3622145003fb3ed8b93d226f Mon Sep 17 00:00:00 2001 From: bogdanvlviv Date: Tue, 7 Mar 2017 00:09:55 +0200 Subject: Remove ability update locking_column value --- guides/source/active_record_querying.md | 3 --- 1 file changed, 3 deletions(-) (limited to 'guides') diff --git a/guides/source/active_record_querying.md b/guides/source/active_record_querying.md index 31865ea375..2902c5d677 100644 --- a/guides/source/active_record_querying.md +++ b/guides/source/active_record_querying.md @@ -953,9 +953,6 @@ class Client < ApplicationRecord end ``` -NOTE: Please note that the optimistic locking will be ignored if you update the -locking column's value. - ### Pessimistic Locking Pessimistic locking uses a locking mechanism provided by the underlying database. Using `lock` when building a relation obtains an exclusive lock on the selected rows. Relations using `lock` are usually wrapped inside a transaction for preventing deadlock conditions. -- cgit v1.2.3 From 5a09b3fd6b22dda7b77dfa47d6ace210ea84f43a Mon Sep 17 00:00:00 2001 From: marvin Date: Thu, 16 Mar 2017 19:42:00 +0800 Subject: Fix asset_pipeline docs incorrect image dir info --- guides/source/asset_pipeline.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides') diff --git a/guides/source/asset_pipeline.md b/guides/source/asset_pipeline.md index 68dde4482f..61b7112247 100644 --- a/guides/source/asset_pipeline.md +++ b/guides/source/asset_pipeline.md @@ -335,7 +335,7 @@ an asset has been updated and if so loads it into the page: <%= javascript_include_tag "application", "data-turbolinks-track" => "reload" %> ``` -In regular views you can access images in the `public/assets/images` directory +In regular views you can access images in the `app/assets/images` directory like this: ```erb -- cgit v1.2.3 From 7b02f86680b2d712ea5b0ca541dc620f0a524b5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Fri, 17 Mar 2017 13:14:51 -0400 Subject: Fix resolve usage in the release notes [ci skip] --- guides/source/5_1_release_notes.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides') diff --git a/guides/source/5_1_release_notes.md b/guides/source/5_1_release_notes.md index f3c8f1f155..6bd5321b92 100644 --- a/guides/source/5_1_release_notes.md +++ b/guides/source/5_1_release_notes.md @@ -120,7 +120,7 @@ The `resolve` method allows customizing polymorphic mapping of models. ``` ruby resource :basket -resolve(class: "Basket") { [:basket] } +resolve("Basket") { [:basket] } ``` ``` erb -- cgit v1.2.3 From da7c4126d34c358cd83a0343af800c1c3d4ac5d8 Mon Sep 17 00:00:00 2001 From: James Baer Date: Fri, 17 Mar 2017 16:02:24 -0400 Subject: Improve Caching with Rails Guides [ci skip] Adds the "Caching in Development" section to demonstrate usage of the dev:cache task in development mode. Also, makes a small grammatical correction in section 2.4. --- guides/source/caching_with_rails.md | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'guides') diff --git a/guides/source/caching_with_rails.md b/guides/source/caching_with_rails.md index fd7626250c..af4ef6a58d 100644 --- a/guides/source/caching_with_rails.md +++ b/guides/source/caching_with_rails.md @@ -396,7 +396,7 @@ config.cache_store = :file_store, "/path/to/cache/directory" ``` With this cache store, multiple server processes on the same host can share a -cache. The cache store is appropriate for low to medium traffic sites that are +cache. This cache store is appropriate for low to medium traffic sites that are served off one or two hosts. Server processes running on different hosts could share a cache by using a shared file system, but that setup is not recommended. @@ -570,6 +570,20 @@ You can also set the strong ETag directly on the response. response.strong_etag = response.body # => "618bbc92e2d35ea1945008b42799b0e7" ``` +Caching in Development +---------------------- + +It's common to want to test the caching strategy of your application +in developement mode. Rails provides the rake task `dev:cache` to +easily toggle caching on/off. + +```bash +$ bin/rails dev:cache +Development mode is now being cached. +$ bin/rails dev:cache +Development mode is no longer being cached. +``` + References ---------- -- cgit v1.2.3 From 33786f62f9a1f9bd855bc51da501fb6a0fd6d0bf Mon Sep 17 00:00:00 2001 From: Jon Moss Date: Sat, 18 Mar 2017 22:07:20 -0400 Subject: First pass on 5.1 release notes Fixing tons of grammar, etc. [ci skip] --- guides/source/5_1_release_notes.md | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) (limited to 'guides') diff --git a/guides/source/5_1_release_notes.md b/guides/source/5_1_release_notes.md index 6bd5321b92..5b46cc57b2 100644 --- a/guides/source/5_1_release_notes.md +++ b/guides/source/5_1_release_notes.md @@ -41,20 +41,24 @@ Rails 5.1 app. ### Optional Webpack support -Rails apps can use Webpack easily now using the [Webpacker](https://github.com/rails/webpacker) -gem. New Rails 5.1 app can be generated using `--webpack` switch to enable Webpack integration. +Rails apps can integrate with [Webpack](https://webpack.js.org/), a JavaScript +asset bundler, more easily using the new [Webpacker](https://github.com/rails/webpacker) +gem. Use the `--webpack` flag when generating new applications to enable Webpack +integration. This is fully compatible with the asset pipeline, which you can continue to use for -images, fonts, sounds, whatever. You can even have some JavaScript on the asset pipeline -and some done via Webpack. It’s all managed via Yarn that’s on by default. +images, fonts, sounds, and other assets. You can even have some JavaScript code +managed by the asset pipeline, and other code processed via Webpack. It’s all managed via Yarn that’s on by default. ### jQuery no longer a default dependency -jQuery was required by default in earlier versions of Rails to provide features like -`data-remote`, `data-confirm` and other parts of Rails UJS. It is no longer required, -as the `rails-ujs` is now written using plain vanilla JavaScript. +jQuery was required by default in earlier versions of Rails to provide features +like `data-remote`, `data-confirm` and other parts of Rails' Unobtrusive JavaScript +offerings. It is no longer required, as the UJS has been rewritten to use plain, +vanilla JavaScript. This code now ships inside of Action View as +`rails-ujs`. -You can still use jQuery if needed, but it is no longer required by default. +You can still use jQuery version if needed, but it is no longer required by default. ### System tests @@ -63,7 +67,7 @@ You can still use jQuery if needed, but it is no longer required by default. Rails 5.1 has support for writing Capybara tests baked in in the form of System tests. Now you don't have to worry about configuring Capybara and database cleaning strategies for such tests. Rails 5.1 provides a wrapper -for running such tests in chrome with additional features such as failure +for running tests in Chrome with additional features such as failure screenshots. ### Encrypted secrets @@ -71,14 +75,14 @@ screenshots. [Pull Request](https://github.com/rails/rails/pull/28038) Rails will now allow management of application secrets in a secure way -built on top of [sekrets](https://github.com/ahoward/sekrets) gem. +built on top of the [sekrets](https://github.com/ahoward/sekrets) gem. Run `bin/rails secrets:setup` to setup a new encrypted secrets file. It will -generate a master key which needs to be stored outside of the repository and it will +generate a master key which needs to be stored outside of the repository, and it will allow checking in the actual secrets in the revision control. -The secrets will be decrypted in production either using `RAILS_MASTER_KEY` from -the ENV or injected key file. +The secrets will be decrypted in production using either the `RAILS_MASTER_KEY` +environment variable from a key file. ### Parameterized mailers @@ -112,7 +116,7 @@ InvitationsMailer.with(inviter: person_a, invitee: person_b).account_invitation. [Pull Request](https://github.com/rails/rails/pull/23138) -Rails 5.1 has added two new methods - `resolve` and `direct` to the routing +Rails 5.1 has added two new methods, `resolve` and `direct`, to the routing DSL. The `resolve` method allows customizing polymorphic mapping of models. -- cgit v1.2.3 From cb12b2a075956cac23da86648028b45e8ee30f69 Mon Sep 17 00:00:00 2001 From: Jon Moss Date: Sat, 18 Mar 2017 22:09:53 -0400 Subject: Second pass on 5.1 release notes [ci skip] --- guides/source/5_1_release_notes.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'guides') diff --git a/guides/source/5_1_release_notes.md b/guides/source/5_1_release_notes.md index 5b46cc57b2..1b6eb76e32 100644 --- a/guides/source/5_1_release_notes.md +++ b/guides/source/5_1_release_notes.md @@ -133,7 +133,7 @@ resolve("Basket") { [:basket] } <% end %> ``` -This will generate the singular URL `/basket` instead of usual `/baskets/:id`. +This will generate the singular URL `/basket` instead of the usual `/baskets/:id`. The `direct` method allows creation of custom URL helpers. @@ -145,8 +145,8 @@ direct(:homepage) { "http://www.rubyonrails.org" } ``` The return value of the block must be a valid argument for the `url_for` -method. So you can pass a valid string URL, or a hash, or an array, or an -Active Model instance or an Active Model class. +method. So, you can pass a valid string URL, Hash, array, an +Active Model instance, or an Active Model class. ``` ruby direct :commentable do |model| @@ -162,10 +162,10 @@ end [Pull Request](https://github.com/rails/rails/pull/26976) -Before Rails 5.1, there were two interfaces for handling HTML forms, +Before Rails 5.1, there were two interfaces for handling HTML forms: `form_for` for model instances and `form_tag` for custom URLs. -Rails 5.1 combines both of these interfaces with `form_with` and +Rails 5.1 combines both of these interfaces with `form_with`, and can generate form tags based on URLs, scopes or models. ``` erb -- cgit v1.2.3 From 061927b4a84770c71f26e706e8720e56eed32b58 Mon Sep 17 00:00:00 2001 From: Jon Moss Date: Sat, 18 Mar 2017 22:15:27 -0400 Subject: Add link to Webpack/Webpacker PR [ci skip] --- guides/source/5_1_release_notes.md | 2 ++ 1 file changed, 2 insertions(+) (limited to 'guides') diff --git a/guides/source/5_1_release_notes.md b/guides/source/5_1_release_notes.md index 1b6eb76e32..d072c67108 100644 --- a/guides/source/5_1_release_notes.md +++ b/guides/source/5_1_release_notes.md @@ -41,6 +41,8 @@ Rails 5.1 app. ### Optional Webpack support +[Pull Request](https://github.com/rails/rails/pull/27288) + Rails apps can integrate with [Webpack](https://webpack.js.org/), a JavaScript asset bundler, more easily using the new [Webpacker](https://github.com/rails/webpacker) gem. Use the `--webpack` flag when generating new applications to enable Webpack -- cgit v1.2.3 From 5e8dfcd12d1c496cf811a32f9f22de6a40d5abd3 Mon Sep 17 00:00:00 2001 From: Jon Moss Date: Sat, 18 Mar 2017 22:20:01 -0400 Subject: Add link to rails-ujs/dropping jQuery PR [ci skip] --- guides/source/5_1_release_notes.md | 2 ++ 1 file changed, 2 insertions(+) (limited to 'guides') diff --git a/guides/source/5_1_release_notes.md b/guides/source/5_1_release_notes.md index d072c67108..0216f04761 100644 --- a/guides/source/5_1_release_notes.md +++ b/guides/source/5_1_release_notes.md @@ -54,6 +54,8 @@ managed by the asset pipeline, and other code processed via Webpack. It’s all ### jQuery no longer a default dependency +[Pull Request](https://github.com/rails/rails/pull/27113) + jQuery was required by default in earlier versions of Rails to provide features like `data-remote`, `data-confirm` and other parts of Rails' Unobtrusive JavaScript offerings. It is no longer required, as the UJS has been rewritten to use plain, -- cgit v1.2.3 From 9cc2f50f9cc3191fd796af68d09826c67c02a572 Mon Sep 17 00:00:00 2001 From: Jon Moss Date: Sat, 18 Mar 2017 22:41:15 -0400 Subject: Update some jquery-ujs references to rails-ujs [ci skip] --- guides/source/action_mailer_basics.md | 5 +++-- guides/source/security.md | 13 ++++++------- guides/source/working_with_javascript_in_rails.md | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) (limited to 'guides') diff --git a/guides/source/action_mailer_basics.md b/guides/source/action_mailer_basics.md index 380fdac658..9673571909 100644 --- a/guides/source/action_mailer_basics.md +++ b/guides/source/action_mailer_basics.md @@ -550,8 +550,9 @@ url helper. <%= user_url(@user, host: 'example.com') %> ``` -NOTE: non-`GET` links require [jQuery UJS](https://github.com/rails/jquery-ujs) -and won't work in mailer templates. They will result in normal `GET` requests. +NOTE: non-`GET` links require [rails-ujs](https://github.com/rails/rails-ujs) or +[jQuery UJS](https://github.com/rails/jquery-ujs), and won't work in mailer templates. +They will result in normal `GET` requests. ### Adding images in Action Mailer Views diff --git a/guides/source/security.md b/guides/source/security.md index a57c6ea247..a14134f8c1 100644 --- a/guides/source/security.md +++ b/guides/source/security.md @@ -257,13 +257,12 @@ protect_from_forgery with: :exception This will automatically include a security token in all forms and Ajax requests generated by Rails. If the security token doesn't match what was expected, an exception will be thrown. -NOTE: By default, Rails includes jQuery and an [unobtrusive scripting adapter for -jQuery](https://github.com/rails/jquery-ujs), which adds a header called -`X-CSRF-Token` on every non-GET Ajax call made by jQuery with the security token. -Without this header, non-GET Ajax requests won't be accepted by Rails. When using -another library to make Ajax calls, it is necessary to add the security token as -a default header for Ajax calls in your library. To get the token, have a look at -`` tag printed by +NOTE: By default, Rails includes an [unobtrusive scripting adapter](https://github.com/rails/rails-ujs), +which adds a header called `X-CSRF-Token` with the security token on every non-GET +Ajax call. Without this header, non-GET Ajax requests won't be accepted by Rails. +When using another library to make Ajax calls, it is necessary to add the security +token as a default header for Ajax calls in your library. To get the token, have +a look at `` tag printed by `<%= csrf_meta_tags %>` in your application view. It is common to use persistent cookies to store user information, with `cookies.permanent` for example. In this case, the cookies will not be cleared and the out of the box CSRF protection will not be effective. If you are using a different cookie store than the session for this information, you must handle what to do with it yourself: diff --git a/guides/source/working_with_javascript_in_rails.md b/guides/source/working_with_javascript_in_rails.md index c1dfcab6f3..e04b3e3581 100644 --- a/guides/source/working_with_javascript_in_rails.md +++ b/guides/source/working_with_javascript_in_rails.md @@ -149,7 +149,7 @@ Because of Unobtrusive JavaScript, the Rails "Ajax helpers" are actually in two parts: the JavaScript half and the Ruby half. Unless you have disabled the Asset Pipeline, -[rails.js](https://github.com/rails/jquery-ujs/blob/master/src/rails.js) +[rails-ujs](https://github.com/rails/rails-ujs/blob/master/src/rails-ujs.coffee) provides the JavaScript half, and the regular Ruby view helpers add appropriate tags to your DOM. -- cgit v1.2.3 From aa56c89eb2691ffccdd60e72d5c17118edbf1b63 Mon Sep 17 00:00:00 2001 From: Simon Dawson Date: Sun, 19 Mar 2017 08:31:49 +0000 Subject: Minor grammar fixes for Rails 5.1 release notes --- guides/source/5_1_release_notes.md | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) (limited to 'guides') diff --git a/guides/source/5_1_release_notes.md b/guides/source/5_1_release_notes.md index 0216f04761..5d4885d55c 100644 --- a/guides/source/5_1_release_notes.md +++ b/guides/source/5_1_release_notes.md @@ -34,7 +34,7 @@ Major Features [Pull Request](https://github.com/rails/rails/pull/26836) Rails 5.1 will allow managing JavaScript dependencies -from NPM via Yarn.This will make it easy to use libraries like React, VueJS +from NPM via Yarn. This will make it easy to use libraries like React, VueJS or any other library from NPM world. The Yarn support is integrated with the asset pipeline so that all dependencies will work seamlessly with the Rails 5.1 app. @@ -50,7 +50,8 @@ integration. This is fully compatible with the asset pipeline, which you can continue to use for images, fonts, sounds, and other assets. You can even have some JavaScript code -managed by the asset pipeline, and other code processed via Webpack. It’s all managed via Yarn that’s on by default. +managed by the asset pipeline, and other code processed via Webpack. All of this is managed +by Yarn, which is enabled by default. ### jQuery no longer a default dependency @@ -62,14 +63,14 @@ offerings. It is no longer required, as the UJS has been rewritten to use plain, vanilla JavaScript. This code now ships inside of Action View as `rails-ujs`. -You can still use jQuery version if needed, but it is no longer required by default. +You can still use the jQuery version if needed, but it is no longer required by default. ### System tests [Pull Request](https://github.com/rails/rails/pull/26703) -Rails 5.1 has support for writing Capybara tests baked in in the form of -System tests. Now you don't have to worry about configuring Capybara and +Rails 5.1 has baked-in support for writing Capybara tests, in the form of +System tests. You need no longer worry about configuring Capybara and database cleaning strategies for such tests. Rails 5.1 provides a wrapper for running tests in Chrome with additional features such as failure screenshots. @@ -78,15 +79,16 @@ screenshots. [Pull Request](https://github.com/rails/rails/pull/28038) -Rails will now allow management of application secrets in a secure way -built on top of the [sekrets](https://github.com/ahoward/sekrets) gem. +Rails will now allow management of application secrets in a secure way, +building on top of the [sekrets](https://github.com/ahoward/sekrets) gem. -Run `bin/rails secrets:setup` to setup a new encrypted secrets file. It will -generate a master key which needs to be stored outside of the repository, and it will -allow checking in the actual secrets in the revision control. +Run `bin/rails secrets:setup` to setup a new encrypted secrets file. This will +also generate a master key, which must be stored outside of the repository. The +secrets themselves can then be safely checked into the revision control system, +in an encrypted form. -The secrets will be decrypted in production using either the `RAILS_MASTER_KEY` -environment variable from a key file. +Secrets will be decrypted in production, using a key stored either in the +`RAILS_MASTER_KEY` environment variable, or in a key file. ### Parameterized mailers @@ -149,7 +151,7 @@ direct(:homepage) { "http://www.rubyonrails.org" } ``` The return value of the block must be a valid argument for the `url_for` -method. So, you can pass a valid string URL, Hash, array, an +method. So, you can pass a valid string URL, Hash, Array, an Active Model instance, or an Active Model class. ``` ruby -- cgit v1.2.3 From 8ee16836982b79a14198c75006672677f1f55947 Mon Sep 17 00:00:00 2001 From: Simon Dawson Date: Sun, 19 Mar 2017 08:34:47 +0000 Subject: Remove stray back-end from ActiveJob Basics guide The hyphenated form "back-end" only appears once in this guide; elsewhere, the un-hyphenated form "backend" is used consistently. --- guides/source/active_job_basics.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides') diff --git a/guides/source/active_job_basics.md b/guides/source/active_job_basics.md index c65d1e6de5..b58ca61848 100644 --- a/guides/source/active_job_basics.md +++ b/guides/source/active_job_basics.md @@ -114,7 +114,7 @@ For enqueuing and executing jobs in production you need to set up a queuing back that is to say you need to decide for a 3rd-party queuing library that Rails should use. Rails itself only provides an in-process queuing system, which only keeps the jobs in RAM. If the process crashes or the machine is reset, then all outstanding jobs are lost with the -default async back-end. This may be fine for smaller apps or non-critical jobs, but most +default async backend. This may be fine for smaller apps or non-critical jobs, but most production apps will need to pick a persistent backend. ### Backends -- cgit v1.2.3 From 5c0d00072d1309dbc77bb5d97e42956bac3e8684 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Mon, 20 Mar 2017 15:04:57 -0400 Subject: Update the maintenance policy [ci skip] --- guides/source/maintenance_policy.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'guides') diff --git a/guides/source/maintenance_policy.md b/guides/source/maintenance_policy.md index 7ced3eab1c..1d6a4edb5b 100644 --- a/guides/source/maintenance_policy.md +++ b/guides/source/maintenance_policy.md @@ -44,7 +44,7 @@ from. In special situations, where someone from the Core Team agrees to support more series, they are included in the list of supported series. -**Currently included series:** `5.0.Z`, `4.2.Z`. +**Currently included series:** `5.1.Z`. Security Issues --------------- @@ -59,7 +59,7 @@ be built from 1.2.2, and then added to the end of 1-2-stable. This means that security releases are easy to upgrade to if you're running the latest version of Rails. -**Currently included series:** `5.0.Z`, `4.2.Z`. +**Currently included series:** `5.1.Z`, `5.0.Z`. Severe Security Issues ---------------------- @@ -68,7 +68,7 @@ For severe security issues we will provide new versions as above, and also the last major release series will receive patches and new versions. The classification of the security issue is judged by the core team. -**Currently included series:** `5.0.Z`, `4.2.Z`. +**Currently included series:** `5.1.Z`, `5.0.Z`, `4.2.Z`. Unsupported Release Series -------------------------- -- cgit v1.2.3 From 17545b4d889149d8185c0a3a78030703d7e70c0e Mon Sep 17 00:00:00 2001 From: Erol Fornoles Date: Tue, 21 Mar 2017 09:21:51 +0800 Subject: Fix typo in Caching with Rails Guide [skip ci] --- guides/source/caching_with_rails.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides') diff --git a/guides/source/caching_with_rails.md b/guides/source/caching_with_rails.md index af4ef6a58d..aa79f59e4f 100644 --- a/guides/source/caching_with_rails.md +++ b/guides/source/caching_with_rails.md @@ -574,7 +574,7 @@ Caching in Development ---------------------- It's common to want to test the caching strategy of your application -in developement mode. Rails provides the rake task `dev:cache` to +in development mode. Rails provides the rake task `dev:cache` to easily toggle caching on/off. ```bash -- cgit v1.2.3 From 3b51c8a591b0b79fa6d9f42f948b6b733dfae936 Mon Sep 17 00:00:00 2001 From: Hendy Tanata Date: Tue, 21 Mar 2017 08:49:48 -0700 Subject: Update Configuring Rails Component guide example config.time_zone is no longer in included in config/application.rb. See 28dcadc0140dfdebe87d5e691fd709c0a9ae0bae. --- guides/source/configuring.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides') diff --git a/guides/source/configuring.md b/guides/source/configuring.md index a4f3882124..ae70b06996 100644 --- a/guides/source/configuring.md +++ b/guides/source/configuring.md @@ -32,7 +32,7 @@ Configuring Rails Components In general, the work of configuring Rails means configuring the components of Rails, as well as configuring Rails itself. The configuration file `config/application.rb` and environment-specific configuration files (such as `config/environments/production.rb`) allow you to specify the various settings that you want to pass down to all of the components. -For example, the `config/application.rb` file includes this setting: +For example, you could add this setting to `config/application.rb` file: ```ruby config.time_zone = 'Central Time (US & Canada)' -- cgit v1.2.3 From 6c08d480f13d3332c878ca8a120a03fcd78f7ba2 Mon Sep 17 00:00:00 2001 From: Matthew Draper Date: Wed, 22 Mar 2017 10:11:39 +1030 Subject: Start Rails 5.2 development --- guides/CHANGELOG.md | 7 +------ guides/bug_report_templates/action_controller_master.rb | 1 + guides/bug_report_templates/active_job_master.rb | 1 + guides/bug_report_templates/active_record_master.rb | 1 + guides/bug_report_templates/active_record_migrations_master.rb | 1 + guides/bug_report_templates/generic_master.rb | 1 + 6 files changed, 6 insertions(+), 6 deletions(-) (limited to 'guides') diff --git a/guides/CHANGELOG.md b/guides/CHANGELOG.md index 3a602efb3d..d8b122d264 100644 --- a/guides/CHANGELOG.md +++ b/guides/CHANGELOG.md @@ -1,6 +1 @@ -## Rails 5.1.0.beta1 (February 23, 2017) ## - -* No changes. - - -Please check [5-0-stable](https://github.com/rails/rails/blob/5-0-stable/guides/CHANGELOG.md) for previous changes. +Please check [5-1-stable](https://github.com/rails/rails/blob/5-1-stable/guides/CHANGELOG.md) for previous changes. diff --git a/guides/bug_report_templates/action_controller_master.rb b/guides/bug_report_templates/action_controller_master.rb index 486c7243ad..7644f6fe4a 100644 --- a/guides/bug_report_templates/action_controller_master.rb +++ b/guides/bug_report_templates/action_controller_master.rb @@ -8,6 +8,7 @@ end gemfile(true) do source "https://rubygems.org" gem "rails", github: "rails/rails" + gem "arel", github: "rails/arel" end require "action_controller/railtie" diff --git a/guides/bug_report_templates/active_job_master.rb b/guides/bug_report_templates/active_job_master.rb index f61518713f..7591470440 100644 --- a/guides/bug_report_templates/active_job_master.rb +++ b/guides/bug_report_templates/active_job_master.rb @@ -8,6 +8,7 @@ end gemfile(true) do source "https://rubygems.org" gem "rails", github: "rails/rails" + gem "arel", github: "rails/arel" end require "active_job" diff --git a/guides/bug_report_templates/active_record_master.rb b/guides/bug_report_templates/active_record_master.rb index 7265a671b0..8bbc1ef19e 100644 --- a/guides/bug_report_templates/active_record_master.rb +++ b/guides/bug_report_templates/active_record_master.rb @@ -8,6 +8,7 @@ end gemfile(true) do source "https://rubygems.org" gem "rails", github: "rails/rails" + gem "arel", github: "rails/arel" gem "sqlite3" end diff --git a/guides/bug_report_templates/active_record_migrations_master.rb b/guides/bug_report_templates/active_record_migrations_master.rb index 13a375d1ba..84a4b71909 100644 --- a/guides/bug_report_templates/active_record_migrations_master.rb +++ b/guides/bug_report_templates/active_record_migrations_master.rb @@ -8,6 +8,7 @@ end gemfile(true) do source "https://rubygems.org" gem "rails", github: "rails/rails" + gem "arel", github: "rails/arel" gem "sqlite3" end diff --git a/guides/bug_report_templates/generic_master.rb b/guides/bug_report_templates/generic_master.rb index d3a7ae4ac4..ed45726e92 100644 --- a/guides/bug_report_templates/generic_master.rb +++ b/guides/bug_report_templates/generic_master.rb @@ -8,6 +8,7 @@ end gemfile(true) do source "https://rubygems.org" gem "rails", github: "rails/rails" + gem "arel", github: "rails/arel" end require "active_support" -- cgit v1.2.3 From afbbcf24d791362a65c7f29b739c73a5b09e3816 Mon Sep 17 00:00:00 2001 From: Matthew Draper Date: Wed, 22 Mar 2017 10:11:43 +1030 Subject: Update bug report templates --- guides/bug_report_templates/action_controller_gem.rb | 2 +- guides/bug_report_templates/active_job_gem.rb | 2 +- guides/bug_report_templates/active_record_gem.rb | 2 +- guides/bug_report_templates/active_record_migrations_gem.rb | 2 +- guides/bug_report_templates/generic_gem.rb | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) (limited to 'guides') diff --git a/guides/bug_report_templates/action_controller_gem.rb b/guides/bug_report_templates/action_controller_gem.rb index 85d698f81b..46fabca3e8 100644 --- a/guides/bug_report_templates/action_controller_gem.rb +++ b/guides/bug_report_templates/action_controller_gem.rb @@ -8,7 +8,7 @@ end gemfile(true) do source "https://rubygems.org" # Activate the gem you are reporting the issue against. - gem "rails", "5.0.1" + gem "rails", "5.1.0.rc1" end require "rack/test" diff --git a/guides/bug_report_templates/active_job_gem.rb b/guides/bug_report_templates/active_job_gem.rb index f715caec95..71fe356ea0 100644 --- a/guides/bug_report_templates/active_job_gem.rb +++ b/guides/bug_report_templates/active_job_gem.rb @@ -8,7 +8,7 @@ end gemfile(true) do source "https://rubygems.org" # Activate the gem you are reporting the issue against. - gem "activejob", "5.0.1" + gem "activejob", "5.1.0.rc1" end require "minitest/autorun" diff --git a/guides/bug_report_templates/active_record_gem.rb b/guides/bug_report_templates/active_record_gem.rb index 98edcb76b1..a685c257ea 100644 --- a/guides/bug_report_templates/active_record_gem.rb +++ b/guides/bug_report_templates/active_record_gem.rb @@ -8,7 +8,7 @@ end gemfile(true) do source "https://rubygems.org" # Activate the gem you are reporting the issue against. - gem "activerecord", "5.0.1" + gem "activerecord", "5.1.0.rc1" gem "sqlite3" end diff --git a/guides/bug_report_templates/active_record_migrations_gem.rb b/guides/bug_report_templates/active_record_migrations_gem.rb index ece6ae4f12..b4e822dfe0 100644 --- a/guides/bug_report_templates/active_record_migrations_gem.rb +++ b/guides/bug_report_templates/active_record_migrations_gem.rb @@ -8,7 +8,7 @@ end gemfile(true) do source "https://rubygems.org" # Activate the gem you are reporting the issue against. - gem "activerecord", "5.0.1" + gem "activerecord", "5.1.0.rc1" gem "sqlite3" end diff --git a/guides/bug_report_templates/generic_gem.rb b/guides/bug_report_templates/generic_gem.rb index fa9f94eea0..e1b705bea4 100644 --- a/guides/bug_report_templates/generic_gem.rb +++ b/guides/bug_report_templates/generic_gem.rb @@ -8,7 +8,7 @@ end gemfile(true) do source "https://rubygems.org" # Activate the gem you are reporting the issue against. - gem "activesupport", "5.0.1" + gem "activesupport", "5.1.0.rc1" end require "active_support/core_ext/object/blank" -- cgit v1.2.3 From 9e14f42a2ece637829eb8db307a105f321a0f77f Mon Sep 17 00:00:00 2001 From: brchristian Date: Thu, 23 Mar 2017 10:00:04 -0700 Subject: Additional explanation about cache implementations --- guides/source/caching_with_rails.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'guides') diff --git a/guides/source/caching_with_rails.md b/guides/source/caching_with_rails.md index aa79f59e4f..798fea9f30 100644 --- a/guides/source/caching_with_rails.md +++ b/guides/source/caching_with_rails.md @@ -387,6 +387,11 @@ store is not appropriate for large application deployments. However, it can work well for small, low traffic sites with only a couple of server processes, as well as development and test environments. +New Rails projects will be configured to use this implementation in the +development environment by default. (Note that, because processes will not share +cache data, if using `:memory_store` it will not be possible to manually read, +write or expire the cache via the Rails console.) + ### ActiveSupport::Cache::FileStore This cache store uses the file system to store entries. The path to the directory where the store files will be stored must be specified when initializing the cache. @@ -403,7 +408,8 @@ share a cache by using a shared file system, but that setup is not recommended. As the cache will grow until the disk is full, it is recommended to periodically clear out old entries. -This is the default cache store implementation. +This is the default cache store implementation (at `"#{root}/tmp/cache/"`) if +no explicit `config.cache_store` is supplied. ### ActiveSupport::Cache::MemCacheStore -- cgit v1.2.3 From aed7bb67485b1e4d4c7eeb40971ac4057d48999c Mon Sep 17 00:00:00 2001 From: Rachel Carvalho Date: Thu, 23 Mar 2017 16:21:11 -0400 Subject: update guide to reflect browser compatibility for HTTP verbs [ci skip] --- guides/source/security.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'guides') diff --git a/guides/source/security.md b/guides/source/security.md index a14134f8c1..7e27e6f37d 100644 --- a/guides/source/security.md +++ b/guides/source/security.md @@ -212,7 +212,7 @@ CSRF appears very rarely in CVE (Common Vulnerabilities and Exposures) - less th NOTE: _First, as is required by the W3C, use GET and POST appropriately. Secondly, a security token in non-GET requests will protect your application from CSRF._ -The HTTP protocol basically provides two main types of requests - GET and POST (and more, but they are not supported by most browsers). The World Wide Web Consortium (W3C) provides a checklist for choosing HTTP GET or POST: +The HTTP protocol basically provides two main types of requests - GET and POST (DELETE, PUT, and PATCH should be used like POST). The World Wide Web Consortium (W3C) provides a checklist for choosing HTTP GET or POST: **Use GET if:** @@ -224,7 +224,7 @@ The HTTP protocol basically provides two main types of requests - GET and POST ( * The interaction _changes the state_ of the resource in a way that the user would perceive (e.g., a subscription to a service), or * The user is _held accountable for the results_ of the interaction. -If your web application is RESTful, you might be used to additional HTTP verbs, such as PATCH, PUT or DELETE. Most of today's web browsers, however, do not support them - only GET and POST. Rails uses a hidden `_method` field to handle this barrier. +If your web application is RESTful, you might be used to additional HTTP verbs, such as PATCH, PUT or DELETE. Some legacy web browsers, however, do not support them - only GET and POST. Rails uses a hidden `_method` field to handle these cases. _POST requests can be sent automatically, too_. In this example, the link www.harmless.com is shown as the destination in the browser's status bar. But it has actually dynamically created a new form that sends a POST request. -- cgit v1.2.3 From 684de497a8c60c9cb367ff2e3657fb785c2a35ea Mon Sep 17 00:00:00 2001 From: Vipul A M Date: Fri, 24 Mar 2017 18:14:01 +0530 Subject: Doc cleanup for caching guide [ci skip] (#28556) --- guides/source/caching_with_rails.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'guides') diff --git a/guides/source/caching_with_rails.md b/guides/source/caching_with_rails.md index 798fea9f30..6cdce5c2f4 100644 --- a/guides/source/caching_with_rails.md +++ b/guides/source/caching_with_rails.md @@ -387,10 +387,10 @@ store is not appropriate for large application deployments. However, it can work well for small, low traffic sites with only a couple of server processes, as well as development and test environments. -New Rails projects will be configured to use this implementation in the -development environment by default. (Note that, because processes will not share -cache data, if using `:memory_store` it will not be possible to manually read, -write or expire the cache via the Rails console.) +New Rails projects are configured to use this implementation in development environment by default. + +NOTE: Since processes will not share cache data when using `:memory_store`, +it will not be possible to manually read, write or expire the cache via the Rails console. ### ActiveSupport::Cache::FileStore -- cgit v1.2.3 From c096262f614a0c307f89691e9b8e976b3be3f89f Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Sat, 25 Mar 2017 20:57:40 +0900 Subject: Rename local variable name `current_user` to `verified_user` [ci skip] Related #28570 --- guides/source/action_cable_overview.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'guides') diff --git a/guides/source/action_cable_overview.md b/guides/source/action_cable_overview.md index e929945dd0..50a28571b4 100644 --- a/guides/source/action_cable_overview.md +++ b/guides/source/action_cable_overview.md @@ -6,7 +6,7 @@ incorporate real-time features into your Rails application. After reading this guide, you will know: -* What Action Cable is and its integration on backend and frontend +* What Action Cable is and its integration on backend and frontend * How to setup Action Cable * How to setup channels * Deployment and Architecture setup for running Action Cable @@ -64,8 +64,8 @@ module ApplicationCable private def find_verified_user - if current_user = User.find_by(id: cookies.signed[:user_id]) - current_user + if verified_user = User.find_by(id: cookies.signed[:user_id]) + verified_user else reject_unauthorized_connection end -- cgit v1.2.3 From f116d36c93a316302239de9ef17bf1f19aef3b45 Mon Sep 17 00:00:00 2001 From: Jon Moss Date: Sat, 25 Mar 2017 11:27:28 -0400 Subject: Add WIP Rails 5.1 release notes to documents.yaml [ci skip] --- guides/source/documents.yaml | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'guides') diff --git a/guides/source/documents.yaml b/guides/source/documents.yaml index 2925fb4b58..5fccdcccec 100644 --- a/guides/source/documents.yaml +++ b/guides/source/documents.yaml @@ -193,6 +193,11 @@ name: Upgrading Ruby on Rails url: upgrading_ruby_on_rails.html description: This guide helps in upgrading applications to latest Ruby on Rails versions. + - + name: Ruby on Rails 5.1 Release Notes + url: 5_1_release_notes.html + description: Release notes for Rails 5.1. + work_in_progress: true - name: Ruby on Rails 5.0 Release Notes url: 5_0_release_notes.html -- cgit v1.2.3 From aaa9a5b5d80f168e71593a75b06de94ab6129bca Mon Sep 17 00:00:00 2001 From: Jon Moss Date: Sat, 25 Mar 2017 11:45:46 -0400 Subject: Upgrade various Rails 5.0 references to 5.1 RC1 is out, `5-1-stable` has been created, figured it was time to start updating this stuff :) [ci skip] --- guides/source/_welcome.html.erb | 3 ++- guides/source/command_line.md | 8 ++++---- guides/source/debugging_rails_applications.md | 12 ++++++------ guides/source/getting_started.md | 2 +- 4 files changed, 13 insertions(+), 12 deletions(-) (limited to 'guides') diff --git a/guides/source/_welcome.html.erb b/guides/source/_welcome.html.erb index 5bd1ea4d22..8afec00018 100644 --- a/guides/source/_welcome.html.erb +++ b/guides/source/_welcome.html.erb @@ -10,12 +10,13 @@

<% else %>

- These are the new guides for Rails 5.0 based on <%= @version %>. + These are the new guides for Rails 5.1 based on <%= @version %>. These guides are designed to make you immediately productive with Rails, and to help you understand how all of the pieces fit together.

<% end %>

The guides for earlier releases: +Rails 5.0, Rails 4.2, Rails 4.1, Rails 4.0, diff --git a/guides/source/command_line.md b/guides/source/command_line.md index c8d559745e..e28547e14f 100644 --- a/guides/source/command_line.md +++ b/guides/source/command_line.md @@ -63,7 +63,7 @@ With no further work, `rails server` will run our new shiny Rails app: $ cd commandsapp $ bin/rails server => Booting Puma -=> Rails 5.0.0 application starting in development on http://0.0.0.0:3000 +=> Rails 5.1.0 application starting in development on http://0.0.0.0:3000 => Run `rails server -h` for more startup options Puma starting in single mode... * Version 3.0.2 (ruby 2.3.0-p0), codename: Plethora of Penguin Pinatas @@ -294,7 +294,7 @@ If you wish to test out some code without changing any data, you can do that by ```bash $ bin/rails console --sandbox -Loading development environment in sandbox (Rails 5.0.0) +Loading development environment in sandbox (Rails 5.1.0) Any modifications you make will be rolled back on exit irb(main):001:0> ``` @@ -428,10 +428,10 @@ INFO: You can also use `bin/rails -T` to get the list of tasks. ```bash $ bin/rails about About your application's environment -Rails version 5.0.0 +Rails version 5.1.0 Ruby version 2.2.2 (x86_64-linux) RubyGems version 2.4.6 -Rack version 1.6 +Rack version 2.0.1 JavaScript Runtime Node.js (V8) Middleware Rack::Sendfile, ActionDispatch::Static, ActionDispatch::Executor, #, Rack::Runtime, Rack::MethodOverride, ActionDispatch::RequestId, Rails::Rack::Logger, ActionDispatch::ShowExceptions, ActionDispatch::DebugExceptions, ActionDispatch::RemoteIp, ActionDispatch::Reloader, ActionDispatch::Callbacks, ActiveRecord::Migration::CheckPending, ActionDispatch::Cookies, ActionDispatch::Session::CookieStore, ActionDispatch::Flash, Rack::Head, Rack::ConditionalGet, Rack::ETag Application root /home/foobar/commandsapp diff --git a/guides/source/debugging_rails_applications.md b/guides/source/debugging_rails_applications.md index 33dee6a868..58aab774b3 100644 --- a/guides/source/debugging_rails_applications.md +++ b/guides/source/debugging_rails_applications.md @@ -313,7 +313,7 @@ For example: ```bash => Booting Puma -=> Rails 5.0.0 application starting in development on http://0.0.0.0:3000 +=> Rails 5.1.0 application starting in development on http://0.0.0.0:3000 => Run `rails server -h` for more startup options Puma starting in single mode... * Version 3.4.0 (ruby 2.3.1-p112), codename: Owl Bowl Brawl @@ -445,11 +445,11 @@ then `backtrace` will supply the answer. --> #0 ArticlesController.index at /PathToProject/app/controllers/articles_controller.rb:8 #1 ActionController::BasicImplicitRender.send_action(method#String, *args#Array) - at /PathToGems/actionpack-5.0.0/lib/action_controller/metal/basic_implicit_render.rb:4 + at /PathToGems/actionpack-5.1.0/lib/action_controller/metal/basic_implicit_render.rb:4 #2 AbstractController::Base.process_action(action#NilClass, *args#Array) - at /PathToGems/actionpack-5.0.0/lib/abstract_controller/base.rb:181 + at /PathToGems/actionpack-5.1.0/lib/abstract_controller/base.rb:181 #3 ActionController::Rendering.process_action(action, *args) - at /PathToGems/actionpack-5.0.0/lib/action_controller/metal/rendering.rb:30 + at /PathToGems/actionpack-5.1.0/lib/action_controller/metal/rendering.rb:30 ... ``` @@ -461,7 +461,7 @@ context. ``` (byebug) frame 2 -[176, 185] in /PathToGems/actionpack-5.0.0/lib/abstract_controller/base.rb +[176, 185] in /PathToGems/actionpack-5.1.0/lib/abstract_controller/base.rb 176: # is the intended way to override action dispatching. 177: # 178: # Notice that the first argument is the method to be dispatched @@ -676,7 +676,7 @@ Ruby instruction to be executed -- in this case, Active Support's `week` method. ``` (byebug) step -[49, 58] in /PathToGems/activesupport-5.0.0/lib/active_support/core_ext/numeric/time.rb +[49, 58] in /PathToGems/activesupport-5.1.0/lib/active_support/core_ext/numeric/time.rb 49: 50: # Returns a Duration instance matching the number of weeks provided. 51: # diff --git a/guides/source/getting_started.md b/guides/source/getting_started.md index 57b8472462..068114898d 100644 --- a/guides/source/getting_started.md +++ b/guides/source/getting_started.md @@ -127,7 +127,7 @@ run the following: $ rails --version ``` -If it says something like "Rails 5.0.0", you are ready to continue. +If it says something like "Rails 5.1.0", you are ready to continue. ### Creating the Blog Application -- cgit v1.2.3 From 430f1e02fafd30a08edfa2b1e8032eb7e0e729cc Mon Sep 17 00:00:00 2001 From: Jon Moss Date: Sat, 25 Mar 2017 11:52:16 -0400 Subject: Update middleware list Taken from `bin/rails about` run on a v5.1.0.rc1 application. [ci skip] --- guides/source/command_line.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides') diff --git a/guides/source/command_line.md b/guides/source/command_line.md index e28547e14f..3360496c08 100644 --- a/guides/source/command_line.md +++ b/guides/source/command_line.md @@ -433,7 +433,7 @@ Ruby version 2.2.2 (x86_64-linux) RubyGems version 2.4.6 Rack version 2.0.1 JavaScript Runtime Node.js (V8) -Middleware Rack::Sendfile, ActionDispatch::Static, ActionDispatch::Executor, #, Rack::Runtime, Rack::MethodOverride, ActionDispatch::RequestId, Rails::Rack::Logger, ActionDispatch::ShowExceptions, ActionDispatch::DebugExceptions, ActionDispatch::RemoteIp, ActionDispatch::Reloader, ActionDispatch::Callbacks, ActiveRecord::Migration::CheckPending, ActionDispatch::Cookies, ActionDispatch::Session::CookieStore, ActionDispatch::Flash, Rack::Head, Rack::ConditionalGet, Rack::ETag +Middleware: Rack::Sendfile, ActionDispatch::Static, ActionDispatch::Executor, ActiveSupport::Cache::Strategy::LocalCache::Middleware, Rack::Runtime, Rack::MethodOverride, ActionDispatch::RequestId, ActionDispatch::RemoteIp, Sprockets::Rails::QuietAssets, Rails::Rack::Logger, ActionDispatch::ShowExceptions, WebConsole::Middleware, ActionDispatch::DebugExceptions, ActionDispatch::Reloader, ActionDispatch::Callbacks, ActiveRecord::Migration::CheckPending, ActionDispatch::Cookies, ActionDispatch::Session::CookieStore, ActionDispatch::Flash, Rack::Head, Rack::ConditionalGet, Rack::ETag Application root /home/foobar/commandsapp Environment development Database adapter sqlite3 -- cgit v1.2.3 From b8c330cb69c1b4e4cdfe30872db2a36d119b9c1b Mon Sep 17 00:00:00 2001 From: Jon Moss Date: Sat, 25 Mar 2017 12:17:37 -0400 Subject: Small grammar fix Add necessary commas. [ci skip] --- guides/source/contributing_to_ruby_on_rails.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'guides') diff --git a/guides/source/contributing_to_ruby_on_rails.md b/guides/source/contributing_to_ruby_on_rails.md index fe5437ae5d..9ffc86aa08 100644 --- a/guides/source/contributing_to_ruby_on_rails.md +++ b/guides/source/contributing_to_ruby_on_rails.md @@ -98,13 +98,13 @@ Anything you can do to make bug reports more succinct or easier to reproduce hel ### Testing Patches -You can also help out by examining pull requests that have been submitted to Ruby on Rails via GitHub. To apply someone's changes you need first to create a dedicated branch: +You can also help out by examining pull requests that have been submitted to Ruby on Rails via GitHub. In order to apply someone's changes, you need to first create a dedicated branch: ```bash $ git checkout -b testing_branch ``` -Then you can use their remote branch to update your codebase. For example, let's say the GitHub user JohnSmith has forked and pushed to a topic branch "orange" located at https://github.com/JohnSmith/rails. +Then, you can use their remote branch to update your codebase. For example, let's say the GitHub user JohnSmith has forked and pushed to a topic branch "orange" located at https://github.com/JohnSmith/rails. ```bash $ git remote add JohnSmith https://github.com/JohnSmith/rails.git -- cgit v1.2.3 From 3f27c9cbe97010bff0a6fa4d770f3ce3c3703b31 Mon Sep 17 00:00:00 2001 From: Jon Moss Date: Sat, 25 Mar 2017 12:18:29 -0400 Subject: Small grammar fix Add apostrophe. [ci skip] --- guides/source/contributing_to_ruby_on_rails.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides') diff --git a/guides/source/contributing_to_ruby_on_rails.md b/guides/source/contributing_to_ruby_on_rails.md index 9ffc86aa08..3b19b0dff1 100644 --- a/guides/source/contributing_to_ruby_on_rails.md +++ b/guides/source/contributing_to_ruby_on_rails.md @@ -15,7 +15,7 @@ After reading this guide, you will know: Ruby on Rails is not "someone else's framework." Over the years, hundreds of people have contributed to Ruby on Rails ranging from a single character to massive architectural changes or significant documentation - all with the goal of making Ruby on Rails better for everyone. Even if you don't feel up to writing code or documentation yet, there are a variety of other ways that you can contribute, from reporting issues to testing patches. -As mentioned in [Rails +As mentioned in [Rails' README](https://github.com/rails/rails/blob/master/README.md), everyone interacting in Rails and its sub-projects' codebases, issue trackers, chat rooms, and mailing lists is expected to follow the Rails [code of conduct](http://rubyonrails.org/conduct/). -------------------------------------------------------------------------------- -- cgit v1.2.3 From 2b3a3738b7a519f32f593f6e6b9c6ba89daa72ea Mon Sep 17 00:00:00 2001 From: Frederik Wille Date: Wed, 29 Mar 2017 15:46:10 +0200 Subject: add hint on after_action filters Adds a hint that ``after_action``-callbacks are not executed when an exception was raised in the rest of the request cycle. The ``before_action`` section mentions "If there are additional filters scheduled to run after that filter, they are also cancelled." but this is IMO not sufficient. --- guides/source/action_controller_overview.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides') diff --git a/guides/source/action_controller_overview.md b/guides/source/action_controller_overview.md index 69c4a00c5f..a43a69b7a3 100644 --- a/guides/source/action_controller_overview.md +++ b/guides/source/action_controller_overview.md @@ -719,7 +719,7 @@ Now, the `LoginsController`'s `new` and `create` actions will work as before wit In addition to "before" filters, you can also run filters after an action has been executed, or both before and after. -"after" filters are similar to "before" filters, but because the action has already been run they have access to the response data that's about to be sent to the client. Obviously, "after" filters cannot stop the action from running. +"after" filters are similar to "before" filters, but because the action has already been run they have access to the response data that's about to be sent to the client. Obviously, "after" filters cannot stop the action from running. Please note that "after" filters are executed only after a successful action but not when an exception was raised in the request cycle. "around" filters are responsible for running their associated actions by yielding, similar to how Rack middlewares work. -- cgit v1.2.3 From 40f226ae94a726ca8935062a8aac50af8cad1de9 Mon Sep 17 00:00:00 2001 From: Ryunosuke Sato Date: Thu, 30 Mar 2017 01:10:20 +0900 Subject: Fix link to rails-ujs https://github.com/rails/rails-ujs is merged into actionview in favor of https://github.com/rails/rails/pull/28098. [skip ci] --- guides/source/action_mailer_basics.md | 2 +- guides/source/security.md | 2 +- guides/source/working_with_javascript_in_rails.md | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'guides') diff --git a/guides/source/action_mailer_basics.md b/guides/source/action_mailer_basics.md index 9673571909..65146ee7da 100644 --- a/guides/source/action_mailer_basics.md +++ b/guides/source/action_mailer_basics.md @@ -550,7 +550,7 @@ url helper. <%= user_url(@user, host: 'example.com') %> ``` -NOTE: non-`GET` links require [rails-ujs](https://github.com/rails/rails-ujs) or +NOTE: non-`GET` links require [rails-ujs](https://github.com/rails/rails/blob/master/actionview/app/assets/javascripts) or [jQuery UJS](https://github.com/rails/jquery-ujs), and won't work in mailer templates. They will result in normal `GET` requests. diff --git a/guides/source/security.md b/guides/source/security.md index 7e27e6f37d..c305350243 100644 --- a/guides/source/security.md +++ b/guides/source/security.md @@ -257,7 +257,7 @@ protect_from_forgery with: :exception This will automatically include a security token in all forms and Ajax requests generated by Rails. If the security token doesn't match what was expected, an exception will be thrown. -NOTE: By default, Rails includes an [unobtrusive scripting adapter](https://github.com/rails/rails-ujs), +NOTE: By default, Rails includes an [unobtrusive scripting adapter](https://github.com/rails/rails/blob/master/actionview/app/assets/javascripts), which adds a header called `X-CSRF-Token` with the security token on every non-GET Ajax call. Without this header, non-GET Ajax requests won't be accepted by Rails. When using another library to make Ajax calls, it is necessary to add the security diff --git a/guides/source/working_with_javascript_in_rails.md b/guides/source/working_with_javascript_in_rails.md index e04b3e3581..cbaf9100f7 100644 --- a/guides/source/working_with_javascript_in_rails.md +++ b/guides/source/working_with_javascript_in_rails.md @@ -149,7 +149,7 @@ Because of Unobtrusive JavaScript, the Rails "Ajax helpers" are actually in two parts: the JavaScript half and the Ruby half. Unless you have disabled the Asset Pipeline, -[rails-ujs](https://github.com/rails/rails-ujs/blob/master/src/rails-ujs.coffee) +[rails-ujs](https://github.com/rails/rails/blob/master/actionview/app/assets/javascripts/rails-ujs.coffee) provides the JavaScript half, and the regular Ruby view helpers add appropriate tags to your DOM. -- cgit v1.2.3 From f77a6be8d23f048ced4fac54f1f4caea5e0749d7 Mon Sep 17 00:00:00 2001 From: Jon Moss Date: Wed, 29 Mar 2017 16:14:06 -0400 Subject: Small grammar fix Add comma and change verb. [ci skip] --- guides/source/action_controller_overview.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides') diff --git a/guides/source/action_controller_overview.md b/guides/source/action_controller_overview.md index a43a69b7a3..5d987264f5 100644 --- a/guides/source/action_controller_overview.md +++ b/guides/source/action_controller_overview.md @@ -719,7 +719,7 @@ Now, the `LoginsController`'s `new` and `create` actions will work as before wit In addition to "before" filters, you can also run filters after an action has been executed, or both before and after. -"after" filters are similar to "before" filters, but because the action has already been run they have access to the response data that's about to be sent to the client. Obviously, "after" filters cannot stop the action from running. Please note that "after" filters are executed only after a successful action but not when an exception was raised in the request cycle. +"after" filters are similar to "before" filters, but because the action has already been run they have access to the response data that's about to be sent to the client. Obviously, "after" filters cannot stop the action from running. Please note that "after" filters are executed only after a successful action, but not when an exception is raised in the request cycle. "around" filters are responsible for running their associated actions by yielding, similar to how Rack middlewares work. -- cgit v1.2.3 From b68aae003ad7456f6c365fa86d212fd1e5a46ff7 Mon Sep 17 00:00:00 2001 From: Jon Moss Date: Thu, 30 Mar 2017 15:57:32 -0400 Subject: Small grammar fix [ci skip] --- guides/source/routing.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides') diff --git a/guides/source/routing.md b/guides/source/routing.md index 86492a9332..53735ce82e 100644 --- a/guides/source/routing.md +++ b/guides/source/routing.md @@ -545,7 +545,7 @@ TIP: If you find yourself adding many extra actions to a resourceful route, it's Non-Resourceful Routes ---------------------- -In addition to resource routing, Rails has powerful support for routing arbitrary URLs to actions. Here, you don't get groups of routes automatically generated by resourceful routing. Instead, you set up each route within your application separately. +In addition to resource routing, Rails has powerful support for routing arbitrary URLs to actions. Here, you don't get groups of routes automatically generated by resourceful routing. Instead, you set up each route separately within your application. While you should usually use resourceful routing, there are still many places where the simpler routing is more appropriate. There's no need to try to shoehorn every last piece of your application into a resourceful framework if that's not a good fit. -- cgit v1.2.3 From 9aeba503c4bc321e4c5a14cd9c9fbf9fbcc60edb Mon Sep 17 00:00:00 2001 From: Ross Kaffenberger Date: Fri, 31 Mar 2017 18:11:15 -0400 Subject: Add default_scope note to AR guide [ci skip] Adds note to explain unexpected behavior described in issue #28561. Developers may be surprised that the internal representation of similar query conditions in Hash and Array formats in default_scope will yield different results for model initialization. Link: https://github.com/rails/rails/issues/28561 --- guides/source/active_record_querying.md | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'guides') diff --git a/guides/source/active_record_querying.md b/guides/source/active_record_querying.md index 2902c5d677..26d01d4ede 100644 --- a/guides/source/active_record_querying.md +++ b/guides/source/active_record_querying.md @@ -1381,8 +1381,9 @@ class Client < ApplicationRecord end ``` -NOTE: The `default_scope` is also applied while creating/building a record. -It is not applied while updating a record. E.g.: +NOTE: The `default_scope` is also applied while creating/building a record +when the scope arguments are given as a `Hash`. It is not applied while +updating a record. E.g.: ```ruby class Client < ApplicationRecord @@ -1393,6 +1394,17 @@ Client.new # => # Client.unscoped.new # => # ``` +Be aware that, when given in the `Array` format, `default_scope` query arguments +cannot be converted to a `Hash` for default attribute assignment. E.g.: + +```ruby +class Client < ApplicationRecord + default_scope { where("active = ?", true) } +end + +Client.new # => # +``` + ### Merging of scopes Just like `where` clauses scopes are merged using `AND` conditions. -- cgit v1.2.3 From b5c56090ee5f71134b85e3cdf7e3b89093649fac Mon Sep 17 00:00:00 2001 From: Ruy Diaz Date: Sat, 1 Apr 2017 21:35:20 -0700 Subject: Add anchor links to all headers To allow easy linking at all levels and not just from index --- guides/assets/stylesheets/main.css | 3 +++ guides/rails_guides/markdown.rb | 4 ++++ 2 files changed, 7 insertions(+) (limited to 'guides') diff --git a/guides/assets/stylesheets/main.css b/guides/assets/stylesheets/main.css index b56699a0d0..a1e4851833 100644 --- a/guides/assets/stylesheets/main.css +++ b/guides/assets/stylesheets/main.css @@ -294,6 +294,9 @@ a, a:link, a:visited { #mainCol a, #subCol a, #feature a {color: #980905;} #mainCol a code, #subCol a code, #feature a code {color: #980905;} +#mainCol a.anchorlink { text-decoration: none; } +#mainCol a.anchorlink:hover { text-decoration: underline; } + /* Navigation --------------------------------------- */ diff --git a/guides/rails_guides/markdown.rb b/guides/rails_guides/markdown.rb index bf2cc82c7c..16aaa7d1eb 100644 --- a/guides/rails_guides/markdown.rb +++ b/guides/rails_guides/markdown.rb @@ -105,6 +105,10 @@ module RailsGuides node.inner_html = "#{node_index(hierarchy)} #{node.inner_html}" end end + + doc.css('h3, h4, h5, h6').each do |node| + node.inner_html = "#{node.inner_html}" + end end.to_html end end -- cgit v1.2.3