Commit Graph

12409 Commits

Author SHA1 Message Date
Janko Marohnić
ca12968587
Use ImageProcessing gem for ActiveStorage variants
ImageProcessing gem is a wrapper around MiniMagick and ruby-vips, and
implements an interface for common image resizing and processing. This
is the canonical image processing gem recommended in [Shrine], and
that's where it developed from. The initial implementation was extracted
from Refile, which also implements on-the-fly transformations.

Some features that ImageProcessing gem adds on top of MiniMagick:

  * resizing macros
    - #resize_to_limit
    - #resize_to_fit
    - #resize_to_fill
    - #resize_and_pad
  * automatic orientation
  * automatic thumbnail sharpening
  * avoids the complex and inefficient MiniMagick::Image class
  * will use "magick" instead of "convert" on ImageMagick 7

However, the biggest feature of the ImageProcessing gem is that it has
an alternative implementation that uses libvips. Libvips is an
alternative to ImageMagick that can process images very rapidly (we've
seen up 10x faster than ImageMagick).

What's great is that the ImageProcessing gem provides the same interface
for both implementations. The macros are named the same, and the libvips
implementation does auto orientation and thumbnail sharpening as well;
only the operations/options specific to ImageMagick/libvips differ. The
integration provided by this PR should work for both implementations.

The plan is to introduce the ImageProcessing backend in Rails 6.0 as the
default backend and deprecate the MiniMagick backend, then in Rails 6.1
remove the MiniMagick backend.
2018-04-18 17:46:25 +02:00
Paul
b17cdfe8e0
Add .keep exception for storage folder
Fixes https://github.com/rails/rails/issues/32546 by including the `.keep` file in the .gitignore, bringing the `storage` folder in line with the `tmp` and `log` folders.
2018-04-13 09:40:48 -04:00
yuuji.yaginuma
686f4f3a94 Allow use of minitest-rails gem with Rails test runner
Add explicit global namespace to `Rails::TestUnit::Runner` to resolve a
namespace conflict between `minitest-rails` and Rails test runner.

Fixes #31324
2018-04-11 07:20:53 +09:00
eileencodes
72f17d59e4 Remove upper bound on Capybara
There's no reason to block future versions of Capybara since we don't
_know_ they are going to break. How will we know if we have a
conservative option set? This change prevents us from blocking users who
want to upgrade in the future.
2018-04-10 16:40:14 -04:00
eileencodes
fa5a028ed9 Add multidb application test
I realized I wasn't really testing some of the new rake tasks added so I
built out this new test that uses a multi-db database.yml and allows us
to run create/drop/migrate/schema:dump/schema:load and those that are
namespaced like create:animals. This will make our testing more robust
so we can catch problems quicker and set a good place to add future
tests as these features evolve.
2018-04-09 13:08:05 -04:00
Yoshiyuki Hirano
bc864aa7ab rewords a bit RDOC_MAIN.rdoc [ci skip]
* Same change as bba832d
2018-04-08 05:50:02 +09:00
bogdanvlviv
fd1c8c16c7
Fix test added in #32444
Currently test `#test_logger_does_not_mutate_app_return` doesn't
test mutation of response and the test passes with and without changes
added in #32444. `#freeze` response in the test in order to
test mutation.
2018-04-06 14:00:13 +03:00
Rafael França
fe4e9d4c5d
Merge pull request #32441 from composerinteralia/refute-not
Add custom RuboCop for `assert_not` over `refute`
2018-04-04 18:19:35 -04:00
Rafael Mendonça França
826b17cd8a
Merge pull request #32444 from matrinox/fix-return-response-mutation-rack-logger
Stop mutating body response
2018-04-04 18:17:16 -04:00
Eileen M. Uchitelle
f815e77341
Merge pull request #32435 from bogdanvlviv/add-missing-dots-at-the-end-of-comments
Add missing dots at the end of comments in environment file templates
2018-04-04 07:47:28 -04:00
Geoff Lee
0ac64470ea
Stop mutating body response
If @app.call returns an object that is saved (for e.g., in a constant), the mutation results in a continuing cycle of wrapping the body in Rack::BodyProxy, eventually leading to SystemStackError
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
On branch fix-return-response-mutation-rack-logger - Tue  3 Apr 2018 19:54:28 PDT by Geoff Lee <geoff.lee@lendesk.com>
2018-04-03 19:54:27 -07:00
Daniel Colson
c1ceafc9d1 Autocorrect refute RuboCop violations
73e7aab behaved as expected on codeship, failing the build with
exactly these RuboCop violations. Hopefully `rubocop -a` will
have been enough to get a passing build!
2018-04-03 22:35:49 -04:00
Yoshiyuki Hirano
53f2241a95 Fix RenderingTest in railtie
Test class name is not `RoutingTest` but `RenderingTest`
2018-04-04 06:12:24 +09:00
bogdanvlviv
74e91263cb
Add missing dots at the end of comments in environment file templates
Add dots in order to keep consistency between other comments in these files.
2018-04-03 16:52:53 +03:00
Simon Coffey
eede8d8130 Add action_view.finalize_compiled_template_methods config option
ActionView::Template instances compile their source to methods on the
ActionView::CompiledTemplates module. To prevent leaks in development
mode, where templates can frequently change, a finalizer is added that
undefines these methods[1] when the templates are garbage-collected.

This is undesirable in the test environment, however, as templates don't
change during the life of the test. Moreover, the cost of undefining a
method is proportional to the number of descendants a class or module
has, since the method cache must be cleared for all descendant classes.

As ActionView::CompiledTemplates is mixed into every
ActionView::TestCase (or in RSpec suites, every view spec example
group), it can end up with a very large number of descendants, and
undefining its methods can become very expensive.

In large test suites, this results in a long delay at the end of the
test suite as all template finalizers are run, only for the process to
then exit.

To avoid this unnecessary cost, this change adds a config option,
`action_view.finalize_compiled_template_methods`, defaulting to true,
and sets it to false in the test environment only.

[1] 09b2348f7f/actionview/lib/action_view/template.rb (L118-L126)
2018-04-02 20:50:33 +01:00
Kasper Timm Hansen
0ec23effa7
Merge pull request #32065 from sikachu/move-SourceAnnotationExtractor-under-rails-namespec
Move SourceAnnotationExtractor under Rails module
2018-04-02 16:15:52 +02:00
Yoshiyuki Kinjo
7419a4f911 Deriving secret_key_base breaks key_generator defined in 5.1.
If one created Rails 5.1 app and then updated to 5.2,
`secret_key_base` defined in `config/secrets.yml` is ignored for
`development` and `test` environment.
A change in `secret_key_base` in turn breaks
`Rails.application.key_generator`.

If one encrypt data in Rails 5.1, she cannot decrypt it in Rails 5.2
for `development` and `test` environment.
2018-03-31 23:12:16 +09:00
yuuji.yaginuma
06332d5867 Remove unnecessary line break and quotes 2018-03-30 07:58:50 +09:00
Guillermo Iguaran
f9ec3e5cc3
Fix "--frozen-lockfile" argument used in yarn install rake task
--frozen-lockfile is the right name of the argument
2018-03-29 11:53:25 -05:00
Guillermo Iguaran
480595e491
Merge pull request #32289 from gsamokovarov/did-you-mean-suggestions
Use `did_you_mean` spell checker for option suggestions
2018-03-29 11:05:47 -05:00
Guillermo Iguaran
1765f09b10
Merge pull request #32243 from maschwenk/patch-2
[Webpack] Raise an error when lockfile diff is generated
2018-03-29 11:02:49 -05:00
Shia
0014790b2a
Compare ruby version with correct way 2018-03-29 16:26:19 +09:00
Eileen M. Uchitelle
93e6b5c27b
Merge pull request #32274 from eileencodes/part-1-add-rake-tasks-for-multi-db
Part 1 Easy Multi db in Rails: Add basic rake tasks for multi db setup
2018-03-26 16:37:21 -04:00
Genadi Samokovarov
cb25f2c989 Use did_you_mean spell checker for option suggestions
Now that we require Ruby over `2.3`, we can replace the current
suggestion methods we have with tooling from the `did_you_mean` gem.

There is a small user visible change and this is that we now offer a
single suggestion for misspelled options. We are suggesting fixes during
generator invocation and during a mistyped rails server rack handler. In
both cases, if we don't make a proper prediction on the first match, we
won't do so in the second or third one, so in my mind, this is okay.
2018-03-23 11:36:03 +02:00
Prem Sichanugrist
92dac547fd Add deprecation note for SourceAnnotationExtractor 2018-03-22 17:06:15 +00:00
Prem Sichanugrist
1638d3c075 Make Annotation into a proper class
This cleans up the documentation for SourceAnnotationExtractor because
RDoc does not seems to know how to parse `Struct.new() do` block.
2018-03-22 17:06:14 +00:00
Prem Sichanugrist
67cc450086 Move SourceAnnotationExtractor under Rails module
This class should be under Rails module as it belongs to Rails.
2018-03-22 17:06:14 +00:00
eileencodes
4e663c1e8d Refactor configs_for and friends
Moves the configs_for and DatabaseConfig struct into it's own file. I
was considering doing this in a future refactoring but our set up forced
me to move it now. You see there are `mattr_accessor`'s on the Core
module that have default settings. For example the `schema_format`
defaults to Ruby. So if I call `configs_for` or any methods in the Core
module it will reset the `schema_format` to `:ruby`. By moving it to
it's own class we can keep the logic contained and avoid this
unfortunate issue.

The second change here does a double loop over the yaml files. Bear with
me...

Our tests dictate that we need to load an environment before our rake
tasks because we could have something in an environment that the
database.yml depends on. There are side-effects to this and I think
there's a deeper bug that needs to be fixed but that's for another
issue. The gist of the problem is when I was creating the dynamic rake
tasks if the yaml that that rake task is calling evaluates code (like
erb) that calls the environment configs the code will blow up because
the environment is not loaded yet.

To avoid this issue we added a new method that simply loads the yaml and
does not evaluate the erb or anything in it. We then use that yaml to
create the task name. Inside the task name we can then call
`load_config` and load the real config to actually call the code
internal to the task. I admit, this is gross, but refactoring can't all
be pretty all the time and I'm working hard with `@tenderlove` to
refactor much more of this code to get to a better place re connection
management and rake tasks.
2018-03-21 16:54:24 -04:00
Ryuta Kamizono
958c5ad9e9 Fix test_config_another_database failure
Somehow `test_config_another_database` didn't fail on CI, but it will
fail locally.

https://travis-ci.org/rails/rails/jobs/356212950#L2474-L2482

```
% bundle exec ruby -w -Itest test/generators/app_generator_test.rb -n test_config_another_database
Run options: -n test_config_another_database --seed 7260

# Running:

F

Failure:
AppGeneratorTest#test_config_another_database [test/generators/app_generator_test.rb:417]:
Expected /^\s*gem\s+["']mysql2["'], '~> 0.4.4'$*/ to match "source 'https://rubygems.org'\ngit_source(:github) { |repo| \"https://github.com/\#{repo}.git\" }\n\nruby '2.5.0'\n\n# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'\ngem 'rails', '~> 6.0.0.alpha'\n# Use mysql as the database for Active Record\ngem 'mysql2', '>= 0.4.4', '< 0.6.0'\n# Use Puma as the app server\ngem 'puma', '~> 3.11'\n# Use SCSS for stylesheets\ngem 'sass-rails', '~> 5.0'\n# Use Uglifier as compressor for JavaScript assets\ngem 'uglifier', '>= 1.3.0'\n# See https://github.com/rails/execjs#readme for more supported runtimes\n# gem 'mini_racer', platforms: :ruby\n\n# Use CoffeeScript for .coffee assets and views\ngem 'coffee-rails', '~> 4.2'\n# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks\ngem 'turbolinks', '~> 5'\n# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder\ngem 'jbuilder', '~> 2.5'\n# Use Redis adapter to run Action Cable in production\n# gem 'redis', '~> 4.0'\n# Use ActiveModel has_secure_password\n# gem 'bcrypt', '~> 3.1.7'\n\n# Use ActiveStorage variant\n# gem 'mini_magick', '~> 4.8'\n\n# Use Capistrano for deployment\n# gem 'capistrano-rails', group: :development\n\n# Reduces boot times through caching; required in config/boot.rb\ngem 'bootsnap', '>= 1.1.0', require: false\n\ngroup :development, :test do\n  # Call 'byebug' anywhere in the code to stop execution and get a debugger console\n  gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]\nend\n\ngroup :development do\n  # Access an interactive console on exception pages or by calling 'console' anywhere in the code.\n  gem 'web-console', '>= 3.3.0'\n  gem 'listen', '>= 3.0.5', '< 3.2'\n  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring\n  gem 'spring'\n  gem 'spring-watcher-listen', '~> 2.0.0'\nend\n\ngroup :test do\n  # Adds support for Capybara system testing and selenium driver\n  gem 'capybara', '>= 2.15', '< 4.0'\n  gem 'selenium-webdriver'\n  # Easy installation and use of chromedriver to run system tests with Chrome\n  gem 'chromedriver-helper'\nend\n\n# Windows does not include zoneinfo files, so bundle the tzinfo-data gem\ngem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]\n".

bin/rails test test/generators/app_generator_test.rb:411

Finished in 0.174681s, 5.7247 runs/s, 34.3483 assertions/s.
1 runs, 6 assertions, 1 failures, 0 errors, 0 skips
```
2018-03-22 03:20:04 +09:00
Aaron Stone
9f5477af93 Support mysql2 0.4.x and 0.5.x 2018-03-20 23:38:00 -07:00
Eileen M. Uchitelle
9700dacffe
Merge pull request #32271 from eileencodes/fix-three-tier-default-connection
Fix default connection handling with three-tier config
2018-03-16 15:18:26 -04:00
eileencodes
4027643f7f Switch dbconsole config loader check
In a three-tier config environment
`configurations[environment].presence` will return `{ :primary => {
:key => value, :key => value }, :secondary => { :key => value, :key =>
value} }, which means it's not given a single config to connect to.

If we flip these however it will connect to primary because that's the
default connection, and on a two tier it will be `nil` so the code will
select the connection from the configurations rather than the
connection.
2018-03-16 12:40:34 -04:00
Andrew White
ae7a57209d Pass the skip_pipeline option in image_submit_tag
Fixes #32248.
2018-03-14 11:18:06 +00:00
Max Schwenk
3e032bf23b
Raise an error when lockfile diff is generated
https://yarnpkg.com/en/docs/cli/install#toc-yarn-install-frozen-lockfile
2018-03-13 13:56:16 -07:00
Kasper Timm Hansen
6629d51a27
Rely on Rails::Command's help output.
We end up with:

```
Usage:
  bin/rails routes [options]

Options:
  -c, [--controller=CONTROLLER]      # Filter by a specific controller, e.g. PostsController or Admin::PostsController.
  -g, [--grep=GREP]                  # Grep routes by a specific pattern.
  -E, [--expanded], [--no-expanded]  # Print routes expanded vertically with parts explained.
```

which does miss the bit about routes being printed in order.

Also:

* Renames options to ease help output readability, then clarifies each option.
* Fixes a bunch of indentation.
2018-03-13 20:56:37 +01:00
Kasper Timm Hansen
f6310a3f16
Extract details to methods to clarify command. 2018-03-13 20:22:23 +01:00
Rafael Mendonça França
ba0ae542ca
Remove changelog header for unreleased version
We only add the header when releasing to avoid some conflicts.

[ci skip]
2018-03-13 15:20:57 -04:00
bogdanvlviv
304906f1bd
Introduce ActionDispatch::Routing::ConsoleFormatter::Base
- Create `Base` and inherit `Sheet` and `Expanded` in order to
- prevent code duplication.
  - Remove trailing "\n" for components of `Expanded`.
  - There is no need for `Expanded#header` to return `@buffer` so return `nil` instead.

- Change `no_routes` message "No routes were found for this controller"
  since if use `-g`, it sounds incorrect.
  - Display `No routes were found for this controller.` if apply `-c`.
  - Display `No routes were found for this grep pattern.` if apply `-g`.

Related to #32130
2018-03-13 11:58:52 +02:00
Yuji Yaginuma
4483c926fc Remove path option from AzureStorage config
Follow up of 309bb6c4d068b0d480681cf4ef1b90158527dfe5
2018-03-13 08:20:28 +09:00
Kasper Timm Hansen
ee01c753a3
Merge pull request #32160 from bogdanvlviv/improve-rails-routes-expanded
Draw line of a route name to the end of row console on `rails routes --expanded`
2018-03-11 20:48:50 +01:00
yuuji.yaginuma
9af6601a46 Do not show unnecessary message during server startup
Currently, `Exiting` is showed during server startup.

```
./bin/rails s
=> Booting Puma
=> Rails 6.0.0.alpha application starting in development
=> Run `rails server --help` for more startup options
Exiting
Puma starting in single mode...
* Version 3.11.2 (ruby 2.5.0-p0), codename: Love Song
```

This is because processing at server stop is passed as a block, and
`Rack::Serve#start` receives a block and executes it during startup processing.
50db1ffdf8/lib/rack/server.rb (L258)

In order to avoid this, stop processing is passed as argument.
2018-03-10 19:43:31 +09:00
Andrew White
190744cd8e Always yield a CSP policy instance
If the app has the CSP disabled globally allow a controller action
to enable the policy for that request.
2018-03-08 14:14:09 +00:00
yuuji.yaginuma
f30ac99d0c Allow using inline style and script in the internal controllers
We use inline style and script for the view held inside Rails like
welcome page and mailer preview.
Therefore, if inline is prohibited by CSP, they will not work properly.
I think that this is not as expected.  

For that reason, I have made it possible to use inline style and script
regardless of application settings.
2018-03-08 21:17:18 +09:00
Thomas Walpole
207536c063 Allow Capybara 3.x (#32151) 2018-03-05 17:44:39 -08:00
Ryuta Kamizono
9cc0c1aaf4
Merge pull request #32174 from bogdanvlviv/remove-extra-passing-arg-to-run_routes_command
Remove extra arg passed to `Rails::Command::RoutesTest#run_routes_command`
2018-03-06 01:23:20 +09:00
bogdanvlviv
c98050199e
Remove extra arg passed to Rails::Command::RoutesTest#run_routes_command
Related to 6bd33d66dde015a55912af20b469788ba20ddb4e
2018-03-05 15:07:33 +02:00
bogdanvlviv
012a4a3842
Draw line of a route name to the end of row console on rails routes --expanded
In order to get width of console use `IO::console_size`,
See https://ruby-doc.org/stdlib-2.4.1/libdoc/io/console/rdoc/IO.html#method-c-console_size

Related to #32130
2018-03-05 14:56:59 +02:00
Ryuta Kamizono
d13ce1f398
Merge pull request #32170 from koic/deprecate_safe_level_of_erb_new_in_ruby_2_6
Deprecate safe_level of `ERB.new` in Ruby 2.6
2018-03-05 21:18:00 +09:00
Koichi ITO
e8be4f0891 Deprecate safe_level of ERB.new in Ruby 2.6
### Summary

In a Rails application using Ruby 2.6.0-dev, when running `bin/rails g migration`
with `RUBYOPT=-w`, an ERB deprecation warnings will be displayed.

```console
% ruby -v
ruby 2.6.0dev (2018-03-03 trunk 62644) [x86_64-darwin17]
% bin/rails -v
Rails 6.0.0.alpha
% RUBYOPT=-w bin/rails g migration create_foos

(snip)

/Users/koic/src/github.com/rails/rails/railties/lib/rails/generators/migration.rb:66:
warning: Passing safe_level with the 2nd argument of ERB.new is
deprecated. Do not use it, and specify other arguments as keyword
arguments.
/Users/koic/src/github.com/rails/rails/railties/lib/rails/generators/migration.rb:66:
warning: Passing trim_mode with the 3rd argument of ERB.new is
deprecated. Use keyword argument like ERB.new(str, trim_mode: ...)
instead.
/Users/koic/src/github.com/rails/rails/railties/lib/rails/generators/migration.rb:66:
warning: Passing eoutvar with the 4th argument of ERB.new is
deprecated. Use keyword argument like ERB.new(str, eoutvar: ...)
instead.
      create    db/migrate/20180304002144_create_foos.rb
```

This PR suppresses the above deprecation warnings in Ruby 2.6.0-dev.

This warning is due to the interface of `ERB.new` will change from Ruby 2.6.

> Add :trim_mode and :eoutvar keyword arguments to ERB.new.
> Now non-keyword arguments other than first one are softly deprecated
> and will be removed when Ruby 2.5 becomes EOL. [Feature #14256]

2311087b68/NEWS (stdlib-updates-outstanding-ones-only)

The following addresses are related Ruby's commit.
https://github.com/ruby/ruby/commit/cc777d0

Also this PR will change `ERB.new` used in `tasks/release.rb`.

### Other Information

This PR uses `ERB.version` to switch `ERB.new` interface. Because Rails 6
supports multiple Ruby versions (Ruby 2.4.1 or higher), it need to
use the appropriate interface.

Using `ERB.version` instead of `RUBY_VERSON` is based on the following patch.
https://github.com/ruby/ruby/pull/1826

This patch is built into Ruby.
40db89c093
2018-03-05 18:49:45 +09:00
yuuji.yaginuma
968c499aca Fix "NameError: undefined local variable or method `host'"
The `host` and `port` can't use this context.
2018-03-05 08:02:04 +09:00