ruby-rails-controller-testing-1.0.4/0000755000175000017500000000000013577354001017002 5ustar samyaksamyakruby-rails-controller-testing-1.0.4/LICENSE0000644000175000017500000000204713577354001020012 0ustar samyaksamyakCopyright 2015-2016 Alan Guo Xiang Tan Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ruby-rails-controller-testing-1.0.4/.travis.yml0000644000175000017500000000074013577354001021114 0ustar samyaksamyaksudo: false cache: bundler rvm: - 2.2.10 - 2.3.7 - 2.4.4 - 2.5.1 - ruby-head gemfile: - gemfiles/Gemfile-rails-5-0 - gemfiles/Gemfile-rails-5-1 - gemfiles/Gemfile-rails-5-2 - gemfiles/Gemfile-rails-master matrix: allow_failures: - rvm: ruby-head fast_finish: true exclude: - rvm: 2.2.10 gemfile: gemfiles/Gemfile-rails-master - rvm: 2.3.7 gemfile: gemfiles/Gemfile-rails-master env: global: - "JRUBY_OPTS=-Xcext.enabled=true" ruby-rails-controller-testing-1.0.4/Rakefile0000644000175000017500000000052513577354001020451 0ustar samyaksamyakbegin require 'bundler/setup' rescue LoadError puts 'You must `gem install bundler` and `bundle install` to run rake tasks' end Bundler::GemHelper.install_tasks require 'rake/testtask' Rake::TestTask.new(:test) do |t| t.libs << 'lib' t.libs << 'test' t.pattern = 'test/**/*_test.rb' t.verbose = false end task default: :test ruby-rails-controller-testing-1.0.4/test/0000755000175000017500000000000013577354001017761 5ustar samyaksamyakruby-rails-controller-testing-1.0.4/test/helpers/0000755000175000017500000000000013577354001021423 5ustar samyaksamyakruby-rails-controller-testing-1.0.4/test/helpers/template_assertions_test.rb0000644000175000017500000000460713577354001027103 0ustar samyaksamyakrequire 'test_helper' class RenderTemplateTest < ActionView::TestCase test "supports specifying templates with a Regexp" do render(template: "test/hello_world") assert_template %r{\Atest/hello_world\Z} end test "supports specifying partials" do controller.controller_path = "test" render(template: "test/calling_partial_with_layout") assert_template partial: "_partial_for_use_in_layout" end test "supports specifying locals (passing)" do controller.controller_path = "test" render(template: "test/calling_partial_with_layout") assert_template partial: "_partial_for_use_in_layout", locals: { name: "David" } end test "supports specifying locals (failing)" do controller.controller_path = "test" render(template: "test/calling_partial_with_layout") e = assert_raise ActiveSupport::TestCase::Assertion do assert_template partial: "_partial_for_use_in_layout", locals: { name: "Somebody Else" } end assert_match(/Somebody Else.*David/m, e.message) end test 'supports different locals on the same partial' do controller.controller_path = "test" render(template: "test/render_two_partials") assert_template partial: '_partial', locals: { 'first' => '1' } assert_template partial: '_partial', locals: { 'second' => '2' } end test 'raises descriptive error message when template was not rendered' do controller.controller_path = "test" render(template: "test/hello_world_with_partial") e = assert_raise ActiveSupport::TestCase::Assertion do assert_template partial: 'i_was_never_rendered', locals: { 'did_not' => 'happen' } end assert_match "i_was_never_rendered to be rendered but it was not.", e.message assert_match 'Expected ["/test/partial"] to include "i_was_never_rendered"', e.message end test 'specifying locals works when the partial is inside a directory with underline prefix' do controller.controller_path = "test" render(template: 'test/render_partial_inside_directory') assert_template partial: 'test/_directory/_partial_with_locales', locals: { 'name' => 'Jane' } end test 'specifying locals works when the partial is inside a directory without underline prefix' do controller.controller_path = "test" render(template: 'test/render_partial_inside_directory') assert_template partial: 'test/_directory/partial_with_locales', locals: { 'name' => 'Jane' } end end ruby-rails-controller-testing-1.0.4/test/controllers/0000755000175000017500000000000013577354001022327 5ustar samyaksamyakruby-rails-controller-testing-1.0.4/test/controllers/template_assertions_test.rb0000644000175000017500000001163113577354001030002 0ustar samyaksamyakrequire 'test_helper' class TemplateAssertionsControllerTest < ActionController::TestCase def test_with_invalid_hash_keys_raises_argument_error assert_raise(ArgumentError) do assert_template foo: "bar" end end def test_with_partial get :render_with_partial assert_template partial: '_partial' end def test_file_with_absolute_path_success get :render_file_absolute_path assert_template file: File.expand_path('../../dummy/README.rdoc', __FILE__) end def test_file_with_relative_path_success get :render_file_relative_path assert_template file: 'README.rdoc' end def test_with_file_failure get :render_file_absolute_path assert_raise(ActiveSupport::TestCase::Assertion) do assert_template :file => 'test/hello_world' end get :render_file_absolute_path assert_raise(ActiveSupport::TestCase::Assertion) do assert_template file: nil end end def test_with_nil_passes_when_no_template_rendered get :render_nothing assert_template nil end def test_with_nil_fails_when_template_rendered get :render_with_template assert_raise(ActiveSupport::TestCase::Assertion) do assert_template nil end end def test_with_empty_string_fails_when_template_rendered get :render_with_template assert_raise(ActiveSupport::TestCase::Assertion) do assert_template "" end end def test_with_empty_string_fails_when_no_template_rendered get :render_nothing assert_raise(ActiveSupport::TestCase::Assertion) do assert_template "" end end def test_passes_with_correct_string get :render_with_template assert_template 'hello_world' assert_template 'test/hello_world' end def test_passes_with_correct_symbol get :render_with_template assert_template :hello_world end def test_fails_with_incorrect_string get :render_with_template assert_raise(ActiveSupport::TestCase::Assertion) do assert_template 'hello_planet' end end def test_fails_with_incorrect_string_that_matches get :render_with_template assert_raise(ActiveSupport::TestCase::Assertion) do assert_template 'est/he' end end def test_fails_with_repeated_name_in_path get :render_with_template_repeating_in_path assert_raise(ActiveSupport::TestCase::Assertion) do assert_template 'test/hello' end end def test_fails_with_incorrect_symbol get :render_with_template assert_raise(ActiveSupport::TestCase::Assertion) do assert_template :hello_planet end end def test_fails_with_incorrect_symbol_that_matches get :render_with_template assert_raise(ActiveSupport::TestCase::Assertion) do assert_template :"est/he" end end def test_fails_with_wrong_layout get :render_with_layout assert_raise(ActiveSupport::TestCase::Assertion) do assert_template layout: "application" end end def test_fails_expecting_no_layout get :render_with_layout assert_raise(ActiveSupport::TestCase::Assertion) do assert_template layout: nil end end def test_fails_expecting_not_known_layout get :render_with_layout assert_raise(ArgumentError) do assert_template layout: 1 end end def test_passes_with_correct_layout get :render_with_layout assert_template layout: "layouts/standard" end def test_passes_with_layout_and_partial get :render_with_layout_and_partial assert_template layout: "layouts/standard" assert_template partial: "test/_partial" end def test_passed_with_no_layout get :render_with_template assert_template layout: nil end def test_passed_with_no_layout_false get :render_with_template assert_template layout: false end def test_passes_with_correct_layout_without_layouts_prefix get :render_with_layout assert_template layout: "standard" end def test_passes_with_correct_layout_symbol get :render_with_layout assert_template layout: :standard end def test_assert_template_reset_between_requests get :render_with_template assert_template 'test/hello_world' get :render_nothing assert_template nil get :render_with_partial assert_template partial: 'test/_partial' get :render_nothing assert_template partial: nil get :render_with_layout assert_template layout: 'layouts/standard' get :render_nothing assert_template layout: nil get :render_file_relative_path assert_template file: 'README.rdoc' get :render_nothing assert_template file: nil end def test_locals_option_to_assert_template_is_not_supported get :render_nothing warning_buffer = StringIO.new $stderr = warning_buffer assert_template partial: 'customer_greeting', locals: { greeting: 'Bonjour' } assert_includes warning_buffer.string, "the :locals option to #assert_template is only supported in a ActionView::TestCase\n" ensure $stderr = STDERR end end ruby-rails-controller-testing-1.0.4/test/controllers/assigns_test.rb0000644000175000017500000000143313577354001025363 0ustar samyaksamyakrequire 'test_helper' class AssignsControllerTest < ActionController::TestCase def test_assigns process :test_assigns # assigns can be accessed using assigns(key) # or assigns[key], where key is a string or # a symbol assert_equal "foo", assigns(:foo) assert_equal "foo", assigns("foo") assert_equal "foo", assigns[:foo] assert_equal "foo", assigns["foo"] # but the assigned variable should not have its own keys stringified expected_hash = { foo: :bar } assert_equal expected_hash, assigns(:foo_hash) end def test_view_assigns @controller = ViewAssignsController.new process :test_assigns assert_nil assigns(:foo) assert_nil assigns[:foo] assert_equal "bar", assigns(:bar) assert_equal "bar", assigns[:bar] end end ruby-rails-controller-testing-1.0.4/test/test_helper.rb0000644000175000017500000000122113577354001022620 0ustar samyaksamyak# Configure Rails Environment ENV["RAILS_ENV"] = "test" require File.expand_path("../../test/dummy/config/environment.rb", __FILE__) require "rails/test_help" require 'rails-controller-testing' # Filter out Minitest backtrace while allowing backtrace from other libraries # to be shown. Minitest.backtrace_filter = Minitest::BacktraceFilter.new # Load support files Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f } # Load fixtures from the engine if ActiveSupport::TestCase.respond_to?(:fixture_path=) ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__) ActiveSupport::TestCase.fixtures :all end ruby-rails-controller-testing-1.0.4/test/dummy/0000755000175000017500000000000013577354001021114 5ustar samyaksamyakruby-rails-controller-testing-1.0.4/test/dummy/bin/0000755000175000017500000000000013577354001021664 5ustar samyaksamyakruby-rails-controller-testing-1.0.4/test/dummy/bin/rails0000755000175000017500000000022113577354001022717 0ustar samyaksamyak#!/usr/bin/env ruby APP_PATH = File.expand_path('../../config/application', __FILE__) require_relative '../config/boot' require 'rails/commands' ruby-rails-controller-testing-1.0.4/test/dummy/bin/setup0000755000175000017500000000144513577354001022756 0ustar samyaksamyak#!/usr/bin/env ruby require 'pathname' # path to your application root. APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) Dir.chdir APP_ROOT do # This script is a starting point to setup your application. # Add necessary setup steps to this file: puts "== Installing dependencies ==" system "gem install bundler --conservative" system "bundle check || bundle install" # puts "\n== Copying sample files ==" # unless File.exist?("config/database.yml") # system "cp config/database.yml.sample config/database.yml" # end puts "\n== Preparing database ==" system "bin/rake db:setup" puts "\n== Removing old logs and tempfiles ==" system "rm -f log/*" system "rm -rf tmp/cache" puts "\n== Restarting application server ==" system "touch tmp/restart.txt" end ruby-rails-controller-testing-1.0.4/test/dummy/bin/bundle0000755000175000017500000000020113577354001023054 0ustar samyaksamyak#!/usr/bin/env ruby ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) load Gem.bin_path('bundler', 'bundle') ruby-rails-controller-testing-1.0.4/test/dummy/bin/rake0000755000175000017500000000013213577354001022530 0ustar samyaksamyak#!/usr/bin/env ruby require_relative '../config/boot' require 'rake' Rake.application.run ruby-rails-controller-testing-1.0.4/test/dummy/Rakefile0000644000175000017500000000037113577354001022562 0ustar samyaksamyak# Add your own tasks in files placed in lib/tasks ending in .rake, # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. require File.expand_path('../config/application', __FILE__) Rails.application.load_tasks ruby-rails-controller-testing-1.0.4/test/dummy/config.ru0000644000175000017500000000023113577354001022725 0ustar samyaksamyak# This file is used by Rack-based servers to start the application. require ::File.expand_path('../config/environment', __FILE__) run Rails.application ruby-rails-controller-testing-1.0.4/test/dummy/public/0000755000175000017500000000000013577354001022372 5ustar samyaksamyakruby-rails-controller-testing-1.0.4/test/dummy/public/422.html0000644000175000017500000000301313577354001023564 0ustar samyaksamyak The change you wanted was rejected (422)

The change you wanted was rejected.

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

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

ruby-rails-controller-testing-1.0.4/test/dummy/public/404.html0000644000175000017500000000303413577354001023567 0ustar samyaksamyak The page you were looking for doesn't exist (404)

The page you were looking for doesn't exist.

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

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

ruby-rails-controller-testing-1.0.4/test/dummy/public/favicon.ico0000644000175000017500000000000013577354001024501 0ustar samyaksamyakruby-rails-controller-testing-1.0.4/test/dummy/public/500.html0000644000175000017500000000270513577354001023570 0ustar samyaksamyak We're sorry, but something went wrong (500)

We're sorry, but something went wrong.

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

ruby-rails-controller-testing-1.0.4/test/dummy/app/0000755000175000017500000000000013577354001021674 5ustar samyaksamyakruby-rails-controller-testing-1.0.4/test/dummy/app/models/0000755000175000017500000000000013577354001023157 5ustar samyaksamyakruby-rails-controller-testing-1.0.4/test/dummy/app/models/concerns/0000755000175000017500000000000013577354001024771 5ustar samyaksamyakruby-rails-controller-testing-1.0.4/test/dummy/app/models/concerns/.keep0000644000175000017500000000000013577354001025704 0ustar samyaksamyakruby-rails-controller-testing-1.0.4/test/dummy/app/models/.keep0000644000175000017500000000000013577354001024072 0ustar samyaksamyakruby-rails-controller-testing-1.0.4/test/dummy/app/helpers/0000755000175000017500000000000013577354001023336 5ustar samyaksamyakruby-rails-controller-testing-1.0.4/test/dummy/app/helpers/application_helper.rb0000644000175000017500000000003513577354001027523 0ustar samyaksamyakmodule ApplicationHelper end ruby-rails-controller-testing-1.0.4/test/dummy/app/controllers/0000755000175000017500000000000013577354001024242 5ustar samyaksamyakruby-rails-controller-testing-1.0.4/test/dummy/app/controllers/concerns/0000755000175000017500000000000013577354001026054 5ustar samyaksamyakruby-rails-controller-testing-1.0.4/test/dummy/app/controllers/concerns/.keep0000644000175000017500000000000013577354001026767 0ustar samyaksamyakruby-rails-controller-testing-1.0.4/test/dummy/app/controllers/assigns_controller.rb0000644000175000017500000000021213577354001030474 0ustar samyaksamyakclass AssignsController < ActionController::Base def test_assigns @foo = "foo" @foo_hash = { foo: :bar } head :ok end end ruby-rails-controller-testing-1.0.4/test/dummy/app/controllers/view_assigns_controller.rb0000644000175000017500000000024113577354001031530 0ustar samyaksamyakclass ViewAssignsController < ActionController::Base def test_assigns @foo = "foo" head :ok end def view_assigns { "bar" => "bar" } end end ruby-rails-controller-testing-1.0.4/test/dummy/app/controllers/template_assertions_controller.rb0000644000175000017500000000137613577354001033126 0ustar samyaksamyakclass TemplateAssertionsController < ActionController::Base def render_nothing head :ok end def render_with_template render template: "test/hello_world" end def render_with_template_repeating_in_path render template: "test/hello/hello" end def render_with_partial render partial: 'test/partial' end def render_file_absolute_path render file: File.expand_path('../../../README.rdoc', __FILE__) end def render_file_relative_path render file: 'test/dummy/README.rdoc' end def render_with_layout @variable_for_layout = 'hello' render "test/hello_world", layout: "layouts/standard" end def render_with_layout_and_partial render "test/hello_world_with_partial", layout: "layouts/standard" end end ruby-rails-controller-testing-1.0.4/test/dummy/app/views/0000755000175000017500000000000013577354001023031 5ustar samyaksamyakruby-rails-controller-testing-1.0.4/test/dummy/app/views/test/0000755000175000017500000000000013577354001024010 5ustar samyaksamyakruby-rails-controller-testing-1.0.4/test/dummy/app/views/test/hello_world.html.erb0000644000175000017500000000000013577354001027745 0ustar samyaksamyakruby-rails-controller-testing-1.0.4/test/dummy/app/views/test/_layout_for_partial.html.erb0000644000175000017500000000005013577354001031476 0ustar samyaksamyakBefore (<%= name %>) <%= yield %> After ruby-rails-controller-testing-1.0.4/test/dummy/app/views/test/hello_world_with_partial.html.erb0000644000175000017500000000003613577354001032525 0ustar samyaksamyak<%= render '/test/partial' %> ruby-rails-controller-testing-1.0.4/test/dummy/app/views/test/render_two_partials.html.erb0000644000175000017500000000016713577354001031520 0ustar samyaksamyak<%= render partial: 'partial', locals: {'first' => '1'} %> <%= render partial: 'partial', locals: {'second' => '2'} %> ruby-rails-controller-testing-1.0.4/test/dummy/app/views/test/_partial.html.erb0000644000175000017500000000000013577354001027226 0ustar samyaksamyakruby-rails-controller-testing-1.0.4/test/dummy/app/views/test/calling_partial_with_layout.html.erb0000644000175000017500000000015513577354001033223 0ustar samyaksamyak<%= render(layout: "layout_for_partial", partial: "partial_for_use_in_layout", locals: { name: "David" }) %> ruby-rails-controller-testing-1.0.4/test/dummy/app/views/test/_partial_for_use_in_layout.html.erb0000644000175000017500000000004213577354001033041 0ustar samyaksamyakInside from partial (<%= name %>) ././@LongLink0000644000000000000000000000014700000000000011605 Lustar rootrootruby-rails-controller-testing-1.0.4/test/dummy/app/views/test/render_partial_inside_directory.html.erbruby-rails-controller-testing-1.0.4/test/dummy/app/views/test/render_partial_inside_directory.html.e0000644000175000017500000000013213577354001033527 0ustar samyaksamyak<%= render partial: 'test/_directory/partial_with_locales', locals: {'name' => 'Jane'} %> ruby-rails-controller-testing-1.0.4/test/dummy/app/views/test/_directory/0000755000175000017500000000000013577354001026153 5ustar samyaksamyak././@LongLink0000644000000000000000000000015000000000000011577 Lustar rootrootruby-rails-controller-testing-1.0.4/test/dummy/app/views/test/_directory/_partial_with_locales.html.erbruby-rails-controller-testing-1.0.4/test/dummy/app/views/test/_directory/_partial_with_locales.html.0000644000175000017500000000002213577354001033441 0ustar samyaksamyakHello <%= name %> ruby-rails-controller-testing-1.0.4/test/dummy/app/views/test/hello/0000755000175000017500000000000013577354001025113 5ustar samyaksamyakruby-rails-controller-testing-1.0.4/test/dummy/app/views/test/hello/hello.html.erb0000644000175000017500000000000013577354001027641 0ustar samyaksamyakruby-rails-controller-testing-1.0.4/test/dummy/app/views/layouts/0000755000175000017500000000000013577354001024531 5ustar samyaksamyakruby-rails-controller-testing-1.0.4/test/dummy/app/views/layouts/standard.html.erb0000644000175000017500000000000013577354001027754 0ustar samyaksamyakruby-rails-controller-testing-1.0.4/test/dummy/app/views/layouts/application.html.erb0000644000175000017500000000044713577354001030476 0ustar samyaksamyak Dummy <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %> <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %> <%= csrf_meta_tags %> <%= yield %> ruby-rails-controller-testing-1.0.4/test/dummy/app/mailers/0000755000175000017500000000000013577354001023330 5ustar samyaksamyakruby-rails-controller-testing-1.0.4/test/dummy/app/mailers/.keep0000644000175000017500000000000013577354001024243 0ustar samyaksamyakruby-rails-controller-testing-1.0.4/test/dummy/lib/0000755000175000017500000000000013577354001021662 5ustar samyaksamyakruby-rails-controller-testing-1.0.4/test/dummy/lib/assets/0000755000175000017500000000000013577354001023164 5ustar samyaksamyakruby-rails-controller-testing-1.0.4/test/dummy/lib/assets/.keep0000644000175000017500000000000013577354001024077 0ustar samyaksamyakruby-rails-controller-testing-1.0.4/test/dummy/config/0000755000175000017500000000000013577354001022361 5ustar samyaksamyakruby-rails-controller-testing-1.0.4/test/dummy/config/locales/0000755000175000017500000000000013577354001024003 5ustar samyaksamyakruby-rails-controller-testing-1.0.4/test/dummy/config/locales/en.yml0000644000175000017500000000117213577354001025131 0ustar samyaksamyak# Files in the config/locales directory are used for internationalization # and are automatically loaded by Rails. If you want to use locales other # than English, add the necessary files in this directory. # # To use the locales, use `I18n.t`: # # I18n.t 'hello' # # In views, this is aliased to just `t`: # # <%= t('hello') %> # # To use a different locale, set it with `I18n.locale`: # # I18n.locale = :es # # This would use the information in config/locales/es.yml. # # To learn more, please read the Rails Internationalization guide # available at http://guides.rubyonrails.org/i18n.html. en: hello: "Hello world" ruby-rails-controller-testing-1.0.4/test/dummy/config/initializers/0000755000175000017500000000000013577354001025067 5ustar samyaksamyakruby-rails-controller-testing-1.0.4/test/dummy/config/initializers/session_store.rb0000644000175000017500000000021113577354001030305 0ustar samyaksamyak# Be sure to restart your server when you modify this file. Rails.application.config.session_store :cookie_store, key: '_dummy_session' ruby-rails-controller-testing-1.0.4/test/dummy/config/initializers/backtrace_silencers.rb0000644000175000017500000000062413577354001031404 0ustar samyaksamyak# Be sure to restart your server when you modify this file. # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. # Rails.backtrace_cleaner.remove_silencers! ruby-rails-controller-testing-1.0.4/test/dummy/config/initializers/filter_parameter_logging.rb0000644000175000017500000000030213577354001032442 0ustar samyaksamyak# Be sure to restart your server when you modify this file. # Configure sensitive parameters which will be filtered from the log file. Rails.application.config.filter_parameters += [:password] ruby-rails-controller-testing-1.0.4/test/dummy/config/initializers/assets.rb0000644000175000017500000000075013577354001026720 0ustar samyaksamyak# Be sure to restart your server when you modify this file. # Version of your assets, change this if you want to expire all your assets. # Rails.application.config.assets.version = '1.0' # Add additional assets to the asset load path # Rails.application.config.assets.paths << Emoji.images_path # Precompile additional assets. # application.js, application.css, and all non-JS/CSS in app/assets folder are already added. # Rails.application.config.assets.precompile += %w( search.js ) ruby-rails-controller-testing-1.0.4/test/dummy/config/initializers/mime_types.rb0000644000175000017500000000023413577354001027566 0ustar samyaksamyak# Be sure to restart your server when you modify this file. # Add new mime types for use in respond_to blocks: # Mime::Type.register "text/richtext", :rtf ruby-rails-controller-testing-1.0.4/test/dummy/config/initializers/inflections.rb0000644000175000017500000000120713577354001027731 0ustar samyaksamyak# Be sure to restart your server when you modify this file. # Add new inflection rules using the following format. Inflections # are locale specific, and you may define rules for as many different # locales as you wish. All of these examples are active by default: # ActiveSupport::Inflector.inflections(:en) do |inflect| # inflect.plural /^(ox)$/i, '\1en' # inflect.singular /^(ox)en/i, '\1' # inflect.irregular 'person', 'people' # inflect.uncountable %w( fish sheep ) # end # These inflection rules are supported but not enabled by default: # ActiveSupport::Inflector.inflections(:en) do |inflect| # inflect.acronym 'RESTful' # end ruby-rails-controller-testing-1.0.4/test/dummy/config/initializers/cookies_serializer.rb0000644000175000017500000000020113577354001031272 0ustar samyaksamyak# Be sure to restart your server when you modify this file. Rails.application.config.action_dispatch.cookies_serializer = :json ruby-rails-controller-testing-1.0.4/test/dummy/config/initializers/wrap_parameters.rb0000644000175000017500000000100513577354001030604 0ustar samyaksamyak# Be sure to restart your server when you modify this file. # This file contains settings for ActionController::ParamsWrapper which # is enabled by default. # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. ActiveSupport.on_load(:action_controller) do wrap_parameters format: [:json] if respond_to?(:wrap_parameters) end # To enable root element in JSON for ActiveRecord objects. # ActiveSupport.on_load(:active_record) do # self.include_root_in_json = true # end ruby-rails-controller-testing-1.0.4/test/dummy/config/application.rb0000644000175000017500000000160113577354001025207 0ustar samyaksamyakrequire File.expand_path('../boot', __FILE__) require 'rails/all' Bundler.require(*Rails.groups) require "rails-controller-testing" module Dummy class Application < Rails::Application # Settings in config/environments/* take precedence over those specified here. # Application configuration should go into files in config/initializers # -- all .rb files in that directory are automatically loaded. # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. # config.time_zone = 'Central Time (US & Canada)' # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] # config.i18n.default_locale = :de end end ruby-rails-controller-testing-1.0.4/test/dummy/config/secrets.yml0000644000175000017500000000170413577354001024556 0ustar samyaksamyak# Be sure to restart your server when you modify this file. # Your secret key is used for verifying the integrity of signed cookies. # If you change this key, all old signed cookies will become invalid! # Make sure the secret is at least 30 characters and all random, # no regular words or you'll be exposed to dictionary attacks. # You can use `rake secret` to generate a secure secret key. # Make sure the secrets in this file are kept private # if you're sharing your code publicly. development: secret_key_base: 0c98f262d18c62158146949b3d392a1f04abbb2cdcbcf90ad5b1ad6f8d98307a6aaeccb5508086ed315dce930865e24f46ead5fc2aa3152fa735d14d2e3161de test: secret_key_base: 42f2032a64ab0798dc992d01d1f4637dc4c827a585cac2fbe4066a9d06a8dfdd1b4690761a4095e33f2a54cbc8e3816fb88aac44cb834796ac2a3524f8d2c0a3 # Do not keep production secrets in the repository, # instead read values from the environment. production: secret_key_base: <%= ENV["SECRET_KEY_BASE"] %> ruby-rails-controller-testing-1.0.4/test/dummy/config/database.yml0000644000175000017500000000105013577354001024644 0ustar samyaksamyak# SQLite version 3.x # gem install sqlite3 # # Ensure the SQLite 3 gem is defined in your Gemfile # gem 'sqlite3' # default: &default adapter: sqlite3 pool: 5 timeout: 5000 development: <<: *default database: db/development.sqlite3 # Warning: The database defined as "test" will be erased and # re-generated from your development database when you run "rake". # Do not set this db to the same as development or production. test: <<: *default database: db/test.sqlite3 production: <<: *default database: db/production.sqlite3 ruby-rails-controller-testing-1.0.4/test/dummy/config/boot.rb0000644000175000017500000000036113577354001023651 0ustar samyaksamyak# Set up gems listed in the Gemfile. ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../../Gemfile', __FILE__) require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE']) $LOAD_PATH.unshift File.expand_path('../../../../lib', __FILE__) ruby-rails-controller-testing-1.0.4/test/dummy/config/environments/0000755000175000017500000000000013577354001025110 5ustar samyaksamyakruby-rails-controller-testing-1.0.4/test/dummy/config/environments/production.rb0000644000175000017500000000635013577354001027627 0ustar samyaksamyakRails.application.configure do # Settings specified here will take precedence over those in config/application.rb. # Code is not reloaded between requests. config.cache_classes = true # Eager load code on boot. This eager loads most of Rails and # your application in memory, allowing both threaded web servers # and those relying on copy on write to perform better. # Rake tasks automatically ignore this option for performance. config.eager_load = true # Full error reports are disabled and caching is turned on. config.consider_all_requests_local = false config.action_controller.perform_caching = true # Enable Rack::Cache to put a simple HTTP cache in front of your application # Add `rack-cache` to your Gemfile before enabling this. # For large-scale production use, consider using a caching reverse proxy like # NGINX, varnish or squid. # config.action_dispatch.rack_cache = true # Disable serving static files from the `/public` folder by default since # Apache or NGINX already handles this. config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present? # Compress JavaScripts and CSS. config.assets.js_compressor = :uglifier # config.assets.css_compressor = :sass # Do not fallback to assets pipeline if a precompiled asset is missed. config.assets.compile = false # Asset digests allow you to set far-future HTTP expiration dates on all assets, # yet still be able to expire them through the digest params. config.assets.digest = true # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb # Specifies the header that your server uses for sending files. # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. # config.force_ssl = true # Use the lowest log level to ensure availability of diagnostic information # when problems arise. config.log_level = :debug # Prepend all log lines with the following tags. # config.log_tags = [ :subdomain, :uuid ] # Use a different logger for distributed setups. # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new) # Use a different cache store in production. # config.cache_store = :mem_cache_store # Enable serving of images, stylesheets, and JavaScripts from an asset server. # config.action_controller.asset_host = 'http://assets.example.com' # Ignore bad email addresses and do not raise email delivery errors. # Set this to true and configure the email server for immediate delivery to raise delivery errors. # config.action_mailer.raise_delivery_errors = false # Enable locale fallbacks for I18n (makes lookups for any locale fall back to # the I18n.default_locale when a translation cannot be found). config.i18n.fallbacks = true # Send deprecation notices to registered listeners. config.active_support.deprecation = :notify # Use default logging formatter so that PID and timestamp are not suppressed. config.log_formatter = ::Logger::Formatter.new # Do not dump schema after migrations. config.active_record.dump_schema_after_migration = false end ruby-rails-controller-testing-1.0.4/test/dummy/config/environments/test.rb0000644000175000017500000000305613577354001026420 0ustar samyaksamyakRails.application.configure do # Settings specified here will take precedence over those in config/application.rb. # The test environment is used exclusively to run your application's # test suite. You never need to work with it otherwise. Remember that # your test database is "scratch space" for the test suite and is wiped # and recreated between test runs. Don't rely on the data there! config.cache_classes = true # Do not eager load code on boot. This avoids loading your whole application # just for the purpose of running a single test. If you are using a tool that # preloads Rails for running tests, you may have to set it to true. config.eager_load = false # Configure public file server for tests with Cache-Control for performance. config.public_file_server.enabled = true config.public_file_server.headers = { 'Cache-Control' => 'public, max-age=3600' } # Show full error reports and disable caching. config.consider_all_requests_local = true config.action_controller.perform_caching = false # Raise exceptions instead of rendering exception templates. config.action_dispatch.show_exceptions = false # Disable request forgery protection in test environment. config.action_controller.allow_forgery_protection = false # Randomize the order test cases are executed. config.active_support.test_order = :random # Print deprecation notices to the stderr. config.active_support.deprecation = :stderr # Raises error for missing translations # config.action_view.raise_on_missing_translations = true end ruby-rails-controller-testing-1.0.4/test/dummy/config/environments/development.rb0000644000175000017500000000255313577354001027764 0ustar samyaksamyakRails.application.configure do # Settings specified here will take precedence over those in config/application.rb. # In the development environment your application's code is reloaded on # every request. This slows down response time but is perfect for development # since you don't have to restart the web server when you make code changes. config.cache_classes = false # Do not eager load code on boot. config.eager_load = false # Show full error reports and disable caching. config.consider_all_requests_local = true config.action_controller.perform_caching = false # Print deprecation notices to the Rails logger. config.active_support.deprecation = :log # Debug mode disables concatenation and preprocessing of assets. # This option may cause significant delays in view rendering with a large # number of complex assets. config.assets.debug = true # Asset digests allow you to set far-future HTTP expiration dates on all assets, # yet still be able to expire them through the digest params. config.assets.digest = true # Adds additional error checking when serving assets at runtime. # Checks for improperly declared sprockets dependencies. # Raises helpful error messages. config.assets.raise_runtime_errors = true # Raises error for missing translations # config.action_view.raise_on_missing_translations = true end ruby-rails-controller-testing-1.0.4/test/dummy/config/routes.rb0000644000175000017500000000313713577354001024233 0ustar samyaksamyakRails.application.routes.draw do get ':controller(/:action)' # The priority is based upon order of creation: first created -> highest priority. # See how all your routes lay out with "rake routes". # You can have the root of your site routed with "root" # root 'welcome#index' # Example of regular route: # get 'products/:id' => 'catalog#view' # Example of named route that can be invoked with purchase_url(id: product.id) # get 'products/:id/purchase' => 'catalog#purchase', as: :purchase # Example resource route (maps HTTP verbs to controller actions automatically): # resources :products # Example resource route with options: # resources :products do # member do # get 'short' # post 'toggle' # end # # collection do # get 'sold' # end # end # Example resource route with sub-resources: # resources :products do # resources :comments, :sales # resource :seller # end # Example resource route with more complex sub-resources: # resources :products do # resources :comments # resources :sales do # get 'recent', on: :collection # end # end # Example resource route with concerns: # concern :toggleable do # post 'toggle' # end # resources :posts, concerns: :toggleable # resources :photos, concerns: :toggleable # Example resource route within a namespace: # namespace :admin do # # Directs /admin/products/* to Admin::ProductsController # # (app/controllers/admin/products_controller.rb) # resources :products # end end ruby-rails-controller-testing-1.0.4/test/dummy/config/environment.rb0000644000175000017500000000022613577354001025252 0ustar samyaksamyak# Load the Rails application. require File.expand_path('../application', __FILE__) # Initialize the Rails application. Rails.application.initialize! ruby-rails-controller-testing-1.0.4/test/dummy/log/0000755000175000017500000000000013577354001021675 5ustar samyaksamyakruby-rails-controller-testing-1.0.4/test/dummy/log/.keep0000644000175000017500000000000013577354001022610 0ustar samyaksamyakruby-rails-controller-testing-1.0.4/test/dummy/README.rdoc0000644000175000017500000000073613577354001022730 0ustar samyaksamyak== README This README would normally document whatever steps are necessary to get the application up and running. Things you may want to cover: * Ruby version * System dependencies * Configuration * Database creation * Database initialization * How to run the test suite * Services (job queues, cache servers, search engines, etc.) * Deployment instructions * ... Please feel free to use a different markup language if you do not plan to run rake doc:app. ruby-rails-controller-testing-1.0.4/test/integration/0000755000175000017500000000000013577354001022304 5ustar samyaksamyakruby-rails-controller-testing-1.0.4/test/integration/template_assertions_test.rb0000644000175000017500000000512413577354001027757 0ustar samyaksamyakrequire 'test_helper' class TemplateAssertionsIntegrationTest < ActionDispatch::IntegrationTest def test_template_reset_between_requests get '/template_assertions/render_with_template' assert_template 'test/hello_world' get '/template_assertions/render_nothing' assert_template nil end def test_partial_reset_between_requests get '/template_assertions/render_with_partial' assert_template partial: 'test/_partial' get '/template_assertions/render_nothing' assert_template partial: nil end def test_layout_reset_between_requests get '/template_assertions/render_with_layout' assert_template layout: 'layouts/standard' get '/template_assertions/render_nothing' assert_template layout: nil end def test_file_reset_between_requests get '/template_assertions/render_file_relative_path' assert_template file: 'README.rdoc' get '/template_assertions/render_nothing' assert_template file: nil end def test_template_reset_between_requests_when_opening_a_session open_session do |session| session.get '/template_assertions/render_with_template' session.assert_template 'test/hello_world' session.get '/template_assertions/render_nothing' session.assert_template nil end end def test_partial_reset_between_requests_when_opening_a_session open_session do |session| session.get '/template_assertions/render_with_partial' session.assert_template partial: 'test/_partial' session.get '/template_assertions/render_nothing' session.assert_template partial: nil end end def test_layout_reset_between_requests_when_opening_a_session open_session do |session| session.get '/template_assertions/render_with_layout' session.assert_template layout: 'layouts/standard' session.get '/template_assertions/render_nothing' session.assert_template layout: nil end end def test_file_reset_between_requests_when_opening_a_session open_session do |session| session.get '/template_assertions/render_file_relative_path' session.assert_template file: 'README.rdoc' session.get '/template_assertions/render_nothing' session.assert_template file: nil end end def test_assigns_do_not_reset_template_assertion get '/template_assertions/render_with_layout' assert_equal 'hello', assigns(:variable_for_layout) assert_template layout: 'layouts/standard' end def test_cookies_do_not_reset_template_assertion get '/template_assertions/render_with_layout' cookies assert_template layout: 'layouts/standard' end end ruby-rails-controller-testing-1.0.4/Gemfile0000644000175000017500000000004613577354001020275 0ustar samyaksamyaksource 'https://rubygems.org' gemspec ruby-rails-controller-testing-1.0.4/.gitignore0000644000175000017500000000023713577354001020774 0ustar samyaksamyak.bundle/ log/*.log pkg/ test/dummy/db/*.sqlite3 test/dummy/db/*.sqlite3-journal test/dummy/log/*.log test/dummy/tmp/ test/dummy/.sass-cache *.gem Gemfile.lock ruby-rails-controller-testing-1.0.4/README.md0000644000175000017500000000434513577354001020267 0ustar samyaksamyak# Rails::Controller::Testing This gem brings back `assigns` to your controller tests as well as `assert_template` to both controller and integration tests. Note: This gem is only useful once `assigns` and `assert_template` have been removed from Rails. ## Installation Add this line to your application's Gemfile: gem 'rails-controller-testing' And then execute: $ bundle Or install it yourself as: $ gem install rails-controller-testing ### RSpec See https://github.com/rspec/rspec-rails/issues/1393. rspec-rails automatically integrates with this gem since version `3.5.0`. Adding the gem to your `Gemfile` is sufficient. If you use an older version of rspec-rails, you can manually include the modules in your `rails_helper`. ```ruby RSpec.configure do |config| [:controller, :view, :request].each do |type| config.include ::Rails::Controller::Testing::TestProcess, :type => type config.include ::Rails::Controller::Testing::TemplateAssertions, :type => type config.include ::Rails::Controller::Testing::Integration, :type => type end end ``` ## Outside Rails For projects and gems using controller tests outside of a Rails application, invoke the `Rails::Controller::Testing.install` method inside your test suite setup to include the required modules on controller test cases. ```ruby # test/test_helper.rb require 'rails-controller-testing' Rails::Controller::Testing.install ``` ## Usage ### assigns `assigns` allows you to access the instance variables that have been passed to your views. ```ruby class PostsController < ActionController::Base def index @posts = Post.all end end class PostControllerTest < ActionController::TestCase def test_index get :index assert_equal Post.all, assigns(:posts) end end ``` ### assert_template `assert_template` allows to you assert that certain templates have been rendered. ```ruby class PostControllerTest < ActionController::TestCase def test_index get :index assert_template 'posts/index' end end ``` ## Contributing 1. Fork it 2. Create your feature branch (`git checkout -b my-new-feature`) 3. Commit your changes (`git commit -am 'Add some feature'`) 4. Push to the branch (`git push origin my-new-feature`) 5. Create new Pull Request ruby-rails-controller-testing-1.0.4/CONTRIBUTING.md0000644000175000017500000000555713577354001021247 0ustar samyaksamyakContributing to Rails::Controller::Testing ===================== [![Build Status](https://travis-ci.org/rails/rails-controller-testing.svg?branch=master)](https://travis-ci.org/rails/rails-controller-testing) Rails::Controller::Testing is work of [many contributors](https://github.com/rails/rails-controller-testing/graphs/contributors). You're encouraged to submit [pull requests](https://github.com/rails/rails-controller-testing/pulls), [propose features and discuss issues](https://github.com/rails/rails-controller-testing/issues). #### Fork the Project Fork the [project on Github](https://github.com/rails/rails-controller-testing) and check out your copy. ``` git clone https://github.com/contributor/rails-controller-testing.git cd rails-controller-testing git remote add upstream https://github.com/rails/rails-controller-testing.git ``` #### Create a Topic Branch Make sure your fork is up-to-date and create a topic branch for your feature or bug fix. ``` git checkout master git pull upstream master git checkout -b my-feature-branch ``` #### Bundle Install and Test Ensure that you can build the project and run tests. ``` bundle install bundle exec rake test ``` #### Write Tests Try to write a test that reproduces the problem you're trying to fix or describes a feature that you want to build. Add to [test](test). We definitely appreciate pull requests that highlight or reproduce a problem, even without a fix. #### Write Code Implement your feature or bug fix. Make sure that `bundle exec rake test` completes without errors. #### Write Documentation Document any external behavior in the [README](README.md). #### Commit Changes Make sure git knows your name and email address: ``` git config --global user.name "Your Name" git config --global user.email "contributor@example.com" ``` Writing good commit logs is important. A commit log should describe what changed and why. ``` git add ... git commit ``` #### Push ``` git push origin my-feature-branch ``` #### Make a Pull Request Go to https://github.com/contributor/rails-controller-testing and select your feature branch. Click the 'Pull Request' button and fill out the form. Pull requests are usually reviewed within a few days. #### Rebase If you've been working on a change for a while, rebase with upstream/master. ``` git fetch upstream git rebase upstream/master git push origin my-feature-branch -f ``` #### Check on Your Pull Request Go back to your pull request after a few minutes and see whether it passed muster with Travis-CI. Everything should look green, otherwise fix issues and amend your commit as described above. #### Be Patient It's likely that your change will not be merged and that the nitpicky maintainers will ask you to do more, or fix seemingly benign problems. Hang on there! #### Thank You Please do know that we really appreciate and value your time and work. We love you, really. ruby-rails-controller-testing-1.0.4/rails-controller-testing.gemspec0000644000175000017500000000207113577354001025315 0ustar samyaksamyak$:.push File.expand_path("../lib", __FILE__) # Maintain your gem's version: require "rails/controller/testing/version" # Describe your gem and declare its dependencies: Gem::Specification.new do |s| s.name = "rails-controller-testing" s.version = Rails::Controller::Testing::VERSION s.authors = ["Rails Core Team"] s.homepage = "https://github.com/rails/rails-controller-testing" s.summary = "Extracting `assigns` and `assert_template` from ActionDispatch." s.license = "MIT" s.files = Dir["{lib}/**/*", "LICENSE", "Rakefile", "README.md"] s.test_files = Dir["test/**/*"] s.require_path = ['lib'] s.required_ruby_version = '>= 2.2.2' s.add_dependency "actionpack", ">= 5.0.1.x" s.add_dependency "actionview", ">= 5.0.1.x" s.add_dependency "activesupport", ">= 5.0.1.x" s.add_development_dependency "railties", "> 5.0.1.x" if defined?(JRUBY_VERSION) s.add_development_dependency "jdbc-sqlite3" s.add_development_dependency "activerecord-jdbc-adapter" else s.add_development_dependency "sqlite3" end end ruby-rails-controller-testing-1.0.4/gemfiles/0000755000175000017500000000000013577354001020575 5ustar samyaksamyakruby-rails-controller-testing-1.0.4/gemfiles/Gemfile-rails-5-10000644000175000017500000000011713577354001023477 0ustar samyaksamyaksource 'https://rubygems.org' gemspec path: '..' gem 'actionpack', '~> 5.1.0' ruby-rails-controller-testing-1.0.4/gemfiles/Gemfile-rails-5-20000644000175000017500000000011613577354001023477 0ustar samyaksamyaksource 'https://rubygems.org' gemspec path: '..' gem 'actionpack', '~> 5.2.0'ruby-rails-controller-testing-1.0.4/gemfiles/Gemfile-rails-5-00000644000175000017500000000011713577354001023476 0ustar samyaksamyaksource 'https://rubygems.org' gemspec path: '..' gem 'actionpack', '~> 5.0.1' ruby-rails-controller-testing-1.0.4/gemfiles/Gemfile-rails-master0000644000175000017500000000015613577354001024473 0ustar samyaksamyaksource 'https://rubygems.org' gemspec path: '..' gem 'actionpack', git: "https://github.com/rails/rails.git" ruby-rails-controller-testing-1.0.4/lib/0000755000175000017500000000000013577354001017550 5ustar samyaksamyakruby-rails-controller-testing-1.0.4/lib/rails-controller-testing.rb0000644000175000017500000000022513577354001025042 0ustar samyaksamyakrequire 'rails/controller/testing' require 'rails/controller/testing/railtie' if defined?(Rails::Railtie) require 'rails/controller/testing/version' ruby-rails-controller-testing-1.0.4/lib/rails/0000755000175000017500000000000013577354001020662 5ustar samyaksamyakruby-rails-controller-testing-1.0.4/lib/rails/controller/0000755000175000017500000000000013577354001023045 5ustar samyaksamyakruby-rails-controller-testing-1.0.4/lib/rails/controller/testing.rb0000644000175000017500000000157213577354001025054 0ustar samyaksamyakrequire 'active_support/lazy_load_hooks' require 'rails/controller/testing/test_process' require 'rails/controller/testing/integration' require 'rails/controller/testing/template_assertions' module Rails module Controller module Testing def self.install ActiveSupport.on_load(:action_controller_test_case) do include Rails::Controller::Testing::TestProcess include Rails::Controller::Testing::TemplateAssertions end ActiveSupport.on_load(:action_dispatch_integration_test) do include Rails::Controller::Testing::TemplateAssertions include Rails::Controller::Testing::Integration include Rails::Controller::Testing::TestProcess end ActiveSupport.on_load(:action_view_test_case) do include Rails::Controller::Testing::TemplateAssertions end end end end end ruby-rails-controller-testing-1.0.4/lib/rails/controller/testing/0000755000175000017500000000000013577354001024522 5ustar samyaksamyakruby-rails-controller-testing-1.0.4/lib/rails/controller/testing/railtie.rb0000644000175000017500000000023013577354001026473 0ustar samyaksamyakclass Rails::Controller::Testing::Railtie < Rails::Railtie initializer "rails_controller_testing" do Rails::Controller::Testing.install end end ruby-rails-controller-testing-1.0.4/lib/rails/controller/testing/template_assertions.rb0000644000175000017500000001675013577354001031145 0ustar samyaksamyakrequire 'active_support/concern' module Rails module Controller module Testing module TemplateAssertions extend ActiveSupport::Concern included do setup :setup_subscriptions teardown :teardown_subscriptions end RENDER_TEMPLATE_INSTANCE_VARIABLES = %w{partials templates layouts files}.freeze def setup_subscriptions RENDER_TEMPLATE_INSTANCE_VARIABLES.each do |instance_variable| instance_variable_set("@_#{instance_variable}", Hash.new(0)) end @_subscribers = [] @_subscribers << ActiveSupport::Notifications.subscribe("render_template.action_view") do |_name, _start, _finish, _id, payload| path = payload[:layout] if path @_layouts[path] += 1 if path =~ /^layouts\/(.*)/ @_layouts[$1] += 1 end end end @_subscribers << ActiveSupport::Notifications.subscribe("!render_template.action_view") do |_name, _start, _finish, _id, payload| if virtual_path = payload[:virtual_path] partial = virtual_path =~ /^.*\/_[^\/]*$/ if partial @_partials[virtual_path] += 1 @_partials[virtual_path.split("/").last] += 1 end @_templates[virtual_path] += 1 else path = payload[:identifier] if path @_files[path] += 1 @_files[path.split("/").last] += 1 end end end end def teardown_subscriptions @_subscribers.each do |subscriber| ActiveSupport::Notifications.unsubscribe(subscriber) end end def process(*args) reset_template_assertion super end def reset_template_assertion RENDER_TEMPLATE_INSTANCE_VARIABLES.each do |instance_variable| ivar_name = "@_#{instance_variable}" if instance_variable_defined?(ivar_name) instance_variable_get(ivar_name).clear end end end # Asserts that the request was rendered with the appropriate template file or partials. # # # assert that the "new" view template was rendered # assert_template "new" # # # assert that the exact template "admin/posts/new" was rendered # assert_template %r{\Aadmin/posts/new\Z} # # # assert that the layout 'admin' was rendered # assert_template layout: 'admin' # assert_template layout: 'layouts/admin' # assert_template layout: :admin # # # assert that no layout was rendered # assert_template layout: nil # assert_template layout: false # # # assert that the "_customer" partial was rendered twice # assert_template partial: '_customer', count: 2 # # # assert that no partials were rendered # assert_template partial: false # # # assert that a file was rendered # assert_template file: "README.rdoc" # # # assert that no file was rendered # assert_template file: nil # assert_template file: false # # In a view test case, you can also assert that specific locals are passed # to partials: # # # assert that the "_customer" partial was rendered with a specific object # assert_template partial: '_customer', locals: { customer: @customer } def assert_template(options = {}, message = nil) # Force body to be read in case the template is being streamed. response.body case options when NilClass, Regexp, String, Symbol options = options.to_s if Symbol === options rendered = @_templates msg = message || sprintf("expecting <%s> but rendering with <%s>", options.inspect, rendered.keys) matches_template = case options when String !options.empty? && rendered.any? do |t, num| options_splited = options.split(File::SEPARATOR) t_splited = t.split(File::SEPARATOR) t_splited.last(options_splited.size) == options_splited end when Regexp rendered.any? { |t,num| t.match(options) } when NilClass rendered.blank? end assert matches_template, msg when Hash options.assert_valid_keys(:layout, :partial, :locals, :count, :file) if options.key?(:layout) expected_layout = options[:layout] msg = message || sprintf("expecting layout <%s> but action rendered <%s>", expected_layout, @_layouts.keys) case expected_layout when String, Symbol assert_includes @_layouts.keys, expected_layout.to_s, msg when Regexp assert(@_layouts.keys.any? {|l| l =~ expected_layout }, msg) when nil, false assert(@_layouts.empty?, msg) else raise ArgumentError, "assert_template only accepts a String, Symbol, Regexp, nil or false for :layout" end end if options[:file] assert_includes @_files.keys, options[:file] elsif options.key?(:file) assert @_files.blank?, "expected no files but #{@_files.keys} was rendered" end if expected_partial = options[:partial] if expected_locals = options[:locals] if defined?(@_rendered_views) view = expected_partial.to_s.sub(/^_/, '').sub(/\/_(?=[^\/]+\z)/, '/') partial_was_not_rendered_msg = "expected %s to be rendered but it was not." % view assert_includes @_rendered_views.rendered_views, view, partial_was_not_rendered_msg msg = 'expecting %s to be rendered with %s but was with %s' % [expected_partial, expected_locals, @_rendered_views.locals_for(view)] assert(@_rendered_views.view_rendered?(view, options[:locals]), msg) else warn "the :locals option to #assert_template is only supported in a ActionView::TestCase" end elsif expected_count = options[:count] actual_count = @_partials[expected_partial] msg = message || sprintf("expecting %s to be rendered %s time(s) but rendered %s time(s)", expected_partial, expected_count, actual_count) assert(actual_count == expected_count.to_i, msg) else msg = message || sprintf("expecting partial <%s> but action rendered <%s>", options[:partial], @_partials.keys) assert_includes @_partials, expected_partial, msg end elsif options.key?(:partial) assert @_partials.empty?, "Expected no partials to be rendered" end else raise ArgumentError, "assert_template only accepts a String, Symbol, Hash, Regexp, or nil" end end end end end end ruby-rails-controller-testing-1.0.4/lib/rails/controller/testing/version.rb0000644000175000017500000000013613577354001026534 0ustar samyaksamyakmodule Rails module Controller module Testing VERSION = "1.0.4" end end end ruby-rails-controller-testing-1.0.4/lib/rails/controller/testing/integration.rb0000644000175000017500000000074613577354001027401 0ustar samyaksamyakrequire 'action_pack' module Rails module Controller module Testing module Integration http_verbs = %w(get post patch put head delete get_via_redirect post_via_redirect) http_verbs.push('xhr', 'xml_http_request') if ActionPack.version < Gem::Version.new('5.1') http_verbs.each do |method| define_method(method) do |*args| reset_template_assertion super(*args) end end end end end end ruby-rails-controller-testing-1.0.4/lib/rails/controller/testing/test_process.rb0000644000175000017500000000057213577354001027570 0ustar samyaksamyakrequire 'active_support/core_ext/hash/indifferent_access' module Rails module Controller module Testing module TestProcess def assigns(key = nil) assigns = {}.with_indifferent_access @controller.view_assigns.each { |k, v| assigns.regular_writer(k, v) } key.nil? ? assigns : assigns[key] end end end end end ruby-rails-controller-testing-1.0.4/.github/0000755000175000017500000000000013577354001020342 5ustar samyaksamyakruby-rails-controller-testing-1.0.4/.github/no-response.yml0000644000175000017500000000120413577354001023332 0ustar samyaksamyak# Configuration for probot-no-response - https://github.com/probot/no-response # Number of days of inactivity before an Issue is closed for lack of response daysUntilClose: 14 # Label requiring a response responseRequiredLabel: more-information-needed # Comment to post when closing an Issue for lack of response. Set to `false` to disable closeComment: > This issue has been automatically closed because there has been no follow-up response from the original author. We currently don't have enough information in order to take action. Please reach out if you have any additional information that will help us move this issue forward.