Commit Graph

13317 Commits

Author SHA1 Message Date
Phil Ross
e9425abe33
Update to TZInfo v2.0.0
Co-authored-by: Jared Beck <jared@jaredbeck.com>
Co-authored-by: Jonathan Hefner <jonathan@hefner.pro>
2020-03-28 20:42:43 +01:00
Kasper Timm Hansen
54cb01610e
Merge pull request #38495 from jonathanhefner/isolate-argv-in-command-invoke
Isolate ARGV in Rails::Command.invoke
2020-03-14 02:47:22 +01:00
Aaron Patterson
690d946db9
Rails::Command.invoke wants kwargs, so give it kwargs
This fixes an exception when generating a new app on Ruby 2.8.  Before
this commit, I get this exception:

```
$ be ruby railties/exe/rails new ~/git/fix-bug --dev
...
...
Traceback (most recent call last):
	31: from railties/exe/rails:10:in `<main>'
	30: from railties/exe/rails:10:in `require'
	29: from /Users/aaron/git/rails/railties/lib/rails/cli.rb:18:in `<top (required)>'
	28: from /Users/aaron/git/rails/railties/lib/rails/command.rb:45:in `invoke'
	27: from /Users/aaron/git/rails/railties/lib/rails/command/base.rb:69:in `perform'
	26: from /Users/aaron/.rbenv/versions/ruby-trunk/lib/ruby/gems/2.8.0/gems/thor-1.0.1/lib/thor.rb:392:in `dispatch'
	25: from /Users/aaron/.rbenv/versions/ruby-trunk/lib/ruby/gems/2.8.0/gems/thor-1.0.1/lib/thor/invocation.rb:127:in `invoke_command'
	24: from /Users/aaron/.rbenv/versions/ruby-trunk/lib/ruby/gems/2.8.0/gems/thor-1.0.1/lib/thor/command.rb:27:in `run'
	23: from /Users/aaron/git/rails/railties/lib/rails/commands/application/application_command.rb:26:in `perform'
	22: from /Users/aaron/.rbenv/versions/ruby-trunk/lib/ruby/gems/2.8.0/gems/thor-1.0.1/lib/thor/base.rb:485:in `start'
	21: from /Users/aaron/.rbenv/versions/ruby-trunk/lib/ruby/gems/2.8.0/gems/thor-1.0.1/lib/thor/group.rb:232:in `dispatch'
	20: from /Users/aaron/.rbenv/versions/ruby-trunk/lib/ruby/gems/2.8.0/gems/thor-1.0.1/lib/thor/invocation.rb:134:in `invoke_all'
	19: from /Users/aaron/.rbenv/versions/ruby-trunk/lib/ruby/gems/2.8.0/gems/thor-1.0.1/lib/thor/invocation.rb:134:in `map'
	18: from /Users/aaron/.rbenv/versions/ruby-trunk/lib/ruby/gems/2.8.0/gems/thor-1.0.1/lib/thor/invocation.rb:134:in `each'
	17: from /Users/aaron/.rbenv/versions/ruby-trunk/lib/ruby/gems/2.8.0/gems/thor-1.0.1/lib/thor/invocation.rb:134:in `block in invoke_all'
	16: from /Users/aaron/.rbenv/versions/ruby-trunk/lib/ruby/gems/2.8.0/gems/thor-1.0.1/lib/thor/invocation.rb:127:in `invoke_command'
	15: from /Users/aaron/.rbenv/versions/ruby-trunk/lib/ruby/gems/2.8.0/gems/thor-1.0.1/lib/thor/command.rb:27:in `run'
	14: from (eval):1:in `run_webpack'
	13: from /Users/aaron/git/rails/railties/lib/rails/generators/app_base.rb:419:in `run_webpack'
	12: from /Users/aaron/git/rails/railties/lib/rails/generators/actions.rb:255:in `rails_command'
	11: from /Users/aaron/.rbenv/versions/ruby-trunk/lib/ruby/gems/2.8.0/gems/thor-1.0.1/lib/thor/actions.rb:197:in `in_root'
	10: from /Users/aaron/.rbenv/versions/ruby-trunk/lib/ruby/gems/2.8.0/gems/thor-1.0.1/lib/thor/actions.rb:187:in `inside'
	 9: from /Users/aaron/.rbenv/versions/ruby-trunk/lib/ruby/2.8.0/fileutils.rb:139:in `cd'
	 8: from /Users/aaron/.rbenv/versions/ruby-trunk/lib/ruby/2.8.0/fileutils.rb:139:in `chdir'
	 7: from /Users/aaron/.rbenv/versions/ruby-trunk/lib/ruby/gems/2.8.0/gems/thor-1.0.1/lib/thor/actions.rb:187:in `block in inside'
	 6: from /Users/aaron/.rbenv/versions/ruby-trunk/lib/ruby/gems/2.8.0/gems/thor-1.0.1/lib/thor/actions.rb:197:in `block in in_root'
	 5: from /Users/aaron/git/rails/railties/lib/rails/generators/actions.rb:256:in `block in rails_command'
	 4: from /Users/aaron/git/rails/activesupport/lib/active_support/core_ext/kernel/reporting.rb:15:in `silence_warnings'
	 3: from /Users/aaron/git/rails/activesupport/lib/active_support/core_ext/kernel/reporting.rb:28:in `with_warnings'
	 2: from /Users/aaron/git/rails/activesupport/lib/active_support/core_ext/kernel/reporting.rb:15:in `block in silence_warnings'
	 1: from /Users/aaron/git/rails/railties/lib/rails/generators/actions.rb:257:in `block (2 levels) in rails_command'
/Users/aaron/git/rails/railties/lib/rails/command.rb:31:in `invoke': wrong number of arguments (given 3, expected 1..2) (ArgumentError)
```

After this commit, things seem to work.
2020-03-12 10:04:56 -07:00
OsamaSayegh
ac1d4a6a62 Include rack-mini-profiler gem by default 2020-03-11 18:47:50 +03:00
Nate Berkopec
670026737b
Fix exceptions raised/rescued in dev by IPAddr
Putting ".localhost" at the end causes 4 IPAddr::InvalidAddressError
exceptions to be raised and rescued during every request when the
HostAuthorization middleware attempts to compare an IPAddr with a
"localhost" string.
2020-03-10 12:40:23 -06:00
eileencodes
095f1bfaa0
Refactor schema migration on connection
This method was jumping through extra hoops to find the name of the
class the connection is stored on when we can get it from the connection
itself. Since we already have the connection we don't need to loop through the
pools.

In addition, this was using the wrong class name. The class name for the
schema migration should come from the connection owner class, not from
the `db_config.name`. In this case, `db_config.name` is the name of the
configuration in the database.yml. Rails uses the class name to lookup
connections, not the db config name, so we should be consistent here.

While working on this I noticed that we were generating an extra schema
migration class for `ActiveRecord::Base`. Since `ActiveRecord::Base` can
and should use the default and we don't want to create a new one for
single db applications, we should skip creating this if the spec name is
`ActiveRecord::Base`. I added an additional test that ensures the class
generation is correct.
2020-03-09 09:59:36 -04:00
eileencodes
67b102a57f
Add erb tests for multi-db
If I had had these tests previously I would have not created PR #38658
and then promptly realize I needed to revert it.

We need to load and parse the configurations twice. Once before the
environment is loaded to create the named tasks and once after the
environment is loaded to have the real configurations. The configs
loaded before the env have the ERB stripped out and aren't valid
configs.
2020-03-06 11:23:43 -05:00
eileencodes
2dcf07a53a
Fix test name
Wow this is embarrassing. I literally named this FIXME so I'd remember
to give it some name that made sense and then I totally did not.
2020-03-06 10:01:14 -05:00
eileencodes
150fcf7b37
Fix database configruation for multi-db
The key, value is `replica: true` not `readonly: true`. Fix the database
configuration to be correct.
2020-03-06 09:33:18 -05:00
Eileen M. Uchitelle
712cee1741
Merge pull request #38665 from roramirez/test-master-new-app
Add tests for --master app_generator
2020-03-06 08:40:28 -05:00
Rodrigo Ramírez Norambuena
3b882deb0c Add tests for --master app_generator
These tests verify is added the entry into the Gemfile using
`branch: "master"` for Rails and web-console from Github for
:development
2020-03-05 18:39:03 -03:00
Charles Oliver Nutter
09e0372532
Use optimized subclass of StringInquirer for Rails.env
This adds a StringInquirer subclass EnvironmentInquirer that
predefines the three default environments as query methods, in
order to avoid dispatching through `method_missing` for every call
to those methods. The original StringInquirer was not modified due
to the side effects of having new env-related methods on it. This
new class was not implemented using lazy method definition to
avoid the open-ended possibility of defining a new method for all
query calls. The three default environments should cover a high
percentage of real-world uses, and users with custom environments
could add their own to this class.

Fixes #37803.
2020-03-05 14:57:27 -06:00
Aaron Patterson
227ff44e36
Revert "Merge pull request #37808 from headius/optimize_string_inquirer"
This reverts commit 9e5c6c4c845c176e138927f9fa8774957da55e99, reversing
changes made to 3aacd855cdb5b4543f3b31cd2fa9a5242a8d618e.
2020-03-05 11:12:14 -08:00
Aaron Patterson
9e5c6c4c84
Merge pull request #37808 from headius/optimize_string_inquirer
Use optimized subclass of StringInquirer for Rails.env
2020-03-05 10:00:20 -08:00
Eugene Kenny
d3599d8aff Use index_by and index_with wherever possible
Using `index_by` or `index_with` is more concise than `each_with_object`
and more performant than `map { ... }.to_h` or `Hash[map { ... }]`.
2020-03-05 01:24:14 +00:00
Rafael França
35c2620d23
Merge pull request #38631 from Schwad/master
Allow `rails new . --master` to point to master branch
2020-03-04 13:41:54 -05:00
Nick Schwaderer
6d15fab8ec
Update railties/lib/rails/generators/app_base.rb
Co-Authored-By: Rafael França <rafael@franca.dev>
2020-03-04 17:18:35 +00:00
Humberto
efb62fa3d1
Properly close a tag to avoid errors with some ruby versions
It raises an error if the ruby version is 2.5.0
2020-03-04 16:37:22 +00:00
Nick Schwaderer
531fd3d529 Allow rails new —master to point to master branch
Currently the `rails new` generator supports options `—dev` and `—edge`.

`—dev` points to one’s local rails setup and `--edge` points to the latest stable Rails branch.

However, in the Rails community we often think of the ‘edge’ as the latest merged master. We can see as much in Shopify’s fantastic article showing how they point to the latest master version of Rails: https://engineering.shopify.com/blogs/engineering/living-on-the-edge-of-rails

I would originally have recommended changing ‘edge’ to point to master, as it has tripped me up on numerous occasions now.

However I would rather add the desired functionality then change the current edge functionality.

Therefore this PR adds the `—master` flag.

It is intended to do exactly as `edge` does, simply with the changethat it points to Rails’ master branch instead of latest stable (i.e. 6_0_stable)

Whenever developers see a new feature in Rails, such as the recently committed horizontal sharding (which prompted my PR), we would love to spin up a new Rails App to try out these new features.

This command would allow us to jump right in with no configuration and offer our testing of the features, even those of us who aren’t able to spend a lot of time on OSS support.
2020-03-04 12:20:52 +00:00
Kyle Thompson
4b81e367ef
Dump the schema or structure of a database when calling db:migrate:name 2020-02-27 13:40:00 -05:00
Kyle Thompson
0366cbd742
Reset the ActiveRecord::Base connection after rails db:migrate:name 2020-02-27 13:10:54 -05:00
Ryuta Kamizono
1d3eb7be13 Fixup CHANGELOGs [ci skip] 2020-02-25 14:14:54 +09:00
eileencodes
79ce7d9af6
Deprecate spec_name and use name for configurations
I have so. many. regrets. about using `spec_name` for database
configurations and now I'm finally putting this mistake to an end.

Back when I started multi-db work I assumed that eventually
`connection_specification_name` (sometimes called `spec_name`) and
`spec_name` for configurations would one day be the same thing. After
2 years I no longer believe they will ever be the same thing.

This PR deprecates `spec_name` on database configurations in favor of
`name`. It's the same behavior, just a better name, or at least a
less confusing name.

`connection_specification_name` refers to the parent class name (ie
ActiveRecord::Base, AnimalsBase, etc) that holds the connection for it's
models. In some places like ConnectionHandler it shortens this to
`spec_name`, hence the major confusion.

Recently I've been working with some new folks on database stuff and
connection management and realize how confusing it was to explain that
`db_config.spec_name` was not `spec_name` and
`connection_specification_name`. Worse than that one is a symbole while
the other is a class name. This was made even more complicated by the
fact that `ActiveRecord::Base` used `primary` as the
`connection_specification_name` until #38190.

After spending 2 years with connection management I don't believe that
we can ever use the symbols from the database configs as a way to
connect the database without the class name being _somewhere_ because
a db_config does not know who it's owner class is until it's been
connected and a model has no idea what db_config belongs to it until
it's connected. The model is the only way to tie a primary/writer config
to a replica/reader config. This could change in the future but I don't
see value in adding a class name to the db_configs before connection or
telling a model what config belongs to it before connection. That would
probably break a lot of application assumptions. If we do ever end up in
that world, we can use name, because tbh `spec_name` and
`connection_specification_name` were always confusing to me.
2020-02-24 13:27:07 -05:00
Kyle Thompson
e8c61b6bfd
Adds additional database-specific rake tasks for multi-database users 2020-02-24 12:05:44 -05:00
Carlos Antonio da Silva
6f98614b1f Calculate mailbox and channel test files as Test LOC stats
If they are not included in this "test types" list, they're counted
towards app code lines, not test lines.
2020-02-19 10:10:12 -03:00
Joshua Cody
53348ed820 Count TypeScript files as javascript in rails stats 2020-02-18 16:46:19 -06:00
Jonathan Hefner
8ec7a2b7aa Isolate ARGV in Rails::Command.invoke
Follow-up to #38463.

By isolating ARGV, we guard against commands inadvertently depending on
prior ARGV contents.  Any such command will now behave consistently when
run via `Rails::Command.invoke`, whether coming from the Rails CLI or
from library code.  Likewise, any ARGV mutations done by a command will
not affect code that executes after `Rails::Command.invoke`.
2020-02-18 15:02:56 -06:00
Jonathan Hefner
373ad2c624 Change commands to not depend on ARGV
Follow-up to #38463.

This commit changes additional command classes to not depend on prior
ARGV contents.
2020-02-18 14:08:59 -06:00
Kasper Timm Hansen
0cb6c27344
Merge pull request #38463 from jonathanhefner/fix-rails-new-dev
Fix `rails new --dev`
2020-02-17 00:33:32 +01:00
Jonathan Hefner
9efaa669eb Delete .ruby-version in generated plugin dummy app
A .ruby-version file is not useful in a plugin dummy app because the
plugin itself dictates the required Ruby version.  Indeed, the dummy app
.ruby-version file might fall out of sync with whatever the plugin
dictates, and thus result in unexpected "Could not find gem" errors when
running commands from within the dummy app directory.
2020-02-16 15:02:37 -06:00
Jonathan Hefner
7e54d3bc21 Fix rails new --dev
Follow-up to #38429.

`Rails::Command.invoke` passes arguments through to the appropriate
command class.  However, some command classes were ignoring those
arguments, and instead relying on the contents of ARGV.  In particular,
RakeCommand expected ARGV to contain the arguments necessary to the Rake
task, and no other arguments.  This caused the `webpacker:install` task
to fail when the `--dev` option from `rails new --dev` remained in ARGV.

This commit changes the relevant command classes to not rely on the
previous contents of ARGV.  This commit also adds a missing `require`
for use of `Kernel#silence_warnings`.

Fixes #38459.
2020-02-16 00:44:37 -06:00
Rafael França
d9bfafd9b8
Merge pull request #38441 from fastruby/grammar-update
Grammar update
2020-02-13 16:51:10 -05:00
Rafael França
428509700b
Merge pull request #38442 from roramirez/routes-in-scaffold_controller
scaffold_controller: Include the routes when create a generator Controller
2020-02-13 14:45:19 -05:00
Rodrigo Ramírez Norambuena
55b2264746 scaffold_controller: Include the routes when create a generator Controller
When is use a scaffold_controller add the routes as resources to the
config/route.rb

Also enable to use --skip-routes if doesn't want include the resources
into the config/routes.rb file.
2020-02-13 11:07:21 -03:00
eileencodes
c1a215a06b
Add schema cache tests
The schema cache tests test the following scenarios:

1) The default case works (single db, primary spec name (dev is default
to primary in 2-tier config), standard default schema cache filename)
2) Primary always wins over other entries
3) A custom schema cache filename works when set in the configuration
4) A custom schema cache filename works when set in the ENV

Cases that don't work:

1) A non-primary database entry picks up a namespaced schema cache file

This can't work currently because there's no way of knowing which cache
we actually want. In this railtie we can only load ActiveRecord::Base's
schema cache. If we grab the first config we risk loading a cache for
another connection because order is not guaranteed.

2) Multi-db schema caches

The reasons are similar to above. In addition we can't loop through the
configs, establish a connection, and load the cache because we don't
know what parent class to establish a connection to. In that case AR
Base will always get the cache and it would cause the last one to win
and therefore be loaded on the wrong connection.

The real fix for these issues is to get rid of the railtie entirely, but
for now we needed to set this back to what the behavior was before
recent changes but with the ability to pass a custom key.

Co-authored-by: Katrina Owen <kytrinyx@github.com>
2020-02-13 09:06:18 -05:00
aminamos
149d53e818 removing edits where setup is referred to as a method and not a verb 2020-02-12 13:31:43 -05:00
aminamos
7bb0706f2c update from PR #36222 2020-02-12 13:31:43 -05:00
Jonathan Hefner
f8204cb98a Add tmp/ to generated plugin .gitignore
The documentation for Rails::Generators::TestCase suggests using tmp/ as
the destination directory when testing generators.  Many plugins test
generators, so it makes sense to include tmp/ in the default .gitignore.
2020-02-11 12:54:06 -06:00
Jonathan Hefner
f6f51632e8 Use rails_command :inline option
Follow-up to #37516.
2020-02-10 17:53:41 -06:00
Kasper Timm Hansen
c77a949299
Merge pull request #38067
Closes #38067
2020-02-10 02:52:47 +01:00
Kurtis Rainbolt-Greene
ef7599fe91
Extract internal ActiveSupport::ConfigurationFile object
Rails has a number of places where a YAML configuration file is read,
then ERB is evaluated and finally the YAML is parsed.

This consolidates that into one common class.

Co-authored-by: Kasper Timm Hansen <kaspth@gmail.com>
2020-02-10 02:50:12 +01:00
Kasper Timm Hansen
420d533021
Merge pull request #37988 from abhaynikam/37823-change-action-mailbox-installer-to-generator
Add ActionMailbox install generator
2020-02-10 02:32:08 +01:00
Kasper Timm Hansen
e8070990ef Merge pull request #37516 from jonathanhefner/generator-generate-avoid-shell-out
Avoid shelling out for generator `generate` action
2020-02-09 23:29:23 +01:00
Kasper Timm Hansen
8818d4754d Merge pull request #38421 from jonathanhefner/plugin-anchor-gitignore-entries
Anchor generated plugin .gitgnore entries
2020-02-09 23:16:31 +01:00
Kasper Timm Hansen
b7027099b1
Update git init when generating plugins
* Extract separate test, test with `--skip-git`
* Move `version_control` beneath `gitignore` to match `AppBuilder` from 8989a505
* Add changelog entry
2020-02-09 23:04:29 +01:00
Kasper Timm Hansen
71b6d721f7
Merge pull request #38396 from okuramasafumi/plugin-generator-git-init
Initialize Git when generating plugins
2020-02-09 22:51:34 +01:00
Jonathan Hefner
e0692257b7 Anchor generated plugin .gitgnore entries
This is a good practice to encourage to prevent inadvertent exclusions
from version control.  This also matches generated app .gitignore files.
2020-02-09 15:45:08 -06:00
Kasper Timm Hansen
a0569ff8c3
Group requires together 2020-02-09 17:44:41 +01:00
Kasper Timm Hansen
9128c09448
Merge pull request #38410 from jonathanhefner/plugin-deobfuscate-rake-version-error
Deobfuscate Rake version error in generated plugin
2020-02-09 17:43:12 +01:00
Jonathan Hefner
437896e249 Deobfuscate Rake version error in generated plugin
If the plugin or one of its dependencies requires a version of Rake
that is different than the version executing the Rakefile,
`require 'bundler/setup'` will raise a LoadError with a helpful error
message like: "You have already activated rake 13.0.1, but your Gemfile
requires rake 12.3.3. Prepending `bundle exec` to your command may solve
this."

If that LoadError is swallowed, another LoadError will eventually be
raised with a less helpful / more confusing error message like: "cannot
load such file -- rake".
2020-02-07 15:04:48 -06:00