Commit Graph

13010 Commits

Author SHA1 Message Date
Yuji Yaginuma
bf625f7fec
Merge pull request #36486 from benthorner/master
Allow using env var to specify pidfile
2019-06-20 11:52:21 +09:00
Ben Thorner
2e5ec9a6ef Allow using env var to specify pidfile
Previously it was only possible to specify the location of the pidfile
for the 'rails server' command with the '-P' flag. This adds support for
specifying the pidfile using a PIDFILE env var, which can still be
overridden by the '-P' flag and with the default pidfile path unchanged.

The motivation for this feature comes from using Docker to run multiple
instances of the same rails app. When developing a rails app with
Docker, it's common to bind-mount the rails root directory in the
running container, so that changes to files are shared between the
container and the host. However, this doesn't work so well with the
pidfile and it's necessary to (remember to) add a '-P' flag to the
'rails server' command line; being able to specify this flag using an
env var would make developing with Rails+Docker a bit simpler.
2019-06-19 14:06:38 +01:00
eileencodes
7cc27d749c Move SchemaMigration to migration_context
This PR moves the `schema_migration` to `migration_context` so that we
can access the `schema_migration` per connection.

This does not change behavior of the SchemaMigration if you are using
one database. This also does not change behavior of any public APIs.
`Migrator` is private as is `MigrationContext` so we can change these as
needed.

We now need to pass a `schema_migration` to `Migrator` so that we can
run migrations on the right connection outside the context of a rake
task.

The bugs this fixes were discovered while debugging the issues around
the SchemaCache on initialization with multiple database. It was clear
that `get_all_versions` wouldn't work without these changes outside the
context of a rake task (because in the rake task we establish a
connection and change AR::Base.connection to the db we're running on).

Because the `SchemaCache` relies on the `SchemaMigration` information we
need to make sure we store it per-connection rather than on
ActiveRecord::Base.

[Eileen M. Uchitelle & Aaron Patterson]
2019-06-14 11:15:08 -04:00
Ryuta Kamizono
98a57aa5f6
Merge pull request #36472 from kamipo/empty_line_only_before_access_modifier
Enable `Layout/EmptyLinesAroundAccessModifier` cop
2019-06-13 18:36:23 +09:00
Ryuta Kamizono
75eb3d0cec Don't drop_table before schema cache tests
Since 5cab34449, `drop_table` clears schema cache.
2019-06-13 13:43:26 +09:00
Ryuta Kamizono
c81af6ae72 Enable Layout/EmptyLinesAroundAccessModifier cop
We sometimes say "✂️ newline after `private`" in a code review (e.g.
https://github.com/rails/rails/pull/18546#discussion_r23188776,
https://github.com/rails/rails/pull/34832#discussion_r244847195).

Now `Layout/EmptyLinesAroundAccessModifier` cop have new enforced style
`EnforcedStyle: only_before` (https://github.com/rubocop-hq/rubocop/pull/7059).

That cop and enforced style will reduce the our code review cost.
2019-06-13 12:00:45 +09:00
Mark Lee
cb8b57d07e Convert the db:abort_if_pending_migrations task to be multi-DB aware 2019-06-10 18:01:32 -07:00
yuuji.yaginuma
770f8f345f Remove redundant blank line at the bottom of the generated controller test 2019-06-07 15:18:44 +09:00
Eileen M. Uchitelle
ccb30615a3
Merge pull request #36416 from freeletics/fix-db-prepare
Fixed db:prepare task for multiple databases.
2019-06-05 10:31:52 -04:00
Eileen M. Uchitelle
71a019efe8
Merge pull request #36394 from eileencodes/treat-application-record-as-primary
Treat ActiveRecord::Base and ApplicationRecord as "primary"
2019-06-05 10:01:18 -04:00
eileencodes
2f8b397258 Treat ActiveRecord::Base and ApplicationRecord as "primary"
When someone has a multi-db application their `ApplicationRecord` will
look like:

```ruby
class ApplicationRecord < ActiveRecord::Base
  self.abstract_class = true

  connects_to database: { writing: :primary, reading: :replica }
end
```

This will cause us to open 2 connections to ActiveRecord::Base's
database when we actually only want 1. This is because Rails sees
`ApplicationRecord` and thinks it's a new connection, not the existing
`ActiveRecord::Base` connection because the
`connection_specification_name` is different.

This PR changes `ApplicationRecord` classes to consider themselves the
same as the "primary" connection.

Fixes #36382
2019-06-05 09:29:29 -04:00
Wojciech Wnętrzak
87796b3c81
Fixed db:prepare task for multiple databases.
When one database existed already, but not the other,
during setup of missing one, existing database was wiped out.
2019-06-05 12:17:02 +02:00
yuuji.yaginuma
689b371a52 Extract default log file open operation to method
This allows customize a default log file(e.g. `reopen`) by an application.

Fixes #32211.
2019-06-05 11:19:15 +09:00
yuuji.yaginuma
4cb0ce2e79 Fix rubocop violation 2019-06-05 10:37:03 +09:00
Eileen M. Uchitelle
61c3ea8c04 Merge pull request #36395 from cpruitt/6-0-stable
Do not clear deprecated initializer dependencies if using classic autoloader
2019-06-04 10:04:30 -04:00
John Hawthorn
9fd02d181a Fail parallel tests if workers exit early
Previously, if a test worker exited early, the in-flight test it was
supposed to run wasn't reported as a failure.

If all workers exited immediately, this would be reported as ex.

    Finished in 1.708349s, 39.2192 runs/s, 79.0237 assertions/s.
    67 runs, 135 assertions, 0 failures, 0 errors, 2 skips

This commit validates that all workers finish running tests by ensuring
that the queue is empty after they exit. This works because we signal
the workers to exit by pushing nil onto the queue, so that there should
be a number of items left in the queue matching potentially missed
tests.
2019-05-30 21:34:47 -07:00
yuuji.yaginuma
784664f85b Bring after_bundle back to API document [ci skip]
At class level `:nodoc:` all elements are prevented. Instead, use
`:stopdoc:` / `:startdoc:` to make `after_bundle` appear.
2019-05-29 11:46:32 +09:00
Kasper Timm Hansen
a1c269fbdf
Skip needless spaces from generated app layout. 2019-05-26 23:02:37 +02:00
Anton Rieder
1fe26f7f8b
Bump Gemfile entry jbuilder version
jbuilder 2.6.4 is the first version that relaxes the version constraint to allow
Rails 6. I also did some more tests in #25183, although not with 2.6.4
explicitly.

To simplify the version requirement, I went for 2.7.

https://github.com/rails/jbuilder/blob/v2.6.4/jbuilder.gemspec
https://github.com/rails/rails/issues/25183#issuecomment-494342406
2019-05-23 17:21:34 +02:00
Vishal Telangre
ae9be13713
Fix: DummyCompiler embeds invalid YAML content
Fixes https://github.com/rails/rails/issues/36285.

Follow up of https://github.com/rails/rails/pull/36237.
2019-05-15 22:26:07 +05:30
Eileen M. Uchitelle
bd0618b1f3
Merge pull request #36237 from eileencodes/fix-erb-in-database-yaml-again
Fix database loading when ERB is single line ternary
2019-05-14 03:29:37 -04:00
George Claghorn
b2b6341374
Add ActionDispatch::SystemTestCase#fill_in_rich_text_area 2019-05-13 12:44:06 -04:00
Xavier Noria
4829214aa2 adds a blank line [ci skip] 2019-05-13 06:00:28 +02:00
Xavier Noria
63f39dd6eb warn about non-eager loaded dirs in zeitwerk:check 2019-05-13 05:49:00 +02:00
Vipul A M
31a3eea5ac Update the sqlite db yaml template to match others and mention proper supported version 2019-05-12 07:08:56 +05:30
Gannon McGibbon
e84ee74854 Merge branch 'migration-timestamp-fix'
Closes #28707.
2019-05-10 16:45:46 -04:00
eileencodes
5df84533d5 Fix database loading when ERB is single line ternary
*sigh* this seems like the never ending bug. I don't love or even like
this fix but it does _work_.

Rafael suggested using `dummy_key: dummy_value` but unfortunately
that doesn't work. So we're left with checking whethere there might be
ternary type things in the content and then assuming that we want to
replace the line with a key value pair.

Technically fixes https://github.com/rails/rails/issues/36088
2019-05-10 16:28:08 -04:00
Yuji Yaginuma
669b52d296
Merge pull request #36225 from deivid-rodriguez/workaround_sass_rails_requirement
Use a better requirement for sass-rails 6 prereleases
2019-05-09 17:33:55 +09:00
Sharang Dashputre
3d5cf0c595 Fix indentation of the config.eager_load nil warning 2019-05-09 13:17:04 +05:30
David Rodríguez
786bdc4c11
Use a better requirement for sass-rails 6 prereleases
This is the behavior I naively expect for the operator when used with a
single digit, but it's definitely an edge case for it, and it doesn't
seem to work as expected for including prereleases.

Using >= works fine and make the intention more clear anyways.
2019-05-09 09:40:30 +02:00
Abhay Nikam
dd643f4893 Fix indentation for config.eager_load nil warning message 2019-05-08 20:57:16 +05:30
Eileen M. Uchitelle
d155f61b64 Merge pull request #36196 from st0012/fix-29947
Hide malformed parameters from error page

Accidentally merged this to 6-0-stable so forward porting it to master
here instead.
2019-05-07 15:14:14 -04:00
yuuji.yaginuma
85a8bc644b Make generated test work even when using virtual attributes
The virtual attributes(`attachment` and `rich_text`) can't set value
with `fill_in`. So avoid using it. Once #35885 is merged, will be
modified to use it.

Also, add checking attachment attached or not for avoiding
`DelegationError` when attachment didn't attach.
2019-05-05 09:55:37 +09:00
Ryuta Kamizono
c1ff1392db Fix rubocop offences 2019-04-30 18:32:41 +09:00
Xavier Noria
b6e17b6a4b new config to opt-out from adding app directories to $LOAD_PATH 2019-04-28 13:48:26 +02:00
Guilherme Mansur
dbcaf9d157 Fallback to spawn instead of fork in jruby (#36111)
* Fallback to spawn instead of fork in jruby

This commit: b342db6 introduced a `fork` fork when running the railties
tests since this is not supported in jruby we fallback to using spawn.
Fixes: https://github.com/rails/rails/issues/35900
2019-04-26 17:22:28 -05:00
Prathamesh Sonpatki
fa0ce5c790
Bump bootsnap to a version with disables iseq_cache for Ruby 2.5
- Refs https://github.com/Shopify/bootsnap/pull/257
2019-04-26 12:55:28 +05:30
Rafael Mendonça França
9834be6565
Start Rails 6.1 development 2019-04-24 15:57:14 -04:00
Rafael França
5566b4a636
Merge pull request #36067 from st0012/update-generator-for-api-app
Remove action_controller.perform_caching from api app's configs
2019-04-23 14:37:46 -04:00
Rafael França
d33f5e55f1
Merge pull request #35852 from larouxn/resurrection
Resurrect external JS/CS generation
2019-04-23 14:21:30 -04:00
st0012
d63f9383a6 Remove action_controller.perform_caching from api app's configs
As suggested in https://github.com/rails/rails/issues/35602#issuecomment-485833483, because we don't provide view caching and doesn't include `ActionController::Caching` for api apps, we should also avoid generating

```ruby
config.action_controller.perform_caching = true
```

for those api apps. So it won't confuse people.

**But because `perform_caching` will be `true` if not set, the behavior of the app would still be the same without these configs.**
2019-04-24 02:08:13 +08:00
Xavier Noria
afc17e5ea2 Implements the task zeitwerk:check
[Matilda Smeds & Xavier Noria]
2019-04-23 03:17:34 +02:00
Xavier Noria
1b2efe5a11 upgrades Zeitwerk to 2.1.4
This commit more or less undoes 9b5401f, restores autoloaded? not to
touch the descendants tracker, and autoloaded_constants because it is
documented in the guide.
2019-04-23 01:18:21 +02:00
Rafael França
b62b038d9a
Revert "Include Caching module for ActionController::API" 2019-04-22 17:20:48 -04:00
Guillermo Iguaran
216ef01d14
Merge pull request #36038 from st0012/fix-35602
Include Caching module for ActionController::API
2019-04-22 16:05:51 -05:00
Guillermo Iguaran
2e4c65e3af Allow sass-rails greater than 5.x in new apps 2019-04-22 14:35:04 -05:00
Richard Macklin
ef12ccfd8b Make system tests take failed screenshots in before_teardown hook
Previously we were calling the `take_failed_screenshot` method in an
`after_teardown` hook. However, this means that other teardown hooks
have to be executed before we take the screenshot. Since there can be
dynamic updates to the page after the assertion fails and before we
take a screenshot, it seems desirable to minimize that gap as much as
possible. Taking the screenshot in a `before_teardown` rather than an
`after_teardown` helps with that, and has a side benefit of allowing
us to remove the nested `ensure` commented on here:
https://github.com/rails/rails/pull/34411#discussion_r232819478
2019-04-20 19:32:30 -07:00
Gannon McGibbon
d3dc651a81
Merge pull request #35896 from jlw/bug/active-jobless-seeds
[#35782] Allow loading seeds without ActiveJob (~> 5.2.3)
2019-04-20 12:39:03 +09:00
yuuji.yaginuma
21747560be Remove duplicated test
With 8b4d344815655027d9f7584c0a59271dce8f1d5a, `test_required_polymorphic_belongs_to_generates_correct_model`
and `test_required_and_polymorphic_are_order_independent` are completely
same. Also, remove `required` from test name because that not passed to
generator.
2019-04-20 09:30:22 +09:00
eileencodes
f9244c6585 Handle up/down for multiple databases
This change adds the ability to run up/down for a database in a multi-db
environment.

If you have an app with a primary and animals database the following
tasks will be generated:

```
VERSION=123 rake db:migrate:up:primary
VERSION=123 rake db:migrate:up:primary

VERSION=123 rake db:migrate:down:primary
VERSION=123 rake db:migrate:up:animals
```

I didn't generate descriptions with them since we don't generate a
description for a single database application.

In addition to this change I've made it so if your application has
multiple databases Rails will raise if you try to run `up` or `down`
without a namespace. This is because we don't know which DB you want to
run `up` or `down` against unless the app tells us, so it's safer to
just block it and recommend using namespaced versions of up/down
respectively.

The output for the raise looks like:

```
You're using a multiple database application. To use `db:migrate:down`
you must run the namespaced task with a VERSION. Available tasks are
db:migrate:down:primary and db:migrate:down:animals.
```
2019-04-19 13:14:24 -04:00