diff options
Diffstat (limited to 'railties/test')
-rw-r--r-- | railties/test/application/configuration/custom_test.rb | 7 | ||||
-rw-r--r-- | railties/test/application/configuration_test.rb | 2 | ||||
-rw-r--r-- | railties/test/application/middleware/session_test.rb | 6 | ||||
-rw-r--r-- | railties/test/application/rake/notes_test.rb | 12 | ||||
-rw-r--r-- | railties/test/backtrace_cleaner_test.rb | 24 | ||||
-rw-r--r-- | railties/test/generators/app_generator_test.rb | 87 | ||||
-rw-r--r-- | railties/test/generators/plugin_generator_test.rb | 81 | ||||
-rw-r--r-- | railties/test/generators/shared_generator_tests.rb | 35 | ||||
-rw-r--r-- | railties/test/initializable_test.rb | 5 |
9 files changed, 149 insertions, 110 deletions
diff --git a/railties/test/application/configuration/custom_test.rb b/railties/test/application/configuration/custom_test.rb index 28b3b2f2d6..3e0db6fad8 100644 --- a/railties/test/application/configuration/custom_test.rb +++ b/railties/test/application/configuration/custom_test.rb @@ -33,6 +33,13 @@ module ApplicationTests assert_nil x.i_do_not_exist.zomg end + test 'custom configuration responds to all messages' do + x = Rails.configuration.x + assert_equal true, x.respond_to?(:i_do_not_exist) + assert_kind_of Method, x.method(:i_do_not_exist) + assert_kind_of ActiveSupport::OrderedOptions, x.i_do_not_exist + end + private def new_app File.expand_path("#{app_path}/../new_app") diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index 7ec25aeca1..57f8b09c36 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -1088,7 +1088,7 @@ module ApplicationTests assert_equal %w( controller action format ), ActionController::Parameters.always_permitted_parameters end - test "config.action_controller.always_permitted_parameters = ['controller','action','format'] does not raise exeception" do + test "config.action_controller.always_permitted_parameters = ['controller','action','format'] does not raise exception" do app_file 'app/controllers/posts_controller.rb', <<-RUBY class PostsController < ActionController::Base def create diff --git a/railties/test/application/middleware/session_test.rb b/railties/test/application/middleware/session_test.rb index 85e7761727..6ea7cad201 100644 --- a/railties/test/application/middleware/session_test.rb +++ b/railties/test/application/middleware/session_test.rb @@ -373,5 +373,11 @@ module ApplicationTests refute Rails.application.middleware.include?(ActionDispatch::Flash) end + + test "cookie_only is set to true even if user tries to overwrite it" do + add_to_config "config.session_store :cookie_store, key: '_myapp_session', cookie_only: false" + require "#{app_path}/config/environment" + assert app.config.session_options[:cookie_only], "Expected cookie_only to be set to true" + end end end diff --git a/railties/test/application/rake/notes_test.rb b/railties/test/application/rake/notes_test.rb index 50def9beb0..a94e302099 100644 --- a/railties/test/application/rake/notes_test.rb +++ b/railties/test/application/rake/notes_test.rb @@ -126,6 +126,18 @@ module ApplicationTests end end + test 'register additional directories' do + app_file "spec/spec_helper.rb", "# TODO: note in spec" + app_file "spec/models/user_spec.rb", "# TODO: note in model spec" + add_to_config %q{ config.annotations.register_directories("spec") } + + run_rake_notes do |output, lines| + assert_match(/note in spec/, output) + assert_match(/note in model spec/, output) + assert_equal 2, lines.size + end + end + private def run_rake_notes(command = 'bin/rails notes') diff --git a/railties/test/backtrace_cleaner_test.rb b/railties/test/backtrace_cleaner_test.rb index 2dd74f8fd1..1b23b0de91 100644 --- a/railties/test/backtrace_cleaner_test.rb +++ b/railties/test/backtrace_cleaner_test.rb @@ -1,24 +1,32 @@ require 'abstract_unit' require 'rails/backtrace_cleaner' -class BacktraceCleanerVendorGemTest < ActiveSupport::TestCase +class BacktraceCleanerTest < ActiveSupport::TestCase def setup @cleaner = Rails::BacktraceCleaner.new end test "should format installed gems correctly" do - @backtrace = [ "#{Gem.path[0]}/gems/nosuchgem-1.2.3/lib/foo.rb" ] - @result = @cleaner.clean(@backtrace, :all) - assert_equal "nosuchgem (1.2.3) lib/foo.rb", @result[0] + backtrace = [ "#{Gem.path[0]}/gems/nosuchgem-1.2.3/lib/foo.rb" ] + result = @cleaner.clean(backtrace, :all) + assert_equal "nosuchgem (1.2.3) lib/foo.rb", result[0] end test "should format installed gems not in Gem.default_dir correctly" do - @target_dir = Gem.path.detect { |p| p != Gem.default_dir } + target_dir = Gem.path.detect { |p| p != Gem.default_dir } # skip this test if default_dir is the only directory on Gem.path if @target_dir - @backtrace = [ "#{@target_dir}/gems/nosuchgem-1.2.3/lib/foo.rb" ] - @result = @cleaner.clean(@backtrace, :all) - assert_equal "nosuchgem (1.2.3) lib/foo.rb", @result[0] + backtrace = [ "#{target_dir}/gems/nosuchgem-1.2.3/lib/foo.rb" ] + result = @cleaner.clean(backtrace, :all) + assert_equal "nosuchgem (1.2.3) lib/foo.rb", result[0] end end + + test "should consider traces from irb lines as User code" do + backtrace = [ "from (irb):1", + "from /Path/to/rails/railties/lib/rails/commands/console.rb:77:in `start'", + "from bin/rails:4:in `<main>'" ] + result = @cleaner.clean(backtrace, :all) + assert_equal "from (irb):1", result[0] + end end diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 058308aa13..ac1488abb3 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -597,6 +597,21 @@ class AppGeneratorTest < Rails::Generators::TestCase end end + def test_generation_runs_bundle_install + assert_generates_with_bundler + end + + def test_dev_option + assert_generates_with_bundler dev: true + rails_path = File.expand_path('../../..', Rails.root) + assert_file 'Gemfile', /^gem\s+["']rails["'],\s+path:\s+["']#{Regexp.escape(rails_path)}["']$/ + end + + def test_edge_option + assert_generates_with_bundler edge: true + assert_file 'Gemfile', %r{^gem\s+["']rails["'],\s+github:\s+["']#{Regexp.escape("rails/rails")}["'],\s+branch:\s+["']#{Regexp.escape("5-0-stable")}["']$} + end + def test_spring run_generator assert_gem 'spring' @@ -754,41 +769,61 @@ class AppGeneratorTest < Rails::Generators::TestCase protected - def stub_rails_application(root) - Rails.application.config.root = root - Rails.application.class.stub(:name, "Myapp") do - yield + def stub_rails_application(root) + Rails.application.config.root = root + Rails.application.class.stub(:name, "Myapp") do + yield + end end - end - def action(*args, &block) - capture(:stdout) { generator.send(*args, &block) } - end + def action(*args, &block) + capture(:stdout) { generator.send(*args, &block) } + end - def assert_gem(gem, constraint = nil) - if constraint - assert_file "Gemfile", /^\s*gem\s+["']#{gem}["'], #{constraint}$*/ - else - assert_file "Gemfile", /^\s*gem\s+["']#{gem}["']$*/ + def assert_gem(gem, constraint = nil) + if constraint + assert_file "Gemfile", /^\s*gem\s+["']#{gem}["'], #{constraint}$*/ + else + assert_file "Gemfile", /^\s*gem\s+["']#{gem}["']$*/ + end end - end - def assert_listen_related_configuration - assert_gem 'listen' - assert_gem 'spring-watcher-listen' + def assert_listen_related_configuration + assert_gem 'listen' + assert_gem 'spring-watcher-listen' - assert_file 'config/environments/development.rb' do |content| - assert_match(/^\s*config.file_watcher = ActiveSupport::EventedFileUpdateChecker/, content) + assert_file 'config/environments/development.rb' do |content| + assert_match(/^\s*config.file_watcher = ActiveSupport::EventedFileUpdateChecker/, content) + end end - end - def assert_no_listen_related_configuration - assert_file 'Gemfile' do |content| - assert_no_match(/listen/, content) + def assert_no_listen_related_configuration + assert_file 'Gemfile' do |content| + assert_no_match(/listen/, content) + end + + assert_file 'config/environments/development.rb' do |content| + assert_match(/^\s*# config.file_watcher = ActiveSupport::EventedFileUpdateChecker/, content) + end end - assert_file 'config/environments/development.rb' do |content| - assert_match(/^\s*# config.file_watcher = ActiveSupport::EventedFileUpdateChecker/, content) + def assert_generates_with_bundler(options = {}) + generator([destination_root], options) + + command_check = -> command do + @install_called ||= 0 + + case command + when 'install' + @install_called += 1 + assert_equal 1, @install_called, "install expected to be called once, but was called #{@install_called} times" + when 'exec spring binstub --all' + # Called when running tests with spring, let through unscathed. + end + end + + generator.stub :bundle_command, command_check do + quietly { generator.invoke_all } + end end - end end diff --git a/railties/test/generators/plugin_generator_test.rb b/railties/test/generators/plugin_generator_test.rb index 5dd4cce28a..823dcc50ee 100644 --- a/railties/test/generators/plugin_generator_test.rb +++ b/railties/test/generators/plugin_generator_test.rb @@ -193,13 +193,24 @@ class PluginGeneratorTest < Rails::Generators::TestCase assert_file "test/dummy/config/database.yml", /postgres/ end - def test_generation_runs_bundle_install_with_full_and_mountable - result = run_generator [destination_root, "--mountable", "--full", "--dev"] - assert_match(/run bundle install/, result) - assert $?.success?, "Command failed: #{result}" - assert_file "#{destination_root}/Gemfile.lock" do |contents| - assert_match(/bukkits/, contents) - end + def test_generation_runs_bundle_install + assert_generates_without_bundler + end + + def test_dev_option + assert_generates_without_bundler(dev: true) + rails_path = File.expand_path('../../..', Rails.root) + assert_file 'Gemfile', /^gem\s+["']rails["'],\s+path:\s+["']#{Regexp.escape(rails_path)}["']$/ + end + + def test_edge_option + assert_generates_without_bundler(edge: true) + assert_file 'Gemfile', %r{^gem\s+["']rails["'],\s+github:\s+["']#{Regexp.escape("rails/rails")}["'],\s+branch:\s+["']#{Regexp.escape("5-0-stable")}["']$} + end + + def test_generation_does_not_run_bundle_install_with_full_and_mountable + assert_generates_without_bundler(mountable: true, full: true, dev: true) + assert_no_file "#{destination_root}/Gemfile.lock" end def test_skipping_javascripts_without_mountable_option @@ -697,48 +708,38 @@ class PluginGeneratorTest < Rails::Generators::TestCase end end - def test_after_bundle_callback - path = 'http://example.org/rails_template' - template = %{ after_bundle { run 'echo ran after_bundle' } } - template.instance_eval "def read; self; end" # Make the string respond to read + protected - check_open = -> *args do - assert_equal [ path, 'Accept' => 'application/x-thor-template' ], args - template + def action(*args, &block) + silence(:stdout){ generator.send(*args, &block) } end - sequence = ['install', 'echo ran after_bundle'] - @sequence_step ||= 0 - ensure_bundler_first = -> command do - assert_equal sequence[@sequence_step], command, "commands should be called in sequence #{sequence}" - @sequence_step += 1 + def default_files + ::DEFAULT_PLUGIN_FILES end - generator([destination_root], template: path).stub(:open, check_open, template) do - generator.stub(:bundle_command, ensure_bundler_first) do - generator.stub(:run, ensure_bundler_first) do - quietly { generator.invoke_all } - end + def assert_match_sqlite3(contents) + if defined?(JRUBY_VERSION) + assert_match(/group :development do\n gem 'activerecord-jdbcsqlite3-adapter'\nend/, contents) + else + assert_match(/group :development do\n gem 'sqlite3'\nend/, contents) end end - assert_equal 2, @sequence_step - end + def assert_generates_without_bundler(options = {}) + generator([destination_root], options) -protected - def action(*args, &block) - silence(:stdout){ generator.send(*args, &block) } - end - - def default_files - ::DEFAULT_PLUGIN_FILES - end + command_check = -> command do + case command + when 'install' + flunk "install expected to not be called" + when 'exec spring binstub --all' + # Called when running tests with spring, let through unscathed. + end + end - def assert_match_sqlite3(contents) - if defined?(JRUBY_VERSION) - assert_match(/group :development do\n gem 'activerecord-jdbcsqlite3-adapter'\nend/, contents) - else - assert_match(/group :development do\n gem 'sqlite3'\nend/, contents) + generator.stub :bundle_command, command_check do + quietly { generator.invoke_all } + end end - end end diff --git a/railties/test/generators/shared_generator_tests.rb b/railties/test/generators/shared_generator_tests.rb index e83d54890a..03ea521355 100644 --- a/railties/test/generators/shared_generator_tests.rb +++ b/railties/test/generators/shared_generator_tests.rb @@ -26,30 +26,6 @@ module SharedGeneratorTests default_files.each { |path| assert_file path } end - def assert_generates_with_bundler(options = {}) - generator([destination_root], options) - - command_check = -> command do - @install_called ||= 0 - - case command - when 'install' - @install_called += 1 - assert_equal 1, @install_called, "install expected to be called once, but was called #{@install_called} times" - when 'exec spring binstub --all' - # Called when running tests with spring, let through unscathed. - end - end - - generator.stub :bundle_command, command_check do - quietly { generator.invoke_all } - end - end - - def test_generation_runs_bundle_install - assert_generates_with_bundler - end - def test_plugin_new_generate_pretend run_generator ["testapp", "--pretend"] default_files.each{ |path| assert_no_file File.join("testapp",path) } @@ -114,17 +90,6 @@ module SharedGeneratorTests end end - def test_dev_option - assert_generates_with_bundler dev: true - rails_path = File.expand_path('../../..', Rails.root) - assert_file 'Gemfile', /^gem\s+["']rails["'],\s+path:\s+["']#{Regexp.escape(rails_path)}["']$/ - end - - def test_edge_option - assert_generates_with_bundler edge: true - assert_file 'Gemfile', %r{^gem\s+["']rails["'],\s+github:\s+["']#{Regexp.escape("rails/rails")}["']$} - end - def test_skip_gemfile assert_not_called(generator([destination_root], skip_gemfile: true), :bundle_command) do quietly { generator.invoke_all } diff --git a/railties/test/initializable_test.rb b/railties/test/initializable_test.rb index ed9573453b..d4eafebfa4 100644 --- a/railties/test/initializable_test.rb +++ b/railties/test/initializable_test.rb @@ -174,6 +174,11 @@ module InitializableTests end end end + + test "Initializer provides context's class name" do + foo = Foo.new + assert_equal foo.class, foo.initializers.first.context_class + end end class BeforeAfter < ActiveSupport::TestCase |