diff options
Diffstat (limited to 'actionpack')
7 files changed, 117 insertions, 78 deletions
diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md index 0167dcbf96..641af029aa 100644 --- a/actionpack/CHANGELOG.md +++ b/actionpack/CHANGELOG.md @@ -1,3 +1,5 @@ +## Rails 5.1.0.beta1 (February 23, 2017) ## + * Prefer `remove_method` over `undef_method` when reloading routes When `undef_method` is used it prevents access to other implementations of that diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 073dabd0a8..10d733e477 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -2034,7 +2034,7 @@ module ActionDispatch # end # # direct :main do - # { controller: 'pages', action: 'index', subdomain: 'www' } + # { controller: "pages", action: "index", subdomain: "www" } # end # # The return value from the block passed to `direct` must be a valid set of @@ -2042,7 +2042,7 @@ module ActionDispatch # be one of the following: # # * A string, which is treated as a generated url - # * A hash, e.g. { controller: 'pages', action: 'index' } + # * A hash, e.g. { controller: "pages", action: "index" } # * An array, which is passed to `polymorphic_url` # * An Active Model instance # * An Active Model class @@ -2057,6 +2057,15 @@ module ActionDispatch # [ :products, options.merge(params.permit(:page, :size)) ] # end # + # In this instance the `params` object comes from the context in which the the + # block is executed, e.g. generating a url inside a controller action or a view. + # If the block is executed where there isn't a params object such as this: + # + # Rails.application.routes.url_helpers.browse_path + # + # then it will raise a `NameError`. Because of this you need to be aware of the + # context in which you will use your custom url helper when defining it. + # # NOTE: The `direct` method can't be used inside of a scope block such as # `namespace` or `scope` and will raise an error if it detects that it is. def direct(name, options = {}, &block) @@ -2101,7 +2110,7 @@ module ActionDispatch # You can pass options to a polymorphic mapping - the arity for the block # needs to be two as the instance is passed as the first argument, e.g: # - # direct class: "Basket", anchor: "items" do |basket, options| + # resolve "Basket", anchor: "items" do |basket, options| # [:basket, options] # end # diff --git a/actionpack/lib/action_dispatch/system_test_case.rb b/actionpack/lib/action_dispatch/system_test_case.rb index 99c2be0a35..70a5b75781 100644 --- a/actionpack/lib/action_dispatch/system_test_case.rb +++ b/actionpack/lib/action_dispatch/system_test_case.rb @@ -7,79 +7,79 @@ require "action_dispatch/system_testing/test_helpers/screenshot_helper" require "action_dispatch/system_testing/test_helpers/setup_and_teardown" module ActionDispatch + # = System Testing + # + # System tests let you test applications in the browser. Because system + # tests use a real browser experience, you can test all of your JavaScript + # easily from your test suite. + # + # To create a system test in your application, extend your test class + # from <tt>ApplicationSystemTestCase</tt>. System tests use Capybara as a + # base and allow you to configure the settings through your + # <tt>application_system_test_case.rb</tt> file that is generated with a new + # application or scaffold. + # + # Here is an example system test: + # + # require 'application_system_test_case' + # + # class Users::CreateTest < ApplicationSystemTestCase + # test "adding a new user" do + # visit users_path + # click_on 'New User' + # + # fill_in 'Name', with: 'Arya' + # click_on 'Create User' + # + # assert_text 'Arya' + # end + # end + # + # When generating an application or scaffold, an +application_system_test_case.rb+ + # file will also be generated containing the base class for system testing. + # This is where you can change the driver, add Capybara settings, and other + # configuration for your system tests. + # + # require "test_helper" + # + # class ApplicationSystemTestCase < ActionDispatch::SystemTestCase + # driven_by :selenium, using: :chrome, screen_size: [1400, 1400] + # end + # + # By default, <tt>ActionDispatch::SystemTestCase</tt> is driven by the + # Selenium driver, with the Chrome browser, and a browser size of 1400x1400. + # + # Changing the driver configuration options are easy. Let's say you want to use + # the Firefox browser instead of Chrome. In your +application_system_test_case.rb+ + # file add the following: + # + # require "test_helper" + # + # class ApplicationSystemTestCase < ActionDispatch::SystemTestCase + # driven_by :selenium, using: :firefox + # end + # + # +driven_by+ has a required argument for the driver name. The keyword + # arguments are +:using+ for the browser and +:screen_size+ to change the + # size of the browser screen. These two options are not applicable for + # headless drivers and will be silently ignored if passed. + # + # To use a headless driver, like Poltergeist, update your Gemfile to use + # Poltergeist instead of Selenium and then declare the driver name in the + # +application_system_test_case.rb+ file. In this case you would leave out the +:using+ + # option because the driver is headless. + # + # require "test_helper" + # require "capybara/poltergeist" + # + # class ApplicationSystemTestCase < ActionDispatch::SystemTestCase + # driven_by :poltergeist + # end + # + # Because <tt>ActionDispatch::SystemTestCase</tt> is a shim between Capybara + # and Rails, any driver that is supported by Capybara is supported by system + # tests as long as you include the required gems and files. class SystemTestCase < IntegrationTest - # = System Testing - # - # System tests let you test applications in the browser. Because system - # tests use a real browser experience, you can test all of your JavaScript - # easily from your test suite. - # - # To create a system test in your application, extend your test class - # from <tt>ApplicationSystemTestCase</tt>. System tests use Capybara as a - # base and allow you to configure the settings through your - # <tt>application_system_test_case.rb</tt> file that is generated with a new - # application or scaffold. - # - # Here is an example system test: - # - # require 'application_system_test_case' - # - # class Users::CreateTest < ApplicationSystemTestCase - # test "adding a new user" do - # visit users_path - # click_on 'New User' - # - # fill_in 'Name', with: 'Arya' - # click_on 'Create User' - # - # assert_text 'Arya' - # end - # end - # - # When generating an application or scaffold, an +application_system_test_case.rb+ - # file will also be generated containing the base class for system testing. - # This is where you can change the driver, add Capybara settings, and other - # configuration for your system tests. - # - # require "test_helper" - # - # class ApplicationSystemTestCase < ActionDispatch::SystemTestCase - # driven_by :selenium, using: :chrome, screen_size: [1400, 1400] - # end - # - # By default, <tt>ActionDispatch::SystemTestCase</tt> is driven by the - # Selenium driver, with the Chrome browser, and a browser size of 1400x1400. - # - # Changing the driver configuration options are easy. Let's say you want to use - # the Firefox browser instead of Chrome. In your +application_system_test_case.rb+ - # file add the following: - # - # require "test_helper" - # - # class ApplicationSystemTestCase < ActionDispatch::SystemTestCase - # driven_by :selenium, using: :firefox - # end - # - # +driven_by+ has a required argument for the driver name. The keyword - # arguments are +:using+ for the browser and +:screen_size+ to change the - # size of the browser screen. These two options are not applicable for - # headless drivers and will be silently ignored if passed. - # - # To use a headless driver, like Poltergeist, update your Gemfile to use - # Poltergeist instead of Selenium and then declare the driver name in the - # +application_system_test_case.rb+ file. In this case you would leave out the +:using+ - # option because the driver is headless. - # - # require "test_helper" - # require "capybara/poltergeist" - # - # class ApplicationSystemTestCase < ActionDispatch::SystemTestCase - # driven_by :poltergeist - # end - # - # Because <tt>ActionDispatch::SystemTestCase</tt> is a shim between Capybara - # and Rails, any driver that is supported by Capybara is supported by system - # tests as long as you include the required gems and files. include Capybara::DSL include SystemTesting::TestHelpers::SetupAndTeardown include SystemTesting::TestHelpers::ScreenshotHelper diff --git a/actionpack/lib/action_dispatch/system_testing/test_helpers/screenshot_helper.rb b/actionpack/lib/action_dispatch/system_testing/test_helpers/screenshot_helper.rb index 784005cb93..ddc961cf84 100644 --- a/actionpack/lib/action_dispatch/system_testing/test_helpers/screenshot_helper.rb +++ b/actionpack/lib/action_dispatch/system_testing/test_helpers/screenshot_helper.rb @@ -22,12 +22,12 @@ module ActionDispatch # fails add +take_failed_screenshot+ to the teardown block before clearing # sessions. def take_failed_screenshot - take_screenshot unless passed? + take_screenshot if failed? end private def image_name - passed? ? method_name : "failures_#{method_name}" + failed? ? "failures_#{method_name}" : method_name end def image_path @@ -51,6 +51,10 @@ module ActionDispatch def inline_base64(path) Base64.encode64(path).gsub("\n", "") end + + def failed? + !passed? && !skipped? + end end end end diff --git a/actionpack/lib/action_pack/gem_version.rb b/actionpack/lib/action_pack/gem_version.rb index d8f86630b1..d6a91a0569 100644 --- a/actionpack/lib/action_pack/gem_version.rb +++ b/actionpack/lib/action_pack/gem_version.rb @@ -8,7 +8,7 @@ module ActionPack MAJOR = 5 MINOR = 1 TINY = 0 - PRE = "alpha" + PRE = "beta1" STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".") end diff --git a/actionpack/test/dispatch/routing/custom_url_helpers_test.rb b/actionpack/test/dispatch/routing/custom_url_helpers_test.rb index 6d230a2557..f85b989892 100644 --- a/actionpack/test/dispatch/routing/custom_url_helpers_test.rb +++ b/actionpack/test/dispatch/routing/custom_url_helpers_test.rb @@ -96,6 +96,10 @@ class TestCustomUrlHelpers < ActionDispatch::IntegrationTest direct(:options) { |options| [:products, options] } direct(:defaults, size: 10) { |options| [:products, options] } + direct(:browse, page: 1, size: 10) do |options| + [:products, options.merge(params.permit(:page, :size).to_h.symbolize_keys)] + end + resolve("Article") { |article| [:post, { id: article.id }] } resolve("Basket") { |basket| [:basket] } resolve("User", anchor: "details") { |user, options| [:profile, options] } @@ -127,6 +131,10 @@ class TestCustomUrlHelpers < ActionDispatch::IntegrationTest @safe_params = ActionController::Parameters.new(@path_params).permit(:controller, :action) end + def params + ActionController::Parameters.new(page: 2, size: 25) + end + def test_direct_paths assert_equal "http://www.rubyonrails.org", website_path assert_equal "http://www.rubyonrails.org", Routes.url_helpers.website_path @@ -162,6 +170,9 @@ class TestCustomUrlHelpers < ActionDispatch::IntegrationTest assert_equal "/products?size=10", Routes.url_helpers.defaults_path assert_equal "/products?size=20", defaults_path(size: 20) assert_equal "/products?size=20", Routes.url_helpers.defaults_path(size: 20) + + assert_equal "/products?page=2&size=25", browse_path + assert_raises(NameError) { Routes.url_helpers.browse_path } end def test_direct_urls @@ -199,6 +210,9 @@ class TestCustomUrlHelpers < ActionDispatch::IntegrationTest assert_equal "http://www.example.com/products?size=10", Routes.url_helpers.defaults_url assert_equal "http://www.example.com/products?size=20", defaults_url(size: 20) assert_equal "http://www.example.com/products?size=20", Routes.url_helpers.defaults_url(size: 20) + + assert_equal "http://www.example.com/products?page=2&size=25", browse_url + assert_raises(NameError) { Routes.url_helpers.browse_url } end def test_resolve_paths diff --git a/actionpack/test/dispatch/system_testing/screenshot_helper_test.rb b/actionpack/test/dispatch/system_testing/screenshot_helper_test.rb index 8c14f799b0..3b4ea96c4f 100644 --- a/actionpack/test/dispatch/system_testing/screenshot_helper_test.rb +++ b/actionpack/test/dispatch/system_testing/screenshot_helper_test.rb @@ -15,4 +15,14 @@ class ScreenshotHelperTest < ActiveSupport::TestCase assert_equal "tmp/screenshots/failures_x.png", new_test.send(:image_path) end end + + test "image path does not include failures text if test skipped" do + new_test = ActionDispatch::SystemTestCase.new("x") + + new_test.stub :passed?, false do + new_test.stub :skipped?, true do + assert_equal "tmp/screenshots/x.png", new_test.send(:image_path) + end + end + end end |