aboutsummaryrefslogtreecommitdiffstats
path: root/railties/test/application
Commit message (Collapse)AuthorAgeFilesLines
* Enable `Layout/LeadingCommentSpace` to not allow cosmetic changes in the futureRyuta Kamizono2017-12-141-2/+2
| | | | Follow up of #31432.
* Expose Active Storage routesMehmet Emin INAC2017-12-131-13/+32
|
* Set the Rails environment from an environment variableAaron Patterson2017-12-081-1/+1
| | | | | | | | | 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`)
* Add failing test for wrong database connectionAaron Patterson2017-12-081-0/+17
| | | | | | 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.
* Fix Rails environment when running tests with RubyAaron Patterson2017-12-061-0/+56
| | | | | | | | | | | | | | | | | | | | | | | | | | | 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: https://github.com/seattlerb/minitest/blob/ca6a71ca901016db09a5ad466b4adea4b52a504a/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.
* Make `Migrator.current_version` work without a current databaseyuuji.yaginuma2017-12-031-0/+14
| | | | | | | 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
* Add DSL for configuring Content-Security-Policy headerAndrew White2017-11-272-0/+198
| | | | https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy
* Change `form_with` to generates ids by defaultnpezza932017-11-251-0/+62
| | | | | | | | | | 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.`
* Add `environment` as dependency of `load_config` (#31135)Yuji Yaginuma2017-11-141-2/+18
| | | | | | | | | | | | 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
* Do not show credentials in generators helpyuuji.yaginuma2017-11-091-1/+2
| | | | | | 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.
* Remove unnecessary migration deletionyuuji.yaginuma2017-11-085-19/+0
| | | | | Since isolation application is generated with the `--skip-gemfile` option, so `active_storage:install` is not executed.
* Fix `bin/rails db:migrate` with specified `VERSION`bogdanvlviv2017-11-061-2/+154
| | | | | | 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.
* Merge pull request #30101 from bogdanvlviv/initialization-active_storageRafael França2017-11-066-2/+24
|\ | | | | Provide initialization of Active Storage
| * `rails new` runs `rails active_storage:install`bogdanvlviv2017-11-066-2/+24
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* | s/an/a/Akira Matsuda2017-11-041-1/+1
|/
* Merge pull request #30579 from ↵Sean Griffin2017-10-181-0/+47
|\ | | | | | | | | bogdanvlviv/fix_ar_internal_metadata_for_a_test_database Fix `bin/rails db:setup` and `bin/rails db:test:prepare` create wrong ar_internal_metadata's data for a test database.
| * `ActiveRecord::Tasks::DatabaseTasks.load_schema` has always to establish ↵bogdanvlviv2017-10-151-0/+8
| | | | | | | | | | | | | | | | | | | | | | | | database connection When load schema from `structure.sql`, database connection isn't established. `ActiveRecord::Tasks::DatabaseTasks.load_schema` has to establish database connection since it executes ``` ActiveRecord::InternalMetadata.create_table ActiveRecord::InternalMetadata[:environment] = environment ```
| * Fix `bin/rails db:setup` and `bin/rails db:test:prepare` create wrong ↵bogdanvlviv2017-10-151-0/+39
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ar_internal_metadata's data for a test database. Before: ``` $ RAILS_ENV=test rails dbconsole > SELECT * FROM ar_internal_metadata; key|value|created_at|updated_at environment|development|2017-09-11 23:14:10.815679|2017-09-11 23:14:10.815679 ``` After: ``` $ RAILS_ENV=test rails dbconsole > SELECT * FROM ar_internal_metadata; key|value|created_at|updated_at environment|test|2017-09-11 23:14:10.815679|2017-09-11 23:14:10.815679 ``` Fixes #26731.
* | Remove unnecessary `allow_failure: true` optionyuuji.yaginuma2017-10-181-1/+1
|/ | | | | `routes` task always returns zero to status, so status is not to non-zeno. Ref: https://github.com/rails/rails/blob/b1867c480dd5476948ff0492ea2f91e2c2fcb04b/railties/lib/rails/tasks/routes.rake#L30
* Improve RakeTest#test_db_test_prepare_when_using_sql_formatbogdanvlviv2017-10-081-3/+1
| | | | | - Remove redundant setting `RAILS_ENV` for `db:test:prepare`. `db:test:prepare` doesn't require it.
* Invoke rails command inside the railties' test app with ↵bogdanvlviv2017-10-083-16/+12
| | | | | | TestHelpers::Generation#rails See #30520
* Remove redundant execution of `Dir.chdir(app_path) { }` in railties' testsbogdanvlviv2017-10-084-230/+194
|
* Deprecate secret_token, long since usurped by secret_key_base.Kasper Timm Hansen2017-09-281-0/+26
| | | | | | | | | | See the changelog entry. Remove `secrets.secret_token` from the bug report templates, since we don't accept bug reports for Rails versions that don't support a `secret_key_base`. [ claudiob & Kasper Timm Hansen ]
* Fix cookies/session tests broken after merging key rotation.Kasper Timm Hansen2017-09-252-35/+31
| | | | | | | | | | | | Based on, yet closes https://github.com/rails/rails/pull/30708 Fix the session test by properly truncating the legacy encryption key for cbc encryption. Borrowed straight from 👆. Fix the cookies test a little differently than the PR. Basically keep every config within the config block. [ Michael Coyne & Kasper Timm Hansen ]
* Skip complex cookie tests for now; I'll deal with them tomorrow.Kasper Timm Hansen2017-09-242-0/+6
|
* Add key rotation message Encryptor and VerifierMichael Coyne2017-09-231-0/+143
| | | | | | Both classes now have a rotate method where new instances are added for each call. When decryption or verification fails the next rotation instance is tried.
* Use `TOPLEVEL_BINDING` in rails runner commandyuuji.yaginuma2017-09-221-0/+12
| | | | | | | | | Binding to capture the local scope. This means that if a constant with same name as constant specified by the user exists in local scope, constant defined in local will use. This is different from what the user expects. Therefore, fixed to use top-level binding instead of local scope. Fixes #30644
* Don't expose Active Storage routesyuuji.yaginuma2017-09-161-28/+13
| | | | | | | These routes are only used internally in Active Storage, and it seems that there is no need for the user to directly use them. Therefore, I think that routes should not be exposed to users.
* Add credentials using a generic EncryptedConfiguration class (#30067)David Heinemeier Hansson2017-09-114-83/+72
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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.
* Remove needless `silence_warnings`yuuji.yaginuma2017-09-092-13/+2
| | | | Since ff30db1, warning is not shown.
* Run in-app rails commands via fork+load where possibleMatthew Draper2017-09-0417-278/+242
| | | | | While this avoids shell argument parsing, we still pass through everything in our stack.
* Don't need the layout hereMatthew Draper2017-09-041-0/+2
|
* Preload Rails component gems in railties testsMatthew Draper2017-09-043-1/+3
|
* Remove needless `silence_warnings`yuuji.yaginuma2017-09-011-4/+1
| | | | Since ff30db1, warning is not show.
* Make `restart` and `dev:cache` tasks work when customizing pid file pathyuuji.yaginuma2017-08-213-13/+36
| | | | | | | | | | Originally, it hard-coded pid file path. It can not be removed when customizing pid file path. But rake task can not get pid file path. Therefore, do not remove file in rake task, makes it possible to judge whether it is restart from the argument of the command and removes the file in server command. Fixes #29306
* Fix RuboCop offensesKoichi ITO2017-08-165-12/+12
| | | | And enable `context_dependent` of Style/BracesAroundHashParameters cop.
* Add test case to make sure Parameters configuration are executed onceRafael Mendonça França2017-08-151-0/+10
| | | | Test case for #30045
* Adding frozen_string_literal pragma to Railties.Pat Allan2017-08-1448-0/+96
|
* Railties updates for frozen string literals.Pat Allan2017-08-141-1/+2
|
* Merge pull request #29559 from kirs/eager-load-controller-actionsRafael França2017-08-111-0/+60
|\ | | | | Eager load controller actions to reduce response time of the first request
| * Eager load controller and mailer actionsKir Shatrov2017-07-291-0/+60
| | | | | | | | | | | | | | | | | | | | | | On the first request, ActionController::Base#action_methods computes and memoized the list of available actions [1]. With this PR we move this expensive operation into eager load step to reduce response time of the first request served in production. This also reduces the memory footprint when running on forking server like Unicorn. [1] https://github.com/rails/rails/blob/a3813dce9a0c950a4af7909111fa730a2622b1db/actionpack/lib/abstract_controller/base.rb#L66-L77
* | Deprecate support of older `config.ru`yuuji.yaginuma2017-08-081-0/+31
| | | | | | | | | | | | | | | | Since Rails 4.0, `config.ru` generated by default uses instances of `Rails.application`. Therefore, I think that it is good to deprecate the old behavior. Related: #9669
* | Check for `app.secrets.secret_key_base`, not `app.config.secret_key_base`George Claghorn2017-08-051-3/+1
| | | | | | | | By default, apps only have the former set.
* | Convert to strings so array can be sorted deterministicallyDavid Heinemeier Hansson2017-08-041-3/+3
| |
* | Deterministic comparisons pleaseDavid Heinemeier Hansson2017-08-031-3/+3
| |
* | Do not eager load ActiveRecord::BaseRafael Mendonça França2017-08-032-10/+6
| | | | | | | | Everything inside the app directory of a engine is autoload/eager loaded automatically so we don't need to require them.
* | Active Storage routes are now part of the default routesDavid Heinemeier Hansson2017-08-031-9/+37
| | | | | | | | It's worth considering whether we should hide these by default, but I'm kinda thinking no. It's very reasonable that someone would want to call these directly, so they should be documented.
* | Same issue from AR getting loaded earlierDavid Heinemeier Hansson2017-08-031-3/+3
| | | | | | | | cc @rafaelfranca
* | Including new default classes in loading testDavid Heinemeier Hansson2017-08-031-3/+3
| |
* | Active Storage loads AR earlier to extend it so require env laterDavid Heinemeier Hansson2017-08-031-3/+7
| |