Commit Graph

12409 Commits

Author SHA1 Message Date
eileencodes
26821d9b57 Add test parallelization to Rails
Provides both a forked process and threaded parallelization options. To
use add `parallelize` to your test suite.

Takes a `workers` argument that controls how many times the process
is forked. For each process a new database will be created suffixed
with the worker number; test-database-0 and test-database-1
respectively.

If `ENV["PARALLEL_WORKERS"]` is set the workers argument will be ignored
and the environment variable will be used instead. This is useful for CI
environments, or other environments where you may need more workers than
you do for local testing.

If the number of workers is set to `1` or fewer, the tests will not be
parallelized.

The default parallelization method is to fork processes. If you'd like to
use threads instead you can pass `with: :threads` to the `parallelize`
method. Note the threaded parallelization does not create multiple
database and will not work with system tests at this time.

parallelize(workers: 2, with: :threads)

The threaded parallelization uses Minitest's parallel exector directly.
The processes paralleliztion uses a Ruby Drb server.

For parallelization via threads a setup hook and cleanup hook are
provided.

```
class ActiveSupport::TestCase
  parallelize_setup do |worker|
    # setup databases
  end

  parallelize_teardown do |worker|
    # cleanup database
  end

  parallelize(workers: 2)
end
```

[Eileen M. Uchitelle, Aaron Patterson]
2018-02-15 19:21:24 -05:00
Kevin Robatel
40a5ba30fb Add SuppressedSummaryReporter and TestUnitReporter only if necessary 2018-02-15 10:02:26 +01:00
claudiob
b77861d0c9 Don't overwrite config/master.key even on --force
See https://github.com/rails/rails/pull/31957#issuecomment-364817423

The purpose of `--force` is not to have any prompt whether a file should
be kept or overwritten. In general, all existing files should be overwritten.
However, `config/master.key` is special because it is git-ignored, and
overwriting it will cause the app not to run (since there won't be a way
to decrypt the credentials).

As a result, it's probably better to keep the existing config/master.key.
2018-02-12 22:10:28 -08:00
Yuji Yaginuma
2c4e9c678b
Do not update load_defaults version when running app:update (#31951)
Incompatible settings are included in the settings set by `load_defaults`.
So, I think that target version should be updated by a user when becomes
available, and should not be updated with `app:update`.
2018-02-13 07:13:38 +09:00
claudiob
24284fd3d4 Respect --force option for config/master.key
This is similar to #30700 which ensures the `--quiet` option of `rails new`
is respected by the `MasterKeyGenerator` (missing from #30067).

Before this commit, running `rails new app --force` would still prompt the
user what to do with the conflict in `config/master.key`:

```
              …
   identical  config/locales/en.yml
    conflict  config/master.key
Overwrite /Users/claudiob/Desktop/pizza/config/master.key? (enter "h" for help) [Ynaqdh]
```

After this commit, `config/master.key` is overwritten:

```
           …
identical  config/locales/en.yml
    force  config/master.key
   append  .gitignore
```

The newly added test generates an app and then generates it again with
`--force`. Without this commit, the test would just wait forever for user
input.
2018-02-11 11:37:21 -08:00
Claudio B
936a96a98b
Merge pull request #31949 from rails/remove-move
Remove warning from 4 years ago [ci skip]
2018-02-09 16:55:05 -08:00
claudiob
4491ce902b Remove warning from 4 years ago [ci skip]
`config/initializers/assets.rb` has been a part of Rails apps since
Rails 4.2 (30b56084). This comment is probably unnecessary by now.
2018-02-09 16:49:38 -08:00
Yoshiyuki Hirano
1469657349 Use heredoc with credentials template
* Use heredoc with credentials template.
* Fix indentation for aws config
2018-02-09 15:38:44 +09:00
Yuji Yaginuma
5d75ef72e6
Do not add master key when RAILS_MASTER_KEY env specified (#31922)
Fixes #31917
2018-02-08 19:49:50 +09:00
yuuji.yaginuma
cb9e35ee00 Add nodoc to CredentialsGenerator and MasterKeyGenerator [ci skip]
These classes are internally used only.
2018-02-03 09:06:09 +09:00
Wojciech Wnętrzak
c8dc4f2e41
Removed "private" generators from command list.
Appropriate way to handle encrypted command is by `bin/rails credentials` and
`bin/rails encrypted`

It was displayed on `bin/rails generate` command:
```
Please choose a generator below.

Rails:
  application_record
  assets
  channel
  controller
  encrypted_file
  encryption_key_file
  generator
  ...
```
2018-02-02 10:33:19 +01:00
Yuji Yaginuma
71a392c465 Fix RuntimeError: Unknown version "6.0" 2018-01-31 14:14:56 +09:00
Rafael Mendonça França
1c383df324 Start Rails 6.0 development!!!
🎉🎉🎉
2018-01-30 18:51:17 -05:00
Rafael França
bec74e1d4a
Merge pull request #31830 from rafaelfranca/disable-csp-by-default
Disable CSP by default
2018-01-30 18:30:13 -05:00
George Claghorn
54bb2f74b5 Add Rack::TempfileReaper to tests and docs 2018-01-30 18:21:07 -05:00
George Claghorn
cdffab4bc7 Add Rack::TempfileReaper to the default middleware stack 2018-01-30 18:13:13 -05:00
Rafael Mendonça França
39c4a5c40b Disable CSP by default
Before this patch, to be able to use webpacker and webconsole we were
defining an used default in the script-src policy. White we don't
implement the automatic nonce approach defined in
https://github.com/rails/rails/issues/31689 it is better to not have any
default configuration in Rails 5.2.
2018-01-30 17:50:32 -05:00
Matthew Draper
44fc16c284 Merge pull request #31769 from justjake/patch-2
yarnpkg: correct exec syntax
2018-01-30 11:57:32 +10:30
Daniel Colson
fda1863e1a Remove extra whitespace 2018-01-25 23:32:59 -05:00
Daniel Colson
82c39e1a0b Use assert_empty and assert_not_empty 2018-01-25 23:32:59 -05:00
Daniel Colson
94333a4c31 Use assert_predicate and assert_not_predicate 2018-01-25 23:32:59 -05:00
Daniel Colson
211adb47e7 Change refute to assert_not 2018-01-25 23:32:58 -05:00
Daniel Colson
0d50cae996 Use respond_to test helpers 2018-01-25 23:32:58 -05:00
Yuji Yaginuma
d25c2e7c4c
Merge pull request #31750 from morygonzalez/consider-locale_selector-missing
Fix locale_selector JS bug in ActionMailer Preview
2018-01-23 19:05:09 +09:00
Jake Teton-Landis
388f64a265
yarnpkg: correct exec syntax
Previous change didn’t expand this array of arguments
2018-01-23 00:44:19 -08:00
Hitoshi Nakashima
77453cfa28 Fix locale_selector JS bug in ActionMailer Preview 2018-01-23 09:32:49 +09:00
Jake Teton-Landis
92e3d95099
bin/yarn: Pass through arguments with spaces
Previously, the `bin/yarn` wrapper would "unquote" arguments to yarn like this:
`yarn run add-copyright "(c) 2017, 2018 MyCompany"`
That results in an ARGV of ['run', 'add-copyright', '(c) 2017, 2018 MyCompany'] in the yarn wrapper,
but a ARGV in the yarn executable of ['run', 'add-copyright', '(c)',  '2017,', '2018', MyCompany']
2018-01-21 09:28:05 -08:00
Yuji Yaginuma
9bf41f2495
Merge pull request #31641 from ckoenig/remove_frozen_string_literal
Use dup'ed options hash
2018-01-20 18:53:10 +09:00
Matthew Draper
acbcef6094
Merge pull request #31732 from koic/enable_autocorrect_for_lint_end_alignment_cop
Enable autocorrect for `Lint/EndAlignment` cop
2018-01-19 17:49:21 +10:30
Hitoshi Nakashima
5fe603ac28 Add locale selector to email preview (#31596)
- Add set_locale to detect suitable locale
- Make feature compatible with Rails 5.x
2018-01-18 15:22:10 -05:00
Eileen M. Uchitelle
7df7780e40
Merge pull request #31730 from bogdanvlviv/allow_false_for-config-generators-system_tests
Allow `false` for `config.generators.system_tests=`
2018-01-18 14:54:13 -05:00
eileencodes
e0ad907ade Add test to properly test down with a block
down is only called with a block from the rake tasks where it passes a
`SCOPE`. Technically this was tested but since we don't run all the
migrations we're not actually testing the down works with a `SCOPE`. To
ensure we're testing both we can run `db:migrate` again to migrate users
and then run `down` with a scope to test that only the bukkits migration
is reverted.

Updates test to prevent having to fix regressions like we did in
4d4db4c.
2018-01-18 13:09:15 -05:00
Matthew Draper
c046143408 Revert "Merge pull request #31434 from olivierlacan/boot-feedback"
This reverts commit edc54fd2068bc21f0d381228e55d97e32f508923, reversing
changes made to a5922f132f4d163e2c7f770427087f5268c18def.

As discussed, this is not an appropriate place to make assumptions about
ARGV, or to write to stdout: config/boot.rb is a library and is required
by other applictions, with which we have no right to interfere.
2018-01-19 01:28:49 +10:30
eileencodes
a2827ec981 Refactor migration to move migrations paths to connection
Rails has some support for multiple databases but it can be hard to
handle migrations with those. The easiest way to implement multiple
databases is to contain migrations into their own folder ("db/migrate"
for the primary db and "db/seconddb_migrate" for the second db). Without
this you would need to write code that allowed you to switch connections
in migrations. I can tell you from experience that is not a fun way to
implement multiple databases.

This refactoring is a pre-requisite for implementing other features
related to parallel testing and improved handling for multiple
databases.

The refactoring here moves the class methods from the `Migrator` class
into it's own new class `MigrationContext`. The goal was to move the
`migrations_paths` method off of the `Migrator` class and onto the
connection. This allows users to do the following in their
`database.yml`:

```
development:
  adapter: mysql2
  username: root
  password:

development_seconddb:
  adapter: mysql2
  username: root
  password:
  migrations_paths: "db/second_db_migrate"
```

Migrations for the `seconddb` can now be store in the
`db/second_db_migrate` directory. Migrations for the primary database
are stored in `db/migrate`".

The refactoring here drastically reduces the internal API for migrations
since we don't need to pass `migrations_paths` around to every single
method. Additionally this change does not require any Rails applications
to make changes unless they want to use the new public API. All of the
class methods from the `Migrator` class were `nodoc`'d except for the
`migrations_paths` and `migrations_path` getter/setters respectively.
2018-01-18 08:55:03 -05:00
Koichi ITO
5ac6ec54a6 Enable autocorrect for Lint/EndAlignment cop
### Summary

This PR changes .rubocop.yml.

Regarding the code using `if ... else ... end`, I think the coding style
that Rails expects is as follows.

```ruby
var = if cond
  a
else
  b
end
```

However, the current .rubocop.yml setting does not offense for the
following code.

```ruby
var = if cond
        a
      else
        b
      end
```

I think that the above code expects offense to be warned.
Moreover, the layout by autocorrect is unnatural.

```ruby
var = if cond
  a
      else
        b
      end
```

This PR adds a setting to .rubocop.yml to make an offense warning and
autocorrect as expected by the coding style.
And this change also fixes `case ... when ... end` together.

Also this PR itself is an example that arranges the layout using
`rubocop -a`.

### Other Information

Autocorrect of `Lint/EndAlignment` cop is `false` by default.
https://github.com/bbatsov/rubocop/blob/v0.51.0/config/default.yml#L1443

This PR changes this value to `true`.

Also this PR has changed it together as it is necessary to enable
`Layout/ElseAlignment` cop to make this behavior.
2018-01-18 17:19:13 +09:00
bogdanvlviv
a2aa18f897
Allow false for config.generators.system_tests=
Mention `config.generators.system_tests` in
the "Configuring Rails Applications" guide.
2018-01-18 01:15:19 +02:00
George Claghorn
6fb3ac1536 Provide a sensible default host 2018-01-16 20:32:02 -05:00
George Claghorn
c2ba530c43
Extract content types from blob data 2018-01-15 13:06:17 -05:00
Yuji Yaginuma
0c743885ba
Merge pull request #31572 from kami-zh/fix-template
Fix comment about initializers to adapt to the fact
2018-01-13 14:50:43 +09:00
Sean Griffin
f8afb5168a
Merge pull request #31651 from eugeneius/use_sha1_digests
Use SHA-1 for non-sensitive digests by default
2018-01-12 15:03:32 -07:00
David Heinemeier Hansson
0f7d3b612c Use unsafe_inline as the default for script_src CSP until we get a nonce alternative
Closes #31273 but we will still want to upgrade this to the
nonce-approach when it’s ready.
2018-01-12 15:35:22 +01:00
David Heinemeier Hansson
9a023c83ca Add note about having to restart when modifying initializer 2018-01-12 15:21:27 +01:00
David Heinemeier Hansson
4697b19b88 Use complete variable names rather than single-letter abbreviations for style 2018-01-12 15:07:32 +01:00
Rafael Mendonça França
181836d894 Merge pull request #31671 from larskanis/pg-1.0
PostgreSQL: Allow pg-1.0 gem to be used with ActiveRecord
2018-01-11 14:31:37 -05:00
Aaron Patterson
013a8abd48
Merge pull request #31624 from y-yagi/fix_minitest_511
Add support for Minitest 5.11
2018-01-10 15:46:29 -08:00
Lars Kanis
f820dc2dea PostgreSQL: Allow pg-1.0 gem to be used with ActiveRecord
pg-1.0.0 is just released and most Gemfiles don't restrict
it's version. But the version is checked when connecting to
the database, which leads to the following error:

Gem::LoadError: can't activate pg (~> 0.18), already activated pg-1.0.0

See also this pg issue:
https://bitbucket.org/ged/ruby-pg/issues/270/pg-100-x64-mingw32-rails-server-not-start

Preparation for pg-1.0 was done in commit f28a331023fab,
but the pg version constraint was not yet relaxed.
2018-01-10 21:55:43 +01:00
bogdanvlviv
b6ed9a7f01
Clean up railties tests
Remove `AppGeneratorTest#test_active_storage_install`.
  The test is added by 67db41aa7f17c2d34eb5a914ac7a6b2574930ff4,
  since #31534 this test doesn't test anything.

  Remove redundant assertions in `SharedGeneratorTests`.
  These assertions is added by 4a835aa3236eedb135ccf8b59ed3c03e040b8b01.
  Follows 67db41aa7f17c2d34eb5a914ac7a6b2574930ff4, #31534.
2018-01-10 13:05:01 +02:00
Kasper Timm Hansen
33721a71e3
Merge pull request #31534 from claudiob/kaspth-approach
Don't include Active Storage migrations in new apps
2018-01-09 20:59:04 +01:00
Christof Koenig
c33f47df67 Work on a dup'ed options hash
Otherwise, at least using JRuby, the replacements in
convert_database_option_for_jruby won't work. Thus a call to

    bundle exec rails app:update

fails. Simply replacing those replace statements doesn't seem to work
either, since the options hash seems to be frozen, too.
2018-01-09 09:13:52 +01:00
Eugene Kenny
d034f488f9 Use SHA-1 for non-sensitive digests by default
Instead of providing a configuration option to set the hash function,
switch to SHA-1 for new apps and allow upgrading apps to opt in later
via `new_framework_defaults_5_2.rb`.
2018-01-08 20:45:46 +00:00
Eugene Kenny
d2113777a1 Allow use_authenticated_message_encryption to be set in new_framework_defaults_5_2.rb
Enabling this option in new_framework_defaults_5_2.rb didn't work
before, as railtie initializers run before application initializers.

Using `respond_to?` to decide whether to set the option wasn't working
either, as `ActiveSupport::OrderedOptions` responds to any message.
2018-01-07 20:13:58 +00:00
Prathamesh Sonpatki
b821f95403
Improve the deprecation message for using subclass of Rails::Application to start the Rails server 2018-01-07 20:48:53 +05:30
yuuji.yaginuma
76b75ac094 Need to use klass to get the class name of the test result
Ref: http://docs.seattlerb.org/minitest/Minitest/Result.html#attribute-i-klass
2018-01-03 17:37:15 +09:00
yuuji.yaginuma
ff0d5f1450 Correctly get source location
`filtered_results` returns an instance of `Minitest::Result` since 00433fc0a4
`Minitest::Result` is not test class. So cannot get location directly.
2018-01-03 17:37:14 +09:00
Yoshiyuki Hirano
b20354afcc Bump license years for 2018 2017-12-31 22:36:55 +09:00
Eugene Kenny
fdd76b7370 Clarify that config.eager_load controls eager loading [ci skip]
Before Rails 4.0, `config.cache_classes` determined whether application
code was eager loaded. The `config.eager_load` option was introduced to
allow the two behaviours to be configured independently, but this
documentation was never updated to reflect that change.
2017-12-30 22:37:44 +00:00
yuuji.yaginuma
41c8e41ff1 Remove unused methods
* `assert_header` and `assert_body` were unused since 6f6a589.
* `assert_success` and `assert_missing` were unused since added.
2017-12-28 12:07:18 +09:00
kami-zh
13c66b1244 Fix comment about initializers to adapt to the fact
Currently the comment says application configuration should go into
files in `config/initializers`.
However some configuration couldn't initialize correctly because of the
initializing process(e.g. `config.time_zone`).

It should be changed by framework but this is large change and it may occur
malfunction to some applications which depends on current initializing
process.

So this comment is changed to adapt to the fact.
2017-12-27 13:37:38 +09:00
Yuji Yaginuma
4943c7ed11
Prevent to install gems when run test (#31564)
`invoke_all` cause `bundle install`. This will install gems actually
defined in `Gemfile`. To avoid this, stubbed `bundle_command`.

Fixes #31557
2017-12-26 08:23:33 +09:00
yuuji.yaginuma
91a4a820fe Ensure to use repo's Gemfile in application
Puma gets bundler's info from `Bundler::ORIGINAL_ENV` for restart.
f6f3892f4d/lib/puma/launcher.rb (L168)

So, specified `BUNDLE_GEMFILE` env for use same Gemfile in the restart.

Fixes #31351
2017-12-25 06:25:10 +09:00
yuuji.yaginuma
0eefc8fdac Move test_skip_bundle to AppGeneratorTest
`skip_bundle` option was removed from plugin generator in 9b72fcc3c22a6f75f37f52dd6cb682bc00c51cf0.
2017-12-24 21:04:25 +09:00
Daniel Lopez
0a27a574c4 Removes OS specific directory separator 2017-12-21 10:35:48 +09:00
Ryuta Kamizono
5232ddad65
Merge pull request #31520 from yahonda/introduce_frozen_error_class
Handle `FrozenError` if it is available
2017-12-20 21:29:43 +09:00
Yasuo Honda
01efbc128d Handle FrozenError if it is available
This pull request handles `FrozenError` introduced by Ruby 2.5.
Refer https://bugs.ruby-lang.org/projects/ruby-trunk/repository/revisions/61131

Since `FrozenError` is a subclass of `RuntimeError` minitest used by master
branch can handle it, though it would be better to handle `FrozenError`
explicitly if possible.

`FrozenError` does not exist in Ruby 2.4 or lower, `frozen_error_class`
handles which exception is expected to be raised.

This pull request is intended to be merged to master,
then backported to `5-1-stable` to address #31508
2017-12-20 11:52:01 +00:00
yuuji.yaginuma
3fcf72d480 Add test case that configure config.active_support.hash_digest_class
Follow up of #31289.
2017-12-20 19:28:54 +09:00
Eugene Kenny
69d5a74393 Remove verbose_query_logs from new_framework_defaults_5_2.rb
The `app:update` rake task will regenerate `development.rb` so that it
contains this option; that means we're currently adding it to existing
apps in two places, which is unnecessary and confusing.

Also:
 - Remove inaccurate comment about which stack frames are ignored
 - Clarify that the feature uses `caller_locations`, not `caller`
 - Remove unused return value in `extract_callstack`
2017-12-20 01:09:23 +00:00
yuuji.yaginuma
373a568324 Implicitly skip bootsnap for rails new --dev
Specifying the `--dev` option is when want to change the codebase,
as it is not necessary to cache it.

Context: https://github.com/rails/rails/pull/31485#issuecomment-352452653
2017-12-19 10:15:47 +09:00
Kasper Timm Hansen
053a4c6990
Merge pull request #31348 from y-yagi/fix_31283
Raise an error only when `require_master_key` is specified
2017-12-18 19:57:35 +01:00
Anton Rieder
391ec4e392
Update new_framework_defaults_5_2.rb.tt
Be consistent in comments when mentioning AES.
2017-12-18 18:28:16 +01:00
Eileen M. Uchitelle
ce2fc70c7b
Merge pull request #31485 from y-yagi/skip_bootsnap_option
Add `skip_bootsnap` option
2017-12-18 10:09:12 -05:00
yuuji.yaginuma
35373219c9 Raise an error only when require_master_key is specified
To prevent errors from being raise in environments where credentials
is unnecessary.

Context: https://github.com/rails/rails/issues/31283#issuecomment-348801489

Fixes #31283
2017-12-18 08:04:15 +09:00
yuuji.yaginuma
c5b900da73 Add test case that active_storage:install task works within engine
Follow up of #31391
2017-12-17 09:10:36 +09:00
yuuji.yaginuma
838b40da84 Add skip_bootsnap option
`bootsnap` is a useful gem normally. However, `bootsnap` is unnecessary
when generating a Rails application to be used only for testing.
So I want to control whether use this or not by option.
2017-12-16 20:07:50 +09:00
claudiob
74996cec93 Don't run rails active_storage:install in new apps
See #31315 for full discussion
2017-12-14 22:50:30 -08:00
Sean Griffin
edc54fd206
Merge pull request #31434 from olivierlacan/boot-feedback
Provide instant feedback when booting Rails
2017-12-14 16:49:02 -07:00
Eileen M. Uchitelle
4bd28efc18
Merge pull request #26815 from olivierlacan/log-query-source
Log the original call site for an ActiveRecord query
2017-12-14 08:10:19 -05:00
Ryuta Kamizono
245c1dafa8 Enable Layout/LeadingCommentSpace to not allow cosmetic changes in the future
Follow up of #31432.
2017-12-14 17:30:54 +09:00
Olivier Lacan
acc03bb695 Provide instant feedback when booting Rails
I've noticed during pair/mob programming sessions with peers that
despite the speed boosts provided by Bootsnap and Spring, there is a
noticeable latency between firing a bin/rails server command and any
feedback being provided to the console. Depending on the size of the
application this lack of feedback can make it seem like something is
wrong when Rails is simply busy initializing.

This change may seem gratuitous but by just printing one line to STDOUT
we're giving a clear signal to the Rails user that their command has
been received and that Rails is indeed booting. It almost imperciptibly
makes Rails feel more responsive.

Sure the code doesn't look very fancy but there's no other appropriate
place I could think of putting it than boot.rb.

Compare these two GIFs of booting without and with this change:

Before:
![Without Boot Feedback](https://user-images.githubusercontent.com/65950/33964140-721041fc-e025-11e7-9b25-9d839ce92977.gif)

After:
![With Boot Feedback](https://user-images.githubusercontent.com/65950/33964151-79e12f86-e025-11e7-93e9-7a75c70d408f.gif)
2017-12-13 20:50:27 -05:00
Olivier Lacan
3876defd7c Log call site for all queries
This new ActiveRecord configuration option allows you to easily
pinpoint what line of application code is triggering SQL queries in the
development log by appending below each SQL statement log the line of
Ruby code that triggered it.

It’s useful with N+1 issues, and to locate stray queries.

By default this new option ignores Rails and Ruby code in order to
surface only callers from your application Ruby code or your gems.

It is enabled on newly generated Rails 5.2 applications and can be
enabled on existing Rails applications:

```ruby
Rails.application.configure do
  # ...
  config.active_record.verbose_query_logs = true
end
```

The `rails app:upgrade` task will also add it to
`config/development.rb`.

This feature purposely avoids coupling with
ActiveSupport::BacktraceCleaner since ActiveRecord can be used without
ActiveRecord. This decision can be reverted in the future to allow more
configurable backtraces (the exclusion of gem callers for example).
2017-12-13 20:13:21 -05:00
Mehmet Emin INAC
ff25c25127
Expose Active Storage routes 2017-12-13 19:28:57 +01:00
Ryuta Kamizono
2b35826389 Enable Layout/SpaceBeforeComma rubocop rule, and fixed more
Follow up of #31390.
2017-12-12 20:00:50 +09:00
Stefan Wrobel
76e545546c
Fix secrets command deprecation message 2017-12-11 21:39:41 -08:00
Edouard CHIN
e6ef1a7673 create_fixtures doesn't work since at least a94220b66c9e4890007f66b092b25f8a64a19d31:
- The namespacing should be `ActiveRecord::FixtureSet`
- I might be missing something but I'm not sure why `create_fixtures` is useful for nowaday (unless for testing rails internal /shrug) and since it's been that long it wasn't working I think it should be fine to just fire it
2017-12-11 17:22:05 -05:00
Aaron Patterson
a50b8ea350
Set the Rails environment from an environment variable
Option parsing happens too late to have any impact on the Rails
environment.  Rails accesses the environment name and memoizes it too
early in the boot process for a commandline option to have any impact on
the database connection, so we'll change this test to set the
environment from an environment variable (and ensure it still works when
running tests with `ruby`)
2017-12-08 14:50:27 -08:00
Aaron Patterson
cd0283ef29
Revert "remove unnecessary RAILS_ENV setting"
This reverts commit 9a80f52541ed2c93ebef02909ecab3aaf9127150.
2017-12-08 13:27:30 -08:00
Aaron Patterson
a58543dbb1
Add failing test for wrong database connection
When tests are run with just `ruby`, the RAILS_ENV is set to
`development` too early, and we connect to the development database
rather than the test database.
2017-12-08 13:23:31 -08:00
Aaron Patterson
da225c0db6
Fix Rails environment when running tests with Ruby
I frequently run tests with `ruby`, not with a runner like `rake` or
`rails`.  When running the test with just `ruby` the `RAILS_ENV`
environment variable did not get set to "test", and this would cause the
tests to fail (and even mutate the development database!)

This commit adds integration tests for running tests with just `ruby`
and ensures the environment gets defaulted to "test".  I also added a
test to ensure that passing an environment to `-e` actually works (and
fixed that case too).

An interesting / annoying thing is that Minitest picks up it's plugins
by asking RubyGems for a list of files:

  ca6a71ca90/lib/minitest.rb (L92-L100)

This means that RubyGems needs to somehow know about the file before it
can return it to Minitest.  Since we are not packaging Rails as a Gem
before running the integration tests on it (duh, why would you do
that?), RubyGems doesn't know about the file, so it can't tell Minitest,
so Minitest doesn't automatically require it.  This means I had to
manually require and insert the plugin in our integration test.  I've
left comments about that in the test as well.

Ugh.
2017-12-06 20:40:04 -08:00
Tsukuru Tanimichi
6a11b0c154 Add more tests for the --webpack option 2017-12-05 18:43:15 +09:00
Tsukuru Tanimichi
b9fb74514b Modify test_webpack_option 2017-12-05 18:41:44 +09:00
Guillermo Iguaran
c383c4142a
Merge pull request #31279 from ttanimichi/tests-for-webpack-option
Add tests for the `--webpack` option
2017-12-04 10:37:54 -05:00
Tsukuru Tanimichi
915f0e682c Add tests for the --webpack option
We probably don't have any tests for the `--webpack` option.
related: #27288
2017-12-04 14:32:44 +09:00
Kasper Timm Hansen
dde620ac6e
Merge pull request #31311 from y-yagi/ignore_no_database_error_when_loading_schema_cache
Ignore `NoDatabaseError` when loading schema cache
2017-12-03 18:12:40 +01:00
yuuji.yaginuma
dbee80bca0 Make Migrator.current_version work without a current database
This is necessary in order to make the processing dependent on
`Migrator.current_version` work even without database.

Context: https://github.com/rails/rails/pull/31135#issuecomment-348404326
2017-12-03 09:50:28 +09:00
claudiob
a71bbed76a Fix typo in test error message
With the current code, a failing test shows this error, which is missing
the number of times called and has two periods at the end.

```
/railties$ be ruby -Itest test/generators/app_generator_test.rb -n test_active_storage_install

Failure:
AppGeneratorTest#test_active_storage_install [test/generators/app_generator_test.rb:313]:
active_storage:install expected to be called once, but was called  times..
Expected: 1
  Actual: 2
```

After the fix, the error message looks correct:

```
/railties$ be ruby -Itest test/generators/app_generator_test.rb -n test_active_storage_install

Failure:
AppGeneratorTest#test_active_storage_install [test/generators/app_generator_test.rb:313]:
active_storage:install expected to be called once, but was called 2 times.
Expected: 1
  Actual: 2
```
2017-12-02 12:00:09 -08:00
Matthew Draper
e40a00e8ac
Merge pull request #31241 from matthewd/no-after-fork
Drop the before_fork/on_worker_boot advice
2017-12-01 20:18:17 +10:30
Anton Rieder
eb9ff5fd39
Move system test dependencies to test group 2017-11-30 16:34:06 +01:00
yuuji.yaginuma
f7e3c68668 Do not overwrite by default if credentials already exists
Fixes #31286
2017-11-30 10:15:45 +09:00
Rafael Mendonça França
1bee2fb600
Build the root folder before specific files
Fixes #31282.
2017-11-29 14:56:27 -05:00
yuuji.yaginuma
9d65ac30fd Use credentials instead of keyfile in GCS sevice
The `keyfile` was renamed to `credentials` in `google-cloud-storage` 1.8.0.
https://github.com/GoogleCloudPlatform/google-cloud-ruby/blob/master/google-cloud-storage/CHANGELOG.md#180--2017-11-14

Although `keyfile` can still be used, but it looks like deprecate.
ddf7b2a856/google-cloud-storage/lib/google/cloud/storage.rb (L589...L590)

Therefore, I think that should use `credentials` in newly generated
applications.

Ref: https://github.com/GoogleCloudPlatform/google-cloud-ruby/issues/1802
2017-11-29 13:17:04 +09:00
Rafael Mendonça França
2837d0f334
Preparing for 5.2.0.beta2 release 2017-11-28 14:41:02 -05:00
yuuji.yaginuma
349f00beaa Use same version constraint in mysql adapter and generated application
Follow up of 924a368f5c654f5304e575c767eb0fc64adc8659
2017-11-28 15:51:59 +09:00
Rafael Mendonça França
cceeeb6e57
Preparing for 5.2.0.beta1 release 2017-11-27 14:50:03 -05:00
Rafael Mendonça França
21cd5b3031
Make form_with_generates_ids default value to be false
This will keep the behavior of an application with the defaults of a 4.2
or 5.0 application behaving the same when upgrading to 5.2.
2017-11-27 11:52:39 -05:00
Matthew Draper
84cad15213 Drop the before_fork/on_worker_boot advice
It's no longer required for Active Record, and other common libraries
(dalli, redis-rb) all seem to be fork-proof too.
2017-11-27 23:39:30 +10:30
yuuji.yaginuma
a64be3ea6f Remove Content-Security-Policy initializer in API-only Applications
Since `ContentSecurityPolicy::Middleware` is not loaded in API-only
Applications, initializer is unnecessary.
Ref: 9c10fec4c0/railties/lib/rails/application/default_middleware_stack.rb (L66..L68)
2017-11-27 21:57:22 +09:00
Prathamesh Sonpatki
30a60b4042
Added missing test for presence of CSP initializer
- Followup of #31162
2017-11-27 15:37:59 +05:30
Andrew White
456c3ffdbe Add DSL for configuring Content-Security-Policy header
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy
2017-11-27 05:59:26 +00:00
yuuji.yaginuma
0d8fd6107f Use Puma 3.11 in newly generated applications
In order to use early hints, need to use Puma 3.11.0 or higher.
So, I think that should specify that version in newly generated applications.

Ref: f6f3892f4d
2017-11-27 14:21:57 +09:00
Rafael França
959d7f73a7
Merge pull request #31167 from albertoalmagro/clean-db-ambiguity
Clean database naming ambiguity
2017-11-26 22:00:38 -05:00
Alberto Almagro
39da171f3c Remove DB naming ambiguity
In some places this file referred to the database in three different ways: database, DB and db. The last one caused confusion with the db namespace and the db folder. This commit removes this ambiguity by using the whole word 'database' everywhere
2017-11-26 11:37:48 +01:00
yuuji.yaginuma
fbb8b37347 Remove field ids from scaffold form
This was added with 27f103fc7e3260efe0b8dde66bf5354f2202ee32 for link labels and fields.
However, `form_with` changed to generates ids by default with d3893ec38ec61282c2598b01a298124356d6b35a.
So I think that adding an explicit ids is unnecessary.
2017-11-26 10:08:07 +09:00
yuuji.yaginuma
11720c2347 Remove duplicated form_with_generates_remote_forms setting
When load `5.1` config, `form_with_generates_remote_forms` is set.
89a209f1ab/railties/lib/rails/application/configuration.rb (L86)
2017-11-26 09:37:55 +09:00
Rafael Mendonça França
aee1a2802f
Use parentheses for multi-line method calls
Own style guide says we should be using parentheses for method calls
with arguments.
2017-11-25 14:10:34 -05:00
Rafael Mendonça França
36ac675d2a
Make form_with_generates_ids default in Rails 5.2
When the defaults being loaded are the 5.0 or 5.1 we disable generation
of ids with form_with.
2017-11-25 11:56:31 -05:00
npezza93
260d6f112a
Change form_with to generates ids by default
When `form_with` was introduced we disabled the automatic
generation of ids that was enabled in `form_for`. This usually
is not an good idea since labels don't work when the input
doesn't have an id and it made harder to test with Capybara.

You can still disable the automatic generation of ids setting
`config.action_view.form_with_generates_ids` to `false.`
2017-11-25 11:55:02 -05:00
Dixit Patel
88d9906d2d Rubocop style 2017-11-24 20:11:17 +05:30
willnet
424debb096 Fix generator suggestion raise error when I18n.available_locales don’t include :en 2017-11-22 09:27:59 +09:00
yuuji.yaginuma
83cb0fc632 Fix formatting of credentials and encrypted [ci skip] 2017-11-19 14:42:45 +09:00
yuuji.yaginuma
60c550370a Deprecate an after_bundle callback in Rails plugin templates
Since fbd1e98cf983572ca9884f17f933ffe92833632a, Rails plugin does not
run `bundle install` when generating.
Therefore, `after_bundle` callback is not actually executed after `bundle`.

Since there is a difference between the name and the actual behavior,
I think that should be remove.
2017-11-18 12:23:53 +09:00
Wojciech Wnętrzak
23b9ad5fb1
Fixed example of Rails.application.encrypted method usage
[ci skip]
2017-11-16 09:52:51 +01:00
yuuji.yaginuma
f27319a72a Add master key to gitignore on rails new
We generate master key on `rails new`.
Therefore, if do not add master key to `.gitginore` on `rails new`as
well, there is a possibility that the master key will be committed
accidentally.
2017-11-16 08:31:58 +09:00
Kasper Timm Hansen
059d1edcbc
Pass options onto key file generator. 2017-11-15 22:00:54 +01:00
Kasper Timm Hansen
68479d09ba
Merge branch 'freeletics-manage-multiple-credential-files'
Fixes https://github.com/rails/rails/pull/30940
2017-11-15 21:31:57 +01:00
Wojciech Wnętrzak
7a8728a039
Add CLI to manage encrypted files/configs.
To edit/show encrypted file:

```
bin/rails encrypted:edit config/staging_tokens.yml.enc
bin/rails encrypted:edit config/staging_tokens.yml.enc --key config/staging.key
bin/rails encrypted:show config/staging_tokens.yml.enc
```

Also provides a backing Rails.application.encrypted API for Ruby access:

```ruby
Rails.application.encrypted("config/staging_tokens.yml.enc").read
Rails.application.encrypted("config/staging_tokens.yml.enc").config
Rails.application.encrypted("config/staging_tokens.yml.enc", key: "config/staging.key")
```
2017-11-15 21:29:15 +01:00
Kasper Timm Hansen
415d0543a5
Go through a single credentials instance.
Instead of stashing the values in constants.
2017-11-15 21:14:25 +01:00
Yuji Yaginuma
874dae1fd4
Merge pull request #30004 from npenzin/patch-1
Update plugin_generator.rb
2017-11-15 07:38:14 +09:00
Rafael Mendonça França
2e0fe5928f
Use released arel 2017-11-14 14:37:59 -05:00
Nikita Penzin
5345b61f29 Ensure plugin_generator adds to new line in Gemfile
Ensure plugin_generator adds to new line in Gemfile, even if the Gemfile
does not end with an empty line.

[Lisa Ugray, Nikita Penzin]
2017-11-14 08:09:12 -05:00
Yuji Yaginuma
b6d5e46311
Add environment as dependency of load_config (#31135)
Currently the environment is not loaded in some db tasks.
Therefore, if use encrypted secrets values in `database.yml`,
`read_encrypted_secrets` will not be true, so the value can not be
used correctly.

To fix this, added `environment` as dependency of `load_config`.
It also removes explicit `environment` dependencies that are no longer
needed.

Fixes #30717
2017-11-14 13:54:58 +09:00
Rafael Mendonça França
8dd76a7a6f
Use .tt extension to all the template files
Make clear that the files are not to be run for interpreters.

Fixes #23847.
Fixes #30690.
Closes #23878.
2017-11-13 15:23:28 -05:00
Eileen M. Uchitelle
a45f234b02
Merge pull request #30773 from y-yagi/fix_30765
Make automatically synchronize test schema work inside engine
2017-11-12 19:18:49 -05:00
Kasper Timm Hansen
5744d00f5d
Revert displaying master key generation info on rails new.
It's already a default for new apps, like so many others, so
no need to flaunt it.
2017-11-12 20:29:35 +01:00
Kasper Timm Hansen
bb30f05f38
Deprecate encrypted secrets in favor of credentials.
Allow edits of existing encrypted secrets generated on Rails 5.1,
but refer to credentials when attempting to setup.

This also removes the need for any of the setup code, so the
generator can be ripped out altogether.
2017-11-12 17:50:09 +01:00
Kasper Timm Hansen
99f4d6e744
Merge pull request #30770 from y-yagi/do_not_create_credential_in_dummy_application
Do not create credentials in dummy application
2017-11-12 14:41:42 +01:00
Ryuta Kamizono
095079abec Adjust blank lines 2017-11-10 21:06:13 +09:00
yuuji.yaginuma
d1e0bc7c17 Do not show credentials in generators help
Since credentials generator is executed via the credentials command and
does not need to be executed directly, so it is not necessary to show it in
help.
2017-11-09 20:59:16 +09:00
Rafael França
7b766bd871
Merge pull request #31093 from bogdanvlviv/express-console-command-in-the-log
Change output log about skipping instalation of Active Storage
2017-11-08 18:03:51 -05:00
bogdanvlviv
6f123341d9
Change output log about skipping instalation of Active Storage
Using of "`" is preferable over "'" to express console command in output log
2017-11-08 22:07:12 +00:00
bogdanvlviv
d5ad63766e
Remove redundant passing --skip-active-storage in test cases
These were added in #30101, after #31084 it became redundant.
2017-11-08 21:39:35 +00:00
yuuji.yaginuma
8e1dca10cd Remove unnecessary migration deletion
Since isolation application is generated with the `--skip-gemfile`
option, so `active_storage:install` is not executed.
2017-11-08 13:24:16 +09:00
yuuji.yaginuma
67db41aa7f Do not run active_storage:install when bundle install is skipped
In order to execute the `rails` command, need to run bundle install in
advance.
Therefore, if skipped bundle install, `rails` command may fail and
should not do it.
2017-11-08 13:24:12 +09:00
yuuji.yaginuma
3815845110 Fix comment in check_class_collision [ci skip]
`ScaffoldBase` was changed to `ResourceHelpers` by 0efedf2.
2017-11-07 14:23:16 +09:00
bogdanvlviv
90fe2a42f0
Fix bin/rails db:migrate with specified VERSION
Ensure that `bin/rails db:migrate` with specified `VERSION` reverts
all migrations only if `VERSION` is `0`.
Raise error if target migration doesn't exist.
2017-11-06 22:40:10 +00:00
Rafael França
63f0c04850
Merge pull request #30101 from bogdanvlviv/initialization-active_storage
Provide initialization of Active Storage
2017-11-06 17:25:54 -05:00
bogdanvlviv
cb8553c95d
Execution of active_storage:install should respect --quiet during rails new 2017-11-06 21:29:25 +00:00
bogdanvlviv
f4af77ab5d
Rails::Generators::Actions#execute_command allows option capture 2017-11-06 21:29:23 +00:00
bogdanvlviv
0835527d6b
rails new runs rails active_storage:install
Omit `rails activestorage:install` for jdbcmysql, jdbc and shebang tests

AppGeneratorTest#test_config_jdbcmysql_database

  rails aborted!
  LoadError: Could not load 'active_record/connection_adapters/mysql_adapter'.
  Make sure that the adapter in config/database.yml is valid.
  If you use an adapter other than 'mysql2', 'postgresql' or 'sqlite3' add
  the necessary adapter gem to the Gemfile.
  (compressed)
  bin/rails:4:in `<main>'
  Tasks: TOP => activestorage:install => environment
  (See full trace by running task with --trace)

AppGeneratorTest#test_config_jdbc_database

  rails aborted!
  LoadError: Could not load 'active_record/connection_adapters/jdbc_adapter'.
  Make sure that the adapter in config/database.yml is valid.
  If you use an adapter other than 'mysql2', 'postgresql' or 'sqlite3' add
  the necessary adapter gem to the Gemfile.
  (compressed)
  bin/rails:4:in `<main>'
  Tasks: TOP => activestorage:install => environment
  (See full trace by running task with --trace)

AppGeneratorTest#test_shebang_is_added_to_rails_file

  /home/ubuntu/.rbenv/versions/2.4.1/bin/ruby: no Ruby script found in input (LoadError)

Prevent PendingMigrationError in tests

 * Run `bin/rails db:migrate RAILS_ENV=test` in test_cases before start tests to prevent PendingMigrationError
 * FileUtils.rm_r("db/migrate")
 * --skip-active-storage

Fix failed tests in `railties/test/railties/engine_test.rb`

Related to #30111

Imporve `SharedGeneratorTests#test_default_frameworks_are_required_when_others_are_removed`

 - Explicitly skip active_storage
 - Ensure that skipped frameworks are commented
 - Ensure that default frameworks are not commented

Fix error `Errno::ENOSPC: No space left on device - sendfile`

Since `rails new` runs `rails active_storage:install`
that boots an app.

Since adding Bootsnap 0312a5c67e35b960e33677b5358c539f1047e4e1
during booting an app, it creates the cache:

   264K    tmp/cache/bootsnap-load-path-cache
   27M     tmp/cache/bootsnap-compile-cache

* teardown_app must remove app
2017-11-06 21:29:14 +00:00
bogdanvlviv
4a835aa323
Add --skip-active-storage and do so automatically when --skip-active-record is used
Closes #30102

Revert part 787fe90dc0a7c5b91bb5af51f2858ea8c4676268

--skip-active-storage pass throughs `rails plugin new`

Add changelog entry about default initialization of Active Storage
2017-11-06 21:08:51 +00:00
yuuji.yaginuma
bb6d369f89 Remove unused require
Since f182831, this file does not use methods added by `module/introspection`.
2017-11-06 16:53:36 +09:00
Eileen M. Uchitelle
03ac95a140
Merge pull request #31053 from y-yagi/fix_namespaced_generator
Generate the correct path in nested scaffold generator
2017-11-05 09:40:56 -05:00