├── .ruby-version ├── test ├── dummy │ ├── log │ │ └── .keep │ ├── app │ │ ├── mailers │ │ │ └── .keep │ │ ├── models │ │ │ ├── .keep │ │ │ └── concerns │ │ │ │ └── .keep │ │ ├── assets │ │ │ ├── images │ │ │ │ └── .keep │ │ │ ├── javascripts │ │ │ │ └── application.js │ │ │ └── stylesheets │ │ │ │ └── application.css │ │ ├── controllers │ │ │ ├── concerns │ │ │ │ └── .keep │ │ │ └── kwargs_controller.rb │ │ ├── helpers │ │ │ └── application_helper.rb │ │ └── views │ │ │ └── layouts │ │ │ └── application.html.erb │ ├── lib │ │ └── assets │ │ │ └── .keep │ ├── public │ │ ├── favicon.ico │ │ ├── 500.html │ │ ├── 422.html │ │ └── 404.html │ ├── bin │ │ ├── bundle │ │ ├── rake │ │ ├── rails │ │ ├── spring │ │ └── setup │ ├── config │ │ ├── boot.rb │ │ ├── initializers │ │ │ ├── cookies_serializer.rb │ │ │ ├── session_store.rb │ │ │ ├── mime_types.rb │ │ │ ├── filter_parameter_logging.rb │ │ │ ├── backtrace_silencers.rb │ │ │ ├── assets.rb │ │ │ ├── to_time_preserves_timezone.rb │ │ │ ├── wrap_parameters.rb │ │ │ └── inflections.rb │ │ ├── environment.rb │ │ ├── database.yml │ │ ├── locales │ │ │ └── en.yml │ │ ├── secrets.yml │ │ ├── application.rb │ │ ├── environments │ │ │ ├── development.rb │ │ │ ├── test.rb │ │ │ └── production.rb │ │ └── routes.rb │ ├── config.ru │ ├── Rakefile │ ├── .gitignore │ └── README.rdoc ├── test_helper.rb ├── integration │ └── kwargs_integration_test.rb └── controllers │ └── kwargs_test.rb ├── .rspec ├── Gemfile ├── lib └── rails │ ├── forward_compatible_controller_tests │ └── version.rb │ └── forward_compatible_controller_tests.rb ├── gemfiles ├── actionpack_4.2.gemfile ├── actionpack_5.0.gemfile ├── actionpack_4.2.gemfile.lock └── actionpack_5.0.gemfile.lock ├── .gitignore ├── bin ├── setup └── console ├── Appraisals ├── Rakefile ├── .github └── dependabot.yaml ├── .circleci └── config.yml ├── spec ├── integration │ └── rspec_integration_spec.rb ├── controllers │ └── rspec_controllers_spec.rb ├── rails_helper.rb └── spec_helper.rb ├── LICENSE.txt ├── rails-forward_compatible_controller_tests.gemspec ├── CHANGELOG.md └── README.md /.ruby-version: -------------------------------------------------------------------------------- 1 | 2.4.0 2 | -------------------------------------------------------------------------------- /test/dummy/log/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/dummy/app/mailers/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/dummy/app/models/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/dummy/lib/assets/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.rspec: -------------------------------------------------------------------------------- 1 | --require spec_helper 2 | -------------------------------------------------------------------------------- /test/dummy/public/favicon.ico: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/dummy/app/assets/images/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/dummy/app/models/concerns/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/dummy/app/controllers/concerns/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/dummy/app/helpers/application_helper.rb: -------------------------------------------------------------------------------- 1 | module ApplicationHelper 2 | end 3 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | # Specify your gem's dependencies in rails-forward_compatible_controller_tests.gemspec 4 | gemspec 5 | -------------------------------------------------------------------------------- /lib/rails/forward_compatible_controller_tests/version.rb: -------------------------------------------------------------------------------- 1 | module Rails 2 | module ForwardCompatibleControllerTests 3 | VERSION = "2.4.0" 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /test/dummy/bin/bundle: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) 3 | load Gem.bin_path('bundler', 'bundle') 4 | -------------------------------------------------------------------------------- /test/dummy/config/boot.rb: -------------------------------------------------------------------------------- 1 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) 2 | 3 | require 'bundler/setup' # Set up gems listed in the Gemfile. 4 | -------------------------------------------------------------------------------- /gemfiles/actionpack_4.2.gemfile: -------------------------------------------------------------------------------- 1 | # This file was generated by Appraisal 2 | 3 | source "https://rubygems.org" 4 | 5 | gem "actionpack", "4.2.10" 6 | 7 | gemspec path: "../" 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.bundle/ 2 | /.yardoc 3 | /Gemfile.lock 4 | /_yardoc/ 5 | /coverage/ 6 | /doc/ 7 | /pkg/ 8 | /spec/reports/ 9 | /tmp/ 10 | 11 | *.gem 12 | gemfiles/.bundle/config 13 | -------------------------------------------------------------------------------- /test/dummy/config.ru: -------------------------------------------------------------------------------- 1 | # This file is used by Rack-based servers to start the application. 2 | 3 | require ::File.expand_path('../config/environment', __FILE__) 4 | run Rails.application 5 | -------------------------------------------------------------------------------- /test/dummy/config/initializers/cookies_serializer.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | Rails.application.config.action_dispatch.cookies_serializer = :json 4 | -------------------------------------------------------------------------------- /test/dummy/config/initializers/session_store.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | Rails.application.config.session_store :cookie_store, key: '_dummy_session' 4 | -------------------------------------------------------------------------------- /bin/setup: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -euo pipefail 3 | IFS=$'\n\t' 4 | set -vx 5 | 6 | bundle install 7 | bundle exec appraisal install 8 | # Do any other automated setup that you need to do here 9 | -------------------------------------------------------------------------------- /test/dummy/config/environment.rb: -------------------------------------------------------------------------------- 1 | # Load the Rails application. 2 | require File.expand_path('../application', __FILE__) 3 | 4 | # Initialize the Rails application. 5 | Rails.application.initialize! 6 | -------------------------------------------------------------------------------- /test/dummy/config/initializers/mime_types.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Add new mime types for use in respond_to blocks: 4 | # Mime::Type.register "text/richtext", :rtf 5 | -------------------------------------------------------------------------------- /Appraisals: -------------------------------------------------------------------------------- 1 | appraise "actionpack-4.2" do 2 | gem "actionpack", "4.2.10" 3 | end 4 | 5 | appraise "actionpack-5.0" do 6 | gem "actionpack", "5.0.7" 7 | gem "rails-controller-testing", "~>1.0" 8 | end 9 | 10 | -------------------------------------------------------------------------------- /gemfiles/actionpack_5.0.gemfile: -------------------------------------------------------------------------------- 1 | # This file was generated by Appraisal 2 | 3 | source "https://rubygems.org" 4 | 5 | gem "actionpack", "5.0.7" 6 | gem "rails-controller-testing", "~>1.0" 7 | 8 | gemspec path: "../" 9 | -------------------------------------------------------------------------------- /test/dummy/config/initializers/filter_parameter_logging.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Configure sensitive parameters which will be filtered from the log file. 4 | Rails.application.config.filter_parameters += [:password] 5 | -------------------------------------------------------------------------------- /test/dummy/bin/rake: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | begin 3 | load File.expand_path('../spring', __FILE__) 4 | rescue LoadError => e 5 | raise unless e.message.include?('spring') 6 | end 7 | require_relative '../config/boot' 8 | require 'rake' 9 | Rake.application.run 10 | -------------------------------------------------------------------------------- /test/dummy/Rakefile: -------------------------------------------------------------------------------- 1 | # Add your own tasks in files placed in lib/tasks ending in .rake, 2 | # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. 3 | 4 | require File.expand_path('../config/application', __FILE__) 5 | 6 | Rails.application.load_tasks 7 | -------------------------------------------------------------------------------- /test/dummy/bin/rails: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | begin 3 | load File.expand_path('../spring', __FILE__) 4 | rescue LoadError => e 5 | raise unless e.message.include?('spring') 6 | end 7 | APP_PATH = File.expand_path('../../config/application', __FILE__) 8 | require_relative '../config/boot' 9 | require 'rails/commands' 10 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require "bundler/gem_tasks" 2 | require "rake/testtask" 3 | require "rspec/core/rake_task" 4 | 5 | Rake::TestTask.new(:test_minitest) do |t| 6 | t.libs << "test" 7 | t.libs << "lib" 8 | t.test_files = FileList['test/**/*_test.rb'] 9 | end 10 | 11 | RSpec::Core::RakeTask.new(:test_rspec) 12 | 13 | task :default => [:test_minitest, :test_rspec] 14 | -------------------------------------------------------------------------------- /test/dummy/app/views/layouts/application.html.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Dummy 5 | <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %> 6 | <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %> 7 | <%= csrf_meta_tags %> 8 | 9 | 10 | 11 | <%= yield %> 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /.github/dependabot.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | version: 2 3 | registries: 4 | ruby-github: 5 | type: rubygems-server 6 | url: https://rubygems.pkg.github.com/appfolio 7 | token: "${{secrets.READ_ONLY_PACKAGES_CCIMU}}" 8 | updates: 9 | - package-ecosystem: bundler 10 | directory: "/" 11 | schedule: 12 | interval: daily 13 | pull-request-branch-name: 14 | separator: "-" 15 | registries: "*" 16 | -------------------------------------------------------------------------------- /bin/console: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | require "bundler/setup" 4 | require "rails/forward_compatible_controller_tests" 5 | 6 | # You can add fixtures and/or initialization code here to make experimenting 7 | # with your gem easier. You can also use a different console, if you like. 8 | 9 | # (If you use this, don't forget to add pry to your Gemfile!) 10 | # require "pry" 11 | # Pry.start 12 | 13 | require "irb" 14 | IRB.start(__FILE__) 15 | -------------------------------------------------------------------------------- /test/dummy/config/initializers/backtrace_silencers.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. 4 | # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } 5 | 6 | # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. 7 | # Rails.backtrace_cleaner.remove_silencers! 8 | -------------------------------------------------------------------------------- /test/dummy/app/controllers/kwargs_controller.rb: -------------------------------------------------------------------------------- 1 | class KwargsController < ActionController::Base 2 | def test_kwargs 3 | @params = params.to_unsafe_h.except('controller', 'action') 4 | @xhr = request.xhr? 5 | @hello_header = request.headers['HTTP_HELLO'] 6 | @flash = flash['flashy'] 7 | @session = session[:sesh] 8 | render json: { params: @params, 9 | xhr: @xhr, 10 | hello_header: @hello_header, 11 | session: @session, 12 | flash: @flash } 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /test/dummy/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files for more about ignoring files. 2 | # 3 | # If you find yourself ignoring temporary files generated by your text editor 4 | # or operating system, you probably want to add a global ignore instead: 5 | # git config --global core.excludesfile '~/.gitignore_global' 6 | 7 | # Ignore bundler config. 8 | /.bundle 9 | 10 | # Ignore the default SQLite database. 11 | /db/*.sqlite3 12 | /db/*.sqlite3-journal 13 | 14 | # Ignore all logfiles and tempfiles. 15 | /log/* 16 | !/log/.keep 17 | /tmp 18 | -------------------------------------------------------------------------------- /test/dummy/config/initializers/assets.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Version of your assets, change this if you want to expire all your assets. 4 | # Rails.application.config.assets.version = '1.0' 5 | 6 | # Add additional assets to the asset load path 7 | # Rails.application.config.assets.paths << Emoji.images_path 8 | 9 | # Precompile additional assets. 10 | # application.js, application.css, and all non-JS/CSS in app/assets folder are already added. 11 | # Rails.application.config.assets.precompile += %w( search.js ) 12 | -------------------------------------------------------------------------------- /.circleci/config.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | jobs: 3 | build: 4 | docker: 5 | - image: circleci/ruby:2.3.3 6 | 7 | working_directory: ~/repo 8 | 9 | steps: 10 | - checkout 11 | 12 | - run: bundle install 13 | 14 | - run: bundle exec appraisal install 15 | 16 | - run: 17 | name: Run test suite with Minitest 18 | command: | 19 | bundle exec appraisal rake test_minitest 20 | 21 | - run: 22 | name: Run test suite with Rspec 23 | command: | 24 | bundle exec appraisal rake test_rspec 25 | -------------------------------------------------------------------------------- /test/dummy/config/initializers/to_time_preserves_timezone.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Preserve the timezone of the receiver when calling to `to_time`. 4 | # Ruby 2.4 will change the behavior of `to_time` to preserve the timezone 5 | # when converting to an instance of `Time` instead of the previous behavior 6 | # of converting to the local system timezone. 7 | # 8 | # Rails 5.0 introduced this config option so that apps made with earlier 9 | # versions of Rails are not affected when upgrading. 10 | ActiveSupport.to_time_preserves_timezone = true 11 | -------------------------------------------------------------------------------- /test/dummy/bin/spring: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | # This file loads spring without using Bundler, in order to be fast. 4 | # It gets overwritten when you run the `spring binstub` command. 5 | 6 | unless defined?(Spring) 7 | require 'rubygems' 8 | require 'bundler' 9 | 10 | lockfile = Bundler::LockfileParser.new(Bundler.default_lockfile.read) 11 | spring = lockfile.specs.detect { |spec| spec.name == "spring" } 12 | if spring 13 | Gem.use_paths Gem.dir, Bundler.bundle_path.to_s, *Gem.path 14 | gem 'spring', spring.version 15 | require 'spring/binstub' 16 | end 17 | end 18 | -------------------------------------------------------------------------------- /test/dummy/config/initializers/wrap_parameters.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # This file contains settings for ActionController::ParamsWrapper which 4 | # is enabled by default. 5 | 6 | # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. 7 | ActiveSupport.on_load(:action_controller) do 8 | wrap_parameters format: [:json] if respond_to?(:wrap_parameters) 9 | end 10 | 11 | # To enable root element in JSON for ActiveRecord objects. 12 | # ActiveSupport.on_load(:active_record) do 13 | # self.include_root_in_json = true 14 | # end 15 | -------------------------------------------------------------------------------- /test/dummy/README.rdoc: -------------------------------------------------------------------------------- 1 | == README 2 | 3 | This README would normally document whatever steps are necessary to get the 4 | application up and running. 5 | 6 | Things you may want to cover: 7 | 8 | * Ruby version 9 | 10 | * System dependencies 11 | 12 | * Configuration 13 | 14 | * Database creation 15 | 16 | * Database initialization 17 | 18 | * How to run the test suite 19 | 20 | * Services (job queues, cache servers, search engines, etc.) 21 | 22 | * Deployment instructions 23 | 24 | * ... 25 | 26 | 27 | Please feel free to use a different markup language if you do not plan to run 28 | rake doc:app. 29 | -------------------------------------------------------------------------------- /test/dummy/config/database.yml: -------------------------------------------------------------------------------- 1 | # SQLite version 3.x 2 | # gem install sqlite3 3 | # 4 | # Ensure the SQLite 3 gem is defined in your Gemfile 5 | # gem 'sqlite3' 6 | # 7 | default: &default 8 | adapter: sqlite3 9 | pool: 5 10 | timeout: 5000 11 | 12 | development: 13 | <<: *default 14 | database: db/development.sqlite3 15 | 16 | # Warning: The database defined as "test" will be erased and 17 | # re-generated from your development database when you run "rake". 18 | # Do not set this db to the same as development or production. 19 | test: 20 | <<: *default 21 | database: db/test.sqlite3 22 | 23 | production: 24 | <<: *default 25 | database: db/production.sqlite3 26 | -------------------------------------------------------------------------------- /test/dummy/config/initializers/inflections.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Add new inflection rules using the following format. Inflections 4 | # are locale specific, and you may define rules for as many different 5 | # locales as you wish. All of these examples are active by default: 6 | # ActiveSupport::Inflector.inflections(:en) do |inflect| 7 | # inflect.plural /^(ox)$/i, '\1en' 8 | # inflect.singular /^(ox)en/i, '\1' 9 | # inflect.irregular 'person', 'people' 10 | # inflect.uncountable %w( fish sheep ) 11 | # end 12 | 13 | # These inflection rules are supported but not enabled by default: 14 | # ActiveSupport::Inflector.inflections(:en) do |inflect| 15 | # inflect.acronym 'RESTful' 16 | # end 17 | -------------------------------------------------------------------------------- /test/dummy/config/locales/en.yml: -------------------------------------------------------------------------------- 1 | # Files in the config/locales directory are used for internationalization 2 | # and are automatically loaded by Rails. If you want to use locales other 3 | # than English, add the necessary files in this directory. 4 | # 5 | # To use the locales, use `I18n.t`: 6 | # 7 | # I18n.t 'hello' 8 | # 9 | # In views, this is aliased to just `t`: 10 | # 11 | # <%= t('hello') %> 12 | # 13 | # To use a different locale, set it with `I18n.locale`: 14 | # 15 | # I18n.locale = :es 16 | # 17 | # This would use the information in config/locales/es.yml. 18 | # 19 | # To learn more, please read the Rails Internationalization guide 20 | # available at http://guides.rubyonrails.org/i18n.html. 21 | 22 | en: 23 | hello: "Hello world" 24 | -------------------------------------------------------------------------------- /spec/integration/rspec_integration_spec.rb: -------------------------------------------------------------------------------- 1 | require "rails_helper" 2 | 3 | # Rspec tests are provided to ensure that the logic handling controller vs request specs 4 | # works with rspec. 5 | # We do this by testing the flash assigns, as this should only be present for controller tests. 6 | # Also see spec/controllers 7 | 8 | RSpec.describe KwargsController, type: :request do 9 | it "handles a rspec test marked as type 'request' as a rails request spec" do 10 | path = "/kwargs/test_kwargs" 11 | params = { params: "params" } 12 | headers = { headers: "session"} 13 | 14 | expect_any_instance_of(ActionDispatch::Integration::Runner).to receive(:get).with(path, params, headers) 15 | 16 | get path, params: params, headers: headers 17 | end 18 | end -------------------------------------------------------------------------------- /test/dummy/app/assets/javascripts/application.js: -------------------------------------------------------------------------------- 1 | // This is a manifest file that'll be compiled into application.js, which will include all the files 2 | // listed below. 3 | // 4 | // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, 5 | // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path. 6 | // 7 | // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the 8 | // compiled file. 9 | // 10 | // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details 11 | // about supported directives. 12 | // 13 | //= require jquery 14 | //= require jquery_ujs 15 | //= require turbolinks 16 | //= require_tree . 17 | -------------------------------------------------------------------------------- /test/dummy/app/assets/stylesheets/application.css: -------------------------------------------------------------------------------- 1 | /* 2 | * This is a manifest file that'll be compiled into application.css, which will include all the files 3 | * listed below. 4 | * 5 | * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets, 6 | * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path. 7 | * 8 | * You're free to add application-wide styles to this file and they'll appear at the bottom of the 9 | * compiled file so the styles you add here take precedence over styles defined in any styles 10 | * defined in the other CSS/SCSS files in this directory. It is generally better to create a new 11 | * file per style scope. 12 | * 13 | *= require_tree . 14 | *= require_self 15 | */ 16 | -------------------------------------------------------------------------------- /spec/controllers/rspec_controllers_spec.rb: -------------------------------------------------------------------------------- 1 | require "rails_helper" 2 | 3 | # Rspec tests are provided to ensure that the logic handling controller vs request specs 4 | # works with rspec. 5 | # We do this by testing the flash assigns, as this should only be present for controller tests. 6 | # Also see spec/integration 7 | 8 | RSpec.describe KwargsController, type: :controller do 9 | it "handles a rspec test marked as type 'controller' as a rails controller spec" do 10 | action = :test_kwargs 11 | params = { params: "params" } 12 | flash = { flash: "flash" } 13 | session = { session: "session"} 14 | 15 | expect_any_instance_of(ActionController::TestCase::Behavior).to receive(:get).with(action, params, session, flash) 16 | 17 | get action, params: params, session: session, flash: flash 18 | end 19 | end -------------------------------------------------------------------------------- /test/test_helper.rb: -------------------------------------------------------------------------------- 1 | # Configure Rails Environment 2 | ENV["RAILS_ENV"] = "test" 3 | 4 | require File.expand_path("../../test/dummy/config/environment.rb", __FILE__) 5 | require "rails/test_help" 6 | require 'rails/forward_compatible_controller_tests' 7 | 8 | # Filter out Minitest backtrace while allowing backtrace from other libraries 9 | # to be shown. 10 | Minitest.backtrace_filter = Minitest::BacktraceFilter.new 11 | 12 | # Use this method when asserting that the library raises exceptions 13 | # When running tests in Rails 5 mode, no exception is raised (instead, Rails prints a deprecation warning) 14 | # Therefore, we don't execute these assertions in Rails 5 mode. 15 | def assert_raise_in_rails_4(exception) 16 | return unless ActionPack.gem_version < Gem::Version.new('5.0.0') 17 | 18 | assert_raise exception do 19 | yield 20 | end 21 | end -------------------------------------------------------------------------------- /test/dummy/bin/setup: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require 'pathname' 3 | 4 | # path to your application root. 5 | APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) 6 | 7 | Dir.chdir APP_ROOT do 8 | # This script is a starting point to setup your application. 9 | # Add necessary setup steps to this file: 10 | 11 | puts "== Installing dependencies ==" 12 | system "gem install bundler --conservative" 13 | system "bundle check || bundle install" 14 | 15 | # puts "\n== Copying sample files ==" 16 | # unless File.exist?("config/database.yml") 17 | # system "cp config/database.yml.sample config/database.yml" 18 | # end 19 | 20 | puts "\n== Preparing database ==" 21 | system "bin/rake db:setup" 22 | 23 | puts "\n== Removing old logs and tempfiles ==" 24 | system "rm -f log/*" 25 | system "rm -rf tmp/cache" 26 | 27 | puts "\n== Restarting application server ==" 28 | system "touch tmp/restart.txt" 29 | end 30 | -------------------------------------------------------------------------------- /test/dummy/config/secrets.yml: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Your secret key is used for verifying the integrity of signed cookies. 4 | # If you change this key, all old signed cookies will become invalid! 5 | 6 | # Make sure the secret is at least 30 characters and all random, 7 | # no regular words or you'll be exposed to dictionary attacks. 8 | # You can use `rake secret` to generate a secure secret key. 9 | 10 | # Make sure the secrets in this file are kept private 11 | # if you're sharing your code publicly. 12 | 13 | development: 14 | secret_key_base: 2d5bffe3dbbcb40824ad1a98c183588ca73e1b5ffba75eef2b16b4763f377fb80531078a193fb14c95221959d0861ba65b2b97938f230d7a2ac510d98605f853 15 | 16 | test: 17 | secret_key_base: b660956f576c37e988af6ebcb90e623e2b1c70233b8395d5b3669c31647049c236ab11fdb4ec251706e9fe914ceb9c29c5698ca448c68cfd887c3d419f30d63b 18 | 19 | # Do not keep production secrets in the repository, 20 | # instead read values from the environment. 21 | production: 22 | secret_key_base: <%= ENV["SECRET_KEY_BASE"] %> 23 | -------------------------------------------------------------------------------- /test/dummy/config/application.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path('../boot', __FILE__) 2 | 3 | require 'rails/all' 4 | 5 | # Require the gems listed in Gemfile, including any gems 6 | # you've limited to :test, :development, or :production. 7 | Bundler.require(*Rails.groups) 8 | 9 | module Dummy 10 | class Application < Rails::Application 11 | # Settings in config/environments/* take precedence over those specified here. 12 | # Application configuration should go into files in config/initializers 13 | # -- all .rb files in that directory are automatically loaded. 14 | 15 | # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. 16 | # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. 17 | # config.time_zone = 'Central Time (US & Canada)' 18 | 19 | # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. 20 | # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] 21 | # config.i18n.default_locale = :de 22 | end 23 | end 24 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2017 AppFolio, Inc. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /rails-forward_compatible_controller_tests.gemspec: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | lib = File.expand_path('../lib', __FILE__) 3 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) 4 | require 'rails/forward_compatible_controller_tests/version' 5 | 6 | Gem::Specification.new do |spec| 7 | spec.name = "rails-forward_compatible_controller_tests" 8 | spec.version = Rails::ForwardCompatibleControllerTests::VERSION 9 | spec.authors = ["Chad Shaffer"] 10 | spec.email = ["chad.shaffer@mycase.com"] 11 | 12 | spec.summary = %q{Back-porting Rails 5 controller & integration tests into Rails 4} 13 | spec.description = %q{Makes upgrading to Rails 5 from Rails 4 easier} 14 | spec.homepage = "https://github.com/appfolio/rails-forward_compatible_controller_tests" 15 | spec.license = "MIT" 16 | 17 | spec.files = Dir["{lib}/**/*", "LICENSE.txt", "Rakefile", "README.md"] 18 | spec.require_paths = ["lib"] 19 | 20 | spec.add_development_dependency "bundler", "~> 1.14" 21 | spec.add_development_dependency "rake", "~> 10.0" 22 | spec.add_development_dependency "minitest", "~> 5.0" 23 | spec.add_development_dependency "railties", ">= 4.2", "< 5.1" 24 | spec.add_development_dependency "rspec-rails", "3.8.0" 25 | spec.add_development_dependency "appraisal", "2.2.0" 26 | 27 | spec.add_dependency "actionpack", ">= 4.2", "< 5.1" 28 | end 29 | -------------------------------------------------------------------------------- /test/dummy/config/environments/development.rb: -------------------------------------------------------------------------------- 1 | Rails.application.configure do 2 | # Settings specified here will take precedence over those in config/application.rb. 3 | 4 | # In the development environment your application's code is reloaded on 5 | # every request. This slows down response time but is perfect for development 6 | # since you don't have to restart the web server when you make code changes. 7 | config.cache_classes = false 8 | 9 | # Do not eager load code on boot. 10 | config.eager_load = false 11 | 12 | # Show full error reports and disable caching. 13 | config.consider_all_requests_local = true 14 | config.action_controller.perform_caching = false 15 | 16 | # Print deprecation notices to the Rails logger. 17 | config.active_support.deprecation = :log 18 | 19 | # Debug mode disables concatenation and preprocessing of assets. 20 | # This option may cause significant delays in view rendering with a large 21 | # number of complex assets. 22 | config.assets.debug = true 23 | 24 | # Asset digests allow you to set far-future HTTP expiration dates on all assets, 25 | # yet still be able to expire them through the digest params. 26 | config.assets.digest = true 27 | 28 | # Adds additional error checking when serving assets at runtime. 29 | # Checks for improperly declared sprockets dependencies. 30 | # Raises helpful error messages. 31 | config.assets.raise_runtime_errors = true 32 | 33 | # Raises error for missing translations 34 | # config.action_view.raise_on_missing_translations = true 35 | end 36 | -------------------------------------------------------------------------------- /test/dummy/config/environments/test.rb: -------------------------------------------------------------------------------- 1 | Rails.application.configure do 2 | # Settings specified here will take precedence over those in config/application.rb. 3 | 4 | # The test environment is used exclusively to run your application's 5 | # test suite. You never need to work with it otherwise. Remember that 6 | # your test database is "scratch space" for the test suite and is wiped 7 | # and recreated between test runs. Don't rely on the data there! 8 | config.cache_classes = true 9 | 10 | # Do not eager load code on boot. This avoids loading your whole application 11 | # just for the purpose of running a single test. If you are using a tool that 12 | # preloads Rails for running tests, you may have to set it to true. 13 | config.eager_load = false 14 | 15 | # Configure static file server for tests with Cache-Control for performance. 16 | config.serve_static_files = true 17 | config.static_cache_control = 'public, max-age=3600' 18 | 19 | # Show full error reports and disable caching. 20 | config.consider_all_requests_local = true 21 | config.action_controller.perform_caching = false 22 | 23 | # Raise exceptions instead of rendering exception templates. 24 | config.action_dispatch.show_exceptions = false 25 | 26 | # Disable request forgery protection in test environment. 27 | config.action_controller.allow_forgery_protection = false 28 | 29 | # Randomize the order test cases are executed. 30 | config.active_support.test_order = :random 31 | 32 | # Print deprecation notices to the stderr. 33 | config.active_support.deprecation = :stderr 34 | 35 | # Raises error for missing translations 36 | # config.action_view.raise_on_missing_translations = true 37 | end 38 | -------------------------------------------------------------------------------- /test/dummy/public/500.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | We're sorry, but something went wrong (500) 5 | 6 | 55 | 56 | 57 | 58 | 59 |
60 |
61 |

We're sorry, but something went wrong.

62 |
63 |

If you are the application owner check the logs for more information.

64 |
65 | 66 | 67 | -------------------------------------------------------------------------------- /test/dummy/public/422.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | The change you wanted was rejected (422) 5 | 6 | 55 | 56 | 57 | 58 | 59 |
60 |
61 |

The change you wanted was rejected.

62 |

Maybe you tried to change something you didn't have access to.

63 |
64 |

If you are the application owner check the logs for more information.

65 |
66 | 67 | 68 | -------------------------------------------------------------------------------- /test/dummy/public/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | The page you were looking for doesn't exist (404) 5 | 6 | 55 | 56 | 57 | 58 | 59 |
60 |
61 |

The page you were looking for doesn't exist.

62 |

You may have mistyped the address or the page may have moved.

63 |
64 |

If you are the application owner check the logs for more information.

65 |
66 | 67 | 68 | -------------------------------------------------------------------------------- /test/dummy/config/routes.rb: -------------------------------------------------------------------------------- 1 | Rails.application.routes.draw do 2 | get ':controller(/:action)' 3 | post ':controller(/:action)' 4 | put ':controller(/:action)' 5 | patch ':controller(/:action)' 6 | delete ':controller(/:action)' 7 | # The priority is based upon order of creation: first created -> highest priority. 8 | # See how all your routes lay out with "rake routes". 9 | 10 | # You can have the root of your site routed with "root" 11 | # root 'welcome#index' 12 | 13 | # Example of regular route: 14 | # get 'products/:id' => 'catalog#view' 15 | 16 | # Example of named route that can be invoked with purchase_url(id: product.id) 17 | # get 'products/:id/purchase' => 'catalog#purchase', as: :purchase 18 | 19 | # Example resource route (maps HTTP verbs to controller actions automatically): 20 | # resources :products 21 | 22 | # Example resource route with options: 23 | # resources :products do 24 | # member do 25 | # get 'short' 26 | # post 'toggle' 27 | # end 28 | # 29 | # collection do 30 | # get 'sold' 31 | # end 32 | # end 33 | 34 | # Example resource route with sub-resources: 35 | # resources :products do 36 | # resources :comments, :sales 37 | # resource :seller 38 | # end 39 | 40 | # Example resource route with more complex sub-resources: 41 | # resources :products do 42 | # resources :comments 43 | # resources :sales do 44 | # get 'recent', on: :collection 45 | # end 46 | # end 47 | 48 | # Example resource route with concerns: 49 | # concern :toggleable do 50 | # post 'toggle' 51 | # end 52 | # resources :posts, concerns: :toggleable 53 | # resources :photos, concerns: :toggleable 54 | 55 | # Example resource route within a namespace: 56 | # namespace :admin do 57 | # # Directs /admin/products/* to Admin::ProductsController 58 | # # (app/controllers/admin/products_controller.rb) 59 | # resources :products 60 | # end 61 | end 62 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## [Unreleased] 4 | 5 | ## [2.4.0] - 2018-12-17 6 | 7 | ### Added 8 | 9 | - Support rspec specs 10 | 11 | - Support string params for integration tests 12 | 13 | ## [2.3.2] - 2018-06-20 14 | 15 | ### Fixed 16 | 17 | - Fix bug with eplicitly provided keyword argument `params` named 18 | `session`, `headers`, and `flash` in XHR requests. 19 | 20 | ## [2.3.1] - 2018-06-19 21 | 22 | ### Fixed 23 | 24 | - Add support for explicitly provided keyword argument `params` named 25 | `session`, `headers`, and `flash`. 26 | 27 | ## [2.3.0] - 2018-06-18 28 | 29 | ### Added 30 | 31 | - Adds support for `format` in controller tests 32 | 33 | ## [2.2.0] - 2018-06-03 34 | 35 | ### Added 36 | 37 | - Adds support for `flash` and `session` in controller tests 38 | 39 | ### Fixed 40 | 41 | - Fixes issue where `headers` was incorrectly treated as a special keyword argument in controller tests 42 | 43 | ## [2.1.0] - 2018-04-30 44 | 45 | - Allow inclusion of the gem in Rails 5. In which case the gem does nothing. 46 | 47 | ## [2.0.1] - 2017-08-10 48 | 49 | ### Fixed 50 | 51 | - Raise exception with the proper message when calling `xhr` with 52 | `raise_exception` enabled. 53 | 54 | ## [2.0.0] - 2017-08-09 55 | 56 | - Rename gem from Controller::Testing::Kwargs to Rails::ForwardCompatibleControllerTests 57 | 58 | ## [1.0.3] - 2017-08-09 59 | 60 | ### Fixed 61 | 62 | - Fix issue where deprecation warnings are output when using the new syntax with nil headers or 63 | params 64 | 65 | ## [1.0.2] - 2017-08-09 66 | 67 | ### Fixed 68 | 69 | - Output deprecation warnings by default -- this should have been the case previously 70 | but a typo prevented it from being so 71 | 72 | 73 | ## [1.0.1] - 2017-08-08 74 | 75 | ### Fixed 76 | 77 | - Fix issue where deprecation warnings are output when using the new syntax 78 | 79 | 80 | ## [1.0.0] - 2017-08-08 81 | 82 | ### Added 83 | 84 | - Deprecation warnings can be output when using the old syntax by calling 85 | `Controller::Testing::Kwargs.deprecate` 86 | - Exceptions can be raised when using the old syntax by calling 87 | `Controller::Testing::Kwargs.raise_exception` 88 | 89 | 90 | ## [0.1.0] - 2017-06-03 91 | 92 | Initial Release 93 | -------------------------------------------------------------------------------- /spec/rails_helper.rb: -------------------------------------------------------------------------------- 1 | # This file is copied to spec/ when you run 'rails generate rspec:install' 2 | require 'spec_helper' 3 | ENV['RAILS_ENV'] ||= 'test' 4 | require File.expand_path('../../test/dummy/config/environment', __FILE__) 5 | # Prevent database truncation if the environment is production 6 | abort("The Rails environment is running in production mode!") if Rails.env.production? 7 | require 'rspec/rails' 8 | # Add additional requires below this line. Rails is not loaded until this point! 9 | 10 | # Requires supporting ruby files with custom matchers and macros, etc, in 11 | # spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are 12 | # run as spec files by default. This means that files in spec/support that end 13 | # in _spec.rb will both be required and run as specs, causing the specs to be 14 | # run twice. It is recommended that you do not name files matching this glob to 15 | # end with _spec.rb. You can configure this pattern with the --pattern 16 | # option on the command line or in ~/.rspec, .rspec or `.rspec-local`. 17 | # 18 | # The following line is provided for convenience purposes. It has the downside 19 | # of increasing the boot-up time by auto-requiring all files in the support 20 | # directory. Alternatively, in the individual `*_spec.rb` files, manually 21 | # require only the support files necessary. 22 | # 23 | # Dir[Rails.root.join('spec', 'support', '**', '*.rb')].each { |f| require f } 24 | 25 | require 'rails/forward_compatible_controller_tests' 26 | 27 | RSpec.configure do |config| 28 | # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures 29 | config.fixture_path = "#{::Rails.root}/spec/fixtures" 30 | 31 | config.include Rails::ForwardCompatibleControllerTests, type: :controller 32 | config.include Rails::ForwardCompatibleControllerTests, type: :request 33 | 34 | # If you're not using ActiveRecord, or you'd prefer not to run each of your 35 | # examples within a transaction, remove the following line or assign false 36 | # instead of true. 37 | config.use_transactional_fixtures = true 38 | 39 | # RSpec Rails can automatically mix in different behaviours to your tests 40 | # based on their file location, for example enabling you to call `get` and 41 | # `post` in specs under `spec/controllers`. 42 | # 43 | # You can disable this behaviour by removing the line below, and instead 44 | # explicitly tag your specs with their type, e.g.: 45 | # 46 | # RSpec.describe UsersController, :type => :controller do 47 | # # ... 48 | # end 49 | # 50 | # The different available types are documented in the features, such as in 51 | # https://relishapp.com/rspec/rspec-rails/docs 52 | config.infer_spec_type_from_file_location! 53 | 54 | # Filter lines from Rails gems in backtraces. 55 | config.filter_rails_from_backtrace! 56 | # arbitrary gems may also be filtered via: 57 | # config.filter_gems_from_backtrace("gem name") 58 | end 59 | -------------------------------------------------------------------------------- /gemfiles/actionpack_4.2.gemfile.lock: -------------------------------------------------------------------------------- 1 | PATH 2 | remote: .. 3 | specs: 4 | rails-forward_compatible_controller_tests (2.3.2) 5 | actionpack (>= 4.2, < 5.1) 6 | 7 | GEM 8 | remote: https://rubygems.org/ 9 | specs: 10 | actionpack (4.2.10) 11 | actionview (= 4.2.10) 12 | activesupport (= 4.2.10) 13 | rack (~> 1.6) 14 | rack-test (~> 0.6.2) 15 | rails-dom-testing (~> 1.0, >= 1.0.5) 16 | rails-html-sanitizer (~> 1.0, >= 1.0.2) 17 | actionview (4.2.10) 18 | activesupport (= 4.2.10) 19 | builder (~> 3.1) 20 | erubis (~> 2.7.0) 21 | rails-dom-testing (~> 1.0, >= 1.0.5) 22 | rails-html-sanitizer (~> 1.0, >= 1.0.3) 23 | activesupport (4.2.10) 24 | i18n (~> 0.7) 25 | minitest (~> 5.1) 26 | thread_safe (~> 0.3, >= 0.3.4) 27 | tzinfo (~> 1.1) 28 | appraisal (2.2.0) 29 | bundler 30 | rake 31 | thor (>= 0.14.0) 32 | builder (3.2.3) 33 | concurrent-ruby (1.0.5) 34 | crass (1.0.4) 35 | diff-lcs (1.3) 36 | erubis (2.7.0) 37 | i18n (0.9.5) 38 | concurrent-ruby (~> 1.0) 39 | loofah (2.2.2) 40 | crass (~> 1.0.2) 41 | nokogiri (>= 1.5.9) 42 | mini_portile2 (2.3.0) 43 | minitest (5.11.3) 44 | nokogiri (1.8.2) 45 | mini_portile2 (~> 2.3.0) 46 | rack (1.6.10) 47 | rack-test (0.6.3) 48 | rack (>= 1.0) 49 | rails-deprecated_sanitizer (1.0.3) 50 | activesupport (>= 4.2.0.alpha) 51 | rails-dom-testing (1.0.9) 52 | activesupport (>= 4.2.0, < 5.0) 53 | nokogiri (~> 1.6) 54 | rails-deprecated_sanitizer (>= 1.0.1) 55 | rails-html-sanitizer (1.0.4) 56 | loofah (~> 2.2, >= 2.2.2) 57 | railties (4.2.10) 58 | actionpack (= 4.2.10) 59 | activesupport (= 4.2.10) 60 | rake (>= 0.8.7) 61 | thor (>= 0.18.1, < 2.0) 62 | rake (10.5.0) 63 | rspec-core (3.8.0) 64 | rspec-support (~> 3.8.0) 65 | rspec-expectations (3.8.2) 66 | diff-lcs (>= 1.2.0, < 2.0) 67 | rspec-support (~> 3.8.0) 68 | rspec-mocks (3.8.0) 69 | diff-lcs (>= 1.2.0, < 2.0) 70 | rspec-support (~> 3.8.0) 71 | rspec-rails (3.8.0) 72 | actionpack (>= 3.0) 73 | activesupport (>= 3.0) 74 | railties (>= 3.0) 75 | rspec-core (~> 3.8.0) 76 | rspec-expectations (~> 3.8.0) 77 | rspec-mocks (~> 3.8.0) 78 | rspec-support (~> 3.8.0) 79 | rspec-support (3.8.0) 80 | thor (0.20.0) 81 | thread_safe (0.3.6) 82 | tzinfo (1.2.5) 83 | thread_safe (~> 0.1) 84 | 85 | PLATFORMS 86 | ruby 87 | 88 | DEPENDENCIES 89 | actionpack (= 4.2.10) 90 | appraisal (= 2.2.0) 91 | bundler (~> 1.14) 92 | minitest (~> 5.0) 93 | rails-forward_compatible_controller_tests! 94 | railties (>= 4.2, < 5.1) 95 | rake (~> 10.0) 96 | rspec-rails (= 3.8.0) 97 | 98 | BUNDLED WITH 99 | 1.16.5 100 | -------------------------------------------------------------------------------- /gemfiles/actionpack_5.0.gemfile.lock: -------------------------------------------------------------------------------- 1 | PATH 2 | remote: .. 3 | specs: 4 | rails-forward_compatible_controller_tests (2.3.2) 5 | actionpack (>= 4.2, < 5.1) 6 | 7 | GEM 8 | remote: https://rubygems.org/ 9 | specs: 10 | actionpack (5.0.7) 11 | actionview (= 5.0.7) 12 | activesupport (= 5.0.7) 13 | rack (~> 2.0) 14 | rack-test (~> 0.6.3) 15 | rails-dom-testing (~> 2.0) 16 | rails-html-sanitizer (~> 1.0, >= 1.0.2) 17 | actionview (5.0.7) 18 | activesupport (= 5.0.7) 19 | builder (~> 3.1) 20 | erubis (~> 2.7.0) 21 | rails-dom-testing (~> 2.0) 22 | rails-html-sanitizer (~> 1.0, >= 1.0.3) 23 | activesupport (5.0.7) 24 | concurrent-ruby (~> 1.0, >= 1.0.2) 25 | i18n (>= 0.7, < 2) 26 | minitest (~> 5.1) 27 | tzinfo (~> 1.1) 28 | appraisal (2.2.0) 29 | bundler 30 | rake 31 | thor (>= 0.14.0) 32 | builder (3.2.3) 33 | concurrent-ruby (1.0.5) 34 | crass (1.0.4) 35 | diff-lcs (1.3) 36 | erubis (2.7.0) 37 | i18n (1.0.1) 38 | concurrent-ruby (~> 1.0) 39 | loofah (2.2.2) 40 | crass (~> 1.0.2) 41 | nokogiri (>= 1.5.9) 42 | method_source (0.9.0) 43 | mini_portile2 (2.3.0) 44 | minitest (5.11.3) 45 | nokogiri (1.8.2) 46 | mini_portile2 (~> 2.3.0) 47 | rack (2.0.5) 48 | rack-test (0.6.3) 49 | rack (>= 1.0) 50 | rails-controller-testing (1.0.4) 51 | actionpack (>= 5.0.1.x) 52 | actionview (>= 5.0.1.x) 53 | activesupport (>= 5.0.1.x) 54 | rails-dom-testing (2.0.3) 55 | activesupport (>= 4.2.0) 56 | nokogiri (>= 1.6) 57 | rails-html-sanitizer (1.0.4) 58 | loofah (~> 2.2, >= 2.2.2) 59 | railties (5.0.7) 60 | actionpack (= 5.0.7) 61 | activesupport (= 5.0.7) 62 | method_source 63 | rake (>= 0.8.7) 64 | thor (>= 0.18.1, < 2.0) 65 | rake (10.5.0) 66 | rspec-core (3.8.0) 67 | rspec-support (~> 3.8.0) 68 | rspec-expectations (3.8.2) 69 | diff-lcs (>= 1.2.0, < 2.0) 70 | rspec-support (~> 3.8.0) 71 | rspec-mocks (3.8.0) 72 | diff-lcs (>= 1.2.0, < 2.0) 73 | rspec-support (~> 3.8.0) 74 | rspec-rails (3.8.0) 75 | actionpack (>= 3.0) 76 | activesupport (>= 3.0) 77 | railties (>= 3.0) 78 | rspec-core (~> 3.8.0) 79 | rspec-expectations (~> 3.8.0) 80 | rspec-mocks (~> 3.8.0) 81 | rspec-support (~> 3.8.0) 82 | rspec-support (3.8.0) 83 | thor (0.20.0) 84 | thread_safe (0.3.6) 85 | tzinfo (1.2.5) 86 | thread_safe (~> 0.1) 87 | 88 | PLATFORMS 89 | ruby 90 | 91 | DEPENDENCIES 92 | actionpack (= 5.0.7) 93 | appraisal (= 2.2.0) 94 | bundler (~> 1.14) 95 | minitest (~> 5.0) 96 | rails-controller-testing (~> 1.0) 97 | rails-forward_compatible_controller_tests! 98 | railties (>= 4.2, < 5.1) 99 | rake (~> 10.0) 100 | rspec-rails (= 3.8.0) 101 | 102 | BUNDLED WITH 103 | 1.16.1 104 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Rails::ForwardCompatibleControllerTests 2 | 3 | Backport Rails 5 style controller/integration testing syntax using kwargs to Rails 4. Supports minitest and rspec. 4 | 5 | ## Installation 6 | 7 | Add this line to your application's Gemfile: 8 | 9 | ```ruby 10 | gem 'rails-forward_compatible_controller_tests', require: false 11 | ``` 12 | 13 | And then execute: 14 | 15 | $ bundle 16 | 17 | Or install it yourself as: 18 | 19 | $ gem install rails-forward_compatible_controller_tests 20 | 21 | At the appropriate spot in your `test_helper.rb`, `spec_helper.rb`, or similar file add the following line: 22 | 23 | ```ruby 24 | require 'rails/forward_compatible_controller_tests' 25 | ``` 26 | 27 | If using rspec, add the following lines to your rspec config: 28 | 29 | ```ruby 30 | config.include Rails::ForwardCompatibleControllerTests, type: :controller 31 | config.include Rails::ForwardCompatibleControllerTests, type: :request 32 | ``` 33 | 34 | ## Usage 35 | 36 | Allows you to simultaneously use the old and new syntax while making HTTP calls to your controllers 37 | in your test suite. So both: 38 | 39 | ```ruby 40 | get #{url_or_action}, params, headers 41 | xhr :post, #{url_or_action}, params, headers 42 | ``` 43 | 44 | and 45 | 46 | ```ruby 47 | get #{url_or_action}, params: params, headers: headers 48 | get #{url_or_action}, xhr: true, params: params, headers: headers 49 | ``` 50 | 51 | should work while you transition your test suite. 52 | 53 | ## Modes of Operation 54 | 55 | Deprecation warnings will appear by default when executing statements that 56 | utilize the old method. Deprecation warnings can be disabled by adding the 57 | following to your appropriate test helper: 58 | 59 | ```ruby 60 | Rails::ForwardCompatibleControllerTests.ignore 61 | ``` 62 | 63 | The above is useful if you simply want to support the Rails 5 syntax. If 64 | instead you want to prevent new uses of the old syntax, add the following: 65 | 66 | ```ruby 67 | Rails::ForwardCompatibleControllerTests.raise_exception 68 | ``` 69 | 70 | The above is useful when you're done coverting the syntax but are not yet ready 71 | to make the switch to Rails 5. 72 | 73 | ## Development 74 | 75 | After checking out the repo, run `bin/setup` to install dependencies. 76 | 77 | This library uses [Appraisal](https://github.com/thoughtbot/appraisal) to run specs in Rails 4 and 5: 78 | - `bundle exec appraisal actionpack-4.2 rake`. 79 | - `bundle exec appraisal actionpack-5.0 rake`. 80 | 81 | The library is a no-op when used with Rails 5 (it doesn't affect the implementation of controller tests). You can run the tests in Rails 5 mode to ensure that the behaviour native to Rails 5 is the same as the behaviour in Rails 4 with the library. 82 | 83 | You can also run `bin/console` for an interactive prompt that will allow you to experiment. 84 | 85 | To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org). 86 | 87 | ## Contributing 88 | 89 | Bug reports and pull requests are welcome on GitHub at https://github.com/appfolio/rails-forward_compatible_controller_tests. 90 | 91 | ## License 92 | 93 | The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT). 94 | 95 | -------------------------------------------------------------------------------- /test/dummy/config/environments/production.rb: -------------------------------------------------------------------------------- 1 | Rails.application.configure do 2 | # Settings specified here will take precedence over those in config/application.rb. 3 | 4 | # Code is not reloaded between requests. 5 | config.cache_classes = true 6 | 7 | # Eager load code on boot. This eager loads most of Rails and 8 | # your application in memory, allowing both threaded web servers 9 | # and those relying on copy on write to perform better. 10 | # Rake tasks automatically ignore this option for performance. 11 | config.eager_load = true 12 | 13 | # Full error reports are disabled and caching is turned on. 14 | config.consider_all_requests_local = false 15 | config.action_controller.perform_caching = true 16 | 17 | # Enable Rack::Cache to put a simple HTTP cache in front of your application 18 | # Add `rack-cache` to your Gemfile before enabling this. 19 | # For large-scale production use, consider using a caching reverse proxy like 20 | # NGINX, varnish or squid. 21 | # config.action_dispatch.rack_cache = true 22 | 23 | # Disable serving static files from the `/public` folder by default since 24 | # Apache or NGINX already handles this. 25 | config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present? 26 | 27 | # Compress JavaScripts and CSS. 28 | config.assets.js_compressor = :uglifier 29 | # config.assets.css_compressor = :sass 30 | 31 | # Do not fallback to assets pipeline if a precompiled asset is missed. 32 | config.assets.compile = false 33 | 34 | # Asset digests allow you to set far-future HTTP expiration dates on all assets, 35 | # yet still be able to expire them through the digest params. 36 | config.assets.digest = true 37 | 38 | # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb 39 | 40 | # Specifies the header that your server uses for sending files. 41 | # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache 42 | # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX 43 | 44 | # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. 45 | # config.force_ssl = true 46 | 47 | # Use the lowest log level to ensure availability of diagnostic information 48 | # when problems arise. 49 | config.log_level = :debug 50 | 51 | # Prepend all log lines with the following tags. 52 | # config.log_tags = [ :subdomain, :uuid ] 53 | 54 | # Use a different logger for distributed setups. 55 | # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new) 56 | 57 | # Use a different cache store in production. 58 | # config.cache_store = :mem_cache_store 59 | 60 | # Enable serving of images, stylesheets, and JavaScripts from an asset server. 61 | # config.action_controller.asset_host = 'http://assets.example.com' 62 | 63 | # Ignore bad email addresses and do not raise email delivery errors. 64 | # Set this to true and configure the email server for immediate delivery to raise delivery errors. 65 | # config.action_mailer.raise_delivery_errors = false 66 | 67 | # Enable locale fallbacks for I18n (makes lookups for any locale fall back to 68 | # the I18n.default_locale when a translation cannot be found). 69 | config.i18n.fallbacks = true 70 | 71 | # Send deprecation notices to registered listeners. 72 | config.active_support.deprecation = :notify 73 | 74 | # Use default logging formatter so that PID and timestamp are not suppressed. 75 | config.log_formatter = ::Logger::Formatter.new 76 | 77 | # Do not dump schema after migrations. 78 | config.active_record.dump_schema_after_migration = false 79 | end 80 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | # This file was generated by the `rails generate rspec:install` command. Conventionally, all 2 | # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. 3 | # The generated `.rspec` file contains `--require spec_helper` which will cause 4 | # this file to always be loaded, without a need to explicitly require it in any 5 | # files. 6 | # 7 | # Given that it is always loaded, you are encouraged to keep this file as 8 | # light-weight as possible. Requiring heavyweight dependencies from this file 9 | # will add to the boot time of your test suite on EVERY test run, even for an 10 | # individual file that may not need all of that loaded. Instead, consider making 11 | # a separate helper file that requires the additional dependencies and performs 12 | # the additional setup, and require it from the spec files that actually need 13 | # it. 14 | # 15 | # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration 16 | RSpec.configure do |config| 17 | # rspec-expectations config goes here. You can use an alternate 18 | # assertion/expectation library such as wrong or the stdlib/minitest 19 | # assertions if you prefer. 20 | config.expect_with :rspec do |expectations| 21 | # This option will default to `true` in RSpec 4. It makes the `description` 22 | # and `failure_message` of custom matchers include text for helper methods 23 | # defined using `chain`, e.g.: 24 | # be_bigger_than(2).and_smaller_than(4).description 25 | # # => "be bigger than 2 and smaller than 4" 26 | # ...rather than: 27 | # # => "be bigger than 2" 28 | expectations.include_chain_clauses_in_custom_matcher_descriptions = true 29 | end 30 | 31 | # rspec-mocks config goes here. You can use an alternate test double 32 | # library (such as bogus or mocha) by changing the `mock_with` option here. 33 | config.mock_with :rspec do |mocks| 34 | # Prevents you from mocking or stubbing a method that does not exist on 35 | # a real object. This is generally recommended, and will default to 36 | # `true` in RSpec 4. 37 | mocks.verify_partial_doubles = true 38 | end 39 | 40 | # This option will default to `:apply_to_host_groups` in RSpec 4 (and will 41 | # have no way to turn it off -- the option exists only for backwards 42 | # compatibility in RSpec 3). It causes shared context metadata to be 43 | # inherited by the metadata hash of host groups and examples, rather than 44 | # triggering implicit auto-inclusion in groups with matching metadata. 45 | config.shared_context_metadata_behavior = :apply_to_host_groups 46 | 47 | # The settings below are suggested to provide a good initial experience 48 | # with RSpec, but feel free to customize to your heart's content. 49 | =begin 50 | # This allows you to limit a spec run to individual examples or groups 51 | # you care about by tagging them with `:focus` metadata. When nothing 52 | # is tagged with `:focus`, all examples get run. RSpec also provides 53 | # aliases for `it`, `describe`, and `context` that include `:focus` 54 | # metadata: `fit`, `fdescribe` and `fcontext`, respectively. 55 | config.filter_run_when_matching :focus 56 | 57 | # Allows RSpec to persist some state between runs in order to support 58 | # the `--only-failures` and `--next-failure` CLI options. We recommend 59 | # you configure your source control system to ignore this file. 60 | config.example_status_persistence_file_path = "spec/examples.txt" 61 | 62 | # Limits the available syntax to the non-monkey patched syntax that is 63 | # recommended. For more details, see: 64 | # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/ 65 | # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ 66 | # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode 67 | config.disable_monkey_patching! 68 | 69 | # Many RSpec users commonly either run the entire suite or an individual 70 | # file, and it's useful to allow more verbose output when running an 71 | # individual spec file. 72 | if config.files_to_run.one? 73 | # Use the documentation formatter for detailed output, 74 | # unless a formatter has already been configured 75 | # (e.g. via a command-line flag). 76 | config.default_formatter = "doc" 77 | end 78 | 79 | # Print the 10 slowest examples and example groups at the 80 | # end of the spec run, to help surface which specs are running 81 | # particularly slow. 82 | config.profile_examples = 10 83 | 84 | # Run specs in random order to surface order dependencies. If you find an 85 | # order dependency and want to debug it, you can fix the order by providing 86 | # the seed, which is printed after each run. 87 | # --seed 1234 88 | config.order = :random 89 | 90 | # Seed global randomization in this process using the `--seed` CLI option. 91 | # Setting this allows you to use `--seed` to deterministically reproduce 92 | # test failures related to randomization by passing the same `--seed` value 93 | # as the one that triggered the failure. 94 | Kernel.srand config.seed 95 | =end 96 | end -------------------------------------------------------------------------------- /lib/rails/forward_compatible_controller_tests.rb: -------------------------------------------------------------------------------- 1 | require "rails/forward_compatible_controller_tests/version" 2 | 3 | module Rails 4 | module ForwardCompatibleControllerTests 5 | ERROR_MESSAGE = 'Please use Rails 5 syntax. See: https://github.com/appfolio/rails-forward_compatible_controller_tests' 6 | 7 | class < 0 14 | response = JSON.parse(@response.body) 15 | assert_equal({ 'hello' => 'world' }, response['params']) 16 | assert_nil response['hello_header'] 17 | refute response['xhr'] 18 | else 19 | assert_equal 'head', verb 20 | end 21 | end 22 | 23 | define_method("test_#{verb}_old_params_only__raises_exception") do 24 | assert_raise_in_rails_4(Exception) do 25 | send(verb.to_sym, '/kwargs/test_kwargs', hello: 'world') 26 | end 27 | end 28 | 29 | define_method("test_#{verb}_new_params_only") do 30 | send(verb.to_sym, '/kwargs/test_kwargs', params: { hello: 'world' }) 31 | if @response.body.size > 0 32 | response = JSON.parse(@response.body) 33 | assert_equal({ 'hello' => 'world' }, response['params']) 34 | assert_nil response['hello_header'] 35 | refute response['xhr'] 36 | else 37 | assert_equal 'head', verb 38 | end 39 | end 40 | 41 | define_method("test_#{verb}_new_string_params_only") do 42 | send(verb.to_sym, '/kwargs/test_kwargs', params: "string_params") 43 | if @response.body.size > 0 44 | response = JSON.parse(@response.body) 45 | assert_equal({ 'string_params' => nil }, response['params']) 46 | assert_nil response['hello_header'] 47 | refute response['xhr'] 48 | else 49 | assert_equal 'head', verb 50 | end 51 | end 52 | 53 | define_method("test_#{verb}_new_blank_headers_only") do 54 | send(verb.to_sym, '/kwargs/test_kwargs', headers: nil) 55 | if @response.body.size > 0 56 | response = JSON.parse(@response.body) 57 | assert_equal({}, response['params']) 58 | assert_nil response['hello_header'] 59 | refute response['xhr'] 60 | else 61 | assert_equal 'head', verb 62 | end 63 | end 64 | 65 | define_method("test_xhr_#{verb}_new_no_params_or_headers") do 66 | send(verb.to_sym, '/kwargs/test_kwargs', xhr: true) 67 | if @response.body.size > 0 68 | response = JSON.parse(@response.body) 69 | assert_equal({}, response['params']) 70 | assert_nil response['hello_header'] 71 | assert response['xhr'] 72 | else 73 | assert_equal 'head', verb 74 | end 75 | end 76 | 77 | define_method("test_xhr_#{verb}_old_params_only") do 78 | Rails::ForwardCompatibleControllerTests.ignore 79 | 80 | xhr verb.to_sym, '/kwargs/test_kwargs', hello: 'world' 81 | if @response.body.size > 0 82 | response = JSON.parse(@response.body) 83 | assert_equal({ 'hello' => 'world' }, response['params']) 84 | assert_nil response['hello_header'] 85 | assert response['xhr'] 86 | else 87 | assert_equal 'head', verb 88 | end 89 | end 90 | 91 | define_method("test_xhr_#{verb}_old_params_only__raises_exception") do 92 | assert_raise_in_rails_4(Exception) do 93 | xhr verb.to_sym, '/kwargs/test_kwargs', hello: 'world' 94 | end 95 | end 96 | 97 | define_method("test_xhr_#{verb}_new_params_only") do 98 | send(verb.to_sym, '/kwargs/test_kwargs', xhr: true, params: { hello: 'world' }) 99 | if @response.body.size > 0 100 | response = JSON.parse(@response.body) 101 | assert_equal({ 'hello' => 'world' }, response['params']) 102 | assert_nil response['hello_header'] 103 | assert response['xhr'] 104 | else 105 | assert_equal 'head', verb 106 | end 107 | end 108 | 109 | define_method("test_#{verb}_old_headers_only") do 110 | Rails::ForwardCompatibleControllerTests.ignore 111 | 112 | send(verb.to_sym, '/kwargs/test_kwargs', nil, 'Hello': 'world') 113 | if @response.body.size > 0 114 | response = JSON.parse(@response.body) 115 | assert_equal('world', response['hello_header']) 116 | assert_equal({}, response['params']) 117 | refute response['xhr'] 118 | else 119 | assert_equal 'head', verb 120 | end 121 | end 122 | 123 | define_method("test_#{verb}_old_headers_only__raises_exception") do 124 | assert_raise_in_rails_4(Exception) do 125 | send(verb.to_sym, '/kwargs/test_kwargs', nil, 'Hello': 'world') 126 | end 127 | end 128 | 129 | define_method("test_#{verb}_new_headers_only") do 130 | send(verb.to_sym, '/kwargs/test_kwargs', headers: { 'Hello': 'world' }) 131 | if @response.body.size > 0 132 | response = JSON.parse(@response.body) 133 | assert_equal('world', response['hello_header']) 134 | assert_equal({}, response['params']) 135 | refute response['xhr'] 136 | else 137 | assert_equal 'head', verb 138 | end 139 | end 140 | 141 | define_method("test_xhr_#{verb}_old_headers_only") do 142 | Rails::ForwardCompatibleControllerTests.ignore 143 | 144 | xhr(verb.to_sym, '/kwargs/test_kwargs', nil, 'Hello': 'world') 145 | if @response.body.size > 0 146 | response = JSON.parse(@response.body) 147 | assert_equal('world', response['hello_header']) 148 | assert_equal({}, response['params']) 149 | assert response['xhr'] 150 | else 151 | assert_equal 'head', verb 152 | end 153 | end 154 | 155 | define_method("test_xhr_#{verb}_old_headers_only__raises_exception") do 156 | assert_raise_in_rails_4(Exception) do 157 | xhr(verb.to_sym, '/kwargs/test_kwargs', nil, 'Hello': 'world') 158 | end 159 | end 160 | 161 | define_method("test_xhr_#{verb}_new_headers_only") do 162 | send(verb.to_sym, '/kwargs/test_kwargs', xhr: true, headers: { 'Hello': 'world' }) 163 | if @response.body.size > 0 164 | response = JSON.parse(@response.body) 165 | assert_equal('world', response['hello_header']) 166 | assert_equal({}, response['params']) 167 | assert response['xhr'] 168 | else 169 | assert_equal 'head', verb 170 | end 171 | end 172 | 173 | define_method("test_#{verb}_old_params_and_headers") do 174 | Rails::ForwardCompatibleControllerTests.ignore 175 | 176 | send(verb.to_sym, '/kwargs/test_kwargs', { hello: 'world' }, { 'Hello': 'world' }) 177 | if @response.body.size > 0 178 | response = JSON.parse(@response.body) 179 | assert_equal({ 'hello' => 'world' }, response['params']) 180 | assert_equal('world', response['hello_header']) 181 | refute response['xhr'] 182 | else 183 | assert_equal 'head', verb 184 | end 185 | end 186 | 187 | define_method("test_#{verb}_old_params_and_headers__raises_exception") do 188 | assert_raise_in_rails_4(Exception) do 189 | send(verb.to_sym, '/kwargs/test_kwargs', { hello: 'world' }, { 'Hello': 'world' }) 190 | end 191 | end 192 | 193 | define_method("test_#{verb}_new_params_and_headers") do 194 | send(verb.to_sym, '/kwargs/test_kwargs', params: { hello: 'world' }, headers: { 'Hello': 'world' }) 195 | if @response.body.size > 0 196 | response = JSON.parse(@response.body) 197 | assert_equal({ 'hello' => 'world' }, response['params']) 198 | assert_equal('world', response['hello_header']) 199 | refute response['xhr'] 200 | else 201 | assert_equal 'head', verb 202 | end 203 | end 204 | 205 | define_method("test_xhr_#{verb}_old_params_and_headers") do 206 | Rails::ForwardCompatibleControllerTests.ignore 207 | 208 | xhr verb.to_sym, '/kwargs/test_kwargs', { hello: 'world' }, { 'Hello': 'world' } 209 | if @response.body.size > 0 210 | response = JSON.parse(@response.body) 211 | assert_equal({ 'hello' => 'world' }, response['params']) 212 | assert_equal('world', response['hello_header']) 213 | assert response['xhr'] 214 | else 215 | assert_equal 'head', verb 216 | end 217 | end 218 | 219 | define_method("test_xhr_#{verb}_old_params_and_headers__outputs_deprecation") do 220 | Rails::ForwardCompatibleControllerTests.deprecate 221 | 222 | assert_deprecated do 223 | xhr verb.to_sym, '/kwargs/test_kwargs', { hello: 'world' }, { 'Hello': 'world' } 224 | end 225 | if @response.body.size > 0 226 | response = JSON.parse(@response.body) 227 | assert_equal({ 'hello' => 'world' }, response['params']) 228 | assert_equal('world', response['hello_header']) 229 | assert response['xhr'] 230 | else 231 | assert_equal 'head', verb 232 | end 233 | end 234 | 235 | define_method("test_xhr_#{verb}_old_params_and_headers__raises_exception") do 236 | assert_raise_in_rails_4(Exception) do 237 | xhr verb.to_sym, '/kwargs/test_kwargs', { hello: 'world' }, { 'Hello': 'world' } 238 | end 239 | end 240 | 241 | define_method("test_xhr_#{verb}_new_params_and_headers") do 242 | send(verb.to_sym, '/kwargs/test_kwargs', xhr: true, params: { hello: 'world' }, headers: { 'Hello': 'world' }) 243 | if @response.body.size > 0 244 | response = JSON.parse(@response.body) 245 | assert_equal({ 'hello' => 'world' }, response['params']) 246 | assert_equal('world', response['hello_header']) 247 | assert response['xhr'] 248 | else 249 | assert_equal 'head', verb 250 | end 251 | end 252 | end 253 | end 254 | -------------------------------------------------------------------------------- /test/controllers/kwargs_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class KwargsControllerTest < ActionController::TestCase 4 | def setup 5 | Rails::ForwardCompatibleControllerTests.raise_exception 6 | end 7 | 8 | %w[get post patch put head delete].each do |verb| 9 | define_method("test_#{verb}_old_params_only") do 10 | Rails::ForwardCompatibleControllerTests.ignore 11 | 12 | send(verb.to_sym, :test_kwargs, hello: 'world') 13 | assert_equal({ 'hello' => 'world' }, assigns(:params)) 14 | assert_nil assigns(:hello_header) 15 | assert_nil assigns(:session) 16 | assert_nil assigns(:flash) 17 | refute assigns(:xhr) 18 | end 19 | 20 | define_method("test_#{verb}_old_params_only__allows_format_keyword") do 21 | send(verb.to_sym, :test_kwargs, format: :json) 22 | assert_equal({ 'format' => 'json' }, assigns(:params)) 23 | end 24 | 25 | define_method("test_#{verb}_old_params_only__outputs_deprecation") do 26 | Rails::ForwardCompatibleControllerTests.deprecate 27 | 28 | assert_deprecated do 29 | send(verb.to_sym, :test_kwargs, hello: 'world') 30 | end 31 | assert_equal({ 'hello' => 'world' }, assigns(:params)) 32 | assert_nil assigns(:hello_header) 33 | assert_nil assigns(:session) 34 | assert_nil assigns(:flash) 35 | refute assigns(:xhr) 36 | end 37 | 38 | 39 | define_method("test_#{verb}_old_params_only__raises_exception") do 40 | assert_raise_in_rails_4(Exception) do 41 | send(verb.to_sym, :test_kwargs, hello: 'world') 42 | end 43 | end 44 | 45 | define_method("test_#{verb}_new_params_only") do 46 | send(verb.to_sym, :test_kwargs, params: { hello: 'world', session: { a: 'foo' } }) 47 | assert_equal({ 'hello' => 'world', 'session' => { 'a' => 'foo' } }, assigns(:params)) 48 | assert_nil assigns(:hello_header) 49 | assert_nil assigns(:session) 50 | assert_nil assigns(:flash) 51 | refute assigns(:xhr) 52 | end 53 | 54 | define_method("test_xhr_#{verb}_old_params_only") do 55 | Rails::ForwardCompatibleControllerTests.ignore 56 | 57 | xhr verb.to_sym, :test_kwargs, hello: 'world' 58 | assert_equal({ 'hello' => 'world' }, assigns(:params)) 59 | assert_nil assigns(:hello_header) 60 | assert_nil assigns(:session) 61 | assert_nil assigns(:flash) 62 | assert assigns(:xhr) 63 | end 64 | 65 | define_method("test_xhr_#{verb}_old_params_only__outputs_deprecation") do 66 | Rails::ForwardCompatibleControllerTests.deprecate 67 | 68 | assert_deprecated do 69 | xhr verb.to_sym, :test_kwargs, hello: 'world' 70 | end 71 | assert_equal({ 'hello' => 'world' }, assigns(:params)) 72 | assert_nil assigns(:hello_header) 73 | assert_nil assigns(:session) 74 | assert_nil assigns(:flash) 75 | assert assigns(:xhr) 76 | end 77 | 78 | 79 | define_method("test_xhr_#{verb}_old_params_only__raises_exception") do 80 | assert_raise_in_rails_4(Exception) do 81 | xhr verb.to_sym, :test_kwargs, hello: 'world' 82 | end 83 | end 84 | 85 | define_method("test_xhr_#{verb}_new_params_only") do 86 | send(verb.to_sym, :test_kwargs, xhr: true, params: { hello: 'world' }) 87 | assert_equal({ 'hello' => 'world' }, assigns(:params)) 88 | assert_nil assigns(:hello_header) 89 | assert_nil assigns(:session) 90 | assert_nil assigns(:flash) 91 | assert assigns(:xhr) 92 | end 93 | 94 | define_method("test_#{verb}_old_session_only") do 95 | Rails::ForwardCompatibleControllerTests.ignore 96 | 97 | send(verb.to_sym, :test_kwargs, nil, sesh: 'shin') 98 | assert_equal('shin', assigns(:session)) 99 | assert_equal({}, assigns(:params)) 100 | assert_nil assigns(:hello_header) 101 | assert_nil assigns(:flash) 102 | refute assigns(:xhr) 103 | end 104 | 105 | define_method("test_#{verb}_old_session_only__outputs_deprecation") do 106 | Rails::ForwardCompatibleControllerTests.deprecate 107 | 108 | assert_deprecated do 109 | send(verb.to_sym, :test_kwargs, nil, sesh: 'shin') 110 | end 111 | assert_equal('shin', assigns(:session)) 112 | assert_equal({}, assigns(:params)) 113 | assert_nil assigns(:hello_header) 114 | assert_nil assigns(:flash) 115 | refute assigns(:xhr) 116 | end 117 | 118 | define_method("test_#{verb}_old_session_only__raises_exception") do 119 | assert_raise_in_rails_4(Exception) do 120 | send(verb.to_sym, :test_kwargs, nil, sesh: 'shin') 121 | end 122 | end 123 | 124 | define_method("test_#{verb}_new_session_only") do 125 | send(verb.to_sym, :test_kwargs, session: { sesh: 'shin' }) 126 | assert_equal('shin', assigns(:session)) 127 | assert_equal({}, assigns(:params)) 128 | assert_nil assigns(:hello_header) 129 | assert_nil assigns(:flash) 130 | refute assigns(:xhr) 131 | end 132 | 133 | define_method("test_xhr_#{verb}_old_session_only") do 134 | Rails::ForwardCompatibleControllerTests.ignore 135 | 136 | xhr(verb.to_sym, :test_kwargs, nil, sesh: 'shin') 137 | assert_equal('shin', assigns(:session)) 138 | assert_equal({}, assigns(:params)) 139 | assert_nil assigns(:hello_header) 140 | assert_nil assigns(:flash) 141 | assert assigns(:xhr) 142 | end 143 | 144 | define_method("test_xhr_#{verb}_old_session_only__outputs_deprecation") do 145 | Rails::ForwardCompatibleControllerTests.deprecate 146 | 147 | assert_deprecated do 148 | xhr(verb.to_sym, :test_kwargs, nil, sesh: 'shin') 149 | end 150 | assert_equal('shin', assigns(:session)) 151 | assert_equal({}, assigns(:params)) 152 | assert_nil assigns(:hello_header) 153 | assert_nil assigns(:flash) 154 | assert assigns(:xhr) 155 | end 156 | 157 | define_method("test_xhr_#{verb}_old_session_only__raises_exception") do 158 | assert_raise_in_rails_4(Exception) do 159 | xhr(verb.to_sym, :test_kwargs, nil, sesh: 'shin') 160 | end 161 | end 162 | 163 | define_method("test_xhr_#{verb}_new_session_only") do 164 | send(verb.to_sym, :test_kwargs, xhr: true, session: { sesh: 'shin' }) 165 | assert_equal('shin', assigns(:session)) 166 | assert_equal({}, assigns(:params)) 167 | assert_nil assigns(:hello_header) 168 | assert_nil assigns(:flash) 169 | assert assigns(:xhr) 170 | end 171 | 172 | define_method("test_#{verb}_old_flash_only") do 173 | Rails::ForwardCompatibleControllerTests.ignore 174 | 175 | send(verb.to_sym, :test_kwargs, nil, nil, flashy: 'flash') 176 | assert_equal('flash', assigns(:flash)) 177 | assert_equal({}, assigns(:params)) 178 | assert_nil assigns(:hello_header) 179 | refute assigns(:xhr) 180 | end 181 | 182 | define_method("test_#{verb}_old_flash_only__outputs_deprecation") do 183 | Rails::ForwardCompatibleControllerTests.deprecate 184 | 185 | assert_deprecated do 186 | send(verb.to_sym, :test_kwargs, nil, nil, flashy: 'flash') 187 | end 188 | assert_equal('flash', assigns(:flash)) 189 | assert_equal({}, assigns(:params)) 190 | assert_nil assigns(:hello_header) 191 | refute assigns(:xhr) 192 | end 193 | 194 | define_method("test_#{verb}_old_flash_only__raises_exception") do 195 | assert_raise_in_rails_4(Exception) do 196 | send(verb.to_sym, :test_kwargs, nil, nil, flashy: 'flash') 197 | end 198 | end 199 | 200 | define_method("test_#{verb}_new_flash_only") do 201 | send(verb.to_sym, :test_kwargs, flash: { flashy: 'flash' }) 202 | assert_equal('flash', assigns(:flash)) 203 | assert_equal({}, assigns(:params)) 204 | assert_nil assigns(:hello_header) 205 | refute assigns(:xhr) 206 | end 207 | 208 | define_method("test_xhr_#{verb}_old_flash_only") do 209 | Rails::ForwardCompatibleControllerTests.ignore 210 | 211 | xhr(verb.to_sym, :test_kwargs, nil, nil, flashy: 'flash') 212 | assert_equal('flash', assigns(:flash)) 213 | assert_equal({}, assigns(:params)) 214 | assert_nil assigns(:hello_header) 215 | assert assigns(:xhr) 216 | end 217 | 218 | define_method("test_xhr_#{verb}_old_flash_only__outputs_deprecation") do 219 | Rails::ForwardCompatibleControllerTests.deprecate 220 | 221 | assert_deprecated do 222 | xhr(verb.to_sym, :test_kwargs, nil, nil, flashy: 'flash') 223 | end 224 | assert_equal('flash', assigns(:flash)) 225 | assert_equal({}, assigns(:params)) 226 | assert_nil assigns(:hello_header) 227 | assert assigns(:xhr) 228 | end 229 | 230 | define_method("test_xhr_#{verb}_old_flash_only__raises_exception") do 231 | assert_raise_in_rails_4(Exception) do 232 | xhr(verb.to_sym, :test_kwargs, nil, nil, flashy: 'flash') 233 | end 234 | end 235 | 236 | define_method("test_xhr_#{verb}_new_flash_only") do 237 | send(verb.to_sym, :test_kwargs, xhr: true, flash: { flashy: 'flash' }) 238 | assert_equal('flash', assigns(:flash)) 239 | assert_equal({}, assigns(:params)) 240 | assert_nil assigns(:hello_header) 241 | assert assigns(:xhr) 242 | end 243 | 244 | define_method("test_#{verb}_old_params_and_session") do 245 | Rails::ForwardCompatibleControllerTests.ignore 246 | 247 | send(verb.to_sym, :test_kwargs, { hello: 'world' }, { sesh: 'shin' }) 248 | assert_equal({ 'hello' => 'world' }, assigns(:params)) 249 | assert_equal('shin', assigns(:session)) 250 | assert_nil assigns(:hello_header) 251 | assert_nil assigns(:flash) 252 | refute assigns(:xhr) 253 | end 254 | 255 | define_method("test_#{verb}_old_params_and_session__outputs_deprecation") do 256 | Rails::ForwardCompatibleControllerTests.deprecate 257 | 258 | assert_deprecated do 259 | send(verb.to_sym, :test_kwargs, { hello: 'world' }, { sesh: 'shin' }) 260 | end 261 | assert_equal({ 'hello' => 'world' }, assigns(:params)) 262 | assert_equal('shin', assigns(:session)) 263 | assert_nil assigns(:hello_header) 264 | assert_nil assigns(:flash) 265 | refute assigns(:xhr) 266 | end 267 | 268 | define_method("test_#{verb}_old_params_and_session__raises_exception") do 269 | assert_raise_in_rails_4(Exception) do 270 | send(verb.to_sym, :test_kwargs, { hello: 'world' }, { sesh: 'shin' }) 271 | end 272 | end 273 | 274 | define_method("test_#{verb}_new_params_and_session") do 275 | send(verb.to_sym, :test_kwargs, params: { hello: 'world' }, session: { sesh: 'shin' }) 276 | assert_equal({ 'hello' => 'world' }, assigns(:params)) 277 | assert_equal('shin', assigns(:session)) 278 | assert_nil assigns(:hello_header) 279 | assert_nil assigns(:flash) 280 | refute assigns(:xhr) 281 | end 282 | 283 | define_method("test_xhr_#{verb}_old_params_and_session") do 284 | Rails::ForwardCompatibleControllerTests.ignore 285 | 286 | xhr verb.to_sym, :test_kwargs, { hello: 'world' }, { sesh: 'shin' } 287 | assert_equal({ 'hello' => 'world' }, assigns(:params)) 288 | assert_equal('shin', assigns(:session)) 289 | assert_nil assigns(:hello_header) 290 | assert_nil assigns(:flash) 291 | assert assigns(:xhr) 292 | end 293 | 294 | define_method("test_xhr_#{verb}_old_params_and_session__deprecated") do 295 | Rails::ForwardCompatibleControllerTests.deprecate 296 | 297 | assert_deprecated do 298 | xhr verb.to_sym, :test_kwargs, { hello: 'world' }, { sesh: 'shin' } 299 | end 300 | assert_equal({ 'hello' => 'world' }, assigns(:params)) 301 | assert_equal('shin', assigns(:session)) 302 | assert_nil assigns(:hello_header) 303 | assert_nil assigns(:flash) 304 | assert assigns(:xhr) 305 | end 306 | 307 | define_method("test_xhr_#{verb}_old_params_and_session__raises_exception") do 308 | assert_raise_in_rails_4(Exception) do 309 | xhr verb.to_sym, :test_kwargs, { hello: 'world' }, { sesh: 'shin' } 310 | end 311 | end 312 | 313 | define_method("test_xhr_#{verb}_new_params_and_session") do 314 | send(verb.to_sym, :test_kwargs, xhr: true, params: { hello: 'world' }, session: { sesh: 'shin' }) 315 | assert_equal({ 'hello' => 'world' }, assigns(:params)) 316 | assert_equal('shin', assigns(:session)) 317 | assert_nil assigns(:hello_header) 318 | assert_nil assigns(:flash) 319 | assert assigns(:xhr) 320 | end 321 | 322 | define_method("test_xhr_#{verb}_new_params_and_session__does_not_output_warning") do 323 | Rails::ForwardCompatibleControllerTests.deprecate 324 | 325 | assert_not_deprecated do 326 | send(verb.to_sym, :test_kwargs, xhr: true, params: { hello: 'world' }, session: { sesh: 'shin' }) 327 | end 328 | assert_equal({ 'hello' => 'world' }, assigns(:params)) 329 | assert_equal('shin', assigns(:session)) 330 | assert_nil assigns(:hello_header) 331 | assert_nil assigns(:flash) 332 | assert assigns(:xhr) 333 | end 334 | 335 | define_method("test_#{verb}_old_params_and_flash") do 336 | Rails::ForwardCompatibleControllerTests.ignore 337 | 338 | send(verb.to_sym, :test_kwargs, { hello: 'world' }, nil, { flashy: 'flash' }) 339 | assert_equal({ 'hello' => 'world' }, assigns(:params)) 340 | assert_equal('flash', assigns(:flash)) 341 | assert_nil assigns(:hello_header) 342 | assert_nil assigns(:session) 343 | refute assigns(:xhr) 344 | end 345 | 346 | define_method("test_#{verb}_old_params_and_flash__outputs_deprecation") do 347 | Rails::ForwardCompatibleControllerTests.deprecate 348 | 349 | assert_deprecated do 350 | send(verb.to_sym, :test_kwargs, { hello: 'world' }, nil, { flashy: 'flash' }) 351 | end 352 | assert_equal({ 'hello' => 'world' }, assigns(:params)) 353 | assert_equal('flash', assigns(:flash)) 354 | assert_nil assigns(:hello_header) 355 | assert_nil assigns(:session) 356 | refute assigns(:xhr) 357 | end 358 | 359 | define_method("test_#{verb}_old_params_and_flash__raises_exception") do 360 | assert_raise_in_rails_4(Exception) do 361 | send(verb.to_sym, :test_kwargs, { hello: 'world' }, nil, { flashy: 'flash' }) 362 | end 363 | end 364 | 365 | define_method("test_#{verb}_new_params_and_flash") do 366 | send(verb.to_sym, :test_kwargs, params: { hello: 'world' }, flash: { flashy: 'flash' }) 367 | assert_equal({ 'hello' => 'world' }, assigns(:params)) 368 | assert_equal('flash', assigns(:flash)) 369 | assert_nil assigns(:hello_header) 370 | assert_nil assigns(:session) 371 | refute assigns(:xhr) 372 | end 373 | 374 | define_method("test_xhr_#{verb}_old_params_and_flash") do 375 | Rails::ForwardCompatibleControllerTests.ignore 376 | 377 | xhr verb.to_sym, :test_kwargs, { hello: 'world' }, nil, { flashy: 'flash' } 378 | assert_equal({ 'hello' => 'world' }, assigns(:params)) 379 | assert_equal('flash', assigns(:flash)) 380 | assert_nil assigns(:hello_header) 381 | assert_nil assigns(:session) 382 | assert assigns(:xhr) 383 | end 384 | 385 | define_method("test_xhr_#{verb}_old_params_and_flash__deprecated") do 386 | Rails::ForwardCompatibleControllerTests.deprecate 387 | 388 | assert_deprecated do 389 | xhr verb.to_sym, :test_kwargs, { hello: 'world' }, nil, { flashy: 'flash' } 390 | end 391 | assert_equal({ 'hello' => 'world' }, assigns(:params)) 392 | assert_equal('flash', assigns(:flash)) 393 | assert_nil assigns(:hello_header) 394 | assert_nil assigns(:session) 395 | assert assigns(:xhr) 396 | end 397 | 398 | define_method("test_xhr_#{verb}_old_params_and_flash__raises_exception") do 399 | assert_raise_in_rails_4(Exception) do 400 | xhr verb.to_sym, :test_kwargs, { hello: 'world' }, nil, { flashy: 'flash' } 401 | end 402 | end 403 | 404 | define_method("test_xhr_#{verb}_new_params_and_flash") do 405 | send(verb.to_sym, :test_kwargs, xhr: true, params: { hello: 'world' }, flash: { flashy: 'flash' }) 406 | assert_equal({ 'hello' => 'world' }, assigns(:params)) 407 | assert_equal('flash', assigns(:flash)) 408 | assert_nil assigns(:hello_header) 409 | assert_nil assigns(:session) 410 | assert assigns(:xhr) 411 | end 412 | 413 | define_method("test_xhr_#{verb}_new_params_and_flash__does_not_output_warning") do 414 | Rails::ForwardCompatibleControllerTests.deprecate 415 | 416 | assert_not_deprecated do 417 | send(verb.to_sym, :test_kwargs, xhr: true, params: { hello: 'world' }, flash: { flashy: 'flash' }) 418 | end 419 | assert_equal({ 'hello' => 'world' }, assigns(:params)) 420 | assert_equal('flash', assigns(:flash)) 421 | assert_nil assigns(:hello_header) 422 | assert_nil assigns(:session) 423 | assert assigns(:xhr) 424 | end 425 | 426 | define_method("test_#{verb}_old_session_and_flash") do 427 | Rails::ForwardCompatibleControllerTests.ignore 428 | 429 | send(verb.to_sym, :test_kwargs, nil, { sesh: 'shin' }, { flashy: 'flash' }) 430 | assert_equal({}, assigns(:params)) 431 | assert_equal('shin', assigns(:session)) 432 | assert_equal('flash', assigns(:flash)) 433 | assert_nil assigns(:hello_header) 434 | refute assigns(:xhr) 435 | end 436 | 437 | define_method("test_#{verb}_old_session_and_flash__outputs_deprecation") do 438 | Rails::ForwardCompatibleControllerTests.deprecate 439 | 440 | assert_deprecated do 441 | send(verb.to_sym, :test_kwargs, nil, { sesh: 'shin' }, { flashy: 'flash' }) 442 | end 443 | assert_equal({}, assigns(:params)) 444 | assert_equal('shin', assigns(:session)) 445 | assert_equal('flash', assigns(:flash)) 446 | assert_nil assigns(:hello_header) 447 | refute assigns(:xhr) 448 | end 449 | 450 | define_method("test_#{verb}_old_session_and_flash__raises_exception") do 451 | assert_raise_in_rails_4(Exception) do 452 | send(verb.to_sym, :test_kwargs, nil, { sesh: 'shin' }, { flashy: 'flash' }) 453 | end 454 | end 455 | 456 | define_method("test_#{verb}_new_session_and_flash") do 457 | send(verb.to_sym, :test_kwargs, session: { sesh: 'shin' }, flash: { flashy: 'flash' }) 458 | assert_equal({}, assigns(:params)) 459 | assert_equal('shin', assigns(:session)) 460 | assert_equal('flash', assigns(:flash)) 461 | assert_nil assigns(:hello_header) 462 | refute assigns(:xhr) 463 | end 464 | 465 | define_method("test_xhr_#{verb}_old_session_and_flash") do 466 | Rails::ForwardCompatibleControllerTests.ignore 467 | 468 | xhr verb.to_sym, :test_kwargs, nil, { sesh: 'shin' }, { flashy: 'flash' } 469 | assert_equal({}, assigns(:params)) 470 | assert_equal('shin', assigns(:session)) 471 | assert_equal('flash', assigns(:flash)) 472 | assert_nil assigns(:hello_header) 473 | assert assigns(:xhr) 474 | end 475 | 476 | define_method("test_xhr_#{verb}_old_session_and_flash__deprecated") do 477 | Rails::ForwardCompatibleControllerTests.deprecate 478 | 479 | assert_deprecated do 480 | xhr verb.to_sym, :test_kwargs, nil, { sesh: 'shin' }, { flashy: 'flash' } 481 | end 482 | assert_equal({}, assigns(:params)) 483 | assert_equal('shin', assigns(:session)) 484 | assert_equal('flash', assigns(:flash)) 485 | assert_nil assigns(:hello_header) 486 | assert assigns(:xhr) 487 | end 488 | 489 | define_method("test_xhr_#{verb}_old_session_and_flash__raises_exception") do 490 | assert_raise_in_rails_4(Exception) do 491 | xhr verb.to_sym, :test_kwargs, { sesh: 'shin' }, { flashy: 'flash' } 492 | end 493 | end 494 | 495 | define_method("test_xhr_#{verb}_new_session_and_flash") do 496 | send(verb.to_sym, :test_kwargs, xhr: true, session: { sesh: 'shin' }, flash: { flashy: 'flash' }) 497 | assert_equal({}, assigns(:params)) 498 | assert_equal('shin', assigns(:session)) 499 | assert_equal('flash', assigns(:flash)) 500 | assert_nil assigns(:hello_header) 501 | assert assigns(:xhr) 502 | end 503 | 504 | define_method("test_xhr_#{verb}_new_session_and_flash__does_not_output_warning") do 505 | Rails::ForwardCompatibleControllerTests.deprecate 506 | 507 | assert_not_deprecated do 508 | send(verb.to_sym, :test_kwargs, xhr: true, session: { sesh: 'shin' }, flash: { flashy: 'flash' }) 509 | end 510 | assert_equal({}, assigns(:params)) 511 | assert_equal('shin', assigns(:session)) 512 | assert_equal('flash', assigns(:flash)) 513 | assert_nil assigns(:hello_header) 514 | assert assigns(:xhr) 515 | end 516 | 517 | define_method("test_#{verb}_old_params_and_session_and_flash") do 518 | Rails::ForwardCompatibleControllerTests.ignore 519 | 520 | send(verb.to_sym, :test_kwargs, { hello: 'world' }, { sesh: 'shin' }, { flashy: 'flash' }) 521 | assert_equal({ 'hello' => 'world' }, assigns(:params)) 522 | assert_equal('shin', assigns(:session)) 523 | assert_equal('flash', assigns(:flash)) 524 | assert_nil assigns(:hello_header) 525 | refute assigns(:xhr) 526 | end 527 | 528 | define_method("test_#{verb}_old_params_and_session_and_flash__outputs_deprecation") do 529 | Rails::ForwardCompatibleControllerTests.deprecate 530 | 531 | assert_deprecated do 532 | send(verb.to_sym, :test_kwargs, { hello: 'world' }, { sesh: 'shin' }, { flashy: 'flash' }) 533 | end 534 | assert_equal({ 'hello' => 'world' }, assigns(:params)) 535 | assert_equal('shin', assigns(:session)) 536 | assert_equal('flash', assigns(:flash)) 537 | assert_nil assigns(:hello_header) 538 | refute assigns(:xhr) 539 | end 540 | 541 | define_method("test_#{verb}_old_params_and_session_and_flash__raises_exception") do 542 | assert_raise_in_rails_4(Exception) do 543 | send(verb.to_sym, :test_kwargs, { hello: 'world' }, { sesh: 'shin' }, { flashy: 'flash' }) 544 | end 545 | end 546 | 547 | define_method("test_#{verb}_new_params_and_session_and_flash") do 548 | send(verb.to_sym, :test_kwargs, params: { hello: 'world' }, session: { sesh: 'shin' }, flash: { flashy: 'flash' }) 549 | assert_equal({ 'hello' => 'world' }, assigns(:params)) 550 | assert_equal('shin', assigns(:session)) 551 | assert_equal('flash', assigns(:flash)) 552 | assert_nil assigns(:hello_header) 553 | refute assigns(:xhr) 554 | end 555 | 556 | define_method("test_xhr_#{verb}_old_params_and_session_and_flash") do 557 | Rails::ForwardCompatibleControllerTests.ignore 558 | 559 | xhr verb.to_sym, :test_kwargs, { hello: 'world' }, { sesh: 'shin' }, { flashy: 'flash' } 560 | assert_equal({ 'hello' => 'world' }, assigns(:params)) 561 | assert_equal('shin', assigns(:session)) 562 | assert_equal('flash', assigns(:flash)) 563 | assert_nil assigns(:hello_header) 564 | assert assigns(:xhr) 565 | end 566 | 567 | define_method("test_xhr_#{verb}_old_params_and_session_and_flash__deprecated") do 568 | Rails::ForwardCompatibleControllerTests.deprecate 569 | 570 | assert_deprecated do 571 | xhr verb.to_sym, :test_kwargs, { hello: 'world' }, { sesh: 'shin' }, { flashy: 'flash' } 572 | end 573 | assert_equal({ 'hello' => 'world' }, assigns(:params)) 574 | assert_equal('shin', assigns(:session)) 575 | assert_equal('flash', assigns(:flash)) 576 | assert_nil assigns(:hello_header) 577 | assert assigns(:xhr) 578 | end 579 | 580 | define_method("test_xhr_#{verb}_old_params_and_session_and_flash__raises_exception") do 581 | assert_raise_in_rails_4(Exception) do 582 | xhr verb.to_sym, :test_kwargs, { hello: 'world' }, { sesh: 'shin' }, { flashy: 'flash' } 583 | end 584 | end 585 | 586 | define_method("test_xhr_#{verb}_new_params_and_session_and_flash") do 587 | send(verb.to_sym, :test_kwargs, xhr: true, params: { hello: 'world' }, session: { sesh: 'shin' }, flash: { flashy: 'flash' }) 588 | assert_equal({ 'hello' => 'world' }, assigns(:params)) 589 | assert_equal('shin', assigns(:session)) 590 | assert_equal('flash', assigns(:flash)) 591 | assert_nil assigns(:hello_header) 592 | assert assigns(:xhr) 593 | end 594 | 595 | define_method("test_xhr_#{verb}_new_params_and_session_and_format") do 596 | send(verb.to_sym, :test_kwargs, format: :json, params: { session: { a: "foo" } }, xhr: true) 597 | assert_equal({ 'session' => { 'a' => 'foo' }, 'format' => 'json' }, assigns(:params)) 598 | assert_nil assigns(:session) 599 | assert_nil assigns(:flash) 600 | assert_nil assigns(:hello_header) 601 | assert assigns(:xhr) 602 | end 603 | 604 | define_method("test_xhr_#{verb}_new_params_and_session_and_flash__does_not_output_warning") do 605 | Rails::ForwardCompatibleControllerTests.deprecate 606 | 607 | assert_not_deprecated do 608 | send(verb.to_sym, :test_kwargs, xhr: true, params: { hello: 'world' }, session: { sesh: 'shin' }, flash: { flashy: 'flash' }) 609 | end 610 | assert_equal({ 'hello' => 'world' }, assigns(:params)) 611 | assert_equal('shin', assigns(:session)) 612 | assert_equal('flash', assigns(:flash)) 613 | assert_nil assigns(:hello_header) 614 | assert assigns(:xhr) 615 | end 616 | end 617 | end 618 | --------------------------------------------------------------------------------