2017-08-14 13:08:09 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2009-10-08 21:12:28 -04:00
|
|
|
require "isolation/abstract_unit"
|
|
|
|
|
|
|
|
module ApplicationTests
|
2012-01-05 20:30:17 -05:00
|
|
|
class GeneratorsTest < ActiveSupport::TestCase
|
2009-10-08 21:12:28 -04:00
|
|
|
include ActiveSupport::Testing::Isolation
|
|
|
|
|
|
|
|
def setup
|
|
|
|
build_app
|
|
|
|
end
|
|
|
|
|
2011-06-06 08:54:05 -04:00
|
|
|
def teardown
|
|
|
|
teardown_app
|
|
|
|
end
|
|
|
|
|
2009-11-30 18:58:38 -05:00
|
|
|
def app_const
|
|
|
|
@app_const ||= Class.new(Rails::Application)
|
|
|
|
end
|
|
|
|
|
|
|
|
def with_config
|
2009-12-31 15:28:48 -05:00
|
|
|
require "rails/all"
|
2009-12-22 20:03:23 -05:00
|
|
|
require "rails/generators"
|
2009-11-30 18:58:38 -05:00
|
|
|
yield app_const.config
|
|
|
|
end
|
|
|
|
|
2010-01-27 20:39:11 -05:00
|
|
|
def with_bare_config
|
|
|
|
require "rails"
|
|
|
|
require "rails/generators"
|
|
|
|
yield app_const.config
|
|
|
|
end
|
|
|
|
|
2010-11-15 14:09:05 -05:00
|
|
|
test "allow running plugin new generator inside Rails app directory" do
|
2017-09-03 12:55:26 -04:00
|
|
|
rails "plugin", "new", "vendor/plugins/bukkits"
|
2010-11-17 17:31:29 -05:00
|
|
|
assert File.exist?(File.join(rails_root, "vendor/plugins/bukkits/test/dummy/config/application.rb"))
|
Do not allow to use plugin_new generator directly, you should use Usage:
rails new APP_PATH [options]
Options:
-G, [--skip-git] # Skip Git ignores and keeps
-r, [--ruby=PATH] # Path to the Ruby binary of your choice
# Default: /Users/drogus/.rvm/rubies/ruby-1.8.7-p302/bin/ruby
-b, [--builder=BUILDER] # Path to an application builder (can be a filesystem path or URL)
[--edge] # Setup the application with Gemfile pointing to Rails repository
[--dev] # Setup the application with Gemfile pointing to your Rails checkout
[--skip-gemfile] # Don't create a Gemfile
-d, [--database=DATABASE] # Preconfigure for selected database (options: mysql/oracle/postgresql/sqlite3/frontbase/ibm_db)
# Default: sqlite3
-O, [--skip-active-record] # Skip Active Record files
-m, [--template=TEMPLATE] # Path to an application template (can be a filesystem path or URL)
-J, [--skip-prototype] # Skip Prototype files
-T, [--skip-test-unit] # Skip Test::Unit files
Runtime options:
-s, [--skip] # Skip files that already exist
-p, [--pretend] # Run but do not make any changes
-f, [--force] # Overwrite files that already exist
-q, [--quiet] # Supress status output
Rails options:
-v, [--version] # Show Rails version number and quit
-h, [--help] # Show this help message and quit
Description:
The 'rails new' command creates a new Rails application with a default
directory structure and configuration at the path you specify.
Example:
rails new ~/Code/Ruby/weblog
This generates a skeletal Rails installation in ~/Code/Ruby/weblog.
See the README in the newly created application to get going. command
2010-11-15 14:09:39 -05:00
|
|
|
end
|
|
|
|
|
2009-10-08 21:12:28 -04:00
|
|
|
test "generators default values" do
|
2010-01-27 20:39:11 -05:00
|
|
|
with_bare_config do |c|
|
2009-10-08 21:12:28 -04:00
|
|
|
assert_equal(true, c.generators.colorize_logging)
|
|
|
|
assert_equal({}, c.generators.aliases)
|
|
|
|
assert_equal({}, c.generators.options)
|
2010-02-01 04:48:59 -05:00
|
|
|
assert_equal({}, c.generators.fallbacks)
|
2009-10-08 21:12:28 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
test "generators set rails options" do
|
2010-01-28 13:45:25 -05:00
|
|
|
with_bare_config do |c|
|
2011-10-18 09:29:16 -04:00
|
|
|
c.generators.orm = :data_mapper
|
2009-10-08 21:12:28 -04:00
|
|
|
c.generators.test_framework = :rspec
|
2009-11-03 21:14:44 -05:00
|
|
|
c.generators.helper = false
|
2012-10-14 06:03:39 -04:00
|
|
|
expected = { rails: { orm: :data_mapper, test_framework: :rspec, helper: false } }
|
2009-10-08 21:12:28 -04:00
|
|
|
assert_equal(expected, c.generators.options)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
test "generators set rails aliases" do
|
2009-11-30 18:58:38 -05:00
|
|
|
with_config do |c|
|
2012-10-14 06:03:39 -04:00
|
|
|
c.generators.aliases = { rails: { test_framework: "-w" } }
|
|
|
|
expected = { rails: { test_framework: "-w" } }
|
2009-10-08 21:12:28 -04:00
|
|
|
assert_equal expected, c.generators.aliases
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-02-06 11:32:06 -05:00
|
|
|
test "generators aliases, options, templates and fallbacks on initialization" do
|
2009-12-22 20:03:23 -05:00
|
|
|
add_to_config <<-RUBY
|
2012-10-14 06:03:39 -04:00
|
|
|
config.generators.rails aliases: { test_framework: "-w" }
|
2011-10-18 09:29:16 -04:00
|
|
|
config.generators.orm :data_mapper
|
2009-12-22 20:03:23 -05:00
|
|
|
config.generators.test_framework :rspec
|
2010-02-01 04:48:59 -05:00
|
|
|
config.generators.fallbacks[:shoulda] = :test_unit
|
2010-02-06 11:32:06 -05:00
|
|
|
config.generators.templates << "some/where"
|
2009-12-22 20:03:23 -05:00
|
|
|
RUBY
|
|
|
|
|
2009-10-15 17:50:02 -04:00
|
|
|
# Initialize the application
|
2010-01-12 11:48:09 -05:00
|
|
|
require "#{app_path}/config/environment"
|
2011-05-25 03:30:41 -04:00
|
|
|
Rails.application.load_generators
|
2009-10-08 21:12:28 -04:00
|
|
|
|
|
|
|
assert_equal :rspec, Rails::Generators.options[:rails][:test_framework]
|
|
|
|
assert_equal "-w", Rails::Generators.aliases[:rails][:test_framework]
|
2012-10-14 06:03:39 -04:00
|
|
|
assert_equal Hash[shoulda: :test_unit], Rails::Generators.fallbacks
|
2010-10-06 11:18:59 -04:00
|
|
|
assert_equal ["some/where"], Rails::Generators.templates_path
|
2009-10-08 21:12:28 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
test "generators no color on initialization" do
|
2009-12-22 20:03:23 -05:00
|
|
|
add_to_config <<-RUBY
|
|
|
|
config.generators.colorize_logging = false
|
|
|
|
RUBY
|
|
|
|
|
2009-10-15 17:50:02 -04:00
|
|
|
# Initialize the application
|
2009-12-22 20:03:23 -05:00
|
|
|
require "#{app_path}/config/environment"
|
2011-05-25 03:30:41 -04:00
|
|
|
Rails.application.load_generators
|
2009-10-08 21:12:28 -04:00
|
|
|
|
|
|
|
assert_equal Thor::Base.shell, Thor::Shell::Basic
|
|
|
|
end
|
|
|
|
|
|
|
|
test "generators with hashes for options and aliases" do
|
2010-01-27 20:39:11 -05:00
|
|
|
with_bare_config do |c|
|
2009-10-08 21:12:28 -04:00
|
|
|
c.generators do |g|
|
2012-10-14 06:03:39 -04:00
|
|
|
g.orm :data_mapper, migration: false
|
|
|
|
g.plugin aliases: { generator: "-g" },
|
|
|
|
generator: true
|
2009-10-08 21:12:28 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
expected = {
|
2012-10-14 06:03:39 -04:00
|
|
|
rails: { orm: :data_mapper },
|
|
|
|
plugin: { generator: true },
|
|
|
|
data_mapper: { migration: false }
|
2009-10-08 21:12:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
assert_equal expected, c.generators.options
|
2012-10-14 06:03:39 -04:00
|
|
|
assert_equal({ plugin: { generator: "-g" } }, c.generators.aliases)
|
2009-10-08 21:12:28 -04:00
|
|
|
end
|
|
|
|
end
|
2010-07-21 10:37:03 -04:00
|
|
|
|
|
|
|
test "generators with string and hash for options should generate symbol keys" do
|
|
|
|
with_bare_config do |c|
|
|
|
|
c.generators do |g|
|
2016-08-06 13:16:09 -04:00
|
|
|
g.orm "data_mapper", migration: false
|
2010-07-21 10:37:03 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
expected = {
|
2012-10-14 06:03:39 -04:00
|
|
|
rails: { orm: :data_mapper },
|
|
|
|
data_mapper: { migration: false }
|
2010-07-21 10:37:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
assert_equal expected, c.generators.options
|
|
|
|
end
|
|
|
|
end
|
2015-04-17 19:34:21 -04:00
|
|
|
|
2015-04-18 19:53:40 -04:00
|
|
|
test "api only generators hide assets, helper, js and css namespaces and set api option" do
|
2015-04-17 19:34:21 -04:00
|
|
|
add_to_config <<-RUBY
|
2015-04-20 12:28:23 -04:00
|
|
|
config.api_only = true
|
2015-04-17 19:34:21 -04:00
|
|
|
RUBY
|
|
|
|
|
|
|
|
# Initialize the application
|
|
|
|
require "#{app_path}/config/environment"
|
|
|
|
Rails.application.load_generators
|
|
|
|
|
2016-09-16 12:44:05 -04:00
|
|
|
assert_includes Rails::Generators.hidden_namespaces, "assets"
|
|
|
|
assert_includes Rails::Generators.hidden_namespaces, "helper"
|
|
|
|
assert_includes Rails::Generators.hidden_namespaces, "js"
|
|
|
|
assert_includes Rails::Generators.hidden_namespaces, "css"
|
2015-04-18 19:53:40 -04:00
|
|
|
assert Rails::Generators.options[:rails][:api]
|
2015-04-19 21:15:39 -04:00
|
|
|
assert_equal false, Rails::Generators.options[:rails][:assets]
|
2015-04-19 21:17:24 -04:00
|
|
|
assert_equal false, Rails::Generators.options[:rails][:helper]
|
2015-04-19 20:23:19 -04:00
|
|
|
assert_nil Rails::Generators.options[:rails][:template_engine]
|
2015-04-17 19:34:21 -04:00
|
|
|
end
|
2015-04-20 12:45:46 -04:00
|
|
|
|
|
|
|
test "api only generators allow overriding generator options" do
|
|
|
|
add_to_config <<-RUBY
|
|
|
|
config.generators.helper = true
|
|
|
|
config.api_only = true
|
|
|
|
config.generators.template_engine = :my_template
|
|
|
|
RUBY
|
|
|
|
|
|
|
|
# Initialize the application
|
|
|
|
require "#{app_path}/config/environment"
|
|
|
|
Rails.application.load_generators
|
|
|
|
|
|
|
|
assert Rails::Generators.options[:rails][:api]
|
|
|
|
assert Rails::Generators.options[:rails][:helper]
|
|
|
|
assert_equal :my_template, Rails::Generators.options[:rails][:template_engine]
|
|
|
|
end
|
2016-02-12 07:13:40 -05:00
|
|
|
|
|
|
|
test "api only generator generate mailer views" do
|
|
|
|
add_to_config <<-RUBY
|
|
|
|
config.api_only = true
|
|
|
|
RUBY
|
|
|
|
|
2017-09-03 12:55:26 -04:00
|
|
|
rails "generate", "mailer", "notifier", "foo"
|
2016-02-12 07:13:40 -05:00
|
|
|
assert File.exist?(File.join(rails_root, "app/views/notifier_mailer/foo.text.erb"))
|
|
|
|
assert File.exist?(File.join(rails_root, "app/views/notifier_mailer/foo.html.erb"))
|
|
|
|
end
|
2016-12-16 20:10:21 -05:00
|
|
|
|
2020-02-18 00:59:06 -05:00
|
|
|
test "ARGV is populated" do
|
2016-12-16 20:10:21 -05:00
|
|
|
require "#{app_path}/config/environment"
|
2020-02-18 00:59:06 -05:00
|
|
|
Rails.application.load_generators
|
2016-12-16 20:10:21 -05:00
|
|
|
|
2020-02-18 00:59:06 -05:00
|
|
|
class Rails::Generators::CheckArgvGenerator < Rails::Generators::Base
|
|
|
|
def check_expected
|
|
|
|
raise "ARGV.first is not expected" unless ARGV.first == "expected"
|
|
|
|
end
|
2016-12-16 20:10:21 -05:00
|
|
|
end
|
|
|
|
|
2020-02-18 00:59:06 -05:00
|
|
|
quietly do
|
|
|
|
Rails::Command.invoke(:generate, ["check_argv", "expected"]) # should not raise
|
|
|
|
end
|
2016-12-16 20:10:21 -05:00
|
|
|
end
|
2017-02-24 09:45:05 -05:00
|
|
|
|
2017-11-09 06:54:24 -05:00
|
|
|
test "help does not show hidden namespaces and hidden commands" do
|
2017-02-24 09:45:05 -05:00
|
|
|
FileUtils.cd(rails_root) do
|
2017-09-03 12:55:26 -04:00
|
|
|
output = rails("generate", "--help")
|
2017-02-24 09:45:05 -05:00
|
|
|
assert_no_match "active_record:migration", output
|
2017-11-09 06:54:24 -05:00
|
|
|
assert_no_match "credentials", output
|
2017-03-26 19:29:20 -04:00
|
|
|
|
2017-09-03 12:55:26 -04:00
|
|
|
output = rails("destroy", "--help")
|
2017-03-26 19:29:20 -04:00
|
|
|
assert_no_match "active_record:migration", output
|
2017-02-24 09:45:05 -05:00
|
|
|
end
|
|
|
|
end
|
2019-06-28 19:43:16 -04:00
|
|
|
|
|
|
|
test "skip collision check" do
|
|
|
|
rails("generate", "model", "post", "title:string")
|
|
|
|
|
|
|
|
output = rails("generate", "model", "post", "title:string", "body:string")
|
|
|
|
assert_match(/The name 'Post' is either already used in your application or reserved/, output)
|
|
|
|
|
|
|
|
output = rails("generate", "model", "post", "title:string", "body:string", "--skip-collision-check")
|
|
|
|
assert_no_match(/The name 'Post' is either already used in your application or reserved/, output)
|
|
|
|
end
|
2019-10-08 20:05:35 -04:00
|
|
|
|
|
|
|
test "force" do
|
|
|
|
rails("generate", "model", "post", "title:string")
|
|
|
|
|
|
|
|
output = rails("generate", "model", "post", "title:string", "body:string")
|
|
|
|
assert_match(/The name 'Post' is either already used in your application or reserved/, output)
|
|
|
|
|
|
|
|
output = rails("generate", "model", "post", "title:string", "body:string", "--force")
|
|
|
|
assert_no_match(/The name 'Post' is either already used in your application or reserved/, output)
|
|
|
|
end
|
2019-06-19 04:22:46 -04:00
|
|
|
|
|
|
|
test "generators with after_generate callback" do
|
|
|
|
model_file = File.join(app_path, "app/models/post.rb")
|
|
|
|
with_config do |c|
|
|
|
|
c.generators.after_generate do |files|
|
|
|
|
expected = %w(
|
|
|
|
db/migrate/20000101000000_create_posts.rb
|
|
|
|
app/models/post.rb
|
|
|
|
test/models/post_test.rb
|
|
|
|
test/fixtures/posts.yml
|
|
|
|
app/controllers/posts_controller.rb
|
|
|
|
app/views/posts/index.html.erb
|
|
|
|
app/views/posts/edit.html.erb
|
|
|
|
app/views/posts/show.html.erb
|
|
|
|
app/views/posts/new.html.erb
|
|
|
|
app/views/posts/_form.html.erb
|
Modernize scaffold generator (#41210)
* Slim down scaffold css
To prevent conflicts with utility frameworks that might also be resetting base elements.
* Use a box-style partial rather than a table
Shows the usage of partials right from the start. Better compatibility with upgrading to Turbo frames/stream updates.
* Correct use of quotes
* Use modern array-of-strings declaration
* Use double quotes for everything
* Fix syntax
* Remove outdated viewport declaration
This should be handled in app stylesheets.
* Use double quotes everywhere
* Use symbols not strings for before_action scoping
* Use human name to deal with double word records
* Grab test fixes from #41219
Thanks @abhaynikam 🙏
* Fix tests
* Use locar var not ivar
* Fix capitalization change
* Update railties/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt
Co-authored-by: Haroon Ahmed <haroon.ahmed25@gmail.com>
* Update railties/test/generators/scaffold_controller_generator_test.rb
Co-authored-by: Haroon Ahmed <haroon.ahmed25@gmail.com>
* Update railties/test/generators/scaffold_controller_generator_test.rb
Co-authored-by: Haroon Ahmed <haroon.ahmed25@gmail.com>
* Fix test
* Update railties/test/generators/scaffold_generator_test.rb
Co-authored-by: Jonathan Hefner <jonathan@hefner.pro>
* Correct logic warning about initializers
Defining initializer 4 to run before itself and after 3 is possible, but
not when the before constraint contradicts the after constraint via 2.
* Rename master to main in all code references
* Use length == 0 instead of empty in Preloader
Previously we were checking empty? on the association which would make a
query. Instead we can check length == 0 to ensure we are using the
length of the loaded records and not issuing extra queries.
Co-authored-by: Dinah Shi <dinahshi@github.com>
* Add regression tests for preloader query count
* ActionCable guides suggest test adapter for test env [ci skip]
* Changing 'rails new' --master to be --main
Renaming test containing flag
Updating other test referencing master branch
Add notice that --master is deprecated, but still working the same as --main
Only set @main if it's nil
Making warn wildcard
I think a hidden aliaes would be just as good
Improving description & fixing rubocop error
Forgot comma
Deprecation warning was kind of hard - so just doing alias for now
rubocop -a
* I think passing in the --master argument to run_generator is the way to go
* Removing .count to figure out why its failing
* Raise unknown type error on the definition time
If unknow type is given for attribute (`attribute :foo, :unknown`),
unknown type error isn't raised on the definition time but runtime.
It should be raised on the definition time.
* Refactor `attribute` not to reference `&block`
* Use major + minor AR versions in 'Directly inheriting' error message
* Raise error when passing passing a class to :source_type
Raise `ArgumentError` when `:source_type` is given as class
in `has_many :through` relation.
Closes #41092
* Adding badges and logo to README and CONTRIBUTING page
* switch references to main branch in docs
* Updating references to /rails/blob/master & raiks/tree/master to point to main
* Don't return query cache enabled pools in the query cache executor
Follow up #41046.
If query cache is enabled for all connection pools, `pools` always
matches to `all_connection_pools`, returning `pools` has become
redundant.
* Remove trailing commas in advanced route constraints example
* Search for yarn.cmd and yarn.ps1 in bin/yarn
Follow-up to #40950.
On Windows, Yarn actually uses `yarn.cmd` and `yarn.ps1` for PowerShell.
* Run bin/yarn via Ruby
Windows cannot directly run shebang scripts, such as `bin/yarn`.
Therefore, run `bin/yarn` via Ruby.
Actually fixes #40942.
Fixes #41123.
* Allow to opt-out of `strict_loading` mode on a per-record base.
This is useful when strict loading is enabled application wide or on a
model level.
* Fix granular connection swapping when there are multiple abstract classes
Some applications maybe have multiple abstract classes in the
inheritance chain but only one of those abstract classes is the one we
want to switch connections on. Previously, multiple abstract class
inhertance would break `connected_to` and not switch models to the
correct connection context.
To fix this we added a boolean that is set on the class when a
connection is established so we can check for whether it's identified as
a `connection_class?`. This allows us to delete the `abstract_class?`
check, since you cannot establish a connection on a non-abstract class.
The existing tests were changed because they were not calling
`connects_to` and granular swapping won't work on classes that didn't
establish the connection. The issue in these tests will be prevented
when #40965 is merged.
Co-authored-by: John Crepezzi <john.crepezzi@gmail.com>
* Avoid testing Thor internals
Thor's `apply` method is responsible for fetching a template when given
a URL. Therefore, assume that `apply` behaves correctly, and simply
test that `apply` is called correctly.
This avoids errors like https://buildkite.com/rails/rails/builds/74245#540ecdf1-58ea-470a-a397-09f675520eb9/1100-1109
resulting from erikhuda/thor@4ce38c5478a5a13f2214ca833eafc167615b4e6a.
* Fix the benchmark script to point to the main branch
* Resolve default annotation tags after config loads
`Rails::SourceAnnotationExtractor::Annotation.tags` may be modified by
app configuration. Therefore, resolve default annotation tags after
loading the app configuration.
This fixes errors like https://buildkite.com/rails/rails/builds/74268#240d60bc-baa7-4b6e-ad21-b3172095f939/1083-1092
resulting from erikhuda/thor@0222fe52ed3803fe3ee0033da5b6faac5ee6299c.
* Upgrade all the gems to make sure we are testing with the latest versions locally
* Don't bother checking if strings respond to string methods
The respond_to? calls here are checking if the unsafe method names, in
this case "gsub" and "sub", respond to those same methods. This is
nonsensical and unnecessary.
* Update name of input to fix typo
* `connected_to` shouldn't be called on the abstract class that not established connection
Fixed: https://github.com/rails/rails/issues/40559#issuecomment-752056106
When abstract class hasn't own connections, calling `AbstractClass.connection`
returns parent class's connection. We call `AbstractClass.connection.preventing_writes?`
expecting abstract class's state to be returned, but actually it is parent's one.
I think that it isn't expected behavior so I prevents call `connected_to` on the abstract
class that not established the connection.
* Add Webpacker to Guides list
Adds a link to the Webpacker guide (added in https://github.com/rails/rails/pull/40817) to the [guides list](https://guides.rubyonrails.org/) and "Guides Index" dropdown menu.
* Update documents.yaml
* Fix unintialized instance variable connection_class
This was throwing a warning when the test suite is run. Adding an
reader fixes the issue.
* Webpacker guide: remove Basecamp reference [docs]
As a Rails user, if you *don't* know who Basecamp is or their relationship to the Rails framework, then this sentence is confusing. Reworded to instead just refer to Rails defaults.
cc @rossta
* fix broken link
* Update webpacker.md
* Added the unless-block for continuity
* Added :status for continuity
* Removed line for continuity
* Added a new line after the include statement
* Connection specification now passes the "url" key to the adapter
If the "url" protocol is "jdbc", "http", or "https" the url option will
be passed to the adapter. Previously only urls with the "jdbc" prefix
were passed to the Active Record Adapter, others are assumed to be
adapter specification urls.
Fixes #41137.
* Support hash config for `structure_dump_flags` and `structure_load_flags` flags
Now that Active Record supports multiple databases configuration
we need a way to pass specific flags for dump/load databases since
the options are not the same for different adapters.
We can use in the original way:
```ruby
ActiveRecord::Tasks::DatabaseTasks.structure_dump_flags = ['--no-defaults', '--skip-add-drop-table']
#or
ActiveRecord::Tasks::DatabaseTasks.structure_dump_flags = '--no-defaults --skip-add-drop-table'
```
And also use it passing a hash, with one or more keys, where the key
is the adapter
```ruby
ActiveRecord::Tasks::DatabaseTasks.structure_dump_flags = {
mysql2: ['--no-defaults', '--skip-add-drop-table'],
postgres: '--no-tablespaces'
}
```
* Update test docs in "contributing to Rails" guide
Updated guide to recommend `bin/test` and show examples of its use in different contexts.
Co-authored-by: Marivaldo Cavalheiro <marivaldo@gmail.com>
* Fix current_page? with kwargs on ruby3
Prevent raising an error when `options` are given as
kwargs, this is done by overriding `options` with kwargs
if `options` are `nil`; this implies that if both `options` and
kwargs are given, `options` takes precedence.
Fixes #41198
* `start_with?` allows multiple prefix values
* Fix code block in Webpacker Guide [ci skip]
Formatting fix: the example directory tree listing was bleeding into the
previous paragraph and had extraneous characters due to a missing
newline.
* Remove wrong usage for `arel_table` [ci skip]
This usage doesn't work properly (missing `where`, undefined `published`,
`arel_table` in the scope definition accidentally lose table alias).
* Restore ActiveStorage::Blob#find_signed
Rails 6.0 had a [public `find_signed` method][docs], but we changed it
to `find_signed!` in https://github.com/rails/rails/commit/31148cd6bef4f3a3059c51c587a8bff78a2e73e3.
This commit adds back `find_signed` alongside `find_signed!` to match
the corresponding [Active Record methods][].
[docs]: https://api.rubyonrails.org/v6.0.0/classes/ActiveStorage/Blob.html#method-c-find_signed
[Active Record methods]: https://github.com/rails/rails/blob/main/activerecord/lib/active_record/signed_id.rb#L42-L66
* Handle throwing in controller action in log subscriber
When throw was used in a controller action, and there is matching catch
around the request in a Rack middleware, then :exception won't be
present in the event payload.
This is because ActiveSupport::Notifications::Instrumenter.instrument
sets :exception in a rescue handler, but rescue is never called in a
throw/catch scenario:
catch(:halt) do
begin
throw :halt
rescue Exception => e
puts "rescue" # never reached
ensure
puts "ensure"
end
end
Missing :exception was actually handled prior to Rails 6.1.0, but an
optimization updated the code to assume this was present. So this can be
considered a regression fix.
* Improve Fixture support for Active Storage (#41065)
* Improve Fixture support for Active Storage
Inspired by [76b33aa][], this commit extends the Active Storage
documentation to elaborate on how to declare fixtures.
In support of that, also introduce the `ActiveStorage::FixtureSet.blob`
method for injecting in-line [ActiveStorage::Blob][] attributes directly
into fixture YAML.
[76b33aa]: https://github.com/rails/rails/commit/76b33aa3d102ad4ff3f766ac2d3a711d73aaee82
[ActiveStorage::Blob]: https://edgeapi.rubyonrails.org/classes/ActiveStorage/Blob.html
* Extra CR for style
* Two-space indention
* Explaining variable didn't explain, inline for style
Co-authored-by: David Heinemeier Hansson <david@loudthinking.com>
* Improve ActionText::FixtureSet documentation (#41062)
* Improve ActionText::FixtureSet documentation
Support for Action Text attachments in fixtures was added by [76b33aa][] and
released as part of [6.1.1][], but has not yet been documented.
This commit documents the `ActionText::FixtureSet` for the API
documentation, and mentions it in the Rails Guides pages.
[76b33aa]: https://github.com/rails/rails/commit/76b33aa3d102ad4ff3f766ac2d3a711d73aaee82
[6.1.1]: https://github.com/rails/rails/releases/tag/v6.1.1
* Fix indention of comments
Co-authored-by: David Heinemeier Hansson <david@loudthinking.com>
* Fix Flaky ActiveStorage test (#41225)
Fixes a flaky Active Storage test introduced by [rails/rails#41065][],
and improves the documentation.
It seems that the test is covering the backwards compatibility of an
older interface for retrieving records through
`ActiveStorage::Record#find_signed!`. The test itself would pass
unpredictably. To isolate the failure and reproduce it consistently, a
see value was found after some trial and error:
```
SEED=59729 bin/test test/fixture_set_test.rb test/models/attachment_test.rb
```
This _used_ to pass consistently because [rails/rails][#41065]
introduced a call to `fixtures :all`, which introduces more variation in
the database's ID generation sequence. Without that line, `id` values
start at `1`, so the fact that calls to
`ActiveStorage::Attached::One#id` and `ActiveStorage::Blob#id` **both
return `1`** is purely coincidence.
The proposed resolution changes the test slightly. Prior to this change,
the identifier used during retrieval and verification fetched from
`@user.avatar.id`, where `@user.avatar` is an instance of
`ActiveStorage::Attached::One`. The verifier/retriever combination in
that test expected a signed identifier for an `ActiveStorage::Blob`
instance. The change involved retrieving an instance through
`@user.avatar.blob`.
To better emphasize how global the `fixtures :all` declaration is, move
it from the `test/fixture_set_test.rb` file to the `test/test_helper.rb`
file.
[rails/rails#41065]: https://github.com/rails/rails/pull/41065
* Fix doc: stylesheet_include_tag -> stylesheet_link_tag
* Remove reference to globalize gem
* Fix typo [ci skip]
* Add small improvements to the Webpacker guide
- fix typos like double spaces, accidental caps
- improve some HTML links by giving them a label
- etc
* Fixing delegated types example.
* Allow jobs to rescue all exceptions
Before this commit, only StandardError exceptions can be handled by
rescue_from handlers.
This changes the rescue clause to catch all Exception objects, allowing
rescue handlers to be defined for Exception classes not inheriting from
StandardError.
This means that rescue handlers that are rescuing Exceptions outside of
StandardError exceptions may rescue exceptions that were not being
rescued before this change.
Co-authored-by: Adrianna Chang <adrianna.chang@shopify.com>
* Guides: Missing erb tags for stylesheet_pack_tag [ci skip]
The section on needing to use `stylesheet_pack_tag` was lacking the erb
%'s.
I updated the markdown to actually show the helper being used with erb
as well as improve the wording of the sentence.
* Guides: Remove unneeded statement about stylesheet_pack_tag [ci skip]
* Update test names to match their behaviour
These tests were names `…creation_failure…` but there's no creation
failing in the tests themselves. Instead creation is succeeding, via
the `create_association` method which is added by the `has_one` relation.
I found these test names very confusing when reading this issue:
https://github.com/rails/rails/issues/13197
And the commit it links to: c6e10b0
The least we can do to make that issue less confusing is to start by
fixing these test names.
[ci skip]
* Remove SET NAMES, set collation using variable
Fixes malformed packet error that occurred with MariaDB client
connecting to RDS Aurora (MySQL 5.7) database.
* Update test helper to call parallelize according to fork support
* Show a warning when running no migration using SCOPE
When running a migration with `ENV["SCOPE"]` set returns a warning
if no migrations ran.
The message serves as a hint for the end-user to make sure he knows
that the migration have been filtered by `SCOPE`.
* Move ActiveStorage fixture hooks to on_load
In a test environment, rely on the loading of
`:active_support_test_case`.
Introduce the `:active_record_fixture_set` hook for the Active Storage
engine to listen for during the load process in a development
environment (like when running `db:fixtures:load`).
Since this commit moves the task-aware path resolution out of the block
that provided local variables, it recreates part of the fixture
directory path resolution logic.
* Improve ActiveRecord strict_loading documentation
Apply the same structure as the documentation of `validate` option by
starting the description with "when set to true". This implies, that
the value passed to the option should be a boolean.
* Remove legacy media=screen default from stylesheet_link_tag.
If the media attribute is omitted, the default for web browsers is "all", meaning that by default links apply to all media.
Before:
```ruby
> stylesheet_link_tag "style"
=> <link href="/assets/style.css" media="screen" rel="stylesheet" />
```
After:
```ruby
> stylesheet_link_tag "style"
=> <link href="/assets/style.css" rel="stylesheet" />
```
The current behavior is not going to change for existing applications.
For newly built applications, the media attribute is not going to be added by default. Which can be configured using the following:
```
Rails.application.config.action_view.stylesheet_media_default = false
```
* Do not eagerly load Request before initializers
Without those changes the configurations to ActionDispatch::Request
could not be applied in initializers.
* Change Request#media_type to return nil
When the request don't have a Content-Type header we were returning
an empty string instead of nil like Rack does.
* `ActionDispatch::Request#content_type` now returned Content-Type header as it is
* Disable rubocop suggestions
* Fix typo in the CHANGELOG
* Add config.action_view.stylesheet_media_default to baseline config
* Rename the config to make clear it is a boolean
* Add CHANGELOG entry for #41215
* Fix CI failure due to `app.config.action_view.delete(:apply_apply_stylesheet_media_default)`
https://buildkite.com/rails/rails/builds/74429#3de35026-a6dc-4f4c-b885-9b59e0c89b96/979-1036
* Fix deprecation message s/Rails 6.1 will return/Rails 7.0 will return/
`return_only_media_type_on_content_type` will be introduced in Rails 6.2
so the changing of returning Content-Type will happen in a future
version of Rails (probably 7.0).
* Revert "Merge pull request #41192 from kamipo/dont_return_pools"
This reverts commit 9d8ff323729f8f8fe09f14f4f45586f2d6340a70, reversing
changes made to 9cde02ef5f17bf4f20aaeb5314de0b52c86496a3.
Need to revert this so I can revert another PR.
* Revert "Merge pull request #41046 from eileencodes/dont-check-if-qc-is-enabled"
This reverts commit c97f1f195fc299d9d2ae7954d2b842ec4822382c, reversing
changes made to ac7851eb58d3e821f0f378c1417bc157d7df3be8.
We haven't quite tracked down why yet, but this change caused our API to
not use the query cache. Our API is Sinatra mixed with Rails. We install
the Exectutor in our API so it was installed. However, (some?)
production requests were showing 0 query cache hits.
jhawthorn found that we likely need this check because if we don't the
pools returned will be a different set. He'll send a test later today.
* Ensure test rake commands run immediately
Before this commit, Rails test Rake tasks only load the test files, and
the tests only run in an at_exit hook via minitest/autorun.
This prevents conditionally running tasks only when tests pass, or even
more simply in the right order. As a simple example, if you have:
task default: [:test, :rubocop]
The rubocop task will run after the test task loads the test files but
before the tests actually run.
This commit changes the test Rake tasks to shell out to the test runner
as a new process.
This diverges from previous behavior because now, any changes made in
the Rakefile or other code loaded by Rake won't be available to the
child process. However this brings the behavior of `rake test` closer to
the behavior of `rails test`.
Co-authored-by: Adrianna Chang <adrianna.chang@shopify.com>
* Fix typo
Co-authored-by: Haroon Ahmed <haroon.ahmed25@gmail.com>
Co-authored-by: Jonathan Hefner <jonathan@hefner.pro>
Co-authored-by: Gannon McGibbon <gannon.mcgibbon@gmail.com>
Co-authored-by: Rafael Mendonça França <rafael@franca.dev>
Co-authored-by: John Hawthorn <john@hawthorn.email>
Co-authored-by: Dinah Shi <dinahshi@github.com>
Co-authored-by: Santiago Bartesaghi <santib@hey.com>
Co-authored-by: Mike Rogers <me@mikerogers.io>
Co-authored-by: Ryuta Kamizono <kamipo@gmail.com>
Co-authored-by: Ryan Bigg <me@ryanbigg.com>
Co-authored-by: Jacopo <beschi.jacopo@gmail.com>
Co-authored-by: Guillaume Briday <guillaumebriday@gmail.com>
Co-authored-by: benhayehudi <bengreenberg@gmail.com>
Co-authored-by: wout@mick-wout.com <Wout>
Co-authored-by: Ayrton De Craene <hello@ayrton.be>
Co-authored-by: eileencodes <eileencodes@gmail.com>
Co-authored-by: John Crepezzi <john.crepezzi@gmail.com>
Co-authored-by: Chris Salzberg <chris@dejimata.com>
Co-authored-by: Tim Tilberg <ttilberg@gmail.com>
Co-authored-by: alpaca-tc <alpaca-tc@alpaca.tc>
Co-authored-by: Alex Ghiculescu <alex@tanda.co>
Co-authored-by: Xavier Noria <fxn@hashref.com>
Co-authored-by: ijlee2 <ijlee2@users.noreply.github.com>
Co-authored-by: Jon Bracy <jonbracy@gmail.com>
Co-authored-by: Gustavo Gonzalez <gustavo@gonzalez.guru>
Co-authored-by: Marivaldo Cavalheiro <marivaldo@gmail.com>
Co-authored-by: Chris Houhoulis <chris@chrishouhoulis.com>
Co-authored-by: Daniel Colson <daniel.colson@hey.com>
Co-authored-by: Janko Marohnić <janko.marohnic@gmail.com>
Co-authored-by: Sean Doyle <seanpdoyle@users.noreply.github.com>
Co-authored-by: André Luis Leal Cardoso Junior <andrehjr@gmail.com>
Co-authored-by: Youssef Boulkaid <yboulkaid@gmail.com>
Co-authored-by: Orhan Toy <toyorhan@gmail.com>
Co-authored-by: David Stosik <david.stosik+git-noreply@gmail.com>
Co-authored-by: Andrew Culver <andrew.culver@gmail.com>
Co-authored-by: Étienne Barrié <etienne.barrie@gmail.com>
Co-authored-by: Adrianna Chang <adrianna.chang@shopify.com>
Co-authored-by: Tony Drake <t27duck@gmail.com>
Co-authored-by: Sam Jewell <sam@bridge-u.com>
Co-authored-by: Robin Roestenburg <robin.roestenburg@4me.com>
Co-authored-by: Brandon Fish <brandon.j.fish@oracle.com>
Co-authored-by: Sean Doyle <sean.p.doyle24@gmail.com>
Co-authored-by: Cecile Veneziani <contact@cecilitse.org>
Co-authored-by: st0012 <stan001212@gmail.com>
2021-02-04 06:26:16 -05:00
|
|
|
app/views/posts/_post.html.erb
|
2019-06-19 04:22:46 -04:00
|
|
|
test/controllers/posts_controller_test.rb
|
|
|
|
test/system/posts_test.rb
|
|
|
|
app/helpers/posts_helper.rb
|
|
|
|
)
|
|
|
|
assert_equal expected, files
|
|
|
|
|
|
|
|
File.open(model_file, "a") { |f| f.write("# Add comment to model") }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
travel_to Time.utc(2000, 1, 1) do
|
|
|
|
rails("generate", "scaffold", "post", "title:string")
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_match(/# Add comment to model/, File.read(model_file))
|
|
|
|
end
|
2009-10-08 21:12:28 -04:00
|
|
|
end
|
2009-11-03 21:14:44 -05:00
|
|
|
end
|