Commit Graph

13442 Commits

Author SHA1 Message Date
Abhay Nikam
b9879bb8ad The abstract parent class file generated via generator should not be pluralized
Currently, the file generated via the generator is pluralized
but the parent class is singluar.

example: bundle exec rails g scaffold Pet name:string --database=animals

The above command should generate: apps/models/animals_record.rb

but the pets model would inherit from: `AnimalRecord` as
`"animals".classify` would be `Animal`

This will throw the `uninitialized constant AnimalRecord Did you mean? AnimalsRecord`
error.
2020-08-02 22:25:57 +05:30
Jonathan Hefner
f24347031f Load plugin VERSION constant by default
For example, for a plugin like `my_plugin`, this makes the
`MyPlugin::VERSION` constant available to all consumers by default.

This commit also replaces the default generated test with a test that
the developer is less likely to delete.
2020-07-31 15:43:34 -05:00
Eugene Kenny
6b359cef39
Merge pull request #39959 from jonathanhefner/plugin-test-class-naming-convention
Follow naming conventions in generated plugin test
2020-07-31 21:31:50 +01:00
Jonathan Hefner
0098088fc1 Follow naming conventions in generated plugin test
This commit ensures that a generated test file like "foo/bar_test.rb"
defines the class `Foo::BarTest` rather than `Foo::Bar::Test`.
2020-07-31 10:01:48 -05:00
André Luis Leal Cardoso Junior
a636aa940b Adds db:migrate:redo:NAME support for multidbs
On current master with multiple DBs configured, calling db:migrate:redo fails when trying to run db:rollback.

Before:

```
» bin/rails db:migrate:redo
rake aborted!
You're using a multiple database application. To use `db:rollback` you must run the namespaced task with a VERSION. Available tasks are db:rollback:primary and db:rollback:secondary.
Tasks: TOP => db:rollback
(See full trace by running task with --trace)
```

After:

```
» bin/rails db:migrate:redo
rake aborted!
You're using a multiple database application. To use `db:migrate:redo` you must run the namespaced task with a VERSION. Available tasks are db:migrate:redo:primary and db:migrate:redo:secondary.
Tasks: TOP => db:migrate:redo
(See full trace by running task with --trace)
```

Running the namespaced version:

```
» bin/rails db:migrate:redo:secondary
== 20200728162820 CreateAnimals: reverting ====================================
-- drop_table(:animals)
   -> 0.0025s
== 20200728162820 CreateAnimals: reverted (0.0047s) ===========================

== 20200728162820 CreateAnimals: migrating ====================================
-- create_table(:animals)
   -> 0.0028s
== 20200728162820 CreateAnimals: migrated (0.0029s) ===========================
```
2020-07-30 22:15:22 -03:00
Abhay Nikam
db5c619541 Fixed typo AnimalsRecrd -> AnimalsRecord [ci skip] 2020-07-30 12:56:54 +05:30
eileencodes
261cbcd2a8
Generate abstract class when generating scaffold in another database
This PR ensures that when you're generating a scaffold or model and that
model should belong to another database it will create an abstract class
if it doesn't already exist.

The new abstract class will ensure that the new model inherits from that
class, but will not be deleted if the scaffold is deleted. This is
because Rails can't know if you have other models inheriting from that
class so we don't want to revoke that if the scaffold is destroyed.

If the abstract class already exists it won't be created twice. If the
options for `parent` are set, the generator will use that as the
abstract class instead of creating one. The generated abstract class
will add the writing connection automatically, users need to add the
reading connection themselves as Rails doesn't know which is the reading
connection.

Co-authored-by: John Crepezzi <john.crepezzi@gmail.com>
2020-07-29 12:43:45 -04:00
Eugene Kenny
4560c36da2
Merge pull request #39933 from exterm/engines-are-not-applications
Correct engine generator docs
2020-07-28 23:19:05 +01:00
Jonathan Hefner
adfa417fbb Use standard config/application.rb in plugin dummy
The `config/application.rb` file of a plugin test dummy app should be
the same as in a standard Rails app, with the exception of an additional
`require` statement to load the plugin itself.  However, prior to this
commit, the plugin generator used a specialized template for a portion
of this file, which tended to drift out-of-sync with the standard app
generator's template.  Specifically, this drift could result in missing
`require` statements of newer Rails frameworks when the plugin generator
was run with any `--skip-xxxx` option.

This commit changes the plugin generator to insert its additional
`require` statement into the standard `config/application.rb` file
generated by the app generator.
2020-07-28 14:33:40 -05:00
Philip Müller
dee804345d
[ci skip] Correct engine generator docs
Engines are not applications, indeed 'Application < Engine', so it's the other way round.
The difference can be confusing anyway, so we should make sure the documentation is clear.
2020-07-27 10:22:29 -04:00
Eugene Kenny
c418fb9fe9
Merge pull request #39708 from jonathanhefner/finish_template-goes-last
Ensure principle tasks go before finish_template
2020-07-18 23:49:24 +01:00
Eugene Kenny
aa85c4ba0c
Merge pull request #39829 from tgxworld/remove_protect_from_forgery_from_application_controller_template
Remove `protect_from_forgery` in rails plugin template.
2020-07-17 00:12:27 +01:00
Chris Oliver
12afb7fb4b
Allow passing URL params to conductor form for inbound emails 2020-07-14 14:02:43 -04:00
Guo Xiang Tan
85316f7bbe
Remove protect_from_forgery in rails plugin template.
`protect_from_forgery` is added to `ActionController::Base` by default
since ec4a836919c021c0a5cf9ebeebb4db5e02104a55
2020-07-13 14:39:30 +08:00
Guo Xiang Tan
f1e53be508
Change default HTTP status to 308 for ActionDispatch::SSL.
308 status code introduced in https://tools.ietf.org/html/rfc7538
preserves the request method unlike 301 status code which would convert
POST requests to GET.
2020-07-06 14:51:24 +08:00
Eugene Kenny
1f1e45630e
Merge pull request #39671 from hahmed/railties/speed-up-test-skip-webpack-install
Speed up railties test test_skip_webpack_install currently ~10s
2020-06-29 23:56:21 +01:00
Jean Boussier
12f3f11f61 Use URI::DEFAULT_PARSER rather than instantiate a new one 2020-06-29 23:06:34 +02:00
Jonathan Hefner
a6e1be7148 Ensure principle tasks go before finish_template
This fixes a regression of #13637, and adds a regression test.
2020-06-23 23:31:47 -05:00
Haroon Ahmed
46045e35ed Speed up test_skip_webpack_install from ~10s to < 5s by avoiding the call to bundler, I also added an assertion for webpacker which was needed for this test 2020-06-22 21:15:12 +01:00
Javan Makhmali
664e94989e
Merge pull request #39521 from rossta/patch/use-import-syntax-in-application-js-template
Use ES module import syntax in application js template
2020-06-18 07:43:09 -04:00
Ross Kaffenberger
04cbaa1475 Use ES module syntax for application.js.tt and docs
This change swaps the CommonJS require() syntax in the Webpacker
application.js pack template file and in documentation examples with ES
module import syntax.

Benefits of this change include:

Provides continuity with the larger frontend community: Arguably, one of
the main draws in adopting Webpacker is its integration with Babel to
support ES module syntax. For a fresh Rails install with Webpacker, the
application.js file will be the first impression most Rails developers
have with webpack and Webpacker.  Most of the recent documentation and
examples they will find online for using other libraries will be based
on ES module syntax.

Reduces confusion: Developers commonly add ES imports to their
application.js pack, typically by following online examples, which means
mixing require() and import statements in a single file. This leads to
confusion and unnecessary friction about differences between require()
and import.

Embraces browser-friendliness: The ES module syntax forward-looking and
is meant to be supported in browsers. On the other hand, require()
syntax is synchronous by design and not browser-supported as CommonJS
originally was adopted in Node.js for server-side JavaScript. That
webpack supports require() syntax is merely a convenience.

Encourages best practices regarding optimization: webpack can statically
analyze ES modules and "tree-shake", i.e., strip out unused exports from
the final build (given certain conditions are met, including
`sideEffects: false` designation in package.json).
2020-06-16 15:12:12 -04:00
Henrik Nyh
63824f9ffb
setup.tt comment: "at anytime" -> "at any time"
https://www.grammarly.com/blog/anytime-any-time/
2020-06-16 16:19:27 +01:00
Rafael França
acf87b4ed2
Merge pull request #39632 from jonathanhefner/springy-boot
Move Spring machinery to boot.rb
2020-06-15 22:42:07 -04:00
Jonathan Hefner
a6c958b3a7 Move Spring machinery to boot.rb
This partially reverts #39225, and folds `boot_with_spring.rb` into
`boot.rb`.

Fixes #39622.
2020-06-15 17:32:55 -05:00
Jonathan Hefner
f67e4cb7e5 Ensure times-called assertions are evaluated
If an assertion is inside a method stub, it may never be evaluated.
This is particularly problematic when asserting a method is called a
non-zero number of times.

This commit moves such assertions outside their method stubs.
2020-06-15 02:10:58 -05:00
Ryuta Kamizono
528b62e386 Address to false negative for Performance/DeletePrefix,DeleteSuffix
Follow up to c07dff72278fb7f2a3c4c71212a0773a2b25c790.

Actually it is not the cop's fault, but we mistakenly use `^`, `$`, and
`\Z` in much places, the cop doesn't correct those conservatively.

I've checked all those usage and replaced all safe ones.
2020-06-14 13:04:47 +09:00
Josef Šimánek
a49dfe38ae
Introduce Rails::TestUnitReporter.app_root to inject app_root when needed. 2020-06-14 00:02:49 +02:00
Josef Šimánek
32aebc76cb
Use COMPONENT_ROOT as app_root when present in test unit reporting. 2020-06-13 20:30:25 +02:00
Étienne Barrié
cf3736dce8
Add application config for URL-safe Base64 CSRF tokens
This allows applications to safely upgrade to Rails 6.1 without
breaking tokens while the deploy is still being rolled out.
2020-06-11 11:39:37 -04:00
Kasper Timm Hansen
4654f4aab6
Merge pull request #39541 from jonathanhefner/silence-rake-task-backtraces
Silence Rake task backtraces
2020-06-05 12:54:11 +02:00
Jonathan Hefner
7ba531be74 Silence Rake task backtraces
Silence Rake task backtraces, similar to Rails::BacktraceCleaner.
Application lines are preserved, but all other lines are hidden.

This also affects unrecognized tasks, causing the backtrace to be hidden
entirely.  Closes #39524.

Co-authored-by: Petrik <petrik@deheus.net>
2020-06-05 02:26:46 -05:00
Ryuta Kamizono
c07dff7227 Auto-correct for delete_prefix/delete_suffix
Follow up to #39409.
2020-06-05 12:40:39 +09:00
Eileen M. Uchitelle
e95edb3d6d
Merge pull request #39536 from eileencodes/remove-assumption-that-primary-exists
Remove assumption that a primary config exists
2020-06-04 16:03:03 -04:00
eileencodes
e7b1e118b9
Fix schema cache load and corresponding test
This test was incorrect. `primary` was winning for the schema cache load
but when you boot an application it's actually the first configuration
that wins (in a multi db app).

The test didn't catch this because I forgot to add a migrations_paths to
the configuration.

We updated the schema cache loader railtie as well because any
application that didn't have a `primary` config would not be able to use
the schema cache. Originally we thought we'd enforce a `primary`
configuration but no longer feel that's correct. It's simpler to say
that the first wins in a 3-tier rather than implementing a solution to
require `primary` and / or allow aliases.

Co-authored-by: John Crepezzi <john.crepezzi@gmail.com>
Co-authored-by: John Hawthorn <john@hawthorn.email>
2020-06-04 15:12:12 -04:00
eileencodes
7b4fdf3ce7
Remove assumption that a primary config exists
Applications may not have a primary configuration so we should not
assume there is one. In both these cases we can get the right connection
without that.

For the databases.rake file we want to re-establish a connection for the
environment we're in. The first config defined under an environment for
a multi-db app will win. This is already the case on application boot so
we should be consistent.

For the info.rb file we already have a connection so we can lookup the
adapter from the connection's db_config. If a primary hadn't existed
this would have thrown an exception.

Followup to https://github.com/rails/rails/pull/39535 which removed the
assumption there was a primary config from the schema cache load
railtie.

Co-authored-by: John Crepezzi <john.crepezzi@gmail.com>
2020-06-04 15:08:59 -04:00
Aaron Patterson
35fe9bc0aa
Merge pull request #39477 from p8/improve-inspect
Make custom inspect methods more consistent
2020-06-03 10:43:35 -07:00
Eugene Kenny
751d46af4f
Merge pull request #39523 from p8/rename-stubs-out-to-generate
Replace 'Stubs out' with 'Generates' in generator USAGE's [ci skip]
2020-06-03 10:40:40 +01:00
Petrik
2b09948637 Replace 'Stubs out' with 'Generates' in generator USAGE's [ci skip]
Generators generate things, but what is meant by 'Stubbing out' might
confuse beginners and non-native English speakers.
While generated tests are stubs that should have an implementation, a
generated model is a valid model that doesn't require any changes.
2020-06-03 08:51:47 +02:00
Haroon Ahmed
7a321d8429
rails new --minimal gives you a minimal rails stack. (#39282) 2020-06-02 13:29:02 -07:00
Petrik
c7a3894667 Fix test name that no longer raises exception 2020-06-02 10:01:30 +02:00
Jonathan Hefner
08aeb01b0f Lazily build path regex in PathParser
Eagerly building the path regex can exclude handlers which are added on
Action View load.

Fixes #39492.
2020-05-31 15:28:24 -05:00
jasl
34adebd4a7 Don't inline run webpacker:install on rails new 2020-05-30 05:44:04 +08:00
Petrik
74cb9a6f38 Make inspect look more like regular Object#inspect
Move the # outside the < > just like regular Object#inspect
2020-05-29 21:53:35 +02:00
Ryuta Kamizono
c65864cdca Prefer no allocation start/end_with? over String#[] == 2020-05-29 10:20:13 +09:00
Eugene Kenny
0ebc720a04 Set retry_jitter to 0.0 for upgraded applications
The point of new framework defaults is that they're opt-in for upgraded
applications, but the default for this option applied the new behaviour.
2020-05-27 22:15:19 +01:00
John Hawthorn
db543ba728
Merge pull request #39361 from jhawthorn/path_parser
Introduce Resolver::PathParser
2020-05-26 20:16:18 -07:00
John Hawthorn
a70ad604cf Add railties test of custom handlers and formats 2020-05-26 19:27:38 -07:00
Ryuta Kamizono
dc94a753d1 require "active_support/core_ext/symbol/starts_ends_with" for Ruby 2.6
And use `Symbol#[]` to strip suffix to avoid intermediate string
allocation.
2020-05-25 05:24:44 +09:00
Jonathan Hefner
a2ca8f062c Utilize Symbol#start_with? and #end_with?
Follow-up to #39155.

Thanks to Symbol#start_with? and #end_with?, these calls no longer need
to be prefixed with `.to_s`.
2020-05-24 14:46:12 -05:00
fatkodima
e24d6ecbfd Update rubocop-performance gem and enable Performance/DeletePrefix and Performance/DeleteSuffix cops 2020-05-24 12:51:35 +03:00