aboutsummaryrefslogtreecommitdiffstats
path: root/railties/test
diff options
context:
space:
mode:
Diffstat (limited to 'railties/test')
-rw-r--r--railties/test/application/configuration_test.rb64
-rw-r--r--railties/test/application/test_runner_test.rb16
-rw-r--r--railties/test/commands/server_test.rb6
-rw-r--r--railties/test/generators/app_generator_test.rb7
-rw-r--r--railties/test/generators_test.rb1
5 files changed, 90 insertions, 4 deletions
diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb
index 886fb0f843..8eaf07586e 100644
--- a/railties/test/application/configuration_test.rb
+++ b/railties/test/application/configuration_test.rb
@@ -331,7 +331,7 @@ module ApplicationTests
assert_not_includes Post.instance_methods, :title
end
- test "eager loads attribute methods in production" do
+ test "does not eager load attribute methods in production when the schema cache is empty" do
app_file "app/models/post.rb", <<-RUBY
class Post < ActiveRecord::Base
end
@@ -354,9 +354,71 @@ module ApplicationTests
app "production"
+ assert_not_includes Post.instance_methods, :title
+ end
+
+ test "eager loads attribute methods in production when the schema cache is populated" do
+ app_file "app/models/post.rb", <<-RUBY
+ class Post < ActiveRecord::Base
+ end
+ RUBY
+
+ app_file "config/initializers/active_record.rb", <<-RUBY
+ ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")
+ ActiveRecord::Migration.verbose = false
+ ActiveRecord::Schema.define(version: 1) do
+ create_table :posts do |t|
+ t.string :title
+ end
+ end
+ RUBY
+
+ add_to_config <<-RUBY
+ config.eager_load = true
+ config.cache_classes = true
+ RUBY
+
+ app_file "config/initializers/schema_cache.rb", <<-RUBY
+ ActiveRecord::Base.connection.schema_cache.add("posts")
+ RUBY
+
+ app "production"
+
assert_includes Post.instance_methods, :title
end
+ test "does not attempt to eager load attribute methods for models that aren't connected" do
+ app_file "app/models/post.rb", <<-RUBY
+ class Post < ActiveRecord::Base
+ end
+ RUBY
+
+ app_file "config/initializers/active_record.rb", <<-RUBY
+ ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")
+ ActiveRecord::Migration.verbose = false
+ ActiveRecord::Schema.define(version: 1) do
+ create_table :posts do |t|
+ t.string :title
+ end
+ end
+ RUBY
+
+ add_to_config <<-RUBY
+ config.eager_load = true
+ config.cache_classes = true
+ RUBY
+
+ app_file "app/models/comment.rb", <<-RUBY
+ class Comment < ActiveRecord::Base
+ establish_connection(adapter: "mysql2", database: "does_not_exist")
+ end
+ RUBY
+
+ assert_nothing_raised do
+ app "production"
+ end
+ end
+
test "initialize an eager loaded, cache classes app" do
add_to_config <<-RUBY
config.eager_load = true
diff --git a/railties/test/application/test_runner_test.rb b/railties/test/application/test_runner_test.rb
index 55ce72181f..6765eef9d0 100644
--- a/railties/test/application/test_runner_test.rb
+++ b/railties/test/application/test_runner_test.rb
@@ -131,6 +131,18 @@ module ApplicationTests
end
end
+ def test_run_mailboxes
+ create_test_file :mailboxes, "foo_mailbox"
+ create_test_file :mailboxes, "bar_mailbox"
+ create_test_file :models, "foo"
+
+ rails("test:mailboxes").tap do |output|
+ assert_match "FooMailboxTest", output
+ assert_match "BarMailboxTest", output
+ assert_match "2 runs, 2 assertions, 0 failures", output
+ end
+ end
+
def test_run_functionals
create_test_file :mailers, "foo_mailer"
create_test_file :controllers, "bar_controller"
@@ -155,11 +167,11 @@ module ApplicationTests
end
def test_run_all_suites
- suites = [:models, :helpers, :unit, :controllers, :mailers, :functional, :integration, :jobs]
+ suites = [:models, :helpers, :unit, :controllers, :mailers, :functional, :integration, :jobs, :mailboxes]
suites.each { |suite| create_test_file suite, "foo_#{suite}" }
run_test_command("") .tap do |output|
suites.each { |suite| assert_match "Foo#{suite.to_s.camelize}Test", output }
- assert_match "8 runs, 8 assertions, 0 failures", output
+ assert_match "9 runs, 9 assertions, 0 failures", output
end
end
diff --git a/railties/test/commands/server_test.rb b/railties/test/commands/server_test.rb
index fbdd3f3ebb..25b89ecbd8 100644
--- a/railties/test/commands/server_test.rb
+++ b/railties/test/commands/server_test.rb
@@ -32,6 +32,12 @@ class Rails::Command::ServerCommandTest < ActiveSupport::TestCase
assert_match(/Could not find server "tin". Maybe you meant "thin"?/, run_command("--using", "tin"))
end
+ def test_using_server_mistype_without_suggestion
+ output = run_command("--using", "t")
+ assert_match(/Could not find server "t"/, output)
+ assert_no_match(/Maybe you meant/, output)
+ end
+
def test_using_positional_argument_deprecation
assert_match(/DEPRECATION WARNING/, run_command("tin"))
end
diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb
index c7a9803adf..f287827f81 100644
--- a/railties/test/generators/app_generator_test.rb
+++ b/railties/test/generators/app_generator_test.rb
@@ -435,7 +435,7 @@ class AppGeneratorTest < Rails::Generators::TestCase
assert_no_file "#{app_root}/config/storage.yml"
end
- def test_generator_when_skip_action_mailbox_is_given
+ def test_generator_skips_action_mailbox_when_skip_action_mailbox_is_given
run_generator [destination_root, "--skip-action-mailbox"]
assert_file "#{application_path}/config/application.rb", /#\s+require\s+["']action_mailbox\/engine["']/
end
@@ -445,6 +445,11 @@ class AppGeneratorTest < Rails::Generators::TestCase
assert_file "#{application_path}/config/application.rb", /#\s+require\s+["']action_mailbox\/engine["']/
end
+ def test_generator_skips_action_mailbox_when_skip_active_storage_is_given
+ run_generator [destination_root, "--skip-active-storage"]
+ assert_file "#{application_path}/config/application.rb", /#\s+require\s+["']action_mailbox\/engine["']/
+ end
+
def test_app_update_does_not_change_config_target_version
run_generator
diff --git a/railties/test/generators_test.rb b/railties/test/generators_test.rb
index f98c1f78f7..abdc04a8d3 100644
--- a/railties/test/generators_test.rb
+++ b/railties/test/generators_test.rb
@@ -28,6 +28,7 @@ class GeneratorsTest < Rails::Generators::TestCase
output = capture(:stdout) { Rails::Generators.invoke name }
assert_match "Could not find generator '#{name}'", output
assert_match "`rails generate --help`", output
+ assert_no_match "Maybe you meant", output
end
def test_generator_suggestions