Commit Graph

146 Commits

Author SHA1 Message Date
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
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
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
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
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
yuuji.yaginuma
116e2c67f5 Fix typo in allow_failure argument [ci skip]
Ref: 3be123ba26/railties/test/isolation/abstract_unit.rb (L243)
2017-10-18 14:34:02 +09:00
David Heinemeier Hansson
69f976b859 Add credentials using a generic EncryptedConfiguration class (#30067)
* WIP: Add credentials using a generic EncryptedConfiguration class

This is sketch code so far.

* Flesh out EncryptedConfiguration and test it

* Better name

* Add command and generator for credentials

* Use the Pathnames

* Extract EncryptedFile from EncryptedConfiguration and add serializers

* Test EncryptedFile

* Extract serializer validation

* Stress the point about losing comments

* Allow encrypted configuration to be read without parsing for display

* Use credentials by default and base them on the master key

* Derive secret_key_base in test/dev, source it from credentials in other envs

And document the usage.

* Document the new credentials setup

* Stop generating the secrets.yml file now that we have credentials

* Document what we should have instead

Still need to make it happen, tho.

* [ci skip] Keep wording to `key base`; prefer defaults.

Usually we say we change defaults, not "spec" out a release.

Can't use backticks in our sdoc generated documentation either.

* Abstract away OpenSSL; prefer MessageEncryptor.

* Spare needless new when raising.

* Encrypted file test shouldn't depend on subclass.

* [ci skip] Some woordings.

* Ditch serializer future coding.

* I said flip it. Flip it good.

* [ci skip] Move require_master_key to the real production.rb.

* Add require_master_key to abort the boot process.

In case the master key is required in a certain environment
we should inspect that the key is there and abort if it isn't.

* Print missing key message and exit immediately.

Spares us a lengthy backtrace and prevents further execution.

I've verified the behavior in a test app, but couldn't figure the
test out as loading the app just exits immediately with:

```
/Users/kasperhansen/Documents/code/rails/activesupport/lib/active_support/testing/isolation.rb:23:in `load': marshal data too short (ArgumentError)
	from /Users/kasperhansen/Documents/code/rails/activesupport/lib/active_support/testing/isolation.rb:23:in `run'
	from /Users/kasperhansen/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/minitest-5.10.2/lib/minitest.rb:830:in `run_one_method'
	from /Users/kasperhansen/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/minitest-5.10.2/lib/minitest/parallel.rb:32:in `block (2 levels) in start'
```

It's likely we need to capture and prevent the exit somehow.
Kernel.stub(:exit) didn't work. Leaving it for tomorrow.

* Fix require_master_key config test.

Loading the app would trigger the `exit 1` per require_master_key's
semantics, which then aborted the test.

Fork and wait for the child process to finish, then inspect the
exit status.

Also check we aborted because of a missing master key, so something
else didn't just abort the boot.

Much <3 to @tenderlove for the tip.

* Support reading/writing configs via methods.

* Skip needless deep symbolizing.

* Remove save; test config reader elsewhere.

* Move secret_key_base check to when we're reading it.

Otherwise we'll abort too soon since we don't assign the secret_key_base
to secrets anymore.

* Add missing string literal comments; require unneeded yaml require.

* ya ya ya, rubocop.

* Add master_key/credentials after bundle.

Then we can reuse the existing message on `rails new bc4`.

It'll look like:

```
Using web-console 3.5.1 from https://github.com/rails/web-console.git (at master@ce985eb)
Using rails 5.2.0.alpha from source at `/Users/kasperhansen/Documents/code/rails`
Using sass-rails 5.0.6
Bundle complete! 16 Gemfile dependencies, 72 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.
Adding config/master.key to store the master encryption key: 97070158c44b4675b876373a6bc9d5a0

Save this in a password manager your team can access.

If you lose the key, no one, including you, can access anything encrypted with it.

      create  config/master.key
```

And that'll be executed even if `--skip-bundle` was passed.

* Ensure test app has secret_key_base.

* Assign secret_key_base to app or omit.

* Merge noise

* Split options for dynamic delegation into its own method and use deep symbols to make it work

* Update error to point to credentials instead

* Appease Rubocop

* Validate secret_key_base when reading it.

Instead of relying on the validation in key_generator move that into
secret_key_base itself.

* Fix generator and secrets test.

Manually add config.read_encrypted_secrets since it's not there by default
anymore.

Move mentions of config/secrets.yml to config/credentials.yml.enc.

* Remove files I have no idea how they got here.

* [ci skip] swap secrets for credentials.

* [ci skip] And now, changelogs are coming.
2017-09-11 20:21:20 +02:00
yuuji.yaginuma
603475b76f Remove needless silence_warnings
Since ff30db1, warning is not shown.
2017-09-09 09:48:15 +09:00
yuuji.yaginuma
39f3ab51e9 Remove unused fork arg for rails 2017-09-08 06:57:09 +09:00
Matthew Draper
802ce8a239 Run in-app rails commands via fork+load where possible
While this avoids shell argument parsing, we still pass through
everything in our stack.
2017-09-04 20:19:39 +09:30
Matthew Draper
c9fc8f8021 Preload some additional specific files 2017-09-04 05:43:01 +09:30
Matthew Draper
e4b0488851 Preload Rails component gems in railties tests 2017-09-04 05:43:01 +09:30
Pat Allan
7f6a31433a Allow for frozen string pragma in generated files. 2017-08-14 19:57:45 +02:00
Pat Allan
acea68de02 Adding frozen_string_literal pragma to Railties. 2017-08-14 19:08:09 +02:00
Pat Allan
d435c92721 Railties updates for frozen string literals. 2017-08-14 19:00:24 +02:00
bogdanvlviv
82414d397d
Remove :sorted test order for isolated tests 2017-08-07 04:54:31 +00:00
Matthew Draper
87b3e226d6 Revert "Merge pull request #29540 from kirs/rubocop-frozen-string"
This reverts commit 3420a14590c0e6915d8b6c242887f74adb4120f9, reversing
changes made to afb66a5a598ce4ac74ad84b125a5abf046dcf5aa.
2017-07-02 02:15:17 +09:30
Kir Shatrov
cfade1ec7e Enforce frozen string in Rubocop 2017-07-01 02:11:03 +03:00
bogdanvlviv
40bdbce191
Define path with __dir__
".. with __dir__ we can restore order in the Universe." - by @fxn

Related to 5b8738c2df003a96f0e490c43559747618d10f5f
2017-05-23 00:53:51 +03:00
Ryuta Kamizono
0d17168289 Replace \Z to \z
\Z was a mistake of \z. Replace \Z to \z to prevent newly \Z added.
2017-04-24 21:22:12 +09:00
Kasper Timm Hansen
fbee4e3ce3 Revert "Revert "Add encrypted secrets"" 2017-02-23 18:15:28 +01:00
David Heinemeier Hansson
039380e3ee Revert "Add encrypted secrets" (#28127) 2017-02-23 15:55:15 +01:00
Kasper Timm Hansen
1166094569 Add encrypted secrets (#28038) 2017-02-23 15:01:02 +01:00
Taishi Kasuga
da1453e6ba Remove aggressive unit test with mock. And add integration level test. 2016-11-24 14:17:13 +09:00
Rafael Mendonça França
fe1f4b2ad5
Add more rubocop rules about whitespaces 2016-10-29 01:17:49 -02:00
Rafael Mendonça França
79a5ea9ead
Remove deprecated support to :text in render 2016-10-10 00:02:52 -03:00
yuuji.yaginuma
f200a52e16 remove useless gemfile option
Rails application for test creates with `--skip-gemfile` option.
https://github.com/rails/rails/blob/master/railties/test/isolation/abstract_unit.rb#L333

Therefore, regardless of the option, Gemfile is not created.
2016-09-12 18:32:07 +09:00
Rafael Mendonça França
55f9b8129a
Add three new rubocop rules
Style/SpaceBeforeBlockBraces
Style/SpaceInsideBlockBraces
Style/SpaceInsideHashLiteralBraces

Fix all violations in the repository.
2016-08-16 04:30:11 -03:00
Xavier Noria
783763bde9 applies new string literal convention in railties/test
The current code base is not uniform. After some discussion,
we have chosen to go with double quotes by default.
2016-08-06 19:16:09 +02:00
Santosh Wadghule
d8575289a2 rails -> Rails [ci skip] 2016-07-12 12:21:36 +05:30
Prathamesh Sonpatki
d93427840e
Remove unused boot_rails method and it's usage
- The `boot_rails` method from abstract_unit.rb is empty after 2abcdfd978fdcd491576a237e8c6b.
- So let's remove it and its usage.
2016-07-04 09:34:21 +05:30
Genadi Samokovarov
4b80a96313 Require "active_support/core_ext/object/blank" for railties abstract unit
In #25380 I moved an `active_support/core_ext/object/blank` in the
`activesupport/lib/active_support/testing/assertions.rb`, however it caused a
chain reaction, resulting in failing railties tests.

Moving the require to `railties/test/isolation/abstract_unit.rb` and
`activesupport/test/abstract_unit.rb`.
2016-06-13 19:07:30 +03:00
Prathamesh Sonpatki
d58cd128dd
Move new default initializers into separate directory
- These initializers are new defaults for Rails 5 and newly generated
  apps do not need to change them.
- Fixes #25181
2016-05-28 21:39:43 -04:00
Arthur Nogueira Neves
15c308582f Merge pull request #23932 from arthurnn/arthurnn/remove_load_paths
Remove load_paths file
2016-03-01 16:10:09 -05:00
Andrew White
6520ea5f7e Deprecate :controller and :action path parameters
Allowing :controller and :action values to be specified via the path
in config/routes.rb has been an underlying cause of a number of issues
in Rails that have resulted in security releases. In light of this it's
better that controllers and actions are explicitly whitelisted rather
than trying to blacklist or sanitize 'bad' values.
2016-03-01 08:48:53 +00:00
Arthur Neves
2abcdfd978 Remove load_paths file 2016-02-27 13:03:57 -05:00
Xavier Noria
94dbc48887 adds --skip-listen to the application generator [closes #23590] 2016-02-17 00:59:42 +01:00
Xavier Noria
bd69718124 prevent apps in the railties test suite from running the evented monitor 2016-02-10 01:32:17 +01:00
Genadi Samokovarov
38492590cf Introduce new welcome page for new projects
As requested by David in 23233.
2016-01-26 00:27:49 +02:00
Aaron Patterson
ff30db1372 run against edge sass to eliminate circular require warnings 2015-09-30 07:42:58 -07:00
Jeremy Daer
20ec1e922c Eliminate overlapping app/assets load path
* Move `app/assets/manifest.js` to `app/assets/config/manifest.js`.
  Avoid the suggestion that you can/should deep-link `stylesheets/foo`.
* Pull in all toplevel stylesheets and JavaScripts, not just
  `application.js` and `.css`. Demonstrate how to use `link_directory`
  with a specified `.js`/`.css` type.
* Fix RAILS_ENV handling in assets tests.
* Shush warnings spam from third-party libs that distract from tests.
2015-09-29 11:56:58 -07:00
Aaron Patterson
46cd257aad make sure flash middleware is required 2015-09-25 15:53:15 -07:00
Andrew White
60239f3e5a Add support for inline images to mailer previews
Use a preview interceptor to search for inline cid: urls in src
attributes and convert them to data urls.
2015-05-04 10:56:59 +01:00
Islam Wazery
4521aadae0 Rename railties/bin to railties/exe
That will match the new Bundler executables convention.
Bundler Blog Post: http://bundler.io/blog/2015/03/20/moving-bins-to-exe.html
Also updated the necessary tests.
2015-04-11 19:26:34 +02:00
Josef Šimánek
6447309817 Remove unused gsub_app_file method from Bukkit. 2015-02-19 02:44:49 +01:00
Rafael Mendonça França
6953f16efa Merge pull request #18526 from vipulnsward/add-silence-stream
Extracted silence_stream method to new module in activesupport/testing
2015-02-05 18:28:51 -02:00
Vipul A M
166ce95f65 - Extracted silence_stream method to new module in activesupport/testing.
- Added include for the same in ActiveSupport::Test.
- Removed occurrences of silence_stream being used elsewhere.
- Reordered activesupport testcase requires alphabetically.

- Removed require of silence stream from test_case

- Moved quietly method to stream helper

- Moved capture output to stream helper module and setup requires for the same elsewhere
2015-01-20 22:28:48 +05:30
Prathamesh Sonpatki
88ff9fd2a3 Fixed test for assert_welcome
- Test was wrongly using assert with assignment statement.
2015-01-17 22:15:15 +05:30
Nobuyoshi Nakada
69e365d2f4 Use IO::NULL always 2015-01-10 15:11:05 +01:00
Rafael Mendonça França
481e49c64f Remove deprecated methods at Kernel.
`silence_stderr`, `silence_stream`, `capture` and `quietly`.
2015-01-04 11:58:40 -03:00